Search in sources :

Example 1 with SiteMapGeneratorConfiguration

use of org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfiguration 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)

Example 2 with SiteMapGeneratorConfiguration

use of org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfiguration in project BroadleafCommerce by BroadleafCommerce.

the class SiteMapServiceImpl method generateSiteMap.

@Override
public SiteMapGenerationResponse generateSiteMap() throws SiteMapException, IOException {
    SiteMapGenerationResponse smgr = new SiteMapGenerationResponse();
    SiteMapConfiguration smc = findActiveSiteMapConfiguration();
    if (smc == null) {
        if (LOG.isWarnEnabled()) {
            LOG.warn("No SiteMap generated since no active configuration was found.");
        }
        smgr.setHasError(true);
        smgr.setErrorCode("No SiteMap Configuration Found");
        return smgr;
    }
    FileWorkArea fileWorkArea = broadleafFileService.initializeWorkArea();
    SiteMapBuilder siteMapBuilder = new SiteMapBuilder(smc, fileWorkArea, baseUrlResolver.getSiteBaseUrl(), getGzipSiteMapFiles());
    if (LOG.isTraceEnabled()) {
        LOG.trace("File work area initalized with path " + fileWorkArea.getFilePathLocation());
    }
    for (SiteMapGeneratorConfiguration currentConfiguration : smc.getSiteMapGeneratorConfigurations()) {
        if (currentConfiguration.isDisabled()) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Skipping disabled sitemap generator configuration" + currentConfiguration.getId());
            }
            continue;
        }
        SiteMapGenerator generator = selectSiteMapGenerator(currentConfiguration);
        if (generator != null) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("SiteMapGenerator found, adding entries" + generator.getClass());
            }
            generator.addSiteMapEntries(currentConfiguration, siteMapBuilder);
        } else {
            LOG.warn("No site map generator found to process generator configuration for " + currentConfiguration.getSiteMapGeneratorType());
        }
    }
    siteMapBuilder.persistSiteMap();
    // Check for GZip
    if (getGzipSiteMapFiles()) {
        gzipAndDeleteFiles(fileWorkArea, siteMapBuilder.getIndexedFileNames(), false);
        List<String> indexFileNames = new ArrayList<String>();
        for (String fileName : siteMapBuilder.getIndexedFileNames()) {
            indexFileNames.add(fileName + ENCODING_EXTENSION);
        }
        smgr.setSiteMapFilePaths(indexFileNames);
    } else {
        smgr.setSiteMapFilePaths(siteMapBuilder.getIndexedFileNames());
    }
    // Move the generated files to their permanent location
    broadleafFileService.addOrUpdateResources(fileWorkArea, true);
    broadleafFileService.closeWorkArea(fileWorkArea);
    return smgr;
}
Also used : SiteMapConfiguration(org.broadleafcommerce.common.sitemap.domain.SiteMapConfiguration) ArrayList(java.util.ArrayList) FileWorkArea(org.broadleafcommerce.common.file.domain.FileWorkArea) SiteMapGeneratorConfiguration(org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfiguration)

Example 3 with SiteMapGeneratorConfiguration

use of org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfiguration in project BroadleafCommerce by BroadleafCommerce.

the class SiteMapGeneratorTest method testGenerator.

protected void testGenerator(List<SiteMapGeneratorConfiguration> smgcList, SiteMapGenerator smg, int maxEntriesPerFile) throws SiteMapException, IOException {
    if (CollectionUtils.isNotEmpty(smgcList)) {
        SiteMapConfiguration smc = new SiteMapConfigurationImpl();
        smc.setMaximumUrlEntriesPerFile(maxEntriesPerFile);
        smc.setSiteMapGeneratorConfigurations(smgcList);
        smc.setIndexedSiteMapFileName("sitemap_index.xml");
        for (SiteMapGeneratorConfiguration smgc : smgcList) {
            smgc.setSiteMapConfiguration(smc);
        }
        List<ModuleConfiguration> mcList = new ArrayList<>();
        mcList.add(smc);
        ModuleConfigurationService mcs = EasyMock.createMock(ModuleConfigurationService.class);
        EasyMock.expect(mcs.findActiveConfigurationsByType(ModuleConfigurationType.SITE_MAP)).andReturn(mcList);
        EasyMock.replay(mcs);
        List<SiteMapGenerator> smgList = new ArrayList<>();
        smgList.add(smg);
        siteMapService.setGzipSiteMapFiles(false);
        siteMapService.setModuleConfigurationService(mcs);
        siteMapService.setSiteMapGenerators(smgList);
        SiteMapGenerationResponse smgr = siteMapService.generateSiteMap();
        Assert.assertFalse(smgr.isHasError());
    }
}
Also used : SiteMapGenerator(org.broadleafcommerce.common.sitemap.service.SiteMapGenerator) ModuleConfiguration(org.broadleafcommerce.common.config.domain.ModuleConfiguration) SiteMapConfigurationImpl(org.broadleafcommerce.common.sitemap.domain.SiteMapConfigurationImpl) ModuleConfigurationService(org.broadleafcommerce.common.config.service.ModuleConfigurationService) SiteMapConfiguration(org.broadleafcommerce.common.sitemap.domain.SiteMapConfiguration) ArrayList(java.util.ArrayList) SiteMapGenerationResponse(org.broadleafcommerce.common.sitemap.service.SiteMapGenerationResponse) SiteMapGeneratorConfiguration(org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfiguration)

