Skip to content

Commit

Permalink
Merge pull request #675 from bcgov/develop/alex-GRAD2-2817
Browse files Browse the repository at this point in the history
Develop/alex grad2 2817
  • Loading branch information
arybakov-cgi authored Aug 28, 2024
2 parents 9fa746b + ed392df commit 2909ee1
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Comparator;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -361,7 +364,10 @@ public ResponseEntity<GraduationStudentRecord> saveStudentGradStatusDistribution
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<ApiResponseModel<Integer>> updateStudentGradHistoryStatusDistributionRun(@PathVariable Long batchID, @RequestParam(required = false) String userName, @RequestParam(required = false) String activityCode, @RequestBody List<UUID> studentGuids) {
logger.debug("Save Distribution student Grad history for Student ID");
return response.UPDATED(historyService.updateStudentRecordHistoryDistributionRun(batchID, userName, activityCode, studentGuids));
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(System.currentTimeMillis()));
LocalDateTime updateDate = LocalDateTime.of(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR), cal.get(Calendar.MINUTE));
return response.UPDATED(historyService.updateStudentRecordHistoryDistributionRun(batchID, userName, updateDate, activityCode, studentGuids));
}

@GetMapping (EducGradStudentApiConstants.STUDENT_LIST_FOR_SCHOOL_REPORT)
Expand Down Expand Up @@ -403,8 +409,11 @@ public ResponseEntity<Long> getStudentsCount(@RequestParam(required = false) Str
@PreAuthorize(PermissionsConstants.ARCHIVE_GRADUATION_STUDENT)
@Operation(summary = "Get Students Count by mincode and status", description = "Get Students Count by mincode and status", tags = { "Business" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<Integer> archiveStudents(@RequestParam long batchId, @RequestParam(required = false) String studentStatus, @RequestBody List<String> schoolOfRecords) {
return response.GET(gradStatusService.archiveStudents(batchId, schoolOfRecords, studentStatus));
public ResponseEntity<Integer> archiveStudents(@RequestParam long batchId, @RequestParam(required = false) String studentStatus, @RequestParam(required = false) String userName, @RequestBody List<String> schoolOfRecords) {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(System.currentTimeMillis()));
LocalDateTime updateDate = LocalDateTime.of(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR), cal.get(Calendar.MINUTE));
return response.GET(gradStatusService.archiveStudents(batchId, schoolOfRecords, studentStatus, userName, updateDate));
}

@PostMapping (EducGradStudentApiConstants.UPDATE_GRAD_STUDENT_FLAG_BY_BATCH_JOB_TYPE_AND_MULTIPLE_STUDENTIDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,116 @@ public interface GraduationStudentRecordHistoryRepository extends JpaRepository<
@Query(value="update GRADUATION_STUDENT_RECORD_HISTORY set HISTORY_ACTIVITY_CODE = :activityCode, UPDATE_USER = :updateUser, UPDATE_DATE = :updateDate where BATCH_ID = :batchId", nativeQuery=true)
Integer updateGradStudentUpdateUser(@Param(value = "batchId") Long batchId, @Param(value = "activityCode") String activityCode, @Param(value = "updateUser") String updateUser, @Param(value = "updateDate") LocalDateTime updateDate);

String INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_BATCH_ID_SQL = """
INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY (
GRADUATION_STUDENT_RECORD_HISTORY_ID,
HISTORY_ACTIVITY_CODE,
GRADUATION_STUDENT_RECORD_ID,
GRADUATION_PROGRAM_CODE,
GPA,
STUDENT_STATUS_CODE,
HONOURS_STANDING,
PROGRAM_COMPLETION_DATE,
RECALCULATE_GRAD_STATUS,
SCHOOL_OF_RECORD,
STUDENT_GRADE,
SCHOOL_AT_GRADUATION,
CREATE_USER,
CREATE_DATE,
UPDATE_USER,
UPDATE_DATE,
RECALCULATE_PROJECTED_GRAD,
BATCH_ID,
CONSUMER_EDUC_REQT_MET,
STUDENT_CITIZENSHIP_CODE,
ADULT_START_DATE,
SCHOOL_OF_RECORD_ID,
SCHOOL_AT_GRADUATION_ID
) SELECT
SYS_GUID(),
:activityCode,
GRADUATION_STUDENT_RECORD_ID,
GRADUATION_PROGRAM_CODE,
GPA,
STUDENT_STATUS_CODE,
HONOURS_STANDING,
PROGRAM_COMPLETION_DATE,
RECALCULATE_GRAD_STATUS,
SCHOOL_OF_RECORD,
STUDENT_GRADE,
SCHOOL_AT_GRADUATION,
CREATE_USER,
CREATE_DATE,
:updateUser,
:updateDate,
RECALCULATE_PROJECTED_GRAD,
BATCH_ID,
CONSUMER_EDUC_REQT_MET,
STUDENT_CITIZENSHIP_CODE,
ADULT_START_DATE,
SCHOOL_OF_RECORD_ID,
SCHOOL_AT_GRADUATION_ID
FROM GRADUATION_STUDENT_RECORD
WHERE BATCH_ID = :batchId
""";
@Modifying
@Query(value= INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_BATCH_ID_SQL, nativeQuery=true)
Integer insertGraduationStudentRecordHistoryByBatchId(@Param(value = "batchId") Long batchId, @Param(value = "activityCode") String activityCode, @Param(value = "updateUser") String updateUser, @Param(value = "updateDate") LocalDateTime updateDate);

String INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_BATCH_ID_AND_STUDENT_ID_IN_SQL = """
INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY (
GRADUATION_STUDENT_RECORD_HISTORY_ID,
HISTORY_ACTIVITY_CODE,
GRADUATION_STUDENT_RECORD_ID,
GRADUATION_PROGRAM_CODE,
GPA,
STUDENT_STATUS_CODE,
HONOURS_STANDING,
PROGRAM_COMPLETION_DATE,
RECALCULATE_GRAD_STATUS,
SCHOOL_OF_RECORD,
STUDENT_GRADE,
SCHOOL_AT_GRADUATION,
CREATE_USER,
CREATE_DATE,
UPDATE_USER,
UPDATE_DATE,
RECALCULATE_PROJECTED_GRAD,
BATCH_ID,
CONSUMER_EDUC_REQT_MET,
STUDENT_CITIZENSHIP_CODE,
ADULT_START_DATE,
SCHOOL_OF_RECORD_ID,
SCHOOL_AT_GRADUATION_ID
) SELECT
SYS_GUID(),
:activityCode,
GRADUATION_STUDENT_RECORD_ID,
GRADUATION_PROGRAM_CODE,
GPA,
STUDENT_STATUS_CODE,
HONOURS_STANDING,
PROGRAM_COMPLETION_DATE,
RECALCULATE_GRAD_STATUS,
SCHOOL_OF_RECORD,
STUDENT_GRADE,
SCHOOL_AT_GRADUATION,
CREATE_USER,
CREATE_DATE,
:updateUser,
:updateDate,
RECALCULATE_PROJECTED_GRAD,
BATCH_ID,
CONSUMER_EDUC_REQT_MET,
STUDENT_CITIZENSHIP_CODE,
ADULT_START_DATE,
SCHOOL_OF_RECORD_ID,
SCHOOL_AT_GRADUATION_ID
FROM GRADUATION_STUDENT_RECORD
WHERE BATCH_ID = :batchId and GRADUATION_STUDENT_RECORD_ID IN (:studentIDs)
""";
@Modifying
@Query(value= INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_BATCH_ID_AND_STUDENT_ID_IN_SQL, nativeQuery=true)
Integer insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(@Param(value = "batchId") Long batchId, @Param(value = "studentIDs") List<UUID> studentIDs, @Param(value = "activityCode") String activityCode, @Param(value = "updateUser") String updateUser, @Param(value = "updateDate") LocalDateTime updateDate);

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ public interface GraduationStudentRecordRepository extends JpaRepository<Graduat
Long countByStudentStatus(String studentStatus);

@Modifying
@Query(value="update graduation_student_record set student_status_code = :inStudStatTo, batch_id = :batchId, student_grad_data = json_transform(student_grad_data, SET '$.gradStatus.studentStatus' = :inStudStatTo IGNORE ON MISSING), update_date = SYSDATE, update_user = 'Batch Archive Process' where school_of_record in (:inSor) and student_status_code = :inStudStatFrom", nativeQuery=true)
Integer archiveStudents(List<String> inSor, String inStudStatFrom, String inStudStatTo, long batchId);
@Query(value="update graduation_student_record set student_status_code = :inStudStatTo, batch_id = :batchId, student_grad_data = json_transform(student_grad_data, SET '$.gradStatus.studentStatus' = :inStudStatTo IGNORE ON MISSING), update_date = SYSDATE, update_user = :userName where school_of_record in (:inSor) and student_status_code = :inStudStatFrom", nativeQuery=true)
Integer archiveStudents(List<String> inSor, String inStudStatFrom, String inStudStatTo, long batchId, String userName);

@Modifying
@Query(value="update graduation_student_record set student_status_code = :inStudStatTo, batch_id = :batchId, student_grad_data = json_transform(student_grad_data, SET '$.gradStatus.studentStatus' = :inStudStatTo IGNORE ON MISSING), update_date = SYSDATE, update_user = 'Batch Archive Process' where student_status_code = :inStudStatFrom", nativeQuery=true)
Integer archiveStudents(String inStudStatFrom, String inStudStatTo, long batchId);
@Query(value="update graduation_student_record set student_status_code = :inStudStatTo, batch_id = :batchId, student_grad_data = json_transform(student_grad_data, SET '$.gradStatus.studentStatus' = :inStudStatTo IGNORE ON MISSING), update_date = SYSDATE, update_user = :userName where student_status_code = :inStudStatFrom", nativeQuery=true)
Integer archiveStudents(String inStudStatFrom, String inStudStatTo, long batchId, String userName);

// Data Conversion
@Modifying
Expand Down Expand Up @@ -123,6 +123,10 @@ void updateStudentGuidPenXrefRecord(
@Query( "update GraduationStudentRecordEntity e set e.recalculateProjectedGrad = 'Y' where e.studentStatus = 'CUR' and e.programCompletionDate is null and (e.studentGrade = '12' or e.studentGrade = 'AD')")
void updateGradStudentRecalcFlagsForCurrentStudentsWithNullCompletion();

@Modifying
@Query( "update GraduationStudentRecordEntity e set e.batchId = :batchId where e.studentID in :studentIDs")
Integer updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(Long batchId, List<UUID> studentIDs);

/**
* Find a GraduationStudentRecord By Student ID using generics. Pass an object with the
* same subset of field names, getters/setters of GraduationStudentRecordEntity to return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import ca.bc.gov.educ.api.gradstudent.constant.FieldName;
import ca.bc.gov.educ.api.gradstudent.constant.TraxEventType;
import ca.bc.gov.educ.api.gradstudent.model.dto.*;
import ca.bc.gov.educ.api.gradstudent.model.entity.*;
import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordEntity;
import ca.bc.gov.educ.api.gradstudent.model.entity.StudentCareerProgramEntity;
import ca.bc.gov.educ.api.gradstudent.model.entity.StudentOptionalProgramEntity;
import ca.bc.gov.educ.api.gradstudent.model.transformer.GradStudentCareerProgramTransformer;
import ca.bc.gov.educ.api.gradstudent.model.transformer.GradStudentOptionalProgramTransformer;
import ca.bc.gov.educ.api.gradstudent.model.transformer.GraduationStatusTransformer;
Expand All @@ -21,7 +23,10 @@
import org.springframework.web.reactive.function.client.WebClient;

import java.time.LocalDateTime;
import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

/**
* Initial Student Loads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1395,22 +1395,19 @@ public Long countBySchoolOfRecordsAndStudentStatus(List<String> schoolOfRecords,
}

@Transactional
public Integer archiveStudents(long batchId, List<String> schoolOfRecords, String studentStatus) {
public Integer archiveStudents(long batchId, List<String> schoolOfRecords, String studentStatus, String user, LocalDateTime updateDate) {
String recordStudentStatus = StringUtils.defaultString(studentStatus, "CUR");
Integer archivedStudentsCount = 0;
Integer archivedStudentsCount;
List<UUID> graduationStudentRecordGuids = new ArrayList<>();
if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) {
List<UUID> graduationStudentRecordGuids = graduationStatusRepository.findBySchoolOfRecordInAndStudentStatus(schoolOfRecords, recordStudentStatus);
for(UUID graduationStudentRecordGuid: graduationStudentRecordGuids) {
saveStudentHistoryRecordArchiveStudentsRun(graduationStudentRecordGuid, batchId, "USERSTUDARC");
}
archivedStudentsCount = graduationStatusRepository.archiveStudents(schoolOfRecords, recordStudentStatus, "ARC", batchId);
graduationStudentRecordGuids.addAll(graduationStatusRepository.findBySchoolOfRecordInAndStudentStatus(schoolOfRecords, recordStudentStatus));
archivedStudentsCount = graduationStatusRepository.archiveStudents(schoolOfRecords, recordStudentStatus, "ARC", batchId, user);
} else {
List<UUID> graduationStudentRecordGuids = graduationStatusRepository.findByStudentStatus(recordStudentStatus);
for(UUID graduationStudentRecordGuid: graduationStudentRecordGuids) {
saveStudentHistoryRecordArchiveStudentsRun(graduationStudentRecordGuid, batchId, "USERSTUDARC");
}
archivedStudentsCount = graduationStatusRepository.archiveStudents(recordStudentStatus, "ARC", batchId);
graduationStudentRecordGuids.addAll(graduationStatusRepository.findByStudentStatus(recordStudentStatus));
archivedStudentsCount = graduationStatusRepository.archiveStudents(recordStudentStatus, "ARC", batchId, user);
}
Integer historyRecordsUpdated = historyService.updateStudentRecordHistoryDistributionRun(batchId, user, updateDate, "USERSTUDARC", graduationStudentRecordGuids);
assert Objects.equals(archivedStudentsCount, historyRecordsUpdated);
return archivedStudentsCount;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

Expand Down Expand Up @@ -163,31 +164,18 @@ public Page<GraduationStudentRecordHistoryEntity> getStudentHistoryByBatchID(Lon
}

@Transactional
public Integer updateStudentRecordHistoryDistributionRun(Long batchId, String updateUser, String activityCode, List<UUID> studentGuids) {
Integer result = 0;
LocalDateTime updateDate = LocalDateTime.now();
public Integer updateStudentRecordHistoryDistributionRun(Long batchId, String updateUser, LocalDateTime updateDate, String activityCode, List<UUID> studentGuids) {
Integer historyRecordsCreated;
if(studentGuids != null && !studentGuids.isEmpty()) {
Page<GraduationStudentRecordHistoryEntity> recordHistoryEntityPage = graduationStudentRecordHistoryRepository.findByBatchId(batchId, PageRequest.of(0, Integer.SIZE));
if(recordHistoryEntityPage == null || recordHistoryEntityPage.isEmpty()) {
for (UUID studentGuid : studentGuids) {
GraduationStudentRecordEntity entity = graduationStatusRepository.findByStudentID(studentGuid);
if(entity != null) {
GraduationStudentRecordEntity toBeSaved = new GraduationStudentRecordEntity();
BeanUtils.copyProperties(entity, toBeSaved);
toBeSaved.setBatchId(batchId);
toBeSaved.setUpdateDate(updateDate);
toBeSaved.setUpdateUser(updateUser);
createStudentHistory(toBeSaved, activityCode);
result ++;
}
}
}
Integer studentRecordsCreated = graduationStatusRepository.updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(batchId, studentGuids);
historyRecordsCreated = graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(batchId, studentGuids, activityCode, updateUser, updateDate);
assert Objects.equals(studentRecordsCreated, historyRecordsCreated);
} else if(StringUtils.isBlank(activityCode) || StringUtils.equalsIgnoreCase(activityCode, "null")) {
result = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, updateUser, updateDate);
historyRecordsCreated = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, updateUser, updateDate);
} else {
result = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, activityCode, updateUser, updateDate);
historyRecordsCreated = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, activityCode, updateUser, updateDate);
}
return result;
return historyRecordsCreated;
}

}
Loading

0 comments on commit 2909ee1

Please sign in to comment.