@@ -175,6 +175,31 @@ public DownloadableReportResponse generateFrenchFromSdcDistrictCollectionID(UUID
175
175
}
176
176
}
177
177
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
+
178
203
private List <Object > prepareStudentDataWithErrorsAndWarningsForCsv (SdcSchoolCollectionStudentEntity student , boolean isDistrict ) {
179
204
List <Object > csvRowData = new ArrayList <>();
180
205
if (Boolean .TRUE .equals (isDistrict )) {
@@ -356,6 +381,46 @@ private List<Object> prepareFrenchStudentDataForCsv(SdcSchoolCollectionStudentLi
356
381
return csvRowData ;
357
382
}
358
383
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
+
359
424
public String formatFullName (String firstName , String middleNames , String lastName ) {
360
425
StringBuilder fullName = new StringBuilder ();
361
426
0 commit comments