Compare commits
37 Commits
master
...
uoa-monito
9
pom.xml
9
pom.xml
|
@ -1,14 +1,13 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>uoa-monitor-service</artifactId>
|
<artifactId>uoa-monitor-service</artifactId>
|
||||||
<version>1.0.4-SNAPSHOT</version>
|
<version>1.1.11-BETA</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<name>uoa-monitor-service</name>
|
<name>uoa-monitor-service</name>
|
||||||
<scm>
|
<scm>
|
||||||
<developerConnection>scm:git:gitea@code-repo.d4science.org:MaDgIK/uoa-monitor-service.git</developerConnection>
|
<developerConnection>scm:git:gitea@code-repo.d4science.org:MaDgIK/uoa-monitor-service.git</developerConnection>
|
||||||
|
<tag>uoa-monitor-service-1.1.11-BETA</tag>
|
||||||
</scm>
|
</scm>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>eu.dnetlib</groupId>
|
<groupId>eu.dnetlib</groupId>
|
||||||
|
@ -30,7 +29,7 @@
|
||||||
<dependency> <!-- this dependency includes dependency to uoa-authorization-library -->
|
<dependency> <!-- this dependency includes dependency to uoa-authorization-library -->
|
||||||
<groupId>eu.dnetlib</groupId>
|
<groupId>eu.dnetlib</groupId>
|
||||||
<artifactId>uoa-admin-tools-library</artifactId>
|
<artifactId>uoa-admin-tools-library</artifactId>
|
||||||
<version>1.0.13</version>
|
<version>1.0.10</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>eu.dnetlib</groupId>
|
<groupId>eu.dnetlib</groupId>
|
||||||
|
|
|
@ -234,6 +234,8 @@ function uniqueIndexes() {
|
||||||
db.stakeholder.createIndex( { "alias": 1 }, { unique: true } );
|
db.stakeholder.createIndex( { "alias": 1 }, { unique: true } );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use monitordb;
|
||||||
|
|
||||||
upperCaseEnumValues();
|
upperCaseEnumValues();
|
||||||
addHeightInIndicators();
|
addHeightInIndicators();
|
||||||
addVisibility();
|
addVisibility();
|
||||||
|
|
|
@ -52,6 +52,8 @@ function addFooterHelpTextForPortalType(portalType) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use monitordb;
|
||||||
|
|
||||||
addHomePageInPortalType("funder");
|
addHomePageInPortalType("funder");
|
||||||
addFooterDivIdForPortalType("funder");
|
addFooterDivIdForPortalType("funder");
|
||||||
addFooterHelpTextForPortalType("funder");
|
addFooterHelpTextForPortalType("funder");
|
||||||
|
|
|
@ -176,5 +176,7 @@ function addFundingStreamInDefaultMSCA() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use monitordb;
|
||||||
|
|
||||||
statsProfileOfIndicatorsAsVariable();
|
statsProfileOfIndicatorsAsVariable();
|
||||||
addFundingStreamInDefaultMSCA();
|
addFundingStreamInDefaultMSCA();
|
||||||
|
|
|
@ -12,12 +12,5 @@ function deleteIndexParameters() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function addCopyWithDefaultValue() {
|
// use irish-prod;
|
||||||
/* Set default profiles with copy: false */
|
|
||||||
db.stakeholder.updateMany({defaultId: null, copy: {$exists: false}}, {$set: {copy: false}});
|
|
||||||
/* Set not default profiles with copy: true */
|
|
||||||
db.stakeholder.updateMany({defaultId: {$ne: null}, copy: {$exists: false}}, {$set: {copy: true}});
|
|
||||||
}
|
|
||||||
|
|
||||||
deleteIndexParameters();
|
deleteIndexParameters();
|
||||||
addCopyWithDefaultValue();
|
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
function addStandaloneWithDefaultValue() {
|
|
||||||
/* Set standalone by default true */
|
|
||||||
db.stakeholder.updateMany({standalone: {$exists: false}}, {$set: {standalone: true}});
|
|
||||||
}
|
|
||||||
|
|
||||||
addStandaloneWithDefaultValue();
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.dnetlib.uoamonitorservice.application;
|
package eu.dnetlib.uoamonitorservice.application;
|
||||||
|
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.UoaAdminToolsLibraryConfiguration;
|
||||||
import eu.dnetlib.uoaauthorizationlibrary.configuration.AuthorizationConfiguration;
|
import eu.dnetlib.uoaauthorizationlibrary.configuration.AuthorizationConfiguration;
|
||||||
import eu.dnetlib.uoanotificationservice.configuration.NotificationConfiguration;
|
import eu.dnetlib.uoanotificationservice.configuration.NotificationConfiguration;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
@ -7,8 +8,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.context.annotation.PropertySource;
|
import org.springframework.context.annotation.PropertySource;
|
||||||
import org.springframework.context.annotation.PropertySources;
|
import org.springframework.context.annotation.PropertySources;
|
||||||
|
//uoahelptexts
|
||||||
|
|
||||||
@SpringBootApplication(scanBasePackages = {"eu.dnetlib.uoamonitorservice"})
|
@SpringBootApplication(scanBasePackages = {"eu.dnetlib.uoamonitorservice"})
|
||||||
@PropertySources({
|
@PropertySources({
|
||||||
@PropertySource("classpath:authorization.properties"),
|
@PropertySource("classpath:authorization.properties"),
|
||||||
|
|
|
@ -1,14 +1,23 @@
|
||||||
package eu.dnetlib.uoamonitorservice.controllers;
|
package eu.dnetlib.uoamonitorservice.controllers;
|
||||||
|
|
||||||
|
import com.mongodb.BasicDBObject;
|
||||||
|
import com.mongodb.CommandResult;
|
||||||
|
import com.mongodb.DBObject;
|
||||||
|
import eu.dnetlib.uoamonitorservice.configuration.GlobalVars;
|
||||||
|
import eu.dnetlib.uoamonitorservice.configuration.mongo.MongoConnection;
|
||||||
|
import eu.dnetlib.uoamonitorservice.configuration.properties.MongoConfig;
|
||||||
import eu.dnetlib.uoamonitorservice.service.MonitorDeployService;
|
import eu.dnetlib.uoamonitorservice.service.MonitorDeployService;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
package eu.dnetlib.uoamonitorservice.controllers;
|
package eu.dnetlib.uoamonitorservice.controllers;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
|
||||||
import eu.dnetlib.uoamonitorservice.dto.BuildStakeholder;
|
import eu.dnetlib.uoamonitorservice.dto.copy;
|
||||||
import eu.dnetlib.uoamonitorservice.dto.ManageStakeholders;
|
|
||||||
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
|
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
|
||||||
import eu.dnetlib.uoamonitorservice.dto.UpdateUmbrella;
|
|
||||||
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
||||||
import eu.dnetlib.uoamonitorservice.primitives.Umbrella;
|
import eu.dnetlib.uoamonitorservice.generics.StakeholderGeneric;
|
||||||
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
||||||
import eu.dnetlib.uoamonitorservice.service.CommonService;
|
|
||||||
import eu.dnetlib.uoamonitorservice.service.StakeholderService;
|
import eu.dnetlib.uoamonitorservice.service.StakeholderService;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
@ -18,6 +16,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin(origins = "*")
|
@CrossOrigin(origins = "*")
|
||||||
|
@ -26,33 +25,29 @@ public class StakeholderController {
|
||||||
|
|
||||||
private final PortalService portalService;
|
private final PortalService portalService;
|
||||||
private final StakeholderService stakeholderService;
|
private final StakeholderService stakeholderService;
|
||||||
private final CommonService commonService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public StakeholderController(PortalService portalService, StakeholderService stakeholderService, CommonService commonService) {
|
public StakeholderController(PortalService portalService, StakeholderService stakeholderService) {
|
||||||
this.portalService = portalService;
|
this.portalService = portalService;
|
||||||
this.stakeholderService = stakeholderService;
|
this.stakeholderService = stakeholderService;
|
||||||
this.commonService = commonService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("isAuthenticated()")
|
@PreAuthorize("isAuthenticated()")
|
||||||
@RequestMapping(value = "/stakeholder/alias", method = RequestMethod.GET)
|
@RequestMapping(value = "/stakeholder/alias", method = RequestMethod.GET)
|
||||||
public List<String> getAllReservedStakeholderAlias(@RequestParam(required = false) String type) {
|
public List<String> getAllReservedStakeholderAlias() {
|
||||||
List<String> stakeholderAlias = this.stakeholderService.getAllAliases(type);
|
List<String> stakeholderAlias = this.stakeholderService.getAllAliases();
|
||||||
if(type == null ) {
|
|
||||||
stakeholderAlias.add("all");
|
stakeholderAlias.add("all");
|
||||||
stakeholderAlias.add("default");
|
stakeholderAlias.add("default");
|
||||||
stakeholderAlias.add("alias");
|
stakeholderAlias.add("alias");
|
||||||
}
|
|
||||||
return stakeholderAlias;
|
return stakeholderAlias;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(" +
|
@PreAuthorize("hasAnyAuthority(" +
|
||||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||||
"@AuthorizationService.curator(#buildStakeholder.stakeholder.getType()))")
|
"@AuthorizationService.curator(#copy.stakeholder.getType()))")
|
||||||
@RequestMapping(value = "/build-stakeholder", method = RequestMethod.POST)
|
@RequestMapping(value = "/build-stakeholder", method = RequestMethod.POST)
|
||||||
public Stakeholder buildStakeholder(@RequestBody BuildStakeholder buildStakeholder) {
|
public Stakeholder buildStakeholder(@RequestBody copy copy) {
|
||||||
Stakeholder stakeholder = buildStakeholder.getStakeholder();
|
Stakeholder stakeholder = copy.getStakeholder();
|
||||||
log.debug("build stakeholder");
|
log.debug("build stakeholder");
|
||||||
log.debug("Alias: " + stakeholder.getAlias());
|
log.debug("Alias: " + stakeholder.getAlias());
|
||||||
Portal portal = portalService.getPortal(stakeholder.getAlias());
|
Portal portal = portalService.getPortal(stakeholder.getAlias());
|
||||||
|
@ -63,11 +58,7 @@ public class StakeholderController {
|
||||||
portal.setType(stakeholder.getType());
|
portal.setType(stakeholder.getType());
|
||||||
portalService.insertPortal(portal);
|
portalService.insertPortal(portal);
|
||||||
}
|
}
|
||||||
stakeholder.setStandalone(buildStakeholder.isStandalone());
|
return this.stakeholderService.buildStakeholder(stakeholder, copy.getCopyId());
|
||||||
if (buildStakeholder.isUmbrella()) {
|
|
||||||
stakeholder.setUmbrella(new Umbrella<>());
|
|
||||||
}
|
|
||||||
return this.stakeholderService.buildStakeholder(stakeholder, buildStakeholder.getCopyId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(" + "@AuthorizationService.PORTAL_ADMIN)")
|
@PreAuthorize("hasAnyAuthority(" + "@AuthorizationService.PORTAL_ADMIN)")
|
||||||
|
@ -76,37 +67,33 @@ public class StakeholderController {
|
||||||
return this.stakeholderService.getAll(type);
|
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)
|
@RequestMapping(value = "/stakeholder", method = RequestMethod.GET)
|
||||||
public List<Stakeholder> getVisibleStakeholders(@RequestParam(required = false) String type,
|
public List<Stakeholder> getVisibleStakeholders(@RequestParam(required = false) String type,
|
||||||
@RequestParam(required = false) String defaultId) {
|
@RequestParam(required = false) String defaultId) {
|
||||||
return stakeholderService.getVisibleStakeholders(type, defaultId);
|
return stakeholderService.getStakeholdersByTypeAndRole(type, defaultId, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("isAuthenticated()")
|
@PreAuthorize("isAuthenticated()")
|
||||||
@RequestMapping(value = "/my-stakeholder", method = RequestMethod.GET)
|
@RequestMapping(value = "/my-stakeholder", method = RequestMethod.GET)
|
||||||
public ManageStakeholders getManagedStakeholders(@RequestParam(required = false) String type) {
|
public List<Stakeholder> getManagedStakeholders(@RequestParam(required = false) String type) {
|
||||||
return stakeholderService.getManageStakeholders(type);
|
return stakeholderService.getStakeholdersByTypeAndRole(type, null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/stakeholder/{alias:.+}", method = RequestMethod.GET)
|
@RequestMapping(value = "/stakeholder/{alias:.+}", method = RequestMethod.GET)
|
||||||
public StakeholderFull getStakeholder(@PathVariable("alias") String alias) {
|
public StakeholderFull getStakeholder(@PathVariable("alias") String alias) {
|
||||||
StakeholderFull stakeholder = this.stakeholderService.getFullStakeholder(this.stakeholderService.findByAlias(alias));
|
StakeholderFull stakeholder = this.stakeholderService.getFullStakeholder(this.stakeholderService.findByAlias(alias));
|
||||||
if (stakeholder == null) {
|
if (stakeholder == null) {
|
||||||
this.commonService.unauthorized("Get stakeholder: You are not authorized to access stakeholder with alias: " + alias);
|
throw new ForbiddenException("Get stakeholder: You are not authorized to access stakeholder with alias: " + alias);
|
||||||
}
|
}
|
||||||
return stakeholder;
|
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("
|
@PreAuthorize("hasAnyAuthority("
|
||||||
+ "@AuthorizationService.PORTAL_ADMIN, "
|
+ "@AuthorizationService.PORTAL_ADMIN, "
|
||||||
+ "@AuthorizationService.curator(#stakeholder.getType()), "
|
+ "@AuthorizationService.curator(#stakeholder.getType()), "
|
||||||
|
@ -128,7 +115,7 @@ public class StakeholderController {
|
||||||
public StakeholderFull saveStakeholderFull(@RequestBody StakeholderFull stakeholder) {
|
public StakeholderFull saveStakeholderFull(@RequestBody StakeholderFull stakeholder) {
|
||||||
log.debug("save stakeholder");
|
log.debug("save stakeholder");
|
||||||
log.debug("Alias: " + stakeholder.getAlias() + " - Id: " + stakeholder.getId());
|
log.debug("Alias: " + stakeholder.getAlias() + " - Id: " + stakeholder.getId());
|
||||||
return this.stakeholderService.getFullStakeholder(this.stakeholderService.save(new Stakeholder(stakeholder, this.stakeholderService)));
|
return this.stakeholderService.getFullStakeholder(this.stakeholderService.save(new Stakeholder(stakeholder)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("isAuthenticated()")
|
@PreAuthorize("isAuthenticated()")
|
||||||
|
@ -152,13 +139,4 @@ public class StakeholderController {
|
||||||
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
||||||
return this.stakeholderService.changeVisibility(stakeholder, visibility, propagate);
|
return this.stakeholderService.changeVisibility(stakeholder, visibility, propagate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("isAuthenticated()")
|
|
||||||
@RequestMapping(value = "/{stakeholderId}/umbrella", method = RequestMethod.POST)
|
|
||||||
public Umbrella<Stakeholder> updateUmbrella(@PathVariable("stakeholderId") String stakeholderId, @RequestBody UpdateUmbrella update) {
|
|
||||||
log.debug("update stakeholder umbrella");
|
|
||||||
log.debug("Stakeholder: " + stakeholderId);
|
|
||||||
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
|
|
||||||
return this.stakeholderService.updateUmbrella(stakeholder, update);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package eu.dnetlib.uoamonitorservice.dao;
|
package eu.dnetlib.uoamonitorservice.dao;
|
||||||
|
|
||||||
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
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.MongoRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@ -10,187 +9,20 @@ import java.util.Optional;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface StakeholderDAO extends MongoRepository<Stakeholder, String> {
|
public interface StakeholderDAO extends MongoRepository<Stakeholder, String> {
|
||||||
/**
|
|
||||||
* All Stakeholders
|
|
||||||
*/
|
|
||||||
List<Stakeholder> findAll();
|
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> findByDefaultIdIsNull();
|
||||||
|
List<Stakeholder> findByDefaultIdAndCopyTrue(String defaultId);
|
||||||
|
List<Stakeholder> findByDefaultIdAndType(String DefaultId, String Type);
|
||||||
|
|
||||||
List<Stakeholder> findByDefaultIdIsNullAndType(StakeholderType Type);
|
List<Stakeholder> findByDefaultIdIsNotNull();
|
||||||
|
List<Stakeholder> findByDefaultIdIsNotNullAndType(String Type);
|
||||||
default List<Stakeholder> defaultStakeholders(StakeholderType type) {
|
|
||||||
if (type == null) {
|
|
||||||
return findByDefaultIdIsNull();
|
|
||||||
}
|
|
||||||
return findByDefaultIdIsNullAndType(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Standalone Stakeholders (not umbrella)
|
|
||||||
*/
|
|
||||||
List<Stakeholder> findByDefaultIdIsNotNullAndStandaloneIsTrueAndUmbrellaIsNull();
|
|
||||||
|
|
||||||
List<Stakeholder> findByStandaloneIsTrueAndUmbrellaIsNullAndDefaultId(String id);
|
|
||||||
|
|
||||||
List<Stakeholder> findByDefaultIdIsNotNullAndStandaloneIsTrueAndUmbrellaIsNullAndType(StakeholderType Type);
|
|
||||||
|
|
||||||
List<Stakeholder> findByStandaloneIsTrueAndUmbrellaIsNullAndTypeAndDefaultId(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 findByStandaloneIsTrueAndUmbrellaIsNullAndTypeAndDefaultId(type, id);
|
|
||||||
} else if (id != null) {
|
|
||||||
return findByStandaloneIsTrueAndUmbrellaIsNullAndDefaultId(id);
|
|
||||||
} else if (type != null) {
|
|
||||||
return findByDefaultIdIsNotNullAndStandaloneIsTrueAndUmbrellaIsNullAndType(type);
|
|
||||||
} else {
|
|
||||||
return findByDefaultIdIsNotNullAndStandaloneIsTrueAndUmbrellaIsNull();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dependent Stakeholders
|
|
||||||
*/
|
|
||||||
List<Stakeholder> findByDefaultIdIsNotNullAndStandaloneIsFalse();
|
|
||||||
|
|
||||||
List<Stakeholder> findByStandaloneIsFalseAndDefaultId(String id);
|
|
||||||
|
|
||||||
List<Stakeholder> findByDefaultIdIsNotNullAndStandaloneIsFalseAndType(StakeholderType Type);
|
|
||||||
|
|
||||||
List<Stakeholder> findByStandaloneIsFalseAndTypeAndDefaultId(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 findByStandaloneIsFalseAndTypeAndDefaultId(type, id);
|
|
||||||
} else if (id != null) {
|
|
||||||
return findByStandaloneIsFalseAndDefaultId(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> findByStandaloneIsTrueAndDefaultId(String id);
|
|
||||||
|
|
||||||
List<Stakeholder> findByDefaultIdNotNullAndStandaloneIsTrueAndType(StakeholderType Type);
|
|
||||||
|
|
||||||
List<Stakeholder> findByStandaloneIsTrueAndTypeAndDefaultId(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 findByStandaloneIsTrueAndTypeAndDefaultId(type, id);
|
|
||||||
} else if (id != null) {
|
|
||||||
return findByStandaloneIsTrueAndDefaultId(id);
|
|
||||||
} else if (type != null) {
|
|
||||||
return findByDefaultIdNotNullAndStandaloneIsTrueAndType(type);
|
|
||||||
} else {
|
|
||||||
return findByDefaultIdNotNullAndStandaloneIsTrue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Other method
|
|
||||||
*/
|
|
||||||
|
|
||||||
List<Stakeholder> findByDefaultIdAndCopyIsTrue(String defaultId);
|
|
||||||
|
|
||||||
List<Stakeholder> findByTopicsContaining(String topic);
|
List<Stakeholder> findByTopicsContaining(String topic);
|
||||||
|
|
||||||
Optional<Stakeholder> findById(String id);
|
Optional<Stakeholder> findById(String Id);
|
||||||
|
Optional<Stakeholder> findByAlias(String Alias);
|
||||||
Optional<Stakeholder> findByAlias(String alias);
|
|
||||||
|
|
||||||
|
|
||||||
void delete(String Id);
|
void delete(String Id);
|
||||||
|
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
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,40 +1,19 @@
|
||||||
package eu.dnetlib.uoamonitorservice.dto;
|
package eu.dnetlib.uoamonitorservice.dto;
|
||||||
|
|
||||||
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
|
||||||
import eu.dnetlib.uoamonitorservice.generics.StakeholderGeneric;
|
import eu.dnetlib.uoamonitorservice.generics.StakeholderGeneric;
|
||||||
import eu.dnetlib.uoamonitorservice.primitives.Umbrella;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class StakeholderFull extends StakeholderGeneric<TopicFull, Stakeholder> {
|
public class StakeholderFull extends StakeholderGeneric<TopicFull> {
|
||||||
public List<Stakeholder> otherParents;
|
|
||||||
public Stakeholder parent;
|
|
||||||
|
|
||||||
public StakeholderFull() {
|
public StakeholderFull() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StakeholderFull(StakeholderGeneric stakeholder, List<TopicFull> topics, Umbrella<Stakeholder> umbrella) {
|
public StakeholderFull(StakeholderGeneric stakeholder, List<TopicFull> topics) {
|
||||||
super(stakeholder);
|
super(stakeholder);
|
||||||
topics.removeIf(Objects::isNull);
|
topics.removeIf(Objects::isNull);
|
||||||
this.topics = topics;
|
this.topics = topics;
|
||||||
this.setUmbrella(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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
package eu.dnetlib.uoamonitorservice.dto;
|
|
||||||
|
|
||||||
import eu.dnetlib.uoamonitorservice.primitives.Action;
|
|
||||||
import eu.dnetlib.uoamonitorservice.primitives.StakeholderType;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class UpdateUmbrella {
|
|
||||||
StakeholderType type;
|
|
||||||
Action action;
|
|
||||||
String child;
|
|
||||||
List<StakeholderType> types;
|
|
||||||
List<String> children;
|
|
||||||
|
|
||||||
public UpdateUmbrella() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public StakeholderType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(StakeholderType type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Action getAction() {
|
|
||||||
return action;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAction(Action action) {
|
|
||||||
this.action = action;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getChild() {
|
|
||||||
return child;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setChild(String child) {
|
|
||||||
this.child = child;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<StakeholderType> getTypes() {
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTypes(List<StakeholderType> types) {
|
|
||||||
this.types = types;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getChildren() {
|
|
||||||
return children;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setChildren(List<String> children) {
|
|
||||||
this.children = children;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,13 +2,11 @@ package eu.dnetlib.uoamonitorservice.dto;
|
||||||
|
|
||||||
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
||||||
|
|
||||||
public class BuildStakeholder {
|
public class copy {
|
||||||
private Stakeholder stakeholder;
|
private Stakeholder stakeholder;
|
||||||
private String copyId;
|
private String copyId;
|
||||||
private boolean umbrella = false;
|
|
||||||
private boolean standalone = true;
|
|
||||||
|
|
||||||
public BuildStakeholder() {
|
public copy() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stakeholder getStakeholder() {
|
public Stakeholder getStakeholder() {
|
||||||
|
@ -26,20 +24,4 @@ public class BuildStakeholder {
|
||||||
public void setCopyId(String copyId) {
|
public void setCopyId(String copyId) {
|
||||||
this.copyId = copyId;
|
this.copyId = copyId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUmbrella() {
|
|
||||||
return umbrella;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUmbrella(boolean umbrella) {
|
|
||||||
this.umbrella = umbrella;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isStandalone() {
|
|
||||||
return standalone;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStandalone(boolean standalone) {
|
|
||||||
this.standalone = standalone;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -3,15 +3,15 @@ package eu.dnetlib.uoamonitorservice.entities;
|
||||||
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
|
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
|
||||||
import eu.dnetlib.uoamonitorservice.generics.Common;
|
import eu.dnetlib.uoamonitorservice.generics.Common;
|
||||||
import eu.dnetlib.uoamonitorservice.generics.StakeholderGeneric;
|
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 org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Document
|
@Document
|
||||||
public class Stakeholder extends StakeholderGeneric<String, String> {
|
public class Stakeholder extends StakeholderGeneric<String> {
|
||||||
|
|
||||||
public Stakeholder() {
|
public Stakeholder() {
|
||||||
super();
|
super();
|
||||||
|
@ -21,13 +21,10 @@ public class Stakeholder extends StakeholderGeneric<String, String> {
|
||||||
super(stakeholder);
|
super(stakeholder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stakeholder(StakeholderFull stakeholder, StakeholderService service) {
|
public Stakeholder(StakeholderFull stakeholder) {
|
||||||
super(stakeholder);
|
super(stakeholder);
|
||||||
Stakeholder old = service.findByPath(stakeholder.getId());
|
this.topics = stakeholder.getTopics().stream().map(Common::getId).collect(Collectors.toList());
|
||||||
this.defaultId = old.getDefaultId();
|
this.topics.removeIf(Objects::isNull);
|
||||||
this.standalone = old.isStandalone();
|
|
||||||
this.topics = old.getTopics();
|
|
||||||
this.umbrella = old.getUmbrella();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTopic(String id) {
|
public void addTopic(String id) {
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
package eu.dnetlib.uoamonitorservice.generics;
|
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 org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Document
|
@Document
|
||||||
public class CategoryGeneric<T> extends Common {
|
public class CategoryGeneric<StringOrSubcategory> extends Common {
|
||||||
protected boolean isOverview;
|
protected boolean isOverview;
|
||||||
protected List<T> subCategories;
|
protected List<StringOrSubcategory> subCategories;
|
||||||
|
|
||||||
public CategoryGeneric() {}
|
public CategoryGeneric() {}
|
||||||
|
|
||||||
|
@ -33,11 +40,11 @@ public class CategoryGeneric<T> extends Common {
|
||||||
this.isOverview = isOverview;
|
this.isOverview = isOverview;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<T> getSubCategories() {
|
public List<StringOrSubcategory> getSubCategories() {
|
||||||
return subCategories;
|
return subCategories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSubCategories(List<T> subCategories) {
|
public void setSubCategories(List<StringOrSubcategory> subCategories) {
|
||||||
this.subCategories = subCategories;
|
this.subCategories = subCategories;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,11 @@ import eu.dnetlib.uoamonitorservice.primitives.IndicatorType;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SectionGeneric<T> extends Common {
|
public class SectionGeneric<StringOrIndicator> extends Common {
|
||||||
protected String title;
|
protected String title;
|
||||||
protected String stakeholderAlias;
|
protected String stakeholderAlias;
|
||||||
protected IndicatorType type;
|
protected IndicatorType type;
|
||||||
protected List<T> indicators;
|
protected List<StringOrIndicator> indicators;
|
||||||
|
|
||||||
public SectionGeneric() {
|
public SectionGeneric() {
|
||||||
}
|
}
|
||||||
|
@ -60,11 +60,11 @@ public class SectionGeneric<T> extends Common {
|
||||||
return this.type == IndicatorType.NUMBER || this.type == IndicatorType.number;
|
return this.type == IndicatorType.NUMBER || this.type == IndicatorType.number;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<T> getIndicators() {
|
public List<StringOrIndicator> getIndicators() {
|
||||||
return indicators;
|
return indicators;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIndicators(List<T> indicators) {
|
public void setIndicators(List<StringOrIndicator> indicators) {
|
||||||
this.indicators = indicators;
|
this.indicators = indicators;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
package eu.dnetlib.uoamonitorservice.generics;
|
package eu.dnetlib.uoamonitorservice.generics;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import eu.dnetlib.uoamonitorservice.primitives.Locale;
|
import eu.dnetlib.uoamonitorservice.primitives.Locale;
|
||||||
import eu.dnetlib.uoamonitorservice.primitives.StakeholderType;
|
import eu.dnetlib.uoamonitorservice.primitives.StakeholderType;
|
||||||
import eu.dnetlib.uoamonitorservice.primitives.Umbrella;
|
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.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class StakeholderGeneric<T, S> extends Common {
|
|
||||||
|
public class StakeholderGeneric<StringOrTopic> extends Common {
|
||||||
protected StakeholderType type;
|
protected StakeholderType type;
|
||||||
protected Date projectUpdateDate = null;
|
protected Date projectUpdateDate = null;
|
||||||
protected String index_id;
|
protected String index_id;
|
||||||
|
@ -21,10 +23,8 @@ public class StakeholderGeneric<T, S> extends Common {
|
||||||
protected boolean isUpload = false;
|
protected boolean isUpload = false;
|
||||||
protected Locale locale = Locale.EU;
|
protected Locale locale = Locale.EU;
|
||||||
protected String funderType;
|
protected String funderType;
|
||||||
protected Boolean standalone = true;
|
|
||||||
protected Boolean copy;
|
protected Boolean copy;
|
||||||
protected List<T> topics = new ArrayList<>();
|
protected List<StringOrTopic> topics;
|
||||||
protected Umbrella<S> umbrella;
|
|
||||||
|
|
||||||
public StakeholderGeneric() {
|
public StakeholderGeneric() {
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,6 @@ public class StakeholderGeneric<T, S> extends Common {
|
||||||
setVisibility(stakeholder.getVisibility());
|
setVisibility(stakeholder.getVisibility());
|
||||||
this.funderType = stakeholder.getFunderType();
|
this.funderType = stakeholder.getFunderType();
|
||||||
this.copy = stakeholder.isCopy();
|
this.copy = stakeholder.isCopy();
|
||||||
this.standalone = stakeholder.isStandalone();
|
|
||||||
creationDate = stakeholder.getCreationDate();
|
creationDate = stakeholder.getCreationDate();
|
||||||
updateDate = stakeholder.getUpdateDate();
|
updateDate = stakeholder.getUpdateDate();
|
||||||
}
|
}
|
||||||
|
@ -60,7 +59,11 @@ public class StakeholderGeneric<T, S> extends Common {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(String type) {
|
public void setType(String type) {
|
||||||
this.type = StakeholderType.convert(type);
|
if (type == null) {
|
||||||
|
this.type = null;
|
||||||
|
} else {
|
||||||
|
this.type = StakeholderType.valueOf(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getProjectUpdateDate() {
|
public Date getProjectUpdateDate() {
|
||||||
|
@ -141,17 +144,6 @@ public class StakeholderGeneric<T, S> extends Common {
|
||||||
this.funderType = funderType;
|
this.funderType = funderType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isStandalone() {
|
|
||||||
if(standalone == null) {
|
|
||||||
standalone = true;
|
|
||||||
}
|
|
||||||
return standalone;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStandalone(boolean standalone) {
|
|
||||||
this.standalone = standalone;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCopy() {
|
public boolean isCopy() {
|
||||||
if(copy == null) {
|
if(copy == null) {
|
||||||
copy = this.defaultId != null;
|
copy = this.defaultId != null;
|
||||||
|
@ -163,24 +155,11 @@ public class StakeholderGeneric<T, S> extends Common {
|
||||||
this.copy = copy;
|
this.copy = copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<T> getTopics() {
|
public List<StringOrTopic> getTopics() {
|
||||||
return topics;
|
return topics;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTopics(List<T> topics) {
|
public void setTopics(List<StringOrTopic> topics) {
|
||||||
this.topics = topics;
|
this.topics = topics;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Umbrella<S> getUmbrella() {
|
|
||||||
return umbrella;
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
public Optional<Umbrella<S>> getUmbrellaOptional() {
|
|
||||||
return Optional.ofNullable(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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SubCategoryGeneric<T> extends Common {
|
public class SubCategoryGeneric<StringOrSection> extends Common {
|
||||||
protected List<T> charts;
|
protected List<StringOrSection> charts;
|
||||||
protected List<T> numbers;
|
protected List<StringOrSection> numbers;
|
||||||
|
|
||||||
public SubCategoryGeneric() {}
|
public SubCategoryGeneric() {}
|
||||||
public SubCategoryGeneric(SubCategoryGeneric subCategory) {
|
public SubCategoryGeneric(SubCategoryGeneric subCategory) {
|
||||||
|
@ -21,19 +21,19 @@ public class SubCategoryGeneric<T> extends Common {
|
||||||
charts = new ArrayList<>();
|
charts = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<T> getCharts() {
|
public List<StringOrSection> getCharts() {
|
||||||
return charts;
|
return charts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCharts(List<T> charts) {
|
public void setCharts(List<StringOrSection> charts) {
|
||||||
this.charts = charts;
|
this.charts = charts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<T> getNumbers() {
|
public List<StringOrSection> getNumbers() {
|
||||||
return numbers;
|
return numbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNumbers(List<T> numbers) {
|
public void setNumbers(List<StringOrSection> numbers) {
|
||||||
this.numbers = numbers;
|
this.numbers = numbers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,18 @@
|
||||||
package eu.dnetlib.uoamonitorservice.generics;
|
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.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TopicGeneric<T> extends Common {
|
public class TopicGeneric<StringOrCategory> extends Common {
|
||||||
protected String icon;
|
protected String icon;
|
||||||
protected List<T> categories;
|
protected List<StringOrCategory> categories;
|
||||||
|
|
||||||
public TopicGeneric() {
|
public TopicGeneric() {
|
||||||
}
|
}
|
||||||
|
@ -32,11 +39,11 @@ public class TopicGeneric<T> extends Common {
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<T> getCategories() {
|
public List<StringOrCategory> getCategories() {
|
||||||
return categories;
|
return categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCategories(List<T> categories) {
|
public void setCategories(List<StringOrCategory> categories) {
|
||||||
this.categories = categories;
|
this.categories = categories;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
package eu.dnetlib.uoamonitorservice.handlers;
|
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
||||||
|
|
||||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
||||||
public class BadRequestException extends RuntimeException {
|
|
||||||
public BadRequestException(String message){
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -25,17 +25,6 @@ public class ExceptionsHandler {
|
||||||
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
|
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(BadRequestException.class)
|
|
||||||
public ResponseEntity<ExceptionResponse> conflictException(Exception ex) {
|
|
||||||
ExceptionResponse response = new ExceptionResponse();
|
|
||||||
response.setErrorCode("Not found Exception");
|
|
||||||
response.setErrorMessage("Conflict Exception");
|
|
||||||
response.setErrors(ex.getMessage());
|
|
||||||
response.setStatus(HttpStatus.BAD_REQUEST);
|
|
||||||
log.error("conflictException exception : "+ ex.getMessage());
|
|
||||||
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(PathNotValidException.class)
|
@ExceptionHandler(PathNotValidException.class)
|
||||||
public ResponseEntity<ExceptionResponse> pathNotValidException(Exception ex) {
|
public ResponseEntity<ExceptionResponse> pathNotValidException(Exception ex) {
|
||||||
ExceptionResponse response = new ExceptionResponse();
|
ExceptionResponse response = new ExceptionResponse();
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
package eu.dnetlib.uoamonitorservice.primitives;
|
|
||||||
|
|
||||||
public enum Action {
|
|
||||||
ADD, REMOVE, UPDATE
|
|
||||||
}
|
|
|
@ -4,16 +4,6 @@ public enum StakeholderType {
|
||||||
// Do not rename or remove existing values. This may cause problems with already stored values in DB
|
// Do not rename or remove existing values. This may cause problems with already stored values in DB
|
||||||
funder, ri, project, organization,
|
funder, ri, project, organization,
|
||||||
country, researcher, datasource,
|
country, researcher, datasource,
|
||||||
publisher, journal,
|
|
||||||
FUNDER, RI, PROJECT, ORGANIZATION,
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,125 +0,0 @@
|
||||||
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.*;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean addType(StakeholderType type) {
|
|
||||||
if(!this.types.contains(type)) {
|
|
||||||
this.types.add(type);
|
|
||||||
this.children.put(type, new ArrayList<>());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean removeType(StakeholderType type) {
|
|
||||||
if(this.types.contains(type)) {
|
|
||||||
this.types.remove(type);
|
|
||||||
this.children.remove(type);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean addChild(StakeholderType type, T child) {
|
|
||||||
if(this.types.contains(type)) {
|
|
||||||
if(!this.children.containsKey(type)) {
|
|
||||||
this.children.put(type, new ArrayList<>());
|
|
||||||
}
|
|
||||||
if(!this.children.get(type).contains(child)) {
|
|
||||||
return this.children.get(type).add(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean removeChild(StakeholderType type, T child) {
|
|
||||||
if(this.types.contains(type)) {
|
|
||||||
if(!this.children.containsKey(type)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(this.children.get(type).contains(child)) {
|
|
||||||
return this.children.get(type).remove(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean update(List<StakeholderType> types) {
|
|
||||||
if(types == null) {
|
|
||||||
return false;
|
|
||||||
} else if(types.size() != this.types.size()) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
if(new HashSet<>(this.types).containsAll(types)) {
|
|
||||||
this.types = types;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean update(StakeholderType type, List<T> children) {
|
|
||||||
if(children == null) {
|
|
||||||
return false;
|
|
||||||
} else if(this.children.get(type) == null) {
|
|
||||||
return false;
|
|
||||||
} else if(children.size() != this.children.get(type).size()) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return new HashSet<>(this.children.get(type)).containsAll(children);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.dnetlib.uoamonitorservice.service;
|
package eu.dnetlib.uoamonitorservice.service;
|
||||||
|
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||||
import eu.dnetlib.uoamonitorservice.dao.CategoryDAO;
|
import eu.dnetlib.uoamonitorservice.dao.CategoryDAO;
|
||||||
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
|
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
|
||||||
import eu.dnetlib.uoamonitorservice.dao.TopicDAO;
|
import eu.dnetlib.uoamonitorservice.dao.TopicDAO;
|
||||||
|
@ -101,7 +102,7 @@ public class CategoryService {
|
||||||
this.updateChildren(category);
|
this.updateChildren(category);
|
||||||
category = this.save(category);
|
category = this.save(category);
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.commonService.hasCreateAuthority(stakeholder.getType())) {
|
if (this.commonService.hasCreateAuthority(stakeholder.getType())) {
|
||||||
|
@ -112,7 +113,7 @@ public class CategoryService {
|
||||||
}
|
}
|
||||||
this.addCategory(topic, category.getId());
|
this.addCategory(topic, category.getId());
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to create a category in stakeholder with id: " + stakeholder.getId());
|
throw new ForbiddenException("You are not authorized to create a category in stakeholder with id: " + stakeholder.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.getFullCategory(stakeholder.getType(), stakeholder.getAlias(), category);
|
return this.getFullCategory(stakeholder.getType(), stakeholder.getAlias(), category);
|
||||||
|
@ -144,13 +145,12 @@ public class CategoryService {
|
||||||
throw new EntityNotFoundException("Some subCategories dont exist in the category with id " + category.getId());
|
throw new EntityNotFoundException("Some subCategories dont exist in the category with id " + category.getId());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to reorder subCategories in category with id: " + category.getId());
|
throw new ForbiddenException("You are not authorized to reorder subCategories in category with id: " + category.getId());
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reorderChildren(Stakeholder defaultStakeholder, Category defaultCategory, List<String> defaultSubCategories) {
|
public void reorderChildren(Stakeholder defaultStakeholder, Category defaultCategory, List<String> defaultSubCategories) {
|
||||||
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
||||||
this.dao.findByDefaultId(defaultCategory.getId()).stream().map(category -> this.getFullCategory(stakeholder.getType(), stakeholder.getAlias(), category)).forEach(category -> {
|
this.dao.findByDefaultId(defaultCategory.getId()).stream().map(category -> this.getFullCategory(stakeholder.getType(), stakeholder.getAlias(), category)).forEach(category -> {
|
||||||
this.reorderSubCategories(stakeholder, new Category(category),
|
this.reorderSubCategories(stakeholder, new Category(category),
|
||||||
this.commonService.reorder(defaultSubCategories, category.getSubCategories().stream().map(subCategory -> (Common) subCategory).collect(Collectors.toList())));
|
this.commonService.reorder(defaultSubCategories, category.getSubCategories().stream().map(subCategory -> (Common) subCategory).collect(Collectors.toList())));
|
||||||
|
@ -171,7 +171,7 @@ public class CategoryService {
|
||||||
}
|
}
|
||||||
this.dao.delete(category);
|
this.dao.delete(category);
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("Delete category: You are not authorized to delete category with id: " + category.getId());
|
throw new ForbiddenException("Delete category: You are not authorized to delete category with id: " + category.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,9 +205,8 @@ public class CategoryService {
|
||||||
category.update(this.save(new Category(category)));
|
category.update(this.save(new Category(category)));
|
||||||
return category;
|
return category;
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("Change category visibility: You are not authorized to update category with id: " + category.getId());
|
throw new ForbiddenException("Change category visibility: You are not authorized to update category with id: " + category.getId());
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CategoryFull changeVisibility(String type, String alias, Category category, Visibility visibility, Boolean propagate) {
|
public CategoryFull changeVisibility(String type, String alias, Category category, Visibility visibility, Boolean propagate) {
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package eu.dnetlib.uoamonitorservice.service;
|
package eu.dnetlib.uoamonitorservice.service;
|
||||||
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
|
||||||
import eu.dnetlib.uoaadmintoolslibrary.handlers.UnauthorizedException;
|
|
||||||
import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService;
|
import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService;
|
||||||
|
import eu.dnetlib.uoamonitorservice.dto.TopicFull;
|
||||||
import eu.dnetlib.uoamonitorservice.generics.Common;
|
import eu.dnetlib.uoamonitorservice.generics.Common;
|
||||||
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -70,12 +69,4 @@ public class CommonService {
|
||||||
});
|
});
|
||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unauthorized(String message) {
|
|
||||||
if(authorizationService.getAaiId() != null) {
|
|
||||||
throw new ForbiddenException(message);
|
|
||||||
} else {
|
|
||||||
throw new UnauthorizedException(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.dnetlib.uoamonitorservice.service;
|
package eu.dnetlib.uoamonitorservice.service;
|
||||||
|
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||||
import eu.dnetlib.uoamonitorservice.dao.*;
|
import eu.dnetlib.uoamonitorservice.dao.*;
|
||||||
import eu.dnetlib.uoamonitorservice.entities.Indicator;
|
import eu.dnetlib.uoamonitorservice.entities.Indicator;
|
||||||
import eu.dnetlib.uoamonitorservice.entities.Section;
|
import eu.dnetlib.uoamonitorservice.entities.Section;
|
||||||
|
@ -81,7 +82,7 @@ public class IndicatorService {
|
||||||
this.updateChildren(indicator);
|
this.updateChildren(indicator);
|
||||||
indicator = this.save(indicator);
|
indicator = this.save(indicator);
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.commonService.hasCreateAuthority(stakeholder.getType())) {
|
if (this.commonService.hasCreateAuthority(stakeholder.getType())) {
|
||||||
|
@ -89,7 +90,7 @@ public class IndicatorService {
|
||||||
this.createChildren(section, indicator);
|
this.createChildren(section, indicator);
|
||||||
this.addIndicator(section, indicator.getId());
|
this.addIndicator(section, indicator.getId());
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to create an indicator in stakeholder with id: " + stakeholder.getId());
|
throw new ForbiddenException("You are not authorized to create an indicator in stakeholder with id: " + stakeholder.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return indicator;
|
return indicator;
|
||||||
|
@ -127,7 +128,7 @@ public class IndicatorService {
|
||||||
}
|
}
|
||||||
this.dao.delete(indicator);
|
this.dao.delete(indicator);
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("Delete indicator: You are not authorized to delete indicator with id: " + indicator.getId());
|
throw new ForbiddenException("Delete indicator: You are not authorized to delete indicator with id: " + indicator.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,8 +157,7 @@ public class IndicatorService {
|
||||||
indicator.setVisibility(visibility);
|
indicator.setVisibility(visibility);
|
||||||
return this.save(indicator);
|
return this.save(indicator);
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("Change section visibility: You are not authorized to update section with id: " + indicator.getId());
|
throw new ForbiddenException("Change section visibility: You are not authorized to update section with id: " + indicator.getId());
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.dnetlib.uoamonitorservice.service;
|
package eu.dnetlib.uoamonitorservice.service;
|
||||||
|
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||||
import eu.dnetlib.uoamonitorservice.dao.*;
|
import eu.dnetlib.uoamonitorservice.dao.*;
|
||||||
import eu.dnetlib.uoamonitorservice.dto.SectionFull;
|
import eu.dnetlib.uoamonitorservice.dto.SectionFull;
|
||||||
import eu.dnetlib.uoamonitorservice.entities.Section;
|
import eu.dnetlib.uoamonitorservice.entities.Section;
|
||||||
|
@ -102,7 +103,7 @@ public class SectionService {
|
||||||
this.createChildren(subCategory, new Section(section), -1);
|
this.createChildren(subCategory, new Section(section), -1);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to create sections in stakeholder with id: " + stakeholder.getId());
|
throw new ForbiddenException("You are not authorized to create sections in stakeholder with id: " + stakeholder.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +115,7 @@ public class SectionService {
|
||||||
this.updateChildren(section);
|
this.updateChildren(section);
|
||||||
section = this.save(section);
|
section = this.save(section);
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.commonService.hasCreateAuthority(stakeholder.getType())) {
|
if (this.commonService.hasCreateAuthority(stakeholder.getType())) {
|
||||||
|
@ -122,7 +123,7 @@ public class SectionService {
|
||||||
this.createChildren(subCategory, section, index);
|
this.createChildren(subCategory, section, index);
|
||||||
this.addSection(subCategory, section.getId(), index);
|
this.addSection(subCategory, section.getId(), index);
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to create a section in stakeholder with id: " + stakeholder.getId());
|
throw new ForbiddenException("You are not authorized to create a section in stakeholder with id: " + stakeholder.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.getFullSection(stakeholder.getType(), stakeholder.getAlias(), section);
|
return this.getFullSection(stakeholder.getType(), stakeholder.getAlias(), section);
|
||||||
|
@ -134,13 +135,13 @@ public class SectionService {
|
||||||
this.topicDAO.findByCategoriesContaining(category.getId()).forEach(topic -> {
|
this.topicDAO.findByCategoriesContaining(category.getId()).forEach(topic -> {
|
||||||
this.stakeholderDAO.findByTopicsContaining(topic.getId()).forEach(stakeholder -> {
|
this.stakeholderDAO.findByTopicsContaining(topic.getId()).forEach(stakeholder -> {
|
||||||
this.save(stakeholder, subCategory, section.copy(), index);
|
this.save(stakeholder, subCategory, section.copy(), index);
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
section.getIndicators().forEach(indicator -> {
|
section.getIndicators().forEach(indicator -> {
|
||||||
this.indicatorService.createChildren(section, this.indicatorService.find(indicator));
|
this.indicatorService.createChildren(section, this.indicatorService.find(indicator));
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateChildren(Section section) {
|
public void updateChildren(Section section) {
|
||||||
|
@ -167,13 +168,12 @@ public class SectionService {
|
||||||
throw new EntityNotFoundException("Some indicators dont exist in the section with id " + section.getId());
|
throw new EntityNotFoundException("Some indicators dont exist in the section with id " + section.getId());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to reorder indicators in section with id: " + section.getId());
|
throw new ForbiddenException("You are not authorized to reorder indicators in section with id: " + section.getId());
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reorderChildren(Stakeholder defaultStakeholder, Section defaultSection, List<String> defaultIndicators) {
|
public void reorderChildren(Stakeholder defaultStakeholder, Section defaultSection, List<String> defaultIndicators) {
|
||||||
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
||||||
this.dao.findByDefaultId(defaultSection.getId()).stream().map(section -> this.getFullSection(stakeholder.getType(), stakeholder.getAlias(), section)).forEach(section -> {
|
this.dao.findByDefaultId(defaultSection.getId()).stream().map(section -> this.getFullSection(stakeholder.getType(), stakeholder.getAlias(), section)).forEach(section -> {
|
||||||
this.reorderIndicators(stakeholder, new Section(section),
|
this.reorderIndicators(stakeholder, new Section(section),
|
||||||
this.commonService.reorder(defaultIndicators, section.getIndicators().stream().map(indicator -> (Common) indicator).collect(Collectors.toList())));
|
this.commonService.reorder(defaultIndicators, section.getIndicators().stream().map(indicator -> (Common) indicator).collect(Collectors.toList())));
|
||||||
|
@ -194,7 +194,7 @@ public class SectionService {
|
||||||
}
|
}
|
||||||
this.dao.delete(section);
|
this.dao.delete(section);
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("Delete section: You are not authorized to delete section with id: " + section.getId());
|
throw new ForbiddenException("Delete section: You are not authorized to delete section with id: " + section.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,8 +238,7 @@ public class SectionService {
|
||||||
section.update(this.save(new Section(section)));
|
section.update(this.save(new Section(section)));
|
||||||
return section;
|
return section;
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("Change section visibility: You are not authorized to update section with id: " + section.getId());
|
throw new ForbiddenException("Change section visibility: You are not authorized to update section with id: " + section.getId());
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,42 +1,34 @@
|
||||||
package eu.dnetlib.uoamonitorservice.service;
|
package eu.dnetlib.uoamonitorservice.service;
|
||||||
|
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||||
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
|
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
|
||||||
import eu.dnetlib.uoamonitorservice.dto.ManageStakeholders;
|
|
||||||
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
|
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
|
||||||
import eu.dnetlib.uoamonitorservice.dto.TopicFull;
|
|
||||||
import eu.dnetlib.uoamonitorservice.dto.UpdateUmbrella;
|
|
||||||
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
||||||
import eu.dnetlib.uoamonitorservice.generics.Common;
|
import eu.dnetlib.uoamonitorservice.generics.Common;
|
||||||
import eu.dnetlib.uoamonitorservice.handlers.BadRequestException;
|
|
||||||
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
|
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
|
||||||
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
|
|
||||||
import eu.dnetlib.uoamonitorservice.primitives.Action;
|
|
||||||
import eu.dnetlib.uoamonitorservice.primitives.StakeholderType;
|
|
||||||
import eu.dnetlib.uoamonitorservice.primitives.Umbrella;
|
|
||||||
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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 org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class StakeholderService {
|
public class StakeholderService {
|
||||||
|
|
||||||
private final StakeholderDAO dao;
|
private final StakeholderDAO dao;
|
||||||
|
|
||||||
private final CommonService commonService;
|
private final CommonService commonService;
|
||||||
private final TopicService topicService;
|
private final TopicService topicService;
|
||||||
private final MongoTemplate mongoTemplate;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public StakeholderService(StakeholderDAO dao, CommonService commonService, TopicService topicService, MongoTemplate mongoTemplate) {
|
public StakeholderService(StakeholderDAO dao, CommonService commonService, TopicService topicService) {
|
||||||
this.dao = dao;
|
this.dao = dao;
|
||||||
this.commonService = commonService;
|
this.commonService = commonService;
|
||||||
this.topicService = topicService;
|
this.topicService = topicService;
|
||||||
this.mongoTemplate = mongoTemplate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stakeholder findByAlias(String alias) {
|
public Stakeholder findByAlias(String alias) {
|
||||||
|
@ -44,7 +36,7 @@ public class StakeholderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Stakeholder> findByDefaultId(String id) {
|
public List<Stakeholder> findByDefaultId(String id) {
|
||||||
return this.dao.findByDefaultIdAndCopyIsTrue(id);
|
return this.dao.findByDefaultIdAndCopyTrue(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stakeholder findByPath(String stakeholderId) {
|
public Stakeholder findByPath(String stakeholderId) {
|
||||||
|
@ -54,75 +46,58 @@ public class StakeholderService {
|
||||||
return dao.findById(stakeholderId).orElseThrow(() -> new EntityNotFoundException("Stakeholder with id: " + stakeholderId + " not found"));
|
return dao.findById(stakeholderId).orElseThrow(() -> new EntityNotFoundException("Stakeholder with id: " + stakeholderId + " not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getAllAliases(String type) {
|
public List<String> getAllAliases() {
|
||||||
return this.getAll(type).stream().map(Stakeholder::getAlias).collect(Collectors.toList());
|
return this.dao.findAll().stream().map(Stakeholder::getAlias).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Stakeholder> getAll(String type) {
|
public List<Stakeholder> getAll(String type) {
|
||||||
return this.dao.allStakeholders(StakeholderType.convert(type));
|
if (type != null) {
|
||||||
|
return this.dao.findByType(type);
|
||||||
|
}
|
||||||
|
return this.dao.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Stakeholder> getAllDefaultByRole(String type) {
|
||||||
public List<Stakeholder> getAccessedStakeholders(List<Stakeholder> stakeholders, boolean isDefault) {
|
return (type == null ? this.dao.findByDefaultIdIsNull() : this.dao.findByDefaultIdAndType(null, type)).stream()
|
||||||
return stakeholders.stream()
|
.filter(stakeholder -> this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), true))
|
||||||
.filter(stakeholder -> this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), isDefault))
|
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ManageStakeholders getManageStakeholders(String type) {
|
public List<Stakeholder> getStakeholdersByTypeAndRole(String type, String defaultId, boolean manage) {
|
||||||
ManageStakeholders manageStakeholders = new ManageStakeholders();
|
List<Stakeholder> stakeholders;
|
||||||
StakeholderType stakeholderType = StakeholderType.convert(type);
|
if (type != null && defaultId != null) {
|
||||||
manageStakeholders.setTemplates(this.getAccessedStakeholders(this.dao.defaultStakeholders(stakeholderType), true));
|
stakeholders = dao.findByDefaultIdAndType(defaultId, type);
|
||||||
manageStakeholders.setStandalone(this.getAccessedStakeholders(this.dao.standaloneStakeholders(stakeholderType), false));
|
} else if (defaultId != null) {
|
||||||
manageStakeholders.setDependent(this.getAccessedStakeholders(this.dao.dependentStakeholders(stakeholderType), false));
|
stakeholders = dao.findByDefaultIdAndCopyTrue(defaultId);
|
||||||
manageStakeholders.setUmbrella(this.getAccessedStakeholders(this.dao.umbrellaStakeholders(stakeholderType), false));
|
} else if (type != null) {
|
||||||
return manageStakeholders;
|
stakeholders = dao.findByDefaultIdIsNotNullAndType(type);
|
||||||
|
} else {
|
||||||
|
stakeholders = dao.findByDefaultIdIsNotNull();
|
||||||
}
|
}
|
||||||
|
return stakeholders.stream().filter(stakeholder ->
|
||||||
public List<Stakeholder> getVisibleStakeholders(String type, String defaultId) {
|
(!manage && (stakeholder.getVisibility() == Visibility.PUBLIC || stakeholder.getVisibility() == Visibility.RESTRICTED))
|
||||||
return this.dao.browseStakeholders(StakeholderType.convert(type), defaultId).stream().filter(stakeholder ->
|
|| this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), false))
|
||||||
stakeholder.getVisibility() == Visibility.PUBLIC ||
|
|
||||||
stakeholder.getVisibility() == Visibility.RESTRICTED ||
|
|
||||||
this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), false))
|
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public StakeholderFull getFullStakeholder(Stakeholder stakeholder) {
|
public StakeholderFull getFullStakeholder(Stakeholder stakeholder) {
|
||||||
List<TopicFull> topics = stakeholder.getTopics().stream()
|
if (this.commonService.hasVisibilityAuthority(stakeholder.getType(), stakeholder.getAlias(), stakeholder)) {
|
||||||
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
if(!stakeholder.isCopy() && stakeholder.getDefaultId() != null) {
|
if(!stakeholder.isCopy() && stakeholder.getDefaultId() != null) {
|
||||||
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
|
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
|
||||||
if(defaultStakeholder != null) {
|
if(defaultStakeholder != null) {
|
||||||
topics = defaultStakeholder.getTopics().stream()
|
return new StakeholderFull(stakeholder,
|
||||||
|
defaultStakeholder.getTopics().stream()
|
||||||
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
|
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Umbrella<Stakeholder> umbrella = Umbrella.convert(stakeholder.getUmbrella(), this);
|
return new StakeholderFull(stakeholder,
|
||||||
return new StakeholderFull(stakeholder, topics, umbrella);
|
stakeholder.getTopics().stream()
|
||||||
|
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
} else {
|
||||||
|
return 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) {
|
public Stakeholder buildStakeholder(Stakeholder stakeholder, String copyId) {
|
||||||
|
@ -148,16 +123,14 @@ public class StakeholderService {
|
||||||
|
|
||||||
public Stakeholder save(Stakeholder stakeholder) {
|
public Stakeholder save(Stakeholder stakeholder) {
|
||||||
if (stakeholder.getId() != null) {
|
if (stakeholder.getId() != null) {
|
||||||
Stakeholder old = this.findByPath(stakeholder.getId());
|
|
||||||
stakeholder.setUmbrella(old.getUmbrella());
|
|
||||||
stakeholder.setStandalone(old.isStandalone());
|
|
||||||
stakeholder.setDefaultId(old.getDefaultId());
|
|
||||||
if (!stakeholder.isCopy() && stakeholder.getDefaultId() != null) {
|
if (!stakeholder.isCopy() && stakeholder.getDefaultId() != null) {
|
||||||
stakeholder.getTopics().forEach(topic -> {
|
stakeholder.getTopics().forEach(topic -> {
|
||||||
this.topicService.delete(stakeholder.getType(), topic, false);
|
this.topicService.delete(stakeholder.getType(), topic, false);
|
||||||
});
|
});
|
||||||
stakeholder.setTopics(new ArrayList<>());
|
stakeholder.setTopics(new ArrayList<>());
|
||||||
} else {
|
} else {
|
||||||
|
Stakeholder old = this.findByPath(stakeholder.getId());
|
||||||
|
stakeholder.setTopics(old.getTopics());
|
||||||
if(old.getTopics().isEmpty() && old.getDefaultId() != null) {
|
if(old.getTopics().isEmpty() && old.getDefaultId() != null) {
|
||||||
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
|
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
|
||||||
if(defaultStakeholder != null) {
|
if(defaultStakeholder != null) {
|
||||||
|
@ -185,14 +158,13 @@ public class StakeholderService {
|
||||||
throw new EntityNotFoundException("Some topics dont exist in the stakeholder with id " + stakeholder.getId());
|
throw new EntityNotFoundException("Some topics dont exist in the stakeholder with id " + stakeholder.getId());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to reorder topics in stakeholder with id: " + stakeholder.getId());
|
throw new ForbiddenException("You are not authorized to reorder topics in stakeholder with id: " + stakeholder.getId());
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reorderChildren(Stakeholder defaultStakeholder, List<String> defaultTopics) {
|
public void reorderChildren(Stakeholder defaultStakeholder, List<String> defaultTopics) {
|
||||||
this.dao.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).stream().map(this::getFullStakeholder).forEach(stakeholder -> {
|
this.dao.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).stream().map(this::getFullStakeholder).forEach(stakeholder -> {
|
||||||
this.reorderTopics(new Stakeholder(stakeholder, this),
|
this.reorderTopics(new Stakeholder(stakeholder),
|
||||||
this.commonService.reorder(defaultTopics, stakeholder.getTopics().stream().map(topic -> (Common) topic).collect(Collectors.toList())));
|
this.commonService.reorder(defaultTopics, stakeholder.getTopics().stream().map(topic -> (Common) topic).collect(Collectors.toList())));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -200,14 +172,7 @@ public class StakeholderService {
|
||||||
public String delete(String id) {
|
public String delete(String id) {
|
||||||
Stakeholder stakeholder = this.findByPath(id);
|
Stakeholder stakeholder = this.findByPath(id);
|
||||||
if (this.commonService.hasDeleteAuthority(stakeholder.getType())) {
|
if (this.commonService.hasDeleteAuthority(stakeholder.getType())) {
|
||||||
this.dao.umbrellaStakeholders().forEach(umbrellaStakeholder -> {
|
this.dao.findByDefaultIdAndCopyTrue(stakeholder.getId()).forEach(child -> {
|
||||||
StakeholderType type = StakeholderType.valueOf(stakeholder.getType());
|
|
||||||
List<String> ids = umbrellaStakeholder.getUmbrella().getChildren().get(type);
|
|
||||||
if(ids != null && ids.contains(stakeholder.getId())) {
|
|
||||||
this.removeChild(umbrellaStakeholder.getId(), StakeholderType.valueOf(stakeholder.getType()), stakeholder.getId());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.dao.findByDefaultIdAndCopyIsTrue(stakeholder.getId()).forEach(child -> {
|
|
||||||
this.delete(child.getId());
|
this.delete(child.getId());
|
||||||
});
|
});
|
||||||
stakeholder.getTopics().forEach(topicId -> {
|
stakeholder.getTopics().forEach(topicId -> {
|
||||||
|
@ -216,9 +181,8 @@ public class StakeholderService {
|
||||||
this.dao.delete(id);
|
this.dao.delete(id);
|
||||||
return stakeholder.getAlias();
|
return stakeholder.getAlias();
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("Delete stakeholder: You are not authorized to delete stakeholder with id: " + id);
|
throw new ForbiddenException("Delete stakeholder: You are not authorized to delete stakeholder with id: " + id);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public StakeholderFull changeVisibility(StakeholderFull stakeholder, Visibility visibility, Boolean propagate) {
|
public StakeholderFull changeVisibility(StakeholderFull stakeholder, Visibility visibility, Boolean propagate) {
|
||||||
|
@ -229,111 +193,15 @@ public class StakeholderService {
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
stakeholder.setVisibility(visibility);
|
stakeholder.setVisibility(visibility);
|
||||||
stakeholder.update(this.save(new Stakeholder(stakeholder, this)));
|
stakeholder.update(this.save(new Stakeholder(stakeholder)));
|
||||||
return stakeholder;
|
return stakeholder;
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("Change stakeholder visibility: You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
throw new ForbiddenException("Change stakeholder visibility: You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public StakeholderFull changeVisibility(Stakeholder stakeholder, Visibility visibility, Boolean propagate) {
|
public StakeholderFull changeVisibility(Stakeholder stakeholder, Visibility visibility, Boolean propagate) {
|
||||||
StakeholderFull stakeholderFull = this.getFullStakeholder(stakeholder);
|
StakeholderFull stakeholderFull = this.getFullStakeholder(stakeholder);
|
||||||
return this.changeVisibility(stakeholderFull, visibility, propagate);
|
return this.changeVisibility(stakeholderFull, visibility, propagate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Umbrella<Stakeholder> updateUmbrella(Stakeholder stakeholder, UpdateUmbrella update) {
|
|
||||||
if (this.commonService.hasEditAuthority(stakeholder.getType(), stakeholder.getAlias())) {
|
|
||||||
if(update.getAction().equals(Action.ADD)) {
|
|
||||||
if(update.getChild() != null) {
|
|
||||||
return this.addChild(stakeholder.getId(), update.getType(), update.getChild());
|
|
||||||
} else {
|
|
||||||
return this.addType(stakeholder.getId(), update.getType());
|
|
||||||
}
|
|
||||||
} else if(update.getAction().equals(Action.REMOVE)) {
|
|
||||||
if(update.getChild() != null) {
|
|
||||||
return this.removeChild(stakeholder.getId(), update.getType(), update.getChild());
|
|
||||||
} else {
|
|
||||||
return this.removeType(stakeholder.getId(), update.getType());
|
|
||||||
}
|
|
||||||
} else if(update.getAction().equals(Action.UPDATE)) {
|
|
||||||
if(update.getType() != null) {
|
|
||||||
return this.updateChildren(stakeholder.getId(), update.getType(), update.getChildren());
|
|
||||||
} else {
|
|
||||||
return this.updateTypes(stakeholder.getId(), update.getTypes());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.commonService.unauthorized("You are not authorized to update umbrella in stakeholder with id: " + stakeholder.getId());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Umbrella<Stakeholder> addType(String id, StakeholderType type) {
|
|
||||||
Stakeholder stakeholder = this.findByPath(id);
|
|
||||||
Umbrella<String> umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new EntityNotFoundException("Umbrella not found in the stakeholder with id " + id));
|
|
||||||
if (umbrella.addType(type)) {
|
|
||||||
stakeholder.setUmbrella(umbrella);
|
|
||||||
stakeholder.setUpdateDate(new Date());
|
|
||||||
return this.getFullStakeholder(this.dao.save(stakeholder)).getUmbrella();
|
|
||||||
}
|
|
||||||
throw new BadRequestException("Cannot add type: " + type + " to stakeholder with id " + id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Umbrella<Stakeholder> removeType(String id, StakeholderType type) {
|
|
||||||
Stakeholder stakeholder = this.findByPath(id);
|
|
||||||
Umbrella<String> umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new EntityNotFoundException("Umbrella not found in the stakeholder with id " + id));
|
|
||||||
if (umbrella.removeType(type)) {
|
|
||||||
stakeholder.setUmbrella(umbrella);
|
|
||||||
stakeholder.setUpdateDate(new Date());
|
|
||||||
return this.getFullStakeholder(this.dao.save(stakeholder)).getUmbrella();
|
|
||||||
}
|
|
||||||
throw new BadRequestException("Cannot add type: " + type + " to stakeholder with id " + id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Umbrella<Stakeholder> addChild(String id, StakeholderType type, String childId) {
|
|
||||||
Stakeholder stakeholder = this.findByPath(id);
|
|
||||||
Umbrella<String> umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new EntityNotFoundException("Umbrella not found in the stakeholder with id " + id));
|
|
||||||
Stakeholder child = this.findByPath(childId);
|
|
||||||
if (child.getType().equals(type.name()) && umbrella.addChild(type, childId)) {
|
|
||||||
stakeholder.setUmbrella(umbrella);
|
|
||||||
stakeholder.setUpdateDate(new Date());
|
|
||||||
return this.getFullStakeholder(this.dao.save(stakeholder)).getUmbrella();
|
|
||||||
}
|
|
||||||
throw new BadRequestException("Cannot add child: " + childId + " to stakeholder with id " + id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Umbrella<Stakeholder> removeChild(String id, StakeholderType type, String childId) {
|
|
||||||
Stakeholder stakeholder = this.findByPath(id);
|
|
||||||
Umbrella<String> umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new EntityNotFoundException("Umbrella not found in the stakeholder with id " + id));
|
|
||||||
Stakeholder child = this.findByPath(childId);
|
|
||||||
if (child.getType().equals(type.name()) && umbrella.removeChild(type, childId)) {
|
|
||||||
stakeholder.setUmbrella(umbrella);
|
|
||||||
stakeholder.setUpdateDate(new Date());
|
|
||||||
return this.getFullStakeholder(this.dao.save(stakeholder)).getUmbrella();
|
|
||||||
}
|
|
||||||
throw new BadRequestException("Cannot remove child: " + childId + " to stakeholder with id " + id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Umbrella<Stakeholder> updateTypes(String id, List<StakeholderType> types) {
|
|
||||||
Stakeholder stakeholder = this.findByPath(id);
|
|
||||||
Umbrella<String> umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new EntityNotFoundException("Umbrella not found in the stakeholder with id " + id));
|
|
||||||
if (stakeholder.getUmbrella().update(types)) {
|
|
||||||
stakeholder.setUmbrella(umbrella);
|
|
||||||
stakeholder.setUpdateDate(new Date());
|
|
||||||
return this.getFullStakeholder(this.dao.save(stakeholder)).getUmbrella();
|
|
||||||
}
|
|
||||||
throw new BadRequestException("Cannot update types in umbrella of stakeholder with id " + id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Umbrella<Stakeholder> updateChildren(String id, StakeholderType type, List<String> children) {
|
|
||||||
Stakeholder stakeholder = this.findByPath(id);
|
|
||||||
Umbrella<String> umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new EntityNotFoundException("Umbrella not found in the stakeholder with id " + id));
|
|
||||||
if (stakeholder.getUmbrella().update(type, children)) {
|
|
||||||
stakeholder.setUmbrella(umbrella);
|
|
||||||
stakeholder.setUpdateDate(new Date());
|
|
||||||
return this.getFullStakeholder(this.dao.save(stakeholder)).getUmbrella();
|
|
||||||
}
|
|
||||||
throw new BadRequestException("Cannot update children of " + type + " in umbrella of stakeholder with id " + id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.dnetlib.uoamonitorservice.service;
|
package eu.dnetlib.uoamonitorservice.service;
|
||||||
|
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||||
import eu.dnetlib.uoamonitorservice.dao.CategoryDAO;
|
import eu.dnetlib.uoamonitorservice.dao.CategoryDAO;
|
||||||
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
|
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
|
||||||
import eu.dnetlib.uoamonitorservice.dao.SubCategoryDAO;
|
import eu.dnetlib.uoamonitorservice.dao.SubCategoryDAO;
|
||||||
|
@ -111,7 +112,7 @@ public class SubCategoryService {
|
||||||
this.updateChildren(subCategory);
|
this.updateChildren(subCategory);
|
||||||
subCategory = this.save(subCategory);
|
subCategory = this.save(subCategory);
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.commonService.hasCreateAuthority(stakeholder.getType())) {
|
if (this.commonService.hasCreateAuthority(stakeholder.getType())) {
|
||||||
|
@ -119,7 +120,7 @@ public class SubCategoryService {
|
||||||
this.createChildren(category, subCategory);
|
this.createChildren(category, subCategory);
|
||||||
this.addSubCategory(category, subCategory.getId());
|
this.addSubCategory(category, subCategory.getId());
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to create a subCategory in stakeholder with id: " + stakeholder.getId());
|
throw new ForbiddenException("You are not authorized to create a subCategory in stakeholder with id: " + stakeholder.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory);
|
return this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory);
|
||||||
|
@ -152,13 +153,12 @@ public class SubCategoryService {
|
||||||
this.moveIndicatorChildren(stakeholder, subCategory, moveIndicator);
|
this.moveIndicatorChildren(stakeholder, subCategory, moveIndicator);
|
||||||
return this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory);
|
return this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory);
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to move indicators in subCategory with id: " + subCategory.getId());
|
throw new ForbiddenException("You are not authorized to move indicators in subCategory with id: " + subCategory.getId());
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveIndicatorChildren(Stakeholder defaultStakeholder, SubCategory defaultSubCategory, MoveIndicator moveIndicator) {
|
public void moveIndicatorChildren(Stakeholder defaultStakeholder, SubCategory defaultSubCategory, MoveIndicator moveIndicator) {
|
||||||
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
||||||
this.dao.findByDefaultId(defaultSubCategory.getId()).stream()
|
this.dao.findByDefaultId(defaultSubCategory.getId()).stream()
|
||||||
.map(subCategory -> this.getFullSubCategory(stakeholder.getType(), stakeholder. getAlias(), subCategory))
|
.map(subCategory -> this.getFullSubCategory(stakeholder.getType(), stakeholder. getAlias(), subCategory))
|
||||||
.collect(Collectors.toList()).forEach(subCategory -> {
|
.collect(Collectors.toList()).forEach(subCategory -> {
|
||||||
|
@ -191,9 +191,8 @@ public class SubCategoryService {
|
||||||
throw new EntityNotFoundException("Some sections dont exist in the subCategory with id " + subCategory.getId());
|
throw new EntityNotFoundException("Some sections dont exist in the subCategory with id " + subCategory.getId());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to reorder sections in subCategory with id: " + subCategory.getId());
|
throw new ForbiddenException("You are not authorized to reorder sections in subCategory with id: " + subCategory.getId());
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubCategoryFull reorderCharts(Stakeholder stakeholder, SubCategory subCategory, List<String> charts) {
|
public SubCategoryFull reorderCharts(Stakeholder stakeholder, SubCategory subCategory, List<String> charts) {
|
||||||
|
@ -207,13 +206,12 @@ public class SubCategoryService {
|
||||||
throw new EntityNotFoundException("Some sections dont exist in the subCategory with id " + subCategory.getId());
|
throw new EntityNotFoundException("Some sections dont exist in the subCategory with id " + subCategory.getId());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to reorder sections in subCategory with id: " + subCategory.getId());
|
throw new ForbiddenException("You are not authorized to reorder sections in subCategory with id: " + subCategory.getId());
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reorderChildrenNumbers(Stakeholder defaultStakeholder, SubCategory defaultSubCategory, List<String> defaultSections) {
|
public void reorderChildrenNumbers(Stakeholder defaultStakeholder, SubCategory defaultSubCategory, List<String> defaultSections) {
|
||||||
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
||||||
this.dao.findByDefaultId(defaultSubCategory.getId()).stream().map(subCategory -> this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory)).forEach(subCategory -> {
|
this.dao.findByDefaultId(defaultSubCategory.getId()).stream().map(subCategory -> this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory)).forEach(subCategory -> {
|
||||||
this.reorderNumbers(stakeholder, new SubCategory(subCategory),
|
this.reorderNumbers(stakeholder, new SubCategory(subCategory),
|
||||||
this.commonService.reorder(defaultSections, subCategory.getNumbers().stream().map(section -> (Common) section).collect(Collectors.toList())));
|
this.commonService.reorder(defaultSections, subCategory.getNumbers().stream().map(section -> (Common) section).collect(Collectors.toList())));
|
||||||
|
@ -222,7 +220,7 @@ public class SubCategoryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reorderChildrenCharts(Stakeholder defaultStakeholder, SubCategory defaultSubCategory, List<String> defaultSections) {
|
public void reorderChildrenCharts(Stakeholder defaultStakeholder, SubCategory defaultSubCategory, List<String> defaultSections) {
|
||||||
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
||||||
this.dao.findByDefaultId(defaultSubCategory.getId()).stream().map(subCategory -> this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory)).forEach(subCategory -> {
|
this.dao.findByDefaultId(defaultSubCategory.getId()).stream().map(subCategory -> this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory)).forEach(subCategory -> {
|
||||||
this.reorderCharts(stakeholder, new SubCategory(subCategory),
|
this.reorderCharts(stakeholder, new SubCategory(subCategory),
|
||||||
this.commonService.reorder(defaultSections, subCategory.getCharts().stream().map(section -> (Common) section).collect(Collectors.toList())));
|
this.commonService.reorder(defaultSections, subCategory.getCharts().stream().map(section -> (Common) section).collect(Collectors.toList())));
|
||||||
|
@ -247,7 +245,7 @@ public class SubCategoryService {
|
||||||
}
|
}
|
||||||
this.dao.delete(subCategory);
|
this.dao.delete(subCategory);
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("Delete subCategory: You are not authorized to delete subCategory with id: " + subCategory.getId());
|
throw new ForbiddenException("Delete subCategory: You are not authorized to delete subCategory with id: " + subCategory.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,9 +282,8 @@ public class SubCategoryService {
|
||||||
subCategory.update(this.save(new SubCategory(subCategory)));
|
subCategory.update(this.save(new SubCategory(subCategory)));
|
||||||
return subCategory;
|
return subCategory;
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("Change subCategory visibility: You are not authorized to update subCategory with id: " + subCategory.getId());
|
throw new ForbiddenException("Change subCategory visibility: You are not authorized to update subCategory with id: " + subCategory.getId());
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubCategoryFull changeVisibility(String type, String alias, SubCategory subCategory, Visibility visibility, Boolean propagate) {
|
public SubCategoryFull changeVisibility(String type, String alias, SubCategory subCategory, Visibility visibility, Boolean propagate) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.dnetlib.uoamonitorservice.service;
|
package eu.dnetlib.uoamonitorservice.service;
|
||||||
|
|
||||||
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
|
||||||
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
|
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
|
||||||
import eu.dnetlib.uoamonitorservice.dao.TopicDAO;
|
import eu.dnetlib.uoamonitorservice.dao.TopicDAO;
|
||||||
import eu.dnetlib.uoamonitorservice.dto.TopicFull;
|
import eu.dnetlib.uoamonitorservice.dto.TopicFull;
|
||||||
|
@ -93,7 +94,7 @@ public class TopicService {
|
||||||
this.updateChildren(topic);
|
this.updateChildren(topic);
|
||||||
topic = this.save(topic);
|
topic = this.save(topic);
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(this.commonService.hasCreateAuthority(stakeholder.getType())) {
|
if(this.commonService.hasCreateAuthority(stakeholder.getType())) {
|
||||||
|
@ -101,14 +102,14 @@ public class TopicService {
|
||||||
this.createChildren(stakeholder, topic);
|
this.createChildren(stakeholder, topic);
|
||||||
this.addTopic(stakeholder, topic.getId());
|
this.addTopic(stakeholder, topic.getId());
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to create a topic in stakeholder with id: " + stakeholder.getId());
|
throw new ForbiddenException("You are not authorized to create a topic in stakeholder with id: " + stakeholder.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topic);
|
return this.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createChildren(Stakeholder defaultStakeholder, Topic topic) {
|
public void createChildren(Stakeholder defaultStakeholder, Topic topic) {
|
||||||
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
||||||
this.save(stakeholder, topic.copy());
|
this.save(stakeholder, topic.copy());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -131,13 +132,12 @@ public class TopicService {
|
||||||
throw new EntityNotFoundException("Some categories dont exist in the topic with id " + topic.getId());
|
throw new EntityNotFoundException("Some categories dont exist in the topic with id " + topic.getId());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("You are not authorized to reorder categories in topic with id: " + topic.getId());
|
throw new ForbiddenException("You are not authorized to reorder categories in topic with id: " + topic.getId());
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reorderChildren(Stakeholder defaultStakeholder, Topic defaultTopic, List<String> defaultCategories) {
|
public void reorderChildren(Stakeholder defaultStakeholder, Topic defaultTopic, List<String> defaultCategories) {
|
||||||
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
||||||
this.dao.findByDefaultId(defaultTopic.getId()).stream().map(topic -> this.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topic)).forEach(topic -> {
|
this.dao.findByDefaultId(defaultTopic.getId()).stream().map(topic -> this.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topic)).forEach(topic -> {
|
||||||
this.reorderCategories(stakeholder, new Topic(topic),
|
this.reorderCategories(stakeholder, new Topic(topic),
|
||||||
this.commonService.reorder(defaultCategories, topic.getCategories().stream().map(category -> (Common) category).collect(Collectors.toList())));
|
this.commonService.reorder(defaultCategories, topic.getCategories().stream().map(category -> (Common) category).collect(Collectors.toList())));
|
||||||
|
@ -158,7 +158,7 @@ public class TopicService {
|
||||||
}
|
}
|
||||||
this.dao.delete(topic);
|
this.dao.delete(topic);
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("Delete topic: You are not authorized to delete topic with id: " + topic.getId());
|
throw new ForbiddenException("Delete topic: You are not authorized to delete topic with id: " + topic.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,9 +192,8 @@ public class TopicService {
|
||||||
topic.update(this.save(new Topic(topic)));
|
topic.update(this.save(new Topic(topic)));
|
||||||
return topic;
|
return topic;
|
||||||
} else {
|
} else {
|
||||||
this.commonService.unauthorized("Change topic visibility: You are not authorized to update topic with id: " + topic.getId());
|
throw new ForbiddenException("Change topic visibility: You are not authorized to update topic with id: " + topic.getId());
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TopicFull changeVisibility(String type, String alias, Topic topic, Visibility visibility, Boolean propagate) {
|
public TopicFull changeVisibility(String type, String alias, Topic topic, Visibility visibility, Boolean propagate) {
|
||||||
|
|
Loading…
Reference in New Issue