Example 4 with SiteMapGeneratorConfiguration

use of org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfiguration in project BroadleafCommerce by BroadleafCommerce.

the class CategorySiteMapGeneratorTest method testCategorySiteMapGenerator.

@Test
public void testCategorySiteMapGenerator() throws SiteMapException, IOException {
    Category c1 = new CategoryImpl();
    c1.setUrl("/");
    c1.setId(1l);
    Category c2 = new CategoryImpl();
    c2.setUrl("/hot-sauces");
    c2.setId(2l);
    CategoryMediaXref cmXref1 = new CategoryMediaXrefImpl();
    Media m1 = new MediaImpl();
    m1.setUrl("/img/hot-sauce-img1.png");
    cmXref1.setCategory(c2);
    cmXref1.setMedia(m1);
    c2.getCategoryMediaXref().put("image1", cmXref1);
    CategoryMediaXref cmXref2 = new CategoryMediaXrefImpl();
    Media m2 = new MediaImpl();
    m2.setUrl("/img/hot-sauce-img2.png");
    cmXref2.setCategory(c2);
    cmXref2.setMedia(m2);
    c2.getCategoryMediaXref().put("image2", cmXref2);
    Category c3 = new CategoryImpl();
    c3.setUrl("merchandise");
    c3.setId(3l);
    Category c4 = new CategoryImpl();
    c4.setUrl("/clearance");
    c4.setId(4l);
    Category c5 = new CategoryImpl();
    c5.setUrl("/mens");
    c5.setId(5l);
    Category c6 = new CategoryImpl();
    c6.setUrl("/womens");
    c6.setId(6l);
    List<Category> merchandiseSubcategories = new ArrayList<Category>();
    merchandiseSubcategories.add(c5);
    merchandiseSubcategories.add(c6);
    CategoryDao categoryDao = EasyMock.createMock(CategoryDao.class);
    EasyMock.expect(categoryDao.readActiveSubCategoriesByCategory(c1, 5, 0)).andReturn(new ArrayList<Category>()).atLeastOnce();
    EasyMock.expect(categoryDao.readCategoryById(c1.getId())).andReturn(c1).atLeastOnce();
    EasyMock.expect(categoryDao.readActiveSubCategoriesByCategory(c2, 5, 0)).andReturn(new ArrayList<Category>()).atLeastOnce();
    EasyMock.expect(categoryDao.readCategoryById(c2.getId())).andReturn(c2).atLeastOnce();
    EasyMock.expect(categoryDao.readActiveSubCategoriesByCategory(c3, 5, 0)).andReturn(merchandiseSubcategories).atLeastOnce();
    EasyMock.expect(categoryDao.readCategoryById(c3.getId())).andReturn(c3).atLeastOnce();
    EasyMock.expect(categoryDao.readActiveSubCategoriesByCategory(c4, 5, 0)).andReturn(new ArrayList<Category>()).atLeastOnce();
    EasyMock.expect(categoryDao.readCategoryById(c4.getId())).andReturn(c4).atLeastOnce();
    EasyMock.expect(categoryDao.readActiveSubCategoriesByCategory(c5, 5, 0)).andReturn(new ArrayList<Category>()).atLeastOnce();
    EasyMock.expect(categoryDao.readCategoryById(c5.getId())).andReturn(c5).atLeastOnce();
    EasyMock.expect(categoryDao.readActiveSubCategoriesByCategory(c6, 5, 0)).andReturn(new ArrayList<Category>()).atLeastOnce();
    EasyMock.expect(categoryDao.readCategoryById(c6.getId())).andReturn(c6).atLeastOnce();
    // Initialize the mocks
    EasyMock.replay(categoryDao);
    CategorySiteMapGenerator csmg = new CategorySiteMapGenerator(new MockEnvironment());
    csmg.setCategoryDao(categoryDao);
    csmg.setRowLimit(5);
    List<SiteMapGeneratorConfiguration> smgcList = new ArrayList<SiteMapGeneratorConfiguration>();
    CategorySiteMapGeneratorConfiguration c1CSMGC = new CategorySiteMapGeneratorConfigurationImpl();
    c1CSMGC.setDisabled(false);
    c1CSMGC.setSiteMapGeneratorType(SiteMapGeneratorType.CATEGORY);
    c1CSMGC.setSiteMapChangeFreq(SiteMapChangeFreqType.HOURLY);
    c1CSMGC.setSiteMapPriority(SiteMapPriorityType.POINT5);
    c1CSMGC.setRootCategory(c1);
    c1CSMGC.setStartingDepth(0);
    c1CSMGC.setEndingDepth(1);
    smgcList.add(c1CSMGC);
    CategorySiteMapGeneratorConfiguration c2CSMGC = new CategorySiteMapGeneratorConfigurationImpl();
    c2CSMGC.setDisabled(false);
    c2CSMGC.setSiteMapGeneratorType(SiteMapGeneratorType.CATEGORY);
    c2CSMGC.setSiteMapChangeFreq(SiteMapChangeFreqType.HOURLY);
    c2CSMGC.setSiteMapPriority(SiteMapPriorityType.POINT5);
    c2CSMGC.setRootCategory(c2);
    c2CSMGC.setStartingDepth(0);
    c2CSMGC.setEndingDepth(1);
    smgcList.add(c2CSMGC);
    CategorySiteMapGeneratorConfiguration c3CSMGC = new CategorySiteMapGeneratorConfigurationImpl();
    c3CSMGC.setDisabled(false);
    c3CSMGC.setSiteMapGeneratorType(SiteMapGeneratorType.CATEGORY);
    c3CSMGC.setSiteMapChangeFreq(SiteMapChangeFreqType.HOURLY);
    c3CSMGC.setSiteMapPriority(SiteMapPriorityType.POINT5);
    c3CSMGC.setRootCategory(c3);
    c3CSMGC.setStartingDepth(0);
    c3CSMGC.setEndingDepth(1);
    smgcList.add(c3CSMGC);
    CategorySiteMapGeneratorConfiguration c4CSMGC = new CategorySiteMapGeneratorConfigurationImpl();
    c4CSMGC.setDisabled(false);
    c4CSMGC.setSiteMapGeneratorType(SiteMapGeneratorType.CATEGORY);
    c4CSMGC.setSiteMapChangeFreq(SiteMapChangeFreqType.HOURLY);
    c4CSMGC.setSiteMapPriority(SiteMapPriorityType.POINT5);
    c4CSMGC.setRootCategory(c4);
    c4CSMGC.setStartingDepth(0);
    c4CSMGC.setEndingDepth(1);
    smgcList.add(c4CSMGC);
    testGenerator(smgcList, csmg, 2);
    File file1 = fileService.getResource("/sitemap_index.xml");
    File file2 = fileService.getResource("/sitemap1.xml");
    File file3 = fileService.getResource("/sitemap2.xml");
    File file4 = fileService.getResource("/sitemap3.xml");
    compareFiles(file1, "src/test/resources/org/broadleafcommerce/sitemap/category/sitemap_index.xml");
    compareFiles(file2, "src/test/resources/org/broadleafcommerce/sitemap/category/sitemap1.xml");
    compareFiles(file3, "src/test/resources/org/broadleafcommerce/sitemap/category/sitemap2.xml");
    compareFiles(file4, "src/test/resources/org/broadleafcommerce/sitemap/category/sitemap3.xml");
    testGenerator(smgcList, csmg, 50000);
    File file5 = fileService.getResource("/sitemap.xml");
    compareFiles(file5, "src/test/resources/org/broadleafcommerce/sitemap/category/sitemap.xml");
}
Also used : CategorySiteMapGeneratorConfigurationImpl(org.broadleafcommerce.core.catalog.domain.CategorySiteMapGeneratorConfigurationImpl) Category(org.broadleafcommerce.core.catalog.domain.Category) MediaImpl(org.broadleafcommerce.common.media.domain.MediaImpl) CategoryDao(org.broadleafcommerce.core.catalog.dao.CategoryDao) Media(org.broadleafcommerce.common.media.domain.Media) ArrayList(java.util.ArrayList) CategoryMediaXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryMediaXrefImpl) CategoryImpl(org.broadleafcommerce.core.catalog.domain.CategoryImpl) MockEnvironment(org.springframework.mock.env.MockEnvironment) CategoryMediaXref(org.broadleafcommerce.core.catalog.domain.CategoryMediaXref) SiteMapGeneratorConfiguration(org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfiguration) CategorySiteMapGeneratorConfiguration(org.broadleafcommerce.core.catalog.domain.CategorySiteMapGeneratorConfiguration) File(java.io.File) CategorySiteMapGeneratorConfiguration(org.broadleafcommerce.core.catalog.domain.CategorySiteMapGeneratorConfiguration) Test(org.junit.Test) SiteMapGeneratorTest(org.broadleafcommerce.common.sitemap.service.SiteMapGeneratorTest)

