Skip to content

Commit bfb9ad7

Browse files
Merge pull request #228 from CodeForPhilly/update_evaluation_of_library_checks
Update checkConfig class and to benefit configuration flows to use checkConfig
2 parents e2f8716 + 6313a67 commit bfb9ad7

File tree

20 files changed

+382
-282
lines changed

20 files changed

+382
-282
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ private Map<String, Object> evaluateBenefit(Benefit benefit, Map<String, Object>
136136
String dmnFilepath = storageService.getCheckDmnModelPath(checkConfig.getCheckId());
137137
EvaluationResult evaluationResult;
138138
if (isLibraryCheck(checkConfig)){
139-
EligibilityCheck check = libraryApi.getById(checkConfig.getCheckId());
140-
String path = check.getPath();
141-
evaluationResult = libraryApi.evaluateCheck(checkConfig, path, formData);
139+
140+
String evaluationUrl = checkConfig.getEvaluationUrl();
141+
evaluationResult = libraryApi.evaluateCheck(checkConfig, evaluationUrl, formData);
142142
} else {
143143
Map<String, Object> customFormValues = (Map<String, Object>) formData.get("custom");
144144
if (customFormValues == null) {

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ public Response createCustomCheck(@Context SecurityIdentity identity,
185185
//TODO: Add validations for user provided data
186186
newCheck.setOwnerId(userId);
187187
newCheck.setPublic(false);
188-
newCheck.setVersion(0);
188+
if (newCheck.getVersion().isEmpty()){
189+
newCheck.setVersion("1.0.0");
190+
}
189191
try {
190192
eligibilityCheckRepository.saveNewWorkingCustomCheck(newCheck);
191193
return Response.ok(newCheck, MediaType.APPLICATION_JSON).build();
@@ -242,7 +244,7 @@ public Response publishCustomCheck(@Context SecurityIdentity identity, @PathPara
242244
}
243245

244246
// Update workingCheck so that the incremented version number is saved
245-
check.setVersion(check.getVersion() + 1);
247+
check.setVersion(incrementMajorVersion(check.getVersion()));
246248
try {
247249
eligibilityCheckRepository.updateWorkingCustomCheck(check);
248250
} catch (Exception e){
@@ -272,6 +274,24 @@ public Response publishCustomCheck(@Context SecurityIdentity identity, @PathPara
272274
return Response.ok(check, MediaType.APPLICATION_JSON).build();
273275
}
274276

277+
private String incrementMajorVersion(String version) {
278+
int[] v = normalize(version);
279+
v[0]++; // increment major
280+
v[1] = 0; // reset minor
281+
v[2] = 0; // reset patch
282+
return v[0] + "." + v[1] + "." + v[2];
283+
}
284+
285+
private int[] normalize(String version) {
286+
String[] parts = version.split("\\.");
287+
int[] nums = new int[]{0, 0, 0};
288+
289+
for (int i = 0; i < parts.length && i < 3; i++) {
290+
nums[i] = Integer.parseInt(parts[i]);
291+
}
292+
return nums;
293+
}
294+
275295
/* Endpoint for returning all Published Check Versions related to a given Working Eligibility Check */
276296
@GET
277297
@Path("/custom-checks/{checkId}/published-check-versions")
@@ -290,7 +310,7 @@ public Response getPublishedVersionsOfWorkingCheck(@Context SecurityIdentity ide
290310
}
291311

292312
// Update workingCheck so that the incremented version number is saved
293-
check.setVersion(check.getVersion() + 1);
313+
check.setVersion(incrementMajorVersion(check.getVersion()));
294314
try {
295315
List<EligibilityCheck> publishedChecks = eligibilityCheckRepository.getPublishedCheckVersions(check);
296316

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
package org.acme.model.domain;
22

33
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.databind.JsonNode;
45

6+
import java.util.List;
57
import java.util.Map;
68

79
@JsonIgnoreProperties(ignoreUnknown = true)
810
public class CheckConfig {
911
private String checkId;
1012
private String checkName;
13+
private String checkVersion;
14+
private String checkModule;
1115
private Map<String, Object> parameters;
16+
// evaluation endpoint url for library checks
17+
private String evaluationUrl;
18+
private JsonNode inputDefinition;
19+
private List<ParameterDefinition> parameterDefinitions;
1220

1321
public String getCheckId() {
1422
return checkId;
@@ -33,4 +41,44 @@ public String getCheckName() {
3341
public void setCheckName(String checkName) {
3442
this.checkName = checkName;
3543
}
44+
45+
public String getEvaluationUrl() {
46+
return evaluationUrl;
47+
}
48+
49+
public void setEvaluationUrl(String libraryCheckEvaluationUrl) {
50+
this.evaluationUrl = libraryCheckEvaluationUrl;
51+
}
52+
53+
public JsonNode getInputDefinition() {
54+
return inputDefinition;
55+
}
56+
57+
public void setInputDefinition(JsonNode inputDefinition) {
58+
this.inputDefinition = inputDefinition;
59+
}
60+
61+
public List<ParameterDefinition> getParameterDefinitions() {
62+
return parameterDefinitions;
63+
}
64+
65+
public void setParameterDefinitions(List<ParameterDefinition> parameterDefinitions) {
66+
this.parameterDefinitions = parameterDefinitions;
67+
}
68+
69+
public String getCheckVersion() {
70+
return checkVersion;
71+
}
72+
73+
public void setCheckVersion(String checkVersion) {
74+
this.checkVersion = checkVersion;
75+
}
76+
77+
public String getCheckModule() {
78+
return checkModule;
79+
}
80+
81+
public void setCheckModule(String checkModule) {
82+
this.checkModule = checkModule;
83+
}
3684
}

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

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ public class EligibilityCheck {
1212
private String name;
1313
private String module;
1414
private String description;
15-
private Integer version;
15+
private String version;
1616
private boolean isActive;
1717
private String dmnModel;
18-
private List<InputDefinition> inputs;
19-
private JsonNode situation;
20-
private List<ParameterDefinition> parameters;
18+
private JsonNode inputDefinition;
19+
private List<ParameterDefinition> parameterDefinitions;
2120
private String ownerId;
2221
@JsonProperty("isPublic")
2322
private Boolean isPublic;
@@ -64,11 +63,11 @@ public void setDescription(String description) {
6463
this.description = description;
6564
}
6665

67-
public Integer getVersion() {
66+
public String getVersion() {
6867
return version;
6968
}
7069

71-
public void setVersion(Integer version) {
70+
public void setVersion(String version) {
7271
this.version = version;
7372
}
7473

@@ -80,20 +79,12 @@ public void setActive(boolean active) {
8079
isActive = active;
8180
}
8281

83-
public List<InputDefinition> getInputs() {
84-
return inputs;
82+
public List<ParameterDefinition> getParameterDefinitions() {
83+
return parameterDefinitions;
8584
}
8685

87-
public void setInputs(List<InputDefinition> inputDefinitions) {
88-
this.inputs = inputDefinitions;
89-
}
90-
91-
public List<ParameterDefinition> getParameters() {
92-
return parameters;
93-
}
94-
95-
public void setParameters(List<ParameterDefinition> parameters) {
96-
this.parameters = parameters;
86+
public void setParameterDefinitions(List<ParameterDefinition> parameterDefinitions) {
87+
this.parameterDefinitions = parameterDefinitions;
9788
}
9889

9990
public String getOwnerId() {
@@ -112,12 +103,12 @@ public void setPublic(Boolean aPublic) {
112103
isPublic = aPublic;
113104
}
114105

115-
public JsonNode getSituation() {
116-
return situation;
106+
public JsonNode getInputDefinition() {
107+
return inputDefinition;
117108
}
118109

119-
public void setSituation(JsonNode situation) {
120-
this.situation = situation;
110+
public void setInputDefinition(JsonNode inputDefinition) {
111+
this.inputDefinition = inputDefinition;
121112
}
122113

123114
public String getPath() {

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

Lines changed: 0 additions & 64 deletions
This file was deleted.

builder-api/src/main/java/org/acme/persistence/impl/EligibilityCheckRepositoryImpl.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,33 @@ public List<EligibilityCheck> getLatestVersionPublishedCustomChecks(String userI
8787
.collect(java.util.stream.Collectors.toMap(
8888
check -> getPublishedPrefix(check),
8989
check -> check,
90-
(check1, check2) -> check1.getVersion() > check2.getVersion() ? check1 : check2
90+
(check1, check2) -> compareVersions(check1.getVersion(), check2.getVersion()) > 0 ? check1 : check2
9191
));
9292
return new ArrayList<>(latestVersionMap.values());
9393
}
9494

95+
private static int compareVersions(String v1, String v2) {
96+
int[] a = normalize(v1);
97+
int[] b = normalize(v2);
98+
99+
for (int i = 0; i < 3; i++) {
100+
if (a[i] != b[i]) {
101+
return a[i] - b[i];
102+
}
103+
}
104+
return 0;
105+
}
106+
107+
private static int[] normalize(String version) {
108+
String[] parts = version.split("\\.");
109+
int[] nums = new int[] {0, 0, 0};
110+
111+
for (int i = 0; i < parts.length && i < 3; i++) {
112+
nums[i] = Integer.parseInt(parts[i]);
113+
}
114+
return nums;
115+
}
116+
95117
public List<EligibilityCheck> getPublishedCheckVersions(EligibilityCheck workingCustomCheck){
96118
Map<String, String> fieldValues = Map.of(
97119
"ownerId", workingCustomCheck.getOwnerId(),

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class LibraryApiService {
2727
@PostConstruct
2828
void init() {
2929
try {
30-
3130
// Get path of most recent library schema json document
3231
Optional<Map<String, Object>> configOpt = FirestoreUtils.getFirestoreDocById("system", "config");
3332
if (configOpt.isEmpty()){
@@ -71,7 +70,7 @@ public EligibilityCheck getById(String id) {
7170
return matches.getFirst();
7271
}
7372

74-
public EvaluationResult evaluateCheck(CheckConfig checkConfig, String path, Map<String, Object> inputs){
73+
public EvaluationResult evaluateCheck(CheckConfig checkConfig, String evaluationUrl, Map<String, Object> inputs){
7574
return EvaluationResult.TRUE;
7675
}
7776
}

builder-frontend/src/api/benefit.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { authFetch } from "@/api/auth";
2+
import BenefitList from "@/components/project/manageBenefits/benefitList/BenefitList";
23

34
import { Benefit } from "@/types";
45

56
const apiUrl = import.meta.env.VITE_API_URL;
67

7-
export const fetchScreenerBenefit = async (srceenerId: string, benefitId: string): Promise<Benefit> => {
8+
export const fetchScreenerBenefit = async (
9+
srceenerId: string,
10+
benefitId: string
11+
): Promise<Benefit> => {
812
const url = apiUrl + "/screener/" + srceenerId + "/benefit/" + benefitId;
913
try {
1014
const response = await authFetch(url, {
@@ -25,7 +29,10 @@ export const fetchScreenerBenefit = async (srceenerId: string, benefitId: string
2529
}
2630
};
2731

28-
export const updateScreenerBenefit = async (screenerId: string, benefitData: Benefit): Promise<Benefit> => {
32+
export const updateScreenerBenefit = async (
33+
screenerId: string,
34+
benefitData: Benefit
35+
): Promise<Benefit> => {
2936
const url = apiUrl + "/screener/" + screenerId + "/benefit";
3037
try {
3138
const response = await authFetch(url, {
@@ -48,7 +55,6 @@ export const updateScreenerBenefit = async (screenerId: string, benefitData: Ben
4855
}
4956
};
5057

51-
5258
export const fetchPublicBenefits = async (): Promise<Benefit[]> => {
5359
const url = apiUrl + "/benefit";
5460
try {

0 commit comments

Comments
 (0)