Search in sources :

Example 1 with WorkflowProcessInstance

use of org.kie.api.runtime.process.WorkflowProcessInstance in project drools by kiegroup.

the class SetProcessInstanceVariablesCommand method execute.

public Void execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
    if (processInstance != null) {
        if (variables != null) {
            for (Map.Entry<String, Object> entry : variables.entrySet()) {
                ((WorkflowProcessInstance) processInstance).setVariable(entry.getKey(), entry.getValue());
            }
        }
    }
    return null;
}
Also used : KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) HashMap(java.util.HashMap) Map(java.util.Map) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance)

Example 2 with WorkflowProcessInstance

use of org.kie.api.runtime.process.WorkflowProcessInstance in project drools by kiegroup.

the class DefaultKnowledgeHelper method getContext.

@SuppressWarnings("unchecked")
public <T> T getContext(Class<T> contextClass) {
    if (ProcessContext.class.equals(contextClass)) {
        String ruleflowGroupName = getMatch().getRule().getRuleFlowGroup();
        if (ruleflowGroupName != null) {
            Map<Long, String> nodeInstances = ((InternalRuleFlowGroup) workingMemory.getAgenda().getRuleFlowGroup(ruleflowGroupName)).getNodeInstances();
            if (!nodeInstances.isEmpty()) {
                if (nodeInstances.size() > 1) {
                    // TODO
                    throw new UnsupportedOperationException("Not supporting multiple node instances for the same ruleflow group");
                }
                Map.Entry<Long, String> entry = nodeInstances.entrySet().iterator().next();
                ProcessInstance processInstance = workingMemory.getProcessInstance(entry.getKey());
                org.drools.core.spi.ProcessContext context = new org.drools.core.spi.ProcessContext(workingMemory.getKnowledgeRuntime());
                context.setProcessInstance(processInstance);
                String nodeInstance = entry.getValue();
                String[] nodeInstanceIds = nodeInstance.split(":");
                NodeInstanceContainer container = (WorkflowProcessInstance) processInstance;
                for (int i = 0; i < nodeInstanceIds.length; i++) {
                    for (NodeInstance subNodeInstance : container.getNodeInstances()) {
                        if (subNodeInstance.getId() == new Long(nodeInstanceIds[i])) {
                            if (i == nodeInstanceIds.length - 1) {
                                context.setNodeInstance(subNodeInstance);
                                break;
                            } else {
                                container = (NodeInstanceContainer) subNodeInstance;
                            }
                        }
                    }
                }
                return (T) context;
            }
        }
    }
    return null;
}
Also used : NodeInstanceContainer(org.kie.api.runtime.process.NodeInstanceContainer) ProcessContext(org.kie.api.runtime.process.ProcessContext) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) InternalWorkingMemoryEntryPoint(org.drools.core.common.InternalWorkingMemoryEntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Map(java.util.Map) NodeInstance(org.kie.api.runtime.process.NodeInstance) InternalRuleFlowGroup(org.drools.core.common.InternalRuleFlowGroup) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance)

Aggregations

Map (java.util.Map)2 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)2 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)2 HashMap (java.util.HashMap)1 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)1 RegistryContext (org.drools.core.command.impl.RegistryContext)1 InternalRuleFlowGroup (org.drools.core.common.InternalRuleFlowGroup)1 InternalWorkingMemoryEntryPoint (org.drools.core.common.InternalWorkingMemoryEntryPoint)1 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)1 KieSession (org.kie.api.runtime.KieSession)1 NodeInstance (org.kie.api.runtime.process.NodeInstance)1 NodeInstanceContainer (org.kie.api.runtime.process.NodeInstanceContainer)1 ProcessContext (org.kie.api.runtime.process.ProcessContext)1 EntryPoint (org.kie.api.runtime.rule.EntryPoint)1