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 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/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..e0ab9c1 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,14 +54,14 @@ 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())) { + 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++; 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..70799e9 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 { @@ -55,21 +52,25 @@ 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); + String userName = searchRequest == null ? "" : searchRequest.getUser(); + return createReportRequest(batchId,schObj, userName); } public ReportRequest preparePackingSlipDataPSI(Psi psiDetails,Long batchId) { @@ -123,40 +124,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 +178,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); 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..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 @@ -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,20 @@ 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(); + String userName = searchRequest == null ? null : searchRequest.getUser(); + commonSchool.setSchlNo(String.format("%09d" , 0)); + 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()); + 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/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 730312c..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 @@ -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; @@ -67,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"; @@ -91,7 +114,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); }