Skip to content

Commit d61ed5d

Browse files
committed
reprocess
1 parent 34e3319 commit d61ed5d

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/controller/v1/SdcSchoolCollectionController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionEntity;
88
import ca.bc.gov.educ.studentdatacollection.api.service.v1.SdcSchoolCollectionSearchService;
99
import ca.bc.gov.educ.studentdatacollection.api.service.v1.SdcSchoolCollectionService;
10+
import ca.bc.gov.educ.studentdatacollection.api.struct.ReprocessSdcSchoolCollection;
1011
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.*;
1112
import ca.bc.gov.educ.studentdatacollection.api.util.JsonUtil;
1213
import ca.bc.gov.educ.studentdatacollection.api.util.RequestUtil;
@@ -97,6 +98,11 @@ public SdcSchoolCollection unsubmitSchoolCollection(UnsubmitSdcSchoolCollection
9798
return mapper.toStructure(sdcSchoolCollectionService.unsubmitSchoolCollection(unsubmitData));
9899
}
99100

101+
@Override
102+
public SdcSchoolCollection reprocessSchoolCollection(ReprocessSdcSchoolCollection reprocessData) {
103+
return mapper.toStructure(sdcSchoolCollectionService.reprocessSchoolCollection(reprocessData));
104+
}
105+
100106
@Override
101107
public SdcSchoolCollection reportZeroEnrollment(ReportZeroEnrollmentSdcSchoolCollection reportZeroEnrollmentData) {
102108
return mapper.toStructure(sdcSchoolCollectionService.reportZeroEnrollment(reportZeroEnrollmentData));

api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/endpoint/v1/SdcSchoolCollectionEndpoint.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ca.bc.gov.educ.studentdatacollection.api.endpoint.v1;
22

33
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.URL;
4+
import ca.bc.gov.educ.studentdatacollection.api.struct.ReprocessSdcSchoolCollection;
45
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.*;
56
import io.swagger.v3.oas.annotations.media.Schema;
67
import io.swagger.v3.oas.annotations.responses.ApiResponse;
@@ -81,6 +82,14 @@ List<SdcSchoolCollection> getAllSchoolCollections(@RequestParam(name = "schoolID
8182
@Schema(name = "SdcSchoolCollection", implementation = SdcSchoolCollection.class)
8283
SdcSchoolCollection unsubmitSchoolCollection(@RequestBody UnsubmitSdcSchoolCollection unsubmitData);
8384

85+
@PostMapping("/reprocess")
86+
@PreAuthorize("hasAuthority('SCOPE_WRITE_SDC_DISTRICT_COLLECTION')")
87+
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "BAD REQUEST"), @ApiResponse(responseCode = "404", description = "NOT FOUND")})
88+
@Transactional
89+
@Tag(name = "Sdc School Collection", description = "Endpoints to reprocess school collection entity.")
90+
@Schema(name = "SdcSchoolCollection", implementation = SdcSchoolCollection.class)
91+
SdcSchoolCollection reprocessSchoolCollection(@RequestBody ReprocessSdcSchoolCollection reprocessData);
92+
8493
@PostMapping("/reportZeroEnrollment")
8594
@PreAuthorize("hasAuthority('SCOPE_WRITE_SDC_SCHOOL_COLLECTION')")
8695
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "BAD REQUEST"), @ApiResponse(responseCode = "404", description = "NOT FOUND")})

api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/service/v1/SdcSchoolCollectionService.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import ca.bc.gov.educ.studentdatacollection.api.exception.errors.ApiError;
1111
import ca.bc.gov.educ.studentdatacollection.api.model.v1.*;
1212
import ca.bc.gov.educ.studentdatacollection.api.repository.v1.*;
13+
import ca.bc.gov.educ.studentdatacollection.api.struct.ReprocessSdcSchoolCollection;
1314
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.ReportZeroEnrollmentSdcSchoolCollection;
1415
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.SdcFileSummary;
1516
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.UnsubmitSdcSchoolCollection;
@@ -237,6 +238,39 @@ public SdcSchoolCollectionEntity unsubmitSchoolCollection(UnsubmitSdcSchoolColle
237238
return sdcSchoolCollectionEntity;
238239
}
239240

