Commit 75d9726b authored by George Kalampokis's avatar George Kalampokis
Browse files

Fix issue with xml export of autocomplete and multiautocomplete fields

parent 15af25e2
package eu.eudat.logic.utilities.documents.xml;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import eu.eudat.logic.services.forms.VisibilityRuleService;
import eu.eudat.logic.utilities.builders.XmlBuilder;
import eu.eudat.models.data.components.commons.datafield.ExternalDatasetsData;
......@@ -19,6 +21,7 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class ExportXmlBuilder {
......@@ -98,16 +101,33 @@ public class ExportXmlBuilder {
}
if (field.getValue() != null) {
Element valueField = element.createElement("value");
ObjectMapper mapper = new ObjectMapper();
try {
JSONArray jsonArray = new JSONArray(field.getValue().toString());
List<Map<String, Object>> jsonArray = mapper.readValue(field.getValue().toString(), List.class);
// JSONArray jsonArray = new JSONArray(field.getValue().toString());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < jsonArray.length(); i++) {
boolean firstTime = true;
for (Map<String, Object> jsonElement: jsonArray) {
if (!firstTime) {
sb.append(", ");
}
sb.append(jsonElement.get("label") != null ? jsonElement.get("label") : jsonElement.get("name"));
firstTime = false;
}
/*for (int i = 0; i < jsonArray.length(); i++) {
sb.append(jsonArray.getJSONObject(i).get("label").toString());
if (i != jsonArray.length() - 1) sb.append(", ");
}
}*/
valueField.setTextContent(sb.toString());
} catch (JSONException ex) {
valueField.setTextContent(field.getValue().toString());
} catch (IOException ex) {
try {
Map<String, Object> jsonElement = mapper.readValue(field.getValue().toString(), Map.class);
valueField.setTextContent((jsonElement.get("label") != null ? jsonElement.get("label").toString() : jsonElement.get("name").toString()));
} catch (IOException e) {
valueField.setTextContent(field.getValue().toString());
}
}
elementField.appendChild(valueField);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment