Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

develop/alex-GRAD2-2817 #678

Merged
merged 6 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
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 @@ -63,7 +60,7 @@ public ResponseEntity<GraduationStudentRecord> getStudentGradStatus(@PathVariabl
GraduationStudentRecord gradResponse = gradStatusService.getGraduationStatus(UUID.fromString(studentID),accessToken.replace(BEARER, ""));
if(gradResponse != null) {
return response.GET(gradResponse);
}else {
} else {
return response.NO_CONTENT();
}
}
Expand Down Expand Up @@ -407,10 +404,7 @@ public ResponseEntity<Long> getStudentsCount(@RequestParam(required = false) Str
@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, @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));
return response.GET(gradStatusService.archiveStudents(batchId, schoolOfRecords, studentStatus, userName));
}

@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 @@ -56,6 +56,9 @@ public interface GraduationStudentRecordRepository extends JpaRepository<Graduat
@Query("select c.studentID from GraduationStudentRecordEntity c where c.studentStatus=:studentStatus")
List<UUID> findByStudentStatus(String studentStatus);

@Query("select c.studentID from GraduationStudentRecordEntity c where c.studentStatus=:studentStatus")
Page<UUID> findByStudentStatus(String studentStatus, Pageable paging);

@Query("select distinct c.studentID from GraduationStudentRecordEntity c")
List<UUID> findAllStudentGuids();

Expand Down Expand Up @@ -127,6 +130,10 @@ void updateStudentGuidPenXrefRecord(
@Query( "update GraduationStudentRecordEntity e set e.batchId = :batchId where e.studentID in :studentIDs")
Integer updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(Long batchId, List<UUID> studentIDs);

@Modifying
@Query( "update GraduationStudentRecordEntity e set e.batchId = :batchId where e.studentStatus = :studentStatus")
Integer updateGraduationStudentRecordEntitiesBatchIdWhereStudentStatus(Long batchId, String studentStatus);

/**
* 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 @@ -50,6 +50,8 @@ public class GraduationStatusService {

public static final int PAGE_SIZE = 500;

public static final long MAX_ROWS_COUNT = 50000;

private static final Logger logger = LoggerFactory.getLogger(GraduationStatusService.class);

private static final String CREATE_USER = "createUser";
Expand Down Expand Up @@ -1395,19 +1397,23 @@ public Long countBySchoolOfRecordsAndStudentStatus(List<String> schoolOfRecords,
}

@Transactional
public Integer archiveStudents(long batchId, List<String> schoolOfRecords, String studentStatus, String user, LocalDateTime updateDate) {
public Integer archiveStudents(long batchId, List<String> schoolOfRecords, String studentStatus, String user) {
String recordStudentStatus = StringUtils.defaultString(studentStatus, "CUR");
Integer archivedStudentsCount;
Integer archivedStudentsCount = 0;
Integer historyStudentsCount = 0;
List<UUID> graduationStudentRecordGuids = new ArrayList<>();
if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) {
graduationStudentRecordGuids.addAll(graduationStatusRepository.findBySchoolOfRecordInAndStudentStatus(schoolOfRecords, recordStudentStatus));
archivedStudentsCount = graduationStatusRepository.archiveStudents(schoolOfRecords, recordStudentStatus, "ARC", batchId, user);
} else {
graduationStudentRecordGuids.addAll(graduationStatusRepository.findByStudentStatus(recordStudentStatus));
archivedStudentsCount = graduationStatusRepository.archiveStudents(recordStudentStatus, "ARC", batchId, user);
Integer numberOfUpdated = graduationStatusRepository.updateGraduationStudentRecordEntitiesBatchIdWhereStudentStatus(batchId, recordStudentStatus);
if(numberOfUpdated > 0) {
archivedStudentsCount = graduationStatusRepository.archiveStudents(recordStudentStatus, "ARC", batchId, user);
}
}
if(archivedStudentsCount > 0) {
historyStudentsCount = historyService.updateStudentRecordHistoryDistributionRun(batchId, user, "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 @@ -169,6 +169,8 @@ public Integer updateStudentRecordHistoryDistributionRun(Long batchId, String up
Integer studentRecordsCreated = graduationStatusRepository.updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(batchId, studentGuids);
historyRecordsCreated = graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(batchId, studentGuids, activityCode, updateUser);
assert Objects.equals(studentRecordsCreated, historyRecordsCreated);
} else if(StringUtils.equalsIgnoreCase(activityCode, "USERSTUDARC")) {
historyRecordsCreated = graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchId(batchId, activityCode, updateUser);
} else if(StringUtils.isBlank(activityCode) || StringUtils.equalsIgnoreCase(activityCode, "null")) {
historyRecordsCreated = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, updateUser);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@

import java.sql.Date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down Expand Up @@ -633,12 +635,9 @@ public void testGetStudentsCount() {
public void testArchiveStudents() {
// ID
String mincode = "123456789";
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(graduationStatusService.archiveStudents(1L, List.of(mincode), "CUR", "Batch Archive Process", updateDate)).thenReturn(1);
Mockito.when(graduationStatusService.archiveStudents(1L, List.of(mincode), "CUR", "Batch Archive Process")).thenReturn(1);
graduationStatusController.archiveStudents(1L, "CUR", "Batch Archive Process", List.of(mincode));
Mockito.verify(graduationStatusService).archiveStudents(1L, List.of(mincode), "CUR", "Batch Archive Process", updateDate);
Mockito.verify(graduationStatusService).archiveStudents(1L, List.of(mincode), "CUR", "Batch Archive Process");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3060,7 +3060,6 @@ public void testCountBySchoolOfRecordsAndStudentStatus() {
@Test
public void testArchiveStudents() {

LocalDateTime updateDate = LocalDateTime.now();
UUID studentID = new UUID(1, 1);
GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity();
graduationStatusEntity.setStudentID(studentID);
Expand All @@ -3074,7 +3073,7 @@ public void testArchiveStudents() {
Mockito.when(graduationStatusRepository.updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(1L, 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);
Integer count = graduationStatusService.archiveStudents(1L, List.of("12345678"), "CUR", "USER");
assertThat(count).isNotNull().isEqualTo(1);
}

Expand All @@ -3093,8 +3092,8 @@ public void testArchiveStudentEmpty() {
Mockito.when(graduationStatusRepository.archiveStudents("CUR", "ARC", 1L, "USER")).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);
Integer count = graduationStatusService.archiveStudents(1L, List.of(), "CUR", "USER");
assertThat(count).isNotNull().isEqualTo(0);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ public void testUpdateStudentRecordHistoryDistributionRun() {
when(graduationStudentRecordRepository.updateGraduationStudentRecordEntitiesBatchIdWhereStudentIDsIn(4000L, List.of(studentID))).thenReturn(1);
when(graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchIdAndStudentIDs(4000L, List.of(studentID), "activityCode", "USER")).thenReturn(1);
when(graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchId(4000L, "activityCode", "USER")).thenReturn(1);
when(graduationStudentRecordHistoryRepository.insertGraduationStudentRecordHistoryByBatchId(4000L, "USERSTUDARC", "USER")).thenReturn(1);

var result = historyService.updateStudentRecordHistoryDistributionRun(4000L, "USER", "activityCode", List.of(studentID));
assertThat(result).isNotNull().isEqualTo(1);
Expand All @@ -335,5 +336,8 @@ public void testUpdateStudentRecordHistoryDistributionRun() {

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

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