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