use of com.salesmanager.shop.model.catalog.category.ReadableCategoryList in project shopizer by shopizer-ecommerce.
the class StoreFilter method setTopCategories.
@SuppressWarnings("unchecked")
private void setTopCategories(MerchantStore store, Language language, HttpServletRequest request) throws Exception {
StringBuilder categoriesKey = new StringBuilder();
categoriesKey.append(store.getId()).append("_").append(Constants.CATEGORIES_CACHE_KEY).append("-").append(language.getCode());
StringBuilder categoriesKeyMissed = new StringBuilder();
categoriesKeyMissed.append(categoriesKey.toString()).append(Constants.MISSED_CACHE_KEY);
// language code - List of category
Map<String, List<ReadableCategory>> objects = null;
List<ReadableCategory> loadedCategories = null;
if (store.isUseCache()) {
objects = (Map<String, List<ReadableCategory>>) webApplicationCache.getFromCache(categoriesKey.toString());
if (objects == null) {
// load categories
ReadableCategoryList categoryList = categoryFacade.getCategoryHierarchy(store, null, 0, language, null, 0, // null
200);
loadedCategories = categoryList.getCategories();
// filter out invisible category
loadedCategories.stream().filter(cat -> cat.isVisible() == true).collect(Collectors.toList());
objects = new ConcurrentHashMap<String, List<ReadableCategory>>();
objects.put(language.getCode(), loadedCategories);
webApplicationCache.putInCache(categoriesKey.toString(), objects);
} else {
loadedCategories = objects.get(language.getCode());
}
} else {
ReadableCategoryList categoryList = categoryFacade.getCategoryHierarchy(store, null, 0, language, null, 0, // null // filter
200);
loadedCategories = categoryList.getCategories();
}
if (loadedCategories != null) {
request.setAttribute(Constants.REQUEST_TOP_CATEGORIES, loadedCategories);
}
}
use of com.salesmanager.shop.model.catalog.category.ReadableCategoryList in project shopizer by shopizer-ecommerce.
the class CategoryFacadeImpl method getCategoryHierarchy.
@Override
public ReadableCategoryList getCategoryHierarchy(MerchantStore store, ListCriteria criteria, int depth, Language language, List<String> filter, int page, int count) {
Validate.notNull(store, "MerchantStore can not be null");
// get parent store
try {
MerchantStore parent = merchantStoreService.getParent(store.getCode());
List<Category> categories = null;
ReadableCategoryList returnList = new ReadableCategoryList();
if (!CollectionUtils.isEmpty(filter) && filter.contains(FEATURED_CATEGORY)) {
categories = categoryService.getListByDepthFilterByFeatured(parent, depth, language);
returnList.setRecordsTotal(categories.size());
returnList.setNumber(categories.size());
returnList.setTotalPages(1);
} else {
org.springframework.data.domain.Page<Category> pageable = categoryService.getListByDepth(parent, language, criteria != null ? criteria.getName() : null, depth, page, count);
categories = pageable.getContent();
returnList.setRecordsTotal(pageable.getTotalElements());
returnList.setTotalPages(pageable.getTotalPages());
returnList.setNumber(categories.size());
}
List<ReadableCategory> readableCategories = null;
if (filter != null && filter.contains(VISIBLE_CATEGORY)) {
readableCategories = categories.stream().filter(Category::isVisible).map(cat -> categoryReadableCategoryConverter.convert(cat, store, language)).collect(Collectors.toList());
} else {
readableCategories = categories.stream().map(cat -> categoryReadableCategoryConverter.convert(cat, store, language)).collect(Collectors.toList());
}
Map<Long, ReadableCategory> readableCategoryMap = readableCategories.stream().collect(Collectors.toMap(ReadableCategory::getId, Function.identity()));
readableCategories.stream().filter(cat -> Objects.nonNull(cat.getParent())).filter(cat -> readableCategoryMap.containsKey(cat.getParent().getId())).forEach(readableCategory -> {
ReadableCategory parentCategory = readableCategoryMap.get(readableCategory.getParent().getId());
if (parentCategory != null) {
parentCategory.getChildren().add(readableCategory);
}
});
List<ReadableCategory> filteredList = readableCategoryMap.values().stream().collect(Collectors.toList());
// execute only if not admin filtered
if (filter == null || (filter != null && !filter.contains(ADMIN_CATEGORY))) {
filteredList = readableCategoryMap.values().stream().filter(cat -> cat.getDepth() == 0).sorted(Comparator.comparing(ReadableCategory::getSortOrder)).collect(Collectors.toList());
returnList.setNumber(filteredList.size());
}
returnList.setCategories(filteredList);
return returnList;
} catch (ServiceException e) {
throw new ServiceRuntimeException(e);
}
}
use of com.salesmanager.shop.model.catalog.category.ReadableCategoryList in project shopizer by shopizer-ecommerce.
the class CategoryFacadeImpl method listByProduct.
@Override
public ReadableCategoryList listByProduct(MerchantStore store, Long product, Language language) {
Validate.notNull(product, "Product id must not be null");
Validate.notNull(store, "Store must not be null");
List<ReadableCategory> readableCategories = new ArrayList<ReadableCategory>();
List<Category> categories = categoryService.getByProductId(product, store);
readableCategories = categories.stream().map(cat -> categoryReadableCategoryConverter.convert(cat, store, language)).collect(Collectors.toList());
ReadableCategoryList readableList = new ReadableCategoryList();
readableList.setCategories(readableCategories);
readableList.setTotalPages(1);
readableList.setNumber(readableCategories.size());
readableList.setRecordsTotal(readableCategories.size());
return readableList;
}
Aggregations