Search in sources :

Example 21 with ClassMetadata

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

the class AdminTranslationController method showAddTranslation.

/**
 * Renders a modal dialog that has a list grid of translations for the specified field
 *
 * @param request
 * @param response
 * @param model
 * @param form
 * @param result
 * @return the return view path
 * @throws Exception
 */
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String showAddTranslation(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @ModelAttribute(value = "form") TranslationForm form, BindingResult result) throws Exception {
    String sectionKey = getSectionKey(pathVars);
    String sectionClassName = getClassNameForSection(sectionKey);
    List<SectionCrumb> sectionCrumbs = new ArrayList<>();
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, sectionCrumbs, pathVars);
    ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    adminRemoteSecurityService.securityCheck(form.getCeilingEntity(), EntityOperationType.FETCH);
    EntityForm entityForm = formService.buildTranslationForm(cmd, form, TranslationFormAction.ADD);
    model.addAttribute("entityForm", entityForm);
    model.addAttribute("viewType", "modal/translationAdd");
    model.addAttribute("currentUrl", request.getRequestURL().toString());
    model.addAttribute("modalHeaderType", ModalHeaderType.ADD_TRANSLATION.getType());
    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) ArrayList(java.util.ArrayList) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with ClassMetadata

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

the class AdminTranslationController method deleteTranslation.

/**
 * Deletes the translation specified by the translation id
 *
 * @param request
 * @param response
 * @param model
 * @param id
 * @param form
 * @param result
 * @return the result of a call to {@link #viewTranslation}, which renders the list grid
 * @throws Exception
 */
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public String deleteTranslation(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @ModelAttribute(value = "form") final TranslationForm form, BindingResult result) throws Exception {
    adminRemoteSecurityService.securityCheck(form.getCeilingEntity(), EntityOperationType.UPDATE);
    SectionCrumb sectionCrumb = new SectionCrumb();
    sectionCrumb.setSectionIdentifier(TranslationImpl.class.getName());
    sectionCrumb.setSectionId(String.valueOf(form.getTranslationId()));
    List<SectionCrumb> sectionCrumbs = Arrays.asList(sectionCrumb);
    String sectionKey = getSectionKey(pathVars);
    String sectionClassName = getClassNameForSection(sectionKey);
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, sectionCrumbs, pathVars);
    ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    EntityForm entityForm = formService.buildTranslationForm(cmd, form, TranslationFormAction.OTHER);
    entityForm.setCeilingEntityClassname(Translation.class.getName());
    entityForm.setEntityType(TranslationImpl.class.getName());
    Field id = new Field();
    id.setName("id");
    id.setValue(String.valueOf(form.getTranslationId()));
    entityForm.getFields().put("id", id);
    entityForm.setId(String.valueOf(form.getTranslationId()));
    String[] sectionCriteria = customCriteriaService.mergeSectionCustomCriteria(Translation.class.getName(), getSectionCustomCriteria());
    service.removeEntity(entityForm, sectionCriteria, sectionCrumbs);
    return viewTranslation(request, response, model, form, result);
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) Translation(org.broadleafcommerce.common.i18n.domain.Translation) TranslationImpl(org.broadleafcommerce.common.i18n.domain.TranslationImpl) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with ClassMetadata

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

the class AdminTranslationController method showUpdateTranslation.

@RequestMapping(value = "/update", method = RequestMethod.GET)
public String showUpdateTranslation(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @ModelAttribute(value = "form") TranslationForm form, BindingResult result) throws Exception {
    String sectionKey = getSectionKey(pathVars);
    String sectionClassName = getClassNameForSection(sectionKey);
    List<SectionCrumb> sectionCrumbs = new ArrayList<>();
    PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, sectionCrumbs, pathVars);
    ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    adminRemoteSecurityService.securityCheck(form.getCeilingEntity(), EntityOperationType.FETCH);
    Translation t = translationService.findTranslationById(form.getTranslationId());
    form.setTranslatedValue(t.getTranslatedValue());
    EntityForm entityForm = formService.buildTranslationForm(cmd, form, TranslationFormAction.UPDATE);
    entityForm.setId(String.valueOf(form.getTranslationId()));
    model.addAttribute("entityForm", entityForm);
    model.addAttribute("viewType", "modal/translationAdd");
    model.addAttribute("currentUrl", request.getRequestURL().toString());
    model.addAttribute("modalHeaderType", ModalHeaderType.UPDATE_TRANSLATION.getType());
    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) Translation(org.broadleafcommerce.common.i18n.domain.Translation) ArrayList(java.util.ArrayList) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with ClassMetadata

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

