2019-02-25 17:46:16 +01:00
|
|
|
package eu.eudat.logic.utilities.documents.xml.datasetProfileXml;
|
|
|
|
|
|
|
|
|
|
|
|
import eu.eudat.models.data.admin.components.datasetprofile.Page;
|
|
|
|
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;
|
|
|
|
import eu.eudat.models.data.user.components.datasetprofile.Section;
|
|
|
|
import eu.eudat.logic.utilities.builders.XmlBuilder;
|
|
|
|
|
2020-04-02 16:22:41 +02:00
|
|
|
import org.springframework.core.env.Environment;
|
2019-02-25 17:46:16 +01:00
|
|
|
import org.w3c.dom.Document;
|
|
|
|
import org.w3c.dom.Element;
|
|
|
|
|
|
|
|
import java.io.BufferedWriter;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileWriter;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
|
|
public class ExportXmlBuilderDatasetProfile {
|
|
|
|
|
|
|
|
|
2020-04-02 16:22:41 +02:00
|
|
|
public File build(eu.eudat.models.data.user.composite.DatasetProfile datasetProfile, Environment environment) throws IOException {
|
2019-02-25 17:46:16 +01:00
|
|
|
|
2020-04-02 16:22:41 +02:00
|
|
|
File xmlFile = new File(environment.getProperty("temp.temp") + UUID.randomUUID() + ".xml");
|
2019-02-25 17:46:16 +01:00
|
|
|
BufferedWriter writer = new BufferedWriter(new FileWriter(xmlFile, true));
|
|
|
|
Document xmlDoc = XmlBuilder.getDocument();
|
|
|
|
// Element root = xmlDoc.createElement("root");
|
|
|
|
// root.appendChild(createPages(datasetProfile.getPages(), datasetProfile.getSections(), xmlDoc));
|
|
|
|
|
|
|
|
xmlDoc.appendChild(createPages(datasetProfile.getPages(), datasetProfile.getSections(), xmlDoc));
|
|
|
|
String xml = XmlBuilder.generateXml(xmlDoc);
|
|
|
|
writer.write(xml);
|
|
|
|
writer.close();
|
|
|
|
return xmlFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Element createPages(List<Page> datasetProfilePages, List<Section> sections, Document element) {
|
|
|
|
Element pages = element.createElement("pages");
|
|
|
|
datasetProfilePages.forEach(item -> {
|
|
|
|
Element page = element.createElement("page");
|
|
|
|
page.setAttribute("id", "" + item.getId());
|
|
|
|
page.setAttribute("ordinal", "" + item.getOrdinal());
|
|
|
|
page.setAttribute("title", "" + item.getTitle());
|
|
|
|
sections.forEach(sectionFromLis -> {
|
|
|
|
if (sectionFromLis.getPage().equals(item.getId())) {
|
|
|
|
Element elementSections = element.createElement("sections");
|
|
|
|
page.appendChild(createSections(sectionFromLis, element, elementSections));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
pages.appendChild(page);
|
|
|
|
});
|
|
|
|
return pages;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Element createSections(Section sections, Document element, Element elementSections) {
|
|
|
|
// if (sections.getSections() != null) {
|
|
|
|
sections.getSections().forEach(sectionFor -> {
|
|
|
|
Element elementSectionsChild = element.createElement("section");
|
|
|
|
elementSections.appendChild(createSections(sectionFor, element, elementSectionsChild));
|
|
|
|
});
|
|
|
|
// }
|
|
|
|
|
|
|
|
elementSections.setAttribute("defaultVisibility", "" + sections.getDefaultVisibility());
|
|
|
|
elementSections.setAttribute("id", "" + sections.getId());
|
|
|
|
elementSections.setAttribute("ordinal", "" + sections.getOrdinal());
|
|
|
|
elementSections.setAttribute("page", "" + sections.getPage());
|
|
|
|
elementSections.setAttribute("page", "" + sections.getPage());
|
|
|
|
|
|
|
|
if (sections.getCompositeFields() != null) {
|
|
|
|
elementSections.appendChild(createFieldSet(sections.getCompositeFields(), element));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sections.getNumbering() != null) {
|
|
|
|
Element numbering = element.createElement("numbering");
|
|
|
|
numbering.setTextContent(sections.getNumbering());
|
|
|
|
elementSections.appendChild(numbering);
|
|
|
|
}
|
|
|
|
if (sections.getDescription() != null) {
|
|
|
|
Element description = element.createElement("description");
|
|
|
|
description.setTextContent(sections.getDescription());
|
|
|
|
elementSections.appendChild(description);
|
|
|
|
}
|
|
|
|
if (sections.getTitle() != null) {
|
|
|
|
Element title = element.createElement("title");
|
|
|
|
title.setTextContent(sections.getTitle());
|
|
|
|
elementSections.appendChild(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
return elementSections;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Element createFieldSet(List<FieldSet> fieldSet, Document element) {
|
|
|
|
Element elementFieldSets = element.createElement("field-Sets");
|
|
|
|
fieldSet.forEach(field -> {
|
|
|
|
Element composite = element.createElement("field-Set");
|
|
|
|
composite.setAttribute("id", field.getId());
|
|
|
|
composite.setAttribute("ordinal", "" + field.getOrdinal());
|
|
|
|
|
|
|
|
if (field.getNumbering() != null) {
|
|
|
|
Element numbering = element.createElement("numbering");
|
|
|
|
numbering.setTextContent(field.getNumbering());
|
|
|
|
composite.appendChild(numbering);
|
|
|
|
}
|
|
|
|
Element commentField = element.createElement("CommentField");
|
|
|
|
commentField.setTextContent("" + field.getHasCommentField());
|
|
|
|
composite.appendChild(commentField);
|
|
|
|
|
|
|
|
composite.appendChild(createFields(field.getFields(), element));
|
|
|
|
|
|
|
|
if (field.getMultiplicity() != null) {
|
|
|
|
Element multiplicity = element.createElement("multiplicity");
|
|
|
|
multiplicity.setAttribute("max", "" + field.getMultiplicity().getMax());
|
|
|
|
multiplicity.setAttribute("min", "" + field.getMultiplicity().getMin());
|
|
|
|
composite.appendChild(multiplicity);
|
|
|
|
}
|
|
|
|
if (field.getTitle() != null && !field.getTitle().isEmpty()) {
|
|
|
|
Element title = element.createElement("title");
|
|
|
|
title.setTextContent(field.getTitle());
|
|
|
|
composite.appendChild(title);
|
|
|
|
}
|
|
|
|
if (field.getDescription() != null && !field.getDescription().isEmpty()) {
|
|
|
|
Element title = element.createElement("description");
|
|
|
|
title.setTextContent(field.getDescription());
|
|
|
|
composite.appendChild(title);
|
|
|
|
}
|
|
|
|
if (field.getExtendedDescription() != null && !field.getExtendedDescription().isEmpty()) {
|
|
|
|
Element extendedDescription = element.createElement("extendedDescription");
|
|
|
|
extendedDescription.setTextContent(field.getExtendedDescription());
|
|
|
|
composite.appendChild(extendedDescription);
|
|
|
|
}
|
2019-03-07 11:04:54 +01:00
|
|
|
if (field.getAdditionalInformation() != null && !field.getAdditionalInformation().isEmpty()) {
|
|
|
|
Element additionalInformation = element.createElement("additionalInformation");
|
|
|
|
additionalInformation.setTextContent(field.getAdditionalInformation());
|
|
|
|
composite.appendChild(additionalInformation);
|
|
|
|
}
|
2019-02-25 17:46:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
elementFieldSets.appendChild(composite);
|
|
|
|
});
|
|
|
|
return elementFieldSets;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Element createFields(List<Field> fields, Document element) {
|
|
|
|
Element elementFields = element.createElement("fields");
|
|
|
|
fields.forEach(field -> {
|
|
|
|
Element elementField = element.createElement("field");
|
|
|
|
elementField.setAttribute("id", field.getId());
|
|
|
|
elementField.setAttribute("ordinal", "" + field.getOrdinal());
|
|
|
|
|
|
|
|
if (field.getNumbering() != null) {
|
|
|
|
Element numbering = element.createElement("numbering");
|
|
|
|
numbering.setTextContent(field.getNumbering());
|
|
|
|
elementField.appendChild(numbering);
|
|
|
|
}
|
|
|
|
if (field.getValidations() != null) {
|
|
|
|
Element validations = element.createElement("validations");
|
|
|
|
field.getValidations().forEach(validation -> {
|
|
|
|
Element validationChild = element.createElement("validation");
|
|
|
|
validationChild.setAttribute("type", "" + validation);
|
|
|
|
validations.appendChild(validationChild);
|
|
|
|
});
|
|
|
|
elementField.appendChild(validations);
|
|
|
|
}
|
|
|
|
if (field.getDefaultValue() != null) {
|
|
|
|
Element defaultValue = element.createElement("defaultValue");
|
|
|
|
defaultValue.setAttribute("type", field.getDefaultValue().getType());
|
|
|
|
defaultValue.setAttribute("value", field.getDefaultValue().getValue());
|
|
|
|
elementField.appendChild(defaultValue);
|
|
|
|
}
|
|
|
|
if (field.getVisible() != null) {
|
|
|
|
Element visible = element.createElement("visible");
|
|
|
|
visible.setAttribute("style", "" + field.getVisible().getStyle());
|
|
|
|
field.getVisible().getRules().forEach(rule -> {
|
|
|
|
Element ruleChild = element.createElement("rule");
|
|
|
|
ruleChild.setAttribute("ruleStyle", "" + rule.getRuleStyle());
|
|
|
|
ruleChild.setAttribute("target", "" + rule.getTarget());
|
|
|
|
ruleChild.setAttribute("type", "" + rule.getRuleType());
|
|
|
|
Element ruleChildValue = element.createElement("value");
|
|
|
|
ruleChildValue.setAttribute("type", "" + rule.getValueType());
|
|
|
|
ruleChildValue.setTextContent(rule.getValue());
|
|
|
|
ruleChild.appendChild(ruleChildValue);
|
|
|
|
visible.appendChild(ruleChild);
|
|
|
|
|
|
|
|
});
|
|
|
|
elementField.appendChild(visible);
|
|
|
|
}
|
|
|
|
if (field.getViewStyle() != null) {
|
|
|
|
Element viewStyle = element.createElement("viewStyle");
|
|
|
|
viewStyle.setAttribute("cssClass", field.getViewStyle().getCssClass());
|
|
|
|
viewStyle.setAttribute("renderStyle", field.getViewStyle().getRenderStyle());
|
|
|
|
elementField.appendChild(viewStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
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());
|
2020-06-17 11:30:54 +02:00
|
|
|
dataOut.setAttribute("multiAutoComplete", autoCompleteDataObject.getMultiAutoComplete().toString());
|
2020-05-25 16:14:42 +02:00
|
|
|
for (AutoCompleteData.AutoCompleteSingleData singleData: autoCompleteDataObject.getAutoCompleteSingleDataList()) {
|
|
|
|
Element singleItem = element.createElement("autocompleteSingle");
|
|
|
|
singleItem.setAttribute("optionsRoot", singleData.getOptionsRoot());
|
|
|
|
singleItem.setAttribute("url", singleData.getUrl());
|
2020-06-17 11:30:54 +02:00
|
|
|
singleItem.setAttribute("autoCompleteType", Integer.toString(singleData.getAutocompleteType()));
|
2020-05-25 16:14:42 +02:00
|
|
|
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);
|
2019-02-25 17:46:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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());
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
elementFields.appendChild(elementField);
|
|
|
|
});
|
|
|
|
return elementFields;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|