Search in sources :

Example 1 with CategorySearchFacet

use of org.broadleafcommerce.core.search.domain.CategorySearchFacet in project BroadleafCommerce by BroadleafCommerce.

the class CategoryImpl method getCumulativeSearchFacets.

@Override
public List<CategorySearchFacet> getCumulativeSearchFacets(Set<Category> categoryHierarchy) {
    categoryHierarchy.add(this);
    List<CategorySearchFacet> returnCategoryFacets = new ArrayList<CategorySearchFacet>();
    returnCategoryFacets.addAll(getSearchFacets());
    Collections.sort(returnCategoryFacets, facetPositionComparator);
    final Collection<SearchFacet> facets = CollectionUtils.collect(returnCategoryFacets, new Transformer() {

        @Override
        public Object transform(Object input) {
            return ((CategorySearchFacet) input).getSearchFacet();
        }
    });
    // Add in parent facets unless they are excluded
    Category parentCategory = getDefaultParentCategory();
    List<CategorySearchFacet> parentFacets = null;
    if (parentCategory != null && !categoryHierarchy.contains(parentCategory)) {
        parentFacets = parentCategory.getCumulativeSearchFacets(categoryHierarchy);
        CollectionUtils.filter(parentFacets, new Predicate() {

            @Override
            public boolean evaluate(Object arg) {
                CategorySearchFacet csf = (CategorySearchFacet) arg;
                return !getExcludedSearchFacets().contains(csf.getSearchFacet()) && !facets.contains(csf.getSearchFacet());
            }
        });
    }
    if (parentFacets != null) {
        returnCategoryFacets.addAll(parentFacets);
    }
    return returnCategoryFacets;
}
Also used : CategorySearchFacet(org.broadleafcommerce.core.search.domain.CategorySearchFacet) CategoryExcludedSearchFacet(org.broadleafcommerce.core.search.domain.CategoryExcludedSearchFacet) CategorySearchFacet(org.broadleafcommerce.core.search.domain.CategorySearchFacet) SearchFacet(org.broadleafcommerce.core.search.domain.SearchFacet) Transformer(org.apache.commons.collections.Transformer) ArrayList(java.util.ArrayList) Predicate(org.apache.commons.collections.Predicate)

Example 2 with CategorySearchFacet

use of org.broadleafcommerce.core.search.domain.CategorySearchFacet in project BroadleafCommerce by BroadleafCommerce.

the class CategoryImpl method createOrRetrieveCopyInstance.

@Override
public <G extends Category> CreateResponse<G> createOrRetrieveCopyInstance(MultiTenantCopyContext context) throws CloneNotSupportedException {
    CreateResponse<G> createResponse = context.createOrRetrieveCopyInstance(this);
    if (createResponse.isAlreadyPopulated()) {
        return createResponse;
    }
    Category cloned = createResponse.getClone();
    cloned.setActiveEndDate(activeEndDate);
    cloned.setActiveStartDate(activeStartDate);
    cloned.setFulfillmentType(getFulfillmentType());
    cloned.setTaxCode(taxCode);
    cloned.setUrl(url);
    cloned.setUrlKey(urlKey);
    cloned.setOverrideGeneratedUrl(getOverrideGeneratedUrl());
    cloned.setName(name);
    cloned.setLongDescription(longDescription);
    cloned.setInventoryType(getInventoryType());
    cloned.setExternalId(externalId);
    cloned.setDisplayTemplate(displayTemplate);
    cloned.setDescription(description);
    for (CategoryXref entry : allParentCategoryXrefs) {
        CategoryXref clonedEntry = entry.createOrRetrieveCopyInstance(context).getClone();
        cloned.getAllParentCategoryXrefs().add(clonedEntry);
    }
    if (getDefaultParentCategory() != null) {
        cloned.setDefaultParentCategory(getDefaultParentCategory().createOrRetrieveCopyInstance(context).getClone());
    }
    for (CategoryXref entry : allChildCategoryXrefs) {
        CategoryXref clonedEntry = entry.createOrRetrieveCopyInstance(context).getClone();
        cloned.getAllChildCategoryXrefs().add(clonedEntry);
    }
    for (Map.Entry<String, CategoryAttribute> entry : getCategoryAttributesMap().entrySet()) {
        CategoryAttribute clonedEntry = entry.getValue().createOrRetrieveCopyInstance(context).getClone();
        cloned.getCategoryAttributesMap().put(entry.getKey(), clonedEntry);
    }
    for (CategorySearchFacet entry : searchFacets) {
        CategorySearchFacet clonedEntry = entry.createOrRetrieveCopyInstance(context).getClone();
        cloned.getSearchFacets().add(clonedEntry);
    }
    for (CategoryExcludedSearchFacet entry : excludedSearchFacets) {
        CategoryExcludedSearchFacet clonedEntry = entry.createOrRetrieveCopyInstance(context).getClone();
        cloned.getExcludedSearchFacets().add(clonedEntry);
    }
    for (Map.Entry<String, CategoryMediaXref> entry : categoryMedia.entrySet()) {
        CategoryMediaXrefImpl clonedEntry = ((CategoryMediaXrefImpl) entry.getValue()).createOrRetrieveCopyInstance(context).getClone();
        cloned.getCategoryMediaXref().put(entry.getKey(), clonedEntry);
    }
    return createResponse;
}
Also used : CategoryExcludedSearchFacet(org.broadleafcommerce.core.search.domain.CategoryExcludedSearchFacet) CategorySearchFacet(org.broadleafcommerce.core.search.domain.CategorySearchFacet) MultiValueMap(org.apache.commons.collections.map.MultiValueMap) Map(java.util.Map) HashedMap(org.apache.commons.collections.map.HashedMap) HashMap(java.util.HashMap) AdminPresentationMap(org.broadleafcommerce.common.presentation.AdminPresentationMap)

