Search in sources :

Example 1 with RegistryContext

use of org.kie.internal.command.RegistryContext in project drools by kiegroup.

the class ExecuteDMNCommand method execute.

@Override
public DMNResult execute(Context context) {
    RegistryContext registryContext = (RegistryContext) context;
    DMNModel activeModel = registryContext.lookup(DMNModel.class);
    DMNRuntime dmnRuntime = registryContext.lookup(DMNRuntime.class);
    DMNContext dmnContext = registryContext.lookup(DMNContext.class);
    if (activeModel == null) {
        throw new IllegalStateException("No DMN active model defined");
    }
    if (dmnRuntime == null) {
        throw new IllegalStateException("No DMNRuntime available");
    }
    if (dmnContext == null) {
        dmnContext = dmnRuntime.newContext();
    }
    DMNResult dmnResult = dmnRuntime.evaluateAll(activeModel, dmnContext);
    registryContext.register(DMNResult.class, dmnResult);
    // reset context
    registryContext.register(DMNContext.class, dmnRuntime.newContext());
    return dmnResult;
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) RegistryContext(org.kie.internal.command.RegistryContext) DMNModel(org.kie.dmn.api.core.DMNModel) DMNRuntime(org.kie.dmn.api.core.DMNRuntime)

Example 2 with RegistryContext

use of org.kie.internal.command.RegistryContext in project drools by kiegroup.

the class ExecuteDMNCommandTest method execute.

@Test
public void execute() {
    RegistryContext registryContext = new ContextImpl();
    ExecuteDMNCommand executeDMNCommand = new ExecuteDMNCommand();
    assertThatThrownBy(() -> executeDMNCommand.execute(registryContext)).isInstanceOf(IllegalStateException.class).hasMessage("No DMN active model defined");
    registryContext.register(DMNModel.class, new DMNModelImpl(null));
    assertThatThrownBy(() -> executeDMNCommand.execute(registryContext)).isInstanceOf(IllegalStateException.class).hasMessage("No DMNRuntime available");
    DMNContext dmnContext = DMNFactory.newContext();
    dmnContext.set("example", 10);
    registryContext.register(DMNRuntime.class, new DMNRuntimeImpl(new VoidDMNRuntimeKB()));
    registryContext.register(DMNContext.class, dmnContext);
    DMNResult result = executeDMNCommand.execute(registryContext);
    assertNotNull(result);
    DMNContext newDmnContext = registryContext.lookup(DMNContext.class);
    assertEquals(1, dmnContext.getAll().size());
    assertEquals(0, newDmnContext.getAll().size());
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNRuntimeImpl(org.kie.dmn.core.impl.DMNRuntimeImpl) DMNContext(org.kie.dmn.api.core.DMNContext) RegistryContext(org.kie.internal.command.RegistryContext) DMNModelImpl(org.kie.dmn.core.impl.DMNModelImpl) ContextImpl(org.drools.core.command.impl.ContextImpl) VoidDMNRuntimeKB(org.kie.dmn.core.impl.VoidDMNRuntimeKB) Test(org.junit.Test)

Example 3 with RegistryContext

use of org.kie.internal.command.RegistryContext in project drools by kiegroup.

the class NewDMNRuntimeCommand method execute.

@Override
public DMNRuntime execute(Context context) {
    RegistryContext registryContext = (RegistryContext) context;
    KieContainer kieContainer = registryContext.lookup(KieContainer.class);
    if (kieContainer == null) {
        throw new IllegalStateException("There is no existing KieContainer assigned to the Registry");
    }
    DMNRuntime dmnRuntime = KieRuntimeFactory.of(kieContainer.getKieBase()).get(DMNRuntime.class);
    registryContext.register(DMNRuntime.class, dmnRuntime);
    return dmnRuntime;
}
Also used : RegistryContext(org.kie.internal.command.RegistryContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) KieContainer(org.kie.api.runtime.KieContainer)

Example 4 with RegistryContext

use of org.kie.internal.command.RegistryContext in project drools by kiegroup.

the class SetDMNInputCommand method execute.

@Override
public Void execute(Context context) {
    RegistryContext registryContext = (RegistryContext) context;
    DMNContext dmnContext = registryContext.computeIfAbsent(DMNContext.class, clazz -> {
        DMNRuntime dmnRuntime = registryContext.lookup(DMNRuntime.class);
        return dmnRuntime != null ? dmnRuntime.newContext() : DMNFactory.newContext();
    });
    dmnContext.set(name, value);
    return null;
}
Also used : DMNContext(org.kie.dmn.api.core.DMNContext) RegistryContext(org.kie.internal.command.RegistryContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime)

Example 5 with RegistryContext

use of org.kie.internal.command.RegistryContext in project drools by kiegroup.

the class AbstractDMNModelCommand method getDMNModel.

protected DMNModel getDMNModel(Context context) {
    RegistryContext registryContext = (RegistryContext) context;
    DMNRuntime dmnRuntime = registryContext.lookup(DMNRuntime.class);
    if (dmnRuntime == null) {
        throw new IllegalStateException("There is no DMNRuntime available");
    }
    return retrieveDMNModel(dmnRuntime);
}
Also used : RegistryContext(org.kie.internal.command.RegistryContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime)

Aggregations

RegistryContext (org.kie.internal.command.RegistryContext)126 KieSession (org.kie.api.runtime.KieSession)106 ExecutionResultImpl (org.drools.core.runtime.impl.ExecutionResultImpl)37 Context (org.kie.api.runtime.Context)27 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)27 ArrayList (java.util.ArrayList)17 FactHandle (org.kie.api.runtime.rule.FactHandle)16 Test (org.junit.Test)14 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)13 List (java.util.List)12 CaseEventSupport (org.jbpm.casemgmt.impl.event.CaseEventSupport)12 EntryPoint (org.kie.api.runtime.rule.EntryPoint)12 Map (java.util.Map)11 HashMap (java.util.HashMap)10 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)9 ExecutableCommand (org.kie.api.command.ExecutableCommand)9 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)8 NodeInstance (org.kie.api.runtime.process.NodeInstance)8 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)8 Collection (java.util.Collection)7