Compare commits
16 Commits
uoa-monito
...
master
11
pom.xml
11
pom.xml
|
@ -1,14 +1,15 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<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">
|
<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">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>uoa-monitor-service</artifactId>
|
<artifactId>uoa-monitor-service</artifactId>
|
||||||
<version>1.1.11</version>
|
<version>1.0.4-SNAPSHOT</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</tag>
|
</scm>
|
||||||
</scm>
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>eu.dnetlib</groupId>
|
<groupId>eu.dnetlib</groupId>
|
||||||
<artifactId>uoa-spring-boot-parent</artifactId>
|
<artifactId>uoa-spring-boot-parent</artifactId>
|
||||||
|
@ -29,7 +30,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.10</version>
|
<version>1.0.13</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>eu.dnetlib</groupId>
|
<groupId>eu.dnetlib</groupId>
|
||||||
|
|
|
@ -234,8 +234,6 @@ 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,8 +52,6 @@ function addFooterHelpTextForPortalType(portalType) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// use monitordb;
|
|
||||||
|
|
||||||
addHomePageInPortalType("funder");
|
addHomePageInPortalType("funder");
|
||||||
addFooterDivIdForPortalType("funder");
|
addFooterDivIdForPortalType("funder");
|
||||||
addFooterHelpTextForPortalType("funder");
|
addFooterHelpTextForPortalType("funder");
|
||||||
|
|
|
@ -176,7 +176,5 @@ function addFundingStreamInDefaultMSCA() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// use monitordb;
|
|
||||||
|
|
||||||
statsProfileOfIndicatorsAsVariable();
|
statsProfileOfIndicatorsAsVariable();
|
||||||
addFundingStreamInDefaultMSCA();
|
addFundingStreamInDefaultMSCA();
|
||||||
|
|
|
@ -12,5 +12,12 @@ function deleteIndexParameters() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// use irish-prod;
|
function addCopyWithDefaultValue() {
|
||||||
|
/* 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();
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
function addStandaloneWithDefaultValue() {
|
||||||
|
/* Set standalone by default true */
|
||||||
|
db.stakeholder.updateMany({standalone: {$exists: false}}, {$set: {standalone: true}});
|
||||||
|
}
|
||||||
|
|
||||||
|
addStandaloneWithDefaultValue();
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
@ -8,7 +7,8 @@ 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,23 +1,14 @@
|
||||||
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,13 +1,15 @@
|
||||||
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.copy;
|
import eu.dnetlib.uoamonitorservice.dto.BuildStakeholder;
|
||||||
|
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.generics.StakeholderGeneric;
|
import eu.dnetlib.uoamonitorservice.primitives.Umbrella;
|
||||||
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;
|
||||||
|
@ -16,7 +18,6 @@ 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 = "*")
|
||||||
|
@ -25,29 +26,33 @@ 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) {
|
public StakeholderController(PortalService portalService, StakeholderService stakeholderService, CommonService commonService) {
|
||||||
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() {
|
public List<String> getAllReservedStakeholderAlias(@RequestParam(required = false) String type) {
|
||||||
List<String> stakeholderAlias = this.stakeholderService.getAllAliases();
|
List<String> stakeholderAlias = this.stakeholderService.getAllAliases(type);
|
||||||
stakeholderAlias.add("all");
|
if(type == null ) {
|
||||||
stakeholderAlias.add("default");
|
stakeholderAlias.add("all");
|
||||||
stakeholderAlias.add("alias");
|
stakeholderAlias.add("default");
|
||||||
|
stakeholderAlias.add("alias");
|
||||||
|
}
|
||||||
return stakeholderAlias;
|
return stakeholderAlias;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(" +
|
@PreAuthorize("hasAnyAuthority(" +
|
||||||
"@AuthorizationService.PORTAL_ADMIN, " +
|
"@AuthorizationService.PORTAL_ADMIN, " +
|
||||||
"@AuthorizationService.curator(#copy.stakeholder.getType()))")
|
"@AuthorizationService.curator(#buildStakeholder.stakeholder.getType()))")
|
||||||
@RequestMapping(value = "/build-stakeholder", method = RequestMethod.POST)
|
@RequestMapping(value = "/build-stakeholder", method = RequestMethod.POST)
|
||||||
public Stakeholder buildStakeholder(@RequestBody copy copy) {
|
public Stakeholder buildStakeholder(@RequestBody BuildStakeholder buildStakeholder) {
|
||||||
Stakeholder stakeholder = copy.getStakeholder();
|
Stakeholder stakeholder = buildStakeholder.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());
|
||||||
|
@ -58,7 +63,11 @@ public class StakeholderController {
|
||||||
portal.setType(stakeholder.getType());
|
portal.setType(stakeholder.getType());
|
||||||
portalService.insertPortal(portal);
|
portalService.insertPortal(portal);
|
||||||
}
|
}
|
||||||
return this.stakeholderService.buildStakeholder(stakeholder, copy.getCopyId());
|
stakeholder.setStandalone(buildStakeholder.isStandalone());
|
||||||
|
if (buildStakeholder.isUmbrella()) {
|
||||||
|
stakeholder.setUmbrella(new Umbrella<>());
|
||||||
|
}
|
||||||
|
return this.stakeholderService.buildStakeholder(stakeholder, buildStakeholder.getCopyId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority(" + "@AuthorizationService.PORTAL_ADMIN)")
|
@PreAuthorize("hasAnyAuthority(" + "@AuthorizationService.PORTAL_ADMIN)")
|
||||||
|
@ -67,33 +76,37 @@ 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.getStakeholdersByTypeAndRole(type, defaultId, false);
|
return stakeholderService.getVisibleStakeholders(type, defaultId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("isAuthenticated()")
|
@PreAuthorize("isAuthenticated()")
|
||||||
@RequestMapping(value = "/my-stakeholder", method = RequestMethod.GET)
|
@RequestMapping(value = "/my-stakeholder", method = RequestMethod.GET)
|
||||||
public List<Stakeholder> getManagedStakeholders(@RequestParam(required = false) String type) {
|
public ManageStakeholders getManagedStakeholders(@RequestParam(required = false) String type) {
|
||||||
return stakeholderService.getStakeholdersByTypeAndRole(type, null, true);
|
return stakeholderService.getManageStakeholders(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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) {
|
||||||
throw new ForbiddenException("Get stakeholder: You are not authorized to access stakeholder with alias: " + alias);
|
this.commonService.unauthorized("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()), "
|
||||||
|
@ -115,7 +128,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)));
|
return this.stakeholderService.getFullStakeholder(this.stakeholderService.save(new Stakeholder(stakeholder, this.stakeholderService)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("isAuthenticated()")
|
@PreAuthorize("isAuthenticated()")
|
||||||
|
@ -139,4 +152,13 @@ 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,6 +1,7 @@
|
||||||
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;
|
||||||
|
|
||||||
|
@ -9,20 +10,187 @@ 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> findByDefaultIdIsNotNull();
|
List<Stakeholder> findByDefaultIdIsNullAndType(StakeholderType Type);
|
||||||
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);
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,13 @@ package eu.dnetlib.uoamonitorservice.dto;
|
||||||
|
|
||||||
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
||||||
|
|
||||||
public class copy {
|
public class BuildStakeholder {
|
||||||
private Stakeholder stakeholder;
|
private Stakeholder stakeholder;
|
||||||
private String copyId;
|
private String copyId;
|
||||||
|
private boolean umbrella = false;
|
||||||
|
private boolean standalone = true;
|
||||||
|
|
||||||
public copy() {
|
public BuildStakeholder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stakeholder getStakeholder() {
|
public Stakeholder getStakeholder() {
|
||||||
|
@ -24,4 +26,20 @@ public class copy {
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package eu.dnetlib.uoamonitorservice.dto;
|
||||||
|
|
||||||
|
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ManageStakeholders {
|
||||||
|
List<Stakeholder> templates;
|
||||||
|
List<Stakeholder> standalone;
|
||||||
|
List<Stakeholder> dependent;
|
||||||
|
List<Stakeholder> umbrella;
|
||||||
|
|
||||||
|
public ManageStakeholders() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Stakeholder> getTemplates() {
|
||||||
|
return templates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTemplates(List<Stakeholder> templates) {
|
||||||
|
this.templates = templates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Stakeholder> getStandalone() {
|
||||||
|
return standalone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStandalone(List<Stakeholder> standalone) {
|
||||||
|
this.standalone = standalone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Stakeholder> getDependent() {
|
||||||
|
return dependent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDependent(List<Stakeholder> dependent) {
|
||||||
|
this.dependent = dependent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Stakeholder> getUmbrella() {
|
||||||
|
return umbrella;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUmbrella(List<Stakeholder> umbrella) {
|
||||||
|
this.umbrella = umbrella;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,19 +1,40 @@
|
||||||
package eu.dnetlib.uoamonitorservice.dto;
|
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> {
|
public class StakeholderFull extends StakeholderGeneric<TopicFull, Stakeholder> {
|
||||||
|
public List<Stakeholder> otherParents;
|
||||||
|
public Stakeholder parent;
|
||||||
|
|
||||||
public StakeholderFull() {
|
public StakeholderFull() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public StakeholderFull(StakeholderGeneric stakeholder, List<TopicFull> topics) {
|
public StakeholderFull(StakeholderGeneric stakeholder, List<TopicFull> topics, Umbrella<Stakeholder> umbrella) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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> {
|
public class Stakeholder extends StakeholderGeneric<String, String> {
|
||||||
|
|
||||||
public Stakeholder() {
|
public Stakeholder() {
|
||||||
super();
|
super();
|
||||||
|
@ -21,10 +21,13 @@ public class Stakeholder extends StakeholderGeneric<String> {
|
||||||
super(stakeholder);
|
super(stakeholder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stakeholder(StakeholderFull stakeholder) {
|
public Stakeholder(StakeholderFull stakeholder, StakeholderService service) {
|
||||||
super(stakeholder);
|
super(stakeholder);
|
||||||
this.topics = stakeholder.getTopics().stream().map(Common::getId).collect(Collectors.toList());
|
Stakeholder old = service.findByPath(stakeholder.getId());
|
||||||
this.topics.removeIf(Objects::isNull);
|
this.defaultId = old.getDefaultId();
|
||||||
|
this.standalone = old.isStandalone();
|
||||||
|
this.topics = old.getTopics();
|
||||||
|
this.umbrella = old.getUmbrella();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTopic(String id) {
|
public void addTopic(String id) {
|
||||||
|
|
|
@ -1,21 +1,14 @@
|
||||||
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<StringOrSubcategory> extends Common {
|
public class CategoryGeneric<T> extends Common {
|
||||||
protected boolean isOverview;
|
protected boolean isOverview;
|
||||||
protected List<StringOrSubcategory> subCategories;
|
protected List<T> subCategories;
|
||||||
|
|
||||||
public CategoryGeneric() {}
|
public CategoryGeneric() {}
|
||||||
|
|
||||||
|
@ -40,11 +33,11 @@ public class CategoryGeneric<StringOrSubcategory> extends Common {
|
||||||
this.isOverview = isOverview;
|
this.isOverview = isOverview;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StringOrSubcategory> getSubCategories() {
|
public List<T> getSubCategories() {
|
||||||
return subCategories;
|
return subCategories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSubCategories(List<StringOrSubcategory> subCategories) {
|
public void setSubCategories(List<T> 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<StringOrIndicator> extends Common {
|
public class SectionGeneric<T> extends Common {
|
||||||
protected String title;
|
protected String title;
|
||||||
protected String stakeholderAlias;
|
protected String stakeholderAlias;
|
||||||
protected IndicatorType type;
|
protected IndicatorType type;
|
||||||
protected List<StringOrIndicator> indicators;
|
protected List<T> indicators;
|
||||||
|
|
||||||
public SectionGeneric() {
|
public SectionGeneric() {
|
||||||
}
|
}
|
||||||
|
@ -60,11 +60,11 @@ public class SectionGeneric<StringOrIndicator> extends Common {
|
||||||
return this.type == IndicatorType.NUMBER || this.type == IndicatorType.number;
|
return this.type == IndicatorType.NUMBER || this.type == IndicatorType.number;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StringOrIndicator> getIndicators() {
|
public List<T> getIndicators() {
|
||||||
return indicators;
|
return indicators;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIndicators(List<StringOrIndicator> indicators) {
|
public void setIndicators(List<T> indicators) {
|
||||||
this.indicators = indicators;
|
this.indicators = indicators;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
package eu.dnetlib.uoamonitorservice.generics;
|
package eu.dnetlib.uoamonitorservice.generics;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
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.Visibility;
|
import eu.dnetlib.uoamonitorservice.primitives.Umbrella;
|
||||||
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;
|
||||||
|
@ -23,8 +21,10 @@ public class StakeholderGeneric<StringOrTopic> 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<StringOrTopic> topics;
|
protected List<T> topics = new ArrayList<>();
|
||||||
|
protected Umbrella<S> umbrella;
|
||||||
|
|
||||||
public StakeholderGeneric() {
|
public StakeholderGeneric() {
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,7 @@ public class StakeholderGeneric<StringOrTopic> 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();
|
||||||
}
|
}
|
||||||
|
@ -59,11 +60,7 @@ public class StakeholderGeneric<StringOrTopic> extends Common {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(String type) {
|
public void setType(String type) {
|
||||||
if (type == null) {
|
this.type = StakeholderType.convert(type);
|
||||||
this.type = null;
|
|
||||||
} else {
|
|
||||||
this.type = StakeholderType.valueOf(type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getProjectUpdateDate() {
|
public Date getProjectUpdateDate() {
|
||||||
|
@ -144,6 +141,17 @@ public class StakeholderGeneric<StringOrTopic> 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;
|
||||||
|
@ -155,11 +163,24 @@ public class StakeholderGeneric<StringOrTopic> extends Common {
|
||||||
this.copy = copy;
|
this.copy = copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StringOrTopic> getTopics() {
|
public List<T> getTopics() {
|
||||||
return topics;
|
return topics;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTopics(List<StringOrTopic> topics) {
|
public void setTopics(List<T> 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<StringOrSection> extends Common {
|
public class SubCategoryGeneric<T> extends Common {
|
||||||
protected List<StringOrSection> charts;
|
protected List<T> charts;
|
||||||
protected List<StringOrSection> numbers;
|
protected List<T> numbers;
|
||||||
|
|
||||||
public SubCategoryGeneric() {}
|
public SubCategoryGeneric() {}
|
||||||
public SubCategoryGeneric(SubCategoryGeneric subCategory) {
|
public SubCategoryGeneric(SubCategoryGeneric subCategory) {
|
||||||
|
@ -21,19 +21,19 @@ public class SubCategoryGeneric<StringOrSection> extends Common {
|
||||||
charts = new ArrayList<>();
|
charts = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StringOrSection> getCharts() {
|
public List<T> getCharts() {
|
||||||
return charts;
|
return charts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCharts(List<StringOrSection> charts) {
|
public void setCharts(List<T> charts) {
|
||||||
this.charts = charts;
|
this.charts = charts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StringOrSection> getNumbers() {
|
public List<T> getNumbers() {
|
||||||
return numbers;
|
return numbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNumbers(List<StringOrSection> numbers) {
|
public void setNumbers(List<T> numbers) {
|
||||||
this.numbers = numbers;
|
this.numbers = numbers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,11 @@
|
||||||
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<StringOrCategory> extends Common {
|
public class TopicGeneric<T> extends Common {
|
||||||
protected String icon;
|
protected String icon;
|
||||||
protected List<StringOrCategory> categories;
|
protected List<T> categories;
|
||||||
|
|
||||||
public TopicGeneric() {
|
public TopicGeneric() {
|
||||||
}
|
}
|
||||||
|
@ -39,11 +32,11 @@ public class TopicGeneric<StringOrCategory> extends Common {
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StringOrCategory> getCategories() {
|
public List<T> getCategories() {
|
||||||
return categories;
|
return categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCategories(List<StringOrCategory> categories) {
|
public void setCategories(List<T> categories) {
|
||||||
this.categories = categories;
|
this.categories = categories;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
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,6 +25,17 @@ 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();
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package eu.dnetlib.uoamonitorservice.primitives;
|
||||||
|
|
||||||
|
public enum Action {
|
||||||
|
ADD, REMOVE, UPDATE
|
||||||
|
}
|
|
@ -4,6 +4,16 @@ 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,125 @@
|
||||||
|
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,6 +1,5 @@
|
||||||
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;
|
||||||
|
@ -102,7 +101,7 @@ public class CategoryService {
|
||||||
this.updateChildren(category);
|
this.updateChildren(category);
|
||||||
category = this.save(category);
|
category = this.save(category);
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
this.commonService.unauthorized("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())) {
|
||||||
|
@ -113,7 +112,7 @@ public class CategoryService {
|
||||||
}
|
}
|
||||||
this.addCategory(topic, category.getId());
|
this.addCategory(topic, category.getId());
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("You are not authorized to create a category in stakeholder with id: " + stakeholder.getId());
|
this.commonService.unauthorized("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);
|
||||||
|
@ -145,12 +144,13 @@ 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 {
|
||||||
throw new ForbiddenException("You are not authorized to reorder subCategories in category with id: " + category.getId());
|
this.commonService.unauthorized("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.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
||||||
this.dao.findByDefaultId(defaultCategory.getId()).stream().map(category -> this.getFullCategory(stakeholder.getType(), stakeholder.getAlias(), category)).forEach(category -> {
|
this.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 {
|
||||||
throw new ForbiddenException("Delete category: You are not authorized to delete category with id: " + category.getId());
|
this.commonService.unauthorized("Delete category: You are not authorized to delete category with id: " + category.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,8 +205,9 @@ public class CategoryService {
|
||||||
category.update(this.save(new Category(category)));
|
category.update(this.save(new Category(category)));
|
||||||
return category;
|
return category;
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("Change category visibility: You are not authorized to update category with id: " + category.getId());
|
this.commonService.unauthorized("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,7 +1,8 @@
|
||||||
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;
|
||||||
|
@ -69,4 +70,12 @@ 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,6 +1,5 @@
|
||||||
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;
|
||||||
|
@ -82,7 +81,7 @@ public class IndicatorService {
|
||||||
this.updateChildren(indicator);
|
this.updateChildren(indicator);
|
||||||
indicator = this.save(indicator);
|
indicator = this.save(indicator);
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
this.commonService.unauthorized("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())) {
|
||||||
|
@ -90,7 +89,7 @@ public class IndicatorService {
|
||||||
this.createChildren(section, indicator);
|
this.createChildren(section, indicator);
|
||||||
this.addIndicator(section, indicator.getId());
|
this.addIndicator(section, indicator.getId());
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("You are not authorized to create an indicator in stakeholder with id: " + stakeholder.getId());
|
this.commonService.unauthorized("You are not authorized to create an indicator in stakeholder with id: " + stakeholder.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return indicator;
|
return indicator;
|
||||||
|
@ -128,7 +127,7 @@ public class IndicatorService {
|
||||||
}
|
}
|
||||||
this.dao.delete(indicator);
|
this.dao.delete(indicator);
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("Delete indicator: You are not authorized to delete indicator with id: " + indicator.getId());
|
this.commonService.unauthorized("Delete indicator: You are not authorized to delete indicator with id: " + indicator.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +156,8 @@ public class IndicatorService {
|
||||||
indicator.setVisibility(visibility);
|
indicator.setVisibility(visibility);
|
||||||
return this.save(indicator);
|
return this.save(indicator);
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("Change section visibility: You are not authorized to update section with id: " + indicator.getId());
|
this.commonService.unauthorized("Change section visibility: You are not authorized to update section with id: " + indicator.getId());
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
@ -103,7 +102,7 @@ public class SectionService {
|
||||||
this.createChildren(subCategory, new Section(section), -1);
|
this.createChildren(subCategory, new Section(section), -1);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("You are not authorized to create sections in stakeholder with id: " + stakeholder.getId());
|
this.commonService.unauthorized("You are not authorized to create sections in stakeholder with id: " + stakeholder.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +114,7 @@ public class SectionService {
|
||||||
this.updateChildren(section);
|
this.updateChildren(section);
|
||||||
section = this.save(section);
|
section = this.save(section);
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
this.commonService.unauthorized("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())) {
|
||||||
|
@ -123,7 +122,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 {
|
||||||
throw new ForbiddenException("You are not authorized to create a section in stakeholder with id: " + stakeholder.getId());
|
this.commonService.unauthorized("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);
|
||||||
|
@ -135,13 +134,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 -> {
|
|
||||||
this.indicatorService.createChildren(section, this.indicatorService.find(indicator));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
section.getIndicators().forEach(indicator -> {
|
||||||
|
this.indicatorService.createChildren(section, this.indicatorService.find(indicator));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateChildren(Section section) {
|
public void updateChildren(Section section) {
|
||||||
|
@ -168,12 +167,13 @@ 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 {
|
||||||
throw new ForbiddenException("You are not authorized to reorder indicators in section with id: " + section.getId());
|
this.commonService.unauthorized("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.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
||||||
this.dao.findByDefaultId(defaultSection.getId()).stream().map(section -> this.getFullSection(stakeholder.getType(), stakeholder.getAlias(), section)).forEach(section -> {
|
this.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 {
|
||||||
throw new ForbiddenException("Delete section: You are not authorized to delete section with id: " + section.getId());
|
this.commonService.unauthorized("Delete section: You are not authorized to delete section with id: " + section.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +238,8 @@ public class SectionService {
|
||||||
section.update(this.save(new Section(section)));
|
section.update(this.save(new Section(section)));
|
||||||
return section;
|
return section;
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("Change section visibility: You are not authorized to update section with id: " + section.getId());
|
this.commonService.unauthorized("Change section visibility: You are not authorized to update section with id: " + section.getId());
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,34 +1,42 @@
|
||||||
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.ArrayList;
|
import java.util.*;
|
||||||
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) {
|
public StakeholderService(StakeholderDAO dao, CommonService commonService, TopicService topicService, MongoTemplate mongoTemplate) {
|
||||||
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) {
|
||||||
|
@ -36,74 +44,91 @@ public class StakeholderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Stakeholder> findByDefaultId(String id) {
|
public List<Stakeholder> findByDefaultId(String id) {
|
||||||
return this.dao.findByDefaultIdAndCopyTrue(id);
|
return this.dao.findByDefaultIdAndCopyIsTrue(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stakeholder findByPath(String stakeholderId) {
|
public Stakeholder findByPath(String stakeholderId) {
|
||||||
if(stakeholderId.equals("-1")) {
|
if (stakeholderId.equals("-1")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
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() {
|
public List<String> getAllAliases(String type) {
|
||||||
return this.dao.findAll().stream().map(Stakeholder::getAlias).collect(Collectors.toList());
|
return this.getAll(type).stream().map(Stakeholder::getAlias).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Stakeholder> getAll(String type) {
|
public List<Stakeholder> getAll(String type) {
|
||||||
if (type != null) {
|
return this.dao.allStakeholders(StakeholderType.convert(type));
|
||||||
return this.dao.findByType(type);
|
|
||||||
}
|
|
||||||
return this.dao.findAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Stakeholder> getAllDefaultByRole(String type) {
|
|
||||||
return (type == null ? this.dao.findByDefaultIdIsNull() : this.dao.findByDefaultIdAndType(null, type)).stream()
|
public List<Stakeholder> getAccessedStakeholders(List<Stakeholder> stakeholders, boolean isDefault) {
|
||||||
.filter(stakeholder -> this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), true))
|
return stakeholders.stream()
|
||||||
|
.filter(stakeholder -> this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), isDefault))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Stakeholder> getStakeholdersByTypeAndRole(String type, String defaultId, boolean manage) {
|
public ManageStakeholders getManageStakeholders(String type) {
|
||||||
List<Stakeholder> stakeholders;
|
ManageStakeholders manageStakeholders = new ManageStakeholders();
|
||||||
if (type != null && defaultId != null) {
|
StakeholderType stakeholderType = StakeholderType.convert(type);
|
||||||
stakeholders = dao.findByDefaultIdAndType(defaultId, type);
|
manageStakeholders.setTemplates(this.getAccessedStakeholders(this.dao.defaultStakeholders(stakeholderType), true));
|
||||||
} else if (defaultId != null) {
|
manageStakeholders.setStandalone(this.getAccessedStakeholders(this.dao.standaloneStakeholders(stakeholderType), false));
|
||||||
stakeholders = dao.findByDefaultIdAndCopyTrue(defaultId);
|
manageStakeholders.setDependent(this.getAccessedStakeholders(this.dao.dependentStakeholders(stakeholderType), false));
|
||||||
} else if (type != null) {
|
manageStakeholders.setUmbrella(this.getAccessedStakeholders(this.dao.umbrellaStakeholders(stakeholderType), false));
|
||||||
stakeholders = dao.findByDefaultIdIsNotNullAndType(type);
|
return manageStakeholders;
|
||||||
} else {
|
}
|
||||||
stakeholders = dao.findByDefaultIdIsNotNull();
|
|
||||||
}
|
public List<Stakeholder> getVisibleStakeholders(String type, String defaultId) {
|
||||||
return stakeholders.stream().filter(stakeholder ->
|
return this.dao.browseStakeholders(StakeholderType.convert(type), defaultId).stream().filter(stakeholder ->
|
||||||
(!manage && (stakeholder.getVisibility() == Visibility.PUBLIC || stakeholder.getVisibility() == Visibility.RESTRICTED))
|
stakeholder.getVisibility() == Visibility.PUBLIC ||
|
||||||
|| this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), false))
|
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) {
|
||||||
if (this.commonService.hasVisibilityAuthority(stakeholder.getType(), stakeholder.getAlias(), stakeholder)) {
|
List<TopicFull> topics = stakeholder.getTopics().stream()
|
||||||
if(!stakeholder.isCopy() && stakeholder.getDefaultId() != null) {
|
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
|
||||||
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
|
.collect(Collectors.toList());
|
||||||
if(defaultStakeholder != null) {
|
if (!stakeholder.isCopy() && stakeholder.getDefaultId() != null) {
|
||||||
return new StakeholderFull(stakeholder,
|
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
|
||||||
defaultStakeholder.getTopics().stream()
|
if (defaultStakeholder != null) {
|
||||||
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
|
topics = defaultStakeholder.getTopics().stream()
|
||||||
.collect(Collectors.toList()));
|
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
|
||||||
}
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
return new StakeholderFull(stakeholder,
|
|
||||||
stakeholder.getTopics().stream()
|
|
||||||
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
Umbrella<Stakeholder> umbrella = Umbrella.convert(stakeholder.getUmbrella(), this);
|
||||||
|
return new StakeholderFull(stakeholder, topics, umbrella);
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
if(stakeholder.getDefaultId() == null) {
|
if (stakeholder.getDefaultId() == null) {
|
||||||
stakeholder.setCopy(false);
|
stakeholder.setCopy(false);
|
||||||
if(copyId == null) {
|
if (copyId == null) {
|
||||||
stakeholder.setTopics(new ArrayList<>());
|
stakeholder.setTopics(new ArrayList<>());
|
||||||
} else {
|
} else {
|
||||||
Stakeholder copyFrom = this.findByPath(copyId);
|
Stakeholder copyFrom = this.findByPath(copyId);
|
||||||
|
@ -111,9 +136,9 @@ public class StakeholderService {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stakeholder.setTopics(new ArrayList<>());
|
stakeholder.setTopics(new ArrayList<>());
|
||||||
if(stakeholder.isCopy()) {
|
if (stakeholder.isCopy()) {
|
||||||
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
|
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
|
||||||
if(defaultStakeholder != null) {
|
if (defaultStakeholder != null) {
|
||||||
stakeholder.setTopics(defaultStakeholder.getTopics().stream().map(this.topicService::build).collect(Collectors.toList()));
|
stakeholder.setTopics(defaultStakeholder.getTopics().stream().map(this.topicService::build).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,17 +148,19 @@ 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());
|
if (old.getTopics().isEmpty() && old.getDefaultId() != null) {
|
||||||
stakeholder.setTopics(old.getTopics());
|
|
||||||
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) {
|
||||||
stakeholder.setTopics(defaultStakeholder.getTopics().stream().map(this.topicService::build).collect(Collectors.toList()));
|
stakeholder.setTopics(defaultStakeholder.getTopics().stream().map(this.topicService::build).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,13 +185,14 @@ 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 {
|
||||||
throw new ForbiddenException("You are not authorized to reorder topics in stakeholder with id: " + stakeholder.getId());
|
this.commonService.unauthorized("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.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).stream().map(this::getFullStakeholder).forEach(stakeholder -> {
|
this.dao.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).stream().map(this::getFullStakeholder).forEach(stakeholder -> {
|
||||||
this.reorderTopics(new Stakeholder(stakeholder),
|
this.reorderTopics(new Stakeholder(stakeholder, this),
|
||||||
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())));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -172,7 +200,14 @@ 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.findByDefaultIdAndCopyTrue(stakeholder.getId()).forEach(child -> {
|
this.dao.umbrellaStakeholders().forEach(umbrellaStakeholder -> {
|
||||||
|
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 -> {
|
||||||
|
@ -181,8 +216,9 @@ public class StakeholderService {
|
||||||
this.dao.delete(id);
|
this.dao.delete(id);
|
||||||
return stakeholder.getAlias();
|
return stakeholder.getAlias();
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("Delete stakeholder: You are not authorized to delete stakeholder with id: " + id);
|
this.commonService.unauthorized("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) {
|
||||||
|
@ -193,15 +229,111 @@ public class StakeholderService {
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
stakeholder.setVisibility(visibility);
|
stakeholder.setVisibility(visibility);
|
||||||
stakeholder.update(this.save(new Stakeholder(stakeholder)));
|
stakeholder.update(this.save(new Stakeholder(stakeholder, this)));
|
||||||
return stakeholder;
|
return stakeholder;
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("Change stakeholder visibility: You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
this.commonService.unauthorized("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,6 +1,5 @@
|
||||||
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;
|
||||||
|
@ -112,7 +111,7 @@ public class SubCategoryService {
|
||||||
this.updateChildren(subCategory);
|
this.updateChildren(subCategory);
|
||||||
subCategory = this.save(subCategory);
|
subCategory = this.save(subCategory);
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
this.commonService.unauthorized("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())) {
|
||||||
|
@ -120,7 +119,7 @@ public class SubCategoryService {
|
||||||
this.createChildren(category, subCategory);
|
this.createChildren(category, subCategory);
|
||||||
this.addSubCategory(category, subCategory.getId());
|
this.addSubCategory(category, subCategory.getId());
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("You are not authorized to create a subCategory in stakeholder with id: " + stakeholder.getId());
|
this.commonService.unauthorized("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);
|
||||||
|
@ -153,12 +152,13 @@ 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 {
|
||||||
throw new ForbiddenException("You are not authorized to move indicators in subCategory with id: " + subCategory.getId());
|
this.commonService.unauthorized("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.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(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,8 +191,9 @@ 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 {
|
||||||
throw new ForbiddenException("You are not authorized to reorder sections in subCategory with id: " + subCategory.getId());
|
this.commonService.unauthorized("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) {
|
||||||
|
@ -206,12 +207,13 @@ 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 {
|
||||||
throw new ForbiddenException("You are not authorized to reorder sections in subCategory with id: " + subCategory.getId());
|
this.commonService.unauthorized("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.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
||||||
this.dao.findByDefaultId(defaultSubCategory.getId()).stream().map(subCategory -> this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory)).forEach(subCategory -> {
|
this.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())));
|
||||||
|
@ -220,7 +222,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.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
||||||
this.dao.findByDefaultId(defaultSubCategory.getId()).stream().map(subCategory -> this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory)).forEach(subCategory -> {
|
this.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())));
|
||||||
|
@ -245,7 +247,7 @@ public class SubCategoryService {
|
||||||
}
|
}
|
||||||
this.dao.delete(subCategory);
|
this.dao.delete(subCategory);
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("Delete subCategory: You are not authorized to delete subCategory with id: " + subCategory.getId());
|
this.commonService.unauthorized("Delete subCategory: You are not authorized to delete subCategory with id: " + subCategory.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,8 +284,9 @@ public class SubCategoryService {
|
||||||
subCategory.update(this.save(new SubCategory(subCategory)));
|
subCategory.update(this.save(new SubCategory(subCategory)));
|
||||||
return subCategory;
|
return subCategory;
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("Change subCategory visibility: You are not authorized to update subCategory with id: " + subCategory.getId());
|
this.commonService.unauthorized("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,6 +1,5 @@
|
||||||
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;
|
||||||
|
@ -94,7 +93,7 @@ public class TopicService {
|
||||||
this.updateChildren(topic);
|
this.updateChildren(topic);
|
||||||
topic = this.save(topic);
|
topic = this.save(topic);
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
|
this.commonService.unauthorized("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())) {
|
||||||
|
@ -102,14 +101,14 @@ public class TopicService {
|
||||||
this.createChildren(stakeholder, topic);
|
this.createChildren(stakeholder, topic);
|
||||||
this.addTopic(stakeholder, topic.getId());
|
this.addTopic(stakeholder, topic.getId());
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("You are not authorized to create a topic in stakeholder with id: " + stakeholder.getId());
|
this.commonService.unauthorized("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.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
||||||
this.save(stakeholder, topic.copy());
|
this.save(stakeholder, topic.copy());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -132,12 +131,13 @@ 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 {
|
||||||
throw new ForbiddenException("You are not authorized to reorder categories in topic with id: " + topic.getId());
|
this.commonService.unauthorized("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.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
|
||||||
this.dao.findByDefaultId(defaultTopic.getId()).stream().map(topic -> this.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topic)).forEach(topic -> {
|
this.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 {
|
||||||
throw new ForbiddenException("Delete topic: You are not authorized to delete topic with id: " + topic.getId());
|
this.commonService.unauthorized("Delete topic: You are not authorized to delete topic with id: " + topic.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,8 +192,9 @@ public class TopicService {
|
||||||
topic.update(this.save(new Topic(topic)));
|
topic.update(this.save(new Topic(topic)));
|
||||||
return topic;
|
return topic;
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException("Change topic visibility: You are not authorized to update topic with id: " + topic.getId());
|
this.commonService.unauthorized("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) {
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
</RollingFile>
|
</RollingFile>
|
||||||
</Appenders>
|
</Appenders>
|
||||||
<Loggers>
|
<Loggers>
|
||||||
<Logger name="eu.dnetlib" level="info" additivity="false">
|
<Logger name="eu.dnetlib" level="debug" additivity="false">
|
||||||
<AppenderRef ref="R"/>
|
<AppenderRef ref="R"/>
|
||||||
</Logger>
|
</Logger>
|
||||||
<Root level="info">
|
<Root level="info">
|
||||||
|
|
Loading…
Reference in New Issue