use of org.broadleafcommerce.common.site.domain.SiteImpl in project BroadleafCommerce by BroadleafCommerce.
the class SiteDaoImpl method retrieveSitesByPotentialIdentifiers.
public List<Site> retrieveSitesByPotentialIdentifiers(String... potentialIdentifiers) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Site> criteria = builder.createQuery(Site.class);
Root<SiteImpl> site = criteria.from(SiteImpl.class);
criteria.select(site);
criteria.where(builder.and(site.get("siteIdentifierValue").as(String.class).in(potentialIdentifiers), builder.and(builder.or(builder.isNull(site.get("archiveStatus").get("archived").as(String.class)), builder.notEqual(site.get("archiveStatus").get("archived").as(Character.class), 'Y')), builder.or(builder.isNull(site.get("deactivated").as(Boolean.class)), builder.notEqual(site.get("deactivated").as(Boolean.class), true)))));
TypedQuery<Site> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "blSiteElementsQuery");
return query.getResultList();
}
use of org.broadleafcommerce.common.site.domain.SiteImpl in project BroadleafCommerce by BroadleafCommerce.
the class CustomUrlSiteMapGeneratorTest method testSiteMapsWithSiteContext.
@Test
public void testSiteMapsWithSiteContext() throws SiteMapException, IOException {
BroadleafRequestContext brc = new BroadleafRequestContext();
BroadleafRequestContext.setBroadleafRequestContext(brc);
Site site = new SiteImpl();
site.setId(256L);
brc.setSite(site);
CustomUrlSiteMapGeneratorConfiguration smgc = getConfiguration();
testGenerator(smgc, new CustomUrlSiteMapGenerator());
File file1 = fileService.getResource("/sitemap_index.xml");
File file2 = fileService.getResource("/sitemap1.xml");
File file3 = fileService.getResource("/sitemap2.xml");
assertThat(file1.getAbsolutePath(), containsString("site-256"));
assertThat(file2.getAbsolutePath(), containsString("site-256"));
assertThat(file3.getAbsolutePath(), containsString("site-256"));
compareFiles(file1, "src/test/resources/org/broadleafcommerce/sitemap/custom/sitemap_index.xml");
compareFiles(file2, "src/test/resources/org/broadleafcommerce/sitemap/custom/sitemap1.xml");
compareFiles(file3, "src/test/resources/org/broadleafcommerce/sitemap/custom/sitemap2.xml");
// Remove the request context from thread local so it doesn't get in the way of subsequent tests
BroadleafRequestContext.setBroadleafRequestContext(null);
}
use of org.broadleafcommerce.common.site.domain.SiteImpl in project BroadleafCommerce by BroadleafCommerce.
the class FileSystemFileServiceProviderTest method testBuildFileName.
/**
* For example, if the URL is /product/myproductimage.jpg, then the MD5 would be
* 35ec52a8dbd8cf3e2c650495001fe55f resulting in the following file on the filesystem
* {assetFileSystemPath}/64/a7/myproductimage.jpg.
*
* If there is a "siteId" in the BroadleafRequestContext then the site is also distributed
* using a similar algorithm but the system attempts to keep images for sites in their own
* directory resulting in an extra two folders required to reach any given product. So, for
* site with id 125, the system will MD5 "site125" in order to build the URL string. "site125" has an md5
* string of "7d905e85b8cb72a0477632be2c342bd6".
*
* So, in this case with the above product URL in site125, the full URL on the filesystem
* will be:
*
* {assetFileSystemPath}/7d/site125/64/a7/myproductimage.jpg.
* @throws Exception
*/
public void testBuildFileName() throws Exception {
FileSystemFileServiceProvider provider = new FileSystemFileServiceProvider();
String tmpdir = FileUtils.getTempDirectoryPath();
if (!tmpdir.endsWith(File.separator)) {
tmpdir = tmpdir + File.separator;
}
provider.fileSystemBaseDirectory = FilenameUtils.concat(tmpdir, "test");
provider.maxGeneratedDirectoryDepth = 2;
File file = provider.getResource("/product/myproductimage.jpg");
String resultPath = tmpdir + StringUtils.join(new String[] { "test", "35", "ec", "myproductimage.jpg" }, File.separator);
assertEquals(file.getAbsolutePath(), FilenameUtils.normalize(resultPath));
BroadleafRequestContext brc = new BroadleafRequestContext();
BroadleafRequestContext.setBroadleafRequestContext(brc);
Site site = new SiteImpl();
site.setId(125L);
brc.setSite(site);
// try with site specific directory
file = provider.getResource("/product/myproductimage.jpg");
resultPath = tmpdir + StringUtils.join(new String[] { "test", "c8", "site-125", "35", "ec", "myproductimage.jpg" }, File.separator);
assertEquals(file.getAbsolutePath(), resultPath);
// try with 3 max generated directories
provider.maxGeneratedDirectoryDepth = 3;
file = provider.getResource("/product/myproductimage.jpg");
resultPath = tmpdir + StringUtils.join(new String[] { "test", "c8", "site-125", "35", "ec", "52", "myproductimage.jpg" }, File.separator);
assertEquals(file.getAbsolutePath(), resultPath);
// Remove the request context from thread local so it doesn't get in the way of subsequent tests
BroadleafRequestContext.setBroadleafRequestContext(null);
}
use of org.broadleafcommerce.common.site.domain.SiteImpl in project BroadleafCommerce by BroadleafCommerce.
the class SiteDaoImpl method readAllActiveSites.
@Override
public List<Site> readAllActiveSites() {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Site> criteria = builder.createQuery(Site.class);
Root<SiteImpl> site = criteria.from(SiteImpl.class);
criteria.select(site);
criteria.where(builder.and(builder.or(builder.isNull(site.get("archiveStatus").get("archived").as(String.class)), builder.notEqual(site.get("archiveStatus").get("archived").as(Character.class), 'Y')), builder.or(builder.isNull(site.get("deactivated").as(Boolean.class)), builder.notEqual(site.get("deactivated").as(Boolean.class), true))));
TypedQuery<Site> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "blSiteElementsQuery");
return query.getResultList();
}
Aggregations