Search in sources :

Example 26 with ServiceException

use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.

the class ProductInstanceGroupFacadeImpl method update.

@Override
public void update(Long productInstanceGroup, PersistableProductInstanceGroup instance, MerchantStore store, Language language) {
    ProductInstanceGroup group = this.group(productInstanceGroup, store);
    instance.setId(productInstanceGroup);
    group = persistableProductIntanceGroupMapper.merge(instance, group, store, language);
    try {
        productInstanceGroupService.saveOrUpdate(group);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Cannot save product instance group [" + productInstanceGroup + "] for store [" + store.getCode() + "]");
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductInstanceGroup(com.salesmanager.core.model.catalog.product.instance.ProductInstanceGroup) ReadableProductInstanceGroup(com.salesmanager.shop.model.catalog.product.product.instanceGroup.ReadableProductInstanceGroup) PersistableProductInstanceGroup(com.salesmanager.shop.model.catalog.product.product.instanceGroup.PersistableProductInstanceGroup) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 27 with ServiceException

use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.

the class ProductInstanceGroupFacadeImpl method delete.

@Override
public void delete(Long productInstanceGroup, Long productId, MerchantStore store) {
    ProductInstanceGroup group = this.group(productInstanceGroup, store);
    if (group == null) {
        throw new ResourceNotFoundException("Product instance group [" + group.getId() + " not found for store [" + store.getCode() + "]");
    }
    try {
        // null all group from instances
        for (ProductInstance instance : group.getProductInstances()) {
            Optional<ProductInstance> p = productInstanceService.getById(instance.getId(), store);
            if (p.isEmpty()) {
                throw new ResourceNotFoundException("Product instance [" + instance.getId() + " not found for store [" + store.getCode() + "]");
            }
            instance.setProductInstanceGroup(null);
            productInstanceService.save(instance);
        }
        // now delete
        productInstanceGroupService.delete(group);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Cannot remove product instance group [" + productInstanceGroup + "] for store [" + store.getCode() + "]");
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductInstanceGroup(com.salesmanager.core.model.catalog.product.instance.ProductInstanceGroup) ReadableProductInstanceGroup(com.salesmanager.shop.model.catalog.product.product.instanceGroup.ReadableProductInstanceGroup) PersistableProductInstanceGroup(com.salesmanager.shop.model.catalog.product.product.instanceGroup.PersistableProductInstanceGroup) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 28 with ServiceException

use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.

the class ProductOptionFacadeImpl method saveAttribute.

@Override
public ReadableProductAttributeEntity saveAttribute(Long productId, PersistableProductAttribute attribute, MerchantStore store, Language language) {
    Validate.notNull(productId, "Product id cannot be null");
    Validate.notNull(attribute, "ProductAttribute cannot be null");
    Validate.notNull(attribute.getOption(), "ProductAttribute option cannot be null");
    Validate.notNull(attribute.getOptionValue(), "ProductAttribute option value cannot be null");
    Validate.notNull(store, "Store cannot be null");
    attribute.setProductId(productId);
    ProductAttribute attr = new ProductAttribute();
    if (attribute.getId() != null && attribute.getId().longValue() > 0) {
        attr = productAttributeService.getById(attribute.getId());
        if (attr == null) {
            throw new ResourceNotFoundException("Product attribute [" + attribute.getId() + "] not found");
        }
        if (productId != attr.getProduct().getId().longValue()) {
            throw new ResourceNotFoundException("Product attribute [" + attribute.getId() + "] not found for product [" + productId + "]");
        }
    }
    attr = persistableProductAttributeMapper.merge(attribute, attr, store, language);
    try {
        productAttributeService.saveOrUpdate(attr);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while saving ProductAttribute", e);
    }
    // refresh
    attr = productAttributeService.getById(attr.getId());
    ReadableProductAttributeEntity readable = readableProductAttributeMapper.convert(attr, store, language);
    return readable;
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) PersistableProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductAttribute) ReadableProductAttributeEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 29 with ServiceException

use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.

the class TaxFacadeImpl method taxClasses.

@Override
public ReadableEntityList<ReadableTaxClass> taxClasses(MerchantStore store, Language language) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        List<TaxClass> models = taxClassService.listByStore(store);
        List<ReadableTaxClass> taxClasses = models.stream().map(t -> convertToReadableTaxClass(t, store, language)).collect(Collectors.toList());
        ReadableEntityList<ReadableTaxClass> list = new ReadableEntityList<ReadableTaxClass>();
        list.setItems(taxClasses);
        list.setNumber(taxClasses.size());
        list.setTotalPages(1);
        list.setRecordsTotal(taxClasses.size());
        return list;
    } catch (ServiceException e) {
        LOGGER.error("Error while getting taxClasses for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while getting taxClasses for store [" + store.getCode() + "]", e);
    }
}
Also used : PersistableTaxClassMapper(com.salesmanager.shop.mapper.tax.PersistableTaxClassMapper) Entity(com.salesmanager.shop.model.entity.Entity) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) TaxRateService(com.salesmanager.core.business.services.tax.TaxRateService) PersistableTaxRateMapper(com.salesmanager.shop.mapper.tax.PersistableTaxRateMapper) TaxClassService(com.salesmanager.core.business.services.tax.TaxClassService) ServiceException(com.salesmanager.core.business.exception.ServiceException) TaxRate(com.salesmanager.core.model.tax.taxrate.TaxRate) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableTaxRate(com.salesmanager.shop.model.tax.ReadableTaxRate) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) PersistableTaxRate(com.salesmanager.shop.model.tax.PersistableTaxRate) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) Logger(org.slf4j.Logger) TaxFacade(com.salesmanager.shop.store.controller.tax.facade.TaxFacade) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) ReadableTaxClassMapper(com.salesmanager.shop.mapper.tax.ReadableTaxClassMapper) Collectors(java.util.stream.Collectors) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) List(java.util.List) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) Validate(org.apache.commons.lang3.Validate) ReadableTaxRateMapper(com.salesmanager.shop.mapper.tax.ReadableTaxRateMapper) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ServiceException(com.salesmanager.core.business.exception.ServiceException) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 30 with ServiceException

