Skip to content

Commit 7d915ac

Browse files
committed
career
1 parent 5d442cc commit 7d915ac

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/DistrictReportTypeCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public enum DistrictReportTypeCode {
2727
ALL_STUDENT_DIS_CSV("ALL_STUDENT_DIS_CSV"),
2828
ALL_STUDENT_ERRORS_WARNS_DIS_CSV("ALL_STUDENT_ERRORS_WARNS_DIS_CSV"),
2929
ALL_STUDENT_FRENCH_DIS_CSV("ALL_STUDENT_FRENCH_DIS_CSV"),
30+
ALL_STUDENT_CAREER_DIS_CSV("ALL_STUDENT_CAREER_DIS_CSV"),
3031
DIS_ZERO_FTE_SUMMARY("DIS_ZERO_FTE_SUMMARY"),
3132
DIS_BAND_RESIDENCE_HEADCOUNT("DIS_BAND_RESIDENCE_HEADCOUNT"),
3233
DIS_BAND_RESIDENCE_HEADCOUNT_PER_SCHOOL("DIS_BAND_RESIDENCE_HEADCOUNT_PER_SCHOOL"),

api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/controller/v1/ReportGenerationController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public DownloadableReportResponse generateSDCDistrictReport(UUID sdcDistrictColl
107107
case ALL_STUDENT_DIS_CSV -> allStudentLightCollectionGenerateCsvService.generateFromSdcDistrictCollectionID(sdcDistrictCollectionID);
108108
case ALL_STUDENT_ERRORS_WARNS_DIS_CSV -> allStudentLightCollectionGenerateCsvService.generateErrorWarnInfoReportFromSdcDistrictCollectionID(sdcDistrictCollectionID);
109109
case ALL_STUDENT_FRENCH_DIS_CSV -> allStudentLightCollectionGenerateCsvService.generateFrenchFromSdcDistrictCollectionID(sdcDistrictCollectionID);
110+
case ALL_STUDENT_CAREER_DIS_CSV -> allStudentLightCollectionGenerateCsvService.generateCareerFromSdcDistrictCollectionID(sdcDistrictCollectionID);
110111
case DIS_ZERO_FTE_SUMMARY -> zeroFTEHeadCountReportService.generateZeroFTEHeadcountReport(sdcDistrictCollectionID);
111112
case DIS_BAND_RESIDENCE_HEADCOUNT -> bandOfResidenceHeadcountReportService.generateDistrictBandOfResidenceReport(sdcDistrictCollectionID);
112113
case DIS_BAND_RESIDENCE_HEADCOUNT_PER_SCHOOL -> bandOfResidenceHeadcountPerSchoolReportService.generateBandOfResidenceHeadcountPerSchoolReport(sdcDistrictCollectionID);

api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/reports/AllStudentLightCollectionGenerateCsvService.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,31 @@ public DownloadableReportResponse generateFrenchFromSdcDistrictCollectionID(UUID
175175
}
176176
}
177177

178+
public DownloadableReportResponse generateCareerFromSdcDistrictCollectionID(UUID sdcDistrictCollectionID) {
179+
List<SdcSchoolCollectionStudentLightWithEnrolledProgramCodesEntity> entities = sdcSchoolCollectionStudentSearchService.findAllCareerStudentsLightByDistrictCollectionId(sdcDistrictCollectionID);
180+
CSVFormat csvFormat = CSVFormat.DEFAULT.builder()
181+
.setHeader("School Code", "School Name", "Facility Code", "PEN", "Legal Name", "Usual Name", "FTE", "Program Eligible", "Local ID", "Adult", "Graduate", "Grade", "Funding Code", "Career Program", "Career Code")
182+
.build();
183+
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
184+
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(byteArrayOutputStream));
185+
CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat)) {
186+
187+
for (SdcSchoolCollectionStudentLightWithEnrolledProgramCodesEntity student : entities) {
188+
List<Object> csvRowData = prepareCareerStudentDataForCsv(student, true);
189+
csvPrinter.printRecord(csvRowData);
190+
}
191+
csvPrinter.flush();
192+
193+
var downloadableReport = new DownloadableReportResponse();
194+
downloadableReport.setReportType(DistrictReportTypeCode.ALL_STUDENT_CAREER_DIS_CSV.getCode());
195+
downloadableReport.setDocumentData(Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray()));
196+
197+
return downloadableReport;
198+
} catch (IOException e) {
199+
throw new StudentDataCollectionAPIRuntimeException(e);
200+
}
201+
}
202+
178203
private List<Object> prepareStudentDataWithErrorsAndWarningsForCsv(SdcSchoolCollectionStudentEntity student, boolean isDistrict) {
179204
List<Object> csvRowData = new ArrayList<>();
180205
if (Boolean.TRUE.equals(isDistrict)) {
@@ -356,6 +381,46 @@ private List<Object> prepareFrenchStudentDataForCsv(SdcSchoolCollectionStudentLi
356381
return csvRowData;
357382
}
358383

384+
private List<Object> prepareCareerStudentDataForCsv(SdcSchoolCollectionStudentLightWithEnrolledProgramCodesEntity student, Boolean isDistrict) {
385+
List<Object> csvRowData = new ArrayList<>();
386+
if (Boolean.TRUE.equals(isDistrict)) {
387+
UUID schoolID = student.getSdcSchoolCollectionEntitySchoolID();
388+
Optional<SchoolTombstone> school = restUtils.getSchoolBySchoolID(schoolID.toString());
389+
var facilityType = restUtils.getFacilityTypeCode(school.get().getFacilityTypeCode());
390+
391+
String schoolCode = school.isPresent() ? school.get().getMincode() : "No School Code Found";
392+
String schoolName = school.map(SchoolTombstone::getDisplayName).orElse("No School Name Found");
393+
String finalFacilityType = facilityType.isPresent() ? facilityType.get().getLabel() : "No Facility Type Found";
394+
395+
csvRowData.add(schoolCode);
396+
csvRowData.add(schoolName);
397+
csvRowData.add(finalFacilityType);
398+
}
399+
String legalFullName = formatFullName(student.getLegalFirstName(), student.getLegalMiddleNames(), student.getLegalLastName());
400+
String usualFullName = formatFullName(student.getUsualFirstName(), student.getUsualMiddleNames(), student.getUsualLastName());
401+
402+
csvRowData.addAll(Arrays.asList(
403+
student.getStudentPen(),
404+
legalFullName,
405+
usualFullName,
406+
student.getFte(),
407+
StringUtils.isBlank(student.getFrenchProgramNonEligReasonCode()) ? "1" : "",
408+
student.getLocalID(),
409+
Boolean.TRUE.equals(student.getIsAdult()) ? "1" : "",
410+
Boolean.TRUE.equals(student.getIsGraduated()) ? "1" : "",
411+
student.getEnrolledGradeCode(),
412+
StringUtils.isBlank(student.getSchoolFundingCode()) ? "" : student.getSchoolFundingCode().replaceAll("(.{2})(?=.)","$1,"),
413+
StringUtils.isBlank(student.getEnrolledProgramCodes())
414+
? ""
415+
: Arrays.stream(student.getEnrolledProgramCodes().split("(?<=\\G.{2})"))
416+
.filter(code -> EnrolledProgramCodes.getCareerProgramCodes().contains(code))
417+
.collect(Collectors.joining(",")),
418+
student.getCareerProgramCode()
419+
));
420+
return csvRowData;
421+
}
422+
423+
359424
public String formatFullName(String firstName, String middleNames, String lastName) {
360425
StringBuilder fullName = new StringBuilder();
361426

api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/service/v1/SdcSchoolCollectionStudentSearchService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ public List<SdcSchoolCollectionStudentLightWithEnrolledProgramCodesEntity> findA
140140
}
141141
}
142142

143+
@Transactional(propagation = Propagation.SUPPORTS)
144+
public List<SdcSchoolCollectionStudentLightWithEnrolledProgramCodesEntity> findAllCareerStudentsLightByDistrictCollectionId(UUID sdcDistrictCollectionID) {
145+
try {
146+
var status = Arrays.asList(SdcSchoolStudentStatus.DELETED.getCode(), SdcSchoolStudentStatus.ERROR.getCode());
147+
return this.sdcSchoolCollectionStudentLightWithEnrolledProgramCodesRepository.findByDistrictCollectionIDAndStatusNotInAndEnrolledProgramCodeIn(sdcDistrictCollectionID, status, EnrolledProgramCodes.getCareerProgramCodes());
148+
} catch (final Exception ex) {
149+
log.error("Failure querying for light career SDC school students by District Collection ID: {}", ex.getMessage());
150+
throw new CompletionException(ex);
151+
}
152+
}
153+
143154
public Specification<SdcSchoolCollectionStudentPaginationEntity> setSpecificationAndSortCriteria(String sortCriteriaJson, String searchCriteriaListJson, ObjectMapper objectMapper, List<Sort.Order> sorts) {
144155
Specification<SdcSchoolCollectionStudentPaginationEntity> schoolSpecs = null;
145156
try {

0 commit comments

Comments
 (0)