Search in sources :

Example 6 with PersistencePackageRequest

use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.

the class AdminEntityServiceImpl method updateEntity.

@Override
public PersistenceResponse updateEntity(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumb) throws ServiceException {
    PersistencePackageRequest ppr = getRequestForEntityForm(entityForm, customCriteria, sectionCrumb);
    ppr.setRequestingEntityName(entityForm.getMainEntityName());
    // based on the criteria specific in the PersistencePackage.
    for (Entry<String, EntityForm> entry : entityForm.getDynamicForms().entrySet()) {
        DynamicEntityFormInfo info = entityForm.getDynamicFormInfo(entry.getKey());
        if (info.getCustomCriteriaOverride() != null) {
            customCriteria = info.getCustomCriteriaOverride();
        } else {
            String propertyName = info.getPropertyName();
            String propertyValue = entityForm.findField(propertyName).getValue();
            customCriteria = new String[] { info.getCriteriaName(), entityForm.getId(), propertyName, propertyValue };
        }
        PersistencePackageRequest subRequest = getRequestForEntityForm(entry.getValue(), customCriteria, sectionCrumb);
        subRequest.withSecurityCeilingEntityClassname(info.getSecurityCeilingClassName());
        ppr.addSubRequest(info.getPropertyName(), subRequest);
    }
    return update(ppr);
}
Also used : EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) DynamicEntityFormInfo(org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo)

Example 7 with PersistencePackageRequest

use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.

the class AdminEntityServiceImpl method removeSubCollectionEntity.

@Override
public PersistenceResponse removeSubCollectionEntity(ClassMetadata mainMetadata, Property field, Entity parentEntity, String itemId, String alternateId, String priorKey, List<SectionCrumb> sectionCrumbs) throws ServiceException {
    List<Property> properties = new ArrayList<Property>();
    Property p;
    String parentId = getContextSpecificRelationshipId(mainMetadata, parentEntity, field.getName());
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(field.getMetadata(), sectionCrumbs).withEntity(new Entity());
    if (field.getMetadata() instanceof BasicCollectionMetadata) {
        BasicCollectionMetadata fmd = (BasicCollectionMetadata) field.getMetadata();
        p = new Property();
        p.setName("id");
        p.setValue(itemId);
        properties.add(p);
        p = new Property();
        p.setName(ppr.getForeignKey().getManyToField());
        p.setValue(parentId);
        properties.add(p);
        ppr.getEntity().setType(new String[] { fmd.getCollectionCeilingEntity() });
    } else if (field.getMetadata() instanceof AdornedTargetCollectionMetadata) {
        AdornedTargetList adornedList = ppr.getAdornedList();
        p = new Property();
        p.setName(adornedList.getLinkedObjectPath() + "." + adornedList.getLinkedIdProperty());
        p.setValue(parentId);
        properties.add(p);
        p = new Property();
        p.setName(adornedList.getTargetObjectPath() + "." + adornedList.getTargetIdProperty());
        p.setValue(itemId);
        properties.add(p);
        if (!StringUtils.isEmpty(alternateId)) {
            p = new Property();
            p.setName(BasicPersistenceModule.ALTERNATE_ID_PROPERTY);
            p.setValue(alternateId);
            properties.add(p);
        }
        ppr.getEntity().setType(new String[] { adornedList.getAdornedTargetEntityClassname() });
    } else if (field.getMetadata() instanceof MapMetadata) {
        MapMetadata fmd = (MapMetadata) field.getMetadata();
        p = new Property();
        p.setName("id");
        p.setValue(itemId);
        properties.add(p);
        p = new Property();
        p.setName("symbolicId");
        p.setValue(getContextSpecificRelationshipId(mainMetadata, parentEntity, field.getName()));
        properties.add(p);
        p = new Property();
        p.setName("priorKey");
        p.setValue(priorKey);
        properties.add(p);
        MapStructure mapStructure = ppr.getMapStructure();
        p = new Property();
        p.setName(mapStructure.getKeyPropertyName());
        p.setValue(itemId);
        properties.add(p);
        ppr.getEntity().setType(new String[] { fmd.getTargetClass() });
    }
    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 remove(ppr);
}
Also used : MapStructure(org.broadleafcommerce.openadmin.dto.MapStructure) AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) 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) AdornedTargetList(org.broadleafcommerce.openadmin.dto.AdornedTargetList) MapMetadata(org.broadleafcommerce.openadmin.dto.MapMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)

Example 8 with PersistencePackageRequest

use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest 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 9 with PersistencePackageRequest

use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest 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 10 with PersistencePackageRequest

use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest 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)

Aggregations

PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)48 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)36 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)29 Property (org.broadleafcommerce.openadmin.dto.Property)26 Entity (org.broadleafcommerce.openadmin.dto.Entity)24 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)20 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)19 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)16 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)13 EntityForm (org.broadleafcommerce.openadmin.web.form.entity.EntityForm)12 ArrayList (java.util.ArrayList)10 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)10 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)10 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)9 MapMetadata (org.broadleafcommerce.openadmin.dto.MapMetadata)8 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)7 PersistenceResponse (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse)7 HashMap (java.util.HashMap)6