From c15b63d3dadb96e53d687ea152e114763650108f Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Fri, 24 May 2024 13:40:14 +0300 Subject: [PATCH] Add method to get child stakeholder and change manageStakeholder to return object of different types of stakeholders. --- .../controllers/StakeholderController.java | 49 ++--- .../uoamonitorservice/dao/StakeholderDAO.java | 183 +++++++++++++++++- .../dto/{copy.java => BuildStakeholder.java} | 13 +- .../dto/ManageStakeholders.java | 47 +++++ .../dto/StakeholderFull.java | 25 ++- .../entities/Stakeholder.java | 13 +- .../generics/CategoryGeneric.java | 15 +- .../generics/SectionGeneric.java | 8 +- .../generics/StakeholderGeneric.java | 44 +++-- .../generics/SubCategoryGeneric.java | 14 +- .../generics/TopicGeneric.java | 15 +- .../primitives/StakeholderType.java | 12 +- .../primitives/Umbrella.java | 60 ++++++ .../service/CategoryService.java | 2 +- .../service/SectionService.java | 2 +- .../service/StakeholderService.java | 135 +++++++------ .../service/SubCategoryService.java | 6 +- .../service/TopicService.java | 4 +- 18 files changed, 498 insertions(+), 149 deletions(-) rename src/main/java/eu/dnetlib/uoamonitorservice/dto/{copy.java => BuildStakeholder.java} (66%) create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/dto/ManageStakeholders.java create mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/primitives/Umbrella.java diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java index dea1cae..f1ffa3c 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java @@ -3,10 +3,10 @@ package eu.dnetlib.uoamonitorservice.controllers; import eu.dnetlib.uoaadmintoolslibrary.entities.Portal; import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException; import eu.dnetlib.uoaadmintoolslibrary.services.PortalService; -import eu.dnetlib.uoamonitorservice.dto.copy; +import eu.dnetlib.uoamonitorservice.dto.BuildStakeholder; +import eu.dnetlib.uoamonitorservice.dto.ManageStakeholders; import eu.dnetlib.uoamonitorservice.dto.StakeholderFull; import eu.dnetlib.uoamonitorservice.entities.Stakeholder; -import eu.dnetlib.uoamonitorservice.generics.StakeholderGeneric; import eu.dnetlib.uoamonitorservice.primitives.Visibility; import eu.dnetlib.uoamonitorservice.service.CommonService; import eu.dnetlib.uoamonitorservice.service.StakeholderService; @@ -17,7 +17,6 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import java.util.List; -import java.util.stream.Collectors; @RestController @CrossOrigin(origins = "*") @@ -37,20 +36,22 @@ public class StakeholderController { @PreAuthorize("isAuthenticated()") @RequestMapping(value = "/stakeholder/alias", method = RequestMethod.GET) - public List getAllReservedStakeholderAlias() { - List stakeholderAlias = this.stakeholderService.getAllAliases(); - stakeholderAlias.add("all"); - stakeholderAlias.add("default"); - stakeholderAlias.add("alias"); + public List getAllReservedStakeholderAlias(@RequestParam(required = false) String type) { + List stakeholderAlias = this.stakeholderService.getAllAliases(type); + if(type == null ) { + stakeholderAlias.add("all"); + stakeholderAlias.add("default"); + stakeholderAlias.add("alias"); + } return stakeholderAlias; } @PreAuthorize("hasAnyAuthority(" + "@AuthorizationService.PORTAL_ADMIN, " + - "@AuthorizationService.curator(#copy.stakeholder.getType()))") + "@AuthorizationService.curator(#buildStakeholder.stakeholder.getType()))") @RequestMapping(value = "/build-stakeholder", method = RequestMethod.POST) - public Stakeholder buildStakeholder(@RequestBody copy copy) { - Stakeholder stakeholder = copy.getStakeholder(); + public Stakeholder buildStakeholder(@RequestBody BuildStakeholder buildStakeholder) { + Stakeholder stakeholder = buildStakeholder.getStakeholder(); log.debug("build stakeholder"); log.debug("Alias: " + stakeholder.getAlias()); Portal portal = portalService.getPortal(stakeholder.getAlias()); @@ -61,7 +62,7 @@ public class StakeholderController { portal.setType(stakeholder.getType()); portalService.insertPortal(portal); } - return this.stakeholderService.buildStakeholder(stakeholder, copy.getCopyId()); + return this.stakeholderService.buildStakeholder(stakeholder, buildStakeholder.getCopyId(), buildStakeholder.isUmbrella()); } @PreAuthorize("hasAnyAuthority(" + "@AuthorizationService.PORTAL_ADMIN)") @@ -70,22 +71,16 @@ public class StakeholderController { return this.stakeholderService.getAll(type); } - @PreAuthorize("isAuthenticated()") - @RequestMapping(value = "/stakeholder/default", method = RequestMethod.GET) - public List getAllDefaultStakeholders(@RequestParam(required = false) String type) { - return this.stakeholderService.getAllDefaultByRole(type); - } - @RequestMapping(value = "/stakeholder", method = RequestMethod.GET) public List getVisibleStakeholders(@RequestParam(required = false) String type, @RequestParam(required = false) String defaultId) { - return stakeholderService.getStakeholdersByTypeAndRole(type, defaultId, false); + return stakeholderService.getVisibleStakeholders(type, defaultId); } @PreAuthorize("isAuthenticated()") @RequestMapping(value = "/my-stakeholder", method = RequestMethod.GET) - public List getManagedStakeholders(@RequestParam(required = false) String type) { - return stakeholderService.getStakeholdersByTypeAndRole(type, null, true); + public ManageStakeholders getManagedStakeholders(@RequestParam(required = false) String type) { + return stakeholderService.getManageStakeholders(type); } @RequestMapping(value = "/stakeholder/{alias:.+}", method = RequestMethod.GET) @@ -97,6 +92,16 @@ public class StakeholderController { return stakeholder; } + @RequestMapping(value = "/stakeholder/{parent:.+}/{type}/{child:.+}", method = RequestMethod.GET) + public StakeholderFull getStakeholderWithParent(@PathVariable("parent") String parent, @PathVariable("type") String type, @PathVariable("child") String child) { + StakeholderFull stakeholder = this.stakeholderService.getFullStakeholderWithParents(this.stakeholderService.findByAlias(child), type, parent); + if (stakeholder == null) { + this.commonService.unauthorized("Get stakeholder: You are not authorized to access stakeholder with alias: " + child); + } + return stakeholder; + + } + @PreAuthorize("hasAnyAuthority(" + "@AuthorizationService.PORTAL_ADMIN, " + "@AuthorizationService.curator(#stakeholder.getType()), " @@ -118,7 +123,7 @@ public class StakeholderController { public StakeholderFull saveStakeholderFull(@RequestBody StakeholderFull stakeholder) { log.debug("save stakeholder"); log.debug("Alias: " + stakeholder.getAlias() + " - Id: " + stakeholder.getId()); - return this.stakeholderService.getFullStakeholder(this.stakeholderService.save(new Stakeholder(stakeholder))); + return this.stakeholderService.getFullStakeholder(this.stakeholderService.save(new Stakeholder(stakeholder, this.stakeholderService))); } @PreAuthorize("isAuthenticated()") diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/StakeholderDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/StakeholderDAO.java index 1d639fa..689ed01 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/StakeholderDAO.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/dao/StakeholderDAO.java @@ -1,7 +1,9 @@ package eu.dnetlib.uoamonitorservice.dao; import eu.dnetlib.uoamonitorservice.entities.Stakeholder; +import eu.dnetlib.uoamonitorservice.primitives.StakeholderType; import org.springframework.data.mongodb.repository.MongoRepository; +import org.springframework.data.mongodb.repository.Query; import org.springframework.stereotype.Repository; import java.util.List; @@ -9,20 +11,187 @@ import java.util.Optional; @Repository public interface StakeholderDAO extends MongoRepository { + /** + * All Stakeholders + */ List findAll(); - List findByType(String Type); + List findByDefaultId(String id); + + List findByType(StakeholderType Type); + + List findByTypeAndDefaultId(StakeholderType Type, String id); + + default List allStakeholders() { + return allStakeholders(null); + } + + default List allStakeholders(StakeholderType type) { + return allStakeholders(type, null); + } + + default List allStakeholders(StakeholderType type, String id) { + if (type != null && id != null) { + return findByTypeAndDefaultId(type, id); + } else if (id != null) { + return findByDefaultId(id); + } else if (type != null) { + return findByType(type); + } else { + return findAll(); + } + } + + /** + * Default Stakeholders + */ List findByDefaultIdIsNull(); - List findByDefaultIdAndCopyTrue(String defaultId); - List findByDefaultIdAndType(String DefaultId, String Type); - List findByDefaultIdIsNotNull(); - List findByDefaultIdIsNotNullAndType(String Type); + List findByDefaultIdIsNullAndType(StakeholderType Type); + + default List defaultStakeholders(StakeholderType type) { + if (type == null) { + return findByDefaultIdIsNull(); + } + return findByDefaultIdIsNullAndType(type); + } + + /** + * Standalone Stakeholders (not umbrella) + */ + List findByDefaultIdIsNotNullAndStandaloneIsTrueAndUmbrellaIsNull(); + + List findByDefaultIdIsNotNullAndStandaloneIsTrueAndUmbrellaIsNullAndDefaultId(String id); + + List findByDefaultIdIsNotNullAndStandaloneIsTrueAndUmbrellaIsNullAndType(StakeholderType Type); + + List findByDefaultIdIsNotNullAndStandaloneIsTrueAndUmbrellaIsNullAndTypeAndDefaultId(StakeholderType Type, String id); + + default List standaloneStakeholders() { + return standaloneStakeholders(null); + } + + default List standaloneStakeholders(StakeholderType type) { + return standaloneStakeholders(type, null); + } + + default List standaloneStakeholders(StakeholderType type, String id) { + if (type != null && id != null) { + return findByDefaultIdIsNotNullAndStandaloneIsTrueAndUmbrellaIsNullAndTypeAndDefaultId(type, id); + } else if (id != null) { + return findByDefaultIdIsNotNullAndStandaloneIsTrueAndUmbrellaIsNullAndDefaultId(id); + } else if (type != null) { + return findByDefaultIdIsNotNullAndStandaloneIsTrueAndUmbrellaIsNullAndType(type); + } else { + return findByDefaultIdIsNotNullAndStandaloneIsTrueAndUmbrellaIsNull(); + } + } + + /** + * Dependent Stakeholders + */ + List findByDefaultIdIsNotNullAndStandaloneIsFalse(); + + List findByDefaultIdIsNotNullAndStandaloneIsFalseAndDefaultId(String id); + + List findByDefaultIdIsNotNullAndStandaloneIsFalseAndType(StakeholderType Type); + + List findByDefaultIdIsNotNullAndStandaloneIsFalseAndTypeAndDefaultId(StakeholderType Type, String id); + + default List dependentStakeholders() { + return dependentStakeholders(null); + } + + default List dependentStakeholders(StakeholderType type) { + return dependentStakeholders(type, null); + } + + default List dependentStakeholders(StakeholderType type, String id) { + if (type != null && id != null) { + return findByDefaultIdIsNotNullAndStandaloneIsFalseAndTypeAndDefaultId(type, id); + } else if (id != null) { + return findByDefaultIdIsNotNullAndStandaloneIsFalseAndDefaultId(id); + } else if (type != null) { + return findByDefaultIdIsNotNullAndStandaloneIsFalseAndType(type); + } else { + return findByDefaultIdIsNotNullAndStandaloneIsFalse(); + } + } + + /** + * Umbrella Stakeholders + */ + List findByUmbrellaNotNull(); + + List findByUmbrellaNotNullAndDefaultId(String id); + + List findByUmbrellaNotNullAndType(StakeholderType Type); + + List findByUmbrellaNotNullAndTypeAndDefaultId(StakeholderType Type, String id); + + default List umbrellaStakeholders() { + return umbrellaStakeholders(null); + } + + default List umbrellaStakeholders(StakeholderType type) { + return umbrellaStakeholders(type, null); + } + + default List umbrellaStakeholders(StakeholderType type, String id) { + if (type != null && id != null) { + return findByUmbrellaNotNullAndTypeAndDefaultId(type, id); + } else if (id != null) { + return findByUmbrellaNotNullAndDefaultId(id); + } else if (type != null) { + return findByUmbrellaNotNullAndType(type); + } else { + return findByUmbrellaNotNull(); + } + } + + /** + * Browse Stakeholders + * */ + List findByDefaultIdNotNullAndStandaloneIsTrue(); + + List findByDefaultIdNotNullAndStandaloneIsTrueAndDefaultId(String id); + + List findByDefaultIdNotNullAndStandaloneIsTrueAndType(StakeholderType Type); + + List findByDefaultIdNotNullAndStandaloneIsTrueAndTypeAndDefaultId(StakeholderType Type, String id); + + default List browseStakeholders() { + return browseStakeholders(null); + } + + default List browseStakeholders(StakeholderType type) { + return browseStakeholders(type, null); + } + + default List browseStakeholders(StakeholderType type, String id) { + if (type != null && id != null) { + return findByDefaultIdNotNullAndStandaloneIsTrueAndTypeAndDefaultId(type, id); + } else if (id != null) { + return findByDefaultIdNotNullAndStandaloneIsTrueAndDefaultId(id); + } else if (type != null) { + return findByDefaultIdNotNullAndStandaloneIsTrueAndType(type); + } else { + return findByDefaultIdNotNullAndStandaloneIsTrue(); + } + } + + /** + * Other method + */ + + List findByDefaultIdAndCopyIsTrue(String defaultId); List findByTopicsContaining(String topic); - Optional findById(String Id); - Optional findByAlias(String Alias); + Optional findById(String id); + + Optional findByAlias(String alias); + void delete(String Id); diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dto/copy.java b/src/main/java/eu/dnetlib/uoamonitorservice/dto/BuildStakeholder.java similarity index 66% rename from src/main/java/eu/dnetlib/uoamonitorservice/dto/copy.java rename to src/main/java/eu/dnetlib/uoamonitorservice/dto/BuildStakeholder.java index f3c0a0e..9db7170 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/dto/copy.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/dto/BuildStakeholder.java @@ -2,11 +2,12 @@ package eu.dnetlib.uoamonitorservice.dto; import eu.dnetlib.uoamonitorservice.entities.Stakeholder; -public class copy { +public class BuildStakeholder { private Stakeholder stakeholder; private String copyId; + private boolean umbrella = false; - public copy() { + public BuildStakeholder() { } public Stakeholder getStakeholder() { @@ -24,4 +25,12 @@ public class copy { public void setCopyId(String copyId) { this.copyId = copyId; } + + public boolean isUmbrella() { + return umbrella; + } + + public void setUmbrella(boolean umbrella) { + this.umbrella = umbrella; + } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dto/ManageStakeholders.java b/src/main/java/eu/dnetlib/uoamonitorservice/dto/ManageStakeholders.java new file mode 100644 index 0000000..5ce4d8a --- /dev/null +++ b/src/main/java/eu/dnetlib/uoamonitorservice/dto/ManageStakeholders.java @@ -0,0 +1,47 @@ +package eu.dnetlib.uoamonitorservice.dto; + +import eu.dnetlib.uoamonitorservice.entities.Stakeholder; + +import java.util.List; + +public class ManageStakeholders { + List templates; + List standalone; + List dependent; + List umbrella; + + public ManageStakeholders() { + } + + public List getTemplates() { + return templates; + } + + public void setTemplates(List templates) { + this.templates = templates; + } + + public List getStandalone() { + return standalone; + } + + public void setStandalone(List standalone) { + this.standalone = standalone; + } + + public List getDependent() { + return dependent; + } + + public void setDependent(List dependent) { + this.dependent = dependent; + } + + public List getUmbrella() { + return umbrella; + } + + public void setUmbrella(List umbrella) { + this.umbrella = umbrella; + } +} diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dto/StakeholderFull.java b/src/main/java/eu/dnetlib/uoamonitorservice/dto/StakeholderFull.java index 3c14598..474ed03 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/dto/StakeholderFull.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/dto/StakeholderFull.java @@ -1,19 +1,40 @@ package eu.dnetlib.uoamonitorservice.dto; +import eu.dnetlib.uoamonitorservice.entities.Stakeholder; import eu.dnetlib.uoamonitorservice.generics.StakeholderGeneric; +import eu.dnetlib.uoamonitorservice.primitives.Umbrella; import java.util.List; import java.util.Objects; -public class StakeholderFull extends StakeholderGeneric { +public class StakeholderFull extends StakeholderGeneric { + public List otherParents; + public Stakeholder parent; public StakeholderFull() { super(); } - public StakeholderFull(StakeholderGeneric stakeholder, List topics) { + public StakeholderFull(StakeholderGeneric stakeholder, List topics, Umbrella umbrella) { super(stakeholder); topics.removeIf(Objects::isNull); this.topics = topics; + this.umbrella = umbrella; + } + + public List getOtherParents() { + return otherParents; + } + + public void setOtherParents(List otherParents) { + this.otherParents = otherParents; + } + + public Stakeholder getParent() { + return parent; + } + + public void setParent(Stakeholder parent) { + this.parent = parent; } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java b/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java index 3de1efd..c1ec8b5 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java @@ -3,15 +3,15 @@ package eu.dnetlib.uoamonitorservice.entities; import eu.dnetlib.uoamonitorservice.dto.StakeholderFull; import eu.dnetlib.uoamonitorservice.generics.Common; import eu.dnetlib.uoamonitorservice.generics.StakeholderGeneric; +import eu.dnetlib.uoamonitorservice.primitives.Umbrella; +import eu.dnetlib.uoamonitorservice.service.StakeholderService; import org.springframework.data.mongodb.core.mapping.Document; -import java.util.HashSet; -import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @Document -public class Stakeholder extends StakeholderGeneric { +public class Stakeholder extends StakeholderGeneric { public Stakeholder() { super(); @@ -21,10 +21,11 @@ public class Stakeholder extends StakeholderGeneric { super(stakeholder); } - public Stakeholder(StakeholderFull stakeholder) { + public Stakeholder(StakeholderFull stakeholder, StakeholderService service) { super(stakeholder); - this.topics = stakeholder.getTopics().stream().map(Common::getId).collect(Collectors.toList()); - this.topics.removeIf(Objects::isNull); + Stakeholder old = service.findByPath(stakeholder.getId()); + this.topics = old.getTopics(); + this.umbrella = old.getUmbrella(); } public void addTopic(String id) { diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/generics/CategoryGeneric.java b/src/main/java/eu/dnetlib/uoamonitorservice/generics/CategoryGeneric.java index 30166f7..9f75594 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/generics/CategoryGeneric.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/generics/CategoryGeneric.java @@ -1,21 +1,14 @@ package eu.dnetlib.uoamonitorservice.generics; -import com.fasterxml.jackson.annotation.JsonProperty; -import eu.dnetlib.uoamonitorservice.entities.Category; -import eu.dnetlib.uoamonitorservice.primitives.Visibility; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.mongodb.core.mapping.Document; import java.util.ArrayList; -import java.util.Date; import java.util.List; @Document -public class CategoryGeneric extends Common { +public class CategoryGeneric extends Common { protected boolean isOverview; - protected List subCategories; + protected List subCategories; public CategoryGeneric() {} @@ -40,11 +33,11 @@ public class CategoryGeneric extends Common { this.isOverview = isOverview; } - public List getSubCategories() { + public List getSubCategories() { return subCategories; } - public void setSubCategories(List subCategories) { + public void setSubCategories(List subCategories) { this.subCategories = subCategories; } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/generics/SectionGeneric.java b/src/main/java/eu/dnetlib/uoamonitorservice/generics/SectionGeneric.java index ce0cd09..acf4b15 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/generics/SectionGeneric.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/generics/SectionGeneric.java @@ -5,11 +5,11 @@ import eu.dnetlib.uoamonitorservice.primitives.IndicatorType; import java.util.ArrayList; import java.util.List; -public class SectionGeneric extends Common { +public class SectionGeneric extends Common { protected String title; protected String stakeholderAlias; protected IndicatorType type; - protected List indicators; + protected List indicators; public SectionGeneric() { } @@ -60,11 +60,11 @@ public class SectionGeneric extends Common { return this.type == IndicatorType.NUMBER || this.type == IndicatorType.number; } - public List getIndicators() { + public List getIndicators() { return indicators; } - public void setIndicators(List indicators) { + public void setIndicators(List indicators) { this.indicators = indicators; } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/generics/StakeholderGeneric.java b/src/main/java/eu/dnetlib/uoamonitorservice/generics/StakeholderGeneric.java index 50cf486..6b9f1b9 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/generics/StakeholderGeneric.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/generics/StakeholderGeneric.java @@ -1,18 +1,14 @@ package eu.dnetlib.uoamonitorservice.generics; -import com.fasterxml.jackson.annotation.JsonProperty; import eu.dnetlib.uoamonitorservice.primitives.Locale; import eu.dnetlib.uoamonitorservice.primitives.StakeholderType; -import eu.dnetlib.uoamonitorservice.primitives.Visibility; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.LastModifiedDate; +import eu.dnetlib.uoamonitorservice.primitives.Umbrella; +import java.util.ArrayList; import java.util.Date; import java.util.List; - -public class StakeholderGeneric extends Common { +public class StakeholderGeneric extends Common { protected StakeholderType type; protected Date projectUpdateDate = null; protected String index_id; @@ -23,8 +19,10 @@ public class StakeholderGeneric extends Common { protected boolean isUpload = false; protected Locale locale = Locale.EU; protected String funderType; + protected Boolean standalone = true; protected Boolean copy; - protected List topics; + protected List topics = new ArrayList<>(); + protected Umbrella umbrella; public StakeholderGeneric() { } @@ -47,6 +45,7 @@ public class StakeholderGeneric extends Common { setVisibility(stakeholder.getVisibility()); this.funderType = stakeholder.getFunderType(); this.copy = stakeholder.isCopy(); + this.standalone = stakeholder.isStandalone(); creationDate = stakeholder.getCreationDate(); updateDate = stakeholder.getUpdateDate(); } @@ -59,11 +58,7 @@ public class StakeholderGeneric extends Common { } public void setType(String type) { - if (type == null) { - this.type = null; - } else { - this.type = StakeholderType.valueOf(type); - } + this.type = StakeholderType.convert(type); } public Date getProjectUpdateDate() { @@ -144,6 +139,17 @@ public class StakeholderGeneric extends Common { this.funderType = funderType; } + public boolean isStandalone() { + if(standalone == null) { + standalone = true; + } + return standalone; + } + + public void setStandalone(boolean standalone) { + this.standalone = standalone; + } + public boolean isCopy() { if(copy == null) { copy = this.defaultId != null; @@ -155,11 +161,19 @@ public class StakeholderGeneric extends Common { this.copy = copy; } - public List getTopics() { + public List getTopics() { return topics; } - public void setTopics(List topics) { + public void setTopics(List topics) { this.topics = topics; } + + public Umbrella getUmbrella() { + return umbrella; + } + + public void setUmbrella(Umbrella umbrella) { + this.umbrella = umbrella; + } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/generics/SubCategoryGeneric.java b/src/main/java/eu/dnetlib/uoamonitorservice/generics/SubCategoryGeneric.java index e1870fa..a1b415d 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/generics/SubCategoryGeneric.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/generics/SubCategoryGeneric.java @@ -3,9 +3,9 @@ package eu.dnetlib.uoamonitorservice.generics; import java.util.ArrayList; import java.util.List; -public class SubCategoryGeneric extends Common { - protected List charts; - protected List numbers; +public class SubCategoryGeneric extends Common { + protected List charts; + protected List numbers; public SubCategoryGeneric() {} public SubCategoryGeneric(SubCategoryGeneric subCategory) { @@ -21,19 +21,19 @@ public class SubCategoryGeneric extends Common { charts = new ArrayList<>(); } - public List getCharts() { + public List getCharts() { return charts; } - public void setCharts(List charts) { + public void setCharts(List charts) { this.charts = charts; } - public List getNumbers() { + public List getNumbers() { return numbers; } - public void setNumbers(List numbers) { + public void setNumbers(List numbers) { this.numbers = numbers; } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/generics/TopicGeneric.java b/src/main/java/eu/dnetlib/uoamonitorservice/generics/TopicGeneric.java index af48845..2c52cb6 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/generics/TopicGeneric.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/generics/TopicGeneric.java @@ -1,18 +1,11 @@ package eu.dnetlib.uoamonitorservice.generics; -import com.fasterxml.jackson.annotation.JsonProperty; -import eu.dnetlib.uoamonitorservice.primitives.Visibility; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.LastModifiedDate; - import java.util.ArrayList; -import java.util.Date; import java.util.List; -public class TopicGeneric extends Common { +public class TopicGeneric extends Common { protected String icon; - protected List categories; + protected List categories; public TopicGeneric() { } @@ -39,11 +32,11 @@ public class TopicGeneric extends Common { this.icon = icon; } - public List getCategories() { + public List getCategories() { return categories; } - public void setCategories(List categories) { + public void setCategories(List categories) { this.categories = categories; } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/primitives/StakeholderType.java b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/StakeholderType.java index 8e58b2b..6692e02 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/primitives/StakeholderType.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/StakeholderType.java @@ -4,6 +4,16 @@ public enum StakeholderType { // Do not rename or remove existing values. This may cause problems with already stored values in DB funder, ri, project, organization, country, researcher, datasource, + publisher, journal, FUNDER, RI, PROJECT, ORGANIZATION, - COUNTRY, RESEARCHER, DATASOURCE; + COUNTRY, RESEARCHER, DATASOURCE, + PUBLISHER, JOURNAL; + + public static StakeholderType convert(String type) { + if(type == null) { + return null; + } else { + return StakeholderType.valueOf(type); + } + } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/primitives/Umbrella.java b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/Umbrella.java new file mode 100644 index 0000000..3d85c29 --- /dev/null +++ b/src/main/java/eu/dnetlib/uoamonitorservice/primitives/Umbrella.java @@ -0,0 +1,60 @@ +package eu.dnetlib.uoamonitorservice.primitives; + +import eu.dnetlib.uoamonitorservice.entities.Stakeholder; +import eu.dnetlib.uoamonitorservice.generics.Common; +import eu.dnetlib.uoamonitorservice.service.StakeholderService; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class Umbrella { + List types; + Map> children; + + public Umbrella() { + this.types = new ArrayList<>(); + this.children = new HashMap<>(); + } + + public Umbrella(List types) { + this.types = types; + this.children = new HashMap<>(); + } + + public static Umbrella convert(Umbrella umbrellaFull) { + if(umbrellaFull == null) { + return null; + } + Umbrella umbrella = new Umbrella<>(umbrellaFull.getTypes()); + umbrella.types.forEach(type -> umbrella.children.put(type, umbrellaFull.getChildren().get(type).stream().map(Common::getId).collect(Collectors.toList()))); + return umbrella; + } + + public static Umbrella convert(Umbrella umbrella, StakeholderService service) { + if(umbrella == null) { + return null; + } + Umbrella umbrellaFull = new Umbrella<>(umbrella.getTypes()); + umbrella.types.forEach(type -> umbrellaFull.children.put(type, umbrella.getChildren().get(type).stream().map(service::findByPath).collect(Collectors.toList()))); + return umbrellaFull; + } + + public Map> getChildren() { + return children; + } + + public void setChildren(Map> children) { + this.children = children; + } + + public List getTypes() { + return types; + } + + public void setTypes(List types) { + this.types = types; + } +} diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/service/CategoryService.java b/src/main/java/eu/dnetlib/uoamonitorservice/service/CategoryService.java index aafe373..3124699 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/service/CategoryService.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/service/CategoryService.java @@ -151,7 +151,7 @@ public class CategoryService { } public void reorderChildren(Stakeholder defaultStakeholder, Category defaultCategory, List defaultSubCategories) { - this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> { + this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> { this.dao.findByDefaultId(defaultCategory.getId()).stream().map(category -> this.getFullCategory(stakeholder.getType(), stakeholder.getAlias(), category)).forEach(category -> { this.reorderSubCategories(stakeholder, new Category(category), this.commonService.reorder(defaultSubCategories, category.getSubCategories().stream().map(subCategory -> (Common) subCategory).collect(Collectors.toList()))); diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/service/SectionService.java b/src/main/java/eu/dnetlib/uoamonitorservice/service/SectionService.java index d10df17..5665bcc 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/service/SectionService.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/service/SectionService.java @@ -174,7 +174,7 @@ public class SectionService { } public void reorderChildren(Stakeholder defaultStakeholder, Section defaultSection, List defaultIndicators) { - this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> { + this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> { this.dao.findByDefaultId(defaultSection.getId()).stream().map(section -> this.getFullSection(stakeholder.getType(), stakeholder.getAlias(), section)).forEach(section -> { this.reorderIndicators(stakeholder, new Section(section), this.commonService.reorder(defaultIndicators, section.getIndicators().stream().map(indicator -> (Common) indicator).collect(Collectors.toList()))); diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/service/StakeholderService.java b/src/main/java/eu/dnetlib/uoamonitorservice/service/StakeholderService.java index a3e81eb..4d88463 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/service/StakeholderService.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/service/StakeholderService.java @@ -1,34 +1,38 @@ package eu.dnetlib.uoamonitorservice.service; -import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException; import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO; +import eu.dnetlib.uoamonitorservice.dto.ManageStakeholders; import eu.dnetlib.uoamonitorservice.dto.StakeholderFull; +import eu.dnetlib.uoamonitorservice.dto.TopicFull; import eu.dnetlib.uoamonitorservice.entities.Stakeholder; import eu.dnetlib.uoamonitorservice.generics.Common; import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException; +import eu.dnetlib.uoamonitorservice.primitives.StakeholderType; +import eu.dnetlib.uoamonitorservice.primitives.Umbrella; import eu.dnetlib.uoamonitorservice.primitives.Visibility; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashSet; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; @Service public class StakeholderService { private final StakeholderDAO dao; - private final CommonService commonService; private final TopicService topicService; + private final MongoTemplate mongoTemplate; @Autowired - public StakeholderService(StakeholderDAO dao, CommonService commonService, TopicService topicService) { + public StakeholderService(StakeholderDAO dao, CommonService commonService, TopicService topicService, MongoTemplate mongoTemplate) { this.dao = dao; this.commonService = commonService; this.topicService = topicService; + this.mongoTemplate = mongoTemplate; } public Stakeholder findByAlias(String alias) { @@ -36,74 +40,95 @@ public class StakeholderService { } public List findByDefaultId(String id) { - return this.dao.findByDefaultIdAndCopyTrue(id); + return this.dao.findByDefaultIdAndCopyIsTrue(id); } public Stakeholder findByPath(String stakeholderId) { - if(stakeholderId.equals("-1")) { + if (stakeholderId.equals("-1")) { return null; } return dao.findById(stakeholderId).orElseThrow(() -> new EntityNotFoundException("Stakeholder with id: " + stakeholderId + " not found")); } - public List getAllAliases() { - return this.dao.findAll().stream().map(Stakeholder::getAlias).collect(Collectors.toList()); + public List getAllAliases(String type) { + return this.getAll(type).stream().map(Stakeholder::getAlias).collect(Collectors.toList()); } public List getAll(String type) { - if (type != null) { - return this.dao.findByType(type); - } - return this.dao.findAll(); + return this.dao.allStakeholders(StakeholderType.convert(type)); } - public List getAllDefaultByRole(String type) { - return (type == null ? this.dao.findByDefaultIdIsNull() : this.dao.findByDefaultIdAndType(null, type)).stream() - .filter(stakeholder -> this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), true)) + + public List getAccessedStakeholders(List stakeholders, boolean isDefault) { + return stakeholders.stream() + .filter(stakeholder -> this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), isDefault)) .collect(Collectors.toList()); } - public List getStakeholdersByTypeAndRole(String type, String defaultId, boolean manage) { - List stakeholders; - if (type != null && defaultId != null) { - stakeholders = dao.findByDefaultIdAndType(defaultId, type); - } else if (defaultId != null) { - stakeholders = dao.findByDefaultIdAndCopyTrue(defaultId); - } else if (type != null) { - stakeholders = dao.findByDefaultIdIsNotNullAndType(type); - } else { - stakeholders = dao.findByDefaultIdIsNotNull(); - } - return stakeholders.stream().filter(stakeholder -> - (!manage && (stakeholder.getVisibility() == Visibility.PUBLIC || stakeholder.getVisibility() == Visibility.RESTRICTED)) - || this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), false)) + public ManageStakeholders getManageStakeholders(String type) { + ManageStakeholders manageStakeholders = new ManageStakeholders(); + StakeholderType stakeholderType = StakeholderType.convert(type); + manageStakeholders.setTemplates(this.getAccessedStakeholders(this.dao.defaultStakeholders(stakeholderType), true)); + manageStakeholders.setStandalone(this.getAccessedStakeholders(this.dao.standaloneStakeholders(stakeholderType), false)); + manageStakeholders.setDependent(this.getAccessedStakeholders(this.dao.dependentStakeholders(stakeholderType), false)); + manageStakeholders.setUmbrella(this.getAccessedStakeholders(this.dao.umbrellaStakeholders(stakeholderType), false)); + return manageStakeholders; + } + + public List getVisibleStakeholders(String type, String defaultId) { + return this.dao.browseStakeholders(StakeholderType.convert(type), defaultId).stream().filter(stakeholder -> + stakeholder.getVisibility() == Visibility.PUBLIC || + stakeholder.getVisibility() == Visibility.RESTRICTED || + this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), false)) .collect(Collectors.toList()); } public StakeholderFull getFullStakeholder(Stakeholder stakeholder) { if (this.commonService.hasVisibilityAuthority(stakeholder.getType(), stakeholder.getAlias(), stakeholder)) { - if(!stakeholder.isCopy() && stakeholder.getDefaultId() != null) { + List topics = stakeholder.getTopics().stream() + .map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId)) + .collect(Collectors.toList()); + if (!stakeholder.isCopy() && stakeholder.getDefaultId() != null) { Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId()); - if(defaultStakeholder != null) { - return new StakeholderFull(stakeholder, - defaultStakeholder.getTopics().stream() - .map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId)) - .collect(Collectors.toList())); + if (defaultStakeholder != null) { + topics = defaultStakeholder.getTopics().stream() + .map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId)) + .collect(Collectors.toList()); } } - return new StakeholderFull(stakeholder, - stakeholder.getTopics().stream() - .map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId)) - .collect(Collectors.toList())); + Umbrella umbrella = Umbrella.convert(stakeholder.getUmbrella(), this); + return new StakeholderFull(stakeholder, topics, umbrella); } else { return null; } } - public Stakeholder buildStakeholder(Stakeholder stakeholder, String copyId) { - if(stakeholder.getDefaultId() == null) { + private List getOtherParents(String parent, String type, String id) { + Query query = new Query(); + query.addCriteria(Criteria.where("alias").ne(parent).and("umbrella.children." + type).regex(id, "i")); + return mongoTemplate.find(query, Stakeholder.class); + } + + private Optional getActiveParent(String parent, String type, String id) { + Query query = new Query(); + query.addCriteria(Criteria.where("alias").is(parent).and("umbrella.children." + type).regex(id, "i")); + return Optional.ofNullable(mongoTemplate.findOne(query, Stakeholder.class)); + } + + public StakeholderFull getFullStakeholderWithParents(Stakeholder stakeholder, String type, String parent) { + StakeholderFull stakeholderFull = this.getFullStakeholder(stakeholder); + if(stakeholderFull != null) { + stakeholderFull.setParent(this.getActiveParent(parent, type, stakeholder.getId()) + .orElseThrow(() -> new EntityNotFoundException("Stakeholder with alias: " + stakeholder.getAlias() + " not found in stakeholder " + parent))); + stakeholderFull.setOtherParents(this.getOtherParents(parent, type, stakeholder.getId())); + } + return stakeholderFull; + } + + public Stakeholder buildStakeholder(Stakeholder stakeholder, String copyId, boolean umbrella) { + if (stakeholder.getDefaultId() == null) { stakeholder.setCopy(false); - if(copyId == null) { + if (copyId == null) { stakeholder.setTopics(new ArrayList<>()); } else { Stakeholder copyFrom = this.findByPath(copyId); @@ -111,29 +136,31 @@ public class StakeholderService { } } else { stakeholder.setTopics(new ArrayList<>()); - if(stakeholder.isCopy()) { + if (stakeholder.isCopy()) { Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId()); - if(defaultStakeholder != null) { + if (defaultStakeholder != null) { stakeholder.setTopics(defaultStakeholder.getTopics().stream().map(this.topicService::build).collect(Collectors.toList())); } } } + if (umbrella) { + stakeholder.setUmbrella(new Umbrella<>()); + } return this.save(stakeholder); } public Stakeholder save(Stakeholder stakeholder) { if (stakeholder.getId() != null) { Stakeholder old = this.findByPath(stakeholder.getId()); - stakeholder.setTopics(old.getTopics()); if (!stakeholder.isCopy() && stakeholder.getDefaultId() != null) { stakeholder.getTopics().forEach(topic -> { this.topicService.delete(stakeholder.getType(), topic, false); }); stakeholder.setTopics(new ArrayList<>()); } else { - if(old.getTopics().isEmpty() && old.getDefaultId() != null) { + if (old.getTopics().isEmpty() && old.getDefaultId() != null) { Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId()); - if(defaultStakeholder != null) { + if (defaultStakeholder != null) { stakeholder.setTopics(defaultStakeholder.getTopics().stream().map(this.topicService::build).collect(Collectors.toList())); } } @@ -164,8 +191,8 @@ public class StakeholderService { } public void reorderChildren(Stakeholder defaultStakeholder, List defaultTopics) { - this.dao.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).stream().map(this::getFullStakeholder).forEach(stakeholder -> { - this.reorderTopics(new Stakeholder(stakeholder), + this.dao.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).stream().map(this::getFullStakeholder).forEach(stakeholder -> { + this.reorderTopics(new Stakeholder(stakeholder, this), this.commonService.reorder(defaultTopics, stakeholder.getTopics().stream().map(topic -> (Common) topic).collect(Collectors.toList()))); }); } @@ -173,7 +200,7 @@ public class StakeholderService { public String delete(String id) { Stakeholder stakeholder = this.findByPath(id); if (this.commonService.hasDeleteAuthority(stakeholder.getType())) { - this.dao.findByDefaultIdAndCopyTrue(stakeholder.getId()).forEach(child -> { + this.dao.findByDefaultIdAndCopyIsTrue(stakeholder.getId()).forEach(child -> { this.delete(child.getId()); }); stakeholder.getTopics().forEach(topicId -> { @@ -195,7 +222,7 @@ public class StakeholderService { .collect(Collectors.toList())); } stakeholder.setVisibility(visibility); - stakeholder.update(this.save(new Stakeholder(stakeholder))); + stakeholder.update(this.save(new Stakeholder(stakeholder, this))); return stakeholder; } else { this.commonService.unauthorized("Change stakeholder visibility: You are not authorized to update stakeholder with id: " + stakeholder.getId()); diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/service/SubCategoryService.java b/src/main/java/eu/dnetlib/uoamonitorservice/service/SubCategoryService.java index 92ce3a0..1948fd3 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/service/SubCategoryService.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/service/SubCategoryService.java @@ -159,7 +159,7 @@ public class SubCategoryService { } public void moveIndicatorChildren(Stakeholder defaultStakeholder, SubCategory defaultSubCategory, MoveIndicator moveIndicator) { - this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> { + this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> { this.dao.findByDefaultId(defaultSubCategory.getId()).stream() .map(subCategory -> this.getFullSubCategory(stakeholder.getType(), stakeholder. getAlias(), subCategory)) .collect(Collectors.toList()).forEach(subCategory -> { @@ -214,7 +214,7 @@ public class SubCategoryService { } public void reorderChildrenNumbers(Stakeholder defaultStakeholder, SubCategory defaultSubCategory, List defaultSections) { - this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> { + this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> { this.dao.findByDefaultId(defaultSubCategory.getId()).stream().map(subCategory -> this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory)).forEach(subCategory -> { this.reorderNumbers(stakeholder, new SubCategory(subCategory), this.commonService.reorder(defaultSections, subCategory.getNumbers().stream().map(section -> (Common) section).collect(Collectors.toList()))); @@ -223,7 +223,7 @@ public class SubCategoryService { } public void reorderChildrenCharts(Stakeholder defaultStakeholder, SubCategory defaultSubCategory, List defaultSections) { - this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> { + this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> { this.dao.findByDefaultId(defaultSubCategory.getId()).stream().map(subCategory -> this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory)).forEach(subCategory -> { this.reorderCharts(stakeholder, new SubCategory(subCategory), this.commonService.reorder(defaultSections, subCategory.getCharts().stream().map(section -> (Common) section).collect(Collectors.toList()))); diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/service/TopicService.java b/src/main/java/eu/dnetlib/uoamonitorservice/service/TopicService.java index f26bdcf..f25b80a 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/service/TopicService.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/service/TopicService.java @@ -109,7 +109,7 @@ public class TopicService { } public void createChildren(Stakeholder defaultStakeholder, Topic topic) { - this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> { + this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> { this.save(stakeholder, topic.copy()); }); } @@ -138,7 +138,7 @@ public class TopicService { } public void reorderChildren(Stakeholder defaultStakeholder, Topic defaultTopic, List defaultCategories) { - this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> { + this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> { this.dao.findByDefaultId(defaultTopic.getId()).stream().map(topic -> this.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topic)).forEach(topic -> { this.reorderCategories(stakeholder, new Topic(topic), this.commonService.reorder(defaultCategories, topic.getCategories().stream().map(category -> (Common) category).collect(Collectors.toList())));