|
6 | 6 | import jakarta.enterprise.context.ApplicationScoped; |
7 | 7 | import jakarta.inject.Inject; |
8 | 8 |
|
| 9 | +import org.acme.constants.CheckStatus; |
9 | 10 | import org.acme.constants.CollectionNames; |
10 | 11 | import org.acme.constants.FieldNames; |
11 | 12 | import org.acme.model.domain.Benefit; |
@@ -107,39 +108,48 @@ private Optional<EligibilityCheck> getCustomCheck(String userId, String checkId, |
107 | 108 | return Optional.of(check); |
108 | 109 | } |
109 | 110 |
|
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); |
111 | 114 | ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); |
112 | 115 | 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); |
115 | 117 | } |
116 | 118 |
|
117 | 119 | public void updateWorkingCustomCheck(EligibilityCheck check) throws Exception{ |
118 | 120 | ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); |
119 | 121 | 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()); |
122 | 123 | } |
123 | 124 |
|
124 | | - public String savePublishedCustomCheck(EligibilityCheck check) throws Exception{ |
| 125 | + public String saveNewPublishedCustomCheck(EligibilityCheck check) throws Exception{ |
| 126 | + check.setId(getPublishedId(check)); |
125 | 127 | ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); |
126 | 128 | Map<String, Object> data = mapper.convertValue(check, Map.class); |
127 | | - String checkDocId = check.getPublishedId(); |
| 129 | + String checkDocId = getPublishedId(check); |
128 | 130 | return FirestoreUtils.persistDocumentWithId(CollectionNames.PUBLISHED_CUSTOM_CHECK_COLLECTION, checkDocId, data); |
129 | 131 | } |
130 | 132 |
|
131 | 133 |
|
132 | 134 | public void updatePublishedCustomCheck(EligibilityCheck check) throws Exception{ |
133 | 135 | ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); |
134 | 136 | 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()); |
137 | 138 | } |
138 | 139 |
|
139 | 140 | public String savePublicCheck(EligibilityCheck check) throws Exception{ |
| 141 | + String checkId = getPublishedId(check); |
| 142 | + check.setId(checkId); |
140 | 143 | ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); |
141 | 144 | 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(); |
144 | 154 | } |
145 | 155 | } |
0 commit comments