Example 3 with CategorySearchFacet

use of org.broadleafcommerce.core.search.domain.CategorySearchFacet in project BroadleafCommerce by BroadleafCommerce.

the class CategoryImpl method getParentFacets.

protected List<CategorySearchFacet> getParentFacets(final Collection<SearchFacet> facets) {
    List<CategorySearchFacet> parentFacets = null;
    if (getParentCategory() != null) {
        parentFacets = getParentCategory().getCumulativeSearchFacets();
        CollectionUtils.filter(parentFacets, new Predicate() {

            @Override
            public boolean evaluate(Object arg) {
                CategorySearchFacet csf = (CategorySearchFacet) arg;
                return !isExcludedSearchFacet(csf) && !facets.contains(csf.getSearchFacet());
            }

            protected boolean isExcludedSearchFacet(CategorySearchFacet csf) {
                boolean isExcludedSearchFacet = false;
                for (CategoryExcludedSearchFacet excludedSearchFacet : getExcludedSearchFacets()) {
                    if (excludedSearchFacet.getSearchFacet().equals(csf.getSearchFacet())) {
                        isExcludedSearchFacet = true;
                        break;
                    }
                }
                return isExcludedSearchFacet;
            }
        });
    }
    return parentFacets;
}
Also used : CategorySearchFacet(org.broadleafcommerce.core.search.domain.CategorySearchFacet) CategoryExcludedSearchFacet(org.broadleafcommerce.core.search.domain.CategoryExcludedSearchFacet) Predicate(org.apache.commons.collections.Predicate)

Example 4 with CategorySearchFacet

use of org.broadleafcommerce.core.search.domain.CategorySearchFacet in project BroadleafCommerce by BroadleafCommerce.

the class DatabaseSearchServiceImpl method getCategoryFacets.

@Override
@SuppressWarnings("unchecked")
public List<SearchFacetDTO> getCategoryFacets(Category category) {
    List<SearchFacetDTO> facets = null;
    String cacheKey = CACHE_KEY_PREFIX + "category:" + category.getId();
    Element element = cache.get(cacheKey);
    if (element != null) {
        facets = (List<SearchFacetDTO>) element.getValue();
    }
    if (facets == null) {
        List<CategorySearchFacet> categorySearchFacets = category.getCumulativeSearchFacets();
        List<SearchFacet> searchFacets = new ArrayList<SearchFacet>();
        for (CategorySearchFacet categorySearchFacet : categorySearchFacets) {
            searchFacets.add(categorySearchFacet.getSearchFacet());
        }
        facets = buildSearchFacetDtos(searchFacets);
        element = new Element(cacheKey, facets);
        cache.put(element);
    }
    return facets;
}
Also used : CategorySearchFacet(org.broadleafcommerce.core.search.domain.CategorySearchFacet) SearchFacet(org.broadleafcommerce.core.search.domain.SearchFacet) CategorySearchFacet(org.broadleafcommerce.core.search.domain.CategorySearchFacet) Element(net.sf.ehcache.Element) SearchFacetDTO(org.broadleafcommerce.core.search.domain.SearchFacetDTO) ArrayList(java.util.ArrayList)

Example 5 with CategorySearchFacet

use of org.broadleafcommerce.core.search.domain.CategorySearchFacet in project BroadleafCommerce by BroadleafCommerce.

the class SolrSearchServiceImpl method getCategoryFacets.

@Override
public List<SearchFacetDTO> getCategoryFacets(Category category) {
    List<SearchFacet> searchFacets = new ArrayList<>();
    ExtensionResultStatusType status = extensionManager.getProxy().getCategorySearchFacets(category, searchFacets);
    if (Objects.equals(ExtensionResultStatusType.NOT_HANDLED, status)) {
        List<CategorySearchFacet> categorySearchFacets = category.getCumulativeSearchFacets();
        for (CategorySearchFacet categorySearchFacet : categorySearchFacets) {
            searchFacets.add(categorySearchFacet.getSearchFacet());
        }
    }
    return buildSearchFacetDTOs(searchFacets);
}
Also used : CategorySearchFacet(org.broadleafcommerce.core.search.domain.CategorySearchFacet) SearchFacet(org.broadleafcommerce.core.search.domain.SearchFacet) CategorySearchFacet(org.broadleafcommerce.core.search.domain.CategorySearchFacet) ArrayList(java.util.ArrayList) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType)

Aggregations

CategorySearchFacet (org.broadleafcommerce.core.search.domain.CategorySearchFacet)5 ArrayList (java.util.ArrayList)3 CategoryExcludedSearchFacet (org.broadleafcommerce.core.search.domain.CategoryExcludedSearchFacet)3 SearchFacet (org.broadleafcommerce.core.search.domain.SearchFacet)3 Predicate (org.apache.commons.collections.Predicate)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Element (net.sf.ehcache.Element)1 Transformer (org.apache.commons.collections.Transformer)1 HashedMap (org.apache.commons.collections.map.HashedMap)1 MultiValueMap (org.apache.commons.collections.map.MultiValueMap)1 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)1 AdminPresentationMap (org.broadleafcommerce.common.presentation.AdminPresentationMap)1 SearchFacetDTO (org.broadleafcommerce.core.search.domain.SearchFacetDTO)1