Search in sources :

Example 71 with ServiceException

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

the class IntegrationModulesLoader method loadIntegrationModules.

public List<IntegrationModule> loadIntegrationModules(String jsonFilePath) throws Exception {
    List<IntegrationModule> modules = new ArrayList<IntegrationModule>();
    ObjectMapper mapper = new ObjectMapper();
    try {
        InputStream in = this.getClass().getClassLoader().getResourceAsStream(jsonFilePath);
        @SuppressWarnings("rawtypes") Map[] objects = mapper.readValue(in, Map[].class);
        for (Map object : objects) {
            modules.add(this.loadModule(object));
        }
        return modules;
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) IntegrationModule(com.salesmanager.core.model.system.IntegrationModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ServiceException(com.salesmanager.core.business.exception.ServiceException)

Example 72 with ServiceException

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

the class PaymentServiceImpl method getPaymentModulesConfigured.

@Override
public Map<String, IntegrationConfiguration> getPaymentModulesConfigured(MerchantStore store) throws ServiceException {
    try {
        Map<String, IntegrationConfiguration> modules = new HashMap<String, IntegrationConfiguration>();
        MerchantConfiguration merchantConfiguration = merchantConfigurationService.getMerchantConfiguration(Constants.PAYMENT_MODULES, store);
        if (merchantConfiguration != null) {
            if (!StringUtils.isBlank(merchantConfiguration.getValue())) {
                String decrypted = encryption.decrypt(merchantConfiguration.getValue());
                modules = ConfigurationModulesLoader.loadIntegrationConfigurations(decrypted);
            }
        }
        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) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 73 with ServiceException

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

the class PaymentServiceImpl method removePaymentModuleConfiguration.

@Override
public void removePaymentModuleConfiguration(String moduleCode, MerchantStore store) throws ServiceException {
    try {
        Map<String, IntegrationConfiguration> modules = new HashMap<String, IntegrationConfiguration>();
        MerchantConfiguration merchantConfiguration = merchantConfigurationService.getMerchantConfiguration(Constants.PAYMENT_MODULES, store);
        if (merchantConfiguration != null) {
            if (!StringUtils.isBlank(merchantConfiguration.getValue())) {
                String decrypted = encryption.decrypt(merchantConfiguration.getValue());
                modules = ConfigurationModulesLoader.loadIntegrationConfigurations(decrypted);
            }
            modules.remove(moduleCode);
            String configs = ConfigurationModulesLoader.toJSONString(modules);
            String encrypted = encryption.encrypt(configs);
            merchantConfiguration.setValue(encrypted);
            merchantConfigurationService.saveOrUpdate(merchantConfiguration);
        }
        MerchantConfiguration configuration = merchantConfigurationService.getMerchantConfiguration(moduleCode, store);
        if (configuration != null) {
            // custom module
            merchantConfigurationService.delete(configuration);
        }
    } 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) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 74 with ServiceException

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

the class PaymentServiceImpl method validateCreditCard.

@Override
public void validateCreditCard(String number, CreditCardType creditCard, String month, String date) throws ServiceException {
    try {
        Integer.parseInt(month);
        Integer.parseInt(date);
    } catch (NumberFormatException nfe) {
        throw new ServiceException(ServiceException.EXCEPTION_VALIDATION, "Invalid date format", "messages.error.creditcard.dateformat");
    }
    if (StringUtils.isBlank(number)) {
        throw new ServiceException(ServiceException.EXCEPTION_VALIDATION, "Invalid card number", "messages.error.creditcard.number");
    }
    Matcher m = Pattern.compile("[^\\d\\s.-]").matcher(number);
    if (m.find()) {
        throw new ServiceException(ServiceException.EXCEPTION_VALIDATION, "Invalid card number", "messages.error.creditcard.number");
    }
    Matcher matcher = Pattern.compile("[\\s.-]").matcher(number);
    number = matcher.replaceAll("");
    validateCreditCardDate(Integer.parseInt(month), Integer.parseInt(date));
    validateCreditCardNumber(number, creditCard);
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) Matcher(java.util.regex.Matcher)

Example 75 with ServiceException

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

the class PaymentServiceImpl method savePaymentModuleConfiguration.

@Override
public void savePaymentModuleConfiguration(IntegrationConfiguration configuration, MerchantStore store) throws ServiceException {
    // validate entries
    try {
        String moduleCode = configuration.getModuleCode();
        PaymentModule module = paymentModules.get(moduleCode);
        if (module == null) {
            throw new ServiceException("Payment module " + moduleCode + " does not exist");
        }
        module.validateModuleConfiguration(configuration, store);
    } catch (IntegrationException ie) {
        throw ie;
    }
    try {
        Map<String, IntegrationConfiguration> modules = new HashMap<String, IntegrationConfiguration>();
        MerchantConfiguration merchantConfiguration = merchantConfigurationService.getMerchantConfiguration(Constants.PAYMENT_MODULES, store);
        if (merchantConfiguration != null) {
            if (!StringUtils.isBlank(merchantConfiguration.getValue())) {
                String decrypted = encryption.decrypt(merchantConfiguration.getValue());
                modules = ConfigurationModulesLoader.loadIntegrationConfigurations(decrypted);
            }
        } else {
            merchantConfiguration = new MerchantConfiguration();
            merchantConfiguration.setMerchantStore(store);
            merchantConfiguration.setKey(Constants.PAYMENT_MODULES);
        }
        modules.put(configuration.getModuleCode(), configuration);
        String configs = ConfigurationModulesLoader.toJSONString(modules);
        String encrypted = encryption.encrypt(configs);
        merchantConfiguration.setValue(encrypted);
        merchantConfigurationService.saveOrUpdate(merchantConfiguration);
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : PaymentModule(com.salesmanager.core.modules.integration.payment.model.PaymentModule) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) HashMap(java.util.HashMap) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

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