Search in sources :

Example 1 with WorkflowContext

use of org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf.WorkflowContext in project kogito-runtimes by kiegroup.

the class ProtobufProcessInstanceReader method buildWorkflowContext.

private void buildWorkflowContext(CompositeContextNodeInstance container, WorkflowContext workflowContext) {
    if (workflowContext.getNodeInstanceCount() > 0) {
        for (KogitoTypesProtobuf.NodeInstance nodeInstanceProtobuf : workflowContext.getNodeInstanceList()) {
            buildNodeInstance(nodeInstanceProtobuf, container);
        }
    }
    for (KogitoTypesProtobuf.NodeInstanceGroup group : workflowContext.getExclusiveGroupList()) {
        Function<String, KogitoNodeInstance> finder = nodeInstanceId -> container.getNodeInstance(nodeInstanceId, true);
        container.addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, buildExclusiveGroupInstance(group, finder));
    }
    container.addContextInstance(VariableScope.VARIABLE_SCOPE, new VariableScopeInstance());
    if (workflowContext.getVariableCount() > 0) {
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) container.getContextInstance(VariableScope.VARIABLE_SCOPE);
        varReader.buildVariables(workflowContext.getVariableList()).forEach(v -> variableScopeInstance.internalSetVariable(v.getName(), v.getValue()));
    }
    if (workflowContext.getIterationLevelsCount() > 0) {
        container.getIterationLevels().putAll(buildIterationLevels(workflowContext.getIterationLevelsList()));
    }
}
Also used : Comment(org.kie.kogito.process.workitem.Comment) ProtobufTypeRegistryFactory.protobufTypeRegistryFactoryInstance(org.kie.kogito.serialization.process.protobuf.ProtobufTypeRegistryFactory.protobufTypeRegistryFactoryInstance) Date(java.util.Date) RuleSetNodeInstance(org.jbpm.workflow.instance.node.RuleSetNodeInstance) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ExclusiveGroupInstance(org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) MarshallerContextName(org.kie.kogito.serialization.process.MarshallerContextName) HumanTaskWorkItemData(org.kie.kogito.serialization.process.protobuf.KogitoWorkItemsProtobuf.HumanTaskWorkItemData) KogitoNodeInstanceContainer(org.kie.kogito.internal.process.runtime.KogitoNodeInstanceContainer) StateNodeInstance(org.jbpm.workflow.instance.node.StateNodeInstance) TimerNodeInstance(org.jbpm.workflow.instance.node.TimerNodeInstance) MarshallerReaderContext(org.kie.kogito.serialization.process.MarshallerReaderContext) Map(java.util.Map) CompositeContextNodeInstance(org.jbpm.workflow.instance.node.CompositeContextNodeInstance) DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) MilestoneNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.MilestoneNodeInstanceContent) ProcessInstanceMarshallerException(org.kie.kogito.serialization.process.ProcessInstanceMarshallerException) URI(java.net.URI) EventNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.EventNodeInstanceContent) WorkflowContext(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf.WorkflowContext) Attachment(org.kie.kogito.process.workitem.Attachment) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ForEachNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.ForEachNodeInstanceContent) DynamicNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.DynamicNodeInstanceContent) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) KogitoTypesProtobuf(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf) VariableScope(org.jbpm.process.core.context.variable.VariableScope) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) List(java.util.List) EventSubProcessNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.EventSubProcessNodeInstanceContent) JsonFormat(com.google.protobuf.util.JsonFormat) ExclusiveGroup(org.jbpm.process.core.context.exclusive.ExclusiveGroup) Any(com.google.protobuf.Any) NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) StateNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.StateNodeInstanceContent) SwimlaneContext(org.jbpm.process.core.context.swimlane.SwimlaneContext) AbstractProcess(org.kie.kogito.process.impl.AbstractProcess) CompositeContextNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.CompositeContextNodeInstanceContent) KogitoWorkItemsProtobuf(org.kie.kogito.serialization.process.protobuf.KogitoWorkItemsProtobuf) HashMap(java.util.HashMap) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) JoinNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.JoinNodeInstanceContent) Function(java.util.function.Function) ArrayList(java.util.ArrayList) AsyncEventNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.AsyncEventNodeInstanceContent) WorkItemNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.WorkItemNodeInstanceContent) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance) LambdaSubProcessNodeInstance(org.jbpm.workflow.instance.node.LambdaSubProcessNodeInstance) LambdaSubProcessNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.LambdaSubProcessNodeInstanceContent) KogitoProcessInstanceProtobuf(org.kie.kogito.serialization.process.protobuf.KogitoProcessInstanceProtobuf) SubProcessNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.SubProcessNodeInstanceContent) TimerNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.TimerNodeInstanceContent) IOException(java.io.IOException) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) InputStreamReader(java.io.InputStreamReader) SwimlaneContextInstance(org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance) ForEachNodeInstance(org.jbpm.workflow.instance.node.ForEachNodeInstance) RuleSetNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.RuleSetNodeInstanceContent) SLAContext(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf.SLAContext) HumanTaskWorkItemImpl(org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl) AsyncEventNodeInstance(org.jbpm.workflow.core.node.AsyncEventNodeInstance) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl) MilestoneNodeInstance(org.jbpm.workflow.instance.node.MilestoneNodeInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) JoinInstance(org.jbpm.workflow.instance.node.JoinInstance) Reassignment(org.jbpm.process.instance.impl.humantask.Reassignment) InputStream(java.io.InputStream) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) KogitoTypesProtobuf(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf)

