use of gov.ca.cwds.rest.exception.BaseExceptionResponse in project api-core by ca-cwds.
the class CustomJerseyViolationExceptionMapper method toResponse.
@Override
public Response toResponse(final JerseyViolationException exception) {
final Set<IssueDetails> validationDetailsList = new HashSet<>();
final Set<ConstraintViolation<?>> transgressions = exception.getConstraintViolations();
for (ConstraintViolation<?> v : transgressions) {
String message = CustomConstraintMessage.getMessage(v, exception.getInvocable()).trim();
IssueDetails details = unmarshallData(message);
if (details != null) {
details.setType(IssueType.BUSINESS_VALIDATION);
} else {
details = IssueDetailsCreator.create(v, loggingContext.getUniqueId());
}
details.setIncidentId(loggingContext.getUniqueId());
validationDetailsList.add(details);
}
BaseExceptionResponse constraintViolationsResponse = new BaseExceptionResponse();
constraintViolationsResponse.setIssueDetails(validationDetailsList);
int status = CustomConstraintMessage.determineStatus(exception.getConstraintViolations(), exception.getInvocable());
return Response.status(status).type(MediaType.APPLICATION_JSON_TYPE).entity(constraintViolationsResponse).build();
}
use of gov.ca.cwds.rest.exception.BaseExceptionResponse in project api-core by ca-cwds.
the class ExpectedExceptionMapperImpl method toResponse.
@Override
public Response toResponse(ExpectedException exception) {
IssueDetails details = new IssueDetails();
details.setType(IssueType.EXPECTED_EXCEPTION);
details.setIncidentId(loggingContext.getUniqueId());
details.setTechnicalMessage(exception.getMessage());
details.setUserMessage(BASE_MESSAGE);
Set<IssueDetails> detailsList = new HashSet<>();
detailsList.add(details);
BaseExceptionResponse expectedExceptionResponse = new BaseExceptionResponse();
expectedExceptionResponse.setIssueDetails(detailsList);
return Response.status(exception.getResponseStatus()).entity(expectedExceptionResponse).type(MediaType.APPLICATION_JSON).build();
}
use of gov.ca.cwds.rest.exception.BaseExceptionResponse in project api-core by ca-cwds.
the class CustomJsonProcessingExceptionMapper method toResponse.
@Override
public Response toResponse(JsonProcessingException exception) {
Response response = super.toResponse(exception);
if (!(response.getEntity() instanceof ErrorMessage)) {
throw new IllegalStateException("ErrorMessage class is expected here");
}
ErrorMessage errorMessage = (ErrorMessage) response.getEntity();
IssueDetails details = new IssueDetails();
details.setType(IssueType.JSON_PROCESSING_EXCEPTION);
details.setIncidentId(loggingContext.getUniqueId());
details.setUserMessage(BASE_MESSAGE);
details.setTechnicalMessage(StringUtils.join(new Object[] { errorMessage.getMessage(), errorMessage.getDetails() }, ". "));
Set<IssueDetails> detailsList = new HashSet<>();
detailsList.add(details);
BaseExceptionResponse jsonProcessingExceptionResponse = new BaseExceptionResponse();
jsonProcessingExceptionResponse.setIssueDetails(detailsList);
return Response.status(response.getStatus()).type(response.getMediaType()).entity(jsonProcessingExceptionResponse).build();
}
use of gov.ca.cwds.rest.exception.BaseExceptionResponse in project api-core by ca-cwds.
the class ExceptionMapperUtils method createGenericResponse.
/**
* Create a generic exception response
*
* @param ex The exception
* @param issueType Issue type
* @param status Response status
* @param incidentId Incident ID
* @return A generic Response created from given exception
*/
public static Response createGenericResponse(Exception ex, IssueType issueType, int status, String incidentId) {
IssueDetails issueDetails = new IssueDetails();
issueDetails.setType(issueType);
issueDetails.setIncidentId(incidentId);
issueDetails.setUserMessage(BASE_MESSAGE);
issueDetails.setTechnicalMessage(ex.getMessage());
if (ex.getCause() != null) {
issueDetails.setTechnicalMessage(ex.getCause().getMessage());
issueDetails.setCauseStackTrace(StringEscapeUtils.escapeJson(ExceptionUtils.getStackTrace(ex.getCause())));
}
issueDetails.setStackTrace(StringEscapeUtils.escapeJson(ExceptionUtils.getStackTrace(ex)));
final Set<IssueDetails> detailsList = new HashSet<>();
detailsList.add(issueDetails);
final BaseExceptionResponse response = new BaseExceptionResponse();
response.setIssueDetails(detailsList);
return Response.status(status).entity(response).type(MediaType.APPLICATION_JSON).build();
}
use of gov.ca.cwds.rest.exception.BaseExceptionResponse in project cals-api by ca-cwds.
the class RFA1aSubmitValidationTest method validateAdultChildrenAndOtherAdultsCorrelation.
@Test
public void validateAdultChildrenAndOtherAdultsCorrelation() throws Exception {
// There are Other Adults-children added to Other Adults Section
// and not all of them added to Adult Children Section
// There are grown-up children living in home (Adult Children Section)
// and not all of them is added to Other Adults section
Long formId = formAHelper.createRFA1aForm().getId();
ResidenceDTO residence = residenceHelper.getResidenceDTO();
residenceHelper.putResidence(formId, residence);
ApplicantDTO applicantDTO = applicantHelper.postApplicant(formId);
otherAdultHelper.postOtherAdult(formId, otherAdultHelper.getOtherAdultDTO(applicantDTO, FixtureHelpers.fixture("fixtures/rfa/validation/adultchildren/rfa-1a-other-adults1.json")));
otherAdultHelper.postOtherAdult(formId, otherAdultHelper.getOtherAdultDTO(applicantDTO, FixtureHelpers.fixture("fixtures/rfa/validation/adultchildren/rfa-1a-other-adults2.json")));
otherAdultHelper.postOtherAdult(formId, otherAdultHelper.getOtherAdultDTO(applicantDTO, FixtureHelpers.fixture("fixtures/rfa/validation/adultchildren/rfa-1a-other-adults3.json")));
otherAdultHelper.postOtherAdult(formId, otherAdultHelper.getOtherAdultDTO(applicantDTO, FixtureHelpers.fixture("fixtures/rfa/validation/adultchildren/rfa-1a-other-adults4.json")));
formBHelper.postRfa1bForm(formId, applicantDTO.getId(), formBHelper.getRfa1bForm());
/*formBHelper.postRfa1bForm(formId, applicantDTO.getId(), formBHelper.getRfa1bForm());
formBHelper.postRfa1bForm(formId, applicantDTO.getId(), formBHelper.getRfa1bForm());
formBHelper.postRfa1bForm(formId, applicantDTO.getId(), formBHelper.getRfa1bForm());
formBHelper.postRfa1bForm(formId, applicantDTO.getId(), formBHelper.getRfa1bForm());*/
applicantsHistoryHelper.putApplicantsHistory(formId, applicantsHistoryHelper.getApplicantHistoryDTO("fixtures/rfa/validation/adultchildren/rfa-1a-applicants-history.json"));
BaseExceptionResponse actualResponse = statusHelper.submitApplication(formId).readEntity(BaseExceptionResponse.class);
BaseExceptionResponse expectedResponse = Jackson.newObjectMapper().readValue(FixtureHelpers.fixture("fixtures/rfa/validation/adultchildren/adult-children-validation-violation-response.json"), BaseExceptionResponse.class);
assertTrue(CollectionUtils.isEqualCollection(expectedResponse.getIssueDetails(), actualResponse.getIssueDetails(), new CustomEquator()));
}
Aggregations