Skip to content

Commit

Permalink
Merge pull request #390 from bcgov/feature/lastTwo
Browse files Browse the repository at this point in the history
Fix to pull back grad status
  • Loading branch information
SodhiA1 authored Jan 11, 2024
2 parents 7ea64a4 + 23cd785 commit f923c1e
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
Expand All @@ -33,6 +35,7 @@ public class ValidationRulesService {
private final SdcSchoolCollectionStudentRepository sdcSchoolStudentRepository;
private final RestUtils restUtils;
private static final CodeTableMapper mapper = CodeTableMapper.mapper;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

public ValidationRulesService(CodeTableService codeTableService, SdcStudentEllRepository sdcStudentEllRepository, SdcSchoolCollectionStudentRepository sdcSchoolStudentRepository, RestUtils restUtils) {
this.codeTableService = codeTableService;
Expand Down Expand Up @@ -99,7 +102,7 @@ public void updatePenMatchAndGradStatusColumns(SdcSchoolCollectionStudentEntity

if (StringUtils.isNotEmpty(penMatchResultCode) && validPenMatchResults.contains(penMatchResultCode)) {
if (penMatchResult.getMatchingRecords() == null || penMatchResult.getMatchingRecords().isEmpty()) {
log.error("PEN Match records list is null or empty - this should not have happened :: ", penMatchResult);
log.error("PEN Match records list is null or empty - this should not have happened :: {}", penMatchResult);
throw new StudentDataCollectionAPIRuntimeException("PEN Match records list is null or empty - this should not have happened");
}
final var penMatchRecordOptional = penMatchResult.getMatchingRecords().stream().findFirst();
Expand All @@ -115,13 +118,29 @@ public void updatePenMatchAndGradStatusColumns(SdcSchoolCollectionStudentEntity
} else {
student.setPenMatchResult("NEW");
}
setGraduationStatus(student);
}

private void setGraduationStatus(SdcSchoolCollectionStudentEntity student){
student.setIsGraduated(false);
if(student.getAssignedStudentId() != null) {
final var gradResult = this.restUtils.getGradStatusResult(UUID.randomUUID(), SdcSchoolCollectionStudentMapper.mapper.toSdcSchoolStudent(student));
log.info("Grad status for SDC student {} :: is {}", student.getSdcSchoolCollectionStudentID(), gradResult);
student.setIsGraduated(false);
if(StringUtils.isNotEmpty(gradResult.getException()) && gradResult.getException().equalsIgnoreCase("error")){
log.error("Exception occurred calling grad service for grad status - this should not have happened :: {}", gradResult);
throw new StudentDataCollectionAPIRuntimeException("Exception occurred calling grad service for grad status - this should not have happened");
}else if(StringUtils.isNotEmpty(gradResult.getProgramCompletionDate())){
try{
LocalDate programCompletionDate = LocalDate.parse(gradResult.getProgramCompletionDate(), formatter);
if(programCompletionDate.isBefore(student.getSdcSchoolCollection().getCollectionEntity().getSnapshotDate())){
student.setIsGraduated(true);
}
}catch(Exception e){
log.error("Exception occurred calling trying to parse program completion date - this should not have happened :: {}", gradResult);
throw new StudentDataCollectionAPIRuntimeException("Exception occurred calling trying to parse program completion date - this should not have happened");
}
}
}

}

public boolean hasEnrollmentHistory(StudentRuleData studentRuleData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public class GradStatusResult implements Serializable {

private static final long serialVersionUID = 7900220143043919913L;
private String gradStatus;
private String studentID;
private String program;
private String programCompletionDate;
private String exception;
}
25 changes: 15 additions & 10 deletions api/src/main/resources/scripts/SLD_Migration_1 - Student Load.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ CREATE TABLE COLLECTION_TYPE_CODE
EXPIRY_DATE TIMESTAMP NOT NULL,
OPEN_DATE TIMESTAMP NOT NULL,
CLOSE_DATE TIMESTAMP NOT NULL,
SNAPSHOT_DATE DATE NOT NULL,
CREATE_USER VARCHAR(32) NOT NULL,
CREATE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
UPDATE_USER VARCHAR(32) NOT NULL,
Expand All @@ -34,47 +35,47 @@ CREATE TABLE COLLECTION_TYPE_CODE
);

INSERT INTO COLLECTION_TYPE_CODE (COLLECTION_TYPE_CODE, LABEL, DESCRIPTION, DISPLAY_ORDER, EFFECTIVE_DATE,
EXPIRY_DATE, OPEN_DATE, CLOSE_DATE, CREATE_USER, CREATE_DATE,
EXPIRY_DATE, OPEN_DATE, CLOSE_DATE, SNAPSHOT_DATE, CREATE_USER, CREATE_DATE,
UPDATE_USER, UPDATE_DATE)
VALUES ('SEPTEMBER', 'September', 'September collection', '10', TO_DATE('20230210', 'YYYYMMDD'),
TO_DATE('99991231', 'YYYYMMDD'), TO_DATE('20230929', 'YYYYMMDD'),
TO_DATE('20231115', 'YYYYMMDD'), 'API_STUDENT_DATA_COLLECTION',
TO_DATE('20231115', 'YYYYMMDD'), TO_DATE('99990929', 'YYYYMMDD'), 'API_STUDENT_DATA_COLLECTION',
TO_DATE('20230210', 'YYYYMMDD'),
'API_STUDENT_DATA_COLLECTION', TO_DATE('20230210', 'YYYYMMDD'));

INSERT INTO COLLECTION_TYPE_CODE (COLLECTION_TYPE_CODE, LABEL, DESCRIPTION, DISPLAY_ORDER, EFFECTIVE_DATE,
EXPIRY_DATE, OPEN_DATE, CLOSE_DATE, CREATE_USER, CREATE_DATE,
EXPIRY_DATE, OPEN_DATE, CLOSE_DATE, SNAPSHOT_DATE, CREATE_USER, CREATE_DATE,
UPDATE_USER, UPDATE_DATE)
VALUES ('FEBRUARY', 'February', 'February collection', '10', TO_DATE('20230210', 'YYYYMMDD'),
TO_DATE('99991231', 'YYYYMMDD'), TO_DATE('20230201', 'YYYYMMDD'),
TO_DATE('20230307', 'YYYYMMDD'), 'API_STUDENT_DATA_COLLECTION',
TO_DATE('20230307', 'YYYYMMDD'), TO_DATE('99990210', 'YYYYMMDD'), 'API_STUDENT_DATA_COLLECTION',
TO_DATE('20230210', 'YYYYMMDD'),
'API_STUDENT_DATA_COLLECTION', TO_DATE('20230210', 'YYYYMMDD'));

INSERT INTO COLLECTION_TYPE_CODE (COLLECTION_TYPE_CODE, LABEL, DESCRIPTION, DISPLAY_ORDER, EFFECTIVE_DATE,
EXPIRY_DATE, OPEN_DATE, CLOSE_DATE, CREATE_USER, CREATE_DATE,
EXPIRY_DATE, OPEN_DATE, CLOSE_DATE, SNAPSHOT_DATE, CREATE_USER, CREATE_DATE,
UPDATE_USER, UPDATE_DATE)
VALUES ('MAY', 'May', 'May collection', '10', TO_DATE('20230210', 'YYYYMMDD'),
TO_DATE('99991231', 'YYYYMMDD'), TO_DATE('20230501', 'YYYYMMDD'),
TO_DATE('20230530', 'YYYYMMDD'), 'API_STUDENT_DATA_COLLECTION',
TO_DATE('20230530', 'YYYYMMDD'), TO_DATE('99990505', 'YYYYMMDD'), 'API_STUDENT_DATA_COLLECTION',
TO_DATE('20230210', 'YYYYMMDD'),
'API_STUDENT_DATA_COLLECTION', TO_DATE('20230210', 'YYYYMMDD'));

INSERT INTO COLLECTION_TYPE_CODE (COLLECTION_TYPE_CODE, LABEL, DESCRIPTION, DISPLAY_ORDER, EFFECTIVE_DATE,
EXPIRY_DATE, OPEN_DATE, CLOSE_DATE, CREATE_USER, CREATE_DATE,
EXPIRY_DATE, OPEN_DATE, CLOSE_DATE, SNAPSHOT_DATE, CREATE_USER, CREATE_DATE,
UPDATE_USER, UPDATE_DATE)
VALUES ('JUNE', 'June', 'June collection', '10', TO_DATE('20230210', 'YYYYMMDD'),
TO_DATE('99991231', 'YYYYMMDD'), TO_DATE('20230601', 'YYYYMMDD'),
TO_DATE('20230630', 'YYYYMMDD'), 'API_STUDENT_DATA_COLLECTION',
TO_DATE('20230630', 'YYYYMMDD'), TO_DATE('99990605', 'YYYYMMDD'), 'API_STUDENT_DATA_COLLECTION',
TO_DATE('20230210', 'YYYYMMDD'),
'API_STUDENT_DATA_COLLECTION', TO_DATE('20230210', 'YYYYMMDD'));

INSERT INTO COLLECTION_TYPE_CODE (COLLECTION_TYPE_CODE, LABEL, DESCRIPTION, DISPLAY_ORDER, EFFECTIVE_DATE,
EXPIRY_DATE, OPEN_DATE, CLOSE_DATE, CREATE_USER, CREATE_DATE,
EXPIRY_DATE, OPEN_DATE, CLOSE_DATE, SNAPSHOT_DATE, CREATE_USER, CREATE_DATE,
UPDATE_USER, UPDATE_DATE)
VALUES ('JULY', 'July', 'July Collection', '10', TO_DATE('20230210', 'YYYYMMDD'),
TO_DATE('99991231', 'YYYYMMDD'), TO_DATE('20230707', 'YYYYMMDD'),
TO_DATE('20230730', 'YYYYMMDD'), 'API_STUDENT_DATA_COLLECTION',
TO_DATE('20230730', 'YYYYMMDD'), TO_DATE('99990707', 'YYYYMMDD'), 'API_STUDENT_DATA_COLLECTION',
TO_DATE('20230210', 'YYYYMMDD'),
'API_STUDENT_DATA_COLLECTION', TO_DATE('20230210', 'YYYYMMDD'));

Expand All @@ -91,6 +92,10 @@ SELECT
WHERE TO_DATE('1900' || LPAD(EXTRACT(MONTH FROM TO_DATE(sld_student.REPORT_DATE,'YYYYMMDD')),2,'0') || LPAD(EXTRACT(DAY FROM TO_DATE(sld_student.REPORT_DATE,'YYYYMMDD')),2,'0'), 'YYYYMMDD')
BETWEEN TO_DATE('1900' || LPAD(EXTRACT(MONTH FROM ctc.OPEN_DATE),2,'0') || LPAD(EXTRACT(DAY FROM ctc.OPEN_DATE),2,'0'), 'YYYYMMDD')
AND TO_DATE('1900' || LPAD(EXTRACT(MONTH FROM ctc.CLOSE_DATE),2,'0') || LPAD(EXTRACT(DAY FROM ctc.CLOSE_DATE),2,'0'), 'YYYYMMDD')) as CLOSE_DATE,
(SELECT TO_DATE(EXTRACT(YEAR FROM TO_DATE(sld_student.REPORT_DATE,'YYYYMMDD')) || LPAD(EXTRACT(MONTH FROM ctc.SNAPSHOT_DATE),2,'0') || LPAD(EXTRACT(DAY FROM ctc.SNAPSHOT_DATE),2,'0'),'YYYYMMDD') FROM COLLECTION_TYPE_CODE ctc
WHERE TO_DATE('1900' || LPAD(EXTRACT(MONTH FROM TO_DATE(sld_student.REPORT_DATE,'YYYYMMDD')),2,'0') || LPAD(EXTRACT(DAY FROM TO_DATE(sld_student.REPORT_DATE,'YYYYMMDD')),2,'0'), 'YYYYMMDD')
BETWEEN TO_DATE('1900' || LPAD(EXTRACT(MONTH FROM ctc.OPEN_DATE),2,'0') || LPAD(EXTRACT(DAY FROM ctc.OPEN_DATE),2,'0'), 'YYYYMMDD')
AND TO_DATE('1900' || LPAD(EXTRACT(MONTH FROM ctc.CLOSE_DATE),2,'0') || LPAD(EXTRACT(DAY FROM ctc.CLOSE_DATE),2,'0'), 'YYYYMMDD')) as SNAPSHOT_DATE,
'SLD_MIGRATION' as CREATE_USER,
sysdate as CREATE_DATE,
'SLD_MIGRATION' as UPDATE_USER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import ca.bc.gov.educ.studentdatacollection.api.struct.SdcStudentSagaData;
import ca.bc.gov.educ.studentdatacollection.api.struct.StudentRuleData;
import ca.bc.gov.educ.studentdatacollection.api.struct.external.grad.v1.GradStatusPayload;
import ca.bc.gov.educ.studentdatacollection.api.struct.external.grad.v1.GradStatusResult;
import ca.bc.gov.educ.studentdatacollection.api.struct.external.penmatch.v1.PenMatchRecord;
import ca.bc.gov.educ.studentdatacollection.api.struct.external.penmatch.v1.PenMatchResult;
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.School;
Expand Down Expand Up @@ -429,12 +430,12 @@ public PenMatchResult getPenMatchResult(){
return penMatchResult;
}

public GradStatusPayload getGradStatusResult(){
GradStatusPayload gradStatusPayload = new GradStatusPayload();
gradStatusPayload.setException(null);
gradStatusPayload.setProgram("ABC");
gradStatusPayload.setProgramCompletionDate("2023-08-09");
return gradStatusPayload;
public GradStatusResult getGradStatusResult(){
GradStatusResult gradStatusResult = new GradStatusResult();
gradStatusResult.setException(null);
gradStatusResult.setProgram("ABC");
gradStatusResult.setProgramCompletionDate("2023-08-09");
return gradStatusResult;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

import ca.bc.gov.educ.studentdatacollection.api.BaseStudentDataCollectionAPITest;
import ca.bc.gov.educ.studentdatacollection.api.exception.StudentDataCollectionAPIRuntimeException;
import ca.bc.gov.educ.studentdatacollection.api.model.v1.CollectionEntity;
import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionEntity;
import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionStudentEntity;
import ca.bc.gov.educ.studentdatacollection.api.rest.RestUtils;
import ca.bc.gov.educ.studentdatacollection.api.struct.external.grad.v1.GradStatusResult;
import ca.bc.gov.educ.studentdatacollection.api.struct.external.penmatch.v1.PenMatchResult;
import org.checkerframework.checker.units.qual.C;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDate;
import java.util.ArrayList;

import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -83,10 +88,73 @@ void testGetPenMatchResultFoundPEN() {
SdcSchoolCollectionStudentEntity mockStudentEntity = new SdcSchoolCollectionStudentEntity();
PenMatchResult penMatchResult = getPenMatchResult();
when(this.restUtils.getPenMatchResult(any(),any(), anyString())).thenReturn(penMatchResult);
GradStatusResult gradStatusResult = getGradStatusResult();
when(this.restUtils.getGradStatusResult(any(),any())).thenReturn(gradStatusResult);
SdcSchoolCollectionEntity schoolCollectionEntity = new SdcSchoolCollectionEntity();
CollectionEntity collectionEntity = new CollectionEntity();
collectionEntity.setSnapshotDate(LocalDate.now());
schoolCollectionEntity.setCollectionEntity(collectionEntity);
mockStudentEntity.setSdcSchoolCollection(schoolCollectionEntity);

validationRulesService.updatePenMatchAndGradStatusColumns(mockStudentEntity, "123456789");

assertEquals(mockStudentEntity.getAssignedStudentId().toString(), penMatchResult.getMatchingRecords().get(0).getStudentID());
assertSame(mockStudentEntity.getPenMatchResult(), penMatchResult.getPenStatus());
}

@Test
void testGetPenMatchResultFoundPENExceptionOccurred() {
SdcSchoolCollectionStudentEntity mockStudentEntity = new SdcSchoolCollectionStudentEntity();
PenMatchResult penMatchResult = getPenMatchResult();
when(this.restUtils.getPenMatchResult(any(),any(), anyString())).thenReturn(penMatchResult);
GradStatusResult gradStatusResult = getGradStatusResult();
gradStatusResult.setException("error");
when(this.restUtils.getGradStatusResult(any(),any())).thenReturn(gradStatusResult);
SdcSchoolCollectionEntity schoolCollectionEntity = new SdcSchoolCollectionEntity();
CollectionEntity collectionEntity = new CollectionEntity();
collectionEntity.setSnapshotDate(LocalDate.now());
schoolCollectionEntity.setCollectionEntity(collectionEntity);
mockStudentEntity.setSdcSchoolCollection(schoolCollectionEntity);

assertThrows(StudentDataCollectionAPIRuntimeException.class, () -> validationRulesService.updatePenMatchAndGradStatusColumns(mockStudentEntity, "123456789"));
}

@Test
void testGetPenMatchResultFoundPENExceptionOccurredParseDate() {
SdcSchoolCollectionStudentEntity mockStudentEntity = new SdcSchoolCollectionStudentEntity();
PenMatchResult penMatchResult = getPenMatchResult();
when(this.restUtils.getPenMatchResult(any(),any(), anyString())).thenReturn(penMatchResult);
GradStatusResult gradStatusResult = getGradStatusResult();
gradStatusResult.setProgramCompletionDate("10-10-2011");
when(this.restUtils.getGradStatusResult(any(),any())).thenReturn(gradStatusResult);
SdcSchoolCollectionEntity schoolCollectionEntity = new SdcSchoolCollectionEntity();
CollectionEntity collectionEntity = new CollectionEntity();
collectionEntity.setSnapshotDate(LocalDate.now());
schoolCollectionEntity.setCollectionEntity(collectionEntity);
mockStudentEntity.setSdcSchoolCollection(schoolCollectionEntity);

assertThrows(StudentDataCollectionAPIRuntimeException.class, () -> validationRulesService.updatePenMatchAndGradStatusColumns(mockStudentEntity, "123456789"));
}

@Test
void testGetPenMatchResultFoundPENGradNotFound() {
SdcSchoolCollectionStudentEntity mockStudentEntity = new SdcSchoolCollectionStudentEntity();
PenMatchResult penMatchResult = getPenMatchResult();
when(this.restUtils.getPenMatchResult(any(),any(), anyString())).thenReturn(penMatchResult);
GradStatusResult gradStatusResult = getGradStatusResult();
gradStatusResult.setException("not found");
gradStatusResult.setProgramCompletionDate(null);
when(this.restUtils.getGradStatusResult(any(),any())).thenReturn(gradStatusResult);
SdcSchoolCollectionEntity schoolCollectionEntity = new SdcSchoolCollectionEntity();
CollectionEntity collectionEntity = new CollectionEntity();
collectionEntity.setSnapshotDate(LocalDate.now());
schoolCollectionEntity.setCollectionEntity(collectionEntity);
mockStudentEntity.setSdcSchoolCollection(schoolCollectionEntity);

validationRulesService.updatePenMatchAndGradStatusColumns(mockStudentEntity, "123456789");

assertEquals(mockStudentEntity.getAssignedStudentId().toString(), penMatchResult.getMatchingRecords().get(0).getStudentID());
assertSame(mockStudentEntity.getPenMatchResult(), penMatchResult.getPenStatus());
assertFalse(mockStudentEntity.getIsGraduated());
}
}

0 comments on commit f923c1e

Please sign in to comment.