use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method convertContentToReadableContentPage.
private ReadableContentPage convertContentToReadableContentPage(MerchantStore store, Language language, Content content) {
if (language != null) {
ReadableContentPage page = new ReadableContentPage();
Optional<ContentDescription> contentDescription = findAppropriateContentDescription(content.getDescriptions(), language);
if (contentDescription.isPresent()) {
com.salesmanager.shop.model.content.common.ContentDescription desc = this.contentDescription(contentDescription.get());
page.setDescription(desc);
}
page.setCode(content.getCode());
page.setId(content.getId());
page.setVisible(content.isVisible());
return page;
} else {
ReadableContentPageFull page = new ReadableContentPageFull();
List<com.salesmanager.shop.model.content.common.ContentDescription> descriptions = content.getDescriptions().stream().map(d -> this.contentDescription(d)).collect(Collectors.toList());
page.setDescriptions(descriptions);
page.setCode(content.getCode());
page.setId(content.getId());
page.setVisible(content.isVisible());
return page;
}
}
use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method getContents.
@Override
public List<ReadableContentEntity> getContents(Optional<String> type, MerchantStore store, Language language) {
/**
* get all types
*/
List<ContentType> types = new ArrayList<ContentType>();
types.add(ContentType.BOX);
types.add(ContentType.PAGE);
types.add(ContentType.SECTION);
try {
return contentService.listByType(types, store, language).stream().map(content -> convertContentToReadableContentEntity(store, language, content)).collect(Collectors.toList());
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while getting contents", e);
}
}
use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method getContentBoxes.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public ReadableEntityList<ReadableContentBox> getContentBoxes(ContentType type, MerchantStore store, Language language, int page, int count) {
Validate.notNull(store, "MerchantStore cannot be null");
ReadableEntityList items = new ReadableEntityList();
Page<Content> contentBoxes;
try {
contentBoxes = contentService.listByType(type, store, page, count);
items.setTotalPages(contentBoxes.getTotalPages());
items.setNumber(contentBoxes.getContent().size());
items.setRecordsTotal(contentBoxes.getNumberOfElements());
List<ReadableContentBox> boxes = contentBoxes.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.model.content.Content in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method getContentPage.
@Override
public ReadableContentPage getContentPage(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;
if (language == null) {
content = Optional.ofNullable(contentService.getByCode(code, store)).orElseThrow(() -> new ResourceNotFoundException("No page found : " + code));
} else {
content = Optional.ofNullable(contentService.getByCode(code, store, language)).orElseThrow(() -> new ResourceNotFoundException("No page found : " + code));
}
return convertContentToReadableContentPage(store, language, content);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Error while getting page " + e.getMessage(), e);
}
}
use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method updateContentBox.
@Override
public void updateContentBox(Long id, PersistableContentBox box, MerchantStore merchantStore, Language language) {
Validate.notNull(box);
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() + "]");
}
box.setId(id);
content = convertContentBoxToContent(merchantStore, content, box);
contentService.saveOrUpdate(content);
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
}
Aggregations