Search in sources :

Example 1 with DynamicResultSet

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

the class AdminPermissionCustomPersistenceHandler method fetch.

@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    addFriendlyRestriction(cto);
    addDefaultSort(cto);
    PersistenceModule myModule = helper.getCompatibleModule(persistencePackage.getPersistencePerspective().getOperationTypes().getFetchType());
    DynamicResultSet results = myModule.fetch(persistencePackage, cto);
    return results;
}
Also used : PersistenceModule(org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 2 with DynamicResultSet

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

the class MapStructurePersistenceModule method fetch.

@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto) throws ServiceException {
    Entity[] payload;
    int totalRecords;
    String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
    if (StringUtils.isEmpty(persistencePackage.getFetchTypeFullyQualifiedClassname())) {
        persistencePackage.setFetchTypeFullyQualifiedClassname(ceilingEntityFullyQualifiedClassname);
    }
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        Class<?>[] entities = persistenceManager.getPolymorphicEntities(ceilingEntityFullyQualifiedClassname);
        Map<String, FieldMetadata> mergedProperties = persistenceManager.getDynamicEntityDao().getMergedProperties(ceilingEntityFullyQualifiedClassname, entities, (ForeignKey) persistencePerspective.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.FOREIGNKEY), persistencePerspective.getAdditionalNonPersistentProperties(), persistencePerspective.getAdditionalForeignKeys(), MergedPropertyType.PRIMARY, persistencePerspective.getPopulateToOneFields(), persistencePerspective.getIncludeFields(), persistencePerspective.getExcludeFields(), persistencePerspective.getConfigurationKey(), "");
        MapStructure mapStructure = (MapStructure) persistencePerspective.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.MAPSTRUCTURE);
        PersistentClass persistentClass = persistenceManager.getDynamicEntityDao().getPersistentClass(mapStructure.getValueClassName());
        Map<String, FieldMetadata> valueUnfilteredMergedProperties;
        if (persistentClass == null) {
            valueUnfilteredMergedProperties = persistenceManager.getDynamicEntityDao().getPropertiesForPrimitiveClass(((SimpleValueMapStructure) mapStructure).getValuePropertyName(), ((SimpleValueMapStructure) mapStructure).getValuePropertyFriendlyName(), Class.forName(mapStructure.getValueClassName()), Class.forName(ceilingEntityFullyQualifiedClassname), MergedPropertyType.MAPSTRUCTUREVALUE);
        } else {
            String valueClassName = mapStructure.getValueClassName();
            Class<?>[] mapEntities = persistenceManager.getPolymorphicEntities(valueClassName);
            valueUnfilteredMergedProperties = persistenceManager.getDynamicEntityDao().getMergedProperties(valueClassName, mapEntities, null, new String[] {}, new ForeignKey[] {}, MergedPropertyType.MAPSTRUCTUREVALUE, false, new String[] {}, new String[] {}, null, "");
        }
        Map<String, FieldMetadata> valueMergedProperties = filterOutCollectionMetadata(valueUnfilteredMergedProperties);
        List<FilterMapping> filterMappings = getFilterMappings(persistencePerspective, cto, persistencePackage.getFetchTypeFullyQualifiedClassname(), mergedProperties);
        if (CollectionUtils.isNotEmpty(cto.getAdditionalFilterMappings())) {
            filterMappings.addAll(cto.getAdditionalFilterMappings());
        }
        totalRecords = getTotalRecords(persistencePackage.getFetchTypeFullyQualifiedClassname(), filterMappings);
        if (totalRecords > 1) {
            throw new ServiceException("Queries to retrieve an entity containing a MapStructure must return only 1 entity. Your query returned (" + totalRecords + ") values.");
        }
        List<Serializable> records = getPersistentRecords(persistencePackage.getFetchTypeFullyQualifiedClassname(), filterMappings, cto.getFirstResult(), cto.getMaxResults());
        Map<String, FieldMetadata> ceilingMergedProperties = getSimpleMergedProperties(ceilingEntityFullyQualifiedClassname, persistencePerspective);
        payload = getMapRecords(records.get(0), mapStructure, ceilingMergedProperties, valueMergedProperties, null, persistencePackage.getCustomCriteria());
    } catch (Exception e) {
        throw new ServiceException("Unable to fetch results for " + ceilingEntityFullyQualifiedClassname, e);
    }
    DynamicResultSet results = new DynamicResultSet(null, payload, payload.length);
    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) FilterMapping(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping) ForeignKey(org.broadleafcommerce.openadmin.dto.ForeignKey) ParseException(java.text.ParseException) ServiceException(org.broadleafcommerce.common.exception.ServiceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecurityServiceException(org.broadleafcommerce.common.exception.SecurityServiceException) MapStructure(org.broadleafcommerce.openadmin.dto.MapStructure) SimpleValueMapStructure(org.broadleafcommerce.openadmin.dto.SimpleValueMapStructure) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) SecurityServiceException(org.broadleafcommerce.common.exception.SecurityServiceException) PersistentClass(org.hibernate.mapping.PersistentClass) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) SimpleValueMapStructure(org.broadleafcommerce.openadmin.dto.SimpleValueMapStructure) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 3 with DynamicResultSet

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

the class OfferCustomPersistenceHandler method inspect.

