Merge remote-tracking branch 'origin/spring-boot3' into indicatorPathGroups

This commit is contained in:
Konstantinos Triantafyllou 2024-10-16 23:41:41 +03:00
commit 976a11b81c
41 changed files with 351 additions and 664 deletions

30
README.md Normal file
View File

@ -0,0 +1,30 @@
# UOA Monitor Service
This service provides method in order to create templates and profiles for Monitor Dashboards.
Also includes notifications, admin-tools and stateless authorization.
## Configuration
- Check [Notification Service](https://code-repo.d4science.org/MaDgIK/uoa-notification-service)
- Check [Admin Tools Library](https://code-repo.d4science.org/MaDgIK/uoa-admin-tools-library)
### Mongo Configuration
monitor-service.mongodb.host # Required - Host of mongo server - Default: localhost
monitor-service.mongodb.database # Required - Database name
monitor-service.mongodb.username # Optional - Username if needed
monitor-service.mongodb.password # Optional - Password if needed
monitor-service.mongodb.port # Required - Mongo server port - Default: 27017
## Usage as dependency
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>uoa-monitor-service</artifactId>
<version>2.0.0</version>
<classifier>library</classifier>
</dependency>
## Run
Check [Spring boot Documentation](https://code-repo.d4science.org/MaDgIK/Documentation/wiki/Spring-boot) (need Login)

61
pom.xml
View File

@ -1,20 +1,19 @@
<?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">
<parent>
<groupId>eu.dnetlib</groupId>
<artifactId>uoa-spring-boot-parent</artifactId>
<version>2.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>uoa-monitor-service</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>2.0.1-SNAPSHOT</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>
<parent>
<groupId>eu.dnetlib</groupId>
<artifactId>uoa-spring-boot-parent</artifactId>
<version>1.0.0</version>
</parent>
<tag>HEAD</tag>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
@ -26,59 +25,30 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<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>2.0.1</version>
</dependency>
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>uoa-notification-service</artifactId>
<version>1.0.7</version>
</dependency>
<!--swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger-version}</version>
</dependency>
<!--swagger official ui-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger-version}</version>
<version>2.0.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-version}</version>
<configuration>
<mainClass>eu.dnetlib.uoamonitorservice.application.UoaMonitorServiceApplication</mainClass>
<executable>true</executable>
</configuration>
<executions>
<execution>
<id>default-war</id>
<phase>package</phase>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -94,20 +64,15 @@
<classifier>library</classifier>
<excludes>
<exclude>**/eu/dnetlib/uoamonitorservice/application/**</exclude>
<exclude>**/eu/dnetlib/uoamonitorservice/configuration/SwaggerConfig.class</exclude>
<exclude>**/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.class</exclude>
</excludes>
<classesDirectory />
<outputDirectory />
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<finalName>uoa-monitor-service</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>

View File

