Skip to content

Commit

Permalink
TRUNK-3658: FormService.saveFormResouce doesn't effectively replace
Browse files Browse the repository at this point in the history
existing resources(cherry picked from commit 146cd66)
  • Loading branch information
lluismf authored and dkayiwa committed Feb 18, 2013
1 parent bb71cbd commit 0df51b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 12 additions & 6 deletions api/src/main/java/org/openmrs/api/impl/FormServiceImpl.java
Expand Up @@ -850,13 +850,19 @@ public FormResource saveFormResource(FormResource formResource) throws APIExcept
if (formResource == null)
return null;

// purge the original if it is being overridden (same name)
// If a form resource with same name exists, replace it with current value
FormResource toPersist = formResource;
FormResource original = Context.getFormService().getFormResource(formResource.getForm(), formResource.getName());
if (original != null)
Context.getFormService().purgeFormResource(original);

CustomDatatypeUtil.saveIfDirty(formResource);
return dao.saveFormResource(formResource);
if (original != null) {
original.setName(formResource.getName());
original.setValue(formResource.getValue());
original.setDatatypeClassname(formResource.getDatatypeClassname());
original.setDatatypeConfig(formResource.getDatatypeConfig());
original.setPreferredHandlerClassname(formResource.getPreferredHandlerClassname());
toPersist = original;
}
CustomDatatypeUtil.saveIfDirty(toPersist);
return dao.saveFormResource(toPersist);
}

/**
Expand Down
Expand Up @@ -16,8 +16,6 @@
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.Form;
import org.openmrs.FormResource;
import org.openmrs.api.context.Context;
Expand All @@ -37,8 +35,6 @@
@Controller
public class FormResourceController {

private final Log log = LogFactory.getLog(getClass());

@RequestMapping(method = RequestMethod.GET, value = "admin/forms/formResources")
public void manageFormResources(@RequestParam("formId") Form form, Model model) {
model.addAttribute("form", form);
Expand Down

0 comments on commit 0df51b4

Please sign in to comment.