Search in sources :

Example 1 with HumanTaskWorkItemImpl

use of org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl in project kogito-runtimes by kiegroup.

the class HumanTaskNodeInstance method createWorkItem.

@Override
protected InternalKogitoWorkItem createWorkItem(WorkItemNode workItemNode) {
    HumanTaskWorkItemImpl workItem = (HumanTaskWorkItemImpl) super.createWorkItem(workItemNode);
    String actorId = assignWorkItem(workItem);
    if (actorId != null) {
        workItem.setParameter(ACTOR_ID, actorId);
    }
    workItem.setTaskName((String) workItem.getParameter(TASK_NAME));
    workItem.setTaskDescription((String) workItem.getParameter(DESCRIPTION));
    workItem.setTaskPriority((String) workItem.getParameter(PRIORITY));
    workItem.setReferenceName((String) workItem.getParameter(NODE_NAME));
    Work work = workItemNode.getWork();
    scheduleDeadlines(work.getNotStartedDeadlines(), notStartedDeadlines);
    scheduleDeadlines(work.getNotCompletedDeadlines(), notCompletedDeadlines);
    scheduleDeadlines(work.getNotStartedReassignments(), notStartedReassignments);
    scheduleDeadlines(work.getNotCompletedReassigments(), notCompletedReassignments);
    return workItem;
}
Also used : Work(org.jbpm.process.core.Work) HumanTaskWorkItemImpl(org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl)

Example 2 with HumanTaskWorkItemImpl

use of org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl in project kogito-runtimes by kiegroup.

the class ProtobufProcessInstanceReader method buildWorkItemNodeInstance.

private NodeInstanceImpl buildWorkItemNodeInstance(WorkItemNodeInstanceContent content) {
    try {
        WorkItemNodeInstance nodeInstance = instanceWorkItem(content);
        if (nodeInstance instanceof HumanTaskNodeInstance) {
            HumanTaskNodeInstance humanTaskNodeInstance = (HumanTaskNodeInstance) nodeInstance;
            HumanTaskWorkItemImpl workItem = (HumanTaskWorkItemImpl) nodeInstance.getWorkItem();
            Any workItemDataMessage = content.getWorkItemData();
            if (workItemDataMessage.is(HumanTaskWorkItemData.class)) {
                HumanTaskWorkItemData workItemData = workItemDataMessage.unpack(HumanTaskWorkItemData.class);
                humanTaskNodeInstance.getNotCompletedDeadlineTimers().putAll(buildDeadlines(workItemData.getCompletedDeadlinesMap()));
                humanTaskNodeInstance.getNotCompletedReassigments().putAll(buildReassignments(workItemData.getCompletedReassigmentsMap()));
                humanTaskNodeInstance.getNotStartedDeadlineTimers().putAll(buildDeadlines(workItemData.getStartDeadlinesMap()));
                humanTaskNodeInstance.getNotStartedReassignments().putAll(buildReassignments(workItemData.getStartReassigmentsMap()));
                if (workItemData.hasTaskName()) {
                    workItem.setTaskName(workItemData.getTaskName());
                }
                if (workItemData.hasTaskDescription()) {
                    workItem.setTaskDescription(workItemData.getTaskDescription());
                }
                if (workItemData.hasTaskPriority()) {
                    workItem.setTaskPriority(workItemData.getTaskPriority());
                }
                if (workItemData.hasTaskReferenceName()) {
                    workItem.setReferenceName(workItemData.getTaskReferenceName());
                }
                if (workItemData.hasActualOwner()) {
                    workItem.setActualOwner(workItemData.getActualOwner());
                }
                workItem.getAdminUsers().addAll(workItemData.getAdminUsersList());
                workItem.getAdminGroups().addAll(workItemData.getAdminGroupsList());
                workItem.getPotentialUsers().addAll(workItemData.getPotUsersList());
                workItem.getPotentialGroups().addAll(workItemData.getPotGroupsList());
                workItem.getExcludedUsers().addAll(workItemData.getExcludedUsersList());
                workItem.getComments().putAll(workItemData.getCommentsList().stream().map(this::buildComment).collect(Collectors.toMap(Comment::getId, Function.identity())));
                workItem.getAttachments().putAll(workItemData.getAttachmentsList().stream().map(this::buildAttachment).collect(Collectors.toMap(Attachment::getId, Function.identity())));
            }
        }
        nodeInstance.internalSetWorkItemId(content.getWorkItemId());
        KogitoWorkItemImpl workItem = (KogitoWorkItemImpl) nodeInstance.getWorkItem();
        workItem.setId(content.getWorkItemId());
        workItem.setProcessInstanceId(ruleFlowProcessInstance.getStringId());
        workItem.setName(content.getName());
        workItem.setState(content.getState());
        workItem.setDeploymentId(ruleFlowProcessInstance.getDeploymentId());
        workItem.setProcessInstance(ruleFlowProcessInstance);
        workItem.setPhaseId(content.getPhaseId());
        workItem.setPhaseStatus(content.getPhaseStatus());
        workItem.setStartDate(new Date(content.getStartDate()));
        if (content.getCompleteDate() > 0) {
            workItem.setCompleteDate(new Date(content.getCompleteDate()));
        }
        if (content.getTimerInstanceIdCount() > 0) {
            nodeInstance.internalSetTimerInstances(new ArrayList<>(content.getTimerInstanceIdList()));
        }
        nodeInstance.internalSetProcessInstanceId(content.getErrorHandlingProcessInstanceId());
        varReader.buildVariables(content.getVariableList()).forEach(var -> nodeInstance.getWorkItem().getParameters().put(var.getName(), var.getValue()));
        varReader.buildVariables(content.getResultList()).forEach(var -> nodeInstance.getWorkItem().getResults().put(var.getName(), var.getValue()));
        return nodeInstance;
    } catch (InvalidProtocolBufferException ex) {
        throw new ProcessInstanceMarshallerException("cannot unpack node instance", ex);
    }
}
Also used : Comment(org.kie.kogito.process.workitem.Comment) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ProcessInstanceMarshallerException(org.kie.kogito.serialization.process.ProcessInstanceMarshallerException) Attachment(org.kie.kogito.process.workitem.Attachment) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) HumanTaskWorkItemImpl(org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl) HumanTaskWorkItemData(org.kie.kogito.serialization.process.protobuf.KogitoWorkItemsProtobuf.HumanTaskWorkItemData) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl) Any(com.google.protobuf.Any) Date(java.util.Date)

