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);
}
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);
}
}
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);
}
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;
}
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));
}
Aggregations