Search in sources :

Example 21 with Content

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

Example 22 with Content

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);
        }
    }
}
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 23 with Content

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);
    }
}
Also used : ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) Category(com.salesmanager.core.model.catalog.category.Category) Language(com.salesmanager.core.model.reference.language.Language) BreadcrumbItem(com.salesmanager.shop.model.shop.BreadcrumbItem) Content(com.salesmanager.core.model.content.Content) Product(com.salesmanager.core.model.catalog.product.Product) Breadcrumb(com.salesmanager.shop.model.shop.Breadcrumb)

Example 24 with Content

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();
}
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)

Example 25 with Content

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

Aggregations

Content (com.salesmanager.core.model.content.Content)25 ServiceException (com.salesmanager.core.business.exception.ServiceException)14 ContentDescription (com.salesmanager.core.model.content.ContentDescription)14 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)14 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)14 ConstraintException (com.salesmanager.shop.store.api.exception.ConstraintException)11 IOException (java.io.IOException)11 Language (com.salesmanager.core.model.reference.language.Language)10 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)9 ArrayList (java.util.ArrayList)8 ContentType (com.salesmanager.core.model.content.ContentType)7 ContentService (com.salesmanager.core.business.services.content.ContentService)6 LanguageService (com.salesmanager.core.business.services.reference.language.LanguageService)6 FileContentType (com.salesmanager.core.model.content.FileContentType)6 InputContentFile (com.salesmanager.core.model.content.InputContentFile)6 OutputContentFile (com.salesmanager.core.model.content.OutputContentFile)6 ContentDescriptionEntity (com.salesmanager.shop.model.content.ContentDescriptionEntity)6 ContentFile (com.salesmanager.shop.model.content.ContentFile)6 ContentFolder (com.salesmanager.shop.model.content.ContentFolder)6 ContentImage (com.salesmanager.shop.model.content.ContentImage)6