Example 3 with HumanTaskWorkItemImpl

use of org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl in project kogito-runtimes by kiegroup.

the class ProtobufProcessInstanceReader method instanceWorkItem.

private WorkItemNodeInstance instanceWorkItem(WorkItemNodeInstanceContent content) {
    if (content.hasWorkItemData()) {
        Any workItemDataMessage = content.getWorkItemData();
        if (workItemDataMessage.is(HumanTaskWorkItemData.class)) {
            HumanTaskNodeInstance nodeInstance = new HumanTaskNodeInstance();
            HumanTaskWorkItemImpl workItem = new HumanTaskWorkItemImpl();
            nodeInstance.internalSetWorkItem(workItem);
            return nodeInstance;
        } else {
            throw new ProcessInstanceMarshallerException("Don't know which type of work item is");
        }
    } else {
        WorkItemNodeInstance nodeInstance = new WorkItemNodeInstance();
        KogitoWorkItemImpl workItem = new KogitoWorkItemImpl();
        nodeInstance.internalSetWorkItem(workItem);
        return nodeInstance;
    }
}
Also used : HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) ProcessInstanceMarshallerException(org.kie.kogito.serialization.process.ProcessInstanceMarshallerException) HumanTaskWorkItemImpl(org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl) Any(com.google.protobuf.Any)

Example 4 with HumanTaskWorkItemImpl

use of org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl in project kogito-runtimes by kiegroup.

the class ProcessHumanTaskTest method testSwimlane.