@ -2,27 +2,14 @@ package eu.dnetlib.uoamonitorservice;
import eu.dnetlib.uoaadmintoolslibrary.UoaAdminToolsLibraryConfiguration;
import eu.dnetlib.uoamonitorservice.configuration.GlobalVars;
import eu.dnetlib.uoamonitorservice.configuration.properties.APIProperties;
import eu.dnetlib.uoamonitorservice.configuration.properties.MongoConfig;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
@EnableConfigurationProperties({ MongoConfig.class, GlobalVars.class, APIProperties.class})
@ComponentScan(basePackages = { "eu.dnetlib.uoamonitorservice" })
@EnableConfigurationProperties({MongoConfig.class, GlobalVars.class})
@ComponentScan(basePackages = {"eu.dnetlib.uoamonitorservice"})
@Import({UoaAdminToolsLibraryConfiguration.class})
public class UoaMonitorServiceConfiguration extends WebMvcConfigurerAdapter {
private final Logger log = LogManager.getLogger(this.getClass());
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
public class UoaMonitorServiceConfiguration { }

View File

@ -1,8 +1,7 @@
package eu.dnetlib.uoamonitorservice.application;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
//import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {

View File

@ -1,6 +1,6 @@
package eu.dnetlib.uoamonitorservice.application;
import eu.dnetlib.uoaauthorizationlibrary.configuration.AuthorizationConfiguration;
import eu.dnetlib.uoaauthorizationlibrary.SecurityConfiguration;
import eu.dnetlib.uoanotificationservice.configuration.NotificationConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -19,7 +19,7 @@ import org.springframework.context.annotation.PropertySources;
})
@Import({
NotificationConfiguration.class,
AuthorizationConfiguration.class
SecurityConfiguration.class,
})
public class UoaMonitorServiceApplication {
public static void main(String[] args) {

View File

@ -4,7 +4,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.Date;
@ConfigurationProperties("monitorservice.globalVars")
@ConfigurationProperties("monitor-service.global-vars")
public class GlobalVars {
public static Date date = new Date();
private Date buildDate;

View File

@ -1,118 +0,0 @@
package eu.dnetlib.uoamonitorservice.configuration;
import eu.dnetlib.uoamonitorservice.configuration.properties.APIProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.Collections;
import java.util.List;
/**
* Swagger configuration class
*/
@Configuration
@Profile({"swagger"})
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurerAdapter {
private final APIProperties apiProperties;
@Autowired
public SwaggerConfig(APIProperties apiProperties) {
this.apiProperties = apiProperties;
}
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("eu.dnetlib.uoamonitorservice.controllers"))
.paths(PathSelectors.any())
.build();
}
@Bean
public Docket createRestApiLibrary() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.groupName("Library")
.select()
.apis(RequestHandlerSelectors.basePackage("eu.dnetlib.uoaadmintoolslibrary.controllers"))
.paths(PathSelectors.any())
.build();
}
@Bean
public Docket createRestApiAuthorizationLibrary() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.groupName("Authorization Library")
.select()
.apis(RequestHandlerSelectors.basePackage("eu.dnetlib.uoaauthorizationlibrary.controllers"))
.paths(PathSelectors.any())
.build();
}
@Bean
public Docket createRestApiNotificationLibrary() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.groupName("Notification Service")
.select()
.apis(RequestHandlerSelectors.basePackage("eu.dnetlib.uoanotificationservice.controllers"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title(this.apiProperties.getTitle())
.description(this.apiProperties.getDescription())
.version(this.apiProperties.getVersion())
.build();
}
private List<Parameter> globalParameterList() {
Parameter authTokenHeader = new ParameterBuilder()
.name("Session") // name of the header
.modelRef(new ModelRef("string")) // data-type of the header
.required(false)
.parameterType("header")
.description("Session ID")
.build();
return Collections.singletonList(authTokenHeader);
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addRedirectViewController("/v2/api-docs", "/v2/api-docs");
registry.addRedirectViewController("/swagger-resources/configuration/ui", "/swagger-resources/configuration/ui");
registry.addRedirectViewController("/swagger-resources/configuration/security", "/swagger-resources/configuration/security");
registry.addRedirectViewController("/swagger-resources", "/swagger-resources");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/swagger-ui.html**").addResourceLocations("classpath:/META-INF/resources/swagger-ui.html");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}

View File

@ -1,45 +1,48 @@
package eu.dnetlib.uoamonitorservice.configuration.mongo;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientSettings;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import eu.dnetlib.uoamonitorservice.configuration.properties.MongoConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import java.util.Collections;
@Configuration
@EnableMongoRepositories(basePackages = {"eu.dnetlib.uoamonitorservice.dao", "eu.dnetlib.uoaadmintoolslibrary.dao"})
public class MongoConnection {
@Autowired
private MongoConfig mongoConfig;
private final MongoConfig mongoConfig;
@Bean
@Primary
public MongoDbFactory mongoDbFactory() {
return new SimpleMongoDbFactory(getMongoClient(), mongoConfig.getDatabase());
@Autowired
public MongoConnection(MongoConfig mongoConfig) {
this.mongoConfig = mongoConfig;
}
@Bean(name = "mongoTemplate")
@Primary
public MongoTemplate getMongoTemplate() {
return new MongoTemplate(mongoDbFactory());
return new MongoTemplate(getMongoClient(), mongoConfig.getDatabase());
}
private MongoClient getMongoClient() {
if(mongoConfig.getUsername() != null && mongoConfig.getPassword() != null){
return new MongoClient(Collections.singletonList(
new ServerAddress(mongoConfig.getHost(), mongoConfig.getPort())),
Collections.singletonList(MongoCredential.createCredential(mongoConfig.getUsername(), mongoConfig.getDatabase(), mongoConfig.getPassword().toCharArray())));
} else {
return new MongoClient(Collections.singletonList(new ServerAddress(mongoConfig.getHost(), mongoConfig.getPort())));
MongoClientSettings.Builder builder = MongoClientSettings.builder()
.applyToClusterSettings(b -> b.hosts(Collections.singletonList(new ServerAddress(mongoConfig.getHost(), mongoConfig.getPort()))));
if(mongoConfig.getUsername() != null && mongoConfig.getPassword() != null) {
MongoCredential credential = MongoCredential.createCredential(
mongoConfig.getUsername(),
mongoConfig.getDatabase(),
mongoConfig.getPassword().toCharArray()
);
builder.credential(credential);
}
return MongoClients.create(builder.build());
}
}

View File

@ -1,38 +0,0 @@
package eu.dnetlib.uoamonitorservice.configuration.properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties("api")
public class APIProperties {
private String title;
private String description;
private String version;
public APIProperties() {
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
}

View File

@ -2,14 +2,14 @@ package eu.dnetlib.uoamonitorservice.configuration.properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties("monitorservice.mongodb")
@ConfigurationProperties("monitor-service.mongodb")
public class MongoConfig {
private String host;
private String host = "localhost";
private String database;
private String username;
private String password;
private int port;
private int port = 27017;
public String getHost() {

View File

@ -11,13 +11,13 @@ import eu.dnetlib.uoamonitorservice.service.TopicService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin(origins = "*")
public class CategoryController {
private final Logger log = LogManager.getLogger(this.getClass());
@ -34,9 +34,9 @@ public class CategoryController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/save", method = RequestMethod.POST)
public CategoryFull saveCategory(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@RequestBody CategoryFull categoryFull) {
public ResponseEntity<CategoryFull> saveCategory(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@RequestBody CategoryFull categoryFull) {
log.debug("save category");
log.debug("Alias: " + categoryFull.getAlias() + " - Id: " + categoryFull.getId() + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId);
Stakeholder stakeholder = stakeholderService.findByPath(stakeholderId);
@ -44,48 +44,48 @@ public class CategoryController {
if(categoryFull.getId() != null) {
this.categoryService.findByPath(topic, categoryFull.getId());
}
return this.categoryService.save(stakeholder, topic, new Category(categoryFull));
return ResponseEntity.ok(this.categoryService.save(stakeholder, topic, new Category(categoryFull)));
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/delete", method = RequestMethod.DELETE)
public boolean deleteCategory(@PathVariable("stakeholderId") String stakeholderId,
public ResponseEntity<Boolean> deleteCategory(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@RequestParam(required = false) String children) {
@RequestParam(required = false, name = "children") String children) {
log.debug("delete category");
log.debug("Id: " + categoryId + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId);
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
Topic topic = this.topicService.findByPath(stakeholder, topicId);
Category category = this.categoryService.findByPath(topic, categoryId);
this.categoryService.delete(stakeholder.getType(), category, true);
return true;
return ResponseEntity.ok(true);
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/reorder", method = RequestMethod.POST)
public List<CategoryFull> reorderCategories(@PathVariable("stakeholderId") String stakeholderId,
public ResponseEntity<List<CategoryFull>> reorderCategories(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@RequestBody List<String> categories) {
log.debug("reorder categories");
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId);
Stakeholder stakeholder = stakeholderService.findByPath(stakeholderId);
Topic topic = topicService.findByPath(stakeholder, topicId);
return this.topicService.reorderCategories(stakeholder, topic, categories).getCategories();
return ResponseEntity.ok(this.topicService.reorderCategories(stakeholder, topic, categories).getCategories());
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/change-visibility", method = RequestMethod.POST)
public CategoryFull changeCategoryVisibility(@PathVariable("stakeholderId") String stakeholderId,
public ResponseEntity<CategoryFull> changeCategoryVisibility(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@RequestParam("visibility") Visibility visibility, @RequestParam(defaultValue = "false") Boolean propagate) {
@RequestParam("visibility") Visibility visibility, @RequestParam(defaultValue = "false", name = "propagate") Boolean propagate) {
log.debug("change category visibility: " + visibility + " - toggle propagate: " + propagate);
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId);
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
Topic topic = this.topicService.findByPath(stakeholder, topicId);
Category category = this.categoryService.findByPath(topic, categoryId);
return this.categoryService.changeVisibility(stakeholder.getType(), stakeholder.getAlias(), category, visibility, propagate);
return ResponseEntity.ok(this.categoryService.changeVisibility(stakeholder.getType(), stakeholder.getAlias(), category, visibility, propagate));
}
}

View File

@ -1,13 +1,13 @@
package eu.dnetlib.uoamonitorservice.controllers;
import eu.dnetlib.uoaadmintoolslibrary.emailSender.EmailSender;
import eu.dnetlib.uoaadmintoolslibrary.entities.email.Email;
import eu.dnetlib.uoaadmintoolslibrary.entities.email.EmailRecaptcha;
import eu.dnetlib.uoaadmintoolslibrary.handlers.InvalidReCaptchaException;
import eu.dnetlib.uoaadmintoolslibrary.recaptcha.VerifyRecaptcha;
import eu.dnetlib.uoaadmintoolslibrary.exceptions.InvalidReCaptchaException;
import eu.dnetlib.uoaadmintoolslibrary.services.EmailService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
@ -16,29 +16,25 @@ import java.util.Map;
import java.util.Optional;
@RestController
@CrossOrigin(origins = "*")
public class EmailController {
private final Logger log = LogManager.getLogger(this.getClass());
private final EmailSender emailSender;
private final VerifyRecaptcha verifyRecaptcha;
private final EmailService service;
@Autowired
public EmailController(EmailSender emailSender, VerifyRecaptcha verifyRecaptcha) {
this.emailSender = emailSender;
this.verifyRecaptcha = verifyRecaptcha;
public EmailController(EmailService service) {
this.service = service;
}
@RequestMapping(value = "/contact", method = RequestMethod.POST)
public Boolean contact(@RequestBody EmailRecaptcha form) throws InvalidReCaptchaException {
verifyRecaptcha.processResponse(form.getRecaptcha());
public ResponseEntity<Boolean> contact(@RequestBody EmailRecaptcha form) throws InvalidReCaptchaException {
this.service.processResponse(form.getRecaptcha());
Email email = form.getEmail();
return emailSender.send(email.getRecipients(), email.getSubject(), email.getBody(), false);
return ResponseEntity.ok(this.service.send(email.getRecipients(), email.getSubject(), email.getBody(), false));
}
@RequestMapping(value = "/sendMail", method = RequestMethod.POST)
public Map<String, ArrayList<String>> sendEmail(@RequestBody Email email,
@RequestParam(required = false) Optional<Boolean> optional) {
public ResponseEntity<Map<String, ArrayList<String>>> sendEmail(@RequestBody Email email,
@RequestParam(required = false, name = "optional") Optional<Boolean> optional) {
String successString = "success";
String failureString = "failure";
Map<String, ArrayList<String>> mailResults = new HashMap<>();
@ -46,7 +42,7 @@ public class EmailController {
for (String userMail : email.getRecipients()) {
ArrayList<String> sendTo = new ArrayList<>();
sendTo.add(userMail);
boolean success = emailSender.send(sendTo, email.getSubject(), email.getBody(), bcc);
boolean success = this.service.send(sendTo, email.getSubject(), email.getBody(), bcc);
if (success) {
if (!mailResults.containsKey(successString)) {
mailResults.put(successString, new ArrayList<>());
@ -59,8 +55,7 @@ public class EmailController {
mailResults.get(failureString).add(userMail);
}
}
return mailResults;
return ResponseEntity.ok(mailResults);
}
}

View File

@ -9,6 +9,7 @@ import eu.dnetlib.uoamonitorservice.service.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -16,7 +17,6 @@ import java.io.UnsupportedEncodingException;
import java.util.List;
@RestController
@CrossOrigin(origins = "*")
public class IndicatorController {
private final Logger log = LogManager.getLogger(this.getClass());
@ -40,11 +40,11 @@ public class IndicatorController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/save-bulk", method = RequestMethod.POST)
public StakeholderFull saveBulkIndicators(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@RequestBody List<SectionFull> sections) throws UnsupportedEncodingException {
public ResponseEntity<StakeholderFull> saveBulkIndicators(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@RequestBody List<SectionFull> sections) throws UnsupportedEncodingException {
log.debug("save bulk indicators");
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId);
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
@ -52,12 +52,12 @@ public class IndicatorController {
Category category = this.categoryService.findByPath(topic, categoryId);
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
this.sectionService.saveBulk(stakeholder, subCategory, sections);
return this.stakeholderService.getFullStakeholder(stakeholder);
return ResponseEntity.ok(this.stakeholderService.getFullStakeholder(stakeholder));
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/save", method = RequestMethod.POST)
public Indicator saveIndicator(@PathVariable("stakeholderId") String stakeholderId,
public ResponseEntity<Indicator> saveIndicator(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@ -73,18 +73,18 @@ public class IndicatorController {
if(indicator.getId() != null) {
this.indicatorService.findByPath(section, indicator.getId());
}
return this.indicatorService.save(stakeholder, section, indicator);
return ResponseEntity.ok(this.indicatorService.save(stakeholder, section, indicator));
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/delete", method = RequestMethod.DELETE)
public boolean deleteIndicator(@PathVariable("stakeholderId") String stakeholderId,
public ResponseEntity<Boolean> deleteIndicator(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@PathVariable("sectionId") String sectionId,
@PathVariable("indicatorId") String indicatorId,
@RequestParam(required = false) String children) {
@RequestParam(required = false, name = "children") String children) {
log.debug("delete indicator");
log.debug("Id: " + indicatorId + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId + " - Section: " + sectionId);
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
@ -94,13 +94,13 @@ public class IndicatorController {
Section section = this.sectionService.findByPath(subCategory, sectionId);
Indicator indicator = this.indicatorService.findByPath(section, indicatorId);
this.indicatorService.delete(stakeholder.getType(), indicator, true);
return true;
return ResponseEntity.ok(true);
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/reorder", method = RequestMethod.POST)
public List<Indicator> reorderIndicators(@PathVariable("stakeholderId") String stakeholderId,
public ResponseEntity<List<Indicator>> reorderIndicators(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@ -112,12 +112,12 @@ public class IndicatorController {
Category category = this.categoryService.findByPath(topic, categoryId);
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
Section section = this.sectionService.findByPath(subCategory, sectionId);
return this.sectionService.reorderIndicators(stakeholder, section, indicators).getIndicators();
return ResponseEntity.ok(this.sectionService.reorderIndicators(stakeholder, section, indicators).getIndicators());
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/{indicatorId}/change-visibility", method = RequestMethod.POST)
public Indicator changeIndicatorVisibility(@PathVariable("stakeholderId") String stakeholderId,
public ResponseEntity<Indicator> changeIndicatorVisibility(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@ -132,6 +132,6 @@ public class IndicatorController {
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
Section section = this.sectionService.findByPath(subCategory, sectionId);
Indicator indicator = this.indicatorService.findByPath(section, indicatorId);
return this.indicatorService.changeVisibility(stakeholder.getType(), stakeholder.getAlias(), indicator, visibility);
return ResponseEntity.ok(this.indicatorService.changeVisibility(stakeholder.getType(), stakeholder.getAlias(), indicator, visibility));
}
}

View File

@ -6,47 +6,38 @@ import eu.dnetlib.uoaadmintoolslibrary.services.PageService;
import eu.dnetlib.uoaadmintoolslibrary.services.PortalService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.*;
@RestController
@RequestMapping(value={"/monitor", "/funder", "/project", "/ri", "/organization"})
@CrossOrigin(origins = "*")
@RequestMapping(value={"/monitor", "/funder", "/project", "/ri", "/organization", "country", "researcher", "datasource", "publisher", "journal"})
public class MonitorController {
private final Logger log = LogManager.getLogger(this.getClass());
@Autowired
private PortalService portalService;
private final PortalService portalService;
@Autowired
private PageService pageService;
public MonitorController(PortalService portalService) {
this.portalService = portalService;
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
public PortalResponse updatePortal(@RequestBody Portal portal) {
String old_pid = portalService.getPortalById(portal.getId()).getPid();
String new_pid = portal.getPid();
PortalResponse portalResponse = portalService.updatePortal(portal);
if (!old_pid.equals(new_pid)) {
pageService.updatePid(old_pid, new_pid, portal.getType());
}
return portalResponse;
public ResponseEntity<PortalResponse> updatePortal(@RequestBody Portal portal) {
return ResponseEntity.ok(portalService.updatePortal(portal));
}
@RequestMapping(value = "/save", method = RequestMethod.POST)
public PortalResponse insertPortal(@RequestBody Portal portal) {
PortalResponse portalResponse = portalService.insertPortal(portal);
return portalResponse;
public ResponseEntity<PortalResponse> insertPortal(@RequestBody Portal portal) {
return ResponseEntity.ok(portalService.insertPortal(portal));
}
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public Boolean deletePortals(@RequestBody List<String> portals) {
portals.forEach(id -> portalService.deletePortal(id));
return true;
public ResponseEntity<Boolean> deletePortals(@RequestBody List<String> portals) {
portals.forEach(portalService::deletePortal);
return ResponseEntity.ok(true);
}
}

View File

@ -3,8 +3,8 @@ package eu.dnetlib.uoamonitorservice.controllers;
import eu.dnetlib.uoamonitorservice.service.MonitorDeployService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.http.ResponseEntity;
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;
@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/monitor-library")
public class MonitorLibraryCheckDeployController {
private final Logger log = LogManager.getLogger(this.getClass());
@ -23,15 +22,15 @@ public class MonitorLibraryCheckDeployController {
this.service = service;
}
@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET)
public String hello() {
@RequestMapping(value = {"", "/", "/health_check"}, method = RequestMethod.GET)
public ResponseEntity<String> hello() {
log.debug("Hello from uoa-monitor-service library!");
return "Hello from uoa-monitor-service library!";
return ResponseEntity.ok("Hello from uoa-monitor-service library!");
}
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET)
public Map<String, String> checkEverything() {
return this.service.checkEverything();
public ResponseEntity<Map<String, String>> checkEverything() {
return ResponseEntity.ok(this.service.getProperties());
}
}

View File

@ -3,8 +3,8 @@ package eu.dnetlib.uoamonitorservice.controllers;
import eu.dnetlib.uoamonitorservice.service.MonitorDeployService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.http.ResponseEntity;
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;
@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
@CrossOrigin(origins = "*")
public class MonitorServiceCheckDeployController {
private final Logger log = LogManager.getLogger(this.getClass());
@ -22,15 +21,15 @@ public class MonitorServiceCheckDeployController {
this.service = service;
}
@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET)
public String hello() {
@RequestMapping(value = {"", "/", "/health_check"}, method = RequestMethod.GET)
public ResponseEntity<String> hello() {
log.debug("Hello from uoa-monitor-service!");
return "Hello from uoa-monitor-service!";
return ResponseEntity.ok("Hello from uoa-monitor-service!");
}
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET)
public Map<String, String> checkEverything() {
return this.service.checkEverything();
public ResponseEntity<Map<String, String>> checkEverything() {
return ResponseEntity.ok(this.service.getProperties());
}
}

View File

@ -9,13 +9,13 @@ import eu.dnetlib.uoamonitorservice.service.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin(origins = "*")
public class SectionController {
private final Logger log = LogManager.getLogger(this.getClass());
@ -37,12 +37,12 @@ public class SectionController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/save/{index}", method = RequestMethod.POST)
public SectionFull saveSection(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@PathVariable("index") String index,
@RequestBody SectionFull sectionFull) {
public ResponseEntity<SectionFull> saveSection(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@PathVariable("index") String index,
@RequestBody SectionFull sectionFull) {
log.debug("save section");
log.debug("Name: " + sectionFull.getTitle() + " - Id: " + sectionFull.getId() + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId);
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
@ -52,17 +52,17 @@ public class SectionController {
if(sectionFull.getId() != null) {
this.sectionService.findByPath(subCategory, sectionFull.getId());
}
return this.sectionService.save(stakeholder, subCategory, new Section(sectionFull), Integer.parseInt(index));
return ResponseEntity.ok(this.sectionService.save(stakeholder, subCategory, new Section(sectionFull), Integer.parseInt(index)));
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/{sectionId}/delete", method = RequestMethod.DELETE)
public boolean deleteSection(@PathVariable("stakeholderId") String stakeholderId,
public ResponseEntity<Boolean> deleteSection(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@PathVariable("sectionId") String sectionId,
@RequestParam(required = false) String children) {
@RequestParam(required = false, name = "children") String children) {
log.debug("delete section");
log.debug("Id: " + sectionId + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId);
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
@ -71,12 +71,12 @@ public class SectionController {
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
Section section = this.sectionService.findByPath(subCategory, sectionId);
this.sectionService.delete(stakeholder.getType(), section, true);
return true;
return ResponseEntity.ok(true);
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/moveIndicator", method = RequestMethod.POST)
public SubCategoryFull moveIndicator(@PathVariable("stakeholderId") String stakeholderId,
public ResponseEntity<SubCategoryFull> moveIndicator(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@ -87,6 +87,6 @@ public class SectionController {
Topic topic = this.topicService.findByPath(stakeholder, topicId);
Category category = this.categoryService.findByPath(topic, categoryId);
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
return this.subCategoryService.moveIndicator(stakeholder, subCategory, moveIndicator);
return ResponseEntity.ok(this.subCategoryService.moveIndicator(stakeholder, subCategory, moveIndicator));
}
}

View File

@ -14,13 +14,13 @@ import eu.dnetlib.uoamonitorservice.service.StakeholderService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin(origins = "*")
public class StakeholderController {
private final Logger log = LogManager.getLogger(this.getClass());
@ -37,21 +37,21 @@ public class StakeholderController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/stakeholder/alias", method = RequestMethod.GET)
public List<String> getAllReservedStakeholderAlias(@RequestParam(required = false) String type) {
public ResponseEntity<List<String>> getAllReservedStakeholderAlias(@RequestParam(required = false, name = "type") String type) {
List<String> stakeholderAlias = this.stakeholderService.getAllAliases(type);
if(type == null ) {
stakeholderAlias.add("all");
stakeholderAlias.add("default");
stakeholderAlias.add("alias");
}
return stakeholderAlias;
return ResponseEntity.ok(stakeholderAlias);
}
@PreAuthorize("hasAnyAuthority(" +
"@AuthorizationService.PORTAL_ADMIN, " +
"@AuthorizationService.curator(#buildStakeholder.stakeholder.getType()))")
@RequestMapping(value = "/build-stakeholder", method = RequestMethod.POST)
public Stakeholder buildStakeholder(@RequestBody BuildStakeholder buildStakeholder) {
public ResponseEntity<Stakeholder> buildStakeholder(@RequestBody BuildStakeholder buildStakeholder) {
Stakeholder stakeholder = buildStakeholder.getStakeholder();
log.debug("build stakeholder");
log.debug("Alias: " + stakeholder.getAlias());
@ -67,43 +67,43 @@ public class StakeholderController {
if (buildStakeholder.isUmbrella()) {
stakeholder.setUmbrella(new Umbrella<>());
}
return this.stakeholderService.buildStakeholder(stakeholder, buildStakeholder.getCopyId());
return ResponseEntity.ok(this.stakeholderService.buildStakeholder(stakeholder, buildStakeholder.getCopyId()));
}
@PreAuthorize("hasAnyAuthority(" + "@AuthorizationService.PORTAL_ADMIN)")
@RequestMapping(value = "/stakeholder/all", method = RequestMethod.GET)
public List<Stakeholder> getAllStakeholders(@RequestParam(required = false) String type) {
return this.stakeholderService.getAll(type);
public ResponseEntity<List<Stakeholder>> getAllStakeholders(@RequestParam(required = false, name = "type") String type) {
return ResponseEntity.ok(this.stakeholderService.getAll(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);
public ResponseEntity<List<Stakeholder>> getVisibleStakeholders(@RequestParam(required = false, name = "type") String type,
@RequestParam(required = false, name = "defaultId") String defaultId) {
return ResponseEntity.ok(stakeholderService.getVisibleStakeholders(type, defaultId));
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/my-stakeholder", method = RequestMethod.GET)
public ManageStakeholders getManagedStakeholders(@RequestParam(required = false) String type) {
return stakeholderService.getManageStakeholders(type);
public ResponseEntity<ManageStakeholders> getManagedStakeholders(@RequestParam(required = false, name = "type") String type) {
return ResponseEntity.ok(stakeholderService.getManageStakeholders(type));
}
@RequestMapping(value = "/stakeholder/{alias:.+}", method = RequestMethod.GET)
public StakeholderFull getStakeholder(@PathVariable("alias") String alias) {
public ResponseEntity<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);
}
return stakeholder;
return ResponseEntity.ok(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) {
public ResponseEntity<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;
return ResponseEntity.ok(stakeholder);
}
@ -113,10 +113,10 @@ public class StakeholderController {
+ "@AuthorizationService.manager(#stakeholder.getType(), #stakeholder.getAlias()) "
+ ")")
@RequestMapping(value = "/save", method = RequestMethod.POST)
public Stakeholder saveStakeholder(@RequestBody Stakeholder stakeholder) {
public ResponseEntity<Stakeholder> saveStakeholder(@RequestBody Stakeholder stakeholder) {
log.debug("save stakeholder");
log.debug("Alias: " + stakeholder.getAlias() + " - Id: " + stakeholder.getId());
return this.stakeholderService.save(stakeholder);
return ResponseEntity.ok(this.stakeholderService.save(stakeholder));
}
@PreAuthorize("hasAnyAuthority("
@ -125,40 +125,40 @@ public class StakeholderController {
+ "@AuthorizationService.manager(#stakeholder.getType(), #stakeholder.getAlias()) "
+ ")")
@RequestMapping(value = "/save/full", method = RequestMethod.POST)
public StakeholderFull saveStakeholderFull(@RequestBody StakeholderFull stakeholder) {
public ResponseEntity<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 ResponseEntity.ok(this.stakeholderService.getFullStakeholder(this.stakeholderService.save(new Stakeholder(stakeholder, this.stakeholderService))));
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/delete", method = RequestMethod.DELETE)
public boolean deleteStakeholder(@PathVariable("stakeholderId") String id) {
public ResponseEntity<Boolean> deleteStakeholder(@PathVariable("stakeholderId") String id) {
log.debug("delete stakeholder");
log.debug("Id: " + id);
Portal portal = portalService.getPortal(this.stakeholderService.delete(id));
if (portal != null) {
portalService.deletePortal(portal.getId());
}
return true;
return ResponseEntity.ok(true);
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/change-visibility", method = RequestMethod.POST)
public StakeholderFull changeStakeholderVisibility(@PathVariable("stakeholderId") String stakeholderId,
@RequestParam("visibility") Visibility visibility, @RequestParam(defaultValue = "false") Boolean propagate) {
public ResponseEntity<StakeholderFull> changeStakeholderVisibility(@PathVariable("stakeholderId") String stakeholderId,
@RequestParam("visibility") Visibility visibility, @RequestParam(defaultValue = "false", name = "propagate") Boolean propagate) {
log.debug("change stakeholder visibility: " + visibility + " - toggle propagate: " + propagate);
log.debug("Stakeholder: " + stakeholderId);
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
return this.stakeholderService.changeVisibility(stakeholder, visibility, propagate);
return ResponseEntity.ok(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) {
public ResponseEntity<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);
return ResponseEntity.ok(this.stakeholderService.updateUmbrella(stakeholder, update));
}
}

View File

@ -13,13 +13,13 @@ import eu.dnetlib.uoamonitorservice.service.TopicService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin(origins = "*")
public class SubCategoryController {
private final Logger log = LogManager.getLogger(this.getClass());
@ -38,10 +38,10 @@ public class SubCategoryController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/save", method = RequestMethod.POST)
public SubCategoryFull saveSubCategory(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@RequestBody SubCategoryFull subcategoryFull) {
public ResponseEntity<SubCategoryFull> saveSubCategory(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@RequestBody SubCategoryFull subcategoryFull) {
log.debug("save subcategory");
log.debug("Alias: " + subcategoryFull.getAlias() + " - Id: " + subcategoryFull.getId() + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId);
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
@ -50,16 +50,16 @@ public class SubCategoryController {
if(subcategoryFull.getId() != null) {
this.subCategoryService.findByPath(category, subcategoryFull.getId());
}
return this.subCategoryService.save(stakeholder, category, new SubCategory(subcategoryFull));
return ResponseEntity.ok(this.subCategoryService.save(stakeholder, category, new SubCategory(subcategoryFull)));
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/delete", method = RequestMethod.DELETE)
public boolean deleteSubCategory(@PathVariable("stakeholderId") String stakeholderId,
public ResponseEntity<Boolean> deleteSubCategory(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@RequestParam(required = false) String children) {
@RequestParam(required = false, name = "children") String children) {
log.debug("delete subcategory");
log.debug("Id: " + subcategoryId + " - Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId);
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
@ -67,12 +67,12 @@ public class SubCategoryController {
Category category = this.categoryService.findByPath(topic, categoryId);
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
this.subCategoryService.delete(stakeholder.getType(), subCategory, true);
return true;
return ResponseEntity.ok(true);
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/reorder", method = RequestMethod.POST)
public List<SubCategoryFull> reorderSubCategories(@PathVariable("stakeholderId") String stakeholderId,
public ResponseEntity<List<SubCategoryFull>> reorderSubCategories(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@RequestBody List<String> subCategories) {
@ -81,23 +81,23 @@ public class SubCategoryController {
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
Topic topic = this.topicService.findByPath(stakeholder, topicId);
Category category = this.categoryService.findByPath(topic, categoryId);
return this.categoryService.reorderSubCategories(stakeholder, category, subCategories).getSubCategories();
return ResponseEntity.ok(this.categoryService.reorderSubCategories(stakeholder, category, subCategories).getSubCategories());
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/{categoryId}/{subcategoryId}/change-visibility", method = RequestMethod.POST)
public SubCategoryFull changeSubCategoryVisibility(@PathVariable("stakeholderId") String stakeholderId,
public ResponseEntity<SubCategoryFull> changeSubCategoryVisibility(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@PathVariable("categoryId") String categoryId,
@PathVariable("subcategoryId") String subcategoryId,
@RequestParam("visibility") Visibility visibility,
@RequestParam(defaultValue = "false") Boolean propagate) {
@RequestParam(defaultValue = "false", name = "propagate") Boolean propagate) {
log.debug("change subCategory visibility: " + visibility + " - toggle propagate: " + propagate);
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId + " - Category: " + categoryId + " - SubCategory: " + subcategoryId);
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
Topic topic = this.topicService.findByPath(stakeholder, topicId);
Category category = this.categoryService.findByPath(topic, categoryId);
SubCategory subCategory = this.subCategoryService.findByPath(category, subcategoryId);
return this.subCategoryService.changeVisibility(stakeholder.getType(), stakeholder.getAlias(), subCategory, visibility, propagate);
return ResponseEntity.ok(this.subCategoryService.changeVisibility(stakeholder.getType(), stakeholder.getAlias(), subCategory, visibility, propagate));
}
}

View File

@ -9,13 +9,13 @@ import eu.dnetlib.uoamonitorservice.service.TopicService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@CrossOrigin(origins = "*")
public class TopicController {
private final Logger log = LogManager.getLogger(this.getClass());
@ -30,49 +30,49 @@ public class TopicController {
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/save", method = RequestMethod.POST)
public TopicFull saveTopic(@PathVariable("stakeholderId") String stakeholderId, @RequestBody TopicFull topicFull) {
public ResponseEntity<TopicFull> saveTopic(@PathVariable("stakeholderId") String stakeholderId, @RequestBody TopicFull topicFull) {
log.debug("save topic");
log.debug("Alias: " + topicFull.getAlias() + " - Id: " + topicFull.getId() + " - Stakeholder: " + stakeholderId);
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
if(topicFull.getId() != null) {
this.topicService.findByPath(stakeholder, topicFull.getId());
}
return this.topicService.save(stakeholder, new Topic(topicFull));
return ResponseEntity.ok(this.topicService.save(stakeholder, new Topic(topicFull)));
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/delete", method = RequestMethod.DELETE)
public boolean deleteTopic(@PathVariable("stakeholderId") String stakeholderId,
public ResponseEntity<Boolean> deleteTopic(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@RequestParam(required = false) String children) {
@RequestParam(required = false, name = "children") String children) {
log.debug("delete topic");
log.debug("Id: " + topicId + " - Stakeholder: " + stakeholderId);
Stakeholder stakeholder = stakeholderService.findByPath(stakeholderId);
Topic topic = this.topicService.findByPath(stakeholder, topicId);
this.topicService.delete(stakeholder.getType(), topic, true);
return true;
return ResponseEntity.ok(true);
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/reorder", method = RequestMethod.POST)
public List<TopicFull> reorderTopics(@PathVariable("stakeholderId") String stakeholderId,
public ResponseEntity<List<TopicFull>> reorderTopics(@PathVariable("stakeholderId") String stakeholderId,
@RequestBody List<String> topics) {
log.debug("reorder topics");
log.debug("Stakeholder: " + stakeholderId);
Stakeholder stakeholder = stakeholderService.findByPath(stakeholderId);
return this.stakeholderService.reorderTopics(stakeholder, topics).getTopics();
return ResponseEntity.ok(this.stakeholderService.reorderTopics(stakeholder, topics).getTopics());
}
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{stakeholderId}/{topicId}/change-visibility", method = RequestMethod.POST)
public TopicFull changeTopicVisibility(@PathVariable("stakeholderId") String stakeholderId,
public ResponseEntity<TopicFull> changeTopicVisibility(@PathVariable("stakeholderId") String stakeholderId,
@PathVariable("topicId") String topicId,
@RequestParam("visibility") Visibility visibility, @RequestParam(defaultValue = "false") Boolean propagate) {
@RequestParam("visibility") Visibility visibility, @RequestParam(defaultValue = "false", name = "propagate") Boolean propagate) {
log.debug("change topic visibility: " + visibility + " - toggle propagate: " + propagate);
log.debug("Stakeholder: " + stakeholderId + " - Topic: " + topicId);
Stakeholder stakeholder = this.stakeholderService.findByPath(stakeholderId);
Topic topic = this.topicService.findByPath(stakeholder, topicId);
return this.topicService.changeVisibility(stakeholder.getType(), stakeholder.getAlias(), topic, visibility, propagate);
return ResponseEntity.ok(this.topicService.changeVisibility(stakeholder.getType(), stakeholder.getAlias(), topic, visibility, propagate));
}
}

View File

@ -4,19 +4,15 @@ import eu.dnetlib.uoamonitorservice.entities.Category;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@Repository
public interface CategoryDAO extends MongoRepository<Category, String> {
List<Category> findAll();
List<Category> findByDefaultId(String DefaultId);
<T> List<Category> findBySubCategoriesContaining(List<T> subCategories);
List<Category> findBySubCategoriesContaining(String subCategory);
Optional<Category> findById(String Id);
void delete(String Id);
Category save(Category category);
default List<Category> findBySubCategory(String subCategory) {
return findBySubCategoriesContaining(Collections.singletonList(subCategory));
}
}

View File

@ -9,13 +9,5 @@ import java.util.Optional;
@Repository
public interface IndicatorDAO extends MongoRepository<Indicator, String> {
List<Indicator> findAll();
List<Indicator> findByDefaultId(String DefaultId);
Optional<Indicator> findById(String Id);
void delete(String Id);
Indicator save(Indicator indicator);
//List<Indicator> saveAll(List<Indicator> indicators);
}

View File

@ -4,18 +4,16 @@ import eu.dnetlib.uoamonitorservice.entities.Section;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@Repository
public interface SectionDAO extends MongoRepository<Section, String> {
List<Section> findAll();
List<Section> findByDefaultId(String DefaultId);
List<Section> findByIndicatorsContaining(String id);
<T> List<Section> findByIndicatorsContaining(List<T> indicators);
Optional<Section> findById(String Id);
void delete(String Id);
Section save(Section indicator);
default List<Section> findByIndicator(String indicator) {
return findByIndicatorsContaining(Collections.singletonList(indicator));
}
}

View File

@ -5,6 +5,7 @@ import eu.dnetlib.uoamonitorservice.primitives.StakeholderType;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@ -13,8 +14,6 @@ public interface StakeholderDAO extends MongoRepository<Stakeholder, String> {
/**
* All Stakeholders
*/
List<Stakeholder> findAll();
List<Stakeholder> findByDefaultId(String id);
List<Stakeholder> findByType(StakeholderType Type);
@ -182,17 +181,11 @@ public interface StakeholderDAO extends MongoRepository<Stakeholder, String> {
/**
* Other method
*/
List<Stakeholder> findByDefaultIdAndCopyIsTrue(String defaultId);
List<Stakeholder> findByTopicsContaining(String topic);
Optional<Stakeholder> findById(String id);
Optional<Stakeholder> findByAlias(String alias);
<T> List<Stakeholder> findByTopicsContaining(List<T> topics);
void delete(String Id);
Stakeholder save(Stakeholder stakeholder);
default List<Stakeholder> findByTopic(String topic) {
return this.findByTopicsContaining(Collections.singletonList(topic));
}
}

View File

@ -4,19 +4,21 @@ import eu.dnetlib.uoamonitorservice.entities.SubCategory;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@Repository
public interface SubCategoryDAO extends MongoRepository<SubCategory, String> {
List<SubCategory> findAll();
List<SubCategory> findByDefaultId(String defaultId);
List<SubCategory> findByNumbersContaining(String id);
List<SubCategory> findByChartsContaining(String id);
<T> List<SubCategory> findByNumbersContaining(List<T> numbers);
Optional<SubCategory> findById(String Id);
default List<SubCategory> findByNumber(String number) {
return findByNumbersContaining(Collections.singletonList(number));
}
void delete(String Id);
<T> List<SubCategory> findByChartsContaining(List<T> charts);
SubCategory save(SubCategory subCategory);
default List<SubCategory> findByChart(String chart) {
return findByChartsContaining(Collections.singletonList(chart));
}
}

View File

@ -4,19 +4,15 @@ import eu.dnetlib.uoamonitorservice.entities.Topic;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@Repository
public interface TopicDAO extends MongoRepository<Topic, String> {
List<Topic> findAll();
List<Topic> findByDefaultId(String DefaultId);
<T> List<Topic> findByCategoriesContaining(List<T> categories);
List<Topic> findByCategoriesContaining(String category);
Optional<Topic> findById(String Id);
void delete(String Id);
Topic save(Topic topic);
default List<Topic> findByCategory(String category) {
return findByCategoriesContaining(Collections.singletonList(category));
}
}

View File

@ -3,7 +3,6 @@ package eu.dnetlib.uoamonitorservice.dto;
import eu.dnetlib.uoamonitorservice.entities.Indicator;
import eu.dnetlib.uoamonitorservice.entities.Section;
import eu.dnetlib.uoamonitorservice.generics.SectionGeneric;
import io.swagger.models.auth.In;
import java.util.List;
import java.util.Objects;

View File

@ -1,11 +1,11 @@
package eu.dnetlib.uoamonitorservice.handlers;
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.HttpException;
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);
public class BadRequestException extends HttpException {
public BadRequestException(String message) {
super(message, HttpStatus.BAD_REQUEST);
}
}

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.NOT_FOUND)
public class EntityNotFoundException extends RuntimeException {
public EntityNotFoundException(String message){
super(message);
}
}

View File

@ -1,50 +0,0 @@
package eu.dnetlib.uoamonitorservice.handlers;
import eu.dnetlib.uoaadmintoolslibrary.responses.ExceptionResponse;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
@ControllerAdvice
@RestController
public class ExceptionsHandler {
private final Logger log = LogManager.getLogger(this.getClass());
@ExceptionHandler(EntityNotFoundException.class)
public ResponseEntity<ExceptionResponse> entityNotFoundException(Exception ex) {
ExceptionResponse response = new ExceptionResponse();
response.setErrorCode("Not found Exception");
response.setErrorMessage("Entity not found Exception");
response.setErrors(ex.getMessage());
response.setStatus(HttpStatus.NOT_FOUND);
log.error("entityNotFoundException exception : "+ ex.getMessage());
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();
response.setErrorCode("Not found Exception");
response.setErrorMessage("Path not valid Exception");
response.setErrors(ex.getMessage());
response.setStatus(HttpStatus.NOT_FOUND);
log.error("pathNotValidException exception : "+ ex.getMessage());
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
}
}

View File

@ -1,11 +1,10 @@
package eu.dnetlib.uoamonitorservice.handlers;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.NotFoundException;
@ResponseStatus(HttpStatus.NOT_FOUND)
public class PathNotValidException extends RuntimeException {
public PathNotValidException(String message){
public class PathNotValidException extends NotFoundException {
public PathNotValidException(String message) {
super(message);
}
}

View File

@ -1,5 +1,6 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.NotFoundException;
import eu.dnetlib.uoamonitorservice.dao.CategoryDAO;
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
import eu.dnetlib.uoamonitorservice.dao.TopicDAO;
@ -8,12 +9,12 @@ import eu.dnetlib.uoamonitorservice.entities.Category;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import eu.dnetlib.uoamonitorservice.entities.Topic;
import eu.dnetlib.uoamonitorservice.generics.Common;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
@ -38,14 +39,14 @@ public class CategoryService {
}
public Category find(String id) {
return dao.findById(id).orElseThrow(() -> new EntityNotFoundException("Category with id: " + id + " not found"));
return dao.findById(id).orElseThrow(() -> new NotFoundException("Category with id: " + id + " not found"));
}
public Category findByPath(Topic topic, String categoryId) {
if (!topic.getCategories().contains(categoryId)) {
throw new PathNotValidException("Category with id: " + categoryId + " not found in Topic: " + topic.getId());
}
return this.dao.findById(categoryId).orElseThrow(() -> new EntityNotFoundException("Category with id: " + categoryId + " not found"));
return this.dao.findById(categoryId).orElseThrow(() -> new NotFoundException("Category with id: " + categoryId + " not found"));
}
public CategoryFull getFullCategory(String type, String alias, Category category) {
@ -120,7 +121,7 @@ public class CategoryService {
public void createChildren(Topic defaultTopic, Category category) {
this.topicDAO.findByDefaultId(defaultTopic.getId()).forEach(topic -> {
this.stakeholderDAO.findByTopicsContaining(topic.getId()).forEach(stakeholder -> {
this.stakeholderDAO.findByTopic(topic.getId()).forEach(stakeholder -> {
this.save(stakeholder, topic, category.copy(), false);
});
});
@ -141,7 +142,7 @@ public class CategoryService {
this.reorderChildren(stakeholder, category, subcategories);
return this.getFullCategory(stakeholder.getType(), stakeholder.getAlias(), this.dao.save(category));
} else {
throw new EntityNotFoundException("Some subCategories dont exist in the category with id " + category.getId());
throw new NotFoundException("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());
@ -187,7 +188,7 @@ public class CategoryService {
}
public void removeCategory(String id) {
this.topicDAO.findByCategoriesContaining(id).forEach(topic -> {
this.topicDAO.findByCategory(id).forEach(topic -> {
topic.removeCategory(id);
topic.setUpdateDate(new Date());
this.topicDAO.save(topic);

View File

@ -1,17 +1,14 @@
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.authorization.exceptions.http.ForbiddenException;
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.UnauthorizedException;
import eu.dnetlib.uoaauthorizationlibrary.authorization.security.AuthorizationService;
import eu.dnetlib.uoamonitorservice.generics.Common;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Service

View File

@ -1,11 +1,11 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.NotFoundException;
import eu.dnetlib.uoamonitorservice.dao.*;
import eu.dnetlib.uoamonitorservice.entities.Indicator;
import eu.dnetlib.uoamonitorservice.entities.Section;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import eu.dnetlib.uoamonitorservice.entities.SubCategory;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.beans.factory.annotation.Autowired;
@ -38,14 +38,14 @@ public class IndicatorService {
}
public Indicator find(String id) {
return dao.findById(id).orElseThrow(() -> new EntityNotFoundException("Indicator with id: " + id + " not found"));
return dao.findById(id).orElseThrow(() -> new NotFoundException("Indicator with id: " + id + " not found"));
}
public Indicator findByPath(Section section, String indicatorId) {
if (!section.getIndicators().contains(indicatorId)) {
throw new PathNotValidException("Indicator with id: " + indicatorId + " not found in Section: " + section.getId());
}
return this.dao.findById(indicatorId).orElseThrow(() -> new EntityNotFoundException("Indicator with id: " + indicatorId + " not found"));
return this.dao.findById(indicatorId).orElseThrow(() -> new NotFoundException("Indicator with id: " + indicatorId + " not found"));
}
public Indicator getIndicator(String type, String alias, String id) {
@ -97,12 +97,12 @@ public class IndicatorService {
public void createChildren(Section defaultSection, Indicator indicator) {
this.sectionDAO.findByDefaultId(defaultSection.getId()).forEach(section -> {
List<SubCategory> subCategories = this.subCategoryDAO.findByNumbersContaining(section.getId());
subCategories.addAll(this.subCategoryDAO.findByChartsContaining(section.getId()));
List<SubCategory> subCategories = this.subCategoryDAO.findByNumber(section.getId());
subCategories.addAll(this.subCategoryDAO.findByChart(section.getId()));
subCategories.forEach(subCategory -> {
this.categoryDAO.findBySubCategoriesContaining(subCategory.getId()).forEach(category -> {
this.topicDAO.findByCategoriesContaining(category.getId()).forEach(topic -> {
this.stakeholderDAO.findByTopicsContaining(topic.getId()).forEach(stakeholder -> {
this.categoryDAO.findBySubCategory(subCategory.getId()).forEach(category -> {
this.topicDAO.findByCategory(category.getId()).forEach(topic -> {
this.stakeholderDAO.findByTopic(topic.getId()).forEach(stakeholder -> {
this.save(stakeholder, section, indicator.copy());
});
});
@ -144,7 +144,7 @@ public class IndicatorService {
}
public void removeIndicator(String id) {
this.sectionDAO.findByIndicatorsContaining(id).forEach(section -> {
this.sectionDAO.findByIndicator(id).forEach(section -> {
section.removeIndicator(id);
section.setUpdateDate(new Date());
this.sectionDAO.save(section);

View File

@ -1,11 +1,10 @@
package eu.dnetlib.uoamonitorservice.service;
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 jakarta.annotation.PostConstruct;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
@ -26,27 +25,32 @@ public class MonitorDeployService {
this.globalVars = globalVars;
}
public Map<String, String> checkEverything() {
Map<String, String> response = new HashMap<>();
@PostConstruct
public void checkProperties() {
if(mongoConfig.getHost() == null || mongoConfig.getHost().isEmpty()) {
throw new RuntimeException("monitor-service.mongodb.host is missing!");
} else if(mongoConfig.getDatabase() == null || mongoConfig.getDatabase().isEmpty()) {
throw new RuntimeException("monitor-service.mongodb.database is missing!");
}
}
public Map<String, String> getProperties() {
Map<String, String> response = new HashMap<>();
MongoTemplate mt = mongoConnection.getMongoTemplate();
DBObject ping = new BasicDBObject("ping", "1");
Document ping = new Document("ping", 1);
try {
CommandResult answer = mt.getDb().command(ping);
response.put("Mongo try: error", answer.getErrorMessage());
Document answer = mt.executeCommand(ping);
response.put("Mongo try: error", String.valueOf(answer.getDouble("ok") == 1.0));
} catch (Exception e) {
response.put("Mongo catch: error", e.getMessage());
}
response.put("monitor-service.mongodb.database", mongoConfig.getDatabase());
response.put("monitor-service.mongodb.host", mongoConfig.getHost());
response.put("monitor-service.mongodb.port", mongoConfig.getPort() + "");
response.put("monitor-service.mongodb.username", mongoConfig.getUsername() == null ? null : "[unexposed value]");
response.put("monitor-service.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]");
response.put("monitorservice.mongodb.database", mongoConfig.getDatabase());
response.put("monitorservice.mongodb.host", mongoConfig.getHost());
response.put("monitorservice.mongodb.port", mongoConfig.getPort() + "");
response.put("monitorservice.mongodb.username", mongoConfig.getUsername() == null ? null : "[unexposed value]");
response.put("monitorservice.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]");
if (globalVars.date != null) {
response.put("Date of deploy", globalVars.date.toString());
}
response.put("Date of deploy", GlobalVars.date.toString());
if (globalVars.getBuildDate() != null) {
response.put("Date of build", globalVars.getBuildDate());
}

View File

@ -1,12 +1,12 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.NotFoundException;
import eu.dnetlib.uoamonitorservice.dao.*;
import eu.dnetlib.uoamonitorservice.dto.SectionFull;
import eu.dnetlib.uoamonitorservice.entities.Section;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import eu.dnetlib.uoamonitorservice.entities.SubCategory;
import eu.dnetlib.uoamonitorservice.generics.Common;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.beans.factory.annotation.Autowired;
@ -41,14 +41,14 @@ public class SectionService {
}
public Section find(String id) {
return dao.findById(id).orElseThrow(() -> new EntityNotFoundException("Section with id: " + id + " not found"));
return dao.findById(id).orElseThrow(() -> new NotFoundException("Section with id: " + id + " not found"));
}
public Section findByPath(SubCategory subCategory, String sectionId) {
if (!subCategory.getNumbers().contains(sectionId) && !subCategory.getCharts().contains(sectionId)) {
throw new PathNotValidException("Section with id: " + sectionId + " not found in SubCategory: " + subCategory.getId());
}
return this.dao.findById(sectionId).orElseThrow(() -> new EntityNotFoundException("Section with id: " + sectionId + " not found"));
return this.dao.findById(sectionId).orElseThrow(() -> new NotFoundException("Section with id: " + sectionId + " not found"));
}
public SectionFull getFullSection(String type, String alias, Section section) {
@ -129,24 +129,24 @@ public class SectionService {
}
public void createChildren(SubCategory defaultSubCategory, Section section, int index) {
this.subCategoryDAO.findByDefaultId(defaultSubCategory.getId()).forEach(subCategory -> {
this.categoryDAO.findBySubCategoriesContaining(subCategory.getId()).forEach(category -> {
this.topicDAO.findByCategoriesContaining(category.getId()).forEach(topic -> {
this.stakeholderDAO.findByTopicsContaining(topic.getId()).forEach(stakeholder -> {
this.save(stakeholder, subCategory, section.copy(), index);
});
});
});
});
section.getIndicators().forEach(indicator -> {
this.indicatorService.createChildren(section, this.indicatorService.find(indicator));
});
this.subCategoryDAO.findByDefaultId(defaultSubCategory.getId()).forEach(subCategory ->
this.categoryDAO.findBySubCategory(subCategory.getId()).forEach(category ->
this.topicDAO.findByCategory(category.getId()).forEach(topic ->
this.stakeholderDAO.findByTopic(topic.getId()).forEach(stakeholder ->
this.save(stakeholder, subCategory, section.copy(), index)
)
)
)
);
section.getIndicators().forEach(indicator ->
this.indicatorService.createChildren(section, this.indicatorService.find(indicator))
);
}
public void updateChildren(Section section) {
this.dao.findByDefaultId(section.getId()).forEach(child -> {
this.save(section.override(child, this.find(section.getId())));
});
this.dao.findByDefaultId(section.getId()).forEach(child ->
this.save(section.override(child, this.find(section.getId())))
);
}
public SectionFull reorderIndicators(Stakeholder stakeholder, Section section, List<String> indicators) {
@ -159,12 +159,12 @@ public class SectionService {
if (section.getIndicators().size() == indicators.size() && new HashSet<>(section.getIndicators()).containsAll(indicators)) {
section.setIndicators(indicators);
section.setUpdateDate(new Date());
if(reorderChildren) {
if (reorderChildren) {
this.reorderChildren(stakeholder, section, indicators);
}
return this.getFullSection(stakeholder.getType(), stakeholder.getAlias(), this.dao.save(section));
} else {
throw new EntityNotFoundException("Some indicators dont exist in the section with id " + section.getId());
throw new NotFoundException("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());
@ -173,22 +173,21 @@ public class SectionService {
}
public void reorderChildren(Stakeholder defaultStakeholder, Section defaultSection, List<String> defaultIndicators) {
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder -> {
this.dao.findByDefaultId(defaultSection.getId()).stream().map(section -> this.getFullSection(stakeholder.getType(), stakeholder.getAlias(), section)).forEach(section -> {
this.reorderIndicators(stakeholder, new Section(section),
this.commonService.reorder(defaultIndicators, section.getIndicators().stream().map(indicator -> (Common) indicator).collect(Collectors.toList())));
});
});
this.stakeholderDAO.findByDefaultIdAndCopyIsTrue(defaultStakeholder.getId()).forEach(stakeholder ->
this.dao.findByDefaultId(defaultSection.getId()).stream().map(section -> this.getFullSection(stakeholder.getType(), stakeholder.getAlias(), section)).forEach(section ->
this.reorderIndicators(stakeholder, new Section(section), this.commonService.reorder(defaultIndicators, section.getIndicators().stream().map(indicator -> (Common) indicator).collect(Collectors.toList())))
)
);
}
public void delete(String type, Section section, boolean remove) {
if (this.commonService.hasDeleteAuthority(type)) {
this.dao.findByDefaultId(section.getId()).forEach(child -> {
this.delete(type, child.getId(), remove);
});
section.getIndicators().forEach(indicatorId -> {
this.indicatorService.delete(type, indicatorId, false);
});
this.dao.findByDefaultId(section.getId()).forEach(child ->
this.delete(type, child.getId(), remove)
);
section.getIndicators().forEach(indicatorId ->
this.indicatorService.delete(type, indicatorId, false)
);
if (remove) {
this.removeSection(section.getId());
}
@ -218,12 +217,12 @@ public class SectionService {
}
public void removeSection(String id) {
this.subCategoryDAO.findByNumbersContaining(id).forEach(subCategory -> {
this.subCategoryDAO.findByNumber(id).forEach(subCategory -> {
subCategory.removeNumber(id);
subCategory.setUpdateDate(new Date());
this.subCategoryDAO.save(subCategory);
});
this.subCategoryDAO.findByChartsContaining(id).forEach(subCategory -> {
this.subCategoryDAO.findByChart(id).forEach(subCategory -> {
subCategory.removeChart(id);
subCategory.setUpdateDate(new Date());
this.subCategoryDAO.save(subCategory);

View File

@ -1,5 +1,6 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.NotFoundException;
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
import eu.dnetlib.uoamonitorservice.dto.ManageStakeholders;
import eu.dnetlib.uoamonitorservice.dto.StakeholderFull;
@ -8,8 +9,6 @@ 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;
@ -40,7 +39,7 @@ public class StakeholderService {
}
public Stakeholder findByAlias(String alias) {
return this.dao.findByAlias(alias).orElseThrow(() -> new EntityNotFoundException("Stakeholder with alias: " + alias + " not found"));
return this.dao.findByAlias(alias).orElseThrow(() -> new NotFoundException("Stakeholder with alias: " + alias + " not found"));
}
public List<Stakeholder> findByDefaultId(String id) {
@ -51,7 +50,7 @@ public class StakeholderService {
if (stakeholderId.equals("-1")) {
return null;
}
return dao.findById(stakeholderId).orElseThrow(() -> new EntityNotFoundException("Stakeholder with id: " + stakeholderId + " not found"));
return dao.findById(stakeholderId).orElseThrow(() -> new NotFoundException("Stakeholder with id: " + stakeholderId + " not found"));
}
public List<String> getAllAliases(String type) {
@ -119,7 +118,7 @@ public class StakeholderService {
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)));
.orElseThrow(() -> new NotFoundException("Stakeholder with alias: " + stakeholder.getAlias() + " not found in stakeholder " + parent)));
stakeholderFull.setOtherParents(this.getOtherParents(parent, type, stakeholder.getId()));
}
return stakeholderFull;
@ -182,7 +181,7 @@ public class StakeholderService {
this.reorderChildren(stakeholder, topics);
return this.getFullStakeholder(this.dao.save(stakeholder));
} else {
throw new EntityNotFoundException("Some topics dont exist in the stakeholder with id " + stakeholder.getId());
throw new NotFoundException("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());
@ -213,7 +212,7 @@ public class StakeholderService {
stakeholder.getTopics().forEach(topicId -> {
this.topicService.delete(stakeholder.getType(), topicId, false);
});
this.dao.delete(id);
this.dao.deleteById(id);
return stakeholder.getAlias();
} else {
this.commonService.unauthorized("Delete stakeholder: You are not authorized to delete stakeholder with id: " + id);
@ -271,7 +270,7 @@ public class StakeholderService {
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));
Umbrella<String> umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new NotFoundException("Umbrella not found in the stakeholder with id " + id));
if (umbrella.addType(type)) {
stakeholder.setUmbrella(umbrella);
stakeholder.setUpdateDate(new Date());
@ -282,7 +281,7 @@ public class StakeholderService {
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));
Umbrella<String> umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new NotFoundException("Umbrella not found in the stakeholder with id " + id));
if (umbrella.removeType(type)) {
stakeholder.setUmbrella(umbrella);
stakeholder.setUpdateDate(new Date());
@ -293,7 +292,7 @@ public class StakeholderService {
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));
Umbrella<String> umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new NotFoundException("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);
@ -305,7 +304,7 @@ public class StakeholderService {
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));
Umbrella<String> umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new NotFoundException("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);
@ -317,7 +316,7 @@ public class StakeholderService {
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));
Umbrella<String> umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new NotFoundException("Umbrella not found in the stakeholder with id " + id));
if (stakeholder.getUmbrella().update(types)) {
stakeholder.setUmbrella(umbrella);
stakeholder.setUpdateDate(new Date());
@ -328,7 +327,7 @@ public class StakeholderService {
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));
Umbrella<String> umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new NotFoundException("Umbrella not found in the stakeholder with id " + id));
if (stakeholder.getUmbrella().update(type, children)) {
stakeholder.setUmbrella(umbrella);
stakeholder.setUpdateDate(new Date());

View File

@ -1,5 +1,6 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.NotFoundException;
import eu.dnetlib.uoamonitorservice.dao.CategoryDAO;
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
import eu.dnetlib.uoamonitorservice.dao.SubCategoryDAO;
@ -10,7 +11,6 @@ import eu.dnetlib.uoamonitorservice.dto.SectionInfo;
import eu.dnetlib.uoamonitorservice.dto.SubCategoryFull;
import eu.dnetlib.uoamonitorservice.entities.*;
import eu.dnetlib.uoamonitorservice.generics.Common;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.beans.factory.annotation.Autowired;
@ -43,14 +43,14 @@ public class SubCategoryService {
}
public SubCategory find(String id) {
return dao.findById(id).orElseThrow(() -> new EntityNotFoundException("SubCategory with id: " + id + " not found"));
return dao.findById(id).orElseThrow(() -> new NotFoundException("SubCategory with id: " + id + " not found"));
}
public SubCategory findByPath(Category category, String subcategoryId) {
if (!category.getSubCategories().contains(subcategoryId)) {
throw new PathNotValidException("SubCategory with id: " + subcategoryId + " not found in Category: " + category.getId());
}
return this.dao.findById(subcategoryId).orElseThrow(() -> new EntityNotFoundException("SubCategory with id: " + subcategoryId + " not found"));
return this.dao.findById(subcategoryId).orElseThrow(() -> new NotFoundException("SubCategory with id: " + subcategoryId + " not found"));
}
public SubCategoryFull getFullSubCategory(String type, String alias, SubCategory subCategory) {
@ -127,8 +127,8 @@ public class SubCategoryService {
public void createChildren(Category defaultCategory, SubCategory subCategory) {
this.categoryDAO.findByDefaultId(defaultCategory.getId()).forEach(category -> {
this.topicDAO.findByCategoriesContaining(category.getId()).forEach(topic -> {
this.stakeholderDAO.findByTopicsContaining(topic.getId()).forEach(stakeholder -> {
this.topicDAO.findByCategory(category.getId()).forEach(topic -> {
this.stakeholderDAO.findByTopic(topic.getId()).forEach(stakeholder -> {
this.save(stakeholder, category, subCategory.copy());
});
});
@ -188,7 +188,7 @@ public class SubCategoryService {
this.reorderChildrenNumbers(stakeholder, subCategory, numbers);
return this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), this.dao.save(subCategory));
} else {
throw new EntityNotFoundException("Some sections dont exist in the subCategory with id " + subCategory.getId());
throw new NotFoundException("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());
@ -204,7 +204,7 @@ public class SubCategoryService {
this.reorderChildrenCharts(stakeholder, subCategory, charts);
return this.getFullSubCategory(stakeholder.getType(), stakeholder.getAlias(), this.dao.save(subCategory));
} else {
throw new EntityNotFoundException("Some sections dont exist in the subCategory with id " + subCategory.getId());
throw new NotFoundException("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());
@ -263,7 +263,7 @@ public class SubCategoryService {
}
public void removeSubCategory(String id) {
this.categoryDAO.findBySubCategoriesContaining(id).forEach(category -> {
this.categoryDAO.findBySubCategory(id).forEach(category -> {
category.removeSubCategory(id);
category.setUpdateDate(new Date());
this.categoryDAO.save(category);

View File

@ -1,12 +1,12 @@
package eu.dnetlib.uoamonitorservice.service;
import eu.dnetlib.uoaauthorizationlibrary.authorization.exceptions.http.NotFoundException;
import eu.dnetlib.uoamonitorservice.dao.StakeholderDAO;
import eu.dnetlib.uoamonitorservice.dao.TopicDAO;
import eu.dnetlib.uoamonitorservice.dto.TopicFull;
import eu.dnetlib.uoamonitorservice.entities.Stakeholder;
import eu.dnetlib.uoamonitorservice.entities.Topic;
import eu.dnetlib.uoamonitorservice.generics.Common;
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException;
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException;
import eu.dnetlib.uoamonitorservice.primitives.Visibility;
import org.springframework.beans.factory.annotation.Autowired;
@ -35,14 +35,14 @@ public class TopicService {
}
public Topic find(String id) {
return dao.findById(id).orElseThrow(() -> new EntityNotFoundException("Topic with id: " + id + " not found"));
return dao.findById(id).orElseThrow(() -> new NotFoundException("Topic with id: " + id + " not found"));
}
public Topic findByPath(Stakeholder stakeholder, String topicId) {
if (!stakeholder.getTopics().contains(topicId)) {
throw new PathNotValidException("Topic with id: " + topicId + " not found in Stakeholder: " + stakeholder.getId());
}
return this.dao.findById(topicId).orElseThrow(() -> new EntityNotFoundException("Topic with id: " + topicId + " not found"));
return this.dao.findById(topicId).orElseThrow(() -> new NotFoundException("Topic with id: " + topicId + " not found"));
}
public TopicFull getFullTopic(String type, String alias, Topic topic) {
@ -128,7 +128,7 @@ public class TopicService {
topic.setUpdateDate(new Date());
return this.getFullTopic(stakeholder.getType(), stakeholder.getAlias(), this.dao.save(topic));
} else {
throw new EntityNotFoundException("Some categories dont exist in the topic with id " + topic.getId());
throw new NotFoundException("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());
@ -174,7 +174,7 @@ public class TopicService {
}
public void removeTopic(String id) {
this.stakeholderDAO.findByTopicsContaining(id).forEach(stakeholder -> {
this.stakeholderDAO.findByTopic(id).forEach(stakeholder -> {
stakeholder.removeTopic(id);
stakeholder.setUpdateDate(new Date());
this.stakeholderDAO.save(stakeholder);

View File

@ -1,24 +1,2 @@
#mongodb
#beta
#spring.data.mongodb.host=beta.services.openaire.eu
#spring.data.mongodb.port=27017
#spring.data.mongodb.database=openairemonitor
#production
#spring.data.mongodb.host=localhost
#spring.data.mongodb.port=27017
#spring.data.mongodb.database=openairemonitor
#spring.data.mongodb.authentication-database=openairemonitor
#spring.data.mongodb.username=dnet8480
#spring.data.mongodb.password=...
#dev
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=openaire_monitor
#static properties
api.title = Uoa Monitor Service Documentation Swagger
api.description = Uoa Monitor Service is a service which serves and saves dynamic content and indicators (numbers & charts)
api.version = ${project.version}
# temp until refactoring the code in admin tools library
spring.main.allow-circular-references=true

View File

@ -1,27 +1,10 @@
#dev
monitorservice.host = smtp.gmail.com
monitorservice.port = 587
monitorservice.auth = true
monitorservice.from = openaire.test@gmail.com
monitorservice.username = openaire.test@gmail.com
monitorservice.password = ...
monitorservice.mongodb.host=localhost
monitorservice.mongodb.port=27017
monitorservice.mongodb.database=openaire_monitor3
monitorservice.globalVars.buildDate=@timestamp@
monitorservice.globalVars.version=@version@
## API Documentation Properties
api.title = Uoa Monitor Service
api.description = Uoa Monitor Service is a service which serves and saves dynamic content and indicators (numbers & charts)
api.version = ${project.version}
monitor-service.global-vars.buildDate=@timestamp@
monitor-service.global-vars.version=@version@
#beta
#monitorservice.userInfoUrl = https://beta.services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken=
#monitorservice.originServer = .openaire.eu
#monitorservice.host = bwnmail.icm.edu.pl
#monitorservice.port = 25
#monitorservice.auth = false
#monitorservice.username = no-reply@openaire.eu
#monitorservice.from = no-reply@beta.openaire.eu
#monitorservice.password = ...
#production
#monitorservice.userInfoUrl = https://services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken=
#monitorservice.originServer = .openaire.eu