Search in sources :

Example 16 with ServiceException

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

the class CmsImageFileManagerImpl method getImages.

@Override
public List<OutputContentFile> getImages(Product product) throws ServiceException {
    if (cacheManager.getTreeCache() == null) {
        throw new ServiceException("CmsImageFileManagerInfinispan has a null cacheManager.getTreeCache()");
    }
    List<OutputContentFile> images = new ArrayList<OutputContentFile>();
    try {
        FileNameMap fileNameMap = URLConnection.getFileNameMap();
        StringBuilder nodePath = new StringBuilder();
        nodePath.append(product.getMerchantStore().getCode());
        Node<String, Object> merchantNode = this.getNode(nodePath.toString());
        if (merchantNode == null) {
            return null;
        }
        for (String key : merchantNode.getKeys()) {
            byte[] imageBytes = (byte[]) merchantNode.get(key);
            OutputContentFile contentImage = new OutputContentFile();
            InputStream input = new ByteArrayInputStream(imageBytes);
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            IOUtils.copy(input, output);
            String contentType = fileNameMap.getContentTypeFor(key);
            contentImage.setFile(output);
            contentImage.setMimeType(contentType);
            contentImage.setFileName(key);
            images.add(contentImage);
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    } finally {
    }
    return images;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputContentFile(com.salesmanager.core.model.content.OutputContentFile) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileNameMap(java.net.FileNameMap) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 17 with ServiceException

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

the class CmsImageFileManagerImpl method getProductImage.

private OutputContentFile getProductImage(String merchantStoreCode, String productCode, String imageName, String size) throws ServiceException {
    if (cacheManager.getTreeCache() == null) {
        throw new ServiceException("CmsImageFileManagerInfinispan has a null cacheManager.getTreeCache()");
    }
    InputStream input = null;
    OutputContentFile contentImage = new OutputContentFile();
    try {
        FileNameMap fileNameMap = URLConnection.getFileNameMap();
        // SMALL by default
        StringBuilder nodePath = new StringBuilder();
        nodePath.append(merchantStoreCode).append(Constants.SLASH).append(productCode).append(Constants.SLASH).append(size);
        Node<String, Object> productNode = this.getNode(nodePath.toString());
        byte[] imageBytes = (byte[]) productNode.get(imageName);
        if (imageBytes == null) {
            LOGGER.warn("Image " + imageName + " does not exist");
            // no post processing will occur
            return null;
        }
        input = new ByteArrayInputStream(imageBytes);
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        IOUtils.copy(input, output);
        String contentType = fileNameMap.getContentTypeFor(imageName);
        contentImage.setFile(output);
        contentImage.setMimeType(contentType);
        contentImage.setFileName(imageName);
    } catch (Exception e) {
        throw new ServiceException(e);
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (Exception ignore) {
            }
        }
    }
    return contentImage;
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputContentFile(com.salesmanager.core.model.content.OutputContentFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileNameMap(java.net.FileNameMap) ServiceException(com.salesmanager.core.business.exception.ServiceException)

Example 18 with ServiceException

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

the class ImportIntegrationModule method importSpecificIntegrationModule.

/**
 * Import a specific integration module. Will delete and recreate the module
 * if it already exists
 * @throws Exception
 */
@Ignore
public // @Test
void importSpecificIntegrationModule() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    File file = new File(" /Users/carlsamson/Documents/dev/workspaces/shopizer-master/shopizer/sm-core/src/main/resources/reference/integrationmodules.json");
    try (InputStream in = new FileInputStream(file)) {
        @SuppressWarnings("rawtypes") Map[] objects = mapper.readValue(in, Map[].class);
        IntegrationModule module = null;
        // get the module to be loaded
        for (Map o : objects) {
            // load that specific module
            if (o.get("code").equals("beanstream")) {
                // get module object
                module = integrationModulesLoader.loadModule(o);
                break;
            }
        }
        if (module != null) {
            IntegrationModule m = moduleCongigurationService.getByCode(module.getCode());
            if (m != null) {
                moduleCongigurationService.delete(m);
            }
            moduleCongigurationService.create(module);
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileInputStream(java.io.FileInputStream) IntegrationModule(com.salesmanager.core.model.system.IntegrationModule) ServiceException(com.salesmanager.core.business.exception.ServiceException) Ignore(org.junit.Ignore)

Example 19 with ServiceException

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

the class ImportIntegrationModule method importNonExistingIntegrationModule.

/**
 * Import all non existing modules
 * @throws Exception
 */
@Ignore
public // @Test
void importNonExistingIntegrationModule() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    File file = new File("/Users/carlsamson/Documents/dev/workspaces/shopizer-master/shopizer/sm-core/src/main/resources/reference/integrationmodules.json");
    try (InputStream in = new FileInputStream(file)) {
        @SuppressWarnings("rawtypes") Map[] objects = mapper.readValue(in, Map[].class);
        // get the module to be loaded
        for (Map o : objects) {
            // get module object
            IntegrationModule module = integrationModulesLoader.loadModule(o);
            if (module != null) {
                IntegrationModule m = moduleCongigurationService.getByCode(module.getCode());
                if (m == null) {
                    moduleCongigurationService.create(module);
                }
            }
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileInputStream(java.io.FileInputStream) IntegrationModule(com.salesmanager.core.model.system.IntegrationModule) ServiceException(com.salesmanager.core.business.exception.ServiceException) Ignore(org.junit.Ignore)

Example 20 with ServiceException

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

the class ContentFolderTest method addFolder.

@Ignore
public void addFolder() {
    MerchantStore store;
    try {
        store = super.merchantService.getByCode("DEFAULT");
        String folderName = "newFolder";
        Optional<String> path = Optional.ofNullable(null);
        // add folder to root
        contentService.addFolder(store, path, folderName);
    // add new folder to newFolder
    } catch (ServiceException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) Ignore(org.junit.Ignore)

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