Example 5 with SiteMapGeneratorConfiguration

use of org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfiguration in project BroadleafCommerce by BroadleafCommerce.

the class ProductSiteMapGeneratorTest method testProductSiteMapGenerator.

@Test
public void testProductSiteMapGenerator() throws SiteMapException, IOException {
    Product p1 = new ProductImpl();
    p1.setUrl("/hot-sauces/sudden_death_sauce");
    Sku s1 = new SkuImpl();
    p1.setDefaultSku(s1);
    Product p2 = new ProductImpl();
    p2.setUrl("hot-sauces/sweet_death_sauce");
    Sku s2 = new SkuImpl();
    p2.setDefaultSku(s2);
    Product p3 = new ProductImpl();
    p3.setUrl("/hot-sauces/hoppin_hot_sauce");
    Sku s3 = new SkuImpl();
    p3.setDefaultSku(s3);
    Product p4 = new ProductImpl();
    p4.setUrl("/hot-sauces/day_of_the_dead_chipotle_hot_sauce");
    Sku s4 = new SkuImpl();
    p4.setDefaultSku(s4);
    List<Product> products = new ArrayList<Product>();
    products.add(p1);
    products.add(p2);
    products.add(p3);
    products.add(p4);
    ProductDao productDao = EasyMock.createMock(ProductDao.class);
    EasyMock.expect(productDao.readAllActiveProducts(EasyMock.eq(0), EasyMock.eq(5))).andReturn(products);
    EasyMock.replay(productDao);
    ProductSiteMapGenerator psmg = new ProductSiteMapGenerator();
    psmg.setProductDao(productDao);
    psmg.setPageSize(5);
    SiteMapGeneratorConfiguration smgc = new SiteMapGeneratorConfigurationImpl();
    smgc.setDisabled(false);
    smgc.setSiteMapGeneratorType(SiteMapGeneratorType.PRODUCT);
    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/product/sitemap_index.xml");
    compareFiles(file2, "src/test/resources/org/broadleafcommerce/sitemap/product/sitemap1.xml");
    compareFiles(file3, "src/test/resources/org/broadleafcommerce/sitemap/product/sitemap2.xml");
}
Also used : SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) SiteMapGeneratorConfigurationImpl(org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfigurationImpl) ProductDao(org.broadleafcommerce.core.catalog.dao.ProductDao) SiteMapGeneratorConfiguration(org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfiguration) File(java.io.File) Test(org.junit.Test) SiteMapGeneratorTest(org.broadleafcommerce.common.sitemap.service.SiteMapGeneratorTest)

