/** * Clears deprecated names and descriptions (because they exactly matched the underlying form * @param request * @return */ @RequestMapping(method=RequestMethod.POST, params="migration=clearNamesAndDescriptions") public String clearNamesAndDescriptionsThatMatch(@RequestParam(value="clearName", required=false) List<Integer> clearNames, @RequestParam(value="clearDescription", required=false) List<Integer> clearDescriptions) { HtmlFormEntryService service = HtmlFormEntryUtil.getService(); for (HtmlForm form : service.getAllHtmlForms()) { boolean needToSave = false; if (clearNames != null && clearNames.contains(form.getId())) { form.setDeprecatedName(null); needToSave = true; } if (clearDescriptions != null && clearDescriptions.contains(form.getId())) { form.setDeprecatedDescription(null); needToSave = true; } if (needToSave) service.saveHtmlForm(form); } return "redirect:migrateNamesAndDescriptions.form"; }
service.saveHtmlForm(htmlForm);
/** * Save changes to an HTML Form */ @RequestMapping(value="/module/htmlformentry/htmlForm", method=RequestMethod.POST) public String saveHtmlForm(Model model, @ModelAttribute("htmlForm") HtmlForm htmlForm, BindingResult result, WebRequest request) { HtmlFormEntryService service = HtmlFormEntryUtil.getService(); if (htmlForm.getId() == null && StringUtils.isBlank(htmlForm.getXmlData())) { htmlForm.setXmlData(service.getStartingFormXml(htmlForm)); } HtmlFormValidator validator = new HtmlFormValidator(); validator.validate(htmlForm, result); if (validator.getHtmlFormWarnings().size() > 0) { request.setAttribute("tagWarnings", validator.getHtmlFormWarnings(), WebRequest.SCOPE_SESSION); } if (result.hasErrors()) { return null; } else { htmlForm = service.saveHtmlForm(htmlForm); request.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Saved " + htmlForm.getForm().getName() + " " + htmlForm.getForm().getVersion(), WebRequest.SCOPE_SESSION); return "redirect:htmlForm.form?id=" + htmlForm.getId(); } }
/** * Duplicates the Form that this HtmlForm points to, and points this HtmlForm to the new form. * @param htmlForm */ private void splitUnderlyingForm(HtmlForm htmlForm) { Form oldForm = htmlForm.getForm(); Form newForm = Context.getFormService().duplicateForm(oldForm); htmlForm.setForm(newForm); HtmlFormEntryService service = HtmlFormEntryUtil.getService(); if (htmlForm.getDeprecatedName() != null) { newForm.setName(htmlForm.getDeprecatedName()); htmlForm.setDeprecatedName(null); } service.saveHtmlForm(htmlForm); }