use of org.broadleafcommerce.common.file.domain.FileWorkArea in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafFileServiceImplTest method testCreateAddFile.
public void testCreateAddFile() throws Exception {
FileWorkArea workArea1 = bfs.initializeWorkArea();
File f1 = new File(workArea1.getFilePathLocation() + "test.txt");
FileWriter fw = new FileWriter(f1);
fw.append("Test File");
fw.close();
bfs.addOrUpdateResource(workArea1, f1, false);
bfs.closeWorkArea(workArea1);
File resource = bfs.getResource("test.txt");
assertTrue(resource.exists());
bfs.removeResource("test.txt");
resource = bfs.getResource("test.txt");
assertFalse(resource.exists());
}
use of org.broadleafcommerce.common.file.domain.FileWorkArea 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.file.domain.FileWorkArea in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafFileServiceImpl method initializeWorkArea.
/**
* Create a file work area that can be used for further operations.
* @return
*/
@Override
public FileWorkArea initializeWorkArea() {
String baseDirectory = getBaseDirectory(false);
String tempDirectory = getTempDirectory(baseDirectory);
FileWorkArea fw = new FileWorkArea();
fw.setFilePathLocation(tempDirectory);
File tmpDir = new File(tempDirectory);
if (!tmpDir.exists()) {
if (LOG.isTraceEnabled()) {
LOG.trace("Creating temp directory named " + tempDirectory);
}
if (!tmpDir.mkdirs()) {
throw new FileServiceException("Unable to create temporary working directory for " + tempDirectory);
}
}
return fw;
}
use of org.broadleafcommerce.common.file.domain.FileWorkArea in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafFileServiceImplTest method testCreateFilesCopyWorkarea.
public void testCreateFilesCopyWorkarea() throws Exception {
FileWorkArea workArea1 = bfs.initializeWorkArea();
File f1 = new File(workArea1.getFilePathLocation() + "test4.txt");
FileWriter fw = new FileWriter(f1);
fw.append("Test File 4");
fw.close();
File f2 = new File(workArea1.getFilePathLocation() + "test5.txt");
FileWriter fw2 = new FileWriter(f2);
fw2.append("Test File 5");
fw2.close();
bfs.addOrUpdateResources(workArea1, false);
bfs.closeWorkArea(workArea1);
File resource = bfs.getResource("test4.txt");
assertTrue(resource.exists());
resource = bfs.getResource("test5.txt");
assertTrue(resource.exists());
bfs.removeResource("test4.txt");
bfs.removeResource("test5.txt");
resource = bfs.getResource("test5.txt");
assertFalse(resource.exists());
}
use of org.broadleafcommerce.common.file.domain.FileWorkArea in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafFileServiceImplTest method testCreateWorkArea.
public void testCreateWorkArea() throws Exception {
FileWorkArea workArea1 = bfs.initializeWorkArea();
File f1 = new File(workArea1.getFilePathLocation());
// The service should return a directory that is ready write to.
assertTrue(f1.exists());
// The service should return a unique work area.
FileWorkArea workArea2 = bfs.initializeWorkArea();
assertFalse(workArea2.getFilePathLocation().equals(workArea1.getFilePathLocation()));
// Remove the work areas
bfs.closeWorkArea(workArea1);
assertFalse(f1.exists());
bfs.closeWorkArea(workArea2);
}
Aggregations