Search in sources :

Example 6 with FilterAndSortCriteria

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

the class SearchFacetRangeCustomPersistenceHandler method addDefaultSort.

protected void addDefaultSort(CriteriaTransferObject cto) {
    boolean userSort = false;
    for (FilterAndSortCriteria fasc : cto.getCriteriaMap().values()) {
        if (fasc.getSortDirection() != null) {
            userSort = true;
            break;
        }
    }
    if (!userSort) {
        for (int i = 0; i < sortFields.length; i++) {
            String string = sortFields[i];
            FilterAndSortCriteria fsc = cto.getCriteriaMap().get(string);
            if (fsc == null) {
                fsc = new FilterAndSortCriteria(string, i);
                cto.add(fsc);
            }
            fsc.setSortAscending(true);
        }
    }
}
Also used : FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria)

Example 7 with FilterAndSortCriteria

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

the class SkuBundleItemCustomPersistenceHandler method fetch.

@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        ForeignKey foreignKey = (ForeignKey) persistencePerspective.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.FOREIGNKEY);
        // sort it
        if (foreignKey != null && foreignKey.getSortField() != null) {
            FilterAndSortCriteria sortCriteria = cto.get(foreignKey.getSortField());
            sortCriteria.setSortAscending(foreignKey.getSortAscending());
        }
        // get the default properties from Inventory and its subclasses
        Map<String, FieldMetadata> originalProps = helper.getSimpleMergedProperties(SkuBundleItem.class.getName(), persistencePerspective);
        // Pull back the Inventory based on the criteria from the client
        List<FilterMapping> filterMappings = helper.getFilterMappings(persistencePerspective, cto, ceilingEntityFullyQualifiedClassname, originalProps);
        // attach the product option criteria
        skuPersistenceHandler.applyProductOptionValueCriteria(filterMappings, cto, persistencePackage, "sku");
        List<Serializable> records = helper.getPersistentRecords(persistencePackage.getCeilingEntityFullyQualifiedClassname(), filterMappings, cto.getFirstResult(), cto.getMaxResults());
        // Convert Skus into the client-side Entity representation
        Entity[] payload = helper.getRecords(originalProps, records);
        int totalRecords = helper.getTotalRecords(persistencePackage.getCeilingEntityFullyQualifiedClassname(), filterMappings);
        for (int i = 0; i < payload.length; i++) {
            Entity entity = payload[i];
            SkuBundleItem bundleItem = (SkuBundleItem) records.get(i);
            Sku bundleSku = bundleItem.getSku();
            entity.findProperty("sku").setDisplayValue(bundleSku.getName());
            List<ProductOptionValue> productOptionValues = new ArrayList<>();
            for (SkuProductOptionValueXref skuProductOptionValueXref : bundleSku.getProductOptionValueXrefs()) {
                productOptionValues.add(skuProductOptionValueXref.getProductOptionValue());
            }
            Property optionsProperty = skuPersistenceHandler.getConsolidatedOptionProperty(productOptionValues);
            entity.addProperty(optionsProperty);
        }
        return new DynamicResultSet(null, payload, totalRecords);
    } catch (Exception e) {
        throw new ServiceException("There was a problem fetching inventory. See server logs for more details", e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) Serializable(java.io.Serializable) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) 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) ProductOptionValue(org.broadleafcommerce.core.catalog.domain.ProductOptionValue) SkuProductOptionValueXref(org.broadleafcommerce.core.catalog.domain.SkuProductOptionValueXref) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) SkuBundleItem(org.broadleafcommerce.core.catalog.domain.SkuBundleItem) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Property(org.broadleafcommerce.openadmin.dto.Property) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 8 with FilterAndSortCriteria

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

the class AdminEntityServiceImpl method getAdvancedCollectionRecord.

@Override
public PersistenceResponse getAdvancedCollectionRecord(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, String collectionItemId, List<SectionCrumb> sectionCrumbs, String alternateId, String[] customCriteria) throws ServiceException {
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(collectionProperty.getMetadata(), sectionCrumbs);
    ppr.addCustomCriteria(customCriteria);
    FieldMetadata md = collectionProperty.getMetadata();
    String containingEntityId = getContextSpecificRelationshipId(containingClassMetadata, containingEntity, collectionProperty.getName());
    ppr.setSectionEntityField(collectionProperty.getName());
    PersistenceResponse response;
    if (md instanceof AdornedTargetCollectionMetadata) {
        FilterAndSortCriteria fasc = new FilterAndSortCriteria(ppr.getAdornedList().getCollectionFieldName());
        fasc.setFilterValue(containingEntityId);
        ppr.addFilterAndSortCriteria(fasc);
        fasc = new FilterAndSortCriteria(ppr.getAdornedList().getCollectionFieldName() + "Target");
        fasc.setFilterValue(collectionItemId);
        ppr.addFilterAndSortCriteria(fasc);
        if (!StringUtils.isEmpty(alternateId)) {
            fasc = new FilterAndSortCriteria(ppr.getAdornedList().getIdProperty());
            fasc.setFilterValue(alternateId);
            ppr.addFilterAndSortCriteria(fasc);
        }
        response = fetch(ppr);
        Entity[] entities = response.getDynamicResultSet().getRecords();
        if (ArrayUtils.isEmpty(entities)) {
            throw new EntityNotFoundException();
        }
    } else if (md instanceof MapMetadata) {
        MapMetadata mmd = (MapMetadata) md;
        FilterAndSortCriteria fasc = new FilterAndSortCriteria(ppr.getForeignKey().getManyToField());
        fasc.setFilterValue(containingEntityId);
        ppr.addFilterAndSortCriteria(fasc);
        response = fetch(ppr);
        Entity[] entities = response.getDynamicResultSet().getRecords();
        for (Entity e : entities) {
            String idProperty = getIdProperty(containingClassMetadata);
            if (mmd.isSimpleValue()) {
                idProperty = "key";
            }
            Property p = e.getPMap().get(idProperty);
            if (p.getValue().equals(collectionItemId)) {
                response.setEntity(e);
                break;
            }
        }
    } else {
        throw new IllegalArgumentException(String.format("The specified field [%s] for class [%s] was not an " + "advanced collection field.", collectionProperty.getName(), containingClassMetadata.getCeilingType()));
    }
    return response;
}
Also used : AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) EntityNotFoundException(org.broadleafcommerce.openadmin.exception.EntityNotFoundException) MapMetadata(org.broadleafcommerce.openadmin.dto.MapMetadata) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) Property(org.broadleafcommerce.openadmin.dto.Property) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)

