Skip to content

Commit

Permalink
Updates to pull new institute values
Browse files Browse the repository at this point in the history
  • Loading branch information
arcshiftsolutions committed Oct 17, 2023
1 parent 4fea49d commit fee3dbe
Show file tree
Hide file tree
Showing 15 changed files with 356 additions and 612 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM artifacts.developer.gov.bc.ca/docker-remote/maven:3-jdk-11 as build
FROM artifacts.developer.gov.bc.ca/docker-remote/maven:3.8.7-openjdk-18 AS build
WORKDIR /workspace/app

COPY api/pom.xml .
Expand All @@ -10,7 +10,7 @@ FROM build AS vulnscan
COPY --from=artifacts.developer.gov.bc.ca/docker-remote/aquasec/trivy:latest /usr/local/bin/trivy /usr/local/bin/trivy
RUN trivy filesystem --severity CRITICAL --exit-code 0 --no-progress /

FROM artifacts.developer.gov.bc.ca/docker-remote/openjdk:11-jdk as pen-myed
FROM artifacts.developer.gov.bc.ca/docker-remote/openjdk:18.0.2.1-jdk-oracle AS pen-myed
RUN useradd -ms /bin/bash spring
RUN mkdir -p /logs
RUN chown -R spring:spring /logs
Expand Down
3 changes: 2 additions & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
<sonar.exclusions>
src/main/resources/**,
</sonar.exclusions>
<java.version>11</java.version>
<java.version>17</java.version>

<maven.compiler.version>3.8.0</maven.compiler.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<org.mapstruct.version>1.4.1.Final</org.mapstruct.version>
<shedlock.version>4.20.0</shedlock.version>
<springdoc.version>1.5.2</springdoc.version>
<lombok.version>1.18.28</lombok.version>
<nats.version>2.11.0</nats.version>
<ojdbc.version>12.2.0.1</ojdbc.version>
<guava.version>30.1.1-jre</guava.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import ca.bc.gov.educ.api.pen.myed.mappers.v1.PenRegBatchMapper;
import ca.bc.gov.educ.api.pen.myed.service.v1.PenMyEdService;
import ca.bc.gov.educ.api.pen.myed.struct.v1.*;
import ca.bc.gov.educ.api.pen.myed.struct.v1.school.PenCoordinator;
import ca.bc.gov.educ.api.pen.myed.struct.v1.school.StudentRegistrationContact;
import ca.bc.gov.educ.api.pen.myed.validator.PenMyEdPayloadValidator;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
Expand Down Expand Up @@ -81,8 +81,8 @@ public Mono<ResponseEntity<MyEdSubmissionResult>> batchSubmissionResult(final UU
}

@Override
public Mono<ResponseEntity<List<PenCoordinator>>> getPenCoordinators() {
return this.penMyEdService.getPenCoordinators();
public List<StudentRegistrationContact> getStudentRegistrationContacts() {
return this.penMyEdService.getStudentRegistrationContacts();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ca.bc.gov.educ.api.pen.myed.endpoint.v1;

import ca.bc.gov.educ.api.pen.myed.struct.v1.*;
import ca.bc.gov.educ.api.pen.myed.struct.v1.school.PenCoordinator;
import ca.bc.gov.educ.api.pen.myed.struct.v1.school.StudentRegistrationContact;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.media.ArraySchema;
Expand Down Expand Up @@ -65,10 +65,10 @@ public interface PenMyEdApiEndpoint {
*/
@GetMapping("/pen-coordinators")
@PreAuthorize("hasAuthority('SCOPE_MYED_READ_PEN_COORDINATOR')")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(name = "PenCoordinator", implementation = PenCoordinator.class)))),
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(name = "StudentRegistrationContact", implementation = StudentRegistrationContact.class)))),
@ApiResponse(responseCode = "404", description = "NOT FOUND")})
@Tag(name = "Endpoint to get all Pen Coordinators.", description = "Endpoint to get all Pen Coordinators.")
Mono<ResponseEntity<List<PenCoordinator>>> getPenCoordinators();
@Tag(name = "Endpoint to get all student registration contacts.", description = "Endpoint to get all student registration contacts.")
List<StudentRegistrationContact> getStudentRegistrationContacts();


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,26 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
* The type Application properties.
*/
@Component
@Getter
@Setter
public class ApplicationProperties {

/**
* The constant API_NAME.
*/
public static final String API_NAME = "PEN_MYED_API";
/**
* The Client id.
*/
@Value("${client.id}")
private String clientID;
/**
* The Client secret.
*/
@Value("${client.secret}")
private String clientSecret;
/**
* The Token url.
*/
@Value("${url.token}")
private String tokenURL;

/**
* The Pen reg batch api url.
*/
@Value("${url.api.pen.reg.batch}")
private String penRegBatchApiUrl;

/**
* The School api url.
*/
@Value("${url.api.school}")
private String schoolApiUrl;

/**
* The Pen services api url.
*/
@Value("${url.api.institute}")
private String instituteApiUrl;
@Value("${url.api.pen.services}")
private String penServicesApiURL;

/**
* The Pen match api url.
*/
@Value("${url.api.pen.match}")
private String penMatchApiURL;

/**
* The Student api url.
*/
@Value("${url.api.student}")
private String studentApiURL;

Expand Down
137 changes: 91 additions & 46 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 @@ -9,23 +9,26 @@
import ca.bc.gov.educ.api.pen.myed.struct.v1.PenRequestBatchSubmissionResult;
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.penregbatch.PenRequestBatch;
import ca.bc.gov.educ.api.pen.myed.struct.v1.school.PenCoordinator;
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.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;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.lang3.StringUtils;
import org.jboss.threads.EnhancedQueueExecutor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
Expand All @@ -36,6 +39,7 @@
import javax.annotation.PostConstruct;
import java.net.URI;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -64,15 +68,15 @@ public class RestUtils {
* The School lock.
*/
private final ReadWriteLock schoolLock = new ReentrantReadWriteLock();
/**
* The School map.
*/

@Getter
private final Map<String, School> schoolMap = new ConcurrentHashMap<>();
private final Map<String, School> schoolMincodeMap = new ConcurrentHashMap<>();

/**
* The Props.
*/
@Getter
private final Map<String, School> schoolIDMap = new ConcurrentHashMap<>();

@Getter
private final Map<String, District> districtIDMap = new ConcurrentHashMap<>();

private final ApplicationProperties props;
/**
Expand Down Expand Up @@ -105,12 +109,12 @@ public RestUtils(final ApplicationProperties props, final WebClient webClient) {
public void init() {
if (this.isBackgroundInitializationEnabled != null && this.isBackgroundInitializationEnabled) {
this.bgTask.execute(() -> {
this.populateSchoolMap();
this.getPenCoordinators().block();
this.populateSchoolMaps();
this.populateDistrictMap();
});
} else {
this.populateSchoolMap();
this.getPenCoordinators().block();
this.populateSchoolMaps();
this.populateDistrictMap();
}
}

Expand All @@ -128,14 +132,19 @@ public void scheduled() {
}
}

/**
* Populate school map.
*/
private void populateSchoolMap() {
private void populateSchoolMaps() {
for (val school : this.getSchools()) {
this.schoolMap.put(school.getDistNo() + school.getSchlNo(), school);
this.schoolMincodeMap.put(school.getMincode(), school);
this.schoolIDMap.put(school.getSchoolId(), school);
}
log.info("Loaded {} schools to memory", this.schoolIDMap.values().size());
}

private void populateDistrictMap() {
for (val district : this.getDistricts()) {
this.districtIDMap.put(district.getDistrictId(), district);
}
log.info("loaded {} schools to memory", this.schoolMap.values().size());
log.info("Loaded {} districts to memory", this.districtIDMap.values().size());
}

/**
Expand All @@ -160,20 +169,26 @@ public Mono<ResponseEntity<String>> postBatchSubmission(final PenRequestBatch pe
});
}

/**
* Gets schools.
*
* @return the schools
*/
public List<District> getDistricts() {
log.info("Calling Institute api to get list of districts");
return this.webClient.get()
.uri(this.props.getInstituteApiUrl() + "/district")
.header(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.retrieve()
.bodyToFlux(District.class)
.collectList()
.block();
}

public List<School> getSchools() {
log.info("calling school api to load schools to memory");
log.info("Calling Institute api to get list of schools");
return this.webClient.get()
.uri(this.props.getSchoolApiUrl())
.header(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.retrieve()
.bodyToFlux(School.class)
.collectList()
.block();
.uri(this.props.getInstituteApiUrl() + "/school")
.header(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.retrieve()
.bodyToFlux(School.class)
.collectList()
.block();
}

/**
Expand Down Expand Up @@ -229,21 +244,51 @@ public Mono<ResponseEntity<PenRequestResult>> postPenRequestToBatchAPI(final Req
});
}

public Mono<ResponseEntity<List<PenCoordinator>>> getPenCoordinators() {
log.info("making api call to get pen coordinators data ");
return this.webClient.get()
.uri(this.props.getSchoolApiUrl() + "/pen-coordinator")
.header(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.exchangeToMono(response -> {
if (response.statusCode().equals(HttpStatus.OK)) {
log.info("API call to get Pen coordinators success :: {}", response.rawStatusCode());
return response.toEntity(new ParameterizedTypeReference<List<PenCoordinator>>() {
});
} else {
log.error("API call to get Pen coordinators failed :: {}", response.rawStatusCode());
return Mono.just(ResponseEntity.status(response.statusCode()).build());
}
});
public List<StudentRegistrationContact> getStudentRegistrationContactList() {
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() + "/school")
.header(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.retrieve()
.bodyToFlux(SchoolContact.class)
.collectList()
.block();

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

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

List<StudentRegistrationContact> studentRegistrationContacts = new ArrayList<>();
schoolContacts.forEach(schoolContact -> {
var school = schools.get(schoolContact.getSchoolId());
StudentRegistrationContact coordinator = new StudentRegistrationContact();
coordinator.setMincode(school.getMincode());
coordinator.setDistrictNumber(school.getMincode().substring(0,3));
coordinator.setSchoolNumber(school.getMincode().substring(4));
coordinator.setPenCoordinatorName(StringUtils.trim(schoolContact.getFirstName() + " " + schoolContact.getLastName()));
coordinator.setPenCoordinatorEmail(schoolContact.getEmail());
studentRegistrationContacts.add(coordinator);
});

districtContacts.forEach(districtContact -> {
var district = districts.get(districtContact.getDistrictId());
StudentRegistrationContact coordinator = new StudentRegistrationContact();
coordinator.setMincode(district.getDistrictNumber() + "00000");
coordinator.setDistrictNumber(district.getDistrictNumber());
coordinator.setSchoolNumber("00000");
coordinator.setPenCoordinatorName(StringUtils.trim(districtContact.getFirstName() + " " + districtContact.getLastName()));
coordinator.setPenCoordinatorEmail(districtContact.getEmail());
studentRegistrationContacts.add(coordinator);
});
return studentRegistrationContacts;
}

public Mono<ResponseEntity<RestPageImpl<Student>>> findStudentsByCriteria(final String criteriaJSON, final Integer pageSize) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package ca.bc.gov.educ.api.pen.myed.service.v1;

import ca.bc.gov.educ.api.pen.myed.exception.MyEdAPIRuntimeException;
import ca.bc.gov.educ.api.pen.myed.mappers.v1.MyEdStudentMapper;
import ca.bc.gov.educ.api.pen.myed.rest.RestUtils;
import ca.bc.gov.educ.api.pen.myed.struct.v1.MyEdStudent;
import ca.bc.gov.educ.api.pen.myed.struct.v1.MyEdSubmissionResult;
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.penregbatch.PenRequestBatch;
import ca.bc.gov.educ.api.pen.myed.struct.v1.school.PenCoordinator;
import ca.bc.gov.educ.api.pen.myed.struct.v1.school.StudentRegistrationContact;
import ca.bc.gov.educ.api.pen.myed.struct.v1.student.*;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.lang3.RegExUtils;
Expand Down Expand Up @@ -81,8 +79,8 @@ public Mono<ResponseEntity<PenRequestResult>> postPenRequestToBatchAPI(final Req
});
}

public Mono<ResponseEntity<List<PenCoordinator>>> getPenCoordinators() {
return this.restUtils.getPenCoordinators();
public List<StudentRegistrationContact> getStudentRegistrationContacts() {
return this.restUtils.getStudentRegistrationContactList();
}

public Mono<ResponseEntity<List<MyEdStudent>>> findStudents(final List<String> penList) {
Expand All @@ -98,12 +96,12 @@ public Mono<ResponseEntity<List<MyEdStudent>>> findStudents(final List<String> p
searches.add(Search.builder().searchCriteriaList(criteriaList).build());
students.addAll(this.restUtils.findStudentsByCriteria(getJsonStringFromObject(searches), batch.size()).block().getBody().getContent());
}
return Mono.just(ResponseEntity.ok(students.stream().map(MyEdStudentMapper.mapper::toMyEdStudent).collect(Collectors.toList())));
return Mono.just(ResponseEntity.ok(students.stream().map(MyEdStudentMapper.mapper::toMyEdStudent).toList()));
}

public static <T> List<List<T>> getBatches(List<T> collection, int batchSize) {
return IntStream.iterate(0, i -> i < collection.size(), i -> i + batchSize)
.mapToObj(i -> collection.subList(i, Math.min(i + batchSize, collection.size())))
.collect(Collectors.toList());
.toList();
}
}
Loading

0 comments on commit fee3dbe

Please sign in to comment.