Search in sources :

Example 1 with Site

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

the class AdminTestHelper method startView.

/**
 * Useful to start an EntityManager-In-View. This allows test operations that want to read directly from the database
 * to work without lazy init exceptions, etc... This is not needed for MockMVC#perform operations, since those
 * requests will include the OpenEntityManagerInView filter as part of their flow. At the completion of the test
 * operation, the {@link #endView()} method should be called to end the scope of the view.
 * </p>
 * This view scope is also aware of nested views against the same persistence unit, so you don't need to worry
 * about coding carefully to avoid nesting calls to startView.
 *
 * @param siteId
 * @param sandBoxName
 */
public void startView(Long siteId, String sandBoxName) {
    EntityManagerFactory emf = ((JpaTransactionManager) transUtil.getTransactionManager()).getEntityManagerFactory();
    boolean isEntityManagerInView = TransactionSynchronizationManager.hasResource(emf);
    if (!isEntityManagerInView) {
        EntityManager em = emf.createEntityManager();
        em.clear();
        EntityManagerHolder emHolder = new EntityManagerHolder(em);
        TransactionSynchronizationManager.bindResource(emf, emHolder);
        Stack<String> stack = new Stack<>();
        TransactionSynchronizationManager.bindResource("emStack", stack);
        if (siteId != null) {
            Site site = siteService.retrievePersistentSiteById(siteId);
            ThreadLocalManager.remove();
            BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
            context.setSite(site);
            context.setDeployBehavior(DeployBehavior.CLONE_PARENT);
            context.setAdmin(true);
            if (!StringUtils.isEmpty(sandBoxName)) {
                SandBox sb = findSandBox(siteId, sandBoxName, false);
                context.setSandBox(sb);
            }
        }
    }
    Stack<String> stack = (Stack<String>) TransactionSynchronizationManager.getResource("emStack");
    RuntimeException trace = new RuntimeException();
    StringWriter writer = new StringWriter();
    PrintWriter pw = new PrintWriter(writer);
    trace.printStackTrace(pw);
    stack.push(writer.toString());
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) SandBox(org.broadleafcommerce.common.sandbox.domain.SandBox) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) JpaTransactionManager(org.springframework.orm.jpa.JpaTransactionManager) Stack(java.util.Stack) EntityManager(javax.persistence.EntityManager) StringWriter(java.io.StringWriter) EntityManagerFactory(javax.persistence.EntityManagerFactory) EntityManagerHolder(org.springframework.orm.jpa.EntityManagerHolder) PrintWriter(java.io.PrintWriter)

Example 2 with Site

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

the class PageServiceImpl method buildKey.

protected String buildKey(String identifier, Locale locale, Boolean secure) {
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    Site site = context.getNonPersistentSite();
    Long siteId = (site != null) ? site.getId() : null;
    locale = findLanguageOnlyLocale(locale);
    StringBuilder key = new StringBuilder(identifier);
    if (locale != null) {
        key.append("-").append(locale.getLocaleCode());
    }
    if (secure != null) {
        key.append("-").append(secure);
    }
    if (siteId != null) {
        key.append("-").append(siteId);
    }
    return key.toString();
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 3 with Site

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

the class PageServiceImpl method addPageMapCacheEntry.

@SuppressWarnings("unchecked")
protected void addPageMapCacheEntry(String identifier, String key) {
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    Site site = context.getNonPersistentSite();
    Long siteId = (site != null) ? site.getId() : null;
    String mapKey = getPageMapCacheKey(identifier, siteId);
    if (mapKey != null) {
        Element e = getPageMapCache().get(mapKey);
        if (e == null || e.getObjectValue() == null) {
            List<String> keys = new ArrayList<>();
            keys.add(key);
            getPageMapCache().put(new Element(mapKey, keys));
        } else {
            ((List<String>) e.getObjectValue()).add(mapKey);
        }
    }
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) Element(net.sf.ehcache.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with Site

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

the class BroadleafProcessURLFilter method doFilterInternal.

/**
 * (non-Javadoc)
 *
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
 */
@Override
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException {
    if (!shouldProcessURL(request, request.getRequestURI())) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Process URL not processing URL " + request.getRequestURI());
        }
        filterChain.doFilter(request, response);
        return;
    }
    final String requestURIWithoutContext;
    if (request.getContextPath() != null) {
        requestURIWithoutContext = request.getRequestURI().substring(request.getContextPath().length());
    } else {
        requestURIWithoutContext = request.getRequestURI();
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("Process URL Filter Begin " + requestURIWithoutContext);
    }
    if (request.getAttribute(REQUEST_DTO) == null) {
        request.setAttribute(REQUEST_DTO, new RequestDTOImpl(request));
    }
    Site site = determineSite(request);
    SandBox currentSandbox = determineSandbox(request, site);
    BroadleafRequestContext brc = new BroadleafRequestContext();
    brc.setLocale(determineLocale(request, site));
    brc.setSandBox(currentSandbox);
    brc.setRequest(request);
    brc.setResponse(response);
    BroadleafRequestContext.setBroadleafRequestContext(brc);
    try {
        URLProcessor urlProcessor = null;
        if (isProduction(currentSandbox)) {
            try {
                urlProcessor = lookupProcessorFromCache(requestURIWithoutContext);
            } catch (ExecutionException e) {
                LOG.error(e);
            }
        }
        if (urlProcessor == null) {
            urlProcessor = determineURLProcessor(requestURIWithoutContext);
        }
        if (urlProcessor instanceof NullURLProcessor) {
            // Pass request down the filter chain
            if (LOG.isTraceEnabled()) {
                LOG.trace("URL not being processed by a Broadleaf URLProcessor " + requestURIWithoutContext);
            }
            StatusExposingServletResponse sesResponse = new StatusExposingServletResponse(response);
            filterChain.doFilter(request, sesResponse);
            if (sesResponse.getStatus() == sesResponse.SC_NOT_FOUND) {
                if (LOG.isWarnEnabled()) {
                    LOG.warn("Page not found.  Unable to render " + requestURIWithoutContext);
                }
                urlCache.invalidate(requestURIWithoutContext);
            }
        } else {
            if (LOG.isTraceEnabled()) {
                LOG.trace("URL about to be processed by a Broadleaf URLProcessor " + requestURIWithoutContext);
            }
            urlProcessor.processURL(requestURIWithoutContext);
        }
    } finally {
        // If the system-time was overridden, set it back to normal
        SystemTime.resetLocalTimeSource();
    }
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) SandBox(org.broadleafcommerce.common.sandbox.domain.SandBox) StatusExposingServletResponse(org.broadleafcommerce.common.web.util.StatusExposingServletResponse) RequestDTOImpl(org.broadleafcommerce.common.RequestDTOImpl) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with Site

use of org.broadleafcommerce.common.site.domain.Site 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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Site(org.broadleafcommerce.common.site.domain.Site) SiteImpl(org.broadleafcommerce.common.site.domain.SiteImpl)

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