use of com.salesmanager.core.model.content.ContentDescription in project shopizer by shopizer-ecommerce.
the class ContentRepositoryImpl method listNameByType.
@Override
public List<ContentDescription> listNameByType(List<ContentType> contentType, MerchantStore store, Language language) {
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 c.contentType in (:ct) ");
qs.append("and cm.id =:cm ");
qs.append("and cd.language.id =:cl ");
qs.append("and c.visible=true ");
qs.append("order by c.sortOrder");
String hql = qs.toString();
Query q = this.em.createQuery(hql);
q.setParameter("ct", contentType);
q.setParameter("cm", store.getId());
q.setParameter("cl", language.getId());
@SuppressWarnings("unchecked") List<Content> contents = q.getResultList();
List<ContentDescription> descriptions = new ArrayList<ContentDescription>();
for (Content c : contents) {
String name = c.getDescription().getName();
String url = c.getDescription().getSeUrl();
ContentDescription contentDescription = new ContentDescription();
contentDescription.setName(name);
contentDescription.setSeUrl(url);
contentDescription.setContent(c);
descriptions.add(contentDescription);
}
return descriptions;
}
use of com.salesmanager.core.model.content.ContentDescription 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.ContentDescription in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method buildDescriptions.
/*
* private List<ContentDescription> createContentDescription(
* PersistableContentPage content) throws ServiceException {
* Validate.notNull(contentModel, "Content cannot be null");
*
* List<ContentDescription> descriptions = new
* ArrayList<ContentDescription>(); for (NamedEntity objectContent :
* content.getDescriptions()) { Language lang =
* languageService.getByCode(objectContent.getLanguage());
* ContentDescription contentDescription = new ContentDescription(); if
* (contentModel != null) {
* setContentDescriptionToContentModel(contentModel, contentDescription,
* lang); } contentDescription.setLanguage(lang);
* contentDescription.setMetatagDescription(objectContent.getMetaDescription
* ()); contentDescription.setTitle(objectContent.getTitle());
* contentDescription.setName(objectContent.getName());
* contentDescription.setSeUrl(objectContent.getFriendlyUrl());
* contentDescription.setDescription(objectContent.getDescription());
* contentDescription.setMetatagTitle(objectContent.getTitle());
* descriptions.add(contentDescription); } return descriptions; }
*/
private List<ContentDescription> buildDescriptions(Content contentModel, List<com.salesmanager.shop.model.content.common.ContentDescription> persistableDescriptions) throws Exception {
List<ContentDescription> descriptions = new ArrayList<ContentDescription>();
for (com.salesmanager.shop.model.content.common.ContentDescription objectContent : persistableDescriptions) {
Language lang = languageService.getByCode(objectContent.getLanguage());
Validate.notNull(lang, "language cannot be null");
ContentDescription contentDescription = null;
if (!CollectionUtils.isEmpty(contentModel.getDescriptions())) {
for (ContentDescription descriptionModel : contentModel.getDescriptions()) {
if (descriptionModel.getLanguage().getCode().equals(lang.getCode())) {
contentDescription = descriptionModel;
break;
}
}
}
if (contentDescription == null) {
contentDescription = new ContentDescription();
}
// if (contentModel != null) {
// setContentDescriptionToContentModel(contentModel, contentDescription, lang);
// }
contentDescription.setMetatagDescription(objectContent.getMetaDescription());
contentDescription.setTitle(objectContent.getTitle());
contentDescription.setName(objectContent.getName());
contentDescription.setSeUrl(objectContent.getFriendlyUrl());
contentDescription.setDescription(objectContent.getDescription());
contentDescription.setMetatagTitle(objectContent.getTitle());
contentDescription.setContent(contentModel);
contentDescription.setLanguage(lang);
descriptions.add(contentDescription);
// contentDescription.setId(objectContent.getId());
/**
* contentDescription.setMetatagDescription(objectContent.getMetaDescription());
* contentDescription.setTitle(objectContent.getTitle());
* contentDescription.setName(objectContent.getName());
* contentDescription.setSeUrl(objectContent.getFriendlyUrl());
* contentDescription.setDescription(objectContent.getDescription());
* contentDescription.setMetatagTitle(objectContent.getTitle());
* descriptions.add(contentDescription);
*/
}
return descriptions;
}
use of com.salesmanager.core.model.content.ContentDescription 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.ContentDescription 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();
}
Aggregations