use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.
the class AdminProductController method viewEntityListSelectize.
@Override
@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).withStartIndex(getStartIndex(requestParams)).withMaxIndex(getMaxIndex(requestParams)).withCustomCriteria(getCustomCriteria(requestParams));
FilterAndSortCriteria[] fascs = getCriteria(requestParams);
for (FilterAndSortCriteria fasc : fascs) {
if (SELECTIZE_NAME_PROPERTY.equals(fasc.getPropertyId())) {
fasc.setPropertyId(DEFAULT_SKU_NAME);
break;
}
}
ppr.withFilterAndSortCriteria(fascs);
ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
return constructSelectizeOptionMap(drs, cmd);
}
use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.
the class AdminBasicEntityController method buildAddCollectionItemModel.
/**
* Builds out all of the model information needed for showing the add modal for collection items on both the initial GET
* as well as after a POST with validation errors
*
* @param request
* @param model
* @param id
* @param collectionField
* @param sectionKey
* @param collectionProperty
* @param md
* @param ppr
* @return the appropriate view to display for the modal
* @see {@link #addCollectionItem(HttpServletRequest, HttpServletResponse, Model, Map, String, String, EntityForm, BindingResult)}
* @see {@link #showAddCollectionItem(HttpServletRequest, HttpServletResponse, Model, Map, String, String, MultiValueMap)}
* @throws ServiceException
*/
protected String buildAddCollectionItemModel(HttpServletRequest request, HttpServletResponse response, Model model, String id, String collectionField, String sectionKey, Property collectionProperty, FieldMetadata md, PersistencePackageRequest ppr, EntityForm entityForm, Entity entity) throws ServiceException {
// For requests to add a new collection item include the main class that the subsequent request comes from.
// For instance, with basic collections we know the main associated class for a fetch through the ForeignKey
// persistence item but map and adorned target lookups make a standard persistence request. This solution
// fixes all cases.
String mainClassName = getClassNameForSection(sectionKey);
ppr.addCustomCriteria("owningClass=" + mainClassName);
ppr.setAddOperationInspect(true);
if (entityForm != null) {
entityForm.clearFieldsMap();
}
List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, sectionKey, id);
if (md instanceof BasicCollectionMetadata) {
BasicCollectionMetadata fmd = (BasicCollectionMetadata) md;
// and sometimes show a list grid to allow the user to associate an existing record.
if (fmd.getAddMethodType().equals(AddMethodType.PERSIST)) {
ClassMetadata collectionMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
if (entityForm == null) {
entityForm = formService.createEntityForm(collectionMetadata, sectionCrumbs);
entityForm.setCeilingEntityClassname(ppr.getCeilingEntityClassname());
entityForm.setEntityType(ppr.getCeilingEntityClassname());
} else {
formService.populateEntityForm(collectionMetadata, entityForm, sectionCrumbs);
formService.populateEntityFormFieldValues(collectionMetadata, entity, entityForm);
}
formService.removeNonApplicableFields(collectionMetadata, entityForm, ppr.getCeilingEntityClassname());
entityForm.getTabs().iterator().next().getIsVisible();
model.addAttribute("entityForm", entityForm);
model.addAttribute("viewType", "modal/simpleAddEntity");
} else {
DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
ListGrid listGrid = formService.buildCollectionListGrid(id, drs, collectionProperty, sectionKey, sectionCrumbs);
listGrid.setPathOverride(request.getRequestURL().toString());
if (AddMethodType.LOOKUP.equals(fmd.getAddMethodType()) || AddMethodType.SELECTIZE_LOOKUP.equals(fmd.getAddMethodType())) {
listGrid.removeAllRowActions();
}
model.addAttribute("listGrid", listGrid);
model.addAttribute("viewType", "modal/simpleSelectEntity");
}
} else if (md instanceof AdornedTargetCollectionMetadata) {
AdornedTargetCollectionMetadata fmd = (AdornedTargetCollectionMetadata) md;
// Even though this field represents an adorned target collection, the list we want to show in the modal
// is the standard list grid for the target entity of this field
ppr.setOperationTypesOverride(null);
ppr.setType(PersistencePackageRequest.Type.STANDARD);
ppr.setSectionEntityField(collectionField);
ClassMetadata collectionMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
ListGrid listGrid = formService.buildCollectionListGrid(id, drs, collectionProperty, sectionKey, sectionCrumbs);
listGrid.setSubCollectionFieldName(collectionField);
listGrid.setPathOverride(request.getRequestURL().toString());
listGrid.setFriendlyName(collectionMetadata.getPolymorphicEntities().getFriendlyName());
if (entityForm == null) {
entityForm = formService.buildAdornedListForm(fmd, ppr.getAdornedList(), id, false, sectionCrumbs, true);
entityForm.setCeilingEntityClassname(ppr.getAdornedList().getAdornedTargetEntityClassname());
} else {
formService.buildAdornedListForm(fmd, ppr.getAdornedList(), id, false, entityForm, sectionCrumbs, true);
formService.populateEntityFormFieldValues(collectionMetadata, entity, entityForm);
}
listGrid.setListGridType(ListGrid.Type.ADORNED);
for (Entry<String, Field> entry : entityForm.getFields().entrySet()) {
if (entry.getValue().getIsVisible()) {
listGrid.setListGridType(ListGrid.Type.ADORNED_WITH_FORM);
break;
}
}
// This is part of an add, so we want to be able to filter/sort the listgrid
listGrid.setIsSortable(false);
listGrid.setCanFilterAndSort(true);
listGrid.removeAllRowActions();
model.addAttribute("listGrid", listGrid);
model.addAttribute("entityForm", entityForm);
model.addAttribute("viewType", "modal/adornedSelectEntity");
} else if (md instanceof MapMetadata) {
MapMetadata fmd = (MapMetadata) md;
ClassMetadata collectionMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
if (entityForm == null) {
entityForm = formService.buildMapForm(fmd, ppr.getMapStructure(), collectionMetadata, id);
} else {
formService.buildMapForm(fmd, ppr.getMapStructure(), collectionMetadata, id, entityForm);
formService.populateEntityFormFieldValues(collectionMetadata, entity, entityForm);
}
model.addAttribute("entityForm", entityForm);
model.addAttribute("viewType", "modal/mapAddEntity");
}
// Set the parent id on the entity form
if (entityForm != null) {
entityForm.setParentId(id);
}
model.addAttribute("currentUrl", request.getRequestURL().toString());
model.addAttribute("modalHeaderType", ModalHeaderType.ADD_COLLECTION_ITEM.getType());
model.addAttribute("collectionProperty", collectionProperty);
setModelAttributes(model, sectionKey);
return "modules/modalContainer";
}
use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.
the class PageTemplateCustomPersistenceHandler method fetch.
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
String pageId = persistencePackage.getCustomCriteria()[1];
Entity entity = fetchEntityBasedOnId(pageId, null);
DynamicResultSet results = new DynamicResultSet(new Entity[] { entity }, 1);
populateFKLookupValues(dynamicEntityDao, entity);
return results;
} catch (Exception e) {
throw new ServiceException("Unable to perform fetch for entity: " + ceilingEntityFullyQualifiedClassname, e);
}
}
use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.
the class StructuredContentTypeCustomPersistenceHandler method inspect.
@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
String structuredContentTypeId = persistencePackage.getCustomCriteria()[3];
StructuredContentType structuredContentType = structuredContentService.findStructuredContentTypeById(Long.valueOf(structuredContentTypeId));
ClassMetadata metadata = new ClassMetadata();
metadata.setCeilingType(StructuredContentType.class.getName());
ClassTree entities = new ClassTree(StructuredContentTypeImpl.class.getName());
metadata.setPolymorphicEntities(entities);
Property[] properties = dynamicFieldUtil.buildDynamicPropertyList(structuredContentType.getStructuredContentFieldTemplate().getFieldGroups(), StructuredContentTypeImpl.class);
metadata.setProperties(properties);
DynamicResultSet results = new DynamicResultSet(metadata);
return results;
} catch (Exception e) {
throw new ServiceException("Unable to perform inspect for entity: " + ceilingEntityFullyQualifiedClassname, e);
}
}
use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.
the class AdminBasicEntityController method getSelectizeCollectionOptions.
/**
* @param request
* @param response
* @param model
* @param pathVars
* @param id
* @param collectionField
* @param requestParams
* @return Json collection data
* @throws Exception
*/
@RequestMapping(value = "/{id}/{collectionField:.*}/selectize", method = RequestMethod.GET)
@ResponseBody
public Map<String, Object> getSelectizeCollectionOptions(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @PathVariable(value = "collectionField") String collectionField, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
String sectionKey = getSectionKey(pathVars);
String mainClassName = getClassNameForSection(sectionKey);
List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, sectionKey, id);
ClassMetadata mainMetadata = service.getClassMetadata(getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars)).getDynamicResultSet().getClassMetaData();
Property collectionProperty = mainMetadata.getPMap().get(collectionField);
FieldMetadata md = collectionProperty.getMetadata();
PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs).withFilterAndSortCriteria(getCriteria(requestParams)).withStartIndex(getStartIndex(requestParams)).withMaxIndex(getMaxIndex(requestParams)).withCustomCriteria(buildSelectizeCustomCriteria());
if (md instanceof AdornedTargetCollectionMetadata) {
ppr.setOperationTypesOverride(null);
ppr.setType(PersistencePackageRequest.Type.STANDARD);
ppr.setSectionEntityField(collectionField);
}
DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
return formService.buildSelectizeCollectionInfo(id, drs, collectionProperty, sectionKey, sectionCrumbs);
}
Aggregations