Skip to content

Commit b0e4773

Browse files
committed
smells
1 parent 1af85b9 commit b0e4773

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionStudentLightWithEnrolledProgramCodesEntity;
1111
import ca.bc.gov.educ.studentdatacollection.api.rest.RestUtils;
1212
import ca.bc.gov.educ.studentdatacollection.api.service.v1.SdcSchoolCollectionStudentSearchService;
13+
import ca.bc.gov.educ.studentdatacollection.api.struct.external.institute.v1.FacilityTypeCode;
1314
import ca.bc.gov.educ.studentdatacollection.api.struct.external.institute.v1.SchoolTombstone;
1415
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.reports.DownloadableReportResponse;
1516
import lombok.extern.slf4j.Slf4j;
@@ -436,11 +437,12 @@ private List<Object> prepareStudentDataWithErrorsAndWarningsForCsv(SdcSchoolColl
436437
if (Boolean.TRUE.equals(isDistrict)) {
437438
UUID schoolID = student.getSdcSchoolCollection().getSchoolID();
438439
Optional<SchoolTombstone> school = restUtils.getSchoolBySchoolID(schoolID.toString());
439-
var facilityType = restUtils.getFacilityTypeCode(school.get().getFacilityTypeCode());
440+
Optional<FacilityTypeCode> facilityType = school.map(schoolTombstone -> restUtils.getFacilityTypeCode(schoolTombstone.getFacilityTypeCode())).orElse(null);
440441

441442
String schoolCode = school.isPresent() ? school.get().getMincode() : NO_SCHOOL_CODE_FOUND;
442443
String schoolName = school.map(SchoolTombstone::getDisplayName).orElse(NO_SCHOOL_NAME_FOUND);
443-
String finalFacilityType = facilityType.isPresent() ? facilityType.get().getLabel() : NO_FACILITY_TYPE_FOUND;
444+
String finalFacilityType = facilityType != null && facilityType.isPresent() ? facilityType.get().getLabel() : NO_FACILITY_TYPE_FOUND;
445+
444446
csvRowData.add(schoolCode);
445447
csvRowData.add(schoolName);
446448
csvRowData.add(finalFacilityType);
@@ -518,11 +520,12 @@ private List<Object> prepareStudentDataForCsv(SdcSchoolCollectionStudentLightEnt
518520
if (Boolean.TRUE.equals(isDistrict)) {
519521
UUID schoolID = student.getSdcSchoolCollectionEntitySchoolID();
520522
Optional<SchoolTombstone> school = restUtils.getSchoolBySchoolID(schoolID.toString());
521-
var facilityType = restUtils.getFacilityTypeCode(school.get().getFacilityTypeCode());
523+
Optional<FacilityTypeCode> facilityType = school.map(schoolTombstone -> restUtils.getFacilityTypeCode(schoolTombstone.getFacilityTypeCode())).orElse(null);
522524

523525
String schoolCode = school.isPresent() ? school.get().getMincode() : NO_SCHOOL_CODE_FOUND;
524526
String schoolName = school.map(SchoolTombstone::getDisplayName).orElse(NO_SCHOOL_NAME_FOUND);
525-
String finalFacilityType = facilityType.isPresent() ? facilityType.get().getLabel() : NO_FACILITY_TYPE_FOUND;
527+
String finalFacilityType = facilityType != null && facilityType.isPresent() ? facilityType.get().getLabel() : NO_FACILITY_TYPE_FOUND;
528+
526529
csvRowData.add(schoolCode);
527530
csvRowData.add(schoolName);
528531
csvRowData.add(finalFacilityType);
@@ -579,11 +582,11 @@ private List<Object> prepareFrenchStudentDataForCsv(SdcSchoolCollectionStudentLi
579582
if (Boolean.TRUE.equals(isDistrict)) {
580583
UUID schoolID = student.getSdcSchoolCollectionEntitySchoolID();
581584
Optional<SchoolTombstone> school = restUtils.getSchoolBySchoolID(schoolID.toString());
582-
var facilityType = restUtils.getFacilityTypeCode(school.get().getFacilityTypeCode());
585+
Optional<FacilityTypeCode> facilityType = school.map(schoolTombstone -> restUtils.getFacilityTypeCode(schoolTombstone.getFacilityTypeCode())).orElse(null);
583586

584587
String schoolCode = school.isPresent() ? school.get().getMincode() : NO_SCHOOL_CODE_FOUND;
585588
String schoolName = school.map(SchoolTombstone::getDisplayName).orElse(NO_SCHOOL_NAME_FOUND);
586-
String finalFacilityType = facilityType.isPresent() ? facilityType.get().getLabel() : NO_FACILITY_TYPE_FOUND;
589+
String finalFacilityType = facilityType != null && facilityType.isPresent() ? facilityType.get().getLabel() : NO_FACILITY_TYPE_FOUND;
587590

588591
csvRowData.add(schoolCode);
589592
csvRowData.add(schoolName);
@@ -617,11 +620,11 @@ private List<Object> prepareCareerStudentDataForCsv(SdcSchoolCollectionStudentLi
617620
if (Boolean.TRUE.equals(isDistrict)) {
618621
UUID schoolID = student.getSdcSchoolCollectionEntitySchoolID();
619622
Optional<SchoolTombstone> school = restUtils.getSchoolBySchoolID(schoolID.toString());
620-
var facilityType = restUtils.getFacilityTypeCode(school.get().getFacilityTypeCode());
623+
Optional<FacilityTypeCode> facilityType = school.map(schoolTombstone -> restUtils.getFacilityTypeCode(schoolTombstone.getFacilityTypeCode())).orElse(null);
621624

622625
String schoolCode = school.isPresent() ? school.get().getMincode() : NO_SCHOOL_CODE_FOUND;
623626
String schoolName = school.map(SchoolTombstone::getDisplayName).orElse(NO_SCHOOL_NAME_FOUND);
624-
String finalFacilityType = facilityType.isPresent() ? facilityType.get().getLabel() : NO_FACILITY_TYPE_FOUND;
627+
String finalFacilityType = facilityType != null && facilityType.isPresent() ? facilityType.get().getLabel() : NO_FACILITY_TYPE_FOUND;
625628

626629
csvRowData.add(schoolCode);
627630
csvRowData.add(schoolName);
@@ -656,11 +659,11 @@ private List<Object> prepareIndigenousStudentDataForCsv(SdcSchoolCollectionStude
656659
if (Boolean.TRUE.equals(isDistrict)) {
657660
UUID schoolID = student.getSdcSchoolCollectionEntitySchoolID();
658661
Optional<SchoolTombstone> school = restUtils.getSchoolBySchoolID(schoolID.toString());
659-
var facilityType = restUtils.getFacilityTypeCode(school.get().getFacilityTypeCode());
662+
Optional<FacilityTypeCode> facilityType = school.map(schoolTombstone -> restUtils.getFacilityTypeCode(schoolTombstone.getFacilityTypeCode())).orElse(null);
660663

661664
String schoolCode = school.isPresent() ? school.get().getMincode() : NO_SCHOOL_CODE_FOUND;
662665
String schoolName = school.map(SchoolTombstone::getDisplayName).orElse(NO_SCHOOL_NAME_FOUND);
663-
String finalFacilityType = facilityType.isPresent() ? facilityType.get().getLabel() : NO_FACILITY_TYPE_FOUND;
666+
String finalFacilityType = facilityType != null && facilityType.isPresent() ? facilityType.get().getLabel() : NO_FACILITY_TYPE_FOUND;
664667

665668
csvRowData.add(schoolCode);
666669
csvRowData.add(schoolName);
@@ -696,11 +699,11 @@ private List<Object> prepareInclusiveStudentDataForCsv(SdcSchoolCollectionStuden
696699
if (Boolean.TRUE.equals(isDistrict)) {
697700
UUID schoolID = student.getSdcSchoolCollectionEntitySchoolID();
698701
Optional<SchoolTombstone> school = restUtils.getSchoolBySchoolID(schoolID.toString());
699-
var facilityType = restUtils.getFacilityTypeCode(school.get().getFacilityTypeCode());
702+
Optional<FacilityTypeCode> facilityType = school.map(schoolTombstone -> restUtils.getFacilityTypeCode(schoolTombstone.getFacilityTypeCode())).orElse(null);
700703

701704
String schoolCode = school.isPresent() ? school.get().getMincode() : NO_SCHOOL_CODE_FOUND;
702705
String schoolName = school.map(SchoolTombstone::getDisplayName).orElse(NO_SCHOOL_NAME_FOUND);
703-
String finalFacilityType = facilityType.isPresent() ? facilityType.get().getLabel() : NO_FACILITY_TYPE_FOUND;
706+
String finalFacilityType = facilityType != null && facilityType.isPresent() ? facilityType.get().getLabel() : NO_FACILITY_TYPE_FOUND;
704707

705708
csvRowData.add(schoolCode);
706709
csvRowData.add(schoolName);
@@ -730,11 +733,11 @@ private List<Object> prepareEllStudentDataForCsv(SdcSchoolCollectionStudentLight
730733
if (Boolean.TRUE.equals(isDistrict)) {
731734
UUID schoolID = student.getSdcSchoolCollectionEntitySchoolID();
732735
Optional<SchoolTombstone> school = restUtils.getSchoolBySchoolID(schoolID.toString());
733-
var facilityType = restUtils.getFacilityTypeCode(school.get().getFacilityTypeCode());
736+
Optional<FacilityTypeCode> facilityType = school.map(schoolTombstone -> restUtils.getFacilityTypeCode(schoolTombstone.getFacilityTypeCode())).orElse(null);
734737

735738
String schoolCode = school.isPresent() ? school.get().getMincode() : NO_SCHOOL_CODE_FOUND;
736739
String schoolName = school.map(SchoolTombstone::getDisplayName).orElse(NO_SCHOOL_NAME_FOUND);
737-
String finalFacilityType = facilityType.isPresent() ? facilityType.get().getLabel() : NO_FACILITY_TYPE_FOUND;
740+
String finalFacilityType = facilityType != null && facilityType.isPresent() ? facilityType.get().getLabel() : NO_FACILITY_TYPE_FOUND;
738741

739742
csvRowData.add(schoolCode);
740743
csvRowData.add(schoolName);

0 commit comments

Comments
 (0)