Skip to content

Commit

Permalink
Merge pull request #676 from bcgov/develop/alex-GRAD2-2817
Browse files Browse the repository at this point in the history
Update date fix
  • Loading branch information
infstar authored Sep 3, 2024
2 parents 2909ee1 + 849b0ec commit 6c19ffd
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,11 @@ public ResponseEntity<GraduationStudentRecord> saveStudentGradStatusDistribution

@PutMapping(EducGradStudentApiConstants.GRADUATION_RECORD_HISTORY_BY_BATCH_ID_DISTRIBUTION_RUN)
@PreAuthorize(PermissionsConstants.UPDATE_GRADUATION_STUDENT)
@Operation(summary = "Save Student Grad Status by Student ID for projected run", description = "Save Student Grad Status by Student ID for projected run", tags = { "Student Graduation Status" })
@Operation(summary = "Save Student Grad Status History by List of Student IDs", description = "Save Student Grad Status History by List of Student IDs", tags = { "Student Graduation History" })
@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");
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));
return response.UPDATED(historyService.updateStudentRecordHistoryDistributionRun(batchID, userName, activityCode, studentGuids));
}

@GetMapping (EducGradStudentApiConstants.STUDENT_LIST_FOR_SCHOOL_REPORT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

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

Expand All @@ -22,12 +21,12 @@ public interface GraduationStudentRecordHistoryRepository extends JpaRepository<
void deleteByStudentID(UUID studentID);

@Modifying
@Query(value="update GRADUATION_STUDENT_RECORD_HISTORY set UPDATE_USER = :updateUser, UPDATE_DATE = :updateDate where BATCH_ID = :batchId", nativeQuery=true)
Integer updateGradStudentUpdateUser(@Param(value = "batchId") Long batchId, @Param(value = "updateUser") String updateUser, @Param(value = "updateDate") LocalDateTime updateDate);
@Query(value="update GRADUATION_STUDENT_RECORD_HISTORY set UPDATE_USER = :updateUser, UPDATE_DATE = SYSDATE where BATCH_ID = :batchId", nativeQuery=true)
Integer updateGradStudentUpdateUser(@Param(value = "batchId") Long batchId, @Param(value = "updateUser") String updateUser);

@Modifying
@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);
@Query(value="update GRADUATION_STUDENT_RECORD_HISTORY set HISTORY_ACTIVITY_CODE = :activityCode, UPDATE_USER = :updateUser, UPDATE_DATE = SYSDATE where BATCH_ID = :batchId", nativeQuery=true)
Integer updateGradStudentUpdateUser(@Param(value = "batchId") Long batchId, @Param(value = "activityCode") String activityCode, @Param(value = "updateUser") String updateUser);

String INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_BATCH_ID_SQL = """
INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY (
Expand Down Expand Up @@ -70,7 +69,7 @@ INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY (
CREATE_USER,
CREATE_DATE,
:updateUser,
:updateDate,
SYSDATE,
RECALCULATE_PROJECTED_GRAD,
BATCH_ID,
CONSUMER_EDUC_REQT_MET,
Expand All @@ -83,7 +82,7 @@ INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY (
""";
@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);
Integer insertGraduationStudentRecordHistoryByBatchId(@Param(value = "batchId") Long batchId, @Param(value = "activityCode") String activityCode, @Param(value = "updateUser") String updateUser);

String INSERT_INTO_GRADUATION_STUDENT_RECORD_HISTORY_BY_BATCH_ID_AND_STUDENT_ID_IN_SQL = """
INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY (
Expand Down Expand Up @@ -126,7 +125,7 @@ INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY (
CREATE_USER,
CREATE_DATE,
:updateUser,
:updateDate,
SYSDATE,
RECALCULATE_PROJECTED_GRAD,
BATCH_ID,
CONSUMER_EDUC_REQT_MET,
Expand All @@ -139,6 +138,6 @@ INSERT INTO GRADUATION_STUDENT_RECORD_HISTORY (
""";
@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);
Integer insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(@Param(value = "batchId") Long batchId, @Param(value = "studentIDs") List<UUID> studentIDs, @Param(value = "activityCode") String activityCode, @Param(value = "updateUser") String updateUser);

}
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ public Integer archiveStudents(long batchId, List<String> schoolOfRecords, Strin
graduationStudentRecordGuids.addAll(graduationStatusRepository.findByStudentStatus(recordStudentStatus));
archivedStudentsCount = graduationStatusRepository.archiveStudents(recordStudentStatus, "ARC", batchId, user);
}
Integer historyRecordsUpdated = historyService.updateStudentRecordHistoryDistributionRun(batchId, user, updateDate, "USERSTUDARC", graduationStudentRecordGuids);
Integer historyRecordsUpdated = historyService.updateStudentRecordHistoryDistributionRun(batchId, user, "USERSTUDARC", graduationStudentRecordGuids);
assert Objects.equals(archivedStudentsCount, historyRecordsUpdated);
return archivedStudentsCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.reactive.function.client.WebClient;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -164,16 +163,16 @@ public Page<GraduationStudentRecordHistoryEntity> getStudentHistoryByBatchID(Lon
}

