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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations