JBoss Community

Re: JBPM 5.4.0-Final: Human Task variable mapping is not working

created by vchmakov in jBPM - View the full discussion

Hi Maciej,

That is exactly what is going on. However, as far as I understand and according to the examples coming with the JBPM deployment:

1)      The instance of the LocalHTWorkItemHandler is attached to the session and is purposed for the HT engine’s event handling. As far as I can see it does not possess the persistence context but rather shares it with the Drools’s one when rule’s RHS starts the process and the process reaches the wait/persisted state.

    private void registerHumanTaskHandler(StatefulKnowledgeSession session) {

        if (taskServer != null) {

            logger.info("Registering Human Task Handler...");

            LocalHTWorkItemHandler humanTaskHandler = new LocalHTWorkItemHandler(createTaskService(), session);

            humanTaskHandler.setLocal(true);

            humanTaskHandler.connect();

            session.getWorkItemManager().registerWorkItemHandler("Human Task", humanTaskHandler);

            logger.info("OK.");

        }

    }

2)      When user completes a task from the Web form the event is delivered to the engine. In my case it is a Message Queue event which I process in MDB. Then I create a fresh instance of the LocalTaskService and complete the task. According to the examples provided with the JBPM installation and the source code of the LocalTaskService it is a recommended way to avoid reusing of the Entity Manager.

    private void registerHumanTaskHandler(StatefulKnowledgeSession session) {

        if (taskServer != null) {

            logger.info("Registering Human Task Handler...");

            LocalHTWorkItemHandler humanTaskHandler = new LocalHTWorkItemHandler(createTaskService(), session);

            humanTaskHandler.setLocal(true);

            humanTaskHandler.connect();

            session.getWorkItemManager().registerWorkItemHandler("Human Task", humanTaskHandler);

            logger.info("OK.");

        }

    }

    private void createTaskServer() throws Exception {

        logger.info("Creating Task Server...");

        if (persistenceManager != null) {

            taskServer = new TaskService(persistenceManager.getTaskEntityManagerFactory(),

                    SystemEventListenerFactory.getSystemEventListener());

        }

        else {

            throw new IllegalArgumentException("createTaskServer() - Persistence Manager must be created for this operation");

        }

        logger.info("OK.");

    }

    private org.jbpm.task.TaskService createTaskService() {

        logger.debug("Creating Task Service...");

        if (taskServer != null) {

            return new LocalTaskService(taskServer);

        }

        else {

            throw new IllegalArgumentException("Task Server is not yet created");

        }

    }

    private void processCompleteTaskCommand(BvCompleteTaskCommand command) throws Exception {

        logger.trace("Processing TaskCompleteCommand()...");

        final String userId = command.getUserId();

        final String wf_userId = WORKFLOW_USERID;

        logger_processes.debug("Completing task id={}, userId={}", command.getTaskId(), userId);

        org.jbpm.task.TaskService taskService = createTaskService();

        taskService.start(command.getTaskId(), wf_userId);

        Object data = command.getData();

        if (data != null) {

            taskService.completeWithResults(command.getTaskId(), wf_userId, data);

        }

        else {

            logger_processes.debug("**** data is NULL");

            taskService.complete(command.getTaskId(), wf_userId, null);

       }

        logger_processes.debug("  - task id={}, userId={} completed.", command.getTaskId(), userId);

        logger.trace("Processing TaskCompleteCommand(). OK.");

    }

It seems to me that I’m misunderstanding something…

Thanks,

Vladimir

 



Reply to this message by going to Community

Start a new discussion in jBPM at Community