241+
@Transactional(propagation = Propagation.REQUIRES_NEW)
242+
public SdcSchoolCollectionEntity reprocessSchoolCollection(ReprocessSdcSchoolCollection reprocessData) {
243+
Optional<SdcSchoolCollectionEntity> sdcSchoolCollectionOptional = sdcSchoolCollectionRepository.findById(reprocessData.getSdcSchoolCollectionID());
244+
SdcSchoolCollectionEntity sdcSchoolCollectionEntity = sdcSchoolCollectionOptional.orElseThrow(() -> new EntityNotFoundException(SdcSchoolCollectionEntity.class, SDC_SCHOOL_COLLECTION_ID_KEY, reprocessData.getSdcSchoolCollectionID().toString()));
245+
246+
if(StringUtils.equals(sdcSchoolCollectionEntity.getSdcSchoolCollectionStatusCode(), SdcSchoolCollectionStatus.P_DUP_POST.getCode())
247+
|| StringUtils.equals(sdcSchoolCollectionEntity.getSdcSchoolCollectionStatusCode(), SdcSchoolCollectionStatus.P_DUP_VRFD.getCode())) {
248+
ApiError error = ApiError.builder().timestamp(LocalDateTime.now()).message(INVALID_PAYLOAD_MSG).status(BAD_REQUEST).build();
249+
var validationError = ValidationUtil.createFieldError(SDC_SCHOOL_COLLECTION_ID_KEY, reprocessData.getSdcSchoolCollectionID(), "Cannot reprocess SDC School Collection that is in or beyond provincial duplicates.");
250+
List<FieldError> fieldErrorList = new ArrayList<>();
251+
fieldErrorList.add(validationError);
252+
error.addValidationErrors(fieldErrorList);
253+
throw new InvalidPayloadException(error);
254+
}
255+
256+
sdcSchoolCollectionEntity.getSDCSchoolStudentEntities().forEach(sdcSchoolCollectionStudentEntity -> {
257+
if (!StringUtils.equals(sdcSchoolCollectionStudentEntity.getSdcSchoolCollectionStudentStatusCode(), SdcSchoolStudentStatus.DELETED.getCode())) {
258+
TransformUtil.clearCalculatedFields(sdcSchoolCollectionStudentEntity, true);
259+
sdcSchoolCollectionStudentEntity.setSdcSchoolCollectionStudentStatusCode(SdcSchoolStudentStatus.LOADED.getCode());
260+
sdcSchoolCollectionStudentEntity.setUpdateDate(LocalDateTime.now());
261+
sdcSchoolCollectionStudentEntity.setUpdateUser(reprocessData.getUpdateUser());
262+
}
263+
});
264+
265+
sdcSchoolCollectionStudentStorageService.saveAllSDCStudentsWithHistory(sdcSchoolCollectionEntity.getSDCSchoolStudentEntities().stream().toList());
266+
267+
sdcSchoolCollectionEntity.setUpdateDate(LocalDateTime.now());
268+
sdcSchoolCollectionEntity.setUpdateUser(reprocessData.getUpdateUser());
269+
saveSdcSchoolCollectionWithHistory(sdcSchoolCollectionEntity);
270+
271+
return sdcSchoolCollectionEntity;
272+
}
273+
240274
@Transactional(propagation = Propagation.REQUIRES_NEW)
241275
public SdcSchoolCollectionEntity reportZeroEnrollment(ReportZeroEnrollmentSdcSchoolCollection reportZeroEnrollmentData) {
242276
Optional<SdcSchoolCollectionEntity> sdcSchoolCollectionOptional = sdcSchoolCollectionRepository.findById(reportZeroEnrollmentData.getSdcSchoolCollectionID());
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package ca.bc.gov.educ.studentdatacollection.api.struct;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import jakarta.validation.constraints.NotNull;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Builder;
7+
import lombok.Data;
8+
import lombok.NoArgsConstructor;
9+
10+
import java.util.UUID;
11+
12+
@Data
13+
@Builder
14+
@AllArgsConstructor
15+
@NoArgsConstructor
16+
@JsonIgnoreProperties(ignoreUnknown = true)
17+
public class ReprocessSdcSchoolCollection {
18+
@NotNull
19+
UUID sdcSchoolCollectionID;
20+
String updateUser;
21+
}

0 commit comments

Comments
 (0)