Search in sources :

Example 6 with InputContentFile

use of com.salesmanager.core.model.content.InputContentFile in project shopizer by shopizer-ecommerce.

the class CmsStaticContentFileManagerImpl method addFiles.

/**
 * <p>
 * Method to add files for given store.Files will be stored in Infinispan
 * and will be retrieved based on the storeID. Following steps will be
 * performed to store static content files
 * </p>
 * <li>Merchant Node will be retrieved from the cacheTree if it exists else
 * new node will be created.</li>
 * <li>Files will be stored in StaticContentCacheAttribute , which
 * eventually will be stored in Infinispan</li>
 *
 * @param merchantStoreCode
 *            Merchant store for which files are getting stored in
 *            Infinispan.
 * @param inputStaticContentDataList
 *            input static content file list which will get
 *            {@link InputContentImage} stored
 * @throws ServiceException
 *             if content file storing process fail.
 * @see InputStaticContentData
 * @see StaticContentCacheAttribute
 */
@Override
public void addFiles(final String merchantStoreCode, Optional<String> folderPath, final List<InputContentFile> inputStaticContentDataList) throws ServiceException {
    /*
		 * if ( cacheManager.getTreeCache() == null ) { LOGGER.error(
		 * "Unable to find cacheManager.getTreeCache() in Infinispan.." ); throw
		 * new ServiceException(
		 * "CmsStaticContentFileManagerInfinispanImpl has a null cacheManager.getTreeCache()"
		 * ); }
		 */
    try {
        // base path
        String rootPath = this.buildRootPath();
        Path confDir = Paths.get(rootPath);
        this.createDirectoryIfNorExist(confDir);
        // node path
        StringBuilder nodePath = new StringBuilder();
        nodePath.append(rootPath).append(merchantStoreCode);
        Path merchantPath = Paths.get(nodePath.toString());
        this.createDirectoryIfNorExist(merchantPath);
        for (final InputContentFile inputStaticContentData : inputStaticContentDataList) {
            // file path
            nodePath.append(Constants.SLASH).append(inputStaticContentData.getFileContentType()).append(Constants.SLASH);
            Path dirPath = Paths.get(nodePath.toString());
            this.createDirectoryIfNorExist(dirPath);
            // file creation
            nodePath.append(Constants.SLASH).append(inputStaticContentData.getFileName());
            Path path = Paths.get(nodePath.toString());
            Files.copy(inputStaticContentData.getFile(), path, StandardCopyOption.REPLACE_EXISTING);
        // String nodePath = this.getNodePath(merchantStoreCode,
        // inputStaticContentData.getFileContentType());
        // final Node<String, Object> merchantNode =
        // this.getNode(nodePath);
        // merchantNode.put(inputStaticContentData.getFileName(),
        // IOUtils.toByteArray(
        // inputStaticContentData.getFile() ));
        }
        LOGGER.info("Total {} files added successfully.", inputStaticContentDataList.size());
    } catch (final Exception e) {
        LOGGER.error("Error while saving content image", e);
        throw new ServiceException(e);
    }
}
Also used : Path(java.nio.file.Path) InputContentFile(com.salesmanager.core.model.content.InputContentFile) ServiceException(com.salesmanager.core.business.exception.ServiceException) IOException(java.io.IOException) ServiceException(com.salesmanager.core.business.exception.ServiceException)

Example 7 with InputContentFile

use of com.salesmanager.core.model.content.InputContentFile in project shopizer by shopizer-ecommerce.

the class MerchantStoreApi method createInputContentFile.

private InputContentFile createInputContentFile(MultipartFile image) {
    InputContentFile cmsContentImage = null;
    try {
        InputStream input = new ByteArrayInputStream(image.getBytes());
        cmsContentImage = new InputContentFile();
        cmsContentImage.setFileName(image.getOriginalFilename());
        cmsContentImage.setMimeType(image.getContentType());
        cmsContentImage.setFileContentType(FileContentType.LOGO);
        cmsContentImage.setFile(input);
    } catch (IOException ioe) {
        throw new RestApiException(ioe);
    }
    return cmsContentImage;
}
Also used : InputContentFile(com.salesmanager.core.model.content.InputContentFile) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) RestApiException(com.salesmanager.shop.store.api.exception.RestApiException)

Example 8 with InputContentFile

use of com.salesmanager.core.model.content.InputContentFile in project shopizer by shopizer-ecommerce.

the class ContentServiceImpl method renameFile.

