Skip to content

Commit

Permalink
Grad release 1.12.0
Browse files Browse the repository at this point in the history
Grad release 1.12.0
  • Loading branch information
kamal-mohammed authored Jan 15, 2024
2 parents 5e70b84 + c0bee51 commit a87364c
Show file tree
Hide file tree
Showing 17 changed files with 217 additions and 36 deletions.
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-data-conversion-api</artifactId>
<version>1.8.50</version>
<version>1.8.51</version>
<name>educ-grad-data-conversion-api</name>
<description>Ministry of Education GRAD DATA CONVERSION API</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.core.launch.support.SimpleJobLauncher;
import org.springframework.batch.core.launch.support.TaskExecutorJobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.builder.StepBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class CourseProcess {
private static final String ZFRAL_STR = "ZFRAL";
private static final String IBFAS_STR = "IBFAS";
private static final String QFRAP_STR = "QFRAP";
private static final String CPWE_STR = "CPWE";
private static final String CPCOW_STR = "CPCOW";
private static final String CPSSA_STR = "CPSSA";

private static final String ERR_MSG_FORMAT = "For {} : {}";

Expand Down Expand Up @@ -627,7 +630,7 @@ public void createCourseRequirements(ConversionCourseSummaryDTO summary) {
createCourseRequirement(populate(LTSTF_STR, "11", "201"), summary);

// Adult Work Experience
createCourseRequirement(populate("CPWE", "12", "506"), summary);
createCourseRequirement(populate(CPWE_STR, "12", "506"), summary);
createCourseRequirement(populate("SSA", "12A", "506"), summary);
createCourseRequirement(populate("SSA", "12B", "506"), summary);
createCourseRequirement(populate("WEX", "12A", "506"), summary);
Expand Down Expand Up @@ -1145,13 +1148,24 @@ public void createCourseRequirements(ConversionCourseSummaryDTO summary) {
createCourseRequirement(populate("ELNMF", "11", "201"), summary);
createCourseRequirement(populate("ELSLF", "11", "201"), summary);
createCourseRequirement(populate("EFLSF", "11", "201"), summary);
createCourseRequirement(populate(FRALP_STR, "11", "201"), summary);
// GRAD2-2402: Rule 202
createCourseRequirement(populate(QFRAP_STR, "10", "202"), summary);
createCourseRequirement(populate("LANMF", "10", "202"), summary);
createCourseRequirement(populate("LAEOF", "10", "202"), summary);
createCourseRequirement(populate("LACWF", "10", "202"), summary);
createCourseRequirement(populate(FRALP_STR, "10", "202"), summary);
// GRAD2-2386: Rule 600
createCourseRequirement(populate(CPWE_STR, "12", "600"), summary);
createCourseRequirement(populate(CPWE_STR, "12A", "600"), summary);
createCourseRequirement(populate(CPWE_STR, "12B", "600"), summary);
createCourseRequirement(populate(CPWE_STR, "12C", "600"), summary);
createCourseRequirement(populate(CPWE_STR, "12D", "600"), summary);
createCourseRequirement(populate(CPCOW_STR, "12", "600"), summary);
createCourseRequirement(populate(CPCOW_STR, "12A", "600"), summary);
createCourseRequirement(populate(CPCOW_STR, "12B", "600"), summary);
createCourseRequirement(populate(CPSSA_STR, "11A", "600"), summary);
createCourseRequirement(populate(CPSSA_STR, "11B", "600"), summary);
createCourseRequirement(populate(CPSSA_STR, "12A", "600"), summary);
createCourseRequirement(populate(CPSSA_STR, "12B", "600"), summary);
}

private CourseRequirement populate(String courseCode, String courseLevel, String courseRequirementCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -923,9 +923,11 @@ private ConversionResultType processProgramCodes(GraduationStudentRecord student
private Pair<ConversionResultType, Boolean> handleProgramCode(String programCode, GraduationStudentRecord student, StudentLoadType studentLoadType, StudentLoadType originalStudentLoadType, ConversionStudentSummaryDTO summary) {
ConversionResultType resultType;
boolean isCareerProgramCreated = false;
if (isStudentSCCPForTwoPrograms(student.getProgram(), originalStudentLoadType)) {
return Pair.of(ConversionResultType.SUCCESS, isCareerProgramCreated);
}
if (isOptionalProgramCode(programCode)) {
resultType = isStudentSCCPForTwoPrograms(student.getProgram(), originalStudentLoadType)? ConversionResultType.SUCCESS :
createStudentOptionalProgram(programCode, student, studentLoadType, summary);
resultType = createStudentOptionalProgram(programCode, student, studentLoadType, summary);
} else {
resultType = createStudentCareerProgram(programCode, student, summary);
if (ConversionResultType.SUCCESS == resultType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import ca.bc.gov.educ.api.dataconversion.entity.Event;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand All @@ -13,4 +17,9 @@ public interface EventRepository extends JpaRepository<Event, UUID> {
Optional<Event> findByEventId(UUID eventId);

List<Event> findAllByEventStatusOrderByCreateDate(String eventStatus);

@Transactional
@Modifying
@Query("delete from Event where createDate <= :createDate")
void deleteByCreateDateBefore(LocalDateTime createDate);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package ca.bc.gov.educ.api.dataconversion.scheduler;

import ca.bc.gov.educ.api.dataconversion.repository.EventRepository;
import ca.bc.gov.educ.api.dataconversion.util.EducGradDataConversionApiConstants;
import jakarta.transaction.Transactional;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.core.LockAssert;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class PurgeOldRecordsScheduler {
private final EventRepository eventRepository;
private final EducGradDataConversionApiConstants constants;

public PurgeOldRecordsScheduler(final EventRepository eventRepository,
final EducGradDataConversionApiConstants constants) {
this.eventRepository = eventRepository;
this.constants = constants;
}

@Scheduled(cron = "${cron.scheduled.process.purge-old-records.run}")
@SchedulerLock(name = "PurgeOldRecordsLock",
lockAtLeastFor = "PT1H", lockAtMostFor = "PT1H") //midnight job so lock for an hour
@Transactional
public void purgeOldRecords() {
LockAssert.assertLocked();
final LocalDateTime createDateToCompare = this.calculateCreateDateBasedOnStaleEventInDays();
this.eventRepository.deleteByCreateDateBefore(createDateToCompare);
}


private LocalDateTime calculateCreateDateBasedOnStaleEventInDays() {
final LocalDateTime currentTime = LocalDateTime.now();
return currentTime.minusDays(this.constants.getRecordsStaleInDays());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,41 +70,25 @@ public void processStudentDemographics(TraxDemographicsUpdateDTO updateDemog, St
boolean isChanged = false;
// Last Name
if (!StringUtils.equals(updateDemog.getLastName(), currentStudent.getLastName())) {
// Transcript
currentStudent.setNewRecalculateGradStatus("Y");
// TVR
currentStudent.setNewRecalculateProjectedGrad("Y");

populateNewBatchFlags(currentStudent);
isChanged = true;
log.info(" => student last name : current = {}, request = {}", currentStudent.getLastName(), updateDemog.getLastName());
}
// First Name
if (!StringUtils.equals(updateDemog.getFirstName(), currentStudent.getFirstName())) {
// Transcript
currentStudent.setNewRecalculateGradStatus("Y");
// TVR
currentStudent.setNewRecalculateProjectedGrad("Y");

populateNewBatchFlags(currentStudent);
isChanged = true;
log.info(" => student first name : current = {}, request = {}", currentStudent.getFirstName(), updateDemog.getFirstName());
}
// Middle Names
if (!StringUtils.equals(updateDemog.getMiddleNames(), currentStudent.getMiddleName())) {
// Transcript
currentStudent.setNewRecalculateGradStatus("Y");
// TVR
currentStudent.setNewRecalculateProjectedGrad("Y");

populateNewBatchFlags(currentStudent);
isChanged = true;
log.info(" => student middle name : current = {}, request = {}", currentStudent.getMiddleName(), updateDemog.getMiddleNames());
}
// Date of Birth
if (!StringUtils.equals(updateDemog.getBirthday(), currentStudent.getBirthday())) {
// Transcript
currentStudent.setNewRecalculateGradStatus("Y");
// TVR
currentStudent.setNewRecalculateProjectedGrad("Y");

populateNewBatchFlags(currentStudent);
isChanged = true;
log.info(" => student dob : current = {}, request = {}", currentStudent.getBirthday(), updateDemog.getBirthday());
}
Expand All @@ -115,6 +99,18 @@ public void processStudentDemographics(TraxDemographicsUpdateDTO updateDemog, St
}
}

private void populateNewBatchFlags(StudentGradDTO currentStudent) {
if ("ARC".equalsIgnoreCase(currentStudent.getStudentStatus())) {
// Transcript
currentStudent.setNewRecalculateGradStatus("Y");
} else {
// Transcript
currentStudent.setNewRecalculateGradStatus("Y");
// TVR
currentStudent.setNewRecalculateProjectedGrad("Y");
}
}

@Override
public String getEventType() {
return UPD_DEMOG.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public void processStudent(TraxGraduationUpdateDTO updateGrad, StudentGradDTO cu
boolean isChanged = false;

log.info(" Process Student : studentID = {}, pen = {}", currentStudent.getStudentID(), updateGrad.getPen());
if ("ARC".equalsIgnoreCase(currentStudent.getStudentStatus())) {
return;
}
// Order is important for first 3 items below!!!
// 1. School of record
if (!StringUtils.equals(updateGrad.getSchoolOfRecord(), currentStudent.getSchoolOfRecord())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,7 @@ public class EducGradDataConversionApiConstants {

@Value("${cron.scheduled.process.events.stan.threshold}")
private int traxToGradProcessingThreshold;

@Value("${cron.scheduled.process.purge-old-records.staleInDays}")
private int recordsStaleInDays;
}
5 changes: 4 additions & 1 deletion api/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spring:
username: ${CONV_USERNAME}
password: ${CONV_PASSWORD}
url: ${CONNECTION_STRING}
driver-class: oracle.jdbc.driver.OracleDriver
driver-class-name: oracle.jdbc.driver.OracleDriver
jpa:
show-sql: ${SHOW_SQL_LOGS}
database-platform: org.hibernate.dialect.Oracle12cDialect
Expand Down Expand Up @@ -177,6 +177,9 @@ cron:
lockAtLeastFor: ${CRON_SCHEDULED_PROCESS_EVENTS_STAN_LOCK_AT_LEAST_FOR}
lockAtMostFor: ${CRON_SCHEDULED_PROCESS_EVENTS_STAN_LOCK_AT_MOST_FOR}
threshold: ${CRON_SCHEDULED_PROCESS_EVENTS_STAN_THRESHOLD}
purge-old-records:
run: ${CRON_SCHEDULED_PURGE_OLD_RECORDS}
staleInDays: ${RECORDS_STALE_IN_DAYS}

#Endpoints
endpoint:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void testProcessStudentAssessmentForGrad2018ENProgram_givenUpdated_STUDEN
currentStudent.setStudentID(studentID);
currentStudent.setProgram(program);
currentStudent.setStudentGrade("12");
currentStudent.setStudentStatus("A");
currentStudent.setStudentStatus("CUR");
currentStudent.setSchoolOfRecord(mincode);
currentStudent.setSchoolAtGrad(mincode);
// Optional Program Codes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void testProcessStudentCourseForGrad2018ENProgram_givenUpdated_STUDENT_re
currentStudent.setStudentID(studentID);
currentStudent.setProgram(program);
currentStudent.setStudentGrade("12");
currentStudent.setStudentStatus("A");
currentStudent.setStudentStatus("CUR");
currentStudent.setSchoolOfRecord(mincode);
currentStudent.setSchoolAtGrad(mincode);
// Optional Program Codes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,53 @@ public void testProcessStudentDemographicsForGrad2018ENProgram_givenUpdated_UPD_
currentStudent.setStudentID(studentID);
currentStudent.setProgram(program);
currentStudent.setStudentGrade("12");
currentStudent.setStudentStatus("A");
currentStudent.setStudentStatus("CUR");
currentStudent.setSchoolOfRecord(mincode);
currentStudent.setSchoolAtGrad(mincode);

when(this.studentProcess.loadStudentData(eq(pen), any())).thenReturn(currentStudent);
when(this.eventRepository.findByEventId(event.getEventId())).thenReturn(Optional.of(event));

studentDemographicsUpdateEventService.processEvent(traxDemogUpdate, event);

assertThat(event).isNotNull();
assertThat(event.getEventStatus()).isEqualTo(EventStatus.PROCESSED.name());
}

@Test
public void testProcessStudentDemographicsForArchivedGrad2018ENProgram_givenUpdated_UPD_DEMOG_then_returnsAPICallSuccess() {
// ID
UUID studentID = UUID.randomUUID();
String pen = "111222333";

// Program & School
String program = "2018-EN";
String mincode = "222333";

String updateType = "UPD_DEMOG";

// TraxUpdateInGrad
TraxDemographicsUpdateDTO traxDemogUpdate = new TraxDemographicsUpdateDTO();
traxDemogUpdate.setPen(pen);
traxDemogUpdate.setFirstName("Test");
traxDemogUpdate.setMiddleNames("and");
traxDemogUpdate.setLastName("QA");
traxDemogUpdate.setBirthday("19960601");

// Event
Event event = new Event();
event.setEventType(EventType.UPD_DEMOG.name());
event.setEventStatus(EventStatus.DB_COMMITTED.name());
event.setActivityCode(updateType);
event.setEventId(UUID.randomUUID());

// current GRAD Student
StudentGradDTO currentStudent = new StudentGradDTO();
// GraduationStudentRecord
currentStudent.setStudentID(studentID);
currentStudent.setProgram(program);
currentStudent.setStudentGrade("12");
currentStudent.setStudentStatus("ARC");
currentStudent.setSchoolOfRecord(mincode);
currentStudent.setSchoolAtGrad(mincode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void testProcessStudentForGrad2018ENProgram_givenUpdated_FI10ADD_whenNewC
currentStudent.setStudentID(studentID);
currentStudent.setProgram(program);
currentStudent.setStudentGrade("12");
currentStudent.setStudentStatus("A");
currentStudent.setStudentStatus("CUR");
currentStudent.setSchoolOfRecord(mincode);
currentStudent.setSchoolAtGrad(mincode);
// Optional Program Codes
Expand Down Expand Up @@ -141,7 +141,7 @@ public void testProcessStudentForGrad2018ENProgram_givenUpdated_FI10DELETE_whenC
currentStudent.setStudentID(studentID);
currentStudent.setProgram(program);
currentStudent.setStudentGrade("12");
currentStudent.setStudentStatus("A");
currentStudent.setStudentStatus("CUR");
currentStudent.setSchoolOfRecord(mincode);
currentStudent.setSchoolAtGrad(mincode);
// Optional Program Codes
Expand Down
Loading

0 comments on commit a87364c

Please sign in to comment.