Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grad release 1.10.0 #234

Merged
merged 10 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ca.bc.gov.educ</groupId>
<artifactId>educ-grad-distribution-api</artifactId>
<version>1.8.51</version>
<version>1.8.52</version>
<name>educ-grad-distribution-api</name>
<description>Ministry of Education GRAD DISTRIBUTION API</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class StudentSearchRequest implements Serializable {
private List<String> programs;

private String user;
private Address address;

@JsonFormat(pattern = "yyyy-MM-dd")
Date gradDateFrom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Student> 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++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public ProcessorData fire(ProcessorData processorData) {
List<School> schoolsForLabels = new ArrayList<>();
List<School> 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++;
Expand All @@ -60,9 +61,7 @@ public ProcessorData fire(ProcessorData processorData) {
logger.debug("{} School {}/{}", mincode, schoolCounter, mapDist.size());
List<Student> 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<Integer, Integer> pV = processTranscriptPrintRequest(distributionPrintRequest, currentSlipCount, packSlipReq, studListNonGrad, processorData, mincode, schoolCategoryCode, numberOfPdfs);
currentSlipCount = pV.getLeft();
numberOfPdfs = pV.getRight();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -123,40 +124,52 @@ public ReportRequest prepareSchoolDistributionReportData(SchoolDistributionReque
ReportData data = new ReportData();

List<StudentCredentialDistribution> schoolReportList = schoolDistributionRequest.getStudentList();
List<Student> stdList = new ArrayList<>();
School schObj = new School();
schObj.setMincode(schoolDetails.getDistNo()+schoolDetails.getSchlNo());
schObj.setName(schoolDetails.getSchoolName());
Map<Pen, Student> 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<Student> uniqueStudentList = new ArrayList<>(new LinkedHashSet<>(stdList));
schObj.setStudents(uniqueStudentList);
data.setSchool(schObj);
List<Student> 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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}


}
Loading
Loading