Question

I have created a dummy workflow which i have tested using the folowing test case :

@Test
    public void testNonPifCondition(){
        //prepare input parameters for the process:
        String document_id = "3002001";
        String task_name = "Index";
        String insured_name = "Tushar";
        String acct_action_needed = "false";

        Map<String, Object> inputVariables = new HashMap<String, Object>();
        inputVariables.put("document_id", document_id);
        inputVariables.put("task_name", task_name);
        inputVariables.put("insured_name", insured_name);
        inputVariables.put("acct_action_needed", acct_action_needed);

        //Start the process using its ID and pass the input variables
        WorkflowProcessInstance processInstance = (WorkflowProcessInstance) session.startProcess("NS_UW_WorkFlow", inputVariables);

        System.out.println("processInstance.getNodeInstances().iterator().next().getNodeName() : " + processInstance.getNodeInstances().iterator().next().getNodeName() );
        System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"document_id\") : " + processInstance.getNodeInstances().iterator().next().getVariable("document_id") );
         //Assert.assertEquals("Coordinate Staff", processInstance.getNodeInstances().iterator().next().getNodeName());

        /*Assert.assertEquals(date, mockWorkItemHandler.getInputParameter("bedrequest_date"));
        Assert.assertEquals(entity, mockWorkItemHandler.getInputParameter("bedrequest_entity"));
        Assert.assertEquals(patientAge, mockWorkItemHandler.getInputParameter("bedrequest_patientage"));
        Assert.assertEquals(patientGender, mockWorkItemHandler.getInputParameter("bedrequest_patientgender"));
        Assert.assertEquals(patientStatus, mockWorkItemHandler.getInputParameter("bedrequest_patientstatus"));
        */
        //let's complete the task emulating the results of this task.
        Map<String,Object> taskResults = new HashMap<String, Object>();
        taskResults.put("out_insured_name", "Chandra");
        mockWorkItemHandler.completeWorkItem(taskResults);

        System.out.println("processInstance.getNodeInstances().iterator().next().getNodeName() : " + processInstance.getNodeInstances().iterator().next().getNodeName() );
        System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"document_id\") : " + processInstance.getNodeInstances().iterator().next().getVariable("document_id") );
        System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"insured_name\") : " + processInstance.getNodeInstances().iterator().next().getVariable("insured_name") );
        // Assert.assertEquals("3C", mockWorkItemHandler.getInputParameter("insured_name"));

        //let's complete the task with a mocked resource
        taskResults = new HashMap<String, Object>();
        taskResults.put("nsig_insured_name", "Soham");
        mockWorkItemHandler.completeWorkItem(taskResults);

        System.out.println("processInstance.getNodeInstances().iterator().next().getNodeName() : " + processInstance.getNodeInstances().iterator().next().getNodeName() );
        System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"document_id\") : " + processInstance.getNodeInstances().iterator().next().getVariable("document_id") );
        System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"insured_name\") : " + processInstance.getNodeInstances().iterator().next().getVariable("insured_name") );
        //Assert.assertEquals("Check In Patient", processInstance.getNodeInstances().iterator().next().getNodeName());

       // Assert.assertEquals("true", mockWorkItemHandler.getInputParameter("checkinresults_notified"));

        //let's complete the task passing the mocked results
        taskResults = new HashMap<String, Object>();
        taskResults.put("nsuw_insured_name", "Venkata");
        mockWorkItemHandler.completeWorkItem(taskResults);

        System.out.println("processInstance.getNodeInstances().iterator().next().getNodeName() : " + processInstance.getNodeInstances().iterator().next().getNodeName() );
        System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"document_id\") : " + processInstance.getNodeInstances().iterator().next().getVariable("document_id") );
        System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"insured_name\") : " + processInstance.getNodeInstances().iterator().next().getVariable("insured_name") );

        System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"acct_action_needed\") : " + processInstance.getNodeInstances().iterator().next().getVariable("acct_action_needed") );
        System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"acct_action_boolean\") : " + processInstance.getNodeInstances().iterator().next().getVariable("acct_action_boolean") );
        //The process should be completed now. Let's check the 2 output
        //parameters of the last task: they should be mapped to process variables.
        /*Assert.assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
        Assert.assertEquals("true", processInstance.getVariable("checkinresults_checkedin"));
        Assert.assertEquals(checkinDate, processInstance.getVariable("checkinresults_time"));*/

        taskResults = new HashMap<String, Object>();
        taskResults.put("nsau_insured_name", "Raju");
        mockWorkItemHandler.completeWorkItem(taskResults);
    }

