diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmp/DmpBlueprintValueEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmp/DmpBlueprintValueEntity.java new file mode 100644 index 000000000..f0158df3c --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmp/DmpBlueprintValueEntity.java @@ -0,0 +1,25 @@ +package eu.eudat.commons.types.dmp; + +public class DmpBlueprintValueEntity { + + private String fieldId; + + private String value; + + public String getFieldId() { + return fieldId; + } + + public void setFieldId(String fieldId) { + this.fieldId = fieldId; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpproperties/DmpContact.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmp/DmpContactEntity.java similarity index 90% rename from dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpproperties/DmpContact.java rename to dmp-backend/core/src/main/java/eu/eudat/commons/types/dmp/DmpContactEntity.java index 99519ee5b..81f24fa0b 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpproperties/DmpContact.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmp/DmpContactEntity.java @@ -1,6 +1,6 @@ -package eu.eudat.model.persist.dmpproperties; +package eu.eudat.commons.types.dmp; -public class DmpContact { +public class DmpContactEntity { String userId; diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmp/DmpPropertiesEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmp/DmpPropertiesEntity.java new file mode 100644 index 000000000..38a79fe30 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/dmp/DmpPropertiesEntity.java @@ -0,0 +1,27 @@ +package eu.eudat.commons.types.dmp; + +import java.util.List; + +public class DmpPropertiesEntity { + + private List dmpBlueprintValues; + + private List contacts; + + public List getDmpBlueprintValues() { + return dmpBlueprintValues; + } + + public void setDmpBlueprintValues(List dmpBlueprintValues) { + this.dmpBlueprintValues = dmpBlueprintValues; + } + + public List getContacts() { + return contacts; + } + + public void setContacts(List contacts) { + this.contacts = contacts; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpproperties/DmpBlueprintValue.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpproperties/DmpBlueprintValue.java deleted file mode 100644 index e3302e132..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/dmpproperties/DmpBlueprintValue.java +++ /dev/null @@ -1,25 +0,0 @@ -package eu.eudat.model.persist.dmpproperties; - -public class DmpBlueprintValue { - - private String fieldId; - - private String fieldValue; - - public String getFieldId() { - return fieldId; - } - - public void setFieldId(String fieldId) { - this.fieldId = fieldId; - } - - public String getFieldValue() { - return fieldValue; - } - - public void setFieldValue(String fieldValue) { - this.fieldValue = fieldValue; - } - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java index 00b55f606..9a15ebe9f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java @@ -7,6 +7,9 @@ import eu.eudat.commons.JsonHandlingService; import eu.eudat.commons.XmlHandlingService; import eu.eudat.commons.enums.*; import eu.eudat.commons.scope.user.UserScope; +import eu.eudat.commons.types.dmp.DmpBlueprintValueEntity; +import eu.eudat.commons.types.dmp.DmpContactEntity; +import eu.eudat.commons.types.dmp.DmpPropertiesEntity; import eu.eudat.commons.types.reference.DefinitionEntity; import eu.eudat.commons.types.reference.FieldEntity; import eu.eudat.convention.ConventionService; @@ -22,6 +25,9 @@ import eu.eudat.model.deleter.DmpDescriptionTemplateDeleter; import eu.eudat.model.deleter.DmpReferenceDeleter; import eu.eudat.model.deleter.DmpUserDeleter; import eu.eudat.model.persist.*; +import eu.eudat.model.persist.dmpproperties.DmpBlueprintValuePersist; +import eu.eudat.model.persist.dmpproperties.DmpContactPersist; +import eu.eudat.model.persist.dmpproperties.DmpPropertiesPersist; import eu.eudat.model.persist.referencedefinition.DefinitionPersist; import eu.eudat.model.persist.referencedefinition.FieldPersist; import eu.eudat.query.*; @@ -408,7 +414,7 @@ public class DmpServiceImpl implements DmpService { } data.setLabel(model.getLabel()); - data.setProperties(this.jsonHandlingService.toJson(model.getProperties())); + data.setProperties(this.jsonHandlingService.toJson(this.buildDmpPropertiesEntity(model.getProperties()))); data.setDescription(model.getDescription()); data.setAccessType(model.getAccessType()); data.setUpdatedAt(Instant.now()); @@ -424,6 +430,46 @@ public class DmpServiceImpl implements DmpService { return data; } + private @NotNull DmpPropertiesEntity buildDmpPropertiesEntity(DmpPropertiesPersist persist){ + DmpPropertiesEntity data = new DmpPropertiesEntity(); + if (persist == null) return data; + if (!this.conventionService.isListNullOrEmpty(persist.getContacts())){ + data.setContacts(new ArrayList<>()); + for (DmpContactPersist contactPersist: persist.getContacts()) { + data.getContacts().add(this.buildDmpContactEntity(contactPersist)); + } + } + if (!this.conventionService.isListNullOrEmpty(persist.getDmpBlueprintValues())){ + data.setDmpBlueprintValues(new ArrayList<>()); + for (DmpBlueprintValuePersist fieldValuePersist: persist.getDmpBlueprintValues()) { + data.getDmpBlueprintValues().add(this.buildDmpBlueprintValueEntity(fieldValuePersist)); + } + } + return data; + } + + private @NotNull DmpContactEntity buildDmpContactEntity(DmpContactPersist persist){ + DmpContactEntity data = new DmpContactEntity(); + if (persist == null) return data; + + data.setEmail(persist.getEmail()); + data.setLastName(persist.getLastName()); + data.setFirstName(persist.getFirstName()); + data.setUserId(persist.getUserId()); + return data; + } + + + + private @NotNull DmpBlueprintValueEntity buildDmpBlueprintValueEntity(DmpBlueprintValuePersist persist){ + DmpBlueprintValueEntity data = new DmpBlueprintValueEntity(); + if (persist == null) return data; + + data.setValue(persist.getFieldValue()); + data.setFieldId(persist.getFieldId()); + return data; + } + private void patchAndSaveReferences(List models, UUID dmpId) throws InvalidApplicationException { if (models == null || models.isEmpty()) return; @@ -532,14 +578,14 @@ public class DmpServiceImpl implements DmpService { if (!this.conventionService.isListNullOrEmpty(persist.getFields())){ data.setFields(new ArrayList<>()); for (FieldPersist fieldPersist: persist.getFields()) { - data.getFields().add(this.buildFieldEntity(fieldPersist)); + data.getFields().add(this.buildDmpContactEntity(fieldPersist)); } } return data; } - private @NotNull FieldEntity buildFieldEntity(FieldPersist persist){ + private @NotNull FieldEntity buildDmpContactEntity(FieldPersist persist){ FieldEntity data = new FieldEntity(); if (persist == null) return data;