use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.
the class ContentRepositoryImpl method getBySeUrl.
@Override
public ContentDescription getBySeUrl(MerchantStore store, String seUrl) {
StringBuilder qs = new StringBuilder();
qs.append("select c from Content c ");
qs.append("left join fetch c.descriptions cd join fetch c.merchantStore cm ");
qs.append("where cm.id =:cm ");
qs.append("and c.visible =true ");
qs.append("and cd.seUrl =:se ");
String hql = qs.toString();
Query q = this.em.createQuery(hql);
q.setParameter("cm", store.getId());
q.setParameter("se", seUrl);
Content content = (Content) q.getSingleResult();
if (content != null) {
return content.getDescription();
}
@SuppressWarnings("unchecked") List<Content> results = q.getResultList();
if (results.isEmpty()) {
return null;
} else if (results.size() >= 1) {
content = results.get(0);
}
if (content != null) {
return content.getDescription();
}
return null;
}
use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.
the class StoreFilter method getContentObjects.
@SuppressWarnings({ "unchecked" })
private void getContentObjects(MerchantStore store, Language language, HttpServletRequest request) throws Exception {
/**
* CMS links Those links are implemented as pages (Content)
* ContentDescription will provide attributes name for the label to be
* displayed and seUrl for the friendly url page
*/
// build the key
/**
* The cache is kept as a Map<String,Object> The key is
* CONTENT_<MERCHANT_ID>_<LOCALE> The value is a List of Content object
*/
StringBuilder contentKey = new StringBuilder();
contentKey.append(store.getId()).append("_").append(Constants.CONTENT_CACHE_KEY).append("-").append(language.getCode());
StringBuilder contentKeyMissed = new StringBuilder();
contentKeyMissed.append(contentKey.toString()).append(Constants.MISSED_CACHE_KEY);
Map<String, List<Content>> contents = null;
if (store.isUseCache()) {
// get from the cache
contents = (Map<String, List<Content>>) cache.getFromCache(contentKey.toString());
if (contents == null) {
// get from missed cache
// Boolean missedContent =
// (Boolean)cache.getFromCache(contentKeyMissed.toString());
// if(missedContent==null) {
contents = this.getContent(store, language);
if (contents != null && contents.size() > 0) {
// put in cache
cache.putInCache(contents, contentKey.toString());
} else {
// put in missed cache
// cache.putInCache(new Boolean(true),
// contentKeyMissed.toString());
}
// }
}
} else {
contents = this.getContent(store, language);
}
if (contents != null && contents.size() > 0) {
// request.setAttribute(Constants.REQUEST_CONTENT_OBJECTS,
// contents);
List<Content> contentByStore = contents.get(contentKey.toString());
if (!CollectionUtils.isEmpty(contentByStore)) {
Map<String, ContentDescription> contentMap = new HashMap<String, ContentDescription>();
for (Content content : contentByStore) {
if (content.isVisible()) {
contentMap.put(content.getCode(), content.getDescription());
}
}
request.setAttribute(Constants.REQUEST_CONTENT_OBJECTS, contentMap);
}
}
}
use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.
the class StoreFilter method setBreadcrumb.
private void setBreadcrumb(HttpServletRequest request, Locale locale) {
try {
// breadcrumb
Breadcrumb breadCrumb = (Breadcrumb) request.getSession().getAttribute(Constants.BREADCRUMB);
Language language = (Language) request.getAttribute(Constants.LANGUAGE);
if (breadCrumb == null) {
breadCrumb = new Breadcrumb();
breadCrumb.setLanguage(language);
BreadcrumbItem item = this.getDefaultBreadcrumbItem(language, locale);
breadCrumb.getBreadCrumbs().add(item);
} else {
// check language
if (language.getCode().equals(breadCrumb.getLanguage().getCode())) {
// rebuild using the appropriate language
List<BreadcrumbItem> items = new ArrayList<BreadcrumbItem>();
for (BreadcrumbItem item : breadCrumb.getBreadCrumbs()) {
if (item.getItemType().name().equals(BreadcrumbItemType.HOME)) {
BreadcrumbItem homeItem = this.getDefaultBreadcrumbItem(language, locale);
homeItem.setItemType(BreadcrumbItemType.HOME);
homeItem.setLabel(messages.getMessage(Constants.HOME_MENU_KEY, locale));
homeItem.setUrl(Constants.HOME_URL);
items.add(homeItem);
} else if (item.getItemType().name().equals(BreadcrumbItemType.PRODUCT)) {
Product product = productService.getProductForLocale(item.getId(), language, locale);
if (product != null) {
BreadcrumbItem productItem = new BreadcrumbItem();
productItem.setId(product.getId());
productItem.setItemType(BreadcrumbItemType.PRODUCT);
productItem.setLabel(product.getProductDescription().getName());
productItem.setUrl(product.getProductDescription().getSeUrl());
items.add(productItem);
}
} else if (item.getItemType().name().equals(BreadcrumbItemType.CATEGORY)) {
Category category = categoryService.getOneByLanguage(item.getId(), language);
if (category != null) {
BreadcrumbItem categoryItem = new BreadcrumbItem();
categoryItem.setId(category.getId());
categoryItem.setItemType(BreadcrumbItemType.CATEGORY);
categoryItem.setLabel(category.getDescription().getName());
categoryItem.setUrl(category.getDescription().getSeUrl());
items.add(categoryItem);
}
} else if (item.getItemType().name().equals(BreadcrumbItemType.PAGE)) {
Content content = contentService.getByLanguage(item.getId(), language);
if (content != null) {
BreadcrumbItem contentItem = new BreadcrumbItem();
contentItem.setId(content.getId());
contentItem.setItemType(BreadcrumbItemType.PAGE);
contentItem.setLabel(content.getDescription().getName());
contentItem.setUrl(content.getDescription().getSeUrl());
items.add(contentItem);
}
}
}
breadCrumb = new Breadcrumb();
breadCrumb.setLanguage(language);
breadCrumb.setBreadCrumbs(items);
}
}
request.getSession().setAttribute(Constants.BREADCRUMB, breadCrumb);
request.setAttribute(Constants.BREADCRUMB, breadCrumb);
} catch (Exception e) {
LOGGER.error("Error while building breadcrumbs", e);
}
}
use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.
the class ContactController method display.
@RequestMapping("/shop/store/contactus.html")
public String display(Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
model.addAttribute("googleMapsKey", googleMapsKey);
request.setAttribute(Constants.LINK_CODE, CONTACT_LINK);
Language language = (Language) request.getAttribute("LANGUAGE");
ContactForm contact = new ContactForm();
model.addAttribute("contact", contact);
model.addAttribute("recapatcha_public_key", siteKeyKey);
Content content = contentService.getByCode(Constants.CONTENT_CONTACT_US, store, language);
ContentDescription contentDescription = null;
if (content != null && content.isVisible()) {
contentDescription = content.getDescription();
}
if (contentDescription != null) {
// meta information
PageInformation pageInformation = new PageInformation();
pageInformation.setPageDescription(contentDescription.getMetatagDescription());
pageInformation.setPageKeywords(contentDescription.getMetatagKeywords());
pageInformation.setPageTitle(contentDescription.getTitle());
pageInformation.setPageUrl(contentDescription.getName());
request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation);
model.addAttribute("content", contentDescription);
}
/**
* template *
*/
StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Content.contactus).append(".").append(store.getStoreTemplate());
return template.toString();
}
use of com.salesmanager.core.model.content.Content in project shopizer by shopizer-ecommerce.
the class ShopContentController method displayContent.
@RequestMapping("/shop/pages/{friendlyUrl}.html")
public String displayContent(@PathVariable final String friendlyUrl, Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
ContentDescription contentDescription = contentService.getBySeUrl(store, friendlyUrl);
Content content = null;
if (contentDescription != null) {
content = contentDescription.getContent();
if (!content.isVisible()) {
return "redirect:/shop";
}
// meta information
PageInformation pageInformation = new PageInformation();
pageInformation.setPageDescription(contentDescription.getMetatagDescription());
pageInformation.setPageKeywords(contentDescription.getMetatagKeywords());
pageInformation.setPageTitle(contentDescription.getTitle());
pageInformation.setPageUrl(contentDescription.getName());
request.setAttribute(Constants.REQUEST_PAGE_INFORMATION, pageInformation);
}
// TODO breadcrumbs
request.setAttribute(Constants.LINK_CODE, contentDescription.getSeUrl());
model.addAttribute("content", contentDescription);
if (!StringUtils.isBlank(content.getProductGroup())) {
model.addAttribute("productGroup", content.getProductGroup());
}
/**
* template *
*/
StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Content.content).append(".").append(store.getStoreTemplate());
return template.toString();
}
Aggregations