use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.
the class LandingController method displayLanding.
@RequestMapping(value = { Constants.SHOP_URI + "/home.html", Constants.SHOP_URI + "/", Constants.SHOP_URI }, method = RequestMethod.GET)
public String displayLanding(Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
Language language = (Language) request.getAttribute(Constants.LANGUAGE);
MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
request.setAttribute(Constants.LINK_CODE, HOME_LINK_CODE);
Content content = contentService.getByCode(LANDING_PAGE, store, language);
/**
* Rebuild breadcrumb *
*/
BreadcrumbItem item = new BreadcrumbItem();
item.setItemType(BreadcrumbItemType.HOME);
item.setLabel(messages.getMessage(Constants.HOME_MENU_KEY, locale));
item.setUrl(Constants.HOME_URL);
Breadcrumb breadCrumb = new Breadcrumb();
breadCrumb.setLanguage(language);
List<BreadcrumbItem> items = new ArrayList<BreadcrumbItem>();
items.add(item);
breadCrumb.setBreadCrumbs(items);
request.getSession().setAttribute(Constants.BREADCRUMB, breadCrumb);
request.setAttribute(Constants.BREADCRUMB, breadCrumb);
if (content != null) {
ContentDescription description = content.getDescription();
model.addAttribute("page", description);
PageInformation pageInformation = new PageInformation();
pageInformation.setPageTitle(description.getName());
pageInformation.setPageDescription(description.getMetatagDescription());
pageInformation.setPageKeywords(description.getMetatagKeywords());
request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation);
}
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
// featured items
List<ProductRelationship> relationships = productRelationshipService.getByType(store, ProductRelationshipType.FEATURED_ITEM, language);
List<ReadableProduct> featuredItems = new ArrayList<ReadableProduct>();
Date today = new Date();
for (ProductRelationship relationship : relationships) {
Product product = relationship.getRelatedProduct();
if (product.isAvailable() && DateUtil.dateBeforeEqualsDate(product.getDateAvailable(), today)) {
ReadableProduct proxyProduct = populator.populate(product, new ReadableProduct(), store, language);
featuredItems.add(proxyProduct);
}
}
String tmpl = store.getStoreTemplate();
if (StringUtils.isBlank(tmpl)) {
tmpl = "generic";
}
model.addAttribute("featuredItems", featuredItems);
/**
* template *
*/
StringBuilder template = new StringBuilder().append("landing.").append(tmpl);
return template.toString();
}
use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.
the class StoreFilter method getContent.
private Map<String, List<Content>> getContent(MerchantStore store, Language language) throws Exception {
Map<String, List<Content>> contents = new ConcurrentHashMap<String, List<Content>>();
// Get boxes and sections from the database
List<ContentType> contentTypes = new ArrayList<ContentType>();
contentTypes.add(ContentType.BOX);
contentTypes.add(ContentType.SECTION);
List<Content> contentPages = contentService.listByType(contentTypes, store, language);
if (contentPages != null && contentPages.size() > 0) {
// create a Map<String,List<Content>
for (Content content : contentPages) {
if (content.isVisible()) {
List<ContentDescription> descriptions = content.getDescriptions();
for (ContentDescription contentDescription : descriptions) {
Language lang = contentDescription.getLanguage();
String key = new StringBuilder().append(store.getId()).append("_").append(Constants.CONTENT_CACHE_KEY).append("-").append(lang.getCode()).toString();
List<Content> contentList = null;
if (contents == null || contents.size() == 0) {
contents = new HashMap<String, List<Content>>();
}
if (!contents.containsKey(key)) {
contentList = new ArrayList<Content>();
contents.put(key, contentList);
} else {
// get from key
contentList = contents.get(key);
if (contentList == null) {
LOGGER.error("Cannot find content key in cache " + key);
continue;
}
}
contentList.add(content);
}
}
}
}
return contents;
}
use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method convertContentBoxToContent.
private Content convertContentBoxToContent(MerchantStore store, Content model, PersistableContentBox content) throws Exception {
Content contentModel = new Content();
if (model != null) {
contentModel = model;
}
List<ContentDescription> descriptions = buildDescriptions(contentModel, content.getDescriptions());
for (ContentDescription cd : descriptions) {
cd.setContent(contentModel);
}
contentModel.setCode(content.getCode());
contentModel.setContentType(ContentType.BOX);
contentModel.setMerchantStore(store);
contentModel.setVisible(content.isVisible());
contentModel.setDescriptions(descriptions);
contentModel.setId(content.getId());
return contentModel;
}
use of com.salesmanager.core.model.content.Content 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.model.content.Content in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method deleteContent.
@Override
public void deleteContent(Long id, MerchantStore merchantStore) {
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("Content with id [" + id + "] does not exist for store [" + merchantStore.getCode() + "]");
}
contentService.delete(content);
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
}
Aggregations