Search in sources :

Example 41 with Property

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

the class AdminEntityServiceImpl method addSubCollectionEntity.

@Override
public PersistenceResponse addSubCollectionEntity(EntityForm entityForm, ClassMetadata mainMetadata, Property field, Entity parentEntity, List<SectionCrumb> sectionCrumbs) throws ServiceException, ClassNotFoundException {
    // Assemble the properties from the entity form
    List<Property> properties = getPropertiesFromEntityForm(entityForm);
    FieldMetadata md = field.getMetadata();
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs).withEntity(new Entity());
    ppr.getEntity().setIsPreAdd(parentEntity.isPreAdd());
    if (md instanceof BasicCollectionMetadata) {
        BasicCollectionMetadata fmd = (BasicCollectionMetadata) md;
        ppr.getEntity().setType(new String[] { entityForm.getEntityType() });
        // that we're not changing the target entity at all and only creating the association to the id
        if (fmd.getAddMethodType().equals(AddMethodType.LOOKUP) || fmd.getAddMethodType().equals(AddMethodType.LOOKUP_FOR_UPDATE)) {
            List<String> fieldsToRemove = new ArrayList<String>();
            String idProp = getIdProperty(mainMetadata);
            for (String key : entityForm.getFields().keySet()) {
                if (!idProp.equals(key)) {
                    fieldsToRemove.add(key);
                }
            }
            for (String key : fieldsToRemove) {
                ListIterator<Property> li = properties.listIterator();
                while (li.hasNext()) {
                    if (li.next().getName().equals(key)) {
                        li.remove();
                    }
                }
            }
            ppr.setValidateUnsubmittedProperties(false);
        }
        if (fmd.getAddMethodType().equals(AddMethodType.LOOKUP_FOR_UPDATE)) {
            ppr.setUpdateLookupType(true);
        }
        Property fp = new Property();
        fp.setName(ppr.getForeignKey().getManyToField());
        fp.setValue(getContextSpecificRelationshipId(mainMetadata, parentEntity, field.getName()));
        properties.add(fp);
    } else if (md instanceof AdornedTargetCollectionMetadata) {
        ppr.getEntity().setType(new String[] { ppr.getAdornedList().getAdornedTargetEntityClassname() });
        String[] maintainedFields = ((AdornedTargetCollectionMetadata) md).getMaintainedAdornedTargetFields();
        if (maintainedFields == null || maintainedFields.length == 0) {
            ppr.setValidateUnsubmittedProperties(false);
        }
    } else if (md instanceof MapMetadata) {
        ppr.getEntity().setType(new String[] { entityForm.getEntityType() });
        Property p = new Property();
        p.setName("symbolicId");
        p.setValue(getContextSpecificRelationshipId(mainMetadata, parentEntity, field.getName()));
        properties.add(p);
    } else {
        throw new IllegalArgumentException(String.format("The specified field [%s] for class [%s] was" + " not a collection field.", field.getName(), mainMetadata.getCeilingType()));
    }
    ppr.setCeilingEntityClassname(ppr.getEntity().getType()[0]);
    String sectionField = field.getName();
    if (sectionField.contains(".")) {
        sectionField = sectionField.substring(0, sectionField.lastIndexOf("."));
    }
    ppr.setSectionEntityField(sectionField);
    Property parentNameProp = parentEntity.getPMap().get(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY);
    if (parentNameProp != null) {
        ppr.setRequestingEntityName(parentNameProp.getValue());
    }
    Property[] propArr = new Property[properties.size()];
    properties.toArray(propArr);
    ppr.getEntity().setProperties(propArr);
    return add(ppr);
}
Also used : AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) ArrayList(java.util.ArrayList) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) Property(org.broadleafcommerce.openadmin.dto.Property) MapMetadata(org.broadleafcommerce.openadmin.dto.MapMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)

Example 42 with Property

use of org.broadleafcommerce.openadmin.dto.Property 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 43 with Property

use of org.broadleafcommerce.openadmin.dto.Property 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 44 with Property

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

Example 45 with Property

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

the class AdminBasicEntityController method updateCollectionItem.

/**
 * Updates the specified collection item
 *
 * @param request
 * @param response
 * @param model
 * @param pathVars
 * @param id
 * @param collectionField
 * @param collectionItemId the collection primary key value (in the case of adorned target collection, this is the primary key value of the target entity)
 * @param entityForm
 * @param alternateId in the case of adorned target collections, this is the primary key value of the collection member
 * @param result
 * @return the return view path
 * @throws Exception
 */
@RequestMapping(value = "/{id}/{collectionField:.*}/{collectionItemId}/{alternateId}", method = RequestMethod.POST)
public String updateCollectionItem(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @PathVariable(value = "collectionField") String collectionField, @PathVariable(value = "collectionItemId") String collectionItemId, @ModelAttribute(value = "entityForm") EntityForm entityForm, @PathVariable(value = "alternateId") String alternateId, BindingResult result) 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);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars);
    Entity entity = service.getRecord(ppr, id, mainMetadata, false).getDynamicResultSet().getRecords()[0];
    // First, we must save the collection entity
    PersistenceResponse persistenceResponse = service.updateSubCollectionEntity(entityForm, mainMetadata, collectionProperty, entity, collectionItemId, alternateId, sectionCrumbs);
    Entity savedEntity = persistenceResponse.getEntity();
    entityFormValidator.validate(entityForm, savedEntity, result);
    if (result.hasErrors()) {
        return showViewUpdateCollection(request, model, pathVars, id, collectionField, collectionItemId, alternateId, ModalHeaderType.UPDATE_COLLECTION_ITEM.getType(), entityForm, savedEntity);
    }
    // Next, we must get the new list grid that represents this collection
    // We return the new list grid so that it can replace the currently visible one
    ListGrid listGrid = getCollectionListGrid(mainMetadata, entity, collectionProperty, null, sectionKey, persistenceResponse, sectionCrumbs);
    model.addAttribute("listGrid", listGrid);
    model.addAttribute("currentUrl", request.getRequestURL().toString());
    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) PersistenceResponse(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse) Property(org.broadleafcommerce.openadmin.dto.Property) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Property (org.broadleafcommerce.openadmin.dto.Property)120 Entity (org.broadleafcommerce.openadmin.dto.Entity)62 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)45 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)38 ArrayList (java.util.ArrayList)28 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)26 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)25 DataWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper)21 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)19 HashMap (java.util.HashMap)18 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)18 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)16 Map (java.util.Map)15 ServiceException (org.broadleafcommerce.common.exception.ServiceException)15 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)15 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)13 RuleBuilderField (org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField)12 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)12