upgrade blueprint xml

This commit is contained in:
Efstratios Giannopoulos 2024-01-26 12:42:46 +02:00
parent 962840d738
commit 2726d232dd
8 changed files with 22 additions and 179 deletions

View File

@ -9,6 +9,11 @@ public enum DmpBlueprintFieldCategory implements DatabaseEnum<Short> {
System((short) 0),
Extra((short) 1);
public static class Names {
public static final String System = "system";
public static final String Extra = "extra";
}
private final Short value;
DmpBlueprintFieldCategory(Short value) {

View File

@ -13,7 +13,7 @@ import java.util.List;
@XmlRootElement(name = "root")
@XmlAccessorType(XmlAccessType.FIELD)
public class DefinitionEntity implements XmlSerializable<DefinitionEntity> {
public class DefinitionEntity {
@XmlElementWrapper(name = "sections")
@XmlElement(name = "section")
private List<SectionEntity> sections;
@ -24,32 +24,4 @@ public class DefinitionEntity implements XmlSerializable<DefinitionEntity> {
public void setSections(List<SectionEntity> sections) {
this.sections = sections;
}
@Override
public Element toXml(Document doc) {
Element root = doc.createElement("root");
Element sections = doc.createElement("sections");
for (SectionEntity section : this.sections) {
sections.appendChild(section.toXml(doc));
}
root.appendChild(sections);
return root;
}
@Override
public DefinitionEntity fromXml(Element item) {
this.sections = new LinkedList<>();
Element sections = (Element) XmlBuilder.getNodeFromListByTagName(item.getChildNodes(), "sections");
if (sections != null) {
NodeList sectionElements = sections.getChildNodes();
for (int temp = 0; temp < sectionElements.getLength(); temp++) {
Node sectionElement = sectionElements.item(temp);
if (sectionElement.getNodeType() == Node.ELEMENT_NODE) {
this.sections.add(new SectionEntity().fromXml((Element) sectionElement));
}
}
}
return this;
}
}

View File

@ -10,7 +10,7 @@ import org.w3c.dom.Element;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public class DescriptionTemplateEntity implements XmlSerializable<DescriptionTemplateEntity> {
public class DescriptionTemplateEntity {
@XmlAttribute(name="descriptionTemplateGroupId")
private UUID descriptionTemplateGroupId;
@ -50,22 +50,4 @@ public class DescriptionTemplateEntity implements XmlSerializable<DescriptionTem
this.maxMultiplicity = maxMultiplicity;
}
@Override
public Element toXml(Document doc) {
Element rootElement = doc.createElement("descriptionTemplate");
rootElement.setAttribute("descriptionTemplateGroupId", this.getDescriptionTemplateGroupId().toString());
rootElement.setAttribute("label", this.label);
rootElement.setAttribute("minMultiplicity", String.valueOf(this.minMultiplicity));
rootElement.setAttribute("maxMultiplicity", String.valueOf(this.maxMultiplicity));
return rootElement;
}
@Override
public DescriptionTemplateEntity fromXml(Element item) {
this.descriptionTemplateGroupId = UUID.fromString(item.getAttribute("descriptionTemplateGroupId"));
this.label = item.getAttribute("label");
this.minMultiplicity = item.hasAttribute("minMultiplicity") && !item.getAttribute("minMultiplicity").equals("null") ? Integer.parseInt(item.getAttribute("minMultiplicity")) : null;
this.maxMultiplicity = item.hasAttribute("maxMultiplicity") && !item.getAttribute("minMultiplicity").equals("null") ? Integer.parseInt(item.getAttribute("maxMultiplicity")) : null;
return this;
}
}

View File

@ -20,16 +20,4 @@ public class ExtraFieldEntity extends FieldEntity {
this.type = type;
}
@Override
public Element appendXmlChild(Element rootElement) {
rootElement.setAttribute("type", String.valueOf(this.type.getValue()));
return rootElement;
}
@Override
public ExtraFieldEntity fromXmlChild(Element item) {
this.type = DmpBlueprintExtraFieldDataType.of(Short.parseShort(item.getAttribute("type")));
this.setCategory(DmpBlueprintFieldCategory.Extra);
return this;
}
}

View File

@ -13,11 +13,11 @@ import org.w3c.dom.Element;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class FieldEntity implements XmlSerializable<FieldEntity> {
public abstract class FieldEntity {
@XmlAttribute(name="id")
private UUID id;
@XmlTransient
@XmlAttribute(name="category")
private DmpBlueprintFieldCategory category;
@XmlAttribute(name="label")
@ -83,30 +83,5 @@ public abstract class FieldEntity implements XmlSerializable<FieldEntity> {
public void setRequired(boolean required) {
this.required = required;
}
protected abstract Element appendXmlChild(Element rootElement);
protected abstract FieldEntity fromXmlChild(Element item);
@Override
public Element toXml(Document doc) {
Element rootElement = doc.createElement("extraField");
rootElement.setAttribute("id", this.getId().toString());
rootElement.setAttribute("label", this.label);
rootElement.setAttribute("description", this.description);
rootElement.setAttribute("placeholder", this.placeholder);
rootElement.setAttribute("required", String.valueOf(this.required));
rootElement.setAttribute("ordinal", String.valueOf(this.ordinal));
this.appendXmlChild(rootElement);
return rootElement;
}
@Override
public FieldEntity fromXml(Element item) {
this.id = UUID.fromString(item.getAttribute("id"));
this.label = item.getAttribute("label");
this.description = item.getAttribute("description");
this.placeholder = item.getAttribute("placeholder");
this.required = Boolean.parseBoolean(item.getAttribute("required"));
this.ordinal = Integer.valueOf(item.getAttribute("ordinal"));
this.fromXmlChild(item);
return this;
}
}

View File

@ -1,6 +1,10 @@
package eu.eudat.commons.types.dmpblueprint;
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
import eu.eudat.commons.enums.ReferenceTypeSourceType;
import eu.eudat.commons.types.referencetype.ReferenceTypeSourceBaseConfigurationEntity;
import eu.eudat.commons.types.referencetype.ReferenceTypeSourceExternalApiConfigurationEntity;
import eu.eudat.commons.types.referencetype.ReferenceTypeSourceStaticOptionConfigurationEntity;
import eu.eudat.commons.types.xml.XmlBuilder;
import eu.eudat.commons.types.xml.XmlSerializable;
import jakarta.xml.bind.annotation.*;
@ -15,7 +19,7 @@ import java.util.UUID;
import java.util.stream.Collectors;
@XmlAccessorType(XmlAccessType.FIELD)
public class SectionEntity implements XmlSerializable<SectionEntity> {
public class SectionEntity {
@XmlAttribute(name="id")
private UUID id;
@ -29,9 +33,13 @@ public class SectionEntity implements XmlSerializable<SectionEntity> {
@XmlAttribute(name="ordinal")
private Integer ordinal;
@XmlTransient
@XmlElementWrapper(name = "fields")
@XmlElements({
@XmlElement(name = DmpBlueprintFieldCategory.Names.Extra, type = ExtraFieldEntity.class),
@XmlElement(name = DmpBlueprintFieldCategory.Names.System, type = SystemFieldEntity.class),
})
private List<FieldEntity> fields;
@XmlAttribute(name="hasTemplates")
private Boolean hasTemplates;
@ -88,78 +96,4 @@ public class SectionEntity implements XmlSerializable<SectionEntity> {
this.descriptionTemplates = descriptionTemplates;
}
@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));
rootElement.setAttribute("hasTemplates", String.valueOf(this.hasTemplates));
List<FieldEntity> temp = this.fields.stream().filter(f -> f.getCategory().equals(DmpBlueprintFieldCategory.System)).collect(Collectors.toList());
List<SystemFieldEntity> systemFieldsList = temp.stream().map(x-> (SystemFieldEntity)x).collect(Collectors.toList());
Element systemFields = doc.createElement("systemFields");
for (SystemFieldEntity systemField : systemFieldsList) {
systemFields.appendChild(systemField.toXml(doc));
}
rootElement.appendChild(systemFields);
if (this.descriptionTemplates != null) {
Element descriptionTemplates = doc.createElement("descriptionTemplates");
for (DescriptionTemplateEntity descriptionTemplate : this.descriptionTemplates) {
descriptionTemplates.appendChild(descriptionTemplate.toXml(doc));
}
rootElement.appendChild(descriptionTemplates);
}
temp = this.fields.stream().filter(f -> f.getCategory().equals(DmpBlueprintFieldCategory.Extra)).collect(Collectors.toList());
List<ExtraFieldEntity> extraFieldList = temp.stream().map(x-> (ExtraFieldEntity)x).collect(Collectors.toList());
Element extraFields = doc.createElement("extraFields");
for (ExtraFieldEntity extraField : extraFieldList) {
extraFields.appendChild(extraField.toXml(doc));
}
rootElement.appendChild(extraFields);
return rootElement;
}
@Override
public SectionEntity 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.hasTemplates = Boolean.valueOf(item.getAttribute("hasTemplates"));
this.fields = 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.fields.add(new SystemFieldEntity().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 DescriptionTemplateEntity().fromXml((Element) descriptionTemplateElement));
}
}
}
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.fields.add(new ExtraFieldEntity().fromXml((Element) extraFieldElement));
}
}
}
return this;
}
}

