141 lines
5.3 KiB
Java
141 lines
5.3 KiB
Java
package eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition;
|
|
|
|
import eu.eudat.logic.utilities.builders.XmlBuilder;
|
|
import eu.eudat.logic.utilities.interfaces.XmlSerializable;
|
|
import org.w3c.dom.Document;
|
|
import org.w3c.dom.Element;
|
|
import org.w3c.dom.Node;
|
|
import org.w3c.dom.NodeList;
|
|
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
|
|
public class Section implements XmlSerializable<Section> {
|
|
|
|
private UUID id;
|
|
private String label;
|
|
private String description;
|
|
private Integer ordinal;
|
|
private List<SystemField> systemFields;
|
|
private List<DescriptionTemplate> descriptionTemplates;
|
|
private List<ExtraField> extraFields;
|
|
|
|
public UUID getId() {
|
|
return id;
|
|
}
|
|
public void setId(UUID id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public String getLabel() {
|
|
return label;
|
|
}
|
|
public void setLabel(String label) {
|
|
this.label = label;
|
|
}
|
|
|
|
public String getDescription() {
|
|
return description;
|
|
}
|
|
public void setDescription(String description) {
|
|
this.description = description;
|
|
}
|
|
|
|
public Integer getOrdinal() {
|
|
return ordinal;
|
|
}
|
|
public void setOrdinal(Integer ordinal) {
|
|
this.ordinal = ordinal;
|
|
}
|
|
|
|
public List<SystemField> getSystemFields() {
|
|
return systemFields;
|
|
}
|
|
public void setSystemFields(List<SystemField> systemFields) {
|
|
this.systemFields = systemFields;
|
|
}
|
|
|
|
public List<DescriptionTemplate> getDescriptionTemplates() {
|
|
return descriptionTemplates;
|
|
}
|
|
public void setDescriptionTemplates(List<DescriptionTemplate> descriptionTemplates) {
|
|
this.descriptionTemplates = descriptionTemplates;
|
|
}
|
|
|
|
public List<ExtraField> getExtraFields() {
|
|
return extraFields;
|
|
}
|
|
public void setExtraFields(List<ExtraField> extraFields) {
|
|
this.extraFields = extraFields;
|
|
}
|
|
|
|
@Override
|
|
public Element toXml(Document doc) {
|
|
Element rootElement = doc.createElement("section");
|
|
rootElement.setAttribute("id", this.getId().toString());
|
|
rootElement.setAttribute("label", this.label);
|
|
rootElement.setAttribute("description", this.description);
|
|
rootElement.setAttribute("ordinal", String.valueOf(this.ordinal));
|
|
Element systemFields = doc.createElement("systemFields");
|
|
for (SystemField systemField : this.systemFields) {
|
|
systemFields.appendChild(systemField.toXml(doc));
|
|
}
|
|
rootElement.appendChild(systemFields);
|
|
Element descriptionTemplates = doc.createElement("descriptionTemplates");
|
|
for (DescriptionTemplate descriptionTemplate : this.descriptionTemplates) {
|
|
descriptionTemplates.appendChild(descriptionTemplate.toXml(doc));
|
|
}
|
|
rootElement.appendChild(descriptionTemplates);
|
|
Element extraFields = doc.createElement("extraFields");
|
|
for (ExtraField extraField : this.extraFields) {
|
|
extraFields.appendChild(extraField.toXml(doc));
|
|
}
|
|
rootElement.appendChild(extraFields);
|
|
|
|
return rootElement;
|
|
}
|
|
|
|
@Override
|
|
public Section fromXml(Element item) {
|
|
this.id = UUID.fromString(item.getAttribute("id"));
|
|
this.label = item.getAttribute("label");
|
|
this.description = item.getAttribute("description");
|
|
this.ordinal = Integer.valueOf(item.getAttribute("ordinal"));
|
|
this.systemFields = new LinkedList<>();
|
|
Element systemFields = (Element) XmlBuilder.getNodeFromListByTagName(item.getChildNodes(), "systemFields");
|
|
if (systemFields != null) {
|
|
NodeList systemFieldElements = systemFields.getChildNodes();
|
|
for (int temp = 0; temp < systemFieldElements.getLength(); temp++) {
|
|
Node systemFieldElement = systemFieldElements.item(temp);
|
|
if (systemFieldElement.getNodeType() == Node.ELEMENT_NODE) {
|
|
this.systemFields.add(new SystemField().fromXml((Element) systemFieldElement));
|
|
}
|
|
}
|
|
}
|
|
this.descriptionTemplates = new LinkedList<>();
|
|
Element descriptionTemplates = (Element) XmlBuilder.getNodeFromListByTagName(item.getChildNodes(), "descriptionTemplates");
|
|
if (descriptionTemplates != null) {
|
|
NodeList descriptionTemplateElements = descriptionTemplates.getChildNodes();
|
|
for (int temp = 0; temp < descriptionTemplateElements.getLength(); temp++) {
|
|
Node descriptionTemplateElement = descriptionTemplateElements.item(temp);
|
|
if (descriptionTemplateElement.getNodeType() == Node.ELEMENT_NODE) {
|
|
this.descriptionTemplates.add(new DescriptionTemplate().fromXml((Element) descriptionTemplateElement));
|
|
}
|
|
}
|
|
}
|
|
this.extraFields = new LinkedList<>();
|
|
Element extraFields = (Element) XmlBuilder.getNodeFromListByTagName(item.getChildNodes(), "extraFields");
|
|
if (extraFields != null) {
|
|
NodeList extraFieldElements = extraFields.getChildNodes();
|
|
for (int temp = 0; temp < extraFieldElements.getLength(); temp++) {
|
|
Node extraFieldElement = extraFieldElements.item(temp);
|
|
if (extraFieldElement.getNodeType() == Node.ELEMENT_NODE) {
|
|
this.extraFields.add(new ExtraField().fromXml((Element) extraFieldElement));
|
|
}
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
}
|