use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class CmsImageFileManagerImpl method getImages.
@Override
public List<OutputContentFile> getImages(Product product) throws ServiceException {
if (cacheManager.getTreeCache() == null) {
throw new ServiceException("CmsImageFileManagerInfinispan has a null cacheManager.getTreeCache()");
}
List<OutputContentFile> images = new ArrayList<OutputContentFile>();
try {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
StringBuilder nodePath = new StringBuilder();
nodePath.append(product.getMerchantStore().getCode());
Node<String, Object> merchantNode = this.getNode(nodePath.toString());
if (merchantNode == null) {
return null;
}
for (String key : merchantNode.getKeys()) {
byte[] imageBytes = (byte[]) merchantNode.get(key);
OutputContentFile contentImage = new OutputContentFile();
InputStream input = new ByteArrayInputStream(imageBytes);
ByteArrayOutputStream output = new ByteArrayOutputStream();
IOUtils.copy(input, output);
String contentType = fileNameMap.getContentTypeFor(key);
contentImage.setFile(output);
contentImage.setMimeType(contentType);
contentImage.setFileName(key);
images.add(contentImage);
}
} catch (Exception e) {
throw new ServiceException(e);
} finally {
}
return images;
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class CmsImageFileManagerImpl method getProductImage.
private OutputContentFile getProductImage(String merchantStoreCode, String productCode, String imageName, String size) throws ServiceException {
if (cacheManager.getTreeCache() == null) {
throw new ServiceException("CmsImageFileManagerInfinispan has a null cacheManager.getTreeCache()");
}
InputStream input = null;
OutputContentFile contentImage = new OutputContentFile();
try {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
// SMALL by default
StringBuilder nodePath = new StringBuilder();
nodePath.append(merchantStoreCode).append(Constants.SLASH).append(productCode).append(Constants.SLASH).append(size);
Node<String, Object> productNode = this.getNode(nodePath.toString());
byte[] imageBytes = (byte[]) productNode.get(imageName);
if (imageBytes == null) {
LOGGER.warn("Image " + imageName + " does not exist");
// no post processing will occur
return null;
}
input = new ByteArrayInputStream(imageBytes);
ByteArrayOutputStream output = new ByteArrayOutputStream();
IOUtils.copy(input, output);
String contentType = fileNameMap.getContentTypeFor(imageName);
contentImage.setFile(output);
contentImage.setMimeType(contentType);
contentImage.setFileName(imageName);
} catch (Exception e) {
throw new ServiceException(e);
} finally {
if (input != null) {
try {
input.close();
} catch (Exception ignore) {
}
}
}
return contentImage;
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class ImportIntegrationModule method importSpecificIntegrationModule.
/**
* Import a specific integration module. Will delete and recreate the module
* if it already exists
* @throws Exception
*/
@Ignore
public // @Test
void importSpecificIntegrationModule() throws Exception {
ObjectMapper mapper = new ObjectMapper();
File file = new File(" /Users/carlsamson/Documents/dev/workspaces/shopizer-master/shopizer/sm-core/src/main/resources/reference/integrationmodules.json");
try (InputStream in = new FileInputStream(file)) {
@SuppressWarnings("rawtypes") Map[] objects = mapper.readValue(in, Map[].class);
IntegrationModule module = null;
// get the module to be loaded
for (Map o : objects) {
// load that specific module
if (o.get("code").equals("beanstream")) {
// get module object
module = integrationModulesLoader.loadModule(o);
break;
}
}
if (module != null) {
IntegrationModule m = moduleCongigurationService.getByCode(module.getCode());
if (m != null) {
moduleCongigurationService.delete(m);
}
moduleCongigurationService.create(module);
}
} catch (Exception e) {
throw new ServiceException(e);
}
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class ImportIntegrationModule method importNonExistingIntegrationModule.
/**
* Import all non existing modules
* @throws Exception
*/
@Ignore
public // @Test
void importNonExistingIntegrationModule() throws Exception {
ObjectMapper mapper = new ObjectMapper();
File file = new File("/Users/carlsamson/Documents/dev/workspaces/shopizer-master/shopizer/sm-core/src/main/resources/reference/integrationmodules.json");
try (InputStream in = new FileInputStream(file)) {
@SuppressWarnings("rawtypes") Map[] objects = mapper.readValue(in, Map[].class);
// get the module to be loaded
for (Map o : objects) {
// get module object
IntegrationModule module = integrationModulesLoader.loadModule(o);
if (module != null) {
IntegrationModule m = moduleCongigurationService.getByCode(module.getCode());
if (m == null) {
moduleCongigurationService.create(module);
}
}
}
} catch (Exception e) {
throw new ServiceException(e);
}
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class ContentFolderTest method addFolder.
@Ignore
public void addFolder() {
MerchantStore store;
try {
store = super.merchantService.getByCode("DEFAULT");
String folderName = "newFolder";
Optional<String> path = Optional.ofNullable(null);
// add folder to root
contentService.addFolder(store, path, folderName);
// add new folder to newFolder
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations