Skip to content

Commit 372e4c6

Browse files
Added property isArchived to EligibilityChecks. Updated RemoveCheck button to archive EligibilityChecks.
1 parent 77b2a3f commit 372e4c6

File tree

7 files changed

+127
-28
lines changed

7 files changed

+127
-28
lines changed

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

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public Response getCustomCheck(@Context SecurityIdentity identity, @PathParam("c
171171

172172
EligibilityCheck check = checkOpt.get();
173173

174-
if (!check.getPublic() && !check.getOwnerId().equals(userId)){
174+
if (!check.getOwnerId().equals(userId)){
175175
return Response.status(Response.Status.UNAUTHORIZED).build();
176176
}
177177
return Response.ok(check, MediaType.APPLICATION_JSON).build();
@@ -185,7 +185,6 @@ public Response createCustomCheck(@Context SecurityIdentity identity,
185185

186186
//TODO: Add validations for user provided data
187187
newCheck.setOwnerId(userId);
188-
newCheck.setPublic(false);
189188
if (newCheck.getVersion().isEmpty()){
190189
newCheck.setVersion("1.0.0");
191190
}
@@ -209,6 +208,12 @@ public Response updateCustomCheck(@Context SecurityIdentity identity,
209208
return Response.status(Response.Status.UNAUTHORIZED).build();
210209
}
211210

211+
// Check if the check exists and is not archived
212+
Optional<EligibilityCheck> existingCheckOpt = eligibilityCheckRepository.getWorkingCustomCheck(userId, updateCheck.getId());
213+
if (existingCheckOpt.isEmpty()) {
214+
return Response.status(Response.Status.NOT_FOUND).build();
215+
}
216+
212217
try {
213218
eligibilityCheckRepository.updateWorkingCustomCheck(updateCheck);
214219
return Response.ok().entity(updateCheck).build();
@@ -305,6 +310,42 @@ private int[] normalize(String version) {
305310
return nums;
306311
}
307312

313+
@POST
314+
@Path("/custom-checks/{checkId}/archive")
315+
public Response archiveCustomCheck(@Context SecurityIdentity identity, @PathParam("checkId") String checkId) {
316+
String userId = AuthUtils.getUserId(identity);
317+
if (userId == null) {
318+
return Response.status(Response.Status.UNAUTHORIZED).build();
319+
}
320+
321+
Optional<EligibilityCheck> checkOpt = eligibilityCheckRepository.getWorkingCustomCheck(userId, checkId, true);
322+
if (checkOpt.isEmpty()) {
323+
return Response.status(Response.Status.NOT_FOUND).build();
324+
}
325+
326+
EligibilityCheck check = checkOpt.get();
327+
328+
if (!check.getOwnerId().equals(userId)) {
329+
return Response.status(Response.Status.UNAUTHORIZED).build();
330+
}
331+
332+
if (check.getIsArchived()) {
333+
return Response.status(Response.Status.BAD_REQUEST)
334+
.entity(Map.of("error", "Check is already archived"))
335+
.build();
336+
}
337+
338+
check.setIsArchived(true);
339+
try {
340+
eligibilityCheckRepository.updateWorkingCustomCheck(check);
341+
return Response.ok().build();
342+
} catch (Exception e) {
343+
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
344+
.entity(Map.of("error", "Could not archive check"))
345+
.build();
346+
}
347+
}
348+
308349
/* Endpoint for returning all Published Check Versions related to a given Working Eligibility Check */
309350
@GET
310351
@Path("/custom-checks/{checkId}/published-check-versions")

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

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ public class EligibilityCheck {
1313
private String module;
1414
private String description;
1515
private String version;
16-
private boolean isActive;
1716
private String dmnModel;
1817
private JsonNode inputDefinition;
1918
private List<ParameterDefinition> parameterDefinitions;
2019
private String ownerId;
21-
@JsonProperty("isPublic")
22-
private Boolean isPublic;
2320
// API endpoint for evaluating library checks
2421
private String path;
22+
private Boolean isArchived;
2523

2624
public String getId() {
2725
return this.id;
@@ -71,14 +69,6 @@ public void setVersion(String version) {
7169
this.version = version;
7270
}
7371

74-
public boolean isActive() {
75-
return isActive;
76-
}
77-
78-
public void setActive(boolean active) {
79-
isActive = active;
80-
}
81-
8272
public List<ParameterDefinition> getParameterDefinitions() {
8373
return parameterDefinitions;
8474
}
@@ -95,14 +85,6 @@ public void setOwnerId(String ownerId) {
9585
this.ownerId = ownerId;
9686
}
9787

98-
public Boolean getPublic() {
99-
return isPublic;
100-
}
101-
102-
public void setPublic(Boolean aPublic) {
103-
isPublic = aPublic;
104-
}
105-
10688
public JsonNode getInputDefinition() {
10789
return inputDefinition;
10890
}
@@ -118,4 +100,12 @@ public String getPath() {
118100
public void setPath(String path) {
119101
this.path = path;
120102
}
103+
104+
public Boolean getIsArchived() {
105+
return isArchived != null ? isArchived : false;
106+
}
107+
108+
public void setIsArchived(Boolean isArchived) {
109+
this.isArchived = isArchived;
110+
}
121111
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public interface EligibilityCheckRepository {
2424

2525
Optional<EligibilityCheck> getWorkingCustomCheck(String userId, String checkId);
2626

27+
Optional<EligibilityCheck> getWorkingCustomCheck(String userId, String checkId, boolean includeArchived);
28+
2729
Optional<EligibilityCheck> getPublishedCustomCheck(String userId, String checkId);
2830

2931
String saveNewWorkingCustomCheck(EligibilityCheck check) throws Exception;

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

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ public List<EligibilityCheck> getChecksInBenefit(Benefit benefit){
7272
public List<EligibilityCheck> getWorkingCustomChecks(String userId){
7373
List<Map<String, Object>> checkMaps = FirestoreUtils.getFirestoreDocsByField(CollectionNames.WORKING_CUSTOM_CHECK_COLLECTION, FieldNames.OWNER_ID, userId);
7474
ObjectMapper mapper = new ObjectMapper();
75-
return checkMaps.stream().map(checkMap -> mapper.convertValue(checkMap, EligibilityCheck.class)).toList();
75+
return checkMaps.stream()
76+
.map(checkMap -> mapper.convertValue(checkMap, EligibilityCheck.class))
77+
.filter(check -> !check.getIsArchived())
78+
.toList();
7679
}
7780

7881
public List<EligibilityCheck> getPublishedCustomChecks(String userId){
@@ -83,7 +86,15 @@ public List<EligibilityCheck> getPublishedCustomChecks(String userId){
8386

8487
public List<EligibilityCheck> getLatestVersionPublishedCustomChecks(String userId) {
8588
List<EligibilityCheck> publishedChecks = getPublishedCustomChecks(userId);
89+
90+
// Get all working checks to determine which are archived
91+
List<EligibilityCheck> workingChecks = getWorkingCustomChecks(userId);
92+
java.util.Set<String> nonArchivedPrefixes = workingChecks.stream()
93+
.map(this::getPublishedPrefix)
94+
.collect(java.util.stream.Collectors.toSet());
95+
8696
Map<String, EligibilityCheck> latestVersionMap = publishedChecks.stream()
97+
.filter(check -> nonArchivedPrefixes.contains(getPublishedPrefix(check)))
8798
.collect(java.util.stream.Collectors.toMap(
8899
check -> getPublishedPrefix(check),
89100
check -> check,
@@ -133,11 +144,38 @@ public List<EligibilityCheck> getPublishedCheckVersions(EligibilityCheck working
133144
}
134145

135146
public Optional<EligibilityCheck> getWorkingCustomCheck(String userId, String checkId){
136-
return getCustomCheck(userId, checkId, false);
147+
return getWorkingCustomCheck(userId, checkId, false);
148+
}
149+
150+
public Optional<EligibilityCheck> getWorkingCustomCheck(String userId, String checkId, boolean includeArchived){
151+
Optional<EligibilityCheck> checkOpt = getCustomCheck(userId, checkId, false);
152+
if (checkOpt.isEmpty()) {
153+
return Optional.empty();
154+
}
155+
EligibilityCheck check = checkOpt.get();
156+
if (!includeArchived && check.getIsArchived()) {
157+
return Optional.empty();
158+
}
159+
return checkOpt;
137160
}
138161

139162
public Optional<EligibilityCheck> getPublishedCustomCheck(String userId, String checkId){
140-
return getCustomCheck(userId, checkId, true);
163+
Optional<EligibilityCheck> publishedCheckOpt = getCustomCheck(userId, checkId, true);
164+
if (publishedCheckOpt.isEmpty()) {
165+
return Optional.empty();
166+
}
167+
168+
// Check if the corresponding working check is archived
169+
EligibilityCheck publishedCheck = publishedCheckOpt.get();
170+
String workingCheckId = getWorkingId(publishedCheck);
171+
Optional<EligibilityCheck> workingCheckOpt = getWorkingCustomCheck(userId, workingCheckId, true);
172+
173+
// If working check exists and is archived, return empty
174+
if (workingCheckOpt.isPresent() && workingCheckOpt.get().getIsArchived()) {
175+
return Optional.empty();
176+
}
177+
178+
return publishedCheckOpt;
141179
}
142180

143181
private Optional<EligibilityCheck> getCustomCheck(String userId, String checkId, boolean isPublished){

builder-frontend/src/api/check.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,22 @@ export const publishCheck = async (
245245
throw error; // rethrow so you can handle it in your component if needed
246246
}
247247
};
248+
249+
export const archiveCheck = async (checkId: string): Promise<void> => {
250+
const url = apiUrl + `/custom-checks/${checkId}/archive`;
251+
try {
252+
const response = await authFetch(url, {
253+
method: "POST",
254+
headers: {
255+
Accept: "application/json",
256+
},
257+
});
258+
259+
if (!response.ok) {
260+
throw new Error(`Archive failed with status: ${response.status}`);
261+
}
262+
} catch (error) {
263+
console.error("Error archiving check:", error);
264+
throw error;
265+
}
266+
};

builder-frontend/src/components/homeScreen/eligibilityCheckList/EligibilityChecksList.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import CheckModal from "./modals/CheckModal";
66
import eligibilityCheckResource from "./eligibilityCheckResource";
77

88
import type { EligibilityCheck } from "@/types";
9+
import ConfirmationModal from "@/components/shared/ConfirmationModal";
910

1011
const EligibilityChecksList = () => {
1112
const { checks, actions, actionInProgress, initialLoadStatus } =
@@ -59,6 +60,14 @@ const EligibilityChecksList = () => {
5960
modalAction={actions.addNewCheck}
6061
/>
6162
)}
63+
{checkIdToRemove() && (
64+
<ConfirmationModal
65+
confirmationTitle="Archive Check"
66+
confirmationText="Are you sure you want to archive this Eligibility Check? This action cannot be undone."
67+
callback={() => actions.removeCheck(checkIdToRemove()!)}
68+
closeModal={() => setCheckIdToRemove(null)}
69+
/>
70+
)}
6271
</div>
6372
);
6473
};
@@ -107,7 +116,7 @@ const CheckCard = ({
107116
setCheckIdToRemove(eligibilityCheck.id);
108117
}}
109118
>
110-
Remove
119+
Archive
111120
</div>
112121
</div>
113122
</div>

builder-frontend/src/components/homeScreen/eligibilityCheckList/eligibilityCheckResource.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createResource, createEffect, Accessor, createSignal } from "solid-js";
22
import { createStore } from "solid-js/store";
33

44
import type { EligibilityCheck } from "@/types";
5-
import { addCheck, fetchUserDefinedChecks } from "@/api/check";
5+
import { addCheck, archiveCheck, fetchUserDefinedChecks } from "@/api/check";
66

77
export interface EligibilityCheckResource {
88
checks: () => EligibilityCheck[];
@@ -46,10 +46,10 @@ const eligibilityCheckResource = (): EligibilityCheckResource => {
4646
const removeCheck = async (checkIdToRemove: string) => {
4747
setActionInProgress(true);
4848
try {
49-
// await removeCustomBenefit(screenerId(), benefitIdToRemove); TODO
49+
await archiveCheck(checkIdToRemove);
5050
await refetch();
5151
} catch (e) {
52-
console.error("Failed to delete check", e);
52+
console.error("Failed to archive check", e);
5353
}
5454
setActionInProgress(false);
5555
};

0 commit comments

Comments
 (0)