Search in sources :

Example 1 with SiteMapConfiguration

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

the class SiteMapServiceImpl method findActiveSiteMapConfiguration.

protected SiteMapConfiguration findActiveSiteMapConfiguration() {
    List<ModuleConfiguration> configurations = moduleConfigurationService.findActiveConfigurationsByType(ModuleConfigurationType.SITE_MAP);
    SiteMapConfiguration smc = null;
    if (configurations != null && !configurations.isEmpty()) {
        // Try to find a default configuration
        for (ModuleConfiguration configuration : configurations) {
            if (configuration.getIsDefault()) {
                smc = (SiteMapConfiguration) configuration;
                break;
            }
        }
        if (smc == null) {
            // if there wasn't a default one, use the first active one...
            smc = (SiteMapConfiguration) configurations.get(0);
        }
    }
    return smc;
}
Also used : ModuleConfiguration(org.broadleafcommerce.common.config.domain.ModuleConfiguration) SiteMapConfiguration(org.broadleafcommerce.common.sitemap.domain.SiteMapConfiguration)

Example 2 with SiteMapConfiguration

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

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

Aggregations

SiteMapConfiguration (org.broadleafcommerce.common.sitemap.domain.SiteMapConfiguration)3 ArrayList (java.util.ArrayList)2 ModuleConfiguration (org.broadleafcommerce.common.config.domain.ModuleConfiguration)2 SiteMapGeneratorConfiguration (org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfiguration)2 ModuleConfigurationService (org.broadleafcommerce.common.config.service.ModuleConfigurationService)1 FileWorkArea (org.broadleafcommerce.common.file.domain.FileWorkArea)1 SiteMapConfigurationImpl (org.broadleafcommerce.common.sitemap.domain.SiteMapConfigurationImpl)1 SiteMapGenerationResponse (org.broadleafcommerce.common.sitemap.service.SiteMapGenerationResponse)1 SiteMapGenerator (org.broadleafcommerce.common.sitemap.service.SiteMapGenerator)1