use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method updateContentPage.
@Override
public void updateContentPage(Long id, PersistableContentPage page, MerchantStore merchantStore, Language language) {
Validate.notNull(page);
Validate.notNull(id, "Content id must not be null");
Validate.notNull(merchantStore);
try {
Content content = null;
content = contentService.getById(id, merchantStore);
if (content == null) {
throw new ConstraintException("Page with id [" + id + "] does not exist for store [" + merchantStore.getCode() + "]");
}
page.setId(id);
content = convertContentPageToContent(merchantStore, content, page);
contentService.saveOrUpdate(content);
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method getContentPageByName.
@Override
public ReadableContentPage getContentPageByName(String name, MerchantStore store, Language language) {
Validate.notNull(name, "Content name cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
try {
ContentDescription contentDescription = Optional.ofNullable(contentService.getBySeUrl(store, name)).orElseThrow(() -> new ResourceNotFoundException("No page found : " + name));
return this.contentDescriptionToReadableContent(store, contentDescription.getContent(), contentDescription);
} catch (Exception e) {
throw new ServiceRuntimeException("Error while getting page " + e.getMessage(), e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException 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.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class StoreFacadeImpl method supportedLanguages.
@Override
public List<Language> supportedLanguages(MerchantStore store) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(store.getClass(), "MerchantStore code cannot be null");
if (!CollectionUtils.isEmpty(store.getLanguages())) {
return store.getLanguages();
}
// refresh
try {
store = merchantStoreService.getByCode(store.getCode());
} catch (ServiceException e) {
throw new ServiceRuntimeException("An exception occured when getting store [" + store.getCode() + "]");
}
if (store != null) {
return store.getLanguages();
}
return Collections.emptyList();
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class StoreFacadeImpl method getMerchantStoresByCriteria.
private ReadableMerchantStoreList getMerchantStoresByCriteria(MerchantStoreCriteria criteria, Language language) {
try {
GenericEntityList<MerchantStore> stores = Optional.ofNullable(merchantStoreService.getByCriteria(criteria)).orElseThrow(() -> new ResourceNotFoundException("Criteria did not match any store"));
ReadableMerchantStoreList storeList = new ReadableMerchantStoreList();
storeList.setData((List<ReadableMerchantStore>) stores.getList().stream().map(s -> convertMerchantStoreToReadableMerchantStore(language, s)).collect(Collectors.toList()));
storeList.setTotalPages(stores.getTotalPages());
storeList.setRecordsTotal(stores.getTotalCount());
storeList.setNumber(stores.getList().size());
return storeList;
} catch (ServiceException e) {
throw new ServiceRuntimeException(e);
}
}
Aggregations