Skip to content

Commit

Permalink
refactor to match duplicatePosting closeCollection from educ-student-…
Browse files Browse the repository at this point in the history
…admin
  • Loading branch information
alexmcdermid committed Jan 9, 2025
1 parent 570f51a commit 630f9d5
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class CloseCollectionService {
private final SdcSchoolCollectionStudentRepository sdcSchoolCollectionStudentRepository;
private final SdcSchoolCollectionStudentStorageService sdcSchoolCollectionStudentStorageService;
private final SdcSchoolCollectionService sdcSchoolCollectionService;
private final CodeTableService codeTableService;
private final RestUtils restUtils;
private final SdcSchoolCollectionRepository sdcSchoolCollectionRepository;
private final SdcSchoolCollectionStudentHistoryRepository sdcSchoolCollectionStudentHistoryRepository;
Expand All @@ -47,7 +48,7 @@ public class CloseCollectionService {
private static final String SDC_COLLECTION_ID_KEY = "collectionID";
private final IndependentSchoolFundingGroupSnapshotRepository independentSchoolFundingGroupSnapshotRepository;

public CloseCollectionService(CollectionRepository collectionRepository, CollectionTypeCodeRepository collectionTypeCodeRepository, CollectionCodeCriteriaRepository collectionCodeCriteriaRepository, SdcDistrictCollectionRepository sdcDistrictCollectionRepository, SdcSchoolCollectionHistoryService sdcSchoolHistoryService, SdcSchoolCollectionStudentRepository sdcSchoolCollectionStudentRepository, SdcSchoolCollectionStudentStorageService sdcSchoolCollectionStudentStorageService, SdcSchoolCollectionService sdcSchoolCollectionService, RestUtils restUtils, SdcSchoolCollectionRepository sdcSchoolCollectionRepository, SdcSchoolCollectionStudentHistoryRepository sdcSchoolCollectionStudentHistoryRepository, SdcDuplicateRepository sdcDuplicateRepository, EmailService emailService, EmailProperties emailProperties, IndependentSchoolFundingGroupSnapshotRepository independentSchoolFundingGroupSnapshotRepository) {
public CloseCollectionService(CollectionRepository collectionRepository, CollectionTypeCodeRepository collectionTypeCodeRepository, CollectionCodeCriteriaRepository collectionCodeCriteriaRepository, SdcDistrictCollectionRepository sdcDistrictCollectionRepository, SdcSchoolCollectionHistoryService sdcSchoolHistoryService, SdcSchoolCollectionStudentRepository sdcSchoolCollectionStudentRepository, SdcSchoolCollectionStudentStorageService sdcSchoolCollectionStudentStorageService, SdcSchoolCollectionService sdcSchoolCollectionService, RestUtils restUtils, SdcSchoolCollectionRepository sdcSchoolCollectionRepository, SdcSchoolCollectionStudentHistoryRepository sdcSchoolCollectionStudentHistoryRepository, SdcDuplicateRepository sdcDuplicateRepository, EmailService emailService, EmailProperties emailProperties, IndependentSchoolFundingGroupSnapshotRepository independentSchoolFundingGroupSnapshotRepository, CodeTableService codeTableService) {
this.collectionRepository = collectionRepository;
this.collectionTypeCodeRepository = collectionTypeCodeRepository;
this.collectionCodeCriteriaRepository = collectionCodeCriteriaRepository;
Expand All @@ -63,6 +64,7 @@ public CloseCollectionService(CollectionRepository collectionRepository, Collect
this.emailService = emailService;
this.emailProperties = emailProperties;
this.independentSchoolFundingGroupSnapshotRepository = independentSchoolFundingGroupSnapshotRepository;
this.codeTableService = codeTableService;
}

@Transactional(propagation = Propagation.REQUIRES_NEW)
Expand Down Expand Up @@ -98,8 +100,24 @@ public void openNewCollection() {
Optional<CollectionEntity> entityOptional = collectionRepository.findActiveCollection();
CollectionEntity currentCollectionEntity = entityOptional.orElseThrow(() -> new EntityNotFoundException(CollectionEntity.class, entityOptional.toString()));

LocalDate snapshotDate = currentCollectionEntity.getSnapshotDate();
snapshotDate = snapshotDate.isBefore(LocalDate.now()) ? snapshotDate.plusYears(1) : snapshotDate;
String closingCollectionType = currentCollectionEntity.getCollectionTypeCode();

String newCollectionType = CollectionTypeCodes.findByValue(closingCollectionType)
.map(CollectionTypeCodes::getNextCollectionToOpen)
.orElseThrow(() -> new IllegalArgumentException(
"No 'nextCollectionToOpen' mapping found for collection type: " + closingCollectionType));

CollectionTypeCodeEntity newCollectionTypeEntity = codeTableService.getCollectionCodeList()
.stream()
.filter(collectionTypeCodeEntity -> newCollectionType.equalsIgnoreCase(collectionTypeCodeEntity.getCollectionTypeCode()))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException(
"No CollectionTypeCodeEntity found for type: " + newCollectionType));

LocalDate snapshotDate = newCollectionTypeEntity.getSnapshotDate();
if (snapshotDate.isBefore(LocalDate.now())) {
snapshotDate = snapshotDate.plusYears(1);
}
LocalDate submissionDate = snapshotDate.plusWeeks(1).with(TemporalAdjusters.nextOrSame(DayOfWeek.FRIDAY));
LocalDate duplicationResolutionDueDate = submissionDate.plusWeeks(2);
LocalDate signOffDueDate = submissionDate.plusWeeks(3);
Expand Down

0 comments on commit 630f9d5

Please sign in to comment.