Compare commits

..

37 Commits

Author SHA1 Message Date
Konstantinos Triantafyllou f0fc81b27a [maven-release-plugin] prepare release uoa-monitor-service-1.1.11-BETA 2024-04-15 10:43:36 +03:00
Konstantinos Triantafyllou 409ec76b67 Merge remote-tracking branch 'origin/master' into beta 2024-04-15 10:43:03 +03:00
Konstantinos Triantafyllou 095058e45b [maven-release-plugin] prepare for next development iteration 2024-03-12 17:58:15 +02:00
Konstantinos Triantafyllou 3d757fc2d2 [maven-release-plugin] prepare release uoa-monitor-service-1.1.10-BETA 2024-03-12 17:58:11 +02:00
Konstantinos Triantafyllou cc59982d8a Merge remote-tracking branch 'origin/master' into beta 2024-03-12 17:57:07 +02:00
Konstantinos Triantafyllou ed0626032f [maven-release-plugin] prepare for next development iteration 2024-02-20 09:30:29 +02:00
Konstantinos Triantafyllou 73d8f2cc95 [maven-release-plugin] prepare release uoa-monitor-service-1.1.9-BETA 2024-02-20 09:30:25 +02:00
Konstantinos Triantafyllou 78680d933c Merge remote-tracking branch 'origin/master' into beta 2024-02-20 09:30:04 +02:00
Konstantinos Triantafyllou c3e452d9bd [maven-release-plugin] prepare for next development iteration 2024-02-20 09:11:17 +02:00
Konstantinos Triantafyllou 8b89929622 [maven-release-plugin] prepare release uoa-monitor-service-1.1.8-BETA 2024-02-20 09:11:13 +02:00
Konstantinos Triantafyllou b727c07970 [maven-release-plugin] prepare for next development iteration 2023-12-21 15:30:38 +02:00
Konstantinos Triantafyllou ba4eac5f60 [maven-release-plugin] prepare release uoa-monitor-service-1.1.7-BETA 2023-12-21 15:30:33 +02:00
Konstantinos Triantafyllou c82a393e1e Merge remote-tracking branch 'origin/irish-monitor-service' into beta 2023-12-21 15:30:09 +02:00
Konstantinos Triantafyllou 5e213020b4 [maven-release-plugin] prepare for next development iteration 2023-11-14 13:22:10 +02:00
Konstantinos Triantafyllou a0584f2010 [maven-release-plugin] prepare release uoa-monitor-service-1.1.6-BETA 2023-11-14 13:22:07 +02:00
Konstantinos Triantafyllou 51bdeb5e1e Merge remote-tracking branch 'origin/master' into beta 2023-11-14 13:21:28 +02:00
Konstantinos Triantafyllou 075ecab118 [maven-release-plugin] prepare for next development iteration 2023-07-31 10:59:54 +03:00
Konstantinos Triantafyllou 65a4e8d3fe [maven-release-plugin] prepare release uoa-monitor-service-1.1.5-BETA 2023-07-31 10:59:50 +03:00
Konstantinos Triantafyllou 3c3c4295dc Merge remote-tracking branch 'origin/master' into beta 2023-07-31 10:59:25 +03:00
Konstantinos Triantafyllou c4805df822 [maven-release-plugin] prepare for next development iteration 2023-07-27 16:11:06 +03:00
Konstantinos Triantafyllou 14a0add458 [maven-release-plugin] prepare release uoa-monitor-service-1.1.4-BETA 2023-07-27 16:11:02 +03:00
Konstantinos Triantafyllou 36675ce12d Merge remote-tracking branch 'origin/master' into beta 2023-07-27 16:09:19 +03:00
Konstantinos Triantafyllou e6e8eb283f [maven-release-plugin] prepare for next development iteration 2023-07-04 16:04:19 +03:00
Konstantinos Triantafyllou fb3812db5c [maven-release-plugin] prepare release uoa-monitor-service-1.1.3-BETA 2023-07-04 16:04:15 +03:00
Konstantinos Triantafyllou e61d90fd9c Merge remote-tracking branch 'origin/master' into beta 2023-07-04 16:03:42 +03:00
Konstantinos Triantafyllou f036f7c98d [maven-release-plugin] prepare for next development iteration 2023-06-20 14:23:43 +03:00
Konstantinos Triantafyllou a95b9cecd5 [maven-release-plugin] prepare release uoa-monitor-service-1.1.2-BETA 2023-06-20 14:23:40 +03:00
Konstantinos Triantafyllou 0150975600 Merge remote-tracking branch 'origin/master' into beta 2023-06-20 14:22:34 +03:00
Konstantinos Triantafyllou 15b16613bf Merge remote-tracking branch 'origin/master' into beta 2023-05-31 16:27:36 +03:00
Konstantinos Triantafyllou b365e713e7 [maven-release-plugin] prepare for next development iteration 2023-05-30 16:29:20 +03:00
Konstantinos Triantafyllou fc37faa83d [maven-release-plugin] prepare release uoa-monitor-service-1.1.1-BETA 2023-05-30 16:29:16 +03:00
Konstantinos Triantafyllou 2e86ddca90 Merge branch 'master' into beta 2023-05-30 16:27:15 +03:00
Konstantina Galouni 6cbda6babc Merge pull request 'master' (#1) from master into beta
Reviewed-on: #1
2023-05-03 12:07:48 +02:00
Konstantinos Triantafyllou d3782a1fe9 [maven-release-plugin] prepare for next development iteration 2022-10-20 10:57:53 +03:00
Konstantinos Triantafyllou d85cdb8c23 [maven-release-plugin] prepare release uoa-monitor-service-1.1.0-BETA 2022-10-20 10:57:50 +03:00
Konstantinos Triantafyllou 07dd7d4ca7 Merge remote-tracking branch 'origin/log4j2' into beta 2022-10-20 10:57:20 +03:00
Konstantina Galouni ea7f71f0ab Configure beta pom (added -BETA- in version) 2022-10-10 15:31:15 +03:00
32 changed files with 216 additions and 867 deletions

11
pom.xml
View File

@ -1,15 +1,14 @@
<?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>
<artifactId>uoa-monitor-service</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.1.11-BETA</version>
<packaging>war</packaging>
<name>uoa-monitor-service</name>
<scm>
<developerConnection>scm:git:gitea@code-repo.d4science.org:MaDgIK/uoa-monitor-service.git</developerConnection>
</scm>
<tag>uoa-monitor-service-1.1.11-BETA</tag>
</scm>
<parent>
<groupId>eu.dnetlib</groupId>
<artifactId>uoa-spring-boot-parent</artifactId>
@ -30,7 +29,7 @@
<dependency> <!-- this dependency includes dependency to uoa-authorization-library -->
<groupId>eu.dnetlib</groupId>
<artifactId>uoa-admin-tools-library</artifactId>
<version>1.0.13</version>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>eu.dnetlib</groupId>

View File

@ -234,6 +234,8 @@ function uniqueIndexes() {
db.stakeholder.createIndex( { "alias": 1 }, { unique: true } );
}
// use monitordb;
upperCaseEnumValues();
addHeightInIndicators();
addVisibility();

View File

@ -52,6 +52,8 @@ function addFooterHelpTextForPortalType(portalType) {
}
}
// use monitordb;
addHomePageInPortalType("funder");
addFooterDivIdForPortalType("funder");
addFooterHelpTextForPortalType("funder");

