Skip to content

Commit

Permalink
Merge pull request #671 from bcgov/develop/alex-GRAD2-2283
Browse files Browse the repository at this point in the history
GRAD2-2283
  • Loading branch information
arybakov-cgi authored Aug 15, 2024
2 parents 4c3356b + 52e8952 commit 4fa5246
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ protected void onCreate() {
if (StringUtils.isBlank(updateUser)) {
this.updateUser = EducGradStudentApiConstants.DEFAULT_UPDATED_BY;
}
}
this.createDate = LocalDateTime.now();
this.updateDate = LocalDateTime.now();
}
if(this.createDate == null) {
this.createDate = LocalDateTime.now();
}
if(this.updateDate == null) {
this.updateDate = LocalDateTime.now();
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public interface GraduationStudentRecordRepository extends JpaRepository<Graduat

List<GraduationStudentRecordView> findBySchoolOfRecordAndStudentStatus(String schoolOfRecord, String studentStatus);

@Query("select c.studentID from GraduationStudentRecordEntity c where c.schoolOfRecord IN (:schoolOfRecords) and c.studentStatus=:studentStatus")
List<UUID> findBySchoolOfRecordInAndStudentStatus(List<String> schoolOfRecords, String studentStatus);

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

List<GraduationStudentRecordView> findBySchoolOfRecordAndStudentStatusAndStudentGradeIn(String schoolOfRecord, String studentStatus, List<String> studentGrade);

@Query("select count(*) from GraduationStudentRecordEntity c where c.schoolOfRecord=:schoolOfRecord and c.studentStatus='CUR' and (c.studentGrade='AD' or c.studentGrade='12')")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,18 @@ public GraduationStudentRecord saveStudentRecordDistributionRun(UUID studentID,
return null;
}

@Retry(name = "generalpostcall")
public void saveStudentHistoryRecordDistributionRun(UUID studentID, Long batchId, String activityCode) {
Optional<GraduationStudentRecordEntity> gradStatusOptional = graduationStatusRepository.findById(studentID);
if (gradStatusOptional.isPresent()) {
GraduationStudentRecordEntity gradEntity = gradStatusOptional.get();
gradEntity.setUpdateUser(null);
gradEntity.setUpdateDate(null);
gradEntity.setBatchId(batchId);
historyService.createStudentHistory(gradEntity, activityCode);
}
}

@Retry(name = "generalpostcall")
public GraduationStudentRecord saveStudentRecordProjectedTVRRun(UUID studentID, Long batchId, ProjectedRunClob projectedRunClob) {
Optional<GraduationStudentRecordEntity> gradStatusOptional = graduationStatusRepository.findById(studentID);
Expand Down Expand Up @@ -1379,10 +1391,19 @@ public Long countBySchoolOfRecordsAndStudentStatus(List<String> schoolOfRecords,

@Transactional
public Integer archiveStudents(long batchId, List<String> schoolOfRecords, String studentStatus) {
String recordStudentStatus = StringUtils.defaultString(studentStatus, "CUR");
if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) {
return graduationStatusRepository.archiveStudents(schoolOfRecords, StringUtils.defaultString(studentStatus, "CUR"), "ARC", batchId);
List<UUID> graduationStudentRecordGuids = graduationStatusRepository.findBySchoolOfRecordInAndStudentStatus(schoolOfRecords, recordStudentStatus);
for(UUID graduationStudentRecordGuid: graduationStudentRecordGuids) {
saveStudentHistoryRecordDistributionRun(graduationStudentRecordGuid, batchId, "USERSTUDARC");
}
return graduationStatusRepository.archiveStudents(schoolOfRecords, recordStudentStatus, "ARC", batchId);
} else {
return graduationStatusRepository.archiveStudents(StringUtils.defaultString(studentStatus, "CUR"), "ARC", batchId);
List<UUID> graduationStudentRecordGuids = graduationStatusRepository.findByStudentStatus(recordStudentStatus);
for(UUID graduationStudentRecordGuid: graduationStudentRecordGuids) {
saveStudentHistoryRecordDistributionRun(graduationStudentRecordGuid, batchId, "USERSTUDARC");
}
return graduationStatusRepository.archiveStudents(recordStudentStatus, "ARC", batchId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public void createStudentHistory(GraduationStudentRecordEntity curStudentEntity,
logger.debug("Create Student History");
final GraduationStudentRecordHistoryEntity graduationStudentRecordHistoryEntity = new GraduationStudentRecordHistoryEntity();
BeanUtils.copyProperties(curStudentEntity, graduationStudentRecordHistoryEntity);
graduationStudentRecordHistoryEntity.setCreateUser(curStudentEntity.getCreateUser());
graduationStudentRecordHistoryEntity.setCreateDate(curStudentEntity.getCreateDate());
graduationStudentRecordHistoryEntity.setActivityCode(historyActivityCode);
graduationStudentRecordHistoryEntity.setStudentGradData("{ EMPTY CLOB }");
graduationStudentRecordHistoryRepository.save(graduationStudentRecordHistoryEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2218,6 +2218,23 @@ public void testSaveStudentRecord_DistributionRun() {
assertThat(res).isNotNull();
}

@Test
public void testSaveStudentRecord_DistributionRun_2() {
UUID studentID = new UUID(1, 1);
Long batchId = null;
GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity();
graduationStatusEntity.setStudentID(studentID);
graduationStatusEntity.setPen("12321321");
graduationStatusEntity.setStudentStatus("A");
graduationStatusEntity.setSchoolOfRecord("12345678");

when(graduationStatusRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity));

graduationStatusService.saveStudentHistoryRecordDistributionRun(studentID, batchId, "ACTIVITYCODE");

assertThat(graduationStatusEntity).isNotNull();
}

@Test
public void testGetStudentDataByStudentIds() {
// ID
Expand Down Expand Up @@ -2904,13 +2921,32 @@ public void testCountBySchoolOfRecordsAndStudentStatus() {

@Test
public void testArchiveStudents() {

UUID studentID = new UUID(1, 1);
GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity();
graduationStatusEntity.setStudentID(studentID);
graduationStatusEntity.setPen("12321321");
graduationStatusEntity.setStudentStatus("A");
graduationStatusEntity.setSchoolOfRecord("12345678");

when(graduationStatusRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity));
Mockito.when(graduationStatusRepository.findBySchoolOfRecordInAndStudentStatus(List.of("12345678"), "CUR")).thenReturn(List.of(studentID));
Mockito.when(graduationStatusRepository.archiveStudents(List.of("12345678"), "CUR", "ARC", 1L)).thenReturn(1);
Integer count = graduationStatusService.archiveStudents(1L, List.of("12345678"), "CUR");
assertThat(count).isNotNull().isEqualTo(1);
}

@Test
public void testArchiveStudentEmpty() {
UUID studentID = new UUID(1, 1);
GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity();
graduationStatusEntity.setStudentID(studentID);
graduationStatusEntity.setPen("12321321");
graduationStatusEntity.setStudentStatus("A");
graduationStatusEntity.setSchoolOfRecord("12345678");

when(graduationStatusRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity));
Mockito.when(graduationStatusRepository.findBySchoolOfRecordInAndStudentStatus(List.of("12345678"), "CUR")).thenReturn(List.of(studentID));
Mockito.when(graduationStatusRepository.archiveStudents("CUR", "ARC", 1L)).thenReturn(1);
Integer count = graduationStatusService.archiveStudents(1L, new ArrayList<>(), "CUR");
assertThat(count).isNotNull().isEqualTo(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStatusSubscriber;
import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Publisher;
import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Subscriber;
import ca.bc.gov.educ.api.gradstudent.model.dto.*;
import ca.bc.gov.educ.api.gradstudent.model.dto.GradSearchStudent;
import ca.bc.gov.educ.api.gradstudent.model.dto.GraduationData;
import ca.bc.gov.educ.api.gradstudent.model.dto.OptionalProgram;
import ca.bc.gov.educ.api.gradstudent.model.dto.Student;
import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordEntity;
import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordHistoryEntity;
import ca.bc.gov.educ.api.gradstudent.model.entity.HistoryActivityCodeEntity;
import ca.bc.gov.educ.api.gradstudent.model.entity.StudentOptionalProgramHistoryEntity;
import ca.bc.gov.educ.api.gradstudent.repository.GraduationStudentRecordHistoryRepository;
import ca.bc.gov.educ.api.gradstudent.repository.GraduationStudentRecordRepository;
import ca.bc.gov.educ.api.gradstudent.repository.HistoryActivityRepository;
import ca.bc.gov.educ.api.gradstudent.repository.StudentOptionalProgramHistoryRepository;
import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants;
Expand All @@ -33,8 +37,10 @@
import reactor.core.publisher.Mono;

import java.sql.Date;
import java.time.LocalDateTime;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Consumer;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -51,6 +57,7 @@ public class HistoryServiceTest {
@Autowired HistoryService historyService;
@MockBean CommonService commonService;
@MockBean GraduationStudentRecordHistoryRepository graduationStudentRecordHistoryRepository;
@MockBean GraduationStudentRecordRepository graduationStudentRecordRepository;
@MockBean HistoryActivityRepository historyActivityRepository;
@MockBean StudentOptionalProgramHistoryRepository studentOptionalProgramHistoryRepository;
@MockBean WebClient webClient;
Expand Down Expand Up @@ -136,6 +143,22 @@ public void testGetStudentOptionalProgramHistory() {

}

@Test
public void testCreateStudentHistory() {
UUID studentID = new UUID(1, 1);
GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity();
graduationStatusEntity.setStudentID(studentID);
graduationStatusEntity.setPen("12321321");
graduationStatusEntity.setStudentStatus("A");
graduationStatusEntity.setSchoolOfRecord("12345678");

when(graduationStudentRecordRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity));

historyService.createStudentHistory(graduationStatusEntity, "ACTIVITYCODE");

assertThat(graduationStatusEntity).isNotNull();
}

@Test
public void testGetStudentHistoryByHistoryID() {
// ID
Expand Down

0 comments on commit 4fa5246

Please sign in to comment.