[rules-users] Resuming a simple process involving human task

nanic23 nanic23 at hotmail.com
Wed Apr 14 14:13:18 EDT 2010


@Touma

I'm doing something very similar and it is working for me. Well, I have a
different problem that I'm trying to solve but I am able to successfully
resume the flow.

I am not using the Mina server either. I am just hooking a regular
WorkItemHandler to the HumanTask.

This is my flow : (start) --> (Human Task) --> (Print Out Node) --> [end]

I start the flow the following way:

@Test
public void shouldSuspendOnHumanTask() {
    ksession =
JPAKnowledgeService.newStatefulKnowledgeSession(knowledgeBase, null, env);
    dbLogger = new WorkingMemoryDbLogger(ksession);

    registerWorkItemHandlers(ksession); //nothing special here.... I just
register my work item handlers.

    Map<String, Object> params = new HashMap<String, Object>();
    params.put( "user", "nick" );
   
    ksession.startProcess("approval", params);
}

The WorkItemHandler for the HumanTask doesn't complete the workItem so the
flow suspends and gets persisted.

I reload and resume the flow the following way:

@Test
public void shouldResumeFlow() {
    System.out.println("Resuming flow...");
    MyDAO dao = new MyJpaDAO(emf.createEntityManager());
    MyEntity myEntity = dao.findById(ID); //id of the entity that holds the
session id for the flow I want to resume

    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(
myEntity.getSessionId(), knowledgeBase, null, env );
		
    registerWorkItemHandlers( ksession ); //register work item handlers
again.
		
    dbLogger = new WorkingMemoryDbLogger( ksession );
		
    ksession.getWorkItemManager().completeWorkItem(
myEntity.getWorkItemId(), null );
}

The only thing to notice which is different and will vary depending on your
implementation is that I am using an Entity to store the different IDs that
I'll need. So, before the flow suspends I persist this entity and when the
flow resumes I use DAO to retrieve it.
My entity looks something like:
MyEntity {
    private long id; //entity id
    private int sessionId; //drools-flow session id 
    private int processInstanceId; //drools-flow process instance id
    private int workItemId; //drools-flow work item id
    .......
    //Constructor
   //Setters and Getters
}

So, before resuming the flow I retrieve this entity and then use
"myEntity.getSessionId()" to reload the flow.

Oh, just in case... my "env" drools runtime environment object looks like
this:

		env = KnowledgeBaseFactory.newEnvironment();
		env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
		env.set(EnvironmentName.GLOBALS, new MapGlobalResolver());

I think that's it......

It resumes and the "Print Node" executes and the flow completes.

Let me know if you need more details or explanation about what's presented
above.

I hope it helps!!!

Nick.

-- 
View this message in context: http://n3.nabble.com/Resuming-a-simple-process-involving-human-task-tp716250p719197.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list