Search in sources :

Example 1 with PersistableCatalog

use of com.salesmanager.shop.model.catalog.catalog.PersistableCatalog 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 2 with PersistableCatalog

use of com.salesmanager.shop.model.catalog.catalog.PersistableCatalog 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)2 PersistableCatalog (com.salesmanager.shop.model.catalog.catalog.PersistableCatalog)2 ReadableCatalog (com.salesmanager.shop.model.catalog.catalog.ReadableCatalog)2 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)1 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)1