Search in sources :

Example 1 with RequestContextImpl

use of org.drools.core.command.RequestContextImpl in project drools by kiegroup.

the class GetContextCommand method execute.

@Override
public Void execute(Context context) {
    Context returned = ((RegistryContext) context).getContextManager().getContext(name);
    ((RequestContextImpl) context).setApplicationContext(returned);
    return null;
}
Also used : RegistryContext(org.drools.core.command.impl.RegistryContext) Context(org.kie.api.runtime.Context) RequestContextImpl(org.drools.core.command.RequestContextImpl)

Example 2 with RequestContextImpl

use of org.drools.core.command.RequestContextImpl in project drools by kiegroup.

the class NewContextCommand method execute.

@Override
public Void execute(Context context) {
    Context returned = ((RegistryContext) context).getContextManager().createContext(name);
    ((RequestContextImpl) context).setApplicationContext(returned);
    return null;
}
Also used : RegistryContext(org.drools.core.command.impl.RegistryContext) Context(org.kie.api.runtime.Context) RequestContextImpl(org.drools.core.command.RequestContextImpl)

Example 3 with RequestContextImpl

use of org.drools.core.command.RequestContextImpl in project drools by kiegroup.

the class SetCommand method execute.

@Override
public T execute(Context context) {
    RequestContextImpl reqContext = (RequestContextImpl) context;
    T returned = (T) reqContext.getResult();
    if (scope == Scope.REQUEST) {
        reqContext.set(name, returned);
    } else if (scope == Scope.CONVERSATION) {
        if (reqContext.getConversationContext() == null) {
            throw new IllegalStateException("No Conversation Context Exists");
        }
        reqContext.getConversationContext().set(name, returned);
    } else if (scope == Scope.APPLICATION) {
        if (reqContext.getApplicationContext() == null) {
            throw new IllegalStateException("No Application Context Exists");
        }
        reqContext.getApplicationContext().set(name, returned);
    }
    ((RequestContextImpl) context).setLastSetOrGet(name);
    return returned;
}
Also used : RequestContextImpl(org.drools.core.command.RequestContextImpl)

Example 4 with RequestContextImpl

use of org.drools.core.command.RequestContextImpl in project drools by kiegroup.

the class ApplyPmmlModelCommand method execute.

@Override
public PMML4Result execute(Context context) {
    PMML4Result resultHolder = new PMML4Result(requestData.getCorrelationId());
    RequestContextImpl ctx = (RequestContextImpl) context;
    KieBase kbase = ((RegistryContext) context).lookup(KieBase.class);
    if (kbase == null) {
        System.out.println("KieBase not found in context!");
        return null;
    } else {
        KieContainer kcont = ((KnowledgeBaseImpl) kbase).getKieContainer();
        kcont.getKieBaseNames().forEach(n -> {
            System.out.println(n);
        });
        kbase.getKiePackages().forEach(kp -> {
            System.out.println("Package: " + kp.getName());
        });
    }
    return null;
// RuleUnitExecutor executor = RuleUnitExecutor.create().bind(kbase);
// DataSource<PMMLRequestData> data = executor.newDataSource("request", this.requestData);
// DataSource<PMML4Result> resultData = executor.newDataSource("results", resultHolder);
// System.out.println("Setting result: "+resultHolder);
// ctx.lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, resultHolder);
// return resultHolder;
}
Also used : PMML4Result(org.kie.api.pmml.PMML4Result) KieBase(org.kie.api.KieBase) RequestContextImpl(org.drools.core.command.RequestContextImpl) RegistryContext(org.drools.core.command.impl.RegistryContext) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) KieContainer(org.kie.api.runtime.KieContainer)

Example 5 with RequestContextImpl

use of org.drools.core.command.RequestContextImpl in project drools by kiegroup.

the class GetCommand method execute.

@Override
public T execute(Context context) {
    RequestContextImpl reqContext = (RequestContextImpl) context;
    T object = null;
    if (reqContext.has(name)) {
        object = (T) reqContext.get(name);
        reqContext.setLastSetOrGet(name);
    }
    return object;
}
Also used : RequestContextImpl(org.drools.core.command.RequestContextImpl)

Aggregations

RequestContextImpl (org.drools.core.command.RequestContextImpl)6 RegistryContext (org.drools.core.command.impl.RegistryContext)3 Context (org.kie.api.runtime.Context)2 ExecutableBuilderImpl (org.drools.core.fluent.impl.ExecutableBuilderImpl)1 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)1 Test (org.junit.Test)1 KieBase (org.kie.api.KieBase)1 PMML4Result (org.kie.api.pmml.PMML4Result)1 KieContainer (org.kie.api.runtime.KieContainer)1 RequestContext (org.kie.api.runtime.RequestContext)1 ExecutableBuilder (org.kie.api.runtime.builder.ExecutableBuilder)1