Skip to content

Commit a56be48

Browse files
Updates to list and fetch individual library benefits
1 parent e28db75 commit a56be48

File tree

13 files changed

+196
-92
lines changed

13 files changed

+196
-92
lines changed

builder-api/src/main/java/org/acme/controller/DecisionResource.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import jakarta.ws.rs.core.Response;
1010

1111
import org.acme.auth.AuthUtils;
12-
import org.acme.enums.OptionalBoolean;
12+
import org.acme.enums.CheckResult;
1313
import org.acme.model.domain.Benefit;
1414
import org.acme.model.domain.CheckConfig;
1515
import org.acme.model.domain.EligibilityCheck;
@@ -20,6 +20,7 @@
2020
import org.acme.persistence.ScreenerRepository;
2121
import org.acme.persistence.StorageService;
2222
import org.acme.service.DmnService;
23+
import org.acme.service.LibraryApiService;
2324

2425
import java.util.*;
2526

@@ -41,6 +42,9 @@ public class DecisionResource {
4142
@Inject
4243
DmnService dmnService;
4344

45+
@Inject
46+
LibraryApiService libraryApi;
47+
4448
@POST
4549
@Path("/published/{screenerId}/evaluate")
4650
@Consumes(MediaType.APPLICATION_JSON)
@@ -124,15 +128,20 @@ private Map<String, Object> evaluateBenefit(Benefit benefit, Map<String, Object>
124128
return result;
125129
} else {
126130
// Custom benefit, evaluate here in the web app api (as opposed to calling the library api for evaluation)
127-
List<OptionalBoolean> checkResultsList = new ArrayList<>();
131+
List<CheckResult> checkResultsList = new ArrayList<>();
128132
Map<String, Object> checkResults = new HashMap<>();
129133

130134
int checkNum = 0;
131135
for (CheckConfig checkConfig : benefit.getChecks()) {
132136
String dmnFilepath = storageService.getCheckDmnModelPath(checkConfig.getCheckId());
133-
OptionalBoolean result = dmnService.evaluateDmn(
134-
dmnFilepath, checkConfig.getCheckName(), inputData, checkConfig.getParameters()
135-
);
137+
CheckResult result;
138+
if (isLibraryCheck(checkConfig)){
139+
result = libraryApi.evaluateCheck(checkConfig, inputData);
140+
} else {
141+
result = dmnService.evaluateDmn(
142+
dmnFilepath, checkConfig.getCheckName(), inputData, checkConfig.getParameters()
143+
);
144+
}
136145
checkResultsList.add(result);
137146

138147
String uniqueCheckKey = checkConfig.getCheckId() + checkNum;
@@ -141,16 +150,16 @@ private Map<String, Object> evaluateBenefit(Benefit benefit, Map<String, Object>
141150
}
142151

143152
// Determine overall Benefit result
144-
Boolean allChecksTrue = checkResultsList.stream().allMatch(result -> result == OptionalBoolean.TRUE);
145-
Boolean anyChecksFalse = checkResultsList.stream().anyMatch(result -> result == OptionalBoolean.FALSE);
153+
Boolean allChecksTrue = checkResultsList.stream().allMatch(result -> result == CheckResult.TRUE);
154+
Boolean anyChecksFalse = checkResultsList.stream().anyMatch(result -> result == CheckResult.FALSE);
146155

147-
OptionalBoolean benefitResult;
156+
CheckResult benefitResult;
148157
if (allChecksTrue) {
149-
benefitResult = OptionalBoolean.TRUE;
158+
benefitResult = CheckResult.TRUE;
150159
} else if (anyChecksFalse) {
151-
benefitResult = OptionalBoolean.FALSE;
160+
benefitResult = CheckResult.FALSE;
152161
} else {
153-
benefitResult = OptionalBoolean.UNABLE_TO_DETERMINE;
162+
benefitResult = CheckResult.UNABLE_TO_DETERMINE;
154163
}
155164

156165
return new HashMap<String, Object>(
@@ -192,7 +201,7 @@ public Response evaluateCheck(
192201
try {
193202
String dmnFilepath = storageService.getCheckDmnModelPath(check.getId());
194203

195-
OptionalBoolean result = dmnService.evaluateDmn(
204+
CheckResult result = dmnService.evaluateDmn(
196205
dmnFilepath, request.checkConfig.getCheckName(), request.inputData, request.checkConfig.getParameters()
197206
);
198207
return Response.ok().entity(Map.of("result", result)).build();
@@ -218,4 +227,9 @@ private boolean isUserAuthorizedToAccessScreenerByScreener(String userId, Screen
218227
}
219228
return false;
220229
}
230+
231+
private boolean isLibraryCheck(CheckConfig checkConfig){
232+
Character libraryCheckPrefix = 'L';
233+
return libraryCheckPrefix.equals(checkConfig.getCheckId().charAt(0));
234+
}
221235
}

builder-api/src/main/java/org/acme/controller/LibraryCheckResource.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import jakarta.inject.Inject;
44
import jakarta.ws.rs.*;
55
import jakarta.ws.rs.core.MediaType;
6+
import jakarta.ws.rs.core.Response;
67
import org.acme.model.domain.EligibilityCheck;
7-
import org.acme.service.LibraryApiMetadataService;
8+
import org.acme.service.LibraryApiService;
89

910
import java.util.List;
1011

@@ -13,7 +14,7 @@
1314
public class LibraryCheckResource {
1415

1516
@Inject
16-
LibraryApiMetadataService libraryApiMetadataService; // Inject the singleton bean
17+
LibraryApiService libraryApiMetadataService; // Inject the singleton bean
1718

1819
@GET
1920
@Path("/library-checks")
@@ -23,5 +24,18 @@ public List<EligibilityCheck> getLibraryChecks(@QueryParam("module") String modu
2324
}
2425
return libraryApiMetadataService.getAll();
2526
}
27+
28+
@GET
29+
@Path("/library-checks/{checkId}")
30+
public Response getLibraryCheck(@PathParam("checkId") String checkId) {
31+
if ( checkId != null) {
32+
List<EligibilityCheck> checks = libraryApiMetadataService.getById(checkId);
33+
if (checks.isEmpty()){
34+
return Response.status(Response.Status.NOT_FOUND).build();
35+
}
36+
return Response.ok().entity(checks.getFirst()).build();
37+
}
38+
return Response.status(Response.Status.NOT_FOUND).build();
39+
}
2640
}
2741

builder-api/src/main/java/org/acme/enums/OptionalBoolean.java renamed to builder-api/src/main/java/org/acme/enums/CheckResult.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package org.acme.enums;
22

3-
public enum OptionalBoolean {
3+
public enum CheckResult {
44
TRUE("TRUE"),
55
FALSE("FALSE"),
66
UNABLE_TO_DETERMINE("UNABLE_TO_DETERMINE");
77

88
public final String label;
99

10-
private OptionalBoolean(String label) {
10+
private CheckResult(String label) {
1111
this.label = label;
1212
}
1313
}

builder-api/src/main/java/org/acme/model/domain/CheckConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
public class CheckConfig {
99
private String checkId;
1010
private String checkName;
11+
// evaluation endpoint path for library checks
12+
private String path;
1113
private Map<String, Object> parameters;
1214

1315
public String getCheckId() {
@@ -33,4 +35,12 @@ public String getCheckName() {
3335
public void setCheckName(String checkName) {
3436
this.checkName = checkName;
3537
}
38+
39+
public String getPath() {
40+
return path;
41+
}
42+
43+
public void setPath(String path) {
44+
this.path = path;
45+
}
3646
}

builder-api/src/main/java/org/acme/model/domain/EligibilityCheck.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class EligibilityCheck {
2121
private String ownerId;
2222
@JsonProperty("isPublic")
2323
private Boolean isPublic;
24+
// API endpoint for evaluating library checks
25+
private String path;
2426

2527
public String getId() {
2628
return this.id;
@@ -117,4 +119,12 @@ public JsonNode getSituation() {
117119
public void setSituation(JsonNode situation) {
118120
this.situation = situation;
119121
}
122+
123+
public String getPath() {
124+
return path;
125+
}
126+
127+
public void setPath(String path) {
128+
this.path = path;
129+
}
120130
}

builder-api/src/main/java/org/acme/service/DmnService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package org.acme.service;
2-
import org.acme.enums.OptionalBoolean;
2+
import org.acme.enums.CheckResult;
33

44
import java.util.List;
55
import java.util.Map;
@@ -11,7 +11,7 @@ public List<String> validateDmnXml(
1111
String modelId,
1212
String requiredBooleanDecisionName
1313
) throws Exception;
14-
public OptionalBoolean evaluateDmn(
14+
public CheckResult evaluateDmn(
1515
String dmnFilePath,
1616
String dmnModelName,
1717
Map<String, Object> inputs,

builder-api/src/main/java/org/acme/service/KieDmnService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import io.quarkus.logging.Log;
44
import jakarta.enterprise.context.ApplicationScoped;
55
import jakarta.inject.Inject;
6-
import org.acme.enums.OptionalBoolean;
6+
import org.acme.enums.CheckResult;
77
import org.acme.persistence.StorageService;
88
import org.kie.api.KieServices;
99
import org.kie.api.builder.*;
@@ -133,7 +133,7 @@ private DmnCompilationResult compileDmnModel(String dmnXml, Map<String, String>
133133
return new DmnCompilationResult(kieModuleBytes, new ArrayList<String>());
134134
}
135135

136-
public OptionalBoolean evaluateDmn(
136+
public CheckResult evaluateDmn(
137137
String dmnFilePath,
138138
String dmnModelName,
139139
Map<String, Object> inputs,
@@ -189,13 +189,13 @@ public OptionalBoolean evaluateDmn(
189189
DMNDecisionResult decisionResult = decisionResults.get(0);
190190
Object result = decisionResult.getResult();
191191
if (result == null) {
192-
return OptionalBoolean.UNABLE_TO_DETERMINE;
192+
return CheckResult.UNABLE_TO_DETERMINE;
193193
}
194194
else if (result instanceof Boolean && (Boolean) result) {
195-
return OptionalBoolean.TRUE;
195+
return CheckResult.TRUE;
196196
}
197197
else if (result instanceof Boolean && !(Boolean) result) {
198-
return OptionalBoolean.FALSE;
198+
return CheckResult.FALSE;
199199
}
200200
throw new RuntimeException("Unexpected decision result type: " + result.getClass().getName());
201201
}

builder-api/src/main/java/org/acme/service/LibraryApiMetadataService.java renamed to builder-api/src/main/java/org/acme/service/LibraryApiService.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import jakarta.annotation.PostConstruct;
77
import jakarta.enterprise.context.ApplicationScoped;
88
import jakarta.inject.Inject;
9+
import org.acme.enums.CheckResult;
10+
import org.acme.model.domain.CheckConfig;
911
import org.acme.model.domain.EligibilityCheck;
1012
import org.acme.persistence.StorageService;
1113
import org.acme.persistence.FirestoreUtils;
@@ -16,7 +18,7 @@
1618

1719

1820
@ApplicationScoped
19-
public class LibraryApiMetadataService {
21+
public class LibraryApiService {
2022
@Inject
2123
private StorageService storageService;
2224

@@ -58,5 +60,15 @@ public List<EligibilityCheck> getByModule(String module) {
5860
.filter(e -> module.equals(e.getModule()))
5961
.toList();
6062
}
63+
64+
public List<EligibilityCheck> getById(String id) {
65+
return checks.stream()
66+
.filter(e -> id.equals(e.getId()))
67+
.toList();
68+
}
69+
70+
public CheckResult evaluateCheck(CheckConfig checkConfig, Map<String, Object> inputs){
71+
return CheckResult.TRUE;
72+
}
6173
}
6274

0 commit comments

Comments
 (0)