Skip to content

Commit

Permalink
Grad release 1.11.0
Browse files Browse the repository at this point in the history
Grad release 1.11.0
  • Loading branch information
kamal-mohammed authored Dec 7, 2023
2 parents c0cf384 + dad5899 commit bea86a8
Show file tree
Hide file tree
Showing 39 changed files with 533 additions and 269 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>ca.bc.gov.educ</groupId>
<artifactId>educ-grad-report-api</artifactId>
<name>educ-grad-report-api</name>
<version>1.8.54</version>
<version>1.8.55</version>
<description>Ministry of Education and Child Care REPORT API</description>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import ca.bc.gov.educ.grad.report.api.service.utils.JsonTransformer;
import ca.bc.gov.educ.grad.report.api.util.JwtTokenUtil;
import ca.bc.gov.educ.grad.report.dao.ReportRequestDataThreadLocal;
import ca.bc.gov.educ.grad.report.exception.InvalidParameterException;
import ca.bc.gov.educ.grad.report.utils.EducGradReportApiConstants;
import ca.bc.gov.educ.grad.report.utils.GradValidation;
import jakarta.servlet.http.HttpServletRequest;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -23,11 +25,16 @@
import java.net.InetAddress;
import java.net.UnknownHostException;

import static ca.bc.gov.educ.grad.report.utils.EducGradReportApiConstants.NO_ELIGIBLE_COURSES_TRANSCRIPT_REPORT_IS_NOT_CREATED;

