Skip to content

Commit

Permalink
Merge pull request #618 from bcgov/feature/Grad2-2434
Browse files Browse the repository at this point in the history
Grad2-2434 Archived students user name Corrected
  • Loading branch information
arybakov-cgi authored Feb 1, 2024
2 parents ead83d9 + c7e4aa8 commit 720372f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordHistoryEntity;
import ca.bc.gov.educ.api.gradstudent.service.GraduationStatusService;
import ca.bc.gov.educ.api.gradstudent.service.HistoryService;
import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants;
import ca.bc.gov.educ.api.gradstudent.util.GradValidation;
import ca.bc.gov.educ.api.gradstudent.util.PermissionsConstants;
import ca.bc.gov.educ.api.gradstudent.util.ResponseHelper;
import ca.bc.gov.educ.api.gradstudent.util.*;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -362,10 +359,10 @@ public ResponseEntity<GraduationStudentRecord> saveStudentGradStatusDistribution
@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" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<GraduationStudentRecordHistory> saveStudentGradHistoryStatusDistributionRun(@PathVariable Long batchID, @RequestParam(required = false) String userName) {
public ResponseEntity<ApiResponseModel<Void>> updateStudentGradHistoryStatusDistributionRun(@PathVariable Long batchID, @RequestParam(required = false) String userName) {
logger.debug("Save Distribution student Grad history for Student ID");
GraduationStudentRecordHistory gradRecord = historyService.saveStudentRecordHistoryDistributionRun(batchID, userName);
return response.GET(gradRecord);
historyService.updateStudentRecordHistoryDistributionRun(batchID, userName);
return response.UPDATED(null);
}

@GetMapping (EducGradStudentApiConstants.STUDENT_LIST_FOR_SCHOOL_REPORT)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package ca.bc.gov.educ.api.gradstudent.repository;

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

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordHistoryEntity;
Expand All @@ -17,6 +21,10 @@ public interface GraduationStudentRecordHistoryRepository extends JpaRepository<
List<GraduationStudentRecordHistoryEntity> findAll();
List<GraduationStudentRecordHistoryEntity> findByStudentID(UUID studentID);
Page<GraduationStudentRecordHistoryEntity> findByBatchId(Long batchId, Pageable paging);
GraduationStudentRecordHistoryEntity findByBatchId(Long batchId);
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)
void updateGradStudentUpdateUser(@Param(value = "batchId") Long batchId, @Param(value = "updateUser") String updateUser, @Param(value = "updateDate") LocalDateTime updateDate);

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
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.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -154,14 +156,12 @@ public Page<GraduationStudentRecordHistoryEntity> getStudentHistoryByBatchID(Lon
return pagedDate;
}

public GraduationStudentRecordHistory saveStudentRecordHistoryDistributionRun(Long batchId, String userName) {
@Transactional
public void updateStudentRecordHistoryDistributionRun(Long batchId, String updateUser) {

GraduationStudentRecordHistoryEntity gradStudentRecordHistoryEntity = graduationStudentRecordHistoryRepository.findByBatchId(batchId);
gradStudentRecordHistoryEntity.setUpdateUser(userName);
gradStudentRecordHistoryEntity.setUpdateDate(null);
graduationStudentRecordHistoryRepository.save(gradStudentRecordHistoryEntity);
return graduationStudentRecordHistoryTransformer.transformToDTO(gradStudentRecordHistoryEntity);
LocalDateTime updateDate = LocalDateTime.now();
graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, updateUser, updateDate);

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -442,21 +442,6 @@ public void testSaveStudentRecord_DsitributionRun() {
Mockito.verify(graduationStatusService).saveStudentRecordDistributionRun(studentID,null,"ACTIVITYCODE");
}

@Test
public void saveStudentGradHistoryStatusDistributionRun() {
// ID
final Long batchID = 426L;
final String userName = "ABC";

GraduationStudentRecordHistory gradStudRecHistory = new GraduationStudentRecordHistory();
gradStudRecHistory.setBatchId(426L);
gradStudRecHistory.setUpdateUser("ABC");

Mockito.when(historyService.saveStudentRecordHistoryDistributionRun(batchID, userName)).thenReturn(gradStudRecHistory);
graduationStatusController.saveStudentGradHistoryStatusDistributionRun(batchID, userName);
Mockito.verify(historyService).saveStudentRecordHistoryDistributionRun(batchID, userName);
}

@Test
public void testreturnToOriginalState_returnsfalse() {
// ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,6 @@ public void testGetStudentHistoryByHistoryID() {
assertThat(result).isNotNull();
}

@Test
public void testSaveStudentRecordHistoryDistributionRun() {
final Long batchID = 426L;
final String userName = "ABC";

GraduationStudentRecordHistoryEntity graduationStatusEntity = new GraduationStudentRecordHistoryEntity();
graduationStatusEntity.setUpdateUser("ABC");
graduationStatusEntity.setUpdateDate(LocalDateTime.now());

when(graduationStudentRecordHistoryRepository.findByBatchId(batchID)).thenReturn(graduationStatusEntity);
var result = historyService.saveStudentRecordHistoryDistributionRun(batchID, userName);
assertThat(result).isNotNull();
}

@Test
public void testGetStudentOptionalProgramHistoryByID() {
UUID studentID = UUID.randomUUID();
Expand Down

0 comments on commit 720372f

Please sign in to comment.