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