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