Search in sources :

Example 1 with Catalog

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);
    }
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) Catalog(org.broadleafcommerce.common.site.domain.Catalog)

Example 2 with Catalog

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);
    }
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) Catalog(org.broadleafcommerce.common.site.domain.Catalog)

Example 3 with Catalog

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);
    }
}
Also used : BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) CatalogStructure(org.broadleafcommerce.core.search.dao.CatalogStructure) Catalog(org.broadleafcommerce.common.site.domain.Catalog)

Example 4 with Catalog

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());
                }
            }
        }
    }
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) Set(java.util.Set) ArrayList(java.util.ArrayList) Catalog(org.broadleafcommerce.common.site.domain.Catalog) AdminUser(org.broadleafcommerce.openadmin.server.security.domain.AdminUser) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 5 with Catalog

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;
}
Also used : Catalog(org.broadleafcommerce.common.site.domain.Catalog)

Aggregations

Catalog (org.broadleafcommerce.common.site.domain.Catalog)6 BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)4 Site (org.broadleafcommerce.common.site.domain.Site)3 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)1 CatalogStructure (org.broadleafcommerce.core.search.dao.CatalogStructure)1 AdminUser (org.broadleafcommerce.openadmin.server.security.domain.AdminUser)1