@Transactional
public Integer updateStudentRecordHistoryDistributionRun(Long batchId, String updateUser, LocalDateTime updateDate, String activityCode, List<UUID> studentGuids) {
public Integer updateStudentRecordHistoryDistributionRun(Long batchId, String updateUser, String activityCode, List<UUID> studentGuids) {
Integer historyRecordsCreated;
if(studentGuids != null && !studentGuids.isEmpty()) {
Integer studentRecordsCreated = graduationStatusRepository.updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(batchId, studentGuids);
historyRecordsCreated = graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(batchId, studentGuids, activityCode, updateUser, updateDate);
historyRecordsCreated = graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(batchId, studentGuids, activityCode, updateUser);
assert Objects.equals(studentRecordsCreated, historyRecordsCreated);
} else if(StringUtils.isBlank(activityCode) || StringUtils.equalsIgnoreCase(activityCode, "null")) {
historyRecordsCreated = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, updateUser, updateDate);
historyRecordsCreated = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, updateUser);
} else {
historyRecordsCreated = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, activityCode, updateUser, updateDate);
historyRecordsCreated = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, activityCode, updateUser);
}
return historyRecordsCreated;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,9 @@ public void testGetStudentsForYearlyRun() {

@Test
public void testUpdateStudentGradHistoryStatusDistributionRun() {
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));
Mockito.when(historyService.updateStudentRecordHistoryDistributionRun(1L, "Batch Archive Process", updateDate, "activityCode", List.of())).thenReturn(1);
Mockito.when(historyService.updateStudentRecordHistoryDistributionRun(1L, "Batch Archive Process", "activityCode", List.of())).thenReturn(1);
graduationStatusController.updateStudentGradHistoryStatusDistributionRun(1L, "Batch Archive Process", "activityCode", List.of());
Mockito.verify(historyService).updateStudentRecordHistoryDistributionRun(1L, "Batch Archive Process", updateDate, "activityCode", List.of());
Mockito.verify(historyService).updateStudentRecordHistoryDistributionRun(1L, "Batch Archive Process", "activityCode", List.of());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3072,7 +3072,7 @@ public void testArchiveStudents() {
Mockito.when(graduationStatusRepository.findBySchoolOfRecordInAndStudentStatus(List.of("12345678"), "CUR")).thenReturn(List.of(studentID));
Mockito.when(graduationStatusRepository.archiveStudents(List.of("12345678"), "CUR", "ARC", 1L, "USER")).thenReturn(1);
Mockito.when(graduationStatusRepository.updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(1L, List.of(studentID))).thenReturn(1);
Mockito.when(historyService.updateStudentRecordHistoryDistributionRun(1L, "USER", updateDate, "USERSTUDARC", List.of(studentID))).thenReturn(1);
Mockito.when(historyService.updateStudentRecordHistoryDistributionRun(1L, "USER", "USERSTUDARC", List.of(studentID))).thenReturn(1);

Integer count = graduationStatusService.archiveStudents(1L, List.of("12345678"), "CUR", "USER", updateDate);
assertThat(count).isNotNull().isEqualTo(1);
Expand All @@ -3091,7 +3091,7 @@ public void testArchiveStudentEmpty() {
when(graduationStatusRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity));
Mockito.when(graduationStatusRepository.findByStudentStatus("CUR")).thenReturn(List.of(studentID));
Mockito.when(graduationStatusRepository.archiveStudents("CUR", "ARC", 1L, "USER")).thenReturn(1);
Mockito.when(historyService.updateStudentRecordHistoryDistributionRun(1L, "USER", updateDate, "USERSTUDARC", List.of(studentID))).thenReturn(1);
Mockito.when(historyService.updateStudentRecordHistoryDistributionRun(1L, "USER", "USERSTUDARC", List.of(studentID))).thenReturn(1);

Integer count = graduationStatusService.archiveStudents(1L, List.of(), "CUR", "USER", updateDate);
assertThat(count).isNotNull().isEqualTo(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,28 +312,28 @@ public void testUpdateStudentRecordHistoryDistributionRun() {

when(graduationStudentRecordHistoryRepository.findByBatchId(4000L, PageRequest.of(0, Integer.SIZE))).thenReturn(hPage);
when(graduationStudentRecordHistoryRepository.findByStudentID(studentID)).thenReturn(List.of(graduationStudentRecordHistoryEntity));
when(graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(4000L, "USER", updateDate)).thenReturn(1);
when(graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(4000L, "USER")).thenReturn(1);
when(graduationStudentRecordRepository.findByStudentID(studentID)).thenReturn(graduationStudentRecordEntity);

when(graduationStudentRecordRepository.updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(4000L, List.of(studentID))).thenReturn(1);
when(graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(4000L, List.of(studentID), "activityCode", "USER", updateDate)).thenReturn(1);
when(graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchId(4000L, "activityCode", "USER", updateDate)).thenReturn(1);
when(graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(4000L, List.of(studentID), "activityCode", "USER")).thenReturn(1);
when(graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchId(4000L, "activityCode", "USER")).thenReturn(1);

var result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", updateDate, "activityCode", List.of(studentID));
var result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", "activityCode", List.of(studentID));
assertThat(result).isNotNull().isEqualTo(1);

when(graduationStudentRecordHistoryRepository.findByBatchId(4000L, PageRequest.of(0, Integer.SIZE))).thenReturn(null);
result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", updateDate, "activityCode", List.of(studentID));
result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", "activityCode", List.of(studentID));
assertThat(result).isNotNull().isEqualTo(1);

when(graduationStudentRecordHistoryRepository.findByBatchId(4000L, PageRequest.of(0, Integer.SIZE))).thenReturn(new PageImpl(List.of()));
result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", updateDate, "activityCode", List.of(studentID));
result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", "activityCode", List.of(studentID));
assertThat(result).isNotNull().isEqualTo(1);

result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", updateDate, "activityCode", List.of());
result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", "activityCode", List.of());
assertThat(result).isNotNull().isZero();

result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", updateDate, "", List.of());
result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", "", List.of());
assertThat(result).isNotNull().isEqualTo(1);
}
}

0 comments on commit 6c19ffd

Please sign in to comment.