use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class TimeDTOCustomPersistenceHandler method inspect.
@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
Map<String, FieldMetadata> mergedProperties = dynamicEntityDao.getSimpleMergedProperties(ceilingEntityFullyQualifiedClassname, persistencePackage.getPersistencePerspective());
allMergedProperties.put(MergedPropertyType.PRIMARY, mergedProperties);
ClassMetadata mergedMetadata = helper.buildClassMetadata(new Class<?>[] { Class.forName(ceilingEntityFullyQualifiedClassname) }, persistencePackage, allMergedProperties);
DynamicResultSet results = new DynamicResultSet(mergedMetadata);
return results;
} catch (Exception e) {
ServiceException ex = new ServiceException("Unable to retrieve inspection results for " + persistencePackage.getCeilingEntityFullyQualifiedClassname(), e);
throw ex;
}
}
use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityRemoteService method add.
@Override
public PersistenceResponse add(final PersistencePackage persistencePackage) throws ServiceException {
final PersistenceResponse[] response = new PersistenceResponse[1];
try {
PlatformTransactionManager transactionManager = identifyTransactionManager(persistencePackage);
transUtil.runTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
@Override
public void execute() throws Throwable {
response[0] = nonTransactionalAdd(persistencePackage);
}
@Override
public boolean shouldRetryOnTransactionLockAcquisitionFailure() {
return super.shouldRetryOnTransactionLockAcquisitionFailure();
}
}, RuntimeException.class, transactionManager);
} catch (RuntimeException e) {
if (e.getCause() instanceof ServiceException) {
throw (ServiceException) e.getCause();
}
throw e;
}
return response[0];
}
use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityRemoteService method fetch.
@Override
public PersistenceResponse fetch(final PersistencePackage persistencePackage, final CriteriaTransferObject cto) throws ServiceException {
final PersistenceResponse[] response = new PersistenceResponse[1];
try {
PlatformTransactionManager transactionManager = identifyTransactionManager(persistencePackage);
transUtil.runOptionalTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
@Override
public void execute() throws Throwable {
response[0] = nonTransactionalFetch(persistencePackage, cto);
}
}, RuntimeException.class, true, TransactionDefinition.PROPAGATION_REQUIRED, TransactionDefinition.ISOLATION_DEFAULT, true, transactionManager);
} catch (RuntimeException e) {
if (e.getCause() instanceof ServiceException) {
throw (ServiceException) e.getCause();
}
throw e;
}
return response[0];
}
use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityRemoteService method update.
@Override
public PersistenceResponse update(final PersistencePackage persistencePackage) throws ServiceException {
final PersistenceResponse[] response = new PersistenceResponse[1];
try {
PlatformTransactionManager transactionManager = identifyTransactionManager(persistencePackage);
transUtil.runTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
@Override
public void execute() throws Throwable {
response[0] = nonTransactionalUpdate(persistencePackage);
}
@Override
public boolean shouldRetryOnTransactionLockAcquisitionFailure() {
return super.shouldRetryOnTransactionLockAcquisitionFailure();
}
}, RuntimeException.class, transactionManager);
} catch (RuntimeException e) {
if (e.getCause() instanceof ServiceException) {
throw (ServiceException) e.getCause();
}
throw e;
}
return response[0];
}
use of org.broadleafcommerce.common.exception.ServiceException in project BroadleafCommerce by BroadleafCommerce.
the class PersistenceManagerImpl method update.
@Override
public PersistenceResponse update(PersistencePackage persistencePackage) throws ServiceException {
for (PersistenceManagerEventHandler handler : persistenceManagerEventHandlers) {
PersistenceManagerEventHandlerResponse response = handler.preUpdate(this, persistencePackage);
if (PersistenceManagerEventHandlerResponse.PersistenceManagerEventHandlerResponseStatus.HANDLED_BREAK == response.getStatus()) {
break;
}
}
// check to see if there is a custom handler registered
// execute the root PersistencePackage
Entity response;
try {
checkRoot: {
for (CustomPersistenceHandler handler : getCustomPersistenceHandlers()) {
if (handler.canHandleUpdate(persistencePackage)) {
if (!handler.willHandleSecurity(persistencePackage)) {
adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.UPDATE);
}
response = handler.update(persistencePackage, dynamicEntityDao, (RecordHelper) getCompatibleModule(OperationType.BASIC));
break checkRoot;
}
}
adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.UPDATE);
PersistenceModule myModule = getCompatibleModule(persistencePackage.getPersistencePerspective().getOperationTypes().getUpdateType());
response = myModule.update(persistencePackage);
}
} catch (ValidationException e) {
response = e.getEntity();
} catch (ServiceException e) {
if (e.getCause() instanceof ValidationException) {
response = ((ValidationException) e.getCause()).getEntity();
} else {
throw e;
}
}
Map<String, List<String>> subPackageValidationErrors = new HashMap<>();
for (Map.Entry<String, PersistencePackage> subPackage : persistencePackage.getSubPackages().entrySet()) {
try {
// Run through any subPackages -- add up any validation errors
checkHandler: {
for (CustomPersistenceHandler handler : getCustomPersistenceHandlers()) {
if (handler.canHandleUpdate(subPackage.getValue())) {
Entity subResponse = handler.update(subPackage.getValue(), dynamicEntityDao, (RecordHelper) getCompatibleModule(OperationType.BASIC));
subPackage.getValue().setEntity(subResponse);
break checkHandler;
}
}
PersistenceModule subModule = getCompatibleModule(subPackage.getValue().getPersistencePerspective().getOperationTypes().getUpdateType());
Entity subResponse = subModule.update(persistencePackage);
subPackage.getValue().setEntity(subResponse);
}
} catch (ValidationException e) {
subPackage.getValue().setEntity(e.getEntity());
} catch (ServiceException e) {
if (e.getCause() instanceof ValidationException) {
response = ((ValidationException) e.getCause()).getEntity();
} else {
throw e;
}
}
}
// Build up validation errors in all of the subpackages, even those that might not have thrown ValidationExceptions
for (Map.Entry<String, PersistencePackage> subPackage : persistencePackage.getSubPackages().entrySet()) {
for (Map.Entry<String, List<String>> error : subPackage.getValue().getEntity().getPropertyValidationErrors().entrySet()) {
subPackageValidationErrors.put(subPackage.getKey() + DynamicEntityFormInfo.FIELD_SEPARATOR + error.getKey(), error.getValue());
}
}
response.getPropertyValidationErrors().putAll(subPackageValidationErrors);
if (response.isValidationFailure()) {
PersistenceResponse validationResponse = executeValidationProcessors(persistencePackage, new PersistenceResponse().withEntity(response));
Entity entity = validationResponse.getEntity();
String message = ValidationUtil.buildErrorMessage(entity.getPropertyValidationErrors(), entity.getGlobalValidationErrors());
throw new ValidationException(entity, message);
}
return executePostUpdateHandlers(persistencePackage, new PersistenceResponse().withEntity(response));
}
Aggregations