Skip to content

Commit 895a0a9

Browse files
Merge pull request #608 from bcgov/feature/GRAD2-3421
Feature/grad2 3421
2 parents dadce72 + 3b72d41 commit 895a0a9

9 files changed

Lines changed: 131 additions & 36 deletions

File tree

api/src/main/java/ca/bc/gov/educ/api/batchgraduation/model/StudentCredentialDistribution.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,10 @@ public class StudentCredentialDistribution implements Serializable {
3939
@JsonIgnore
4040
private String schoolOfRecord; // minCode is required for the print file name
4141

42+
//Start of YE specific properties
43+
private String reportingSchoolTypeCode;
44+
private String transcriptTypeCode;
45+
private String certificateTypeCode;
46+
//End of YE specific properties
47+
4248
}

api/src/main/java/ca/bc/gov/educ/api/batchgraduation/processor/DistributionRunStatusUpdateProcessor.java

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import ca.bc.gov.educ.api.batchgraduation.rest.RestUtils;
77
import ca.bc.gov.educ.api.batchgraduation.service.DistributionService;
88
import ca.bc.gov.educ.api.batchgraduation.util.JsonTransformer;
9+
import ca.bc.gov.educ.api.batchgraduation.util.ThreadLocalStateUtil;
10+
import com.google.common.collect.Lists;
911
import org.apache.commons.lang3.StringUtils;
1012
import org.slf4j.Logger;
1113
import org.slf4j.LoggerFactory;
@@ -71,38 +73,41 @@ private Map<String, ServiceException> updateBackStudentRecords(List<StudentCrede
7173
final int totalCredentialCount = cList.size();
7274
List<UUID> studentIDs = cList.stream().map(StudentCredentialDistribution::getStudentID).distinct().toList();
7375
final int totalStudentCount = studentIDs.size();
76+
final int partitionSize = 999;
7477

75-
final int[] processedCount = {1};
78+
final int[] processedCount = {0};
7679
// Credential Records
77-
cList.forEach(scd-> {
78-
try {
80+
if(!cList.isEmpty()) {
81+
List<List<StudentCredentialDistribution>> studentCredPartitions = Lists.partition(cList, partitionSize);
82+
studentCredPartitions.forEach(studentCredPartition -> {
83+
if ("NONGRADYERUN".equalsIgnoreCase(activityCode)) { studentCredPartition.forEach(entry -> entry.setDocumentStatusCode("IP")); }
7984
final String accessToken = restUtils.getAccessToken();
80-
restUtils.updateStudentCredentialRecord(scd.getStudentID(),scd.getCredentialTypeCode(),scd.getPaperType(),
81-
"NONGRADYERUN".equalsIgnoreCase(activityCode)? "IP" : scd.getDocumentStatusCode(),activityCode,accessToken);
82-
LOGGER.debug("Dist Job [{}] / [{}] - update {} of {} student credential record: studentID, credentials, document status [{}, {}, {}]", batchId, activityCode, processedCount[0], totalCredentialCount, scd.getStudentID(), scd.getCredentialTypeCode(), scd.getDocumentStatusCode());
83-
processedCount[0]++;
84-
} catch (Exception e) {
85-
unprocessedStudents.put(scd.getStudentID().toString(), new ServiceException(e));
86-
LOGGER.error("Unexpected Error on update {} of {} student credential record: studentID [{}] \n {}",
87-
processedCount[0], totalCredentialCount, scd.getStudentID(), e.getMessage());
85+
Integer processed = restUtils.updateStudentCredentialRecords(studentCredPartition, activityCode, accessToken);
86+
if(studentCredPartition.size() != processed) {
87+
studentCredPartition.stream().forEach(scd -> unprocessedStudents.put(scd.getStudentID().toString(), new ServiceException("Updating student credential failed.")));
88+
}
89+
processedCount[0] = processedCount[0] + processed;
90+
});
91+
LOGGER.debug("Dist Job [{}] / [{}] - updated {} of {} student credential record", batchId, activityCode, processedCount[0], totalCredentialCount);
92+
if (cList.size() != processedCount[0]) {
93+
LOGGER.error("Dist Job [{}] / [{}] - Unexpected Error on updating student credential record {} of {} ",
94+
batchId, activityCode, (totalCredentialCount - processedCount[0]), totalCredentialCount);
8895
}
89-
});
96+
}
9097

91-
processedCount[0] = 1;
9298
// Unique Students
93-
studentIDs.forEach(uuid-> {
94-
try {
95-
if(!StringUtils.equalsAnyIgnoreCase(jobType, "REGALG", "TVRRUN")) {
96-
restUtils.updateStudentGradRecord(uuid, batchId, activityCode);
97-
LOGGER.debug("Dist Job [{}] / [{}] - update {} of {} student grad record: studentID [{}]", batchId, activityCode, processedCount[0], totalStudentCount, uuid);
98-
}
99-
processedCount[0]++;
100-
} catch (Exception e) {
101-
unprocessedStudents.put(uuid.toString(), new ServiceException(e));
102-
LOGGER.error("Unexpected Error on create {} of {} audit history: studentID [{}] \n {}",
103-
processedCount[0], totalStudentCount, uuid, e.getMessage());
99+
processedCount[0] = 0;
100+
if(!StringUtils.equalsAnyIgnoreCase(jobType, "REGALG", "TVRRUN") && !studentIDs.isEmpty()) {
101+
List<List<UUID>> studentIDPartitions = Lists.partition(studentIDs, partitionSize);
102+
studentIDPartitions.forEach(studentIDPartition -> {
103+
processedCount[0] = processedCount[0] + restUtils.updateStudentGradRecordHistory(studentIDPartition, batchId, ThreadLocalStateUtil.getCurrentUser(), activityCode);
104+
});
105+
LOGGER.debug("Dist Job [{}] / [{}] - updated {} of {} student grad record & history", batchId, activityCode, processedCount[0], totalStudentCount);
106+
if(studentIDs.size() != processedCount[0]) {
107+
LOGGER.error("Dist Job [{}] / [{}] - Unexpected Error on updating {} of {} student grad record & history",
108+
batchId, activityCode, (totalStudentCount - processedCount[0]), totalStudentCount);
104109
}
105-
});
110+
}
106111
return unprocessedStudents;
107112
}
108113

api/src/main/java/ca/bc/gov/educ/api/batchgraduation/rest/RestUtils.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,11 @@ public Boolean updateStudentCredentialRecord(UUID studentID, String credentialTy
451451
return restService.get(url, Boolean.class, accessToken);
452452
}
453453

454+
public Integer updateStudentCredentialRecords(List<StudentCredentialDistribution> studentCredentialDistributions, String activityCode, String accessToken) {
455+
String url = String.format(constants.getUpdateStudentCredentialByBatch(), activityCode);
456+
return restService.post(url, studentCredentialDistributions, Integer.class, accessToken);
457+
}
458+
454459
public void deleteSchoolReportRecord(UUID schoolId, String reportTypeCode) {
455460
ThreadLocalStateUtil.setCorrelationID(UUID.randomUUID().toString());
456461
restService.delete(String.format(constants.getDeleteSchoolReportsBySchoolIdAndReportType(),schoolId, reportTypeCode), Boolean.class);
@@ -499,15 +504,16 @@ public void updateStudentGradRecord(UUID studentID, Long batchId,String activity
499504
}
500505
}
501506

502-
public void updateStudentGradRecordHistory(List<UUID> studentIDs, Long batchId, String userName, String activityCode) {
507+
public Integer updateStudentGradRecordHistory(List<UUID> studentIDs, Long batchId, String userName, String activityCode) {
503508
try {
504509
if (batchId != null) {
505510
String url = String.format(constants.getUpdateStudentRecordHistory(), batchId, userName, activityCode);
506-
restService.put(url,studentIDs, GraduationStudentRecord.class);
511+
return restService.put(url, studentIDs, Integer.class);
507512
}
508513
} catch (Exception e) {
509514
LOGGER.error("Unable to update student record history {}", e.getLocalizedMessage());
510515
}
516+
return 0;
511517
}
512518

513519
public String updateStudentFlagReadyForBatch(List<UUID> studentIds, String batchJobType) {

api/src/main/java/ca/bc/gov/educ/api/batchgraduation/service/GraduationReportService.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package ca.bc.gov.educ.api.batchgraduation.service;
22

3-
import ca.bc.gov.educ.api.batchgraduation.model.PsiCredentialDistribution;
4-
import ca.bc.gov.educ.api.batchgraduation.model.ReportGradStudentData;
5-
import ca.bc.gov.educ.api.batchgraduation.model.StudentCredentialDistribution;
6-
import ca.bc.gov.educ.api.batchgraduation.model.StudentSearchRequest;
3+
import ca.bc.gov.educ.api.batchgraduation.model.*;
74
import ca.bc.gov.educ.api.batchgraduation.rest.RESTService;
85
import ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants;
96
import ca.bc.gov.educ.api.batchgraduation.util.JsonTransformer;
@@ -23,6 +20,8 @@
2320
import java.util.ArrayList;
2421
import java.util.List;
2522
import java.util.UUID;
23+
import java.util.function.Function;
24+
import java.util.stream.Collectors;
2625

2726
import static ca.bc.gov.educ.api.batchgraduation.constants.ReportingSchoolTypesEnum.SCHOOL_AT_GRAD;
2827

@@ -89,7 +88,6 @@ public List<StudentCredentialDistribution> getStudentsNonGradForYearlyDistributi
8988
return populateStudentCredentialDistributions(reportGradStudentDataList);
9089
}
9190

92-
// Year-end distribution
9391
public List<StudentCredentialDistribution> getStudentsForYearlyDistribution(String accessToken) {
9492
var response = restService.get(String.format(constants.getStudentReportDataYearly()), List.class, accessToken);
9593
List<ReportGradStudentData> reportGradStudentDataList = jsonTransformer.convertValue(response, new TypeReference<>(){});
@@ -99,7 +97,7 @@ public List<StudentCredentialDistribution> getStudentsForYearlyDistribution(Stri
9997
public List<StudentCredentialDistribution> getStudentsForYearlyDistributionBySearchCriteria(String accessToken, StudentSearchRequest searchRequest) {
10098
var response = restService.post(String.format(constants.getStudentReportDataYearly()), searchRequest, List.class, accessToken);
10199
List<ReportGradStudentData> reportGradStudentDataList = jsonTransformer.convertValue(response, new TypeReference<>(){});
102-
return populateStudentCredentialDistributions(reportGradStudentDataList);
100+
return populateYearEndStudentCredentialDistributions(reportGradStudentDataList);
103101
}
104102

105103
public List<UUID> getSchoolsNonGradYearly(String accessToken) {
@@ -117,16 +115,37 @@ public List<UUID> getDistrictsYearly(String accessToken) {
117115
return jsonTransformer.convertValue(response, new TypeReference<>(){});
118116
}
119117

118+
private List<StudentCredentialDistribution> populateStudentCredentialDistributions(
119+
List<ReportGradStudentData> dataList,
120+
Function<ReportGradStudentData, StudentCredentialDistribution> mapper) {
121+
return dataList.stream()
122+
.filter(data -> !"DEC".equalsIgnoreCase(data.getStudentStatus()))
123+
.map(mapper).collect(Collectors.toList());
124+
}
125+
120126
private List<StudentCredentialDistribution> populateStudentCredentialDistributions(List<ReportGradStudentData> reportGradStudentDataList) {
127+
return populateStudentCredentialDistributions(reportGradStudentDataList, this::populateStudentCredentialDistribution);
128+
}
129+
130+
private List<StudentCredentialDistribution> populateYearEndStudentCredentialDistributions(List<ReportGradStudentData> reportGradStudentDataList) {
121131
List<StudentCredentialDistribution> result = new ArrayList<>();
122132
for(ReportGradStudentData data: reportGradStudentDataList) {
123133
if (!"DEC".equalsIgnoreCase(data.getStudentStatus())) {
124-
result.add(populateStudentCredentialDistribution(data));
134+
result.add(populateYearEndStudentCredentialDistribution(data));
125135
}
126136
}
127137
return result;
128138
}
129139

140+
private StudentCredentialDistribution populateYearEndStudentCredentialDistribution(ReportGradStudentData data) {
141+
StudentCredentialDistribution dist = populateStudentCredentialDistribution(data);
142+
dist.setReportingSchoolTypeCode(data.getReportingSchoolTypeCode());
143+
dist.setCertificateTypeCode(data.getCertificateTypeCode());
144+
dist.setTranscriptTypeCode(data.getTranscriptTypeCode());
145+
LOGGER.info("Populate Student Credential Distribution for pen {}: SchoolOfRecordOrigin->{}, SchoolAtGrad->{}, SchoolOfRecord->{}", dist.getPen(), dist.getSchoolOfRecordOriginId(), dist.getSchoolAtGradId(), dist.getSchoolId());
146+
return dist;
147+
}
148+
130149
private StudentCredentialDistribution populateStudentCredentialDistribution(ReportGradStudentData data) {
131150
StudentCredentialDistribution dist = new StudentCredentialDistribution();
132151
dist.setId(data.getGraduationStudentRecordId());
@@ -162,4 +181,5 @@ private StudentCredentialDistribution populateStudentCredentialDistribution(Repo
162181
LOGGER.info("Populate Student Credential Distribution for pen {}: SchoolOfRecordOrigin->{}, SchoolAtGrad->{}, SchoolOfRecord->{}", dist.getPen(), dist.getSchoolOfRecordOriginId(), dist.getSchoolAtGradId(), dist.getSchoolId());
163182
return dist;
164183
}
184+
165185
}

api/src/main/java/ca/bc/gov/educ/api/batchgraduation/util/EducGradBatchGraduationApiConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ public class EducGradBatchGraduationApiConstants {
218218
@Value("${endpoint.grad-graduation-report-api.update-student-credential.url}")
219219
private String updateStudentCredential;
220220

221+
@Value("${endpoint.grad-graduation-report-api.update-student-credential-by-batch.url}")
222+
private String updateStudentCredentialByBatch;
223+
221224
@Value("${endpoint.grad-graduation-report-api.get-certificate-types.url}")
222225
private String certificateTypes;
223226

api/src/main/resources/application.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ endpoint:
217217
url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/getcertificatesfordistribution
218218
update-student-credential:
219219
url: ${GRAD_GRADUATION_REPORT_API}api/v1/graduationreports/studentcredential?studentID=%s&credentialTypeCode=%s&paperType=%s&documentStatusCode=%s&activityCode=%s
220+
update-student-credential-by-batch:
221+
url: ${GRAD_GRADUATION_REPORT_API}api/v2/graduationreports/studentcredential?activityCode=%s
220222
user-req-dis-run:
221223
url: ${GRAD_GRADUATION_REPORT_API}api/v2/graduationreports/userrequest/%s
222224
user-req-dis-run-for-not-yet-distributed:

api/src/test/java/ca/bc/gov/educ/api/batchgraduation/service/GraduationReportServiceTest.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package ca.bc.gov.educ.api.batchgraduation.service;
22

3-
import ca.bc.gov.educ.api.batchgraduation.model.PsiCredentialDistribution;
4-
import ca.bc.gov.educ.api.batchgraduation.model.StudentCredentialDistribution;
3+
import ca.bc.gov.educ.api.batchgraduation.model.*;
54
import ca.bc.gov.educ.api.batchgraduation.rest.RESTService;
65
import ca.bc.gov.educ.api.batchgraduation.util.EducGradBatchGraduationApiConstants;
76
import org.junit.Test;
@@ -21,6 +20,7 @@
2120
import java.util.UUID;
2221
import java.util.function.Consumer;
2322

23+
import static ca.bc.gov.educ.api.batchgraduation.constants.ReportingSchoolTypesEnum.SCHOOL_AT_GRAD;
2424
import static org.assertj.core.api.Assertions.assertThat;
2525
import static org.mockito.ArgumentMatchers.any;
2626
import static org.mockito.Mockito.when;
@@ -131,6 +131,32 @@ public void testGetPsiStudentsForRun() {
131131

132132
}
133133

134+
@Test
135+
public void testGeYearEndStudentsForRun() {
136+
137+
UUID schoolId = UUID.randomUUID();
138+
StudentCredentialDistribution scd = new StudentCredentialDistribution();
139+
scd.setId(new UUID(1,1));
140+
scd.setStudentID(new UUID(2,2));
141+
scd.setCredentialTypeCode("E");
142+
scd.setPaperType("YED2");
143+
scd.setSchoolOfRecord("05005001");
144+
scd.setSchoolId(schoolId);
145+
scd.setReportingSchoolTypeCode(SCHOOL_AT_GRAD.name());
146+
147+
ReportGradStudentData reportGradStudentData = new ReportGradStudentData();
148+
reportGradStudentData.setGraduationStudentRecordId(scd.getStudentID());
149+
reportGradStudentData.setFirstName(scd.getLegalFirstName());
150+
reportGradStudentData.setLastName(scd.getLegalLastName());
151+
152+
StudentSearchRequest searchRequest = new StudentSearchRequest();
153+
searchRequest.setSchoolIds(List.of(schoolId));
154+
155+
when(restService.post(String.format(constants.getStudentReportDataYearly()), searchRequest, List.class, "accessToken")).thenReturn(List.of(reportGradStudentData));
134156

157+
List<StudentCredentialDistribution> res = graduationReportService.getStudentsForYearlyDistributionBySearchCriteria("accessToken", searchRequest);
158+
assertThat(res).isNotNull().hasSize(1);
159+
160+
}
135161

136162
}

api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,31 @@ public void testUpdateStudentCredentialRecord() {
965965
assertThat(grd).isNotNull();
966966
}
967967

968+
@Test
969+
public void testUpdateStudentCredentialRecords() {
970+
String activityCode="USERDISTOC";
971+
UUID schoolId = UUID.randomUUID();
972+
StudentSearchRequest req = new StudentSearchRequest();
973+
List<UUID> sch = List.of(schoolId);
974+
req.setSchoolIds(sch);
975+
List<StudentCredentialDistribution> scdList = new ArrayList<>();
976+
StudentCredentialDistribution scd = new StudentCredentialDistribution();
977+
scd.setSchoolId(schoolId);
978+
scd.setPaperType("YED2");
979+
scd.setCredentialTypeCode("E");
980+
scd.setId(new UUID(1,1));
981+
scdList.add(scd);
982+
GraduationStudentRecord grd = new GraduationStudentRecord();
983+
grd.setStudentID(new UUID(1,1));
984+
grd.setProgram("2018-EN");
985+
mockTokenResponseObject();
986+
987+
when(this.restService.post(String.format(constants.getUpdateStudentCredentialByBatch(),activityCode), req, Integer.class, "accessToken")).thenReturn(1);
988+
this.restUtils.updateStudentCredentialRecords(scdList, activityCode, "accessToken");
989+
assertThat(grd).isNotNull();
990+
}
991+
992+
968993
@Test
969994
public void testGetStudentsForUserReqDisRun() {
970995
String credentialType = "OT";

api/src/test/resources/application.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ endpoint:
181181
url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/getcertificatesfordistribution
182182
update-student-credential:
183183
url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/graduationreports/studentcredential?studentID=%s&credentialTypeCode=%s&paperType=%s&documentStatusCode=%s&activityCode=%s
184+
update-student-credential-by-batch:
185+
url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v2/graduationreports/studentcredential?activityCode=%s
184186
user-req-dis-run:
185187
url: https://educ-grad-graduation-report-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v2/graduationreports/userrequest/%s
186188
user-req-dis-run-for-not-yet-distributed:

0 commit comments

Comments
 (0)