Skip to content

Commit

Permalink
District level year end non graduation report (#592)
Browse files Browse the repository at this point in the history
* District level year end non graduation report

* Fix duplicated code

* Fix code smells

* Update YE query

* Update YE query

* Update YE query

* Update YE query

* Update YE query

* Update YE query

* Merge with grad-release

* Improve performance

* Fix sorting for school reports

* Added NONGRADDISTREP_SC report

* Fix report header

* Fix code smells

* Added missing test

* Scale font for headers

---------

Co-authored-by: Kamal Mohammed <kamal.mohammed@outlook.com>
  • Loading branch information
arybakov-cgi and kamal-mohammed authored Jul 21, 2023
1 parent 2623b77 commit 8fbf427
Show file tree
Hide file tree
Showing 36 changed files with 2,046 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class School implements Serializable {
Expand Down Expand Up @@ -120,7 +119,6 @@ public List<Student> getStudents() {

public void setStudents(List<Student> students) {
if(students != null) {
Collections.sort(students);
this.students = students;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.List;
import java.util.Objects;

public class Student implements Comparable<Student>, Serializable {
public class Student implements Serializable {

private Pen pen = new Pen();
private String firstName = "";
Expand Down Expand Up @@ -235,20 +235,6 @@ public void setLastUpdateDate(Date lastUpdateDate) {
this.lastUpdateDate = lastUpdateDate;
}

@Override
public int compareTo(Student student) {
String lastNameSt
= "" + student.lastName;
String firstNameSt
= "" + student.firstName;
String middleNameSt
= "" + student.middleName;
String gradProgramSt = "" + student.gradProgram;
String lastUpdateDateSt = "" + student.lastUpdateDate;
return "".concat(gradProgramSt).concat("" + getLastName()).concat("" + getFirstName()).concat("" + getMiddleName()).concat(lastUpdateDateSt)
.compareTo("".concat("" + getGradProgram()).concat(lastNameSt).concat(firstNameSt).concat(middleNameSt).concat("" + getLastUpdateDate()));
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@
import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceAdapter;

import java.lang.reflect.Type;
import java.util.Optional;

@ControllerAdvice
public class CustomRequestBodyAdviceAdapter extends RequestBodyAdviceAdapter {

@Autowired
JsonTransformer jsonTransformer;
final JsonTransformer jsonTransformer;

HttpServletRequest httpServletRequest;

@Autowired
public CustomRequestBodyAdviceAdapter(JsonTransformer jsonTransformer) {
this.jsonTransformer = jsonTransformer;
}

@Autowired
public void setHttpServletRequest(final HttpServletRequest httpServletRequest) {
this.httpServletRequest = httpServletRequest;
Expand All @@ -39,21 +44,25 @@ public boolean supports(final MethodParameter methodParameter, final Type type,
@SneakyThrows
public Object afterBodyRead(final Object body, final HttpInputMessage inputMessage, final MethodParameter parameter, final Type targetType,
final Class<? extends HttpMessageConverter<?>> converterType) {
Object bodyRequest;
if (body instanceof ReportRequest) {
ReportRequest cloneRequest = SerializationUtils.clone((ReportRequest)body);
Student st = cloneRequest.getData().getStudent();
hideStudentDataForLogging(st);
if(cloneRequest.getData().getSchool() != null) {
for (Student s : cloneRequest.getData().getSchool().getStudents()) {
hideStudentDataForLogging(s);
String appLogLevel = Optional.ofNullable(System.getenv("APP_LOG_LEVEL")).orElse("INFO");
boolean isDebugMode = "DEBUG".equalsIgnoreCase(appLogLevel);
if(isDebugMode) {
Object bodyRequest;
if (body instanceof ReportRequest) {
ReportRequest cloneRequest = SerializationUtils.clone((ReportRequest) body);
Student st = cloneRequest.getData().getStudent();
hideStudentDataForLogging(st);
if (cloneRequest.getData().getSchool() != null) {
for (Student s : cloneRequest.getData().getSchool().getStudents()) {
hideStudentDataForLogging(s);
}
}
bodyRequest = cloneRequest;
} else {
bodyRequest = body;
}
bodyRequest = cloneRequest;
} else {
bodyRequest = body;
this.httpServletRequest.setAttribute("payload", bodyRequest);
}
this.httpServletRequest.setAttribute("payload", bodyRequest);
return super.afterBodyRead(body, inputMessage, parameter, targetType, converterType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import org.springframework.context.annotation.*;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.integration.annotation.IntegrationComponentScan;
import org.springframework.integration.config.EnableIntegration;

import java.util.TimeZone;

@Configuration
@IntegrationComponentScan
@EnableIntegration
Expand All @@ -32,6 +30,7 @@ public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
ObjectMapper jacksonObjectMapper() {
return JsonMapper.builder()
.findAndAddModules()
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public ResponseEntity<byte[]> getSchoolDistributionYearEnd(@RequestBody ReportRe

@PostMapping(ReportApiConstants.DISTRICT_DISTRIBUTION_YEAR_END)
@PreAuthorize(PermissionsContants.SCHOOL_DISTRIBUTION)
@Operation(summary = "Generate School Distribution Report", description = "Generate School Distribution Report", tags = {"Report"})
@Operation(summary = "Generate District Distribution Report", description = "Generate District Distribution Year End Report", tags = {"Report"})
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<byte[]> getDistrictDistributionYearEnd(@RequestBody ReportRequest report, @RequestHeader(name = "Authorization") String accessToken) {
logger.debug("getDistrictDistributionYearEnd");
Expand All @@ -166,6 +166,23 @@ public ResponseEntity<byte[]> getDistrictDistributionYearEnd(@RequestBody Report
}
}

@PostMapping(ReportApiConstants.DISTRICT_DISTRIBUTION_YEAR_END_NONGRAD)
@PreAuthorize(PermissionsContants.SCHOOL_DISTRIBUTION)
@Operation(summary = "Generate District Distribution Report", description = "Generate District Distribution Year End Non Grad Report", tags = {"Report"})
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<byte[]> getDistrictDistributionYearEndNonGrad(@RequestBody ReportRequest report, @RequestHeader(name = "Authorization") String accessToken) {
logger.debug("getDistrictDistributionYearEndNonGrad");
logRequest(report);
setAccessToken(report, accessToken);
try {
String reportFile = report.getOptions().getReportFile();
byte[] resultBinary = reportService.getDistrictDistributionReportYearEndNonGrad(report);
return handleBinaryResponse(resultBinary, reportFile);
} catch (Exception e) {
return getInternalServerErrorResponse(e);
}
}

@PostMapping(ReportApiConstants.SCHOOL_LABEL)
@PreAuthorize(PermissionsContants.SCHOOL_LABEL)
@Operation(summary = "Generate School Label Report", description = "Generate School Label Report", tags = {"Report"})
Expand Down Expand Up @@ -217,9 +234,26 @@ public ResponseEntity<byte[]> getSchoolNonGraduation(@RequestBody ReportRequest
}
}

@PostMapping(ReportApiConstants.STUDENT_NON_GRAD_PROJECTED)
@PreAuthorize(PermissionsContants.STUDENT_NON_GRAD)
@Operation(summary = "Generate Student NonGraduate Projected Requirements Report", description = "Generate Student NonGraduate Projected Requirements Report", tags = {"Report"})
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<byte[]> getStudentNonGradProjected(@RequestBody ReportRequest report, @RequestHeader(name = "Authorization") String accessToken) {
logger.debug("getStudentNonGradProjected");
logRequest(report);
setAccessToken(report, accessToken);
try {
String reportFile = report.getOptions().getReportFile();
byte[] resultBinary = reportService.getStudentNonGradProjectedReport(report);
return handleBinaryResponse(resultBinary, reportFile);
} catch (Exception e) {
return getInternalServerErrorResponse(e);
}
}

@PostMapping(ReportApiConstants.STUDENT_NON_GRAD)
@PreAuthorize(PermissionsContants.STUDENT_NON_GRAD)
@Operation(summary = "Generate Student NonGraduate Requirements Report", description = "Generate Student NonGraduate Requirements Report", tags = {"Report"})
@Operation(summary = "Generate Student NonGraduate Report", description = "Generate Student NonGraduate Report", tags = {"Report"})
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<byte[]> getStudentNonGrad(@RequestBody ReportRequest report, @RequestHeader(name = "Authorization") String accessToken) {
logger.debug("getStudentNonGrad");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import ca.bc.gov.educ.grad.report.model.reports.ReportDocument;
import ca.bc.gov.educ.grad.report.model.reports.ReportFormat;
import ca.bc.gov.educ.grad.report.model.school.*;
import ca.bc.gov.educ.grad.report.model.student.SchoolNonGraduationService;
import ca.bc.gov.educ.grad.report.model.student.StudentNonGradReport;
import ca.bc.gov.educ.grad.report.model.student.StudentNonGradService;
import ca.bc.gov.educ.grad.report.model.student.*;
import ca.bc.gov.educ.grad.report.model.transcript.StudentTranscriptReport;
import ca.bc.gov.educ.grad.report.model.transcript.StudentTranscriptService;
import ca.bc.gov.educ.grad.report.model.transcript.StudentXmlTranscriptService;
Expand Down Expand Up @@ -74,6 +72,10 @@ public class GradReportService {
@Autowired
SchoolDistributionService districtDistributionEndYearCredentialsService;

@Qualifier("districtDistributionYearEndNonGradCredentialsServiceImpl")
@Autowired
SchoolDistributionService districtDistributionEndYearNonGradCredentialsService;

@Qualifier("schoolDistributionYearEndIssuedTranscriptsServiceImpl")
@Autowired
SchoolDistributionService schoolDistributionEndYearIssuedTranscriptsService;
Expand All @@ -87,6 +89,9 @@ public class GradReportService {
@Autowired
SchoolNonGraduationService schoolNonGraduationService;

@Autowired
StudentNonGradProjectedService studentNonGradProjectedService;

@Autowired
StudentNonGradService studentNonGradService;

Expand Down Expand Up @@ -290,6 +295,22 @@ public byte[] getDistrictDistributionReportYearEnd(ReportRequest reportRequest)
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
return response;
}

public byte[] getDistrictDistributionReportYearEndNonGrad(ReportRequest reportRequest) {
String methodName = "getDistrictDistributionReportYearEndNonGrad(ReportRequest reportRequest)";
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);

byte[] response = null;

try {
SchoolDistributionReport districtDistributionYearEndReport = getDistrictDistributionNonGradCredentialsReportDocument(reportRequest);
response = districtDistributionYearEndReport.asBytes();
} catch (Exception e) {
throw new ServiceException(String.format(EXCEPTION_MSG, methodName), e);
}
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
return response;
}

public byte[] getSchoolLabelReport(ReportRequest reportRequest) {
String methodName = "getSchoolLabelReport(ReportRequest reportRequest)";
Expand Down Expand Up @@ -339,6 +360,22 @@ public byte[] getSchoolNonGraduationReport(ReportRequest reportRequest) {
return response;
}

public byte[] getStudentNonGradProjectedReport(ReportRequest reportRequest) {
String methodName = "getStudentNonGradProjectedReport(ReportRequest reportRequest)";
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);

byte[] response = null;

try {
StudentNonGradProjectedReport studentNonGradProjectedReport = getStudentNonGradProjectedReportDocument(reportRequest);
response = studentNonGradProjectedReport.asBytes();
} catch (Exception e) {
throw new ServiceException(String.format(EXCEPTION_MSG, methodName), e);
}
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
return response;
}

public byte[] getStudentNonGradReport(ReportRequest reportRequest) {
String methodName = "getStudentNonGradReport(ReportRequest reportRequest)";
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
Expand Down Expand Up @@ -433,6 +470,15 @@ public SchoolNonGraduationReport getSchoolNonGraduationReportDocument(ReportRequ
return schoolNonGraduationService.buildSchoolNonGraduationReport();
}

public StudentNonGradProjectedReport getStudentNonGradProjectedReportDocument(ReportRequest reportRequest) throws IOException {
String methodName = "getStudentNonGradProjectedReportDocument(ReportRequest reportRequest)";
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);

ReportRequestDataThreadLocal.setReportData(reportRequest.getData());

return studentNonGradProjectedService.buildStudentNonGradProjectedReport();
}

public StudentNonGradReport getStudentNonGradReportDocument(ReportRequest reportRequest) throws IOException {
String methodName = "getStudentNonGradReportDocument(ReportRequest reportRequest)";
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
Expand All @@ -456,4 +502,9 @@ private SchoolDistributionReport getDistrictDistributionCredentialsReportDocumen
ReportRequestDataThreadLocal.setReportData(reportRequest.getData());
return this.districtDistributionEndYearCredentialsService.buildSchoolDistributionReport();
}

private SchoolDistributionReport getDistrictDistributionNonGradCredentialsReportDocument(ReportRequest reportRequest) throws IOException {
ReportRequestDataThreadLocal.setReportData(reportRequest.getData());
return this.districtDistributionEndYearNonGradCredentialsService.buildSchoolDistributionReport();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.transform.TransformerException;
import java.io.IOException;
import java.io.InputStream;

Expand All @@ -16,19 +15,19 @@ abstract class BaseTransformer implements Transformer {
ObjectMapper objectMapper;

@Override
public Object unmarshall(byte[] input, Class<?> clazz) throws TransformerException {
public Object unmarshall(byte[] input, Class<?> clazz) {
Object result = null;
long start = System.currentTimeMillis();
try {
result = objectMapper.readValue(input, clazz);
} catch (IOException e) {
throw new TransformerException(e);
log.error(e.getLocalizedMessage(), e);
}
log.debug("Time taken for unmarshalling response from bytes to {} is {} ms", clazz.getName(), (System.currentTimeMillis() - start));
return result;
}

public Object unmarshallWithWrapper(String input, Class<?> clazz) throws TransformerException {
public Object unmarshallWithWrapper(String input, Class<?> clazz) {
final ObjectReader reader = objectMapper.readerFor(clazz);
Object result = null;
long start = System.currentTimeMillis();
Expand All @@ -38,47 +37,47 @@ public Object unmarshallWithWrapper(String input, Class<?> clazz) throws Transfo
.with(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY)
.readValue(input);
} catch (IOException e) {
throw new TransformerException(e);
log.error(e.getLocalizedMessage(), e);
}
log.debug("Time taken for unmarshalling response from String to {} is {} ms", clazz.getSimpleName(), (System.currentTimeMillis() - start));
return result;
}

public String marshallWithWrapper(Object input) throws TransformerException {
public String marshallWithWrapper(Object input) {
ObjectWriter prettyPrinter = objectMapper.writer();//.writerWithDefaultPrettyPrinter();
String result = null;
try {
result = prettyPrinter
.with(SerializationFeature.WRAP_ROOT_VALUE)
.writeValueAsString(input);
} catch (IOException e) {
throw new TransformerException(e);
log.error(e.getLocalizedMessage(), e);
}

return result;
}

@Override
public Object unmarshall(String input, Class<?> clazz) throws TransformerException {
public Object unmarshall(String input, Class<?> clazz) {
Object result = null;
long start = System.currentTimeMillis();
try {
result = objectMapper.readValue(input, clazz);
} catch (IOException e) {
throw new TransformerException(e);
log.error(e.getLocalizedMessage(), e);
}
log.debug("Time taken for unmarshalling response from String to {} is {} ms", clazz.getName(), (System.currentTimeMillis() - start));
return result;
}

@Override
public Object unmarshall(InputStream input, Class<?> clazz) throws TransformerException {
public Object unmarshall(InputStream input, Class<?> clazz) {
Object result = null;
long start = System.currentTimeMillis();
try {
result = objectMapper.readValue(input, clazz);
} catch (IOException e) {
throw new TransformerException(e);
log.error(e.getLocalizedMessage(), e);
}
log.debug("Time taken for unmarshalling response from stream to {} is {} ms", clazz.getName(), (System.currentTimeMillis() - start));
return result;
Expand All @@ -97,13 +96,13 @@ public String marshall(Object input) {
}

@Override
public String marshallPrettyPrinter(Object input) throws TransformerException {
public String marshallPrettyPrinter(Object input) {
ObjectWriter prettyPrinter = objectMapper.writerWithDefaultPrettyPrinter();
String result = null;
try {
result = prettyPrinter.writeValueAsString(input);
} catch (IOException e) {
throw new TransformerException(e);
log.error(e.getLocalizedMessage(), e);
}

return result;
Expand Down
Loading

0 comments on commit 8fbf427

Please sign in to comment.