Java
Project Information
- Repository: github.com/QuantumDMN/dmn-java-sdk
Installation
Add the dependency to your pom.xml:
<dependency>
<groupId>com.quantumdmn</groupId>
<artifactId>dmn-sdk</artifactId>
<version>1.0.0</version>
</dependency>
Usage
import com.quantumdmn.client.DmnEngine;
import com.quantumdmn.client.DmnService;
import com.quantumdmn.client.model.EvaluationResult;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.HashMap;
public class Example {
public static void main(String[] args) throws Exception {
// Configuration
String keyFile = "path/to/service-user.json";
String projectId = "YOUR_DMN_PROJECT_ID";
String definitionId = "YOUR_DEFINITION_ID";
String authProjectId = "YOUR_ZITADEL_PROJECT_ID";
String apiUrl = "https://api.quantumdmn.com";
// Set system properties for configuration
System.setProperty("quantumdmn.auth.zitadel.key-file", keyFile);
System.setProperty("quantumdmn.auth.zitadel.project-id", authProjectId);
System.setProperty("quantumdmn.base-url", apiUrl);
// Initialize Service
DmnService dmnService = new DmnService();
// Create Engine
DmnEngine engine = new DmnEngine(dmnService, projectId);
// Prepare Context
Map<String, Object> context = new HashMap<>();
context.put("RequestedAmt", 1000);
// Evaluate
try {
Map<String, EvaluationResult> results = engine.evaluate(definitionId, null, context);
System.out.println("Result:");
for (Map.Entry<String, EvaluationResult> entry : results.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue().getValue());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Spring Boot Support
If you are using Spring Boot, you can configure the SDK using your application.properties or application.yml file and inject the DmnService directly.
application.properties:
quantumdmn.auth.zitadel.key-file=path/to/service-user.json
quantumdmn.auth.zitadel.project-id=YOUR_ZITADEL_PROJECT_ID
quantumdmn.base-url=https://api.quantumdmn.com
Java Code:
@Service
public class MyService {
private final DmnService dmnService;
public MyService(DmnService dmnService) {
this.dmnService = dmnService;
}
public void evaluateDecision(String projectId, String definitionId, Map<String, Object> context) {
DmnEngine engine = new DmnEngine(dmnService, projectId);
try {
Map<String, EvaluationResult> results = engine.evaluate(definitionId, null, context);
// Process results...
} catch (Exception e) {
// Handle error...
}
}
}