Search in sources :

Example 31 with ServiceRuntimeException

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);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductVariation(com.salesmanager.core.model.catalog.product.variation.ProductVariation) ReadableProductVariation(com.salesmanager.shop.model.catalog.product.variation.ReadableProductVariation) PersistableProductVariation(com.salesmanager.shop.model.catalog.product.variation.PersistableProductVariation) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 32 with ServiceRuntimeException

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);
    }
}
Also used : AntiSamy(org.owasp.validator.html.AntiSamy) CleanResults(org.owasp.validator.html.CleanResults) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 33 with ServiceRuntimeException

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);
    }
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) ServiceException(com.salesmanager.core.business.exception.ServiceException) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 34 with ServiceRuntimeException

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;
}
Also used : ProductVariation(com.salesmanager.core.model.catalog.product.variation.ProductVariation) Product(com.salesmanager.core.model.catalog.product.Product) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Date(java.util.Date) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 35 with ServiceRuntimeException

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);
    }
}
Also used : ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) ProductOptionDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)146 ServiceException (com.salesmanager.core.business.exception.ServiceException)123 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)100 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)37 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)31 List (java.util.List)31 Collectors (java.util.stream.Collectors)31 Language (com.salesmanager.core.model.reference.language.Language)30 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)27 ArrayList (java.util.ArrayList)27 ConversionException (com.salesmanager.core.business.exception.ConversionException)26 Autowired (org.springframework.beans.factory.annotation.Autowired)21 Service (org.springframework.stereotype.Service)20 Optional (java.util.Optional)19 Product (com.salesmanager.core.model.catalog.product.Product)17 IOException (java.io.IOException)17 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 Inject (javax.inject.Inject)16 Page (org.springframework.data.domain.Page)16