-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
66 lines (46 loc) · 2.67 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.redhat.demos.dm.insurance_pricing_dmn;
import org.kie.dmn.api.core.DMNContext;
import org.kie.dmn.api.core.DMNDecisionResult;
import org.kie.dmn.api.core.DMNResult;
import org.kie.server.api.model.ServiceResponse;
import org.kie.server.client.CredentialsProvider;
import org.kie.server.client.DMNServicesClient;
import org.kie.server.client.KieServicesClient;
import org.kie.server.client.KieServicesConfiguration;
import org.kie.server.client.KieServicesFactory;
import org.kie.server.client.credentials.EnteredCredentialsProvider;
/**
* KIE-Server client example for the Insurance Pricing DMN demo that can be found here: https://github.com/jbossdemocentral/rhdm7-insurance-pricing-dmn-demo
*
* Shows how the KIE-Server client API can be used to execute DMN models deployed on the execution server.
*
* @author <a href="mailto:duncan.doyle@redhat.com">Duncan Doyle</a>
*/
public class Main {
private static final String KIE_SERVER_URL = "http://localhost:8080/kie-server/services/rest/server";
private static final String USERNAME = "kieserver";
private static final String PASSWORD = "kieserver1!";
private static final String DMN_MODEL_NAMESPACE = "http://www.trisotech.com/definitions/_bb8b9304-b29f-462e-9f88-03d0d868aec5";
private static final String DMN_MODEL_NAME = "Insurance Pricing";
private static final String CONTAINER_ID = "insurance-pricing-dmn_1.0.0";
public static void main(String[] args) {
CredentialsProvider credentialsProvider = new EnteredCredentialsProvider(USERNAME, PASSWORD);
KieServicesConfiguration kieServicesConfig = KieServicesFactory.newRestConfiguration(KIE_SERVER_URL, credentialsProvider);
KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(kieServicesConfig);
// Get the DMN Services Client.
DMNServicesClient dmnServicesClient = kieServicesClient.getServicesClient(DMNServicesClient.class);
/*
* Create a DMNContext and set the "Age" and "had previous incidents"
* The "Age" should be set to 23, "had previous incidents" should be set to false.
*/
DMNContext dmnContext = dmnServicesClient.newContext();
dmnContext.set("Age", 23);
dmnContext.set("had previous incidents", false);
// Retrieve the DMNResult by evaluating the DMN Model.
ServiceResponse<DMNResult> dmnResultResponse = dmnServicesClient.evaluateAll(CONTAINER_ID, DMN_MODEL_NAMESPACE, DMN_MODEL_NAME, dmnContext);
// Retrieve the DMNDecisionResult "Insurance Total Price"
DMNDecisionResult decisionResult = dmnResultResponse.getResult().getDecisionResultByName("Insurance Total Price");
// Print the result:
System.out.println("Insurance Total Price: " + decisionResult.getResult());
}
}