Search in sources :

Example 1 with NoPossibleResultsException

use of org.broadleafcommerce.common.exception.NoPossibleResultsException in project BroadleafCommerce by BroadleafCommerce.

the class PersistenceManagerImpl method fetch.

@Override
public PersistenceResponse fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto) throws ServiceException {
    for (PersistenceManagerEventHandler handler : persistenceManagerEventHandlers) {
        PersistenceManagerEventHandlerResponse response = handler.preFetch(this, persistencePackage, cto);
        if (PersistenceManagerEventHandlerResponse.PersistenceManagerEventHandlerResponseStatus.HANDLED_BREAK == response.getStatus()) {
            break;
        }
    }
    // check to see if there is a custom handler registered
    for (CustomPersistenceHandler handler : getCustomPersistenceHandlers()) {
        if (handler.canHandleFetch(persistencePackage)) {
            if (!handler.willHandleSecurity(persistencePackage)) {
                adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.FETCH);
            }
            DynamicResultSet results = handler.fetch(persistencePackage, cto, dynamicEntityDao, (RecordHelper) getCompatibleModule(OperationType.BASIC));
            return executePostFetchHandlers(persistencePackage, cto, new PersistenceResponse().withDynamicResultSet(results));
        }
    }
    adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.FETCH);
    PersistenceModule myModule = getCompatibleModule(persistencePackage.getPersistencePerspective().getOperationTypes().getFetchType());
    try {
        DynamicResultSet results = myModule.fetch(persistencePackage, cto);
        return executePostFetchHandlers(persistencePackage, cto, new PersistenceResponse().withDynamicResultSet(results));
    } catch (ServiceException e) {
        if (e.getCause() instanceof NoPossibleResultsException) {
            DynamicResultSet drs = new DynamicResultSet(null, new Entity[] {}, 0);
            return executePostFetchHandlers(persistencePackage, cto, new PersistenceResponse().withDynamicResultSet(drs));
        }
        throw e;
    }
}
Also used : NoPossibleResultsException(org.broadleafcommerce.common.exception.NoPossibleResultsException) AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) ServiceException(org.broadleafcommerce.common.exception.ServiceException) CustomPersistenceHandler(org.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler) PersistenceModule(org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 2 with NoPossibleResultsException

use of org.broadleafcommerce.common.exception.NoPossibleResultsException in project BroadleafCommerce by BroadleafCommerce.

the class CriteriaTranslatorImpl method determineRoot.

/**
 * Determines the appropriate entity in this current class tree to use as the ceiling entity for the query. Because
 * we filter with AND instead of OR, we throw an exception if an attempt to utilize properties from mutually exclusive
 * class trees is made as it would be impossible for such a query to return results.
 *
 * @param dynamicEntityDao
 * @param ceilingMarker
 * @param filterMappings
 * @return the root class
 * @throws NoPossibleResultsException
 */
@SuppressWarnings("unchecked")
protected Class<Serializable> determineRoot(DynamicEntityDao dynamicEntityDao, Class<Serializable> ceilingMarker, List<FilterMapping> filterMappings) throws NoPossibleResultsException {
    Class<?>[] polyEntities = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(ceilingMarker);
    ClassTree root = dynamicEntityDao.getClassTree(polyEntities);
    List<ClassTree> parents = new ArrayList<ClassTree>();
    for (FilterMapping mapping : filterMappings) {
        if (mapping.getInheritedFromClass() != null) {
            root = determineRootInternal(root, parents, mapping.getInheritedFromClass());
            if (root == null) {
                throw new NoPossibleResultsException("AND filter on different class hierarchies produces no results");
            }
        }
    }
    for (Class<?> clazz : polyEntities) {
        if (clazz.getName().equals(root.getFullyQualifiedClassname())) {
            return (Class<Serializable>) clazz;
        }
    }
    throw new IllegalStateException("Class didn't match - this should not occur");
}
Also used : NoPossibleResultsException(org.broadleafcommerce.common.exception.NoPossibleResultsException) ClassTree(org.broadleafcommerce.openadmin.dto.ClassTree) ArrayList(java.util.ArrayList)

Aggregations

NoPossibleResultsException (org.broadleafcommerce.common.exception.NoPossibleResultsException)2 ArrayList (java.util.ArrayList)1 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)1 ServiceException (org.broadleafcommerce.common.exception.ServiceException)1 ClassTree (org.broadleafcommerce.openadmin.dto.ClassTree)1 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)1 Entity (org.broadleafcommerce.openadmin.dto.Entity)1 CustomPersistenceHandler (org.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler)1 PersistenceModule (org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule)1