Search in sources :

Example 26 with DynamicResultSet

use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.

the class AdornedTargetListPersistenceModule method fetch.

@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto) throws ServiceException {
    PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
    String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
    AdornedTargetList adornedTargetList = (AdornedTargetList) persistencePerspective.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST);
    Entity[] payload;
    int totalRecords;
    try {
        Class<?>[] entities = persistenceManager.getPolymorphicEntities(ceilingEntityFullyQualifiedClassname);
        Map<String, FieldMetadata> mergedPropertiesTarget = persistenceManager.getDynamicEntityDao().getMergedProperties(ceilingEntityFullyQualifiedClassname, entities, null, persistencePerspective.getAdditionalNonPersistentProperties(), persistencePerspective.getAdditionalForeignKeys(), MergedPropertyType.PRIMARY, persistencePerspective.getPopulateToOneFields(), persistencePerspective.getIncludeFields(), persistencePerspective.getExcludeFields(), persistencePerspective.getConfigurationKey(), "");
        AdornedTargetRetrieval adornedTargetRetrieval = new AdornedTargetRetrieval(persistencePackage, adornedTargetList, cto).invokeForFetch();
        List<Serializable> records = adornedTargetRetrieval.getRecords();
        Map<String, FieldMetadata> mergedProperties = adornedTargetRetrieval.getMergedProperties();
        payload = getRecords(mergedPropertiesTarget, records, mergedProperties, adornedTargetList.getTargetObjectPath(), persistencePackage.getCustomCriteria());
        totalRecords = getTotalRecords(adornedTargetList.getAdornedTargetEntityClassname(), adornedTargetRetrieval.getFilterMappings());
    } catch (Exception e) {
        throw new ServiceException("Unable to fetch results for " + adornedTargetList.getAdornedTargetEntityClassname(), e);
    }
    DynamicResultSet results = new DynamicResultSet(null, payload, totalRecords);
    return results;
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) Serializable(java.io.Serializable) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) ServiceException(org.broadleafcommerce.common.exception.ServiceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecurityServiceException(org.broadleafcommerce.common.exception.SecurityServiceException) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) SecurityServiceException(org.broadleafcommerce.common.exception.SecurityServiceException) AdornedTargetList(org.broadleafcommerce.openadmin.dto.AdornedTargetList) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 27 with DynamicResultSet

use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.

the class BasicPersistenceModule method fetch.

@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto) throws ServiceException {
    Entity[] payload;
    int totalRecords;
    PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
    String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
    ForeignKey foreignKey = (ForeignKey) persistencePerspective.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.FOREIGNKEY);
    try {
        if (foreignKey != null && foreignKey.getSortField() != null) {
            FilterAndSortCriteria sortCriteria = cto.get(foreignKey.getSortField());
            sortCriteria.setSortAscending(foreignKey.getSortAscending());
        }
        Map<String, FieldMetadata> mergedProperties = getMergedProperties(persistencePackage, cto);
        List<FilterMapping> filterMappings = getFilterMappings(persistencePerspective, cto, persistencePackage.getFetchTypeFullyQualifiedClassname(), mergedProperties);
        List<FilterMapping> standardFilterMappings = new ArrayList<FilterMapping>(filterMappings);
        if (CollectionUtils.isNotEmpty(cto.getAdditionalFilterMappings())) {
            standardFilterMappings.addAll(cto.getAdditionalFilterMappings());
        }
        if (CollectionUtils.isNotEmpty(cto.getNonCountAdditionalFilterMappings())) {
            standardFilterMappings.addAll(cto.getNonCountAdditionalFilterMappings());
        }
        FetchRequest fetchRequest = new FetchRequest(persistencePackage, cto, persistencePackage.getFetchTypeFullyQualifiedClassname(), standardFilterMappings);
        List<Serializable> records = getPersistentRecords(fetchRequest);
        List<FilterMapping> countFilterMappings = new ArrayList<FilterMapping>(filterMappings);
        if (CollectionUtils.isNotEmpty(cto.getAdditionalFilterMappings())) {
            countFilterMappings.addAll(cto.getAdditionalFilterMappings());
        }
        FetchRequest countFetchRequest = new FetchRequest(persistencePackage, cto, persistencePackage.getFetchTypeFullyQualifiedClassname(), countFilterMappings);
        totalRecords = getTotalRecords(countFetchRequest);
        FetchExtractionRequest fetchExtractionRequest = new FetchExtractionRequest(persistencePackage, cto, persistencePackage.getFetchTypeFullyQualifiedClassname(), mergedProperties, records);
        payload = getRecords(fetchExtractionRequest);
    } catch (Exception e) {
        throw new ServiceException("Unable to fetch results for " + ceilingEntityFullyQualifiedClassname, e);
    }
    return new DynamicResultSet(null, payload, totalRecords);
}
Also used : AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) Serializable(java.io.Serializable) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) ArrayList(java.util.ArrayList) FilterMapping(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping) ForeignKey(org.broadleafcommerce.openadmin.dto.ForeignKey) ServiceException(org.broadleafcommerce.common.exception.ServiceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceException) CriteriaConversionException(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.CriteriaConversionException) BeansException(org.springframework.beans.BeansException) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException) ParentEntityPersistenceException(org.broadleafcommerce.openadmin.server.service.persistence.ParentEntityPersistenceException) SecurityServiceException(org.broadleafcommerce.common.exception.SecurityServiceException) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) SecurityServiceException(org.broadleafcommerce.common.exception.SecurityServiceException) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 28 with DynamicResultSet

