Skip to content

Commit 54ac595

Browse files
update checkConfig and EvaluationResult name change
1 parent a56be48 commit 54ac595

File tree

9 files changed

+39
-68
lines changed

9 files changed

+39
-68
lines changed

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

Lines changed: 18 additions & 16 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.CheckResult;
12+
import org.acme.enums.EvaluationResult;
1313
import org.acme.model.domain.Benefit;
1414
import org.acme.model.domain.CheckConfig;
1515
import org.acme.model.domain.EligibilityCheck;
@@ -128,44 +128,46 @@ private Map<String, Object> evaluateBenefit(Benefit benefit, Map<String, Object>
128128
return result;
129129
} else {
130130
// Custom benefit, evaluate here in the web app api (as opposed to calling the library api for evaluation)
131-
List<CheckResult> checkResultsList = new ArrayList<>();
131+
List<EvaluationResult> resultsList = new ArrayList<>();
132132
Map<String, Object> checkResults = new HashMap<>();
133133

134134
int checkNum = 0;
135135
for (CheckConfig checkConfig : benefit.getChecks()) {
136136
String dmnFilepath = storageService.getCheckDmnModelPath(checkConfig.getCheckId());
137-
CheckResult result;
137+
EvaluationResult evaluationResult;
138138
if (isLibraryCheck(checkConfig)){
139-
result = libraryApi.evaluateCheck(checkConfig, inputData);
139+
EligibilityCheck check = libraryApi.getById(checkConfig.getCheckId());
140+
String path = check.getPath();
141+
evaluationResult = libraryApi.evaluateCheck(checkConfig, path, inputData);
140142
} else {
141-
result = dmnService.evaluateDmn(
143+
evaluationResult = dmnService.evaluateDmn(
142144
dmnFilepath, checkConfig.getCheckName(), inputData, checkConfig.getParameters()
143145
);
144146
}
145-
checkResultsList.add(result);
147+
resultsList.add(evaluationResult);
146148

147149
String uniqueCheckKey = checkConfig.getCheckId() + checkNum;
148-
checkResults.put(uniqueCheckKey, Map.of("name", checkConfig.getCheckName(), "result", result));
150+
checkResults.put(uniqueCheckKey, Map.of("name", checkConfig.getCheckName(), "result", evaluationResult));
149151
checkNum += 1;
150152
}
151153

152154
// Determine overall Benefit result
153-
Boolean allChecksTrue = checkResultsList.stream().allMatch(result -> result == CheckResult.TRUE);
154-
Boolean anyChecksFalse = checkResultsList.stream().anyMatch(result -> result == CheckResult.FALSE);
155+
Boolean allChecksTrue = resultsList.stream().allMatch(evaluationResult -> evaluationResult == EvaluationResult.TRUE);
156+
Boolean anyChecksFalse = resultsList.stream().anyMatch(evaluationResult -> evaluationResult == EvaluationResult.FALSE);
155157

156-
CheckResult benefitResult;
158+
EvaluationResult benefitEvaluationResult;
157159
if (allChecksTrue) {
158-
benefitResult = CheckResult.TRUE;
160+
benefitEvaluationResult = EvaluationResult.TRUE;
159161
} else if (anyChecksFalse) {
160-
benefitResult = CheckResult.FALSE;
162+
benefitEvaluationResult = EvaluationResult.FALSE;
161163
} else {
162-
benefitResult = CheckResult.UNABLE_TO_DETERMINE;
164+
benefitEvaluationResult = EvaluationResult.UNABLE_TO_DETERMINE;
163165
}
164166

165167
return new HashMap<String, Object>(
166168
Map.of(
167169
"name", benefit.getName(),
168-
"result", benefitResult,
170+
"result", benefitEvaluationResult,
169171
"check_results", checkResults
170172
)
171173
);
@@ -201,10 +203,10 @@ public Response evaluateCheck(
201203
try {
202204
String dmnFilepath = storageService.getCheckDmnModelPath(check.getId());
203205

204-
CheckResult result = dmnService.evaluateDmn(
206+
EvaluationResult evaluationResult = dmnService.evaluateDmn(
205207
dmnFilepath, request.checkConfig.getCheckName(), request.inputData, request.checkConfig.getParameters()
206208
);
207-
return Response.ok().entity(Map.of("result", result)).build();
209+
return Response.ok().entity(Map.of("evaluationResult", evaluationResult)).build();
208210
} catch (Exception e) {
209211
Log.error("Error: " + e.getMessage());
210212
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public List<EligibilityCheck> getLibraryChecks(@QueryParam("module") String modu
2929
@Path("/library-checks/{checkId}")
3030
public Response getLibraryCheck(@PathParam("checkId") String checkId) {
3131
if ( checkId != null) {
32-
List<EligibilityCheck> checks = libraryApiMetadataService.getById(checkId);
33-
if (checks.isEmpty()){
32+
EligibilityCheck check = libraryApiMetadataService.getById(checkId);
33+
if (check == null){
3434
return Response.status(Response.Status.NOT_FOUND).build();
3535
}
36-
return Response.ok().entity(checks.getFirst()).build();
36+
return Response.ok().entity(check).build();
3737
}
3838
return Response.status(Response.Status.NOT_FOUND).build();
3939
}

builder-api/src/main/java/org/acme/enums/CheckResult.java renamed to builder-api/src/main/java/org/acme/enums/EvaluationResult.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 CheckResult {
3+
public enum EvaluationResult {
44
TRUE("TRUE"),
55
FALSE("FALSE"),
66
UNABLE_TO_DETERMINE("UNABLE_TO_DETERMINE");
77

88
public final String label;
99

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

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

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

1513
public String getCheckId() {
@@ -35,12 +33,4 @@ public String getCheckName() {
3533
public void setCheckName(String checkName) {
3634
this.checkName = checkName;
3735
}
38-
39-
public String getPath() {
40-
return path;
41-
}
42-
43-
public void setPath(String path) {
44-
this.path = path;
45-
}
4636
}

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

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import jakarta.annotation.PostConstruct;
77
import jakarta.enterprise.context.ApplicationScoped;
88
import jakarta.inject.Inject;
9-
import org.acme.enums.CheckResult;
9+
import org.acme.enums.EvaluationResult;
1010
import org.acme.model.domain.CheckConfig;
1111
import org.acme.model.domain.EligibilityCheck;
1212
import org.acme.persistence.StorageService;
@@ -61,14 +61,18 @@ public List<EligibilityCheck> getByModule(String module) {
6161
.toList();
6262
}
6363

64-
public List<EligibilityCheck> getById(String id) {
65-
return checks.stream()
64+
public EligibilityCheck getById(String id) {
65+
List<EligibilityCheck> matches = checks.stream()
6666
.filter(e -> id.equals(e.getId()))
6767
.toList();
68+
if (matches.isEmpty()) {
69+
return null;
70+
}
71+
return matches.getFirst();
6872
}
6973

70-
public CheckResult evaluateCheck(CheckConfig checkConfig, Map<String, Object> inputs){
71-
return CheckResult.TRUE;
74+
public EvaluationResult evaluateCheck(CheckConfig checkConfig, String path, Map<String, Object> inputs){
75+
return EvaluationResult.TRUE;
7276
}
7377
}
7478

builder-frontend/src/api/check.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,6 @@ export const fetchPublicChecks = async (): Promise<EligibilityCheck[]> => {
2525
}
2626
};
2727

28-
// export const fetchCheck = async (
29-
// checkId: string
30-
// ): Promise<EligibilityCheck> => {
31-
// const url = apiUrl + `/library-checks/${checkId}`;
32-
// try {
33-
// const response = await authFetch(url, {
34-
// method: "GET",
35-
// headers: {
36-
// Accept: "application/json",
37-
// },
38-
// });
39-
40-
// if (!response.ok) {
41-
// throw new Error(`Fetch failed with status: ${response.status}`);
42-
// }
43-
// const data = await response.json();
44-
// console.log("Fetched check:", data);
45-
// return data;
46-
// } catch (error) {
47-
// console.error("Error fetching check:", error);
48-
// throw error; // rethrow so you can handle it in your component if needed
49-
// }
50-
// };
51-
5228
export const fetchCheck = async (
5329
checkId: string
5430
): Promise<EligibilityCheck> => {

builder-frontend/src/components/project/manageBenefits/configureBenefit/EligibilityCheckListView.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ const EligibilityCheckListView = ({
5656
const checkConfig: CheckConfig = {
5757
checkId: check.id,
5858
checkName: check.name,
59-
path: check.path,
6059
parameters: {},
6160
};
6261
addCheck(checkConfig);

0 commit comments

Comments
 (0)