use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.
the class AdminBasicEntityController method viewEntityListSelectize.
@RequestMapping(value = "/selectize", method = RequestMethod.GET)
@ResponseBody
public Map<String, Object> viewEntityListSelectize(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
String sectionKey = getSectionKey(pathVars);
String sectionClassName = getClassNameForSection(sectionKey);
List<SectionCrumb> crumbs = getSectionCrumbs(request, null, null);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, requestParams, crumbs, pathVars).withCustomCriteria(getCustomCriteria(requestParams));
ppr.addCustomCriteria(buildSelectizeCustomCriteria());
ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
return formService.constructSelectizeOptionMap(drs, cmd);
}
use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.
the class AdminBasicEntityController method viewEntityList.
// ******************************************
// REQUEST-MAPPING BOUND CONTROLLER METHODS *
// ******************************************
/**
* Renders the main entity listing for the specified class, which is based on the current sectionKey with some optional
* criteria.
*
* @param request
* @param response
* @param model
* @param pathVars
* @param requestParams a Map of property name -> list critiera values
* @return the return view path
* @throws Exception
*/
@RequestMapping(value = "", method = RequestMethod.GET)
public String viewEntityList(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
String sectionKey = getSectionKey(pathVars);
String sectionClassName = getClassNameForSection(sectionKey);
List<SectionCrumb> crumbs = getSectionCrumbs(request, null, null);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, requestParams, crumbs, pathVars);
ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
ListGrid listGrid = formService.buildMainListGrid(drs, cmd, sectionKey, crumbs);
listGrid.setSelectType(ListGrid.SelectType.NONE);
Set<Field> headerFields = listGrid.getHeaderFields();
if (CollectionUtils.isNotEmpty(headerFields)) {
Field firstField = headerFields.iterator().next();
if (requestParams.containsKey(firstField.getName())) {
model.addAttribute("mainSearchTerm", requestParams.get(firstField.getName()).get(0));
}
}
model.addAttribute("viewType", "entityList");
setupViewEntityListBasicModel(request, cmd, sectionKey, sectionClassName, model, requestParams);
model.addAttribute("listGrid", listGrid);
return "modules/defaultContainer";
}
use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest 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";
}
use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.
the class AdminBasicOperationsController method getTypeaheadResults.
@RequestMapping(value = "/{owningClass:.*}/{collectionField:.*}/typeahead", method = RequestMethod.GET)
@ResponseBody
public List<Map<String, String>> getTypeaheadResults(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 query, @RequestParam(required = false) String requestingEntityId, @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);
ClassMetadata mainMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
Property collectionProperty = mainMetadata.getPMap().get(collectionField);
FieldMetadata md = collectionProperty.getMetadata();
ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs);
ppr.addFilterAndSortCriteria(getCriteria(requestParams));
ppr.setStartIndex(getStartIndex(requestParams));
ppr.setMaxIndex(getMaxIndex(requestParams));
ppr.removeFilterAndSortCriteria("query");
ppr.removeFilterAndSortCriteria("requestingEntityId");
ppr.addCustomCriteria("requestingEntityId=" + requestingEntityId);
// This list of datums will populate the typeahead suggestions.
List<Map<String, String>> responses = new ArrayList<Map<String, String>>();
if (md instanceof BasicFieldMetadata) {
String searchField = searchFieldResolver.resolveField(((BasicFieldMetadata) md).getForeignKeyClass());
ppr.addFilterAndSortCriteria(new FilterAndSortCriteria(searchField, query));
DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
ClassMetadata lookupMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
for (Entity e : drs.getRecords()) {
Map<String, String> responseMap = new HashMap<String, String>();
String idProperty = service.getIdProperty(lookupMetadata);
responseMap.put("id", e.findProperty(idProperty).getValue());
String displayKey = e.findProperty(searchField).getDisplayValue();
if (StringUtils.isBlank(displayKey)) {
displayKey = e.findProperty(searchField).getValue();
}
responseMap.put("displayKey", displayKey);
responses.add(responseMap);
}
}
return responses;
}
use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.
the class AdminAbstractController method getEntityForm.
// *********************************************************
// UNBOUND CONTROLLER METHODS (USED BY DIFFERENT SECTIONS) *
// *********************************************************
/**
* Convenience method for obtaining a fully built EntityForm for the given sectionKey, sectionClassName, and id.
*
* @param sectionKey
* @param sectionClassName
* @param id
* @return a fully composed EntityForm
* @throws ServiceException
*/
protected EntityForm getEntityForm(String sectionKey, String sectionClassName, String id) throws ServiceException {
SectionCrumb sc = new SectionCrumb();
sc.setSectionId(id);
sc.setSectionIdentifier("structured-content/all");
List<SectionCrumb> crumbs = new ArrayList<>(1);
crumbs.add(sc);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, crumbs, null);
ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
Entity entity = service.getRecord(ppr, id, cmd, false).getDynamicResultSet().getRecords()[0];
Map<String, DynamicResultSet> subRecordsMap = service.getRecordsForAllSubCollections(ppr, entity, crumbs);
EntityForm entityForm = formService.createEntityForm(cmd, entity, subRecordsMap, crumbs);
return entityForm;
}
Aggregations