Search in sources :

Example 1 with SearchFacet

use of org.broadleafcommerce.core.search.domain.SearchFacet 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 SearchFacet

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

the class SolrSearchServiceImpl method getSearchFacets.

@Override
public List<SearchFacetDTO> getSearchFacets() {
    List<SearchFacet> searchFacets = new ArrayList<>();
    ExtensionResultStatusType status = extensionManager.getProxy().getSearchFacets(searchFacets);
    if (Objects.equals(ExtensionResultStatusType.NOT_HANDLED, status)) {
        if (useSku) {
            return buildSearchFacetDTOs(searchFacetDao.readAllSearchFacets(FieldEntity.SKU));
        }
        return buildSearchFacetDTOs(searchFacetDao.readAllSearchFacets(FieldEntity.PRODUCT));
    }
    return buildSearchFacetDTOs(searchFacets);
}
Also used : CategorySearchFacet(org.broadleafcommerce.core.search.domain.CategorySearchFacet) SearchFacet(org.broadleafcommerce.core.search.domain.SearchFacet) ArrayList(java.util.ArrayList) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType)

Example 3 with SearchFacet

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

the class SolrHelperServiceImpl method buildSearchFacetDTOs.

@Override
public List<SearchFacetDTO> buildSearchFacetDTOs(List<SearchFacet> searchFacets) {
    List<SearchFacetDTO> facets = new ArrayList<SearchFacetDTO>();
    Map<String, String[]> requestParameters = BroadleafRequestContext.getRequestParameterMap();
    for (SearchFacet facet : searchFacets) {
        if (isFacetAvailable(facet, requestParameters)) {
            SearchFacetDTO dto = new SearchFacetDTO();
            dto.setFacet(facet);
            dto.setShowQuantity(true);
            facets.add(dto);
        }
    }
    return facets;
}
Also used : SearchFacet(org.broadleafcommerce.core.search.domain.SearchFacet) SearchFacetDTO(org.broadleafcommerce.core.search.domain.SearchFacetDTO) ArrayList(java.util.ArrayList)

Example 4 with SearchFacet

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

the class SearchFacetCustomPersistenceHandler method getAdminInstance.

protected SearchFacet getAdminInstance(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper, Entity entity) throws ClassNotFoundException {
    PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
    Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(SearchFacetRange.class.getName(), persistencePerspective);
    Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
    String type = entity.getType()[0];
    SearchFacet adminInstance = (SearchFacet) dynamicEntityDao.retrieve(Class.forName(type), primaryKey);
    return adminInstance;
}
Also used : FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) SearchFacet(org.broadleafcommerce.core.search.domain.SearchFacet) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) SearchFacetRange(org.broadleafcommerce.core.search.domain.SearchFacetRange)

Example 5 with SearchFacet

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

the class SearchFacetCustomPersistenceHandler method remove.

@Override
public void remove(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        SearchFacet adminInstance = getAdminInstance(persistencePackage, dynamicEntityDao, helper, entity);
        if (Status.class.isAssignableFrom(adminInstance.getClass())) {
            ((Status) adminInstance).setArchived('Y');
            dynamicEntityDao.merge(adminInstance);
        }
    } catch (Exception e) {
        throw new ServiceException("Unable to remove entity for " + entity.getType()[0], e);
    }
}
Also used : Status(org.broadleafcommerce.common.persistence.Status) Entity(org.broadleafcommerce.openadmin.dto.Entity) SearchFacet(org.broadleafcommerce.core.search.domain.SearchFacet) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Aggregations

SearchFacet (org.broadleafcommerce.core.search.domain.SearchFacet)10 ArrayList (java.util.ArrayList)6 CategorySearchFacet (org.broadleafcommerce.core.search.domain.CategorySearchFacet)5 SearchFacetDTO (org.broadleafcommerce.core.search.domain.SearchFacetDTO)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)2 SearchFacetImpl (org.broadleafcommerce.core.search.domain.SearchFacetImpl)2 NoResultException (javax.persistence.NoResultException)1 Element (net.sf.ehcache.Element)1 Predicate (org.apache.commons.collections.Predicate)1 Transformer (org.apache.commons.collections.Transformer)1 ServiceException (org.broadleafcommerce.common.exception.ServiceException)1 Status (org.broadleafcommerce.common.persistence.Status)1 CategoryExcludedSearchFacet (org.broadleafcommerce.core.search.domain.CategoryExcludedSearchFacet)1 SearchFacetRange (org.broadleafcommerce.core.search.domain.SearchFacetRange)1 Entity (org.broadleafcommerce.openadmin.dto.Entity)1 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)1 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)1