use of com.salesmanager.core.model.content.Content 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.model.content.Content 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.core.model.content.Content in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method getContent.
@Override
public ReadableContentFull getContent(String code, MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore not null");
Validate.notNull(code, "Content code must not be null");
try {
Content content = contentService.getByCode(code, store);
if (content == null) {
throw new ResourceNotFoundException("No content found with code [" + code + "] for store [" + store.getCode() + "]");
}
return this.convertContentToReadableContentFull(store, language, content);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Error while getting content [" + code + "]", e);
}
}
use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method saveContentPage.
@Override
public Long saveContentPage(PersistableContentPage page, MerchantStore merchantStore, Language language) {
Validate.notNull(page);
Validate.notNull(page.getCode(), "Content code must not be null");
Validate.notNull(merchantStore);
try {
Content content = null;
content = contentService.getByCode(page.getCode(), merchantStore);
if (content != null) {
throw new ConstraintException("Page with code [" + page.getCode() + "] already exist for store [" + merchantStore.getCode() + "]");
}
content = convertContentPageToContent(merchantStore, content, page);
contentService.saveOrUpdate(content);
return content.getId();
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
}
use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method delete.
@Override
public void delete(MerchantStore store, Long id) {
Validate.notNull(store, "MerchantStore not null");
Validate.notNull(id, "Content id must not be null");
// select content first
Content content = contentService.getById(id);
if (content != null) {
if (content.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ResourceNotFoundException("No content found with id [" + id + "] for store [" + store.getCode() + "]");
}
}
try {
contentService.delete(content);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while deleting content " + e.getMessage(), e);
}
}
Aggregations