use of org.broadleafcommerce.openadmin.web.form.entity.Field 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;
}
use of org.broadleafcommerce.openadmin.web.form.entity.Field 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;
}
use of org.broadleafcommerce.openadmin.web.form.entity.Field 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);
}
use of org.broadleafcommerce.openadmin.web.form.entity.Field in project BroadleafCommerce by BroadleafCommerce.
the class AdminTranslationController method updateTranslation.
/**
* Updates the given translation id to the new locale code and translated value
*
* @param request
* @param response
* @param model
* @param entityForm
* @param result
* @return the result of a call to {@link #viewTranslation}, which renders the list grid
* @throws Exception
*/
@RequestMapping(value = "/update", method = RequestMethod.POST)
public String updateTranslation(HttpServletRequest request, HttpServletResponse response, Model model, @ModelAttribute(value = "entityForm") EntityForm entityForm, BindingResult result) throws Exception {
final TranslationForm form = getTranslationForm(entityForm);
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);
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.updateEntity(entityForm, sectionCriteria, sectionCrumbs).getEntity();
return viewTranslation(request, response, model, form, result);
}
use of org.broadleafcommerce.openadmin.web.form.entity.Field in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method buildMapForm.
@Override
public EntityForm buildMapForm(MapMetadata mapMd, final MapStructure mapStructure, ClassMetadata cmd, String parentId, EntityForm ef) throws ServiceException {
ForeignKey foreignKey = (ForeignKey) mapMd.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.FOREIGNKEY);
ef.setEntityType(foreignKey.getForeignKeyClass());
Field keyField;
if (!mapMd.getForceFreeFormKeys()) {
// We will use a combo field to render the key choices
ComboField temp = new ComboField();
temp.withName("key").withFieldType("combo_field").withFriendlyName(mapStructure.getKeyPropertyFriendlyName());
if (mapMd.getKeys() != null) {
// The keys can be explicitly set in the annotation...
temp.setOptions(mapMd.getKeys());
} else {
// Or they could be based on a different entity
PersistencePackageRequest ppr = PersistencePackageRequest.standard().withCeilingEntityClassname(mapMd.getMapKeyOptionEntityClass());
DynamicResultSet drs = adminEntityService.getRecords(ppr).getDynamicResultSet();
for (Entity entity : drs.getRecords()) {
String keyValue = entity.getPMap().get(mapMd.getMapKeyOptionEntityValueField()).getValue();
String keyDisplayValue = entity.getPMap().get(mapMd.getMapKeyOptionEntityDisplayField()).getValue();
temp.putOption(keyValue, keyDisplayValue);
}
}
keyField = temp;
} else {
keyField = new Field().withName("key").withFieldType(SupportedFieldType.STRING.toString()).withFriendlyName(mapStructure.getKeyPropertyFriendlyName());
}
keyField.setRequired(true);
ef.addMapKeyField(cmd, keyField);
// Set the fields for this form
List<Property> mapFormProperties;
if (mapMd.isSimpleValue()) {
ef.setIdProperty("key");
mapFormProperties = new ArrayList<>();
Property valueProp = cmd.getPMap().get("value");
mapFormProperties.add(valueProp);
} else {
String valueClassName = mapStructure.getValueClassName();
List<String> classNames = getValueClassNames(valueClassName);
mapFormProperties = new ArrayList<>(Arrays.asList(cmd.getProperties()));
filterMapFormProperties(mapFormProperties, classNames);
}
setEntityFormFields(cmd, ef, mapFormProperties);
Field f = new Field().withName("priorKey").withFieldType(SupportedFieldType.HIDDEN.toString());
ef.addHiddenField(cmd, f);
ef.setParentId(parentId);
return ef;
}
Aggregations