Skip to content

Commit

Permalink
Fixes to pull back new student registration contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
arcshiftsolutions committed Oct 18, 2023
1 parent 4ada0ae commit 217fd7d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 18 deletions.
48 changes: 30 additions & 18 deletions api/src/main/java/ca/bc/gov/educ/api/pen/myed/rest/RestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import ca.bc.gov.educ.api.pen.myed.struct.v1.PenRequestResult;
import ca.bc.gov.educ.api.pen.myed.struct.v1.Request;
import ca.bc.gov.educ.api.pen.myed.struct.v1.district.District;
import ca.bc.gov.educ.api.pen.myed.struct.v1.district.DistrictContact;
import ca.bc.gov.educ.api.pen.myed.struct.v1.district.DistrictContactSearchWrapper;
import ca.bc.gov.educ.api.pen.myed.struct.v1.penregbatch.PenRequestBatch;
import ca.bc.gov.educ.api.pen.myed.struct.v1.school.School;
import ca.bc.gov.educ.api.pen.myed.struct.v1.school.SchoolContact;
import ca.bc.gov.educ.api.pen.myed.struct.v1.school.SchoolContactSearchWrapper;
import ca.bc.gov.educ.api.pen.myed.struct.v1.school.StudentRegistrationContact;
import ca.bc.gov.educ.api.pen.myed.struct.v1.student.RestPageImpl;
import ca.bc.gov.educ.api.pen.myed.struct.v1.student.Student;
Expand Down Expand Up @@ -172,7 +172,7 @@ public Mono<ResponseEntity<String>> postBatchSubmission(final PenRequestBatch pe
public List<District> getDistricts() {
log.info("Calling Institute api to get list of districts");
return this.webClient.get()
.uri(this.props.getInstituteApiUrl() + "/district")
.uri(this.props.getInstituteApiUrl() + "/api/v1/institute/district")
.header(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.retrieve()
.bodyToFlux(District.class)
Expand All @@ -183,7 +183,7 @@ public List<District> getDistricts() {
public List<School> getSchools() {
log.info("Calling Institute api to get list of schools");
return this.webClient.get()
.uri(this.props.getInstituteApiUrl() + "/school")
.uri(this.props.getInstituteApiUrl() + "/api/v1/institute/school")
.header(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.retrieve()
.bodyToFlux(School.class)
Expand Down Expand Up @@ -244,32 +244,44 @@ public Mono<ResponseEntity<PenRequestResult>> postPenRequestToBatchAPI(final Req
});
}

private URI getSchoolContactURI(String criterion){
return UriComponentsBuilder.fromHttpUrl(this.props.getInstituteApiUrl() + "/api/v1/institute/school/contact/paginated")
.queryParam("pageNumber", "0")
.queryParam("pageSize", "10000")
.queryParam("searchCriteriaList", criterion).build().toUri();
}

private URI getDistrictContactURI(String criterion){
return UriComponentsBuilder.fromHttpUrl(this.props.getInstituteApiUrl() + "/api/v1/institute/district/contact/paginated")
.queryParam("pageNumber", "0")
.queryParam("pageSize", "10000")
.queryParam("searchCriteriaList", criterion).build().toUri();
}

public List<StudentRegistrationContact> getStudentRegistrationContactList() {
try {
log.info("Calling Institute api to get list of school and district student registration contacts");
List<SchoolContact> schoolContacts = this.webClient.get()
.uri(this.props.getInstituteApiUrl()
+ "/api/v1/institute/school/contact/paginated?pageNumber=0&pageSize=10000")
String criterion = "[{\"searchCriteriaList\":[{\"key\":\"schoolContactTypeCode\",\"operation\":\"eq\",\"value\":\"STUDREGIS\",\"valueType\":\"STRING\",\"condition\":\"AND\"}]}]";
SchoolContactSearchWrapper schoolContactSearchWrapper = this.webClient.get()
.uri(getSchoolContactURI(criterion))
.header(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.retrieve()
.bodyToFlux(SchoolContact.class)
.collectList()
.block();
.bodyToFlux(SchoolContactSearchWrapper.class)
.blockFirst();

List<DistrictContact> districtContacts = this.webClient.get()
.uri(this.props.getInstituteApiUrl()
+ "/api/v1/institute/district/contact/paginated?pageNumber=0&pageSize=10000&searchCriteriaList=[{'condition':null,'searchCriteriaList':[{'key':'districtContactTypeCode','operation':'eq','value':'STUDREGIS','valueType':'STRING','condition':'AND'}]}]")
criterion = "[{\"searchCriteriaList\":[{\"key\":\"districtContactTypeCode\",\"operation\":\"eq\",\"value\":\"STUDREGIS\",\"valueType\":\"STRING\",\"condition\":\"AND\"}]}]";
DistrictContactSearchWrapper districtContactSearchWrapper = this.webClient.get()
.uri(getDistrictContactURI(criterion))
.header(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.retrieve()
.bodyToFlux(DistrictContact.class)
.collectList()
.block();
.bodyToFlux(DistrictContactSearchWrapper.class)
.blockFirst();

var schools = getSchoolIDMap();
var districts = getDistrictIDMap();

List<StudentRegistrationContact> studentRegistrationContacts = new ArrayList<>();
schoolContacts.forEach(schoolContact -> {
schoolContactSearchWrapper.getContent().forEach(schoolContact -> {
var school = schools.get(schoolContact.getSchoolId());
StudentRegistrationContact coordinator = new StudentRegistrationContact();
coordinator.setMincode(school.getMincode());
Expand All @@ -280,7 +292,7 @@ public List<StudentRegistrationContact> getStudentRegistrationContactList() {
studentRegistrationContacts.add(coordinator);
});

districtContacts.forEach(districtContact -> {
districtContactSearchWrapper.getContent().forEach(districtContact -> {
var district = districts.get(districtContact.getDistrictId());
StudentRegistrationContact coordinator = new StudentRegistrationContact();
coordinator.setMincode(district.getDistrictNumber() + "00000");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ca.bc.gov.educ.api.pen.myed.struct.v1.district;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class DistrictContactSearchWrapper implements Serializable {
private List<DistrictContact> content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ca.bc.gov.educ.api.pen.myed.struct.v1.school;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class SchoolContactSearchWrapper implements Serializable {
private List<SchoolContact> content;
}

0 comments on commit 217fd7d

Please sign in to comment.