Skip to content

Commit

Permalink
Merge pull request #636 from bcgov/grad-release
Browse files Browse the repository at this point in the history
Grad release 1.17.0
  • Loading branch information
githubmamatha authored Apr 8, 2024
2 parents 1226fcf + 52a98de commit 7aa9cb8
Show file tree
Hide file tree
Showing 12 changed files with 569 additions and 164 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ca.bc.gov.educ</groupId>
<artifactId>educ-grad-student-api</artifactId>
<version>1.8.56</version>
<version>1.8.57</version>
<name>educ-grad-student-api</name>
<description>Student Demographics API for GRAD team</description>

Expand Down
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
Expand Up @@ -5,8 +5,10 @@
import ca.bc.gov.educ.api.gradstudent.model.dc.Event;
import ca.bc.gov.educ.api.gradstudent.model.dc.GradStatusPayload;
import ca.bc.gov.educ.api.gradstudent.model.dto.GraduationStudentRecord;
import ca.bc.gov.educ.api.gradstudent.model.dto.messaging.GraduationStudentRecordGradStatus;
import ca.bc.gov.educ.api.gradstudent.service.GraduationStatusService;
import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants;
import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiUtils;
import ca.bc.gov.educ.api.gradstudent.util.JsonUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.nats.client.*;
Expand Down Expand Up @@ -50,7 +52,7 @@ public void onMessage(Message message) {
try {
Event event = JsonUtil.getJsonObjectFromString(Event.class, eventString);
UUID stdId = JsonUtil.getJsonObjectFromString(UUID.class, event.getEventPayload());
GraduationStudentRecord graduationStatus = graduationStatusService.getGraduationStatus(stdId);
GraduationStudentRecordGradStatus graduationStatus = graduationStatusService.getGraduationStatusProjection(stdId);
response = getResponse(graduationStatus);
} catch (Exception e) {
response = getErrorResponse(e);
Expand All @@ -61,10 +63,12 @@ public void onMessage(Message message) {
this.natsConnection.publish(message.getReplyTo(), response.getBytes());
}

private String getResponse(GraduationStudentRecord graduationStudentRecord) throws JsonProcessingException {
private String getResponse(GraduationStudentRecordGradStatus graduationStudentRecord) throws JsonProcessingException {
GradStatusPayload gradStatusPayload = GradStatusPayload.builder()
.program(graduationStudentRecord.getProgram())
.programCompletionDate(graduationStudentRecord.getProgramCompletionDate())
.programCompletionDate(
graduationStudentRecord.getProgramCompletionDate() != null ?
EducGradStudentApiUtils.formatDate(graduationStudentRecord.getProgramCompletionDate()) : null)
.build();
return JsonUtil.getJsonStringFromObject(gradStatusPayload);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ca.bc.gov.educ.api.gradstudent.model.dto.messaging;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Date;
import java.util.UUID;

@Data
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class GraduationStudentRecordGradStatus {

private UUID studentID;
private String program;
private Date programCompletionDate;

}
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 Expand Up @@ -91,4 +90,15 @@ void updateStudentGuidPenXrefRecord(
@Modifying
@Query( "update GraduationStudentRecordEntity e set e.recalculateProjectedGrad = 'Y' where e.studentStatus = 'CUR' and e.programCompletionDate is null and (e.studentGrade = '12' or e.studentGrade = 'AD')")
void updateGradStudentRecalcFlagsForCurrentStudentsWithNullCompletion();

/**
* Find a GraduationStudentRecord By Student ID using generics. Pass an object with the
* same subset of field names, getters/setters of GraduationStudentRecordEntity to return
* objects with a subset of values. More info: https://docs.spring.io/spring-data/jpa/reference/repositories/projections.html
* @param studentId the student ID
* @param type The class type of the object you wish to use
* @return
* @param <T>
*/
<T> T findByStudentID(UUID studentId, Class<T> type);
}
Loading

0 comments on commit 7aa9cb8

Please sign in to comment.