Search in sources :

Example 1 with InputContentFile

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

the class ProductInstanceGroupFacadeImpl method addImage.

@Override
public void addImage(MultipartFile image, Long productOptionGroupId, MerchantStore store, Language language) {
    Validate.notNull(productOptionGroupId, "productOptionGroupId must not be null");
    Validate.notNull(image, "Image must not be null");
    Validate.notNull(store, "MerchantStore must not be null");
    // get option group
    ProductInstanceGroup group = this.group(productOptionGroupId, store);
    try {
        ProductInstanceImage instanceImage = new ProductInstanceImage();
        instanceImage.setProductImage(image.getOriginalFilename());
        instanceImage.setProductInstanceGroup(group);
        String imageName = image.getOriginalFilename();
        InputStream inputStream = image.getInputStream();
        InputContentFile cmsContentImage = new InputContentFile();
        cmsContentImage.setFileName(imageName);
        cmsContentImage.setMimeType(image.getContentType());
        cmsContentImage.setFile(inputStream);
        cmsContentImage.setPath(Constants.SLASH + store.getCode() + Constants.SLASH + productOptionGroupId);
        cmsContentImage.setFileContentType(FileContentType.INSTANCE);
        contentService.addContentFile(store.getCode(), cmsContentImage);
        group.getImages().add(instanceImage);
        productInstanceGroupService.save(group);
    } catch (Exception e) {
        throw new ServiceRuntimeException("Exception while adding instance group image", e);
    }
    return;
}
Also used : InputContentFile(com.salesmanager.core.model.content.InputContentFile) ProductInstanceImage(com.salesmanager.core.model.catalog.product.instance.ProductInstanceImage) InputStream(java.io.InputStream) 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) 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 2 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> path, 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 {
        for (final InputContentFile inputStaticContentData : inputStaticContentDataList) {
            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 : InputContentFile(com.salesmanager.core.model.content.InputContentFile) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceException(com.salesmanager.core.business.exception.ServiceException)

Example 3 with InputContentFile

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

the class ContentFacadeImpl method addContentFile.

@Override
public void addContentFile(ContentFile file, String merchantStoreCode) {
    try {
        byte[] payload = file.getFile();
        String fileName = file.getName();
        try (InputStream targetStream = new ByteArrayInputStream(payload)) {
            String type = file.getContentType().split(FILE_CONTENT_DELIMETER)[0];
            FileContentType fileType = getFileContentType(type);
            InputContentFile cmsContent = new InputContentFile();
            cmsContent.setFileName(fileName);
            cmsContent.setMimeType(file.getContentType());
            cmsContent.setFile(targetStream);
            cmsContent.setFileContentType(fileType);
            contentService.addContentFile(merchantStoreCode, cmsContent);
        }
    } catch (ServiceException | IOException e) {
        throw new ServiceRuntimeException(e);
    }
}
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) IOException(java.io.IOException) FileContentType(com.salesmanager.core.model.content.FileContentType) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 4 with InputContentFile

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

the class ContentServiceImpl method addContentFiles.

/**
 * Method responsible for adding list of content images for given merchant
 * store in underlying Infinispan tree cache. It will take list of
 * {@link CMSContentImage} and will store them for given merchant store.
 *
 * @param merchantStoreCode
 *            Merchant store
 * @param contentImagesList
 *            list of {@link CMSContentImage} being stored
 * @throws ServiceException
 *             service exception
 */
@Override
public void addContentFiles(String merchantStoreCode, List<InputContentFile> contentFilesList) throws ServiceException {
    Assert.notNull(merchantStoreCode, "Merchant store ID can not be null");
    Assert.notEmpty(contentFilesList, "File list can not be empty");
    LOG.info("Adding total {} images for given merchant", contentFilesList.size());
    String p = null;
    Optional<String> path = Optional.ofNullable(p);
    LOG.info("Adding content images for merchant....");
    contentFileManager.addFiles(merchantStoreCode, path, contentFilesList);
    try {
        for (InputContentFile file : contentFilesList) {
            if (file.getFile() != null) {
                file.getFile().close();
            }
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : InputContentFile(com.salesmanager.core.model.content.InputContentFile) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceException(com.salesmanager.core.business.exception.ServiceException)

Example 5 with InputContentFile

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

the class MerchantStoreApi method addLogo.

@ResponseStatus(HttpStatus.CREATED)
@PostMapping(value = { "/private/store/{code}/marketing/logo" })
@ApiOperation(httpMethod = "POST", value = "Add store logo", notes = "")
public void addLogo(@PathVariable String code, @RequestParam("file") MultipartFile uploadfile, HttpServletRequest request) {
    // user doing action must be attached to the store being modified
    String userName = getUserFromRequest(request);
    validateUserPermission(userName, code);
    if (uploadfile.isEmpty()) {
        throw new RestApiException("Upload file is empty");
    }
    InputContentFile cmsContentImage = createInputContentFile(uploadfile);
    storeFacade.addStoreLogo(code, cmsContentImage);
}
Also used : InputContentFile(com.salesmanager.core.model.content.InputContentFile) RestApiException(com.salesmanager.shop.store.api.exception.RestApiException) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation)

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