Search in sources :

Example 11 with ContentDescription

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;
}
Also used : Query(javax.persistence.Query) Content(com.salesmanager.core.model.content.Content) ArrayList(java.util.ArrayList) ContentDescription(com.salesmanager.core.model.content.ContentDescription)

Example 12 with ContentDescription

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;
    }
}
Also used : ContentDescription(com.salesmanager.core.model.content.ContentDescription) ContentFacade(com.salesmanager.shop.store.controller.content.facade.ContentFacade) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) ContentDescriptionEntity(com.salesmanager.shop.model.content.ContentDescriptionEntity) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) PersistableContentBox(com.salesmanager.shop.model.content.box.PersistableContentBox) PersistableContentPage(com.salesmanager.shop.model.content.page.PersistableContentPage) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ContentFile(com.salesmanager.shop.model.content.ContentFile) ReadableContentPageFull(com.salesmanager.shop.model.content.page.ReadableContentPageFull) ReadableContentPage(com.salesmanager.shop.model.content.page.ReadableContentPage) ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Content(com.salesmanager.core.model.content.Content) ReadableContentFull(com.salesmanager.shop.model.content.ReadableContentFull) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ContentType(com.salesmanager.core.model.content.ContentType) FileContentType(com.salesmanager.core.model.content.FileContentType) ReadableContentBox(com.salesmanager.shop.model.content.box.ReadableContentBox) Validate(org.jsoup.helper.Validate) OutputContentFile(com.salesmanager.core.model.content.OutputContentFile) Logger(org.slf4j.Logger) ConstraintException(com.salesmanager.shop.store.api.exception.ConstraintException) IOException(java.io.IOException) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) Page(org.springframework.data.domain.Page) InputContentFile(com.salesmanager.core.model.content.InputContentFile) Collectors(java.util.stream.Collectors) ContentService(com.salesmanager.core.business.services.content.ContentService) ContentFolder(com.salesmanager.shop.model.content.ContentFolder) ReadableContentBoxFull(com.salesmanager.shop.model.content.box.ReadableContentBoxFull) URLEncoder(java.net.URLEncoder) List(java.util.List) Component(org.springframework.stereotype.Component) ContentImage(com.salesmanager.shop.model.content.ContentImage) CollectionUtils(org.springframework.util.CollectionUtils) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) ReadableContentEntity(com.salesmanager.shop.model.content.ReadableContentEntity) FilePathUtils(com.salesmanager.shop.utils.FilePathUtils) InputStream(java.io.InputStream) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ReadableContentPageFull(com.salesmanager.shop.model.content.page.ReadableContentPageFull) ReadableContentPage(com.salesmanager.shop.model.content.page.ReadableContentPage) ContentDescription(com.salesmanager.core.model.content.ContentDescription)

Example 13 with ContentDescription

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;
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) ArrayList(java.util.ArrayList) ContentDescription(com.salesmanager.core.model.content.ContentDescription)

Example 14 with ContentDescription

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);
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Content(com.salesmanager.core.model.content.Content) ContentDescription(com.salesmanager.core.model.content.ContentDescription) ReadableCategoryList(com.salesmanager.shop.model.catalog.category.ReadableCategoryList)

Example 15 with ContentDescription

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();
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) PageInformation(com.salesmanager.shop.model.shop.PageInformation) Content(com.salesmanager.core.model.content.Content) ContactForm(com.salesmanager.shop.model.shop.ContactForm) ContentDescription(com.salesmanager.core.model.content.ContentDescription) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ContentDescription (com.salesmanager.core.model.content.ContentDescription)16 Content (com.salesmanager.core.model.content.Content)10 Language (com.salesmanager.core.model.reference.language.Language)8 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)6 ArrayList (java.util.ArrayList)6 ContentType (com.salesmanager.core.model.content.ContentType)4 PageInformation (com.salesmanager.shop.model.shop.PageInformation)4 ServiceException (com.salesmanager.core.business.exception.ServiceException)3 ReadableCategoryList (com.salesmanager.shop.model.catalog.category.ReadableCategoryList)3 ContentDescriptionEntity (com.salesmanager.shop.model.content.ContentDescriptionEntity)3 ReadableContentPage (com.salesmanager.shop.model.content.page.ReadableContentPage)3 ConstraintException (com.salesmanager.shop.store.api.exception.ConstraintException)3 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)3 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)3 IOException (java.io.IOException)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ContentService (com.salesmanager.core.business.services.content.ContentService)2 LanguageService (com.salesmanager.core.business.services.reference.language.LanguageService)2 FileContentType (com.salesmanager.core.model.content.FileContentType)2 InputContentFile (com.salesmanager.core.model.content.InputContentFile)2