Compare commits

..

No commits in common. "master" and "reposByCountry" have entirely different histories.

43 changed files with 428 additions and 1003 deletions

221
README.md
View File

@ -1,218 +1,9 @@
# OpenAIRE Provide - backend service
# Provide
## Introduction
OpenAIRE PROVIDE is the content gateway service of OpenAIRE, where data providers are invited to connect scholarly content with OpenAIRE.<br>
OpenAIRE PROVIDE allows repositories, data archives, journals, aggregators, CRIS systems, to enter the OpenAIRE and European Open Science (EOSC) ecosystem and be accessible by millions of researchers, research institutes and networks, research funders, policy makers and citizens.<br>
OpenAIRE PROVIDE lowers any technological barriers, by supporting a series of integrations, therefore, enabling its users to visually access OpenAIRE's services that are responsible for the data harvesting process.
<br><br>
There are four distinctive steps from the initial express of interest for OpenAIRE PROVIDE to the actual content availability on OpenAIRE and EOSC.
<br>
The steps indicate the important subservices of OpenAIRE that perform the following functionalities:
- Validation of data sources with the OpenAIRE guidelines (via the OpenAIRE Validator)
- Registration of data sources to OpenAIRE and global interlinked networks provides links to content for text and data mining, view history of validations, status of harvesting Enrichment of metadata information that describes the data sources to be available through OpenAIRE.
- Subscribe and view/receive notifications to enrich the metadata or the content of the data source (via the OpenAIRE Broker)
- View usage statistics of Open research impact by subscribing to the OpenAIRE UsageCounts service; view aggregated, cleaned usage stats for repository access and broaden your mechanisms for impact assessment.
<br>
## Architecture
[...]
<br>
## Building
The backend is a [Maven](https://maven.apache.org/index.html) project. It has been tested using Java 8.
<br>
#### Manual Build Instructions
###### Requirements:
- Java 8
- Apache Maven 3+
###### Build Instructions:
1. Clone the repository and move inside the directory
<br> `git clone https://code-repo.d4science.org/MaDgIK/uoa-repository-manager-service.git && cd uoa-repository-manager-service`
2. Provide all not-set or redacted configurations, inside the **src/main/resources/application.yml** file.
3. Build Maven project
<br> `mvn clean package`
<br> Produces the file "./target/**uoa-repository-manager-service.jar**" which can be run with: - Run the app with: `java -jar ./target/uoa-repository-manager-service.jar`
#### Build using Docker
The repository contains a **Dockerfile** which can be used to build an image containing the compiled project.
###### Requirements:
- Docker
###### Build Instructions:
1. Clone the repository and move inside the directory
<br> `git clone https://code-repo.d4science.org/MaDgIK/uoa-repository-manager-service.git && cd uoa-repository-manager-service`
2. Provide all not-set or redacted configurations, inside the **src/main/resources/application.yml** file.
3. Build Docker image
<br> `docker build . -t <docker-image-name>`
<br>
## Configuration
The configuration can be set inside the **src/main/resources/application.yml** file.
### Server-related configuration.
```
server:
port: 8480
servlet:
context-path: /uoa-repository-manager-service
```
### Swagger UI - related configuration
```
springdoc:
swagger-ui:
disable-swagger-default-url: true
path: /swagger-ui.html
displayRequestDuration: true
api-docs:
path: /api-docs
```
### Datasource -related configuration
```
spring:
jpa:
hibernate:
ddl-auto: update
datasource:
url: ${services.provide.db.url}
username: ${services.provide.db.username}
password: ${services.provide.db.password}
driverClassName: ${services.provide.db.driverClassName}
```
### Configurations about the provide service.
```
services:
openaireServicesBaseUrl: https://beta.services.openaire.eu
provide:
dev-machine: 88.197.53.71 # VM-71
```
### Configuration about Authentication and authorization infrastructure (AAI).
```
aai:
baseURL: https://aai.openaire.eu
oidc:
domain: .openaire.eu # use empty value for local, otherwise: ".openaire.eu"
id: XX
issuer: ${services.provide.aai.baseURL}/oidc/
redirectURL: http://localhost:${server.port}${server.servlet.context-path}/openid_connect_login
secret: XX
webURL: http://localhost:4200/join
registry:
coid: XX
username: XX
password: XX
production: false
url: ${services.provide.aai.baseURL}/registry/
```
### Broker's configuration
```
broker:
api: api/
openaire: openaireBroker
port: 443
url: https://beta.broker.openaire.eu
```
### Client's configuration
```
clients:
dsm: ${services.provide.baseUrl}
search: ${services.openaireServicesBaseUrl}/search/v2/api
usageEvents: http://beta.lbs.openaire.eu:8080/ajax/summary
usagestats: ${services.openaireServicesBaseUrl}/usagestats
```
### Database configuration for Provide.
```
db:
driverClassName: org.postgresql.Driver
password: dnetPwd
url: jdbc:postgresql://${services.provide.dev-machine}:5432/repomanager
username: dnet
```
### Configuration for the IS LookUp service.
```
iSLookUpService:
url: https://dev-openaire.d4science.org:443/is/services/isLookUp
```
### Mail-server configuration.
```
mail:
authenticate: true
debug: false
from: XX
host: smtp.gmail.com
mode: ssl
password: XX
port: 465
replyTo: XX
username: XX
```
### Redis's configuration
```
redis:
host: vereniki.athenarc.gr
password: XX
port: 6379
```
### Usage statistics
```
usageStatisticsDiagramsBaseURL: https://beta.openaire.eu/stats3/
usageStatisticsNumbersBaseURL: ${services.openaireServicesBaseUrl}/usagestats/datasources/
usagestats:
adminEmail: XX
sushiliteEndpoint: ${services.openaireServicesBaseUrl}/usagestats/sushilite/
sushiliteR5Endpoint: ${services.openaireServicesBaseUrl}/usagestats_r5/sushilite/r5/
```
### Validator - related configuration.
```
validator:
results:
url: https://beta.provide.openaire.eu/compatibility/browseHistory/
validatorService:
url: http://${services.provide.dev-machine}:8080/uoa-validator-service/services/validatorWebService
```
### Miscellaneous
```
topic_types:
url: ${services.openaireServicesBaseUrl}/provision/mvc/vocabularies/dnet:topic_types.json
adminEmail: XX
analyticsURL: https://analytics.openaire.eu/addsite.php?
baseUrl: ${services.openaireServicesBaseUrl}/openaire
```
<br>
## Deployment
### Prerequisites
* install [PostgreSQL 9.5+](https://www.postgresql.org/)
* Run the app with: `java -jar ./target/uoa-repository-manager-service.jar --spring.config.location=application.yml`
<br>
## misc
### Notes for Swagger-UI:
- Access it through this url: http://localhost:8480/uoa-repository-manager-service/swagger-ui/index.html
- In order to request data from most endpoints, you have to be a "REGISTERED_USER", otherwise you will get a 403 error code.
- In order to be a registered user, you have to run the [UI-service](https://code-repo.d4science.org/MaDgIK/uoa-repository-manager-ui) , in the same machine, at the same time and login through a browser, using the following url: http://localhost:8480/uoa-repository-manager-service/openid_connect_login
## Install and run:
- Run **git clone** and then **cd uoa-repository-manager-service**.
- Provide all not-set or redacted configurations, inside the **src/main/resources/application.properties** file.
- Build the app with: `mvn clean install`
- Run the app with: `java -jar ./target/uoa-repository-manager-service.jar`

154
pom.xml
View File

@ -6,8 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.18</version>
<relativePath></relativePath>
<version>2.5.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -17,14 +16,13 @@
<packaging>jar</packaging>
<properties>
<spring.boot.version>2.7.18</spring.boot.version>
<spring.boot.version>2.5.4</spring.boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
@ -35,81 +33,47 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${spring.boot.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>${spring.boot.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.224</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>9.1.1</version>
</dependency>
<dependency>
<groupId>eu.dnetlib.dhp</groupId>
<artifactId>dnet-exporter-model</artifactId>
<version>[3.5.1, )</version>
<exclusions>
<exclusion>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-common</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-registry-prometheus -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.12.4</version>
<artifactId>dnet-exporter-api</artifactId>
<version>[3.3.3-SNAPSHOT, )</version>
</dependency>
<dependency>
@ -121,6 +85,7 @@
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
@ -158,11 +123,6 @@
<artifactId>dnet-openaire-usage-stats-sushilite</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>dnet-openaire-usage-stats-sushilite-r5</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>eu.dnetlib.dhp</groupId>
<artifactId>dnet-openaire-broker-common</artifactId>
@ -174,17 +134,16 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>3.3.0</version>
<version>2.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.16.0</version>
<version>2.4</version>
</dependency>
<dependency>
@ -192,58 +151,63 @@
<artifactId>oai4j</artifactId>
<version>[0.6b1,)</version>
</dependency>
<!-- TODO - Do we need this? -->
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.3</version>
<version>2.7.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-client -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>2.42</version>
<version>1.19.3</version>
</dependency>
<!-- TODO - Do we need this? We already have: "com.google.code.gson:gson" -->
<dependency>
<groupId>org.aksw.gson</groupId>
<artifactId>gson-utils-core</artifactId>
<version>1.0.1</version>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20240303</version>
<version>20080701</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
<version>1.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/postgresql/postgresql -->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.3</version>
<version>9.1-901.jdbc3</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.5</version>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.mitre</groupId>
<artifactId>openid-connect-client</artifactId>
<version>1.3.4</version>
<version>1.3.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
@ -254,40 +218,36 @@
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<version>2.7.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version> <!-- This property comes from the parent-pom. -->
<version>${jedis.version}</version>
<!--<version>3.7.0</version>-->
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>com.thetransactioncompany</groupId>
<artifactId>cors-filter</artifactId>
<version>3.0</version>
<version>2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.xml.ws/jaxws-api -->
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
<version>2.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.jws/javax.jws-api -->
<dependency>
@ -298,23 +258,23 @@
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.9</version>
<version>2.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
<version>1.1-rev-1</version>
</dependency>
<dependency>
@ -337,7 +297,7 @@
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-bom</artifactId>
<version>2021.2.3</version>
<version>2021.0.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -351,7 +311,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
@ -361,23 +321,22 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.4.0</version>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
-->
</plugin>
-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
</plugin>
<plugin>
<groupId>cz.habarta.typescript-generator</groupId>
<artifactId>typescript-generator-maven-plugin</artifactId>
<version>2.37.1128</version>
<version>2.16.538</version>
<executions>
<execution>
<id>java to typeScript</id>
@ -408,15 +367,6 @@
</build>
<repositories>
<repository>
<id>central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>dnet45-bootstrap-snapshot</id>
<name>D-Net 45 Bootstrap Snapshot</name>
@ -471,12 +421,6 @@
<enabled>false</enabled>
</releases>
</repository>
<!-- Use this when testing local JARs. -->
<!--<repository>
<id>libs</id>
<url>file:///${project.basedir}/libs</url>
</repository>-->
</repositories>
</project>

View File

@ -1,16 +1,12 @@
package eu.dnetlib.repo.manager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableJpaRepositories
@EnableScheduling
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
package eu.dnetlib.repo.manager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@ -1,20 +0,0 @@
package eu.dnetlib.repo.manager.components;
import eu.dnetlib.repo.manager.service.PendingUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class ScheduledTasks {
@Autowired
PendingUserRoleService pendingUserRoleService;
@Scheduled(fixedRate = 3_600_000)
public void assignPendingRoles() {
pendingUserRoleService.assignRoles();
}
}

View File

@ -63,15 +63,12 @@ public class AaiSecurityConfiguration extends WebSecurityConfigurerAdapter {
.csrf().disable()
.authorizeRequests()
.regexMatchers("/actuator/.*").permitAll()
.regexMatchers("/repositories/.*/metrics/?.*").permitAll()
.regexMatchers("/metrics").permitAll()
.antMatchers("/api-docs/**","/swagger-ui/**").permitAll()
.anyRequest().authenticated()
.and()
.logout().logoutUrl("/openid_logout")
.clearAuthentication(true)
.invalidateHttpSession(true)
.deleteCookies()
.deleteCookies("openAIRESession")
.logoutSuccessUrl(logoutSuccessUrl)
.and()
.addFilterBefore(openIdConnectAuthenticationFilter(), AbstractPreAuthenticatedProcessingFilter.class)

View File

@ -1,17 +0,0 @@
package eu.dnetlib.repo.manager.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
@Configuration
public class JPAConfig {
@Bean
public PlatformTransactionManager transactionManager() {
return new JpaTransactionManager();
}
}

View File

@ -1,23 +0,0 @@
package eu.dnetlib.repo.manager.config;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
@OpenAPIDefinition(
info = @Info(
title = "Repository Manager Dashboard API Documentation",
description = "Repository Manager Dashboard API Documentation",
version = "1.0",
termsOfService = "urn:tos",
license = @License(
name = "Apache 2.0",
url = "https://www.apache.org/licenses/LICENSE-2.0.html"
),
contact = @Contact(name = "", url = "", email = "")
)
)
public class OpenAPIConfiguration {
}

View File

@ -0,0 +1,47 @@
package eu.dnetlib.repo.manager.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
/**
* Created by panagiotis on 16/11/2017.
*/
@Configuration
@EnableSwagger2
@EnableWebMvc
public class SwaggerConfig {
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.pathMapping("/")
.apiInfo(getApiInfo());
}
private ApiInfo getApiInfo() {
return new ApiInfo("Repository Manager Dashboard API Documentation",
"Repository Manager Dashboard API Documentation",
"1.0",
"urn:tos",
new Contact("", "", ""),
"Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0",
new ArrayList<VendorExtension>());
}
}

View File

@ -4,8 +4,8 @@ import eu.dnetlib.repo.manager.domain.Term;
import eu.dnetlib.repo.manager.domain.broker.*;
import eu.dnetlib.repo.manager.exception.BrokerException;
import eu.dnetlib.repo.manager.service.BrokerServiceImpl;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired;
@ -21,7 +21,7 @@ import java.util.Map;
@RestController
@RequestMapping(value = "/broker")
@Tag(name="broker", description="Broker API")
@Api(description = "Broker API", tags = {"broker"})
public class BrokerController{
@Autowired
@ -33,9 +33,9 @@ public class BrokerController{
@PreAuthorize("hasAuthority('REGISTERED_USER')")
public DatasourcesBroker getDatasourcesOfUser(
@RequestParam("includeShared")
@Parameter(description = "Include shared datasources (default = false)", required = true) String includeShared,
@ApiParam(value = "Include shared datasources", required = true , defaultValue = "false") String includeShared,
@RequestParam("includeByOthers")
@Parameter(description = "Include datasources of other (default = false)", required = true) String includeByOthers) throws JSONException {
@ApiParam(value = "Include datasources of other", required = true,defaultValue = "false") String includeByOthers) throws JSONException {
return brokerService.getDatasourcesOfUser(((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail(), includeShared, includeByOthers);
}

View File

@ -1,6 +1,6 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.openaire.exporter.model.dsm.AggregationInfo;
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
import eu.dnetlib.repo.manager.domain.BrokerSummary;
import eu.dnetlib.repo.manager.domain.CollectionMonitorSummary;
import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
@ -8,7 +8,7 @@ import eu.dnetlib.repo.manager.domain.UsageSummary;
import eu.dnetlib.repo.manager.exception.BrokerException;
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
import eu.dnetlib.repo.manager.service.*;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired;
@ -21,7 +21,7 @@ import java.util.List;
@RestController
@RequestMapping(value = "/dashboard")
@Tag(name="dashboard", description = "Dashboard API")
@Api(description = "Dashboard API", tags = {"dashboard"})
public class DashboardController {
@Autowired

View File

@ -4,8 +4,8 @@ import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.domain.JobsOfUser;
import eu.dnetlib.repo.manager.service.MonitorServiceImpl;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "/monitor")
@Tag(name="monitor", description="Monitor API")
@Api(description = "Monitor API", tags = {"monitor"})
public class MonitorController {
private static final Logger logger = LoggerFactory.getLogger(MonitorController.class);
@ -31,13 +31,13 @@ public class MonitorController {
@ResponseBody
@PreAuthorize("hasAuthority('REGISTERED_USER')")
public JobsOfUser getJobsOfUser(@RequestParam(value = "jobType", required = false)
@Parameter(description = "Equals to filter job type on validation history page") String jobType,
@RequestParam("offset") @Parameter(name = "Page number", required = true) String offset,
@RequestParam(value = "limit", required = false,defaultValue = "10") @Parameter(description = "Null value") String limit,
@RequestParam(value = "dateFrom", required = false) @Parameter(description = "Null value") String dateFrom,
@RequestParam(value = "dateTo", required = false) @Parameter(description = "Null value") String dateTo,
@RequestParam("validationStatus") @Parameter(description = "Equals to filter validation jobs", required = false) String validationStatus,
@RequestParam("includeJobsTotal") @Parameter(description = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException {
@ApiParam(value = "Equals to filter job type on validation history page") String jobType,
@RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset,
@RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit,
@RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom,
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = false) String validationStatus,
@RequestParam("includeJobsTotal") @ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException {
return monitorService.getJobsOfUser(((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail(), jobType, offset, limit, dateFrom, dateTo, validationStatus, includeJobsTotal);
}

View File

@ -6,9 +6,9 @@ import eu.dnetlib.repo.manager.domain.OrderByType;
import eu.dnetlib.repo.manager.domain.Paging;
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
import eu.dnetlib.repo.manager.service.PiWikServiceImpl;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -31,7 +31,7 @@ import java.util.List;
@RestController
@RequestMapping(value = "/piwik")
@Tag(name="piwik", description = "Piwik API")
@Api(description = "Piwik API", tags = {"piwik"})
public class PiWikController {
private static final Logger logger = LoggerFactory.getLogger(PiWikController.class);
@ -39,16 +39,6 @@ public class PiWikController {
@Autowired
private PiWikServiceImpl piWikService;
@RequestMapping(value = "/validated", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Boolean isPiwikValidated(@RequestParam("repositoryId") String repositoryId) {
PiwikInfo info = piWikService.getPiwikSiteForRepo(repositoryId);
if (info != null) {
return info.isValidated();
}
return false;
}
@RequestMapping(value = "/getPiwikSiteForRepo/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOf(#repositoryId) or (@repositoryService.getRepositoryById(#repositoryId).registeredby==null and hasAuthority('REGISTERED_USER'))")
@ -63,17 +53,17 @@ public class PiWikController {
}
@RequestMapping(value = "/getPiwikSitesForRepos" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@Parameters({
@Parameter(name = "from", description = "number"),
@Parameter(name = "quantity", description = "number"),
@Parameter(name = "order", description = "eu.dnetlib.repo.manager.domain.OrderByType"),
@Parameter(name = "orderField", description = "eu.dnetlib.repo.manager.domain.OrderByField"),
@Parameter(name = "searchField", description = "string")
@ApiImplicitParams({
@ApiImplicitParam(name = "from", dataType = "number", paramType = "query"),
@ApiImplicitParam(name = "quantity", dataType = "number", paramType = "query"),
@ApiImplicitParam(name = "order", dataType = "eu.dnetlib.repo.manager.domain.OrderByType", paramType = "query"),
@ApiImplicitParam(name = "orderField", dataType = "eu.dnetlib.repo.manager.domain.OrderByField", paramType = "query"),
@ApiImplicitParam(name = "searchField", dataType = "string", paramType = "query"),
})
public Paging<PiwikInfo> getPiwikSitesForRepos(
@RequestParam(value = "from", required=false, defaultValue = "0") int from,
@RequestParam(value = "quantity", required=false, defaultValue = "100") int quantity,
@RequestParam(value = "order", required=false, defaultValue = "DSC") OrderByType orderType,
@RequestParam(value = "from",required=false,defaultValue = "0") int from,
@RequestParam(value = "quantity",required=false,defaultValue = "100") int quantity,
@RequestParam(value = "order",required=false,defaultValue = "DSC") OrderByType orderType,
@RequestParam(value = "orderField", required = false, defaultValue = "REPOSITORY_NAME") OrderByField orderField,
@RequestParam(value = "searchField", required = false, defaultValue = "") String searchField
@ -87,12 +77,12 @@ public class PiWikController {
return results;
}
@Parameters({
@Parameter(name = "from", description = "number"),
@Parameter(name = "quantity", description = "number"),
@Parameter(name = "order", description = "eu.dnetlib.repo.manager.domain.OrderByType"),
@Parameter(name = "searchField", description = "eu.dnetlib.repo.manager.domain.OrderByField"),
@Parameter(name = "orderField", description = "string")
@ApiImplicitParams({
@ApiImplicitParam(name = "from", dataType = "number", paramType = "query"),
@ApiImplicitParam(name = "quantity", dataType = "number", paramType = "query"),
@ApiImplicitParam(name = "order", dataType = "eu.dnetlib.repo.manager.domain.OrderByType", paramType = "query"),
@ApiImplicitParam(name = "searchField", dataType = "eu.dnetlib.repo.manager.domain.OrderByField", paramType = "query"),
@ApiImplicitParam(name = "orderField", dataType = "string", paramType = "query"),
})
@RequestMapping(value = "/getPiwikSitesForRepos/csv" , method = RequestMethod.GET,produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody

View File

@ -23,8 +23,8 @@ import java.io.File;
@RestController
@RequestMapping(value = "/actuator/prometheus", produces = "application/openmetrics-text; version=1.0.0; charset=utf-8")
public class PrometheusController {
@RequestMapping("/actuator/prometheus")
public class PrometheusController { // TODO: remove this with migration to Spring Boot 2
private static final Logger logger = LoggerFactory.getLogger(PrometheusController.class);
private final PiWikService piWikService;
@ -36,12 +36,12 @@ public class PrometheusController {
this.repositoryService = repositoryService;
}
@RequestMapping(method = RequestMethod.GET)
@RequestMapping(method = RequestMethod.GET, path = "", produces = MediaType.TEXT_PLAIN_VALUE)
public String getPiwikMetrics() {
PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
registry.gauge("provide_repositories_registered", repositoryService.getTotalRegisteredRepositories());
registry.gauge("provide_usagecounts_repositories_registered", piWikService.getTotal());
registry.gauge("provide_usagecounts_repositories_validated", piWikService.getValidated(true));
registry.counter("provide_repositories_registered").increment(repositoryService.getTotalRegisteredRepositories());
registry.counter("provide_usagecounts_repositories_registered").increment(piWikService.getTotal());
registry.counter("provide_usagecounts_repositories_validated").increment(piWikService.getValidated(true));
return registry.scrape(TextFormat.CONTENT_TYPE_OPENMETRICS_100);
}

View File

@ -1,18 +1,16 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.openaire.exporter.model.dsm.AggregationInfo;
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
import eu.dnetlib.repo.manager.domain.*;
import eu.dnetlib.repo.manager.domain.dto.RepositoryTerms;
import eu.dnetlib.repo.manager.domain.dto.User;
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.service.AggregationService;
import eu.dnetlib.repo.manager.service.PiWikService;
import eu.dnetlib.repo.manager.service.RepositoryService;
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
import eu.dnetlib.repo.manager.utils.JsonUtils;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
@ -34,7 +32,7 @@ import java.util.Map;
@RestController
@RequestMapping(value = "/repositories")
@Tag(name="repositories", description="Repository API")
@Api(description = "Repository API", tags = {"repositories"})
public class RepositoryController {
private static final Logger logger = LoggerFactory.getLogger(RepositoryController.class);
@ -45,17 +43,12 @@ public class RepositoryController {
private final AuthorizationService authorizationService;
private final PiWikService piWikService;
@Autowired
RepositoryController(RepositoryService repositoryService,
AggregationService aggregationService,
AuthorizationService authorizationService,
PiWikService piWikService) {
AggregationService aggregationService, AuthorizationService authorizationService) {
this.repositoryService = repositoryService;
this.aggregationService = aggregationService;
this.authorizationService = authorizationService;
this.piWikService = piWikService;
}
@RequestMapping(value = "/countries", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ -302,26 +295,4 @@ public class RepositoryController {
authorizationService.removeAdmin(id, email);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Returns whether the Piwik Site of a repository is enabled and validated.
*/
@RequestMapping(value = "{repositoryId}/metrics/valid", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public boolean getMetricsEnabledAndValidated(@PathVariable("repositoryId") String repositoryId) {
PiwikInfo info = piWikService.getPiwikSiteForRepo(repositoryId);
return info != null && info.isValidated();
}
/**
* Returns repository Metrics.
*/
@RequestMapping(value = "{repositoryId}/metrics", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public MetricsInfo getMetricsInfo(@PathVariable("repositoryId") String id) throws RepositoryServiceException {
return repositoryService.getMetricsInfoForRepository(id);
}
}

View File

@ -1,7 +1,7 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.service.StatsServiceImpl;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
@ -13,7 +13,7 @@ import java.util.Map;
@RestController
@RequestMapping(value = "/stats")
@Tag(name="statistics", description = "Stats API")
@Api(description = "Stats API", tags = {"statistics"})
public class StatsController {
@Autowired

View File

@ -1,8 +1,8 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.service.sushilite.SushiliteServiceImpl;
import eu.dnetlib.repo.manager.service.SushiliteServiceImpl;
import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
@ -10,9 +10,10 @@ import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "/sushilite")
@Tag(name="sushilite", description = "Sushi-Lite API")
@Api(description = "Sushi-Lite API", tags = {"sushilite"})
public class SushiliteController {
@Autowired
private SushiliteServiceImpl sushiliteService;

View File

@ -1,52 +0,0 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.service.sushilite.SushiliteR5ServiceImpl;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(value = "/sushiliteR5")
@Tag(name="sushiliteR5", description = "Sushi-Lite R5 API")
public class SushiliteR5Controller {
private static final Logger logger = LoggerFactory.getLogger(SushiliteR5Controller.class);
@Autowired
private SushiliteR5ServiceImpl sushiliteR5Service;
@RequestMapping(value = "/getReportResults", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasAuthority('REGISTERED_USER')")
public ResponseEntity<?> getReportResults(@RequestParam(value = "Report") String report,
@RequestParam(value = "Release", required=false, defaultValue="5") String release,
@RequestParam(value = "RequestorID",required=false, defaultValue="anonymous") String requestorID,
@RequestParam(value = "BeginDate",required=false, defaultValue="") String beginDate,
@RequestParam(value = "EndDate",required=false, defaultValue="") String endDate,
@RequestParam(value = "RepositoryIdentifier", required=false, defaultValue="") String repositoryIdentifier,
@RequestParam(value = "DatasetIdentifier", required=false, defaultValue="") String datasetIdentifier,
@RequestParam(value = "ItemIdentifier",required=false, defaultValue="") String itemIdentifier,
@RequestParam(value = "MetricType",required=false) List<String> metricTypes,
@RequestParam(value = "DataType",required=false, defaultValue="") String dataType,
@RequestParam(value = "Granularity", required = false, defaultValue ="Monthly") String granularity,
@RequestParam(value = "Pretty",required=false, defaultValue="") String pretty) {
try {
return sushiliteR5Service.getReportResults(report, release, requestorID, beginDate, endDate, repositoryIdentifier, datasetIdentifier, itemIdentifier, metricTypes, dataType, granularity, pretty);
} catch (JSONException je) {
logger.error("", je);
return ResponseEntity.internalServerError().build();
}
}
}

View File

@ -1,7 +1,7 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.service.UserServiceImpl;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/user")
@Tag(name="user", description = "User API")
@Api(description = "User API", tags = {"user"})
public class UserController {
@Autowired

View File

@ -9,8 +9,8 @@ import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.exception.ValidationServiceException;
import eu.dnetlib.repo.manager.service.EmailUtils;
import eu.dnetlib.repo.manager.service.ValidatorServiceImpl;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired;
@ -25,7 +25,7 @@ import java.util.List;
@RestController
@RequestMapping(value = "/validator")
@Tag(name="validator", description = "Validator API")
@Api(description = "Validator API", tags = {"validator"})
public class ValidatorController {
@Autowired
@ -80,12 +80,12 @@ public class ValidatorController {
@ResponseBody
@PreAuthorize("hasAuthority('REGISTERED_USER')")
public List<StoredJob> getStoredJobsNew(@RequestParam(value = "jobType", required = false)
@Parameter(description = "Equals to filter job type on validation history page") String jobType,
@RequestParam("offset") @Parameter(description = "Page number", required = true) String offset,
@RequestParam(value = "limit", required = false,defaultValue = "10") @Parameter(description = "Null value") String limit,
@RequestParam(value = "dateFrom", required = false) @Parameter(description = "Null value") String dateFrom,
@RequestParam(value = "dateTo", required = false) @Parameter(description = "Null value") String dateTo,
@RequestParam("validationStatus") @Parameter(description = "Equals to filter validation jobs", required = true) String validationStatus
@ApiParam(value = "Equals to filter job type on validation history page") String jobType,
@RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset,
@RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit,
@RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom,
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus
) throws ValidatorServiceException {
return validatorService.getStoredJobsNew(((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail(), jobType, offset, limit, dateFrom, dateTo, validationStatus);
}

View File

@ -0,0 +1,29 @@
package eu.dnetlib.repo.manager.domain;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import java.util.List;
@JsonAutoDetect
public class AggregationHistoryResponse extends Response {
private List<AggregationInfo> aggregationInfo;
public AggregationHistoryResponse() {
// no-arg constructor
}
public AggregationHistoryResponse(final List<AggregationInfo> aggregationInfo) {
super();
this.aggregationInfo = aggregationInfo;
}
public List<AggregationInfo> getAggregationInfo() {
return aggregationInfo;
}
public void setAggregationInfo(final List<AggregationInfo> aggregationInfo) {
this.aggregationInfo = aggregationInfo;
}
}

View File

@ -0,0 +1,8 @@
package eu.dnetlib.repo.manager.domain;
// TODO: this class must be replaced by common dnet class (CollectionInfo / TransformationInfo / AggregationInfo)
public class AggregationInfo extends eu.dnetlib.enabling.datasources.common.AggregationInfo {
public AggregationInfo() {
}
}

View File

@ -1,6 +1,6 @@
package eu.dnetlib.repo.manager.domain;
import eu.dnetlib.openaire.exporter.model.dsm.AggregationInfo;
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
import java.util.List;

View File

@ -1,53 +0,0 @@
package eu.dnetlib.repo.manager.domain;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class PendingUserRole {
@Id
long id;
int coPersonId;
int couId;
public PendingUserRole() {
// no-arg constructor
}
public PendingUserRole(int coPersonId, int couId) {
this.coPersonId = coPersonId;
this.couId = couId;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public int getCoPersonId() {
return coPersonId;
}
public void setCoPersonId(int coPersonId) {
this.coPersonId = coPersonId;
}
public int getCouId() {
return couId;
}
public void setCouId(int couId) {
this.couId = couId;
}
@Override
public String toString() {
return "PendingUserRole{" +
"coPersonId=" + coPersonId +
", couId=" + couId +
'}';
}
}

View File

@ -1,9 +0,0 @@
package eu.dnetlib.repo.manager.repository;
import eu.dnetlib.repo.manager.domain.PendingUserRole;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface PendingUserRoleRepository extends CrudRepository<PendingUserRole, Long> {
}

View File

@ -1,6 +1,6 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.openaire.exporter.model.dsm.AggregationInfo;
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
import org.json.JSONException;
import java.util.List;

View File

@ -1,7 +1,7 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.openaire.exporter.model.dsm.AggregationHistoryResponseV2;
import eu.dnetlib.openaire.exporter.model.dsm.AggregationInfo;
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
import eu.dnetlib.repo.manager.domain.AggregationHistoryResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
@ -41,7 +41,7 @@ public class AggregationServiceImpl implements AggregationService {
logger.debug("Retrieving aggregations for repository with id : " + id);
UriComponents uriComponents = getAggregationHistory(id);
AggregationHistoryResponseV2 rs = restTemplate.getForObject(uriComponents.toUri(), AggregationHistoryResponseV2.class);
AggregationHistoryResponse rs = restTemplate.getForObject(uriComponents.toUri(), AggregationHistoryResponse.class);
return rs != null ? (List<T>) rs.getAggregationInfo() : null;
}
@ -73,7 +73,7 @@ public class AggregationServiceImpl implements AggregationService {
private UriComponents getAggregationHistory(String repoId) {
return UriComponentsBuilder
.fromHttpUrl(baseAddress + "/dsm/2.0/aggregationhistory/")
.fromHttpUrl(baseAddress + "/ds/aggregationhistory/")
.path(repoId)
.build().expand(repoId).encode();
}

View File

@ -1,6 +1,6 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.openaire.exporter.model.dsm.AggregationInfo;
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
import eu.dnetlib.repo.manager.domain.MetricsNumbers;
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
@ -49,7 +49,7 @@ public class DashboardServiceImpl implements DashboardService {
repositorySummaryInfo.setRepositoryName(repoOfficialName);
repositorySummaryInfo.setLogoURL(repository.getLogoUrl());
//TODO getRepositoryAggregations returns only the 20 more recent items. Is it possible that we will find an indexed version there?
//TODO getRepositoryAggregations returns only the 20 more recent items. Is it positive that we will find an indexed version there?
boolean isIndexedVersionFound = false;
long start = System.currentTimeMillis();
List<AggregationInfo> aggregationInfoList = aggregationService.getRepositoryAggregations(repoId, 0, 20);

View File

@ -39,30 +39,20 @@ public class InterfaceComplianceService {
@Scheduled(cron = "0 0 0 * * *") // every day at 00:00
public void cleanUp() {
Set<InterfaceComplianceRequest> requests = getOutdated();
// TODO - In case we want to send the emails, uncomment the following code.
/*for ( InterfaceComplianceRequest request : requests )
{
String repoId = request.getRepositoryId();
String interfaceId = request.getInterfaceId();
for (InterfaceComplianceRequest request : requests) {
try {
Map<String, RepositoryInterface> repositoryInterfaceMap = repositoryService.getRepositoryInterface(repoId)
Map<String, RepositoryInterface> repositoryInterfaceMap = repositoryService.getRepositoryInterface(request.getRepositoryId())
.stream()
.collect(Collectors.toMap(ApiDetails::getId, i -> i));
RepositoryInterface iFace = repositoryInterfaceMap.get(interfaceId);
if ( iFace == null ) {
logger.error("The repository-interface \"" + interfaceId + "\" does not exist! | the request had the \"repoId\": \"" + repoId + "\"");
continue;
}
Repository repo = repositoryService.getRepositoryById(repoId);
List<User> repositoryAdmins = authorizationService.getAdminsOfRepo(repoId);
Repository repo = repositoryService.getRepositoryById(request.getRepositoryId());
RepositoryInterface iFace = repositoryInterfaceMap.get(request.getInterfaceId());
List<User> repositoryAdmins = authorizationService.getAdminsOfRepo(request.getRepositoryId());
emailUtils.sendUserUpdateInterfaceComplianceFailure(repositoryAdmins.stream().map(User::getEmail).collect(Collectors.toList()), repo, iFace, request);
emailUtils.sendAdminUpdateInterfaceComplianceFailure(repo, iFace, request);
} catch (ResourceNotFoundException e) {
logger.error("Error for request with \"repoId\": \"" + repoId + "\" and \"interfaceId\": \"" + interfaceId + "\"", e);
} // Continue to the next request.
}*/
logger.error("Error", e);
}
}
repository.deleteAll(requests);
}

View File

@ -1,36 +0,0 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.repo.manager.domain.PendingUserRole;
import eu.dnetlib.repo.manager.repository.PendingUserRoleRepository;
import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@Service
public class PendingUserRoleService {
private static final Logger logger = LoggerFactory.getLogger(PendingUserRoleService.class);
private final PendingUserRoleRepository pendingUserRoleRepository;
private final AaiRegistryService aaiRegistryService;
public PendingUserRoleService(PendingUserRoleRepository pendingUserRoleRepository,
AaiRegistryService aaiRegistryService) {
this.pendingUserRoleRepository = pendingUserRoleRepository;
this.aaiRegistryService = aaiRegistryService;
}
public void assignRoles() {
Iterable<PendingUserRole> roles = pendingUserRoleRepository.findAll();
for (PendingUserRole role : roles) {
logger.debug("Attempt to assign role: {}", role);
try {
aaiRegistryService.assignMemberRole(role.getCoPersonId(), role.getCouId());
pendingUserRoleRepository.deleteById(role.getId());
} catch (Exception e) {
logger.warn("Could not assign role to user. Pending Role: {}\n", role, e);
}
}
}
}

View File

@ -4,6 +4,7 @@ import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.repo.manager.domain.*;
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import org.json.JSONException;
import org.springframework.security.core.Authentication;
import java.util.List;

View File

@ -28,7 +28,6 @@ import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@ -39,7 +38,6 @@ import javax.annotation.PostConstruct;
import java.sql.Timestamp;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@Service("repositoryService")
public class RepositoryServiceImpl implements RepositoryService {
@ -286,14 +284,14 @@ public class RepositoryServiceImpl implements RepositoryService {
public List<Repository> getRepositoriesOfUser(String page, String size) {
logger.debug("Retrieving repositories of authenticated user : {}",
((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail());
Collection<String> repoIds = roleMappingService.getRepositoryIds(authorizationService.getUserRoles());
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles());
return getRepositories(new ArrayList<>(repoIds));
}
@Override
public List<Repository> getRepositoriesOfUser(String userEmail, String page, String size) {
logger.debug("Retrieving repositories of authenticated user : {}", userEmail);
Collection<String> repoIds = roleMappingService.getRepositoryIds(authorizationService.getUserRolesByEmail(userEmail));
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRolesByEmail(userEmail));
return getRepositories(new ArrayList<>(repoIds));
}
@ -306,7 +304,12 @@ public class RepositoryServiceImpl implements RepositoryService {
public List<RepositorySnippet> getRepositoriesSnippetsOfUser(String userEmail, String page, String size) {
int from = Integer.parseInt(page) * Integer.parseInt(size);
int to = from + Integer.parseInt(size);
List<String> repoIds = getRepoIdsOfUser(userEmail);
List<String> repoIds = new ArrayList<>();
if (userEmail != null && !"".equals(userEmail)) {
repoIds.addAll(roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRolesByEmail(userEmail)));
} else {
repoIds.addAll(roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles()));
}
if (repoIds.size() < from) {
return Collections.emptyList();
@ -531,8 +534,8 @@ public class RepositoryServiceImpl implements RepositoryService {
emailUtils.sendUserRegisterInterfaceEmail(repo, comment, repositoryInterface, desiredCompatibilityLevel, authentication);
String prevCompatibilityLevel = repositoryInterface.getCompatibility();
if ((desiredCompatibilityLevel != null)
&& ((prevCompatibilityLevel == null) || !prevCompatibilityLevel.equals(desiredCompatibilityLevel))) {
if ( (desiredCompatibilityLevel != null)
&& ((prevCompatibilityLevel == null) || ! prevCompatibilityLevel.equals(desiredCompatibilityLevel))) {
InterfaceComplianceRequest request = new InterfaceComplianceRequest(repoId, repositoryInterface.getId(), desiredCompatibilityLevel);
interfaceComplianceService.create(request);
}
@ -686,20 +689,19 @@ public class RepositoryServiceImpl implements RepositoryService {
public Map<String, String> getCompatibilityClasses(String mode) {
logger.debug("Getting compatibility classes for mode: {}", mode);
String lowercaseMode = mode.toLowerCase();
Map<String, String> retMap = new HashMap<>();
Map<String, String> compatibilityClasses = this.getVocabulary("dnet:compatibilityLevel").getAsMap();
boolean foundData = false;
for (Map.Entry<String, String> entry : compatibilityClasses.entrySet()) {
if (lowercaseMode.equals(Constants.REPOSITORY_MODE_ALL))
if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_ALL))
return compatibilityClasses;
else if (lowercaseMode.equals(Constants.REPOSITORY_MODE_RE3DATA)) {
else if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA)) {
if (ValidatorServiceImpl.OPENAIRE_DATA_REGEX.matcher(entry.getKey()).matches()) {
retMap.put(entry.getKey(), entry.getValue());
foundData = true;
}
} else if (lowercaseMode.startsWith("cris")) { // Future proofing for inconsistent CRIS modes.
} else if (mode.equalsIgnoreCase("cris")) {
if (entry.getKey().contains("openaire-cris")) {
retMap.put(entry.getKey(), entry.getValue());
foundData = true;
@ -711,7 +713,7 @@ public class RepositoryServiceImpl implements RepositoryService {
}
//TODO TO BE REMOVED WHEN VOCABULARIES ARE UPDATED
if ((lowercaseMode.equals("repository") || lowercaseMode.equals(Constants.REPOSITORY_MODE_RE3DATA)) && !foundData)
if ((mode.equalsIgnoreCase("repository") || mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA)) && !foundData)
retMap.put("openaire2.0_data", "OpenAIRE Data (funded, referenced datasets)");
return retMap;
@ -864,8 +866,6 @@ public class RepositoryServiceImpl implements RepositoryService {
new ParameterizedTypeReference<MetricsNumbers>() {
});
// TODO - the project "usagestats" returns "200-OK" even for an invalid datasourceID.. Report this to the person who manages usage-stats.
return resp.getBody();
}
@ -935,12 +935,7 @@ public class RepositoryServiceImpl implements RepositoryService {
private <T> Paging<T> searchApi(UriComponents uriComponents, RequestFilter requestFilter, Class<T> clazz) {
Paging<T> repositories = new Paging<>();
ResponseEntity<Map> rs;
try {
rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, new HttpEntity<>(requestFilter), Map.class);
} catch (Exception e) {
logger.error("", e);
throw e;
}
rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, new HttpEntity<>(requestFilter), Map.class);
if (!rs.getStatusCode().is2xxSuccessful()) {
logger.error("Api call not successful. Code: {} | Body: {}", rs.getStatusCode(), rs.getBody());
}
@ -960,27 +955,10 @@ public class RepositoryServiceImpl implements RepositoryService {
return repositories;
}
private List<String> getRepoIdsOfUser(String userEmail) {
List<String> repoIds;
if (userEmail != null && !"".equals(userEmail)) {
repoIds = new ArrayList<>(roleMappingService.getRepositoryIds(authorizationService.getUserRolesByEmail(userEmail)));
} else {
Collection<?> authorities = SecurityContextHolder.getContext().getAuthentication().getAuthorities();
repoIds = authorities
.stream()
.map(a -> roleMappingService.authorityToRepositoryId((GrantedAuthority) a))
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
return repoIds;
}
@Deprecated
private String getRepositoryType(String typology) {
return invertedDataSourceClass.get(typology);
}
@Deprecated
private List<String> getRoleIdsFromUserRoles(String userEmail) {
List<Integer> coPersonId = registryCalls.getCoPersonIdsByEmail(userEmail);
JsonArray roles;

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.sushilite;
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper;
import org.json.JSONException;

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.sushilite;
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.usagestats.sushilite.domain.Customer;
import eu.dnetlib.usagestats.sushilite.domain.ReportItem;
@ -93,8 +93,8 @@ public class SushiliteServiceImpl implements SushiliteService {
List<ReportItem> requestedItemList = new ArrayList<>();
Customer customer = reportResponseWrapper.getReportResponse().getReportWrapper().getReport().getCustomer();
List<ReportItem> allReportItems = customer.getReportItems();
if ( allReportItems != null ) {
try {
int totalItems = allReportItems.size();
@ -111,10 +111,10 @@ public class SushiliteServiceImpl implements SushiliteService {
logger.error("Exception on getReportResults - trying to cast strings to integers", e);
throw e;
}
customer.setReportItems(requestedItemList); // Setting the reportItems to the "customer"-reference, updates the "reportResponseWrapper" object.
}
customer.setReportItems(requestedItemList); // Setting the reportItems to the "customer"-reference, updates the "reportResponseWrapper" object.
return reportResponseWrapper;
}

View File

@ -15,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
@ -56,7 +55,7 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public List<String> getUserIdentifiersByCoPersonId(Integer coPersonId) throws RestClientException {
public List<String> getUserIdentifiersByCoPersonId(Integer coPersonId) {
List<String> ids = new ArrayList<>();
Map<String, String> params = new HashMap<>();
params.put("copersonid", coPersonId.toString());
@ -87,7 +86,7 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public List<Integer> getCoPersonIdsByEmail(String email) throws RestClientException {
public List<Integer> getCoPersonIdsByEmail(String email) {
List<Integer> coPersonIds = new ArrayList<>();
Map<String, String> params = new HashMap<>();
params.put("mail", email);
@ -114,7 +113,7 @@ public class RegistryCalls implements AaiRegistryService {
}
}
public Integer getCoPersonIdByIdentifier(String sub) throws RestClientException {
public Integer getCoPersonIdByIdentifier(String sub) {
Map<String, String> params = new HashMap<>();
params.put("search.identifier", sub);
params.put("coid", coid);
@ -123,7 +122,7 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public JsonArray getCous(String name) throws RestClientException {
public JsonArray getCous(String name) {
Map<String, String> params = new HashMap<>();
if (name != null) {
try {
@ -164,9 +163,8 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public JsonArray getRoles(Integer coPersonId) throws RestClientException {
public JsonArray getRoles(Integer coPersonId) {
Map<String, String> params = new HashMap<>();
params.put("coid", coid);
params.put("copersonid", coPersonId.toString());
JsonElement response = httpUtils.get("co_person_roles.json", params);
return (response != null) ? response.getAsJsonObject().get("CoPersonRoles").getAsJsonArray() : new JsonArray();
@ -205,7 +203,7 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public JsonArray getUserGroups(Integer coPersonId) throws RestClientException {
public JsonArray getUserGroups(Integer coPersonId) {
Map<String, String> params = new HashMap<>();
params.put("copersonid", coPersonId.toString());
JsonElement response = httpUtils.get("co_groups.json", params);
@ -213,7 +211,7 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public JsonObject getUserAdminGroup(Integer coPersonId, Integer couId) throws RestClientException {
public JsonObject getUserAdminGroup(Integer coPersonId, Integer couId) {
Map<String, String> params = new HashMap<>();
params.put("copersonid", coPersonId.toString());
JsonElement response = httpUtils.get("co_groups.json", params);
@ -230,7 +228,7 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public JsonArray getCouGroups(Integer couId) throws RestClientException {
public JsonArray getCouGroups(Integer couId) {
Map<String, String> params = new HashMap<>();
params.put("couid", couId.toString());
JsonElement response = httpUtils.get("co_groups.json", params);
@ -249,7 +247,7 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public JsonArray getGroupMembers(Integer coGroupId) throws RestClientException {
public JsonArray getGroupMembers(Integer coGroupId) {
Map<String, String> params = new HashMap<>();
params.put("cogroupid", coGroupId.toString());
JsonElement response = httpUtils.get("co_group_members.json", params);
@ -258,7 +256,7 @@ public class RegistryCalls implements AaiRegistryService {
@Override
public JsonArray getUserEmailByCouId(Integer couId, boolean admin) throws RestClientException {
public JsonArray getUserEmailByCouId(Integer couId, boolean admin) {
Map<String, String> params = new HashMap<>();
if (couId == null) {
throw new IllegalArgumentException("Provided 'couId' is null");
@ -289,7 +287,7 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public JsonArray getUsersByCouId(Integer couId) throws RestClientException {
public JsonArray getUsersByCouId(Integer couId) {
Map<String, String> params = new HashMap<>();
params.put("couid", couId.toString());
JsonElement response = httpUtils.get("co_person_roles.json", params);
@ -322,7 +320,7 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public JsonArray getUserNamesByCouId(Integer couId, boolean admin) throws RestClientException {
public JsonArray getUserNamesByCouId(Integer couId, boolean admin) {
Map<String, String> params = new HashMap<>();
params.put("couid", couId.toString());
if (admin) {
@ -342,7 +340,7 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public JsonArray getUserIdByCouId(Integer couId, boolean admin) throws RestClientException {
public JsonArray getUserIdByCouId(Integer couId, boolean admin) {
Map<String, String> params = new HashMap<>();
params.put("couid", couId.toString());
if (admin) {
@ -362,26 +360,26 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public void assignMemberRole(Integer coPersonId, Integer couId) throws RestClientException {
public void assignMemberRole(Integer coPersonId, Integer couId) {
httpUtils.post("co_person_roles.json", jsonUtils.coPersonRoles(coPersonId, couId, "Active"));
}
@Override
public void removeMemberRole(Integer coPersonId, Integer couId, Integer id) throws RestClientException {
public void removeMemberRole(Integer coPersonId, Integer couId, Integer id) {
if (id != null) {
httpUtils.put("co_person_roles/" + id + ".json", jsonUtils.coPersonRoles(coPersonId, couId, "Deleted"));
}
}
@Override
public Integer createRole(Role role) throws RestClientException {
public Integer createRole(Role role) {
JsonElement element = httpUtils.post("cous.json", jsonUtils.createNewCou(role));
return element.getAsJsonObject().get("Id").getAsInt();
}
@Override
public String getUserEmail(Integer coPersonId) throws RestClientException {
public String getUserEmail(Integer coPersonId) {
Map<String, String> params = new HashMap<>();
params.put("copersonid", coPersonId.toString());
JsonElement response = httpUtils.get("email_addresses.json", params);
@ -390,7 +388,7 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public String getUserNames(Integer coPersonId) throws RestClientException {
public String getUserNames(Integer coPersonId) {
Map<String, String> params = new HashMap<>();
params.put("copersonid", coPersonId.toString());
JsonElement response = httpUtils.get("names.json", params);
@ -403,7 +401,7 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public String getUserId(Integer coPersonId) throws RestClientException {
public String getUserId(Integer coPersonId) {
Map<String, String> params = new HashMap<>();
params.put("copersonid", coPersonId.toString());
JsonElement response = httpUtils.get("identifiers.json", params);
@ -412,7 +410,7 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public void assignAdminRole(Integer coPersonId, Integer couId) throws RestClientException {
public void assignAdminRole(Integer coPersonId, Integer couId) {
JsonObject group = getCouAdminGroup(couId);
if (group != null) {
httpUtils.post("co_group_members.json", jsonUtils.coGroupMembers(group.get("Id").getAsInt(), coPersonId, true));
@ -420,7 +418,7 @@ public class RegistryCalls implements AaiRegistryService {
}
@Override
public void removeAdminRole(Integer coPersonId, Integer couId) throws RestClientException {
public void removeAdminRole(Integer coPersonId, Integer couId) {
JsonObject adminGroup = this.getCouAdminGroup(couId);
JsonArray admins = this.getGroupMembers(adminGroup.get("Id").getAsInt());
Integer id = null;

View File

@ -10,7 +10,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
@ -33,7 +32,7 @@ public class HttpUtils {
@Value("${services.provide.aai.registry.password}")
private String password;
public JsonElement post(String path, JsonObject body) throws RestClientException {
public JsonElement post(String path, JsonObject body) {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = createHeaders(user, password);
headers.setContentType(MediaType.APPLICATION_JSON);
@ -42,7 +41,7 @@ public class HttpUtils {
return getResponseEntityAsJsonElement(responseEntity);
}
public JsonElement put(String path, JsonObject body) throws RestClientException {
public JsonElement put(String path, JsonObject body) {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = createHeaders(user, password);
headers.setContentType(MediaType.APPLICATION_JSON);
@ -51,7 +50,7 @@ public class HttpUtils {
return getResponseEntityAsJsonElement(responseEntity);
}
public JsonElement get(String path, Map<String, String> params) throws RestClientException {
public JsonElement get(String path, Map<String, String> params) {
RestTemplate restTemplate = new RestTemplate();
String url = createUrl(registryUrl + path, params);
ResponseEntity<String> responseEntity = restTemplate.exchange
@ -59,7 +58,7 @@ public class HttpUtils {
return getResponseEntityAsJsonElement(responseEntity);
}
public JsonElement delete(String path) throws RestClientException {
public JsonElement delete(String path) {
RestTemplate restTemplate = new RestTemplate();
String url = registryUrl + path;
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.DELETE, new HttpEntity<>(createHeaders(user, password)), String.class);

View File

@ -7,8 +7,6 @@ import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Collection;
import java.util.Objects;
@ -22,8 +20,21 @@ public class AaiRoleMappingService implements RoleMappingService {
@Value("${services.provide.aai.registry.production:true}")
private boolean production;
private String createRepoRoleName(String prefix, String repoId) {
return prefix + "." + repoId.replace(":", "$");
}
@Override
public String getRepositoryId(String roleId) {
public String getRepoNameWithoutType(String fullName, String prefix) {
if (fullName != null && prefix != null && fullName.startsWith(prefix)) {
return fullName.substring(prefix.length());
}
return null;
}
@Override
public String getRepoIdByRoleId(String roleId) {
if (!roleActive(roleId)) {
return null;
}
@ -31,46 +42,43 @@ public class AaiRoleMappingService implements RoleMappingService {
}
@Override
public Collection<String> getRepositoryIds(Collection<String> roleIds) {
public Collection<String> getRepoIdsByRoleIds(Collection<String> roleIds) {
return roleIds
.stream()
.map(this::getRepositoryId)
//.filter(this::roleActive) // implicitly executed in the next statement
.map(this::getRepoIdByRoleId)
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
@Override
public String getRole(String repoId) {
String role = null;
public String getRoleIdByRepoId(String repoId) {
String roleId = "";
String prefix = (production ? "" : "beta.") + "datasource";
if (repoId != null) {
role = createRole(prefix, repoId);
roleId = createRepoRoleName(prefix, repoId);
return roleId;
} else {
return null;
}
return role;
}
@Override
public Collection<String> getRoles(Collection<String> repoIds) {
public Collection<String> getRoleIdsByRepoIds(Collection<String> repoIds) {
return repoIds
.stream()
.map(this::getRole)
.map(this::getRoleIdByRepoId)
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
@Override
public String authorityToRepositoryId(GrantedAuthority authority) {
String repo = null;
String auth = null;
try {
auth = URLDecoder.decode(authority.getAuthority(), "UTF-8").toLowerCase();
} catch (UnsupportedEncodingException e) {
logger.error("", e);
}
if (auth != null && roleActive(auth)) {
repo = auth
.replaceFirst(".*datasource\\_", "")
public String convertAuthorityIdToRepoId(String authorityId) {
String repo = "";
if (authorityId != null && roleActive(authorityId)) {
repo = authorityId
.replaceFirst(".*datasource\\.", "")
.replace("$", ":")
.toLowerCase();
}
@ -78,26 +86,12 @@ public class AaiRoleMappingService implements RoleMappingService {
}
@Override
public GrantedAuthority repositoryIdToAuthority(String repoId) {
String role = null;
try {
role = URLEncoder.encode(convertRepoIdToAuthorityId(repoId), "UTF-8");
} catch (UnsupportedEncodingException e) {
logger.error("", e);
}
return new SimpleGrantedAuthority(role);
public String convertAuthorityToRepoId(GrantedAuthority authority) {
return convertAuthorityIdToRepoId(authority.toString());
}
private String createRole(String prefix, String repoId) {
return prefix + "." + repoId.replace(":", "$");
}
private boolean roleActive(String roleId) {
return (production && !roleId.toLowerCase().startsWith("beta"))
|| (!production && roleId.toLowerCase().startsWith("beta"));
}
private String convertRepoIdToAuthorityId(String repoId) {
@Override
public String convertRepoIdToAuthorityId(String repoId) {
StringBuilder roleBuilder = new StringBuilder();
String role = "";
if (repoId != null) {
@ -108,4 +102,20 @@ public class AaiRoleMappingService implements RoleMappingService {
}
return role;
}
@Override
public String convertRepoIdToEncodedAuthorityId(String repoId) {
return URLEncoder.encode(convertRepoIdToAuthorityId(repoId));
}
@Override
public SimpleGrantedAuthority convertRepoIdToAuthority(String repoId) {
String role = convertRepoIdToEncodedAuthorityId(repoId);
return new SimpleGrantedAuthority(role);
}
private boolean roleActive(String roleId) {
return (production && !roleId.toLowerCase().startsWith("beta."))
|| (!production && roleId.toLowerCase().startsWith("beta."));
}
}

View File

@ -1,11 +1,9 @@
package eu.dnetlib.repo.manager.service.security;
import com.google.gson.JsonElement;
import eu.dnetlib.repo.manager.domain.PendingUserRole;
import eu.dnetlib.repo.manager.domain.dto.Role;
import eu.dnetlib.repo.manager.domain.dto.User;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.repository.PendingUserRoleRepository;
import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.mitre.openid.connect.model.UserInfo;
@ -32,16 +30,13 @@ public class AuthorizationServiceImpl implements AuthorizationService {
private final RoleMappingService roleMappingService;
private final AaiRegistryService aaiRegistryService;
private final AuthoritiesUpdater authoritiesUpdater;
private final PendingUserRoleRepository pendingUserRoleRepository;
@Autowired
AuthorizationServiceImpl(RoleMappingService roleMappingService, AaiRegistryService aaiRegistryService,
AuthoritiesUpdater authoritiesUpdater,
PendingUserRoleRepository pendingUserRoleRepository) {
AuthoritiesUpdater authoritiesUpdater) {
this.roleMappingService = roleMappingService;
this.aaiRegistryService = aaiRegistryService;
this.authoritiesUpdater = authoritiesUpdater;
this.pendingUserRoleRepository = pendingUserRoleRepository;
}
private String mapType(String type) {
@ -61,9 +56,9 @@ public class AuthorizationServiceImpl implements AuthorizationService {
@Override
public boolean isMemberOf(String repoId) {
String repoAuthority = roleMappingService.repositoryIdToAuthority(repoId).getAuthority();
String repoRole = roleMappingService.convertRepoIdToEncodedAuthorityId(repoId);
return SecurityContextHolder.getContext().getAuthentication().getAuthorities()
.stream().anyMatch(authority -> authority.toString().equals(repoAuthority));
.stream().anyMatch(authority -> authority.toString().equals(repoRole));
}
@Override
@ -79,7 +74,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
public List<User> getAdminsOfRepo(String repoId) {
// find couId by role name
String role = roleMappingService.getRole(repoId);
String role = roleMappingService.getRoleIdByRepoId(repoId);
Integer couId = aaiRegistryService.getCouId(role);
return aaiRegistryService.getUsers(couId);
}
@ -87,29 +82,26 @@ public class AuthorizationServiceImpl implements AuthorizationService {
@Override
public void addAdmin(String resourceId, String email) throws ResourceNotFoundException {
String role = roleMappingService.getRole(resourceId);
String role = roleMappingService.getRoleIdByRepoId(resourceId);
Integer couId = aaiRegistryService.getCouId(role);
if (couId == null) {
throw new ResourceNotFoundException("Cannot find CouId for role: " + role);
}
List<Integer> coPersonIds = aaiRegistryService.getCoPersonIdsByEmail(email);
if (coPersonIds.isEmpty()) {
throw new ResourceNotFoundException("User with email '%s' could not be found..");
}
for (Integer coPersonId : coPersonIds) {
assert coPersonId != null;
aaiRegistryService.assignMemberRole(coPersonId, couId);
// Add role to user current authorities
for (String userId : aaiRegistryService.getUserIdentifiersByEmail(email)) {
authoritiesUpdater.addRole(userId, roleMappingService.repositoryIdToAuthority(resourceId));
authoritiesUpdater.addRole(userId, roleMappingService.convertRepoIdToAuthority(resourceId));
}
}
}
@Override
public void removeAdmin(String resourceId, String email) throws ResourceNotFoundException {
String role = roleMappingService.getRole(resourceId);
String role = roleMappingService.getRoleIdByRepoId(resourceId);
Integer couId = aaiRegistryService.getCouId(role);
if (couId == null) {
throw new ResourceNotFoundException("Cannot find CouId for role: " + role);
@ -123,7 +115,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
// Remove role from user current authorities
for (String userId : aaiRegistryService.getUserIdentifiersByEmail(email)) {
authoritiesUpdater.removeRole(userId, roleMappingService.repositoryIdToAuthority(resourceId));
authoritiesUpdater.removeRole(userId, roleMappingService.convertRepoIdToAuthority(resourceId));
}
} else {
logger.error("Cannot find RoleId for role: {}", role);
@ -134,7 +126,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
@Override
public void createAndAssignRoleToAuthenticatedUser(String resourceId, String roleDescription) {
// Create new role
String newRoleName = roleMappingService.getRole(resourceId);
String newRoleName = roleMappingService.getRoleIdByRepoId(resourceId);
Role newRole = new Role(newRoleName, roleDescription);
Integer couId;
@ -153,15 +145,10 @@ public class AuthorizationServiceImpl implements AuthorizationService {
// Assign new role to the current authenticated user
Integer coPersonId = aaiRegistryService.getCoPersonIdByIdentifier();
if (couId != null) {
try {
aaiRegistryService.assignMemberRole(coPersonId, couId);
} catch (Exception e) {
pendingUserRoleRepository.save(new PendingUserRole(coPersonId, couId));
}
aaiRegistryService.assignMemberRole(coPersonId, couId);
// Add role to current user authorities
authoritiesUpdater.addRole(roleMappingService.repositoryIdToAuthority(resourceId));
authoritiesUpdater.addRole(roleMappingService.convertRepoIdToAuthority(resourceId));
}
}

View File

@ -7,41 +7,68 @@ import java.util.Collection;
public interface RoleMappingService {
/**
* @param fullName
* @param prefix
* @return
*/
String getRepoNameWithoutType(String fullName, String prefix);
/**
* @param roleId Role Id
* @return Converts {@param roleId} to a repo Id.
*/
String getRepositoryId(String roleId);
String getRepoIdByRoleId(String roleId);
/**
*
* @param roleIds Collection of roles
* @return Converts {@param roleIds} to a repo Ids.
*/
Collection<String> getRepositoryIds(Collection<String> roleIds);
Collection<String> getRepoIdsByRoleIds(Collection<String> roleIds);
/**
* @param repoId Repository Id
* @return Converts {@param repoId} to a role Id.
*/
String getRole(String repoId);
String getRoleIdByRepoId(String repoId);
/**
* @param repoIds Collection of Repository Ids
* @return Converts {@param repoIds} to role Ids.
*/
Collection<String> getRoles(Collection<String> repoIds);
Collection<String> getRoleIdsByRepoIds(Collection<String> repoIds);
/**
* @param authority {@link GrantedAuthority}
* @return Converts {@param authority} to repository Id.
* @param authorityId Authority Id
* @return Converts {@param authorityId} to repo Id.
*/
String authorityToRepositoryId(GrantedAuthority authority);
String convertAuthorityIdToRepoId(String authorityId);
/**
* @param authority Granted authority
* @return Converts {@param authority} to repo Id.
*/
String convertAuthorityToRepoId(GrantedAuthority authority);
/**
* @param repoId Repository Id
* @return
*/
String convertRepoIdToAuthorityId(String repoId);
/**
* @param repoId Repository Id
* @return Converts {@param repoId} to {@link String} role id url encoded ($ -> %24)
* // TODO: remove role encoding and perform url decoding when mapping authorities. (Must be performed in all OpenAIRE projects because of Redis)
*/
String convertRepoIdToEncodedAuthorityId(String repoId);
/**
* @param repoId Repository Id
* @return Converts {@param repoId} to {@link SimpleGrantedAuthority} with the role url encoded ($ -> %24)
* // TODO: remove role encoding and perform url decoding when mapping authorities. (Must be performed in all OpenAIRE projects because of Redis)
*/
GrantedAuthority repositoryIdToAuthority(String repoId);
SimpleGrantedAuthority convertRepoIdToAuthority(String repoId);
}

View File

@ -1,27 +0,0 @@
package eu.dnetlib.repo.manager.service.sushilite;
import org.json.JSONException;
import org.springframework.http.ResponseEntity;
import java.util.List;
public interface SushiliteR5Service {
ResponseEntity<?> getReportResults(String Report,
String release,
String requestorID,
String beginDate,
String endDate,
String repositoryIdentifier,
String datasetIdentifier,
String itemIdentifier,
List<String> metricTypes,
String dataType,
String granularity,
String pretty) throws JSONException;
}

View File

@ -1,135 +0,0 @@
package eu.dnetlib.repo.manager.service.sushilite;
//import eu.dnetlib.usagestats.sushilite.domain.COUNTER_Item_Report;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import java.net.URI;
import java.util.List;
@Service("sushiliteR5Service")
public class SushiliteR5ServiceImpl implements SushiliteR5Service {
private static final Logger logger = LoggerFactory.getLogger(SushiliteR5ServiceImpl.class);
@Value("${services.provide.usagestats.sushiliteR5Endpoint}")
private String usagestatsSushiliteR5Endpoint;
public ResponseEntity<?> getReportResults(String report,
String release,
String requestorID,
String beginDate,
String endDate,
String repositoryIdentifier,
String datasetIdentifier,
String itemIdentifier,
List<String> metricTypes,
String dataType,
String granularity,
String pretty) throws JSONException
{
//build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usagestatsSushiliteR5Endpoint + "reports/" + report.toLowerCase())
.queryParam("Report", report)
.queryParam("Release", release)
.queryParam("RequestorID", requestorID)
.queryParam("BeginDate", beginDate)
.queryParam("EndDate", endDate)
.queryParam("RepositoryIdentifier", repositoryIdentifier)
.queryParam("DatasetIdentifier", datasetIdentifier)
.queryParam("ItemIdentifier", itemIdentifier);
if ( metricTypes != null ) {
for ( String metricType : metricTypes )
builder.queryParam("MetricType", metricType);
}
builder.queryParam("DataType", dataType)
.queryParam("Granularity", granularity)
.queryParam("Pretty", pretty);
URI uri = builder.build().encode().toUri();
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
ResponseEntity<?> resp;
try {
resp = restTemplate.exchange(
uri,
HttpMethod.GET,
null,
new ParameterizedTypeReference<Object>() {}); // THis "Object" must be a valid json-object.
} catch (RestClientException rce) {
String errorMsg = "Failed to get a response from sushiliteR5!";
String message = rce.getMessage();
if ( (message != null) && message.contains("504 Gateway Time-out") ) // In this case the parsing-exception is thrown before we get to check the response code..
errorMsg += " Reason: 504 Gateway Time-out";
logger.error(errorMsg + " URI was:\n" + uri + "\n" + message);
return ResponseEntity.internalServerError().body(errorMsg);
}
HttpStatus httpStatus = resp.getStatusCode();
if ( httpStatus != HttpStatus.OK ) {
logger.warn("Sushi cannot give us data! Responded status: " + httpStatus);
return ResponseEntity.status(httpStatus).build();
}
Object reportResult = resp.getBody();
if ( reportResult == null ) {
logger.error("The \"reportResponseWrapper\" for sushi was null!");
return ResponseEntity.internalServerError().build();
}
logger.trace(reportResult.toString());
return ResponseEntity.ok(reportResult);
// TODO - Depending on the "report-type", map the "object" to the right Report-type class.
// TODO - This will be useful, in case we add preprocessing steps, like pagination.
/* try {
switch ( report ) {
case "PR":
break;
case "PR_P1":
break;
case "IR":
COUNTER_Item_Report counterItemReport = (COUNTER_Item_Report) resp.getBody();
if ( counterItemReport == null ) {
logger.error("The \"reportResponseWrapper\" for sushi was null!");
return ResponseEntity.internalServerError().build();
} else {
logger.debug(counterItemReport.toString());
return ResponseEntity.ok(counterItemReport);
}
case "DSR":
break;
default:
String errorMsg = "Invalid report type was given: " + report;
logger.error(errorMsg);
return ResponseEntity.badRequest().body(errorMsg);
}
} catch (ClassCastException cce) {
logger.error("The report object could not be mapped to the repo-type-object of \"" + report + "\"!", cce);
return ResponseEntity.internalServerError().build();
}*/
}
}

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
<context:component-scan base-package="eu.dnetlib.repo.manager.service.*"/>
<bean class="eu.dnetlib.repo.manager.config.CascadingPropertyLoader"
id="propertyLoader">
<property name="order" value="2"/>
<property name="properties">
<bean class="eu.dnetlib.conf.WebappContextProperyFactory">
<property name="propertyFetcher">
<bean class="eu.dnetlib.conf.PropertyFetcher"/>
</property>
</bean>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath*:/gr/**/springContext-*.properties</value>
<value>classpath*:/eu/**/springContext-*.properties</value>
<value>classpath*:/application.properties</value>
<value>classpath*:email-texts.properties</value>
<!-- <value>classpath*:dnet-site-wizard.properties</value>-->
<!-- <value>classpath*:dnet-site-override.properties</value>-->
<!-- <value>classpath*:dnet-wizard.properties</value>-->
<!-- <value>classpath*:dnet-override.properties</value>-->
<!-- <value>classpath*:dnet-validator-wizard.properties</value>-->
<!-- <value>classpath*:dnet-validator-override.properties</value>-->
<!-- <value>classpath*:dnet-site-force-override.properties</value>-->
<!-- <value>classpath*:dnet-force-override.properties</value>-->
</list>
</property>
</bean>
</beans>

View File

@ -1,16 +1,6 @@
server:
port: 8480
servlet:
context-path: /uoa-repository-manager-service
springdoc:
swagger-ui:
disable-swagger-default-url: true
path: /swagger-ui.html
displayRequestDuration: true
api-docs:
path: /api-docs
show-actuator: true
springdoc.swagger-ui:
disable-swagger-default-url: true
version: 3
spring:
jpa:
@ -24,11 +14,11 @@ spring:
driverClassName: ${services.provide.db.driverClassName}
services:
openaireServicesBaseUrl: https://beta.services.openaire.eu # dev-openaire.d4science.org
openaireServicesBaseUrl: https://beta.services.openaire.eu
provide:
dev-machine: 88.197.53.71 # VM-71
aai:
baseURL: https://aai.openaire.eu
baseURL: https://beta.aai.openaire.eu
oidc:
domain: .openaire.eu # use empty value for local, otherwise: ".openaire.eu"
id: XX
@ -44,14 +34,14 @@ services:
url: ${services.provide.aai.baseURL}/registry/
adminEmail: XX
analyticsURL: https://analytics.openaire.eu/addsite.php?
baseUrl: ${services.openaireServicesBaseUrl}/openaire
baseUrl: https://dev-openaire.d4science.org/openaire
broker:
api: api/
openaire: openaireBroker
port: 443
url: https://beta.broker.openaire.eu
clients:
dsm: ${services.provide.baseUrl}
dsm: https://dev-openaire.d4science.org/openaire
search: ${services.openaireServicesBaseUrl}/search/v2/api
usageEvents: http://beta.lbs.openaire.eu:8080/ajax/summary
usagestats: ${services.openaireServicesBaseUrl}/usagestats
@ -77,14 +67,12 @@ services:
password: XX
port: 6379
topic_types:
url: ${services.openaireServicesBaseUrl}/provision/mvc/vocabularies/dnet:topic_types.json # TODO - Check this! The requested json file does not exist in the DEV-url below)
# https://dev-openaire.d4science.org/provision/mvc/vocabularies/
url: ${services.openaireServicesBaseUrl}/provision/mvc/vocabularies/dnet:topic_types.json
usageStatisticsDiagramsBaseURL: https://beta.openaire.eu/stats3/
usageStatisticsNumbersBaseURL: ${services.openaireServicesBaseUrl}/usagestats/datasources/
usagestats:
adminEmail: XX
sushiliteEndpoint: ${services.openaireServicesBaseUrl}/usagestats/sushilite/
sushiliteR5Endpoint: ${services.openaireServicesBaseUrl}/usagestats_r5/sushilite/r5/
validator:
results:
url: https://beta.provide.openaire.eu/compatibility/browseHistory/

View File

@ -15,5 +15,8 @@
<Logger name="org.springframework.boot" level="warn" additivity="false">
<AppenderRef ref="LogToConsole"/>
</Logger>
<Logger name="springfox.documentation" level="warn" additivity="false">
<AppenderRef ref="LogToConsole"/>
</Logger>
</Loggers>
</Configuration>