@Test
public void testSwimlane() {
    Reader source = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + "         type=\"RuleFlow\" name=\"flow\" id=\"org.drools.humantask\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + "  <header>\n" + "    <swimlanes>\n" + "      <swimlane name=\"actor1\" />\n" + "    </swimlanes>\n" + "  </header>\n" + "\n" + "  <nodes>\n" + "    <start id=\"1\" name=\"Start\" />\n" + "    <humanTask id=\"2\" name=\"HumanTask\" swimlane=\"actor1\" >\n" + "      <work name=\"Human Task\" >\n" + "        <parameter name=\"ActorId\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "          <value>John Doe</value>\n" + "        </parameter>\n" + "        <parameter name=\"TaskName\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "          <value>Do something</value>\n" + "        </parameter>\n" + "        <parameter name=\"Priority\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "        </parameter>\n" + "        <parameter name=\"Comment\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "        </parameter>\n" + "      </work>\n" + "      <mapping type=\"out\" from=\"ActorId\" to=\"ActorId\" />" + "    </humanTask>\n" + "    <humanTask id=\"3\" name=\"HumanTask\" swimlane=\"actor1\" >\n" + "      <work name=\"Human Task\" >\n" + "        <parameter name=\"ActorId\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "        </parameter>\n" + "        <parameter name=\"TaskName\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "          <value>Do something else</value>\n" + "        </parameter>\n" + "        <parameter name=\"Priority\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "        </parameter>\n" + "        <parameter name=\"Comment\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "        </parameter>\n" + "      </work>\n" + "      <mapping type=\"out\" from=\"ActorId\" to=\"ActorId\" />" + "    </humanTask>\n" + "    <end id=\"4\" name=\"End\" />\n" + "  </nodes>\n" + "\n" + "  <connections>\n" + "    <connection from=\"1\" to=\"2\" />\n" + "    <connection from=\"2\" to=\"3\" />\n" + "    <connection from=\"3\" to=\"4\" />\n" + "  </connections>\n" + "\n" + "</process>");
    builder.add(new ReaderResource(source), ResourceType.DRF);
    KogitoProcessRuntime kruntime = createKogitoProcessRuntime();
    TestWorkItemHandler handler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler);
    KogitoProcessInstance processInstance = kruntime.startProcess("org.drools.humantask");
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    KogitoWorkItem workItem = handler.getWorkItem();
    assertNotNull(workItem);
    assertEquals("Do something", workItem.getParameter("TaskName"));
    assertEquals("John Doe", workItem.getParameter("ActorId"));
    Map<String, Object> results = new HashMap<String, Object>();
    ((HumanTaskWorkItemImpl) workItem).setActualOwner("Jane Doe");
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), results);
    workItem = handler.getWorkItem();
    assertNotNull(workItem);
    assertEquals("Do something else", workItem.getParameter("TaskName"));
    assertEquals("Jane Doe", workItem.getParameter("SwimlaneActorId"));
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    assertEquals(KogitoProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : TestWorkItemHandler(org.jbpm.integrationtests.handler.TestWorkItemHandler) HashMap(java.util.HashMap) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) StringReader(java.io.StringReader) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) Reader(java.io.Reader) StringReader(java.io.StringReader) ReaderResource(org.drools.core.io.impl.ReaderResource) HumanTaskWorkItemImpl(org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl) Test(org.junit.jupiter.api.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 5 with HumanTaskWorkItemImpl

use of org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl in project kogito-runtimes by kiegroup.

the class PredictionAwareHumanTaskLifeCycle method transitionTo.

@Override
public Map<String, Object> transitionTo(KogitoWorkItem workItem, KogitoWorkItemManager manager, Transition<Map<String, Object>> transition) {
    LifeCyclePhase targetPhase = phaseById(transition.phase());
    if (targetPhase == null) {
        logger.debug("Target life cycle phase '{}' does not exist in {}", transition.phase(), this.getClass().getSimpleName());
        throw new InvalidLifeCyclePhaseException(transition.phase());
    }
    HumanTaskWorkItemImpl humanTaskWorkItem = (HumanTaskWorkItemImpl) workItem;
    if (targetPhase.id().equals(Active.ID)) {
        PredictionOutcome outcome = predictionService.predict(workItem, workItem.getParameters());
        logger.debug("Prediction service returned confidence level {} for work item {}", outcome.getConfidenceLevel(), humanTaskWorkItem.getStringId());
        if (outcome.isCertain()) {
            humanTaskWorkItem.getResults().putAll(outcome.getData());
            logger.debug("Prediction service is certain (confidence level {}) on the outputs, completing work item {}", outcome.getConfidenceLevel(), humanTaskWorkItem.getStringId());
            ((InternalKogitoWorkItemManager) manager).internalCompleteWorkItem(humanTaskWorkItem);
            return outcome.getData();
        } else if (outcome.isPresent()) {
            logger.debug("Prediction service is NOT certain (confidence level {}) on the outputs, setting recommended outputs on work item {}", outcome.getConfidenceLevel(), humanTaskWorkItem.getStringId());
            humanTaskWorkItem.getResults().putAll(outcome.getData());
        }
    }
    // prediction service does work only on activating tasks
    Map<String, Object> data = super.transitionTo(workItem, manager, transition);
    if (targetPhase.id().equals(Complete.ID)) {
        // upon actual transition train the data if it's completion phase
        predictionService.train(humanTaskWorkItem, workItem.getParameters(), data);
    }
    return data;
}
Also used : InvalidLifeCyclePhaseException(org.kie.kogito.process.workitem.InvalidLifeCyclePhaseException) InternalKogitoWorkItemManager(org.kie.kogito.process.workitems.InternalKogitoWorkItemManager) HumanTaskWorkItemImpl(org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl) LifeCyclePhase(org.kie.kogito.process.workitem.LifeCyclePhase)

Aggregations

HumanTaskWorkItemImpl (org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl)10 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)4 HashMap (java.util.HashMap)3 Test (org.junit.jupiter.api.Test)3 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)3 Any (com.google.protobuf.Any)2 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)2 HumanTaskNodeInstance (org.jbpm.workflow.instance.node.HumanTaskNodeInstance)2 WorkItemNodeInstance (org.jbpm.workflow.instance.node.WorkItemNodeInstance)2 HumanTaskWorkItem (org.kie.kogito.process.workitem.HumanTaskWorkItem)2 KogitoWorkItemImpl (org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl)2 ProcessInstanceMarshallerException (org.kie.kogito.serialization.process.ProcessInstanceMarshallerException)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Date (java.util.Date)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 BiConsumer (java.util.function.BiConsumer)1 Consumer (java.util.function.Consumer)1