use of com.salesmanager.core.business.exception.ServiceException 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.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class CmsStaticContentFileManagerImpl method getFileNames.
/**
* Queries the CMS to retrieve all static content files. Only the name of
* the file will be returned to the client
*
* @param merchantStoreCode
* @return
* @throws ServiceException
*/
@Override
public List<String> getFileNames(final String merchantStoreCode, Optional<String> folderPath, final FileContentType staticContentType) throws ServiceException {
try {
StringBuilder merchantPath = new StringBuilder();
merchantPath.append(buildRootPath()).append(merchantStoreCode).append(Constants.SLASH).append(staticContentType);
Path path = Paths.get(merchantPath.toString());
List<String> fileNames = null;
if (Files.exists(path)) {
fileNames = new ArrayList<String>();
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path)) {
for (Path dirPath : directoryStream) {
String fileName = dirPath.getFileName().toString();
if (staticContentType.name().equals(FileContentType.IMAGE.name())) {
// File f = new File(fileName);
String mimetype = URLConnection.guessContentTypeFromName(fileName);
// MimetypesFileTypeMap().getContentType(f);
if (!StringUtils.isBlank(mimetype)) {
String type = mimetype.split("/")[0];
if (type.equals("image")) {
fileNames.add(fileName);
}
}
// fileNames.add(fileName);
} else {
fileNames.add(fileName);
}
}
}
return fileNames;
}
} catch (final Exception e) {
LOGGER.error("Error while fetching file for {} merchant ", merchantStoreCode);
throw new ServiceException(e);
}
return new ArrayList<>();
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class CmsStaticContentFileManagerImpl method removeFiles.
/**
* Removes the data in a given merchant node
*/
@Override
public void removeFiles(final String merchantStoreCode, Optional<String> folderPath) throws ServiceException {
LOGGER.debug("Removing all images for {} merchant ", merchantStoreCode);
try {
StringBuilder merchantPath = new StringBuilder();
merchantPath.append(buildRootPath()).append(Constants.SLASH).append(merchantStoreCode);
Path path = Paths.get(merchantPath.toString());
Files.deleteIfExists(path);
} catch (final Exception e) {
LOGGER.error("Error while deleting content image for {} merchant ", merchantStoreCode);
throw new ServiceException(e);
}
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class CmsStaticContentFileManagerImpl method removeFolder.
@Override
public void removeFolder(String merchantStoreCode, String folderName, Optional<String> folderPath) throws ServiceException {
// String rootPath = this.buildRootPath();
try {
Path merchantPath = this.buildMerchantPath(merchantStoreCode);
StringBuilder nodePath = new StringBuilder();
nodePath.append(merchantPath.toString()).append(Constants.SLASH);
if (folderPath.isPresent()) {
nodePath.append(folderPath.get()).append(Constants.SLASH);
}
nodePath.append(folderName);
Path longPath = Paths.get(nodePath.toString());
if (Files.exists(longPath)) {
Files.delete(longPath);
}
} catch (IOException e) {
LOGGER.error("Error while creating fiolder for {} merchant ", merchantStoreCode);
throw new ServiceException(e);
}
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class CmsStaticContentFileManagerImpl method removeFile.
@Override
public void removeFile(final String merchantStoreCode, final FileContentType staticContentType, final String fileName, Optional<String> folderPath) throws ServiceException {
try {
StringBuilder merchantPath = new StringBuilder();
merchantPath.append(buildRootPath()).append(Constants.SLASH).append(merchantStoreCode).append(Constants.SLASH).append(staticContentType).append(Constants.SLASH).append(fileName);
Path path = Paths.get(merchantPath.toString());
Files.deleteIfExists(path);
} catch (final Exception e) {
LOGGER.error("Error while deleting files for {} merchant ", merchantStoreCode);
throw new ServiceException(e);
}
}
Aggregations