Search in sources :

Example 11 with EntityForm

use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm 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)

Example 12 with EntityForm

use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm in project BroadleafCommerce by BroadleafCommerce.

the class AdminAbstractController method getEntityForm.

protected EntityForm getEntityForm(DynamicEntityFormInfo info, EntityForm dynamicFormOverride) throws ServiceException {
    // We need to inspect with the second custom criteria set to the id of
    // the desired structured content type
    PersistencePackageRequest ppr = PersistencePackageRequest.standard().withCeilingEntityClassname(info.getCeilingClassName()).withSecurityCeilingEntityClassname(info.getSecurityCeilingClassName()).withCustomCriteria(new String[] { info.getCriteriaName(), null, info.getPropertyName(), info.getPropertyValue() });
    ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    EntityForm dynamicForm = formService.createEntityForm(cmd, null);
    dynamicForm.clearFieldsMap();
    if (dynamicFormOverride != null) {
        dynamicFormOverride.clearFieldsMap();
        Map<String, Field> fieldOverrides = dynamicFormOverride.getFields();
        for (Entry<String, Field> override : fieldOverrides.entrySet()) {
            if (dynamicForm.getFields().containsKey(override.getKey())) {
                dynamicForm.findField(override.getKey()).setValue(override.getValue().getValue());
            }
        }
    }
    return dynamicForm;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)

Example 13 with EntityForm

use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm in project BroadleafCommerce by BroadleafCommerce.

the class AdminAbstractController method getDynamicFieldTemplateForm.

/**
 * Convenience method for obtaining a dynamic field template form for a particular entity. This method differs from
 * {@link #getBlankDynamicFieldTemplateForm(DynamicEntityFormInfo)} in that it will fill out the current values for
 * the fields in this dynamic form from the database. This method is invoked when the initial view of a page containing
 * a dynamic form is triggered.
 *
 * Optionally, you can pass in a pre-existing dynamic form to this method that already has updated values. Example usage
 * would be for after validation has failed and you do not want to lookup old values from the database again.
 *
 * @param info
 * @param entityId
 * @param dynamicFormOverride optional dynamic form that already has values to fill out
 * @return the entity form
 * @throws ServiceException
 */
protected EntityForm getDynamicFieldTemplateForm(DynamicEntityFormInfo info, String entityId, EntityForm dynamicFormOverride) throws ServiceException {
    // We need to inspect with the second custom criteria set to the id of
    // the desired structured content type
    PersistencePackageRequest ppr = PersistencePackageRequest.standard().withCeilingEntityClassname(info.getCeilingClassName()).withSecurityCeilingEntityClassname(info.getSecurityCeilingClassName()).withCustomCriteria(new String[] { info.getCriteriaName(), entityId, info.getPropertyName(), info.getPropertyValue() });
    ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    // However, when we fetch, the second custom criteria needs to be the id
    // of this particular structured content entity
    ppr.setCustomCriteria(new String[] { info.getCriteriaName(), entityId });
    Entity entity = service.getRecord(ppr, info.getPropertyValue(), cmd, true).getDynamicResultSet().getRecords()[0];
    List<Field> fieldsToMove = new ArrayList<>();
    // override the results of the entity with the dynamic form passed in
    if (dynamicFormOverride != null) {
        dynamicFormOverride.clearFieldsMap();
        Map<String, Field> fieldOverrides = dynamicFormOverride.getFields();
        for (Entry<String, Field> override : fieldOverrides.entrySet()) {
            if (entity.getPMap().containsKey(override.getKey())) {
                entity.getPMap().get(override.getKey()).setValue(override.getValue().getValue());
            } else {
                fieldsToMove.add(override.getValue());
            }
        }
    }
    // Assemble the dynamic form for structured content type
    EntityForm dynamicForm = formService.createEntityForm(cmd, entity, null, null);
    for (Field field : fieldsToMove) {
        FieldMetadata fmd = cmd.getPMap().get(field.getName()).getMetadata();
        if (fmd instanceof BasicFieldMetadata) {
            BasicFieldMetadata bfmd = (BasicFieldMetadata) fmd;
            field.setFieldType(bfmd.getFieldType().toString());
            field.setFriendlyName(bfmd.getFriendlyName());
            field.setRequired(bfmd.getRequired());
        }
        dynamicForm.addField(cmd, field);
    }
    setSpecializedNameForFields(info, dynamicForm);
    extensionManager.getProxy().modifyDynamicForm(dynamicForm, entityId);
    return dynamicForm;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) EntityForm(org.broadleafcommerce.openadmin.web.form.entity.EntityForm) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) ArrayList(java.util.ArrayList) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)

Example 14 with EntityForm

use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm 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 15 with EntityForm

use of org.broadleafcommerce.openadmin.web.form.entity.EntityForm 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)

Aggregations

EntityForm (org.broadleafcommerce.openadmin.web.form.entity.EntityForm)33 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)12 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)10 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)10 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)8 DynamicEntityFormInfo (org.broadleafcommerce.openadmin.web.form.entity.DynamicEntityFormInfo)7 ArrayList (java.util.ArrayList)6 Entity (org.broadleafcommerce.openadmin.dto.Entity)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)3 Property (org.broadleafcommerce.openadmin.dto.Property)3 Page (org.broadleafcommerce.cms.page.domain.Page)2 Translation (org.broadleafcommerce.common.i18n.domain.Translation)2 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)2 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)2 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)2 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)2 EntityFormAction (org.broadleafcommerce.openadmin.web.form.entity.EntityFormAction)2