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 #674

Merged
merged 13 commits into from
Aug 22, 2024
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package ca.bc.gov.educ.api.gradstudent.controller;

import java.util.List;

import ca.bc.gov.educ.api.gradstudent.model.dto.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import ca.bc.gov.educ.api.gradstudent.service.GradStudentService;
import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants;
import ca.bc.gov.educ.api.gradstudent.util.PermissionsConstants;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@RestController
@CrossOrigin
Expand Down Expand Up @@ -116,4 +117,12 @@ public GraduationStudentRecordDistribution getGradStudentByStudentIDFromGRAD(@Pa
public Student addNewPenFromStudentAPI(@Validated @RequestBody StudentCreate student, @RequestHeader(name="Authorization") String accessToken) {
return gradStudentService.addNewPenFromStudentAPI(student, accessToken.replaceAll("Bearer ", ""));
}

@PostMapping (EducGradStudentApiConstants.GRAD_STUDENT_BY_SEARCH_CRITERIAS)
@PreAuthorize(PermissionsConstants.READ_GRADUATION_STUDENT)
@Operation(summary = "Find Students by StudentSearchRequest criteria", description = "Find Students by StudentSearchRequest criteria", tags = { "Search Student Records" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public List<UUID> searchGraduationStudentRecords(@RequestBody StudentSearchRequest searchRequest) {
return gradStudentService.getStudentIDsBySearchCriteriaOrAll(searchRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -349,19 +349,19 @@ public ResponseEntity<List<UUID>> getStudentsForYearlyRun() {
@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<GraduationStudentRecord> saveStudentGradStatusDistributionRun(@PathVariable String studentID, @RequestParam(required = false) Long batchId,@RequestParam(required = false) String activityCode) {
public ResponseEntity<GraduationStudentRecord> saveStudentGradStatusDistributionRun(@PathVariable String studentID, @RequestParam(required = false) Long batchId, @RequestParam(required = false) String activityCode, @RequestParam(required = false) String username) {
logger.debug("Save Distribution student Grad Status for Student ID");
GraduationStudentRecord gradRecord = gradStatusService.saveStudentRecordDistributionRun(UUID.fromString(studentID),batchId,activityCode);
GraduationStudentRecord gradRecord = gradStatusService.saveStudentRecordDistributionRun(UUID.fromString(studentID),batchId,activityCode,username);
return response.GET(gradRecord);
}

@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" })
@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) {
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));
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 @@ -29,12 +29,14 @@ public class StudentSearchRequest implements Serializable {
String schoolOfRecord;
String gradProgram;

private List<String> schoolOfRecords;
private List<String> districts;
private List<String> schoolCategoryCodes;
private List<String> pens;
private List<String> programs;
private List<UUID> studentIDs;
private List<String> schoolOfRecords = new ArrayList<>();
private List<String> districts = new ArrayList<>();
private List<String> schoolCategoryCodes = new ArrayList<>();
private List<String> pens = new ArrayList<>();
private List<String> programs = new ArrayList<>();
private List<UUID> studentIDs = new ArrayList<>();
private List<String> statuses = new ArrayList<>();
private List<String> reportTypes = new ArrayList();

@JsonFormat(pattern= EducGradStudentApiConstants.DEFAULT_DATE_FORMAT)
LocalDate gradDateFrom;
Expand Down Expand Up @@ -82,4 +84,13 @@ public List<String> getPrograms() {
public String toJson() {
return new Gson().toJson(this);
}

public boolean isEmpty() {
return schoolOfRecords.isEmpty() &&
districts.isEmpty() &&
schoolCategoryCodes.isEmpty() &&
pens.isEmpty() &&
studentIDs.isEmpty() &&
programs.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ public interface GraduationStudentRecordRepository extends JpaRepository<Graduat
@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.schoolOfRecord IN (:schoolOfRecords)")
List<UUID> findBySchoolOfRecordIn(List<String> schoolOfRecords);

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

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

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 All @@ -61,6 +67,9 @@ public interface GraduationStudentRecordRepository extends JpaRepository<Graduat
@Query("select count(*) from GraduationStudentRecordEntity c where c.schoolOfRecord IN (:schoolOfRecords) and c.studentStatus=:studentStatus")
Long countBySchoolOfRecordsAndStudentStatus(List<String> schoolOfRecords, String studentStatus);

@Query("select count(*) from GraduationStudentRecordEntity c where c.schoolOfRecord IN (:schoolOfRecords)")
Long countBySchoolOfRecords(List<String> schoolOfRecords);

@Query("select count(*) from GraduationStudentRecordEntity c where c.studentStatus=:studentStatus")
Long countByStudentStatus(String studentStatus);

Expand Down Expand Up @@ -96,8 +105,8 @@ void updateStudentGuidPenXrefRecord(
long countStudentGuidPenXrefRecord(@Param("studentGuid") UUID studentGuid);

@Query(value="select STUDENT_GUID from STUDENT_GUID_PEN_XREF \n"
+ "where STUDENT_PEN = :pen", nativeQuery = true)
byte[] findStudentID(@Param("pen") String pen);
+ "where STUDENT_PEN in (:pens)", nativeQuery = true)
List<UUID> findStudentIDsByPenIn(@Param("pens") List<String> pens);

@Query("select c.studentID from GraduationStudentRecordEntity c where c.studentStatus = :statusCode and c.studentID in :studentIDList")
List<UUID> filterGivenStudentsByStatusCode(@Param("studentIDList") List<UUID> studentIDs, @Param("statusCode") String statusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public GradOnlyStudentSearch getGRADStudents(StudentSearchRequest studentSearchR
h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID());
})
.retrieve().bodyToMono(new ParameterizedTypeReference<RestResponsePage<Student>>() {}).block();
List<Student> studentList = response != null ?response.getContent():new ArrayList<>();
List<Student> studentList = response != null ? response.getContent() : new ArrayList<>();
if (!studentList.isEmpty()) {
studentList.forEach(st -> {
GradSearchStudent gradStu = populateGradSearchStudent(st, accessToken);
Expand Down Expand Up @@ -405,4 +405,25 @@ public List<UUID> getStudentIDsByStatusCode(List<UUID> studentIDs, String status
}
return results;
}

public List<UUID> getStudentIDsBySearchCriteriaOrAll(StudentSearchRequest searchRequest) {
ArrayList<UUID> result = new ArrayList<>();
boolean paramsNotEmpty = false;
if(searchRequest.getStudentIDs() != null && !searchRequest.getStudentIDs().isEmpty()) {
paramsNotEmpty = true;
result.addAll(searchRequest.getStudentIDs());
}
if(searchRequest.getPens() != null && !searchRequest.getPens().isEmpty()) {
paramsNotEmpty = true;
result.addAll(graduationStatusRepository.findStudentIDsByPenIn(searchRequest.getPens()));
}
if(searchRequest.getSchoolOfRecords() != null && !searchRequest.getSchoolOfRecords().isEmpty()) {
paramsNotEmpty = true;
result.addAll(graduationStatusRepository.findBySchoolOfRecordIn(searchRequest.getSchoolOfRecords()));
}
if(!paramsNotEmpty) {
result.addAll(graduationStatusRepository.findAllStudentGuids());
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1219,12 +1219,12 @@ public boolean restoreGradStudentRecord(UUID studentID,boolean isGraduated) {
}

@Retry(name = "generalpostcall")
public GraduationStudentRecord saveStudentRecordDistributionRun(UUID studentID, Long batchId, String activityCode) {
public GraduationStudentRecord saveStudentRecordDistributionRun(UUID studentID, Long batchId, String activityCode, String username) {
Optional<GraduationStudentRecordEntity> gradStatusOptional = graduationStatusRepository.findById(studentID);
if (gradStatusOptional.isPresent()) {
GraduationStudentRecordEntity gradEntity = gradStatusOptional.get();
gradEntity.setUpdateUser(null);
gradEntity.setUpdateDate(null);
gradEntity.setUpdateUser(StringUtils.isNotBlank(username) && !StringUtils.equalsIgnoreCase(username, "null") ? username : null);
gradEntity.setUpdateDate(LocalDateTime.now());
gradEntity.setBatchId(batchId);
gradEntity = graduationStatusRepository.saveAndFlush(gradEntity);
historyService.createStudentHistory(gradEntity, activityCode);
Expand Down Expand Up @@ -1385,10 +1385,12 @@ public Integer countStudentsForAmalgamatedSchoolReport(String schoolOfRecord) {
}

public Long countBySchoolOfRecordsAndStudentStatus(List<String> schoolOfRecords, String studentStatus) {
if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) {
return graduationStatusRepository.countBySchoolOfRecordsAndStudentStatus(schoolOfRecords, StringUtils.defaultString(studentStatus, "CUR"));
if(schoolOfRecords != null && !schoolOfRecords.isEmpty() && StringUtils.isNotBlank(studentStatus) && !StringUtils.equalsAnyIgnoreCase(studentStatus, "null")) {
return graduationStatusRepository.countBySchoolOfRecordsAndStudentStatus(schoolOfRecords, StringUtils.upperCase(studentStatus));
} else if(StringUtils.isNotBlank(studentStatus) && !StringUtils.equalsAnyIgnoreCase(studentStatus, "null")) {
return graduationStatusRepository.countByStudentStatus(StringUtils.upperCase(studentStatus));
} else {
return graduationStatusRepository.countByStudentStatus(StringUtils.defaultString(studentStatus, "CUR"));
return countBySchoolOfRecords(schoolOfRecords);
}
}

Expand Down Expand Up @@ -1448,6 +1450,14 @@ private void saveBatchFlagsOfGraduationStudentRecord(GraduationStudentRecordEnti
}
}

private Long countBySchoolOfRecords(List<String> schoolOfRecords) {
if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) {
return graduationStatusRepository.countBySchoolOfRecords(schoolOfRecords);
} else {
return graduationStatusRepository.count();
}
}

private void resetBatchFlags(GraduationStudentRecordEntity gradEntity, boolean projectedRun) {
String flag = null;
if (gradEntity.getProgram().equalsIgnoreCase("SCCP") && EducGradStudentApiUtils.isDateInFuture(gradEntity.getProgramCompletionDate())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ca.bc.gov.educ.api.gradstudent.model.transformer.GraduationStudentRecordHistoryTransformer;
import ca.bc.gov.educ.api.gradstudent.model.transformer.StudentOptionalProgramHistoryTransformer;
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 Down Expand Up @@ -38,6 +39,7 @@ public class HistoryService {
final
WebClient webClient;

final GraduationStudentRecordRepository graduationStatusRepository;
final GraduationStudentRecordHistoryRepository graduationStudentRecordHistoryRepository;
final GraduationStudentRecordHistoryTransformer graduationStudentRecordHistoryTransformer;
final StudentOptionalProgramHistoryRepository studentOptionalProgramHistoryRepository;
Expand All @@ -46,13 +48,14 @@ public class HistoryService {
final EducGradStudentApiConstants constants;

@Autowired
public HistoryService(WebClient webClient, GraduationStudentRecordHistoryRepository graduationStudentRecordHistoryRepository, GraduationStudentRecordHistoryTransformer graduationStudentRecordHistoryTransformer, StudentOptionalProgramHistoryRepository studentOptionalProgramHistoryRepository, StudentOptionalProgramHistoryTransformer studentOptionalProgramHistoryTransformer, EducGradStudentApiConstants constants, HistoryActivityRepository historyActivityRepository) {
public HistoryService(WebClient webClient, GraduationStudentRecordHistoryRepository graduationStudentRecordHistoryRepository, GraduationStudentRecordHistoryTransformer graduationStudentRecordHistoryTransformer, StudentOptionalProgramHistoryRepository studentOptionalProgramHistoryRepository, StudentOptionalProgramHistoryTransformer studentOptionalProgramHistoryTransformer, EducGradStudentApiConstants constants, HistoryActivityRepository historyActivityRepository, GraduationStudentRecordRepository graduationStatusRepository) {
this.webClient = webClient;
this.graduationStudentRecordHistoryRepository = graduationStudentRecordHistoryRepository;
this.graduationStudentRecordHistoryTransformer = graduationStudentRecordHistoryTransformer;
this.studentOptionalProgramHistoryRepository = studentOptionalProgramHistoryRepository;
this.studentOptionalProgramHistoryTransformer = studentOptionalProgramHistoryTransformer;
this.historyActivityRepository = historyActivityRepository;
this.graduationStatusRepository = graduationStatusRepository;
this.constants = constants;
}

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

@Transactional
public Integer updateStudentRecordHistoryDistributionRun(Long batchId, String updateUser, String activityCode) {
public Integer updateStudentRecordHistoryDistributionRun(Long batchId, String updateUser, String activityCode, List<UUID> studentGuids) {
Integer result = 0;
LocalDateTime updateDate = LocalDateTime.now();
if(StringUtils.isBlank(activityCode) || StringUtils.equalsIgnoreCase(activityCode, "null")) {
return graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, updateUser, updateDate);
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 ++;
}
}
}
} else if(StringUtils.isBlank(activityCode) || StringUtils.equalsIgnoreCase(activityCode, "null")) {
result = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, updateUser, updateDate);
} else {
return graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, activityCode, updateUser, updateDate);
result = graduationStudentRecordHistoryRepository.updateGradStudentUpdateUser(batchId, activityCode, updateUser, updateDate);
}
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class EducGradStudentApiConstants {
public static final String GRAD_STUDENT_DEMOG_BY_PEN = "/demog/pen/{pen}";
public static final String GRAD_STUDENT_BY_STUDENT_ID_STUDENT_API = "/stdid/{studentID}";
public static final String GRAD_STUDENT_BY_STUDENT_ID_GRAD="/grad/{studentID}";
public static final String GRAD_STUDENT_BY_SEARCH_CRITERIAS = "/gradstudentbysearchcriteria";
public static final String GRAD_STUDENT_BY_LAST_NAME = "/gradstudent";
public static final String GRAD_STUDENT_BY_FIRST_NAME = "/studentsearchfirstname";
public static final String GRAD_STUDENT_BY_MULTIPLE_STUDENTIDS = "/multistudentids";
Expand Down
Loading
Loading