use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class ReadableOrderProductMapper method merge.
@Override
public ReadableOrderProduct merge(OrderProduct source, ReadableOrderProduct target, MerchantStore store, Language language) {
Validate.notNull(source, "OrderProduct cannot be null");
Validate.notNull(target, "ReadableOrderProduct cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
target.setId(source.getId());
target.setOrderedQuantity(source.getProductQuantity());
try {
target.setPrice(pricingService.getDisplayAmount(source.getOneTimeCharge(), store));
} catch (Exception e) {
throw new ConversionRuntimeException("Cannot convert price", e);
}
target.setProductName(source.getProductName());
target.setSku(source.getSku());
// subtotal = price * quantity
BigDecimal subTotal = source.getOneTimeCharge();
subTotal = subTotal.multiply(new BigDecimal(source.getProductQuantity()));
try {
String subTotalPrice = pricingService.getDisplayAmount(subTotal, store);
target.setSubTotal(subTotalPrice);
} catch (Exception e) {
throw new ConversionRuntimeException("Cannot format price", e);
}
if (source.getOrderAttributes() != null) {
List<ReadableOrderProductAttribute> attributes = new ArrayList<ReadableOrderProductAttribute>();
for (OrderProductAttribute attr : source.getOrderAttributes()) {
ReadableOrderProductAttribute readableAttribute = new ReadableOrderProductAttribute();
try {
String price = pricingService.getDisplayAmount(attr.getProductAttributePrice(), store);
readableAttribute.setAttributePrice(price);
} catch (ServiceException e) {
throw new ConversionRuntimeException("Cannot format price", e);
}
readableAttribute.setAttributeName(attr.getProductAttributeName());
readableAttribute.setAttributeValue(attr.getProductAttributeValueName());
attributes.add(readableAttribute);
}
target.setAttributes(attributes);
}
String productSku = source.getSku();
if (!StringUtils.isBlank(productSku)) {
Product product = productService.getByCode(productSku, language);
if (product != null) {
// TODO autowired
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
ReadableProduct productProxy;
try {
productProxy = populator.populate(product, new ReadableProduct(), store, language);
target.setProduct(productProxy);
} catch (ConversionException e) {
throw new ConversionRuntimeException("Cannot convert product", e);
}
Set<ProductImage> images = product.getImages();
ProductImage defaultImage = null;
if (images != null) {
for (ProductImage image : images) {
if (defaultImage == null) {
defaultImage = image;
}
if (image.isDefaultImage()) {
defaultImage = image;
}
}
}
if (defaultImage != null) {
target.setImage(defaultImage.getProductImage());
}
}
}
return target;
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class ReadableOrderProductPopulator method populate.
@Override
public ReadableOrderProduct populate(OrderProduct source, ReadableOrderProduct target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(productService, "Requires ProductService");
Validate.notNull(pricingService, "Requires PricingService");
Validate.notNull(imageUtils, "Requires imageUtils");
target.setId(source.getId());
target.setOrderedQuantity(source.getProductQuantity());
try {
target.setPrice(pricingService.getDisplayAmount(source.getOneTimeCharge(), store));
} catch (Exception e) {
throw new ConversionException("Cannot convert price", e);
}
target.setProductName(source.getProductName());
target.setSku(source.getSku());
// subtotal = price * quantity
BigDecimal subTotal = source.getOneTimeCharge();
subTotal = subTotal.multiply(new BigDecimal(source.getProductQuantity()));
try {
String subTotalPrice = pricingService.getDisplayAmount(subTotal, store);
target.setSubTotal(subTotalPrice);
} catch (Exception e) {
throw new ConversionException("Cannot format price", e);
}
if (source.getOrderAttributes() != null) {
List<ReadableOrderProductAttribute> attributes = new ArrayList<ReadableOrderProductAttribute>();
for (OrderProductAttribute attr : source.getOrderAttributes()) {
ReadableOrderProductAttribute readableAttribute = new ReadableOrderProductAttribute();
try {
String price = pricingService.getDisplayAmount(attr.getProductAttributePrice(), store);
readableAttribute.setAttributePrice(price);
} catch (ServiceException e) {
throw new ConversionException("Cannot format price", e);
}
readableAttribute.setAttributeName(attr.getProductAttributeName());
readableAttribute.setAttributeValue(attr.getProductAttributeValueName());
attributes.add(readableAttribute);
}
target.setAttributes(attributes);
}
String productSku = source.getSku();
if (!StringUtils.isBlank(productSku)) {
Product product = productService.getByCode(productSku, language);
if (product != null) {
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
ReadableProduct productProxy = populator.populate(product, new ReadableProduct(), store, language);
target.setProduct(productProxy);
Set<ProductImage> images = product.getImages();
ProductImage defaultImage = null;
if (images != null) {
for (ProductImage image : images) {
if (defaultImage == null) {
defaultImage = image;
}
if (image.isDefaultImage()) {
defaultImage = image;
}
}
}
if (defaultImage != null) {
target.setImage(defaultImage.getProductImage());
}
}
}
return target;
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class ShoppingCartItemPopulator method populate.
@Override
public ShoppingCartItem populate(PersistableOrderProduct source, /**
* TODO: Fix, target not used possible future bug ! *
*/
ShoppingCartItem target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(productService, "Requires to set productService");
Validate.notNull(productAttributeService, "Requires to set productAttributeService");
Validate.notNull(shoppingCartService, "Requires to set shoppingCartService");
Product product = productService.getById(source.getProduct().getId());
if (source.getAttributes() != null) {
for (com.salesmanager.shop.model.catalog.product.attribute.ProductAttribute attr : source.getAttributes()) {
ProductAttribute attribute = productAttributeService.getById(attr.getId());
if (attribute == null) {
throw new ConversionException("ProductAttribute with id " + attr.getId() + " is null");
}
if (attribute.getProduct().getId().longValue() != source.getProduct().getId().longValue()) {
throw new ConversionException("ProductAttribute with id " + attr.getId() + " is not assigned to Product id " + source.getProduct().getId());
}
product.getAttributes().add(attribute);
}
}
try {
return shoppingCartService.populateShoppingCartItem(product);
} catch (ServiceException e) {
throw new ConversionException(e);
}
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class CategoryFacadeImpl method saveCategory.
private void saveCategory(MerchantStore store, Category category, Category parent) throws ServiceException {
/**
* set lineage *
*/
if (parent != null) {
category.setParent(category);
String lineage = parent.getLineage();
int depth = parent.getDepth();
category.setDepth(depth + 1);
// service
category.setLineage(new StringBuilder().append(lineage).toString());
// will
// adjust
// lineage
}
category.setMerchantStore(store);
// remove children
List<Category> children = category.getCategories();
List<Category> saveAfter = children.stream().filter(c -> c.getId() == null || c.getId().longValue() == 0).collect(Collectors.toList());
List<Category> saveNow = children.stream().filter(c -> c.getId() != null && c.getId().longValue() > 0).collect(Collectors.toList());
category.setCategories(saveNow);
/**
* set parent *
*/
if (parent != null) {
category.setParent(parent);
}
categoryService.saveOrUpdate(category);
if (!CollectionUtils.isEmpty(saveAfter)) {
parent = category;
for (Category c : saveAfter) {
if (c.getId() == null || c.getId().longValue() == 0) {
for (Category sub : children) {
saveCategory(store, sub, parent);
}
}
}
}
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method convertContentToReadableContentFull.
@Deprecated
private ReadableContentFull convertContentToReadableContentFull(MerchantStore store, Language language, Content content) {
ReadableContentFull contentFull = new ReadableContentFull();
try {
List<ContentDescriptionEntity> descriptions = this.createContentDescriptionEntitys(store, content, language);
contentFull.setDescriptions(descriptions);
contentFull.setId(content.getId());
contentFull.setDisplayedInMenu(content.isLinkToMenu());
contentFull.setContentType(content.getContentType().name());
contentFull.setCode(content.getCode());
contentFull.setId(content.getId());
contentFull.setVisible(content.isVisible());
return contentFull;
} catch (ServiceException e) {
throw new ServiceRuntimeException("Error while creating ReadableContentFull", e);
}
}
Aggregations