Search in sources :

Example 1 with SwimlaneContext

use of org.jbpm.process.core.context.swimlane.SwimlaneContext in project jbpm by kiegroup.

the class XmlBPMNProcessDumper method visitLanes.

private void visitLanes(WorkflowProcess process, StringBuilder xmlDump) {
    // lanes
    Collection<Swimlane> swimlanes = ((SwimlaneContext) ((org.jbpm.workflow.core.WorkflowProcess) process).getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE)).getSwimlanes();
    if (!swimlanes.isEmpty()) {
        xmlDump.append("    <laneSet>" + EOL);
        for (Swimlane swimlane : swimlanes) {
            xmlDump.append("      <lane name=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(swimlane.getName()) + "\" >" + EOL);
            visitLane(process, swimlane.getName(), xmlDump);
            xmlDump.append("      </lane>" + EOL);
        }
        xmlDump.append("    </laneSet>" + EOL);
    }
}
Also used : SwimlaneContext(org.jbpm.process.core.context.swimlane.SwimlaneContext) Swimlane(org.jbpm.process.core.context.swimlane.Swimlane)

Example 2 with SwimlaneContext

use of org.jbpm.process.core.context.swimlane.SwimlaneContext in project jbpm by kiegroup.

the class AbstractProtobufProcessInstanceMarshaller method readProcessInstance.

// Input methods
public ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException {
    InternalKnowledgeBase ruleBase = context.kBase;
    InternalWorkingMemory wm = context.wm;
    JBPMMessages.ProcessInstance _instance = (org.jbpm.marshalling.impl.JBPMMessages.ProcessInstance) context.parameterObject;
    if (_instance == null) {
        // try to parse from the stream
        ExtensionRegistry registry = PersisterHelper.buildRegistry(context, null);
        Header _header;
        try {
            _header = PersisterHelper.readFromStreamWithHeaderPreloaded(context, registry);
        } catch (ClassNotFoundException e) {
            // Java 5 does not accept [new IOException(String, Throwable)]
            IOException ioe = new IOException("Error deserializing process instance.");
            ioe.initCause(e);
            throw ioe;
        }
        _instance = JBPMMessages.ProcessInstance.parseFrom(_header.getPayload(), registry);
    }
    WorkflowProcessInstanceImpl processInstance = createProcessInstance();
    processInstance.setId(_instance.getId());
    String processId = _instance.getProcessId();
    processInstance.setProcessId(processId);
    String processXml = _instance.getProcessXml();
    Process process = null;
    if (processXml != null && processXml.trim().length() > 0) {
        processInstance.setProcessXml(processXml);
        process = processInstance.getProcess();
    } else {
        process = ruleBase.getProcess(processId);
        if (process == null) {
            throw new RuntimeException("Could not find process " + processId + " when restoring process instance " + processInstance.getId());
        }
        processInstance.setProcess(process);
    }
    processInstance.setDescription(_instance.getDescription());
    processInstance.setState(_instance.getState());
    processInstance.setParentProcessInstanceId(_instance.getParentProcessInstanceId());
    processInstance.setSignalCompletion(_instance.getSignalCompletion());
    processInstance.setDeploymentId(_instance.getDeploymentId());
    processInstance.setCorrelationKey(_instance.getCorrelationKey());
    processInstance.internalSetSlaCompliance(_instance.getSlaCompliance());
    if (_instance.getSlaDueDate() > 0) {
        processInstance.internalSetSlaDueDate(new Date(_instance.getSlaDueDate()));
    }
    processInstance.internalSetSlaTimerId(_instance.getSlaTimerId());
    long nodeInstanceCounter = _instance.getNodeInstanceCounter();
    processInstance.setKnowledgeRuntime(wm.getKnowledgeRuntime());
    processInstance.internalSetNodeInstanceCounter(nodeInstanceCounter);
    for (String completedNodeId : _instance.getCompletedNodeIdsList()) {
        processInstance.addCompletedNodeId(completedNodeId);
    }
    if (_instance.getSwimlaneContextCount() > 0) {
        Context swimlaneContext = ((org.jbpm.process.core.Process) process).getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
        SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance(swimlaneContext);
        for (JBPMMessages.ProcessInstance.SwimlaneContextInstance _swimlane : _instance.getSwimlaneContextList()) {
            swimlaneContextInstance.setActorId(_swimlane.getSwimlane(), _swimlane.getActorId());
        }
    }
    for (JBPMMessages.ProcessInstance.NodeInstance _node : _instance.getNodeInstanceList()) {
        context.parameterObject = _node;
        readNodeInstance(context, processInstance, processInstance);
    }
    for (JBPMMessages.ProcessInstance.ExclusiveGroupInstance _excl : _instance.getExclusiveGroupList()) {
        ExclusiveGroupInstance exclusiveGroupInstance = new ExclusiveGroupInstance();
        processInstance.addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, exclusiveGroupInstance);
        for (Long nodeInstanceId : _excl.getGroupNodeInstanceIdList()) {
            NodeInstance nodeInstance = ((org.jbpm.workflow.instance.NodeInstanceContainer) processInstance).getNodeInstance(nodeInstanceId, true);
            if (nodeInstance == null) {
                throw new IllegalArgumentException("Could not find node instance when deserializing exclusive group instance: " + nodeInstanceId);
            }
            exclusiveGroupInstance.addNodeInstance(nodeInstance);
        }
    }
    if (_instance.getVariableCount() > 0) {
        Context variableScope = ((org.jbpm.process.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance(variableScope);
        for (JBPMMessages.Variable _variable : _instance.getVariableList()) {
            try {
                Object _value = ProtobufProcessMarshaller.unmarshallVariableValue(context, _variable);
                variableScopeInstance.internalSetVariable(_variable.getName(), _value);
            } catch (ClassNotFoundException e) {
                throw new IllegalArgumentException("Could not reload variable " + _variable.getName());
            }
        }
    }
    if (_instance.getIterationLevelsCount() > 0) {
        for (JBPMMessages.IterationLevel _level : _instance.getIterationLevelsList()) {
            processInstance.getIterationLevels().put(_level.getId(), _level.getLevel());
        }
    }
    processInstance.reconnect();
    return processInstance;
}
Also used : NodeInstanceContainer(org.kie.api.runtime.process.NodeInstanceContainer) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) Process(org.kie.api.definition.process.Process) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) MarshallerWriteContext(org.drools.core.marshalling.impl.MarshallerWriteContext) MarshallerReaderContext(org.drools.core.marshalling.impl.MarshallerReaderContext) Context(org.jbpm.process.core.Context) SwimlaneContext(org.jbpm.process.core.context.swimlane.SwimlaneContext) ExclusiveGroupInstance(org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance) SwimlaneContextInstance(org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance) IOException(java.io.IOException) Date(java.util.Date) Header(org.drools.core.marshalling.impl.ProtobufMessages.Header) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) 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)

