Search in sources :

Example 1 with BusinessValidationException

use of gov.ca.cwds.rest.exception.BusinessValidationException in project api-core by ca-cwds.

the class R03855Test method testMaxAgeInvalid.

@Test
public void testMaxAgeInvalid() throws Exception {
    PlacementHome placementHome = new PlacementHome();
    placementHome.setAgeToNo((short) 27);
    try {
        runBusinessValidation(placementHome);
        fail();
    } catch (BusinessValidationException e) {
        assert e.getValidationDetailsList().stream().anyMatch(issueDetails -> issueDetails.getCode().equals("R-03855"));
    }
}
Also used : DroolsException(gov.ca.cwds.drools.DroolsException) PlacementHome(gov.ca.cwds.data.legacy.cms.entity.PlacementHome) PlacementHomeDroolsConfiguration(gov.ca.cwds.cms.data.access.service.rules.PlacementHomeDroolsConfiguration) BaseDocToolRulesPlacementHomeTest(gov.ca.cwds.cms.data.access.service.impl.placementHome.BaseDocToolRulesPlacementHomeTest) BusinessValidationException(gov.ca.cwds.rest.exception.BusinessValidationException) Assert.fail(org.junit.Assert.fail) Test(org.junit.Test) PlacementHome(gov.ca.cwds.data.legacy.cms.entity.PlacementHome) BusinessValidationException(gov.ca.cwds.rest.exception.BusinessValidationException) BaseDocToolRulesPlacementHomeTest(gov.ca.cwds.cms.data.access.service.impl.placementHome.BaseDocToolRulesPlacementHomeTest) Test(org.junit.Test)

Example 2 with BusinessValidationException

use of gov.ca.cwds.rest.exception.BusinessValidationException in project cals-api by ca-cwds.

the class RFA1aFormService method submitApplication.

/**
 * There is using XA Transaction
 */
private void submitApplication(Long formId, RFAApplicationStatus newStatus) throws NotSupportedException, SystemException, DroolsException {
    RFA1aFormDTO expandedFormDTO = getExpandedFormDTO(formId);
    performSubmissionValidation(expandedFormDTO);
    // Start transaction here
    UserTransaction userTransaction = new UserTransactionImp();
    userTransaction.setTransactionTimeout(3600);
    userTransaction.begin();
    PlacementHome storedPlacementHome = null;
    try {
        storedPlacementHome = storePlaceMentHome(expandedFormDTO);
        updateFormAfterPlacementHomeCreation(formId, storedPlacementHome.getIdentifier(), newStatus);
        userTransaction.commit();
    } catch (BusinessValidationException e) {
        userTransaction.rollback();
        LOG.error("Can not create Placement Home because of BusinessValidationException", e);
        throw e;
    } catch (UnauthorizedException e) {
        userTransaction.rollback();
        LOG.error("Can not create Placement Home because of UnauthorizedException", e);
        throw e;
    } catch (Exception e) {
        try {
            userTransaction.rollback();
        } catch (Exception re) {
            LOG.warn(re.getMessage(), re);
        }
        StringBuilder sb = new StringBuilder();
        sb.append(e.getMessage());
        sb.append('\n');
        Throwable cause = e.getCause();
        while (cause != null) {
            sb.append(" Cause: ");
            sb.append(cause.getMessage());
            sb.append('\n');
            cause = cause.getCause();
        }
        LOG.error("Can not create Placement Home: \n", e);
        throw new SystemException(sb.toString());
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) SystemException(javax.transaction.SystemException) PlacementHome(gov.ca.cwds.data.legacy.cms.entity.PlacementHome) RFA1aFormDTO(gov.ca.cwds.cals.service.dto.rfa.RFA1aFormDTO) BusinessValidationException(gov.ca.cwds.rest.exception.BusinessValidationException) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) UserTransactionImp(com.atomikos.icatch.jta.UserTransactionImp) DataAccessServicesException(gov.ca.cwds.cms.data.access.service.DataAccessServicesException) ExpectedException(gov.ca.cwds.rest.exception.ExpectedException) NotSupportedException(javax.transaction.NotSupportedException) DroolsException(gov.ca.cwds.drools.DroolsException) ConstraintViolationException(javax.validation.ConstraintViolationException) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) SystemException(javax.transaction.SystemException) BusinessValidationException(gov.ca.cwds.rest.exception.BusinessValidationException)

Example 3 with BusinessValidationException

use of gov.ca.cwds.rest.exception.BusinessValidationException in project cals-api by ca-cwds.

the class RFA1aFormService method performSubmissionValidation.

private void performSubmissionValidation(RFA1aFormDTO formDTO) throws DroolsException {
    Validator validator = environment.getValidator();
    Optional.ofNullable(validator.validate(formDTO)).ifPresent(violations -> {
        if (!violations.isEmpty()) {
            throw new ConstraintViolationException(violations);
        }
    });
    Set<IssueDetails> detailsList = droolsService.performBusinessRules(createConfiguration(), formDTO);
    if (!detailsList.isEmpty()) {
        throw new BusinessValidationException(detailsList);
    }
}
Also used : BusinessValidationException(gov.ca.cwds.rest.exception.BusinessValidationException) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails) ConstraintViolationException(javax.validation.ConstraintViolationException) Validator(javax.validation.Validator)

Aggregations

BusinessValidationException (gov.ca.cwds.rest.exception.BusinessValidationException)3 PlacementHome (gov.ca.cwds.data.legacy.cms.entity.PlacementHome)2 DroolsException (gov.ca.cwds.drools.DroolsException)2 ConstraintViolationException (javax.validation.ConstraintViolationException)2 UserTransactionImp (com.atomikos.icatch.jta.UserTransactionImp)1 RFA1aFormDTO (gov.ca.cwds.cals.service.dto.rfa.RFA1aFormDTO)1 DataAccessServicesException (gov.ca.cwds.cms.data.access.service.DataAccessServicesException)1 BaseDocToolRulesPlacementHomeTest (gov.ca.cwds.cms.data.access.service.impl.placementHome.BaseDocToolRulesPlacementHomeTest)1 PlacementHomeDroolsConfiguration (gov.ca.cwds.cms.data.access.service.rules.PlacementHomeDroolsConfiguration)1 ExpectedException (gov.ca.cwds.rest.exception.ExpectedException)1 IssueDetails (gov.ca.cwds.rest.exception.IssueDetails)1 NotSupportedException (javax.transaction.NotSupportedException)1 SystemException (javax.transaction.SystemException)1 UserTransaction (javax.transaction.UserTransaction)1 Validator (javax.validation.Validator)1 UnauthorizedException (org.apache.shiro.authz.UnauthorizedException)1 Assert.fail (org.junit.Assert.fail)1 Test (org.junit.Test)1