diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/enums/DmpBlueprintFieldCategory.java b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/DmpBlueprintFieldCategory.java index 787a5cbbf..032d476e8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/enums/DmpBlueprintFieldCategory.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/DmpBlueprintFieldCategory.java @@ -9,6 +9,11 @@ public enum DmpBlueprintFieldCategory implements DatabaseEnum { 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) { diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/DefinitionEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/DefinitionEntity.java index 7525006bf..26c80a43f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/DefinitionEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/DefinitionEntity.java @@ -13,7 +13,7 @@ import java.util.List; @XmlRootElement(name = "root") @XmlAccessorType(XmlAccessType.FIELD) -public class DefinitionEntity implements XmlSerializable { +public class DefinitionEntity { @XmlElementWrapper(name = "sections") @XmlElement(name = "section") private List sections; @@ -24,32 +24,4 @@ public class DefinitionEntity implements XmlSerializable { public void setSections(List 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; - } - } diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/DescriptionTemplateEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/DescriptionTemplateEntity.java index d2421c670..eb1db220b 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/DescriptionTemplateEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/DescriptionTemplateEntity.java @@ -10,7 +10,7 @@ import org.w3c.dom.Element; import java.util.UUID; @XmlAccessorType(XmlAccessType.FIELD) -public class DescriptionTemplateEntity implements XmlSerializable { +public class DescriptionTemplateEntity { @XmlAttribute(name="descriptionTemplateGroupId") private UUID descriptionTemplateGroupId; @@ -50,22 +50,4 @@ public class DescriptionTemplateEntity implements XmlSerializable { +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 { 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; - } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/SectionEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/SectionEntity.java index 50d6c1e59..a1dd62736 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/SectionEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/SectionEntity.java @@ -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 { +public class SectionEntity { @XmlAttribute(name="id") private UUID id; @@ -29,9 +33,13 @@ public class SectionEntity implements XmlSerializable { @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 fields; - + @XmlAttribute(name="hasTemplates") private Boolean hasTemplates; @@ -88,78 +96,4 @@ public class SectionEntity implements XmlSerializable { 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 temp = this.fields.stream().filter(f -> f.getCategory().equals(DmpBlueprintFieldCategory.System)).collect(Collectors.toList()); - List 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 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; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/SystemFieldEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/SystemFieldEntity.java index 6787af8d2..52a6a312f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/SystemFieldEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/SystemFieldEntity.java @@ -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; - } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java index 7071a0afa..e2930155d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java @@ -1928,7 +1928,7 @@ public class DataManagementPlanManager { Element extraFields = xmlDoc.createElement("extraFields"); Map dmpProperties = new ObjectMapper().readValue(dmp.getProperties(), new TypeReference>() {}); - 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 -> {