Search in sources :

Example 1 with PageImpl

use of org.broadleafcommerce.cms.page.domain.PageImpl in project BroadleafCommerce by BroadleafCommerce.

the class PageDaoImpl method readAllPages.

@Override
public List<Page> readAllPages() {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Page> criteria = builder.createQuery(Page.class);
    Root<PageImpl> page = criteria.from(PageImpl.class);
    criteria.select(page);
    try {
        Query query = em.createQuery(criteria);
        query.setHint(QueryHints.HINT_CACHEABLE, true);
        return query.getResultList();
    } catch (NoResultException e) {
        return Collections.emptyList();
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) PageImpl(org.broadleafcommerce.cms.page.domain.PageImpl) TypedQuery(javax.persistence.TypedQuery) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) Page(org.broadleafcommerce.cms.page.domain.Page) NoResultException(javax.persistence.NoResultException)

Example 2 with PageImpl

use of org.broadleafcommerce.cms.page.domain.PageImpl in project BroadleafCommerce by BroadleafCommerce.

the class PageDaoImpl method readOnlineAndIncludedPages.

@Override
public List<Page> readOnlineAndIncludedPages(int limit, int offset, String sortBy) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Page> criteria = builder.createQuery(Page.class);
    Root<PageImpl> page = criteria.from(PageImpl.class);
    criteria.select(page);
    criteria.where(builder.and(builder.or(builder.isFalse(page.get("offlineFlag").as(Boolean.class)), builder.isNull(page.get("offlineFlag").as(Boolean.class))), builder.or(builder.isFalse(page.get("excludeFromSiteMap").as(Boolean.class)), builder.isNull(page.get("excludeFromSiteMap").as(Boolean.class)))));
    criteria.orderBy(builder.asc(page.get(sortBy)));
    TypedQuery<Page> query = em.createQuery(criteria);
    query.setFirstResult(offset);
    query.setMaxResults(limit);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) PageImpl(org.broadleafcommerce.cms.page.domain.PageImpl) Page(org.broadleafcommerce.cms.page.domain.Page)

Example 3 with PageImpl

use of org.broadleafcommerce.cms.page.domain.PageImpl in project BroadleafCommerce by BroadleafCommerce.

the class PageSiteMapGeneratorTest method testPageSiteMapGenerator.

@Test
public void testPageSiteMapGenerator() throws SiteMapException, IOException {
    Page p1 = new PageImpl();
    p1.setFullUrl("/about_us");
    Page p2 = new PageImpl();
    p2.setFullUrl("faq");
    Page p3 = new PageImpl();
    p3.setFullUrl("/new-to-hot-sauce");
    List<Page> pages = new ArrayList<Page>();
    pages.add(p1);
    pages.add(p2);
    pages.add(p3);
    PageDao pageDao = EasyMock.createMock(PageDao.class);
    EasyMock.expect(pageDao.readOnlineAndIncludedPages(5, 0, "fullUrl")).andReturn(pages);
    EasyMock.replay(pageDao);
    PageSiteMapGenerator psmg = new PageSiteMapGenerator();
    psmg.setPageDao(pageDao);
    psmg.setRowLimit(5);
    SiteMapGeneratorConfiguration smgc = new SiteMapGeneratorConfigurationImpl();
    smgc.setDisabled(false);
    smgc.setSiteMapGeneratorType(SiteMapGeneratorType.PAGE);
    smgc.setSiteMapChangeFreq(SiteMapChangeFreqType.HOURLY);
    smgc.setSiteMapPriority(SiteMapPriorityType.POINT5);
    testGenerator(smgc, psmg);
    File file1 = fileService.getResource("/sitemap_index.xml");
    File file2 = fileService.getResource("/sitemap1.xml");
    File file3 = fileService.getResource("/sitemap2.xml");
    compareFiles(file1, "src/test/resources/org/broadleafcommerce/sitemap/page/sitemap_index.xml");
    compareFiles(file2, "src/test/resources/org/broadleafcommerce/sitemap/page/sitemap1.xml");
    compareFiles(file3, "src/test/resources/org/broadleafcommerce/sitemap/page/sitemap2.xml");
}
Also used : PageImpl(org.broadleafcommerce.cms.page.domain.PageImpl) PageDao(org.broadleafcommerce.cms.page.dao.PageDao) ArrayList(java.util.ArrayList) Page(org.broadleafcommerce.cms.page.domain.Page) SiteMapGeneratorConfigurationImpl(org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfigurationImpl) SiteMapGeneratorConfiguration(org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfiguration) File(java.io.File) Test(org.junit.Test) SiteMapGeneratorTest(org.broadleafcommerce.common.sitemap.service.SiteMapGeneratorTest)

Aggregations

Page (org.broadleafcommerce.cms.page.domain.Page)3 PageImpl (org.broadleafcommerce.cms.page.domain.PageImpl)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 NoResultException (javax.persistence.NoResultException)1 Query (javax.persistence.Query)1 TypedQuery (javax.persistence.TypedQuery)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1 PageDao (org.broadleafcommerce.cms.page.dao.PageDao)1 SiteMapGeneratorConfiguration (org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfiguration)1 SiteMapGeneratorConfigurationImpl (org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfigurationImpl)1 SiteMapGeneratorTest (org.broadleafcommerce.common.sitemap.service.SiteMapGeneratorTest)1 Test (org.junit.Test)1