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);
}
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);
}
Aggregations