Search in sources :

Example 1 with ContextInstance

use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.

the class ProcessInstanceImpl method getContextInstance.

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

Example 2 with ContextInstance

use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.

the class ProcessInstanceImpl method getContextInstance.

public ContextInstance getContextInstance(final Context context) {
    ContextInstanceFactory conf = ContextInstanceFactoryRegistry.INSTANCE.getContextInstanceFactory(context);
    if (conf == null) {
        throw new IllegalArgumentException("Illegal context type (registry not found): " + context.getClass());
    }
    ContextInstance contextInstance = (ContextInstance) conf.getContextInstance(context, this, this);
    if (contextInstance == null) {
        throw new IllegalArgumentException("Illegal context type (instance not found): " + context.getClass());
    }
    return contextInstance;
}
Also used : ContextInstance(org.jbpm.process.instance.ContextInstance)

Example 3 with ContextInstance

use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.

the class WorkItemNodeInstance method getContextInstance.

@Override
public ContextInstance getContextInstance(Context context) {
    ContextInstanceFactory conf = ContextInstanceFactoryRegistry.INSTANCE.getContextInstanceFactory(context);
    if (conf == null) {
        throw new IllegalArgumentException("Illegal context type (registry not found): " + context.getClass());
    }
    ContextInstance contextInstance = (ContextInstance) conf.getContextInstance(context, this, (ProcessInstance) getProcessInstance());
    if (contextInstance == null) {
        throw new IllegalArgumentException("Illegal context type (instance not found): " + context.getClass());
    }
    return contextInstance;
}
Also used : ContextInstance(org.jbpm.process.instance.ContextInstance) ProcessInstance(org.jbpm.process.instance.ProcessInstance) ContextInstanceFactory(org.jbpm.process.instance.impl.ContextInstanceFactory)

Example 4 with ContextInstance

use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.

the class WorkflowProcessInstanceImpl method getVariables.

public Map<String, Object> getVariables() {
    // be null and the associated working memory is no longer accessible)
    if (getKnowledgeRuntime() == null) {
        List<ContextInstance> variableScopeInstances = getContextInstances(VariableScope.VARIABLE_SCOPE);
        if (variableScopeInstances == null) {
            return null;
        }
        Map<String, Object> result = new HashMap<String, Object>();
        for (ContextInstance contextInstance : variableScopeInstances) {
            Map<String, Object> variables = ((VariableScopeInstance) contextInstance).getVariables();
            result.putAll(variables);
        }
        return result;
    }
    // else retrieve the variable scope
    VariableScopeInstance variableScopeInstance = (VariableScopeInstance) getContextInstance(VariableScope.VARIABLE_SCOPE);
    if (variableScopeInstance == null) {
        return null;
    }
    return variableScopeInstance.getVariables();
}
Also used : VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) HashMap(java.util.HashMap) ContextInstance(org.jbpm.process.instance.ContextInstance)

Example 5 with ContextInstance

use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.

the class AbstractProcessInstanceMarshaller method writeProcessInstance.

// Output methods
public Object writeProcessInstance(MarshallerWriteContext context, ProcessInstance processInstance) throws IOException {
    WorkflowProcessInstanceImpl workFlow = (WorkflowProcessInstanceImpl) processInstance;
    ObjectOutputStream stream = context.stream;
    stream.writeLong(workFlow.getId());
    stream.writeUTF(workFlow.getProcessId());
    stream.writeInt(workFlow.getState());
    stream.writeLong(workFlow.getNodeInstanceCounter());
    SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) workFlow.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);
    if (swimlaneContextInstance != null) {
        Map<String, String> swimlaneActors = swimlaneContextInstance.getSwimlaneActors();
        stream.writeInt(swimlaneActors.size());
        for (Map.Entry<String, String> entry : swimlaneActors.entrySet()) {
            stream.writeUTF(entry.getKey());
            stream.writeUTF(entry.getValue());
        }
    } else {
        stream.writeInt(0);
    }
    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) {
        stream.writeShort(PersisterEnums.NODE_INSTANCE);
        writeNodeInstance(context, nodeInstance);
    }
    stream.writeShort(PersisterEnums.END);
    List<ContextInstance> exclusiveGroupInstances = workFlow.getContextInstances(ExclusiveGroup.EXCLUSIVE_GROUP);
    if (exclusiveGroupInstances == null) {
        stream.writeInt(0);
    } else {
        stream.writeInt(exclusiveGroupInstances.size());
        for (ContextInstance contextInstance : exclusiveGroupInstances) {
            ExclusiveGroupInstance exclusiveGroupInstance = (ExclusiveGroupInstance) contextInstance;
            Collection<NodeInstance> groupNodeInstances = exclusiveGroupInstance.getNodeInstances();
            stream.writeInt(groupNodeInstances.size());
            for (NodeInstance nodeInstance : groupNodeInstances) {
                stream.writeLong(nodeInstance.getId());
            }
        }
    }
    VariableScopeInstance variableScopeInstance = (VariableScopeInstance) workFlow.getContextInstance(VariableScope.VARIABLE_SCOPE);
    Map<String, Object> variables = variableScopeInstance.getVariables();
    List<String> keys = new ArrayList<String>(variables.keySet());
    Collection<Object> values = variables.values();
    Collections.sort(keys, new Comparator<String>() {

        public int compare(String o1, String o2) {
            return o1.compareTo(o2);
        }
    });
    // Process Variables
    // - Number of non null Variables = nonnullvariables.size()
    // For Each Variable
    // - Variable Key
    // - Marshalling Strategy Index
    // - Marshalled Object
    Collection<Object> notNullValues = new ArrayList<Object>();
    for (Object value : values) {
        if (value != null) {
            notNullValues.add(value);
        }
    }
    stream.writeInt(notNullValues.size());
    for (String key : keys) {
        Object object = variables.get(key);
        if (object != null) {
            stream.writeUTF(key);
            // New marshalling algorithm when using strategies
            int useNewMarshallingStrategyAlgorithm = -2;
            stream.writeInt(useNewMarshallingStrategyAlgorithm);
            // Choose first strategy that accepts the object (what was always done)
            ObjectMarshallingStrategy strategy = context.objectMarshallingStrategyStore.getStrategyObject(object);
            stream.writeUTF(strategy.getClass().getName());
            strategy.write(stream, object);
        }
    }
    return null;
}
Also used : 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) ArrayList(java.util.ArrayList) ObjectOutputStream(java.io.ObjectOutputStream) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) ContextInstance(org.jbpm.process.instance.ContextInstance) SwimlaneContextInstance(org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance) HashMap(java.util.HashMap) Map(java.util.Map) NodeInstance(org.kie.api.runtime.process.NodeInstance)

Aggregations

ContextInstance (org.jbpm.process.instance.ContextInstance)15 HashMap (java.util.HashMap)5 VariableScopeInstance (org.jbpm.process.instance.context.variable.VariableScopeInstance)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 ProcessInstance (org.jbpm.process.instance.ProcessInstance)4 ExclusiveGroupInstance (org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance)4 SwimlaneContextInstance (org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance)4 ContextInstanceFactory (org.jbpm.process.instance.impl.ContextInstanceFactory)4 NodeInstance (org.kie.api.runtime.process.NodeInstance)4 Collection (java.util.Collection)2 Comparator (java.util.Comparator)2 List (java.util.List)2 TextMapEntry (org.jbpm.marshalling.impl.JBPMMessages.ProcessInstance.NodeInstanceContent.RuleSetNode.TextMapEntry)2 Context (org.jbpm.process.core.Context)2 AbstractContextInstance (org.jbpm.process.instance.context.AbstractContextInstance)2 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)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