From e6231b52aceede3b1633b8ae4dfbaa7bc777e3e8 Mon Sep 17 00:00:00 2001 From: arybakov Date: Wed, 13 Sep 2023 17:19:10 -0600 Subject: [PATCH 1/7] GRAD2-1893 SUPP: Supplemental Distribution Run - Changes Required --- .../ca/bc/gov/educ/api/distribution/process/MergeProcess.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/process/MergeProcess.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/process/MergeProcess.java index fbe7657..8f28b46 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/process/MergeProcess.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/process/MergeProcess.java @@ -59,7 +59,7 @@ public ProcessorData fire(ProcessorData processorData) { List studListNonGrad = new ArrayList<>(); ReportRequest packSlipReq = reportService.preparePackingSlipData(searchRequest.getUser(), schoolDetails, processorData.getBatchId()); - if(distributionPrintRequest.getSchoolDistributionRequest() != null && MONTHLYDIST.equalsIgnoreCase(processorData.getActivityCode())) { + if(distributionPrintRequest.getSchoolDistributionRequest() != null && (MONTHLYDIST.equalsIgnoreCase(processorData.getActivityCode()) || SUPPDIST.equalsIgnoreCase(processorData.getActivityCode()))) { ReportRequest schoolDistributionReportRequest = reportService.prepareSchoolDistributionReportData(distributionPrintRequest.getSchoolDistributionRequest(), processorData.getBatchId(),schoolDetails); createAndSaveDistributionReport(schoolDistributionReportRequest,mincode,schoolCategoryCode,processorData); numberOfPdfs++; From a53673b791389d7cc37832aceb11fddb5f7a0c2a Mon Sep 17 00:00:00 2001 From: arybakov Date: Thu, 14 Sep 2023 11:06:27 -0600 Subject: [PATCH 2/7] GRAD2-1893 SUPP: Supplemental Distribution Run - Changes Required --- .../ca/bc/gov/educ/api/distribution/process/MergeProcess.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/process/MergeProcess.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/process/MergeProcess.java index 8f28b46..e5fdc56 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/process/MergeProcess.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/process/MergeProcess.java @@ -59,7 +59,7 @@ public ProcessorData fire(ProcessorData processorData) { List studListNonGrad = new ArrayList<>(); ReportRequest packSlipReq = reportService.preparePackingSlipData(searchRequest.getUser(), schoolDetails, processorData.getBatchId()); - if(distributionPrintRequest.getSchoolDistributionRequest() != null && (MONTHLYDIST.equalsIgnoreCase(processorData.getActivityCode()) || SUPPDIST.equalsIgnoreCase(processorData.getActivityCode()))) { + if(distributionPrintRequest.getSchoolDistributionRequest() != null && StringUtils.equalsAnyIgnoreCase(processorData.getActivityCode(), MONTHLYDIST, SUPPDIST)) { ReportRequest schoolDistributionReportRequest = reportService.prepareSchoolDistributionReportData(distributionPrintRequest.getSchoolDistributionRequest(), processorData.getBatchId(),schoolDetails); createAndSaveDistributionReport(schoolDistributionReportRequest,mincode,schoolCategoryCode,processorData); numberOfPdfs++; From 189b93e9181c7263ddf653c588c29b43405b1fb2 Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 2 Oct 2023 13:22:08 -0600 Subject: [PATCH 3/7] GRAD2-1869 User Request Blank Certificate Adult Dogwood to Advanced Education fails --- .../model/dto/StudentSearchRequest.java | 1 + .../api/distribution/process/BaseProcess.java | 6 ++-- .../process/CreateBlankCredentialProcess.java | 14 ++++----- .../process/CreateReprintProcess.java | 4 +-- .../distribution/process/MergeProcess.java | 4 +-- .../process/YearEndMergeProcess.java | 7 ++--- .../distribution/service/ReportService.java | 21 +++++++------ .../distribution/service/SchoolService.java | 31 +++++++++---------- .../service/DistributionServiceTest.java | 6 ++-- .../service/SchoolServiceTest.java | 7 ++--- 10 files changed, 51 insertions(+), 50 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/StudentSearchRequest.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/StudentSearchRequest.java index 18b6a07..b07d2a4 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/StudentSearchRequest.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/StudentSearchRequest.java @@ -24,6 +24,7 @@ public class StudentSearchRequest implements Serializable { private List programs; private String user; + private Address address; @JsonFormat(pattern = "yyyy-MM-dd") Date gradDateFrom; diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/process/BaseProcess.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/process/BaseProcess.java index 4e3c289..27f4354 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/process/BaseProcess.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/process/BaseProcess.java @@ -57,9 +57,9 @@ public abstract class BaseProcess implements DistributionProcess { @Autowired PsiService psiService; - protected CommonSchool getBaseSchoolDetails(DistributionPrintRequest obj, String mincode, ExceptionMessage exception) { - if (obj != null && obj.getProperName() != null) - return schoolService.getCommonSchoolDetailsForPackingSlip(obj.getProperName()); + protected CommonSchool getBaseSchoolDetails(DistributionPrintRequest distributionPrintRequest, StudentSearchRequest searchRequest, String mincode, ExceptionMessage exception) { + if (distributionPrintRequest != null && distributionPrintRequest.getProperName() != null) + return schoolService.getDefaultSchoolDetailsForPackingSlip(searchRequest, distributionPrintRequest.getProperName()); else return schoolService.getCommonSchoolDetails(mincode, exception); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/process/CreateBlankCredentialProcess.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/process/CreateBlankCredentialProcess.java index 43d9fad..b854c5d 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/process/CreateBlankCredentialProcess.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/process/CreateBlankCredentialProcess.java @@ -40,16 +40,16 @@ public ProcessorData fire(ProcessorData processorData) { for (String mincode : mapDist.keySet()) { counter++; int currentSlipCount = 0; - DistributionPrintRequest obj = mapDist.get(mincode); - CommonSchool schoolDetails = getBaseSchoolDetails(obj,mincode,exception); + DistributionPrintRequest distributionPrintRequest = mapDist.get(mincode); + CommonSchool schoolDetails = getBaseSchoolDetails(distributionPrintRequest, searchRequest, mincode,exception); if(schoolDetails != null) { logger.debug("*** School Details Acquired {}", schoolDetails.getSchoolName()); - ReportRequest packSlipReq = reportService.preparePackingSlipData(searchRequest.getUser(), schoolDetails, processorData.getBatchId()); - numberOfPdfs = processYed4Transcript(obj,currentSlipCount,packSlipReq,mincode,processorData,numberOfPdfs); - numberOfPdfs = processYed2Certificate(obj,currentSlipCount,packSlipReq,mincode,processorData,numberOfPdfs); - numberOfPdfs = processYedbCertificate(obj,currentSlipCount,packSlipReq,mincode,processorData,numberOfPdfs); - numberOfPdfs = processYedrCertificate(obj,currentSlipCount,packSlipReq,mincode,processorData,numberOfPdfs); + ReportRequest packSlipReq = reportService.preparePackingSlipData(searchRequest, schoolDetails, processorData.getBatchId()); + numberOfPdfs = processYed4Transcript(distributionPrintRequest,currentSlipCount,packSlipReq,mincode,processorData,numberOfPdfs); + numberOfPdfs = processYed2Certificate(distributionPrintRequest,currentSlipCount,packSlipReq,mincode,processorData,numberOfPdfs); + numberOfPdfs = processYedbCertificate(distributionPrintRequest,currentSlipCount,packSlipReq,mincode,processorData,numberOfPdfs); + numberOfPdfs = processYedrCertificate(distributionPrintRequest,currentSlipCount,packSlipReq,mincode,processorData,numberOfPdfs); logger.debug("PDFs Merged {}", schoolDetails.getSchoolName()); logger.debug("{} School {}/{}",mincode,counter,mapDist.size()); diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/process/CreateReprintProcess.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/process/CreateReprintProcess.java index 87e3325..c4fe2a6 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/process/CreateReprintProcess.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/process/CreateReprintProcess.java @@ -39,11 +39,11 @@ public ProcessorData fire(ProcessorData processorData) { counter++; int currentSlipCount = 0; DistributionPrintRequest obj = mapDist.get(mincode); - CommonSchool schoolDetails = getBaseSchoolDetails(obj,mincode,exception); + CommonSchool schoolDetails = getBaseSchoolDetails(obj, searchRequest, mincode,exception); if(schoolDetails != null) { logger.debug("*** School Details Acquired {}", schoolDetails.getSchoolName()); - ReportRequest packSlipReq = reportService.preparePackingSlipData(searchRequest.getUser(), schoolDetails, processorData.getBatchId()); + ReportRequest packSlipReq = reportService.preparePackingSlipData(searchRequest, schoolDetails, processorData.getBatchId()); if(obj.getSchoolDistributionRequest() != null) { ReportRequest schoolDistributionReportRequest = reportService.prepareSchoolDistributionReportData(obj.getSchoolDistributionRequest(), processorData.getBatchId(),schoolDetails); diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/process/MergeProcess.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/process/MergeProcess.java index b5bda1c..1edfdbe 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/process/MergeProcess.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/process/MergeProcess.java @@ -54,12 +54,12 @@ public ProcessorData fire(ProcessorData processorData) { counter++; int currentSlipCount = 0; DistributionPrintRequest distributionPrintRequest = mapDist.get(mincode); - CommonSchool schoolDetails = getBaseSchoolDetails(distributionPrintRequest,mincode,exception); + CommonSchool schoolDetails = getBaseSchoolDetails(distributionPrintRequest, searchRequest, mincode,exception); if(schoolDetails != null) { String schoolCategoryCode = schoolDetails.getSchoolCategoryCode(); logger.debug("*** School Details Acquired {} category {}", mincode, schoolCategoryCode); List studListNonGrad = new ArrayList<>(); - ReportRequest packSlipReq = reportService.preparePackingSlipData(searchRequest.getUser(), schoolDetails, processorData.getBatchId()); + ReportRequest packSlipReq = reportService.preparePackingSlipData(searchRequest, schoolDetails, processorData.getBatchId()); if(distributionPrintRequest.getSchoolDistributionRequest() != null && MONTHLYDIST.equalsIgnoreCase(processorData.getActivityCode())) { ReportRequest schoolDistributionReportRequest = reportService.prepareSchoolDistributionReportData(distributionPrintRequest.getSchoolDistributionRequest(), processorData.getBatchId(),schoolDetails); diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/process/YearEndMergeProcess.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/process/YearEndMergeProcess.java index 53c2ea9..5116cae 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/process/YearEndMergeProcess.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/process/YearEndMergeProcess.java @@ -42,7 +42,8 @@ public ProcessorData fire(ProcessorData processorData) { List schoolsForLabels = new ArrayList<>(); List districtsForLabels = new ArrayList<>(); for (String mincode : mapDist.keySet()) { - CommonSchool commonSchool = getBaseSchoolDetails(null, mincode, exception); + DistributionPrintRequest distributionPrintRequest = mapDist.get(mincode); + CommonSchool commonSchool = getBaseSchoolDetails(distributionPrintRequest, searchRequest, mincode, exception); if (commonSchool != null) { int currentSlipCount = 0; schoolCounter++; @@ -60,9 +61,7 @@ public ProcessorData fire(ProcessorData processorData) { logger.debug("{} School {}/{}", mincode, schoolCounter, mapDist.size()); List studListNonGrad = new ArrayList<>(); - DistributionPrintRequest distributionPrintRequest = mapDist.get(mincode); - - ReportRequest packSlipReq = reportService.preparePackingSlipData(searchRequest.getUser(), getBaseSchoolDetails(distributionPrintRequest, mincode, exception), processorData.getBatchId()); + ReportRequest packSlipReq = reportService.preparePackingSlipData(searchRequest, getBaseSchoolDetails(distributionPrintRequest, searchRequest, mincode, exception), processorData.getBatchId()); Pair pV = processTranscriptPrintRequest(distributionPrintRequest, currentSlipCount, packSlipReq, studListNonGrad, processorData, mincode, schoolCategoryCode, numberOfPdfs); currentSlipCount = pV.getLeft(); numberOfPdfs = pV.getRight(); diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/service/ReportService.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/service/ReportService.java index 8b08ede..5785ffa 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/service/ReportService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/service/ReportService.java @@ -55,21 +55,24 @@ public InputStreamResource getPackingSlip(ReportRequest packingSlipReq) { return new InputStreamResource(bis); } - public ReportRequest preparePackingSlipData(String recipient, CommonSchool schoolDetails, Long batchId) { + public ReportRequest preparePackingSlipData(StudentSearchRequest searchRequest, CommonSchool schoolDetails, Long batchId) { School schObj = new School(); - Address addr = new Address(); - addr.setStreetLine1(schoolDetails.getScAddressLine1()); - addr.setStreetLine2(schoolDetails.getScAddressLine2()); - addr.setCity(schoolDetails.getScCity()); - addr.setCode(schoolDetails.getScPostalCode()); - addr.setCountry(schoolDetails.getScCountryCode()); - addr.setRegion(schoolDetails.getScProvinceCode()); + boolean useSchoolAddress = searchRequest == null || searchRequest.getAddress() == null; + Address addr = useSchoolAddress ? new Address() : searchRequest.getAddress(); + if(useSchoolAddress) { + addr.setStreetLine1(schoolDetails.getScAddressLine1()); + addr.setStreetLine2(schoolDetails.getScAddressLine2()); + addr.setCity(schoolDetails.getScCity()); + addr.setCode(schoolDetails.getScPostalCode()); + addr.setCountry(schoolDetails.getScCountryCode()); + addr.setRegion(schoolDetails.getScProvinceCode()); + } schObj.setAddress(addr); schObj.setDistno(schoolDetails.getDistNo()); schObj.setName(schoolDetails.getSchoolName()); schObj.setSchlno(schoolDetails.getSchlNo()); schObj.setMincode(schoolDetails.getDistNo()+schoolDetails.getSchlNo()); - return createReportRequest(batchId,schObj,recipient); + return createReportRequest(batchId,schObj, searchRequest.getUser()); } public ReportRequest preparePackingSlipDataPSI(Psi psiDetails,Long batchId) { diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/service/SchoolService.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/service/SchoolService.java index 116aea4..2af61d2 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/service/SchoolService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/service/SchoolService.java @@ -1,11 +1,9 @@ package ca.bc.gov.educ.api.distribution.service; -import ca.bc.gov.educ.api.distribution.model.dto.CommonSchool; -import ca.bc.gov.educ.api.distribution.model.dto.ExceptionMessage; -import ca.bc.gov.educ.api.distribution.model.dto.TraxDistrict; -import ca.bc.gov.educ.api.distribution.model.dto.TraxSchool; +import ca.bc.gov.educ.api.distribution.model.dto.*; import ca.bc.gov.educ.api.distribution.util.EducDistributionApiConstants; import ca.bc.gov.educ.api.distribution.util.RestUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,18 +41,19 @@ public CommonSchool getCommonSchoolDetails(String mincode, ExceptionMessage exce return commonSchool; } - public CommonSchool getCommonSchoolDetailsForPackingSlip(String properName) { - CommonSchool fakeSchoolObj = new CommonSchool(); - fakeSchoolObj.setSchlNo(String.format("%09d" , 0)); - fakeSchoolObj.setSchoolName(properName); - fakeSchoolObj.setDistNo(String.format("%03d" , 0)); - fakeSchoolObj.setScAddressLine1("4TH FLOOR 620 SUPERIOR"); - fakeSchoolObj.setScAddressLine2("PO BOX 9886 STN PROV GOVT"); - fakeSchoolObj.setScCity("VICTORIA"); - fakeSchoolObj.setScProvinceCode("BC"); - fakeSchoolObj.setScPostalCode("V8W 9T6"); - fakeSchoolObj.setScCountryCode("CN"); - return fakeSchoolObj; + public CommonSchool getDefaultSchoolDetailsForPackingSlip(StudentSearchRequest searchRequest, String properName) { + CommonSchool commonSchool = new CommonSchool(); + Address address = (searchRequest == null || searchRequest.getAddress() == null) ? null : searchRequest.getAddress(); + commonSchool.setSchlNo(String.format("%09d" , 0)); + commonSchool.setSchoolName(ObjectUtils.defaultIfNull(properName, ObjectUtils.defaultIfNull(searchRequest.getUser(), ""))); + commonSchool.setDistNo(String.format("%03d" , 0)); + commonSchool.setScAddressLine1(address == null ? "4TH FLOOR 620 SUPERIOR" : address.getStreetLine1()); + commonSchool.setScAddressLine2(address == null ? "PO BOX 9886 STN PROV GOVT" : address.getStreetLine2()); + commonSchool.setScCity(address == null ? "VICTORIA" : address.getCity()); + commonSchool.setScProvinceCode(address == null ? "BC" : address.getRegion()); + commonSchool.setScPostalCode(address == null ? "V8W 9T6" : address.getCode()); + commonSchool.setScCountryCode(address == null ? "CN" : address.getCountry()); + return commonSchool; } public TraxSchool getTraxSchool(String minCode, ExceptionMessage exception) { diff --git a/api/src/test/java/ca/bc/gov/educ/api/distribution/service/DistributionServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/distribution/service/DistributionServiceTest.java index 7bd14cd..8553362 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/distribution/service/DistributionServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/distribution/service/DistributionServiceTest.java @@ -775,7 +775,9 @@ private synchronized DistributionResponse testdistributeCredentials_transcript(S printRequest.setSchoolDistributionRequest(sdReq); mapDist.put(mincode, printRequest); - mockTraxSchool(mincode); + if (!schoolNull) { + mockTraxSchool(mincode); + } byte[] bytesSAR = "Any String you want".getBytes(); when(this.webClient.post()).thenReturn(this.requestBodyUriMock); @@ -1062,7 +1064,7 @@ private synchronized DistributionResponse testdistributeCredentials_certificate( if (properName == null) Mockito.doReturn(schObj).when(schoolService).getCommonSchoolDetails(mincode, exception); else - Mockito.doReturn(schObj).when(schoolService).getCommonSchoolDetailsForPackingSlip(properName); + Mockito.doReturn(schObj).when(schoolService).getDefaultSchoolDetailsForPackingSlip(null, properName); ProcessorData data = new ProcessorData(); data.setAccessToken(MOCK_TOKEN); diff --git a/api/src/test/java/ca/bc/gov/educ/api/distribution/service/SchoolServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/distribution/service/SchoolServiceTest.java index 730312c..1c4235b 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/distribution/service/SchoolServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/distribution/service/SchoolServiceTest.java @@ -1,9 +1,6 @@ package ca.bc.gov.educ.api.distribution.service; -import ca.bc.gov.educ.api.distribution.model.dto.CommonSchool; -import ca.bc.gov.educ.api.distribution.model.dto.ExceptionMessage; -import ca.bc.gov.educ.api.distribution.model.dto.TraxDistrict; -import ca.bc.gov.educ.api.distribution.model.dto.TraxSchool; +import ca.bc.gov.educ.api.distribution.model.dto.*; import ca.bc.gov.educ.api.distribution.util.EducDistributionApiConstants; import org.junit.Assert; import org.junit.Test; @@ -91,7 +88,7 @@ public void testGetCommonSchoolDetails_Exception() { @Test public void testGetCommonSchoolDetailsForPackingSlip() { String properName = "properName"; - var response = this.schoolService.getCommonSchoolDetailsForPackingSlip(properName); + var response = this.schoolService.getDefaultSchoolDetailsForPackingSlip(new StudentSearchRequest(), properName); Assert.assertNotNull(response); } From 229e099f53d52dfd513af9f8f13bdde8b12a8117 Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 2 Oct 2023 14:28:03 -0600 Subject: [PATCH 4/7] Fix NPE --- .../bc/gov/educ/api/distribution/service/ReportService.java | 5 +++-- .../bc/gov/educ/api/distribution/service/SchoolService.java | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/service/ReportService.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/service/ReportService.java index 5785ffa..2e83e21 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/service/ReportService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/service/ReportService.java @@ -57,7 +57,7 @@ public InputStreamResource getPackingSlip(ReportRequest packingSlipReq) { public ReportRequest preparePackingSlipData(StudentSearchRequest searchRequest, CommonSchool schoolDetails, Long batchId) { School schObj = new School(); - boolean useSchoolAddress = searchRequest == null || searchRequest.getAddress() == null; + boolean useSchoolAddress = (searchRequest == null || searchRequest.getAddress() == null); Address addr = useSchoolAddress ? new Address() : searchRequest.getAddress(); if(useSchoolAddress) { addr.setStreetLine1(schoolDetails.getScAddressLine1()); @@ -72,7 +72,8 @@ public ReportRequest preparePackingSlipData(StudentSearchRequest searchRequest, schObj.setName(schoolDetails.getSchoolName()); schObj.setSchlno(schoolDetails.getSchlNo()); schObj.setMincode(schoolDetails.getDistNo()+schoolDetails.getSchlNo()); - return createReportRequest(batchId,schObj, searchRequest.getUser()); + String userName = searchRequest == null ? "" : searchRequest.getUser(); + return createReportRequest(batchId,schObj, userName); } public ReportRequest preparePackingSlipDataPSI(Psi psiDetails,Long batchId) { diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/service/SchoolService.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/service/SchoolService.java index 2af61d2..282bade 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/service/SchoolService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/service/SchoolService.java @@ -44,8 +44,9 @@ public CommonSchool getCommonSchoolDetails(String mincode, ExceptionMessage exce public CommonSchool getDefaultSchoolDetailsForPackingSlip(StudentSearchRequest searchRequest, String properName) { CommonSchool commonSchool = new CommonSchool(); Address address = (searchRequest == null || searchRequest.getAddress() == null) ? null : searchRequest.getAddress(); + String userName = searchRequest == null ? null : searchRequest.getUser(); commonSchool.setSchlNo(String.format("%09d" , 0)); - commonSchool.setSchoolName(ObjectUtils.defaultIfNull(properName, ObjectUtils.defaultIfNull(searchRequest.getUser(), ""))); + commonSchool.setSchoolName(ObjectUtils.defaultIfNull(properName, ObjectUtils.defaultIfNull(userName, ""))); commonSchool.setDistNo(String.format("%03d" , 0)); commonSchool.setScAddressLine1(address == null ? "4TH FLOOR 620 SUPERIOR" : address.getStreetLine1()); commonSchool.setScAddressLine2(address == null ? "PO BOX 9886 STN PROV GOVT" : address.getStreetLine2()); From 966def131238aa7a3dc9cc6c372c0717c6938fb6 Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 2 Oct 2023 14:42:44 -0600 Subject: [PATCH 5/7] Fix NPE --- .../service/ReportServiceTest.java | 42 +++++++++++++++++++ .../service/SchoolServiceTest.java | 26 ++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 api/src/test/java/ca/bc/gov/educ/api/distribution/service/ReportServiceTest.java diff --git a/api/src/test/java/ca/bc/gov/educ/api/distribution/service/ReportServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/distribution/service/ReportServiceTest.java new file mode 100644 index 0000000..ac43588 --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/distribution/service/ReportServiceTest.java @@ -0,0 +1,42 @@ +package ca.bc.gov.educ.api.distribution.service; + +import ca.bc.gov.educ.api.distribution.model.dto.Address; +import ca.bc.gov.educ.api.distribution.model.dto.CommonSchool; +import ca.bc.gov.educ.api.distribution.model.dto.StudentSearchRequest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@SpringBootTest +@RunWith(SpringRunner.class) +public class ReportServiceTest { + + @Autowired + private ReportService reportService; + + @Test + public void testPreparePackingSlipData() { + String mincode = "123456"; + CommonSchool commonSchool = new CommonSchool(); + commonSchool.setSchlNo(mincode); + commonSchool.setSchoolName("Test School"); + + StudentSearchRequest searchRequest = new StudentSearchRequest(); + searchRequest.setUser("Test User"); + searchRequest.setAddress(new Address()); + + var response = this.reportService.preparePackingSlipData(searchRequest, commonSchool, 0L); + Assert.assertNotNull(response); + + searchRequest.setUser(null); + searchRequest.setAddress(null); + + response = this.reportService.preparePackingSlipData(searchRequest, commonSchool, 0L); + Assert.assertNotNull(response); + } + + +} diff --git a/api/src/test/java/ca/bc/gov/educ/api/distribution/service/SchoolServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/distribution/service/SchoolServiceTest.java index 1c4235b..a94579b 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/distribution/service/SchoolServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/distribution/service/SchoolServiceTest.java @@ -64,6 +64,32 @@ public void testGetCommonSchoolDetails() { Assert.assertEquals(mincode, response.getSchlNo()); } + @Test + public void testGetDefaultSchoolDetails() { + String mincode = "123456"; + CommonSchool commonSchool = new CommonSchool(); + commonSchool.setSchlNo(mincode); + commonSchool.setSchoolName("Test School"); + commonSchool.setScCity("VANCOUVER"); + + StudentSearchRequest searchRequest = new StudentSearchRequest(); + searchRequest.setUser("Test User"); + Address address = new Address(); + address.setCity("VANCOUVER"); + searchRequest.setAddress(address); + + var response = this.schoolService.getDefaultSchoolDetailsForPackingSlip(searchRequest, "properName"); + Assert.assertNotNull(response); + Assert.assertEquals("VANCOUVER", response.getScCity()); + + searchRequest.setUser(null); + searchRequest.setAddress(null); + + response = this.schoolService.getDefaultSchoolDetailsForPackingSlip(searchRequest, "properName"); + Assert.assertNotNull(response); + Assert.assertEquals("VICTORIA", response.getScCity()); + } + @Test public void testGetCommonSchoolDetails_Exception() { String mincode = "123456"; From 2bb4180672665d9640685136f09de0b588646889 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 17 Oct 2023 14:38:44 -0600 Subject: [PATCH 6/7] GRAD2-2339 Monthly Graduation Run - Distribution Report Counts Error --- .../model/dto/GraduationStatus.java | 5 +- .../distribution/service/ReportService.java | 75 +++++++++++-------- 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/GraduationStatus.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/GraduationStatus.java index 19b03dc..2cfe62a 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/GraduationStatus.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/GraduationStatus.java @@ -7,6 +7,7 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.NoArgsConstructor; +import org.apache.commons.lang3.StringUtils; import java.io.Serializable; import java.time.LocalDate; @@ -103,7 +104,9 @@ public String getCertificates() { } public void setCertificates(String certificates) { - this.certificates = certificates; + String nextSeparator = StringUtils.isNotBlank(this.certificates) ? "," : ""; + String nextCertificate = StringUtils.isNotBlank(certificates) ? nextSeparator + certificates : ""; + this.certificates = StringUtils.defaultIfBlank(this.certificates, "") + nextCertificate; } public String getGraduationMessage() { diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/service/ReportService.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/service/ReportService.java index 8b08ede..67fbbda 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/service/ReportService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/service/ReportService.java @@ -15,10 +15,7 @@ import org.springframework.web.reactive.function.client.WebClient; import java.io.ByteArrayInputStream; -import java.util.ArrayList; -import java.util.Date; -import java.util.LinkedHashSet; -import java.util.List; +import java.util.*; @Service public class ReportService { @@ -123,40 +120,52 @@ public ReportRequest prepareSchoolDistributionReportData(SchoolDistributionReque ReportData data = new ReportData(); List schoolReportList = schoolDistributionRequest.getStudentList(); - List stdList = new ArrayList<>(); - School schObj = new School(); - schObj.setMincode(schoolDetails.getDistNo()+schoolDetails.getSchlNo()); - schObj.setName(schoolDetails.getSchoolName()); + Map students = new HashMap<>(); + School school = new School(); + school.setMincode(schoolDetails.getDistNo()+schoolDetails.getSchlNo()); + school.setName(schoolDetails.getSchoolName()); for(StudentCredentialDistribution sc:schoolReportList) { - Student std = new Student(); - std.setFirstName(sc.getLegalFirstName()); - std.setLastName(sc.getLegalLastName()); - std.setMiddleName(sc.getLegalMiddleNames()); - std.setCitizenship(sc.getStudentCitizenship()); + Pen pen = new Pen(); pen.setPen(sc.getPen()); pen.setEntityID("" + sc.getStudentID()); - std.setPen(pen); - std.setGradProgram(sc.getProgram()); - GraduationData gradData = new GraduationData(); - gradData.setGraduationDate(sc.getProgramCompletionDate() != null ? EducDistributionApiUtils.asDate(sc.getProgramCompletionDate()) : null); - gradData.setHonorsFlag(sc.getHonoursStanding() != null && sc.getHonoursStanding().equalsIgnoreCase("Y")); - std.setGraduationData(gradData); - - std.setGraduationStatus(GraduationStatus.builder() - .programCompletionDate(sc.getProgramCompletionDate()) - .honours(sc.getHonoursStanding()) - .programName(sc.getProgram()) - .studentGrade(sc.getStudentGrade()) - .schoolOfRecord(sc.getSchoolOfRecord()) - .build()); - - stdList.add(std); + Student student = students.get(pen); + + if (student == null) { + + student = new Student(); + + student.setFirstName(sc.getLegalFirstName()); + student.setLastName(sc.getLegalLastName()); + student.setMiddleName(sc.getLegalMiddleNames()); + student.setCitizenship(sc.getStudentCitizenship()); + + student.setPen(pen); + student.setGradProgram(sc.getProgram()); + GraduationData gradData = new GraduationData(); + gradData.setGraduationDate(sc.getProgramCompletionDate() != null ? EducDistributionApiUtils.asDate(sc.getProgramCompletionDate()) : null); + gradData.setHonorsFlag(sc.getHonoursStanding() != null && sc.getHonoursStanding().equalsIgnoreCase("Y")); + student.setGraduationData(gradData); + + student.setGraduationStatus(GraduationStatus.builder() + .programCompletionDate(sc.getProgramCompletionDate()) + .honours(sc.getHonoursStanding()) + .programName(sc.getProgram()) + .studentGrade(sc.getStudentGrade()) + .schoolOfRecord(sc.getSchoolOfRecord()) + .build()); + + students.put(pen, student); + } + //Add student certificate into the list of student certificate credentials + if(!"YED4".equalsIgnoreCase(sc.getPaperType())) { + student.getGraduationStatus().setCertificates(sc.getCredentialTypeCode()); + } } //No dups for school report - List uniqueStudentList = new ArrayList<>(new LinkedHashSet<>(stdList)); - schObj.setStudents(uniqueStudentList); - data.setSchool(schObj); + List uniqueStudentList = new ArrayList<>(students.values()); + school.setStudents(uniqueStudentList); + data.setSchool(school); data.setOrgCode(StringUtils.startsWith(data.getSchool().getMincode(), "098") ? "YU" : "BC"); data.setReportNumber(data.getOrgCode()+"-"+batchId); req.setData(data); @@ -165,7 +174,7 @@ public ReportRequest prepareSchoolDistributionReportData(SchoolDistributionReque options.setConvertTo("pdf"); options.setCacheReport(false); options.setOverwrite(false); - options.setReportFile(String.format("%s School distribution.%s", schObj.getMincode(), options.getConvertTo())); + options.setReportFile(String.format("%s School distribution.%s", school.getMincode(), options.getConvertTo())); options.setReportName("SchoolDistribution"); req.setOptions(options); From ae2f27f8606babf447b85e71621fc4a76a1650b6 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Fri, 17 Nov 2023 02:46:02 +0530 Subject: [PATCH 7/7] Update pom.xml --- api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/pom.xml b/api/pom.xml index 3fed912..b7c9dce 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -6,7 +6,7 @@ ca.bc.gov.educ educ-grad-distribution-api - 1.8.51 + 1.8.52 educ-grad-distribution-api Ministry of Education GRAD DISTRIBUTION API