-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abd71f9
commit 8886401
Showing
23 changed files
with
174 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
.../ca/bc/gov/educ/studentdatacollection/api/calculator/impl/PRPorYouthSchoolCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ca.bc.gov.educ.studentdatacollection.api.calculator.impl; | ||
|
||
import ca.bc.gov.educ.studentdatacollection.api.calculator.FteCalculator; | ||
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.FacilityTypeCodes; | ||
import ca.bc.gov.educ.studentdatacollection.api.struct.StudentRuleData; | ||
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.FteCalculationResult; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Arrays; | ||
|
||
import static ca.bc.gov.educ.studentdatacollection.api.constants.v1.ZeroFteReasonCodes.PRP_OR_YOUTH_SCHOOL; | ||
|
||
@Component | ||
@Slf4j | ||
@Order(31) | ||
public class PRPorYouthSchoolCalculator implements FteCalculator { | ||
FteCalculator nextCalculator; | ||
@Override | ||
public void setNext(FteCalculator nextCalculator) { | ||
this.nextCalculator = nextCalculator; | ||
} | ||
@Override | ||
public FteCalculationResult calculateFte(StudentRuleData studentData) { | ||
log.debug("PRPorYouthSchoolCalculator: Starting calculation for student :: " + studentData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollectionStudentID()); | ||
var prpAndYouthSchools = Arrays.asList(FacilityTypeCodes.SHORT_PRP.getCode(), FacilityTypeCodes.LONG_PRP.getCode(), FacilityTypeCodes.YOUTH.getCode()); | ||
|
||
if(prpAndYouthSchools.contains(studentData.getSchool().getFacilityTypeCode())) { | ||
FteCalculationResult fteCalculationResult = new FteCalculationResult(); | ||
fteCalculationResult.setFte(BigDecimal.ZERO); | ||
fteCalculationResult.setFteZeroReason(PRP_OR_YOUTH_SCHOOL.getCode()); | ||
log.debug("PRPorYouthSchoolCalculator: Fte result {} calculated with zero reason '{}' for student :: {}", fteCalculationResult.getFte(), fteCalculationResult.getFteZeroReason(), studentData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollectionStudentID()); | ||
return fteCalculationResult; | ||
} else { | ||
log.debug("PRPorYouthSchoolCalculator: No FTE result, moving to next calculation for student :: " + studentData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollectionStudentID()); | ||
return this.nextCalculator.calculateFte(studentData); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
...bc/gov/educ/studentdatacollection/api/calculator/impl/PrpOrYouthSchoolCalculatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package ca.bc.gov.educ.studentdatacollection.api.calculator.impl; | ||
|
||
import ca.bc.gov.educ.studentdatacollection.api.calculator.FteCalculator; | ||
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.FacilityTypeCodes; | ||
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolCategoryCodes; | ||
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.ZeroFteReasonCodes; | ||
import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionStudentEntity; | ||
import ca.bc.gov.educ.studentdatacollection.api.struct.StudentRuleData; | ||
import ca.bc.gov.educ.studentdatacollection.api.struct.external.institute.v1.SchoolTombstone; | ||
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.FteCalculationResult; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.math.BigDecimal; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.*; | ||
|
||
class PrpOrYouthSchoolCalculatorTest { | ||
|
||
private PRPorYouthSchoolCalculator prPorYouthSchoolCalculator; | ||
private FteCalculator nextCalculator; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
nextCalculator = mock(FteCalculator.class); | ||
prPorYouthSchoolCalculator = new PRPorYouthSchoolCalculator(); | ||
prPorYouthSchoolCalculator.setNext(nextCalculator); | ||
} | ||
|
||
@Test | ||
void testCalculateFte_StudentPrpSchool() { | ||
// Given | ||
SdcSchoolCollectionStudentEntity student = new SdcSchoolCollectionStudentEntity(); | ||
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyyMMdd"); | ||
student.setDob(format.format(LocalDateTime.now().minusYears(6))); | ||
StudentRuleData studentData = new StudentRuleData(); | ||
studentData.setSdcSchoolCollectionStudentEntity(student); | ||
studentData.setSchool(createSchool()); | ||
|
||
// When | ||
FteCalculationResult result = prPorYouthSchoolCalculator.calculateFte(studentData); | ||
|
||
// Then | ||
assertEquals(BigDecimal.ZERO, result.getFte()); | ||
assertEquals(ZeroFteReasonCodes.PRP_OR_YOUTH_SCHOOL.getCode(), result.getFteZeroReason()); | ||
verify(nextCalculator, never()).calculateFte(any()); | ||
} | ||
|
||
@Test | ||
void testCalculateFte_StudentYouthSchool() { | ||
// Given | ||
SdcSchoolCollectionStudentEntity student = new SdcSchoolCollectionStudentEntity(); | ||
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyyMMdd"); | ||
student.setDob(format.format(LocalDateTime.now().minusYears(6))); | ||
StudentRuleData studentData = new StudentRuleData(); | ||
studentData.setSdcSchoolCollectionStudentEntity(student); | ||
var school = createSchool(); | ||
school.setFacilityTypeCode(FacilityTypeCodes.YOUTH.getCode()); | ||
studentData.setSchool(school); | ||
|
||
// When | ||
FteCalculationResult result = prPorYouthSchoolCalculator.calculateFte(studentData); | ||
|
||
// Then | ||
assertEquals(BigDecimal.ZERO, result.getFte()); | ||
assertEquals(ZeroFteReasonCodes.PRP_OR_YOUTH_SCHOOL.getCode(), result.getFteZeroReason()); | ||
verify(nextCalculator, never()).calculateFte(any()); | ||
} | ||
|
||
@Test | ||
void testCalculateFte_StudentExactlyOldEnough() { | ||
// Given | ||
SdcSchoolCollectionStudentEntity student = new SdcSchoolCollectionStudentEntity(); | ||
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyyMMdd"); | ||
student.setDob(format.format(LocalDateTime.now().minusYears(6))); | ||
StudentRuleData studentData = new StudentRuleData(); | ||
studentData.setSdcSchoolCollectionStudentEntity(student); | ||
var school = createSchool(); | ||
school.setFacilityTypeCode(FacilityTypeCodes.STANDARD.getCode()); | ||
studentData.setSchool(school); | ||
|
||
// When | ||
FteCalculationResult expectedResult = new FteCalculationResult(); | ||
expectedResult.setFte(BigDecimal.ONE); | ||
expectedResult.setFteZeroReason(null); | ||
|
||
when(nextCalculator.calculateFte(any())).thenReturn(expectedResult); | ||
FteCalculationResult result = prPorYouthSchoolCalculator.calculateFte(studentData); | ||
|
||
// Then | ||
assertEquals(expectedResult, result); | ||
verify(nextCalculator).calculateFte(studentData); | ||
} | ||
|
||
private SchoolTombstone createSchool(){ | ||
SchoolTombstone schoolTombstone = new SchoolTombstone(); | ||
schoolTombstone.setSchoolCategoryCode(SchoolCategoryCodes.PUBLIC.getCode()); | ||
schoolTombstone.setFacilityTypeCode(FacilityTypeCodes.LONG_PRP.getCode()); | ||
schoolTombstone.setDistrictId(UUID.randomUUID().toString()); | ||
return schoolTombstone; | ||
} | ||
} |