use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class ProductInstanceGroupFacadeImpl method update.
@Override
public void update(Long productInstanceGroup, PersistableProductInstanceGroup instance, MerchantStore store, Language language) {
ProductInstanceGroup group = this.group(productInstanceGroup, store);
instance.setId(productInstanceGroup);
group = persistableProductIntanceGroupMapper.merge(instance, group, store, language);
try {
productInstanceGroupService.saveOrUpdate(group);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Cannot save product instance group [" + productInstanceGroup + "] for store [" + store.getCode() + "]");
}
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class ProductInstanceGroupFacadeImpl method delete.
@Override
public void delete(Long productInstanceGroup, Long productId, MerchantStore store) {
ProductInstanceGroup group = this.group(productInstanceGroup, store);
if (group == null) {
throw new ResourceNotFoundException("Product instance group [" + group.getId() + " not found for store [" + store.getCode() + "]");
}
try {
// null all group from instances
for (ProductInstance instance : group.getProductInstances()) {
Optional<ProductInstance> p = productInstanceService.getById(instance.getId(), store);
if (p.isEmpty()) {
throw new ResourceNotFoundException("Product instance [" + instance.getId() + " not found for store [" + store.getCode() + "]");
}
instance.setProductInstanceGroup(null);
productInstanceService.save(instance);
}
// now delete
productInstanceGroupService.delete(group);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Cannot remove product instance group [" + productInstanceGroup + "] for store [" + store.getCode() + "]");
}
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method saveAttribute.
@Override
public ReadableProductAttributeEntity saveAttribute(Long productId, PersistableProductAttribute attribute, MerchantStore store, Language language) {
Validate.notNull(productId, "Product id cannot be null");
Validate.notNull(attribute, "ProductAttribute cannot be null");
Validate.notNull(attribute.getOption(), "ProductAttribute option cannot be null");
Validate.notNull(attribute.getOptionValue(), "ProductAttribute option value cannot be null");
Validate.notNull(store, "Store cannot be null");
attribute.setProductId(productId);
ProductAttribute attr = new ProductAttribute();
if (attribute.getId() != null && attribute.getId().longValue() > 0) {
attr = productAttributeService.getById(attribute.getId());
if (attr == null) {
throw new ResourceNotFoundException("Product attribute [" + attribute.getId() + "] not found");
}
if (productId != attr.getProduct().getId().longValue()) {
throw new ResourceNotFoundException("Product attribute [" + attribute.getId() + "] not found for product [" + productId + "]");
}
}
attr = persistableProductAttributeMapper.merge(attribute, attr, store, language);
try {
productAttributeService.saveOrUpdate(attr);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while saving ProductAttribute", e);
}
// refresh
attr = productAttributeService.getById(attr.getId());
ReadableProductAttributeEntity readable = readableProductAttributeMapper.convert(attr, store, language);
return readable;
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class TaxFacadeImpl method taxClasses.
@Override
public ReadableEntityList<ReadableTaxClass> taxClasses(MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
try {
List<TaxClass> models = taxClassService.listByStore(store);
List<ReadableTaxClass> taxClasses = models.stream().map(t -> convertToReadableTaxClass(t, store, language)).collect(Collectors.toList());
ReadableEntityList<ReadableTaxClass> list = new ReadableEntityList<ReadableTaxClass>();
list.setItems(taxClasses);
list.setNumber(taxClasses.size());
list.setTotalPages(1);
list.setRecordsTotal(taxClasses.size());
return list;
} catch (ServiceException e) {
LOGGER.error("Error while getting taxClasses for store [" + store.getCode() + "]", e);
throw new ServiceRuntimeException("Error while getting taxClasses for store [" + store.getCode() + "]", e);
}
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class TaxFacadeImpl method taxRates.
@Override
public ReadableEntityList<ReadableTaxRate> taxRates(MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
try {
List<TaxRate> rates = taxRateService.listByStore(store, language);
List<ReadableTaxRate> readableRates = rates.stream().map(r -> readableTaxRateMapper.convert(r, store, language)).collect(Collectors.toList());
ReadableEntityList<ReadableTaxRate> returnRates = new ReadableEntityList<ReadableTaxRate>();
returnRates.setItems(readableRates);
returnRates.setTotalPages(1);
returnRates.setNumber(readableRates.size());
returnRates.setRecordsTotal(readableRates.size());
return returnRates;
} catch (ServiceException e) {
LOGGER.error("Error while getting taxRates for store [" + store.getCode() + "]", e);
throw new ServiceRuntimeException("Error while getting taxRates for store [" + store.getCode() + "]", e);
}
}
Aggregations