Search in sources :

Example 11 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class SkuDaoImpl method findSkuByURI.

@Override
public List<Sku> findSkuByURI(String uri) {
    if (extensionManager != null) {
        ExtensionResultHolder holder = new ExtensionResultHolder();
        ExtensionResultStatusType result = extensionManager.getProxy().findSkuByURI(uri, holder);
        if (ExtensionResultStatusType.HANDLED.equals(result)) {
            return (List<Sku>) holder.getResult();
        }
    }
    String skuUrlKey = uri.substring(uri.lastIndexOf('/'));
    String productUrl = uri.substring(0, uri.lastIndexOf('/'));
    Query query;
    query = em.createNamedQuery("BC_READ_SKU_BY_OUTGOING_URL");
    query.setParameter("url", uri);
    query.setParameter("productUrl", productUrl);
    query.setParameter("skuUrlKey", skuUrlKey);
    query.setParameter("currentDate", DateUtil.getCurrentDateAfterFactoringInDateResolution(cachedDate, currentDateResolution));
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
    @SuppressWarnings("unchecked") List<Sku> results = query.getResultList();
    return results;
}
Also used : TypedQuery(javax.persistence.TypedQuery) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) List(java.util.List) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 12 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class CategoryDaoImpl method findCategoryByURI.

@Override
public Category findCategoryByURI(String uri) {
    if (extensionManager != null) {
        ExtensionResultHolder holder = new ExtensionResultHolder();
        ExtensionResultStatusType result = extensionManager.getProxy().findCategoryByURI(uri, holder);
        if (ExtensionResultStatusType.HANDLED.equals(result)) {
            return (Category) holder.getResult();
        }
    }
    Query query;
    query = em.createNamedQuery("BC_READ_CATEGORY_OUTGOING_URL");
    query.setParameter("currentDate", getCurrentDateAfterFactoringInDateResolution());
    query.setParameter("url", uri);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
    @SuppressWarnings("unchecked") List<Category> results = query.getResultList();
    if (results != null && !results.isEmpty()) {
        return results.get(0);
    } else {
        return null;
    }
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 13 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class ProductDaoImpl method findProductByURI.

@Override
public List<Product> findProductByURI(String uri) {
    if (extensionManager != null) {
        ExtensionResultHolder holder = new ExtensionResultHolder();
        ExtensionResultStatusType result = extensionManager.getProxy().findProductByURI(uri, holder);
        if (ExtensionResultStatusType.HANDLED.equals(result)) {
            return (List<Product>) holder.getResult();
        }
    }
    String urlKey = uri.substring(uri.lastIndexOf('/'));
    Query query;
    query = em.createNamedQuery("BC_READ_PRODUCTS_BY_OUTGOING_URL");
    query.setParameter("url", uri);
    query.setParameter("urlKey", urlKey);
    query.setParameter("currentDate", DateUtil.getCurrentDateAfterFactoringInDateResolution(cachedDate, currentDateResolution));
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
    @SuppressWarnings("unchecked") List<Product> results = query.getResultList();
    return results;
}
Also used : TypedQuery(javax.persistence.TypedQuery) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) Product(org.broadleafcommerce.core.catalog.domain.Product) ArrayList(java.util.ArrayList) List(java.util.List) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 14 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class AdminBasicEntityController method isAddRequest.

private boolean isAddRequest(Entity entity) {
    ExtensionResultHolder<Boolean> resultHolder = new ExtensionResultHolder<>();
    ExtensionResultStatusType result = extensionManager.getProxy().isAddRequest(entity, resultHolder);
    if (result.equals(ExtensionResultStatusType.NOT_HANDLED)) {
        return false;
    }
    return resultHolder.getResult();
}
Also used : ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 15 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class AdminBasicOperationsController method showSelectCollectionItem.

/**
 * Shows the modal dialog that is used to select a "to-one" collection item. For example, this could be used to show
 * a list of categories for the ManyToOne field "defaultCategory" in Product.
 *
 * @param request
 * @param response
 * @param model
 * @param pathVars
 * @param owningClass
 * @param collectionField
 * @return the return view path
 * @throws Exception
 */
