use of org.kie.server.client.DMNServicesClient in project droolsjbpm-integration by kiegroup.
the class RemoteBusinessRuleTaskHandler method executeWorkItem.
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
Map<String, Object> parameters = new HashMap<>(workItem.getParameters());
String containerId = (String) parameters.remove("ContainerId");
if (containerId == null || containerId.isEmpty()) {
throw new IllegalArgumentException("Container ID is required for remote BusinessRuleTask");
}
String language = (String) parameters.remove("Language");
if (language == null) {
language = DRL_LANG;
}
String kieSessionName = (String) parameters.remove("KieSessionName");
// remove engine specific parameters
parameters.remove("TaskName");
parameters.remove("KieSessionType");
Map<String, Object> results = new HashMap<>();
logger.debug("Facts to be inserted into working memory {}", parameters);
if (DRL_LANG.equalsIgnoreCase(language)) {
RuleServicesClient ruleClient = client.getServicesClient(RuleServicesClient.class);
List<Command<?>> commands = new ArrayList<Command<?>>();
BatchExecutionCommand executionCommand = commandsFactory.newBatchExecution(commands, kieSessionName);
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
String inputKey = workItem.getId() + "_" + entry.getKey();
commands.add(commandsFactory.newInsert(entry.getValue(), inputKey, true, null));
}
commands.add(commandsFactory.newFireAllRules("Fired"));
ServiceResponse<ExecutionResults> reply = ruleClient.executeCommandsWithResults(containerId, executionCommand);
if (ServiceResponse.ResponseType.FAILURE.equals(reply.getType())) {
throw new KieServicesException(reply.getMsg());
}
ExecutionResults executionResults = reply.getResult();
logger.debug("{} rules fired", executionResults.getValue("Fired"));
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
String inputKey = workItem.getId() + "_" + entry.getKey();
String key = entry.getKey().replaceAll(workItem.getId() + "_", "");
results.put(key, executionResults.getValue(inputKey));
}
} else if (DMN_LANG.equalsIgnoreCase(language)) {
String namespace = (String) parameters.remove("Namespace");
String model = (String) parameters.remove("Model");
String decision = (String) parameters.remove("Decision");
DMNServicesClient dmnClient = client.getServicesClient(DMNServicesClient.class);
DMNContext dmnContext = dmnClient.newContext();
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
dmnContext.set(entry.getKey(), entry.getValue());
}
ServiceResponse<DMNResult> evaluationResult = null;
if (decision != null) {
evaluationResult = dmnClient.evaluateDecisionByName(containerId, namespace, model, decision, dmnContext);
} else {
evaluationResult = dmnClient.evaluateAll(containerId, namespace, model, dmnContext);
}
DMNResult dmnResult = evaluationResult.getResult();
results.putAll(dmnResult.getContext().getAll());
} else {
throw new IllegalArgumentException("Not supported language type " + language);
}
logger.debug("Facts retrieved from working memory {}", results);
workItemManager.completeWorkItem(workItem.getId(), results);
}
use of org.kie.server.client.DMNServicesClient in project businessautomation-cop by redhat-cop.
the class RulesApiImpl method canOpenAccount.
@Override
public CanOpenAccountResults canOpenAccount(final Customer customer) {
final DMNServicesClient dmnClient = kieServicesClient.getServicesClient(DMNServicesClient.class);
final DMNContext dmnContext = dmnClient.newContext();
dmnContext.set("customer", customer);
final ServiceResponse<DMNResult> serviceResponse = dmnClient.evaluateAll(CONTAINER_ID, NAMESPACE, MODEL_NAME, dmnContext);
final DMNResult dmnResult = serviceResponse.getResult();
return extractResult(dmnResult);
}
use of org.kie.server.client.DMNServicesClient in project businessautomation-cop by redhat-cop.
the class RulesApiImpl method canOpenAccount.
@Override
public CanOpenAccountResults canOpenAccount(final Customer customer) {
final DMNServicesClient dmnClient = kieServicesClient.getServicesClient(DMNServicesClient.class);
final DMNContext dmnContext = dmnClient.newContext();
dmnContext.set("customer", customer);
final ServiceResponse<DMNResult> serviceResponse = dmnClient.evaluateAll(CONTAINER_ID, NAMESPACE, MODEL_NAME, dmnContext);
final DMNResult dmnResult = serviceResponse.getResult();
return extractResult(dmnResult);
}
use of org.kie.server.client.DMNServicesClient in project businessautomation-cop by redhat-cop.
the class RulesApiImpl method canOpenAccount.
@Override
public CanOpenAccountResults canOpenAccount(final Customer customer) {
final DMNServicesClient dmnClient = kieServicesClient.getServicesClient(DMNServicesClient.class);
final DMNContext dmnContext = dmnClient.newContext();
dmnContext.set("customer", customer);
final ServiceResponse<DMNResult> serviceResponse = dmnClient.evaluateAll(CONTAINER_ID, NAMESPACE, MODEL_NAME, dmnContext);
final DMNResult dmnResult = serviceResponse.getResult();
return extractResult(dmnResult);
}
use of org.kie.server.client.DMNServicesClient in project kiegroup-examples by tkobayas.
the class DMNTest method testProcess.
// private static final MarshallingFormat FORMAT = MarshallingFormat.JSON;
// private static final MarshallingFormat FORMAT = MarshallingFormat.JAXB;
@Test
public void testProcess() {
KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(BASE_URL, USERNAME, PASSWORD);
// config.setMarshallingFormat(FORMAT);
// HashSet<Class<?>> classes = new HashSet<Class<?>>();
// classes.add(Person.class);
//
// config.addExtraClasses(classes);
KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(config);
DMNServicesClient dmnClient = kieServicesClient.getServicesClient(DMNServicesClient.class);
DMNContext dmnContext = dmnClient.newContext();
Map<String, Object> driverMap = new HashMap<>();
driverMap.put("Points", 2);
dmnContext.set("Driver", driverMap);
Map<String, Object> violationMap = new HashMap<>();
violationMap.put("Type", "speed");
violationMap.put("Actual Speed", 120);
violationMap.put("Speed Limit", 100);
dmnContext.set("Violation", violationMap);
ServiceResponse<DMNResult> serverResp = dmnClient.evaluateAll(CONTAINER_ID, "https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF", "Traffic Violation", dmnContext);
DMNResult dmnResult = serverResp.getResult();
for (DMNDecisionResult dr : dmnResult.getDecisionResults()) {
System.out.println("Decision: '" + dr.getDecisionName() + "', " + "Result: " + dr.getResult());
}
}
Aggregations