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