Skip to content

Commit 0abc692

Browse files
removed working and published ids functions from EligibilityCheck
1 parent e2ef520 commit 0abc692

File tree

4 files changed

+27
-28
lines changed

4 files changed

+27
-28
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.acme.persistence.EligibilityCheckRepository;
1515
import org.acme.persistence.StorageService;
1616

17-
import java.util.ArrayList;
1817
import java.util.List;
1918
import java.util.Map;
2019
import java.util.Optional;
@@ -217,7 +216,7 @@ public Response createCustomCheck(@Context SecurityIdentity identity,
217216
newCheck.setPublic(false);
218217
newCheck.setVersion(1);
219218
try {
220-
eligibilityCheckRepository.saveWorkingCustomCheck(newCheck);
219+
eligibilityCheckRepository.saveNewWorkingCustomCheck(newCheck);
221220
return Response.ok(newCheck, MediaType.APPLICATION_JSON).build();
222221
} catch (Exception e){
223222
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
@@ -274,17 +273,15 @@ public Response publishCustomCheck(@Context SecurityIdentity identity, @PathPara
274273
}
275274

276275
// Create new published custom check
277-
check.setId(check.getPublishedId());
278276
try {
279277
// save published check meta data document
280-
eligibilityCheckRepository.savePublishedCustomCheck(check);
278+
String publishedCheckId = eligibilityCheckRepository.saveNewPublishedCustomCheck(check);
281279

282280
// save published check DMN to storage
283-
Optional<String> workingDmnOpt = storageService.getStringFromStorage(storageService.getCheckDmnModelPath(userId, check.getWorkingId()));
281+
Optional<String> workingDmnOpt = storageService.getStringFromStorage(storageService.getCheckDmnModelPath(userId, check.getId()));
284282
if (workingDmnOpt.isPresent()){
285283
String workingDmn = workingDmnOpt.get();
286-
storageService.writeStringToStorage(storageService.getCheckDmnModelPath(userId, check.getPublishedId()), workingDmn, "application/xml");
287-
284+
storageService.writeStringToStorage(storageService.getCheckDmnModelPath(userId, publishedCheckId), workingDmn, "application/xml");
288285
}
289286
} catch (Exception e){
290287
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ public class EligibilityCheck {
2121
@JsonProperty("isPublic")
2222
private Boolean isPublic;
2323

24-
public String getWorkingId() {
25-
return CheckStatus.WORKING.getCode() + "-" + ownerId + "-" + module + "-" + name;
26-
}
27-
28-
public String getPublishedId() {
29-
return CheckStatus.PUBLISHED.getCode() + "-" + ownerId + "-" + module + "-" + name + "-" + version.toString();
30-
}
31-
3224
public String getId() {
3325
return this.id;
3426
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public interface EligibilityCheckRepository {
2222

2323
Optional<EligibilityCheck> getPublishedCustomCheck(String userId, String checkId);
2424

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

27-
String savePublishedCustomCheck(EligibilityCheck check) throws Exception;
27+
String saveNewPublishedCustomCheck(EligibilityCheck check) throws Exception;
2828

2929
void updateWorkingCustomCheck(EligibilityCheck check) throws Exception;
3030

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import jakarta.enterprise.context.ApplicationScoped;
77
import jakarta.inject.Inject;
88

9+
import org.acme.constants.CheckStatus;
910
import org.acme.constants.CollectionNames;
1011
import org.acme.constants.FieldNames;
1112
import org.acme.model.domain.Benefit;
@@ -107,39 +108,48 @@ private Optional<EligibilityCheck> getCustomCheck(String userId, String checkId,
107108
return Optional.of(check);
108109
}
109110

110-
public String saveWorkingCustomCheck(EligibilityCheck check) throws Exception{
111+
public String saveNewWorkingCustomCheck(EligibilityCheck check) throws Exception{
112+
String checkId = getWorkingId(check);
113+
check.setId(checkId);
111114
ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
112115
Map<String, Object> data = mapper.convertValue(check, Map.class);
113-
String checkDocId = check.getWorkingId();
114-
return FirestoreUtils.persistDocumentWithId(CollectionNames.WORKING_CUSTOM_CHECK_COLLECTION, checkDocId, data);
116+
return FirestoreUtils.persistDocumentWithId(CollectionNames.WORKING_CUSTOM_CHECK_COLLECTION, checkId, data);
115117
}
116118

117119
public void updateWorkingCustomCheck(EligibilityCheck check) throws Exception{
118120
ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
119121
Map<String, Object> data = mapper.convertValue(check, Map.class);
120-
String checkDocId = check.getWorkingId();
121-
FirestoreUtils.updateDocument(CollectionNames.WORKING_CUSTOM_CHECK_COLLECTION, data, checkDocId);
122+
FirestoreUtils.updateDocument(CollectionNames.WORKING_CUSTOM_CHECK_COLLECTION, data, check.getId());
122123
}
123124

124-
public String savePublishedCustomCheck(EligibilityCheck check) throws Exception{
125+
public String saveNewPublishedCustomCheck(EligibilityCheck check) throws Exception{
126+
check.setId(getPublishedId(check));
125127
ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
126128
Map<String, Object> data = mapper.convertValue(check, Map.class);
127-
String checkDocId = check.getPublishedId();
129+
String checkDocId = getPublishedId(check);
128130
return FirestoreUtils.persistDocumentWithId(CollectionNames.PUBLISHED_CUSTOM_CHECK_COLLECTION, checkDocId, data);
129131
}
130132

131133

132134
public void updatePublishedCustomCheck(EligibilityCheck check) throws Exception{
133135
ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
134136
Map<String, Object> data = mapper.convertValue(check, Map.class);
135-
String checkDocId = check.getPublishedId();
136-
FirestoreUtils.updateDocument(CollectionNames.PUBLISHED_CUSTOM_CHECK_COLLECTION, data, checkDocId);
137+
FirestoreUtils.updateDocument(CollectionNames.PUBLISHED_CUSTOM_CHECK_COLLECTION, data, check.getId());
137138
}
138139

139140
public String savePublicCheck(EligibilityCheck check) throws Exception{
141+
String checkId = getPublishedId(check);
142+
check.setId(checkId);
140143
ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
141144
Map<String, Object> data = mapper.convertValue(check, Map.class);
142-
String checkDocId = check.getPublishedId();
143-
return FirestoreUtils.persistDocumentWithId(CollectionNames.PUBLIC_CHECK_COLLECTION, checkDocId, data);
145+
return FirestoreUtils.persistDocumentWithId(CollectionNames.PUBLIC_CHECK_COLLECTION, checkId , data);
146+
}
147+
148+
public String getWorkingId(EligibilityCheck check) {
149+
return CheckStatus.WORKING.getCode() + "-" + check.getOwnerId() + "-" + check.getModule() + "-" + check.getName();
150+
}
151+
152+
public String getPublishedId(EligibilityCheck check) {
153+
return CheckStatus.PUBLISHED.getCode() + "-" + check.getOwnerId() + "-" + check.getModule() + "-" + check.getName() + "-" + check.getVersion().toString();
144154
}
145155
}

0 commit comments

Comments
 (0)