use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method getContentPages.
@SuppressWarnings("unchecked")
@Override
public ReadableEntityList<ReadableContentPage> getContentPages(MerchantStore store, Language language, int page, int count) {
Validate.notNull(store, "MerchantStore cannot be null");
@SuppressWarnings("rawtypes") ReadableEntityList items = new ReadableEntityList();
Page<Content> contentPages;
try {
contentPages = contentService.listByType(ContentType.PAGE, store, page, count);
items.setTotalPages(contentPages.getTotalPages());
items.setNumber(contentPages.getContent().size());
items.setRecordsTotal(contentPages.getNumberOfElements());
List<ReadableContentBox> boxes = contentPages.getContent().stream().map(content -> convertContentToReadableContentBox(store, language, content)).collect(Collectors.toList());
items.setItems(boxes);
return items;
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while getting content ", e);
}
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method getContentBox.
@Override
public ReadableContentBox getContentBox(String code, MerchantStore store, Language language) {
Validate.notNull(code, "Content code cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
try {
Content content = null;
ReadableContentBox box = new ReadableContentBox();
if (language != null) {
content = Optional.ofNullable(contentService.getByCode(code, store, language)).orElseThrow(() -> new ResourceNotFoundException("Resource not found [" + code + "] for store [" + store.getCode() + "]"));
Optional<ContentDescription> contentDescription = findAppropriateContentDescription(content.getDescriptions(), language);
if (contentDescription.isPresent()) {
com.salesmanager.shop.model.content.common.ContentDescription desc = this.contentDescription(// return cdata description
contentDescription.get());
desc.setDescription(this.fixContentDescription(desc.getDescription()));
box.setDescription(desc);
}
return box;
} else {
content = Optional.ofNullable(contentService.getByCode(code, store)).orElseThrow(() -> new ResourceNotFoundException("Resource not found [" + code + "] for store [" + store.getCode() + "]"));
// all languages
ReadableContentBoxFull full = new ReadableContentBoxFull();
List<com.salesmanager.shop.model.content.common.ContentDescription> descriptions = content.getDescriptions().stream().map(d -> this.contentDescription(d)).collect(Collectors.toList());
/**
* Optional<ContentDescription> contentDescription = findAppropriateContentDescription(
* content.getDescriptions(), store.getDefaultLanguage());
*
* if(contentDescription.isPresent()) {
* com.salesmanager.shop.model.content.common.ContentDescription desc = this
* .contentDescription(contentDescription.get());
* full.setDescription(desc);
* }
*/
full.setDescriptions(descriptions);
full.setCode(content.getCode());
full.setId(content.getId());
full.setVisible(content.isVisible());
return full;
}
} catch (ServiceException e) {
throw new ServiceRuntimeException(e);
}
}
use of com.salesmanager.core.business.exception.ServiceException 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.business.exception.ServiceException 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.core.business.exception.ServiceException 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