but when I try to make this workflow group driven i.e. based on groupID task would be distributed among users, it just bombs.

Following is the approach which i used:

1) first i load the task service using the following code:

@Before
    public void setUp() throws Exception {
        // Compiles and persists all the .bpmn resources
        ds1 = new PoolingDataSource();
        ds1.setUniqueName("jdbc/testDS1");
        ds1.setClassName("org.h2.jdbcx.JdbcDataSource");
        ds1.setMaxPoolSize(3);
        ds1.setAllowLocalTransactions(true);
        ds1.getDriverProperties().put("user", "sa");
        ds1.getDriverProperties().put("password", "sasa");
        ds1.getDriverProperties().put("URL", "jdbc:h2:mem:mydb");
        ds1.init();


        emf = Persistence
                .createEntityManagerFactory("org.jbpm.persistence.jpa");

        env = KnowledgeBaseFactory.newEnvironment();
        env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
        env.set(EnvironmentName.TRANSACTION_MANAGER,
                TransactionManagerServices.getTransactionManager());
        System.setProperty("java.naming.factory.initial",
        "bitronix.tm.jndi.BitronixInitialContextFactory");

        emfTask = Persistence.createEntityManagerFactory("org.jbpm.task");
        taskService = new TaskService(emfTask,
                SystemEventListenerFactory.getSystemEventListener());
        taskSession = taskService.createSession();
        MockUserInfo userInfo = new MockUserInfo();

        taskService.setUserinfo(userInfo);

        this.fillUsersAndGroups(taskSession);

//      server = new MinaTaskServer(taskService);
        taskServer = new HornetQTaskServer(taskService, 5446);
        Thread thread = new Thread(taskServer);
        thread.start();
        System.out.println("Waiting for the HornetQTask Server to come up");
        while (!taskServer.isRunning()) {
            System.out.print(".");
            Thread.sleep(50);
        }

            TaskClient taskClient = new TaskClient(new HornetQTaskClientConnector("client 1",

                        new HornetQTaskClientHandler(SystemEventListenerFactory
                        .getSystemEventListener())));
        this.client = new TaskClientWrapper(taskClient);
        this.client.connect("127.0.0.1", 5446);
}

2)then ran the following test case:

