Search in sources :

Example 6 with Context

use of org.jbpm.process.core.Context in project jbpm by kiegroup.

the class CompositeContextNodeInstance method getContextInstance.

public ContextInstance getContextInstance(String contextId) {
    ContextInstance contextInstance = this.contextInstances.get(contextId);
    if (contextInstance != null) {
        return contextInstance;
    }
    Context context = getCompositeContextNode().getDefaultContext(contextId);
    if (context != null) {
        contextInstance = getContextInstance(context);
        return contextInstance;
    }
    return null;
}
Also used : Context(org.jbpm.process.core.Context) ContextInstance(org.jbpm.process.instance.ContextInstance)

Example 7 with Context

use of org.jbpm.process.core.Context in project jbpm by kiegroup.

the class ProcessBuilderImpl method buildContexts.

public void buildContexts(ContextContainer contextContainer, ProcessBuildContext buildContext) {
    List<Context> exceptionScopes = contextContainer.getContexts(ExceptionScope.EXCEPTION_SCOPE);
    if (exceptionScopes != null) {
        for (Context context : exceptionScopes) {
            // TODO: OCRAM: add compensation scope to process builder????
            ExceptionScope exceptionScope = (ExceptionScope) context;
            for (ExceptionHandler exceptionHandler : exceptionScope.getExceptionHandlers().values()) {
                if (exceptionHandler instanceof ActionExceptionHandler) {
                    DroolsConsequenceAction action = (DroolsConsequenceAction) ((ActionExceptionHandler) exceptionHandler).getAction();
                    ActionDescr actionDescr = new ActionDescr();
                    actionDescr.setText(action.getConsequence());
                    actionDescr.setResource(buildContext.getProcessDescr().getResource());
                    ProcessDialect dialect = ProcessDialectRegistry.getDialect(action.getDialect());
                    dialect.getActionBuilder().build(buildContext, action, actionDescr, (ProcessImpl) buildContext.getProcess());
                }
            }
        }
    }
}
Also used : Context(org.jbpm.process.core.Context) ProcessBuildContext(org.jbpm.process.builder.ProcessBuildContext) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler) ExceptionHandler(org.jbpm.process.core.context.exception.ExceptionHandler) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ActionDescr(org.drools.compiler.lang.descr.ActionDescr) ProcessDialect(org.jbpm.process.builder.dialect.ProcessDialect) ExceptionScope(org.jbpm.process.core.context.exception.ExceptionScope) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler)

Example 8 with Context

use of org.jbpm.process.core.Context in project jbpm by kiegroup.

the class AbstractProcessInstanceMarshaller method readNodeInstance.

public NodeInstance readNodeInstance(MarshallerReaderContext context, NodeInstanceContainer nodeInstanceContainer, WorkflowProcessInstance processInstance) throws IOException {
    ObjectInputStream stream = context.stream;
    long id = stream.readLong();
    long nodeId = stream.readLong();
    int nodeType = stream.readShort();
    NodeInstanceImpl nodeInstance = readNodeInstanceContent(nodeType, stream, context, processInstance);
    nodeInstance.setNodeId(nodeId);
    nodeInstance.setNodeInstanceContainer(nodeInstanceContainer);
    nodeInstance.setProcessInstance((org.jbpm.workflow.instance.WorkflowProcessInstance) processInstance);
    nodeInstance.setId(id);
    switch(nodeType) {
        case PersisterEnums.COMPOSITE_NODE_INSTANCE:
        case PersisterEnums.DYNAMIC_NODE_INSTANCE:
            int nbVariables = stream.readInt();
            if (nbVariables > 0) {
                Context variableScope = ((org.jbpm.process.core.Process) ((org.jbpm.process.instance.ProcessInstance) processInstance).getProcess()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
                VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((CompositeContextNodeInstance) nodeInstance).getContextInstance(variableScope);
                for (int i = 0; i < nbVariables; i++) {
                    String name = stream.readUTF();
                    try {
                        Object value = stream.readObject();
                        variableScopeInstance.internalSetVariable(name, value);
                    } catch (ClassNotFoundException e) {
                        throw new IllegalArgumentException("Could not reload variable " + name);
                    }
                }
            }
            while (stream.readShort() == PersisterEnums.NODE_INSTANCE) {
                readNodeInstance(context, (CompositeContextNodeInstance) nodeInstance, processInstance);
            }
            int exclusiveGroupInstances = stream.readInt();
            for (int i = 0; i < exclusiveGroupInstances; i++) {
                ExclusiveGroupInstance exclusiveGroupInstance = new ExclusiveGroupInstance();
                ((org.jbpm.process.instance.ProcessInstance) processInstance).addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, exclusiveGroupInstance);
                int nodeInstances = stream.readInt();
                for (int j = 0; j < nodeInstances; j++) {
                    long nodeInstanceId = stream.readLong();
                    NodeInstance groupNodeInstance = processInstance.getNodeInstance(nodeInstanceId);
                    if (groupNodeInstance == null) {
                        throw new IllegalArgumentException("Could not find node instance when deserializing exclusive group instance: " + nodeInstanceId);
                    }
                    exclusiveGroupInstance.addNodeInstance(groupNodeInstance);
                }
            }
            break;
        case PersisterEnums.FOR_EACH_NODE_INSTANCE:
            while (stream.readShort() == PersisterEnums.NODE_INSTANCE) {
                readNodeInstance(context, (ForEachNodeInstance) nodeInstance, processInstance);
            }
            break;
        default:
    }
    return nodeInstance;
}
Also used : NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) 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) Process(org.kie.api.definition.process.Process) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) ObjectInputStream(java.io.ObjectInputStream)

Example 9 with Context

use of org.jbpm.process.core.Context 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

Context (org.jbpm.process.core.Context)9 VariableScopeInstance (org.jbpm.process.instance.context.variable.VariableScopeInstance)5 NodeInstance (org.kie.api.runtime.process.NodeInstance)5 MarshallerReaderContext (org.drools.core.marshalling.impl.MarshallerReaderContext)4 MarshallerWriteContext (org.drools.core.marshalling.impl.MarshallerWriteContext)4 SwimlaneContext (org.jbpm.process.core.context.swimlane.SwimlaneContext)4 ExclusiveGroupInstance (org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance)4 Process (org.kie.api.definition.process.Process)4 ContextInstance (org.jbpm.process.instance.ContextInstance)3 ObjectInputStream (java.io.ObjectInputStream)2 Date (java.util.Date)2 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)2 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)2 ContextContainer (org.jbpm.process.core.ContextContainer)2 ExceptionScope (org.jbpm.process.core.context.exception.ExceptionScope)2 ContextInstanceContainer (org.jbpm.process.instance.ContextInstanceContainer)2 SwimlaneContextInstance (org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance)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