Search in sources :

Example 1 with CategoryService

use of com.salesmanager.core.business.services.catalog.category.CategoryService in project shopizer by shopizer-ecommerce.

the class CategoryFacadeImpl method saveCategory.

@Override
public PersistableCategory saveCategory(MerchantStore store, PersistableCategory category) {
    try {
        Long categoryId = category.getId();
        Category target = Optional.ofNullable(categoryId).filter(merchant -> store != null).filter(id -> id > 0).map(categoryService::getById).orElse(new Category());
        Category dbCategory = populateCategory(store, category, target);
        saveCategory(store, dbCategory, null);
        // set category id
        category.setId(dbCategory.getId());
        return category;
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while updating category", 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) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

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 ReadableCategory (com.salesmanager.shop.model.catalog.category.ReadableCategory)1 ReadableCategoryList (com.salesmanager.shop.model.catalog.category.ReadableCategoryList)1 ReadableProductVariant (com.salesmanager.shop.model.catalog.product.attribute.ReadableProductVariant)1 ReadableProductVariantValue (com.salesmanager.shop.model.catalog.product.attribute.ReadableProductVariantValue)1 ListCriteria (com.salesmanager.shop.model.entity.ListCriteria)1 PersistableCategoryPopulator (com.salesmanager.shop.populator.catalog.PersistableCategoryPopulator)1