@Test
public void taskAssignedToGroup() throws InterruptedException {
    UserTransaction ut = null;
    try{
    KnowledgeBase kbase = this.createKnowledgeBase();
    ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
    ut.begin();
    session = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null,
            env);
    new JPAWorkingMemoryDbLogger(session);
    KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
    CommandBasedHornetQWSHumanTaskHandler wsHumanTaskHandler = new CommandBasedHornetQWSHumanTaskHandler(
            session);
    wsHumanTaskHandler.setClient(client.getTaskClient());
    session.getWorkItemManager().registerWorkItemHandler("Human Task",
            wsHumanTaskHandler);

    String document_id = "3002001";
    String task_name = "Index";
    String insured_name = "Tushar";
    String acct_action_needed = "false";

    Map<String, Object> inputVariables = new HashMap<String, Object>();
    inputVariables.put("document_id", document_id);
    inputVariables.put("task_name", task_name);
    inputVariables.put("insured_name", insured_name);
    inputVariables.put("acct_action_needed", acct_action_needed);


    ProcessInstance process = session.createProcessInstance("NS_UW_WorkFlow",
            inputVariables);
    session.insert(process);
    long processInstanceId = process.getId();
    WorkflowProcessInstance processInstance = (WorkflowProcessInstance) session.startProcessInstance(processInstanceId);

    System.out.println("processInstance.getNodeInstances().iterator().next().getNodeName() : " + processInstance.getNodeInstances().iterator().next().getNodeName() );
    System.out.println("processInstance.getNodeInstances().iterator().next().getVariable(\"document_id\") : " + processInstance.getNodeInstances().iterator().next().getVariable("document_id") );
    Thread.sleep(2000);

    // For Tushar
    List<TaskSummary> tasks = client.getTasksAssignedAsPotentialOwner(
            "tushar", "en-UK", this.getTestUserGroupsAssignments().get("tushar"));

    Assert.assertEquals(0, tasks.size());

    // Pass the user and the group it belongs
    client.claim(tasks.get(0).getId(), "tushar", this.getTestUserGroupsAssignments().get("tushar"));

    // The task owned method will give the tasks for a user which have been already claimed by him.
    tasks = client.getTasksOwned("tushar", "en-UK");
    Assert.assertEquals(1, tasks.size());

    client.start(tasks.get(0).getId(), "tushar");
    Map<String,Object> taskResults = new HashMap<String, Object>();
    taskResults.put("insured_name", "Chandra");
    client.complete(tasks.get(0).getId(), "tushar", taskResults);

    tasks = client.getTasksOwned("tushar", "en-UK");
    Assert.assertEquals(1, tasks.size());
    ut.commit();

    }catch(Exception e){
        try {
            ut.rollback();
        } catch (IllegalStateException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (SecurityException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (SystemException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        System.out.println("error : " + e.getLocalizedMessage());
    }



}

Everything works fine till the code reaches the following line: long processInstanceId = process.getId();

When i try to start the process by firing the following command: WorkflowProcessInstance processInstance = (WorkflowProcessInstance) session.startProcessInstance(processInstanceId);

the code gives me the following error:

>..java.lang.RuntimeException: Could not commit transaction
>   at org.jbpm.task.service.TaskServiceSession.doOperationInTransaction>>>>(TaskServiceSession.java:1130)
>   at org.jbpm.task.service.TaskServiceSession.addTask(TaskServiceSession.java:189)
>   at org.jbpm.task.service.TaskServerHandler.messageReceived(TaskServerHandler.java:151)
>   at org.jbpm.task.service.hornetq.HornetQTaskServerHandler.messageReceived>(HornetQTaskServerHandler.java:43)
>   at org.jbpm.task.service.hornetq.BaseHornetQTaskServer.run(BaseHornetQTaskServer.java:104)
>   at java.lang.Thread.run(Thread.java:662)
>Caused by: java.lang.RuntimeException: Unable to rollback transaction
>   at org.jbpm.task.service.persistence.TaskLocalTransactionManager.rollback>(TaskLocalTransactionManager.java:77)
>   at org.jbpm.task.service.persistence.TaskPersistenceManager.endTransaction>(TaskPersistenceManager.java:110)
>   at org.jbpm.task.service.TaskServiceSession.doOperationInTransaction(TaskServiceSession.java:1118)
>   ... 5 more
>Caused by: java.lang.IllegalStateException: Transaction not active
>   at org.hibernate.ejb.TransactionImpl.rollback(TransactionImpl.java:82)
>   at org.jbpm.task.service.persistence.TaskLocalTransactionManager.rollback>(TaskLocalTransactionManager.java:70)
>   ... 7 more
>

and after that when i try to lookup for tasks assigned to user "tushar" by firing the following command:

List<TaskSummary> tasks = client.getTasksAssignedAsPotentialOwner(
                "tushar", "en-UK", this.getTestUserGroupsAssignments().get("tushar"));

I get 0 task listed.

The task service is induces with the username and group by the help of following function:

private void fillUsersAndGroups(TaskServiceSession taskSession) {
        User tushar = new User("tushar");
        User venkata = new User("venkata");
        User raju = new User("raju");
        User ramya = new User("ramya");
        taskSession.addUser(tushar);
        taskSession.addUser(venkata);
        taskSession.addUser(raju);
        taskSession.addUser(ramya);
        users.put("tushar", tushar);
        users.put("venkata", venkata);
        users.put("raju", raju);
        users.put("ramya", ramya);
        Group index = new Group("INDEX");
        Group auSme = new Group("TASK 1");
        Group uwSme = new Group("TASK 2");
        Group accSme = new Group("TASK 3");
        taskSession.addGroup(index);
        taskSession.addGroup(auSme);
        taskSession.addGroup(uwSme);
        taskSession.addGroup(accSme);
        groups.put("INDEX", index);
        groups.put("TASK 1", auSme);
        groups.put("TASK 2", uwSme);
        groups.put("TASK 3", accSme);
    }

and then i assign my self (TUSHAR) in 'INDEX' group by the help of following function:

protected Map<String, List<String>> getTestUserGroupsAssignments() {
        Map<String, List<String>> assign = new HashMap<String, List<String>>();
        List<String> tusharGroups = new ArrayList<String>();
        List<String> venkataGroups = new ArrayList<String>();
        List<String> rajuGroups = new ArrayList<String>();
        List<String> ramyaGroups = new ArrayList<String>();
        tusharGroups.add("INDEX");
        venkataGroups.add("TASK 1");
        rajuGroups.add("TASK 2");
        ramyaGroups.add("TASK 3");
        assign.put("tushar", tusharGroups);
        assign.put("venkata", venkataGroups);
        assign.put("raju", rajuGroups);
        assign.put("ramya", ramyaGroups);
        return assign;
    }

still I gon't get any task assigned .

as far as workflow is concerned, after start, i have an index task whose group id is set as 'INDEX'.

If additional information is needed, do let me know.

I just want to acquire a task and complete it so that it moves to the next node in the workflow.

guys need help seriously :(

Here's my persistance.xml (If that helps):

http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" xmlns:orm="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/persistence">

<!-- <persistence-unit name="transactions-optional">
    <provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
    <properties>
        <property name="datanucleus.NontransactionalRead" value="true"/>
        <property name="datanucleus.NontransactionalWrite" value="true"/>
        <property name="datanucleus.ConnectionURL" value="appengine"/>
    </properties>
</persistence-unit> -->

<persistence-unit name="org.jbpm.persistence.jpa" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <!-- <jta-data-source>jdbc/testDS1</jta-data-source> -->
    <mapping-file>META-INF/JBPMorm.xml</mapping-file>
    <mapping-file>META-INF/ProcessInstanceInfo.hbm.xml</mapping-file>
    <mapping-file>META-INF/ExtraIndexes.hbm.xml</mapping-file>
    <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
    <class>org.jbpm.persistence.processinstance.ProcessInstanceEventInfo</class>    
    <class>org.drools.persistence.info.SessionInfo</class>
    <class>org.drools.persistence.info.WorkItemInfo</class>
    <class>org.jbpm.process.audit.ProcessInstanceLog</class>
    <class>org.jbpm.process.audit.NodeInstanceLog</class>
    <class>org.jbpm.process.audit.VariableInstanceLog</class>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
        <property name="hibernate.connection.driver_class" value="org.h2.Driver" />
        <property name="hibernate.connection.url" value="jdbc:h2:mem:mydb" />
        <property name="hibernate.connection.username" value="root" />
        <property name="hibernate.connection.password" value="root" />
        <property name="hibernate.connection.autocommit" value="false" />
        <property name="hibernate.max_fetch_depth" value="3" />
        <property name="hibernate.hbm2ddl.auto" value="create" />
        <property name="hibernate.show_sql" value="false" />
        <property name="hibernate.transaction.manager_lookup_class"
            value="org.hibernate.transaction.BTMTransactionManagerLookup" />
    </properties>
</persistence-unit>


<persistence-unit name="org.jbpm.task">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <mapping-file>META-INF/Taskorm.xml</mapping-file>
    <!-- <mapping-file>META-INF/TaskEventsorm.xml</mapping-file> -->
    <class>org.jbpm.task.Attachment</class>
    <class>org.jbpm.task.Content</class>
    <class>org.jbpm.task.BooleanExpression</class>
    <class>org.jbpm.task.Comment</class>
    <class>org.jbpm.task.Deadline</class>
    <class>org.jbpm.task.Comment</class>
    <class>org.jbpm.task.Deadline</class>
    <class>org.jbpm.task.Delegation</class>
    <class>org.jbpm.task.Escalation</class>
    <class>org.jbpm.task.Group</class>
    <class>org.jbpm.task.I18NText</class>
    <class>org.jbpm.task.Notification</class>
    <class>org.jbpm.task.EmailNotification</class>
    <class>org.jbpm.task.EmailNotificationHeader</class>
    <class>org.jbpm.task.PeopleAssignments</class>
    <class>org.jbpm.task.Reassignment</class>
    <class>org.jbpm.task.Status</class>
    <class>org.jbpm.task.Task</class>
    <class>org.jbpm.task.TaskData</class>
    <class>org.jbpm.task.SubTasksStrategy</class>
    <class>org.jbpm.task.OnParentAbortAllSubTasksEndStrategy</class>
    <class>org.jbpm.task.OnAllSubTasksEndParentEndStrategy</class>
    <class>org.jbpm.task.User</class>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
        <property name="hibernate.connection.driver_class" value="org.h2.Driver" />
        <property name="hibernate.connection.url" value="jdbc:h2:mem:humanTasks" />
        <property name="hibernate.connection.username" value="sa" />
        <property name="hibernate.connection.password" value="sasa" />
        <property name="hibernate.connection.autocommit" value="false" />
        <property name="hibernate.max_fetch_depth" value="3" />
        <property name="hibernate.hbm2ddl.auto" value="create-drop" />
        <property name="hibernate.show_sql" value="false" />
    </properties>
</persistence-unit>

Was it helpful?

Solution

just added the following piece of code and it works:

Properties userGroups = new Properties(); 
 userGroups.setProperty("john", "user"); 
 UserGroupCallbackManager manager = UserGroupCallbackManager.getInstance(); 
 manager.setCallback(new DefaultUserGroupCallbackImpl(userGroups)); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top