@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
    Class ceilingEntityClass = getClassForName(persistencePackage.getCeilingEntityFullyQualifiedClassname());
    PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
    Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
    // retrieve the default properties for WorkflowEvents
    Map<String, FieldMetadata> properties = helper.getSimpleMergedProperties(ceilingEntityClass.getCanonicalName(), persistencePerspective);
    properties.put(SHOW_ADVANCED_VISIBILITY_OPTIONS, buildAdvancedVisibilityOptionsFieldMetaData());
    properties.put(QUALIFIERS_CAN_BE_QUALIFIERS, buildQualifiersCanBeQualifiersFieldMetaData());
    properties.put(QUALIFIERS_CAN_BE_TARGETS, buildQualifiersCanBeTargetsFieldMetaData());
    properties.put(STACKABLE, buildStackableFieldMetaData());
    if (isActiveFilter) {
        properties.put(IS_ACTIVE, buildIsActiveFieldMetaData());
    }
    allMergedProperties.put(MergedPropertyType.PRIMARY, properties);
    Class<?>[] entityClasses = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(ceilingEntityClass);
    ClassMetadata mergedMetadata = helper.buildClassMetadata(entityClasses, persistencePackage, allMergedProperties);
    return new DynamicResultSet(mergedMetadata, null, null);
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType)

Example 4 with DynamicResultSet

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

the class ProductCustomPersistenceHandler method fetch.

@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    boolean legacy = parentCategoryLegacyModeService.isLegacyMode();
    // which seeks matching values in  allParentCategoryXRefs instead
    if (!legacy) {
        FilterAndSortCriteria fsc = cto.getCriteriaMap().get("defaultCategory");
        if (fsc != null) {
            List<String> filterValues = fsc.getFilterValues();
            cto.getCriteriaMap().remove("defaultCategory");
            List<Long> transformedValues = BLCCollectionUtils.collectList(filterValues, new TypedTransformer<Long>() {

                @Override
                public Long transform(Object input) {
                    return Long.parseLong(((String) input));
                }
            });
            CriteriaBuilder builder = dynamicEntityDao.getStandardEntityManager().getCriteriaBuilder();
            CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
            Root<CategoryProductXrefImpl> root = criteria.from(CategoryProductXrefImpl.class);
            criteria.select(root.get("product").get("id").as(Long.class));
            List<Predicate> restrictions = new ArrayList<Predicate>();
            restrictions.add(builder.equal(root.get("defaultReference"), Boolean.TRUE));
            if (CollectionUtils.isNotEmpty(transformedValues)) {
                restrictions.add(root.get("category").get("id").in(transformedValues));
            }
            criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
            TypedQuery<Long> query = dynamicEntityDao.getStandardEntityManager().createQuery(criteria);
            List<Long> productIds = query.getResultList();
            productIds = sandBoxHelper.mergeCloneIds(ProductImpl.class, productIds.toArray(new Long[productIds.size()]));
            if (productIds.size() == 0) {
                return new DynamicResultSet(null, new Entity[0], 0);
            }
            if (productIds.size() <= queryLimit) {
                FilterMapping filterMapping = new FilterMapping().withFieldPath(new FieldPath().withTargetProperty("id")).withDirectFilterValues(productIds).withRestriction(new Restriction().withPredicateProvider(new PredicateProvider() {

                    @Override
                    public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path explicitPath, List directValues) {
                        return explicitPath.in(directValues);
                    }
                }));
                cto.getAdditionalFilterMappings().add(filterMapping);
            } else {
                String joined = StringUtils.join(transformedValues, ',');
                LOG.warn(String.format("Skipping default category filtering for product fetch query since there are " + "more than " + queryLimit + " products found to belong to the selected default categories(%s). This is a " + "filter query limitation.", joined));
            }
        }
    }
    if (eagerFetchAssociations) {
        cto.getNonCountAdditionalFilterMappings().add(new FilterMapping().withDirectFilterValues(new EmptyFilterValues()).withRestriction(new Restriction().withPredicateProvider(new PredicateProvider() {

            @Override
            public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path explicitPath, List directValues) {
                root.fetch("defaultSku", JoinType.LEFT);
                root.fetch("defaultCategory", JoinType.LEFT);
                return null;
            }
        })));
    }
    return helper.getCompatibleModule(OperationType.BASIC).fetch(persistencePackage, cto);
}
Also used : FieldPath(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPath) ArrayList(java.util.ArrayList) FilterMapping(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping) Predicate(javax.persistence.criteria.Predicate) EmptyFilterValues(org.broadleafcommerce.openadmin.server.service.persistence.module.EmptyFilterValues) CategoryProductXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl) List(java.util.List) ArrayList(java.util.ArrayList) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Path(javax.persistence.criteria.Path) FieldPath(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPath) From(javax.persistence.criteria.From) FieldPathBuilder(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPathBuilder) Restriction(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.Restriction) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) PredicateProvider(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.predicate.PredicateProvider) CriteriaTransferObject(org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)

Example 5 with DynamicResultSet

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

the class SearchFacetRangeCustomPersistenceHandler method fetch.

@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    addDefaultSort(cto);
    PersistenceModule myModule = helper.getCompatibleModule(persistencePackage.getPersistencePerspective().getOperationTypes().getFetchType());
    DynamicResultSet results = myModule.fetch(persistencePackage, cto);
    return results;
}
Also used : PersistenceModule(org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule) 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