Discussion:
[jboss-user] [jBPM] - Invoke Human Task Flow - Using API
Balaji Subramaniam
2013-03-11 14:25:15 UTC
Permalink
Balaji Subramaniam [https://community.jboss.org/people/balajiora] created the discussion

"Invoke Human Task Flow - Using API"

To view the discussion, visit: https://community.jboss.org/message/801923#801923

--------------------------------------------------------------
I am new to JBPM and I appreciate, if you help me in below points.

1. How to Invoke human task flow and complete using Knowledge API?

(Ex: I have deployed the simple human workflow in Guvnor, logged in as Krisv and created the task.  I do not want to login as Mary to act on the work item in JBPM Console, instead using JBPM API;I need to complete this task)

2. Example to read the instances deployed in Guvnor.

3. How to pause / suspend the Process using JBPM API?

Balaji S
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/801923#801923]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
roxy1987
2013-03-11 16:17:43 UTC
Permalink
roxy1987 [https://community.jboss.org/people/roxy1987] created the discussion

"Re: Invoke Human Task Flow - Using API"

To view the discussion, visit: https://community.jboss.org/message/801956#801956

--------------------------------------------------------------
To 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.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/801956#801956]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Thomas Setiabudi
2013-03-13 02:48:58 UTC
Permalink
Thomas Setiabudi [https://community.jboss.org/people/thomas.setiabudi] created the discussion

"Re: Invoke Human Task Flow - Using API"

To view the discussion, visit: https://community.jboss.org/message/802238#802238

--------------------------------------------------------------
Hi Balaji Subramaniam,

About getting process definition from guvnor, you can see how JBPM Console server do it in

https://github.com/droolsjbpm/jbpm/blob/master/jbpm-gwt/jbpm-gwt-core/src/main/java/org/jbpm/integration/console/kbase/DefaultKnowledgeBaseManager.java https://github.com/droolsjbpm/jbpm/blob/master/jbpm-gwt/jbpm-gwt-core/src/main/java/org/jbpm/integration/console/kbase/DefaultKnowledgeBaseManager.java

They have a utility to connect to guvnor

https://github.com/droolsjbpm/jbpm/blob/master/jbpm-gwt/jbpm-gwt-shared/src/main/java/org/jbpm/integration/console/shared/GuvnorConnectionUtils.java https://github.com/droolsjbpm/jbpm/blob/master/jbpm-gwt/jbpm-gwt-shared/src/main/java/org/jbpm/integration/console/shared/GuvnorConnectionUtils.java


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
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/802238#802238]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Loading...