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