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

DTO Projection for grad status #633

Merged
merged 4 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 @@ -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
Expand Up @@ -91,4 +91,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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ca.bc.gov.educ.api.gradstudent.constant.Generated;
import ca.bc.gov.educ.api.gradstudent.exception.EntityNotFoundException;
import ca.bc.gov.educ.api.gradstudent.model.dto.*;
import ca.bc.gov.educ.api.gradstudent.model.dto.messaging.GraduationStudentRecordGradStatus;
import ca.bc.gov.educ.api.gradstudent.model.entity.*;
import ca.bc.gov.educ.api.gradstudent.model.transformer.GradStudentCareerProgramTransformer;
import ca.bc.gov.educ.api.gradstudent.model.transformer.GradStudentOptionalProgramTransformer;
Expand Down Expand Up @@ -167,6 +168,20 @@ public GraduationStudentRecord getGraduationStatus(UUID studentID) throws Entity
throw new EntityNotFoundException(String.format("Student with ID: %s not found", studentID));
}

/**
* Returns a condensed version of GraduationStudentRecord without the CLOB etc
* @param studentID
* @return
* @throws EntityNotFoundException
*/
public GraduationStudentRecordGradStatus getGraduationStatusProjection(UUID studentID) throws EntityNotFoundException {
GraduationStudentRecordGradStatus response = graduationStatusRepository.findByStudentID(studentID, GraduationStudentRecordGradStatus.class);
if (response != null) {
return response;
}
throw new EntityNotFoundException(String.format("Student with ID: %s not found", studentID));
}

@Transactional
@Retry(name = "generalpostcall")
public Pair<GraduationStudentRecord, GradStatusEvent> saveGraduationStatus(UUID studentID, GraduationStudentRecord graduationStatus, Long batchId, String accessToken) throws JsonProcessingException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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.messaging.GraduationStudentRecordGradStatus;
import ca.bc.gov.educ.api.gradstudent.model.entity.*;
import ca.bc.gov.educ.api.gradstudent.repository.*;
import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants;
Expand Down Expand Up @@ -142,6 +143,25 @@ public void testGetGraduationStatus_givenNotFound_ExpectEntityNotFoundExcetpion(
});
}

@Test
public void testGetGraduationStatusProjection_GivenValidProgramCompletionDate_ExpectTrue() throws EntityNotFoundException {
UUID studentID = UUID.randomUUID();
GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity();
graduationStatusEntity.setProgramCompletionDate(new java.util.Date());
when(graduationStatusRepository.findByStudentID(studentID, GraduationStudentRecordGradStatus.class)).thenReturn(new GraduationStudentRecordGradStatus(studentID, "2018-EN", new java.util.Date()));
GraduationStudentRecordGradStatus result = graduationStatusService.getGraduationStatusProjection(studentID);
assertNotNull(result);
}

@Test
public void testGetGraduationStatusProjection_givenNotFound_ExpectEntityNotFoundExcetpion() {
UUID studentID = UUID.randomUUID();
when(graduationStatusRepository.findByStudentID(studentID, GraduationStudentRecordGradStatus.class)).thenReturn(null);
assertThrows(EntityNotFoundException.class, () -> {
graduationStatusService.getGraduationStatusProjection(studentID);
});
}

@Test
public void testGetGraduationStatusForAlgorithm() {
// ID
Expand Down
Loading