Search in sources :

Example 6 with ClassMetadata

use of org.broadleafcommerce.openadmin.dto.ClassMetadata in project BroadleafCommerce by BroadleafCommerce.

the class AdminEntityServiceImpl method getRecordsForAllSubCollections.

@Override
public Map<String, DynamicResultSet> getRecordsForAllSubCollections(PersistencePackageRequest ppr, Entity containingEntity, Integer startIndex, Integer maxIndex, List<SectionCrumb> sectionCrumb) throws ServiceException {
    Map<String, DynamicResultSet> map = new HashMap<String, DynamicResultSet>();
    PersistenceResponse response = getClassMetadata(ppr);
    ClassMetadata cmd = response.getDynamicResultSet().getClassMetaData();
    for (Property p : cmd.getProperties()) {
        if (ArrayUtils.contains(p.getMetadata().getAvailableToTypes(), containingEntity.getType()[0]) && p.getMetadata() instanceof CollectionMetadata) {
            PersistenceResponse response2 = getRecordsForCollection(cmd, containingEntity, p, null, startIndex, maxIndex, sectionCrumb);
            map.put(p.getName(), response2.getDynamicResultSet());
        }
    }
    return map;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) CollectionMetadata(org.broadleafcommerce.openadmin.dto.CollectionMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata) HashMap(java.util.HashMap) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 7 with ClassMetadata

use of org.broadleafcommerce.openadmin.dto.ClassMetadata in project BroadleafCommerce by BroadleafCommerce.

the class AdminBasicEntityController method viewAddEntityForm.

/**
 * Renders the modal form that is used to add a new parent level entity. Note that this form cannot render any
 * subcollections as operations on those collections require the parent level entity to first be saved and have
 * and id. Once the entity is initially saved, we will redirect the user to the normal manage entity screen where
 * they can then perform operations on sub collections.
 *
 * @param request
 * @param response
 * @param model
 * @param pathVars
 * @param entityType
 * @return the return view path
 * @throws Exception
 */
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String viewAddEntityForm(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @RequestParam(defaultValue = "") String entityType) throws Exception {
    String sectionKey = getSectionKey(pathVars);
    String sectionClassName = getClassNameForSection(sectionKey);
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, null, null);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, sectionCrumbs, pathVars);
    ppr.setAddOperationInspect(true);
    ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    // If the entity type isn't specified, we need to determine if there are various polymorphic types for this entity.
    if (StringUtils.isBlank(entityType)) {
        if (cmd.getPolymorphicEntities().getChildren().length == 0) {
            entityType = cmd.getPolymorphicEntities().getFullyQualifiedClassname();
        } else {
            entityType = getDefaultEntityType();
        }
    } else {
        entityType = URLDecoder.decode(entityType, "UTF-8");
    }
    EntityForm entityForm = formService.createEntityForm(cmd, sectionCrumbs);
    // We need to make sure that the ceiling entity is set to the interface and the specific entity type
    // is set to the type we're going to be creating.
    entityForm.setCeilingEntityClassname(cmd.getCeilingType());
    entityForm.setEntityType(entityType);
    // When we initially build the class metadata (and thus, the entity form), we had all of the possible
    // polymorphic fields built out. Now that we have a concrete entity type to render, we can remove the
    // fields that are not applicable for this given entity type.
    formService.removeNonApplicableFields(cmd, entityForm, entityType);
    modifyAddEntityForm(entityForm, pathVars);
    model.addAttribute("entityForm", entityForm);
    model.addAttribute("viewType", "modal/entityAdd");
    model.addAttribute("entityFriendlyName", cmd.getPolymorphicEntities().getFriendlyName());
    model.addAttribute("currentUrl", request.getRequestURL().toString());
    model.addAttribute("modalHeaderType", ModalHeaderType.ADD_ENTITY.getType());
    setModelAttributes(model, sectionKey);
    return "modules/modalContainer";
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with ClassMetadata

use of org.broadleafcommerce.openadmin.dto.ClassMetadata in project BroadleafCommerce by BroadleafCommerce.

the class AdminBasicEntityController method getCollectionValueDetails.

