Search in sources :

Example 1 with DroolsException

use of gov.ca.cwds.drools.DroolsException 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 2 with DroolsException

use of gov.ca.cwds.drools.DroolsException in project api-core by ca-cwds.

the class DataAccessServiceBase method update.

@Override
public T update(P entityAwareDTO) throws DataAccessServicesException, DroolsException {
    try {
        DataAccessBundle<P> dataAccessBundle = new DataAccessBundle<>(entityAwareDTO);
        updateLifecycle.beforeDataProcessing(dataAccessBundle);
        PerryAccount perryAccount = PrincipalUtils.getPrincipal();
        updateLifecycle.dataProcessing(dataAccessBundle, perryAccount);
        updateLifecycle.afterDataProcessing(dataAccessBundle);
        updateLifecycle.beforeBusinessValidation(dataAccessBundle);
        updateLifecycle.businessValidation(dataAccessBundle, perryAccount);
        updateLifecycle.afterBusinessValidation(dataAccessBundle);
        T t = crudDao.update(entityAwareDTO.getEntity());
        updateLifecycle.afterStore(dataAccessBundle);
        return t;
    } catch (DroolsException e) {
        throw new DataAccessServicesException(e);
    }
}
Also used : DataAccessBundle(gov.ca.cwds.cms.data.access.service.lifecycle.DataAccessBundle) DroolsException(gov.ca.cwds.drools.DroolsException) PerryAccount(gov.ca.cwds.security.realm.PerryAccount)

Example 3 with DroolsException

use of gov.ca.cwds.drools.DroolsException in project api-core by ca-cwds.

the class DataAccessServiceBase method create.

@Override
public T create(P entityAwareDTO) throws DataAccessServicesException {
    try {
        DataAccessBundle<P> dataAccessBundle = new DataAccessBundle<>(entityAwareDTO);
        createLifecycle.beforeDataProcessing(dataAccessBundle);
        PerryAccount perryAccount = PrincipalUtils.getPrincipal();
        createLifecycle.dataProcessing(dataAccessBundle, perryAccount);
        createLifecycle.afterDataProcessing(dataAccessBundle);
        createLifecycle.beforeBusinessValidation(dataAccessBundle);
        createLifecycle.businessValidation(dataAccessBundle, perryAccount);
        createLifecycle.afterBusinessValidation(dataAccessBundle);
        T t = crudDao.create(entityAwareDTO.getEntity());
        createLifecycle.afterStore(dataAccessBundle);
        return t;
    } catch (DroolsException e) {
        throw new DataAccessServicesException(e);
    }
}
Also used : DataAccessBundle(gov.ca.cwds.cms.data.access.service.lifecycle.DataAccessBundle) DroolsException(gov.ca.cwds.drools.DroolsException) PerryAccount(gov.ca.cwds.security.realm.PerryAccount)

Example 4 with DroolsException

use of gov.ca.cwds.drools.DroolsException in project api-core by ca-cwds.

the class AbstractBaseAuthorizer method authorizeInstanceOperation.

protected boolean authorizeInstanceOperation(final T instance, List<Object> authorizationFacts) {
    try {
        final PerryAccount perryAccount = PerrySubject.getPerryAccount();
        final Set<StaffPrivilegeType> staffPrivilegeTypes = toStaffPersonPrivilegeTypes(perryAccount);
        if (staffPrivilegeTypes.isEmpty()) {
            return false;
        }
        if (authorizationFacts == null) {
            authorizationFacts = new ArrayList<>();
        }
        authorizationFacts.add(instance);
        authorizationFacts.add(perryAccount);
        final boolean authorizationResult = droolsAuthorizationService.authorizeObjectOperation(staffPrivilegeTypes, droolsConfiguration, authorizationFacts);
        logAuthorization(perryAccount, staffPrivilegeTypes, instance, authorizationResult);
        return authorizationResult;
    } catch (DroolsException e) {
        throw new AuthorizationException(e.getMessage(), e);
    }
}
Also used : AuthorizationException(org.apache.shiro.authz.AuthorizationException) DroolsException(gov.ca.cwds.drools.DroolsException) PerryAccount(gov.ca.cwds.security.realm.PerryAccount)

Example 5 with DroolsException

use of gov.ca.cwds.drools.DroolsException in project api-core by ca-cwds.

the class DroolsValidator method isValid.

@Override
public boolean isValid(T obj, ConstraintValidatorContext context) {
    if (obj == null) {
        return true;
    }
    DroolsConfiguration<T> configuration = getConfiguration();
    Object validatedFact = configuration.getValidatedFact(obj);
    DroolsService droolsService = InjectorHolder.INSTANCE.getInstance(DroolsService.class);
    Set<IssueDetails> detailsList = null;
    try {
        detailsList = droolsService.performBusinessRules(configuration, validatedFact);
    } catch (DroolsException e) {
        LOGGER.warn(e.getMessage(), e);
        throw new RuntimeException(String.format(DroolsErrorMessages.CANT_PERFORM_BUSINESS_VALIDATION, configuration.getAgendaGroup()));
    }
    if (detailsList.isEmpty()) {
        return true;
    } else {
        context.disableDefaultConstraintViolation();
        detailsList.forEach((details -> context.buildConstraintViolationWithTemplate(marshallData(details)).addPropertyNode("").addConstraintViolation()));
        return false;
    }
}
Also used : DroolsErrorMessages(gov.ca.cwds.drools.DroolsErrorMessages) Logger(org.slf4j.Logger) ConstraintValidator(javax.validation.ConstraintValidator) ConstraintValidatorContext(javax.validation.ConstraintValidatorContext) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) InjectorHolder(gov.ca.cwds.inject.InjectorHolder) DroolsConfiguration(gov.ca.cwds.drools.DroolsConfiguration) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails) DroolsException(gov.ca.cwds.drools.DroolsException) JsonUtils(gov.ca.cwds.utils.JsonUtils) Annotation(java.lang.annotation.Annotation) DroolsService(gov.ca.cwds.drools.DroolsService) DroolsException(gov.ca.cwds.drools.DroolsException) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails) DroolsService(gov.ca.cwds.drools.DroolsService)

Aggregations

DroolsException (gov.ca.cwds.drools.DroolsException)5 PerryAccount (gov.ca.cwds.security.realm.PerryAccount)3 DataAccessBundle (gov.ca.cwds.cms.data.access.service.lifecycle.DataAccessBundle)2 UserTransactionImp (com.atomikos.icatch.jta.UserTransactionImp)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 RFA1aFormDTO (gov.ca.cwds.cals.service.dto.rfa.RFA1aFormDTO)1 DataAccessServicesException (gov.ca.cwds.cms.data.access.service.DataAccessServicesException)1 PlacementHome (gov.ca.cwds.data.legacy.cms.entity.PlacementHome)1 DroolsConfiguration (gov.ca.cwds.drools.DroolsConfiguration)1 DroolsErrorMessages (gov.ca.cwds.drools.DroolsErrorMessages)1 DroolsService (gov.ca.cwds.drools.DroolsService)1 InjectorHolder (gov.ca.cwds.inject.InjectorHolder)1 BusinessValidationException (gov.ca.cwds.rest.exception.BusinessValidationException)1 ExpectedException (gov.ca.cwds.rest.exception.ExpectedException)1 IssueDetails (gov.ca.cwds.rest.exception.IssueDetails)1 JsonUtils (gov.ca.cwds.utils.JsonUtils)1 Annotation (java.lang.annotation.Annotation)1 Set (java.util.Set)1 NotSupportedException (javax.transaction.NotSupportedException)1 SystemException (javax.transaction.SystemException)1