@@ -58,13 +58,14 @@ public class SdcSchoolCollectionService {
58
58
private final SdcDistrictCollectionRepository sdcDistrictCollectionRepository ;
59
59
private final SdcSchoolCollectionStudentValidationIssueRepository sdcSchoolCollectionStudentValidationIssueRepository ;
60
60
private final SdcSchoolCollectionLightRepository sdcSchoolCollectionLightRepository ;
61
+ private final SagaRepository sagaRepository ;
61
62
62
63
private static final String INVALID_PAYLOAD_MSG = "Payload contains invalid data." ;
63
64
private static final String SDC_SCHOOL_COLLECTION_ID_KEY = "sdcSchoolCollectionID" ;
64
65
private final DateTimeFormatter formatter = DateTimeFormatter .ofPattern ("yyyyMMdd" );
65
66
66
67
@ Autowired
67
- public SdcSchoolCollectionService (SdcSchoolCollectionRepository sdcSchoolCollectionRepository , SdcSchoolCollectionStudentRepository sdcSchoolCollectionStudentRepository , SdcSchoolCollectionHistoryService sdcSchoolCollectionHistoryService , SdcSchoolCollectionStudentHistoryRepository sdcSchoolCollectionStudentHistoryRepository , SdcDuplicateRepository sdcDuplicateRepository , SdcSchoolCollectionStudentStorageService sdcSchoolCollectionStudentStorageService , SdcSchoolCollectionStudentHistoryService sdcSchoolCollectionStudentHistoryService , CollectionRepository collectionRepository , SdcDistrictCollectionRepository sdcDistrictCollectionRepository , SdcDistrictCollectionService sdcDistrictCollectionService , SdcSchoolCollectionStudentValidationIssueRepository sdcSchoolCollectionStudentValidationIssueRepository , SdcSchoolCollectionLightRepository sdcSchoolCollectionLightRepository ) {
68
+ public SdcSchoolCollectionService (SdcSchoolCollectionRepository sdcSchoolCollectionRepository , SdcSchoolCollectionStudentRepository sdcSchoolCollectionStudentRepository , SdcSchoolCollectionHistoryService sdcSchoolCollectionHistoryService , SdcSchoolCollectionStudentHistoryRepository sdcSchoolCollectionStudentHistoryRepository , SdcDuplicateRepository sdcDuplicateRepository , SdcSchoolCollectionStudentStorageService sdcSchoolCollectionStudentStorageService , SdcSchoolCollectionStudentHistoryService sdcSchoolCollectionStudentHistoryService , CollectionRepository collectionRepository , SdcDistrictCollectionRepository sdcDistrictCollectionRepository , SdcDistrictCollectionService sdcDistrictCollectionService , SdcSchoolCollectionStudentValidationIssueRepository sdcSchoolCollectionStudentValidationIssueRepository , SdcSchoolCollectionLightRepository sdcSchoolCollectionLightRepository , SagaRepository sagaRepository ) {
68
69
this .sdcSchoolCollectionRepository = sdcSchoolCollectionRepository ;
69
70
this .sdcSchoolCollectionStudentRepository = sdcSchoolCollectionStudentRepository ;
70
71
this .sdcSchoolCollectionHistoryService = sdcSchoolCollectionHistoryService ;
@@ -77,6 +78,7 @@ public SdcSchoolCollectionService(SdcSchoolCollectionRepository sdcSchoolCollect
77
78
this .sdcDistrictCollectionService = sdcDistrictCollectionService ;
78
79
this .sdcSchoolCollectionStudentValidationIssueRepository = sdcSchoolCollectionStudentValidationIssueRepository ;
79
80
this .sdcSchoolCollectionLightRepository = sdcSchoolCollectionLightRepository ;
81
+ this .sagaRepository = sagaRepository ;
80
82
}
81
83
82
84
@ Transactional (propagation = Propagation .MANDATORY )
@@ -253,6 +255,17 @@ public SdcSchoolCollectionEntity reprocessSchoolCollection(ReprocessSdcSchoolCol
253
255
throw new InvalidPayloadException (error );
254
256
}
255
257
258
+ if (sdcSchoolCollectionEntity .getSDCSchoolStudentEntities ().stream ().anyMatch (student -> StringUtils .equals (student .getSdcSchoolCollectionStudentStatusCode (), SdcSchoolStudentStatus .LOADED .getCode ()))) {
259
+ ApiError error = ApiError .builder ().timestamp (LocalDateTime .now ()).message (INVALID_PAYLOAD_MSG ).status (BAD_REQUEST ).build ();
260
+ var validationError = ValidationUtil .createFieldError (SDC_SCHOOL_COLLECTION_ID_KEY , reprocessData .getSdcSchoolCollectionID (), "Cannot reprocess SDC School Collection that has students in loaded status." );
261
+ List <FieldError > fieldErrorList = new ArrayList <>();
262
+ fieldErrorList .add (validationError );
263
+ error .addValidationErrors (fieldErrorList );
264
+ throw new InvalidPayloadException (error );
265
+ }
266
+
267
+ sagaRepository .deleteCompletedStudentProcessingSagas ();
268
+
256
269
sdcSchoolCollectionEntity .getSDCSchoolStudentEntities ().forEach (sdcSchoolCollectionStudentEntity -> {
257
270
if (!StringUtils .equals (sdcSchoolCollectionStudentEntity .getSdcSchoolCollectionStudentStatusCode (), SdcSchoolStudentStatus .DELETED .getCode ())) {
258
271
TransformUtil .clearCalculatedFields (sdcSchoolCollectionStudentEntity , true );
0 commit comments