the class FormBuilderServiceImpl method populateDropdownToOneFields.

protected void populateDropdownToOneFields(EntityForm ef, ClassMetadata cmd) throws ServiceException {
    for (Property p : cmd.getProperties()) {
        if (p.getMetadata() instanceof BasicFieldMetadata) {
            BasicFieldMetadata fmd = (BasicFieldMetadata) p.getMetadata();
            if (LookupType.DROPDOWN.equals(fmd.getLookupType()) && !ArrayUtils.contains(getFormHiddenVisibilities(), fmd.getVisibility())) {
                // Get the records
                PersistencePackageRequest toOnePpr = PersistencePackageRequest.standard().withCeilingEntityClassname(fmd.getForeignKeyClass());
                Entity[] rows = adminEntityService.getRecords(toOnePpr).getDynamicResultSet().getRecords();
                // Determine the id field
                String idProp = null;
                ClassMetadata foreignClassMd = adminEntityService.getClassMetadata(toOnePpr).getDynamicResultSet().getClassMetaData();
                for (Property foreignP : foreignClassMd.getProperties()) {
                    if (foreignP.getMetadata() instanceof BasicFieldMetadata) {
                        BasicFieldMetadata foreignFmd = (BasicFieldMetadata) foreignP.getMetadata();
                        if (SupportedFieldType.ID.equals(foreignFmd.getFieldType())) {
                            idProp = foreignP.getName();
                        }
                    }
                }
                if (idProp == null) {
                    throw new RuntimeException("Could not determine ID property for " + fmd.getForeignKeyClass());
                }
                // Determine the display field
                String displayProp = fmd.getLookupDisplayProperty();
                // Build the options map
                Map<String, String> options = new HashMap<>();
                for (Entity row : rows) {
                    Property prop = row.findProperty(displayProp);
                    if (prop == null) {
                        LOG.warn("Could not find displayProp [" + StringUtil.sanitize(displayProp) + "] on entity [" + ef.getCeilingEntityClassname() + "]");
                    } else {
                        String displayValue = prop.getDisplayValue();
                        if (StringUtils.isBlank(displayValue)) {
                            displayValue = prop.getValue();
                        }
                        options.put(row.findProperty(idProp).getValue(), displayValue);
                    }
                }
                // Set the options on the entity field
                ComboField cf = (ComboField) ef.findField(p.getName());
                cf.setOptions(options);
            }
        }
    }
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) ComboField(org.broadleafcommerce.openadmin.web.form.entity.ComboField) HashMap(java.util.HashMap) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 25 with ClassMetadata

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

the class FormBuilderServiceImpl method buildSelectizeCollectionInfo.

@Override
public Map<String, Object> buildSelectizeCollectionInfo(String containingEntityId, DynamicResultSet drs, Property field, String sectionKey, List<SectionCrumb> sectionCrumbs) throws ServiceException {
    FieldMetadata fmd = field.getMetadata();
    // Get the class metadata for this particular field
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(fmd, sectionCrumbs);
    if (field != null) {
        ppr.setSectionEntityField(field.getName());
    }
    ClassMetadata cmd = adminEntityService.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    Map<String, Object> result = constructSelectizeOptionMap(drs, cmd);
    AdornedTargetList adornedList = ppr.getAdornedList();
    if (adornedList != null && adornedList.getLinkedObjectPath() != null && adornedList.getTargetObjectPath() != null && adornedList.getLinkedIdProperty() != null && adornedList.getTargetIdProperty() != null) {
        result.put("linkedObjectPath", adornedList.getLinkedObjectPath() + "." + adornedList.getLinkedIdProperty());
        result.put("linkedObjectId", containingEntityId);
        result.put("targetObjectPath", adornedList.getTargetObjectPath() + "." + adornedList.getTargetIdProperty());
    }
    return result;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) JSONObject(org.codehaus.jettison.json.JSONObject) AdornedTargetList(org.broadleafcommerce.openadmin.dto.AdornedTargetList)

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