Aggregations

ArrayList (java.util.ArrayList)6 SiteMapGeneratorConfiguration (org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfiguration)6 File (java.io.File)4 SiteMapGeneratorTest (org.broadleafcommerce.common.sitemap.service.SiteMapGeneratorTest)4 Test (org.junit.Test)4 SiteMapGeneratorConfigurationImpl (org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfigurationImpl)3 SiteMapConfiguration (org.broadleafcommerce.common.sitemap.domain.SiteMapConfiguration)2 Product (org.broadleafcommerce.core.catalog.domain.Product)2 ProductImpl (org.broadleafcommerce.core.catalog.domain.ProductImpl)2 Sku (org.broadleafcommerce.core.catalog.domain.Sku)2 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)2 PageDao (org.broadleafcommerce.cms.page.dao.PageDao)1 Page (org.broadleafcommerce.cms.page.domain.Page)1 PageImpl (org.broadleafcommerce.cms.page.domain.PageImpl)1 ModuleConfiguration (org.broadleafcommerce.common.config.domain.ModuleConfiguration)1 ModuleConfigurationService (org.broadleafcommerce.common.config.service.ModuleConfigurationService)1 FileWorkArea (org.broadleafcommerce.common.file.domain.FileWorkArea)1 Media (org.broadleafcommerce.common.media.domain.Media)1 MediaImpl (org.broadleafcommerce.common.media.domain.MediaImpl)1 SiteMapConfigurationImpl (org.broadleafcommerce.common.sitemap.domain.SiteMapConfigurationImpl)1