View File

@ -23,17 +23,4 @@ public class SystemFieldEntity extends FieldEntity {
public void setType(DmpBlueprintSystemFieldType type) {
this.type = type;
}
@Override
public Element appendXmlChild(Element rootElement) {
rootElement.setAttribute("type", String.valueOf(this.type.getValue()));
return rootElement;
}
@Override
public SystemFieldEntity fromXmlChild(Element item) {
this.type = DmpBlueprintSystemFieldType.of(Short.parseShort(item.getAttribute("type")));
this.setCategory(DmpBlueprintFieldCategory.System);
return this;
}
}

View File

@ -1928,7 +1928,7 @@ public class DataManagementPlanManager {
Element extraFields = xmlDoc.createElement("extraFields");
Map<String, Object> dmpProperties = new ObjectMapper().readValue(dmp.getProperties(), new TypeReference<Map<String, Object>>() {});
DefinitionEntity blueprint = new DefinitionEntity().fromXml(XmlBuilder.fromXml(this.queryFactory.query(DmpBlueprintQuery.class).ids(dmp.getBlueprintId()).first().getDefinition()).getDocumentElement());
DefinitionEntity blueprint = new DefinitionEntity(); //new DefinitionEntity().fromXml(XmlBuilder.fromXml(this.queryFactory.query(DmpBlueprintQuery.class).ids(dmp.getBlueprintId()).first().getDefinition()).getDocumentElement());
blueprint.getSections().forEach(section -> {
section.getFields().forEach(fieldModel -> {