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 2581 2 #635

Merged
merged 9 commits into from
Mar 28, 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 @@ -387,10 +387,10 @@ public ResponseEntity<List<UUID>> getStudentsForAmalgamatedSchoolReport(@PathVar
@PreAuthorize(PermissionsConstants.UPDATE_GRADUATION_STUDENT)
@Operation(summary = "Update Student Flag ready for batch by Batch Job Type and Student IDs", description = "Update Student Flag ready for batch by Batch Job Type and Student IDs", tags = { "Batch Algorithm" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<List<GraduationStudentRecord>> updateStudentFlagReadyForBatchJobByStudentIDs(@PathVariable String batchJobType, @RequestBody StudentList sList) {
public ResponseEntity<String> updateStudentFlagReadyForBatchJobByStudentIDs(@PathVariable String batchJobType, @RequestBody StudentList sList) {
logger.debug("Update Student Flag ready for batch by Student IDs and Batch Job Type - {}", batchJobType);
List<GraduationStudentRecord> gradRecords = gradStatusService.updateStudentFlagReadyForBatchJobByStudentIDs(batchJobType, sList.getStudentids());
return response.GET(gradRecords);
gradStatusService.updateStudentFlagReadyForBatchJobByStudentIDs(batchJobType, sList.getStudentids());
return response.GET("SUCCESS");
}

@GetMapping (EducGradStudentApiConstants.GRAD_STUDENT_NON_GRAD_REASON_BY_PEN)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ca.bc.gov.educ.api.gradstudent.model.entity;

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

public interface GraduationStudentRecordView {

public String getProgram();
public Date getProgramCompletionDate();
public String getGpa();
public String getHonoursStanding();
public String getRecalculateGradStatus();
public String getSchoolOfRecord();
public String getStudentGrade();
public String getStudentStatus();
public UUID getStudentID();
public String getSchoolAtGrad();
public String getRecalculateProjectedGrad();
public Long getBatchId();
public String getConsumerEducationRequirementMet();
public String getStudentCitizenship();
public Date getAdultStartDate();
public String getStudentProjectedGradData() ;
public LocalDateTime getCreateDate();
public LocalDateTime getUpdateDate();
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package ca.bc.gov.educ.api.gradstudent.model.transformer;

import ca.bc.gov.educ.api.gradstudent.model.dto.GraduationData;
import ca.bc.gov.educ.api.gradstudent.model.dto.GraduationStudentRecord;
import ca.bc.gov.educ.api.gradstudent.model.dto.GraduationStudentRecordDistribution;
import ca.bc.gov.educ.api.gradstudent.model.dto.ProjectedRunClob;
import ca.bc.gov.educ.api.gradstudent.model.dto.*;
import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordEntity;
import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordView;
import ca.bc.gov.educ.api.gradstudent.model.entity.ReportGradStudentDataEntity;
import ca.bc.gov.educ.api.gradstudent.repository.ReportGradStudentDataRepository;
import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiUtils;
import ca.bc.gov.educ.api.gradstudent.util.GradValidation;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import ca.bc.gov.educ.api.gradstudent.util.JsonTransformer;
import com.fasterxml.jackson.databind.type.TypeFactory;
import org.apache.commons.lang3.StringUtils;
import org.modelmapper.ModelMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -18,6 +18,8 @@

import java.sql.Date;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;


@Component
Expand All @@ -33,6 +35,12 @@ public class GraduationStatusTransformer {
@Autowired
GradValidation validation;

@Autowired
JsonTransformer jsonTransformer;

@Autowired
ReportGradStudentDataRepository reportGradStudentDataRepository;

public GraduationStudentRecord transformToDTOWithModifiedProgramCompletionDate(GraduationStudentRecordEntity gradStatusEntity) {
GraduationStudentRecord gradStatus = modelMapper.map(gradStatusEntity, GraduationStudentRecord.class);
gradStatus.setProgramCompletionDate(EducGradStudentApiUtils.parseDateFromString(gradStatusEntity.getProgramCompletionDate() != null ?
Expand Down Expand Up @@ -107,12 +115,7 @@ public GraduationStudentRecordDistribution tToDForDistribution(GraduationStudent
distObj.setStudentID(ent.getStudentID());
distObj.setStudentCitizenship(ent.getStudentCitizenship());
if(ent.getStudentGradData() != null) {
GraduationData existingData = null;
try {
existingData = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).readValue(ent.getStudentGradData(), GraduationData.class);
} catch (JsonProcessingException e) {
logger.error(JSON_PARSING_ERROR, e.getMessage());
}
GraduationData existingData = (GraduationData)jsonTransformer.unmarshall(ent.getStudentGradData(), GraduationData.class);
if(existingData != null) {
distObj.setPen(existingData.getGradStudent().getPen());
distObj.setLegalFirstName(existingData.getGradStudent().getLegalFirstName());
Expand All @@ -125,14 +128,14 @@ public GraduationStudentRecordDistribution tToDForDistribution(GraduationStudent
return distObj;
}

public List<GraduationStudentRecord> tToDForBatch(Iterable<GraduationStudentRecordEntity> gradStatusEntities) {
public List<GraduationStudentRecord> tToDForBatchView(List<GraduationStudentRecordView> gradStatusEntities) {
List<GraduationStudentRecord> gradStatusList = new ArrayList<>();
for (GraduationStudentRecordEntity gradStatusEntity : gradStatusEntities) {
Map<UUID, ReportGradStudentDataEntity> reportGradStudentDataMap = convertGraduationStudentRecordViewToReportGradStudentDataMap(gradStatusEntities);
for (GraduationStudentRecordView gradStatusEntity : gradStatusEntities) {
GraduationStudentRecord gradStatus = modelMapper.map(gradStatusEntity, GraduationStudentRecord.class);
logger.debug("GraduationStudentRecordEntity {} with database program completion date {}", gradStatusEntity.getPen(), gradStatusEntity.getProgramCompletionDate());
gradStatus.setProgramCompletionDate(EducGradStudentApiUtils.formatDate(gradStatusEntity.getProgramCompletionDate(), "yyyy/MM"));
populatePenAndLegalNamesAndNonGradReasons(gradStatus, reportGradStudentDataMap);
logger.debug("GraduationStudentRecord {} with trax program completion date {}", gradStatus.getPen(), gradStatus.getProgramCompletionDate());
populatePenAndLegalNamesAndNonGradReasons(gradStatus);
gradStatus.setStudentCitizenship(gradStatusEntity.getStudentCitizenship());
gradStatus.setStudentGradData(null);
gradStatus.setCreateDate((gradStatusEntity.getCreateDate()));
Expand All @@ -142,20 +145,17 @@ public List<GraduationStudentRecord> tToDForBatch(Iterable<GraduationStudentReco
return gradStatusList;
}

public List<UUID> tToDForAmalgamation(Iterable<GraduationStudentRecordEntity> gradStatusEntities, String type) {
public List<UUID> tToDForAmalgamation(List<GraduationStudentRecordView> gradStatusEntities, String type) {
List<GraduationStudentRecord> results = new ArrayList<>();
for (GraduationStudentRecordEntity gradStatusEntity : gradStatusEntities) {
Map<UUID, ReportGradStudentDataEntity> reportGradStudentDataMap = convertGraduationStudentRecordViewToReportGradStudentDataMap(gradStatusEntities);
for (GraduationStudentRecordView gradStatusEntity : gradStatusEntities) {
GraduationStudentRecord gradStatus = modelMapper.map(gradStatusEntity, GraduationStudentRecord.class);
gradStatus.setProgramCompletionDate(EducGradStudentApiUtils.parseTraxDate(gradStatusEntity.getProgramCompletionDate() != null ? gradStatusEntity.getProgramCompletionDate().toString():null));
populatePenAndLegalNamesAndNonGradReasons(gradStatus);
populatePenAndLegalNamesAndNonGradReasons(gradStatus, reportGradStudentDataMap);
if(gradStatus.getStudentProjectedGradData() != null) {
try {
ProjectedRunClob existingData = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).readValue(gradStatus.getStudentProjectedGradData(), ProjectedRunClob.class);
if((!existingData.isGraduated() && type.equalsIgnoreCase("TVRNONGRAD")) || (existingData.isGraduated() && type.equalsIgnoreCase("TVRGRAD"))) {
results.add(gradStatus);
}
} catch (JsonProcessingException e) {
logger.error(JSON_PARSING_ERROR ,e.getMessage());
ProjectedRunClob existingData = (ProjectedRunClob)jsonTransformer.unmarshall(gradStatus.getStudentProjectedGradData(), ProjectedRunClob.class);
if((!existingData.isGraduated() && type.equalsIgnoreCase("TVRNONGRAD")) || (existingData.isGraduated() && type.equalsIgnoreCase("TVRGRAD"))) {
results.add(gradStatus);
}
}

Expand All @@ -171,20 +171,23 @@ public List<UUID> tToDForAmalgamation(Iterable<GraduationStudentRecordEntity> gr
return results.stream().map(GraduationStudentRecord::getStudentID).toList();
}

private void populatePenAndLegalNamesAndNonGradReasons(GraduationStudentRecord gradStatus) {
if(gradStatus.getStudentGradData() != null) {
GraduationData existingData = null;
try {
existingData = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).readValue(gradStatus.getStudentGradData(), GraduationData.class);
} catch (JsonProcessingException e) {
logger.error(JSON_PARSING_ERROR, e.getMessage());
}
if (existingData != null) {
gradStatus.setPen(existingData.getGradStudent().getPen());
gradStatus.setLegalFirstName(existingData.getGradStudent().getLegalFirstName());
gradStatus.setLegalMiddleNames(existingData.getGradStudent().getLegalMiddleNames());
gradStatus.setLegalLastName(existingData.getGradStudent().getLegalLastName());
gradStatus.setNonGradReasons(existingData.getNonGradReasons());
private Map<UUID, ReportGradStudentDataEntity> convertGraduationStudentRecordViewToReportGradStudentDataMap(List<GraduationStudentRecordView> gradStatusEntities) {
List<UUID> uuids = gradStatusEntities.stream().map(GraduationStudentRecordView::getStudentID).toList();
List<ReportGradStudentDataEntity> reportGradStudentData = reportGradStudentDataRepository.findReportGradStudentDataEntityByGraduationStudentRecordIdInOrderByMincodeAscSchoolNameAscLastNameAsc(uuids);
return reportGradStudentData.stream().collect(Collectors.toMap(ReportGradStudentDataEntity::getGraduationStudentRecordId, Function.identity()));
}

private void populatePenAndLegalNamesAndNonGradReasons(GraduationStudentRecord gradStatus, Map<UUID, ReportGradStudentDataEntity> reportGradStudentDataMap) {
ReportGradStudentDataEntity existingData = reportGradStudentDataMap.get(gradStatus.getStudentID());
if (existingData != null) {
gradStatus.setPen(existingData.getPen());
gradStatus.setLegalFirstName(existingData.getFirstName());
gradStatus.setLegalMiddleNames(existingData.getMiddleName());
gradStatus.setLegalLastName(existingData.getLastName());
if (StringUtils.isNotBlank(existingData.getNonGradReasons())) {
TypeFactory typeFactory = jsonTransformer.getTypeFactory();
List<GradRequirement> nonGradReasons = (List<GradRequirement>) jsonTransformer.unmarshall(existingData.getNonGradReasons(), typeFactory.constructCollectionType(List.class, GradRequirement.class));
gradStatus.setNonGradReasons(nonGradReasons);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.bc.gov.educ.api.gradstudent.model.dto.BatchGraduationStudentRecord;
import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordEntity;
import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordView;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down Expand Up @@ -39,16 +40,14 @@ public interface GraduationStudentRecordRepository extends JpaRepository<Graduat
+ "(:schoolOfRecord is null or si.school_of_record = :schoolOfRecord)",nativeQuery = true)
public Page<GraduationStudentRecordEntity> findStudentWithFilter(String gradProgram,String schoolOfRecord, Pageable paging);

List<GraduationStudentRecordEntity> findByStudentIDIn(List<UUID> studentIds);
List<GraduationStudentRecordView> findByStudentIDIn(List<UUID> studentIds);

@Query("select c.studentID from GraduationStudentRecordEntity c where c.programCompletionDate is null and c.studentStatus='CUR' and (c.studentGrade='AD' or c.studentGrade='12')")
Page<UUID> findStudentsForYearlyDistribution(Pageable page);

@Query("select c from GraduationStudentRecordEntity c where c.schoolOfRecord=:schoolOfRecord and c.studentStatus='CUR'")
List<GraduationStudentRecordEntity> findBySchoolOfRecord(String schoolOfRecord);
List<GraduationStudentRecordView> findBySchoolOfRecordAndStudentStatus(String schoolOfRecord, String studentStatus);

@Query("select c from GraduationStudentRecordEntity c where c.schoolOfRecord=:schoolOfRecord and c.studentStatus='CUR' and (c.studentGrade='AD' or c.studentGrade='12')")
List<GraduationStudentRecordEntity> findBySchoolOfRecordAmalgamated(String schoolOfRecord);
List<GraduationStudentRecordView> findBySchoolOfRecordAndStudentStatusAndStudentGradeIn(String schoolOfRecord, String studentStatus, List<String> studentGrade);

// Data Conversion
@Modifying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.bc.gov.educ.api.gradstudent.model.dto.*;
import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordEntity;
import ca.bc.gov.educ.api.gradstudent.model.entity.GraduationStudentRecordView;
import ca.bc.gov.educ.api.gradstudent.model.transformer.GraduationStatusTransformer;
import ca.bc.gov.educ.api.gradstudent.repository.GraduationStudentRecordRepository;
import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants;
Expand Down Expand Up @@ -221,7 +222,7 @@ private List<GradSearchStudent> buildPartitions(List<Student> studentLists, Stri
for (int i = 0; i < partitions.size(); i++) {
List<UUID> subList = partitions.get(i);
logger.debug(" sub list length {} par {}", subList.size(), i);
List<GraduationStudentRecordEntity> gradList = graduationStatusRepository.findByStudentIDIn(subList);
List<GraduationStudentRecordView> gradList = graduationStatusRepository.findByStudentIDIn(subList);
if (!gradList.isEmpty()) {
gradList.forEach(st -> {
GradSearchStudent gradStu = populateGradStudent(st, accessToken);
Expand Down Expand Up @@ -273,9 +274,9 @@ private void getSearchCriteria(String value, String value2, String paramterType,
if(StringUtils.isNotBlank(value) && StringUtils.isNotBlank(value2)) {
criteria = SearchCriteria.builder().condition(Condition.AND).key(paramterType).operation(FilterOperation.BETWEEN).value(value + "," + value2).valueType(ValueType.DATE).build();
}
}else if (paramterType.equalsIgnoreCase("studentID")) {
} else if (paramterType.equalsIgnoreCase("studentID")) {
criteria = SearchCriteria.builder().key(paramterType).operation(FilterOperation.IN).value(value).valueType(ValueType.UUID).condition(Condition.AND).build();
}else {
} else {
if(StringUtils.isNotBlank(value)) {
if(StringUtils.contains(value,"*")) {
criteria = SearchCriteria.builder().key(paramterType).operation(FilterOperation.STARTS_WITH_IGNORE_CASE).value(StringUtils.strip(value,"*")).valueType(ValueType.STRING).condition(Condition.AND).build();
Expand All @@ -290,21 +291,32 @@ private void getSearchCriteria(String value, String value2, String paramterType,
private GradSearchStudent populateGradStudent(GraduationStudentRecordEntity gradRecord, String accessToken) {
GradSearchStudent gradStu = new GradSearchStudent();
BeanUtils.copyProperties(gradRecord, gradStu);
Student studentPen = webClient.get().uri(String.format(constants.getPenStudentApiByStudentIdUrl(), gradRecord.getStudentID()))
.headers(h -> {
h.setBearerAuth(accessToken);
h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID());
})
.retrieve().bodyToMono(Student.class).block();
return populateGradStudent(gradStu, accessToken);
}

private GradSearchStudent populateGradStudent(GraduationStudentRecordView gradRecord, String accessToken) {
GradSearchStudent gradStu = new GradSearchStudent();
BeanUtils.copyProperties(gradRecord, gradStu);
gradStu.setStudentID(gradRecord.getStudentID().toString());
return populateGradStudent(gradStu, accessToken);
}

private GradSearchStudent populateGradStudent(GradSearchStudent gradStu, String accessToken) {
Student studentPen = webClient.get().uri(String.format(constants.getPenStudentApiByStudentIdUrl(), gradStu.getStudentID()))
.headers(h -> {
h.setBearerAuth(accessToken);
h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID());
})
.retrieve().bodyToMono(Student.class).block();
if(studentPen != null) {
BeanUtils.copyProperties(studentPen, gradStu);
}
School school = webClient.get().uri(String.format(constants.getSchoolByMincodeUrl(), gradStu.getSchoolOfRecord()))
.headers(h -> {
h.setBearerAuth(accessToken);
h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID());
})
.retrieve().bodyToMono(School.class).block();
.headers(h -> {
h.setBearerAuth(accessToken);
h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID());
})
.retrieve().bodyToMono(School.class).block();
if (school != null) {
gradStu.setSchoolOfRecordName(school.getSchoolName());
gradStu.setSchoolOfRecordindependentAffiliation(school.getIndependentAffiliation());
Expand Down
Loading
Loading