Add method to get child stakeholder and change manageStakeholder to return object of different types of stakeholders.
This commit is contained in:
parent
0fdb13ae56
commit
c15b63d3da
|
@ -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<String> getAllReservedStakeholderAlias() {
|
||||
List<String> stakeholderAlias = this.stakeholderService.getAllAliases();
|
||||
stakeholderAlias.add("all");
|
||||
stakeholderAlias.add("default");
|
||||
stakeholderAlias.add("alias");
|
||||
public List<String> getAllReservedStakeholderAlias(@RequestParam(required = false) String type) {
|
||||
List<String> 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<Stakeholder> getAllDefaultStakeholders(@RequestParam(required = false) String type) {
|
||||
return this.stakeholderService.getAllDefaultByRole(type);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/stakeholder", method = RequestMethod.GET)
|
||||
public List<Stakeholder> 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<Stakeholder> 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()")
|
||||
|
|
|
@ -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<Stakeholder, String> {
|
||||
/**
|
||||
* All Stakeholders
|
||||
*/
|
||||
List<Stakeholder> findAll();
|
||||
List<Stakeholder> findByType(String Type);
|
||||
|
||||
List<Stakeholder> findByDefaultId(String id);
|
||||
|
||||
List<Stakeholder> findByType(StakeholderType Type);
|
||||
|
||||
List<Stakeholder> findByTypeAndDefaultId(StakeholderType Type, String id);
|
||||
|
||||
default List<Stakeholder> allStakeholders() {
|
||||
return allStakeholders(null);
|
||||
}
|
||||
|
||||
default List<Stakeholder> allStakeholders(StakeholderType type) {
|
||||
return allStakeholders(type, null);
|
||||
}
|
||||
|
||||
default List<Stakeholder> 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<Stakeholder> findByDefaultIdIsNull();
|
||||
List<Stakeholder> findByDefaultIdAndCopyTrue(String defaultId);
|
||||
List<Stakeholder> findByDefaultIdAndType(String DefaultId, String Type);
|
||||
|
||||
List<Stakeholder> findByDefaultIdIsNotNull();
|
||||
List<Stakeholder> findByDefaultIdIsNotNullAndType(String Type);
|
||||
List<Stakeholder> findByDefaultIdIsNullAndType(StakeholderType Type);
|
||||
|
||||
default List<Stakeholder> defaultStakeholders(StakeholderType type) {
|
||||
if (type == null) {
|
||||
return findByDefaultIdIsNull();
|
||||
}
|
||||
return findByDefaultIdIsNullAndType(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Standalone Stakeholders (not umbrella)
|
||||
*/
|
||||
List<Stakeholder> findByDefaultIdIsNotNullAndStandaloneIsTrueAndUmbrellaIsNull();
|
||||
|
||||
List<Stakeholder> findByDefaultIdIsNotNullAndStandaloneIsTrueAndUmbrellaIsNullAndDefaultId(String id);
|
||||
|
||||
List<Stakeholder> findByDefaultIdIsNotNullAndStandaloneIsTrueAndUmbrellaIsNullAndType(StakeholderType Type);
|
||||
|
||||
List<Stakeholder> findByDefaultIdIsNotNullAndStandaloneIsTrueAndUmbrellaIsNullAndTypeAndDefaultId(StakeholderType Type, String id);
|
||||
|
||||
default List<Stakeholder> standaloneStakeholders() {
|
||||
return standaloneStakeholders(null);
|
||||
}
|
||||
|
||||
default List<Stakeholder> standaloneStakeholders(StakeholderType type) {
|
||||
return standaloneStakeholders(type, null);
|
||||
}
|
||||
|
||||
default List<Stakeholder> 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<Stakeholder> findByDefaultIdIsNotNullAndStandaloneIsFalse();
|
||||
|
||||
List<Stakeholder> findByDefaultIdIsNotNullAndStandaloneIsFalseAndDefaultId(String id);
|
||||
|
||||
List<Stakeholder> findByDefaultIdIsNotNullAndStandaloneIsFalseAndType(StakeholderType Type);
|
||||
|
||||
List<Stakeholder> findByDefaultIdIsNotNullAndStandaloneIsFalseAndTypeAndDefaultId(StakeholderType Type, String id);
|
||||
|
||||
default List<Stakeholder> dependentStakeholders() {
|
||||
return dependentStakeholders(null);
|
||||
}
|
||||
|
||||
default List<Stakeholder> dependentStakeholders(StakeholderType type) {
|
||||
return dependentStakeholders(type, null);
|
||||
}
|
||||
|
||||
default List<Stakeholder> 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<Stakeholder> findByUmbrellaNotNull();
|
||||
|
||||
List<Stakeholder> findByUmbrellaNotNullAndDefaultId(String id);
|
||||
|
||||
List<Stakeholder> findByUmbrellaNotNullAndType(StakeholderType Type);
|
||||
|
||||
List<Stakeholder> findByUmbrellaNotNullAndTypeAndDefaultId(StakeholderType Type, String id);
|
||||
|
||||
default List<Stakeholder> umbrellaStakeholders() {
|
||||
return umbrellaStakeholders(null);
|
||||
}
|
||||
|
||||
default List<Stakeholder> umbrellaStakeholders(StakeholderType type) {
|
||||
return umbrellaStakeholders(type, null);
|
||||
}
|
||||
|
||||
default List<Stakeholder> 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<Stakeholder> findByDefaultIdNotNullAndStandaloneIsTrue();
|
||||
|
||||
List<Stakeholder> findByDefaultIdNotNullAndStandaloneIsTrueAndDefaultId(String id);
|
||||
|
||||
List<Stakeholder> findByDefaultIdNotNullAndStandaloneIsTrueAndType(StakeholderType Type);
|
||||
|
||||
List<Stakeholder> findByDefaultIdNotNullAndStandaloneIsTrueAndTypeAndDefaultId(StakeholderType Type, String id);
|
||||
|
||||
default List<Stakeholder> browseStakeholders() {
|
||||
return browseStakeholders(null);
|
||||
}
|
||||
|
||||
default List<Stakeholder> browseStakeholders(StakeholderType type) {
|
||||
return browseStakeholders(type, null);
|
||||
}
|
||||
|
||||
default List<Stakeholder> 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<Stakeholder> findByDefaultIdAndCopyIsTrue(String defaultId);
|
||||
|
||||
List<Stakeholder> findByTopicsContaining(String topic);
|
||||
|
||||
Optional<Stakeholder> findById(String Id);
|
||||
Optional<Stakeholder> findByAlias(String Alias);
|
||||
Optional<Stakeholder> findById(String id);
|
||||
|
||||
Optional<Stakeholder> findByAlias(String alias);
|
||||
|
||||
|
||||
void delete(String Id);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package eu.dnetlib.uoamonitorservice.dto;
|
||||
|
||||
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ManageStakeholders {
|
||||
List<Stakeholder> templates;
|
||||
List<Stakeholder> standalone;
|
||||
List<Stakeholder> dependent;
|
||||
List<Stakeholder> umbrella;
|
||||
|
||||
public ManageStakeholders() {
|
||||
}
|
||||
|
||||
public List<Stakeholder> getTemplates() {
|
||||
return templates;
|
||||
}
|
||||
|
||||
public void setTemplates(List<Stakeholder> templates) {
|
||||
this.templates = templates;
|
||||
}
|
||||
|
||||
public List<Stakeholder> getStandalone() {
|
||||
return standalone;
|
||||
}
|
||||
|
||||
public void setStandalone(List<Stakeholder> standalone) {
|
||||
this.standalone = standalone;
|
||||
}
|
||||
|
||||
public List<Stakeholder> getDependent() {
|
||||
return dependent;
|
||||
}
|
||||
|
||||
public void setDependent(List<Stakeholder> dependent) {
|
||||
this.dependent = dependent;
|
||||
}
|
||||
|
||||
public List<Stakeholder> getUmbrella() {
|
||||
return umbrella;
|
||||
}
|
||||
|
||||
public void setUmbrella(List<Stakeholder> umbrella) {
|
||||
this.umbrella = umbrella;
|
||||
}
|
||||
}
|
|
@ -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<TopicFull> {
|
||||
public class StakeholderFull extends StakeholderGeneric<TopicFull, Stakeholder> {
|
||||
public List<Stakeholder> otherParents;
|
||||
public Stakeholder parent;
|
||||
|
||||
public StakeholderFull() {
|
||||
super();
|
||||
}
|
||||
|
||||
public StakeholderFull(StakeholderGeneric stakeholder, List<TopicFull> topics) {
|
||||
public StakeholderFull(StakeholderGeneric stakeholder, List<TopicFull> topics, Umbrella<Stakeholder> umbrella) {
|
||||
super(stakeholder);
|
||||
topics.removeIf(Objects::isNull);
|
||||
this.topics = topics;
|
||||
this.umbrella = umbrella;
|
||||
}
|
||||
|
||||
public List<Stakeholder> getOtherParents() {
|
||||
return otherParents;
|
||||
}
|
||||
|
||||
public void setOtherParents(List<Stakeholder> otherParents) {
|
||||
this.otherParents = otherParents;
|
||||
}
|
||||
|
||||
public Stakeholder getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(Stakeholder parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String> {
|
||||
public class Stakeholder extends StakeholderGeneric<String, String> {
|
||||
|
||||
public Stakeholder() {
|
||||
super();
|
||||
|
@ -21,10 +21,11 @@ public class Stakeholder extends StakeholderGeneric<String> {
|
|||
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) {
|
||||
|
|
|
@ -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<StringOrSubcategory> extends Common {
|
||||
public class CategoryGeneric<T> extends Common {
|
||||
protected boolean isOverview;
|
||||
protected List<StringOrSubcategory> subCategories;
|
||||
protected List<T> subCategories;
|
||||
|
||||
public CategoryGeneric() {}
|
||||
|
||||
|
@ -40,11 +33,11 @@ public class CategoryGeneric<StringOrSubcategory> extends Common {
|
|||
this.isOverview = isOverview;
|
||||
}
|
||||
|
||||
public List<StringOrSubcategory> getSubCategories() {
|
||||
public List<T> getSubCategories() {
|
||||
return subCategories;
|
||||
}
|
||||
|
||||
public void setSubCategories(List<StringOrSubcategory> subCategories) {
|
||||
public void setSubCategories(List<T> subCategories) {
|
||||
this.subCategories = subCategories;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,11 @@ import eu.dnetlib.uoamonitorservice.primitives.IndicatorType;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SectionGeneric<StringOrIndicator> extends Common {
|
||||
public class SectionGeneric<T> extends Common {
|
||||
protected String title;
|
||||
protected String stakeholderAlias;
|
||||
protected IndicatorType type;
|
||||
protected List<StringOrIndicator> indicators;
|
||||
protected List<T> indicators;
|
||||
|
||||
public SectionGeneric() {
|
||||
}
|
||||
|
@ -60,11 +60,11 @@ public class SectionGeneric<StringOrIndicator> extends Common {
|
|||
return this.type == IndicatorType.NUMBER || this.type == IndicatorType.number;
|
||||
}
|
||||
|
||||
public List<StringOrIndicator> getIndicators() {
|
||||
public List<T> getIndicators() {
|
||||
return indicators;
|
||||
}
|
||||
|
||||
public void setIndicators(List<StringOrIndicator> indicators) {
|
||||
public void setIndicators(List<T> indicators) {
|
||||
this.indicators = indicators;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<StringOrTopic> extends Common {
|
||||
public class StakeholderGeneric<T, S> extends Common {
|
||||
protected StakeholderType type;
|
||||
protected Date projectUpdateDate = null;
|
||||
protected String index_id;
|
||||
|
@ -23,8 +19,10 @@ public class StakeholderGeneric<StringOrTopic> extends Common {
|
|||
protected boolean isUpload = false;
|
||||
protected Locale locale = Locale.EU;
|
||||
protected String funderType;
|
||||
protected Boolean standalone = true;
|
||||
protected Boolean copy;
|
||||
protected List<StringOrTopic> topics;
|
||||
protected List<T> topics = new ArrayList<>();
|
||||
protected Umbrella<S> umbrella;
|
||||
|
||||
public StakeholderGeneric() {
|
||||
}
|
||||
|
@ -47,6 +45,7 @@ public class StakeholderGeneric<StringOrTopic> 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<StringOrTopic> 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<StringOrTopic> 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<StringOrTopic> extends Common {
|
|||
this.copy = copy;
|
||||
}
|
||||
|
||||
public List<StringOrTopic> getTopics() {
|
||||
public List<T> getTopics() {
|
||||
return topics;
|
||||
}
|
||||
|
||||
public void setTopics(List<StringOrTopic> topics) {
|
||||
public void setTopics(List<T> topics) {
|
||||
this.topics = topics;
|
||||
}
|
||||
|
||||
public Umbrella<S> getUmbrella() {
|
||||
return umbrella;
|
||||
}
|
||||
|
||||
public void setUmbrella(Umbrella<S> umbrella) {
|
||||
this.umbrella = umbrella;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@ package eu.dnetlib.uoamonitorservice.generics;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SubCategoryGeneric<StringOrSection> extends Common {
|
||||
protected List<StringOrSection> charts;
|
||||
protected List<StringOrSection> numbers;
|
||||
public class SubCategoryGeneric<T> extends Common {
|
||||
protected List<T> charts;
|
||||
protected List<T> numbers;
|
||||
|
||||
public SubCategoryGeneric() {}
|
||||
public SubCategoryGeneric(SubCategoryGeneric subCategory) {
|
||||
|
@ -21,19 +21,19 @@ public class SubCategoryGeneric<StringOrSection> extends Common {
|
|||
charts = new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<StringOrSection> getCharts() {
|
||||
public List<T> getCharts() {
|
||||
return charts;
|
||||
}
|
||||
|
||||
public void setCharts(List<StringOrSection> charts) {
|
||||
public void setCharts(List<T> charts) {
|
||||
this.charts = charts;
|
||||
}
|
||||
|
||||
public List<StringOrSection> getNumbers() {
|
||||
public List<T> getNumbers() {
|
||||
return numbers;
|
||||
}
|
||||
|
||||
public void setNumbers(List<StringOrSection> numbers) {
|
||||
public void setNumbers(List<T> numbers) {
|
||||
this.numbers = numbers;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<StringOrCategory> extends Common {
|
||||
public class TopicGeneric<T> extends Common {
|
||||
protected String icon;
|
||||
protected List<StringOrCategory> categories;
|
||||
protected List<T> categories;
|
||||
|
||||
public TopicGeneric() {
|
||||
}
|
||||
|
@ -39,11 +32,11 @@ public class TopicGeneric<StringOrCategory> extends Common {
|
|||
this.icon = icon;
|
||||
}
|
||||
|
||||
public List<StringOrCategory> getCategories() {
|
||||
public List<T> getCategories() {
|
||||
return categories;
|
||||
}
|
||||
|
||||
public void setCategories(List<StringOrCategory> categories) {
|
||||
public void setCategories(List<T> categories) {
|
||||
this.categories = categories;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<T> {
|
||||
List<StakeholderType> types;
|
||||
Map<StakeholderType, List<T>> children;
|
||||
|
||||
public Umbrella() {
|
||||
this.types = new ArrayList<>();
|
||||
this.children = new HashMap<>();
|
||||
}
|
||||
|
||||
public Umbrella(List<StakeholderType> types) {
|
||||
this.types = types;
|
||||
this.children = new HashMap<>();
|
||||
}
|
||||
|
||||
public static Umbrella<String> convert(Umbrella<Stakeholder> umbrellaFull) {
|
||||
if(umbrellaFull == null) {
|
||||
return null;
|
||||
}
|
||||
Umbrella<String> 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<Stakeholder> convert(Umbrella<String> umbrella, StakeholderService service) {
|
||||
if(umbrella == null) {
|
||||
return null;
|
||||
}
|
||||
Umbrella<Stakeholder> 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<StakeholderType, List<T>> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(Map<StakeholderType, List<T>> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public List<StakeholderType> getTypes() {
|
||||
return types;
|
||||
}
|
||||
|
||||
public void setTypes(List<StakeholderType> types) {
|
||||
this.types = types;
|
||||
}
|
||||
}
|
|
@ -151,7 +151,7 @@ public class CategoryService {
|
|||
}
|
||||
|
||||
public void reorderChildren(Stakeholder defaultStakeholder, Category defaultCategory, List<String> 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())));
|
||||
|
|
|
@ -174,7 +174,7 @@ public class SectionService {
|
|||
}
|
||||
|
||||
public void reorderChildren(Stakeholder defaultStakeholder, Section defaultSection, List<String> 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())));
|
||||
|
|
|
@ -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<Stakeholder> 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<String> getAllAliases() {
|
||||
return this.dao.findAll().stream().map(Stakeholder::getAlias).collect(Collectors.toList());
|
||||
public List<String> getAllAliases(String type) {
|
||||
return this.getAll(type).stream().map(Stakeholder::getAlias).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Stakeholder> getAll(String type) {
|
||||
if (type != null) {
|
||||
return this.dao.findByType(type);
|
||||
}
|
||||
return this.dao.findAll();
|
||||
return this.dao.allStakeholders(StakeholderType.convert(type));
|
||||
}
|
||||
|
||||
public List<Stakeholder> 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<Stakeholder> getAccessedStakeholders(List<Stakeholder> stakeholders, boolean isDefault) {
|
||||
return stakeholders.stream()
|
||||
.filter(stakeholder -> this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), isDefault))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Stakeholder> getStakeholdersByTypeAndRole(String type, String defaultId, boolean manage) {
|
||||
List<Stakeholder> 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<Stakeholder> 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<TopicFull> 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<Stakeholder> 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<Stakeholder> 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<Stakeholder> 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<String> 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());
|
||||
|
|
|
@ -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<String> 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<String> 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())));
|
||||
|
|
|
@ -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<String> 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())));
|
||||
|
|
Loading…
Reference in New Issue