Skip to content

Commit 5d51a37

Browse files
Merge pull request #226 from CodeForPhilly/update-custom-check-form-keys
feat: Updated Custom Checks to accept inputs from the FormEditor that begin with 'custom.'
2 parents f1e21e5 + a59f066 commit 5d51a37

File tree

4 files changed

+17
-84
lines changed

4 files changed

+17
-84
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public Response evaluatePublishedScreener(
8787
public Response evaluateScreener(
8888
@Context SecurityIdentity identity,
8989
@QueryParam("screenerId") String screenerId,
90-
Map<String, Object> inputData
90+
Map<String, Object> formData
9191
) throws Exception {
9292
// Authorize user and get benefit
9393
String userId = AuthUtils.getUserId(identity);
@@ -111,7 +111,7 @@ public Response evaluateScreener(
111111
//TODO: consider ways of processing benefits in parallel
112112
for (Benefit benefit : benefits) {
113113
// Evaluate benefit
114-
Map<String, Object> benefitResults = evaluateBenefit(benefit, inputData);
114+
Map<String, Object> benefitResults = evaluateBenefit(benefit, formData);
115115
screenerResults.put(benefit.getId(), benefitResults);
116116
}
117117
return Response.ok().entity(screenerResults).build();
@@ -121,8 +121,8 @@ public Response evaluateScreener(
121121
}
122122
}
123123

124-
private Map<String, Object> evaluateBenefit(Benefit benefit, Map<String, Object> inputData) throws Exception {
125-
if (benefit.getPublic()){
124+
private Map<String, Object> evaluateBenefit(Benefit benefit, Map<String, Object> formData) throws Exception {
125+
if (benefit.getPublic()) {
126126
// Public benefit, call the Library API to evaluate
127127
Map<String, Object> result = new HashMap<>();
128128
return result;
@@ -138,10 +138,14 @@ private Map<String, Object> evaluateBenefit(Benefit benefit, Map<String, Object>
138138
if (isLibraryCheck(checkConfig)){
139139
EligibilityCheck check = libraryApi.getById(checkConfig.getCheckId());
140140
String path = check.getPath();
141-
evaluationResult = libraryApi.evaluateCheck(checkConfig, path, inputData);
141+
evaluationResult = libraryApi.evaluateCheck(checkConfig, path, formData);
142142
} else {
143+
Map<String, Object> customFormValues = (Map<String, Object>) formData.get("custom");
144+
if (customFormValues == null) {
145+
customFormValues = new HashMap<String, Object>();
146+
}
143147
evaluationResult = dmnService.evaluateDmn(
144-
dmnFilepath, checkConfig.getCheckName(), inputData, checkConfig.getParameters()
148+
dmnFilepath, checkConfig.getCheckName(), customFormValues, checkConfig.getParameters()
145149
);
146150
}
147151
resultsList.add(evaluationResult);
@@ -178,7 +182,7 @@ private Map<String, Object> evaluateBenefit(Benefit benefit, Map<String, Object>
178182
@Path("/decision/working-check")
179183
@Consumes(MediaType.APPLICATION_JSON)
180184
@Produces(MediaType.APPLICATION_JSON)
181-
public Response evaluateCheck(
185+
public Response evaluateCustomCheck(
182186
@Context SecurityIdentity identity,
183187
@QueryParam("checkId") String checkId,
184188
EvaluateCheckRequest request

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

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -32,81 +32,6 @@ public class EligibilityCheckResource {
3232
@Inject
3333
DmnService dmnService;
3434

35-
@GET
36-
@Path("/checks")
37-
public Response getPublicChecks(@Context SecurityIdentity identity) {
38-
String userId = AuthUtils.getUserId(identity);
39-
if (userId == null) {
40-
return Response.status(Response.Status.UNAUTHORIZED).build();
41-
}
42-
Log.info("Fetching all eligibility checks. User: " + userId);
43-
List<EligibilityCheck> checks = eligibilityCheckRepository.getPublicChecks();
44-
45-
return Response.ok(checks, MediaType.APPLICATION_JSON).build();
46-
}
47-
48-
@GET
49-
@Path("/checks/{checkId}")
50-
public Response getPublicCheck(@Context SecurityIdentity identity, @PathParam("checkId") String checkId) {
51-
String userId = AuthUtils.getUserId(identity);
52-
if (userId == null){
53-
return Response.status(Response.Status.UNAUTHORIZED).build();
54-
}
55-
Log.info("Fetching all eligibility checks. User: " + userId);
56-
Optional<EligibilityCheck> checkOpt = eligibilityCheckRepository.getPublicCheck(checkId);
57-
58-
if (checkOpt.isEmpty()){
59-
return Response.status(Response.Status.NOT_FOUND).build();
60-
}
61-
62-
EligibilityCheck check = checkOpt.get();
63-
64-
if (!check.getPublic() && !check.getOwnerId().equals(userId)){
65-
return Response.status(Response.Status.UNAUTHORIZED).build();
66-
}
67-
return Response.ok(check, MediaType.APPLICATION_JSON).build();
68-
}
69-
70-
// Utility endpoint, public checks come from the Library API schema and shouldn't usually be created through the app
71-
@POST
72-
@Path("/checks")
73-
public Response createPublicCheck(@Context SecurityIdentity identity,
74-
EligibilityCheck newCheck) {
75-
String userId = AuthUtils.getUserId(identity);
76-
77-
// TODO: Add validations for user provided data
78-
newCheck.setOwnerId(userId);
79-
newCheck.setPublic(true);
80-
newCheck.setVersion(0);
81-
try {
82-
String checkId = eligibilityCheckRepository.savePublicCheck(newCheck);
83-
return Response.ok(newCheck, MediaType.APPLICATION_JSON).build();
84-
} catch (Exception e){
85-
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
86-
.entity(Map.of("error", "Could not save Check"))
87-
.build();
88-
}
89-
}
90-
91-
// Utility endpoint, public checks are static and come from the library api schema
92-
// and usually should not be updated through the app
93-
@PUT
94-
@Path("/checks")
95-
public Response updatePublicCheck(@Context SecurityIdentity identity,
96-
EligibilityCheck updateCheck){
97-
String userId = AuthUtils.getUserId(identity);
98-
99-
// TODO: Add authorization to update check
100-
try {
101-
eligibilityCheckRepository.savePublicCheck(updateCheck);
102-
return Response.ok().entity(updateCheck).build();
103-
} catch (Exception e){
104-
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
105-
.entity(Map.of("error", "could not update Check"))
106-
.build();
107-
}
108-
}
109-
11035
@POST
11136
@Consumes(MediaType.APPLICATION_JSON)
11237
@Path("/save-check-dmn")

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ public EvaluationResult evaluateDmn(
170170
// Prepare model and context using inputs
171171
DMNModel dmnModel = dmnModels.get(0);
172172
DMNContext context = dmnRuntime.newContext();
173-
context.set("inputs", inputs);
173+
174+
for (Map.Entry<String, Object> input : inputs.entrySet()) {
175+
context.set(input.getKey(), input.getValue());
176+
}
174177
context.set("parameters", parameters);
175178
DMNResult dmnResult = dmnRuntime.evaluateAll(dmnModel, context);
176179

builder-frontend/src/api/check.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export const fetchPublicChecks = async (): Promise<EligibilityCheck[]> => {
2121
return data;
2222
} catch (error) {
2323
console.error("Error fetching checks:", error);
24-
throw error; // rethrow so you can handle it in your component if needed
24+
// TODO: handle error appropriately
25+
return [];
2526
}
2627
};
2728

0 commit comments

Comments
 (0)