Search in sources :

Example 46 with RegistryContext

use of org.drools.core.command.impl.RegistryContext in project drools by kiegroup.

the class FromExternalFactHandleCommand method execute.

public FactHandle execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    Collection<FactHandle> factHandles = ksession.getFactHandles();
    int fhId = Integer.parseInt(factHandleExternalForm.split(":")[1]);
    for (FactHandle factHandle : factHandles) {
        if (factHandle instanceof InternalFactHandle && ((InternalFactHandle) factHandle).getId() == fhId) {
            InternalFactHandle fhClone = ((InternalFactHandle) factHandle).clone();
            if (disconnected) {
                fhClone.disconnect();
            }
            return fhClone;
        }
    }
    return null;
}
Also used : InternalFactHandle(org.drools.core.common.InternalFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) InternalFactHandle(org.drools.core.common.InternalFactHandle)

Example 47 with RegistryContext

use of org.drools.core.command.impl.RegistryContext in project drools by kiegroup.

the class GetFactHandlesCommand method execute.

public Collection<FactHandle> execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    Collection<FactHandle> disconnectedFactHandles = new ArrayList<FactHandle>();
    if (filter != null) {
        Collection<InternalFactHandle> factHandles = ksession.getFactHandles(this.filter);
        if (factHandles != null && disconnected) {
            for (InternalFactHandle factHandle : factHandles) {
                InternalFactHandle handle = factHandle.clone();
                handle.disconnect();
                disconnectedFactHandles.add(handle);
            }
            if (outIdentifier != null) {
                ((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, disconnectedFactHandles);
            }
            return disconnectedFactHandles;
        } else {
            Collection<FactHandle> ksessionFactHandles = ksession.getFactHandles(this.filter);
            if (outIdentifier != null) {
                ((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, new ArrayList<FactHandle>(ksessionFactHandles));
            }
            return ksessionFactHandles;
        }
    } else {
        Collection<InternalFactHandle> factHandles = ksession.getFactHandles();
        if (factHandles != null && disconnected) {
            for (InternalFactHandle factHandle : factHandles) {
                InternalFactHandle handle = factHandle.clone();
                handle.disconnect();
                disconnectedFactHandles.add(handle);
            }
            if (outIdentifier != null) {
                ((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, disconnectedFactHandles);
            }
            return disconnectedFactHandles;
        } else {
            Collection<FactHandle> ksessionFactHandles = ksession.getFactHandles();
            if (outIdentifier != null) {
                ((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, new ArrayList<FactHandle>(ksessionFactHandles));
            }
            return ksessionFactHandles;
        }
    }
}
Also used : InternalFactHandle(org.drools.core.common.InternalFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) InternalFactHandle(org.drools.core.common.InternalFactHandle)

Example 48 with RegistryContext

use of org.drools.core.command.impl.RegistryContext in project drools by kiegroup.

the class GetObjectsCommand method execute.

public Collection execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    Collection col = null;
    if (getFilter() != null) {
        col = ksession.getObjects(this.filter);
    } else {
        col = ksession.getObjects();
    }
    if (this.outIdentifier != null) {
        List objects = new ArrayList(col);
        ((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, objects);
    }
    return col;
}
Also used : ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) ArrayList(java.util.ArrayList) Collection(java.util.Collection) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) ArrayList(java.util.ArrayList) List(java.util.List)

Example 49 with RegistryContext

use of org.drools.core.command.impl.RegistryContext in project drools by kiegroup.

the class ReTryWorkItemCommand method execute.

public Void execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    ((org.drools.core.process.instance.WorkItemManager) ksession.getWorkItemManager()).retryWorkItem(workItemId, params);
    return null;
}
Also used : KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext)

Example 50 with RegistryContext

use of org.drools.core.command.impl.RegistryContext 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)

Aggregations

RegistryContext (org.drools.core.command.impl.RegistryContext)58 KieSession (org.kie.api.runtime.KieSession)52 ExecutionResultImpl (org.drools.core.runtime.impl.ExecutionResultImpl)20 EntryPoint (org.kie.api.runtime.rule.EntryPoint)12 FactHandle (org.kie.api.runtime.rule.FactHandle)10 ArrayList (java.util.ArrayList)8 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)7 InternalFactHandle (org.drools.core.common.InternalFactHandle)6 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)4 HashMap (java.util.HashMap)3 RequestContextImpl (org.drools.core.command.RequestContextImpl)3 Context (org.kie.api.runtime.Context)3 KieContainer (org.kie.api.runtime.KieContainer)3 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 EntryPointCreator (org.drools.core.command.EntryPointCreator)2 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)2 KieServices (org.kie.api.KieServices)2 CorrelationAwareProcessRuntime (org.kie.internal.process.CorrelationAwareProcessRuntime)2