Search in sources :

Example 6 with SwimlaneContextInstance

use of org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance in project jbpm by kiegroup.

the class AbstractProcessInstanceMarshaller method readProcessInstance.

// Input methods
public ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException {
    ObjectInputStream stream = context.stream;
    InternalKnowledgeBase kBase = context.kBase;
    InternalWorkingMemory wm = context.wm;
    WorkflowProcessInstanceImpl processInstance = createProcessInstance();
    processInstance.setId(stream.readLong());
    String processId = stream.readUTF();
    processInstance.setProcessId(processId);
    Process process = kBase.getProcess(processId);
    if (kBase != null) {
        processInstance.setProcess(process);
    }
    processInstance.setState(stream.readInt());
    long nodeInstanceCounter = stream.readLong();
    processInstance.setKnowledgeRuntime(wm.getKnowledgeRuntime());
    int nbSwimlanes = stream.readInt();
    if (nbSwimlanes > 0) {
        Context swimlaneContext = ((org.jbpm.process.core.Process) process).getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
        SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance(swimlaneContext);
        for (int i = 0; i < nbSwimlanes; i++) {
            String name = stream.readUTF();
            String value = stream.readUTF();
            swimlaneContextInstance.setActorId(name, value);
        }
    }
    while (stream.readShort() == PersisterEnums.NODE_INSTANCE) {
        readNodeInstance(context, processInstance, processInstance);
    }
    int exclusiveGroupInstances = stream.readInt();
    for (int i = 0; i < exclusiveGroupInstances; i++) {
        ExclusiveGroupInstance exclusiveGroupInstance = new ExclusiveGroupInstance();
        processInstance.addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, exclusiveGroupInstance);
        int nodeInstances = stream.readInt();
        for (int j = 0; j < nodeInstances; j++) {
            long nodeInstanceId = stream.readLong();
            NodeInstance nodeInstance = processInstance.getNodeInstance(nodeInstanceId);
            if (nodeInstance == null) {
                throw new IllegalArgumentException("Could not find node instance when deserializing exclusive group instance: " + nodeInstanceId);
            }
            exclusiveGroupInstance.addNodeInstance(nodeInstance);
        }
    }
    // Process Variables
    // - Number of Variables = keys.size()
    // For Each Variable
    // - Variable Key
    // - Marshalling Strategy Index
    // - Marshalled Object
    int nbVariables = stream.readInt();
    if (nbVariables > 0) {
        Context variableScope = ((org.jbpm.process.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance(variableScope);
        for (int i = 0; i < nbVariables; i++) {
            String name = stream.readUTF();
            try {
                ObjectMarshallingStrategy strategy = null;
                int index = stream.readInt();
                // This is the old way of de/serializing strategy objects
                if (index >= 0) {
                    strategy = context.resolverStrategyFactory.getStrategy(index);
                } else // This is the new way
                if (index == -2) {
                    String strategyClassName = context.stream.readUTF();
                    if (!StringUtils.isEmpty(strategyClassName)) {
                        strategy = context.resolverStrategyFactory.getStrategyObject(strategyClassName);
                        if (strategy == null) {
                            throw new IllegalStateException("No strategy of type " + strategyClassName + " available.");
                        }
                    }
                }
                // If either way retrieves a strategy, use it
                Object value = null;
                if (strategy != null) {
                    value = strategy.read(stream);
                }
                variableScopeInstance.internalSetVariable(name, value);
            } catch (ClassNotFoundException e) {
                throw new IllegalArgumentException("Could not reload variable " + name);
            }
        }
    }
    processInstance.internalSetNodeInstanceCounter(nodeInstanceCounter);
    if (wm != null) {
        processInstance.reconnect();
    }
    return processInstance;
}
Also used : SwimlaneContext(org.jbpm.process.core.context.swimlane.SwimlaneContext) MarshallerWriteContext(org.drools.core.marshalling.impl.MarshallerWriteContext) MarshallerReaderContext(org.drools.core.marshalling.impl.MarshallerReaderContext) Context(org.jbpm.process.core.Context) ExclusiveGroupInstance(org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance) SwimlaneContextInstance(org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) Process(org.kie.api.definition.process.Process) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) ObjectInputStream(java.io.ObjectInputStream)

