Export properly the data for each field type on dataset templates

This commit is contained in:
George Kalampokis 2021-05-07 14:38:21 +03:00
parent af432cf329
commit 15c3a6fcb5
3 changed files with 149 additions and 53 deletions

View File

@ -2,6 +2,7 @@ package eu.eudat.logic.utilities.documents.xml.datasetProfileXml;
import eu.eudat.models.data.admin.components.datasetprofile.Page;
import eu.eudat.models.data.components.commons.ViewStyle;
import eu.eudat.models.data.components.commons.datafield.*;
import eu.eudat.models.data.user.components.datasetprofile.Field;
import eu.eudat.models.data.user.components.datasetprofile.FieldSet;
@ -202,67 +203,120 @@ public class ExportXmlBuilderDatasetProfile {
if (field.getData() != null) {
Element dataOut = element.createElement("data");
if (field.getViewStyle().getRenderStyle().equals("combobox")) {
ComboBoxData comboBoxDataObject = (ComboBoxData) field.getData();
if (comboBoxDataObject.getType().equals("wordlist")) {
WordListData wordListDataObject = (WordListData) field.getData();
dataOut.setAttribute("label", wordListDataObject.getLabel());
dataOut.setAttribute("type", wordListDataObject.getType());
dataOut.setAttribute("multiList", wordListDataObject.getMultiList().toString());
ViewStyle.Type viewStyleType = ViewStyle.Type.fromName(field.getViewStyle().getRenderStyle());
switch (viewStyleType) {
case COMBO_BOX:
ComboBoxData comboBoxDataObject = (ComboBoxData) field.getData();
if (comboBoxDataObject.getType().equals("wordlist")) {
WordListData wordListDataObject = (WordListData) field.getData();
dataOut.setAttribute("label", wordListDataObject.getLabel());
dataOut.setAttribute("type", wordListDataObject.getType());
dataOut.setAttribute("multiList", wordListDataObject.getMultiList().toString());
Element options = element.createElement("options");
wordListDataObject.getOptions().forEach(optionChildFor -> {
Element optionChild = element.createElement("option");
optionChild.setAttribute("label", optionChildFor.getLabel());
optionChild.setAttribute("value", optionChildFor.getValue());
options.appendChild(optionChild);
});
dataOut.appendChild(options);
} else if (comboBoxDataObject.getType().equals("autocomplete")) {
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());
optionChild.setAttribute("value", singleData.getAutoCompleteOptions().getValue());
singleItem.appendChild(optionChild);
}
dataOut.appendChild(singleItem);
}
}
break;
case BOOLEAN_DECISION:
BooleanDecisionData booleanDecisionDataObject = (BooleanDecisionData) field.getData();
dataOut.setAttribute("label", booleanDecisionDataObject.getLabel());
break;
case RADIO_BOX:
RadioBoxData radioBoxDataObject = (RadioBoxData) field.getData();
dataOut.setAttribute("label", radioBoxDataObject.getLabel());
Element options = element.createElement("options");
wordListDataObject.getOptions().forEach(optionChildFor -> {
radioBoxDataObject.getOptions().forEach(optionChildFor -> {
Element optionChild = element.createElement("option");
optionChild.setAttribute("label", optionChildFor.getLabel());
optionChild.setAttribute("value", optionChildFor.getValue());
options.appendChild(optionChild);
});
dataOut.appendChild(options);
} else if (comboBoxDataObject.getType().equals("autocomplete")) {
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());
optionChild.setAttribute("value", singleData.getAutoCompleteOptions().getValue());
singleItem.appendChild(optionChild);
}
dataOut.appendChild(singleItem);
break;
case CHECK_BOX:
case FREE_TEXT:
case TEXT_AREA:
case DATE_PICKER:
case DATASET_IDENTIFIER:
case CURRENCY:
case TAGS:
FieldData fieldDataObject = (FieldData) field.getData();
dataOut.setAttribute("label", fieldDataObject.getLabel());
break;
case INTERNAL_DMP_ENTRIES:
InternalDmpEntitiesData internalDmpEntitiesData = (InternalDmpEntitiesData) field.getData();
dataOut.setAttribute("label", internalDmpEntitiesData.getLabel());
dataOut.setAttribute("type", internalDmpEntitiesData.getType());
switch (internalDmpEntitiesData.getType()) {
case "researchers":
ResearchersAutoCompleteData researchersAutoCompleteData = (ResearchersAutoCompleteData) internalDmpEntitiesData;
dataOut.setAttribute("multiAutocomplete", researchersAutoCompleteData.getMultiAutoComplete().toString());
break;
case "datasets":
DatasetsAutoCompleteData datasetsAutoCompleteData = (DatasetsAutoCompleteData) internalDmpEntitiesData;
dataOut.setAttribute("multiAutocomplete", datasetsAutoCompleteData.getMultiAutoComplete().toString());
break;
case "dmps":
DMPsAutoCompleteData dmPsAutoCompleteData = (DMPsAutoCompleteData) internalDmpEntitiesData;
dataOut.setAttribute("multiAutocomplete", dmPsAutoCompleteData.getMultiAutoComplete().toString());
break;
}
}
} else if (field.getViewStyle().getRenderStyle().equals("booleanDecision")) {
BooleanDecisionData booleanDecisionDataObject = (BooleanDecisionData) field.getData();
dataOut.setAttribute("label", booleanDecisionDataObject.getLabel());
} else if (field.getViewStyle().getRenderStyle().equals("radiobox")) {
RadioBoxData radioBoxDataObject = (RadioBoxData) field.getData();
dataOut.setAttribute("label", radioBoxDataObject.getLabel());
break;
case EXTERNAL_DATASETS:
ExternalDatasetsData externalDatasetsData = (ExternalDatasetsData) field.getData();
dataOut.setAttribute("label", externalDatasetsData.getLabel());
dataOut.setAttribute("multiAutocomplete", externalDatasetsData.getMultiAutoComplete().toString());
break;
case DATA_REPOSITORIES:
DataRepositoriesData dataRepositoriesData = (DataRepositoriesData) field.getData();
dataOut.setAttribute("label", dataRepositoriesData.getLabel());
dataOut.setAttribute("multiAutocomplete", dataRepositoriesData.getMultiAutoComplete().toString());
break;
case ORGANIZATIONS:
OrganizationsData organizationsData = (OrganizationsData) field.getData();
dataOut.setAttribute("label", organizationsData.getLabel());
dataOut.setAttribute("multiAutocomplete", organizationsData.getMultiAutoComplete().toString());
break;
case RESEARCHERS:
ResearcherData researcherData = (ResearcherData) field.getData();
dataOut.setAttribute("label", researcherData.getLabel());
dataOut.setAttribute("multiAutocomplete", researcherData.getMultiAutoComplete().toString());
break;
case REGISTRIES:
RegistriesData registriesData = (RegistriesData) field.getData();
dataOut.setAttribute("label", registriesData.getLabel());
dataOut.setAttribute("multiAutocomplete", registriesData.getMultiAutoComplete().toString());
break;
case SERVICES:
ServicesData servicesData = (ServicesData) field.getData();
dataOut.setAttribute("label", servicesData.getLabel());
dataOut.setAttribute("multiAutocomplete", servicesData.getMultiAutoComplete().toString());
break;
Element options = element.createElement("options");
radioBoxDataObject.getOptions().forEach(optionChildFor -> {
Element optionChild = element.createElement("option");
optionChild.setAttribute("label", optionChildFor.getLabel());
optionChild.setAttribute("value", optionChildFor.getValue());
options.appendChild(optionChild);
});
dataOut.appendChild(options);
} else if (field.getViewStyle().getRenderStyle().equals("checkBox")) {
CheckBoxData checkBoxDataObject = (CheckBoxData) field.getData();
dataOut.setAttribute("label", checkBoxDataObject.getLabel());
} else if (field.getViewStyle().getRenderStyle().equals("freetext")) {
FreeTextData freeTextDataObject = (FreeTextData) field.getData();
dataOut.setAttribute("label", freeTextDataObject.getLabel());
} else if (field.getViewStyle().getRenderStyle().equals("textarea")) {
TextAreaData textAreaDataObject = (TextAreaData) field.getData();
dataOut.setAttribute("label", textAreaDataObject.getLabel());
} else if (field.getViewStyle().getRenderStyle().equals("datePicker")) {
DatePickerData datePickerDataObject = (DatePickerData) field.getData();
dataOut.setAttribute("label", datePickerDataObject.getLabel());
}
elementField.appendChild(dataOut);
}

