Search in sources :

Example 11 with Site

use of org.broadleafcommerce.common.site.domain.Site in project BroadleafCommerce by BroadleafCommerce.

the class AbstractCacheMissAware method buildKey.

/**
 * Build the key representing this missed cache item. Will include sandbox and/or site information
 * if appropriate.
 *
 * @param params the appropriate params comprising a unique key for this cache item
 * @return the completed key
 */
protected String buildKey(String... params) {
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    SandBox sandBox = null;
    if (context != null) {
        sandBox = context.getSandBox();
    }
    String key = StringUtils.join(params, '_');
    if (sandBox != null) {
        key = sandBox.getId() + "_" + key;
    }
    Site site = context.getNonPersistentSite();
    if (site != null) {
        key = key + "_" + site.getId();
    }
    return key;
}
Also used : SandBox(org.broadleafcommerce.common.sandbox.domain.SandBox) Site(org.broadleafcommerce.common.site.domain.Site) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 12 with Site

use of org.broadleafcommerce.common.site.domain.Site in project BroadleafCommerce by BroadleafCommerce.

the class FileSystemFileServiceProvider method getSiteDirectory.

/**
 * Creates a unique directory on the file system for each site.
 * Each site may be in one of 255 base directories.   This model efficiently supports up to 65,000 sites
 * served from a single file system based on most OS systems ability to quickly access files as long
 * as there are not more than 255 directories.
 *
 * @param The starting directory for local files which must end with a '/';
 */
protected String getSiteDirectory(String baseDirectory) {
    BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
    if (brc != null) {
        Site site = brc.getSite();
        if (site != null) {
            String siteDirectory = "site-" + site.getId();
            String siteHash = DigestUtils.md5Hex(siteDirectory);
            String sitePath = FilenameUtils.concat(siteHash.substring(0, 2), siteDirectory);
            return FilenameUtils.concat(baseDirectory, sitePath);
        }
    }
    return baseDirectory;
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 13 with Site

use of org.broadleafcommerce.common.site.domain.Site in project BroadleafCommerce by BroadleafCommerce.

the class SparseTranslationOverrideStrategy method getLocaleBasedTemplateValue.

@Override
public LocalePair getLocaleBasedTemplateValue(String templateCacheKey, String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode, String specificPropertyKey, String generalPropertyKey) {
    LocalePair override = null;
    if (preCachedSparseOverrideService.isActiveForType(Translation.class.getName())) {
        Site currentSite = BroadleafRequestContext.getBroadleafRequestContext().getNonPersistentSite();
        boolean isIsolatedActive = false;
        if (currentSite != null) {
            isIsolatedActive = preCachedSparseOverrideService.isActiveIsolatedSiteForType(currentSite.getId(), TranslationImpl.class.getName());
        }
        if (isIsolatedActive || templateEnabled) {
            override = new LocalePair();
            List<Translation> templateVals;
            if (!isIsolatedActive) {
                templateVals = getTemplateTranslations(entityType, entityId, property, localeCode);
            } else {
                // We need to include the standard site catalog in the query, so don't try to use an optimized template query
                templateVals = new ArrayList<Translation>();
                Translation translation = dao.readTranslation(entityType, entityId, property, localeCode, localeCountryCode, ResultType.CATALOG_ONLY);
                if (translation != null) {
                    templateVals.add(translation);
                }
            }
            List<String> codesToMatch = new ArrayList<String>();
            if (specificPropertyKey.endsWith(localeCountryCode) && generalPropertyKey.endsWith(localeCountryCode)) {
                codesToMatch.add(localeCountryCode);
            } else if (specificPropertyKey.endsWith(localeCode) && generalPropertyKey.endsWith(localeCode)) {
                codesToMatch.add(localeCode);
            } else {
                codesToMatch.add(localeCountryCode);
                codesToMatch.add(localeCode);
            }
            for (String code : codesToMatch) {
                for (Translation templateVal : templateVals) {
                    if (templateVal.getLocaleCode().equals(code)) {
                        StandardCacheItem cacheItem = new StandardCacheItem();
                        cacheItem.setItemStatus(ItemStatus.NORMAL);
                        cacheItem.setCacheItem(templateVal);
                        override.setSpecificItem(cacheItem);
                        break;
                    }
                }
                if (override.getSpecificItem() != null) {
                    break;
                }
            }
        }
    }
    return override;
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) Translation(org.broadleafcommerce.common.i18n.domain.Translation) StandardCacheItem(org.broadleafcommerce.common.extension.StandardCacheItem) ArrayList(java.util.ArrayList)

Example 14 with Site

use of org.broadleafcommerce.common.site.domain.Site 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);
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) SiteImpl(org.broadleafcommerce.common.site.domain.SiteImpl) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) CustomUrlSiteMapGeneratorConfiguration(org.broadleafcommerce.common.sitemap.domain.CustomUrlSiteMapGeneratorConfiguration) CustomUrlSiteMapGenerator(org.broadleafcommerce.common.sitemap.service.CustomUrlSiteMapGenerator) File(java.io.File) Test(org.junit.Test)

Example 15 with Site

use of org.broadleafcommerce.common.site.domain.Site 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);
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) SiteImpl(org.broadleafcommerce.common.site.domain.SiteImpl) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) File(java.io.File)

Aggregations

Site (org.broadleafcommerce.common.site.domain.Site)27 BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)16 ArrayList (java.util.ArrayList)5 Locale (org.broadleafcommerce.common.locale.domain.Locale)4 SandBox (org.broadleafcommerce.common.sandbox.domain.SandBox)4 SiteImpl (org.broadleafcommerce.common.site.domain.SiteImpl)4 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)3 Catalog (org.broadleafcommerce.common.site.domain.Catalog)3 AdminUser (org.broadleafcommerce.openadmin.server.security.domain.AdminUser)3 File (java.io.File)2 Set (java.util.Set)2 TimeZone (java.util.TimeZone)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Element (net.sf.ehcache.Element)2 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)2 RequestDTOImpl (org.broadleafcommerce.common.RequestDTOImpl)2 BroadleafRequestedCurrencyDto (org.broadleafcommerce.common.currency.domain.BroadleafRequestedCurrencyDto)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1