Search in sources :

Example 11 with SectionCrumb

use of org.broadleafcommerce.openadmin.dto.SectionCrumb 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);
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 12 with SectionCrumb

use of org.broadleafcommerce.openadmin.dto.SectionCrumb 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";
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with SectionCrumb

use of org.broadleafcommerce.openadmin.dto.SectionCrumb 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)

Example 14 with SectionCrumb

use of org.broadleafcommerce.openadmin.dto.SectionCrumb 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;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) Property(org.broadleafcommerce.openadmin.dto.Property) HashMap(java.util.HashMap) Map(java.util.Map) MultiValueMap(org.springframework.util.MultiValueMap) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 15 with SectionCrumb

use of org.broadleafcommerce.openadmin.dto.SectionCrumb 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;
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) ArrayList(java.util.ArrayList) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Aggregations

SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)42 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)32 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)28 Entity (org.broadleafcommerce.openadmin.dto.Entity)19 Property (org.broadleafcommerce.openadmin.dto.Property)19 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)15 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)13 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)12 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)9 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)9 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)8 EntityForm (org.broadleafcommerce.openadmin.web.form.entity.EntityForm)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 PersistenceResponse (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse)6 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)5 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)5 Map (java.util.Map)4 Translation (org.broadleafcommerce.common.i18n.domain.Translation)4