@RequestMapping(value = "/{owningClass:.*}/{collectionField:.*}/select", method = RequestMethod.GET)
public String showSelectCollectionItem(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "owningClass") String owningClass, @PathVariable(value = "collectionField") String collectionField, @RequestParam(required = false) String requestingEntityId, @RequestParam(defaultValue = "false") boolean dynamicField, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, null, null);
    String validatedClass = getClassNameForSection(owningClass);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(validatedClass, requestParams, sectionCrumbs, pathVars);
    // We might need these fields in the initial inspect.
    ppr.addCustomCriteria("requestingEntityId=" + requestingEntityId);
    ppr.addCustomCriteria("owningClass=" + owningClass);
    ppr.addCustomCriteria("requestingField=" + collectionField);
    ClassMetadata mainMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    // Only get collection property metadata when there is a non-structured content field that I am looking for
    Property collectionProperty = null;
    FieldMetadata md = null;
    if (!collectionField.contains("|") && !dynamicField) {
        collectionProperty = mainMetadata.getPMap().get(collectionField);
        md = collectionProperty.getMetadata();
        ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs);
    } else {
        md = new BasicFieldMetadata();
        md.setFriendlyName(mainMetadata.getPolymorphicEntities().getFriendlyName());
        collectionProperty = new Property();
        collectionProperty.setMetadata(md);
    }
    ppr.addFilterAndSortCriteria(getCriteria(requestParams));
    ppr.setStartIndex(getStartIndex(requestParams));
    ppr.setMaxIndex(getMaxIndex(requestParams));
    ppr.removeFilterAndSortCriteria("requestingEntityId");
    ppr.addCustomCriteria("requestingEntityId=" + requestingEntityId);
    ppr.addCustomCriteria("owningClass=" + owningClass);
    ppr.addCustomCriteria("requestingField=" + collectionField);
    modifyFetchPersistencePackageRequest(ppr, pathVars);
    ClassMetadata targetClassMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    ExtensionResultStatusType extensionResultStatusType = extensionManager.getProxy().buildLookupListGrid(ppr, targetClassMetadata, ppr.getCeilingEntityClassname(), sectionCrumbs, model, requestParams);
    if (extensionResultStatusType.equals(ExtensionResultStatusType.NOT_HANDLED)) {
        DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
        ListGrid listGrid = null;
        if (collectionField.contains("|") || dynamicField) {
            // If we're dealing with a lookup from a dynamic field, we need to build the list grid differently
            listGrid = formService.buildMainListGrid(drs, mainMetadata, "/" + owningClass, sectionCrumbs);
            listGrid.setListGridType(ListGrid.Type.TO_ONE);
            listGrid.setSubCollectionFieldName(collectionField);
            listGrid.setPathOverride("/" + owningClass + "/" + collectionField + "/select");
        } else if (md instanceof BasicFieldMetadata) {
            listGrid = formService.buildCollectionListGrid(null, drs, collectionProperty, owningClass, sectionCrumbs);
            listGrid.removeAllRowActions();
        }
        model.addAttribute("listGrid", listGrid);
    }
    model.addAttribute("viewType", "modal/simpleSelectEntity");
    model.addAttribute("currentUrl", request.getRequestURL().toString());
    model.addAttribute("modalHeaderType", ModalHeaderType.SELECT_COLLECTION_ITEM.getType());
    model.addAttribute("collectionProperty", collectionProperty);
    model.addAttribute("sectionCrumbs", request.getParameter("sectionCrumbs"));
    setModelAttributes(model, owningClass);
    return "modules/modalContainer";
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) Property(org.broadleafcommerce.openadmin.dto.Property) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)59 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)35 ArrayList (java.util.ArrayList)11 Product (org.broadleafcommerce.core.catalog.domain.Product)9 Category (org.broadleafcommerce.core.catalog.domain.Category)7 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)7 ServiceException (org.broadleafcommerce.common.exception.ServiceException)6 Sku (org.broadleafcommerce.core.catalog.domain.Sku)6 Entity (org.broadleafcommerce.openadmin.dto.Entity)6 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)6 FieldNotAvailableException (org.broadleafcommerce.openadmin.server.service.persistence.module.FieldNotAvailableException)5 List (java.util.List)4 Query (javax.persistence.Query)4 TypedQuery (javax.persistence.TypedQuery)4 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)4 IndexFieldType (org.broadleafcommerce.core.search.domain.IndexFieldType)4 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)4 PersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 File (java.io.File)3