View File

@ -117,7 +117,9 @@ public class Field {
fieldEntity.setViewStyle(this.viewStyle.toAdminCompositeModelSection());
FieldData data = new ModelBuilder().toFieldData(null, this.viewStyle.getRenderStyle(), (Element) this.data);
// fieldEntity.setData( data.fromXml((Element) this.data));
fieldEntity.setData( data.toMap((Element)this.data));
if (data != null) {
fieldEntity.setData(data.toMap((Element) this.data));
}
return fieldEntity;
}
}

View File

@ -20,4 +20,44 @@ public class ViewStyle {
this.cssClass = cssClass;
}
public enum Type {
COMBO_BOX("combobox"),
BOOLEAN_DECISION("booleanDecision"),
RADIO_BOX("radiobox"),
INTERNAL_DMP_ENTRIES("internalDmpEntities"),
CHECK_BOX("checkBox"),
FREE_TEXT("freetext"),
TEXT_AREA("textarea"),
DATE_PICKER("datePicker"),
EXTERNAL_DATASETS("externalDatasets"),
DATA_REPOSITORIES("dataRepositories"),
REGISTRIES("registries"),
SERVICES("services"),
TAGS("tags"),
RESEARCHERS("researchers"),
ORGANIZATIONS("organizations"),
DATASET_IDENTIFIER("datasetIdentifier"),
CURRENCY("currency"),
VALIDATION("validation");
private final String name;
Type(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static Type fromName(String name) {
for (Type type: Type.values()) {
if (name.equals(type.getName())) {
return type;
}
}
throw new IllegalArgumentException("View Style Type [" + name + "] is not valid");
}
}
}