diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/FieldName.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/FieldName.java index e72a2f41..1aec0d1c 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/FieldName.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/FieldName.java @@ -2,6 +2,7 @@ public enum FieldName { SCHOOL_OF_RECORD, + SCHOOL_OF_RECORD_ID, GRAD_PROGRAM, ADULT_START_DATE, SLP_DATE, diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/FieldType.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/FieldType.java index 0bfb7815..20883949 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/FieldType.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/FieldType.java @@ -2,5 +2,6 @@ public enum FieldType { STRING, - DATE + DATE, + GUID } \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/Topics.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/Topics.java index 7bc5019d..b7342b0d 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/Topics.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/Topics.java @@ -8,5 +8,6 @@ public enum Topics { * GradStatus events topic. */ GRAD_STATUS_EVENT_TOPIC, - GRAD_STUDENT_API_FETCH_GRAD_STATUS_TOPIC + GRAD_STUDENT_API_FETCH_GRAD_STATUS_TOPIC, + GRAD_STUDENT_API_FETCH_GRAD_STUDENT_TOPIC, } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java new file mode 100644 index 00000000..3d47f72a --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStudentRecordSubscriber.java @@ -0,0 +1,91 @@ +package ca.bc.gov.educ.api.gradstudent.messaging.jetstream; + +import ca.bc.gov.educ.api.gradstudent.constant.Topics; +import ca.bc.gov.educ.api.gradstudent.exception.EntityNotFoundException; +import ca.bc.gov.educ.api.gradstudent.model.dc.Event; +import ca.bc.gov.educ.api.gradstudent.model.dc.GradStudentRecordPayload; +import ca.bc.gov.educ.api.gradstudent.model.dto.messaging.GradStudentRecord; +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.EducGradStudentApiUtils; +import ca.bc.gov.educ.api.gradstudent.util.JsonUtil; +import com.fasterxml.jackson.core.JsonProcessingException; +import io.nats.client.*; +import lombok.val; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.UUID; + +@Component +public class FetchGradStudentRecordSubscriber implements MessageHandler { + + private final Connection natsConnection; + private Dispatcher dispatcher; + private final GradStudentService gradStudentService; + public static final String RESPONDING_BACK_TO_NATS_ON_CHANNEL = "responding back to NATS on {} channel "; + public static final String PAYLOAD_LOG = "payload is :: {}"; + private static final String TOPIC = Topics.GRAD_STUDENT_API_FETCH_GRAD_STUDENT_TOPIC.toString(); + private static final Logger log = LoggerFactory.getLogger(FetchGradStudentRecordSubscriber.class); + + @Autowired + public FetchGradStudentRecordSubscriber(final Connection natsConnection, GradStudentService gradStudentService, EducGradStudentApiConstants constants) { + this.natsConnection = natsConnection; + this.gradStudentService = gradStudentService; + } + + @PostConstruct + public void subscribe() { + this.dispatcher = this.natsConnection.createDispatcher(this); + this.dispatcher.subscribe(TOPIC); + } + + @Override + public void onMessage(Message message) { + val eventString = new String(message.getData()); + log.debug("Received message: {}", eventString); + String response; + + try { + Event event = JsonUtil.getJsonObjectFromString(Event.class, eventString); + log.info("received GET_STUDENT event :: {}", event.getSagaId()); + log.trace(PAYLOAD_LOG, event.getEventPayload()); + UUID studentId = JsonUtil.getJsonObjectFromString(UUID.class, event.getEventPayload()); + GradStudentRecord studentRecord = gradStudentService.getGraduationStudentRecord(studentId); + response = getResponse(studentRecord); + log.info(RESPONDING_BACK_TO_NATS_ON_CHANNEL, message.getReplyTo() != null ? message.getReplyTo() : event.getReplyTo()); + } catch (Exception e) { + response = getErrorResponse(e); + log.error("Error while processing GET_STUDENT event", e); + } + this.natsConnection.publish(message.getReplyTo(), response.getBytes()); + } + + private String getResponse(GradStudentRecord studentRecord) throws JsonProcessingException { + GradStudentRecordPayload gradStudentRecordPayload = GradStudentRecordPayload.builder() + .studentID(String.valueOf(studentRecord.getStudentID())) + .program(studentRecord.getProgram()) + .programCompletionDate(studentRecord.getProgramCompletionDate() != null ? EducGradStudentApiUtils.formatDate(studentRecord.getProgramCompletionDate()) : null) + .schoolOfRecord(studentRecord.getSchoolOfRecord()) + .studentStatusCode(studentRecord.getStudentStatusCode()) + .graduated(studentRecord.getGraduated().toString()) + .build(); + return JsonUtil.getJsonStringFromObject(gradStudentRecordPayload); + } + + private String getErrorResponse(Exception e) { + String ex = (e instanceof EntityNotFoundException) ? "not found" : "error"; + GradStudentRecordPayload gradStudentRecordPayload = GradStudentRecordPayload.builder() + .exception(ex) + .build(); + try { + return JsonUtil.getJsonStringFromObject(gradStudentRecordPayload); + } catch (JsonProcessingException exc) { + log.error("Error while serializing error response", exc); + return "{\"studentID\": \"\", \"program\": \"\", \"programCompletionDate\": \"\", \"schoolOfRecord\": \"\", \"studentStatusCode\": \"\", \"graduated\": \"\", \"exception\": \"JSON Parsing exception\"}"; + } + } +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dc/GradStudentRecordPayload.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dc/GradStudentRecordPayload.java new file mode 100644 index 00000000..256b477e --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dc/GradStudentRecordPayload.java @@ -0,0 +1,18 @@ +package ca.bc.gov.educ.api.gradstudent.model.dc; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class GradStudentRecordPayload { + + private String studentID; + private String exception; + private String program; + private String programCompletionDate; + private String schoolOfRecord; + private String studentStatusCode; + private String graduated; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/CommonSchool.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/CommonSchool.java deleted file mode 100644 index 1f7e7428..00000000 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/CommonSchool.java +++ /dev/null @@ -1,269 +0,0 @@ -package ca.bc.gov.educ.api.gradstudent.model.dto; - -import lombok.Data; -import org.springframework.stereotype.Component; - -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; - -@Data -@Component -public class CommonSchool { - - /** - * The constant serialVersionUID. - */ - private static final long serialVersionUID = 1L; - - @Size(max = 3) - @NotNull(message = "distNo can not be null.") - private String distNo; - - @Size(max = 5) - @NotNull(message = "schlNo can not be null.") - private String schlNo; - - @Size(max = 40) - private String scAddressLine1; - - @Size(max = 40) - private String scAddressLine2; - - @Size(max = 30) - private String scCity; - - @Size(max = 2) - private String scProvinceCode; - - @Size(max = 3) - private String scCountryCode; - - @Size(max = 6) - private String scPostalCode; - - @Size(max = 10) - private String scFaxNumber; - - @Size(max = 10) - private String scPhoneNumber; - - @Size(max = 100) - private String scEMailId; - - @Size(max = 2) - private String facilityTypeCode; - - @Size(max = 40) - private String schoolName; - - @Size(max = 2) - private String schoolTypeCode; - - @Size(max = 3) - private String schoolOrganizationCode; - - @Size(max = 2) - private String schoolCategoryCode; - - @Size(max = 25) - private String prGivenName; - - @Size(max = 25) - private String prSurname; - - @Size(max = 25) - private String prMiddleName; - - @Size(max = 2) - private String prTitleCode; - - private Long numberOfDivisions; - - private Long numberOfSecFteTeachers; - - private Long numberOfElmFteTeachers; - - private Long ttblElemInstrMinutes; - - @Size(max = 1) - private String schoolStatusCode; - - private Long enrolHeadcount1523; - - private Long enrolHeadcount1701; - - @Size(max = 1) - private String grade01Ind; - - @Size(max = 1) - private String grade29Ind; - - @Size(max = 1) - private String grade04Ind; - - @Size(max = 1) - private String grade05Ind; - - @Size(max = 1) - private String grade06Ind; - - @Size(max = 1) - private String grade07Ind; - - @Size(max = 1) - private String grade08Ind; - - @Size(max = 1) - private String grade09Ind; - - @Size(max = 1) - private String grade10Ind; - - @Size(max = 1) - private String grade11Ind; - - @Size(max = 1) - private String grade12Ind; - - @Size(max = 1) - private String grade79Ind; - - @Size(max = 1) - private String grade89Ind; - - @Size(max = 8) - private String openedDate; - - @Size(max = 8) - private String closedDate; - - @Size(max = 3) - private String authNumber; - - private Long createDate; - - private Long createTime; - - @Size(max = 12) - private String createUsername; - - private Long editDate; - - private Long editTime; - - @Size(max = 12) - private String editUsername; - - private Long elemTeachersHc; - - private Long secTeachersHc; - - @Size(max = 1) - private String gradeKhInd; - - @Size(max = 1) - private String gradeKfInd; - - @Size(max = 1) - private String grade02Ind; - - @Size(max = 1) - private String grade03Ind; - - @Size(max = 1) - private String gradeEuInd; - - @Size(max = 1) - private String gradeSuInd; - - @Size(max = 1) - private String gradeHsInd; - - @Size(max = 4) - private String contedFundFlag; - - private Long elemFteClassroom; - - private Long elemFteSupport; - - private Long elemFteAdmin; - - private Long secFteClassroom; - - private Long secFteSupport; - - private Long secFteAdmin; - - @Size(max = 40) - private String physAddressLine1; - - @Size(max = 40) - private String physAddressLine2; - - @Size(max = 30) - private String physCity; - - @Size(max = 2) - private String physProvinceCode; - - @Size(max = 3) - private String physCountryCode; - - @Size(max = 6) - private String physPostalCode; - - private Long educMethodClassCnt; - - private Long educMethodDelCnt; - - private Long educMethodBothCnt; - - @Size(max = 3) - private String newDistno; - - @Size(max = 5) - private String newSchlno; - - private String dateOpened; - - private String dateClosed; - - private Long assetNumber; - - @Size(max = 12) - private String assetAssignedBy; - - private String assetAssignedDate; - - @Size(max = 12) - private String assetChangedBy; - - private String assetChangedDate; - - @Size(max = 1) - private String restrictFunding; - - @Size(max = 1) - private String gradeGaInd; - - @Size(max = 1) - private String nlcEarlyLearningFlag; - - @Size(max = 1) - private String nlcAfterSchoolProgramFlag; - - @Size(max = 1) - private String nlcContinuingEdFlag; - - @Size(max = 1) - private String nlcSeniorsFlag; - - @Size(max = 1) - private String nlcSportAndRecFlag; - - @Size(max = 1) - private String nlcCommunityUseFlag; - - @Size(max = 1) - private String nlcIntegratedServicesFlag; -} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GradSearchStudent.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GradSearchStudent.java index 5a7a14fd..f88ca279 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GradSearchStudent.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GradSearchStudent.java @@ -42,6 +42,7 @@ public class GradSearchStudent { private String trueStudentID; private String program; private String schoolOfRecord; + private String schoolOfRecordId; private String schoolOfRecordName; private String schoolOfRecordindependentAffiliation; private String studentGrade; diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GraduationStudentRecord.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GraduationStudentRecord.java index f5061a06..8715ec35 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GraduationStudentRecord.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GraduationStudentRecord.java @@ -25,12 +25,14 @@ public class GraduationStudentRecord extends BaseModel { private String honoursStanding; private String recalculateGradStatus; private String schoolOfRecord; + private UUID schoolOfRecordId; private String schoolName; private String studentGrade; private String studentStatus; private String studentStatusName; private UUID studentID; private String schoolAtGrad; + private UUID schoolAtGradId; private String schoolAtGradName; private String recalculateProjectedGrad; private Long batchId; diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GraduationStudentRecordHistory.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GraduationStudentRecordHistory.java index 33c10bd2..fe690f4a 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GraduationStudentRecordHistory.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GraduationStudentRecordHistory.java @@ -27,10 +27,12 @@ public class GraduationStudentRecordHistory extends BaseModel{ private String honoursStanding; private String recalculateGradStatus; private String schoolOfRecord; + private UUID schoolOfRecordId; private String studentGrade; private String studentStatus; private UUID studentID; private String schoolAtGrad; + private UUID schoolAtGradId; private String recalculateProjectedGrad; private Long batchId; private String consumerEducationRequirementMet; diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/ReportGradStudentData.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/ReportGradStudentData.java index 35388e75..27f5f506 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/ReportGradStudentData.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/ReportGradStudentData.java @@ -15,6 +15,8 @@ public class ReportGradStudentData implements Serializable { private UUID graduationStudentRecordId; private String mincode; private String mincodeAtGrad; + private String schoolOfRecordId; + private String schoolAtGradId; private String distcode; private String distcodeAtGrad; private String pen; diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/School.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/School.java index bda07bf2..bb97dd3e 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/School.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/School.java @@ -8,23 +8,20 @@ public class School { private String minCode; + private String schoolId; private String schoolName; private String districtName; private String transcriptEligibility; private String certificateEligibility; - private String independentDesignation; - private String mailerType; - private String address1; + private String address1; private String address2; private String city; private String provCode; - private String provinceName; - private String countryCode; - private String countryName; + private String countryCode; private String postal; - private String independentAffiliation; private String openFlag; - private String signatureDistrict; + private String schoolCategoryCode; + private String schoolCategoryLegacyCode; public String getSchoolName() { return schoolName != null ? schoolName.trim(): null; @@ -45,14 +42,6 @@ public String getAddress2() { public String getCity() { return city != null ? city.trim(): null; } - - public String getProvinceName() { - return provinceName != null ? provinceName.trim(): null; - } - - public String getCountryName() { - return countryName != null ? countryName.trim(): null; - } public String getPostal() { return postal != null ? postal.trim(): null; @@ -60,11 +49,10 @@ public String getPostal() { @Override public String toString() { - return "School [minCode=" + minCode + ", schoolName=" + schoolName + ", districtName=" + districtName - + ", transcriptEligibility=" + transcriptEligibility + ", certificateEligibility=" - + certificateEligibility + ", independentDesignation=" + independentDesignation + ", mailerType=" - + mailerType + ", address1=" + address1 + ", address2=" + address2 + ", city=" + city + ", provCode=" - + provCode + ", provinceName=" + provinceName + ", countryCode=" + countryCode + ", countryName=" - + countryName + ", postal=" + postal + ", independentAffiliation=" + independentAffiliation +"]"; - } + return "School [minCode=" + minCode + ", schoolId=" + schoolId + ", schoolCategoryCode=" + schoolCategoryCode + ", schoolCategoryLegacyCode=" + schoolCategoryLegacyCode + + ", schoolName=" + schoolName + ", districtName=" + districtName + ", transcriptEligibility=" + transcriptEligibility + ", certificateEligibility=" + certificateEligibility + + ", address1=" + address1 + ", address2=" + address2 + ", city=" + city + ", provCode=" + provCode + ", countryCode=" + countryCode + ", postal=" + postal + ", openFlag=" + openFlag + + "]"; + } + } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/messaging/GradStudentRecord.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/messaging/GradStudentRecord.java new file mode 100644 index 00000000..30b8a805 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/messaging/GradStudentRecord.java @@ -0,0 +1,23 @@ +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 GradStudentRecord { + + private UUID studentID; + private String program; + private Date programCompletionDate; + private String schoolOfRecord; + private String studentStatusCode; + private String studentProjectedGradData; + private Boolean graduated; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordEntity.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordEntity.java index c429104b..1213c194 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordEntity.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordEntity.java @@ -82,7 +82,7 @@ public GraduationStudentRecordEntity() { private UUID schoolOfRecordId; @Column(name = "SCHOOL_AT_GRADUATION_ID", nullable = true) - private UUID schoolAtGraduationId; + private UUID schoolAtGradId; @Transient private String legalFirstName; diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordHistoryEntity.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordHistoryEntity.java index a7b4c323..33a478b5 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordHistoryEntity.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordHistoryEntity.java @@ -79,7 +79,7 @@ public class GraduationStudentRecordHistoryEntity extends BaseEntity { private UUID schoolOfRecordId; @Column(name = "SCHOOL_AT_GRADUATION_ID", nullable = true) - private UUID schoolAtGraduationId; + private UUID schoolAtGradId; //@Lob //@Column(name = "STUDENT_PROJECTED_GRAD_DATA", columnDefinition="CLOB") diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordView.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordView.java index 6e19ec77..ea789e7c 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordView.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/entity/GraduationStudentRecordView.java @@ -23,7 +23,7 @@ public interface GraduationStudentRecordView { public Date getAdultStartDate(); public String getStudentProjectedGradData() ; public UUID getSchoolOfRecordId(); - public UUID getSchoolAtGraduationId(); + public UUID getSchoolAtGradId(); public LocalDateTime getCreateDate(); public LocalDateTime getUpdateDate(); } \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionService.java index 1d321e6f..f5ceee17 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionService.java @@ -311,6 +311,10 @@ private void populate(OngoingUpdateFieldDTO field, GraduationStudentRecordEntity log.info(ONGOING_UPDATE_FIELD_STR, field, targetObject.getSchoolOfRecord()); targetObject.setSchoolOfRecord(getStringValue(field.getValue())); } + case SCHOOL_OF_RECORD_ID -> { + log.info(ONGOING_UPDATE_FIELD_STR, field, targetObject.getSchoolOfRecordId()); + targetObject.setSchoolOfRecordId(getGuidValue(field.getValue())); + } case GRAD_PROGRAM -> { log.info(ONGOING_UPDATE_FIELD_STR, field, targetObject.getProgram()); targetObject.setProgram(getStringValue(field.getValue())); @@ -357,6 +361,11 @@ private String getStringValue(Object value) { return null; } + private UUID getGuidValue(Object value) { + String strGuid = getStringValue(value); + return strGuid != null? UUID.fromString(strGuid) : null; + } + private StudentOptionalProgramEntity handleExistingOptionalProgram(StudentOptionalProgramRequestDTO studentOptionalProgramReq, StudentOptionalProgramEntity gradEntity) { if (studentOptionalProgramReq.getStudentOptionalProgramData() != null) { gradEntity.setStudentOptionalProgramData(studentOptionalProgramReq.getStudentOptionalProgramData()); diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentService.java index c7c15d17..3d736f16 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentService.java @@ -1,12 +1,16 @@ package ca.bc.gov.educ.api.gradstudent.service; +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.GradStudentRecord; 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; import ca.bc.gov.educ.api.gradstudent.util.ThreadLocalStateUtil; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.resilience4j.retry.annotation.Retry; import jakarta.transaction.Transactional; @@ -50,6 +54,7 @@ public class GradStudentService { private static final String PAGE_NUMBER="pageNumber"; private static final String PAGE_SIZE="pageSize"; private static final String SEARCH_CRITERIA_LIST = "searchCriteriaList"; + private static final String STD_NOT_FOUND_MSG = "Student with ID: %s not found"; final EducGradStudentApiConstants constants; final WebClient webClient; @@ -298,6 +303,7 @@ private GradSearchStudent populateGradStudent(GraduationStudentRecordView gradRe GradSearchStudent gradStu = new GradSearchStudent(); BeanUtils.copyProperties(gradRecord, gradStu); gradStu.setStudentID(gradRecord.getStudentID().toString()); + gradStu.setSchoolOfRecordId(gradRecord.getSchoolOfRecordId() != null? gradRecord.getSchoolOfRecordId().toString() : null); return populateGradStudent(gradStu, accessToken); } @@ -311,7 +317,7 @@ private GradSearchStudent populateGradStudent(GradSearchStudent gradStu, String if(studentPen != null) { BeanUtils.copyProperties(studentPen, gradStu); } - School school = webClient.get().uri(String.format(constants.getSchoolByMincodeUrl(), gradStu.getSchoolOfRecord())) + School school = webClient.get().uri(String.format(constants.getSchoolClobBySchoolIdUrl(), gradStu.getSchoolOfRecordId())) .headers(h -> { h.setBearerAuth(accessToken); h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID()); @@ -319,7 +325,6 @@ private GradSearchStudent populateGradStudent(GradSearchStudent gradStu, String .retrieve().bodyToMono(School.class).block(); if (school != null) { gradStu.setSchoolOfRecordName(school.getSchoolName()); - gradStu.setSchoolOfRecordindependentAffiliation(school.getIndependentAffiliation()); } return gradStu; } @@ -334,9 +339,10 @@ private GradSearchStudent populateGradSearchStudent(Student student, String acce gradStu.setStudentGrade(gradObj.getStudentGrade()); gradStu.setStudentStatus(gradObj.getStudentStatus()); gradStu.setSchoolOfRecord(gradObj.getSchoolOfRecord()); + gradStu.setSchoolOfRecordId(gradObj.getSchoolOfRecordId() != null? gradObj.getSchoolOfRecordId().toString() : null); gradStu.setStudentCitizenship(gradObj.getStudentCitizenship()); - School school = webClient.get().uri(String.format(constants.getSchoolByMincodeUrl(), gradStu.getSchoolOfRecord())) + School school = webClient.get().uri(String.format(constants.getSchoolClobBySchoolIdUrl(), gradStu.getSchoolOfRecordId())) .headers(h -> { h.setBearerAuth(accessToken); h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID()); @@ -346,7 +352,6 @@ private GradSearchStudent populateGradSearchStudent(Student student, String acce gradStu.setTranscriptEligibility(school.getTranscriptEligibility()); gradStu.setCertificateEligibility(school.getCertificateEligibility()); gradStu.setSchoolOfRecordName(school.getSchoolName()); - gradStu.setSchoolOfRecordindependentAffiliation(school.getIndependentAffiliation()); } } return gradStu; @@ -419,4 +424,32 @@ public List getStudentIDsBySearchCriteriaOrAll(StudentSearchRequest search } return result; } + + /** + * Returns a condensed version of GraduationStudentRecord for GDC + * @param studentID + * @return + * @throws EntityNotFoundException + */ + public GradStudentRecord getGraduationStudentRecord(UUID studentID) { + GradStudentRecord response = graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class); + if (response != null) { + response.setGraduated(parseGraduationStatus(response.getStudentProjectedGradData())); + return response; + } + throw new EntityNotFoundException(String.format(STD_NOT_FOUND_MSG, studentID)); + } + + public Boolean parseGraduationStatus(String studentProjectedGradData) { + if (studentProjectedGradData == null || studentProjectedGradData.isEmpty()) { + return false; + } + try { + ObjectMapper mapper = new ObjectMapper(); + JsonNode jsonNode = mapper.readTree(studentProjectedGradData); + return jsonNode.get("graduated").asBoolean(); + } catch (JsonProcessingException e) { + return false; + } + } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java index 686df60d..2e9a3f92 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusService.java @@ -141,15 +141,15 @@ public GraduationStudentRecord getGraduationStatus(UUID studentID, String access if (gradStatus.getProgram() != null) { gradStatus.setProgramName(getProgramName(gradStatus.getProgram(), accessToken)); } - if (gradStatus.getSchoolOfRecord() != null) - gradStatus.setSchoolName(getSchoolName(gradStatus.getSchoolOfRecord(), accessToken)); + if (gradStatus.getSchoolOfRecordId() != null) + gradStatus.setSchoolName(getSchoolName(gradStatus.getSchoolOfRecordId().toString(), accessToken)); if (gradStatus.getStudentStatus() != null) { Optional statusEntity = studentStatusRepository.findById(StringUtils.toRootUpperCase(gradStatus.getStudentStatus())); statusEntity.ifPresent(studentStatusEntity -> gradStatus.setStudentStatusName(studentStatusEntity.getLabel())); } - if (gradStatus.getSchoolAtGrad() != null) - gradStatus.setSchoolAtGradName(getSchoolName(gradStatus.getSchoolAtGrad(), accessToken)); + if (gradStatus.getSchoolAtGradId() != null) + gradStatus.setSchoolAtGradName(getSchoolName(gradStatus.getSchoolAtGradId().toString(), accessToken)); List studentCareerProgramEntities = gradStudentCareerProgramRepository.findByStudentID(studentID); gradStatus.setCareerPrograms(gradStudentCareerProgramTransformer.transformToDTO(studentCareerProgramEntities)); @@ -246,6 +246,7 @@ public Pair updateGraduationStatus(UUI sourceObject.setHonoursStanding(null); sourceObject.setGpa(null); sourceObject.setSchoolAtGrad(null); + sourceObject.setSchoolAtGradId(null); archiveStudentAchievements(sourceObject.getStudentID(),accessToken); } else { deleteStudentAchievements(sourceObject.getStudentID(), accessToken); @@ -362,18 +363,14 @@ public GraduationStudentRecordSearchResult searchGraduationStudentRecords(final } if(searchRequest.getDistricts() != null && !searchRequest.getDistricts().isEmpty()) { - List schools = new ArrayList<>(getSchools(accessToken)); - for(Iterator it = schools.iterator(); it.hasNext();) { - CommonSchool school = it.next(); - if(!searchRequest.getDistricts().contains(school.getDistNo())) { + List schools = new ArrayList<>(getSchoolsByDistricts(searchRequest.getDistricts(), accessToken)); + for(Iterator it = schools.iterator(); it.hasNext();) { + School school = it.next(); + List schoolCategoryCodes = searchRequest.getSchoolCategoryCodes().stream().filter(StringUtils::isNotBlank).toList(); + if(!schoolCategoryCodes.isEmpty() && !schoolCategoryCodes.contains(school.getSchoolCategoryLegacyCode())) { it.remove(); } else { - List schoolCategoryCodes = searchRequest.getSchoolCategoryCodes().stream().filter(StringUtils::isNotBlank).toList(); - if(!schoolCategoryCodes.isEmpty() && !schoolCategoryCodes.contains(school.getSchoolCategoryCode())) { - it.remove(); - } else { - searchRequest.getSchoolOfRecords().add(school.getDistNo() + school.getSchlNo()); - } + searchRequest.getSchoolOfRecords().add(school.getMinCode()); } } } @@ -445,12 +442,7 @@ public StudentDemographic getStudentDemographics(String pen, String accessToken) } } - CommonSchool commonSchool = getCommonSchool(accessToken, gradSearchStudent.getSchoolOfRecord()); - if(commonSchool == null) { - validation.addErrorAndStop("Common School with mincode %s not found", gradSearchStudent.getMincode()); - } - - School school = getSchool(gradSearchStudent.getSchoolOfRecord(), accessToken); + School school = getSchool(gradSearchStudent.getSchoolOfRecordId(), accessToken); if(school == null) { validation.addErrorAndStop("School with mincode %s not found", gradSearchStudent.getMincode()); } @@ -478,7 +470,6 @@ public StudentDemographic getStudentDemographics(String pen, String accessToken) break; } } - assert commonSchool != null; assert school != null; return StudentDemographic.builder() .studentID(gradSearchStudent.getStudentID()) @@ -510,8 +501,8 @@ public StudentDemographic getStudentDemographics(String pen, String accessToken) .sccDate(sccDate) .transcriptEligibility(gradSearchStudent.getTranscriptEligibility()) .mincode(school.getMinCode()) - .schoolCategory(commonSchool.getSchoolCategoryCode()) - .schoolType("02".equalsIgnoreCase(commonSchool.getSchoolCategoryCode()) ? "02" : "") + .schoolCategory(school.getSchoolCategoryLegacyCode()) + .schoolType("02".equalsIgnoreCase(school.getSchoolCategoryLegacyCode()) ? "02" : "") .schoolName(school.getSchoolName()) .formerStudent(formerStudent) .build(); @@ -527,28 +518,28 @@ private List getGradStudentCertificates(String studentI }).block(); } - public List getSchools(String accessToken) { - return webClient.get().uri((constants.getSchoolsSchoolApiUrl())) + public List getSchoolsByDistricts(List districts, String accessToken) { + List results = new ArrayList<>(); + for (String distNo : districts) { + results.addAll(getSchoolsByDistrictNumber(distNo, accessToken)); + } + return results; + } + + public List getSchoolsByDistrictNumber(String distNo, String accessToken) { + return webClient.get() + .uri(String.format(constants.getSchoolsByDistrictNumberUrl(), distNo)) .headers(h -> { h.setBearerAuth(accessToken); h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID()); }) - .retrieve().bodyToMono(new ParameterizedTypeReference>() { + .retrieve().bodyToMono(new ParameterizedTypeReference>() { }).block(); } - public CommonSchool getCommonSchool(String accessToken, String mincode) { - return webClient.get().uri(String.format(constants.getSchoolByMincodeSchoolApiUrl(), mincode)) - .headers(h -> { - h.setBearerAuth(accessToken); - h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID()); - }) - .retrieve().bodyToMono(CommonSchool.class).block(); - } - - private School getSchool(String minCode, String accessToken) { + private School getSchool(String schoolId, String accessToken) { return webClient.get() - .uri(String.format(constants.getSchoolByMincodeUrl(), minCode)) + .uri(String.format(constants.getSchoolClobBySchoolIdUrl(), schoolId)) .headers(h -> { h.setBearerAuth(accessToken); h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID()); @@ -558,8 +549,8 @@ private School getSchool(String minCode, String accessToken) { .block(); } - private String getSchoolName(String minCode, String accessToken) { - School schObj = getSchool(minCode, accessToken); + private String getSchoolName(String schoolId, String accessToken) { + School schObj = getSchool(schoolId, accessToken); if (schObj != null) return schObj.getSchoolName(); else @@ -649,9 +640,9 @@ private void validateProgram(GraduationStudentRecordEntity sourceEntity, String } } - private void validateSchool(String minCode, String accessToken) { + private void validateSchool(UUID schoolId, String accessToken) { School schObj = webClient.get() - .uri(String.format(constants.getSchoolByMincodeUrl(), minCode)) + .uri(String.format(constants.getSchoolClobBySchoolIdUrl(), schoolId)) .headers(h -> { h.setBearerAuth(accessToken); h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID()); @@ -661,10 +652,10 @@ private void validateSchool(String minCode, String accessToken) { .block(); if (schObj == null) { validation.addError( - String.format("Invalid School entered, School [%s] does not exist on the School table", minCode)); + String.format("Invalid School entered, SchoolId [%s] does not exist in institute.", schoolId)); } else { if (schObj.getOpenFlag().equalsIgnoreCase("N")) { - validation.addWarning(String.format("This School [%s] is Closed", minCode)); + validation.addWarning(String.format("This School [%s] is Closed", schoolId)); } } } @@ -757,14 +748,14 @@ private ValidateDataResult validateData(GraduationStudentRecordEntity sourceEnti hasDataChanged.recalculateAll(); } - if (sourceEntity.getSchoolOfRecord() != null && !sourceEntity.getSchoolOfRecord().equalsIgnoreCase(existingEntity.getSchoolOfRecord())) { + if (sourceEntity.getSchoolOfRecordId() != null && !sourceEntity.getSchoolOfRecordId().equals(existingEntity.getSchoolOfRecordId())) { hasDataChanged.recalculateAll(); - validateSchool(sourceEntity.getSchoolOfRecord(), accessToken); + validateSchool(sourceEntity.getSchoolOfRecordId(), accessToken); } - if (sourceEntity.getSchoolAtGrad() != null && !sourceEntity.getSchoolAtGrad().equalsIgnoreCase(existingEntity.getSchoolAtGrad())) { + if (sourceEntity.getSchoolAtGradId() != null && !sourceEntity.getSchoolAtGradId().equals(existingEntity.getSchoolAtGradId())) { hasDataChanged.recalculateAll(); - validateSchool(sourceEntity.getSchoolAtGrad(), accessToken); + validateSchool(sourceEntity.getSchoolAtGradId(), accessToken); } if ((sourceEntity.getStudentGrade() != null && !sourceEntity.getStudentGrade().equalsIgnoreCase(existingEntity.getStudentGrade()))) { @@ -1111,6 +1102,7 @@ public Pair undoCompletionStudent(UUID gradEntity.setHonoursStanding(null); gradEntity.setGpa(null); gradEntity.setSchoolAtGrad(null); + gradEntity.setSchoolAtGradId(null); gradEntity.setUpdateUser(null); gradEntity = graduationStatusRepository.save(gradEntity); historyService.createStudentHistory(gradEntity, USER_UNDO_CMPL); @@ -1223,6 +1215,7 @@ public boolean restoreGradStudentRecord(UUID studentID,boolean isGraduated) { gradEnity.setHonoursStanding(null); gradEnity.setGpa(null); gradEnity.setSchoolAtGrad(null); + gradEnity.setSchoolAtGradId(null); } graduationStatusRepository.save(gradEnity); return true; diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java index a930ac1f..d0bb9a53 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java @@ -140,8 +140,8 @@ public class EducGradStudentApiConstants { private String connectionName; //Endpoints - @Value("${endpoint.grad-trax-api.school-by-min-code.url}") - private String schoolByMincodeUrl; + @Value("${endpoint.grad-trax-api.school-clob-by-school-id.url}") + private String schoolClobBySchoolIdUrl; @Value("${endpoint.grad-trax-api.district-by-district-code.url}") private String districtByDistrictCodeUrl; @@ -186,11 +186,8 @@ public class EducGradStudentApiConstants { @Value("${endpoint.grad-graduation-report-api.archive-student-achievement.url}") private String archiveStudentAchievements; - @Value("${endpoint.grad-trax-api.commonschool-by-mincode.url}") - private String schoolByMincodeSchoolApiUrl; - - @Value("${endpoint.grad-trax-api.all-commonschools.url}") - private String schoolsSchoolApiUrl; + @Value("${endpoint.grad-trax-api.schools-by-district-code.url}") + private String schoolsByDistrictNumberUrl; // Splunk LogHelper Enabled @Value("${splunk.log-helper.enabled}") diff --git a/api/src/main/resources/application.yaml b/api/src/main/resources/application.yaml index 43748528..e8f702d5 100644 --- a/api/src/main/resources/application.yaml +++ b/api/src/main/resources/application.yaml @@ -155,14 +155,12 @@ resilience4j.retry: #Endpoint properties endpoint: grad-trax-api: - all-commonschools: - url: ${GRAD_TRAX_API}api/v1/trax/school/common - school-by-min-code: - url: ${GRAD_TRAX_API}api/v1/trax/school/%s + schools-by-district-code: + url: ${GRAD_TRAX_API}api/v2/trax/schools-by-district/%s + school-clob-by-school-id: + url: ${GRAD_TRAX_API}api/v2/trax/school-clob/%s district-by-district-code: - url: ${GRAD_TRAX_API}api/v1/trax/district/%s - commonschool-by-mincode: - url: ${GRAD_TRAX_API}api/v1/trax/school/common/%s + url: ${GRAD_TRAX_API}api/v2/trax/district?distNo=%s grad-program-api: optional_program_name_by_optional_program_id: diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/CommonServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/CommonServiceTest.java index 97bf0306..78036f17 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/CommonServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/CommonServiceTest.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.gradstudent.service; +import ca.bc.gov.educ.api.gradstudent.controller.BaseIntegrationTest; import ca.bc.gov.educ.api.gradstudent.messaging.NatsConnection; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStatusSubscriber; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Publisher; @@ -34,8 +35,7 @@ @RunWith(SpringRunner.class) @SpringBootTest -@ActiveProfiles("test") -public class CommonServiceTest { +public class CommonServiceTest extends BaseIntegrationTest { @Autowired EducGradStudentApiConstants constants; @Autowired CommonService commonService; diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionServiceTest.java index 9e11bc9a..9b51cf96 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/DataConversionServiceTest.java @@ -3,6 +3,7 @@ import ca.bc.gov.educ.api.gradstudent.constant.FieldName; import ca.bc.gov.educ.api.gradstudent.constant.FieldType; import ca.bc.gov.educ.api.gradstudent.constant.TraxEventType; +import ca.bc.gov.educ.api.gradstudent.controller.BaseIntegrationTest; import ca.bc.gov.educ.api.gradstudent.messaging.NatsConnection; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStatusSubscriber; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Publisher; @@ -39,8 +40,7 @@ @RunWith(SpringRunner.class) @SpringBootTest -@ActiveProfiles("test") -public class DataConversionServiceTest { +public class DataConversionServiceTest extends BaseIntegrationTest { @Autowired EducGradStudentApiConstants constants; @Autowired diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/EdwSnapshotServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/EdwSnapshotServiceTest.java index ea5adf7d..8fbb3655 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/EdwSnapshotServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/EdwSnapshotServiceTest.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.gradstudent.service; +import ca.bc.gov.educ.api.gradstudent.controller.BaseIntegrationTest; import ca.bc.gov.educ.api.gradstudent.messaging.NatsConnection; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStatusSubscriber; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Publisher; @@ -31,8 +32,7 @@ @RunWith(SpringRunner.class) @SpringBootTest -@ActiveProfiles("test") -public class EdwSnapshotServiceTest { +public class EdwSnapshotServiceTest extends BaseIntegrationTest { @Autowired EdwSnapshotService edwSnapshotService; diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java index 8ee2f046..7d1829ea 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java @@ -1,10 +1,13 @@ package ca.bc.gov.educ.api.gradstudent.service; +import ca.bc.gov.educ.api.gradstudent.controller.BaseIntegrationTest; +import ca.bc.gov.educ.api.gradstudent.exception.EntityNotFoundException; import ca.bc.gov.educ.api.gradstudent.messaging.NatsConnection; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStatusSubscriber; 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.GradStudentRecord; 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; @@ -41,6 +44,7 @@ import java.util.function.Function; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -48,8 +52,7 @@ @RunWith(SpringRunner.class) @SpringBootTest -@ActiveProfiles("test") -public class GradStudentServiceTest { +public class GradStudentServiceTest extends BaseIntegrationTest { @Autowired EducGradStudentApiConstants constants; @@ -153,11 +156,12 @@ public void testGetStudentFromStudentAPI() { // School final School school = new School(); + school.setSchoolId(UUID.randomUUID().toString()); school.setMinCode(mincode); school.setSchoolName(schoolName); when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); - when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolByMincodeUrl(),mincode))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolClobBySchoolIdUrl(),school.getSchoolId()))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(School.class)).thenReturn(Mono.just(school)); @@ -203,11 +207,12 @@ public void testGetGRADStudents() { // School final School school = new School(); + school.setSchoolId(UUID.randomUUID().toString()); school.setMinCode(mincode); school.setSchoolName(schoolName); when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); - when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolByMincodeUrl(),mincode))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolClobBySchoolIdUrl(),school.getSchoolId()))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(School.class)).thenReturn(Mono.just(school)); @@ -301,11 +306,12 @@ public void testGetStudentFromStudentAPIGradOnly() { // School final School school = new School(); + school.setSchoolId(UUID.randomUUID().toString()); school.setMinCode(mincode); school.setSchoolName(schoolName); when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); - when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolByMincodeUrl(),mincode))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolClobBySchoolIdUrl(),school.getSchoolId()))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(School.class)).thenReturn(Mono.just(school)); @@ -428,7 +434,7 @@ public UUID getSchoolOfRecordId() { } @Override - public UUID getSchoolAtGraduationId() { + public UUID getSchoolAtGradId() { return null; } @@ -519,16 +525,18 @@ public void testStudentDemographics() { when(this.graduationStatusRepository.findById(studentID)).thenReturn(Optional.of(graduationStatusEntity)); - CommonSchool commonSchool = new CommonSchool(); - commonSchool.setSchlNo(mincode); - commonSchool.setSchoolName(schoolName); - commonSchool.setSchoolCategoryCode("02"); + School school = new School(); + school.setSchoolId(UUID.randomUUID().toString()); + school.setMinCode(mincode); + school.setSchoolName(schoolName); + school.setSchoolCategoryLegacyCode("02"); + school.setSchoolCategoryCode("INDEPEN"); when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); - when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolByMincodeSchoolApiUrl(),mincode))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolClobBySchoolIdUrl(),school.getSchoolId()))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); - when(this.responseMock.bodyToMono(CommonSchool.class)).thenReturn(Mono.just(commonSchool)); + when(this.responseMock.bodyToMono(School.class)).thenReturn(Mono.just(school)); GradStudentCertificates certificate = new GradStudentCertificates(); certificate.setStudentID(studentID); @@ -611,11 +619,12 @@ public void testGetStudentByPenFromStudentAPI() { // School final School school = new School(); + school.setSchoolId(UUID.randomUUID().toString()); school.setMinCode(mincode); school.setSchoolName(schoolName); when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); - when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolByMincodeUrl(),mincode))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolClobBySchoolIdUrl(),school.getSchoolId()))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(School.class)).thenReturn(Mono.just(school)); @@ -703,11 +712,12 @@ public void testGetStudentByStudentIDFromStudentAPI() { // School final School school = new School(); + school.setSchoolId(UUID.randomUUID().toString()); school.setMinCode(mincode); school.setSchoolName(schoolName); when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); - when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolByMincodeUrl(),mincode))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolClobBySchoolIdUrl(),school.getSchoolId()))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(School.class)).thenReturn(Mono.just(school)); @@ -847,6 +857,114 @@ public void testGetStudentIDsBySearchCriterias() { assertThat(results).isNotEmpty(); } + @Test + public void testGetGraduationStudentRecord_GivenValidProgramCompletionDate_ExpectTrue() throws EntityNotFoundException { + UUID studentID = UUID.randomUUID(); + GraduationStudentRecordEntity graduationStudentRecordEntity = new GraduationStudentRecordEntity(); + graduationStudentRecordEntity.setProgramCompletionDate(new java.util.Date()); + when(graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class)).thenReturn(new GradStudentRecord(studentID, "2018-EN", new java.util.Date(), "schoolOfRecord", "studentStatusCode", "{\"nonGradReasons\":null,\"graduated\":true}", Boolean.TRUE)); + GradStudentRecord result = gradStudentService.getGraduationStudentRecord(studentID); + assertNotNull(result); + } + + @Test + public void testGetGraduationStudentRecord_givenNotFound_ExpectEntityNotFoundExcetpion() { + UUID studentID = UUID.randomUUID(); + when(graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class)).thenReturn(null); + assertThrows(EntityNotFoundException.class, () -> { + gradStudentService.getGraduationStudentRecord(studentID); + }); + } + + @Test + public void testGetGraduationStudentRecord_GivenGraduatedTrue_ExpectGraduated() { + UUID studentID = UUID.randomUUID(); + GradStudentRecord mockRecord = new GradStudentRecord( + studentID, + "2018-EN", + new java.util.Date(), + "schoolOfRecord", + "studentStatusCode", + "{\"nonGradReasons\":null,\"graduated\":true}", + true + ); + when(graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class)).thenReturn(mockRecord); + + GradStudentRecord result = gradStudentService.getGraduationStudentRecord(studentID); + + assertNotNull(result); + assertTrue(result.getGraduated()); + } + + @Test + public void testGetGraduationStudentRecord_GivenGraduatedFalse_ExpectNotGraduated() { + UUID studentID = UUID.randomUUID(); + GradStudentRecord mockRecord = new GradStudentRecord( + studentID, + "2018-EN", + new java.util.Date(), + "schoolOfRecord", + "studentStatusCode", + "{\"nonGradReasons\":[],\"graduated\":false}", + false + ); + when(graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class)).thenReturn(mockRecord); + + GradStudentRecord result = gradStudentService.getGraduationStudentRecord(studentID); + + assertNotNull(result); + assertFalse(result.getGraduated()); + } + + @Test + public void testGetGraduationStudentRecord_GivenNullCLOBData_ExpectNotGraduated() { + UUID studentID = UUID.randomUUID(); + GradStudentRecord mockRecord = new GradStudentRecord( + studentID, + "2018-EN", + new java.util.Date(), + "schoolOfRecord", + "studentStatusCode", + null, + false + ); + when(graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class)).thenReturn(mockRecord); + + GradStudentRecord result = gradStudentService.getGraduationStudentRecord(studentID); + + assertNotNull(result); + assertFalse(result.getGraduated()); + } + + @Test + public void testGetGraduationStudentRecord_GivenRecordNotFound_ExpectEntityNotFoundException() { + UUID studentID = UUID.randomUUID(); + when(graduationStatusRepository.findByStudentID(studentID, GradStudentRecord.class)).thenReturn(null); + + assertThrows(EntityNotFoundException.class, () -> gradStudentService.getGraduationStudentRecord(studentID)); + } + + @Test + public void testParseGraduationStatus_GivenNullInput_ExpectFalse() { + String studentProjectedGradData = null; + Boolean result = gradStudentService.parseGraduationStatus(studentProjectedGradData); + assertFalse("Expected false for null input", result); + } + + @Test + public void testParseGraduationStatus_GivenEmptyInput_ExpectFalse() { + String studentProjectedGradData = ""; + Boolean result = gradStudentService.parseGraduationStatus(studentProjectedGradData); + assertFalse("Expected false for empty input", result); + } + + @Test + public void testParseGraduationStatus_GivenMalformedJson_ExpectFalse() { + String malformedJson = "{invalid-json}"; + Boolean result = gradStudentService.parseGraduationStatus(malformedJson); + assertFalse("Expected false for malformed JSON", result); + } + @SneakyThrows protected Object createDataObjectFromJson(String jsonPath, Class clazz) { String json = readFile(jsonPath); diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java index c70a33f2..96235e1e 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GraduationStatusServiceTest.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.gradstudent.service; +import ca.bc.gov.educ.api.gradstudent.controller.BaseIntegrationTest; import ca.bc.gov.educ.api.gradstudent.exception.EntityNotFoundException; import ca.bc.gov.educ.api.gradstudent.messaging.NatsConnection; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStatusSubscriber; @@ -50,8 +51,7 @@ @RunWith(SpringRunner.class) @SpringBootTest -@ActiveProfiles("test") -public class GraduationStatusServiceTest { +public class GraduationStatusServiceTest extends BaseIntegrationTest { @Autowired EducGradStudentApiConstants constants; @Autowired GraduationStatusService graduationStatusService; @@ -191,6 +191,7 @@ public void testGetGraduationStatusForAlgorithm() { public void testGetGraduationStatus() { // ID UUID studentID = UUID.randomUUID(); + UUID schoolId = UUID.randomUUID(); String mincode = "12345678"; GraduationStudentRecordEntity graduationStatusEntity = new GraduationStudentRecordEntity(); @@ -203,6 +204,8 @@ public void testGetGraduationStatus() { graduationStatusEntity.setSchoolAtGrad(mincode); graduationStatusEntity.setGpa("4"); graduationStatusEntity.setStudentStatus("A"); + graduationStatusEntity.setSchoolOfRecordId(schoolId); + graduationStatusEntity.setSchoolAtGradId(schoolId); StudentStatus studentStatus = new StudentStatus(); studentStatus.setCode("CUR"); @@ -213,6 +216,7 @@ public void testGetGraduationStatus() { program.setProgramName("Graduation Program 2018"); School school = new School(); + school.setSchoolId(schoolId.toString()); school.setMinCode(mincode); school.setSchoolName("Test School"); @@ -225,7 +229,7 @@ public void testGetGraduationStatus() { when(responseMock.bodyToMono(GradProgram.class)).thenReturn(Mono.just(program)); when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); - when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolByMincodeUrl(),mincode))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolClobBySchoolIdUrl(),school.getSchoolId()))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(School.class)).thenReturn(Mono.just(school)); @@ -724,6 +728,7 @@ public void testUpdateGraduationStatus_givenDifferentPrograms_when1950ProgramIsV assertThat(result.getStudentStatus()).isNull(); assertThat(result.getProgram()).isNull(); assertThat(result.getSchoolOfRecord()).isNull(); + assertThat(result.getSchoolOfRecordId()).isNull(); assertThat(result.getGpa()).isNull(); assertThat(result.getRecalculateGradStatus()).isNull(); @@ -784,6 +789,7 @@ public void testUpdateGraduationStatus_givenDifferentPrograms_whenProgramIsValid assertThat(result.getStudentStatus()).isNull(); assertThat(result.getProgram()).isNull(); assertThat(result.getSchoolOfRecord()).isNull(); + assertThat(result.getSchoolOfRecordId()).isNull(); assertThat(result.getGpa()).isNull(); assertThat(result.getRecalculateGradStatus()).isNull(); @@ -822,6 +828,7 @@ public void testUpdateGraduationStatus_givenDifferentSchoolOfRecords_whenSchoolI savedGraduationStatus.setProgramCompletionDate(graduationStatusEntity.getProgramCompletionDate()); School school = new School(); + school.setSchoolId(UUID.randomUUID().toString()); school.setMinCode(newMincode); school.setSchoolName("Test School"); school.setOpenFlag("Y"); @@ -830,7 +837,7 @@ public void testUpdateGraduationStatus_givenDifferentSchoolOfRecords_whenSchoolI when(graduationStatusRepository.saveAndFlush(graduationStatusEntity)).thenReturn(savedGraduationStatus); when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); - when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolByMincodeUrl(),newMincode))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolClobBySchoolIdUrl(),school.getSchoolId()))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(School.class)).thenReturn(Mono.just(school)); @@ -883,6 +890,7 @@ public void testUpdateGraduationStatus_givenDifferentSchoolOfGrads_whenSchoolIsV savedGraduationStatus.setProgramCompletionDate(graduationStatusEntity.getProgramCompletionDate()); School school = new School(); + school.setSchoolId(UUID.randomUUID().toString()); school.setMinCode(newMincode); school.setSchoolName("Test School"); school.setOpenFlag("Y"); @@ -891,7 +899,7 @@ public void testUpdateGraduationStatus_givenDifferentSchoolOfGrads_whenSchoolIsV when(graduationStatusRepository.saveAndFlush(graduationStatusEntity)).thenReturn(savedGraduationStatus); when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); - when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolByMincodeUrl(),newMincode))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolClobBySchoolIdUrl(),school.getSchoolId()))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(School.class)).thenReturn(Mono.just(school)); @@ -1653,13 +1661,11 @@ public void testSearchGraduationStudentRecords() { //schoolOfRecords.add(schoolOfRecord); School school = new School(); + school.setSchoolId(UUID.randomUUID().toString()); school.setMinCode(schoolOfRecord); school.setSchoolName("Test School"); - - CommonSchool commonSchool = new CommonSchool(); - commonSchool.setSchlNo(schoolOfRecord); - commonSchool.setSchoolName(school.getSchoolName()); - commonSchool.setSchoolCategoryCode("02"); + school.setSchoolCategoryLegacyCode("02"); + school.setSchoolCategoryCode("INDEPEN"); List districts = new ArrayList<>(); districts.add(distCode); @@ -1719,25 +1725,19 @@ public void testSearchGraduationStudentRecords() { when(this.responseMock.bodyToMono(Student.class)).thenReturn(Mono.just(student)); when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); - when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolByMincodeUrl(),schoolOfRecord))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolClobBySchoolIdUrl(),school.getSchoolId()))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(School.class)).thenReturn(Mono.just(school)); - when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); - when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolByMincodeSchoolApiUrl(),schoolOfRecord))).thenReturn(this.requestHeadersMock); - when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); - when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); - when(this.responseMock.bodyToMono(CommonSchool.class)).thenReturn(Mono.just(commonSchool)); - - final ParameterizedTypeReference> commonSchoolsType = new ParameterizedTypeReference<>() { + final ParameterizedTypeReference> schoolsType = new ParameterizedTypeReference<>() { }; when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); - when(this.requestHeadersUriMock.uri(constants.getSchoolsSchoolApiUrl())).thenReturn(this.requestHeadersMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolsByDistrictNumberUrl(),distCode))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); - when(this.responseMock.bodyToMono(commonSchoolsType)).thenReturn(Mono.just(List.of(commonSchool))); + when(this.responseMock.bodyToMono(schoolsType)).thenReturn(Mono.just(List.of(school))); when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); when(this.requestHeadersUriMock.uri(String.format(constants.getDistrictByDistrictCodeUrl(),distCode))).thenReturn(this.requestHeadersMock); @@ -1802,13 +1802,11 @@ public void testSearchGraduationStudentRecords_validateTrue() { schoolOfRecords.add(schoolOfRecord); School school = new School(); + school.setSchoolId(UUID.randomUUID().toString()); school.setMinCode(schoolOfRecord); school.setSchoolName("Test School"); - - CommonSchool commonSchool = new CommonSchool(); - commonSchool.setSchlNo(schoolOfRecord); - commonSchool.setSchoolName(school.getSchoolName()); - commonSchool.setSchoolCategoryCode("02"); + school.setSchoolCategoryLegacyCode("02"); + school.setSchoolCategoryCode("INDEPEN"); List districts = new ArrayList<>(); districts.add(distCode); @@ -1868,25 +1866,19 @@ public void testSearchGraduationStudentRecords_validateTrue() { when(this.responseMock.bodyToMono(Student.class)).thenReturn(Mono.just(student)); when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); - when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolByMincodeUrl(),schoolOfRecord))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolClobBySchoolIdUrl(),school.getSchoolId()))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); when(this.responseMock.bodyToMono(School.class)).thenReturn(Mono.just(school)); - when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); - when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolByMincodeSchoolApiUrl(),schoolOfRecord))).thenReturn(this.requestHeadersMock); - when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); - when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); - when(this.responseMock.bodyToMono(CommonSchool.class)).thenReturn(Mono.just(commonSchool)); - - final ParameterizedTypeReference> commonSchoolsType = new ParameterizedTypeReference<>() { + final ParameterizedTypeReference> schoolsType = new ParameterizedTypeReference<>() { }; when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); - when(this.requestHeadersUriMock.uri(constants.getSchoolsSchoolApiUrl())).thenReturn(this.requestHeadersMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getSchoolsByDistrictNumberUrl(),distCode))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); - when(this.responseMock.bodyToMono(commonSchoolsType)).thenReturn(Mono.just(List.of(commonSchool))); + when(this.responseMock.bodyToMono(schoolsType)).thenReturn(Mono.just(List.of(school))); when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); when(this.requestHeadersUriMock.uri(String.format(constants.getDistrictByDistrictCodeUrl(),distCode))).thenReturn(this.requestHeadersMock); @@ -2049,6 +2041,7 @@ public void testUgradStudent() throws JsonProcessingException { assertThat(result.getHonoursStanding()).isNull(); assertThat(result.getGpa()).isNull(); assertThat(result.getSchoolAtGrad()).isNull(); + assertThat(result.getSchoolAtGradId()).isNull(); } @Test @@ -2323,7 +2316,7 @@ public UUID getSchoolOfRecordId() { } @Override - public UUID getSchoolAtGraduationId() { + public UUID getSchoolAtGradId() { return null; } @@ -2449,7 +2442,7 @@ public UUID getSchoolOfRecordId() { } @Override - public UUID getSchoolAtGraduationId() { + public UUID getSchoolAtGradId() { return null; } @@ -2933,7 +2926,7 @@ public UUID getSchoolOfRecordId() { } @Override - public UUID getSchoolAtGraduationId() { + public UUID getSchoolAtGradId() { return null; } @@ -3210,7 +3203,7 @@ public UUID getSchoolOfRecordId() { } @Override - public UUID getSchoolAtGraduationId() { + public UUID getSchoolAtGradId() { return null; } diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java index 107bdd6e..5d8765b8 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/HistoryServiceTest.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.gradstudent.service; +import ca.bc.gov.educ.api.gradstudent.controller.BaseIntegrationTest; import ca.bc.gov.educ.api.gradstudent.messaging.NatsConnection; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStatusSubscriber; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Publisher; @@ -51,8 +52,7 @@ @RunWith(SpringRunner.class) @SpringBootTest -@ActiveProfiles("test") -public class HistoryServiceTest { +public class HistoryServiceTest extends BaseIntegrationTest { @Autowired EducGradStudentApiConstants constants; @Autowired HistoryService historyService; diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/JetStreamEventHandlerServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/JetStreamEventHandlerServiceTest.java index ba06130e..466cfb75 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/JetStreamEventHandlerServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/JetStreamEventHandlerServiceTest.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.api.gradstudent.service; +import ca.bc.gov.educ.api.gradstudent.controller.BaseIntegrationTest; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStatusSubscriber; import ca.bc.gov.educ.api.gradstudent.model.dto.ChoreographedEvent; import ca.bc.gov.educ.api.gradstudent.model.entity.GradStatusEvent; @@ -8,16 +9,12 @@ import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Subscriber; import ca.bc.gov.educ.api.gradstudent.repository.GradStatusEventRepository; import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.reactive.function.client.WebClient; import java.util.Optional; @@ -27,10 +24,7 @@ import static ca.bc.gov.educ.api.gradstudent.constant.EventStatus.MESSAGE_PUBLISHED; import static org.mockito.MockitoAnnotations.openMocks; -@RunWith(SpringRunner.class) -@SpringBootTest -@ActiveProfiles("test") -public class JetStreamEventHandlerServiceTest { +class JetStreamEventHandlerServiceTest extends BaseIntegrationTest { @Autowired EducGradStudentApiConstants constants; @@ -59,18 +53,18 @@ public class JetStreamEventHandlerServiceTest { @MockBean private Subscriber subscriber; - @Before + @BeforeEach public void setUp() { openMocks(this); } - @After + @AfterEach public void tearDown() { } @Test - public void testUpdateEventStatus() { + void testUpdateEventStatus() { UUID eventId = UUID.randomUUID(); ChoreographedEvent choreographedEvent = new ChoreographedEvent(); diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/support/MockConfiguration.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/support/MockConfiguration.java index d48efe26..5836a491 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/support/MockConfiguration.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/support/MockConfiguration.java @@ -2,6 +2,7 @@ import ca.bc.gov.educ.api.gradstudent.messaging.NatsConnection; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStatusSubscriber; +import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.FetchGradStudentRecordSubscriber; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Publisher; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Subscriber; import io.nats.client.Connection; @@ -56,6 +57,11 @@ public FetchGradStatusSubscriber fetchGradStatusSubscriber() { return Mockito.mock(FetchGradStatusSubscriber.class); } + @Bean + @Primary + public FetchGradStudentRecordSubscriber fetchGradStudentRecordSubscriber() {return Mockito.mock(FetchGradStudentRecordSubscriber.class); + } + @Bean @Primary public Connection connection() { diff --git a/api/src/test/resources/application.yaml b/api/src/test/resources/application.yaml index 1bf87d6a..863c719f 100644 --- a/api/src/test/resources/application.yaml +++ b/api/src/test/resources/application.yaml @@ -106,14 +106,12 @@ cron: #Endpoint properties endpoint: grad-trax-api: - all-commonschools: + schools-by-district-code: url: http://test - school-by-min-code: + school-clob-by-school-id: url: http://test district-by-district-code: url: http://test - commonschool-by-mincode: - url: http://test grad-program-api: optional_program_name_by_optional_program_id: url: http://test