Example 2 with WorkflowContext

use of org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf.WorkflowContext in project kogito-runtimes by kiegroup.

the class ProtobufProcessInstanceReader method buildWorkflow.

private RuleFlowProcessInstance buildWorkflow(KogitoProcessInstanceProtobuf.ProcessInstance processInstanceProtobuf) {
    RuleFlowProcessInstance processInstance = ruleFlowProcessInstance;
    processInstance.setProcess(((AbstractProcess<?>) context.get(MarshallerContextName.MARSHALLER_PROCESS)).get());
    processInstance.setId(processInstanceProtobuf.getId());
    processInstance.setProcessId(processInstanceProtobuf.getProcessId());
    processInstance.setState(processInstanceProtobuf.getState());
    processInstance.setSignalCompletion(processInstanceProtobuf.getSignalCompletion());
    processInstance.setStartDate(new Date(processInstanceProtobuf.getStartDate()));
    processInstance.setDescription(processInstanceProtobuf.getDescription());
    processInstance.setDeploymentId(processInstanceProtobuf.getDeploymentId());
    for (String completedNodeId : processInstanceProtobuf.getCompletedNodeIdsList()) {
        processInstance.addCompletedNodeId(completedNodeId);
    }
    processInstance.setCorrelationKey(processInstanceProtobuf.getBusinessKey());
    SLAContext slaContext = processInstanceProtobuf.getSla();
    if (slaContext.getSlaDueDate() > 0) {
        processInstance.internalSetSlaDueDate(new Date(slaContext.getSlaDueDate()));
    }
    processInstance.internalSetSlaTimerId(slaContext.getSlaTimerId());
    processInstance.internalSetSlaCompliance(slaContext.getSlaCompliance());
    processInstance.setParentProcessInstanceId(processInstanceProtobuf.getParentProcessInstanceId());
    processInstance.setRootProcessInstanceId(processInstanceProtobuf.getRootProcessInstanceId());
    processInstance.setRootProcessId(processInstanceProtobuf.getRootProcessId());
    processInstance.internalSetErrorNodeId(processInstanceProtobuf.getErrorNodeId());
    processInstance.internalSetErrorMessage(processInstanceProtobuf.getErrorMessage());
    processInstance.setReferenceId(processInstanceProtobuf.getReferenceId());
    if (processInstanceProtobuf.getSwimlaneContextCount() > 0) {
        SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);
        for (KogitoTypesProtobuf.SwimlaneContext _swimlane : processInstanceProtobuf.getSwimlaneContextList()) {
            swimlaneContextInstance.setActorId(_swimlane.getSwimlane(), _swimlane.getActorId());
        }
    }
    WorkflowContext workflowContext = processInstanceProtobuf.getContext();
    for (KogitoTypesProtobuf.NodeInstance nodeInstanceProtobuf : workflowContext.getNodeInstanceList()) {
        NodeInstanceImpl nodeInstanceImpl = buildNodeInstance(nodeInstanceProtobuf, processInstance);
        if (nodeInstanceProtobuf.hasTriggerDate()) {
            nodeInstanceImpl.internalSetTriggerTime(new Date(nodeInstanceProtobuf.getTriggerDate()));
        }
    }
    for (KogitoTypesProtobuf.NodeInstanceGroup group : workflowContext.getExclusiveGroupList()) {
        Function<String, KogitoNodeInstance> finder = nodeInstanceId -> processInstance.getNodeInstance(nodeInstanceId, true);
        processInstance.addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, buildExclusiveGroupInstance(group, finder));
    }
    processInstance.addContextInstance(VariableScope.VARIABLE_SCOPE, new VariableScopeInstance());
    if (workflowContext.getVariableCount() > 0) {
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
        varReader.buildVariables(workflowContext.getVariableList()).forEach(v -> variableScopeInstance.internalSetVariable(v.getName(), v.getValue()));
    }
    if (workflowContext.getIterationLevelsCount() > 0) {
        processInstance.getIterationLevels().putAll(buildIterationLevels(workflowContext.getIterationLevelsList()));
    }
    return processInstance;
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) Comment(org.kie.kogito.process.workitem.Comment) ProtobufTypeRegistryFactory.protobufTypeRegistryFactoryInstance(org.kie.kogito.serialization.process.protobuf.ProtobufTypeRegistryFactory.protobufTypeRegistryFactoryInstance) Date(java.util.Date) RuleSetNodeInstance(org.jbpm.workflow.instance.node.RuleSetNodeInstance) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ExclusiveGroupInstance(org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) MarshallerContextName(org.kie.kogito.serialization.process.MarshallerContextName) HumanTaskWorkItemData(org.kie.kogito.serialization.process.protobuf.KogitoWorkItemsProtobuf.HumanTaskWorkItemData) KogitoNodeInstanceContainer(org.kie.kogito.internal.process.runtime.KogitoNodeInstanceContainer) StateNodeInstance(org.jbpm.workflow.instance.node.StateNodeInstance) TimerNodeInstance(org.jbpm.workflow.instance.node.TimerNodeInstance) MarshallerReaderContext(org.kie.kogito.serialization.process.MarshallerReaderContext) Map(java.util.Map) CompositeContextNodeInstance(org.jbpm.workflow.instance.node.CompositeContextNodeInstance) DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) MilestoneNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.MilestoneNodeInstanceContent) ProcessInstanceMarshallerException(org.kie.kogito.serialization.process.ProcessInstanceMarshallerException) URI(java.net.URI) EventNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.EventNodeInstanceContent) WorkflowContext(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf.WorkflowContext) Attachment(org.kie.kogito.process.workitem.Attachment) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ForEachNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.ForEachNodeInstanceContent) DynamicNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.DynamicNodeInstanceContent) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) KogitoTypesProtobuf(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf) VariableScope(org.jbpm.process.core.context.variable.VariableScope) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) List(java.util.List) EventSubProcessNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.EventSubProcessNodeInstanceContent) JsonFormat(com.google.protobuf.util.JsonFormat) ExclusiveGroup(org.jbpm.process.core.context.exclusive.ExclusiveGroup) Any(com.google.protobuf.Any) NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) StateNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.StateNodeInstanceContent) SwimlaneContext(org.jbpm.process.core.context.swimlane.SwimlaneContext) AbstractProcess(org.kie.kogito.process.impl.AbstractProcess) CompositeContextNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.CompositeContextNodeInstanceContent) KogitoWorkItemsProtobuf(org.kie.kogito.serialization.process.protobuf.KogitoWorkItemsProtobuf) HashMap(java.util.HashMap) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) JoinNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.JoinNodeInstanceContent) Function(java.util.function.Function) ArrayList(java.util.ArrayList) AsyncEventNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.AsyncEventNodeInstanceContent) WorkItemNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.WorkItemNodeInstanceContent) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance) LambdaSubProcessNodeInstance(org.jbpm.workflow.instance.node.LambdaSubProcessNodeInstance) LambdaSubProcessNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.LambdaSubProcessNodeInstanceContent) KogitoProcessInstanceProtobuf(org.kie.kogito.serialization.process.protobuf.KogitoProcessInstanceProtobuf) SubProcessNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.SubProcessNodeInstanceContent) TimerNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.TimerNodeInstanceContent) IOException(java.io.IOException) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) InputStreamReader(java.io.InputStreamReader) SwimlaneContextInstance(org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance) ForEachNodeInstance(org.jbpm.workflow.instance.node.ForEachNodeInstance) RuleSetNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.RuleSetNodeInstanceContent) SLAContext(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf.SLAContext) HumanTaskWorkItemImpl(org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl) AsyncEventNodeInstance(org.jbpm.workflow.core.node.AsyncEventNodeInstance) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl) MilestoneNodeInstance(org.jbpm.workflow.instance.node.MilestoneNodeInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) JoinInstance(org.jbpm.workflow.instance.node.JoinInstance) Reassignment(org.jbpm.process.instance.impl.humantask.Reassignment) InputStream(java.io.InputStream) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) SwimlaneContextInstance(org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance) WorkflowContext(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf.WorkflowContext) KogitoTypesProtobuf(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf) Date(java.util.Date) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) SLAContext(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf.SLAContext)

Aggregations

Any (com.google.protobuf.Any)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 JsonFormat (com.google.protobuf.util.JsonFormat)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 ExclusiveGroup (org.jbpm.process.core.context.exclusive.ExclusiveGroup)2 SwimlaneContext (org.jbpm.process.core.context.swimlane.SwimlaneContext)2 VariableScope (org.jbpm.process.core.context.variable.VariableScope)2 ExclusiveGroupInstance (org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance)2 SwimlaneContextInstance (org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance)2