JBoss Community

Re: Combining human and automated tasks

created by Tommer Wizansky in jBPM - View the full discussion

Yes!  That works!  Registering the task handler when invoking the human task client was the part I was missing.  Thank you.

 

As it turns out, I don't even need to load the original session.  I can register the task handler with a new stateful session and it still works:

 

        // Create a new session

        KnowledgeBase kbase = readKnowledgeBase(CREATE_INSTALLER_PROCESS);

        Environment env = KnowledgeBaseFactory.newEnvironment();

        env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);

        env.set(EnvironmentName.TRANSACTION_MANAGER, transactionManager);

        StatefulKnowledgeSession ksession = JPAKnowledgeService

                .newStatefulKnowledgeSession(kbase, null, env);

 

        // Register a handler

        CommandBasedWSHumanTaskHandler handler = new CommandBasedWSHumanTaskHandler(ksession);

        handler.connect();

        ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);

       

        // Create a human task client

        TaskClient client = new TaskClient(new MinaTaskClientConnector(

                "MinaConnector", new MinaTaskClientHandler(

                        SystemEventListenerFactory.getSystemEventListener())));

        client.connect("127.0.0.1", 9123);

        Thread.sleep(1000);

        BlockingTaskSummaryResponseHandler taskSummaryResponseHandler = new BlockingTaskSummaryResponseHandler();

        client.getTasksAssignedAsPotentialOwner("krisv", "en-UK",

                taskSummaryResponseHandler);

        List<TaskSummary> tasks = taskSummaryResponseHandler.getResults();

        TaskSummary taskSummary = tasks.get(0);

        long taskId = taskSummary.getId();

        BlockingTaskOperationResponseHandler responseHandler = new BlockingTaskOperationResponseHandler();

        client.start(taskId, "krisv", responseHandler);

 

        // Complete the task

        long taskId = taskSummary.getId();

        BlockingTaskOperationResponseHandler responseHandler = new BlockingTaskOperationResponseHandler();

        client.start(taskId, "krisv", responseHandler);

        client.complete(taskId, "krisv", null, responseHandler);

 

I'd like to understand the details.  When is it necessary to load an existing session and when can you use a new one?  But, in the meantime, it works.

 

Thanks again.

 

Tommer

Reply to this message by going to Community

Start a new discussion in jBPM at Community