Example 3 with SwimlaneContext

use of org.jbpm.process.core.context.swimlane.SwimlaneContext in project jbpm by kiegroup.

the class SwimlaneHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    WorkflowProcessImpl process = (WorkflowProcessImpl) parser.getParent();
    final String name = attrs.getValue("name");
    emptyAttributeCheck(localName, "name", name, parser);
    SwimlaneContext swimlaneContext = (SwimlaneContext) process.getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
    if (swimlaneContext != null) {
        Swimlane swimlane = new Swimlane();
        swimlane.setName(name);
        swimlaneContext.addSwimlane(swimlane);
    } else {
        throw new SAXParseException("Could not find default swimlane context.", parser.getLocator());
    }
    return null;
}
Also used : SwimlaneContext(org.jbpm.process.core.context.swimlane.SwimlaneContext) Swimlane(org.jbpm.process.core.context.swimlane.Swimlane) SAXParseException(org.xml.sax.SAXParseException) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl)

Example 4 with SwimlaneContext

use of org.jbpm.process.core.context.swimlane.SwimlaneContext in project jbpm by kiegroup.

the class XmlWorkflowProcessDumper method visitHeader.

protected void visitHeader(WorkflowProcess process, StringBuilder xmlDump, boolean includeMeta) {
    xmlDump.append("  <header>" + EOL);
    visitImports(((org.jbpm.process.core.Process) process).getImports(), xmlDump);
    visitGlobals(((org.jbpm.process.core.Process) process).getGlobals(), xmlDump);
    visitFunctionImports(((org.jbpm.process.core.Process) process).getFunctionImports(), xmlDump);
    VariableScope variableScope = (VariableScope) ((org.jbpm.process.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
    if (variableScope != null) {
        visitVariables(variableScope.getVariables(), xmlDump);
    }
    SwimlaneContext swimlaneContext = (SwimlaneContext) ((org.jbpm.process.core.Process) process).getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
    if (swimlaneContext != null) {
        visitSwimlanes(swimlaneContext.getSwimlanes(), xmlDump);
    }
    ExceptionScope exceptionScope = (ExceptionScope) ((org.jbpm.process.core.Process) process).getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
    if (exceptionScope != null) {
        visitExceptionHandlers(exceptionScope.getExceptionHandlers(), xmlDump);
    }
    xmlDump.append("  </header>" + EOL + EOL);
}
Also used : SwimlaneContext(org.jbpm.process.core.context.swimlane.SwimlaneContext) ExceptionScope(org.jbpm.process.core.context.exception.ExceptionScope) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 5 with SwimlaneContext

use of org.jbpm.process.core.context.swimlane.SwimlaneContext 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)

Aggregations

SwimlaneContext (org.jbpm.process.core.context.swimlane.SwimlaneContext)5 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 Swimlane (org.jbpm.process.core.context.swimlane.Swimlane)2 ExclusiveGroupInstance (org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance)2 SwimlaneContextInstance (org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance)2 VariableScopeInstance (org.jbpm.process.instance.context.variable.VariableScopeInstance)2 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)2 Process (org.kie.api.definition.process.Process)2 NodeInstance (org.kie.api.runtime.process.NodeInstance)2 ExtensionRegistry (com.google.protobuf.ExtensionRegistry)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 Date (java.util.Date)1 Header (org.drools.core.marshalling.impl.ProtobufMessages.Header)1 ExceptionScope (org.jbpm.process.core.context.exception.ExceptionScope)1 VariableScope (org.jbpm.process.core.context.variable.VariableScope)1