From 732dfd9bfb8938a1956602ab34d2120e75bed0e4 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Thu, 2 Nov 2023 14:13:13 +0200 Subject: [PATCH] DmpBlueprint feractor --- .../importexport/BlueprintImportExport.java | 22 ++ .../importexport/DefinitionImportExport.java | 21 ++ .../DescriptionTemplateImportExport.java} | 41 ++-- .../ExtraFieldImportExport.java} | 55 ++--- .../importexport/SectionImportExport.java | 94 +++++++ .../SystemFieldImportExport.java} | 57 ++--- .../importmodel/DescriptionTemplates.java | 21 -- .../importmodel/DmpBlueprint.java | 25 -- .../importmodel/DmpBlueprintDefinition.java | 37 --- .../dmpblueprint/importmodel/ExtraFields.java | 21 -- .../dmpblueprint/importmodel/Section.java | 127 ---------- .../dmpblueprint/importmodel/Sections.java | 20 -- .../importmodel/SystemFields.java | 21 -- .../dmpblueprint/DmpBlueprintService.java | 2 +- .../dmpblueprint/DmpBlueprintServiceImpl.java | 232 +++++++++++++++--- .../v2/DmpBlueprintController.java | 2 +- 16 files changed, 390 insertions(+), 408 deletions(-) create mode 100644 dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/BlueprintImportExport.java create mode 100644 dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/DefinitionImportExport.java rename dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/{importmodel/DescriptionTemplate.java => importexport/DescriptionTemplateImportExport.java} (61%) rename dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/{importmodel/ExtraField.java => importexport/ExtraFieldImportExport.java} (60%) create mode 100644 dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/SectionImportExport.java rename dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/{importmodel/SystemField.java => importexport/SystemFieldImportExport.java} (60%) delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/DescriptionTemplates.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/DmpBlueprint.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/DmpBlueprintDefinition.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/ExtraFields.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/Section.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/Sections.java delete mode 100644 dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/SystemFields.java diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/BlueprintImportExport.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/BlueprintImportExport.java new file mode 100644 index 000000000..5f55ecb67 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/BlueprintImportExport.java @@ -0,0 +1,22 @@ +package eu.eudat.commons.types.dmpblueprint.importexport; + +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "root") +@XmlAccessorType(XmlAccessType.FIELD) +public class BlueprintImportExport { + + @XmlElement(name = "definition") + private DefinitionImportExport dmpBlueprintDefinition; + + public DefinitionImportExport getDmpBlueprintDefinition() { + return dmpBlueprintDefinition; + } + + public void setDmpBlueprintDefinition(DefinitionImportExport dmpBlueprintDefinition) { + this.dmpBlueprintDefinition = dmpBlueprintDefinition; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/DefinitionImportExport.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/DefinitionImportExport.java new file mode 100644 index 000000000..63c1fad34 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/DefinitionImportExport.java @@ -0,0 +1,21 @@ +package eu.eudat.commons.types.dmpblueprint.importexport; + +import jakarta.xml.bind.annotation.*; + +import java.util.List; + +@XmlAccessorType(XmlAccessType.FIELD) +public class DefinitionImportExport { + + @XmlElementWrapper(name = "sections") + @XmlElement(name = "section") + private List sections; + + public List getSections() { + return sections; + } + + public void setSections(List sections) { + this.sections = sections; + } +} \ No newline at end of file diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/DescriptionTemplate.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/DescriptionTemplateImportExport.java similarity index 61% rename from dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/DescriptionTemplate.java rename to dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/DescriptionTemplateImportExport.java index 4548dc3a1..0691e6a9c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/DescriptionTemplate.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/DescriptionTemplateImportExport.java @@ -1,21 +1,23 @@ -package eu.eudat.commons.types.dmpblueprint.importmodel; +package eu.eudat.commons.types.dmpblueprint.importexport; -import eu.eudat.commons.types.dmpblueprint.DescriptionTemplateEntity; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlAttribute; -import jakarta.xml.bind.annotation.XmlRootElement; -import java.util.UUID; - -@XmlRootElement(name = "descriptionTemplate") -public class DescriptionTemplate { - - private String id; - private String descriptionTemplateId; - private String label; - private int minMultiplicity; - private int maxMultiplicity; +@XmlAccessorType(XmlAccessType.FIELD) +public class DescriptionTemplateImportExport { @XmlAttribute(name = "id") + private String id; + @XmlAttribute(name = "descriptionTemplateId") + private String descriptionTemplateId; + @XmlAttribute(name = "label") + private String label; + @XmlAttribute(name = "minMultiplicity") + private int minMultiplicity; + @XmlAttribute(name = "maxMultiplicity") + private int maxMultiplicity; + public String getId() { return id; } @@ -24,7 +26,6 @@ public class DescriptionTemplate { this.id = id; } - @XmlAttribute(name = "descriptionTemplateId") public String getDescriptionTemplateId() { return descriptionTemplateId; } @@ -33,7 +34,6 @@ public class DescriptionTemplate { this.descriptionTemplateId = descriptionTemplateId; } - @XmlAttribute(name = "label") public String getLabel() { return label; } @@ -42,7 +42,6 @@ public class DescriptionTemplate { this.label = label; } - @XmlAttribute(name = "minMultiplicity") public int getMinMultiplicity() { return minMultiplicity; } @@ -51,7 +50,6 @@ public class DescriptionTemplate { this.minMultiplicity = minMultiplicity; } - @XmlAttribute(name = "maxMultiplicity") public int getMaxMultiplicity() { return maxMultiplicity; } @@ -60,14 +58,5 @@ public class DescriptionTemplate { this.maxMultiplicity = maxMultiplicity; } - public DescriptionTemplateEntity toEntity() { - DescriptionTemplateEntity descriptionTemplate = new DescriptionTemplateEntity(); - descriptionTemplate.setId(UUID.fromString(this.id)); - descriptionTemplate.setDescriptionTemplateId(UUID.fromString(this.descriptionTemplateId)); - descriptionTemplate.setLabel(this.label); - descriptionTemplate.setMinMultiplicity(this.minMultiplicity); - descriptionTemplate.setMaxMultiplicity(this.maxMultiplicity); - return descriptionTemplate; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/ExtraField.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/ExtraFieldImportExport.java similarity index 60% rename from dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/ExtraField.java rename to dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/ExtraFieldImportExport.java index 1f8f0e4b4..9208d4142 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/ExtraField.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/ExtraFieldImportExport.java @@ -1,26 +1,27 @@ -package eu.eudat.commons.types.dmpblueprint.importmodel; +package eu.eudat.commons.types.dmpblueprint.importexport; -import eu.eudat.commons.enums.DmpBlueprintExtraFieldDataType; -import eu.eudat.commons.enums.DmpBlueprintFieldCategory; -import eu.eudat.commons.types.dmpblueprint.ExtraFieldEntity; -import eu.eudat.commons.types.dmpblueprint.FieldEntity; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlAttribute; -import jakarta.xml.bind.annotation.XmlRootElement; -import java.util.UUID; - -@XmlRootElement(name = "extraField") -public class ExtraField { - - private String id; - private short type; - private String label; - private String placeholder; - private String description; - private int ordinal; - private boolean required; +@XmlAccessorType(XmlAccessType.FIELD) +public class ExtraFieldImportExport { @XmlAttribute(name = "id") + private String id; + @XmlAttribute(name = "type") + private short type; + @XmlAttribute(name = "label") + private String label; + @XmlAttribute(name = "placeholder") + private String placeholder; + @XmlAttribute(name = "description") + private String description; + @XmlAttribute(name = "ordinal") + private int ordinal; + @XmlAttribute(name = "required") + private boolean required; + public String getId() { return id; } @@ -29,7 +30,6 @@ public class ExtraField { this.id = id; } - @XmlAttribute(name = "type") public short getType() { return type; } @@ -38,7 +38,6 @@ public class ExtraField { this.type = type; } - @XmlAttribute(name = "label") public String getLabel() { return label; } @@ -47,7 +46,6 @@ public class ExtraField { this.label = label; } - @XmlAttribute(name = "placeholder") public String getPlaceholder() { return placeholder; } @@ -56,7 +54,6 @@ public class ExtraField { this.placeholder = placeholder; } - @XmlAttribute(name = "description") public String getDescription() { return description; } @@ -65,7 +62,6 @@ public class ExtraField { this.description = description; } - @XmlAttribute(name = "ordinal") public int getOrdinal() { return ordinal; } @@ -74,7 +70,6 @@ public class ExtraField { this.ordinal = ordinal; } - @XmlAttribute(name = "required") public boolean isRequired() { return required; } @@ -83,17 +78,5 @@ public class ExtraField { this.required = required; } - public FieldEntity toEntity() { - ExtraFieldEntity systemField = new ExtraFieldEntity(); - systemField.setId(UUID.fromString(this.id)); - systemField.setCategory(DmpBlueprintFieldCategory.Extra); - systemField.setType(DmpBlueprintExtraFieldDataType.of(this.type)); - systemField.setLabel(this.label); - systemField.setPlaceholder(this.placeholder); - systemField.setDescription(this.description); - systemField.setOrdinal(this.ordinal); - systemField.setRequired(this.required); - return systemField; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/SectionImportExport.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/SectionImportExport.java new file mode 100644 index 000000000..2a0d7c01f --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/SectionImportExport.java @@ -0,0 +1,94 @@ +package eu.eudat.commons.types.dmpblueprint.importexport; + +import jakarta.xml.bind.annotation.*; + +import java.util.List; + +@XmlAccessorType(XmlAccessType.FIELD) +public class SectionImportExport { + + @XmlAttribute(name = "id") + private String id; + @XmlAttribute(name = "label") + private String label; + @XmlAttribute(name = "description") + private String description; + @XmlAttribute(name = "ordinal") + private int ordinal; + @XmlElementWrapper(name = "systemFields") + @XmlElement(name = "systemField") + private List systemFields; + @XmlElementWrapper(name = "extraFields") + @XmlElement(name = "extraField") + private List extraFields; + @XmlAttribute(name = "hasTemplates") + private boolean hasTemplates; + @XmlElementWrapper(name = "descriptionTemplates") + @XmlElement(name = "descriptionTemplate") + private List descriptionTemplates; + + public String getId() { + return id; + } + + public void setId(String 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 int getOrdinal() { + return ordinal; + } + + public void setOrdinal(int ordinal) { + this.ordinal = ordinal; + } + + public List getSystemFields() { + return systemFields; + } + + public void setSystemFields(List systemFields) { + this.systemFields = systemFields; + } + + public List getExtraFields() { + return extraFields; + } + + public void setExtraFields(List extraFields) { + this.extraFields = extraFields; + } + + public boolean isHasTemplates() { + return hasTemplates; + } + + public void setHasTemplates(boolean hasTemplates) { + this.hasTemplates = hasTemplates; + } + + public List getDescriptionTemplates() { + return descriptionTemplates; + } + + public void setDescriptionTemplates(List descriptionTemplates) { + this.descriptionTemplates = descriptionTemplates; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/SystemField.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/SystemFieldImportExport.java similarity index 60% rename from dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/SystemField.java rename to dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/SystemFieldImportExport.java index 20298186d..4116e52bb 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/SystemField.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importexport/SystemFieldImportExport.java @@ -1,26 +1,27 @@ -package eu.eudat.commons.types.dmpblueprint.importmodel; +package eu.eudat.commons.types.dmpblueprint.importexport; -import eu.eudat.commons.enums.DmpBlueprintFieldCategory; -import eu.eudat.commons.enums.DmpBlueprintSystemFieldType; -import eu.eudat.commons.types.dmpblueprint.FieldEntity; -import eu.eudat.commons.types.dmpblueprint.SystemFieldEntity; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlAttribute; -import jakarta.xml.bind.annotation.XmlRootElement; -import java.util.UUID; - -@XmlRootElement(name = "systemField") -public class SystemField { - - private String id; - private short type; - private String label; - private String placeholder; - private String description; - private int ordinal; - private boolean required; +@XmlAccessorType(XmlAccessType.FIELD) +public class SystemFieldImportExport { @XmlAttribute(name = "id") + private String id; + @XmlAttribute(name = "type") + private short type; + @XmlAttribute(name = "label") + private String label; + @XmlAttribute(name = "placeholder") + private String placeholder; + @XmlAttribute(name = "description") + private String description; + @XmlAttribute(name = "ordinal") + private int ordinal; + @XmlAttribute(name = "required") + private boolean required; + public String getId() { return id; } @@ -29,7 +30,6 @@ public class SystemField { this.id = id; } - @XmlAttribute(name = "type") public short getType() { return type; } @@ -38,7 +38,6 @@ public class SystemField { this.type = type; } - @XmlAttribute(name = "label") public String getLabel() { return label; } @@ -47,7 +46,6 @@ public class SystemField { this.label = label; } - @XmlAttribute(name = "placeholder") public String getPlaceholder() { return placeholder; } @@ -56,7 +54,6 @@ public class SystemField { this.placeholder = placeholder; } - @XmlAttribute(name = "description") public String getDescription() { return description; } @@ -65,7 +62,6 @@ public class SystemField { this.description = description; } - @XmlAttribute(name = "ordinal") public int getOrdinal() { return ordinal; } @@ -74,7 +70,6 @@ public class SystemField { this.ordinal = ordinal; } - @XmlAttribute(name = "required") public boolean isRequired() { return required; } @@ -82,18 +77,4 @@ public class SystemField { public void setRequired(boolean required) { this.required = required; } - - public FieldEntity toEntity() { - SystemFieldEntity systemField = new SystemFieldEntity(); - systemField.setId(UUID.fromString(this.id)); - systemField.setCategory(DmpBlueprintFieldCategory.System); - systemField.setType(DmpBlueprintSystemFieldType.of(this.type)); - systemField.setLabel(this.label); - systemField.setPlaceholder(this.placeholder); - systemField.setDescription(this.description); - systemField.setOrdinal(this.ordinal); - systemField.setRequired(this.required); - return systemField; - } - } diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/DescriptionTemplates.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/DescriptionTemplates.java deleted file mode 100644 index 78f004632..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/DescriptionTemplates.java +++ /dev/null @@ -1,21 +0,0 @@ -package eu.eudat.commons.types.dmpblueprint.importmodel; - -import jakarta.xml.bind.annotation.XmlElement; -import jakarta.xml.bind.annotation.XmlRootElement; - -import java.util.List; - -@XmlRootElement(name = "descriptionTemplates") -public class DescriptionTemplates { - - private List descriptionTemplates; - - @XmlElement(name = "descriptionTemplate") - public List getDescriptionTemplates() { - return descriptionTemplates; - } - public void setDescriptionTemplates(List descriptionTemplates) { - this.descriptionTemplates = descriptionTemplates; - } - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/DmpBlueprint.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/DmpBlueprint.java deleted file mode 100644 index ff1ceec2b..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/DmpBlueprint.java +++ /dev/null @@ -1,25 +0,0 @@ -package eu.eudat.commons.types.dmpblueprint.importmodel; - -import eu.eudat.commons.types.dmpblueprint.DefinitionEntity; -import jakarta.xml.bind.annotation.XmlElement; -import jakarta.xml.bind.annotation.XmlRootElement; - -@XmlRootElement(name = "root") -public class DmpBlueprint { - - private DmpBlueprintDefinition dmpBlueprintDefinition; - - @XmlElement(name = "definition") - public DmpBlueprintDefinition getDmpBlueprintDefinition() { - return dmpBlueprintDefinition; - } - - public void setDmpBlueprintDefinition(DmpBlueprintDefinition dmpBlueprintDefinition) { - this.dmpBlueprintDefinition = dmpBlueprintDefinition; - } - - public DefinitionEntity toDefinitionEntity() { - return this.dmpBlueprintDefinition.toEntity(); - } - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/DmpBlueprintDefinition.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/DmpBlueprintDefinition.java deleted file mode 100644 index d16a0f5a1..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/DmpBlueprintDefinition.java +++ /dev/null @@ -1,37 +0,0 @@ -package eu.eudat.commons.types.dmpblueprint.importmodel; - -import eu.eudat.commons.types.dmpblueprint.DefinitionEntity; -import eu.eudat.commons.types.dmpblueprint.SectionEntity; -import jakarta.xml.bind.annotation.XmlElement; -import jakarta.xml.bind.annotation.XmlRootElement; - -import java.util.LinkedList; -import java.util.List; - -@XmlRootElement(name = "definition") -public class DmpBlueprintDefinition { - - private Sections sections; - - @XmlElement(name = "sections") - public Sections getSections() { - return sections; - } - public void setSections(Sections sections) { - this.sections = sections; - } - - - public DefinitionEntity toEntity() { - DefinitionEntity dmpBlueprint = new DefinitionEntity(); - List dmpBlueprintSections = new LinkedList<>(); - if (this.sections != null && this.sections.getSections() != null) { - for (Section section : this.sections.getSections()) { - dmpBlueprintSections.add(section.toEntity()); - } - } - dmpBlueprint.setSections(dmpBlueprintSections); - return dmpBlueprint; - } - -} \ No newline at end of file diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/ExtraFields.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/ExtraFields.java deleted file mode 100644 index 56d23bfd0..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/ExtraFields.java +++ /dev/null @@ -1,21 +0,0 @@ -package eu.eudat.commons.types.dmpblueprint.importmodel; - -import jakarta.xml.bind.annotation.XmlElement; -import jakarta.xml.bind.annotation.XmlRootElement; - -import java.util.List; - -@XmlRootElement(name = "extraFields") -public class ExtraFields { - - private List extraFields; - - @XmlElement(name = "extraField") - public List getExtraFields() { - return extraFields; - } - public void setExtraFields(List extraFields) { - this.extraFields = extraFields; - } - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/Section.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/Section.java deleted file mode 100644 index de8ad525b..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/Section.java +++ /dev/null @@ -1,127 +0,0 @@ -package eu.eudat.commons.types.dmpblueprint.importmodel; - -import eu.eudat.commons.types.dmpblueprint.DescriptionTemplateEntity; -import eu.eudat.commons.types.dmpblueprint.FieldEntity; -import eu.eudat.commons.types.dmpblueprint.SectionEntity; -import jakarta.xml.bind.annotation.XmlAttribute; -import jakarta.xml.bind.annotation.XmlElement; -import jakarta.xml.bind.annotation.XmlRootElement; - -import java.util.LinkedList; -import java.util.List; -import java.util.UUID; - -@XmlRootElement(name = "section") -public class Section { - - private String id; - private String label; - private String description; - private int ordinal; - private SystemFields systemFields; - private ExtraFields extraFields; - private boolean hasTemplates; - private DescriptionTemplates descriptionTemplates; - - @XmlAttribute(name = "id") - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - @XmlAttribute(name = "label") - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - - @XmlAttribute(name = "description") - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @XmlAttribute(name = "ordinal") - public int getOrdinal() { - return ordinal; - } - - public void setOrdinal(int ordinal) { - this.ordinal = ordinal; - } - - @XmlElement(name = "systemFields") - public SystemFields getSystemFields() { - return systemFields; - } - - public void setSystemFields(SystemFields systemFields) { - this.systemFields = systemFields; - } - - @XmlElement(name = "extraFields") - public ExtraFields getExtraFields() { - return extraFields; - } - - public void setExtraFields(ExtraFields extraFields) { - this.extraFields = extraFields; - } - - @XmlAttribute(name = "hasTemplates") - public boolean isHasTemplates() { - return hasTemplates; - } - - public void setHasTemplates(boolean hasTemplates) { - this.hasTemplates = hasTemplates; - } - - @XmlElement(name = "descriptionTemplates") - public DescriptionTemplates getDescriptionTemplates() { - return descriptionTemplates; - } - - public void setDescriptionTemplates(DescriptionTemplates descriptionTemplates) { - this.descriptionTemplates = descriptionTemplates; - } - - public SectionEntity toEntity() { - SectionEntity section = new SectionEntity(); - section.setId(UUID.fromString(this.id)); - section.setLabel(this.label); - section.setDescription(this.description); - section.setOrdinal(this.ordinal); - section.setHasTemplates(this.hasTemplates); - List dmpBlueprintFieldModels = new LinkedList<>(); - if (this.systemFields != null && this.systemFields.getSystemFields() != null) { - for (SystemField systemField : this.systemFields.getSystemFields()) { - dmpBlueprintFieldModels.add(systemField.toEntity()); - } - } - if (this.extraFields != null&& this.extraFields.getExtraFields() != null) { - for (ExtraField extraField : this.extraFields.getExtraFields()) { - dmpBlueprintFieldModels.add(extraField.toEntity()); - } - } - section.setFields(dmpBlueprintFieldModels); - List dmpBlueprintDescriptionTemplates = new LinkedList<>(); - if (this.descriptionTemplates != null && this.descriptionTemplates.getDescriptionTemplates() != null) { - for (DescriptionTemplate descriptionTemplate : this.descriptionTemplates.getDescriptionTemplates()) { - dmpBlueprintDescriptionTemplates.add(descriptionTemplate.toEntity()); - } - } - section.setDescriptionTemplates(dmpBlueprintDescriptionTemplates); - return section; - } - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/Sections.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/Sections.java deleted file mode 100644 index 4cb6f76c9..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/Sections.java +++ /dev/null @@ -1,20 +0,0 @@ -package eu.eudat.commons.types.dmpblueprint.importmodel; - -import jakarta.xml.bind.annotation.XmlElement; -import jakarta.xml.bind.annotation.XmlRootElement; - -import java.util.List; - -@XmlRootElement(name = "sections") -public class Sections { - - private List
sections; - - @XmlElement(name = "section") - public List
getSections() { - return sections; - } - public void setSections(List
sections) { - this.sections = sections; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/SystemFields.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/SystemFields.java deleted file mode 100644 index 87bb14ec3..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmpblueprint/importmodel/SystemFields.java +++ /dev/null @@ -1,21 +0,0 @@ -package eu.eudat.commons.types.dmpblueprint.importmodel; - -import jakarta.xml.bind.annotation.XmlElement; -import jakarta.xml.bind.annotation.XmlRootElement; - -import java.util.List; - -@XmlRootElement(name = "systemFields") -public class SystemFields { - - private List systemFields; - - @XmlElement(name = "systemField") - public List getSystemFields() { - return systemFields; - } - public void setSystemFields(List systemFields) { - this.systemFields = systemFields; - } - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintService.java b/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintService.java index b31b77718..84709a41f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintService.java @@ -31,6 +31,6 @@ public interface DmpBlueprintService { DmpBlueprint buildClone(UUID id, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException; - ResponseEntity exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, TransformerException; + ResponseEntity exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, TransformerException, InvalidApplicationException; DmpBlueprint importXml(byte[] bytes, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintServiceImpl.java index 18104f03e..a3e16df93 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintServiceImpl.java @@ -4,11 +4,9 @@ import com.fasterxml.jackson.core.JsonProcessingException; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.Permission; import eu.eudat.commons.XmlHandlingService; -import eu.eudat.commons.enums.DmpBlueprintFieldCategory; -import eu.eudat.commons.enums.DmpBlueprintStatus; -import eu.eudat.commons.enums.DmpBlueprintSystemFieldType; -import eu.eudat.commons.enums.IsActive; +import eu.eudat.commons.enums.*; import eu.eudat.commons.types.dmpblueprint.*; +import eu.eudat.commons.types.dmpblueprint.importexport.*; import eu.eudat.convention.ConventionService; import eu.eudat.data.DmpBlueprintEntity; import eu.eudat.errorcode.ErrorThesaurusProperties; @@ -35,6 +33,7 @@ import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry; +import gr.cite.tools.validation.ValidationService; import jakarta.persistence.EntityManager; import jakarta.xml.bind.JAXBException; import org.jetbrains.annotations.NotNull; @@ -44,8 +43,6 @@ import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; -import org.w3c.dom.Document; -import org.w3c.dom.Element; import org.xml.sax.SAXException; import javax.management.InvalidApplicationException; @@ -55,6 +52,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import java.util.UUID; @@ -77,6 +75,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { private final ResponseUtilsService responseUtilsService; private final XmlHandlingService xmlHandlingService; private final ErrorThesaurusProperties errors; + private final ValidationService validationService; @Autowired public DmpBlueprintServiceImpl( @@ -86,7 +85,10 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { BuilderFactory builderFactory, ConventionService conventionService, MessageSource messageSource, QueryFactory queryFactory, - ResponseUtilsService responseUtilsService, XmlHandlingService xmlHandlingService, ErrorThesaurusProperties errors) { + ResponseUtilsService responseUtilsService, + XmlHandlingService xmlHandlingService, + ErrorThesaurusProperties errors, + ValidationService validationService) { this.entityManager = entityManager; this.authorizationService = authorizationService; this.deleterFactory = deleterFactory; @@ -97,8 +99,11 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { this.responseUtilsService = responseUtilsService; this.xmlHandlingService = xmlHandlingService; this.errors = errors; + this.validationService = validationService; } + //region Persist + public DmpBlueprint persist(DmpBlueprintPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, JsonProcessingException, TransformerException, ParserConfigurationException { logger.debug(new MapLogEntry("persisting data").And("model", model).And("fields", fields)); @@ -143,7 +148,6 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { return data; } - private @NotNull SectionEntity buildSectionEntity(SectionPersist persist){ SectionEntity data = new SectionEntity(); if (persist == null) return data; @@ -206,6 +210,10 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { return data; } + //endregion + + //region Delete + public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException { logger.debug("deleting : {}", id); @@ -214,6 +222,10 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { this.deleterFactory.deleter(DmpBlueprintDeleter.class).deleteAndSaveByIds(List.of(id)); } + //endregion + + //region FieldInBlueprint + public boolean fieldInBlueprint(DmpBlueprintEntity dmpBlueprintEntity, DmpBlueprintSystemFieldType type) { DefinitionEntity definition = this.xmlHandlingService.fromXmlSafe(DefinitionEntity.class, dmpBlueprintEntity.getDefinition()); @@ -239,6 +251,10 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { return this.fieldInBlueprint(data, type); } + //endregion + + //region Clone + public DmpBlueprint buildClone(UUID id, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException { logger.debug(new MapLogEntry("persisting data").And("id", id).And("fields", fields)); @@ -293,7 +309,11 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { model.setId(UUID.randomUUID()); } - public ResponseEntity exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, TransformerException { + //endregion + + //region Export + + public ResponseEntity exportXml(UUID id) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, SAXException, TransformerException, InvalidApplicationException { logger.debug(new MapLogEntry("persisting data").And("id", id)); this.authorizationService.authorizeForce(Permission.ExportDmpBlueprint); @@ -301,45 +321,189 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale())); DefinitionEntity dmpDefinition = this.xmlHandlingService.fromXml(DefinitionEntity.class, data.getDefinition()); - String xml = this.buildExportXml(dmpDefinition); + String xml = this.xmlHandlingService.toXml(this.definitionXmlToExport(dmpDefinition)); return this.responseUtilsService.buildResponseFileFromText(xml, data.getLabel() + ".xml"); } - private String buildExportXml(DefinitionEntity dmpDefinition) throws TransformerException, ParserConfigurationException { - Document xmlDoc = this.xmlHandlingService.getDocument(); - Element root = xmlDoc.createElement("root"); - Element definition = xmlDoc.createElement("definition"); - Element sections = xmlDoc.createElement("sections"); - for (SectionEntity section : dmpDefinition.getSections()) { - sections.appendChild(section.toXml(xmlDoc)); + private DefinitionImportExport definitionXmlToExport(DefinitionEntity entity){ + if (entity == null) return null; + DefinitionImportExport xml = new DefinitionImportExport(); + List dmpBlueprintSections = new ArrayList<>(); + if (!this.conventionService.isListNullOrEmpty(entity.getSections())) { + for (SectionEntity section : entity.getSections()) { + dmpBlueprintSections.add(this.sectionXmlToExport(section)); + } } - definition.appendChild(sections); - root.appendChild(definition); - xmlDoc.appendChild(root); - return this.xmlHandlingService.generateXml(xmlDoc); + xml.setSections(dmpBlueprintSections); + return xml; } + private SectionImportExport sectionXmlToExport(SectionEntity entity) { + SectionImportExport xml = new SectionImportExport(); + xml.setId(entity.getId().toString()); + xml.setLabel(entity.getLabel()); + xml.setDescription(entity.getDescription()); + xml.setOrdinal(entity.getOrdinal()); + xml.setHasTemplates(entity.getHasTemplates()); + List dmpBlueprintSystemFieldModels = new LinkedList<>(); + if (!this.conventionService.isListNullOrEmpty(entity.getFields())) { + for (SystemFieldEntity systemField : entity.getFields().stream().filter(x-> x.getCategory() == DmpBlueprintFieldCategory.System).map(x-> (SystemFieldEntity)x).toList()) { + dmpBlueprintSystemFieldModels.add(this.systemFieldXmlToExport(systemField)); + } + } + xml.setSystemFields(dmpBlueprintSystemFieldModels); + List dmpBlueprintExtraFieldModels = new LinkedList<>(); + if (!this.conventionService.isListNullOrEmpty(entity.getFields())) { + for (ExtraFieldEntity systemField : entity.getFields().stream().filter(x-> x.getCategory() == DmpBlueprintFieldCategory.Extra).map(x-> (ExtraFieldEntity)x).toList()) { + dmpBlueprintExtraFieldModels.add(this.extraFieldXmlToExport(systemField)); + } + } + xml.setExtraFields(dmpBlueprintExtraFieldModels); + + List dmpBlueprintDescriptionTemplates = new LinkedList<>(); + if (!this.conventionService.isListNullOrEmpty(entity.getDescriptionTemplates())) { + for (DescriptionTemplateEntity descriptionTemplate : entity.getDescriptionTemplates()) { + dmpBlueprintDescriptionTemplates.add(this.descriptionTemplateXmlToExport(descriptionTemplate)); + } + } + xml.setDescriptionTemplates(dmpBlueprintDescriptionTemplates); + return xml; + } + + private DescriptionTemplateImportExport descriptionTemplateXmlToExport(DescriptionTemplateEntity entity) { + DescriptionTemplateImportExport xml = new DescriptionTemplateImportExport(); + xml.setId(entity.getId().toString()); + xml.setDescriptionTemplateId(entity.getDescriptionTemplateId().toString()); + xml.setLabel(entity.getLabel()); + xml.setMinMultiplicity(entity.getMinMultiplicity()); + xml.setMaxMultiplicity(entity.getMaxMultiplicity()); + return xml; + } + + private ExtraFieldImportExport extraFieldXmlToExport(ExtraFieldEntity entity) { + ExtraFieldImportExport xml = new ExtraFieldImportExport(); + xml.setId(entity.getId().toString()); + xml.setType(entity.getType().getValue()); + xml.setLabel(entity.getLabel()); + xml.setPlaceholder(entity.getPlaceholder()); + xml.setDescription(entity.getDescription()); + xml.setOrdinal(entity.getOrdinal()); + xml.setRequired(entity.isRequired()); + return xml; + } + + private SystemFieldImportExport systemFieldXmlToExport(SystemFieldEntity entity) { + SystemFieldImportExport xml = new SystemFieldImportExport(); + xml.setId(entity.getId().toString()); + xml.setType(entity.getType().getValue()); + xml.setLabel(entity.getLabel()); + xml.setPlaceholder(entity.getPlaceholder()); + xml.setDescription(entity.getDescription()); + xml.setOrdinal(entity.getOrdinal()); + xml.setRequired(entity.isRequired()); + return xml; + } + + + //endregion + + //region Import + public DmpBlueprint importXml(byte[] bytes, String label, FieldSet fields) throws MyForbiddenException, MyNotFoundException, JAXBException, ParserConfigurationException, TransformerException, InvalidApplicationException, IOException, InstantiationException, IllegalAccessException, SAXException { logger.debug(new MapLogEntry("import data").And("bytes", bytes).And("label", label).And("fields", fields)); this.authorizationService.authorizeForce(Permission.ImportDmpBlueprint); - eu.eudat.commons.types.dmpblueprint.importmodel.DmpBlueprint dmpDefinition = this.xmlHandlingService.fromXml(eu.eudat.commons.types.dmpblueprint.importmodel.DmpBlueprint.class, new String(bytes, StandardCharsets.UTF_8)); - DmpBlueprintEntity data = new DmpBlueprintEntity(); - data.setId(UUID.randomUUID()); - data.setIsActive(IsActive.Active); - data.setCreatedAt(Instant.now()); + DmpBlueprintPersist persist = new DmpBlueprintPersist(); - data.setLabel(label); - data.setStatus(DmpBlueprintStatus.Draft); - data.setUpdatedAt(Instant.now()); - data.setDefinition(this.xmlHandlingService.toXml(dmpDefinition.toDefinitionEntity())); + persist.setLabel(label); + persist.setStatus(DmpBlueprintStatus.Draft); - this.entityManager.persist(data); + BlueprintImportExport dmpDefinition = this.xmlHandlingService.fromXml(BlueprintImportExport.class, new String(bytes, StandardCharsets.UTF_8)); + if(dmpDefinition != null) persist.setDefinition(this.xmlDefinitionToPersist(dmpDefinition.getDmpBlueprintDefinition())); - this.entityManager.flush(); - - return this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(BaseFieldSet.build(fields, DmpBlueprint._id), data); + this.validationService.validateForce(persist); + return this.persist(persist, fields); } + + private DefinitionPersist xmlDefinitionToPersist(DefinitionImportExport importXml){ + if (importXml == null) return null; + DefinitionPersist persist = new DefinitionPersist(); + List dmpBlueprintSections = new ArrayList<>(); + if (!this.conventionService.isListNullOrEmpty(importXml.getSections())) { + for (SectionImportExport section : importXml.getSections()) { + dmpBlueprintSections.add(this.xmlSectionToPersist(section)); + } + } + persist.setSections(dmpBlueprintSections); + return persist; + } + + private SectionPersist xmlSectionToPersist(SectionImportExport importXml) { + SectionPersist persist = new SectionPersist(); + persist.setId(UUID.fromString(importXml.getId())); + persist.setLabel(importXml.getLabel()); + persist.setDescription(importXml.getDescription()); + persist.setOrdinal(importXml.getOrdinal()); + persist.setHasTemplates(importXml.isHasTemplates()); + List dmpBlueprintFieldModels = new LinkedList<>(); + if (!this.conventionService.isListNullOrEmpty(importXml.getSystemFields())) { + for (SystemFieldImportExport systemField : importXml.getSystemFields()) { + dmpBlueprintFieldModels.add(this.xmlSystemFieldToPersist(systemField)); + } + } + if (!this.conventionService.isListNullOrEmpty(importXml.getExtraFields())) { + for (ExtraFieldImportExport extraField : importXml.getExtraFields()) { + dmpBlueprintFieldModels.add(this.xmlExtraFieldToPersist(extraField)); + } + } + persist.setFields(dmpBlueprintFieldModels); + List dmpBlueprintDescriptionTemplates = new LinkedList<>(); + if (!this.conventionService.isListNullOrEmpty(importXml.getDescriptionTemplates())) { + for (DescriptionTemplateImportExport descriptionTemplate : importXml.getDescriptionTemplates()) { + dmpBlueprintDescriptionTemplates.add(this.xmlDescriptionTemplateToPersist(descriptionTemplate)); + } + } + persist.setDescriptionTemplates(dmpBlueprintDescriptionTemplates); + return persist; + } + + private DescriptionTemplatePersist xmlDescriptionTemplateToPersist(DescriptionTemplateImportExport importXml) { + DescriptionTemplatePersist persist = new DescriptionTemplatePersist(); + persist.setId(UUID.fromString(importXml.getId())); + persist.setDescriptionTemplateId(UUID.fromString(importXml.getDescriptionTemplateId())); + persist.setLabel(importXml.getLabel()); + persist.setMinMultiplicity(importXml.getMinMultiplicity()); + persist.setMaxMultiplicity(importXml.getMaxMultiplicity()); + return persist; + } + + private FieldPersist xmlExtraFieldToPersist(ExtraFieldImportExport importXml) { + ExtraFieldPersist persist = new ExtraFieldPersist(); + persist.setId(UUID.fromString(importXml.getId())); + persist.setCategory(DmpBlueprintFieldCategory.Extra); + persist.setDataType(DmpBlueprintExtraFieldDataType.of(importXml.getType())); + persist.setLabel(importXml.getLabel()); + persist.setPlaceholder(importXml.getPlaceholder()); + persist.setDescription(importXml.getDescription()); + persist.setOrdinal(importXml.getOrdinal()); + persist.setRequired(importXml.isRequired()); + return persist; + } + + private FieldPersist xmlSystemFieldToPersist(SystemFieldImportExport importXml) { + SystemFieldPersist persist = new SystemFieldPersist(); + persist.setId(UUID.fromString(importXml.getId())); + persist.setCategory(DmpBlueprintFieldCategory.System); + persist.setSystemFieldType(DmpBlueprintSystemFieldType.of(importXml.getType())); + persist.setLabel(importXml.getLabel()); + persist.setPlaceholder(importXml.getPlaceholder()); + persist.setDescription(importXml.getDescription()); + persist.setOrdinal(importXml.getOrdinal()); + persist.setRequired(importXml.isRequired()); + return persist; + } + + //endregion } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DmpBlueprintController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DmpBlueprintController.java index 1ba5ebc06..0ca9f3669 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DmpBlueprintController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DmpBlueprintController.java @@ -159,7 +159,7 @@ public class DmpBlueprintController { } @RequestMapping(method = RequestMethod.GET, value = {"/xml/export/{id}"}, produces = "application/xml") - public @ResponseBody ResponseEntity getXml(@PathVariable UUID id) throws JAXBException, ParserConfigurationException, IOException, TransformerException, InstantiationException, IllegalAccessException, SAXException { + public @ResponseBody ResponseEntity getXml(@PathVariable UUID id) throws JAXBException, ParserConfigurationException, IOException, TransformerException, InstantiationException, IllegalAccessException, SAXException, InvalidApplicationException { logger.debug(new MapLogEntry("persisting" + DmpBlueprint.class.getSimpleName()).And("id", id)); ResponseEntity response = this.dmpBlueprintService.exportXml(id);