Search in sources :

Example 66 with ServiceException

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

the class ShippingServiceImpl method removeCustomShippingQuoteModuleConfiguration.

@Override
public void removeCustomShippingQuoteModuleConfiguration(String moduleCode, MerchantStore store) throws ServiceException {
    try {
        removeShippingQuoteModuleConfiguration(moduleCode, store);
        MerchantConfiguration merchantConfiguration = merchantConfigurationService.getMerchantConfiguration(moduleCode, store);
        if (merchantConfiguration != null) {
            merchantConfigurationService.delete(merchantConfiguration);
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 67 with ServiceException

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

the class ShippingServiceImpl method saveCustomShippingConfiguration.

@Override
public void saveCustomShippingConfiguration(String moduleCode, CustomIntegrationConfiguration shippingConfiguration, MerchantStore store) throws ServiceException {
    ShippingQuoteModule quoteModule = shippingModules.get(moduleCode);
    if (quoteModule == null) {
        throw new ServiceException("Shipping module " + moduleCode + " does not exist");
    }
    String configurationValue = shippingConfiguration.toJSONString();
    try {
        MerchantConfiguration configuration = merchantConfigurationService.getMerchantConfiguration(moduleCode, store);
        if (configuration == null) {
            configuration = new MerchantConfiguration();
            configuration.setKey(moduleCode);
            configuration.setMerchantStore(store);
        }
        configuration.setValue(configurationValue);
        merchantConfigurationService.saveOrUpdate(configuration);
    } catch (Exception e) {
        throw new IntegrationException(e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) ShippingQuoteModule(com.salesmanager.core.modules.integration.shipping.model.ShippingQuoteModule) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 68 with ServiceException

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

the class ShoppingCartServiceImpl method getPopulatedShoppingCart.

/*	@Override
	@Transactional
	public ShoppingCart getByCustomer(final Customer customer) throws ServiceException {

		try {
			List<ShoppingCart> shoppingCart = shoppingCartRepository.findByCustomer(customer.getId());
			if (shoppingCart == null) {
				return null;
			}
			return getPopulatedShoppingCart(shoppingCart);

		} catch (Exception e) {
			throw new ServiceException(e);
		}
	}*/
@Transactional(noRollbackFor = { org.springframework.dao.EmptyResultDataAccessException.class })
private ShoppingCart getPopulatedShoppingCart(final ShoppingCart shoppingCart) throws Exception {
    try {
        boolean cartIsObsolete = false;
        if (shoppingCart != null) {
            Set<ShoppingCartItem> items = shoppingCart.getLineItems();
            if (items == null || items.size() == 0) {
                shoppingCart.setObsolete(true);
                return shoppingCart;
            }
            // HashSet<ShoppingCartItem>();
            for (ShoppingCartItem item : items) {
                LOGGER.debug("Populate item " + item.getId());
                getPopulatedItem(item);
                LOGGER.debug("Obsolete item ? " + item.isObsolete());
                if (item.isObsolete()) {
                    cartIsObsolete = true;
                }
            }
            // shoppingCart.setLineItems(shoppingCartItems);
            Set<ShoppingCartItem> refreshedItems = new HashSet<>(items);
            // if (refreshCart) {
            shoppingCart.setLineItems(refreshedItems);
            update(shoppingCart);
            if (cartIsObsolete) {
                shoppingCart.setObsolete(true);
            }
            return shoppingCart;
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
        throw new ServiceException(e);
    }
    return shoppingCart;
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ShoppingCartItem(com.salesmanager.core.model.shoppingcart.ShoppingCartItem) ServiceException(com.salesmanager.core.business.exception.ServiceException) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 69 with ServiceException

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

the class LanguageServiceImpl method getLanguages.

@Override
@SuppressWarnings("unchecked")
public List<Language> getLanguages() throws ServiceException {
    List<Language> langs = null;
    try {
        langs = (List<Language>) cache.getFromCache("LANGUAGES");
        if (langs == null) {
            langs = this.list();
            cache.putInCache(langs, "LANGUAGES");
        }
    } catch (Exception e) {
        LOGGER.error("getCountries()", e);
        throw new ServiceException(e);
    }
    return langs;
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceException(com.salesmanager.core.business.exception.ServiceException)

Example 70 with ServiceException

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

the class ConfigurationModulesLoader method loadIntegrationConfigurations.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static Map<String, IntegrationConfiguration> loadIntegrationConfigurations(String value) throws Exception {
    Map<String, IntegrationConfiguration> modules = new HashMap<String, IntegrationConfiguration>();
    ObjectMapper mapper = new ObjectMapper();
    try {
        Map[] objects = mapper.readValue(value, Map[].class);
        for (Map object : objects) {
            IntegrationConfiguration configuration = new IntegrationConfiguration();
            String moduleCode = (String) object.get("moduleCode");
            if (object.get("active") != null) {
                configuration.setActive((Boolean) object.get("active"));
            }
            if (object.get("defaultSelected") != null) {
                configuration.setDefaultSelected((Boolean) object.get("defaultSelected"));
            }
            if (object.get("environment") != null) {
                configuration.setEnvironment((String) object.get("environment"));
            }
            configuration.setModuleCode(moduleCode);
            modules.put(moduleCode, configuration);
            if (object.get("integrationKeys") != null) {
                Map<String, String> confs = (Map<String, String>) object.get("integrationKeys");
                configuration.setIntegrationKeys(confs);
            }
            if (object.get("integrationKeys") != null) {
                Map<String, List<String>> options = (Map<String, List<String>>) object.get("integrationOptions");
                configuration.setIntegrationOptions(options);
            }
        }
        return modules;
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) HashMap(java.util.HashMap) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ServiceException(com.salesmanager.core.business.exception.ServiceException)

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