@RequestMapping(value = "/{collectionField:.*}/details", method = RequestMethod.GET)
@ResponseBody
public Map<String, String> getCollectionValueDetails(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "collectionField") String collectionField, @RequestParam String ids, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
    String sectionKey = getSectionKey(pathVars);
    String sectionClassName = getClassNameForSection(sectionKey);
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, null, null);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, 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.setStartIndex(getStartIndex(requestParams));
    ppr.setMaxIndex(getMaxIndex(requestParams));
    if (md instanceof BasicFieldMetadata) {
        String idProp = ((BasicFieldMetadata) md).getForeignKeyProperty();
        String displayProp = ((BasicFieldMetadata) md).getForeignKeyDisplayValueProperty();
        List<String> filterValues = BLCArrayUtils.asList(ids.split(FILTER_VALUE_SEPARATOR_REGEX));
        ppr.addFilterAndSortCriteria(new FilterAndSortCriteria(idProp, filterValues));
        DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
        Map<String, String> returnMap = new HashMap<>();
        for (Entity e : drs.getRecords()) {
            String id = e.getPMap().get(idProp).getValue();
            String disp = e.getPMap().get(displayProp).getDisplayValue();
            if (StringUtils.isBlank(disp)) {
                disp = e.getPMap().get(displayProp).getValue();
            }
            returnMap.put(id, disp);
        }
        return returnMap;
    }
    return null;
}
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) 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) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 9 with ClassMetadata

use of org.broadleafcommerce.openadmin.dto.ClassMetadata in project BroadleafCommerce by BroadleafCommerce.

the class AdminBasicEntityController method getCollectionFieldRecords.

/**
 * Returns the records for a given collectionField filtered by a particular criteria
 *
 * @param request
 * @param response
 * @param model
 * @param pathVars
 * @param collectionField
 * @param requestParams
 * @return the return view path
 * @throws Exception
 */
@RequestMapping(value = "/{id}/{collectionField:.*}", method = RequestMethod.GET)
public String getCollectionFieldRecords(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);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(mainClassName, requestParams, sectionCrumbs, pathVars);
    ClassMetadata mainMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    Property collectionProperty = mainMetadata.getPMap().get(collectionField);
    ppr = getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars);
    Entity entity = service.getRecord(ppr, id, mainMetadata, false).getDynamicResultSet().getRecords()[0];
    // Next, we must get the new list grid that represents this collection
    ListGrid listGrid = getCollectionListGrid(mainMetadata, entity, collectionProperty, requestParams, sectionKey, sectionCrumbs);
    model.addAttribute("listGrid", listGrid);
    model.addAttribute("currentParams", new ObjectMapper().writeValueAsString(requestParams));
    // We return the new list grid so that it can replace the currently visible one
    setModelAttributes(model, sectionKey);
    return "views/standaloneListGrid";
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) Property(org.broadleafcommerce.openadmin.dto.Property) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with ClassMetadata

use of org.broadleafcommerce.openadmin.dto.ClassMetadata in project BroadleafCommerce by BroadleafCommerce.

the class AdminBasicEntityController method buildDirtyList.

public List<String> buildDirtyList(Map<String, String> pathVars, HttpServletRequest request, String id) throws ServiceException {
    List<String> dirtyList = new ArrayList<>();
    String sectionKey = getSectionKey(pathVars);
    String sectionClassName = getClassNameForSection(sectionKey);
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, sectionKey, id);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, sectionCrumbs, pathVars);
    ClassMetadata cmd = null;
    Entity entity = null;
    cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    entity = service.getRecord(ppr, id, cmd, false).getDynamicResultSet().getRecords()[0];
    for (Property p : entity.getProperties()) {
        if (p.getIsDirty()) {
            dirtyList.add(p.getName());
        }
    }
    return dirtyList;
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) ArrayList(java.util.ArrayList) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) Property(org.broadleafcommerce.openadmin.dto.Property)

Aggregations

ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)52 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)36 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)32 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)26 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)26 Property (org.broadleafcommerce.openadmin.dto.Property)25 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)22 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)21 Entity (org.broadleafcommerce.openadmin.dto.Entity)19 HashMap (java.util.HashMap)16 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)11 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)11 Map (java.util.Map)10 EntityForm (org.broadleafcommerce.openadmin.web.form.entity.EntityForm)10 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)9 ArrayList (java.util.ArrayList)8 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)8 PersistenceResponse (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse)8 MergedPropertyType (org.broadleafcommerce.openadmin.dto.MergedPropertyType)7 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)7