Skip to content

Commit 352e044

Browse files
Added api endpoint for working and published checks
1 parent 4d78c48 commit 352e044

13 files changed

+130
-247
lines changed
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package org.acme.constants;
22

33
public class CollectionNames {
4-
public static final String SCREENER_COLLECTION = "screener";
5-
public static final String DMN_MODEL_COLLECTION = "dmn_model";
6-
public static final String ELIGIBILITY_CHECK_COLLECTION = "eligibilityCheck";
7-
public static final String CUSTOM_CHECK_COLLECTION = "customCheck";
4+
public static final String WORKING_SCREENER_COLLECTION = "workingScreener";
5+
public static final String PUBLISHED_SCREENER_COLLECTION = "publishedScreener";
6+
public static final String WORKING_CUSTOM_CHECK_COLLECTION = "workingCustomCheck";
7+
public static final String PUBLISHED_CUSTOM_CHECK_COLLECTION = "publishedCustomCheck";
88
public static final String BENEFIT_COLLECTION = "benefit";
9+
public static final String PUBLIC_BENEFIT_COLLECTION = "publicBenefit";
10+
public static final String PUBLIC_CHECK_COLLECTION = "publicCheck";
911
}

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

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.acme.persistence.EligibilityCheckRepository;
1414
import org.acme.persistence.StorageService;
1515