Example 7 with SwimlaneContextInstance

use of org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance in project jbpm by kiegroup.

the class AbstractProtobufProcessInstanceMarshaller method writeProcessInstance.

// Output methods
public JBPMMessages.ProcessInstance writeProcessInstance(MarshallerWriteContext context, ProcessInstance processInstance) throws IOException {
    WorkflowProcessInstanceImpl workFlow = (WorkflowProcessInstanceImpl) processInstance;
    JBPMMessages.ProcessInstance.Builder _instance = JBPMMessages.ProcessInstance.newBuilder().setId(workFlow.getId()).setProcessId(workFlow.getProcessId()).setState(workFlow.getState()).setNodeInstanceCounter(workFlow.getNodeInstanceCounter()).setProcessType(workFlow.getProcess().getType()).setParentProcessInstanceId(workFlow.getParentProcessInstanceId()).setSignalCompletion(workFlow.isSignalCompletion()).setSlaCompliance(workFlow.getSlaCompliance());
    if (workFlow.getProcessXml() != null) {
        _instance.setProcessXml(workFlow.getProcessXml());
    }
    if (workFlow.getDescription() != null) {
        _instance.setDescription(workFlow.getDescription());
    }
    if (workFlow.getDeploymentId() != null) {
        _instance.setDeploymentId(workFlow.getDeploymentId());
    }
    _instance.addAllCompletedNodeIds(workFlow.getCompletedNodeIds());
    if (workFlow.getCorrelationKey() != null) {
        _instance.setCorrelationKey(workFlow.getCorrelationKey());
    }
    if (workFlow.getSlaDueDate() != null) {
        _instance.setSlaDueDate(workFlow.getSlaDueDate().getTime());
    }
    if (workFlow.getSlaTimerId() != null) {
        _instance.setSlaTimerId(workFlow.getSlaTimerId());
    }
    SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) workFlow.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);
    if (swimlaneContextInstance != null) {
        Map<String, String> swimlaneActors = swimlaneContextInstance.getSwimlaneActors();
        for (Map.Entry<String, String> entry : swimlaneActors.entrySet()) {
            _instance.addSwimlaneContext(JBPMMessages.ProcessInstance.SwimlaneContextInstance.newBuilder().setSwimlane(entry.getKey()).setActorId(entry.getValue()).build());
        }
    }
    List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(workFlow.getNodeInstances());
    Collections.sort(nodeInstances, new Comparator<NodeInstance>() {

        public int compare(NodeInstance o1, NodeInstance o2) {
            return (int) (o1.getId() - o2.getId());
        }
    });
    for (NodeInstance nodeInstance : nodeInstances) {
        _instance.addNodeInstance(writeNodeInstance(context, nodeInstance));
    }
    List<ContextInstance> exclusiveGroupInstances = workFlow.getContextInstances(ExclusiveGroup.EXCLUSIVE_GROUP);
    if (exclusiveGroupInstances != null) {
        for (ContextInstance contextInstance : exclusiveGroupInstances) {
            JBPMMessages.ProcessInstance.ExclusiveGroupInstance.Builder _exclusive = JBPMMessages.ProcessInstance.ExclusiveGroupInstance.newBuilder();
            ExclusiveGroupInstance exclusiveGroupInstance = (ExclusiveGroupInstance) contextInstance;
            Collection<NodeInstance> groupNodeInstances = exclusiveGroupInstance.getNodeInstances();
            for (NodeInstance nodeInstance : groupNodeInstances) {
                _exclusive.addGroupNodeInstanceId(nodeInstance.getId());
            }
            _instance.addExclusiveGroup(_exclusive.build());
        }
    }
    VariableScopeInstance variableScopeInstance = (VariableScopeInstance) workFlow.getContextInstance(VariableScope.VARIABLE_SCOPE);
    List<Map.Entry<String, Object>> variables = new ArrayList<Map.Entry<String, Object>>(variableScopeInstance.getVariables().entrySet());
    Collections.sort(variables, new Comparator<Map.Entry<String, Object>>() {

        public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) {
            return o1.getKey().compareTo(o2.getKey());
        }
    });
    for (Map.Entry<String, Object> variable : variables) {
        if (variable.getValue() != null) {
            _instance.addVariable(ProtobufProcessMarshaller.marshallVariable(context, variable.getKey(), variable.getValue()));
        }
    }
    List<Map.Entry<String, Integer>> iterationlevels = new ArrayList<Map.Entry<String, Integer>>(workFlow.getIterationLevels().entrySet());
    Collections.sort(iterationlevels, new Comparator<Map.Entry<String, Integer>>() {

        public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
            return o1.getKey().compareTo(o2.getKey());
        }
    });
    for (Map.Entry<String, Integer> level : iterationlevels) {
        if (level.getValue() != null) {
            _instance.addIterationLevels(JBPMMessages.IterationLevel.newBuilder().setId(level.getKey()).setLevel(level.getValue()));
        }
    }
    return _instance.build();
}
Also used : WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) ArrayList(java.util.ArrayList) TextMapEntry(org.jbpm.marshalling.impl.JBPMMessages.ProcessInstance.NodeInstanceContent.RuleSetNode.TextMapEntry) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) ExclusiveGroupInstance(org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance) SwimlaneContextInstance(org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance) ContextInstance(org.jbpm.process.instance.ContextInstance) SwimlaneContextInstance(org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Map(java.util.Map) HashMap(java.util.HashMap) RuleSetNodeInstance(org.jbpm.workflow.instance.node.RuleSetNodeInstance) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) StateNodeInstance(org.jbpm.workflow.instance.node.StateNodeInstance) TimerNodeInstance(org.jbpm.workflow.instance.node.TimerNodeInstance) CompositeContextNodeInstance(org.jbpm.workflow.instance.node.CompositeContextNodeInstance) DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) AsyncEventNodeInstance(org.jbpm.workflow.instance.node.AsyncEventNodeInstance) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance) ForEachNodeInstance(org.jbpm.workflow.instance.node.ForEachNodeInstance) MilestoneNodeInstance(org.jbpm.workflow.instance.node.MilestoneNodeInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance)

Aggregations

SwimlaneContextInstance (org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance)7 ExclusiveGroupInstance (org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance)4 VariableScopeInstance (org.jbpm.process.instance.context.variable.VariableScopeInstance)4 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)4 NodeInstance (org.kie.api.runtime.process.NodeInstance)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)2 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)2 MarshallerReaderContext (org.drools.core.marshalling.impl.MarshallerReaderContext)2 MarshallerWriteContext (org.drools.core.marshalling.impl.MarshallerWriteContext)2 Context (org.jbpm.process.core.Context)2 SwimlaneContext (org.jbpm.process.core.context.swimlane.SwimlaneContext)2 ContextInstance (org.jbpm.process.instance.ContextInstance)2 AsyncEventNodeInstance (org.jbpm.workflow.instance.node.AsyncEventNodeInstance)2 CompositeContextNodeInstance (org.jbpm.workflow.instance.node.CompositeContextNodeInstance)2 DynamicNodeInstance (org.jbpm.workflow.instance.node.DynamicNodeInstance)2 EventNodeInstance (org.jbpm.workflow.instance.node.EventNodeInstance)2 EventSubProcessNodeInstance (org.jbpm.workflow.instance.node.EventSubProcessNodeInstance)2