Fixed and improved the dataset template export/import to/from xml
This commit is contained in:
parent
8d9913c229
commit
e539278d78
|
@ -26,10 +26,26 @@ public class AdminManager {
|
|||
viewStyleDoc.appendChild(elementViewStyle);
|
||||
String xml = XmlBuilder.generateXml(viewStyleDoc);
|
||||
|
||||
if (profile.getDescription() == null) {
|
||||
profile.setDescription("");
|
||||
}
|
||||
|
||||
if (profile.getLanguage() == null) {
|
||||
profile.setLanguage("en");
|
||||
}
|
||||
|
||||
eu.eudat.data.entities.DatasetProfile datasetProfile = apiContext.getOperationsContext().getBuilderFactory().getBuilder(DatasetProfileBuilder.class).definition(xml).label(profile.getLabel())
|
||||
.status(profile.getStatus()).created(new Date()).description(profile.getDescription()).language(profile.getLanguage())
|
||||
.build();
|
||||
|
||||
if (datasetProfile.getGroupId() == null) {
|
||||
datasetProfile.setGroupId(UUID.randomUUID());
|
||||
}
|
||||
|
||||
if (datasetProfile.getVersion() == null) {
|
||||
datasetProfile.setVersion((short)1);
|
||||
}
|
||||
|
||||
return datasetProfile;
|
||||
}
|
||||
|
||||
|
|
|
@ -217,10 +217,12 @@ public class ExportXmlBuilderDatasetProfile {
|
|||
AutoCompleteData autoCompleteDataObject = (AutoCompleteData) field.getData();
|
||||
dataOut.setAttribute("label", autoCompleteDataObject.getLabel());
|
||||
dataOut.setAttribute("type", autoCompleteDataObject.getType());
|
||||
dataOut.setAttribute("multiAutoComplete", autoCompleteDataObject.getMultiAutoComplete().toString());
|
||||
for (AutoCompleteData.AutoCompleteSingleData singleData: autoCompleteDataObject.getAutoCompleteSingleDataList()) {
|
||||
Element singleItem = element.createElement("autocompleteSingle");
|
||||
singleItem.setAttribute("optionsRoot", singleData.getOptionsRoot());
|
||||
singleItem.setAttribute("url", singleData.getUrl());
|
||||
singleItem.setAttribute("autoCompleteType", Integer.toString(singleData.getAutocompleteType()));
|
||||
if (singleData.getAutoCompleteOptions() != null) {
|
||||
Element optionChild = element.createElement("option");
|
||||
optionChild.setAttribute("label", singleData.getAutoCompleteOptions().getLabel());
|
||||
|
|
|
@ -128,7 +128,7 @@ public class AutoCompleteData extends ComboBoxData<AutoCompleteData> {
|
|||
if (data != null) {
|
||||
this.multiAutoComplete = (Boolean) ((Map<Boolean, Object>) data).get("multiAutoComplete");
|
||||
|
||||
List<Map<String, Object>> dataList = (List<Map<String, Object>>) ((Map<String, Object>) data).get("autoCompleteSingleDataList");
|
||||
List<Map<String, Object>> dataList = (List<Map<String, Object>>) ((Map<String, Object>) data).get("autocompleteSingle");
|
||||
|
||||
this.autoCompleteSingleDataList = new ArrayList<>();
|
||||
|
||||
|
@ -168,16 +168,36 @@ public class AutoCompleteData extends ComboBoxData<AutoCompleteData> {
|
|||
public Map<String, Object> toMap(Element item) {
|
||||
HashMap dataMap = new HashMap();
|
||||
dataMap.put("label", item != null ? item.getAttribute("label") : "");
|
||||
dataMap.put("url", item != null ? item.getAttribute("url") : "");
|
||||
//dataMap.put("url", item != null ? item.getAttribute("url") : "");
|
||||
dataMap.put("type", item != null ? item.getAttribute("type") : "autocomplete");
|
||||
dataMap.put("optionsRoot", item != null ? item.getAttribute("optionsRoot") : "");
|
||||
Element optionElement = (Element) item.getElementsByTagName("option").item(0);
|
||||
dataMap.put("multiAutoComplete", item != null ? Boolean.valueOf(item.getAttribute("multiAutoComplete")) : false);
|
||||
List<Map<String, Object>> autoCompletes = new ArrayList<>();
|
||||
NodeList autoCompleteSingles = item.getChildNodes();
|
||||
for (int i = 0; i < autoCompleteSingles.getLength(); i++) {
|
||||
if (autoCompleteSingles.item(i) instanceof Element && !((Element) autoCompleteSingles.item(i)).getTagName().equals("option")) {
|
||||
Element node = (Element) autoCompleteSingles.item(i);
|
||||
if (!node.hasChildNodes()) {
|
||||
node.appendChild(node);
|
||||
}
|
||||
|
||||
autoCompletes.add(singleToMap(node));
|
||||
} else if (((Element) autoCompleteSingles.item(i)).getTagName().equals("option")) {
|
||||
Element node = item.getOwnerDocument().createElement("autocompleteSingle");
|
||||
node.appendChild(autoCompleteSingles.item(i));
|
||||
node.setAttribute("url", item.getAttribute("url"));
|
||||
node.setAttribute("optionsRoot", item.getAttribute("optionsRoot"));
|
||||
autoCompletes.add(singleToMap(node));
|
||||
}
|
||||
}
|
||||
dataMap.put("autocompleteSingle", autoCompletes);
|
||||
//dataMap.put("optionsRoot", item != null ? item.getAttribute("optionsRoot") : "");
|
||||
//Element optionElement = (Element) item.getElementsByTagName("option").item(0);
|
||||
// if (optionElement != null) {
|
||||
// this.autoCompleteOptions = new Option();
|
||||
// this.autoCompleteOptions.setLabel(optionElement.getAttribute("label"));
|
||||
// this.autoCompleteOptions.setValue(optionElement.getAttribute("value"));
|
||||
// }
|
||||
dataMap.put("autoCompleteOptions", item != null ? optionToMap(optionElement) : null);
|
||||
// dataMap.put("autoCompleteOptions", item != null ? optionToMap(optionElement) : null);
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
|
@ -189,6 +209,18 @@ public class AutoCompleteData extends ComboBoxData<AutoCompleteData> {
|
|||
return dataMap;
|
||||
}
|
||||
|
||||
private Map<String, Object> singleToMap(Element item) {
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
if (!item.getAttribute("autoCompleteType").isEmpty()) {
|
||||
dataMap.put("autoCompleteType", Integer.parseInt(item.getAttribute("autoCompleteType")));
|
||||
}
|
||||
dataMap.put("optionsRoot", item != null ? item.getAttribute("optionsRoot") : "");
|
||||
dataMap.put("url", item != null ? item.getAttribute("url") : "");
|
||||
Element optionElement = (Element) item.getElementsByTagName("option").item(0);
|
||||
dataMap.put("autoCompleteOptions", item != null ? optionToMap(optionElement) : null);
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
public enum AutocompleteType {
|
||||
UNCACHED(0), CACHED(1);
|
||||
|
||||
|
|
Loading…
Reference in New Issue