use of org.broadleafcommerce.openadmin.dto.DynamicResultSet 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 29 with DynamicResultSet

use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.

the class PersistenceManagerImpl method inspect.

@Override
public PersistenceResponse inspect(PersistencePackage persistencePackage) throws ServiceException, ClassNotFoundException {
    for (PersistenceManagerEventHandler handler : persistenceManagerEventHandlers) {
        PersistenceManagerEventHandlerResponse response = handler.preInspect(this, persistencePackage);
        if (PersistenceManagerEventHandlerResponse.PersistenceManagerEventHandlerResponseStatus.HANDLED_BREAK == response.getStatus()) {
            break;
        }
    }
    // check to see if there is a custom handler registered
    for (CustomPersistenceHandler handler : getCustomPersistenceHandlers()) {
        if (handler.canHandleInspect(persistencePackage)) {
            if (!handler.willHandleSecurity(persistencePackage)) {
                adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.INSPECT);
            }
            DynamicResultSet results = handler.inspect(persistencePackage, dynamicEntityDao, this);
            return executePostInspectHandlers(persistencePackage, new PersistenceResponse().withDynamicResultSet(results));
        }
    }
    adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.INSPECT);
    Class<?>[] entities = getPolymorphicEntities(persistencePackage.getCeilingEntityFullyQualifiedClassname());
    Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<>();
    for (PersistenceModule module : modules) {
        module.updateMergedProperties(persistencePackage, allMergedProperties);
    }
    ClassMetadata classMetadata = buildClassMetadata(entities, persistencePackage, allMergedProperties);
    DynamicResultSet results = new DynamicResultSet(classMetadata);
    return executePostInspectHandlers(persistencePackage, new PersistenceResponse().withDynamicResultSet(results));
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) HashMap(java.util.HashMap) CustomPersistenceHandler(org.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler) PersistenceModule(org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) Map(java.util.Map) HashMap(java.util.HashMap)

Example 30 with DynamicResultSet

use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.

the class CustomPersistenceHandlerAdapter method getResultSet.

/**
 * This is a helper method that can be invoked as the last step in a custom inspect phase. It will assemble the
 * appropriate DynamicResultSet from the given parameters.
 */
protected DynamicResultSet getResultSet(PersistencePackage persistencePackage, InspectHelper helper, Map<String, FieldMetadata> metadata) throws ServiceException {
    String entityName = persistencePackage.getCeilingEntityFullyQualifiedClassname();
    try {
        if (helper instanceof PersistenceManager) {
            Class<?>[] entities = ((PersistenceManager) helper).getPolymorphicEntities(entityName);
            Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
            allMergedProperties.put(MergedPropertyType.PRIMARY, metadata);
            ClassMetadata mergedMetadata = helper.buildClassMetadata(entities, persistencePackage, allMergedProperties);
            DynamicResultSet results = new DynamicResultSet(mergedMetadata);
            return results;
        }
    } catch (ClassNotFoundException e) {
        throw new ServiceException(e);
    }
    return new DynamicResultSet();
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistenceManager(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceManager) HashMap(java.util.HashMap) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) ServiceException(org.broadleafcommerce.common.exception.ServiceException) HashMap(java.util.HashMap) Map(java.util.Map) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Aggregations

DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)44 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)26 Entity (org.broadleafcommerce.openadmin.dto.Entity)20 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)18 Property (org.broadleafcommerce.openadmin.dto.Property)16 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)16 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)15 ServiceException (org.broadleafcommerce.common.exception.ServiceException)14 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)14 HashMap (java.util.HashMap)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 Map (java.util.Map)10 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)9 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)7 FilterAndSortCriteria (org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria)7 MergedPropertyType (org.broadleafcommerce.openadmin.dto.MergedPropertyType)7 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)7 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)6 FilterMapping (org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping)6 Serializable (java.io.Serializable)5