Showing posts with label BEPL. Show all posts
Showing posts with label BEPL. Show all posts

Monday, 29 May 2017

Approving OIM request programatically using BEPL APIs

Using BEPL APIs one can programmatically perform actions on a OIM request. Below is an example of the same.

1. Create a project in eclipse.
2. Copy the below jars from servers

            [WL_HOME]/server/lib/weblogic.jar
      [SOA_HOME]/soa/modules/oracle.soa.fabric_11.1.1/bpm-infra.jar
      [SOA_HOME]/soa/modules/oracle.soa.fabric_11.1.1/fabric-runtime.jar
      [SOA_HOME]/soa/modules/oracle.soa.workflow_11.1.1/bpm-services.jar
      [WL_HOME]/server/lib/wlfullclient.jar

      [OIM_HOME]/server/ext/spml/wsclient_extended.jar

3. Set the above jars in your project classpath
4. Use the below code in your project.


import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;


import com.bea.security.providers.xacml.entitlement.parser.Predicate;
import oracle.bpel.services.workflow.WorkflowException;
import oracle.bpel.services.workflow.client.config.RemoteClientType;
import oracle.bpel.services.workflow.client.config.RemoteClientType.Password;
import oracle.bpel.services.workflow.client.config.ServerType;
import oracle.bpel.services.workflow.client.config.WorkflowServicesClientConfigurationType;
import oracle.bpel.services.workflow.client.IWorkflowServiceClient;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
import oracle.bpel.services.workflow.query.ITaskQueryService;
import oracle.bpel.services.workflow.query.ITaskQueryService.AssignmentFilter;
import oracle.bpel.services.workflow.repos.TableConstants;
import oracle.bpel.services.workflow.task.ITaskService;
import oracle.bpel.services.workflow.task.model.Task;
import oracle.bpel.services.workflow.verification.IWorkflowContext;



 

public class ApproveOIMRequest {

public void approveRequest(String reqId) throws Exception{
Logger logger = Logger.getLogger(ApproveOIMRequest.class.getName());

/**
* Adding SOA server and its properties into the WorkflowServicesClientConfigurationType
*/

WorkflowServicesClientConfigurationType wssst = new WorkflowServicesClientConfigurationType();
List<ServerType> servers = wssst.getServer();
ServerType server = new ServerType();
server.setDefault(true);
server.setName("soa");

servers.add(server);


/**
* Creating remote client with all the SOA server connection parameters including login user as xelsysadm.
*/

RemoteClientType rct = new RemoteClientType();
rct.setServerURL("t3://ess.com:8001");
rct.setUserName("xelsysadm");
Password weblogicPWD = new Password();
weblogicPWD.setValue("Welcome1");
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);

ITaskQueryService qService = wfsc.getTaskQueryService();

/**
* Authenticating using xelsysadm
*/

String xelsysadmPassword = "Welcome1";
IWorkflowContext wctx = qService.authenticate("xelsysadm", xelsysadmPassword.toCharArray(), null);

/**
* List the column name to get the value from query service.
* the columns are all from WFTASK table in SOAINFRA schema.
*/

List queryColumns = new ArrayList();
queryColumns.add("TASKID");
queryColumns.add("TASKNUMBER");
queryColumns.add("TITLE");
queryColumns.add("OUTCOME");
queryColumns.add("IDENTIFICATIONKEY");


/**
* Assigning filter for selecting assigned tasks
*/

AssignmentFilter assignmentFilter = AssignmentFilter.ALL;
/**
* List all the assignd tasks for logged in user.
*/

List tasks = qService.queryTasks(wctx, queryColumns, null, assignmentFilter, null, null, null, 0, 0);


/**
* get the object of task service in order to perform actions on tasks.
*/
ITaskService taskService = wfsc.getTaskService();

System.out.println("tasks.size() :"+tasks.size());
/**
* Iterate the list of tasks and check for the request id and status.
* if the status is not APPROVED and request id gets matched, then
* perform update task like APPROVE the task
*/

for (int i=0; i<tasks.size(); i++){

//System.out.println("Task found for request id: "+reqId);
Task task = (Task) tasks.get(i);
int taskNumber = task.getSystemAttributes().getTaskNumber();
String taskTitle = task.getTitle();
String taskId = task.getSystemAttributes().getTaskId();
String taskOutcome = task.getSystemAttributes().getOutcome();
String identificationKey = task.getIdentificationKey();

//System.out.println(taskNumber+" "+taskTitle+" "+taskOutcome+" "+identificationKey);

if (identificationKey.equalsIgnoreCase(reqId) && taskOutcome == null){
System.out.println(taskNumber+" "+""+" "+taskOutcome+" "+identificationKey);
taskOutcome = "APPROVE";
taskService.updateTaskOutcome(wctx, taskId, taskOutcome);

}

}

System.out.println("Done");
}


public static void main(String[] args) {

ApproveOIMRequest a = new ApproveOIMRequest();

try {
a.approveRequest("32001"); //Request Id is the input parameter.
} catch (Exception e) {

e.printStackTrace();

}

}

}


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: /************...