View File

@ -176,5 +176,7 @@ function addFundingStreamInDefaultMSCA() {
}
}
// use monitordb;
statsProfileOfIndicatorsAsVariable();
addFundingStreamInDefaultMSCA();

View File

@ -12,12 +12,5 @@ function deleteIndexParameters() {
})
}
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}});
}
// use irish-prod;
deleteIndexParameters();
addCopyWithDefaultValue();

View File

@ -1,6 +0,0 @@
function addStandaloneWithDefaultValue() {
/* Set standalone by default true */
db.stakeholder.updateMany({standalone: {$exists: false}}, {$set: {standalone: true}});
}
addStandaloneWithDefaultValue();

View File

@ -1,5 +1,6 @@
package eu.dnetlib.uoamonitorservice.application;
import eu.dnetlib.uoaadmintoolslibrary.UoaAdminToolsLibraryConfiguration;
import eu.dnetlib.uoaauthorizationlibrary.configuration.AuthorizationConfiguration;
import eu.dnetlib.uoanotificationservice.configuration.NotificationConfiguration;
import org.springframework.boot.SpringApplication;
@ -7,8 +8,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
//uoahelptexts
@SpringBootApplication(scanBasePackages = {"eu.dnetlib.uoamonitorservice"})
@PropertySources({
@PropertySource("classpath:authorization.properties"),

View File

@ -1,14 +1,23 @@
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 org.apache.logging.log4j.LogManager;
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.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
@RestController

View File

@ -1,15 +1,13 @@
package eu.dnetlib.uoamonitorservice.controllers;
import eu.dnetlib.uoaadmintoolslibrary.entities.Portal;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
import eu.dnetlib.uoamonitorservice.dto.BuildStakeholder;
import eu.dnetlib.uoamonitorservice.dto.ManageStakeholders;
import eu.dnetlib.uoamonitorservice.dto.copy;
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
import eu.dnetlib.uoamonitorservice.dto.UpdateUmbrella;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import eu.dnetlib.uoamonitorservice.primitives.Umbrella;
import eu.dnetlib.uoamonitorservice.generics.StakeholderGeneric;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import eu.dnetlib.uoamonitorservice.service.CommonService;
import eu.dnetlib.uoamonitorservice.service.StakeholderService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -18,6 +16,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@CrossOrigin(origins = "*")
@ -26,33 +25,29 @@ public class StakeholderController {
private final PortalService portalService;
private final StakeholderService stakeholderService;
private final CommonService commonService;
@Autowired
public StakeholderController(PortalService portalService, StakeholderService stakeholderService, CommonService commonService) {
public StakeholderController(PortalService portalService, StakeholderService stakeholderService) {
this.portalService = portalService;
this.stakeholderService = stakeholderService;
this.commonService = commonService;
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/stakeholder/alias", method = RequestMethod.GET)
public List<String> getAllReservedStakeholderAlias(@RequestParam(required = false) String type) {
List<String> stakeholderAlias = this.stakeholderService.getAllAliases(type);
if(type == null ) {
stakeholderAlias.add("all");
stakeholderAlias.add("default");
stakeholderAlias.add("alias");
}
public List<String> getAllReservedStakeholderAlias() {
List<String> stakeholderAlias = this.stakeholderService.getAllAliases();
stakeholderAlias.add("all");
stakeholderAlias.add("default");
stakeholderAlias.add("alias");
return stakeholderAlias;
}
@PreAuthorize("hasAnyAuthority(" +
"@AuthorizationService.PORTAL_ADMIN, " +
"@AuthorizationService.curator(#buildStakeholder.stakeholder.getType()))")
"@AuthorizationService.curator(#copy.stakeholder.getType()))")
@RequestMapping(value = "/build-stakeholder", method = RequestMethod.POST)
public Stakeholder buildStakeholder(@RequestBody BuildStakeholder buildStakeholder) {
Stakeholder stakeholder = buildStakeholder.getStakeholder();
public Stakeholder buildStakeholder(@RequestBody copy copy) {
Stakeholder stakeholder = copy.getStakeholder();
log.debug("build stakeholder");
log.debug("Alias: " + stakeholder.getAlias());
Portal portal = portalService.getPortal(stakeholder.getAlias());
@ -63,11 +58,7 @@ public class StakeholderController {
portal.setType(stakeholder.getType());
portalService.insertPortal(portal);
}
stakeholder.setStandalone(buildStakeholder.isStandalone());
if (buildStakeholder.isUmbrella()) {
stakeholder.setUmbrella(new Umbrella<>());
}
return this.stakeholderService.buildStakeholder(stakeholder, buildStakeholder.getCopyId());
return this.stakeholderService.buildStakeholder(stakeholder, copy.getCopyId());
}
@PreAuthorize("hasAnyAuthority(" + "@AuthorizationService.PORTAL_ADMIN)")
@ -76,37 +67,33 @@ public class StakeholderController {
return this.stakeholderService.getAll(type);
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/stakeholder/default", method = RequestMethod.GET)
public List<Stakeholder> getAllDefaultStakeholders(@RequestParam(required = false) String type) {
return this.stakeholderService.getAllDefaultByRole(type);
}
@RequestMapping(value = "/stakeholder", method = RequestMethod.GET)
public List<Stakeholder> getVisibleStakeholders(@RequestParam(required = false) String type,
@RequestParam(required = false) String defaultId) {
return stakeholderService.getVisibleStakeholders(type, defaultId);
return stakeholderService.getStakeholdersByTypeAndRole(type, defaultId, false);
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/my-stakeholder", method = RequestMethod.GET)
public ManageStakeholders getManagedStakeholders(@RequestParam(required = false) String type) {
return stakeholderService.getManageStakeholders(type);
public List<Stakeholder> getManagedStakeholders(@RequestParam(required = false) String type) {
return stakeholderService.getStakeholdersByTypeAndRole(type, null, true);
}
@RequestMapping(value = "/stakeholder/{alias:.+}", method = RequestMethod.GET)
public StakeholderFull getStakeholder(@PathVariable("alias") String alias) {
StakeholderFull stakeholder = this.stakeholderService.getFullStakeholder(this.stakeholderService.findByAlias(alias));
if (stakeholder == null) {
this.commonService.unauthorized("Get stakeholder: You are not authorized to access stakeholder with alias: " + alias);
throw new ForbiddenException("Get stakeholder: You are not authorized to access stakeholder with alias: " + alias);
}
return stakeholder;
}
@RequestMapping(value = "/stakeholder/{parent:.+}/{type}/{child:.+}", method = RequestMethod.GET)
public StakeholderFull getStakeholderWithParent(@PathVariable("parent") String parent, @PathVariable("type") String type, @PathVariable("child") String child) {
StakeholderFull stakeholder = this.stakeholderService.getFullStakeholderWithParents(this.stakeholderService.findByAlias(child), type, parent);
if (stakeholder == null) {
this.commonService.unauthorized("Get stakeholder: You are not authorized to access stakeholder with alias: " + child);
}
return stakeholder;
}
@PreAuthorize("hasAnyAuthority("
+ "@AuthorizationService.PORTAL_ADMIN, "
+ "@AuthorizationService.curator(#stakeholder.getType()), "
@ -128,7 +115,7 @@ public class StakeholderController {
public StakeholderFull saveStakeholderFull(@RequestBody StakeholderFull stakeholder) {
log.debug("save stakeholder");
log.debug("Alias: " + stakeholder.getAlias() + " - Id: " + stakeholder.getId());
return this.stakeholderService.getFullStakeholder(this.stakeholderService.save(new Stakeholder(stakeholder, this.stakeholderService)));
return this.stakeholderService.getFullStakeholder(this.stakeholderService.save(new Stakeholder(stakeholder)));
}
@PreAuthorize("isAuthenticated()")
@ -152,13 +139,4 @@ public class StakeholderController {
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
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);
}
}

View File

@ -1,7 +1,6 @@
package eu.dnetlib.uoamonitorservice.dao;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import eu.dnetlib.uoamonitorservice.primitives.StakeholderType;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
@ -10,187 +9,20 @@ import java.util.Optional;
@Repository
public interface StakeholderDAO extends MongoRepository<Stakeholder, String> {
/**
* All Stakeholders
*/
List<Stakeholder> findAll();
List<Stakeholder> findByType(String Type);
List<Stakeholder> findByDefaultId(String id);
List<Stakeholder> findByType(StakeholderType Type);
List<Stakeholder> findByTypeAndDefaultId(StakeholderType Type, String id);
default List<Stakeholder> allStakeholders() {
return allStakeholders(null);
}
default List<Stakeholder> allStakeholders(StakeholderType type) {
return allStakeholders(type, null);
}
default List<Stakeholder> allStakeholders(StakeholderType type, String id) {
if (type != null && id != null) {
return findByTypeAndDefaultId(type, id);
} else if (id != null) {
return findByDefaultId(id);
} else if (type != null) {
return findByType(type);
} else {
return findAll();
}
}
/**
* Default Stakeholders
*/
List<Stakeholder> findByDefaultIdIsNull();
List<Stakeholder> findByDefaultIdAndCopyTrue(String defaultId);
List<Stakeholder> findByDefaultIdAndType(String DefaultId, String Type);
List<Stakeholder> findByDefaultIdIsNullAndType(StakeholderType Type);
default List<Stakeholder> defaultStakeholders(StakeholderType type) {
if (type == null) {
return findByDefaultIdIsNull();
}
return findByDefaultIdIsNullAndType(type);
}
/**
* Standalone Stakeholders (not umbrella)
*/
List<Stakeholder> findByDefaultIdIsNotNullAndStandaloneIsTrueAndUmbrellaIsNull();
List<Stakeholder> 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> findByDefaultIdIsNotNull();
List<Stakeholder> findByDefaultIdIsNotNullAndType(String Type);
List<Stakeholder> findByTopicsContaining(String topic);
Optional<Stakeholder> findById(String id);
Optional<Stakeholder> findByAlias(String alias);
Optional<Stakeholder> findById(String Id);
Optional<Stakeholder> findByAlias(String Alias);
void delete(String Id);

View File

@ -1,47 +0,0 @@
package eu.dnetlib.uoamonitorservice.dto;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import java.util.List;
public class ManageStakeholders {
List<Stakeholder> templates;
List<Stakeholder> standalone;
List<Stakeholder> dependent;
List<Stakeholder> umbrella;
public ManageStakeholders() {
}
public List<Stakeholder> getTemplates() {
return templates;
}
public void setTemplates(List<Stakeholder> templates) {
this.templates = templates;
}
public List<Stakeholder> getStandalone() {
return standalone;
}
public void setStandalone(List<Stakeholder> standalone) {
this.standalone = standalone;
}
public List<Stakeholder> getDependent() {
return dependent;
}
public void setDependent(List<Stakeholder> dependent) {
this.dependent = dependent;
}
public List<Stakeholder> getUmbrella() {
return umbrella;
}
public void setUmbrella(List<Stakeholder> umbrella) {
this.umbrella = umbrella;
}
}

View File

@ -1,40 +1,19 @@
package eu.dnetlib.uoamonitorservice.dto;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import eu.dnetlib.uoamonitorservice.generics.StakeholderGeneric;
import eu.dnetlib.uoamonitorservice.primitives.Umbrella;
import java.util.List;
import java.util.Objects;
public class StakeholderFull extends StakeholderGeneric<TopicFull, Stakeholder> {
public List<Stakeholder> otherParents;
public Stakeholder parent;
public class StakeholderFull extends StakeholderGeneric<TopicFull> {
public StakeholderFull() {
super();
}
public StakeholderFull(StakeholderGeneric stakeholder, List<TopicFull> topics, Umbrella<Stakeholder> umbrella) {
public StakeholderFull(StakeholderGeneric stakeholder, List<TopicFull> topics) {
super(stakeholder);
topics.removeIf(Objects::isNull);
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;
}
}

View File

@ -1,57 +0,0 @@
package eu.dnetlib.uoamonitorservice.dto;
import eu.dnetlib.uoamonitorservice.primitives.Action;
import eu.dnetlib.uoamonitorservice.primitives.StakeholderType;
import java.util.List;
public class UpdateUmbrella {
StakeholderType type;
Action action;
String child;
List<StakeholderType> types;
List<String> children;
public UpdateUmbrella() {
}
public StakeholderType getType() {
return type;
}
public void setType(StakeholderType type) {
this.type = type;
}
public Action getAction() {
return action;
}
public void setAction(Action action) {
this.action = action;
}
public String getChild() {
return child;
}
public void setChild(String child) {
this.child = child;
}
public List<StakeholderType> getTypes() {
return types;
}
public void setTypes(List<StakeholderType> types) {
this.types = types;
}
public List<String> getChildren() {
return children;
}
public void setChildren(List<String> children) {
this.children = children;
}
}

View File

@ -2,13 +2,11 @@ package eu.dnetlib.uoamonitorservice.dto;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
public class BuildStakeholder {
public class copy {
private Stakeholder stakeholder;
private String copyId;
private boolean umbrella = false;
private boolean standalone = true;
public BuildStakeholder() {
public copy() {
}
public Stakeholder getStakeholder() {
@ -26,20 +24,4 @@ public class BuildStakeholder {
public void setCopyId(String 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;
}
}

View File

@ -3,15 +3,15 @@ package eu.dnetlib.uoamonitorservice.entities;
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
import eu.dnetlib.uoamonitorservice.generics.Common;
import eu.dnetlib.uoamonitorservice.generics.StakeholderGeneric;
import eu.dnetlib.uoamonitorservice.primitives.Umbrella;
import eu.dnetlib.uoamonitorservice.service.StakeholderService;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Document
public class Stakeholder extends StakeholderGeneric<String, String> {
public class Stakeholder extends StakeholderGeneric<String> {
public Stakeholder() {
super();
@ -21,13 +21,10 @@ public class Stakeholder extends StakeholderGeneric<String, String> {
super(stakeholder);
}
public Stakeholder(StakeholderFull stakeholder, StakeholderService service) {
public Stakeholder(StakeholderFull stakeholder) {
super(stakeholder);
Stakeholder old = service.findByPath(stakeholder.getId());
this.defaultId = old.getDefaultId();
this.standalone = old.isStandalone();
this.topics = old.getTopics();
this.umbrella = old.getUmbrella();
this.topics = stakeholder.getTopics().stream().map(Common::getId).collect(Collectors.toList());
this.topics.removeIf(Objects::isNull);
}
public void addTopic(String id) {

View File

@ -1,14 +1,21 @@
package eu.dnetlib.uoamonitorservice.generics;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.dnetlib.uoamonitorservice.entities.Category;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Document
public class CategoryGeneric<T> extends Common {
public class CategoryGeneric<StringOrSubcategory> extends Common {
protected boolean isOverview;
protected List<T> subCategories;
protected List<StringOrSubcategory> subCategories;
public CategoryGeneric() {}
@ -33,11 +40,11 @@ public class CategoryGeneric<T> extends Common {
this.isOverview = isOverview;
}
public List<T> getSubCategories() {
public List<StringOrSubcategory> getSubCategories() {
return subCategories;
}
public void setSubCategories(List<T> subCategories) {
public void setSubCategories(List<StringOrSubcategory> subCategories) {
this.subCategories = subCategories;
}
}

View File

@ -5,11 +5,11 @@ import eu.dnetlib.uoamonitorservice.primitives.IndicatorType;
import java.util.ArrayList;
import java.util.List;
public class SectionGeneric<T> extends Common {
public class SectionGeneric<StringOrIndicator> extends Common {
protected String title;
protected String stakeholderAlias;
protected IndicatorType type;
protected List<T> indicators;
protected List<StringOrIndicator> indicators;
public SectionGeneric() {
}
@ -60,11 +60,11 @@ public class SectionGeneric<T> extends Common {
return this.type == IndicatorType.NUMBER || this.type == IndicatorType.number;
}
public List<T> getIndicators() {
public List<StringOrIndicator> getIndicators() {
return indicators;
}
public void setIndicators(List<T> indicators) {
public void setIndicators(List<StringOrIndicator> indicators) {
this.indicators = indicators;
}
}

View File

@ -1,16 +1,18 @@
package eu.dnetlib.uoamonitorservice.generics;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.dnetlib.uoamonitorservice.primitives.Locale;
import eu.dnetlib.uoamonitorservice.primitives.StakeholderType;
import eu.dnetlib.uoamonitorservice.primitives.Umbrella;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
public class StakeholderGeneric<T, S> extends Common {
public class StakeholderGeneric<StringOrTopic> extends Common {
protected StakeholderType type;
protected Date projectUpdateDate = null;
protected String index_id;
@ -21,10 +23,8 @@ public class StakeholderGeneric<T, S> extends Common {
protected boolean isUpload = false;
protected Locale locale = Locale.EU;
protected String funderType;
protected Boolean standalone = true;
protected Boolean copy;
protected List<T> topics = new ArrayList<>();
protected Umbrella<S> umbrella;
protected List<StringOrTopic> topics;
public StakeholderGeneric() {
}
@ -47,7 +47,6 @@ public class StakeholderGeneric<T, S> extends Common {
setVisibility(stakeholder.getVisibility());
this.funderType = stakeholder.getFunderType();
this.copy = stakeholder.isCopy();
this.standalone = stakeholder.isStandalone();
creationDate = stakeholder.getCreationDate();
updateDate = stakeholder.getUpdateDate();
}
@ -60,7 +59,11 @@ public class StakeholderGeneric<T, S> extends Common {
}
public void setType(String type) {
this.type = StakeholderType.convert(type);
if (type == null) {
this.type = null;
} else {
this.type = StakeholderType.valueOf(type);
}
}
public Date getProjectUpdateDate() {
@ -141,17 +144,6 @@ public class StakeholderGeneric<T, S> extends Common {
this.funderType = funderType;
}
public boolean isStandalone() {
if(standalone == null) {
standalone = true;
}
return standalone;
}
public void setStandalone(boolean standalone) {
this.standalone = standalone;
}
public boolean isCopy() {
if(copy == null) {
copy = this.defaultId != null;
@ -163,24 +155,11 @@ public class StakeholderGeneric<T, S> extends Common {
this.copy = copy;
}
public List<T> getTopics() {
public List<StringOrTopic> getTopics() {
return topics;
}
public void setTopics(List<T> topics) {
public void setTopics(List<StringOrTopic> 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;
}
}

View File

@ -3,9 +3,9 @@ package eu.dnetlib.uoamonitorservice.generics;
import java.util.ArrayList;
import java.util.List;
public class SubCategoryGeneric<T> extends Common {
protected List<T> charts;
protected List<T> numbers;
public class SubCategoryGeneric<StringOrSection> extends Common {
protected List<StringOrSection> charts;
protected List<StringOrSection> numbers;
public SubCategoryGeneric() {}
public SubCategoryGeneric(SubCategoryGeneric subCategory) {
@ -21,19 +21,19 @@ public class SubCategoryGeneric<T> extends Common {
charts = new ArrayList<>();
}
public List<T> getCharts() {
public List<StringOrSection> getCharts() {
return charts;
}
public void setCharts(List<T> charts) {
public void setCharts(List<StringOrSection> charts) {
this.charts = charts;
}
public List<T> getNumbers() {
public List<StringOrSection> getNumbers() {
return numbers;
}
public void setNumbers(List<T> numbers) {
public void setNumbers(List<StringOrSection> numbers) {
this.numbers = numbers;
}
}

View File

@ -1,11 +1,18 @@
package eu.dnetlib.uoamonitorservice.generics;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class TopicGeneric<T> extends Common {
public class TopicGeneric<StringOrCategory> extends Common {
protected String icon;
protected List<T> categories;
protected List<StringOrCategory> categories;
public TopicGeneric() {
}
@ -32,11 +39,11 @@ public class TopicGeneric<T> extends Common {
this.icon = icon;
}
public List<T> getCategories() {
public List<StringOrCategory> getCategories() {
return categories;
}
public void setCategories(List<T> categories) {
public void setCategories(List<StringOrCategory> categories) {
this.categories = categories;
}
}

View File

@ -1,11 +0,0 @@
package eu.dnetlib.uoamonitorservice.handlers;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(HttpStatus.BAD_REQUEST)
public class BadRequestException extends RuntimeException {
public BadRequestException(String message){
super(message);
}
}

View File

@ -25,17 +25,6 @@ public class ExceptionsHandler {
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)
public ResponseEntity<ExceptionResponse> pathNotValidException(Exception ex) {
ExceptionResponse response = new ExceptionResponse();

View File

@ -1,5 +0,0 @@
package eu.dnetlib.uoamonitorservice.primitives;
public enum Action {
ADD, REMOVE, UPDATE
}

View File

@ -4,16 +4,6 @@ public enum StakeholderType {
// Do not rename or remove existing values. This may cause problems with already stored values in DB
funder, ri, project, organization,
country, researcher, datasource,
publisher, journal,
FUNDER, RI, PROJECT, ORGANIZATION,
COUNTRY, RESEARCHER, DATASOURCE,
PUBLISHER, JOURNAL;
public static StakeholderType convert(String type) {
if(type == null) {
return null;
} else {
return StakeholderType.valueOf(type);
}
}
COUNTRY, RESEARCHER, DATASOURCE;
}

View File

@ -1,125 +0,0 @@
package eu.dnetlib.uoamonitorservice.primitives;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import eu.dnetlib.uoamonitorservice.generics.Common;
import eu.dnetlib.uoamonitorservice.service.StakeholderService;
import java.util.*;
import java.util.stream.Collectors;
public class Umbrella<T> {
List<StakeholderType> types;
Map<StakeholderType, List<T>> children;
public Umbrella() {
this.types = new ArrayList<>();
this.children = new HashMap<>();
}
public Umbrella(List<StakeholderType> types) {
this.types = types;
this.children = new HashMap<>();
}
public static Umbrella<String> convert(Umbrella<Stakeholder> umbrellaFull) {
if(umbrellaFull == null) {
return null;
}
Umbrella<String> umbrella = new Umbrella<>(umbrellaFull.getTypes());
umbrella.types.forEach(type -> umbrella.children.put(type, umbrellaFull.getChildren().get(type).stream().map(Common::getId).collect(Collectors.toList())));
return umbrella;
}
public static Umbrella<Stakeholder> convert(Umbrella<String> umbrella, StakeholderService service) {
if(umbrella == null) {
return null;
}
Umbrella<Stakeholder> umbrellaFull = new Umbrella<>(umbrella.getTypes());
umbrella.types.forEach(type -> umbrellaFull.children.put(type, umbrella.getChildren().get(type).stream().map(service::findByPath).collect(Collectors.toList())));
return umbrellaFull;
}
public Map<StakeholderType, List<T>> getChildren() {
return children;
}
public void setChildren(Map<StakeholderType, List<T>> children) {
this.children = children;
}
public List<StakeholderType> getTypes() {
return types;
}
public void setTypes(List<StakeholderType> types) {
this.types = types;
}
public boolean addType(StakeholderType type) {
if(!this.types.contains(type)) {
this.types.add(type);
this.children.put(type, new ArrayList<>());
return true;
}
return false;
}
public boolean removeType(StakeholderType type) {
if(this.types.contains(type)) {
this.types.remove(type);
this.children.remove(type);
return true;
}
return false;
}
public boolean addChild(StakeholderType type, T child) {
if(this.types.contains(type)) {
if(!this.children.containsKey(type)) {
this.children.put(type, new ArrayList<>());
}
if(!this.children.get(type).contains(child)) {
return this.children.get(type).add(child);
}
}
return false;
}
public boolean removeChild(StakeholderType type, T child) {
if(this.types.contains(type)) {
if(!this.children.containsKey(type)) {
return false;
}
if(this.children.get(type).contains(child)) {
return this.children.get(type).remove(child);
}
}
return false;
}
public boolean update(List<StakeholderType> types) {
if(types == null) {
return false;
} else if(types.size() != this.types.size()) {
return false;
} else {
if(new HashSet<>(this.types).containsAll(types)) {
this.types = types;
return true;
}
return false;
}
}
public boolean update(StakeholderType type, List<T> children) {
if(children == null) {
return false;
} else if(this.children.get(type) == null) {
return false;
} else if(children.size() != this.children.get(type).size()) {
return false;
} else {
return new HashSet<>(this.children.get(type)).containsAll(children);
}
}
}

View File

@ -1,5 +1,6 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoamonitorservice.dao.CategoryDAO;
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
import eu.dnetlib.uoamonitorservice.dao.TopicDAO;
@ -101,7 +102,7 @@ public class CategoryService {
this.updateChildren(category);
category = this.save(category);
} else {
this.commonService.unauthorized("You are not authorized to update stakeholder with id: " + stakeholder.getId());
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
}
} else {
if (this.commonService.hasCreateAuthority(stakeholder.getType())) {
@ -112,7 +113,7 @@ public class CategoryService {
}
this.addCategory(topic, category.getId());
} else {
this.commonService.unauthorized("You are not authorized to create a category in stakeholder with id: " + stakeholder.getId());
throw new ForbiddenException("You are not authorized to create a category in stakeholder with id: " + stakeholder.getId());
}
}
return this.getFullCategory(stakeholder.getType(), stakeholder.getAlias(), category);
@ -144,13 +145,12 @@ public class CategoryService {
throw new EntityNotFoundException("Some subCategories dont exist in the category with id " + category.getId());
}
} else {
this.commonService.unauthorized("You are not authorized to reorder subCategories in category with id: " + category.getId());
throw new ForbiddenException("You are not authorized to reorder subCategories in category with id: " + category.getId());
}
return null;
}
public void reorderChildren(Stakeholder defaultStakeholder, Category defaultCategory, List<String> defaultSubCategories) {
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
this.dao.findByDefaultId(defaultCategory.getId()).stream().map(category -> this.getFullCategory(stakeholder.getType(), stakeholder.getAlias(), category)).forEach(category -> {
this.reorderSubCategories(stakeholder, new Category(category),
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);
} else {
this.commonService.unauthorized("Delete category: You are not authorized to delete category with id: " + category.getId());
throw new ForbiddenException("Delete category: You are not authorized to delete category with id: " + category.getId());
}
}
@ -205,9 +205,8 @@ public class CategoryService {
category.update(this.save(new Category(category)));
return category;
} else {
this.commonService.unauthorized("Change category visibility: You are not authorized to update category with id: " + category.getId());
throw new ForbiddenException("Change category visibility: You are not authorized to update category with id: " + category.getId());
}
return null;
}
public CategoryFull changeVisibility(String type, String alias, Category category, Visibility visibility, Boolean propagate) {

View File

@ -1,8 +1,7 @@
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.uoamonitorservice.dto.TopicFull;
import eu.dnetlib.uoamonitorservice.generics.Common;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.beans.factory.annotation.Autowired;
@ -70,12 +69,4 @@ public class CommonService {
});
return ids;
}
public void unauthorized(String message) {
if(authorizationService.getAaiId() != null) {
throw new ForbiddenException(message);
} else {
throw new UnauthorizedException(message);
}
}
}

View File

@ -1,5 +1,6 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoamonitorservice.dao.*;
import eu.dnetlib.uoamonitorservice.entities.Indicator;
import eu.dnetlib.uoamonitorservice.entities.Section;
@ -81,7 +82,7 @@ public class IndicatorService {
this.updateChildren(indicator);
indicator = this.save(indicator);
} else {
this.commonService.unauthorized("You are not authorized to update stakeholder with id: " + stakeholder.getId());
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
}
} else {
if (this.commonService.hasCreateAuthority(stakeholder.getType())) {
@ -89,7 +90,7 @@ public class IndicatorService {
this.createChildren(section, indicator);
this.addIndicator(section, indicator.getId());
} else {
this.commonService.unauthorized("You are not authorized to create an indicator in stakeholder with id: " + stakeholder.getId());
throw new ForbiddenException("You are not authorized to create an indicator in stakeholder with id: " + stakeholder.getId());
}
}
return indicator;
@ -127,7 +128,7 @@ public class IndicatorService {
}
this.dao.delete(indicator);
} else {
this.commonService.unauthorized("Delete indicator: You are not authorized to delete indicator with id: " + indicator.getId());
throw new ForbiddenException("Delete indicator: You are not authorized to delete indicator with id: " + indicator.getId());
}
}
@ -156,8 +157,7 @@ public class IndicatorService {
indicator.setVisibility(visibility);
return this.save(indicator);
} else {
this.commonService.unauthorized("Change section visibility: You are not authorized to update section with id: " + indicator.getId());
throw new ForbiddenException("Change section visibility: You are not authorized to update section with id: " + indicator.getId());
}
return null;
}
}

View File

@ -1,5 +1,6 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoamonitorservice.dao.*;
import eu.dnetlib.uoamonitorservice.dto.SectionFull;
import eu.dnetlib.uoamonitorservice.entities.Section;
@ -102,7 +103,7 @@ public class SectionService {
this.createChildren(subCategory, new Section(section), -1);
});
} else {
this.commonService.unauthorized("You are not authorized to create sections in stakeholder with id: " + stakeholder.getId());
throw new ForbiddenException("You are not authorized to create sections in stakeholder with id: " + stakeholder.getId());
}
}
@ -114,7 +115,7 @@ public class SectionService {
this.updateChildren(section);
section = this.save(section);
} else {
this.commonService.unauthorized("You are not authorized to update stakeholder with id: " + stakeholder.getId());
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
}
} else {
if (this.commonService.hasCreateAuthority(stakeholder.getType())) {
@ -122,7 +123,7 @@ public class SectionService {
this.createChildren(subCategory, section, index);
this.addSection(subCategory, section.getId(), index);
} else {
this.commonService.unauthorized("You are not authorized to create a section in stakeholder with id: " + stakeholder.getId());
throw new ForbiddenException("You are not authorized to create a section in stakeholder with id: " + stakeholder.getId());
}
}
return this.getFullSection(stakeholder.getType(), stakeholder.getAlias(), section);
@ -167,13 +168,12 @@ public class SectionService {
throw new EntityNotFoundException("Some indicators dont exist in the section with id " + section.getId());
}
} else {
this.commonService.unauthorized("You are not authorized to reorder indicators in section with id: " + section.getId());
throw new ForbiddenException("You are not authorized to reorder indicators in section with id: " + section.getId());
}
return null;
}
public void reorderChildren(Stakeholder defaultStakeholder, Section defaultSection, List<String> defaultIndicators) {
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
this.dao.findByDefaultId(defaultSection.getId()).stream().map(section -> this.getFullSection(stakeholder.getType(), stakeholder.getAlias(), section)).forEach(section -> {
this.reorderIndicators(stakeholder, new Section(section),
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);
} else {
this.commonService.unauthorized("Delete section: You are not authorized to delete section with id: " + section.getId());
throw new ForbiddenException("Delete section: You are not authorized to delete section with id: " + section.getId());
}
}
@ -238,8 +238,7 @@ public class SectionService {
section.update(this.save(new Section(section)));
return section;
} else {
this.commonService.unauthorized("Change section visibility: You are not authorized to update section with id: " + section.getId());
throw new ForbiddenException("Change section visibility: You are not authorized to update section with id: " + section.getId());
}
return null;
}
}

View File

@ -1,42 +1,34 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
import eu.dnetlib.uoamonitorservice.dto.ManageStakeholders;
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
import eu.dnetlib.uoamonitorservice.dto.TopicFull;
import eu.dnetlib.uoamonitorservice.dto.UpdateUmbrella;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import eu.dnetlib.uoamonitorservice.generics.Common;
import eu.dnetlib.uoamonitorservice.handlers.BadRequestException;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class StakeholderService {
private final StakeholderDAO dao;
private final CommonService commonService;
private final TopicService topicService;
private final MongoTemplate mongoTemplate;
@Autowired
public StakeholderService(StakeholderDAO dao, CommonService commonService, TopicService topicService, MongoTemplate mongoTemplate) {
public StakeholderService(StakeholderDAO dao, CommonService commonService, TopicService topicService) {
this.dao = dao;
this.commonService = commonService;
this.topicService = topicService;
this.mongoTemplate = mongoTemplate;
}
public Stakeholder findByAlias(String alias) {
@ -44,91 +36,74 @@ public class StakeholderService {
}
public List<Stakeholder> findByDefaultId(String id) {
return this.dao.findByDefaultIdAndCopyIsTrue(id);
return this.dao.findByDefaultIdAndCopyTrue(id);
}
public Stakeholder findByPath(String stakeholderId) {
if (stakeholderId.equals("-1")) {
if(stakeholderId.equals("-1")) {
return null;
}
return dao.findById(stakeholderId).orElseThrow(() -> new EntityNotFoundException("Stakeholder with id: " + stakeholderId + " not found"));
}
public List<String> getAllAliases(String type) {
return this.getAll(type).stream().map(Stakeholder::getAlias).collect(Collectors.toList());
public List<String> getAllAliases() {
return this.dao.findAll().stream().map(Stakeholder::getAlias).collect(Collectors.toList());
}
public List<Stakeholder> getAll(String type) {
return this.dao.allStakeholders(StakeholderType.convert(type));
if (type != null) {
return this.dao.findByType(type);
}
return this.dao.findAll();
}
public List<Stakeholder> getAccessedStakeholders(List<Stakeholder> stakeholders, boolean isDefault) {
return stakeholders.stream()
.filter(stakeholder -> this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), isDefault))
public List<Stakeholder> getAllDefaultByRole(String type) {
return (type == null ? this.dao.findByDefaultIdIsNull() : this.dao.findByDefaultIdAndType(null, type)).stream()
.filter(stakeholder -> this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), true))
.collect(Collectors.toList());
}
public ManageStakeholders getManageStakeholders(String type) {
ManageStakeholders manageStakeholders = new ManageStakeholders();
StakeholderType stakeholderType = StakeholderType.convert(type);
manageStakeholders.setTemplates(this.getAccessedStakeholders(this.dao.defaultStakeholders(stakeholderType), true));
manageStakeholders.setStandalone(this.getAccessedStakeholders(this.dao.standaloneStakeholders(stakeholderType), false));
manageStakeholders.setDependent(this.getAccessedStakeholders(this.dao.dependentStakeholders(stakeholderType), false));
manageStakeholders.setUmbrella(this.getAccessedStakeholders(this.dao.umbrellaStakeholders(stakeholderType), false));
return manageStakeholders;
}
public List<Stakeholder> getVisibleStakeholders(String type, String defaultId) {
return this.dao.browseStakeholders(StakeholderType.convert(type), defaultId).stream().filter(stakeholder ->
stakeholder.getVisibility() == Visibility.PUBLIC ||
stakeholder.getVisibility() == Visibility.RESTRICTED ||
this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), false))
public List<Stakeholder> getStakeholdersByTypeAndRole(String type, String defaultId, boolean manage) {
List<Stakeholder> stakeholders;
if (type != null && defaultId != null) {
stakeholders = dao.findByDefaultIdAndType(defaultId, type);
} else if (defaultId != null) {
stakeholders = dao.findByDefaultIdAndCopyTrue(defaultId);
} else if (type != null) {
stakeholders = dao.findByDefaultIdIsNotNullAndType(type);
} else {
stakeholders = dao.findByDefaultIdIsNotNull();
}
return stakeholders.stream().filter(stakeholder ->
(!manage && (stakeholder.getVisibility() == Visibility.PUBLIC || stakeholder.getVisibility() == Visibility.RESTRICTED))
|| this.commonService.hasAccessAuthority(stakeholder.getType(), stakeholder.getAlias(), false))
.collect(Collectors.toList());
}
public StakeholderFull getFullStakeholder(Stakeholder stakeholder) {
List<TopicFull> topics = stakeholder.getTopics().stream()
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
.collect(Collectors.toList());
if (!stakeholder.isCopy() && stakeholder.getDefaultId() != null) {
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
if (defaultStakeholder != null) {
topics = defaultStakeholder.getTopics().stream()
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
.collect(Collectors.toList());
if (this.commonService.hasVisibilityAuthority(stakeholder.getType(), stakeholder.getAlias(), stakeholder)) {
if(!stakeholder.isCopy() && stakeholder.getDefaultId() != null) {
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
if(defaultStakeholder != null) {
return new StakeholderFull(stakeholder,
defaultStakeholder.getTopics().stream()
.map(topicId -> topicService.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topicId))
.collect(Collectors.toList()));
}
}
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) {
if (stakeholder.getDefaultId() == null) {
if(stakeholder.getDefaultId() == null) {
stakeholder.setCopy(false);
if (copyId == null) {
if(copyId == null) {
stakeholder.setTopics(new ArrayList<>());
} else {
Stakeholder copyFrom = this.findByPath(copyId);
@ -136,9 +111,9 @@ public class StakeholderService {
}
} else {
stakeholder.setTopics(new ArrayList<>());
if (stakeholder.isCopy()) {
if(stakeholder.isCopy()) {
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
if (defaultStakeholder != null) {
if(defaultStakeholder != null) {
stakeholder.setTopics(defaultStakeholder.getTopics().stream().map(this.topicService::build).collect(Collectors.toList()));
}
}
@ -148,19 +123,17 @@ public class StakeholderService {
public Stakeholder save(Stakeholder stakeholder) {
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) {
stakeholder.getTopics().forEach(topic -> {
this.topicService.delete(stakeholder.getType(), topic, false);
});
stakeholder.setTopics(new ArrayList<>());
} else {
if (old.getTopics().isEmpty() && old.getDefaultId() != null) {
Stakeholder old = this.findByPath(stakeholder.getId());
stakeholder.setTopics(old.getTopics());
if(old.getTopics().isEmpty() && old.getDefaultId() != null) {
Stakeholder defaultStakeholder = this.findByPath(stakeholder.getDefaultId());
if (defaultStakeholder != null) {
if(defaultStakeholder != null) {
stakeholder.setTopics(defaultStakeholder.getTopics().stream().map(this.topicService::build).collect(Collectors.toList()));
}
}
@ -185,14 +158,13 @@ public class StakeholderService {
throw new EntityNotFoundException("Some topics dont exist in the stakeholder with id " + stakeholder.getId());
}
} else {
this.commonService.unauthorized("You are not authorized to reorder topics in stakeholder with id: " + stakeholder.getId());
throw new ForbiddenException("You are not authorized to reorder topics in stakeholder with id: " + stakeholder.getId());
}
return null;
}
public void reorderChildren(Stakeholder defaultStakeholder, List<String> defaultTopics) {
this.dao.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).stream().map(this::getFullStakeholder).forEach(stakeholder -> {
this.reorderTopics(new Stakeholder(stakeholder, this),
this.dao.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).stream().map(this::getFullStakeholder).forEach(stakeholder -> {
this.reorderTopics(new Stakeholder(stakeholder),
this.commonService.reorder(defaultTopics, stakeholder.getTopics().stream().map(topic -> (Common) topic).collect(Collectors.toList())));
});
}
@ -200,14 +172,7 @@ public class StakeholderService {
public String delete(String id) {
Stakeholder stakeholder = this.findByPath(id);
if (this.commonService.hasDeleteAuthority(stakeholder.getType())) {
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.dao.findByDefaultIdAndCopyTrue(stakeholder.getId()).forEach(child -> {
this.delete(child.getId());
});
stakeholder.getTopics().forEach(topicId -> {
@ -216,9 +181,8 @@ public class StakeholderService {
this.dao.delete(id);
return stakeholder.getAlias();
} else {
this.commonService.unauthorized("Delete stakeholder: You are not authorized to delete stakeholder with id: " + id);
throw new ForbiddenException("Delete stakeholder: You are not authorized to delete stakeholder with id: " + id);
}
return null;
}
public StakeholderFull changeVisibility(StakeholderFull stakeholder, Visibility visibility, Boolean propagate) {
@ -229,111 +193,15 @@ public class StakeholderService {
.collect(Collectors.toList()));
}
stakeholder.setVisibility(visibility);
stakeholder.update(this.save(new Stakeholder(stakeholder, this)));
stakeholder.update(this.save(new Stakeholder(stakeholder)));
return stakeholder;
} else {
this.commonService.unauthorized("Change stakeholder visibility: You are not authorized to update stakeholder with id: " + stakeholder.getId());
throw new ForbiddenException("Change stakeholder visibility: You are not authorized to update stakeholder with id: " + stakeholder.getId());
}
return null;
}
public StakeholderFull changeVisibility(Stakeholder stakeholder, Visibility visibility, Boolean propagate) {
StakeholderFull stakeholderFull = this.getFullStakeholder(stakeholder);
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);
}
}

View File

@ -1,5 +1,6 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoamonitorservice.dao.CategoryDAO;
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
import eu.dnetlib.uoamonitorservice.dao.SubCategoryDAO;
@ -111,7 +112,7 @@ public class SubCategoryService {
this.updateChildren(subCategory);
subCategory = this.save(subCategory);
} else {
this.commonService.unauthorized("You are not authorized to update stakeholder with id: " + stakeholder.getId());
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
}
} else {
if (this.commonService.hasCreateAuthority(stakeholder.getType())) {
@ -119,7 +120,7 @@ public class SubCategoryService {
this.createChildren(category, subCategory);
this.addSubCategory(category, subCategory.getId());
} else {
this.commonService.unauthorized("You are not authorized to create a subCategory in stakeholder with id: " + stakeholder.getId());
throw new ForbiddenException("You are not authorized to create a subCategory in stakeholder with id: " + stakeholder.getId());
}
}
return this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory);
@ -152,13 +153,12 @@ public class SubCategoryService {
this.moveIndicatorChildren(stakeholder, subCategory, moveIndicator);
return this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory);
} else {
this.commonService.unauthorized("You are not authorized to move indicators in subCategory with id: " + subCategory.getId());
throw new ForbiddenException("You are not authorized to move indicators in subCategory with id: " + subCategory.getId());
}
return null;
}
public void moveIndicatorChildren(Stakeholder defaultStakeholder, SubCategory defaultSubCategory, MoveIndicator moveIndicator) {
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
this.dao.findByDefaultId(defaultSubCategory.getId()).stream()
.map(subCategory -> this.getFullSubCategory(stakeholder.getType(), stakeholder. getAlias(), subCategory))
.collect(Collectors.toList()).forEach(subCategory -> {
@ -191,9 +191,8 @@ public class SubCategoryService {
throw new EntityNotFoundException("Some sections dont exist in the subCategory with id " + subCategory.getId());
}
} else {
this.commonService.unauthorized("You are not authorized to reorder sections in subCategory with id: " + subCategory.getId());
throw new ForbiddenException("You are not authorized to reorder sections in subCategory with id: " + subCategory.getId());
}
return null;
}
public SubCategoryFull reorderCharts(Stakeholder stakeholder, SubCategory subCategory, List<String> charts) {
@ -207,13 +206,12 @@ public class SubCategoryService {
throw new EntityNotFoundException("Some sections dont exist in the subCategory with id " + subCategory.getId());
}
} else {
this.commonService.unauthorized("You are not authorized to reorder sections in subCategory with id: " + subCategory.getId());
throw new ForbiddenException("You are not authorized to reorder sections in subCategory with id: " + subCategory.getId());
}
return null;
}
public void reorderChildrenNumbers(Stakeholder defaultStakeholder, SubCategory defaultSubCategory, List<String> defaultSections) {
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
this.dao.findByDefaultId(defaultSubCategory.getId()).stream().map(subCategory -> this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory)).forEach(subCategory -> {
this.reorderNumbers(stakeholder, new SubCategory(subCategory),
this.commonService.reorder(defaultSections, subCategory.getNumbers().stream().map(section -> (Common) section).collect(Collectors.toList())));
@ -222,7 +220,7 @@ public class SubCategoryService {
}
public void reorderChildrenCharts(Stakeholder defaultStakeholder, SubCategory defaultSubCategory, List<String> defaultSections) {
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
this.dao.findByDefaultId(defaultSubCategory.getId()).stream().map(subCategory -> this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), subCategory)).forEach(subCategory -> {
this.reorderCharts(stakeholder, new SubCategory(subCategory),
this.commonService.reorder(defaultSections, subCategory.getCharts().stream().map(section -> (Common) section).collect(Collectors.toList())));
@ -247,7 +245,7 @@ public class SubCategoryService {
}
this.dao.delete(subCategory);
} else {
this.commonService.unauthorized("Delete subCategory: You are not authorized to delete subCategory with id: " + subCategory.getId());
throw new ForbiddenException("Delete subCategory: You are not authorized to delete subCategory with id: " + subCategory.getId());
}
}
@ -284,9 +282,8 @@ public class SubCategoryService {
subCategory.update(this.save(new SubCategory(subCategory)));
return subCategory;
} else {
this.commonService.unauthorized("Change subCategory visibility: You are not authorized to update subCategory with id: " + subCategory.getId());
throw new ForbiddenException("Change subCategory visibility: You are not authorized to update subCategory with id: " + subCategory.getId());
}
return null;
}
public SubCategoryFull changeVisibility(String type, String alias, SubCategory subCategory, Visibility visibility, Boolean propagate) {

View File

@ -1,5 +1,6 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException;
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
import eu.dnetlib.uoamonitorservice.dao.TopicDAO;
import eu.dnetlib.uoamonitorservice.dto.TopicFull;
@ -93,7 +94,7 @@ public class TopicService {
this.updateChildren(topic);
topic = this.save(topic);
} else {
this.commonService.unauthorized("You are not authorized to update stakeholder with id: " + stakeholder.getId());
throw new ForbiddenException("You are not authorized to update stakeholder with id: " + stakeholder.getId());
}
} else {
if(this.commonService.hasCreateAuthority(stakeholder.getType())) {
@ -101,14 +102,14 @@ public class TopicService {
this.createChildren(stakeholder, topic);
this.addTopic(stakeholder, topic.getId());
} else {
this.commonService.unauthorized("You are not authorized to create a topic in stakeholder with id: " + stakeholder.getId());
throw new ForbiddenException("You are not authorized to create a topic in stakeholder with id: " + stakeholder.getId());
}
}
return this.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topic);
}
public void createChildren(Stakeholder defaultStakeholder, Topic topic) {
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
this.save(stakeholder, topic.copy());
});
}
@ -131,13 +132,12 @@ public class TopicService {
throw new EntityNotFoundException("Some categories dont exist in the topic with id " + topic.getId());
}
} else {
this.commonService.unauthorized("You are not authorized to reorder categories in topic with id: " + topic.getId());
throw new ForbiddenException("You are not authorized to reorder categories in topic with id: " + topic.getId());
}
return null;
}
public void reorderChildren(Stakeholder defaultStakeholder, Topic defaultTopic, List<String> defaultCategories) {
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
this.stakeholderDAO.findByDefaultIdAndCopyTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
this.dao.findByDefaultId(defaultTopic.getId()).stream().map(topic -> this.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), topic)).forEach(topic -> {
this.reorderCategories(stakeholder, new Topic(topic),
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);
} else {
this.commonService.unauthorized("Delete topic: You are not authorized to delete topic with id: " + topic.getId());
throw new ForbiddenException("Delete topic: You are not authorized to delete topic with id: " + topic.getId());
}
}
@ -192,9 +192,8 @@ public class TopicService {
topic.update(this.save(new Topic(topic)));
return topic;
} else {
this.commonService.unauthorized("Change topic visibility: You are not authorized to update topic with id: " + topic.getId());
throw new ForbiddenException("Change topic visibility: You are not authorized to update topic with id: " + topic.getId());
}
return null;
}
public TopicFull changeVisibility(String type, String alias, Topic topic, Visibility visibility, Boolean propagate) {