Search in sources :

Example 1 with Catalog

use of com.salesmanager.core.model.catalog.catalog.Catalog in project shopizer by shopizer-ecommerce.

the class PersistableCatalogCategoryEntryMapper method merge.

@Override
public CatalogCategoryEntry merge(PersistableCatalogCategoryEntry source, CatalogCategoryEntry destination, MerchantStore store, Language language) {
    Validate.notNull(source, "CatalogEntry must not be null");
    Validate.notNull(store, "MerchantStore must not be null");
    Validate.notNull(source.getProductCode(), "ProductCode must not be null");
    Validate.notNull(source.getCategoryCode(), "CategoryCode must not be null");
    Validate.notNull(source.getCatalog(), "Catalog must not be null");
    if (destination == null) {
        destination = new CatalogCategoryEntry();
    }
    destination.setId(source.getId());
    destination.setVisible(source.isVisible());
    try {
        String catalog = source.getCatalog();
        Catalog catalogModel = catalogFacade.getCatalog(catalog, store);
        if (catalogModel == null) {
            throw new ConversionRuntimeException("Error while converting CatalogEntry product [" + source.getCatalog() + "] not found");
        }
        destination.setCatalog(catalogModel);
        /*			Product productModel = productFacade.getProduct(source.getProductCode(), store);
			if(productModel == null) {
				throw new ConversionRuntimeException("Error while converting CatalogEntry product [" + source.getProductCode() + "] not found");
			}*/
        // destination.setProduct(productModel);
        Category categoryModel = categoryFacade.getByCode(source.getCategoryCode(), store);
        if (categoryModel == null) {
            throw new ConversionRuntimeException("Error while converting CatalogEntry category [" + source.getCategoryCode() + "] not found");
        }
        destination.setCategory(categoryModel);
    } catch (Exception e) {
        throw new ConversionRuntimeException("Error while converting CatalogEntry", e);
    }
    return destination;
}
Also used : CatalogCategoryEntry(com.salesmanager.core.model.catalog.catalog.CatalogCategoryEntry) PersistableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.PersistableCatalogCategoryEntry) Category(com.salesmanager.core.model.catalog.category.Category) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 2 with Catalog

use of com.salesmanager.core.model.catalog.catalog.Catalog in project shopizer by shopizer-ecommerce.

the class CatalogFacadeImpl method deleteCatalog.

@Override
public void deleteCatalog(Long catalogId, MerchantStore store, Language language) {
    Validate.notNull(catalogId, "Catalog id cannot be null");
    Validate.isTrue(catalogId > 0, "Catalog id cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Catalog c = catalogService.getById(catalogId);
    if (Objects.isNull(c)) {
        throw new ResourceNotFoundException("Catalog with id [" + catalogId + "] not found");
    }
    if (Objects.nonNull(c.getMerchantStore()) && !c.getMerchantStore().getCode().equals(store.getCode())) {
        throw new ResourceNotFoundException("Catalog with id [" + catalogId + "] not found for merchant [" + store.getCode() + "]");
    }
    try {
        catalogService.delete(c);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while deleting catalog id [" + catalogId + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 3 with Catalog

use of com.salesmanager.core.model.catalog.catalog.Catalog in project shopizer by shopizer-ecommerce.

the class CatalogFacadeImpl method updateCatalog.

@Override
public void updateCatalog(Long catalogId, PersistableCatalog catalog, MerchantStore store, Language language) {
    Validate.notNull(catalogId, "Catalog id cannot be null");
    Validate.isTrue(catalogId > 0, "Catalog id cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    Catalog c = Optional.ofNullable(catalogService.getById(catalogId)).orElseThrow(() -> new ResourceNotFoundException("Catalog with id [" + catalogId + "] not found"));
    if (Objects.nonNull(c.getMerchantStore()) && !c.getMerchantStore().getCode().equals(store.getCode())) {
        throw new ResourceNotFoundException("Catalog with id [" + catalogId + "] not found for merchant [" + store.getCode() + "]");
    }
    c.setDefaultCatalog(catalog.isDefaultCatalog());
    c.setVisible(catalog.isVisible());
    catalogService.saveOrUpdate(c, store);
}
Also used : ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog)

Example 4 with Catalog

use of com.salesmanager.core.model.catalog.catalog.Catalog in project shopizer by shopizer-ecommerce.

the class CatalogFacadeImpl method listCatalogEntry.

@Override
public ReadableEntityList<ReadableCatalogCategoryEntry> listCatalogEntry(Optional<String> product, Long id, MerchantStore store, Language language, int page, int count) {
    Validate.notNull(store, "MerchantStore cannot be null");
    String productCode = product.orElse(null);
    Catalog catalog = catalogService.getById(id, store).orElseThrow(() -> new ResourceNotFoundException("Catalog with id [" + id + "] not found for store [" + store.getCode() + "]"));
    Page<CatalogCategoryEntry> entries = catalogEntryService.list(catalog, store, language, productCode, page, count);
    if (entries.isEmpty()) {
        return new ReadableEntityList<>();
    }
    List<ReadableCatalogCategoryEntry> readableList = entries.getContent().stream().map(cat -> readableCatalogEntryMapper.convert(cat, store, language)).collect(Collectors.toList());
    return createReadableList(entries, readableList);
}
Also used : PersistableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.PersistableCatalogCategoryEntry) ReadableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.ReadableCatalogCategoryEntry) CatalogCategoryEntry(com.salesmanager.core.model.catalog.catalog.CatalogCategoryEntry) ReadableEntityUtil.createReadableList(com.salesmanager.shop.util.ReadableEntityUtil.createReadableList) ReadableCatalogCategoryEntryMapper(com.salesmanager.shop.mapper.catalog.ReadableCatalogCategoryEntryMapper) CatalogService(com.salesmanager.core.business.services.catalog.catalog.CatalogService) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Autowired(org.springframework.beans.factory.annotation.Autowired) ReadableCatalogMapper(com.salesmanager.shop.mapper.catalog.ReadableCatalogMapper) ServiceException(com.salesmanager.core.business.exception.ServiceException) CatalogFacade(com.salesmanager.shop.store.controller.catalog.facade.CatalogFacade) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) CatalogEntryService(com.salesmanager.core.business.services.catalog.catalog.CatalogEntryService) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog) PersistableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.PersistableCatalogCategoryEntry) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) Mapper(com.salesmanager.shop.mapper.Mapper) Validate(org.jsoup.helper.Validate) ReadableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.ReadableCatalogCategoryEntry) CatalogCategoryEntry(com.salesmanager.core.model.catalog.catalog.CatalogCategoryEntry) PersistableCatalogMapper(com.salesmanager.shop.mapper.catalog.PersistableCatalogMapper) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ReadableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.ReadableCatalogCategoryEntry) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog)