Example 9 with FilterAndSortCriteria

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

the class AdminBasicEntityController method getCollectionValueDetails.

@RequestMapping(value = "/{collectionField:.*}/details", method = RequestMethod.GET)
@ResponseBody
public Map<String, String> getCollectionValueDetails(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "collectionField") String collectionField, @RequestParam String ids, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
    String sectionKey = getSectionKey(pathVars);
    String sectionClassName = getClassNameForSection(sectionKey);
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, null, null);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, requestParams, sectionCrumbs, pathVars);
    ClassMetadata mainMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    Property collectionProperty = mainMetadata.getPMap().get(collectionField);
    FieldMetadata md = collectionProperty.getMetadata();
    ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs);
    ppr.setStartIndex(getStartIndex(requestParams));
    ppr.setMaxIndex(getMaxIndex(requestParams));
    if (md instanceof BasicFieldMetadata) {
        String idProp = ((BasicFieldMetadata) md).getForeignKeyProperty();
        String displayProp = ((BasicFieldMetadata) md).getForeignKeyDisplayValueProperty();
        List<String> filterValues = BLCArrayUtils.asList(ids.split(FILTER_VALUE_SEPARATOR_REGEX));
        ppr.addFilterAndSortCriteria(new FilterAndSortCriteria(idProp, filterValues));
        DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
        Map<String, String> returnMap = new HashMap<>();
        for (Entity e : drs.getRecords()) {
            String id = e.getPMap().get(idProp).getValue();
            String disp = e.getPMap().get(displayProp).getDisplayValue();
            if (StringUtils.isBlank(disp)) {
                disp = e.getPMap().get(displayProp).getValue();
            }
            returnMap.put(id, disp);
        }
        return returnMap;
    }
    return null;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) Property(org.broadleafcommerce.openadmin.dto.Property) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 10 with FilterAndSortCriteria

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

the class AdminBasicOperationsController method getTypeaheadResults.

@RequestMapping(value = "/{owningClass:.*}/{collectionField:.*}/typeahead", method = RequestMethod.GET)
@ResponseBody
public List<Map<String, String>> getTypeaheadResults(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "owningClass") String owningClass, @PathVariable(value = "collectionField") String collectionField, @RequestParam(required = false) String query, @RequestParam(required = false) String requestingEntityId, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, null, null);
    String validatedClass = getClassNameForSection(owningClass);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(validatedClass, requestParams, sectionCrumbs, pathVars);
    ClassMetadata mainMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    Property collectionProperty = mainMetadata.getPMap().get(collectionField);
    FieldMetadata md = collectionProperty.getMetadata();
    ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs);
    ppr.addFilterAndSortCriteria(getCriteria(requestParams));
    ppr.setStartIndex(getStartIndex(requestParams));
    ppr.setMaxIndex(getMaxIndex(requestParams));
    ppr.removeFilterAndSortCriteria("query");
    ppr.removeFilterAndSortCriteria("requestingEntityId");
    ppr.addCustomCriteria("requestingEntityId=" + requestingEntityId);
    // This list of datums will populate the typeahead suggestions.
    List<Map<String, String>> responses = new ArrayList<Map<String, String>>();
    if (md instanceof BasicFieldMetadata) {
        String searchField = searchFieldResolver.resolveField(((BasicFieldMetadata) md).getForeignKeyClass());
        ppr.addFilterAndSortCriteria(new FilterAndSortCriteria(searchField, query));
        DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
        ClassMetadata lookupMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
        for (Entity e : drs.getRecords()) {
            Map<String, String> responseMap = new HashMap<String, String>();
            String idProperty = service.getIdProperty(lookupMetadata);
            responseMap.put("id", e.findProperty(idProperty).getValue());
            String displayKey = e.findProperty(searchField).getDisplayValue();
            if (StringUtils.isBlank(displayKey)) {
                displayKey = e.findProperty(searchField).getValue();
            }
            responseMap.put("displayKey", displayKey);
            responses.add(responseMap);
        }
    }
    return responses;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) Property(org.broadleafcommerce.openadmin.dto.Property) HashMap(java.util.HashMap) Map(java.util.Map) MultiValueMap(org.springframework.util.MultiValueMap) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

FilterAndSortCriteria (org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria)20 FilterMapping (org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping)10 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)8 Entity (org.broadleafcommerce.openadmin.dto.Entity)8 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)8 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)7 ArrayList (java.util.ArrayList)6 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)6 List (java.util.List)5 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)5 FieldPath (org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPath)5 Restriction (org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.Restriction)5 Serializable (java.io.Serializable)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 From (javax.persistence.criteria.From)4 Path (javax.persistence.criteria.Path)4 ServiceException (org.broadleafcommerce.common.exception.ServiceException)4 CriteriaTransferObject (org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)4 ForeignKey (org.broadleafcommerce.openadmin.dto.ForeignKey)4 Property (org.broadleafcommerce.openadmin.dto.Property)4