Skip to content

Commit 62895bf

Browse files
Merge pull request #112 from bcgov/feature/use-institute
transition from school-api to institute-api
2 parents 1fa0f33 + 91896ea commit 62895bf

File tree

12 files changed

+179
-326
lines changed

12 files changed

+179
-326
lines changed

api/src/main/java/ca/bc/gov/educ/api/pen/services/properties/ApplicationProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ public class ApplicationProperties {
6060
@Value("${ramp.up.http}")
6161
private Boolean isHttpRampUp;
6262

63-
@Value("${url.api.school}")
64-
private String schoolApiURL;
63+
@Value("${url.api.institute}")
64+
private String instituteApiURL;
6565
}

api/src/main/java/ca/bc/gov/educ/api/pen/services/rest/RestUtils.java

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import ca.bc.gov.educ.api.pen.services.struct.*;
55
import ca.bc.gov.educ.api.pen.services.struct.v1.GenderCode;
66
import ca.bc.gov.educ.api.pen.services.struct.v1.GradeCode;
7-
import ca.bc.gov.educ.api.pen.services.struct.v1.School;
7+
import ca.bc.gov.educ.api.pen.services.struct.v1.SchoolTombstone;
88
import com.fasterxml.jackson.core.JsonProcessingException;
99
import com.fasterxml.jackson.databind.ObjectMapper;
1010
import lombok.extern.slf4j.Slf4j;
@@ -59,6 +59,10 @@ public class RestUtils {
5959
* The Grade lock.
6060
*/
6161
private final ReadWriteLock gradeLock = new ReentrantReadWriteLock();
62+
/**
63+
* The School lock
64+
*/
65+
private final ReadWriteLock schoolLock = new ReentrantReadWriteLock();
6266
/**
6367
* The Props.
6468
*/
@@ -69,7 +73,7 @@ public class RestUtils {
6973
*/
7074
private final WebClient webClient;
7175

72-
private final Map<String, School> schoolMap = new ConcurrentHashMap<>();
76+
private final Map<String, SchoolTombstone> schoolMap = new ConcurrentHashMap<>();
7377

7478
/**
7579
* Instantiates a new Rest utils.
@@ -103,34 +107,41 @@ public void init() {
103107
* @param mincode the mincode
104108
* @return the school by min code
105109
*/
106-
public Optional<School> getSchoolByMincode(final String mincode) {
110+
public Optional<SchoolTombstone> getSchoolByMincode(final String mincode) {
111+
if (this.schoolMap.isEmpty()) {
112+
log.info("School map is empty reloading schools");
113+
this.populateSchoolMap();
114+
}
107115
return Optional.ofNullable(this.schoolMap.get(mincode));
108116
}
109117

110118
/**
111119
* Populate school map.
112120
*/
113121
public void populateSchoolMap() {
114-
for (val school : this.getSchools()) {
115-
this.schoolMap.putIfAbsent(school.getDistNo() + school.getSchlNo(), school);
122+
val writeLock = this.schoolLock.writeLock();
123+
try {
124+
writeLock.lock();
125+
for (val school : this.getSchools()) {
126+
this.schoolMap.putIfAbsent(school.getMincode(), school);
127+
}
128+
} catch (Exception ex) {
129+
log.error("Unable to load map cache school {}", ex);
130+
} finally {
131+
writeLock.unlock();
116132
}
117133
log.info("loaded {} schools to memory", this.schoolMap.values().size());
118134
}
119135

120-
/**
121-
* Gets schools.
122-
*
123-
* @return the schools
124-
*/
125-
public List<School> getSchools() {
126-
log.info("calling school api to load schools to memory");
136+
public List<SchoolTombstone> getSchools() {
137+
log.info("Calling Institute api to load schools to memory");
127138
return this.webClient.get()
128-
.uri(this.props.getSchoolApiURL())
129-
.header(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
130-
.retrieve()
131-
.bodyToFlux(School.class)
132-
.collectList()
133-
.block();
139+
.uri(this.props.getInstituteApiURL() + "/school")
140+
.header(CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
141+
.retrieve()
142+
.bodyToFlux(SchoolTombstone.class)
143+
.collectList()
144+
.block();
134145
}
135146

136147
/**

api/src/main/java/ca/bc/gov/educ/api/pen/services/rules/impl/BirthDateRule.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,21 @@ public List<PenRequestStudentValidationIssue> validate(final PenRequestStudentVa
8282
* <p>
8383
* Public, Yukon, PSI etc schools – Set to ‘Y’ if
8484
* <p>
85-
* SCHOOL_CATEGORY_CODE OF SCHOOL_MASTER NE "02" and & ; Not Independent
86-
* SCHOOL_CATEGORY_CODE OF SCHOOL_MASTER NE "09" and & ; Not Offshore
87-
* SCHOOL_CATEGORY_CODE OF SCHOOL_MASTER NE "10" ; Not Early Learning
85+
* SCHOOL_CATEGORY_CODE OF INSTITUTE_API NE "INDEPEND" legacy code "02" and & ; Not Independent
86+
* SCHOOL_CATEGORY_CODE OF INSTITUTE_API NE "INDP_FNS" legacy code "02" and & ; Not Independent First Nations
87+
* SCHOOL_CATEGORY_CODE OF INSTITUTE_API NE "OFFSHORE" legacy code "09" and & ; Not Offshore
88+
* SCHOOL_CATEGORY_CODE OF INSTITUTE NE_API "EAR_LEARN" legacy code "10" ; Not Early Learning
8889
*
8990
* @param results the error/warning list
9091
* @param dob the dob of student
9192
* @param validationPayload the payload that is being validated.
9293
*/
9394
private void validateDOBForPublicSchool(final List<PenRequestStudentValidationIssue> results, final LocalDate dob, final PenRequestStudentValidationPayload validationPayload) {
9495
val schoolCategoryCode = this.getSchoolCategoryCode(validationPayload);
95-
if (!StringUtils.equals("02", schoolCategoryCode)
96-
&& !StringUtils.equals("09", schoolCategoryCode)
97-
&& !StringUtils.equals("10", schoolCategoryCode)
96+
if (!StringUtils.equals("INDEPEND", schoolCategoryCode)
97+
&& !StringUtils.equals("INDP_FNS", schoolCategoryCode)
98+
&& !StringUtils.equals("OFFSHORE", schoolCategoryCode)
99+
&& !StringUtils.equals("EAR_LEARN", schoolCategoryCode)
98100
&& (Period.between(dob, this.getComparisonDate()).toTotalMonths() < 60)) {
99101
results.add(this.createValidationEntity(ERROR, DOB_TOO_YOUNG, BIRTH_DATE));
100102
}
@@ -106,8 +108,9 @@ private void validateDOBForPublicSchool(final List<PenRequestStudentValidationIs
106108
* <p>
107109
* Independent or Offshore school– Set to ‘Y’ if
108110
* <p>
109-
* SCHOOL_CATEGORY_CODE OF SCHOOL_MASTER = "02" or ; Independent School
110-
* SCHOOL_CATEGORY_CODE OF SCHOOL_MASTER = "09" ; Offshore School
111+
* SCHOOL_CATEGORY_CODE OF INSTITUTE_API = "INDEPEND" legacy code "02" or ; Independent School
112+
* SCHOOL_CATEGORY_CODE OF INSTITUTE_API = "INDP_FNS" legacy code "02" or ; Independent First Nations School
113+
* SCHOOL_CATEGORY_CODE OF INSTITUTE_API = "OFFSHORE" legacy code "09" ; Offshore School
111114
* BIRTHDATE ERROR ERROR DOB TOO YOUNG
112115
*
113116
* @param results the error/warning list
@@ -116,7 +119,7 @@ private void validateDOBForPublicSchool(final List<PenRequestStudentValidationIs
116119
*/
117120
private void validateDOBForOffshoreAndIndependentSchool(final List<PenRequestStudentValidationIssue> results, final LocalDate dob, final PenRequestStudentValidationPayload validationPayload) {
118121
val schoolCategoryCode = this.getSchoolCategoryCode(validationPayload);
119-
if ((StringUtils.equals("02", schoolCategoryCode) || StringUtils.equals("09", schoolCategoryCode))
122+
if ((StringUtils.equals("INDEPEND", schoolCategoryCode) || StringUtils.equals("INDP_FNS", schoolCategoryCode) || StringUtils.equals("OFFSHORE", schoolCategoryCode))
120123
&& (Period.between(dob, this.getComparisonDate()).toTotalMonths() < 48)) {
121124
results.add(this.createValidationEntity(ERROR, DOB_TOO_YOUNG, BIRTH_DATE));
122125
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ca.bc.gov.educ.api.pen.services.struct.v1;
2+
3+
import jakarta.validation.constraints.Null;
4+
import jakarta.validation.constraints.Size;
5+
import lombok.Data;
6+
7+
/**
8+
* The type Base request.
9+
*/
10+
@Data
11+
public abstract class BaseRequest {
12+
/**
13+
* The Create user.
14+
*/
15+
@Size(max = 100)
16+
public String createUser;
17+
/**
18+
* The Update user.
19+
*/
20+
@Size(max = 100)
21+
public String updateUser;
22+
/**
23+
* The Create date.
24+
*/
25+
@Null(message = "createDate should be null.")
26+
public String createDate;
27+
/**
28+
* The Update date.
29+
*/
30+
@Null(message = "updateDate should be null.")
31+
public String updateDate;
32+
}

0 commit comments

Comments
 (0)