16+
import java.util.ArrayList;
1617
import java.util.List;
1718
import java.util.Map;
1819
import java.util.Optional;
@@ -27,27 +28,27 @@ public class EligibilityCheckResource {
2728
StorageService storageService;
2829

2930
@GET
30-
@Path("/check")
31-
public Response getAllChecks(@Context SecurityIdentity identity) {
31+
@Path("/checks")
32+
public Response getPublicChecks(@Context SecurityIdentity identity) {
3233
String userId = AuthUtils.getUserId(identity);
3334
if (userId == null) {
3435
return Response.status(Response.Status.UNAUTHORIZED).build();
3536
}
3637
Log.info("Fetching all eligibility checks. User: " + userId);
37-
List<EligibilityCheck> checks = eligibilityCheckRepository.getAllPublicChecks();
38+
List<EligibilityCheck> checks = eligibilityCheckRepository.getPublicChecks();
3839

3940
return Response.ok(checks, MediaType.APPLICATION_JSON).build();
4041
}
4142

4243
@GET
43-
@Path("/check/{checkId}")
44-
public Response getCheck(@Context SecurityIdentity identity, @PathParam("checkId") String checkId) {
44+
@Path("/checks/{checkId}")
45+
public Response getPublicCheck(@Context SecurityIdentity identity, @PathParam("checkId") String checkId) {
4546
String userId = AuthUtils.getUserId(identity);
4647
if (userId == null){
4748
return Response.status(Response.Status.UNAUTHORIZED).build();
4849
}
4950
Log.info("Fetching all eligibility checks. User: " + userId);
50-
Optional<EligibilityCheck> checkOpt = eligibilityCheckRepository.getCheck(checkId);
51+
Optional<EligibilityCheck> checkOpt = eligibilityCheckRepository.getPublicCheck(checkId);
5152

5253
if (checkOpt.isEmpty()){
5354
return Response.status(Response.Status.NOT_FOUND).build();
@@ -61,20 +62,19 @@ public Response getCheck(@Context SecurityIdentity identity, @PathParam("checkId
6162
return Response.ok(check, MediaType.APPLICATION_JSON).build();
6263
}
6364

64-
// Utility endpoint to create an Eligibility check
65-
// In the future seperate endpoints will need to be created for publishing public checks and creating private checks
65+
// Utility endpoint, public checks come from the Library API schema and shouldn't usually be created through the app
6666
@POST
67-
@Path("/check")
68-
public Response createCheck(@Context SecurityIdentity identity,
67+
@Path("/checks")
68+
public Response createPublicCheck(@Context SecurityIdentity identity,
6969
EligibilityCheck newCheck) {
7070
String userId = AuthUtils.getUserId(identity);
7171

7272
//TODO: Add validations for user provided data
7373
newCheck.setOwnerId(userId);
74-
newCheck.setPublic(true); // By default all created checks are public
75-
newCheck.setVersion("1");
74+
newCheck.setPublic(true);
75+
newCheck.setVersion(1);
7676
try {
77-
String checkId = eligibilityCheckRepository.saveNewCheck(newCheck);
77+
String checkId = eligibilityCheckRepository.savePublicCheck(newCheck);
7878
newCheck.setId(checkId);
7979
return Response.ok(newCheck, MediaType.APPLICATION_JSON).build();
8080
} catch (Exception e){
@@ -84,15 +84,17 @@ public Response createCheck(@Context SecurityIdentity identity,
8484
}
8585
}
8686

87+
// Utility endpoint, public checks are static and come from the library api schema
88+
// and usually should not be updated through the app
8789
@PUT
88-
@Path("/check")
89-
public Response updateCheck(@Context SecurityIdentity identity,
90+
@Path("/checks")
91+
public Response updatePublicCheck(@Context SecurityIdentity identity,
9092
EligibilityCheck updateCheck){
9193
String userId = AuthUtils.getUserId(identity);
9294

9395
// TODO: Add authorization to update check
9496
try {
95-
eligibilityCheckRepository.updateCheck(updateCheck);
97+
eligibilityCheckRepository.savePublicCheck(updateCheck);
9698
return Response.ok().entity(updateCheck).build();
9799
} catch (Exception e){
98100
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
@@ -114,7 +116,7 @@ public Response updateCheckDmn(@Context SecurityIdentity identity, SaveDmnReques
114116
}
115117

116118
String userId = AuthUtils.getUserId(identity);
117-
Optional<EligibilityCheck> checkOpt = eligibilityCheckRepository.getCustomCheck(userId, checkId);
119+
Optional<EligibilityCheck> checkOpt = eligibilityCheckRepository.getWorkingCustomCheck(userId, checkId);
118120
if (checkOpt.isEmpty()){
119121
return Response.status(Response.Status.NOT_FOUND).build();
120122
}
@@ -146,31 +148,47 @@ public Response updateCheckDmn(@Context SecurityIdentity identity, SaveDmnReques
146148
}
147149
}
148150

151+
// By default, returns the most recent versions of all published checks owned by the calling user
152+
// If the query parameter 'working' is set to true,
153+
// then all the working check objects owned by the user are returned
149154
@GET
150-
@Path("/account/check")
151-
public Response getCustomChecks(@Context SecurityIdentity identity) {
155+
@Path("/custom-checks")
156+
public Response getCustomChecks(@Context SecurityIdentity identity, @QueryParam("working") Boolean working) {
152157
String userId = AuthUtils.getUserId(identity);
153158
if (userId == null) {
154159
return Response.status(Response.Status.UNAUTHORIZED).build();
155160
}
156161

157-
Log.info("Fetching all eligibility checks. User: " + userId);
158-
List<EligibilityCheck> checks = eligibilityCheckRepository.getCustomChecks(userId);
162+
List<EligibilityCheck> checks;
163+
164+
if (working != null && working){
165+
Log.info("Fetching all working custom checks. User: " + userId);
166+
checks = eligibilityCheckRepository.getWorkingCustomChecks(userId);
167+
} else {
168+
Log.info("Fetching all published custom checks. User: " + userId);
169+
checks = eligibilityCheckRepository.getPublishedCustomChecks(userId);
170+
}
159171

160172
return Response.ok(checks, MediaType.APPLICATION_JSON).build();
161173
}
162174

163175
@GET
164-
@Path("/account/check/{checkId}")
165-
public Response getCustomCheck(@Context SecurityIdentity identity) {
176+
@Path("/custom-checks/{checkId}")
177+
public Response getCustomCheck(@Context SecurityIdentity identity, @PathParam("checkId") String checkId, @QueryParam("working") Boolean working) {
166178
String userId = AuthUtils.getUserId(identity);
167179
if (userId == null) {
168180
return Response.status(Response.Status.UNAUTHORIZED).build();
169181
}
170182

171-
Log.info("Fetching all eligibility checks. User: " + userId);
172-
Optional<EligibilityCheck> checkOpt = eligibilityCheckRepository.getCustomCheck(userId, userId);
183+
Optional<EligibilityCheck> checkOpt;
173184

185+
if (working != null && working){
186+
Log.info("Fetching working custom check: " + checkId + " User: " + userId);
187+
checkOpt = eligibilityCheckRepository.getWorkingCustomCheck(userId, userId);
188+
} else {
189+
Log.info("Fetching published custom check: " + checkId + " User: " + userId);
190+
checkOpt = eligibilityCheckRepository.getPublishedCustomCheck(userId, userId);
191+
}
174192

175193
if (checkOpt.isEmpty()){
176194
return Response.status(Response.Status.NOT_FOUND).build();
@@ -185,17 +203,17 @@ public Response getCustomCheck(@Context SecurityIdentity identity) {
185203
}
186204

187205
@POST
188-
@Path("/account/check")
206+
@Path("/custom-checks")
189207
public Response createCustomCheck(@Context SecurityIdentity identity,
190208
EligibilityCheck newCheck) {
191209
String userId = AuthUtils.getUserId(identity);
192210

193211
//TODO: Add validations for user provided data
194212
newCheck.setOwnerId(userId);
195213
newCheck.setPublic(false);
196-
newCheck.setVersion("1");
214+
newCheck.setVersion(1);
197215
try {
198-
String checkId = eligibilityCheckRepository.saveNewCustomCheck(newCheck);
216+
String checkId = eligibilityCheckRepository.saveWorkingCustomCheck(newCheck);
199217
newCheck.setId(checkId);
200218
return Response.ok(newCheck, MediaType.APPLICATION_JSON).build();
201219
} catch (Exception e){
@@ -206,14 +224,14 @@ public Response createCustomCheck(@Context SecurityIdentity identity,
206224
}
207225

208226
@PUT
209-
@Path("/account/check")
227+
@Path("/custom-checks")
210228
public Response updateCustomCheck(@Context SecurityIdentity identity,
211229
EligibilityCheck updateCheck){
212230
String userId = AuthUtils.getUserId(identity);
213231

214232
// TODO: Add authorization to update check
215233
try {
216-
eligibilityCheckRepository.updateCustomCheck(updateCheck);
234+
eligibilityCheckRepository.saveWorkingCustomCheck(updateCheck);
217235
return Response.ok().entity(updateCheck).build();
218236
} catch (Exception e){
219237
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)

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

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class EligibilityCheck {
1010
private String name;
1111
private String module;
1212
private String description;
13-
private String version;
13+
private Integer version;
1414
private boolean isActive;
1515
private String dmnModel;
1616
private List<InputDefinition> inputs;
@@ -59,11 +59,11 @@ public void setDescription(String description) {
5959
this.description = description;
6060
}
6161

62-
public String getVersion() {
62+
public Integer getVersion() {
6363
return version;
6464
}
6565

66-
public void setVersion(String version) {
66+
public void setVersion(Integer version) {
6767
this.version = version;
6868
}
6969

builder-api/src/main/java/org/acme/persistence/DmnModelRepository.java

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

builder-api/src/main/java/org/acme/persistence/DmnModelRespositoryImpl.java

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

builder-api/src/main/java/org/acme/persistence/EligibilityCheckRepository.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@
88

99
public interface EligibilityCheckRepository {
1010

11-
List<EligibilityCheck> getAllPublicChecks();
11+
List<EligibilityCheck> getPublicChecks();
1212

13-
Optional<EligibilityCheck> getCheck(String checkId);
13+
Optional<EligibilityCheck> getPublicCheck(String checkId);
1414

1515
List<EligibilityCheck> getChecksInBenefit(Benefit benefit);
1616

17-
List<EligibilityCheck> getCustomChecks(String userId);
17+
List<EligibilityCheck> getWorkingCustomChecks(String userId);
1818

19-
Optional<EligibilityCheck> getCustomCheck(String userId, String checkId);
19+
List<EligibilityCheck> getPublishedCustomChecks(String userId);
2020

21-
String saveNewCheck(EligibilityCheck check) throws Exception;
21+
Optional<EligibilityCheck> getWorkingCustomCheck(String userId, String checkId);
2222

23-
String saveNewCustomCheck(EligibilityCheck check) throws Exception;
23+
Optional<EligibilityCheck> getPublishedCustomCheck(String userId, String checkId);
2424

25-
void updateCheck(EligibilityCheck check) throws Exception;
25+
String saveWorkingCustomCheck(EligibilityCheck check) throws Exception;
2626

27-
void updateCustomCheck(EligibilityCheck check) throws Exception;
27+
String savePublishedCustomCheck(EligibilityCheck check) throws Exception;
28+
29+
String savePublicCheck(EligibilityCheck check) throws Exception;
2830
}

builder-api/src/main/java/org/acme/persistence/GoogleStorageService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ public String getScreenerPublishedFormSchemaPath(String screenerId){
139139
return "form/published/" + screenerId + ".json";
140140
}
141141

142+
@Override
143+
public String getCheckDmnModelPath(String module, String checkId, String version){
144+
return "check/" + module + "/" + checkId + "/" + version + "/" + checkId + ".dmn";
145+
}
146+
142147
@Override
143148
public String getCheckDmnModelPath(String userId, String module, String checkId, String version){
144149
return "check/" + userId + "/" + module + "/" + checkId + "/" + version + "/" + checkId + ".dmn";

builder-api/src/main/java/org/acme/persistence/StorageService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public interface StorageService {
2323

2424
String getScreenerPublishedFormSchemaPath(String screenerId);
2525

26+
27+
String getCheckDmnModelPath(String module, String checkId, String version);
28+
2629
String getCheckDmnModelPath(String userId, String module, String checkId, String version);
2730

2831
Map<String, Object> getFormSchemaFromStorage(String filePath);

0 commit comments

Comments
 (0)