Search in sources :

Example 1 with BaseExceptionResponse

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();
}
Also used : BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) ConstraintViolation(javax.validation.ConstraintViolation) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails) HashSet(java.util.HashSet)

Example 2 with BaseExceptionResponse

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();
}
Also used : BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails) HashSet(java.util.HashSet)

Example 3 with BaseExceptionResponse

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();
}
Also used : Response(javax.ws.rs.core.Response) BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails) ErrorMessage(io.dropwizard.jersey.errors.ErrorMessage) HashSet(java.util.HashSet)

Example 4 with BaseExceptionResponse

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();
}
Also used : BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails) HashSet(java.util.HashSet)

Example 5 with BaseExceptionResponse

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()));
}
Also used : BaseExceptionResponse(gov.ca.cwds.rest.exception.BaseExceptionResponse) Test(org.junit.Test)

Aggregations

BaseExceptionResponse (gov.ca.cwds.rest.exception.BaseExceptionResponse)23 IssueDetails (gov.ca.cwds.rest.exception.IssueDetails)22 Test (org.junit.Test)16 HashMap (java.util.HashMap)12 RFA1aFormDTO (gov.ca.cwds.cals.service.dto.rfa.RFA1aFormDTO)11 ApplicantDTO (gov.ca.cwds.cals.service.dto.rfa.ApplicantDTO)10 Map (java.util.Map)10 Set (java.util.Set)10 ClientErrorException (javax.ws.rs.ClientErrorException)10 Response (javax.ws.rs.core.Response)6 BaseRFAIntegrationTest (gov.ca.cwds.cals.web.rest.rfa.BaseRFAIntegrationTest)5 HashSet (java.util.HashSet)4 VelocityHelper (gov.ca.cwds.cals.web.rest.utils.VelocityHelper)3 WebTarget (javax.ws.rs.client.WebTarget)3 ErrorMessage (io.dropwizard.jersey.errors.ErrorMessage)1 ConstraintViolation (javax.validation.ConstraintViolation)1 Invocation (javax.ws.rs.client.Invocation)1