From 0e6a59ef3de3480717cb9f2a5536755998604130 Mon Sep 17 00:00:00 2001 From: Thomas Georgios Giannos Date: Tue, 7 Nov 2023 16:05:12 +0200 Subject: [PATCH 1/3] Added dmp users on dmp builder --- .../src/main/java/eu/eudat/model/Dmp.java | 13 ++++++ .../eu/eudat/model/builder/DmpBuilder.java | 45 +++++++++++++++---- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/Dmp.java b/dmp-backend/core/src/main/java/eu/eudat/model/Dmp.java index 7615b636e..d334f5624 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/Dmp.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/Dmp.java @@ -90,6 +90,10 @@ public class Dmp { public static final String _dmpReferences = "dmpReferences"; + private List dmpUsers; + + public static final String _dmpUsers = "dmoUsers"; + public UUID getId() { return id; } @@ -249,4 +253,13 @@ public class Dmp { public void setDmpReferences(List dmpReferences) { this.dmpReferences = dmpReferences; } + + public List getDmpUsers() { + return dmpUsers; + } + + public void setDmpUsers(List dmpUsers) { + this.dmpUsers = dmpUsers; + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpBuilder.java index 2a33e37f1..9551b28dd 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpBuilder.java @@ -6,6 +6,7 @@ import eu.eudat.data.DmpEntity; import eu.eudat.model.*; import eu.eudat.query.DescriptionQuery; import eu.eudat.query.DmpReferenceQuery; +import eu.eudat.query.DmpUserQuery; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.exception.MyApplicationException; @@ -58,8 +59,11 @@ public class DmpBuilder extends BaseBuilder { FieldSet dmpDescriptionsFields = fields.extractPrefixed(this.asPrefix(Dmp._dmpDescriptions)); Map> dmpDescriptionsMap = this.collectDmpDescriptions(dmpDescriptionsFields, data); - FieldSet dmpReferencesFields = fields.extractPrefixed(this.asPrefix(Reference._dmpReferences)); - Map> dmpReferenceMap = this.collectDmpReferences(dmpReferencesFields, data); + FieldSet dmpReferencesFields = fields.extractPrefixed(this.asPrefix(Dmp._dmpReferences)); + Map> dmpReferencesMap = this.collectDmpReferences(dmpReferencesFields, data); + + FieldSet dmpUsersFields = fields.extractPrefixed(this.asPrefix(Dmp._dmpUsers)); + Map> dmpUsersMap = this.collectDmpUsers(dmpUsersFields, data); for (DmpEntity d : data) { Dmp m = new Dmp(); @@ -96,11 +100,14 @@ public class DmpBuilder extends BaseBuilder { if (fields.hasField(this.asIndexer(Dmp._hash))) m.setHash(this.hashValue(d.getUpdatedAt())); - if (!dmpDescriptionsFields.isEmpty() && dmpDescriptionsMap != null && dmpDescriptionsMap.containsKey(d.getId())) + if (dmpDescriptionsMap != null && !dmpDescriptionsMap.isEmpty() && dmpDescriptionsMap.containsKey(d.getId())) m.setDmpDescriptions(dmpDescriptionsMap.get(d.getId())); - if (dmpReferenceMap != null && !dmpReferenceMap.isEmpty() && dmpReferenceMap.containsKey(d.getId())) - m.setDmpReferences(dmpReferenceMap.get(d.getId())); + if (dmpReferencesMap != null && !dmpReferencesMap.isEmpty() && dmpReferencesMap.containsKey(d.getId())) + m.setDmpReferences(dmpReferencesMap.get(d.getId())); + + if (dmpUsersMap != null && !dmpUsersMap.isEmpty() && dmpUsersMap.containsKey(d.getId())) + m.setDmpUsers(dmpUsersMap.get(d.getId())); models.add(m); } @@ -130,13 +137,14 @@ public class DmpBuilder extends BaseBuilder { return itemMap; } - private Map> collectDmpReferences(FieldSet fields, List datas) throws MyApplicationException { - if (fields.isEmpty() || datas.isEmpty()) return null; + private Map> collectDmpReferences(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) + return null; this.logger.debug("checking related - {}", DmpReference.class.getSimpleName()); - Map> itemMap = null; + Map> itemMap; FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DmpReference._dmp, Dmp._id)); - DmpReferenceQuery query = this.queryFactory.query(DmpReferenceQuery.class).authorize(this.authorize).dmpIds(datas.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())); + DmpReferenceQuery query = this.queryFactory.query(DmpReferenceQuery.class).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())); itemMap = this.builderFactory.builder(DmpReferenceBuilder.class).authorize(this.authorize).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId()); if (!fields.hasField(this.asIndexer(DmpReference._dmp, Dmp._id))) { @@ -148,4 +156,23 @@ public class DmpBuilder extends BaseBuilder { return itemMap; } + private Map> collectDmpUsers(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) + return null; + this.logger.debug("checking related - {}", DmpUser.class.getSimpleName()); + + Map> itemMap; + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DmpUser._dmp, Dmp._id)); + DmpUserQuery query = this.queryFactory.query(DmpUserQuery.class).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DmpUserBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId()); + + if (!fields.hasField(this.asIndexer(DmpUser._dmp, Dmp._id))) { + itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).peek(x -> { + x.getDmp().setId(null); + }); + } + + return itemMap; + } + } From 3e15749b56c83e3d75bbb70a36d844cf17cd85e2 Mon Sep 17 00:00:00 2001 From: Thomas Georgios Giannos Date: Tue, 7 Nov 2023 16:18:18 +0200 Subject: [PATCH 2/3] Added dmp users on dmp builder --- .../eu/eudat/model/builder/DmpBuilder.java | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpBuilder.java index d0a37300f..9de912248 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpBuilder.java @@ -6,6 +6,7 @@ import eu.eudat.data.DmpEntity; import eu.eudat.model.*; import eu.eudat.query.DescriptionQuery; import eu.eudat.query.DmpReferenceQuery; +import eu.eudat.query.DmpUserQuery; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.exception.MyApplicationException; @@ -55,8 +56,11 @@ public class DmpBuilder extends BaseBuilder { List models = new ArrayList<>(); - FieldSet dmpReferencesFields = fields.extractPrefixed(this.asPrefix(Reference._dmpReferences)); - Map> dmpReferenceMap = this.collectDmpReferences(dmpReferencesFields, data); + FieldSet dmpReferencesFields = fields.extractPrefixed(this.asPrefix(Dmp._dmpReferences)); + Map> dmpReferencesMap = this.collectDmpReferences(dmpReferencesFields, data); + + FieldSet dmpUsersFields = fields.extractPrefixed(this.asPrefix(Dmp._dmpUsers)); + Map> dmpUsersMap = this.collectDmpUsers(dmpUsersFields, data); for (DmpEntity d : data) { Dmp m = new Dmp(); @@ -93,8 +97,11 @@ public class DmpBuilder extends BaseBuilder { if (fields.hasField(this.asIndexer(Dmp._hash))) m.setHash(this.hashValue(d.getUpdatedAt())); - if (dmpReferenceMap != null && !dmpReferenceMap.isEmpty() && dmpReferenceMap.containsKey(d.getId())) - m.setDmpReferences(dmpReferenceMap.get(d.getId())); + if (dmpReferencesMap != null && !dmpReferencesMap.isEmpty() && dmpReferencesMap.containsKey(d.getId())) + m.setDmpReferences(dmpReferencesMap.get(d.getId())); + + if (dmpUsersMap != null && !dmpUsersMap.isEmpty() && dmpUsersMap.containsKey(d.getId())) + m.setDmpUsers(dmpUsersMap.get(d.getId())); models.add(m); } @@ -103,14 +110,14 @@ public class DmpBuilder extends BaseBuilder { return models; } - private Map> collectDmpReferences(FieldSet fields, List datas) throws MyApplicationException { - if (fields.isEmpty() || datas.isEmpty()) return null; + private Map> collectDmpReferences(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) return null; this.logger.debug("checking related - {}", DmpReference.class.getSimpleName()); - Map> itemMap = null; + Map> itemMap; FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DmpReference._dmp, Dmp._id)); - DmpReferenceQuery query = this.queryFactory.query(DmpReferenceQuery.class).authorize(this.authorize).dmpIds(datas.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())); - itemMap = this.builderFactory.builder(DmpReferenceBuilder.class).authorize(this.authorize).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId()); + DmpReferenceQuery query = this.queryFactory.query(DmpReferenceQuery.class).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DmpReferenceBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId()); if (!fields.hasField(this.asIndexer(DmpReference._dmp, Dmp._id))) { itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).peek(x -> { @@ -121,4 +128,23 @@ public class DmpBuilder extends BaseBuilder { return itemMap; } + private Map> collectDmpUsers(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) + return null; + this.logger.debug("checking related - {}", DmpUser.class.getSimpleName()); + + Map> itemMap; + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DmpUser._dmp, Dmp._id)); + DmpUserQuery query = this.queryFactory.query(DmpUserQuery.class).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DmpUserBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId()); + + if (!fields.hasField(this.asIndexer(DmpUser._dmp, Dmp._id))) { + itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).peek(x -> { + x.getDmp().setId(null); + }); + } + + return itemMap; + } + } From 24aba556ef924df56c7cc2c1ca0fa7c44deb4e05 Mon Sep 17 00:00:00 2001 From: Thomas Georgios Giannos Date: Tue, 7 Nov 2023 16:34:26 +0200 Subject: [PATCH 3/3] Small fix --- .../core/src/main/java/eu/eudat/model/Dmp.java | 12 ------------ .../java/eu/eudat/model/censorship/DmpCensor.java | 2 -- 2 files changed, 14 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/Dmp.java b/dmp-backend/core/src/main/java/eu/eudat/model/Dmp.java index d334f5624..91ae87715 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/Dmp.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/Dmp.java @@ -82,10 +82,6 @@ public class Dmp { public static final String _hash = "hash"; - private List dmpDescriptions; - - public static final String _dmpDescriptions = "dmpDescriptions"; - private List dmpReferences; public static final String _dmpReferences = "dmpReferences"; @@ -238,14 +234,6 @@ public class Dmp { this.hash = hash; } - public List getDmpDescriptions() { - return dmpDescriptions; - } - - public void setDmpDescriptions(List dmpDescriptions) { - this.dmpDescriptions = dmpDescriptions; - } - public List getDmpReferences() { return dmpReferences; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java index ecdd35220..30e69539b 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java @@ -40,8 +40,6 @@ public class DmpCensor extends BaseCensor { this.authService.authorizeForce(Permission.BrowseDmp); - FieldSet dmpDescriptionsFields = fields.extractPrefixed(this.asIndexerPrefix(Dmp._dmpDescriptions)); - this.censorFactory.censor(DescriptionCensor.class).censor(dmpDescriptionsFields, userId); FieldSet dmpReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(Dmp._dmpReferences)); this.censorFactory.censor(DmpReferenceCensor.class).censor(dmpReferencesFields, userId); }