use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.

the class TaxFacadeImpl method taxRates.

@Override
public ReadableEntityList<ReadableTaxRate> taxRates(MerchantStore store, Language language) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        List<TaxRate> rates = taxRateService.listByStore(store, language);
        List<ReadableTaxRate> readableRates = rates.stream().map(r -> readableTaxRateMapper.convert(r, store, language)).collect(Collectors.toList());
        ReadableEntityList<ReadableTaxRate> returnRates = new ReadableEntityList<ReadableTaxRate>();
        returnRates.setItems(readableRates);
        returnRates.setTotalPages(1);
        returnRates.setNumber(readableRates.size());
        returnRates.setRecordsTotal(readableRates.size());
        return returnRates;
    } catch (ServiceException e) {
        LOGGER.error("Error while getting taxRates for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while getting taxRates for store [" + store.getCode() + "]", e);
    }
}
Also used : PersistableTaxClassMapper(com.salesmanager.shop.mapper.tax.PersistableTaxClassMapper) Entity(com.salesmanager.shop.model.entity.Entity) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) TaxRateService(com.salesmanager.core.business.services.tax.TaxRateService) PersistableTaxRateMapper(com.salesmanager.shop.mapper.tax.PersistableTaxRateMapper) TaxClassService(com.salesmanager.core.business.services.tax.TaxClassService) ServiceException(com.salesmanager.core.business.exception.ServiceException) TaxRate(com.salesmanager.core.model.tax.taxrate.TaxRate) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableTaxRate(com.salesmanager.shop.model.tax.ReadableTaxRate) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) PersistableTaxRate(com.salesmanager.shop.model.tax.PersistableTaxRate) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) Logger(org.slf4j.Logger) TaxFacade(com.salesmanager.shop.store.controller.tax.facade.TaxFacade) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) ReadableTaxClassMapper(com.salesmanager.shop.mapper.tax.ReadableTaxClassMapper) Collectors(java.util.stream.Collectors) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) List(java.util.List) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) Validate(org.apache.commons.lang3.Validate) ReadableTaxRateMapper(com.salesmanager.shop.mapper.tax.ReadableTaxRateMapper) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ServiceException(com.salesmanager.core.business.exception.ServiceException) TaxRate(com.salesmanager.core.model.tax.taxrate.TaxRate) ReadableTaxRate(com.salesmanager.shop.model.tax.ReadableTaxRate) PersistableTaxRate(com.salesmanager.shop.model.tax.PersistableTaxRate) ReadableTaxRate(com.salesmanager.shop.model.tax.ReadableTaxRate) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

ServiceException (com.salesmanager.core.business.exception.ServiceException)230 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)88 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)54 ArrayList (java.util.ArrayList)45 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)44 Language (com.salesmanager.core.model.reference.language.Language)38 List (java.util.List)36 Collectors (java.util.stream.Collectors)30 IOException (java.io.IOException)28 InputStream (java.io.InputStream)27 IntegrationConfiguration (com.salesmanager.core.model.system.IntegrationConfiguration)22 Autowired (org.springframework.beans.factory.annotation.Autowired)21 OutputContentFile (com.salesmanager.core.model.content.OutputContentFile)20 Product (com.salesmanager.core.model.catalog.product.Product)19 HashMap (java.util.HashMap)19 Map (java.util.Map)18 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)17 InputContentFile (com.salesmanager.core.model.content.InputContentFile)17 Optional (java.util.Optional)17 IntegrationModule (com.salesmanager.core.model.system.IntegrationModule)16