Search in sources :

Example 21 with PersistencePackageRequest

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

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

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

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

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

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