Skip to content

Commit a32b649

Browse files
authored
#295 - Initializer should support htmlformentry 5.5.0+ logic for savi… (#296)
1 parent 71a10ee commit a32b649

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ See the [documentation on Initializer's logging properties](readme/rtprops.md#lo
208208
## Releases notes
209209

210210
#### Version 2.10.0
211+
* Support enhanced methods for loading htmlforms when running htmlformentry 5.5.0+
211212

212213
#### Version 2.9.0
213214
* Fix for InitializerSerializer to ensure compatibility with OpenMRS version 2.7.0+

api/src/main/java/org/openmrs/module/initializer/api/loaders/HtmlFormsLoader.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.openmrs.module.initializer.api.loaders;
22

3-
import java.io.File;
4-
53
import org.apache.commons.io.FileUtils;
64
import org.apache.commons.lang3.StringUtils;
75
import org.openmrs.EncounterType;
@@ -17,6 +15,9 @@
1715
import org.w3c.dom.Document;
1816
import org.w3c.dom.Node;
1917

18+
import java.io.File;
19+
import java.lang.reflect.Method;
20+
2021
@OpenmrsProfile(modules = { "htmlformentry:*" })
2122
public class HtmlFormsLoader extends BaseFileLoader {
2223

@@ -57,6 +58,22 @@ protected String getFileExtension() {
5758
@Override
5859
protected void load(File file) throws Exception {
5960
String xmlData = FileUtils.readFileToString(file, "UTF-8");
61+
// In HFE 5.5.0, a new service method was introduced to save or update an html form from xml
62+
// If this method is available, use it, otherwise fall back to the legacy implementation here
63+
try {
64+
Method method = HtmlFormEntryService.class.getDeclaredMethod("saveHtmlFormFromXml", String.class);
65+
method.invoke(htmlFormEntryService, xmlData);
66+
}
67+
catch (NoSuchMethodException e) {
68+
loadFromXmlData(xmlData);
69+
}
70+
}
71+
72+
/**
73+
* Legacy implementation that loads an htmlform from XML. This has been moved and enhanced in the
74+
* HFE module
75+
*/
76+
protected void loadFromXmlData(String xmlData) throws Exception {
6077
Document doc = HtmlFormEntryUtil.stringToDocument(xmlData);
6178
Node htmlFormNode = HtmlFormEntryUtil.findChild(doc, HTML_FORM_TAG);
6279

0 commit comments

Comments
 (0)