Thursday, 16 November 2017

Adding worklist URI of an Human Task Pragmatically using BPEL APIs

In this blog I am going to show how worklist URI can be set for an human task programitically using BPEL APIs. This code snipet can be used to automate the URI adding process after deploying the SOA composite.

Add the below jar files in your project classpath [WLHOME]/server/lib/weblogic.jar [SOAHOME]/soa/modules/oracle.soa.fabric11.1.1/bpm-infra.jar [SOAHOME]/soa/modules/oracle.soa.fabric11.1.1/fabric-runtime.jar [SOAHOME]/soa/modules/oracle.soa.workflow11.1.1/bpm-services.jar [WLHOME]/server/lib/wlfullclient.jar [OIMHOME]/server/ext/spml/wsclientextended.jar

here is the code snipet for adding worklist URI

import java.util.List;
import java.util.logging.Logger;
import oracle.bpel.services.workflow.client.IWorkflowServiceClient;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
import oracle.bpel.services.workflow.client.config.RemoteClientType;
import oracle.bpel.services.workflow.client.config.ServerType;
import oracle.bpel.services.workflow.client.config.WorkflowServicesClientConfigurationType;
import oracle.bpel.services.workflow.client.config.RemoteClientType.Password;
import oracle.bpel.services.workflow.query.ITaskQueryService;
import oracle.bpel.services.workflow.runtimeconfig.model.TaskDisplayInfo;
import oracle.bpel.services.workflow.runtimeconfig.model.TaskDisplayInfoType;
import oracle.bpel.services.workflow.verification.IWorkflowContext;
import oracle.bpel.services.workflow.WorkflowException;
import org.identityconnectors.common.security.GuardedString;
import org.identityconnectors.common.security.GuardedString.Accessor;


public class TestSOA {
    
    private String soaAdminUserName = "weblogic";
    private GuardedString soaAdminPassword = null;
    private String adminPassword = "Weblogic Password"; // put your weblogic password
    private String soaServerName = "SOA Server name"; //put your SOA server name e.g. soa_server1
    private String soaServerURL = "t3://SOA_HOST:8001"; //replace the value of SOA_HOST.
    Password weblogicPWD = null;
    IWorkflowContext wctx = null;
    ITaskQueryService qService = null;

    /**
     * This method will check the input request id has been approved by a human
     * @param reqId : OIM request id
     * @return : true/false
     * @throws Exception
     */
    public void addWorkilistURI() throws Exception{
        
        boolean flag = false;
                Logger logger = Logger.getLogger(TestSOA.class.getName());
                /**
                 * Adding SOA server and its properties into the WorkflowServicesClientConfigurationType
                 */
                WorkflowServicesClientConfigurationType wssst = new WorkflowServicesClientConfigurationType();
                List servers = wssst.getServer();
                ServerType server = new ServerType();
                server.setDefault(true);
                server.setName(soaServerName);
                servers.add(server);

                RemoteClientType rct = new RemoteClientType();
                rct.setServerURL(soaServerURL);
                rct.setUserName(soaAdminUserName);
                soaAdminPassword = new GuardedString (adminPassword.toCharArray());
                soaAdminPassword.access(new Accessor() {
                    @Override
                    public void access(char[] clearChars) {
                        System.out.println( new String(clearChars));
                        weblogicPWD = new Password();
                        weblogicPWD.setValue(new String(clearChars));
                    }
                });

                rct.setPassword(weblogicPWD);
                rct.setInitialContextFactory("weblogic.jndi.WLInitialContextFactory");
                rct.setParticipateInClientTransaction(false);
                server.setRemoteClient(rct);
                
                /**
                 * Creating remote enterprise java bean interface to invoke workflow 
                 * service located remotely from the client.
                 * 
                 * After creating IWorkflowServiceClient object, get the Query Service.
                 */
                IWorkflowServiceClient wfsc = WorkflowServiceClientFactory.getWorkflowServiceClient(WorkflowServiceClientFactory.REMOTE_CLIENT,wssst,logger);
                qService = wfsc.getTaskQueryService();
                  
                 soaAdminPassword.access(new Accessor() {
                     public void access(char[] clearChars) {
                        System.out.println( new String(clearChars));
                        try {
                            wctx = qService.authenticate(soaAdminUserName, clearChars, null);
                    } catch (WorkflowException we) {
                        we.printStackTrace();
                    }
                     }
                });
                    
                soaAdminPassword.dispose();
                List taskDisplayInfoTypeList = wfsc.getRuntimeConfigService().getTaskDisplayInfoByTaskDefinitionId(wctx, TASK_ID, APPLICATION_NAME, FORM_NAME);

                if (taskDisplayInfoTypeList.size()==0){
                 
                 oracle.bpel.services.workflow.runtimeconfig.model.ObjectFactory of = new oracle.bpel.services.workflow.runtimeconfig.model.ObjectFactory();
                    TaskDisplayInfo taskInfoType = of.createTaskDisplayInfo();
                    taskInfoType.setHostname("HOSTNAME"); //enter your URI hostname
                    taskInfoType.setHttpPort("HTTP PORT"); //enter URI HHTP port
                    taskInfoType.setHttpsPort("HTTPS PORT");//enter URI HTTPS port
                    taskInfoType.setApplicationName("worklist");
                    taskInfoType.setFormName("default");
                    taskInfoType.setUri("URI VALUE"); //enter the URI value
                    
                    taskDisplayInfoTypeList.add(taskInfoType);
                    
                    wfsc.getRuntimeConfigService().setTaskDisplayInfo(wctx, HUMANTASK_NAME_SPACE, COMPOSITE_VERSION, PARTITION_NAME, taskDisplayInfoTypeList);
                    System.out.println("done");
                }else{
                 System.out.println("URI already added");
                }
                
               return flag;
    }

 public static void main(String[] args) {
       TestSOA a = new TestSOA();
       try {
            a.addWorkilistURI();
       } catch (Exception e) {
            e.printStackTrace();
       }
   }
}

Replace the below variable as per your requirement

TASK_ID: Human Task id, e.g. "default/DisconnectedProvisioning!1.0/ManualProvisioningTask"
APPLICATION_NAME: name of the application. Default is "worklist"
FORM_NAME: Default value is "default"
HUMANTASK_NAME_SPACE: Namespace of the human task, e.g. "http://xmlns.oracle.com/DefaultProvisioningComposite/DisconnectedProvisioning/ManualProvisioningTask"
COMPOSITE_VERSION: version of the composite, e.g. "1.0"
PARTITION_NAME: name of the partition where the composite is deployed, e.g. "default"

Note: Kindly ignore the line 122 in the code"".. some how it is appearing in the code block.

No comments:

Post a Comment

Followers

OIM API for adding process task and retry failed task

 In this blog you can find how to add new process task and retry any failed/rejected tasks using API. Adding new process task: /************...