use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ProductVariationFacadeImpl method delete.
@Override
public void delete(Long variationId, MerchantStore store) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(variationId, "variationId cannot be null");
ProductVariation opt = productVariationService.getById(variationId);
if (opt == null) {
throw new ResourceNotFoundException("ProductVariation not found for id [" + variationId + "] and store [" + store.getCode() + "]");
}
if (!opt.getMerchantStore().getCode().equals(store.getCode())) {
throw new ResourceNotFoundException("ProductVariation not found for id [" + variationId + "] and store [" + store.getCode() + "]");
}
try {
productVariationService.delete(opt);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while deleting ProductVariation", e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class SanitizeUtils method getSafeString.
public static String getSafeString(String value) {
try {
if (policy == null) {
throw new ServiceRuntimeException("Error in " + SanitizeUtils.class.getName() + " html sanitize utils is null");
}
AntiSamy as = new AntiSamy();
CleanResults cr = as.scan(value, policy);
return cr.getCleanHTML();
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class LanguageUtils method getRESTLanguage.
/**
* Should be used by rest web services
*
* @param request
* @param store
* @return
* @throws Exception
*/
public Language getRESTLanguage(HttpServletRequest request, NativeWebRequest webRequest) {
Validate.notNull(request, "HttpServletRequest must not be null");
try {
Language language = null;
String lang = request.getParameter(Constants.LANG);
if (StringUtils.isBlank(lang)) {
if (language == null) {
String storeValue = Optional.ofNullable(webRequest.getParameter(REQUEST_PARAMATER_STORE)).filter(StringUtils::isNotBlank).orElse(DEFAULT_STORE);
if (!StringUtils.isBlank(storeValue)) {
try {
MerchantStore storeModel = storeFacade.get(storeValue);
language = storeModel.getDefaultLanguage();
} catch (Exception e) {
logger.warn("Cannot get store with code [" + storeValue + "]");
}
} else {
language = languageService.defaultLanguage();
}
}
} else {
if (!ALL_LANGUALES.equals(lang)) {
language = languageService.getByCode(lang);
if (language == null) {
language = languageService.defaultLanguage();
}
}
}
// if language is null then underlying facade must load all languages
return language;
} catch (ServiceException e) {
throw new ServiceRuntimeException(e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class PersistableProductInstanceMapper method merge.
@Override
public ProductInstance merge(PersistableProductInstance source, ProductInstance destination, MerchantStore store, Language language) {
//
Long productVariant = source.getVariant();
Long productVariantValue = source.getVariantValue();
Optional<ProductVariation> variant = productVariationService.getById(store, productVariant);
Optional<ProductVariation> variantValue = productVariationService.getById(store, productVariantValue);
if (variant.isEmpty()) {
throw new ResourceNotFoundException("ProductVariant [" + productVariant + "] + not found for store [" + store.getCode() + "]");
}
destination.setVariant(variant.get());
if (variantValue.isEmpty()) {
throw new ResourceNotFoundException("ProductVariant [" + productVariantValue + "] + not found for store [" + store.getCode() + "]");
}
destination.setVariantValue(variantValue.get());
destination.setCode(variant.get().getCode() + ":" + variantValue.get().getCode());
destination.setAvailable(source.isAvailable());
destination.setDefaultSelection(source.isDefaultSelection());
destination.setSku(source.getSku());
if (StringUtils.isBlank(source.getDateAvailable())) {
source.setDateAvailable(DateUtil.formatDate(new Date()));
}
if (source.getDateAvailable() != null) {
try {
destination.setDateAvailable(DateUtil.getDate(source.getDateAvailable()));
} catch (Exception e) {
throw new ServiceRuntimeException("Cant format date [" + source.getDateAvailable() + "]");
}
}
destination.setSortOrder(source.getSortOrder());
Product product = productService.getById(source.getProductId());
if (product == null) {
throw new ResourceNotFoundException("Product [" + source.getId() + "] + not found for store [" + store.getCode() + "]");
}
if (product.getMerchantStore().getId() != store.getId()) {
throw new ResourceNotFoundException("Product [" + source.getId() + "] + not found for store [" + store.getCode() + "]");
}
destination.setProduct(product);
return destination;
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class PersistableProductOptionMapper method merge.
@Override
public ProductOption merge(PersistableProductOptionEntity source, ProductOption destination, MerchantStore store, Language language) {
if (destination == null) {
destination = new ProductOption();
}
try {
if (!CollectionUtils.isEmpty(source.getDescriptions())) {
for (com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription desc : source.getDescriptions()) {
ProductOptionDescription description = null;
if (!CollectionUtils.isEmpty(destination.getDescriptions())) {
for (ProductOptionDescription d : destination.getDescriptions()) {
if (!StringUtils.isBlank(desc.getLanguage()) && desc.getLanguage().equals(d.getLanguage().getCode())) {
d.setDescription(desc.getDescription());
d.setName(desc.getName());
d.setTitle(desc.getTitle());
description = d;
break;
}
}
}
if (description == null) {
description = description(desc);
description.setProductOption(destination);
destination.getDescriptions().add(description);
}
}
}
destination.setCode(source.getCode());
destination.setMerchantStore(store);
destination.setProductOptionSortOrder(source.getOrder());
destination.setProductOptionType(source.getType());
destination.setReadOnly(source.isReadOnly());
return destination;
} catch (Exception e) {
throw new ServiceRuntimeException("Error while converting product option", e);
}
}
Aggregations