This content has been marked as final.
Show 2 replies
-
1. Re: Invoke Human Task Flow - Using API
roxy1987 Mar 11, 2013 12:17 PM (in response to balajiora)1 of 1 people found this helpfulTo start a process
public static void startProc() throws Exception { try { KnowledgeBase kbase = readKnowledgeBase(); StatefulKnowledgeSession ksession = createKnowledgeSession(kbase); KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "test", 1000); ksession.startProcess("com.sample.demoProc"); if(humanTaskHandler.isConnected()) { humanTaskHandler.dispose(); } System.out.println("Process started ..."); logger.close(); } catch (Throwable t) { t.printStackTrace(); } } private static KnowledgeBase readKnowledgeBase() throws Exception { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newClassPathResource("demoProc.bpmn"), ResourceType.BPMN2); return kbuilder.newKnowledgeBase(); } private static StatefulKnowledgeSession createKnowledgeSession(KnowledgeBase kbase) { StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); humanTaskHandler = new HornetQHTWorkItemHandler(ksession); humanTaskHandler.setIpAddress("localhost"); humanTaskHandler.setPort(5153); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", humanTaskHandler); return ksession; }
To complete a human task
public static void completeTask(long taskId, String userId) throws Exception { String name = "client 1"+UUID.randomUUID(); TaskClient client = new TaskClient(new HornetQTaskClientConnector(name, new HornetQTaskClientHandler(SystemEventListenerFactory.getSystemEventListener()))); BlockingTaskOperationResponseHandler responseHandler = new BlockingTaskOperationResponseHandler(); ContentData contentData = null; client.connect(ipAddress, port); try { client.start(taskId, userId, responseHandler); responseHandler = new BlockingTaskOperationResponseHandler(); responseHandler.waitTillDone(5000); client.complete(taskId, userId, contentData, responseHandler); responseHandler.waitTillDone(5000); BpmAPI.completeWorkItem(taskId); } catch(Exception e) { BpmExceptionHandler.handleException(e); } finally { if(client != null) { client.disconnect(); } } }
To Pause/Suspend
public static void completeTask(long taskId, String userId, Map<String, Object> map) throws Exception { String name = "client 1"+UUID.randomUUID(); TaskClient client = new TaskClient(new HornetQTaskClientConnector(name, new HornetQTaskClientHandler(SystemEventListenerFactory.getSystemEventListener()))); BlockingTaskOperationResponseHandler responseHandler = new BlockingTaskOperationResponseHandler(); client.connect(ipAddress, port); try { client.suspend(taskId, userId, responseHandler); responseHandler.waitTillDone(5000); } catch(Exception e) { BpmExceptionHandler.handleException(e); } finally { if(client != null) { client.disconnect(); } } }
I dont use Guvnor so cant say about that.
Regards.
-
2. Re: Invoke Human Task Flow - Using API
thomas.setiabudi Mar 12, 2013 10:48 PM (in response to balajiora)Hi Balaji Subramaniam,
About getting process definition from guvnor, you can see how JBPM Console server do it in
They have a utility to connect to guvnor
Basically the idea is to build a knowledge agent that has all process definition from guvnor, then create a knowledge base using that knowledge agent
Regards,
Thomas Setiabudi