public abstract class BaseController {

private static final String CLASS_NAME = BaseController.class.getName();
private static Logger log = LoggerFactory.getLogger(CLASS_NAME);

@Autowired
GradValidation validation;

@Value("${endpoint.educ-grad-report-api.get-signature-by-code.url}")
String signatureImageUrlProperty;

Expand All @@ -40,7 +47,7 @@ protected void logRequest(Object request) {
((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
.getRequest();

StringBuffer requestURL = httpServletRequest.getRequestURL();
StringBuilder requestURL = new StringBuilder(httpServletRequest.getRequestURL().toString());
if (httpServletRequest.getQueryString() != null) {
requestURL.append("?").append(httpServletRequest.getQueryString());
}
Expand Down Expand Up @@ -75,36 +82,48 @@ protected void logRequest(Object request) {
String method = httpServletRequest.getMethod();
String accessTokenParam = "?access_token=" + accessToken;
signatureImageUrl = protocol + serverName + ":" + port + path + accessTokenParam;
log.debug(username + ": " + method + "->" + signatureImageUrl);
log.debug("{}: {}->{}", username, method, signatureImageUrl);
} else {
String accessTokenParam = "?access_token=" + accessToken;
signatureImageUrl = signatureImageUrlProperty + "/#signatureCode#" + accessTokenParam;
log.debug(signatureImageUrl);
}
if (StringUtils.trimToNull(signatureImageUrl) == null) {
throw new RuntimeException("signatureImageUrl is undefined");
throw new InvalidParameterException("signatureImageUrl is undefined");
}
ReportRequestDataThreadLocal.setSignatureImageUrl(signatureImageUrl);

}

protected ResponseEntity<byte[]> getInternalServerErrorResponse(Throwable t) {
ResponseEntity<byte[]> result = null;

if(validation.containsError(NO_ELIGIBLE_COURSES_TRANSCRIPT_REPORT_IS_NOT_CREATED)) {
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;

StringBuilder sb = new StringBuilder();
if(validation.hasErrors()) {
for(String error: validation.getErrors()) {
sb.append(error).append('\n');
}
httpStatus = HttpStatus.BAD_REQUEST;
}

Throwable tmp = t;
String message = null;
String message = sb.toString();
if (tmp.getCause() != null) {
tmp = tmp.getCause();
message = tmp.getMessage();
} else {
}
if(StringUtils.isBlank(message)) {
message = tmp.getMessage();
}
if(message == null) {
if(StringUtils.isBlank(message)) {
message = tmp.getClass().getName();
}

result = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(message.getBytes());
return result;
return ResponseEntity.status(httpStatus).body(message.getBytes());
}

protected ResponseEntity<byte[]> handleBinaryResponse(byte[] resultBinary, String reportFile) {
Expand All @@ -114,16 +133,27 @@ protected ResponseEntity<byte[]> handleBinaryResponse(byte[] resultBinary, Strin
protected ResponseEntity<byte[]> handleBinaryResponse(byte[] resultBinary, String reportFile, MediaType contentType) {
ResponseEntity<byte[]> response = null;

if(resultBinary.length > 0) {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Disposition", "inline; filename=" + reportFile);
response = ResponseEntity
.ok()
.headers(headers)
.contentType(contentType)
.body(resultBinary);
if(validation.containsError(NO_ELIGIBLE_COURSES_TRANSCRIPT_REPORT_IS_NOT_CREATED)) {
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
StringBuilder sb = new StringBuilder();
if(validation.hasErrors()) {
for(String error: validation.getErrors()) {
sb.append(error).append('\n');
}
response = ResponseEntity.status(HttpStatus.BAD_REQUEST).body(sb.toString().getBytes());
} else {
response = ResponseEntity.status(HttpStatus.NO_CONTENT).build();
if (resultBinary.length > 0) {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Disposition", "inline; filename=" + reportFile);
response = ResponseEntity
.ok()
.headers(headers)
.contentType(contentType)
.body(resultBinary);
} else {
response = ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import ca.bc.gov.educ.grad.report.dto.reports.bundle.decorator.SchoolReportOrderTypeImpl;
import ca.bc.gov.educ.grad.report.dto.reports.bundle.service.BCMPBundleService;
import ca.bc.gov.educ.grad.report.dto.reports.bundle.service.DocumentBundle;
import ca.bc.gov.educ.grad.report.exception.ServiceException;
import ca.bc.gov.educ.grad.report.exception.ReportApiServiceException;
import ca.bc.gov.educ.grad.report.model.achievement.StudentAchievementReport;
import ca.bc.gov.educ.grad.report.model.achievement.StudentAchievementService;
import ca.bc.gov.educ.grad.report.model.common.BusinessReport;
Expand Down Expand Up @@ -108,7 +108,7 @@ public byte[] getPackingSlipReport(ReportRequest reportRequest) {
ReportDocument report = getPackingSlipReportDocument(reportRequest);
response = report.asBytes();
} catch (Exception e) {
throw new ServiceException(String.format(EXCEPTION_MSG, methodName), e);
throw new ReportApiServiceException(String.format(EXCEPTION_MSG, methodName), e);
}
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
return response;
Expand Down Expand Up @@ -145,7 +145,7 @@ public byte[] getStudentAchievementReport(ReportRequest reportRequest) {
StudentAchievementReport report = getStudentAchievementReportDocument(reportRequest);
response = report.getReportData();
} catch (Exception e) {
throw new ServiceException(String.format(EXCEPTION_MSG, methodName), e);
throw new ReportApiServiceException(String.format(EXCEPTION_MSG, methodName), e);
}
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
return response;
Expand All @@ -172,7 +172,7 @@ public byte[] getStudentTranscriptReport(ReportRequest reportRequest) {
StudentTranscriptReport report = getStudentTranscriptReportDocument(reportRequest);
response = report.getReportData();
} catch (Exception e) {
throw new ServiceException(String.format(EXCEPTION_MSG, methodName), e);
throw new ReportApiServiceException(String.format(EXCEPTION_MSG, methodName), e);
}
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
return response;
Expand All @@ -199,7 +199,7 @@ public byte[] getStudentXmlTranscriptReport(XmlReportRequest reportRequest) {
StudentTranscriptReport transcriptReport = getStudentXmlTranscriptReportDocument(reportRequest);
response = transcriptReport.asBytes();
} catch (Exception e) {
throw new ServiceException(String.format(EXCEPTION_MSG, methodName), e);
throw new ReportApiServiceException(String.format(EXCEPTION_MSG, methodName), e);
}
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
return response;
Expand All @@ -224,7 +224,7 @@ public byte[] getStudentCertificateReport(ReportRequest reportRequest) {
DocumentBundle documentBundle = getStudentCertificateReportDocument(reportRequest);
response = documentBundle.asBytes();
} catch (Exception e) {
throw new ServiceException(String.format(EXCEPTION_MSG, methodName), e);
throw new ReportApiServiceException(String.format(EXCEPTION_MSG, methodName), e);
}
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
return response;
Expand Down Expand Up @@ -258,7 +258,7 @@ public byte[] getSchoolDistributionReport(ReportRequest reportRequest) {
SchoolDistributionReport schoolDistributionReport = getSchoolDistributionReportDocument(reportRequest);
response = schoolDistributionReport.asBytes();
} catch (Exception e) {
throw new ServiceException(String.format(EXCEPTION_MSG, methodName), e);
throw new ReportApiServiceException(String.format(EXCEPTION_MSG, methodName), e);
}
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
return response;
Expand All @@ -274,7 +274,7 @@ public byte[] getSchoolDistributionReportYearEnd(ReportRequest reportRequest) {
DocumentBundle schoolDistributionYearEndReport = getSchoolDistributionYearEndReportDocument(reportRequest);
response = schoolDistributionYearEndReport.asBytes();
} catch (Exception e) {
throw new ServiceException(String.format(EXCEPTION_MSG, methodName), e);
throw new ReportApiServiceException(String.format(EXCEPTION_MSG, methodName), e);
}
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
return response;
Expand All @@ -290,7 +290,7 @@ public byte[] getDistrictDistributionReportYearEnd(ReportRequest reportRequest)
SchoolDistributionReport districtDistributionYearEndReport = getDistrictDistributionCredentialsReportDocument(reportRequest);
response = districtDistributionYearEndReport.asBytes();
} catch (Exception e) {
throw new ServiceException(String.format(EXCEPTION_MSG, methodName), e);
throw new ReportApiServiceException(String.format(EXCEPTION_MSG, methodName), e);
}
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
return response;
Expand All @@ -306,7 +306,7 @@ public byte[] getDistrictDistributionReportYearEndNonGrad(ReportRequest reportRe
SchoolDistributionReport districtDistributionYearEndReport = getDistrictDistributionNonGradCredentialsReportDocument(reportRequest);
response = districtDistributionYearEndReport.asBytes();
} catch (Exception e) {
throw new ServiceException(String.format(EXCEPTION_MSG, methodName), e);
throw new ReportApiServiceException(String.format(EXCEPTION_MSG, methodName), e);
}
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
return response;
Expand All @@ -322,7 +322,7 @@ public byte[] getSchoolLabelReport(ReportRequest reportRequest) {
SchoolLabelReport schoolLabelReport = getSchoolLabelReportDocument(reportRequest);
response = schoolLabelReport.asBytes();
} catch (Exception e) {
throw new ServiceException(String.format(EXCEPTION_MSG, methodName), e);
throw new ReportApiServiceException(String.format(EXCEPTION_MSG, methodName), e);
}
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
return response;
Expand All @@ -338,7 +338,7 @@ public byte[] getSchoolGraduationReport(ReportRequest reportRequest) {
SchoolGraduationReport schoolGraduationReport = getSchoolGraduationReportDocument(reportRequest);
response = schoolGraduationReport.asBytes();
} catch (Exception e) {
throw new ServiceException(String.format(EXCEPTION_MSG, methodName), e);
throw new ReportApiServiceException(String.format(EXCEPTION_MSG, methodName), e);
}
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
return response;
Expand All @@ -354,7 +354,7 @@ public byte[] getSchoolNonGraduationReport(ReportRequest reportRequest) {
SchoolNonGraduationReport schoolNonGraduationReport = getSchoolNonGraduationReportDocument(reportRequest);
response = schoolNonGraduationReport.asBytes();
} catch (Exception e) {
throw new ServiceException(String.format(EXCEPTION_MSG, methodName), e);
throw new ReportApiServiceException(String.format(EXCEPTION_MSG, methodName), e);
}
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
return response;
Expand All @@ -370,7 +370,7 @@ public byte[] getStudentNonGradProjectedReport(ReportRequest reportRequest) {
StudentNonGradProjectedReport studentNonGradProjectedReport = getStudentNonGradProjectedReportDocument(reportRequest);
response = studentNonGradProjectedReport.asBytes();
} catch (Exception e) {
throw new ServiceException(String.format(EXCEPTION_MSG, methodName), e);
throw new ReportApiServiceException(String.format(EXCEPTION_MSG, methodName), e);
}
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
return response;
Expand All @@ -386,7 +386,7 @@ public byte[] getStudentNonGradReport(ReportRequest reportRequest) {
StudentNonGradReport studentNonGradReport = getStudentNonGradReportDocument(reportRequest);
response = studentNonGradReport.asBytes();
} catch (Exception e) {
throw new ServiceException(String.format(EXCEPTION_MSG, methodName), e);
throw new ReportApiServiceException(String.format(EXCEPTION_MSG, methodName), e);
}
log.debug(DEBUG_LOG_PATTERN, methodName, CLASS_NAME);
return response;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ca.bc.gov.educ.grad.report.api.service.utils;

import ca.bc.gov.educ.grad.report.exception.ServiceException;
import ca.bc.gov.educ.grad.report.exception.ReportApiServiceException;
import com.fasterxml.jackson.databind.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -46,7 +46,7 @@ public Object unmarshallWithWrapper(String input, Class<?> clazz) {
}

public String marshallWithWrapper(Object input) {
ObjectWriter prettyPrinter = objectMapper.writer();//.writerWithDefaultPrettyPrinter();
ObjectWriter prettyPrinter = objectMapper.writer();
String result = null;
try {
result = prettyPrinter
Expand Down Expand Up @@ -91,7 +91,7 @@ public String marshall(Object input) {
try {
result = objectMapper.writeValueAsString(input);
} catch (IOException e) {
throw new ServiceException(e.getMessage());
throw new ReportApiServiceException(e.getMessage(), e);
}

return result;
Expand All @@ -110,12 +110,4 @@ public String marshallPrettyPrinter(Object input) {
return result;
}

@Override
public abstract String getAccept();

@Override
public abstract String getFormat();

@Override
public abstract String getContentType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import ca.bc.gov.educ.grad.report.model.transcript.TranscriptCourse;
import ca.bc.gov.educ.grad.report.model.transcript.TranscriptTypeCode;
import ca.bc.gov.educ.grad.report.service.impl.BaseServiceImpl;
import ca.bc.gov.educ.grad.report.utils.GradValidation;
import ca.bc.gov.educ.grad.report.utils.TotalCounts;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.RandomStringUtils;
Expand All @@ -38,16 +39,20 @@
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;

import static ca.bc.gov.educ.grad.report.utils.EducGradReportApiConstants.NO_ELIGIBLE_COURSES_TRANSCRIPT_REPORT_IS_NOT_CREATED;

@Component
public class GradDataConvertionBean extends BaseServiceImpl implements Serializable {
public class GradDataConvertionBean extends BaseServiceImpl {

private static final String CLASS_NAME = GradDataConvertionBean.class.getName();
private static final Logger log = LoggerFactory.getLogger(CLASS_NAME);
private static final Logger logger = LoggerFactory.getLogger(CLASS_NAME);

@Autowired
GradValidation validation;

@Autowired
TranscriptTypeCodeRepository transcriptTypeCodeRepository;
Expand Down Expand Up @@ -196,7 +201,7 @@ public School getSchool(ReportData reportData) {
}

public List<TranscriptCourse> getTranscriptCourses(ReportData reportData) {
Student student = getStudent(reportData);
final Student student = getStudent(reportData);
List<TranscriptCourse> result = new ArrayList<>();
if (reportData.getTranscript() != null && reportData.getTranscript().getResults() != null) {
for (ca.bc.gov.educ.grad.report.api.client.TranscriptResult r : reportData.getTranscript().getResults()) {
Expand Down Expand Up @@ -224,6 +229,12 @@ public List<TranscriptCourse> getTranscriptCourses(ReportData reportData) {
result.add(course);
}
}
final String pen = student.getPen().getValue();
if(StringUtils.isNotBlank(pen) && result.isEmpty()) {
String message = NO_ELIGIBLE_COURSES_TRANSCRIPT_REPORT_IS_NOT_CREATED;
logger.warn(message);
validation.addErrorAndStop(message);
}
return result;
}

Expand Down Expand Up @@ -439,7 +450,7 @@ public Pair<List<Student>, TotalCounts> getStudents(ReportData reportData) {
List<ca.bc.gov.educ.grad.report.api.client.Student> students = school.getStudents();
for (ca.bc.gov.educ.grad.report.api.client.Student st : students) {
if(st.getPen() == null || StringUtils.isBlank(st.getPen().getPen())) {
log.warn("Skip Student {} without Pen #", st.getPen().getEntityID());
logger.warn("Skip Student {} without Pen #", st.getPen().getEntityID());
continue;
}
StudentImpl student = new StudentImpl();
Expand All @@ -449,7 +460,7 @@ public Pair<List<Student>, TotalCounts> getStudents(ReportData reportData) {
student.setPen(pen);

if(result.add(student)) {
log.debug("Student {} added into unique collection for report", student);
logger.debug("Student {} added into unique collection for report", student);
} else {
continue;
}
Expand Down Expand Up @@ -491,7 +502,7 @@ public Pair<List<Student>, TotalCounts> getStudents(ReportData reportData) {
List<String> studentCertificateTypeCodes = new ArrayList<>();
if(st.getGraduationStatus() != null && StringUtils.isNotBlank(st.getGraduationStatus().getCertificates())) {
String studentCertificateTypeCodesString = st.getGraduationStatus().getCertificates();
log.debug("Process student {} certificate credentials {}", student.getPen(), studentCertificateTypeCodesString);
logger.debug("Process student {} certificate credentials {}", student.getPen(), studentCertificateTypeCodesString);
studentCertificateTypeCodes = Arrays.asList(StringUtils.split(studentCertificateTypeCodesString, ","));
}

Expand Down
Loading

0 comments on commit bea86a8

Please sign in to comment.