Example 5 with Catalog

use of com.salesmanager.core.model.catalog.catalog.Catalog in project shopizer by shopizer-ecommerce.

the class CatalogFacadeImpl method saveCatalog.

@Override
public ReadableCatalog saveCatalog(PersistableCatalog catalog, MerchantStore store, Language language) {
    Validate.notNull(catalog, "Catalog cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    Catalog catalogToSave = persistableCatalogMapper.convert(catalog, store, language);
    boolean existByCode = uniqueCatalog(catalog.getCode(), store);
    if (existByCode) {
        throw new OperationNotAllowedException("Catalog [" + catalog.getCode() + "] already exists");
    }
    catalogService.saveOrUpdate(catalogToSave, store);
    Catalog savedCatalog = catalogService.getByCode(catalogToSave.getCode(), store).get();
    return readableCatalogMapper.convert(savedCatalog, store, language);
}
Also used : OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog)

Aggregations

Catalog (com.salesmanager.core.model.catalog.catalog.Catalog)8 PersistableCatalog (com.salesmanager.shop.model.catalog.catalog.PersistableCatalog)7 ReadableCatalog (com.salesmanager.shop.model.catalog.catalog.ReadableCatalog)7 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)6 CatalogCategoryEntry (com.salesmanager.core.model.catalog.catalog.CatalogCategoryEntry)3 PersistableCatalogCategoryEntry (com.salesmanager.shop.model.catalog.catalog.PersistableCatalogCategoryEntry)3 ServiceException (com.salesmanager.core.business.exception.ServiceException)2 ReadableCatalogCategoryEntry (com.salesmanager.shop.model.catalog.catalog.ReadableCatalogCategoryEntry)2 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)2 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)2 CatalogEntryService (com.salesmanager.core.business.services.catalog.catalog.CatalogEntryService)1 CatalogService (com.salesmanager.core.business.services.catalog.catalog.CatalogService)1 Category (com.salesmanager.core.model.catalog.category.Category)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 PersistableCatalogMapper (com.salesmanager.shop.mapper.catalog.PersistableCatalogMapper)1 ReadableCatalogCategoryEntryMapper (com.salesmanager.shop.mapper.catalog.ReadableCatalogCategoryEntryMapper)1 ReadableCatalogMapper (com.salesmanager.shop.mapper.catalog.ReadableCatalogMapper)1 ReadableEntityList (com.salesmanager.shop.model.entity.ReadableEntityList)1