Search in sources :

Example 1 with PageDTO

use of org.broadleafcommerce.common.page.dto.PageDTO in project BroadleafCommerce by BroadleafCommerce.

the class PageServiceImpl method buildPageDTOListUsingCache.

@SuppressWarnings("unchecked")
protected List<PageDTO> buildPageDTOListUsingCache(List<Page> pageList, String identifier, Locale locale, boolean secure) {
    List<PageDTO> dtoList = getCachedPageDTOList(pageList, identifier, locale, secure);
    if (dtoList == null || dtoList.isEmpty()) {
        addPageListToPageDTOList(pageList, secure, dtoList);
        if (dtoList != null && !dtoList.isEmpty()) {
            Collections.sort(dtoList, new BeanComparator("priority"));
            addPageListToCache(dtoList, identifier, locale, secure);
        }
    }
    return dtoList;
}
Also used : NullPageDTO(org.broadleafcommerce.common.page.dto.NullPageDTO) PageDTO(org.broadleafcommerce.common.page.dto.PageDTO) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 2 with PageDTO

use of org.broadleafcommerce.common.page.dto.PageDTO in project BroadleafCommerce by BroadleafCommerce.

the class PageServiceImpl method buildPageDTOList.

/*
     * Converts a list of pages to a list of pageDTOs, and caches the list.
     */
@Override
public List<PageDTO> buildPageDTOList(List<Page> pageList, boolean secure, String identifier, Locale locale) {
    List<PageDTO> dtoList = new ArrayList<>();
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    if (context.isProductionSandBox()) {
        dtoList = buildPageDTOListUsingCache(pageList, identifier, locale, secure);
    } else {
        // no caching actions needed if not production sandbox
        addPageListToPageDTOList(pageList, secure, dtoList);
    }
    return copyDTOList(dtoList);
}
Also used : NullPageDTO(org.broadleafcommerce.common.page.dto.NullPageDTO) PageDTO(org.broadleafcommerce.common.page.dto.PageDTO) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) ArrayList(java.util.ArrayList)

Example 3 with PageDTO

use of org.broadleafcommerce.common.page.dto.PageDTO in project BroadleafCommerce by BroadleafCommerce.

the class PageServiceUtility method hydrateForeignLookups.

public PageDTO hydrateForeignLookups(PageDTO page) {
    for (Entry<String, Object> entry : page.getPageFields().entrySet()) {
        if (entry.getValue() instanceof String && ((String) entry.getValue()).startsWith(FOREIGN_LOOKUP)) {
            page.getForeignPageFields().put(entry.getKey(), entry.getValue());
        }
    }
    if (page.getForeignPageFields().size() > 0) {
        PageDTO clone = new PageDTO();
        clone.copy(page);
        for (Entry<String, Object> entry : page.getForeignPageFields().entrySet()) {
            String clazz = ((String) entry.getValue()).split("\\|")[1];
            String id = ((String) entry.getValue()).split("\\|")[2];
            Object newValue = null;
            if (StringUtils.isNotBlank(clazz) && StringUtils.isNotBlank(id) && !"null".equals(id)) {
                newValue = genericDao.readGenericEntity(genericDao.getImplClass(clazz), id);
            }
            if (newValue != null) {
                clone.getPageFields().put(entry.getKey(), newValue);
            } else {
                clone.getPageFields().remove(entry.getKey());
            }
        }
        return clone;
    } else {
        return page;
    }
}
Also used : PageDTO(org.broadleafcommerce.common.page.dto.PageDTO)

Example 4 with PageDTO

use of org.broadleafcommerce.common.page.dto.PageDTO in project BroadleafCommerce by BroadleafCommerce.

the class PageServiceUtility method buildPageDTO.

public PageDTO buildPageDTO(Page page, boolean secure) {
    PageDTO pageDTO = new PageDTO();
    pageDTO.setId(page.getId());
    pageDTO.setDescription(page.getDescription());
    pageDTO.setUrl(page.getFullUrl());
    pageDTO.setPriority(page.getPriority());
    if (page.getPageTemplate() != null) {
        pageDTO.setTemplatePath(page.getPageTemplate().getTemplatePath());
        if (page.getPageTemplate().getLocale() != null) {
            pageDTO.setLocaleCode(page.getPageTemplate().getLocale().getLocaleCode());
        }
    }
    for (String fieldKey : page.getPageFields().keySet()) {
        addPageFieldToDTO(page, secure, pageDTO, fieldKey);
    }
    pageDTO.setRuleExpression(buildRuleExpression(page));
    if (page.getQualifyingItemCriteria() != null && page.getQualifyingItemCriteria().size() > 0) {
        pageDTO.setItemCriteriaDTOList(buildItemCriteriaDTOList(page));
    }
    for (Entry<String, PageAttribute> entry : page.getAdditionalAttributes().entrySet()) {
        pageDTO.getPageAttributes().put(entry.getKey(), entry.getValue().getValue());
    }
    pageDTO.getPageAttributes().put("title", page.getMetaTitle());
    pageDTO.getPageAttributes().put("metaDescription", page.getMetaDescription());
    return pageDTO;
}
Also used : PageDTO(org.broadleafcommerce.common.page.dto.PageDTO) PageAttribute(org.broadleafcommerce.cms.page.domain.PageAttribute)

Example 5 with PageDTO

use of org.broadleafcommerce.common.page.dto.PageDTO in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafRobotsController method getRobotsFile.

public String getRobotsFile(HttpServletRequest request, HttpServletResponse response) {
    blcContextUtil.establishThinRequestContext();
    response.setContentType("text/plain");
    response.setCharacterEncoding("UTF-8");
    PageDTO page = pageService.findPageByURI(null, "/robots.txt", buildMvelParameters(request), isSecure(request));
    if (page != null && page.getPageFields().containsKey("body")) {
        String body = (String) page.getPageFields().get("body");
        body = body.replace("${siteBaseUrl}", baseUrlResolver.getSiteBaseUrl());
        return body;
    } else {
        return getDefaultRobotsTxt();
    }
}
Also used : PageDTO(org.broadleafcommerce.common.page.dto.PageDTO)

Aggregations

PageDTO (org.broadleafcommerce.common.page.dto.PageDTO)9 NullPageDTO (org.broadleafcommerce.common.page.dto.NullPageDTO)5 ArrayList (java.util.ArrayList)2 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)2 BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)2 BeanComparator (org.apache.commons.beanutils.BeanComparator)1 Page (org.broadleafcommerce.cms.page.domain.Page)1 PageAttribute (org.broadleafcommerce.cms.page.domain.PageAttribute)1 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1