Search in sources :

Example 6 with RegistryContext

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

the class ModifyCommand method execute.

public Object execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    EntryPoint wmep = ksession.getEntryPoint(factHandle.getEntryPointId());
    Object object = wmep.getObject(this.factHandle);
    MVELSafeHelper.getEvaluator().eval(getMvelExpr(), object);
    wmep.update(factHandle, object);
    return object;
}
Also used : EntryPoint(org.kie.api.runtime.rule.EntryPoint) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext)

Example 7 with RegistryContext

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

the class InsertObjectInEntryPointCommand method execute.

public FactHandle execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    EntryPoint ep = ksession.getEntryPoint(entryPoint);
    FactHandle factHandle = ep.insert(object);
    DefaultFactHandle disconnectedHandle = ((DefaultFactHandle) factHandle).clone();
    disconnectedHandle.disconnect();
    if (outIdentifier != null) {
        if (this.returnObject) {
            ((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, object);
        }
        ((RegistryContext) context).lookup(ExecutionResultImpl.class).getFactHandles().put(this.outIdentifier, disconnectedHandle);
    }
    return disconnectedHandle;
}
Also used : DefaultFactHandle(org.drools.core.common.DefaultFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) EntryPoint(org.kie.api.runtime.rule.EntryPoint) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext)

Example 8 with RegistryContext

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

the class ExecuteCommand method execute.

public ExecutionResults execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    ExecutionResults kresults = null;
    if (ksession instanceof StatefulKnowledgeSessionImpl) {
        kresults = ksession.execute(this.command);
    } else {
        // Graceful failure
        kresults = ksession.execute(this.command);
    }
    if (this.outIdentifier != null) {
        ((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, kresults);
    }
    if (disconnected) {
        ExecutionResultImpl disconnectedResults = new ExecutionResultImpl();
        HashMap<String, Object> disconnectedHandles = new HashMap<String, Object>();
        for (String key : kresults.getIdentifiers()) {
            FactHandle handle = (FactHandle) kresults.getFactHandle(key);
            if (handle != null) {
                DefaultFactHandle disconnectedHandle = ((DefaultFactHandle) handle).clone();
                disconnectedHandle.disconnect();
                disconnectedHandles.put(key, disconnectedHandle);
            }
        }
        disconnectedResults.setFactHandles(disconnectedHandles);
        disconnectedResults.setResults((HashMap) ((ExecutionResultImpl) kresults).getResults());
        return disconnectedResults;
    }
    return kresults;
}
Also used : DefaultFactHandle(org.drools.core.common.DefaultFactHandle) HashMap(java.util.HashMap) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) ExecutionResults(org.kie.api.runtime.ExecutionResults) StatefulKnowledgeSessionImpl(org.drools.core.impl.StatefulKnowledgeSessionImpl) ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext)

Example 9 with RegistryContext

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

the class GetKieContainerCommand method execute.

public KieContainer execute(Context context) {
    // use the new API to retrieve the session by ID
    KieServices kieServices = KieServices.Factory.get();
    KieContainer kieContainer = kieServices.newKieContainer(releaseId);
    ((RegistryContext) context).register(KieContainer.class, kieContainer);
    return kieContainer;
}
Also used : KieServices(org.kie.api.KieServices) RegistryContext(org.drools.core.command.impl.RegistryContext) KieContainer(org.kie.api.runtime.KieContainer)

Example 10 with RegistryContext

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

the class SetVariableCommandFromLastReturn method execute.

public Object execute(Context context) {
    Context targetCtx;
    if (this.contextName == null) {
        targetCtx = context;
    } else {
        targetCtx = ((RegistryContext) context).getContextManager().getContext(this.contextName);
    }
    GetDefaultValue sim = (GetDefaultValue) context.get("simulator");
    Object o = sim.getObject();
    // for FactHandle's we store the handle on a map and the actual object as
    if (o instanceof FactHandle) {
        Map<String, FactHandle> handles = (Map<String, FactHandle>) targetCtx.get("h");
        if (handles == null) {
            handles = new HashMap<String, FactHandle>();
            targetCtx.set("h", handles);
        }
        handles.put(identifier, (FactHandle) o);
        o = ((InternalFactHandle) o).getObject();
    }
    targetCtx.set(identifier, o);
    return o;
}
Also used : RegistryContext(org.drools.core.command.impl.RegistryContext) Context(org.kie.api.runtime.Context) InternalFactHandle(org.drools.core.common.InternalFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) RegistryContext(org.drools.core.command.impl.RegistryContext) Map(java.util.Map) HashMap(java.util.HashMap)

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