From d293d23723076173c7e047ccbbc94684b25f3d30 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Tue, 15 Oct 2024 10:26:04 +0300 Subject: [PATCH 1/4] [spring-boot3]: Upgrade to spring boot 3 --- README.md | 30 +++++ pom.xml | 54 ++------ .../UoaMonitorServiceConfiguration.java | 19 +-- .../application/ServletInitializer.java | 3 +- .../UoaMonitorServiceApplication.java | 4 +- .../configuration/GlobalVars.java | 2 +- .../configuration/SwaggerConfig.java | 118 ------------------ .../configuration/mongo/MongoConnection.java | 35 +++--- .../properties/APIProperties.java | 38 ------ .../configuration/properties/MongoConfig.java | 6 +- .../controllers/CategoryController.java | 26 ++-- .../controllers/EmailController.java | 33 +++-- .../controllers/IndicatorController.java | 32 ++--- .../controllers/MonitorController.java | 35 ++---- .../MonitorLibraryCheckDeployController.java | 13 +- .../MonitorServiceCheckDeployController.java | 15 ++- .../controllers/SectionController.java | 26 ++-- .../controllers/StakeholderController.java | 54 ++++---- .../controllers/SubCategoryController.java | 28 ++--- .../controllers/TopicController.java | 22 ++-- .../uoamonitorservice/dao/CategoryDAO.java | 14 +-- .../uoamonitorservice/dao/IndicatorDAO.java | 8 -- .../uoamonitorservice/dao/SectionDAO.java | 12 +- .../uoamonitorservice/dao/StakeholderDAO.java | 17 +-- .../uoamonitorservice/dao/SubCategoryDAO.java | 16 +-- .../uoamonitorservice/dao/TopicDAO.java | 14 +-- .../uoamonitorservice/dto/SectionFull.java | 1 - .../handlers/BadRequestException.java | 10 +- .../handlers/EntityNotFoundException.java | 11 -- .../handlers/ExceptionsHandler.java | 50 -------- .../handlers/PathNotValidException.java | 9 +- .../service/CategoryService.java | 13 +- .../service/CommonService.java | 11 +- .../service/IndicatorService.java | 18 +-- .../service/MonitorDeployService.java | 38 +++--- .../service/SectionService.java | 67 +++++----- .../service/StakeholderService.java | 25 ++-- .../service/SubCategoryService.java | 16 +-- .../service/TopicService.java | 10 +- src/main/resources/application.properties | 26 +--- src/main/resources/monitorservice.properties | 31 ++--- 41 files changed, 349 insertions(+), 661 deletions(-) create mode 100644 README.md delete mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/configuration/SwaggerConfig.java delete mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/configuration/properties/APIProperties.java delete mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/handlers/EntityNotFoundException.java delete mode 100644 src/main/java/eu/dnetlib/uoamonitorservice/handlers/ExceptionsHandler.java diff --git a/README.md b/README.md new file mode 100644 index 0000000..9befbba --- /dev/null +++ b/README.md @@ -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 + + + eu.dnetlib + uoa-monitor-service + 2.0.0 + library + + +## Run + +Check [Spring boot Documentation](https://code-repo.d4science.org/MaDgIK/Documentation/wiki/Spring-boot) (need Login) diff --git a/pom.xml b/pom.xml index 40c7872..1b1472e 100644 --- a/pom.xml +++ b/pom.xml @@ -2,19 +2,19 @@ + + eu.dnetlib + uoa-spring-boot-parent + 2.0.3 + 4.0.0 uoa-monitor-service - 1.0.4-SNAPSHOT + 2.0.0-SNAPSHOT war uoa-monitor-service scm:git:gitea@code-repo.d4science.org:MaDgIK/uoa-monitor-service.git - - eu.dnetlib - uoa-spring-boot-parent - 1.0.0 - UTF-8 UTF-8 @@ -26,59 +26,30 @@ org.springframework.boot spring-boot-starter-data-mongodb - eu.dnetlib uoa-admin-tools-library - 1.0.13 + 2.0.0 eu.dnetlib uoa-notification-service - 1.0.7 - - - - - io.springfox - springfox-swagger2 - ${swagger-version} - - - - io.springfox - springfox-swagger-ui - ${swagger-version} + 2.0.4 - org.springframework.boot spring-boot-maven-plugin - ${spring-boot-version} eu.dnetlib.uoamonitorservice.application.UoaMonitorServiceApplication true - - - default-war - package - - repackage - - - org.apache.maven.plugins maven-war-plugin - 2.6 - - false - org.apache.maven.plugins @@ -94,20 +65,15 @@ library **/eu/dnetlib/uoamonitorservice/application/** - **/eu/dnetlib/uoamonitorservice/configuration/SwaggerConfig.class **/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.class + + uoa-monitor-service - - - src/main/resources - true - - diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/UoaMonitorServiceConfiguration.java b/src/main/java/eu/dnetlib/uoamonitorservice/UoaMonitorServiceConfiguration.java index a3e319f..474dd18 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/UoaMonitorServiceConfiguration.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/UoaMonitorServiceConfiguration.java @@ -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 { } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/application/ServletInitializer.java b/src/main/java/eu/dnetlib/uoamonitorservice/application/ServletInitializer.java index 6df2b1f..a274acf 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/application/ServletInitializer.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/application/ServletInitializer.java @@ -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 { diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/application/UoaMonitorServiceApplication.java b/src/main/java/eu/dnetlib/uoamonitorservice/application/UoaMonitorServiceApplication.java index 6b45846..b1bace9 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/application/UoaMonitorServiceApplication.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/application/UoaMonitorServiceApplication.java @@ -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) { diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/GlobalVars.java b/src/main/java/eu/dnetlib/uoamonitorservice/configuration/GlobalVars.java index 1631c86..2dbee14 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/GlobalVars.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/configuration/GlobalVars.java @@ -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; diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/SwaggerConfig.java b/src/main/java/eu/dnetlib/uoamonitorservice/configuration/SwaggerConfig.java deleted file mode 100644 index 84d90a6..0000000 --- a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/SwaggerConfig.java +++ /dev/null @@ -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 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/"); - } - -} - diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/mongo/MongoConnection.java b/src/main/java/eu/dnetlib/uoamonitorservice/configuration/mongo/MongoConnection.java index 676f4ea..279b3e9 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/mongo/MongoConnection.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/configuration/mongo/MongoConnection.java @@ -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()); } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/properties/APIProperties.java b/src/main/java/eu/dnetlib/uoamonitorservice/configuration/properties/APIProperties.java deleted file mode 100644 index 656b031..0000000 --- a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/properties/APIProperties.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/properties/MongoConfig.java b/src/main/java/eu/dnetlib/uoamonitorservice/configuration/properties/MongoConfig.java index 75c283a..1f5dbaa 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/configuration/properties/MongoConfig.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/configuration/properties/MongoConfig.java @@ -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() { diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java index 37b5e0d..11b5ae4 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java @@ -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 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 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 reorderCategories(@PathVariable("stakeholderId") String stakeholderId, + public ResponseEntity> reorderCategories(@PathVariable("stakeholderId") String stakeholderId, @PathVariable("topicId") String topicId, @RequestBody List 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 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)); } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/EmailController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/EmailController.java index 960fe75..44efb81 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/EmailController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/EmailController.java @@ -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 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> sendEmail(@RequestBody Email email, - @RequestParam(required = false) Optional optional) { + public ResponseEntity>> sendEmail(@RequestBody Email email, + @RequestParam(required = false, name = "optional") Optional optional) { String successString = "success"; String failureString = "failure"; Map> mailResults = new HashMap<>(); @@ -46,7 +42,7 @@ public class EmailController { for (String userMail : email.getRecipients()) { ArrayList 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); } -} \ No newline at end of file +} diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java index ee894cd..cbd859d 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java @@ -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 sections) throws UnsupportedEncodingException { + public ResponseEntity saveBulkIndicators(@PathVariable("stakeholderId") String stakeholderId, + @PathVariable("topicId") String topicId, + @PathVariable("categoryId") String categoryId, + @PathVariable("subcategoryId") String subcategoryId, + @RequestBody List 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 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 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 reorderIndicators(@PathVariable("stakeholderId") String stakeholderId, + public ResponseEntity> 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 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)); } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java index 1c959e3..bb43239 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorController.java @@ -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 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 insertPortal(@RequestBody Portal portal) { + return ResponseEntity.ok(portalService.insertPortal(portal)); } @RequestMapping(value = "/delete", method = RequestMethod.POST) - public Boolean deletePortals(@RequestBody List portals) { - portals.forEach(id -> portalService.deletePortal(id)); - return true; + public ResponseEntity deletePortals(@RequestBody List portals) { + portals.forEach(portalService::deletePortal); + return ResponseEntity.ok(true); } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.java index 3fd7065..4500d39 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorLibraryCheckDeployController.java @@ -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 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 checkEverything() { - return this.service.checkEverything(); + public ResponseEntity> checkEverything() { + return ResponseEntity.ok(this.service.getProperties()); } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java index 0826b83..400d65e 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java @@ -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() { - log.debug("Hello from uoa-monitor-service!"); - return "Hello from uoa-monitor-service!"; + @RequestMapping(value = {"", "/", "/health_check"}, method = RequestMethod.GET) + public ResponseEntity hello() { + log.debug("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 checkEverything() { - return this.service.checkEverything(); + public ResponseEntity> checkEverything() { + return ResponseEntity.ok(this.service.getProperties()); } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java index cd52afa..59071be 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java @@ -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 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 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 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)); } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java index 21424cd..01129b7 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java @@ -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 getAllReservedStakeholderAlias(@RequestParam(required = false) String type) { + public ResponseEntity> getAllReservedStakeholderAlias(@RequestParam(required = false, name = "type") String type) { List 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 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 getAllStakeholders(@RequestParam(required = false) String type) { - return this.stakeholderService.getAll(type); + public ResponseEntity> getAllStakeholders(@RequestParam(required = false, name = "type") String type) { + return ResponseEntity.ok(this.stakeholderService.getAll(type)); } @RequestMapping(value = "/stakeholder", method = RequestMethod.GET) - public List getVisibleStakeholders(@RequestParam(required = false) String type, - @RequestParam(required = false) String defaultId) { - return stakeholderService.getVisibleStakeholders(type, defaultId); + public ResponseEntity> 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 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 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 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 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 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 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 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 updateUmbrella(@PathVariable("stakeholderId") String stakeholderId, @RequestBody UpdateUmbrella update) { + public ResponseEntity> 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)); } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java index bacfd55..8ba731d 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java @@ -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 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 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 reorderSubCategories(@PathVariable("stakeholderId") String stakeholderId, + public ResponseEntity> reorderSubCategories(@PathVariable("stakeholderId") String stakeholderId, @PathVariable("topicId") String topicId, @PathVariable("categoryId") String categoryId, @RequestBody List 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 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)); } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java index eff029e..806e849 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java @@ -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 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 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 reorderTopics(@PathVariable("stakeholderId") String stakeholderId, + public ResponseEntity> reorderTopics(@PathVariable("stakeholderId") String stakeholderId, @RequestBody List 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 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)); } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/CategoryDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/CategoryDAO.java index 4c3d755..8738a14 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/CategoryDAO.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/dao/CategoryDAO.java @@ -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 { - List findAll(); List findByDefaultId(String DefaultId); + List findBySubCategoriesContaining(List subCategories); - List findBySubCategoriesContaining(String subCategory); - - Optional findById(String Id); - - void delete(String Id); - - Category save(Category category); + default List findBySubCategory(String subCategory) { + return findBySubCategoriesContaining(Collections.singletonList(subCategory)); + } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/IndicatorDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/IndicatorDAO.java index e121bae..7c27b4b 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/IndicatorDAO.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/dao/IndicatorDAO.java @@ -9,13 +9,5 @@ import java.util.Optional; @Repository public interface IndicatorDAO extends MongoRepository { - List findAll(); List findByDefaultId(String DefaultId); - - Optional findById(String Id); - - void delete(String Id); - - Indicator save(Indicator indicator); - //List saveAll(List indicators); } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/SectionDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/SectionDAO.java index 1bd2d4b..dcfa79a 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/SectionDAO.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/dao/SectionDAO.java @@ -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 { - List
findAll(); List
findByDefaultId(String DefaultId); - List
findByIndicatorsContaining(String id); + List
findByIndicatorsContaining(List indicators); - Optional
findById(String Id); - - void delete(String Id); - - Section save(Section indicator); + default List
findByIndicator(String indicator) { + return findByIndicatorsContaining(Collections.singletonList(indicator)); + } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/StakeholderDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/StakeholderDAO.java index e143b83..f1ff8e0 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/StakeholderDAO.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/dao/StakeholderDAO.java @@ -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 { /** * All Stakeholders */ - List findAll(); - List findByDefaultId(String id); List findByType(StakeholderType Type); @@ -182,17 +181,11 @@ public interface StakeholderDAO extends MongoRepository { /** * Other method */ - List findByDefaultIdAndCopyIsTrue(String defaultId); - - List findByTopicsContaining(String topic); - - Optional findById(String id); - Optional findByAlias(String alias); + List findByTopicsContaining(List topics); - - void delete(String Id); - - Stakeholder save(Stakeholder stakeholder); + default List findByTopic(String topic) { + return this.findByTopicsContaining(Collections.singletonList(topic)); + } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/SubCategoryDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/SubCategoryDAO.java index 86bcecd..3cd93be 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/SubCategoryDAO.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/dao/SubCategoryDAO.java @@ -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 { - List findAll(); List findByDefaultId(String defaultId); - List findByNumbersContaining(String id); - List findByChartsContaining(String id); + List findByNumbersContaining(List numbers); - Optional findById(String Id); + default List findByNumber(String number) { + return findByNumbersContaining(Collections.singletonList(number)); + } - void delete(String Id); + List findByChartsContaining(List charts); - SubCategory save(SubCategory subCategory); + default List findByChart(String chart) { + return findByChartsContaining(Collections.singletonList(chart)); + } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dao/TopicDAO.java b/src/main/java/eu/dnetlib/uoamonitorservice/dao/TopicDAO.java index 9b7f3f0..073b59c 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/dao/TopicDAO.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/dao/TopicDAO.java @@ -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 { - List findAll(); List findByDefaultId(String DefaultId); + List findByCategoriesContaining(List categories); - List findByCategoriesContaining(String category); - - Optional findById(String Id); - - void delete(String Id); - - Topic save(Topic topic); + default List findByCategory(String category) { + return findByCategoriesContaining(Collections.singletonList(category)); + } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/dto/SectionFull.java b/src/main/java/eu/dnetlib/uoamonitorservice/dto/SectionFull.java index 06643bd..efe2ea5 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/dto/SectionFull.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/dto/SectionFull.java @@ -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; diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/handlers/BadRequestException.java b/src/main/java/eu/dnetlib/uoamonitorservice/handlers/BadRequestException.java index a0e65ae..90a0316 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/handlers/BadRequestException.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/handlers/BadRequestException.java @@ -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); } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/handlers/EntityNotFoundException.java b/src/main/java/eu/dnetlib/uoamonitorservice/handlers/EntityNotFoundException.java deleted file mode 100644 index fc4d645..0000000 --- a/src/main/java/eu/dnetlib/uoamonitorservice/handlers/EntityNotFoundException.java +++ /dev/null @@ -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); - } -} diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/handlers/ExceptionsHandler.java b/src/main/java/eu/dnetlib/uoamonitorservice/handlers/ExceptionsHandler.java deleted file mode 100644 index 569e1d9..0000000 --- a/src/main/java/eu/dnetlib/uoamonitorservice/handlers/ExceptionsHandler.java +++ /dev/null @@ -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 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(response, HttpStatus.NOT_FOUND); - } - - @ExceptionHandler(BadRequestException.class) - public ResponseEntity 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(response, HttpStatus.BAD_REQUEST); - } - - @ExceptionHandler(PathNotValidException.class) - public ResponseEntity 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(response, HttpStatus.NOT_FOUND); - } - -} diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/handlers/PathNotValidException.java b/src/main/java/eu/dnetlib/uoamonitorservice/handlers/PathNotValidException.java index 4c1afa6..084f235 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/handlers/PathNotValidException.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/handlers/PathNotValidException.java @@ -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); } } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/service/CategoryService.java b/src/main/java/eu/dnetlib/uoamonitorservice/service/CategoryService.java index 58837a8..6e302f7 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/service/CategoryService.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/service/CategoryService.java @@ -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); diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/service/CommonService.java b/src/main/java/eu/dnetlib/uoamonitorservice/service/CommonService.java index 2f0acfb..3360ade 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/service/CommonService.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/service/CommonService.java @@ -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 diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/service/IndicatorService.java b/src/main/java/eu/dnetlib/uoamonitorservice/service/IndicatorService.java index 216d877..d02b407 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/service/IndicatorService.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/service/IndicatorService.java @@ -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 subCategories = this.subCategoryDAO.findByNumbersContaining(section.getId()); - subCategories.addAll(this.subCategoryDAO.findByChartsContaining(section.getId())); + List 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); diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/service/MonitorDeployService.java b/src/main/java/eu/dnetlib/uoamonitorservice/service/MonitorDeployService.java index c25daee..87de20f 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/service/MonitorDeployService.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/service/MonitorDeployService.java @@ -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 checkEverything() { - Map 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 getProperties() { + Map 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()); } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/service/SectionService.java b/src/main/java/eu/dnetlib/uoamonitorservice/service/SectionService.java index 346e06c..73bfe15 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/service/SectionService.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/service/SectionService.java @@ -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 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 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); diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/service/StakeholderService.java b/src/main/java/eu/dnetlib/uoamonitorservice/service/StakeholderService.java index a53ca73..f3cfe66 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/service/StakeholderService.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/service/StakeholderService.java @@ -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 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 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 addType(String id, StakeholderType type) { Stakeholder stakeholder = this.findByPath(id); - Umbrella umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new EntityNotFoundException("Umbrella not found in the stakeholder with id " + id)); + Umbrella 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 removeType(String id, StakeholderType type) { Stakeholder stakeholder = this.findByPath(id); - Umbrella umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new EntityNotFoundException("Umbrella not found in the stakeholder with id " + id)); + Umbrella 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 addChild(String id, StakeholderType type, String childId) { Stakeholder stakeholder = this.findByPath(id); - Umbrella umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new EntityNotFoundException("Umbrella not found in the stakeholder with id " + id)); + Umbrella 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 removeChild(String id, StakeholderType type, String childId) { Stakeholder stakeholder = this.findByPath(id); - Umbrella umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new EntityNotFoundException("Umbrella not found in the stakeholder with id " + id)); + Umbrella 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 updateTypes(String id, List types) { Stakeholder stakeholder = this.findByPath(id); - Umbrella umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new EntityNotFoundException("Umbrella not found in the stakeholder with id " + id)); + Umbrella 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 updateChildren(String id, StakeholderType type, List children) { Stakeholder stakeholder = this.findByPath(id); - Umbrella umbrella = stakeholder.getUmbrellaOptional().orElseThrow(() -> new EntityNotFoundException("Umbrella not found in the stakeholder with id " + id)); + Umbrella 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()); diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/service/SubCategoryService.java b/src/main/java/eu/dnetlib/uoamonitorservice/service/SubCategoryService.java index ecda2fa..a73bb63 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/service/SubCategoryService.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/service/SubCategoryService.java @@ -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); diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/service/TopicService.java b/src/main/java/eu/dnetlib/uoamonitorservice/service/TopicService.java index 0d5236d..11df5d2 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/service/TopicService.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/service/TopicService.java @@ -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); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index df3653a..deaaeb6 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -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} \ No newline at end of file +# temp until refactoring the code in admin tools library +spring.main.allow-circular-references=true diff --git a/src/main/resources/monitorservice.properties b/src/main/resources/monitorservice.properties index 86a31d4..8b2c944 100644 --- a/src/main/resources/monitorservice.properties +++ b/src/main/resources/monitorservice.properties @@ -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 \ No newline at end of file From 69c2a50334d055ca3edee51b43707298efd47f2e Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Wed, 16 Oct 2024 23:36:10 +0300 Subject: [PATCH 2/4] Update notification-service and admin-tools-library --- pom.xml | 4 ++-- .../controllers/MonitorServiceCheckDeployController.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 1b1472e..3b66ddf 100644 --- a/pom.xml +++ b/pom.xml @@ -29,12 +29,12 @@ eu.dnetlib uoa-admin-tools-library - 2.0.0 + 2.0.1 eu.dnetlib uoa-notification-service - 2.0.4 + 2.0.5 diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java index 400d65e..92f3a4c 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.java @@ -23,8 +23,8 @@ public class MonitorServiceCheckDeployController { @RequestMapping(value = {"", "/", "/health_check"}, method = RequestMethod.GET) public ResponseEntity hello() { - log.debug("Hello from uoa-monitor-service library!"); - return ResponseEntity.ok("Hello from uoa-monitor-service library!"); + log.debug("Hello from uoa-monitor-service!"); + return ResponseEntity.ok("Hello from uoa-monitor-service!"); } @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)") From 45d17cd2b85deb06a9f6b270497dafc971e34fa0 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Wed, 16 Oct 2024 23:36:48 +0300 Subject: [PATCH 3/4] [maven-release-plugin] prepare release uoa-monitor-service-2.0.0 --- pom.xml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 3b66ddf..304b26e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,5 @@ - + eu.dnetlib uoa-spring-boot-parent @@ -9,12 +7,13 @@ 4.0.0 uoa-monitor-service - 2.0.0-SNAPSHOT + 2.0.0 war uoa-monitor-service scm:git:gitea@code-repo.d4science.org:MaDgIK/uoa-monitor-service.git - + uoa-monitor-service-2.0.0 + UTF-8 UTF-8 @@ -67,8 +66,8 @@ **/eu/dnetlib/uoamonitorservice/application/** **/eu/dnetlib/uoamonitorservice/controllers/MonitorServiceCheckDeployController.class - - + + From d599b7bb2d3f72a4b987cab633f26186d387b369 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Wed, 16 Oct 2024 23:36:53 +0300 Subject: [PATCH 4/4] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 304b26e..02e8ddc 100644 --- a/pom.xml +++ b/pom.xml @@ -7,12 +7,12 @@ 4.0.0 uoa-monitor-service - 2.0.0 + 2.0.1-SNAPSHOT war uoa-monitor-service scm:git:gitea@code-repo.d4science.org:MaDgIK/uoa-monitor-service.git - uoa-monitor-service-2.0.0 + HEAD UTF-8