Search in sources :

Example 1 with ListCriteria

use of com.salesmanager.shop.model.entity.ListCriteria in project shopizer by shopizer-ecommerce.

the class ProductManufacturerApi method list.

@RequestMapping(value = "/manufacturers/", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ApiOperation(httpMethod = "GET", value = "List manufacturers by store", notes = "This request supports paging or not. Paging supports page number and request count", response = ReadableManufacturerList.class)
public ReadableManufacturerList list(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "page", required = false, defaultValue = "0") Integer page, @RequestParam(value = "count", required = false, defaultValue = "10") Integer count) {
    ListCriteria listCriteria = new ListCriteria();
    listCriteria.setName(name);
    return manufacturerFacade.getAllManufacturers(merchantStore, language, listCriteria, page, count);
}
Also used : ListCriteria(com.salesmanager.shop.model.entity.ListCriteria) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with ListCriteria

use of com.salesmanager.shop.model.entity.ListCriteria in project shopizer by shopizer-ecommerce.

the class ProductManufacturerApi method listByStore.

@RequestMapping(value = "/private/manufacturers/", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ApiOperation(httpMethod = "GET", value = "List manufacturers by store", notes = "This request supports paging or not. Paging supports page number and request count", response = ReadableManufacturerList.class)
public ReadableManufacturerList listByStore(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "page", required = false, defaultValue = "0") Integer page, @RequestParam(value = "count", required = false, defaultValue = "10") Integer count) {
    ListCriteria listCriteria = new ListCriteria();
    listCriteria.setName(name);
    return manufacturerFacade.listByStore(merchantStore, language, listCriteria, page, count);
}
Also used : ListCriteria(com.salesmanager.shop.model.entity.ListCriteria) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with ListCriteria

use of com.salesmanager.shop.model.entity.ListCriteria in project shopizer by shopizer-ecommerce.

the class CategoryApi method list.

/**
 * Get all category starting from root filter can be used for filtering on
 * fields only featured is supported
 *
 * @return
 */
@GetMapping(value = "/category", produces = { APPLICATION_JSON_VALUE })
@ApiOperation(httpMethod = "GET", value = "Get category hierarchy from root. Supports filtering FEATURED_CATEGORIES and VISIBLE ONLY by adding ?filter=[featured] or ?filter=[visible] or ? filter=[featured,visible", notes = "Does not return any product attached")
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") })
public ReadableCategoryList list(@RequestParam(value = "filter", required = false) List<String> filter, @RequestParam(value = "name", required = false) String name, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, @RequestParam(value = "page", required = false, defaultValue = "0") Integer page, @RequestParam(value = "count", required = false, defaultValue = "10") Integer count) {
    ListCriteria criteria = new ListCriteria();
    criteria.setName(name);
    return categoryFacade.getCategoryHierarchy(merchantStore, criteria, DEFAULT_CATEGORY_DEPTH, language, filter, page, count);
}
Also used : ListCriteria(com.salesmanager.shop.model.entity.ListCriteria) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with ListCriteria

use of com.salesmanager.shop.model.entity.ListCriteria 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);
    }
}
Also used : CategoryFacade(com.salesmanager.shop.store.controller.category.facade.CategoryFacade) PersistableCategoryPopulator(com.salesmanager.shop.populator.catalog.PersistableCategoryPopulator) HashMap(java.util.HashMap) ReadableProductVariantValue(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductVariantValue) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) Inject(javax.inject.Inject) ProductOptionValueDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription) Language(com.salesmanager.core.model.reference.language.Language) ListCriteria(com.salesmanager.shop.model.entity.ListCriteria) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) Map(java.util.Map) ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) ReadableProductVariant(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductVariant) ReadableCategoryPopulator(com.salesmanager.shop.populator.catalog.ReadableCategoryPopulator) CategoryService(com.salesmanager.core.business.services.catalog.category.CategoryService) MerchantStoreService(com.salesmanager.core.business.services.merchant.MerchantStoreService) ProductAttributeService(com.salesmanager.core.business.services.catalog.product.attribute.ProductAttributeService) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) Mapper(com.salesmanager.shop.mapper.Mapper) Iterator(java.util.Iterator) ProductOptionDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription) Collectors(java.util.stream.Collectors) ReadableCategoryList(com.salesmanager.shop.model.catalog.category.ReadableCategoryList) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) Objects(java.util.Objects) Category(com.salesmanager.core.model.catalog.category.Category) List(java.util.List) Validate(org.apache.commons.lang3.Validate) CollectionUtils(org.springframework.util.CollectionUtils) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) Entry(java.util.Map.Entry) Optional(java.util.Optional) ConversionException(com.salesmanager.core.business.exception.ConversionException) Comparator(java.util.Comparator) PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) Category(com.salesmanager.core.model.catalog.category.Category) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) ReadableCategoryList(com.salesmanager.shop.model.catalog.category.ReadableCategoryList) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore)

Aggregations

ListCriteria (com.salesmanager.shop.model.entity.ListCriteria)4 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)3 ApiOperation (io.swagger.annotations.ApiOperation)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 CategoryService (com.salesmanager.core.business.services.catalog.category.CategoryService)1 ProductAttributeService (com.salesmanager.core.business.services.catalog.product.attribute.ProductAttributeService)1 MerchantStoreService (com.salesmanager.core.business.services.merchant.MerchantStoreService)1 Category (com.salesmanager.core.model.catalog.category.Category)1 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)1 ProductOption (com.salesmanager.core.model.catalog.product.attribute.ProductOption)1 ProductOptionDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription)1 ProductOptionValueDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Language (com.salesmanager.core.model.reference.language.Language)1 Mapper (com.salesmanager.shop.mapper.Mapper)1 PersistableCategory (com.salesmanager.shop.model.catalog.category.PersistableCategory)1