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;
}
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);
}
}
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);
}
}
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);
}
}
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);
}
Aggregations