use of com.salesmanager.core.model.catalog.product.image.ProductImage in project shopizer by shopizer-ecommerce.
the class ProductImageServiceImpl method getProductImage.
// TODO get default product image
@Override
public OutputContentFile getProductImage(ProductImage productImage, ProductImageSize size) throws ServiceException {
ProductImage pi = new ProductImage();
String imageName = productImage.getProductImage();
if (size == ProductImageSize.LARGE) {
imageName = "L-" + imageName;
}
if (size == ProductImageSize.SMALL) {
imageName = "S-" + imageName;
}
pi.setProductImage(imageName);
pi.setProduct(productImage.getProduct());
return productFileManager.getProductImage(pi);
}
use of com.salesmanager.core.model.catalog.product.image.ProductImage in project shopizer by shopizer-ecommerce.
the class ProductServiceImpl method saveOrUpdate.
private void saveOrUpdate(Product product) throws ServiceException {
LOGGER.debug("Save or update product ");
Validate.notNull(product, "product cannot be null");
Validate.notNull(product.getAvailabilities(), "product must have at least one availability");
Validate.notEmpty(product.getAvailabilities(), "product must have at least one availability");
// take care of product images separately
Set<ProductImage> originalProductImages = new HashSet<ProductImage>(product.getImages());
if (product.getId() != null && product.getId() > 0) {
super.update(product);
} else {
super.create(product);
}
/**
* Image creation needs extra service to save the file in the CMS
*/
List<Long> newImageIds = new ArrayList<Long>();
Set<ProductImage> images = product.getImages();
try {
if (images != null && images.size() > 0) {
for (ProductImage image : images) {
if (image.getImage() != null && (image.getId() == null || image.getId() == 0L)) {
image.setProduct(product);
InputStream inputStream = image.getImage();
ImageContentFile cmsContentImage = new ImageContentFile();
cmsContentImage.setFileName(image.getProductImage());
cmsContentImage.setFile(inputStream);
cmsContentImage.setFileContentType(FileContentType.PRODUCT);
productImageService.addProductImage(product, image, cmsContentImage);
newImageIds.add(image.getId());
} else {
if (image.getId() != null) {
productImageService.save(image);
newImageIds.add(image.getId());
}
}
}
}
// cleanup old and new images
if (originalProductImages != null) {
for (ProductImage image : originalProductImages) {
if (image.getImage() != null && image.getId() == null) {
image.setProduct(product);
InputStream inputStream = image.getImage();
ImageContentFile cmsContentImage = new ImageContentFile();
cmsContentImage.setFileName(image.getProductImage());
cmsContentImage.setFile(inputStream);
cmsContentImage.setFileContentType(FileContentType.PRODUCT);
productImageService.addProductImage(product, image, cmsContentImage);
newImageIds.add(image.getId());
} else {
if (!newImageIds.contains(image.getId())) {
productImageService.delete(image);
}
}
}
}
} catch (Exception e) {
LOGGER.error("Cannot save images " + e.getMessage());
}
}
use of com.salesmanager.core.model.catalog.product.image.ProductImage in project shopizer by shopizer-ecommerce.
the class ProductServiceImpl method delete.
@Override
public void delete(Product product) throws ServiceException {
LOGGER.debug("Deleting product");
Validate.notNull(product, "Product cannot be null");
Validate.notNull(product.getMerchantStore(), "MerchantStore cannot be null in product");
// Prevents detached entity
product = this.getById(product.getId());
// error
product.setCategories(null);
Set<ProductImage> images = product.getImages();
for (ProductImage image : images) {
productImageService.removeProductImage(image);
}
product.setImages(null);
// delete reviews
List<ProductReview> reviews = productReviewService.getByProductNoCustomers(product);
for (ProductReview review : reviews) {
productReviewService.delete(review);
}
// related - featured
List<ProductRelationship> relationships = productRelationshipService.listByProduct(product);
for (ProductRelationship relationship : relationships) {
productRelationshipService.deleteRelationship(relationship);
}
super.delete(product);
searchService.deleteIndex(product.getMerchantStore(), product);
}
use of com.salesmanager.core.model.catalog.product.image.ProductImage in project shopizer by shopizer-ecommerce.
the class ProductTest method testViewImage.
private void testViewImage(Product product) throws Exception {
ProductImage productImage = product.getProductImage();
// get physical small image
OutputContentFile contentFile = productImageService.getProductImage(product.getMerchantStore().getCode(), product.getSku(), productImage.getProductImage(), ProductImageSize.SMALL);
Assert.assertNotNull(contentFile);
// get physical original image
contentFile = productImageService.getProductImage(product.getMerchantStore().getCode(), product.getSku(), productImage.getProductImage(), ProductImageSize.LARGE);
Assert.assertNotNull(contentFile);
}
use of com.salesmanager.core.model.catalog.product.image.ProductImage in project shopizer by shopizer-ecommerce.
the class ProductTest method testInsertImage.
/**
* Images
* @param product
* @throws Exception
*/
private void testInsertImage(Product product) throws Exception {
ProductImage productImage = new ProductImage();
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream inputStream = classloader.getResourceAsStream("img/" + IMAGE_NAME);
ImageContentFile cmsContentImage = new ImageContentFile();
cmsContentImage.setFileName(IMAGE_NAME);
cmsContentImage.setFile(inputStream);
cmsContentImage.setFileContentType(FileContentType.PRODUCT);
productImage.setProductImage(IMAGE_NAME);
productImage.setProduct(product);
// absolutely required otherwise the file is not created on disk
productImage.setImage(inputStream);
product.getImages().add(productImage);
// saves the ProductImage entity and the file on disk
productService.update(product);
}
Aggregations