use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ShippingFacadeImpl method updatePackage.
@Override
public void updatePackage(String code, PackageDetails packaging, MerchantStore store) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(packaging, "PackageDetails cannot be null");
Validate.notEmpty(code, "Packaging unique code cannot be empty");
ShippingConfiguration config = getDbConfig(store);
com.salesmanager.core.model.shipping.Package p = this.packageDetails(config, code);
if (p == null) {
throw new ResourceNotFoundException("Package with unique code [" + packaging.getCode() + "] not found");
}
com.salesmanager.core.model.shipping.Package pack = toPackage(packaging);
pack.setCode(code);
// need to check if code exists
List<com.salesmanager.core.model.shipping.Package> packs = config.getPackages().stream().filter(pa -> !pa.getCode().equals(code)).collect(Collectors.toList());
packs.add(pack);
config.setPackages(packs);
this.saveShippingConfiguration(config, store);
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ShippingFacadeImpl method getPackage.
@Override
public PackageDetails getPackage(String code, MerchantStore store) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notEmpty(code, "Packaging unique code cannot be empty");
ShippingConfiguration config = getDbConfig(store);
com.salesmanager.core.model.shipping.Package p = this.packageDetails(config, code);
if (p == null) {
throw new ResourceNotFoundException("Package with unique code [" + code + "] not found");
}
return toPackageDetails(p);
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductImageApi method uploadImage.
/**
* To be used with MultipartFile
*
* @param id
* @param uploadfiles
* @param request
* @param response
* @throws Exception
*/
@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = { "/private/products/{id}/images", "/auth/products/{id}/images" }, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE }, method = RequestMethod.POST)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public void uploadImage(@PathVariable Long id, @RequestParam(value = "file", required = true) MultipartFile[] files, @RequestParam(value = "order", required = false, defaultValue = "0") Integer position, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) throws IOException {
try {
// get the product
Product product = productService.getById(id);
if (product == null) {
throw new ResourceNotFoundException("Product not found");
}
// product belongs to merchant store
if (product.getMerchantStore().getId().intValue() != merchantStore.getId().intValue()) {
throw new UnauthorizedException("Resource not authorized for this merchant");
}
boolean hasDefaultImage = false;
Set<ProductImage> images = product.getImages();
if (!CollectionUtils.isEmpty(images)) {
for (ProductImage image : images) {
if (image.isDefaultImage()) {
hasDefaultImage = true;
break;
}
}
}
List<ProductImage> contentImagesList = new ArrayList<ProductImage>();
int sortOrder = position;
for (MultipartFile multipartFile : files) {
if (!multipartFile.isEmpty()) {
ProductImage productImage = new ProductImage();
productImage.setImage(multipartFile.getInputStream());
productImage.setProductImage(multipartFile.getOriginalFilename());
productImage.setProduct(product);
if (!hasDefaultImage) {
productImage.setDefaultImage(true);
hasDefaultImage = true;
}
productImage.setSortOrder(sortOrder);
position++;
contentImagesList.add(productImage);
}
}
if (CollectionUtils.isNotEmpty(contentImagesList)) {
productImageService.addProductImages(product, contentImagesList);
}
} catch (Exception e) {
LOGGER.error("Error while creating ProductImage", e);
throw new ServiceRuntimeException("Error while creating image");
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductImageApi method images.
/**
* Get product images
* @param id
* @param imageId
* @param merchantStore
* @param language
* @return
*/
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = { "/products/{productId}/images" }, method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "Get images for a given product")
@ApiResponses(value = { @ApiResponse(code = 200, message = "List of ProductImage found", response = List.class) })
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public List<ReadableImage> images(@PathVariable Long productId, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
Product p = productService.getById(productId);
if (p == null) {
throw new ResourceNotFoundException("Product images not found for product id [" + productId + "] and merchant [" + merchantStore.getCode() + "]");
}
if (p.getMerchantStore().getId() != merchantStore.getId()) {
throw new ResourceNotFoundException("Product images not found for product id [" + productId + "] and merchant [" + merchantStore.getCode() + "]");
}
List<ReadableImage> target = new ArrayList<ReadableImage>();
Set<ProductImage> images = p.getImages();
if (images != null && images.size() > 0) {
target = images.stream().map(i -> image(i, merchantStore, language)).sorted(Comparator.comparingInt(ReadableImage::getOrder)).collect(Collectors.toList());
}
return target;
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductInstanceGroupFacadeImpl method removeImage.
@Override
public void removeImage(Long imageId, Long productInstanceGroupId, MerchantStore store) {
Validate.notNull(productInstanceGroupId, "productInstanceGroupId must not be null");
Validate.notNull(store, "MerchantStore must not be null");
ProductInstanceImage image = productInstanceImageService.getById(imageId);
if (image == null) {
throw new ResourceNotFoundException("ProductInstanceImage [" + imageId + "] was not found");
}
ProductInstanceGroup group = this.group(productInstanceGroupId, store);
try {
contentService.removeFile(Constants.SLASH + store.getCode() + Constants.SLASH + productInstanceGroupId, FileContentType.INSTANCE, image.getProductImage());
group.getImages().removeIf(i -> (i.getId() == image.getId()));
// update productinstanceroup
productInstanceGroupService.update(group);
} catch (ServiceException e) {
throw new ServiceRuntimeException("An exception occured while removing instance image [" + imageId + "]", e);
}
}
Aggregations