use of org.broadleafcommerce.common.site.domain.Catalog in project BroadleafCommerce by BroadleafCommerce.
the class IdentityExecutionUtils method runOperationByIdentifier.
public static <T, G extends Throwable> T runOperationByIdentifier(IdentityOperation<T, G> operation, Site site, Site profile, Catalog catalog, PlatformTransactionManager transactionManager) throws G {
IdentityUtilContext context = new IdentityUtilContext();
context.setIdentifier(site);
IdentityUtilContext.setUtilContext(context);
BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
Site previousSite = brc.getSite();
Catalog previousCatalog = brc.getCurrentCatalog();
Site previousProfile = brc.getCurrentProfile();
boolean isNew = initRequestContext(site, profile, catalog);
activateSession();
TransactionContainer container = null;
if (transactionManager != null) {
container = establishTransaction(transactionManager);
}
boolean isError = false;
try {
return operation.execute();
} catch (RuntimeException e) {
isError = true;
throw e;
} finally {
if (container != null) {
finalizeTransaction(transactionManager, container, isError);
}
IdentityUtilContext.setUtilContext(null);
if (isNew) {
BroadleafRequestContext.setBroadleafRequestContext(null);
}
BroadleafRequestContext.getBroadleafRequestContext().setSite(previousSite);
BroadleafRequestContext.getBroadleafRequestContext().setCurrentCatalog(previousCatalog);
BroadleafRequestContext.getBroadleafRequestContext().setCurrentProfile(previousProfile);
}
}
use of org.broadleafcommerce.common.site.domain.Catalog in project BroadleafCommerce by BroadleafCommerce.
the class IdentityExecutionUtils method runOperationAndIgnoreIdentifier.
public static <T, G extends Throwable> T runOperationAndIgnoreIdentifier(IdentityOperation<T, G> operation, PlatformTransactionManager transactionManager) throws G {
BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
Site previousSite = brc.getSite();
Catalog previousCatalog = brc.getCurrentCatalog();
Site previousProfile = brc.getCurrentProfile();
boolean isNew = initRequestContext(null, null, null);
boolean isIgnoringSite = BroadleafRequestContext.getBroadleafRequestContext().getIgnoreSite();
BroadleafRequestContext.getBroadleafRequestContext().setIgnoreSite(true);
activateSession();
TransactionContainer container = null;
if (transactionManager != null) {
container = establishTransaction(transactionManager);
}
boolean isError = false;
try {
return operation.execute();
} catch (RuntimeException e) {
isError = true;
throw e;
} finally {
if (container != null) {
finalizeTransaction(transactionManager, container, isError);
}
if (isNew) {
BroadleafRequestContext.setBroadleafRequestContext(null);
}
BroadleafRequestContext.getBroadleafRequestContext().setIgnoreSite(isIgnoringSite);
BroadleafRequestContext.getBroadleafRequestContext().setSite(previousSite);
BroadleafRequestContext.getBroadleafRequestContext().setCurrentCatalog(previousCatalog);
BroadleafRequestContext.getBroadleafRequestContext().setCurrentProfile(previousProfile);
}
}
use of org.broadleafcommerce.common.site.domain.Catalog in project BroadleafCommerce by BroadleafCommerce.
the class SolrIndexCachedOperation method setCache.
/**
* Set the cache on the current thread
*
* @param cache the cache object (usually an empty map)
*/
public static void setCache(CatalogStructure cache) {
BroadleafRequestContext ctx = BroadleafRequestContext.getBroadleafRequestContext();
Catalog currentCatalog = ctx == null ? null : ctx.getCurrentCatalog();
Map<Long, CatalogStructure> catalogCaches = CACHE.get();
if (catalogCaches == null) {
catalogCaches = new HashMap<Long, CatalogStructure>();
CACHE.set(catalogCaches);
}
if (currentCatalog != null) {
catalogCaches.put(currentCatalog.getId(), cache);
} else {
catalogCaches.put(DEFAULT_CATALOG_CACHE_KEY, cache);
}
}
use of org.broadleafcommerce.common.site.domain.Catalog in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafAdminRequestProcessor method prepareCatalog.
protected void prepareCatalog(WebRequest request, BroadleafRequestContext brc) {
AdminUser adminUser = adminRemoteSecurityService.getPersistentAdminUser();
if (adminUser == null) {
// clear any catalog
if (BLCRequestUtils.isOKtoUseSession(request)) {
request.removeAttribute(CATALOG_REQ_PARAM, WebRequest.SCOPE_GLOBAL_SESSION);
}
} else {
Catalog catalog = null;
if (StringUtils.isNotBlank(request.getParameter(CATALOG_REQ_PARAM))) {
Long catalogId = Long.parseLong(request.getParameter(CATALOG_REQ_PARAM));
catalog = siteService.findCatalogById(catalogId);
if (catalog == null) {
throw new IllegalArgumentException(String.format("Unable to find the requested catalog: %s", catalogId));
}
String token = request.getParameter(staleStateProtectionService.getStateVersionTokenParameter());
staleStateProtectionService.compareToken(token);
staleStateProtectionService.invalidateState(true);
}
if (catalog == null) {
Long previouslySetCatalogId = null;
if (BLCRequestUtils.isOKtoUseSession(request)) {
previouslySetCatalogId = (Long) request.getAttribute(CATALOG_REQ_PARAM, WebRequest.SCOPE_GLOBAL_SESSION);
}
if (previouslySetCatalogId != null) {
catalog = siteService.findCatalogById(previouslySetCatalogId);
}
}
if (catalog == null) {
List<Catalog> catalogs = new ArrayList<Catalog>();
if (brc.getNonPersistentSite() != null) {
Site currentSite = siteService.retrievePersistentSiteById(brc.getNonPersistentSite().getId());
if (extensionManager != null) {
ExtensionResultHolder<Set<Catalog>> catalogResult = new ExtensionResultHolder<Set<Catalog>>();
extensionManager.retrieveCatalogs(currentSite, catalogResult);
if (!CollectionUtils.isEmpty(catalogResult.getResult())) {
catalogs.addAll(catalogResult.getResult());
}
}
}
if (catalogs.size() > 0) {
catalog = catalogs.get(0);
}
}
if (catalog != null) {
if (BLCRequestUtils.isOKtoUseSession(request)) {
request.setAttribute(CATALOG_REQ_PARAM, catalog.getId(), WebRequest.SCOPE_GLOBAL_SESSION);
}
brc.setCurrentCatalog(catalog);
}
if (extensionManager != null) {
if (brc.getNonPersistentSite() != null) {
Site currentSite = siteService.retrievePersistentSiteById(brc.getNonPersistentSite().getId());
ExtensionResultHolder<Catalog> catalogResult = new ExtensionResultHolder<Catalog>();
extensionManager.overrideCurrentCatalog(request, currentSite, catalogResult);
if (catalogResult.getResult() != null) {
brc.setCurrentCatalog(catalogResult.getResult());
}
ExtensionResultHolder<Site> profileResult = new ExtensionResultHolder<Site>();
extensionManager.overrideCurrentProfile(request, currentSite, profileResult);
if (profileResult.getResult() != null) {
brc.setCurrentProfile(profileResult.getResult());
}
}
}
}
}
use of org.broadleafcommerce.common.site.domain.Catalog in project BroadleafCommerce by BroadleafCommerce.
the class SolrIndexServiceImpl method buildPageNumberMessage.
protected String buildPageNumberMessage(int page, Long totalPages) {
String pageNumberMessage = String.format("Building page number %s of %s", page, totalPages);
Catalog currentCatalog = BroadleafRequestContext.getBroadleafRequestContext().getCurrentCatalog();
if (currentCatalog != null) {
pageNumberMessage += String.format(" for catalog: %s", currentCatalog.getName());
}
return pageNumberMessage;
}
Aggregations