From ce8b49deb0b1f9ab6f467b998f20b02423e84856 Mon Sep 17 00:00:00 2001 From: George Kalampokis Date: Tue, 3 Aug 2021 12:15:54 +0300 Subject: [PATCH] Fix issue with DMP disappearing when editing Datasets --- .../java/eu/eudat/elastic/entities/Dmp.java | 62 ++++++++++++------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Dmp.java b/dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Dmp.java index 8faea3233..eee7e035d 100644 --- a/dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Dmp.java +++ b/dmp-backend/elastic/src/main/java/eu/eudat/elastic/entities/Dmp.java @@ -5,6 +5,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; +import java.time.Instant; import java.util.*; import java.util.stream.Collectors; @@ -287,30 +288,43 @@ public class Dmp implements ElasticEntity { @Override public Dmp fromElasticEntity(Map fields) { this.id = UUID.fromString((String) fields.get(MapKey.ID.getName())); - this.label = (String) fields.get(MapKey.LABEL.getName()); - this.description = (String) fields.get(MapKey.DESCRIPTION.getName()); - if (fields.get(MapKey.GROUPID.getName()) != null) { - this.groupId = UUID.fromString((String) fields.get(MapKey.GROUPID.getName())); - } - this.status = Short.valueOf(fields.get(MapKey.STATUS.getName()).toString()); - if (fields.get(MapKey.TEMPLATES.getName()) != null) { - this.templates = ((List>) fields.get(MapKey.TEMPLATES.getName())).stream().map(hashMap -> new DatasetTempalate().fromElasticEntity(hashMap)).collect(Collectors.toList()); - } - if (fields.get(MapKey.COLLABORATORS.getName()) != null) { - this.collaborators = ((List>) fields.get(MapKey.COLLABORATORS.getName())).stream().map(map -> new Collaborator().fromElasticEntity(map)).collect(Collectors.toList()); - } - if (fields.get(MapKey.ORGANIZATIONS.getName()) != null) { - this.organizations = ((List>) fields.get(MapKey.ORGANIZATIONS.getName())).stream().map(map -> new Organization().fromElasticEntity(map)).collect(Collectors.toList()); - } - this.lastVersion = (Boolean) fields.get(MapKey.LASTVERSION.getName()); - this.lastPublicVersion = (Boolean) fields.get(MapKey.LASTPUBLICVERSION.getName()); - this.isPublic = (Boolean) fields.get(MapKey.ISPUBLIC.getName()); - if (fields.get(MapKey.DATASETS.getName()) != null) { - this.datasets = ((List>) fields.get(MapKey.DATASETS.getName())).stream().map(map -> new Dataset().fromElasticEntity(map)).collect(Collectors.toList()); - } - this.grant = UUID.fromString((String) fields.get(MapKey.GRANT.getName())); - if (fields.get(MapKey.GRANTSTATUS.getName()) != null) { - this.grantStatus = Short.valueOf(fields.get(MapKey.GRANTSTATUS.getName()).toString()); + if (fields.size() > 1) { + this.label = (String) fields.get(MapKey.LABEL.getName()); + this.description = (String) fields.get(MapKey.DESCRIPTION.getName()); + if (fields.get(MapKey.GROUPID.getName()) != null) { + this.groupId = UUID.fromString((String) fields.get(MapKey.GROUPID.getName())); + } + this.status = Short.valueOf(fields.get(MapKey.STATUS.getName()).toString()); + if (fields.get(MapKey.TEMPLATES.getName()) != null) { + this.templates = ((List>) fields.get(MapKey.TEMPLATES.getName())).stream().map(hashMap -> new DatasetTempalate().fromElasticEntity(hashMap)).collect(Collectors.toList()); + } + if (fields.get(MapKey.COLLABORATORS.getName()) != null) { + this.collaborators = ((List>) fields.get(MapKey.COLLABORATORS.getName())).stream().map(map -> new Collaborator().fromElasticEntity(map)).collect(Collectors.toList()); + } + if (fields.get(MapKey.ORGANIZATIONS.getName()) != null) { + this.organizations = ((List>) fields.get(MapKey.ORGANIZATIONS.getName())).stream().map(map -> new Organization().fromElasticEntity(map)).collect(Collectors.toList()); + } + this.lastVersion = (Boolean) fields.get(MapKey.LASTVERSION.getName()); + this.lastPublicVersion = (Boolean) fields.get(MapKey.LASTPUBLICVERSION.getName()); + this.isPublic = (Boolean) fields.get(MapKey.ISPUBLIC.getName()); + if (fields.get(MapKey.DATASETS.getName()) != null) { + this.datasets = ((List>) fields.get(MapKey.DATASETS.getName())).stream().map(map -> new Dataset().fromElasticEntity(map)).collect(Collectors.toList()); + } + this.grant = UUID.fromString((String) fields.get(MapKey.GRANT.getName())); + if (fields.get(MapKey.GRANTSTATUS.getName()) != null) { + this.grantStatus = Short.valueOf(fields.get(MapKey.GRANTSTATUS.getName()).toString()); + } + this.created = Date.from(Instant.parse(fields.get(MapKey.CREATED.getName()).toString())); + this.modified = Date.from(Instant.parse(fields.get(MapKey.MODIFIED.getName()).toString())); + if (fields.get(MapKey.FINALIZEDAT.getName()) != null) { + this.finalizedAt = Date.from(Instant.parse(fields.get(MapKey.FINALIZEDAT.getName()).toString())); + } + if (fields.get(MapKey.PUBLISHEDAT.getName()) != null) { + this.publishedAt = Date.from(Instant.parse(fields.get(MapKey.PUBLISHEDAT.getName()).toString())); + } + if (fields.get(MapKey.DOI.getName()) != null) { + this.doi = fields.get(MapKey.DOI.getName()).toString(); + } } return this; }