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());
}
}
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);
}
}
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);
}
}
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);
}
}
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;
}
}
Aggregations