Search in sources :

Example 1 with KogitoWorkItemImpl

use of org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl 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 2 with KogitoWorkItemImpl

use of org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl 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 3 with KogitoWorkItemImpl

use of org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl in project kogito-runtimes by kiegroup.

the class StartEventTest method testMultipleEventBasedStartEventsSignalDifferentPaths.

@Test
public void testMultipleEventBasedStartEventsSignalDifferentPaths() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-MultipleStartEventProcessDifferentPaths.bpmn2");
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    final List<String> list = new ArrayList<>();
    kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() {

        public void afterProcessStarted(ProcessStartedEvent event) {
            list.add(((KogitoProcessInstance) event.getProcessInstance()).getStringId());
        }
    });
    kruntime.signalEvent("startSignal", null);
    assertThat(list.size()).isEqualTo(1);
    KogitoWorkItem workItem = workItemHandler.getWorkItem();
    String processInstanceId = ((KogitoWorkItemImpl) workItem).getProcessInstanceStringId();
    KogitoProcessInstance processInstance = kruntime.getProcessInstance(processInstanceId);
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    assertProcessInstanceFinished(processInstance, kruntime);
    assertNodeTriggered(processInstanceId, "StartSignal", "Script 3", "User task", "End");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl) Test(org.junit.jupiter.api.Test)

Example 4 with KogitoWorkItemImpl

use of org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl in project kogito-runtimes by kiegroup.

the class StartEventTest method testMultipleEventBasedStartEventsTimerDifferentPaths.

@Test
@Timeout(10)
public void testMultipleEventBasedStartEventsTimerDifferentPaths() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartTimer", 2);
    kruntime = createKogitoProcessRuntime("BPMN2-MultipleStartEventProcessDifferentPaths.bpmn2");
    kruntime.getProcessEventManager().addEventListener(countDownListener);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    final List<String> list = new ArrayList<>();
    kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() {

        public void beforeProcessStarted(ProcessStartedEvent event) {
            list.add(((KogitoProcessInstance) event.getProcessInstance()).getStringId());
        }
    });
    assertThat(list.size()).isEqualTo(0);
    // Timer in the process takes 1000ms, so after 2 seconds, there should be 2 process IDs in the list.
    countDownListener.waitTillCompleted();
    assertThat(list.size()).isEqualTo(2);
    List<KogitoWorkItem> workItems = workItemHandler.getWorkItems();
    for (KogitoWorkItem workItem : workItems) {
        String processInstanceId = ((KogitoWorkItemImpl) workItem).getProcessInstanceStringId();
        KogitoProcessInstance processInstance = kruntime.getProcessInstance(processInstanceId);
        assertThat(workItem).isNotNull();
        assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
        kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
        assertProcessInstanceFinished(processInstance, kruntime);
        assertNodeTriggered(processInstanceId, "StartTimer", "Script 2", "User task", "End");
    }
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) NodeLeftCountDownProcessEventListener(org.jbpm.test.util.NodeLeftCountDownProcessEventListener) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 5 with KogitoWorkItemImpl

use of org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl in project kogito-runtimes by kiegroup.

the class LightWorkItemManager method abortWorkItem.

@Override
public void abortWorkItem(String id, Policy<?>... policies) {
    KogitoWorkItemImpl workItem = (KogitoWorkItemImpl) workItems.get(id);
    // work item may have been aborted
    if (workItem != null) {
        if (!workItem.enforce(policies)) {
            throw new NotAuthorizedException("Work item can be aborted as it does not fulfil policies (e.g. security)");
        }
        KogitoProcessInstance processInstance = processInstanceManager.getProcessInstance(workItem.getProcessInstanceStringId());
        Transition<?> transition = new TransitionToAbort(Arrays.asList(policies));
        eventSupport.fireBeforeWorkItemTransition(processInstance, workItem, transition, null);
        workItem.setState(ABORTED);
        abortPhase.apply(workItem, transition);
        // process instance may have finished already
        if (processInstance != null) {
            processInstance.signalEvent("workItemAborted", workItem);
        }
        workItem.setPhaseId(ID);
        workItem.setPhaseStatus(STATUS);
        eventSupport.fireAfterWorkItemTransition(processInstance, workItem, transition, null);
        workItems.remove(id);
    }
}
Also used : KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl) NotAuthorizedException(org.kie.kogito.process.workitem.NotAuthorizedException)

Aggregations

KogitoWorkItemImpl (org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl)13 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)7 Test (org.junit.jupiter.api.Test)4 ArrayList (java.util.ArrayList)3 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)3 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)3 DefaultKogitoProcessEventListener (org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener)3 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)3 Any (com.google.protobuf.Any)2 Date (java.util.Date)2 HumanTaskWorkItemImpl (org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl)2 HumanTaskNodeInstance (org.jbpm.workflow.instance.node.HumanTaskNodeInstance)2 WorkItemNodeInstance (org.jbpm.workflow.instance.node.WorkItemNodeInstance)2 KogitoWorkItemHandler (org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler)2 InternalKogitoWorkItemManager (org.kie.kogito.process.workitems.InternalKogitoWorkItemManager)2 KogitoWorkItemHandlerNotFoundException (org.kie.kogito.process.workitems.KogitoWorkItemHandlerNotFoundException)2 ProcessInstanceMarshallerException (org.kie.kogito.serialization.process.ProcessInstanceMarshallerException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 HttpMethod (io.vertx.core.http.HttpMethod)1