Here is the app link in Workspace
Now I want to initiate via the API.
First Kudos to Rommel Pino's post here
A great starting point -
Anyway - let's get a list of the Initiable Processes I have deployed, and then initiate the above process.
I create a project in jdev and include the following jars -
Code -
package initiatorapi;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import oracle.bpel.services.bpm.common.IBPMContext;
import oracle.bpel.services.workflow.client.IWorkflowServiceClient;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
import oracle.bpel.services.workflow.task.model.Task;
import oracle.bpm.client.BPMServiceClientFactory;
import oracle.bpm.services.client.IBPMServiceClient;
import oracle.bpm.services.instancemanagement.IInstanceManagementService;
import oracle.bpm.services.processmetadata.IProcessMetadataService;
import oracle.bpm.services.processmetadata.ProcessMetadataSummary;
public class InitiableProcesses {
private static String url = "t3://localhost:7001";
public InitiableProcesses() {
super();
}
public void getInitiatiableProcesses() {
System.out.println("getInitiatiableProcesses()");
try {
IProcessMetadataService service =
getBPMServiceClient().getProcessMetadataService();
IBPMContext bpmContext = getIBPMContext("weblogic", "welcome1");
List
service.getInitiatableProcesses(bpmContext);
for (ProcessMetadataSummary pms : initiableTasks) {
System.out.println(pms.getProjectName() + "/" +
pms.getProcessName());
System.out.println("App Link " +
pms.getApplicationLinkDisplayName());
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(" #################### ");
}
public void initiateProcess(String processName) {
System.out.println(" +++ initiateProcess() for " + processName);
try {
IBPMServiceClient ibsc = getBPMServiceClient();
IProcessMetadataService service =
getBPMServiceClient().getProcessMetadataService();
IBPMContext bpmContext = getIBPMContext("weblogic", "welcome1");
List
service.getInitiatableProcesses(bpmContext);
for (ProcessMetadataSummary pms : initiableTasks) {
System.out.println("++++ Process Name = " + pms.getProjectName() + "/" +
pms.getProcessName());
if (pms.getProcessName().equalsIgnoreCase(processName)) {
IInstanceManagementService ims =
ibsc.getInstanceManagementService();
Task task =
ims.createProcessInstanceTask(bpmContext, pms.getCompositeDN() +
"/" +
pms.getProcessName());
System.out.println("++++ Task title = " + task.getTitle());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void initiate() {
}
// Connect to WLS
public static BPMServiceClientFactory getBPMServiceClientFactory() {
Map
new HashMap
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,
WorkflowServiceClientFactory.REMOTE_CLIENT);
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,
url);
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
return BPMServiceClientFactory.getInstance(properties, null, null);
}
public static IBPMContext getIBPMContext(String username,
String password) throws Exception {
return getBPMServiceClientFactory().getBPMUserAuthenticationService().authenticate(username,
password.toCharArray(),
null);
}
public static IWorkflowServiceClient getIWorkflowServiceClient() {
return getBPMServiceClientFactory().getWorkflowServiceClient();
}
public static IBPMServiceClient getBPMServiceClient() {
return getBPMServiceClientFactory().getBPMServiceClient();
}
//
}
Test a couple of times -
I now log in to workspace as weblogic -
Now let's check the roles for this process -
Test the API with jstein/welcome1
I change the method so as to pass in user/pwd -
Re-test -
No comments:
Post a Comment