use of ca.bc.gov.educ.penreg.api.struct.Student in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchReportDataMapperTest method testToReportUserMatchedListItem_GivenNullValues_ShouldMapSuccessfully.
@Test
public void testToReportUserMatchedListItem_GivenNullValues_ShouldMapSuccessfully() throws IOException {
final var batchEntities = PenRequestBatchTestUtils.createBatchStudents(this.repository, "mock_pen_req_batch_repeat.json", "mock_pen_req_batch_student_null_data.json", 1, (batch) -> batch.setProcessDate(LocalDateTime.parse("2021-03-23T13:04:48.840098")));
final var student1 = Student.builder().studentID("566ee980-8e5f-11eb-8dcd-0242ac130002").pen("123456785").demogCode("C").build();
final var student2 = Student.builder().studentID("566ee980-8e5f-11eb-8dcd-0242ac130003").pen("123456780").legalLastName("BILL").build();
final List<Student> students = new ArrayList<>();
students.add(student1);
students.add(student2);
final var sagaData = PenRequestBatchArchiveAndReturnSagaData.builder().facsimile("3333333333").telephone("5555555555").fromEmail("test@abc.com").mailingAddress("mailing address").schoolName("Cataline").penRequestBatch(mapper.toStructure(batchEntities.get(0))).penRequestBatchStudents(batchEntities.get(0).getPenRequestBatchStudentEntities().stream().map(studentMapper::toStructure).collect(Collectors.toList())).penRequestBatchStudentValidationIssues(new HashMap<>()).students(students).build();
final PenRequestBatchReportData reportData = reportMapper.toReportData(sagaData);
assertThat(reportData.getProcessDate()).isEqualTo("2021/03/23");
assertThat(reportData.getProcessTime()).isEqualTo("13:04");
assertThat(reportData.getSubmissionNumber()).isEqualTo(batchEntities.get(0).getSubmissionNumber());
assertThat(reportData.getReportDate()).isEqualTo("2021-MAR-23");
assertThat(reportData.getReviewer()).isEqualTo("School PEN Coordinator");
assertThat(reportData.getMincode()).isEqualTo(formatMincode(batchEntities.get(0).getMincode()));
assertThat(reportData.getSchoolName()).isEqualTo("Cataline");
assertThat(reportData.getFascimile()).isEqualTo("3333333333");
assertThat(reportData.getTelephone()).isEqualTo("5555555555");
assertThat(reportData.getMailingAddress()).isEqualTo("mailing address");
assertThat(reportData.getPenCordinatorEmail()).isEqualTo("test@abc.com");
assertThat(reportData.getDiffList().size()).isEqualTo(1);
assertThat(reportData.getDiffList().get(0).getMin().getBirthDate()).isEqualTo("");
assertThat(reportData.getDiffList().get(0).getMin().getGender()).isEqualTo("");
assertThat(reportData.getDiffList().get(0).getMin().getGivenName()).isEqualTo("");
assertThat(reportData.getDiffList().get(0).getMin().getLegalMiddleNames()).isEqualTo("");
assertThat(reportData.getDiffList().get(0).getMin().getPen()).isEqualTo("123456780");
assertThat(reportData.getDiffList().get(0).getMin().getReason()).isEqualTo(null);
assertThat(reportData.getDiffList().get(0).getMin().getSchoolID()).isEqualTo("");
assertThat(reportData.getDiffList().get(0).getMin().getSurname()).isEqualTo("BILL");
assertThat(reportData.getDiffList().get(0).getMin().getUsualName()).isEqualTo("");
assertThat(reportData.getDiffList().size()).isEqualTo(1);
assertThat(reportData.getDiffList().get(0).getSchool().getBirthDate()).isEqualTo("");
assertThat(reportData.getDiffList().get(0).getSchool().getGender()).isEqualTo("");
assertThat(reportData.getDiffList().get(0).getSchool().getGivenName()).isEqualTo("");
assertThat(reportData.getDiffList().get(0).getSchool().getLegalMiddleNames()).isEqualTo("");
assertThat(reportData.getDiffList().get(0).getSchool().getPen()).isEqualTo("");
assertThat(reportData.getDiffList().get(0).getSchool().getReason()).isEqualTo(null);
assertThat(reportData.getDiffList().get(0).getSchool().getSchoolID()).isEqualTo("");
assertThat(reportData.getDiffList().get(0).getSchool().getSurname()).isEqualTo("");
assertThat(reportData.getDiffList().get(0).getSchool().getUsualName()).isEqualTo("");
assertThat(reportData.getSysMatchedList().size()).isEqualTo(2);
assertThat(reportData.getSysMatchedList().get(1).getBirthDate()).isEqualTo("");
assertThat(reportData.getSysMatchedList().get(1).getGender()).isEqualTo("");
assertThat(reportData.getSysMatchedList().get(1).getGivenName()).isEqualTo("");
assertThat(reportData.getSysMatchedList().get(1).getLegalMiddleNames()).isEqualTo("");
assertThat(reportData.getSysMatchedList().get(1).getPen()).isEqualTo("");
assertThat(reportData.getSysMatchedList().get(1).getReason()).isEqualTo(null);
assertThat(reportData.getSysMatchedList().get(1).getSchoolID()).isEqualTo("");
assertThat(reportData.getSysMatchedList().get(1).getSurname()).isEqualTo("");
assertThat(reportData.getSysMatchedList().get(1).getUsualName()).isEqualTo("");
assertThat(reportData.getNewPenList().size()).isEqualTo(2);
assertThat(reportData.getPendingList().size()).isEqualTo(4);
assertThat(reportData.getSysMatchedList().size()).isEqualTo(2);
}
use of ca.bc.gov.educ.penreg.api.struct.Student in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchAPIControllerTest method testUpdatePenRequestBatchStudent_GivenPenRequestBatchStudent_ShouldReturnStatusOk.
/**
* Test update pen request batch student given pen request batch student should return status ok.
*
* @throws Exception the exception
*/
@Test
public void testUpdatePenRequestBatchStudent_GivenPenRequestBatchStudent_ShouldReturnStatusOk() throws Exception {
final var models = this.createBatchStudents(1);
final var student = studentMapper.toStructure(models.get(0).getPenRequestBatchStudentEntities().stream().findFirst().orElseThrow());
student.setPenRequestBatchStudentStatusCode("FIXABLE");
student.setInfoRequest("Test Info");
final var request = new ObjectMapper().writeValueAsString(student);
this.mockMvc.perform(put(String.format("/api/v1/pen-request-batch/%s/student/%s", student.getPenRequestBatchID(), student.getPenRequestBatchStudentID())).with(jwt().jwt((jwt) -> jwt.claim("scope", "WRITE_PEN_REQUEST_BATCH"))).contentType(APPLICATION_JSON).accept(APPLICATION_JSON).content(request)).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.penRequestBatchStudentStatusCode", is("FIXABLE"))).andExpect(jsonPath("$.infoRequest", is("Test Info")));
}
use of ca.bc.gov.educ.penreg.api.struct.Student in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchAPIControllerTest method testReadPenRequestBatchStudentPaginated_GivenPenRequestBatchIdsAndStudentStatusCodes_ShouldReturnStatusOk.
/**
* Test read pen request batch student paginated given pen request batch ids and student status codes should return status ok.
*
* @throws Exception the exception
*/
@Test
public void testReadPenRequestBatchStudentPaginated_GivenPenRequestBatchIdsAndStudentStatusCodes_ShouldReturnStatusOk() throws Exception {
final String batchIDs = this.createBatchStudentRecords(2);
final SearchCriteria criteria = SearchCriteria.builder().key("penRequestBatchEntity.penRequestBatchID").operation(FilterOperation.IN).value(batchIDs).valueType(ValueType.UUID).build();
final List<SearchCriteria> criteriaList = new LinkedList<>();
criteriaList.add(criteria);
final SearchCriteria criteria1 = SearchCriteria.builder().key("penRequestBatchStudentStatusCode").operation(FilterOperation.IN).value("LOADED,ERROR,FIXABLE").valueType(ValueType.STRING).build();
final List<SearchCriteria> criteriaList1 = new LinkedList<>();
criteriaList1.add(criteria1);
final List<Search> searches = new LinkedList<>();
searches.add(Search.builder().searchCriteriaList(criteriaList).build());
searches.add(Search.builder().condition(AND).searchCriteriaList(criteriaList1).build());
final ObjectMapper objectMapper = new ObjectMapper();
final String criteriaJSON = objectMapper.writeValueAsString(searches);
final String sort = this.createSortParam();
final MvcResult result = this.mockMvc.perform(get("/api/v1/pen-request-batch/student/paginated").with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_PEN_REQUEST_BATCH"))).param("searchCriteriaList", criteriaJSON).param("sort", sort).param("pageSize", "3").contentType(APPLICATION_JSON)).andReturn();
this.mockMvc.perform(asyncDispatch(result)).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.content", hasSize(3)));
}
use of ca.bc.gov.educ.penreg.api.struct.Student in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchAPIControllerTest method testReadPenRequestBatchStudentPaginated_GivenPenRequestBatchIdsAndAllStudentStatusCodesAndOtherConditions_ShouldReturnStatusOk.
/**
* Test read pen request batch student paginated given pen request batch ids and all student status codes and other conditions should return status ok.
*
* @throws Exception the exception
*/
@Test
public void testReadPenRequestBatchStudentPaginated_GivenPenRequestBatchIdsAndAllStudentStatusCodesAndOtherConditions_ShouldReturnStatusOk() throws Exception {
final String batchIDs = this.createBatchStudentRecords(2);
final SearchCriteria criteria = SearchCriteria.builder().key("penRequestBatchEntity.penRequestBatchID").operation(FilterOperation.IN).value(batchIDs).valueType(ValueType.UUID).build();
final List<SearchCriteria> criteriaList = new LinkedList<>();
criteriaList.add(criteria);
final SearchCriteria criteria2 = SearchCriteria.builder().key("penRequestBatchStudentStatusCode").operation(FilterOperation.NOT_EQUAL).value("FIXABLE").valueType(ValueType.STRING).build();
final SearchCriteria criteria3 = SearchCriteria.builder().key("penRequestBatchEntity.mincode").condition(AND).operation(FilterOperation.STARTS_WITH_IGNORE_CASE).value("1").valueType(ValueType.STRING).build();
final SearchCriteria criteria4 = SearchCriteria.builder().key("legalLastName").condition(AND).operation(FilterOperation.STARTS_WITH_IGNORE_CASE).value("j").valueType(ValueType.STRING).build();
final List<SearchCriteria> criteriaList1 = new LinkedList<>();
criteriaList1.add(criteria2);
criteriaList1.add(criteria3);
criteriaList1.add(criteria4);
final List<Search> searches = new LinkedList<>();
searches.add(Search.builder().searchCriteriaList(criteriaList).build());
searches.add(Search.builder().condition(AND).searchCriteriaList(criteriaList1).build());
final ObjectMapper objectMapper = new ObjectMapper();
final String criteriaJSON = objectMapper.writeValueAsString(searches);
final String sort = this.createSortParam();
final MvcResult result = this.mockMvc.perform(get("/api/v1/pen-request-batch/student/paginated").with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_PEN_REQUEST_BATCH"))).param("searchCriteriaList", criteriaJSON).param("sort", sort).param("pageSize", "3").contentType(APPLICATION_JSON)).andReturn();
this.mockMvc.perform(asyncDispatch(result)).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.content", hasSize(3)));
}
use of ca.bc.gov.educ.penreg.api.struct.Student in project EDUC-PEN-REG-BATCH-API by bcgov.
the class RestUtils method getStudentByPEN.
/**
* Gets student by pen.
*
* @param pen the pen
* @return the student by pen
*/
public Optional<Student> getStudentByPEN(final String pen) {
val getStudentByPenEvent = Event.builder().eventType(EventType.GET_STUDENT).eventPayload(pen).sagaId(UUID.randomUUID()).build();
try {
log.info("calling getStudentByPEN :: {} via NATS for pen :: {}", STUDENT_API_TOPIC, pen);
val eventResponse = this.messagePublisher.requestMessage(STUDENT_API_TOPIC.toString(), JsonUtil.getJsonString(getStudentByPenEvent).orElseThrow().getBytes(StandardCharsets.UTF_8)).get(30, TimeUnit.SECONDS).getData();
log.info("got response from NATS for pen :: {}, student found :: {}", pen, eventResponse.length > 0);
if (eventResponse.length > 0) {
return Optional.of(JsonUtil.getJsonObjectFromByteArray(Student.class, eventResponse));
}
} catch (final InterruptedException | ExecutionException | TimeoutException | IOException e) {
Thread.currentThread().interrupt();
log.error("Exception while get student by pen", e);
}
return Optional.empty();
}
Aggregations