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;
}
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;
}
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";
}
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);
}
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";
}
Aggregations