use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method addOptionValueImage.
@Override
public void addOptionValueImage(MultipartFile image, Long optionValueId, MerchantStore store, Language language) {
Validate.notNull(optionValueId, "OptionValueId must not be null");
Validate.notNull(image, "Image must not be null");
// get option value
ProductOptionValue value = productOptionValueService.getById(store, optionValueId);
if (value == null) {
throw new ResourceNotFoundException("Product option value [" + optionValueId + "] not found");
}
try {
String imageName = image.getOriginalFilename();
InputStream inputStream = image.getInputStream();
InputContentFile cmsContentImage = new InputContentFile();
cmsContentImage.setFileName(imageName);
cmsContentImage.setMimeType(image.getContentType());
cmsContentImage.setFile(inputStream);
contentService.addOptionImage(store.getCode(), cmsContentImage);
value.setProductOptionValueImage(imageName);
productOptionValueService.saveOrUpdate(value);
} catch (Exception e) {
throw new ServiceRuntimeException("Exception while adding option value image", e);
}
return;
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method removeOptionValueImage.
@Override
public void removeOptionValueImage(Long optionValueId, MerchantStore store, Language language) {
Validate.notNull(optionValueId, "OptionValueId must not be null");
ProductOptionValue value = productOptionValueService.getById(store, optionValueId);
if (value == null) {
throw new ResourceNotFoundException("Product option value [" + optionValueId + "] not found");
}
try {
contentService.removeFile(store.getCode(), FileContentType.PROPERTY, value.getProductOptionValueImage());
value.setProductOptionValueImage(null);
productOptionValueService.saveOrUpdate(value);
} catch (Exception e) {
throw new ServiceRuntimeException("Exception while removing option value image", e);
}
return;
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ProductTypeFacadeImpl method update.
@Override
public void update(PersistableProductType type, Long id, MerchantStore store, Language language) {
Validate.notNull(type, "ProductType cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(id, "id cannot be empty");
try {
ProductType t = productTypeService.getById(id, store, language);
if (t == null) {
throw new ResourceNotFoundException("Product type [" + type.getCode() + "] does not exist for store [" + store.getCode() + "]");
}
type.setId(t.getId());
type.setCode(t.getCode());
ProductType model = persistableProductTypeMapper.merge(type, t, store, language);
model.setMerchantStore(store);
productTypeService.saveOrUpdate(model);
} catch (Exception e) {
throw new ServiceRuntimeException("An exception occured while saving product type", e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ProductTypeFacadeImpl method get.
@Override
public ReadableProductType get(MerchantStore store, Long id, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(id, "ProductType code cannot be empty");
try {
ProductType type = null;
if (language == null) {
type = productTypeService.getById(id, store);
} else {
type = productTypeService.getById(id, store, language);
}
if (type == null) {
throw new ResourceNotFoundException("Product type [" + id + "] not found for store [" + store.getCode() + "]");
}
ReadableProductType readableType = readableProductTypeMapper.convert(type, store, language);
return readableType;
} catch (Exception e) {
throw new ServiceRuntimeException("An exception occured while getting product type [" + id + "] not found for store [" + store.getCode() + "]", e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ProductTypeFacadeImpl method getByMerchant.
@Override
public ReadableProductTypeList getByMerchant(MerchantStore store, Language language, int count, int page) {
Validate.notNull(store, "MerchantStore cannot be null");
ReadableProductTypeList returnList = new ReadableProductTypeList();
try {
Page<ProductType> types = productTypeService.getByMerchant(store, language, page, count);
if (types != null) {
returnList.setList(types.getContent().stream().map(t -> readableProductTypeMapper.convert(t, store, language)).collect(Collectors.toList()));
returnList.setTotalPages(types.getTotalPages());
returnList.setRecordsTotal(types.getTotalElements());
returnList.setRecordsFiltered(types.getSize());
}
return returnList;
} catch (Exception e) {
throw new ServiceRuntimeException("An exception occured while getting product types for merchant[ " + store.getCode() + "]", e);
}
}
Aggregations