Search in sources :

Example 16 with ServiceException

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;
    }
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) ServiceException(org.broadleafcommerce.common.exception.ServiceException) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 17 with ServiceException

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];
}
Also used : ServiceException(org.broadleafcommerce.common.exception.ServiceException) StreamCapableTransactionalOperationAdapter(org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager)

Example 18 with ServiceException

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];
}
Also used : ServiceException(org.broadleafcommerce.common.exception.ServiceException) StreamCapableTransactionalOperationAdapter(org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager)

Example 19 with ServiceException

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];
}
Also used : ServiceException(org.broadleafcommerce.common.exception.ServiceException) StreamCapableTransactionalOperationAdapter(org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager)

Example 20 with ServiceException

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));
}
Also used : PersistencePackage(org.broadleafcommerce.openadmin.dto.PersistencePackage) AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException) HashMap(java.util.HashMap) CustomPersistenceHandler(org.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler) PersistenceModule(org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule) ServiceException(org.broadleafcommerce.common.exception.ServiceException) RecordHelper(org.broadleafcommerce.openadmin.server.service.persistence.module.RecordHelper) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ServiceException (org.broadleafcommerce.common.exception.ServiceException)77 Entity (org.broadleafcommerce.openadmin.dto.Entity)46 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)44 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)39 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)25 InvocationTargetException (java.lang.reflect.InvocationTargetException)19 SecurityServiceException (org.broadleafcommerce.common.exception.SecurityServiceException)17 ValidationException (org.broadleafcommerce.openadmin.server.service.ValidationException)16 Serializable (java.io.Serializable)15 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)14 CriteriaTransferObject (org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)13 Property (org.broadleafcommerce.openadmin.dto.Property)12 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)11 Map (java.util.Map)11 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)9 ForeignKey (org.broadleafcommerce.openadmin.dto.ForeignKey)9 StreamCapableTransactionalOperationAdapter (org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter)6 Sku (org.broadleafcommerce.core.catalog.domain.Sku)6 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)6