Search in sources :

Example 6 with ContextImpl

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

the class GetDMNModelCommandTest method init.

@Before
public void init() {
    registryContext = new ContextImpl();
    dmnRuntime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
}
Also used : ContextImpl(org.drools.core.command.impl.ContextImpl) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) Before(org.junit.Before)

Example 7 with ContextImpl

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

the class StatelessKnowledgeSessionImpl method execute.

public <T> T execute(Command<T> command) {
    StatefulKnowledgeSession ksession = newWorkingMemory();
    RegistryContext context = new ContextImpl().register(KieSession.class, ksession);
    try {
        if (command instanceof BatchExecutionCommand) {
            context.register(ExecutionResultImpl.class, new ExecutionResultImpl());
        }
        ((StatefulKnowledgeSessionImpl) ksession).startBatchExecution();
        Object o = ((ExecutableCommand) command).execute(context);
        // did the user take control of fireAllRules, if not we will auto execute
        boolean autoFireAllRules = true;
        if (command instanceof FireAllRulesCommand) {
            autoFireAllRules = false;
        } else if (command instanceof BatchExecutionCommandImpl) {
            for (Command nestedCmd : ((BatchExecutionCommandImpl) command).getCommands()) {
                if (nestedCmd instanceof FireAllRulesCommand) {
                    autoFireAllRules = false;
                    break;
                }
            }
        }
        if (autoFireAllRules) {
            ksession.fireAllRules();
        }
        if (command instanceof BatchExecutionCommand) {
            return (T) context.lookup(ExecutionResultImpl.class);
        } else {
            return (T) o;
        }
    } finally {
        ((StatefulKnowledgeSessionImpl) ksession).endBatchExecution();
        dispose(ksession);
    }
}
Also used : FireAllRulesCommand(org.drools.core.command.runtime.rule.FireAllRulesCommand) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) RegistryContext(org.kie.internal.command.RegistryContext) ContextImpl(org.drools.core.command.impl.ContextImpl) BatchExecutionCommandImpl(org.drools.core.command.runtime.BatchExecutionCommandImpl) FireAllRulesCommand(org.drools.core.command.runtime.rule.FireAllRulesCommand) ExecutableCommand(org.kie.api.command.ExecutableCommand) Command(org.kie.api.command.Command) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) ExecutableCommand(org.kie.api.command.ExecutableCommand)

Example 8 with ContextImpl

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

the class ConversationContextManager method startConversation.

public void startConversation(RequestContextImpl requestContext) {
    String conversationId = UUID.randomUUID().toString();
    ContextImpl ctx = new ContextImpl(conversationId, null);
    conversationContexts.put(conversationId, ctx);
    requestContext.setConversationContext(ctx);
}
Also used : ContextImpl(org.drools.core.command.impl.ContextImpl)

Example 9 with ContextImpl

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

the class ContextManagerImpl method createContext.

public Context createContext(String identifier) {
    Context ctx = this.contexts.get(identifier);
    if (ctx == null) {
        ctx = new ContextImpl(identifier, this, root);
        this.contexts.put(identifier, ctx);
    }
    return ctx;
}
Also used : Context(org.kie.api.runtime.Context) ContextImpl(org.drools.core.command.impl.ContextImpl)

Example 10 with ContextImpl

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

the class NewDMNRuntimeCommandTest method execute.

@Test
public void execute() {
    RegistryContext registryContext = new ContextImpl();
    NewDMNRuntimeCommand newDMNRuntimeCommand = new NewDMNRuntimeCommand();
    assertThatThrownBy(() -> newDMNRuntimeCommand.execute(registryContext)).isInstanceOf(IllegalStateException.class).hasMessage("There is no existing KieContainer assigned to the Registry");
    registryContext.register(KieContainer.class, new KieHelper().getKieContainer());
    newDMNRuntimeCommand.execute(registryContext);
    assertNotNull(registryContext.lookup(DMNRuntime.class));
}
Also used : KieHelper(org.kie.internal.utils.KieHelper) RegistryContext(org.kie.internal.command.RegistryContext) ContextImpl(org.drools.core.command.impl.ContextImpl) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) Test(org.junit.Test)

Aggregations

ContextImpl (org.drools.core.command.impl.ContextImpl)12 RegistryContext (org.kie.internal.command.RegistryContext)7 Test (org.junit.Test)6 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)3 DMNContextImpl (org.kie.dmn.core.impl.DMNContextImpl)3 DMNResultImpl (org.kie.dmn.core.impl.DMNResultImpl)3 BatchExecutionCommandImpl (org.drools.core.command.runtime.BatchExecutionCommandImpl)2 FireAllRulesCommand (org.drools.core.command.runtime.rule.FireAllRulesCommand)2 ExecutionResultImpl (org.drools.core.runtime.impl.ExecutionResultImpl)2 Before (org.junit.Before)2 BatchExecutionCommand (org.kie.api.command.BatchExecutionCommand)2 Command (org.kie.api.command.Command)2 DMNContext (org.kie.dmn.api.core.DMNContext)2 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)2 ExecutableCommand (org.drools.core.command.impl.ExecutableCommand)1 RegistryContext (org.drools.core.command.impl.RegistryContext)1 ExecutableCommand (org.kie.api.command.ExecutableCommand)1 Context (org.kie.api.runtime.Context)1 DMNDecisionResult (org.kie.dmn.api.core.DMNDecisionResult)1 DMNMessage (org.kie.dmn.api.core.DMNMessage)1