Search in sources :

Example 1 with HumanTaskWorkItemData

use of org.kie.kogito.serialization.process.protobuf.KogitoWorkItemsProtobuf.HumanTaskWorkItemData 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)

Aggregations

Any (com.google.protobuf.Any)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Date (java.util.Date)1 HumanTaskWorkItemImpl (org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl)1 HumanTaskNodeInstance (org.jbpm.workflow.instance.node.HumanTaskNodeInstance)1 WorkItemNodeInstance (org.jbpm.workflow.instance.node.WorkItemNodeInstance)1 Attachment (org.kie.kogito.process.workitem.Attachment)1 Comment (org.kie.kogito.process.workitem.Comment)1 KogitoWorkItemImpl (org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl)1 ProcessInstanceMarshallerException (org.kie.kogito.serialization.process.ProcessInstanceMarshallerException)1 HumanTaskWorkItemData (org.kie.kogito.serialization.process.protobuf.KogitoWorkItemsProtobuf.HumanTaskWorkItemData)1