@Override
public void renameFile(String merchantStoreCode, FileContentType fileContentType, Optional<String> path, String originalName, String newName) throws ServiceException {
    OutputContentFile file = contentFileManager.getFile(merchantStoreCode, path, fileContentType, originalName);
    if (file == null) {
        throw new ServiceException("File name [" + originalName + "] not found for merchant [" + merchantStoreCode + "]");
    }
    ByteArrayOutputStream os = file.getFile();
    InputStream is = new ByteArrayInputStream(os.toByteArray());
    // remove file
    contentFileManager.removeFile(merchantStoreCode, fileContentType, originalName, path);
    // recreate file
    InputContentFile inputFile = new InputContentFile();
    inputFile.setFileContentType(fileContentType);
    inputFile.setFileName(newName);
    inputFile.setMimeType(file.getMimeType());
    inputFile.setFile(is);
    contentFileManager.addFile(merchantStoreCode, path, inputFile);
}
Also used : InputContentFile(com.salesmanager.core.model.content.InputContentFile) 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)

Example 9 with InputContentFile

use of com.salesmanager.core.model.content.InputContentFile in project shopizer by shopizer-ecommerce.

the class ProductOptionFacadeImpl method addOptionValueImage.

@Override
public void addOptionValueImage(MultipartFile image, Long optionValueId, MerchantStore store, Language language) {
    Validate.notNull(optionValueId, "OptionValueId must not be null");
    Validate.notNull(image, "Image must not be null");
    // get option value
    ProductOptionValue value = productOptionValueService.getById(store, optionValueId);
    if (value == null) {
        throw new ResourceNotFoundException("Product option value [" + optionValueId + "] not found");
    }
    try {
        String imageName = image.getOriginalFilename();
        InputStream inputStream = image.getInputStream();
        InputContentFile cmsContentImage = new InputContentFile();
        cmsContentImage.setFileName(imageName);
        cmsContentImage.setMimeType(image.getContentType());
        cmsContentImage.setFile(inputStream);
        contentService.addOptionImage(store.getCode(), cmsContentImage);
        value.setProductOptionValueImage(imageName);
        productOptionValueService.saveOrUpdate(value);
    } catch (Exception e) {
        throw new ServiceRuntimeException("Exception while adding option value image", e);
    }
    return;
}
Also used : ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) PersistableProductOptionValue(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue) InputContentFile(com.salesmanager.core.model.content.InputContentFile) InputStream(java.io.InputStream) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) ServiceException(com.salesmanager.core.business.exception.ServiceException) 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 10 with InputContentFile

use of com.salesmanager.core.model.content.InputContentFile in project shopizer by shopizer-ecommerce.

the class ContentImagesTest method createStoreLogo.

// @Test
@Ignore
public void createStoreLogo() throws ServiceException, FileNotFoundException, IOException {
    MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    final File file1 = new File("C:/doc/Hadoop.jpg");
    if (!file1.exists() || !file1.canRead()) {
        throw new ServiceException("Can't read" + file1.getAbsolutePath());
    }
    byte[] is = IOUtils.toByteArray(new FileInputStream(file1));
    ByteArrayInputStream inputStream = new ByteArrayInputStream(is);
    InputContentFile cmsContentImage = new InputContentFile();
    cmsContentImage.setFileName(file1.getName());
    cmsContentImage.setFile(inputStream);
    // logo as a content
    contentService.addLogo(store.getCode(), cmsContentImage);
    store.setStoreLogo(file1.getName());
    merchantService.update(store);
    // query the store
    store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    // get the logo
    String logo = store.getStoreLogo();
    OutputContentFile image = contentService.getContentFile(store.getCode(), FileContentType.LOGO, logo);
    // print image
    OutputStream outputStream = new FileOutputStream("C:/doc/logo-" + image.getFileName());
    ByteArrayOutputStream baos = image.getFile();
    baos.writeTo(outputStream);
    // remove image
    contentService.removeFile(store.getCode(), FileContentType.LOGO, store.getStoreLogo());
}
Also used : InputContentFile(com.salesmanager.core.model.content.InputContentFile) ServiceException(com.salesmanager.core.business.exception.ServiceException) ByteArrayInputStream(java.io.ByteArrayInputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) OutputContentFile(com.salesmanager.core.model.content.OutputContentFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) OutputContentFile(com.salesmanager.core.model.content.OutputContentFile) InputContentFile(com.salesmanager.core.model.content.InputContentFile) File(java.io.File) FileInputStream(java.io.FileInputStream) Ignore(org.junit.Ignore)

Aggregations

InputContentFile (com.salesmanager.core.model.content.InputContentFile)11 ServiceException (com.salesmanager.core.business.exception.ServiceException)9 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 OutputContentFile (com.salesmanager.core.model.content.OutputContentFile)3 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)2 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)2 RestApiException (com.salesmanager.shop.store.api.exception.RestApiException)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 ProductOptionValue (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue)1 ProductInstanceGroup (com.salesmanager.core.model.catalog.product.instance.ProductInstanceGroup)1 ProductInstanceImage (com.salesmanager.core.model.catalog.product.instance.ProductInstanceImage)1 FileContentType (com.salesmanager.core.model.content.FileContentType)1 PersistableProductOptionValue (com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue)1