develop #1

Merged
antonis.lempesis merged 36 commits from develop into master 2023-01-19 12:41:45 +01:00
82 changed files with 1932 additions and 1901 deletions

9
README.md Normal file
View File

@ -0,0 +1,9 @@
# Provide
[...]
## 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 -s <settings-file>`
- Run the app with: `java -jar ./target/uoa-repository-manager-service.jar`

View File

@ -1,43 +0,0 @@
cd "${0%/*}" || (echo "Could not change-dir to this script's dir!" && exit) # Change the working directory to the script's directory, when running from other location.
if [[ $# -gt 1 ]]; then
echo -e "Wrong number of arguments given: ${#}\nPlease execute it like: installAndRun.sh <1 | 0 (optional)>"; exit 1
fi
justRun=0
if [[ $# -eq 1 ]]; then # If we have just 1 argument.
numbers_re='^[0-9]+$'
if ! [[ $1 =~ $numbers_re ]]; then # If the first argument is not numeric.
echo -e "Invalid, non-numeric argument given: ${1}\nPlease execute it like: installAndRun.sh <1 | 0 (optional)>"; exit 2
fi
if [[ $1 -ne 0 && $1 -ne 1 ]]; then # If the 1st argument does NOT equal to < 0 > or < 1 >.
echo -e "Invalid argument given: ${1}\nPlease execute it like: installAndRun.sh <1 | 0 (optional)>"; exit 3
fi
justRun=$1 # Assign <1> or <0>
fi
dnet_repo=~/.m2/repository-dnet45
settings_file=settings-dnet45.xml
if [[ justRun -eq 1 ]]; then
if [ ! -f ${dnet_repo}"/"${settings_file} ]; then
echo -e "The file \"~/.m2/repository-dnet45/settings-dnet45.xml\" does not exist! Exiting.." && exit 4
fi
else
if [ ! -d ${dnet_repo} ]; then
mkdir ${dnet_repo} || (echo -e "The directory \"~/.m2/repository-dnet45/\" could not be created! Exiting.." && exit 5)
echo "Created the \"dnet_repo\": ${dnet_repo}"
fi
if [ ! -f ${dnet_repo}"/"${settings_file} ]; then
cp ${settings_file} ${dnet_repo}"/"${settings_file} || (echo -e "The file \"settings-dnet45.xml\" could not be copied in directory \"~/.m2/repository-dnet45\"! Exiting.." && exit 6)
echo "Copied the \"settings_file\" to: ${dnet_repo}/${settings_file}"
fi
mvn clean install -s ${dnet_repo}"/"${settings_file}
fi
java -jar ./target/uoa-repository-manager-service.jar

196
pom.xml
View File

@ -12,7 +12,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>eu.dnetlib</groupId>
<artifactId>uoa-repository-manager-service</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
@ -22,7 +22,7 @@
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
@ -30,27 +30,21 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--<scope>provided</scope>-->
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -60,26 +54,23 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-hystrix -->
<!--
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.2.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.0.1</version>
</dependency>
-->
<!--
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
</dependency>
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>eu.dnetlib.dhp</groupId>
<artifactId>dnet-exporter-api</artifactId>
<version>[3.3.3-SNAPSHOT, )</version>
</dependency>
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>uoa-clients</artifactId>
@ -122,36 +113,6 @@
</exclusion>
</exclusions>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework</groupId>-->
<!-- <artifactId>spring-webmvc</artifactId>-->
<!-- <version>${spring.version}</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.hibernate</groupId>-->
<!-- <artifactId>hibernate-validator-annotation-processor</artifactId>-->
<!-- <version>4.1.0.Final</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>log4j</groupId>-->
<!-- <artifactId>log4j</artifactId>-->
<!-- <version>${log4j.version}</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>eu.dnetlib</groupId>-->
<!-- <artifactId>uoa-domain</artifactId>-->
<!-- <version>[2.0.0-SNAPSHOT, 3.0.0)</version>-->
<!-- <exclusions>-->
<!-- <exclusion> &lt;!&ndash; declare the exclusion here &ndash;&gt;-->
<!-- <groupId>cglib</groupId>-->
<!-- <artifactId>cglib</artifactId>-->
<!-- </exclusion>-->
<!-- <exclusion>-->
<!-- <groupId>log4j</groupId>-->
<!-- <artifactId>log4j</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>dnet-openaire-usage-stats-sushilite</artifactId>
@ -191,38 +152,6 @@
<version>2.7.2</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>xerces</groupId>-->
<!-- <artifactId>xercesImpl</artifactId>-->
<!-- <version>2.11.0</version>-->
<!-- </dependency>-->
<!--
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.4</version>
<scope>compile</scope>
</dependency>
-->
<!-- <dependency>-->
<!-- <groupId>org.springframework</groupId>-->
<!-- <artifactId>spring-context</artifactId>-->
<!-- <version>${spring.version}</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework</groupId>-->
<!-- <artifactId>spring-jdbc</artifactId>-->
<!-- <version>${spring.version}</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
@ -264,13 +193,6 @@
<version>9.1-901.jdbc3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina -->
<!-- <dependency>-->
<!-- <groupId>org.apache.tomcat</groupId>-->
<!-- <artifactId>tomcat-catalina</artifactId>-->
<!-- <version>9.0.22</version>-->
<!-- </dependency>-->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
@ -292,14 +214,6 @@
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
<!--
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<version>2.5.1</version>
<type>pom</type>
</dependency>
-->
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
@ -323,18 +237,7 @@
<artifactId>cors-filter</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
<version>1.5.18</version>
</dependency>
<!--
<dependency>
<groupId>com.netflix.rxjava</groupId>
<artifactId>rxjava-core</artifactId>
<version>0.20.7</version>
</dependency>
-->
<!-- https://mvnrepository.com/artifact/javax.xml.ws/jaxws-api -->
<dependency>
<groupId>javax.xml.ws</groupId>
@ -381,37 +284,6 @@
<!-- </exclusions>-->
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.26.0</version>
<scope>test</scope>
</dependency>
<!-- Enable micrometer >> -->
<!-- <dependency> &lt;!&ndash; TODO: remove this with ActuatorConfig class &ndash;&gt;-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-actuator</artifactId>-->
<!-- <version>1.3.5.RELEASE</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-actuator-autoconfigure</artifactId>-->
<!-- <version>2.1.18.RELEASE</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>io.micrometer</groupId>-->
<!-- <artifactId>micrometer-core</artifactId>-->
<!-- <version>1.7.2</version>-->
<!-- </dependency>-->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.7.2</version>
<scope>compile</scope>
</dependency>
<!-- << Enable micrometer -->
</dependencies>
@ -520,30 +392,6 @@
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>dnet45-bootstrap-snapshot</id>
<name>D-Net 45 Bootstrap Snapshot</name>
<url>https://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-bootstrap-snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<layout>default</layout>
</repository>
<repository>
<id>dnet45-bootstrap-release</id>
<name>D-Net 45 Bootstrap Release</name>
<url>https://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-bootstrap-release</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<layout>default</layout>
</repository>
</repositories>
</project>

View File

@ -1,43 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>${env.HOME}/.m2/repository-dnet45</localRepository>
<pluginGroups>
<pluginGroup>org.apache.tomcat.maven</pluginGroup>
</pluginGroups>
<profiles>
<profile>
<id>dnet4.0</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>dnet45-bootstrap-snapshot</id>
<name>D-Net 45 Bootstrap Snapshot</name>
<url>https://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-bootstrap-snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<layout>default</layout>
</repository>
<repository>
<id>dnet45-bootstrap-release</id>
<name>D-Net 45 Bootstrap Release</name>
<url>https://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-bootstrap-release</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<layout>default</layout>
</repository>
</repositories>
</profile>
</profiles>
</settings>

View File

@ -15,7 +15,6 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter;
import java.util.*;

View File

@ -1,6 +1,7 @@
package eu.dnetlib.repo.manager.config;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
@ -15,7 +16,7 @@ public class AsyncConfiguration implements AsyncConfigurer {
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return new AsyncUncaughtExceptionHandler() {
private final Logger logger = Logger.getLogger(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());
@Override
public void handleUncaughtException(Throwable throwable, Method method, Object... objects) {

View File

@ -0,0 +1,40 @@
package eu.dnetlib.repo.manager.config;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;
@Configuration
public class CustomRestTemplateConfig {
@Bean
public RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(0, mappingJacksonHttpMessageConverter());
return restTemplate;
}
@Bean
public MappingJackson2HttpMessageConverter mappingJacksonHttpMessageConverter() {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setObjectMapper(customObjectMapper());
return converter;
}
@Bean
public ObjectMapper customObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
// Do not fail when reading unknown properties
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// Do not fail when reading properties of different case
objectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
return objectMapper;
}
}

View File

@ -1,59 +0,0 @@
package eu.dnetlib.repo.manager.config;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableTransactionManagement
public class DatasourceConfiguration {
private static Logger LOGGER = Logger.getLogger(DatasourceConfiguration.class);
@Value("${services.provide.db.driverClassName}")
private String driverClassname;
@Value("${services.provide.db.url}")
private String URL;
@Value("${services.provide.db.username}")
private String username;
@Value("${services.provide.db.password}")
private String password;
@Bean
public BasicDataSource dataSource(){
BasicDataSource basicDataSource = new BasicDataSource();
basicDataSource.setDriverClassName(driverClassname);
basicDataSource.setUrl(URL);
basicDataSource.setUsername(username);
basicDataSource.setPassword(password);
basicDataSource.setMaxIdle(10);
basicDataSource.setMaxActive(100);
basicDataSource.setMaxWait(1000);
basicDataSource.setValidationQuery("SELECT 1;");
basicDataSource.setTestOnBorrow(true);
basicDataSource.setTestOnReturn(true);
basicDataSource.setTestWhileIdle(true);
basicDataSource.setTimeBetweenEvictionRunsMillis(1200000);
basicDataSource.setMinEvictableIdleTimeMillis(1800000);
basicDataSource.setMinEvictableIdleTimeMillis(5);
basicDataSource.setPoolPreparedStatements(true);
basicDataSource.setDefaultAutoCommit(true);
return basicDataSource;
}
@Bean
public DataSourceTransactionManager txManager(){
DataSourceTransactionManager txManager = new DataSourceTransactionManager();
txManager.setDataSource(dataSource());
return txManager;
}
}

View File

@ -1,8 +1,9 @@
package eu.dnetlib.repo.manager.config;
import com.google.gson.JsonParser;
import org.apache.log4j.Logger;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
@ -22,25 +23,26 @@ public class FrontEndLinkURIAuthenticationSuccessHandler implements Authenticati
private String frontEndURI;
private static final Logger LOGGER = Logger
.getLogger(FrontEndLinkURIAuthenticationSuccessHandler.class);
private static final Logger logger = LoggerFactory.getLogger(FrontEndLinkURIAuthenticationSuccessHandler.class);
public void init() {
LOGGER.debug("Front end uri : " + frontEndURI);
logger.debug("Front end uri : {}", frontEndURI);
}
@Value("${services.provide.aai.oidc.domain}")
private String domain;
private static final Pattern AUTH_REGEX = Pattern.compile("^([A-Za-z0-9-_=]+)\\.([A-Za-z0-9-_=]+)\\.?([A-Za-z0-9-_.+=]*)$");
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
OIDCAuthenticationToken authOIDC = (OIDCAuthenticationToken) authentication;
request.getSession().setAttribute(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, authOIDC.getUserInfo().getEmail());
request.getSession().setAttribute(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, authOIDC.getUserInfo().getSub());
Cookie accessToken = new Cookie("AccessToken", authOIDC.getAccessTokenValue());
String regex = "^([A-Za-z0-9-_=]+)\\.([A-Za-z0-9-_=]+)\\.?([A-Za-z0-9-_.+=]*)$";
Matcher matcher = Pattern.compile(regex).matcher(authOIDC.getAccessTokenValue());
Matcher matcher = AUTH_REGEX.matcher(authOIDC.getAccessTokenValue());
if (matcher.find()) {
long exp = new JsonParser().parse(new String(Base64.getDecoder().decode(matcher.group(2)))).getAsJsonObject().get("exp").getAsLong();
accessToken.setMaxAge((int) (exp - (new Date().getTime() / 1000)));

View File

@ -3,9 +3,10 @@ package eu.dnetlib.repo.manager.config;
import com.google.gson.JsonArray;
import com.nimbusds.jwt.JWT;
import eu.dnetlib.repo.manager.service.security.AuthoritiesMapper;
import org.apache.log4j.Logger;
import org.mitre.openid.connect.client.OIDCAuthoritiesMapper;
import org.mitre.openid.connect.model.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
@ -18,7 +19,7 @@ import java.util.Set;
@Component
public class OpenAIREAuthoritiesMapper implements OIDCAuthoritiesMapper {
private static final Logger logger = Logger.getLogger(OpenAIREAuthoritiesMapper.class);
private static final Logger logger = LoggerFactory.getLogger(OpenAIREAuthoritiesMapper.class);
@Value("${services.provide.adminEmail}")
String adminEmail;
@ -33,7 +34,7 @@ public class OpenAIREAuthoritiesMapper implements OIDCAuthoritiesMapper {
} else if (userInfo.getSource().getAsJsonArray("eduperson_entitlement") != null) {
entitlements = userInfo.getSource().getAsJsonArray("eduperson_entitlement");
}
logger.debug("user info: " + userInfo + "\nentitlements: " + entitlements);
logger.debug("user info: {}\nentitlements: {}", userInfo, entitlements);
// FIXME: delete this if statement when super administrators are set
if (userInfo.getEmail() != null && userInfo.getEmail().equals(adminEmail)) {

View File

@ -1,16 +1,14 @@
package eu.dnetlib.repo.manager.config;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;
import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
@ -18,7 +16,7 @@ import javax.annotation.PostConstruct;
@EnableRedisHttpSession
public class RedisConfiguration {
private static Logger LOGGER = Logger.getLogger(RedisConfiguration.class);
private static final Logger logger = LoggerFactory.getLogger(RedisConfiguration.class);
@Value("${services.provide.redis.host}")
private String host;
@ -34,12 +32,12 @@ public class RedisConfiguration {
@PostConstruct
private void init() {
LOGGER.info(String.format("Redis : %s Port : %s Password : %s", host, port, password));
logger.info(String.format("Redis : %s Port : %s Password : %s", host, port, password));
}
@Bean
public JedisConnectionFactory connectionFactory() {
LOGGER.info(String.format("Redis : %s Port : %s Password : %s", host, port, password));
logger.info(String.format("Redis : %s Port : %s Password : %s", host, port, password));
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
jedisConnectionFactory.setHostName(host);
jedisConnectionFactory.setPort(Integer.parseInt(port));
@ -54,18 +52,8 @@ public class RedisConfiguration {
serializer.setCookieName("openAIRESession");
serializer.setCookiePath("/");
serializer.setDomainName(domain);
LOGGER.info("Serializer : " + serializer);
logger.info("Cookie Serializer : {}", serializer);
return serializer;
}
@Bean
public RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type", "application/json");
return restTemplate;
}
}

View File

@ -1,8 +1,8 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.exception.BrokerException;
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.annotations.Api;
import io.swagger.annotations.ApiParam;

View File

@ -1,12 +1,13 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.domain.*;
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;
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.BrokerService;
import eu.dnetlib.repo.manager.service.DashboardService;
import eu.dnetlib.repo.manager.service.PiWikService;
import eu.dnetlib.repo.manager.service.RepositoryService;
import eu.dnetlib.repo.manager.service.*;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
@ -29,6 +30,9 @@ public class DashboardController {
@Autowired
private RepositoryService repositoryService;
@Autowired
private AggregationService aggregationService;
@Autowired
private BrokerService brokerService;
@ -53,20 +57,20 @@ public class DashboardController {
@PathVariable("repoId") String repoId,
@RequestParam(name = "size", required = false, defaultValue = "20") int size) throws JSONException {
List<AggregationDetails> aggregationDetails = repositoryService.getRepositoryAggregations(repoId, 0, size);
List<AggregationInfo> aggregationInfo = aggregationService.getRepositoryAggregations(repoId, 0, size);
CollectionMonitorSummary collectionMonitorSummary = new CollectionMonitorSummary();
collectionMonitorSummary.setAggregationDetails(aggregationDetails);
collectionMonitorSummary.setAggregationInfo(aggregationInfo);
size = 0;
do {
aggregationDetails = repositoryService.getRepositoryAggregations(repoId, size, size + 50);
for (AggregationDetails aggregationDetail : aggregationDetails) {
if (aggregationDetail.getIndexedVersion()) {
aggregationInfo = aggregationService.getRepositoryAggregations(repoId, size, size + 50);
for (AggregationInfo aggregationDetail : aggregationInfo) {
if (aggregationDetail.isIndexedVersion()) {
collectionMonitorSummary.setLastIndexedVersion(aggregationDetail);
break;
}
}
size += 30;
} while (aggregationDetails.size() != 0 && collectionMonitorSummary.getLastIndexedVersion() == null);
} while (aggregationInfo.size() != 0 && collectionMonitorSummary.getLastIndexedVersion() == null);
return collectionMonitorSummary;
}
@ -90,5 +94,4 @@ public class DashboardController {
return new BrokerSummary(brokerService.getSimpleSubscriptionsOfUser(((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail()), brokerService.getTopicsForDatasource(datasourceName));
}
}

View File

@ -6,9 +6,9 @@ import eu.dnetlib.repo.manager.exception.BrokerException;
import eu.dnetlib.repo.manager.exception.EndPointException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.exception.ServerError;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
@ -26,7 +26,7 @@ import java.net.UnknownHostException;
@Order(Ordered.HIGHEST_PRECEDENCE)
public class GenericControllerAdvice {
private Logger logger = LogManager.getLogger(GenericControllerAdvice.class);
private Logger logger = LoggerFactory.getLogger(GenericControllerAdvice.class);
@ResponseStatus(HttpStatus.NOT_FOUND)

View File

@ -0,0 +1,47 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.domain.InterfaceComplianceRequest;
import eu.dnetlib.repo.manager.domain.InterfaceComplianceRequestId;
import eu.dnetlib.repo.manager.domain.dto.InterfaceComplianceRequestDTO;
import eu.dnetlib.repo.manager.service.InterfaceComplianceService;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
@RestController
@RequestMapping("compliance")
public class InterfaceComplianceRequestController {
private final InterfaceComplianceService service;
public InterfaceComplianceRequestController(InterfaceComplianceService service) {
this.service = service;
}
@GetMapping("{repositoryId}/{interfaceId}")
public InterfaceComplianceRequest get(@PathVariable("repositoryId") String repositoryId, @PathVariable("interfaceId") String interfaceId) {
InterfaceComplianceRequestId id = new InterfaceComplianceRequestId();
id.setRepositoryId(repositoryId);
id.setInterfaceId(interfaceId);
return service.getById(id).orElse(null);
}
@GetMapping()
public Iterable<InterfaceComplianceRequest> get() {
return service.get();
}
@PostMapping()
public InterfaceComplianceRequest add(@RequestBody InterfaceComplianceRequestDTO requestDTO) {
requestDTO.setSubmissionDate(new Date());
return service.create(InterfaceComplianceRequest.from(requestDTO));
}
@DeleteMapping("{repositoryId}/{interfaceId}")
public void delete(@PathVariable("repositoryId") String repositoryId, @PathVariable("interfaceId") String interfaceId) {
InterfaceComplianceRequestId id = new InterfaceComplianceRequestId();
id.setRepositoryId(repositoryId);
id.setInterfaceId(interfaceId);
this.service.delete(id);
}
}

View File

@ -6,9 +6,10 @@ import eu.dnetlib.repo.manager.domain.JobsOfUser;
import eu.dnetlib.repo.manager.service.MonitorServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
@ -20,8 +21,7 @@ import org.springframework.web.bind.annotation.*;
@Api(description = "Monitor API", tags = {"monitor"})
public class MonitorController {
private static final Logger LOGGER = Logger
.getLogger(MonitorController.class);
private static final Logger logger = LoggerFactory.getLogger(MonitorController.class);
@Autowired
private MonitorServiceImpl monitorService;

View File

@ -9,7 +9,8 @@ import eu.dnetlib.repo.manager.service.PiWikServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.MediaType;
@ -33,8 +34,7 @@ import java.util.List;
@Api(description = "Piwik API", tags = {"piwik"})
public class PiWikController {
private static final Logger LOGGER = Logger
.getLogger(PiWikController.class);
private static final Logger logger = LoggerFactory.getLogger(PiWikController.class);
@Autowired
private PiWikServiceImpl piWikService;
@ -76,6 +76,7 @@ public class PiWikController {
results.setResults(returning);
return results;
}
@ApiImplicitParams({
@ApiImplicitParam(name = "from", dataType = "number", paramType = "query"),
@ApiImplicitParam(name = "quantity", dataType = "number", paramType = "query"),
@ -103,25 +104,22 @@ public class PiWikController {
sb.append(" Repository ID , Repository name, Country, Site ID, Authentication token, Creation date, Requestor full name, Requestor email, Validated, Validation date, Comment \n");
for(PiwikInfo piwikInfo : returning){
sb.append(
(piwikInfo.getRepositoryId() == null ? "," : piwikInfo.getRepositoryId()+ ",")+
(piwikInfo.getRepositoryName() == null ? "," : piwikInfo.getRepositoryName()+ ",")+
(piwikInfo.getCountry() == null ? "," : piwikInfo.getCountry()+ ",")+
(piwikInfo.getSiteId() == null ? "," : piwikInfo.getSiteId()+ ",") +
(piwikInfo.getAuthenticationToken() == null ? "," : piwikInfo.getAuthenticationToken()+ ",")+
(piwikInfo.getCreationDate() == null ? "," : piwikInfo.getCreationDate().toString()+ ",") +
(piwikInfo.getRequestorName() == null ? "," : piwikInfo.getRequestorName()+ ",") +
(piwikInfo.getRequestorEmail() == null ? "," : piwikInfo.getRequestorEmail()+ ",")+
piwikInfo.isValidated() + "," +
(piwikInfo.getValidationDate() == null ? "," : piwikInfo.getValidationDate().toString()+ ",") +
(piwikInfo.getComment() == null ? "\n" : piwikInfo.getComment()+ "\n")
);
sb.append(piwikInfo.getRepositoryId() == null ? "," : piwikInfo.getRepositoryId() + ",")
.append(piwikInfo.getRepositoryName() == null ? "," : piwikInfo.getRepositoryName() + ",")
.append(piwikInfo.getCountry() == null ? "," : piwikInfo.getCountry() + ",")
.append(piwikInfo.getSiteId() == null ? "," : piwikInfo.getSiteId() + ",")
.append(piwikInfo.getAuthenticationToken() == null ? "," : piwikInfo.getAuthenticationToken() + ",")
.append(piwikInfo.getCreationDate() == null ? "," : piwikInfo.getCreationDate().toString() + ",")
.append(piwikInfo.getRequestorName() == null ? "," : piwikInfo.getRequestorName() + ",")
.append(piwikInfo.getRequestorEmail() == null ? "," : piwikInfo.getRequestorEmail() + ",")
.append(piwikInfo.isValidated()).append(",")
.append(piwikInfo.getValidationDate() == null ? "," : piwikInfo.getValidationDate().toString() + ",")
.append(piwikInfo.getComment() == null ? "\n" : piwikInfo.getComment() + "\n");
}
writer.write(sb.toString());
} catch (FileNotFoundException e) {
LOGGER.error(e.getMessage());
logger.error(e.getMessage());
}
@ -141,7 +139,6 @@ public class PiWikController {
strDate);
response.setHeader(headerKey, headerValue);
return new FileSystemResource(p.toFile());
}

View File

@ -11,7 +11,8 @@ import io.micrometer.core.instrument.binder.system.UptimeMetrics;
import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.prometheus.client.exporter.common.TextFormat;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
@ -24,7 +25,7 @@ import java.io.File;
@RestController
@RequestMapping("/actuator/prometheus")
public class PrometheusController { // TODO: remove this with migration to Spring Boot 2
private static final Logger LOGGER = Logger.getLogger(PrometheusController.class);
private static final Logger logger = LoggerFactory.getLogger(PrometheusController.class);
private final PiWikService piWikService;
private final RepositoryService repositoryService;
@ -52,7 +53,7 @@ public class PrometheusController { // TODO: remove this with migration to Sprin
try (JvmGcMetrics jvmGcMetrics = new JvmGcMetrics() ) {
jvmGcMetrics.bindTo(registry);
} catch (Exception e) {
LOGGER.error("", e);
logger.error("", e);
}
new JvmMemoryMetrics().bindTo(registry);
new DiskSpaceMetrics(new File("/")).bindTo(registry);

View File

@ -1,19 +1,20 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.domain.Repository;
import eu.dnetlib.repo.manager.domain.RepositoryInterface;
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.RepositoryService;
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
import eu.dnetlib.repo.manager.utils.JsonUtils;
import io.swagger.annotations.Api;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
@ -35,15 +36,19 @@ import java.util.Map;
@Api(description = "Repository API", tags = {"repositories"})
public class RepositoryController {
private static final Logger logger = Logger.getLogger(RepositoryController.class);
private static final Logger logger = LoggerFactory.getLogger(RepositoryController.class);
private final RepositoryService repositoryService;
private final AggregationService aggregationService;
private final AuthorizationService authorizationService;
@Autowired
RepositoryController(RepositoryService repositoryService,
AuthorizationService authorizationService) {
AggregationService aggregationService, AuthorizationService authorizationService) {
this.repositoryService = repositoryService;
this.aggregationService = aggregationService;
this.authorizationService = authorizationService;
}
@ -121,15 +126,15 @@ public class RepositoryController {
@RequestMapping(value = "/getRepositoryAggregations/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<AggregationDetails> getRepositoryAggregations(@PathVariable("id") String id) throws JSONException {
return repositoryService.getRepositoryAggregations(id, 0, 20);
public List<AggregationInfo> getRepositoryAggregations(@PathVariable("id") String id) throws JSONException {
return aggregationService.getRepositoryAggregations(id, 0, 20);
}
@RequestMapping(value = "/getRepositoryAggregationsByYear/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, List<AggregationDetails>> getRepositoryAggregationsByYear(@PathVariable("id") String id) throws JSONException {
return repositoryService.getRepositoryAggregationsByYear(id);
public Map<String, List<AggregationInfo>> getRepositoryAggregationsByYear(@PathVariable("id") String id) throws JSONException {
return aggregationService.getRepositoryAggregationsByYear(id);
}
@RequestMapping(value = "/getRepositoriesByName/{name:.+}/{page}/{size}/", method = RequestMethod.GET,
@ -205,9 +210,10 @@ public class RepositoryController {
@PreAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOf(#id)")
public RepositoryInterface addRepositoryInterface(@RequestParam("datatype") String datatype,
@RequestParam("repoId") String id,
@RequestParam(required = false, name = "desiredCompatibilityLevel") String desiredCompatibilityLevel,
@RequestParam(value = "comment", required = false) String comment,
@RequestBody RepositoryInterface repositoryInterface) throws Exception {
return repositoryService.addRepositoryInterface(datatype, id, comment, repositoryInterface);
return repositoryService.addRepositoryInterface(datatype, id, comment, repositoryInterface, desiredCompatibilityLevel);
}
@RequestMapping(value = "/updateRepositoryInterface", method = RequestMethod.POST,
@ -215,9 +221,10 @@ public class RepositoryController {
@ResponseBody
@PreAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOf(#id)")
public RepositoryInterface updateRepositoryInterface(@RequestParam("repoId") String id,
@RequestParam(required = false, name = "desiredCompatibilityLevel") String desiredCompatibilityLevel,
@RequestParam(value = "comment", required = false) String comment,
@RequestBody RepositoryInterface repositoryInterface) throws Exception {
return repositoryService.updateRepositoryInterface(id, comment, repositoryInterface);
return repositoryService.updateRepositoryInterface(id, comment, repositoryInterface, desiredCompatibilityLevel);
}
@RequestMapping(value = "/getUrlsOfUserRepos/{page}/{size}/", method = RequestMethod.GET,

View File

@ -19,8 +19,7 @@ public class StatsController {
@Autowired
private StatsServiceImpl statsService;
@RequestMapping(value = "/getStatistics" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/getStatistics" , method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map getStatistics(){
return statsService.getStatistics();

View File

@ -6,7 +6,6 @@ import eu.dnetlib.repo.manager.service.security.AuthoritiesUpdater;
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
import eu.dnetlib.repo.manager.service.security.RoleMappingService;
import eu.dnetlib.repo.manager.utils.JsonUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@ -97,7 +96,7 @@ public class UserRoleController {
@RequestMapping(method = RequestMethod.GET, path = "/users/{email}/roles")
@PreAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or hasAuthority('REGISTERED_USER') and authentication.userInfo.email==#email")
public ResponseEntity<Collection<String>> getRolesByEmail(@PathVariable("email") String email) {
return ResponseEntity.ok(authorizationService.getUserRoles(email));
return ResponseEntity.ok(authorizationService.getUserRolesByEmail(email));
}
@ -107,4 +106,4 @@ public class UserRoleController {
return ResponseEntity.ok(authorizationService.getUserRoles());
}
}
}

View File

@ -5,8 +5,8 @@ import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.domain.functionality.validator.RuleSet;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.domain.InterfaceInformation;
import eu.dnetlib.repo.manager.exception.ValidationServiceException;
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.annotations.Api;
@ -112,8 +112,8 @@ public class ValidatorController {
@RequestMapping(value = "/complete" , method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public void validationCompleted(
@RequestParam(value = "interfaceId") String interfaceId,
@RequestParam(value = "repoId") String repoId,
@RequestParam(value = "interfaceId") String interfaceId,
@RequestParam(value = "jobId") String jobId,
@RequestParam(value = "issuerEmail") String issuerEmail,
@RequestParam(value = "isUpdate") boolean isUpdate,
@ -121,7 +121,7 @@ public class ValidatorController {
@RequestParam(value = "scoreUsage") int scoreUsage,
@RequestParam(value = "scoreContent") int scoreContent) throws Exception {
emailUtils.sendUponJobCompletion(repoId,interfaceId,scoreUsage,scoreContent,isSuccess,isUpdate,issuerEmail, jobId);
validatorService.onComplete(repoId, interfaceId, jobId, issuerEmail, isUpdate, isSuccess, scoreUsage, scoreContent);
}

View File

@ -1,63 +0,0 @@
package eu.dnetlib.repo.manager.domain;
import java.util.Calendar;
import java.util.Date;
public class AggregationDetails{
private String aggregationStage;
private Date date;
private int numberOfRecords;
private String collectionMode;
private Boolean indexedVersion;
public AggregationDetails() {
}
public String getAggregationStage() {
return aggregationStage;
}
public String getCollectionMode() {
return collectionMode;
}
public void setCollectionMode(String collectionMode) {
this.collectionMode = collectionMode;
}
public void setAggregationStage(String aggregationStage) {
this.aggregationStage = aggregationStage;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public int getNumberOfRecords() {
return numberOfRecords;
}
public void setNumberOfRecords(int numberOfRecords) {
this.numberOfRecords = numberOfRecords;
}
public String getYear() {
Calendar calendar = Calendar.getInstance();
calendar.setTime(getDate());
return String.valueOf(calendar.get(Calendar.YEAR));
}
public Boolean getIndexedVersion() {
return indexedVersion;
}
public void setIndexedVersion(Boolean indexedVersion) {
this.indexedVersion = indexedVersion;
}
}

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,32 +1,34 @@
package eu.dnetlib.repo.manager.domain;
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
import java.util.List;
public class CollectionMonitorSummary {
private List<AggregationDetails> aggregationDetails;
private List<AggregationInfo> aggregationInfo;
private AggregationDetails lastIndexedVersion;
private AggregationInfo lastIndexedVersion;
public CollectionMonitorSummary(){}
public CollectionMonitorSummary(List<AggregationDetails> aggregationDetails, AggregationDetails lastIndexedVersion) {
this.aggregationDetails = aggregationDetails;
public CollectionMonitorSummary(List<AggregationInfo> aggregationInfo, AggregationInfo lastIndexedVersion) {
this.aggregationInfo = aggregationInfo;
this.lastIndexedVersion = lastIndexedVersion;
}
public List<AggregationDetails> getAggregationDetails() {
return aggregationDetails;
public List<AggregationInfo> getAggregationInfo() {
return aggregationInfo;
}
public void setAggregationDetails(List<AggregationDetails> aggregationDetails) {
this.aggregationDetails = aggregationDetails;
public void setAggregationInfo(List<AggregationInfo> aggregationInfo) {
this.aggregationInfo = aggregationInfo;
}
public AggregationDetails getLastIndexedVersion() {
public AggregationInfo getLastIndexedVersion() {
return lastIndexedVersion;
}
public void setLastIndexedVersion(AggregationDetails lastIndexedVersion) {
public void setLastIndexedVersion(AggregationInfo lastIndexedVersion) {
this.lastIndexedVersion = lastIndexedVersion;
}
}

View File

@ -1,8 +1,8 @@
package eu.dnetlib.repo.manager.domain;
import javax.persistence.Transient;
import java.util.Date;
import java.util.Set;
import javax.persistence.Transient;
public class DatasourceDetails {

View File

@ -1,7 +1,5 @@
package eu.dnetlib.repo.manager.domain;
import eu.dnetlib.repo.manager.domain.Repository;
import java.util.ArrayList;
import java.util.List;

View File

@ -0,0 +1,95 @@
package eu.dnetlib.repo.manager.domain;
import eu.dnetlib.repo.manager.domain.dto.InterfaceComplianceRequestDTO;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Transient;
import java.util.Date;
@Entity
@IdClass(InterfaceComplianceRequestId.class)
public class InterfaceComplianceRequest {
@Id
String repositoryId;
@Id
String interfaceId;
String desiredCompatibilityLevel;
Date submissionDate;
public InterfaceComplianceRequest() {
this.submissionDate = new Date();
}
public InterfaceComplianceRequest(String repositoryId, String interfaceId, String desiredCompatibilityLevel) {
this.submissionDate = new Date();
this.repositoryId = repositoryId;
this.interfaceId = interfaceId;
this.desiredCompatibilityLevel = desiredCompatibilityLevel;
}
public static InterfaceComplianceRequest from(InterfaceComplianceRequestDTO dto) {
InterfaceComplianceRequest request = new InterfaceComplianceRequest();
request.setRepositoryId(dto.getRepositoryId());
request.setInterfaceId(dto.getInterfaceId());
if (dto.getSubmissionDate() != null) {
request.setSubmissionDate(dto.getSubmissionDate());
} else {
request.setSubmissionDate(new Date());
}
request.setDesiredCompatibilityLevel(dto.getDesiredCompatibilityLevel());
return request;
}
@Transient
public InterfaceComplianceRequestId getId() {
InterfaceComplianceRequestId id = new InterfaceComplianceRequestId();
id.repositoryId = this.repositoryId;
id.interfaceId = this.interfaceId;
return id;
}
public String getRepositoryId() {
return repositoryId;
}
public void setRepositoryId(String repositoryId) {
this.repositoryId = repositoryId;
}
public String getInterfaceId() {
return interfaceId;
}
public void setInterfaceId(String interfaceId) {
this.interfaceId = interfaceId;
}
public String getDesiredCompatibilityLevel() {
return desiredCompatibilityLevel;
}
public void setDesiredCompatibilityLevel(String desiredCompatibilityLevel) {
this.desiredCompatibilityLevel = desiredCompatibilityLevel;
}
public Date getSubmissionDate() {
return submissionDate;
}
public void setSubmissionDate(Date submissionDate) {
this.submissionDate = submissionDate;
}
@Override
public String toString() {
return "InterfaceComplianceRequest{" +
"repositoryId='" + repositoryId + '\'' +
", interfaceId='" + interfaceId + '\'' +
", desiredCompatibilityLevel='" + desiredCompatibilityLevel + '\'' +
", submissionDate=" + submissionDate +
'}';
}
}

View File

@ -0,0 +1,50 @@
package eu.dnetlib.repo.manager.domain;
import java.io.Serializable;
public class InterfaceComplianceRequestId implements Serializable {
String repositoryId;
String interfaceId;
public String getRepositoryId() {
return repositoryId;
}
public void setRepositoryId(String repositoryId) {
this.repositoryId = repositoryId;
}
public String getInterfaceId() {
return interfaceId;
}
public void setInterfaceId(String interfaceId) {
this.interfaceId = interfaceId;
}
public static InterfaceComplianceRequestId of(String repositoryId, String interfaceId) {
InterfaceComplianceRequestId id = new InterfaceComplianceRequestId();
id.setRepositoryId(repositoryId);
id.setInterfaceId(interfaceId);
return id;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof InterfaceComplianceRequestId)) return false;
InterfaceComplianceRequestId that = (InterfaceComplianceRequestId) o;
if (getRepositoryId() != null ? !getRepositoryId().equals(that.getRepositoryId()) : that.getRepositoryId() != null)
return false;
return getInterfaceId() != null ? getInterfaceId().equals(that.getInterfaceId()) : that.getInterfaceId() == null;
}
@Override
public int hashCode() {
int result = getRepositoryId() != null ? getRepositoryId().hashCode() : 0;
result = 31 * result + (getInterfaceId() != null ? getInterfaceId().hashCode() : 0);
return result;
}
}

View File

@ -3,7 +3,8 @@ package eu.dnetlib.repo.manager.domain;
import eu.dnetlib.domain.data.DataCollectionType;
import eu.dnetlib.domain.data.PiwikInfo;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
/**
* The domain object for the Repository resource data structure

View File

@ -0,0 +1,47 @@
package eu.dnetlib.repo.manager.domain.dto;
import java.util.Date;
public class InterfaceComplianceRequestDTO {
String repositoryId;
String interfaceId;
String desiredCompatibilityLevel;
Date submissionDate;
public InterfaceComplianceRequestDTO() {
// no-arg constructor
}
public String getRepositoryId() {
return repositoryId;
}
public void setRepositoryId(String repositoryId) {
this.repositoryId = repositoryId;
}
public String getInterfaceId() {
return interfaceId;
}
public void setInterfaceId(String interfaceId) {
this.interfaceId = interfaceId;
}
public String getDesiredCompatibilityLevel() {
return desiredCompatibilityLevel;
}
public void setDesiredCompatibilityLevel(String desiredCompatibilityLevel) {
this.desiredCompatibilityLevel = desiredCompatibilityLevel;
}
public Date getSubmissionDate() {
return submissionDate;
}
public void setSubmissionDate(Date submissionDate) {
this.submissionDate = submissionDate;
}
}

View File

@ -0,0 +1,13 @@
package eu.dnetlib.repo.manager.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(HttpStatus.CONFLICT)
public class ResourceConflictException extends RuntimeException {
public ResourceConflictException(String message) {
super(message);
}
}

View File

@ -0,0 +1,15 @@
package eu.dnetlib.repo.manager.repository;
import eu.dnetlib.repo.manager.domain.InterfaceComplianceRequest;
import eu.dnetlib.repo.manager.domain.InterfaceComplianceRequestId;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.Set;
@Repository
public interface InterfaceComplianceRequestsRepository extends CrudRepository<InterfaceComplianceRequest, InterfaceComplianceRequestId> {
Set<InterfaceComplianceRequest> findAllBySubmissionDateBefore(Date submittedBefore);
}

View File

@ -0,0 +1,17 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
import org.json.JSONException;
import java.util.List;
import java.util.Map;
public interface AggregationService {
<T extends AggregationInfo> List<T> getRepositoryAggregations(String id) throws JSONException;
<T extends AggregationInfo> List<T> getRepositoryAggregations(String id, int from, int size) throws JSONException;
<T extends AggregationInfo> Map<String, List<T>> getRepositoryAggregationsByYear(String id) throws JSONException;
}

View File

@ -0,0 +1,81 @@
package eu.dnetlib.repo.manager.service;
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;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static eu.dnetlib.repo.manager.utils.DateUtils.getYear;
@Service("aggregationService")
public class AggregationServiceImpl implements AggregationService {
private static final Logger logger = LoggerFactory.getLogger(AggregationServiceImpl.class);
@Value("${services.provide.clients.dsm}")
private String baseAddress;
private final RestTemplate restTemplate;
public AggregationServiceImpl(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
@Override
public <T extends AggregationInfo> List<T> getRepositoryAggregations(String id) {
logger.debug("Retrieving aggregations for repository with id : " + id);
UriComponents uriComponents = getAggregationHistory(id);
AggregationHistoryResponse rs = restTemplate.getForObject(uriComponents.toUri(), AggregationHistoryResponse.class);
return rs != null ? (List<T>) rs.getAggregationInfo() : null;
}
@Override
public <T extends AggregationInfo> List<T> getRepositoryAggregations(String id, int from, int size) {
List<T> res = getRepositoryAggregations(id);
return res.subList(from, Math.min(from + size, res.size()));
}
@Override
public <T extends AggregationInfo> Map<String, List<T>> getRepositoryAggregationsByYear(String id) {
logger.debug("Retrieving aggregations (by year) for repository with id : " + id);
List<T> aggregationHistory = getRepositoryAggregations(id);
return aggregationHistory.isEmpty() ? new HashMap<>() : createYearMap(aggregationHistory);
}
private <T extends AggregationInfo> Map<String, List<T>> createYearMap(List<T> aggregationHistory) {
return aggregationHistory.stream()
.sorted(Comparator.comparing(AggregationInfo::getDate).reversed())
.collect(Collectors.groupingBy(item -> getYear(item.getDate())));
}
private UriComponents getAggregationHistory(String repoId) {
return UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/aggregationhistory/")
.path(repoId)
.build().expand(repoId).encode();
}
}

View File

@ -1,8 +1,8 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.repo.manager.exception.BrokerException;
import eu.dnetlib.repo.manager.domain.Term;
import eu.dnetlib.repo.manager.domain.broker.*;
import eu.dnetlib.repo.manager.exception.BrokerException;
import org.json.JSONException;
import org.springframework.http.ResponseEntity;

View File

@ -2,13 +2,15 @@ package eu.dnetlib.repo.manager.service;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.repo.manager.exception.BrokerException;
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
import eu.dnetlib.repo.manager.domain.Term;
import eu.dnetlib.repo.manager.domain.Tuple;
import eu.dnetlib.repo.manager.domain.broker.*;
import eu.dnetlib.repo.manager.exception.BrokerException;
import org.apache.commons.lang.NotImplementedException;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
@ -26,7 +28,10 @@ import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service("brokerService")
public class BrokerServiceImpl implements BrokerService {
@ -40,15 +45,14 @@ public class BrokerServiceImpl implements BrokerService {
@Value("${services.provide.topic_types.url}")
private String topicsURL;
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
.getLogger(BrokerServiceImpl.class);
private static final Logger logger = LoggerFactory.getLogger(BrokerServiceImpl.class);
@Autowired
RestTemplate restTemplate;
private HttpHeaders httpHeaders;
private HashMap<String, Term> topics = new HashMap<String, Term>();
private HashMap<String, Term> topics = new HashMap<>();
@PostConstruct
private void initDnetTopicsMap() {
@ -56,14 +60,14 @@ public class BrokerServiceImpl implements BrokerService {
httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type", "application/json");
LOGGER.debug("Init dnet topics!");
logger.debug("Init dnet topics!");
try (InputStream is = new URL(topicsURL).openStream()) {
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(is);
for (JsonNode term : root.path("terms"))
topics.put(term.path("code").textValue(), parseTerm(term));
} catch (IOException e) {
LOGGER.error("Exception on initDnetTopicsMap", e);
logger.error("Exception on initDnetTopicsMap", e);
}
}
@ -89,7 +93,7 @@ public class BrokerServiceImpl implements BrokerService {
// ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(user)));
// }
} catch (Exception e) {
LOGGER.error("Exception on getDatasourcesOfUser", e);
logger.error("Exception on getDatasourcesOfUser", e);
}
long end = System.currentTimeMillis();
System.out.println("Getting datasources of user in " + (end - start) + "ms");
@ -121,7 +125,7 @@ public class BrokerServiceImpl implements BrokerService {
@Override
public EventsPage advancedShowEvents(String page,
String size,
AdvQueryObject advQueryObject) throws BrokerException, JSONException, IOException {
AdvQueryObject advQueryObject) throws BrokerException {
final String service = "/events/{page}/{pageSize}";
@ -156,7 +160,7 @@ public class BrokerServiceImpl implements BrokerService {
for (RepositorySnippet repo : repositories) {
BrowseEntry temp = new BrowseEntry();
temp.setValue(repo.getOfficialname());
temp.setSize(new Long(0));
temp.setSize(0L);
for (BrowseEntry e : getTopicsForDatasource(repo.getOfficialname())) {
temp.setSize(temp.getSize() + e.getSize());
}
@ -165,12 +169,7 @@ public class BrokerServiceImpl implements BrokerService {
}
// sort the collection by the second field of the tuple which is size
Collections.sort(entries, new Comparator<Tuple<BrowseEntry, String>>() {
@Override
public int compare(Tuple<BrowseEntry, String> e1, Tuple<BrowseEntry, String> e2) {
return (int) (e2.getFirst().getSize().longValue() - e1.getFirst().getSize().longValue());
}
});
entries.sort((e1, e2) -> (int) (e2.getFirst().getSize() - e1.getFirst().getSize()));
long stop = System.currentTimeMillis();
System.out.println("getDatasourcesOfUserType returned in " + (stop - start) + "ms ");
@ -213,7 +212,7 @@ public class BrokerServiceImpl implements BrokerService {
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
.queryParam("email", userEmail);
LOGGER.debug(builder.build().encode().toUri());
logger.debug("{}", builder.build().encode().toUri());
ResponseEntity<Map<String, List<SimpleSubscriptionDesc>>> resp;
try {
resp = restTemplate.exchange(

View File

@ -1,10 +1,15 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.repo.manager.domain.*;
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
import eu.dnetlib.repo.manager.domain.MetricsInfo;
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
import eu.dnetlib.repo.manager.domain.broker.BrowseEntry;
import eu.dnetlib.repo.manager.exception.BrokerException;
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
import org.apache.log4j.Logger;
import eu.dnetlib.repo.manager.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -14,11 +19,14 @@ import java.util.List;
@Service("dashboardService")
public class DashboardServiceImpl implements DashboardService {
private static final Logger logger = Logger.getLogger(DashboardServiceImpl.class);
private static final Logger logger = LoggerFactory.getLogger(DashboardServiceImpl.class);
@Autowired
private RepositoryService repositoryService;
@Autowired
private AggregationService aggregationService;
@Autowired
private BrokerService brokerService;
@ -30,7 +38,6 @@ public class DashboardServiceImpl implements DashboardService {
List<RepositorySummaryInfo> repositorySummaryInfoList = new ArrayList<>();
try {
List<RepositorySnippet> repositoriesOfUser = repositoryService.getRepositoriesSnippetsOfUser(userEmail, page, size);
for (RepositorySnippet repository : repositoriesOfUser) {
RepositorySummaryInfo repositorySummaryInfo = new RepositorySummaryInfo();
@ -40,44 +47,37 @@ public class DashboardServiceImpl implements DashboardService {
//TODO getRepositoryAggregations returns only the 20 more recent items. Is it positive that we will find an indexed version there?
long start = System.currentTimeMillis();
List<AggregationDetails> aggregationDetailsList = repositoryService.getRepositoryAggregations(repository.getId(), 0, 20);
for (AggregationDetails aggregationDetails : aggregationDetailsList) {
if (aggregationDetails.getIndexedVersion()) {
repositorySummaryInfo.setRecordsCollected(aggregationDetails.getNumberOfRecords());
repositorySummaryInfo.setLastIndexedVersion(aggregationDetails.getDate());
List<AggregationInfo> aggregationInfoList = aggregationService.getRepositoryAggregations(repository.getId(), 0, 20);
for (AggregationInfo aggregationInfo : aggregationInfoList) {
if (aggregationInfo.isIndexedVersion()) {
repositorySummaryInfo.setRecordsCollected(aggregationInfo.getNumberOfRecords());
repositorySummaryInfo.setLastIndexedVersion(DateUtils.toDate(aggregationInfo.getDate()));
break;
}
}
long end = System.currentTimeMillis();
System.out.println("Got repo aggregations in " + (end - start) + "ms");
try {
MetricsInfo metricsInfo = repositoryService.getMetricsInfoForRepository(repository.getId());
repositorySummaryInfo.setTotalDownloads(metricsInfo.getMetricsNumbers().getTotalDownloads());
repositorySummaryInfo.setTotalViews(metricsInfo.getMetricsNumbers().getTotalViews());
} catch (RepositoryServiceException e) {
logger.error("Exception getting metrics info for repository: " + repository.getId(), e);
}
try {
List<BrowseEntry> events = brokerService.getTopicsForDatasource(repository.getOfficialname());
Long totalEvents = 0L;
for (BrowseEntry browseEntry : events)
totalEvents += browseEntry.getSize();
repositorySummaryInfo.setEnrichmentEvents(totalEvents);
} catch (BrokerException e) {
logger.error("Exception getting broker events for repository: " + repository.getId(), e);
}
repositorySummaryInfoList.add(repositorySummaryInfo);
}
} catch (Exception e) {
logger.error("Something baad happened!", e);
}

View File

@ -1,93 +1,103 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.repo.manager.domain.InterfaceComplianceRequest;
import eu.dnetlib.repo.manager.domain.Repository;
import eu.dnetlib.repo.manager.domain.RepositoryInterface;
import eu.dnetlib.domain.functionality.validator.JobForValidation;
import org.springframework.scheduling.annotation.Async;
import org.springframework.security.core.Authentication;
import java.util.List;
public interface EmailUtils {
@Async
void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception;
void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo);
@Async
void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception;
void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo);
@Async
void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) throws Exception;
void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo);
@Async
void sendUserMetricsEnabled(PiwikInfo piwikInfo) throws Exception;
void sendUserMetricsEnabled(PiwikInfo piwikInfo);
/****USER REGISTRATION REQUEST EMAILS****/
@Async
void sendAdminRegistrationEmail(Repository repository, Authentication authentication) throws Exception;
void sendAdminRegistrationEmail(Repository repository, Authentication authentication);
@Async
void sendUserRegistrationEmail(Repository repository, Authentication authentication) throws Exception;
void sendUserRegistrationEmail(Repository repository, Authentication authentication);
@Async
void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication);
@Async
void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication);
/****SUCCESSFUL REGISTRATION RESULTS EMAILS****/
@Async
void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
@Async
void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
/****FAILURE REGISTRATION RESULTS EMAILS****/
@Async
void sendUserRegistrationResultsFailureEmail(String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
@Async
void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
/****SUCCESSFUL UPDATE RESULTS EMAILS****/
@Async
void sendUserUpdateResultsSuccessEmail(String issuer, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
@Async
void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
/****FAILURE UPDATE RESULTS EMAILS****/
@Async
void sendUserUpdateResultsFailureEmail(String issuer, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
@Async
void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
/****FAILURE UPDATE INTERFACE COMPLIANCE****/
@Async
void sendUserUpdateInterfaceComplianceFailure(List<String> emails, Repository repository, RepositoryInterface repositoryInterface, InterfaceComplianceRequest request);
@Async
void sendAdminUpdateInterfaceComplianceFailure(Repository repository, RepositoryInterface repositoryInterface, InterfaceComplianceRequest request);
/****VALIDATION OF CONTENT PROVIDER EMAILS****/
@Async
void sendUserValidationResults(String issuer,String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendUserValidationResults(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
@Async
void sendAdminValidationResults(String issuer,String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendAdminValidationResults(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
/****GENERAL FAILURE OF VALIDATOR****/
@Async
void sendAdminGeneralFailure(String issuer,String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendAdminGeneralFailure(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
@Async
void sendAdminUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) throws Exception;
void sendAdminUpdateRepositoryInfoEmail(Repository repository, Authentication authentication);
@Async
void sendUserUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) throws Exception;
void sendUserUpdateRepositoryInfoEmail(Repository repository, Authentication authentication);
@Async
void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication);
@Async
void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication);
@Async
void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation) throws Exception;
void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation);
@Async
void sendUponJobCompletion(String repoId,

View File

@ -1,13 +1,15 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.repo.manager.domain.InterfaceComplianceRequest;
import eu.dnetlib.repo.manager.domain.Repository;
import eu.dnetlib.repo.manager.domain.RepositoryInterface;
import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.repo.manager.exception.ValidationServiceException;
import eu.dnetlib.utils.MailLibrary;
import org.apache.log4j.Logger;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication;
@ -21,7 +23,7 @@ import java.util.stream.Collectors;
@Component("emailUtils")
public class EmailUtilsImpl implements EmailUtils {
private final static Logger LOGGER = Logger.getLogger(EmailUtilsImpl.class);
private final static Logger logger = LoggerFactory.getLogger(EmailUtilsImpl.class);
private final MailLibrary mailLibrary;
private final RepositoryService repositoryService;
@ -45,33 +47,32 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception {
public void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) {
try {
String subject = "[OpenAIRE-Usage Statistics] New request to enable usage statistics";
String message =
"we have received a request to enable the OpenAIRE usage statistics for the following repository \n" +
"\n" +
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
"Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" +
"Matomo ID - " + piwikInfo.getSiteId() + "\n" +
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
"\n" +
"For more information about this request, go here: \n" +
this.baseUrl + "/admin/metrics";
"\n" +
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
"Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" +
"Matomo ID - " + piwikInfo.getSiteId() + "\n" +
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
"\n" +
"For more information about this request, go here: \n" +
this.baseUrl + "/admin/metrics";
message = createAdminMail(message);
this.sendMail(this.usageStatsAdminEmail, subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending request to enable metrics email to administrator: " + this.usageStatsAdminEmail, e);
throw e;
logger.error("Error while sending request to enable metrics email to administrator: " + this.usageStatsAdminEmail, e);
}
}
@Override
public void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception {
public void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) {
try {
String subject = "[OpenAIRE-Usage Statistics] Your request to enable usage statistics";
@ -102,37 +103,35 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(piwikInfo.getRequestorEmail(), subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending request to enable metrics email to user: " + piwikInfo.getRequestorEmail(), e);
throw e;
logger.error("Error while sending request to enable metrics email to user: " + piwikInfo.getRequestorEmail(), e);
}
}
@Override
public void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) throws Exception {
public void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) {
try {
String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled";
String message =
"The installation and configuration of OpenAIRE's tracking code for the following repository " +
"has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" +
"\n" +
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
"Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" +
"Piwik ID - " + piwikInfo.getSiteId() + "\n" +
"Authentication token - " + piwikInfo.getAuthenticationToken();
"has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" +
"\n" +
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
"Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" +
"Piwik ID - " + piwikInfo.getSiteId() + "\n" +
"Authentication token - " + piwikInfo.getAuthenticationToken();
message = createAdminMail(message);
this.sendMail(this.usageStatsAdminEmail, subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending metrics enabled notification email to administator: " + this.usageStatsAdminEmail, e);
throw e;
logger.error("Error while sending metrics enabled notification email to administator: " + this.usageStatsAdminEmail, e);
}
}
@Override
public void sendUserMetricsEnabled(PiwikInfo piwikInfo) throws Exception {
public void sendUserMetricsEnabled(PiwikInfo piwikInfo) {
try {
String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled";
@ -154,70 +153,67 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(piwikInfo.getRequestorEmail(), subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending metrics enabled notification email to user: " + piwikInfo.getRequestorEmail(), e);
throw e;
logger.error("Error while sending metrics enabled notification email to user: " + piwikInfo.getRequestorEmail(), e);
}
}
@Override
public void sendAdminRegistrationEmail(Repository repository, Authentication authentication) throws Exception {
public void sendAdminRegistrationEmail(Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE content provider registration for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"We received a request to register the " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]" +
" to the OpenAIRE compliant list of content providers. " +
"\n\n" +
"User Contact: " + authentication.getName() + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" +
"\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.";
" to the OpenAIRE compliant list of content providers. " +
"\n\n" +
"User Contact: " + authentication.getName() + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" +
"\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to the administrator", e);
throw e;
logger.error("Error while sending registration notification email to the administrator", e);
}
}
@Override
public void sendUserRegistrationEmail(Repository repository, Authentication authentication) throws Exception {
public void sendUserRegistrationEmail(Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE content provider registration for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"We received a request to register the " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]" +
" to the OpenAIRE compliant list of content providers. " +
"\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.\n\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
" to the OpenAIRE compliant list of content providers. " +
"\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.\n\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication);
this.sendMail(repository.getRegisteredby(), subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
throw e;
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
}
}
@Override
public void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
public void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request started for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"We received a request to add the following interface: \n\n" +
"Base URL: " + repositoryInterface.getBaseurl() + "\n" +
"Set: " + repositoryInterface.getAccessSet() + "\n" +
"Guidelines: " + repositoryInterface.getCompatibilityOverride() + "\n\n" +
"to " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n";
"Base URL: " + repositoryInterface.getBaseurl() + "\n" +
"Set: " + repositoryInterface.getAccessSet() + "\n" +
"Guidelines: " + repositoryInterface.getCompatibilityOverride() + "\n\n" +
"to " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n";
if (comment != null)
message += "\nThe users comment was '" + comment + "'\n";
@ -234,22 +230,21 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.provideAdminEmail, subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending registration of interface notification email to the administrator", e);
throw e;
logger.error("Error while sending registration of interface notification email to the administrator", e);
}
}
@Override
public void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
public void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request started for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"We received a request to add the following interface: \n\n" +
"Base URL: " + repositoryInterface.getBaseurl() + "\n" +
"Set: " + repositoryInterface.getAccessSet() + "\n" +
"Guidelines: " + repositoryInterface.getCompatibilityOverride() + "\n\n" +
"to " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n";
"Base URL: " + repositoryInterface.getBaseurl() + "\n" +
"Set: " + repositoryInterface.getAccessSet() + "\n" +
"Guidelines: " + repositoryInterface.getCompatibilityOverride() + "\n\n" +
"to " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n";
if (comment != null) {
message += "\n Your comment was '" + comment + "'\n";
@ -265,362 +260,404 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(repository.getRegisteredby(), subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending registration of interface notification email to user: " + repository.getRegisteredby(), e);
throw e;
logger.error("Error while sending registration of interface notification email to user: " + repository.getRegisteredby(), e);
}
}
@Override
public void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
public void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request - results (success) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"the compatibility test on " + "[" + repository.getOfficialname() + "]" +
" was successful and the datasource type \""+ repository.getEoscDatasourceType() + "\" will be prepared for aggregation in OpenAIRE."+
"\n\n" +
"Please note that it usually takes about 3-4 weeks until a data source is indexed and its metadata visible on openaire.eu.\n\n" +
"Registration identifier in OpenAIRE: "+ repository.getNamespaceprefix()+
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: "+ repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: "+ repositoryInterface.getCompatibilityOverride() +
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n"+
"This message has been generated manually\n\n"+
"If you have any questions, write to 'helpdesk@openaire.eu'.";
" was successful and the datasource type \"" + repository.getEoscDatasourceType() + "\" will be prepared for aggregation in OpenAIRE." +
"\n\n" +
"Please note that it usually takes about 3-4 weeks until a data source is indexed and it's metadata visible on openaire.eu.\n\n" +
"Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() +
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() +
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n" +
"This message has been generated manually\n\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication);
this.sendMail(repository.getRegisteredby(), subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
throw e;
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
}
}
@Override
public void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
public void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request - results (success) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"the compatibility test on " + "[" + repository.getOfficialname() + "]" +
" was successful and the datasource type \""+ repository.getEoscDatasourceType() + "\" will be prepared for aggregation in OpenAIRE."+
"\n\n" +
"Please note that it usually takes about 3-4 weeks until a data source is indexed and its metadata visible on openaire.eu.\n\n" +
"Registration identifier in OpenAIRE: "+ repository.getNamespaceprefix()+
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: "+ repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: "+ repositoryInterface.getCompatibilityOverride() +
"\n\nUser Contact:"+ issuerEmail +""+
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n"+
"This message has been generated manually\n\n"+
"If you have any questions, write to 'helpdesk@openaire.eu'.";
" was successful and the datasource type \"" + repository.getEoscDatasourceType() + "\" will be prepared for aggregation in OpenAIRE." +
"\n\n" +
"Please note that it usually takes about 3-4 weeks until a data source is indexed and it's metadata visible on openaire.eu.\n\n" +
"Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() +
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() +
"\n\nUser Contact:" + issuerEmail + "" +
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n" +
"This message has been generated manually\n\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
throw e;
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
}
}
@Override
public void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
public void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"the compatibility test on " + "[" + repository.getOfficialname() + "]" +
" was not successful and the registration process was interrupted."+
"\n\n" +
"We will check what caused the problem and get back to you within a couple of days.\n\n" +
"Registration identifier in OpenAIRE: "+ repository.getNamespaceprefix()+
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: "+ repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: "+ repositoryInterface.getCompatibilityOverride() +
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n"+
"This message has been generated manually\n\n"+
"If you have any questions, write to 'helpdesk@openaire.eu'.";
" was not successful and the registration process was interrupted." +
"\n\n" +
"We will check what caused the problem and get back to you within a couple of days.\n\n" +
"Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() +
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() +
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n" +
"This message has been generated manually\n\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication);
this.sendMail(repository.getRegisteredby(), subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
throw e;
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
}
}
@Override
public void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
public void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"the compatibility test on " + "[" + repository.getOfficialname() + "]" +
" was not successful and the registration process was interrupted."+
"\n\n" +
"We will check what caused the problem and get back to you within a couple of days.\n\n" +
"Registration identifier in OpenAIRE: "+ repository.getNamespaceprefix()+
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: "+ repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: "+ repositoryInterface.getCompatibilityOverride() +
"\n\nUser Contact:"+ issuerEmail +""+
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n"+
"This message has been generated manually\n\n"+
"If you have any questions, write to 'helpdesk@openaire.eu'.";
" was not successful and the registration process was interrupted." +
"\n\n" +
"We will check what caused the problem and get back to you within a couple of days.\n\n" +
"Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() +
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() +
"\n\nUser Contact:" + issuerEmail + "" +
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n" +
"This message has been generated manually\n\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
throw e;
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
}
}
@Override
public void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
public void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request - results (success) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"the compatibility test on [" + repository.getOfficialname()+"] has been successful\n\n" +
"We will check your transmitted information and adjust the aggregation settings accordingly. Please note that it usually takes about 3-4 weeks until the changes are visible on openaire.eu."+"\n\n" +
"Registration identifier in OpenAIRE: "+ repository.getNamespaceprefix()+
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: "+ repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: "+ repositoryInterface.getCompatibilityOverride() +
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n"+
"This message has been generated manually\n\n"+
"If you have any questions, write to 'helpdesk@openaire.eu'.";
"the compatibility test on [" + repository.getOfficialname() + "] has been successful\n\n" +
"We will check your transmitted information and adjust the aggregation settings accordingly. Please note that it usually takes about 3-4 weeks until the changes are visible on openaire.eu." + "\n\n" +
"Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() +
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() +
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n" +
"This message has been generated manually\n\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication);
this.sendMail(issuer, subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to the administrator", e);
throw e;
logger.error("Error while sending registration notification email to the administrator", e);
}
}
@Override
public void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE interface update request - results (success) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
public void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request - results (success) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"the compatibility test on [" + repository.getOfficialname()+"] has been successful\n\n" +
"We will check your transmitted information and adjust the aggregation settings accordingly. Please note that it usually takes about 3-4 weeks until the changes are visible on openaire.eu."+"\n\n" +
"Registration identifier in OpenAIRE: "+ repository.getNamespaceprefix()+
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: "+ repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: "+ repositoryInterface.getCompatibilityOverride() +
"\n\nUser Contact:"+ issuerEmail +""+
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n"+
"This message has been generated manually\n\n"+
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createAdminMail(message);
String message =
"the compatibility test on [" + repository.getOfficialname() + "] has been successful\n\n" +
"We will check your transmitted information and adjust the aggregation settings accordingly. Please note that it usually takes about 3-4 weeks until the changes are visible on openaire.eu." + "\n\n" +
"Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() +
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() +
"\n\nUser Contact:" + issuerEmail + "" +
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n" +
"This message has been generated manually\n\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
this.sendMail(this.provideAdminEmail, subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to the administrator", e);
throw e;
}
} catch (Exception e) {
logger.error("Error while sending registration notification email to the administrator", e);
}
}
@Override
public void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
public void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"the compatibility test on " + "[" + repository.getOfficialname() + "]" +
" was not successful."+
"\n\n" +
"WWe will check your transmitted information to see what caused the problem and get back to you within a couple of days.\n\n" +
"Registration identifier in OpenAIRE: "+ repository.getNamespaceprefix()+
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: "+ repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: "+ repositoryInterface.getCompatibilityOverride() +
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n"+
"This message has been generated manually\n\n"+
"If you have any questions, write to 'helpdesk@openaire.eu'.";
" was not successful." +
"\n\n" +
"WWe will check your transmitted information to see what caused the problem and get back to you within a couple of days.\n\n" +
"Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() +
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() +
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n" +
"This message has been generated manually\n\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication);
this.sendMail(issuer, subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
throw e;
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
}
}
@Override
public void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
public void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"the compatibility test on " + "[" + repository.getOfficialname() + "]" +
" was not successful."+
"\n\n" +
"WWe will check your transmitted information to see what caused the problem and get back to you within a couple of days.\n\n" +
"Registration identifier in OpenAIRE: "+ repository.getNamespaceprefix()+
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: "+ repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: "+ repositoryInterface.getCompatibilityOverride() +
"\n\nUser Contact:"+ issuerEmail +""+
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n"+
"This message has been generated manually\n\n"+
"If you have any questions, write to 'helpdesk@openaire.eu'.";
" was not successful." +
"\n\n" +
"WWe will check your transmitted information to see what caused the problem and get back to you within a couple of days.\n\n" +
"Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() +
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() +
"\n\nUser Contact:" + issuerEmail + "" +
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n" +
"This message has been generated manually\n\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
throw e;
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
}
}
@Override
public void sendUserValidationResults(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
public void sendUserUpdateInterfaceComplianceFailure(List<String> emails, Repository repository, RepositoryInterface repositoryInterface, InterfaceComplianceRequest request) {
try {
String subject = "OpenAIRE interface update compliance request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"The request for changing the compatibility of " + "[" + repository.getOfficialname() + "]" +
" was not successful." +
"\n\n" +
"Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() +
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + request.getDesiredCompatibilityLevel() +
"\n\n\nPlease do not reply to this email\n" +
"This message has been generated automatically\n\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createRepoAdminsMail(message);
this.sendMail(emails, subject, message);
} catch (Exception e) {
logger.error("Notification email to repository admins failed.\nRepository: {}\nRequest: {}", repository, request, e);
}
}
@Override
public void sendAdminUpdateInterfaceComplianceFailure(Repository repository, RepositoryInterface repositoryInterface, InterfaceComplianceRequest request) {
try {
String subject = "OpenAIRE interface update compliance request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"The request for changing the compatibility of " + "[" + repository.getOfficialname() + "]" +
" was not successful." +
"\n\n" +
"Registration identifier in OpenAIRE: " + repository.getNamespaceprefix() +
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + request.getDesiredCompatibilityLevel() +
"\n\n\nPlease do not reply to this email\n" +
"This message has been generated automatically\n\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
} catch (Exception e) {
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
}
}
@Override
public void sendUserValidationResults(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE validator - Test results ";
String message =
"the validation request you have submitted has finished. You can retrieve the results by following this url: "+ valBaseUrl+"" + jobId+" .\n\n" +
"Please do not reply to this message.\n" +
"This message has been generated automatically.\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
"the validation request you have submitted has finished. You can retrieve the results by following this url: " + valBaseUrl + "" + jobId + " .\n\n" +
"Please do not reply to this message.\n" +
"This message has been generated automatically.\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication);
this.sendMail(issuer, subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending validation submission notification email to user: " + issuer, e);
throw e;
logger.error("Error while sending validation submission notification email to user: " + issuer, e);
}
}
@Override
public void sendAdminValidationResults(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
public void sendAdminValidationResults(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE validator - Test results ";
String message =
"a validation request has finished. You can retrieve the results by following this url: "+ valBaseUrl+"" + jobId+" .\n\n" +
"\n\nUser Contact:"+ issuer +""+
"Please do not reply to this message.\n" +
"This message has been generated automatically.\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
"a validation request has finished. You can retrieve the results by following this url: " + valBaseUrl + "" + jobId + " .\n\n" +
"\n\nUser Contact:" + issuer + "" +
"Please do not reply to this message.\n" +
"This message has been generated automatically.\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending validation submission notification email to user: " + issuer, e);
throw e;
logger.error("Error while sending validation submission notification email to user: " + issuer, e);
}
}
@Override
public void sendAdminGeneralFailure(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
public void sendAdminGeneralFailure(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE validator - job failure";
String message =
"the validation job that was automatically submitted for the update/registration of the interface "+repositoryInterface.getId()+" ("+repositoryInterface.getBaseurl()+", "+repositoryInterface.getAccessSet()+") of the repository "+repository.getId()+" ("+repository.getOfficialname()+") failed to complete." +
"This message has been generated automatically.";
"the validation job that was automatically submitted for the update/registration of the interface " + repositoryInterface.getId() + " (" + repositoryInterface.getBaseurl() + ", " + repositoryInterface.getAccessSet() + ") of the repository " + repository.getId() + " (" + repository.getOfficialname() + ") failed to complete." +
"This message has been generated automatically.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending validation submission notification email to user: " + issuer, e);
throw e;
logger.error("Error while sending validation submission notification email to user: " + issuer, e);
}
}
@Override
public void sendAdminUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) throws Exception {
public void sendAdminUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE content provider update information for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"We received a request to update the basic information for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.";
"Please do not reply to this message\n" +
"This message has been generated automatically.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to the administrator", e);
throw e;
logger.error("Error while sending registration notification email to the administrator", e);
}
}
@Override
public void sendUserUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) throws Exception {
public void sendUserUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE content provider update information for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"We received a request to update the basic information for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.\n\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
"Please do not reply to this message\n" +
"This message has been generated automatically.\n\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication);
this.sendMail(repository.getRegisteredby(), subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
throw e;
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
}
}
@Override
public void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
public void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request started for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"We received a request to update the following interface: \n\n" +
"Base URL: " + repositoryInterface.getBaseurl() + "\n" +
"Set: " + repositoryInterface.getAccessSet() + "\n" +
"Guidelines: " + repositoryInterface.getCompatibilityOverride() + "\n\n" +
"for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n";
"Base URL: " + repositoryInterface.getBaseurl() + "\n" +
"Set: " + repositoryInterface.getAccessSet() + "\n" +
"Guidelines: " + repositoryInterface.getCompatibilityOverride() + "\n\n" +
"for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n";
if (comment != null)
message += "\nThe users comment was '" + comment + "'\n";
@ -635,23 +672,22 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(this.provideAdminEmail, subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to the administrator", e);
throw e;
logger.error("Error while sending registration notification email to the administrator", e);
}
}
@Override
public void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
public void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request started for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"We received a request to update the following interface: \n\n" +
"Base URL: " + repositoryInterface.getBaseurl() + "\n" +
"Set: " + repositoryInterface.getAccessSet() + "\n" +
"Guidelines: " + repositoryInterface.getCompatibilityOverride() + "\n\n" +
"for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n";
"Base URL: " + repositoryInterface.getBaseurl() + "\n" +
"Set: " + repositoryInterface.getAccessSet() + "\n" +
"Guidelines: " + repositoryInterface.getCompatibilityOverride() + "\n\n" +
"for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n";
if (comment != null) {
message += "\n Your comment was '" + comment + "'\n";
@ -666,28 +702,26 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(repository.getRegisteredby(), subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
throw e;
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
}
}
@Override
public void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation) throws Exception {
public void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation) {
try {
String subject = "OpenAIRE validator - Test submission ";
String message =
"The validation request you have submitted has started.\n" +
"Please do not reply to this message.\n" +
"This message has been generated automatically.\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
"Please do not reply to this message.\n" +
"This message has been generated automatically.\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication);
this.sendMail(jobForValidation.getUserEmail(), subject, message);
} catch (Exception e) {
LOGGER.error("Error while sending validation submission notification email to user: " + jobForValidation.getUserEmail(), e);
throw e;
logger.error("Error while sending validation submission notification email to user: " + jobForValidation.getUserEmail(), e);
}
}
@ -702,51 +736,50 @@ public class EmailUtilsImpl implements EmailUtils {
String issuerEmail,
String jobId) throws Exception {
List<RepositoryInterface> repositoryInterfaces = repositoryService.getRepositoryInterface(repoId);
if(repositoryInterfaces.size()==0)
throw new ValidationServiceException("Repository interface with id \""+repoInterfaceId+"\" not found",ValidationServiceException.ErrorCode.GENERAL_ERROR);
if (repositoryInterfaces.isEmpty())
throw new ValidationServiceException("Repository interface with id \"" + repoInterfaceId + "\" not found", ValidationServiceException.ErrorCode.GENERAL_ERROR);
RepositoryInterface repositoryInterface = repositoryInterfaces.stream().filter( repoInterface -> repoInterface.getId().equals(repoInterfaceId)).collect(Collectors.toList()).get(0);
RepositoryInterface repositoryInterface = repositoryInterfaces.stream().filter(repoInterface -> repoInterface.getId().equals(repoInterfaceId)).collect(Collectors.toList()).get(0);
Repository repository = repositoryService.getRepositoryById(repoId);
if(!isUpdate){
if(isSuccess){
if(scoreContent>=50 && scoreUsage >= 50){
this.sendUserRegistrationResultsSuccessEmail(issuerEmail,jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
this.sendAdminRegistrationResultsSuccessEmail(issuerEmail,jobId,repositoryInterface,repository,SecurityContextHolder.getContext().getAuthentication());
}else{
this.sendUserRegistrationResultsFailureEmail(jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
this.sendAdminRegistrationResultsFailureEmail(issuerEmail,jobId,repositoryInterface,repository,SecurityContextHolder.getContext().getAuthentication());
if (!isUpdate) {
if (isSuccess) {
if (scoreContent >= 50 && scoreUsage >= 50) {
this.sendUserRegistrationResultsSuccessEmail(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication());
this.sendAdminRegistrationResultsSuccessEmail(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication());
} else {
this.sendUserRegistrationResultsFailureEmail(jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication());
this.sendAdminRegistrationResultsFailureEmail(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication());
}
}else{
this.sendAdminGeneralFailure(issuerEmail,jobId,repositoryInterface,repository,SecurityContextHolder.getContext().getAuthentication());
} else {
this.sendAdminGeneralFailure(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication());
}
}else{
if(isSuccess){
if(scoreContent>=50 && scoreUsage >= 50){
this.sendUserUpdateResultsSuccessEmail(issuerEmail,jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
this.sendAdminUpdateResultsSuccessEmail(issuerEmail,jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
}else{
this.sendUserUpdateResultsFailureEmail(issuerEmail,jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
this.sendAdminUpdateResultsFailureEmail(issuerEmail,jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
} else {
if (isSuccess) {
if (scoreContent >= 50 && scoreUsage >= 50) {
this.sendUserUpdateResultsSuccessEmail(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication());
this.sendAdminUpdateResultsSuccessEmail(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication());
} else {
this.sendUserUpdateResultsFailureEmail(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication());
this.sendAdminUpdateResultsFailureEmail(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication());
}
}else{
this.sendAdminGeneralFailure(issuerEmail,jobId,repositoryInterface,repository,SecurityContextHolder.getContext().getAuthentication());
} else {
this.sendAdminGeneralFailure(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication());
}
}
}
private void sendMail(String email, String subject, String message) throws Exception {
private void sendMail(String email, String subject, String message) {
this.sendMail(Collections.singletonList(email), subject, message);
}
public void sendMail(List<String> recipients, String subject, String message) throws Exception {
public void sendMail(List<String> recipients, String subject, String message) {
try {
LOGGER.debug("Sending e-mail\nRecipients: " + recipients + "\nSubject: " + subject + "\nMessage: " + message);
logger.debug("Sending e-mail\nRecipients: {}\nSubject: {}\nMessage: {}", recipients, subject, message);
mailLibrary.sendEmail(recipients.toArray(new String[]{}), subject, message);
} catch (Exception e) {
LOGGER.error("Error sending e-mail\nRecipients: " + recipients + "\nSubject: " + subject + "\nMessage: " + message, e);
throw e;
logger.error("Error sending e-mail\nRecipients: " + recipients + "\nSubject: " + subject + "\nMessage: " + message, e);
}
}
@ -762,13 +795,20 @@ public class EmailUtilsImpl implements EmailUtils {
return body;
}
private String createRepoAdminsMail(String body) {
body = "Dear repository admins,\n\n" + body;
body += "\n\nBest Regards,\nthe OpenAIRE technical team\n";
return body;
}
private String getUserName(Authentication authentication) {
String user = "user";
if (authentication != null) {
try {
user = ((OIDCAuthenticationToken) authentication).getUserInfo().getName();
} catch (NullPointerException ex) {}
} catch (NullPointerException ex) {
}
}
return user;
return user; // It may be just "user". TODO - Wouldn't be better if it was null?
}
}

View File

@ -0,0 +1,87 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.repo.manager.domain.*;
import eu.dnetlib.repo.manager.domain.dto.User;
import eu.dnetlib.repo.manager.exception.ResourceConflictException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.repository.InterfaceComplianceRequestsRepository;
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class InterfaceComplianceService {
private static final Logger logger = LoggerFactory.getLogger(InterfaceComplianceService.class);
private final InterfaceComplianceRequestsRepository repository;
private final EmailUtils emailUtils;
private final AuthorizationService authorizationService;
private final RepositoryService repositoryService;
public InterfaceComplianceService(InterfaceComplianceRequestsRepository repository,
EmailUtils emailUtils,
AuthorizationService authorizationService,
RepositoryService repositoryService) {
this.repository = repository;
this.emailUtils = emailUtils;
this.authorizationService = authorizationService;
this.repositoryService = repositoryService;
}
@Scheduled(cron = "0 0 0 * * *") // every day at 00:00
public void cleanUp() {
Set<InterfaceComplianceRequest> requests = getOutdated();
for (InterfaceComplianceRequest request : requests) {
try {
Map<String, RepositoryInterface> repositoryInterfaceMap = repositoryService.getRepositoryInterface(request.getRepositoryId())
.stream()
.collect(Collectors.toMap(ApiDetails::getId, i -> i));
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 (JSONException | ResourceNotFoundException e) {
logger.error("Error", e);
}
}
repository.deleteAll(requests);
}
private Set<InterfaceComplianceRequest> getOutdated() {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -7);
return this.repository.findAllBySubmissionDateBefore(calendar.getTime());
}
public Optional<InterfaceComplianceRequest> getById(InterfaceComplianceRequestId id) {
return this.repository.findById(id);
}
public Iterable<InterfaceComplianceRequest> get() {
return this.repository.findAll();
}
public InterfaceComplianceRequest create(InterfaceComplianceRequest request) {
Optional<InterfaceComplianceRequest> existing = getById(request.getId());
if (existing.isPresent()) {
logger.warn("New Request: {}\nExisting request: {}", request, existing.get());
throw new ResourceConflictException("A request for altering compliance already exists. Desired Compatibility value: " + existing.get().getDesiredCompatibilityLevel());
}
return this.repository.save(request);
}
public void delete(InterfaceComplianceRequestId id) {
this.repository.deleteById(id);
}
}

View File

@ -7,10 +7,11 @@ import eu.dnetlib.repo.manager.domain.Constants;
import eu.dnetlib.repo.manager.domain.JobsOfUser;
import eu.dnetlib.repo.manager.utils.CrisValidatorUtils;
import gr.uoa.di.driver.util.ServiceLocator;
import org.apache.log4j.Logger;
import org.eurocris.openaire.cris.validator.model.Job;
import org.eurocris.openaire.cris.validator.service.MapJobDao;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -22,6 +23,8 @@ import java.util.stream.Collectors;
@Service("monitorService")
public class MonitorServiceImpl implements MonitorService {
private static final Logger logger = LoggerFactory.getLogger(MonitorServiceImpl.class);
@Autowired
private MapJobDao crisJobs;
@ -41,9 +44,6 @@ public class MonitorServiceImpl implements MonitorService {
}
private static final Logger LOGGER = Logger
.getLogger(MonitorServiceImpl.class);
@Override
public JobsOfUser getJobsOfUser(String user,
String jobType,
@ -54,9 +54,6 @@ public class MonitorServiceImpl implements MonitorService {
String validationStatus,
String includeJobsTotal) throws JSONException, ValidatorServiceException {
LOGGER.debug("Getting jobs of user : " + user);
LOGGER.debug(user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal);
/////////////////////////////////////////////////////////////////////////////////////////
// FIXME: this is a hack for CRIS Jan Dvorak Validator, should be implemented properly //
/////////////////////////////////////////////////////////////////////////////////////////
@ -154,7 +151,7 @@ public class MonitorServiceImpl implements MonitorService {
public int getJobsOfUserPerValidationStatus(String user,
String jobType,
String validationStatus) throws JSONException {
LOGGER.debug("Getting job with validation status : " + validationStatus);
logger.debug("Getting job with validation status : " + validationStatus);
if (jobType.equalsIgnoreCase("cris")) {
return crisJobs.getJobs(user, validationStatus).size();
@ -163,7 +160,7 @@ public class MonitorServiceImpl implements MonitorService {
try {
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
} catch (ValidatorServiceException e) {
LOGGER.error(e);
logger.error(e.getMessage(), e);
}
return 0;
}
@ -171,12 +168,12 @@ public class MonitorServiceImpl implements MonitorService {
@Override
public StoredJob getJobSummary(String jobId,
String groupBy) throws JSONException {
LOGGER.debug("Getting job summary with id : " + jobId);
logger.debug("Getting job summary with id : " + jobId);
StoredJob job = null;
try {
job = getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy);
} catch (ValidatorServiceException e) {
LOGGER.error(e);
logger.error(e.getMessage(), e);
}
/////////////////////////////////////////////////////////////////////////////////////////
// FIXME: this is a hack for CRIS Jan Dvorak Validator, should be implemented properly //

View File

@ -2,12 +2,13 @@ package eu.dnetlib.repo.manager.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.repo.manager.domain.Repository;
import eu.dnetlib.repo.manager.domain.OrderByField;
import eu.dnetlib.repo.manager.domain.OrderByType;
import eu.dnetlib.repo.manager.domain.Repository;
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
@ -32,6 +33,9 @@ import java.util.Map;
@Service("piwikService")
public class PiWikServiceImpl implements PiWikService {
private static final Logger logger = LoggerFactory.getLogger(PiWikServiceImpl.class);
@Autowired
private DataSource dataSource;
@ -47,20 +51,20 @@ public class PiWikServiceImpl implements PiWikService {
@Qualifier("emailUtils")
private EmailUtils emailUtils;
private static final Logger LOGGER = Logger
.getLogger(PiWikServiceImpl.class);
private final static String GET_PIWIK_SITE = "select repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, validated, validationdate, comment, repositoryname, country from piwik_site where repositoryid = ?;";
private static final String GET_PIWIK_SITE = "select repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, validated, validationdate, comment, repositoryname, country from piwik_site where repositoryid = ? LIMIT 1;";
private final static String INSERT_PIWIK_INFO = "insert into piwik_site (repositoryid, siteid, creationdate, requestorname, requestoremail, validated, repositoryname, country, authenticationtoken) values (?, ?, now(), ?, ?, ?, ?, ?, ?)";
private static final String INSERT_PIWIK_INFO = "insert into piwik_site (repositoryid, siteid, creationdate, requestorname, requestoremail, validated, repositoryname, country, authenticationtoken) values (?, ?, now(), ?, ?, ?, ?, ?, ?)";
private final static String GET_PIWIK_SITES = "select repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, validated, validationdate, comment, repositoryname, country from piwik_site ";
private static final String UPDATE_PIWIK_INFO = "update piwik_site set siteid = ?, creationdate = now(), requestorname = ?, requestoremail = ?, validated = ?, repositoryname = ?, country = ?, authenticationtoken = ? where repositoryid = ?";
private final static String GET_PIWIK_SITES_TOTAL = "select count(*) as totals from piwik_site ";
private static final String GET_PIWIK_SITES = "select repositoryid, siteid, authenticationtoken, creationdate, requestorname, requestoremail, validated, validationdate, comment, repositoryname, country from piwik_site ";
private final static String APPROVE_PIWIK_SITE = "update piwik_site set validated=true, validationdate=now() where repositoryid = ?;";
private static final String GET_PIWIK_SITES_TOTAL = "select count(*) as totals from piwik_site ";
private RowMapper<PiwikInfo> piwikRowMapper = (rs, i) -> new PiwikInfo(rs.getString("repositoryid"), getOpenaireId(rs.getString("repositoryid")), rs.getString("repositoryname"), rs.getString("country"),
private static final String APPROVE_PIWIK_SITE = "update piwik_site set validated=true, validationdate=now() where repositoryid = ?;";
private final RowMapper<PiwikInfo> piwikRowMapper = (rs, i) -> new PiwikInfo(rs.getString("repositoryid"), getOpenaireId(rs.getString("repositoryid")), rs.getString("repositoryname"), rs.getString("country"),
rs.getString("siteid"), rs.getString("authenticationtoken"), rs.getTimestamp("creationdate"), rs.getString("requestorname"), rs.getString("requestoremail"),
rs.getBoolean("validated"), rs.getTimestamp("validationdate"), rs.getString("comment"));
@ -78,9 +82,15 @@ public class PiWikServiceImpl implements PiWikService {
@PreAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or (hasAuthority('REGISTERED_USER') and #piwikInfo.requestorEmail == authentication.userInfo.email)")
public PiwikInfo savePiwikInfo(PiwikInfo piwikInfo) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.update(INSERT_PIWIK_INFO, new Object[]{piwikInfo.getRepositoryId(), piwikInfo.getSiteId(), piwikInfo.getRequestorName(),
piwikInfo.getRequestorEmail(), piwikInfo.isValidated(), piwikInfo.getRepositoryName(), piwikInfo.getCountry(), piwikInfo.getAuthenticationToken()},
new int[]{Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BOOLEAN, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR});
if (getPiwikSiteForRepo(piwikInfo.getRepositoryId()) == null) {
jdbcTemplate.update(INSERT_PIWIK_INFO, new Object[]{piwikInfo.getRepositoryId(), piwikInfo.getSiteId(), piwikInfo.getRequestorName(),
piwikInfo.getRequestorEmail(), piwikInfo.isValidated(), piwikInfo.getRepositoryName(), piwikInfo.getCountry(), piwikInfo.getAuthenticationToken()},
new int[]{Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BOOLEAN, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR});
} else {
jdbcTemplate.update(UPDATE_PIWIK_INFO, new Object[]{piwikInfo.getSiteId(), piwikInfo.getRequestorName(), piwikInfo.getRequestorEmail(),
piwikInfo.isValidated(), piwikInfo.getRepositoryName(), piwikInfo.getCountry(), piwikInfo.getAuthenticationToken(), piwikInfo.getRepositoryId()},
new int[]{Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BOOLEAN, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR});
}
return piwikInfo;
}
@ -168,10 +178,10 @@ public class PiWikServiceImpl implements PiWikService {
emailUtils.sendUserMetricsEnabled(piwikInfo);
} catch (EmptyResultDataAccessException e) {
LOGGER.error("Error while approving piwik site: ", e);
logger.error("Error while approving piwik site: ", e);
throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
} catch (Exception e) {
LOGGER.error("Error while sending email to administrator or user about the enabling of metrics", e);
logger.error("Error while sending email to administrator or user about the enabling of metrics", e);
throw new RepositoryServiceException(e, RepositoryServiceException.ErrorCode.GENERAL_ERROR);
}
return new ResponseEntity<>("OK", HttpStatus.OK);
@ -183,9 +193,9 @@ public class PiWikServiceImpl implements PiWikService {
String repoWebsite,
PiwikInfo piwikInfo) throws RepositoryServiceException {
try {
String URL = analyticsURL + "siteName=" + URLEncoder.encode(officialName, "UTF-8") + "&url="
String url = analyticsURL + "siteName=" + URLEncoder.encode(officialName, "UTF-8") + "&url="
+ URLEncoder.encode(repoWebsite, "UTF-8");
Map map = new ObjectMapper().readValue(new URL(URL), Map.class);
Map map = new ObjectMapper().readValue(new URL(url), Map.class);
String siteId = null;
if (map.get("value") != null) {
siteId = map.get("value").toString();
@ -202,13 +212,13 @@ public class PiWikServiceImpl implements PiWikService {
emailUtils.sendAdministratorRequestToEnableMetrics(piwikInfo);
emailUtils.sendUserRequestToEnableMetrics(piwikInfo);
} catch (UnsupportedEncodingException uee) {
LOGGER.error("Error while creating piwikScript URL", uee);
logger.error("Error while creating piwikScript URL", uee);
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
} catch (IOException ioe) {
LOGGER.error("Error while creating piwik site", ioe);
logger.error("Error while creating piwik site", ioe);
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
} catch (Exception e) {
LOGGER.error("Error while sending email to administrator or user about the request to enable metrics", e);
logger.error("Error while sending email to administrator or user about the request to enable metrics", e);
throw new RepositoryServiceException(e, RepositoryServiceException.ErrorCode.GENERAL_ERROR);
}
return piwikInfo;

View File

@ -1,7 +1,5 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.repo.manager.domain.Repository;
import eu.dnetlib.repo.manager.domain.RepositoryInterface;
import eu.dnetlib.repo.manager.domain.*;
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
@ -44,12 +42,6 @@ public interface RepositoryService {
Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException;
List<AggregationDetails> getRepositoryAggregations(String id) throws JSONException;
List<AggregationDetails> getRepositoryAggregations(String id, int from, int size) throws JSONException;
Map<String, List<AggregationDetails>> getRepositoryAggregationsByYear(String id) throws JSONException;
List<Repository> getRepositoriesByName(String name,
String page,
String size) throws JSONException;
@ -68,7 +60,9 @@ public interface RepositoryService {
RepositoryInterface addRepositoryInterface(String datatype,
String repoId,
String comment, RepositoryInterface repositoryInterface) throws Exception;
String comment,
RepositoryInterface repositoryInterface,
String desiredCompatibilityLevel) throws Exception;
List<String> getDnetCountries();
@ -92,6 +86,7 @@ public interface RepositoryService {
Map<String, String> getListLatestUpdate(String mode) throws JSONException;
RepositoryInterface updateRepositoryInterface(String repoId, String comment, RepositoryInterface repositoryInterface) throws Exception;
RepositoryInterface updateRepositoryInterface(String repoId, String comment, RepositoryInterface repositoryInterface, String desiredCompatibilityLevel) throws Exception;
void updateInterfaceCompliance(String repositoryId, String repositoryInterfaceId, String compliance);
}

View File

@ -5,8 +5,6 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.repo.manager.domain.Repository;
import eu.dnetlib.repo.manager.domain.RepositoryInterface;
import eu.dnetlib.domain.enabling.Vocabulary;
import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.repo.manager.domain.*;
@ -20,13 +18,15 @@ import eu.dnetlib.repo.manager.service.security.AuthoritiesUpdater;
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
import eu.dnetlib.repo.manager.service.security.RoleMappingService;
import eu.dnetlib.repo.manager.utils.Converter;
import eu.dnetlib.repo.manager.utils.DateUtils;
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
@ -46,22 +46,23 @@ import java.io.IOException;
import java.sql.Timestamp;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@Service("repositoryService")
public class RepositoryServiceImpl implements RepositoryService {
private static final Logger LOGGER = Logger.getLogger(RepositoryServiceImpl.class);
private static final Logger logger = LoggerFactory.getLogger(RepositoryServiceImpl.class);
private final AuthorizationService authorizationService;
private final RoleMappingService roleMappingService;
private final AaiRegistryService registryCalls;
private final AuthoritiesUpdater authoritiesUpdater;
private final RestTemplate restTemplate;
private final ObjectMapper objectMapper;
private final VocabularyLoader vocabularyLoader;
private final PiWikService piWikService;
private final EmailUtils emailUtils;
private final ValidatorService validatorService;
private final InterfaceComplianceService interfaceComplianceService;
@Value("${services.provide.clients.dsm}")
private String baseAddress;
@ -94,10 +95,12 @@ public class RepositoryServiceImpl implements RepositoryService {
AuthoritiesUpdater authoritiesUpdater,
VocabularyLoader vocabularyLoader,
RestTemplate restTemplate,
ObjectMapper objectMapper,
Converter converter,
@Lazy EmailUtils emailUtils,
@Lazy ValidatorService validatorService,
@Lazy PiWikService piWikService) {
@Lazy PiWikService piWikService,
@Lazy InterfaceComplianceService interfaceComplianceService) {
this.authorizationService = authorizationService;
this.roleMappingService = roleMappingService;
this.registryCalls = registryCalls;
@ -108,12 +111,13 @@ public class RepositoryServiceImpl implements RepositoryService {
this.emailUtils = emailUtils;
this.validatorService = validatorService;
this.restTemplate = restTemplate;
this.objectMapper = objectMapper;
this.interfaceComplianceService = interfaceComplianceService;
}
@PostConstruct
private void init() {
LOGGER.debug("Initialization method of repository api!");
LOGGER.debug("Updated version!");
logger.debug("Initialization method of repository api! Updated version!");
for (String key : this.getVocabulary("dnet:datasource_typologies").getAsMap().keySet()) {
if (key.contains("aggregator")) {
@ -137,7 +141,7 @@ public class RepositoryServiceImpl implements RepositoryService {
}
httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
httpHeaders.setContentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE));
for (String vocName : vocabularyNames) {
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT));
@ -148,8 +152,6 @@ public class RepositoryServiceImpl implements RepositoryService {
countriesMap.put(c.getName(), c.getCode());
inverseCountriesMap.put(c.getCode(), c.getName());
}
}
@Override
@ -159,7 +161,7 @@ public class RepositoryServiceImpl implements RepositoryService {
.build().encode();
return restTemplate.getForObject(uriComponents.toUri(), Country[].class);
}
// FIXME: with the new roles of the users the "requestFilter.setRegisteredby(userEmail)" can no longer be used
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
// another way for paging must be implemented.
@ -174,17 +176,19 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public List<Repository> getRepositories(List<String> ids, int page, int size) throws JSONException {
List<Repository> repos = new ArrayList<>();
LOGGER.debug("Retrieving repositories with ids : " + String.join(", ", ids));
logger.debug("Retrieving repositories with ids : {}", String.join(", ", ids));
UriComponents uriComponents = searchDatasource(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
RequestFilter requestFilter = new RequestFilter();
for (String repoId : ids) {
requestFilter.setId(repoId);
List<Repository> rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, List.class);
List rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, List.class);
// repos.addAll(converter.toRepositoryList(new JSONObject(rs)));
}
// TODO - "repos" is EMPTY!!
for (Repository r : repos)
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId()));
return repos;
@ -204,27 +208,30 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public List<RepositorySnippet> getRepositoriesSnippets(List<String> ids, int page, int size) throws Exception {
List<RepositorySnippet> resultSet = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
// here page should be 0
UriComponents uriComponents = searchSnipperDatasource(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
UriComponents uriComponents = searchSnippetDatasource(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
RequestFilter requestFilter = new RequestFilter();
try {
for (String repoId : ids) {
requestFilter.setId(repoId);
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray),
mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
DatasourceResponse rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
if (rs == null) {
logger.error("The \"DatasourceResponse\" is null!");
return null;
}
resultSet.addAll(objectMapper.readValue(objectMapper.writeValueAsString(rs.getDatasourceInfo()),
objectMapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
}
} catch (Exception e) {
LOGGER.debug("Exception on getRepositoriesSnippetOfUser", e);
logger.debug("Exception on getRepositoriesSnippetOfUser", e);
throw e;
}
LOGGER.debug("resultSet:" + resultSet);
logger.debug("resultSet: {}", resultSet);
resultSet.parallelStream().forEach(repositorySnippet -> {
repositorySnippet.setPiwikInfo(piWikService.getPiwikSiteForRepo(repositorySnippet.getId()));
});
@ -237,7 +244,7 @@ public class RepositoryServiceImpl implements RepositoryService {
String mode,
Boolean managed) throws JSONException, IOException {
LOGGER.debug("Getting repositories by country!");
logger.debug("Getting repositories by country!");
int page = 0;
int size = 100;
List<RepositorySnippet> resultSet = new ArrayList<>();
@ -250,24 +257,17 @@ public class RepositoryServiceImpl implements RepositoryService {
filterKey = "CRIS system";
LOGGER.debug("Country code equals : " + country);
LOGGER.debug("Filter mode equals : " + filterKey);
logger.debug("Country code equals : {} | Filter mode equals : {}", country, filterKey);
UriComponents uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size));
UriComponents uriComponents = searchSnippetDatasource(String.valueOf(page), String.valueOf(size));
RequestFilter requestFilter = new RequestFilter();
requestFilter.setCountry(country);
requestFilter.setEoscDatasourceType(filterKey);
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
while (jsonArray.length() > 0) {
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray),
Map rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, Map.class);
if (rs != null) {
resultSet.addAll(mapper.readValue(mapper.writeValueAsString(rs.get("datasourceInfo")),
mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
page += 1;
uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size));
rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
}
return resultSet;
}
@ -275,7 +275,7 @@ public class RepositoryServiceImpl implements RepositoryService {
public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception {
LOGGER.debug("Searching registered repositories");
logger.debug("Searching registered repositories");
Paging<RepositorySnippet> snippets = null;
ObjectMapper mapper = new ObjectMapper();
@ -289,28 +289,26 @@ public class RepositoryServiceImpl implements RepositoryService {
requestFilter.setEnglishname(englishName);
try {
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
Map rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, Map.class);
if (rs == null) {
LOGGER.error(String.format("DSM response is null : [url=%s]", uriComponents.toUri()));
logger.error("DSM response is null : [url={}]", uriComponents.toUri());
} else {
JSONObject response = new JSONObject(rs);
JSONArray jsonArray = (JSONArray) response.get("datasourceInfo");
Header header = mapper.readValue(response.get("header").toString(), Header.class);
Header header = mapper.readValue(mapper.writeValueAsString(rs.get("header")), Header.class);
snippets = Paging.of(header,
mapper.readValue(
String.valueOf(jsonArray),
mapper.writeValueAsString(rs.get("datasourceInfo")),
mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
}
} catch (Exception e) {
LOGGER.error("Error searching registered datasources", e);
logger.error("Error searching registered datasources", e);
throw e;
}
return snippets != null ? snippets.getResults() : null; // TODO: return paging when ui is compatible
}
@Override
public int getTotalRegisteredRepositories() {
public int getTotalRegisteredRepositories() throws NullPointerException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/countregistered")
.queryParam("fromDate", "1900-01-01")
@ -327,16 +325,16 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public List<Repository> getRepositoriesOfUser(String page, String size) throws JSONException {
String userEmail = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
LOGGER.debug("Retrieving repositories of authenticated user : " + userEmail);
logger.debug("Retrieving repositories of authenticated user : {}",
((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail());
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles());
return getRepositories(new ArrayList<>(repoIds));
}
@Override
public List<Repository> getRepositoriesOfUser(String userEmail, String page, String size) throws JSONException {
LOGGER.debug("Retrieving repositories of authenticated user : " + userEmail);
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles(userEmail));
logger.debug("Retrieving repositories of authenticated user : {}", userEmail);
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRolesByEmail(userEmail));
return getRepositories(new ArrayList<>(repoIds));
}
@ -351,7 +349,7 @@ public class RepositoryServiceImpl implements RepositoryService {
int to = from + Integer.parseInt(size);
List<String> repoIds = new ArrayList<>();
if (userEmail != null && !"".equals(userEmail)) {
repoIds.addAll(roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles(userEmail)));
repoIds.addAll(roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRolesByEmail(userEmail)));
} else {
repoIds.addAll(roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles()));
}
@ -367,13 +365,18 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException {
LOGGER.debug("Retrieving repositories with id : " + id);
logger.debug("Retrieving repositories with id : {}", id);
RepositorySnippet repo;
UriComponents uriComponents = searchSnipperDatasource("0", "100");
UriComponents uriComponents = searchSnippetDatasource("0", "100");
RequestFilter requestFilter = new RequestFilter();
requestFilter.setId(id);
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
if (rs == null) {
logger.error("The result is null!");
return null;
}
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
if (jsonArray.length() == 0)
@ -386,7 +389,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException {
LOGGER.debug("Retrieving repositories with id : " + id);
logger.debug("Retrieving repositories with id : {}", id);
Repository repo;
UriComponents uriComponents = searchDatasource("0", "100");
RequestFilter requestFilter = new RequestFilter();
@ -396,7 +399,12 @@ public class RepositoryServiceImpl implements RepositoryService {
// JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
DatasourceResponse response;
response = (DatasourceResponse) restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
response = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
if (response == null) {
logger.error("The response is null!");
return null;
}
List<DatasourceDetails> datasources = response.getDatasourceInfo();
if (datasources.size() == 0)
throw new ResourceNotFoundException();
@ -409,55 +417,12 @@ public class RepositoryServiceImpl implements RepositoryService {
}
@Override
public List<AggregationDetails> getRepositoryAggregations(String id) throws JSONException {
LOGGER.debug("Retrieving aggregations for repository with id : " + id);
UriComponents uriComponents = getAggregationHistory(id);
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
JSONArray aggregationInfo = new JSONObject(rs).getJSONArray("aggregationInfo");
List<AggregationDetails> aggregationHistory = new ArrayList<>(converter.toAggregationHistory(aggregationInfo));
return aggregationHistory;
}
@Override
public List<AggregationDetails> getRepositoryAggregations(String id, int from, int size) throws JSONException {
List<AggregationDetails> res = getRepositoryAggregations(id);
return res.subList(from, Math.min(from + size, res.size()));
}
@Override
public Map<String, List<AggregationDetails>> getRepositoryAggregationsByYear(String id) throws JSONException {
LOGGER.debug("Retrieving aggregations (by year) for repository with id : " + id);
List<AggregationDetails> aggregationHistory = getRepositoryAggregations(id);
Map<String, List<AggregationDetails>> aggregationByYear = new HashMap<>();
return aggregationHistory.size() == 0 ? aggregationByYear : createYearMap(aggregationHistory);
}
private Map<String, List<AggregationDetails>> createYearMap(List<AggregationDetails> aggregationHistory) {
aggregationHistory = aggregationHistory.stream()
.sorted(Comparator.comparing(AggregationDetails::getDate).reversed())
.collect(Collectors.toList());
return aggregationHistory.stream()
.collect(Collectors.groupingBy(AggregationDetails::getYear));
}
@Override
public List<Repository> getRepositoriesByName(String name,
String page,
String size) throws JSONException {
LOGGER.debug("Retrieving repositories with official name : " + name);
logger.debug("Retrieving repositories with official name : {}", name);
UriComponents uriComponents = searchDatasource("0", "100");
RequestFilter requestFilter = new RequestFilter();
requestFilter.setOfficialname(name);
@ -480,15 +445,19 @@ public class RepositoryServiceImpl implements RepositoryService {
// String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
ApiDetailsResponse rs = restTemplate.getForObject(uriComponents.toUri(), ApiDetailsResponse.class);
if (rs == null) {
logger.error("The ApiDetailsResponse was null!");
return null;
}
// TODO STOP FILTERING OUT "sword", "rest" AND FIX UI!
List<ApiDetails> res = new ArrayList<>();
for (ApiDetails det: rs.getApi()) {
if (!det.getProtocol().equals("sword") &&
!det.getProtocol().equals("rest") &&
!det.getProtocol().equals("ftp")) {
for (ApiDetails det : rs.getApi()) {
String protocol = det.getProtocol();
if (!protocol.equals("sword") &&
!protocol.equals("rest") &&
!protocol.equals("ftp")) {
res.add(det);
}
}
@ -499,7 +468,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public Repository addRepository(String datatype, Repository repository) throws Exception {
LOGGER.debug("storing " + datatype + " repository with id: " + repository.getId());
logger.debug("storing '{}' repository with id: {}", datatype, repository.getId());
repository.setActivationId(UUID.randomUUID().toString());
repository.setCollectedfrom("infrastruct_::openaire");
@ -538,10 +507,10 @@ public class RepositoryServiceImpl implements RepositoryService {
} catch (HttpClientErrorException e) {
couId = registryCalls.getCouId(newRoleName);
if (couId == null) {
LOGGER.error(String.format("Could not create role '%s'", newRoleName), e);
logger.error(String.format("Could not create role '%s'", newRoleName), e);
}
} catch (Exception e) {
LOGGER.error(String.format("Could not create role '%s'", newRoleName), e);
logger.error(String.format("Could not create role '%s'", newRoleName), e);
throw e;
}
@ -549,19 +518,12 @@ public class RepositoryServiceImpl implements RepositoryService {
Integer coPersonId = registryCalls.getCoPersonIdByIdentifier();
if (couId != null) {
Integer role = registryCalls.getRoleId(coPersonId, couId);
try {
registryCalls.assignMemberRole(coPersonId, couId, role);
// Add role to current user authorities
authoritiesUpdater.addRole(roleMappingService.convertRepoIdToAuthority(repository.getId()));
} catch (Exception e) {
LOGGER.debug("Exception on assign role to user during add repository", e);
throw e;
}
registryCalls.assignMemberRole(coPersonId, couId, role);
// Add role to current user authorities
authoritiesUpdater.addRole(roleMappingService.convertRepoIdToAuthority(repository.getId()));
}
return repository;
}
@ -574,20 +536,19 @@ public class RepositoryServiceImpl implements RepositoryService {
// FIXME: problematic
// String json_repository = converter.toJson(repository);
// LOGGER.debug("JSON to add(update) -> " + json_repository);
// logger.debug("JSON to add(update) -> " + json_repository);
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders); // TODO: check if it works (Repository contains extra fields)
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
ResponseEntity<ResponseEntity> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
try {
emailUtils.sendUserRegistrationEmail(repository, authentication);
emailUtils.sendAdminRegistrationEmail(repository, authentication);
} catch (Exception e) {
LOGGER.error("Error sending email", e);
}
} else
LOGGER.error("Error storing repository: " + responseEntity.getBody().toString());
emailUtils.sendUserRegistrationEmail(repository, authentication);
emailUtils.sendAdminRegistrationEmail(repository, authentication);
} else {
Object responseBody = responseEntity.getBody();
if (responseBody != null)
logger.error("Error updating repository: {}", responseBody);
}
return repository;
}
@ -601,21 +562,19 @@ public class RepositoryServiceImpl implements RepositoryService {
// FIXME: problematic
// String json_repository = converter.toJson(repository);
// LOGGER.debug("JSON to update -> " + json_repository);
// logger.debug("JSON to update -> " + json_repository);
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders);
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity
, ResponseEntity.class);
ResponseEntity<ResponseEntity> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
try {
emailUtils.sendUserUpdateRepositoryInfoEmail(repository, authentication);
emailUtils.sendAdminUpdateRepositoryInfoEmail(repository, authentication);
} catch (Exception e) {
LOGGER.error("Error sending emails: " + e);
}
} else
LOGGER.debug(responseEntity.getBody().toString());
emailUtils.sendUserUpdateRepositoryInfoEmail(repository, authentication);
emailUtils.sendAdminUpdateRepositoryInfoEmail(repository, authentication);
} else {
Object responseBody = responseEntity.getBody();
if (responseBody != null)
logger.error("Error updating repository: {}", responseBody);
}
return repository;
}
@ -634,17 +593,15 @@ public class RepositoryServiceImpl implements RepositoryService {
.encode();
// String json_repository = converter.toJson(repository);
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders);
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
ResponseEntity<ResponseEntity> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
try {
emailUtils.sendUserRegistrationEmail(repository, authentication);
emailUtils.sendAdminRegistrationEmail(repository, authentication);
} catch (Exception e) {
LOGGER.error("Error sending emails: " + e);
}
emailUtils.sendUserRegistrationEmail(repository, authentication);
emailUtils.sendAdminRegistrationEmail(repository, authentication);
} else {
LOGGER.debug(responseEntity.getBody().toString());
Object responseBody = responseEntity.getBody();
if (responseBody != null)
logger.error("Error storing repository: {}", responseBody);
}
}
@ -655,14 +612,16 @@ public class RepositoryServiceImpl implements RepositoryService {
.fromHttpUrl(baseAddress + "/ds/api/")
.path("/{id}")
.build().expand(id).encode();
LOGGER.debug(uriComponents.toUri());
logger.debug("{}", uriComponents.toUri());
restTemplate.delete(uriComponents.toUri());
}
@Override
public RepositoryInterface addRepositoryInterface(String datatype,
String repoId,
String comment, RepositoryInterface repositoryInterface) throws Exception {
String comment,
RepositoryInterface repositoryInterface,
String desiredCompatibilityLevel) throws Exception {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Repository e = this.getRepositoryById(repoId);
repositoryInterface = createRepositoryInterface(e, repositoryInterface, datatype);
@ -677,14 +636,15 @@ public class RepositoryServiceImpl implements RepositoryService {
restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class);
try {
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
} catch (Exception ex) {
LOGGER.error("Error sending emails: " + ex);
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
if (desiredCompatibilityLevel != null && (repositoryInterface.getCompatibility() == null || !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel))) {
InterfaceComplianceRequest request = new InterfaceComplianceRequest(repoId, repositoryInterface.getId(), desiredCompatibilityLevel);
interfaceComplianceService.create(request);
}
submitInterfaceValidation(e, getAuthenticatedUser().getEmail(), repositoryInterface, false);
submitInterfaceValidation(e, getAuthenticatedUser().getEmail(), repositoryInterface, false, repositoryInterface.getCompatibility());
return repositoryInterface;
}
@ -692,41 +652,43 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public RepositoryInterface updateRepositoryInterface(String repoId,
String comment,
RepositoryInterface repositoryInterface) throws Exception {
RepositoryInterface repositoryInterface,
String desiredCompatibilityLevel) throws Exception {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
this.updateBaseUrl(repoId, repositoryInterface.getId(), repositoryInterface.getBaseurl());
this.updateCompliance(repoId, repositoryInterface.getId(), repositoryInterface.getCompatibility());
Repository repository = this.getRepositoryById(repoId);
this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet());
Repository repository = this.getRepositoryById(repoId);
try {
try {
emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
} catch (Exception e) {
LOGGER.error("Error sending emails: " + e);
}
} catch (Exception e) {
LOGGER.warn("Could not send emails", e);
emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
if (desiredCompatibilityLevel != null && (repositoryInterface.getCompatibility() == null || !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel))) {
InterfaceComplianceRequest request = new InterfaceComplianceRequest(repoId, repositoryInterface.getId(), desiredCompatibilityLevel);
interfaceComplianceService.create(request);
}
submitInterfaceValidation(getRepositoryById(repoId), getAuthenticatedUser().getEmail(), repositoryInterface, true);
submitInterfaceValidation(getRepositoryById(repoId), getAuthenticatedUser().getEmail(), repositoryInterface, true, desiredCompatibilityLevel);
return repositoryInterface;
}
@Override
public void updateInterfaceCompliance(String repositoryId, String repositoryInterfaceId, String compliance) {
this.updateCompliance(repositoryId, repositoryInterfaceId, compliance);
}
private User getAuthenticatedUser() {
return User.from(((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo());
}
private void submitInterfaceValidation(Repository repo, String userEmail, RepositoryInterface iFace, boolean updateExisting) throws ValidatorServiceException {
private void submitInterfaceValidation(Repository repo, String userEmail, RepositoryInterface iFace, boolean updateExisting, String desiredCompatibilityLevel) throws ValidatorServiceException {
JobForValidation job = new JobForValidation();
job.setActivationId(UUID.randomUUID().toString());
job.setAdminEmails(Collections.singletonList(this.adminEmail));
job.setBaseUrl(iFace.getBaseurl());
job.setDatasourceId(repo.getId());
job.setDesiredCompatibilityLevel(iFace.getCompatibilityOverride());
job.setDesiredCompatibilityLevel(desiredCompatibilityLevel);
job.setInterfaceId(iFace.getId());
job.setOfficialName(repo.getOfficialname());
job.setRepoType(repo.getEoscDatasourceType());
@ -745,7 +707,12 @@ public class RepositoryServiceImpl implements RepositoryService {
iFace.setDatasource(repo.getId());
iFace.setContentdescription("metadata");
iFace.setCompatibility("UNKNOWN");
// TODO: double check me
logger.warn("Compatibility level: {}", iFace.getCompatibility());
if (iFace.getCompatibility() == null || iFace.getCompatibility().equals("")) {
iFace.setCompatibility("UNKNOWN");
}
if (datatype.equals("re3data"))
iFace.setAccessFormat("oai_datacite");
@ -770,8 +737,7 @@ public class RepositoryServiceImpl implements RepositoryService {
iFace.setMetadataIdentifierPath("//*[local-name()='header']/*[local-name()='identifier']");
iFace.setId("api_________::" + repo.getId() + "::" + UUID.randomUUID().toString().substring(0, 8));
if (iFace.getAccessSet() == null || iFace.getAccessSet().isEmpty()) {
LOGGER.debug("set is empty: " + iFace.getAccessSet());
// iFace.removeAccessSet();
logger.debug("set is empty: {}", iFace.getAccessSet());
iFace.setAccessSet("none");
}
return iFace;
@ -779,7 +745,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public List<String> getDnetCountries() {
LOGGER.debug("Getting dnet-countries!");
logger.debug("Getting dnet-countries!");
return converter.readFile("countries.txt");
}
@ -805,7 +771,8 @@ public class RepositoryServiceImpl implements RepositoryService {
RequestFilter requestFilter = new RequestFilter();
requestFilter.setRegisteredby(userEmail);
return Arrays.asList(restTemplate.postForObject(uriComponents.toUri(), requestFilter, String[].class));
Object result = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String[].class);
return (result != null) ? Collections.singletonList(result.toString()) : null;
}
private Vocabulary getVocabulary(String vocName) {
@ -820,7 +787,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public Map<String, String> getCompatibilityClasses(String mode) {
LOGGER.debug("Getting compatibility classes for mode: " + mode);
logger.debug("Getting compatibility classes for mode: {}", mode);
Map<String, String> retMap = new HashMap<String, String>();
Map<String, String> compatibilityClasses = this.getVocabulary("dnet:compatibilityLevel").getAsMap();
@ -829,18 +796,17 @@ public class RepositoryServiceImpl implements RepositoryService {
if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_ALL))
return compatibilityClasses;
else if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA)) {
if (entry.getKey().matches("^openaire[1-9].0_data$")) {
if (ValidatorServiceImpl.OPENAIRE_DATA_REGEX.matcher(entry.getKey()).matches()) {
retMap.put(entry.getKey(), entry.getValue());
foundData = true;
}
}
else if (mode.equalsIgnoreCase("cris")) {
} else if (mode.equalsIgnoreCase("cris")) {
if (entry.getKey().contains("openaire-cris")) {
retMap.put(entry.getKey(), entry.getValue());
foundData = true;
}
} else {
if (entry.getKey().matches("^openaire[1-9].0$") || entry.getKey().equals("driver"))
if (ValidatorServiceImpl.OPENAIRE_OR_DRIVER_REGEX.matcher(entry.getKey()).matches())
retMap.put(entry.getKey(), entry.getValue());
}
}
@ -855,7 +821,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public Map<String, String> getDatasourceClasses(String mode) {
LOGGER.debug("Getting datasource classes for mode: " + mode);
logger.debug("Getting datasource classes for mode: {}", mode);
Map<String, String> retMap = new HashMap<String, String>();
@ -916,7 +882,7 @@ public class RepositoryServiceImpl implements RepositoryService {
return metricsInfo;
} catch (Exception e) {
LOGGER.error("Error while getting metrics info for repository: ", e);
logger.error("Error while getting metrics info for repository: ", e);
throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
}
}
@ -925,31 +891,30 @@ public class RepositoryServiceImpl implements RepositoryService {
public Map<String, String> getListLatestUpdate(String mode) throws JSONException {
Map<String, String> dates = new HashMap<>();
if (mode.equals("repository")) {
dates.put("opendoar", converter.toString(getRepositoryInterface("openaire____::opendoar").get(0).getLastCollectionDate()));
dates.put("fairsharing", converter.toString(getRepositoryInterface("openaire____::fairsharing").get(0).getLastCollectionDate()));
dates.put("opendoar", DateUtils.toString(getRepositoryInterface("openaire____::opendoar").get(0).getLastCollectionDate()));
dates.put("fairsharing", DateUtils.toString(getRepositoryInterface("openaire____::fairsharing").get(0).getLastCollectionDate()));
// create re3data last collection date
// dates.put("re3data", converter.toString(getRepositoryInterface("openaire____::re3data").get(1).getLastCollectionDate()));
List<RepositoryInterface> re3interfaces = getRepositoryInterface("openaire____::re3data");
String re3Date = null;
for (RepositoryInterface interf : re3interfaces) {
if (interf.getLastCollectionDate() != null) {
re3Date = converter.toString(interf.getLastCollectionDate());
re3Date = DateUtils.toString(interf.getLastCollectionDate());
break;
}
}
dates.put("re3data", re3Date);
return dates;
}
else if (mode.equals("cris"))
return Collections.singletonMap("lastCollectionDate", converter.toString(getRepositoryInterface("eurocrisdris::dris").get(0).getLastCollectionDate()));
} else if (mode.equals("cris"))
return Collections.singletonMap("lastCollectionDate", DateUtils.toString(getRepositoryInterface("eurocrisdris::dris").get(0).getLastCollectionDate()));
else if (mode.equals("opendoar")) // TODO: remove this and else clause
return Collections.singletonMap("lastCollectionDate", converter.toString(getRepositoryInterface("openaire____::" + mode).get(0).getLastCollectionDate()));
return Collections.singletonMap("lastCollectionDate", DateUtils.toString(getRepositoryInterface("openaire____::" + mode).get(0).getLastCollectionDate()));
else
/*
* first api of re3data has null value on collection date
* */
return Collections.singletonMap("lastCollectionDate", converter.toString(getRepositoryInterface("openaire____::" + mode).get(0).getLastCollectionDate()));
return Collections.singletonMap("lastCollectionDate", DateUtils.toString(getRepositoryInterface("openaire____::" + mode).get(0).getLastCollectionDate()));
}
private void updateValidationSet(String repositoryId, String repositoryInterfaceId, String validationSet) throws Exception {
@ -1014,12 +979,6 @@ public class RepositoryServiceImpl implements RepositoryService {
return null;
}
private UriComponents getAggregationHistory(String repoId) {
return UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/aggregationhistory/")
.path(repoId)
.build().expand(repoId).encode();
}
private UriComponents searchDatasource(String page, String size) {
@ -1031,7 +990,7 @@ public class RepositoryServiceImpl implements RepositoryService {
.build().expand(page, size).encode();
}
private UriComponents searchSnipperDatasource(String page, String size) {
private UriComponents searchSnippetDatasource(String page, String size) {
return UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/searchsnippet/")

View File

@ -1,17 +1,27 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.repo.manager.service.customHystrixCommands.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Service("statsService")
public class StatsServiceImpl implements StatsService {
private static final Logger logger = LoggerFactory.getLogger(StatsServiceImpl.class);
@Autowired
RestTemplate restTemplate;
@ -24,27 +34,215 @@ public class StatsServiceImpl implements StatsService {
@Override
public Map getStatistics() {
UsageStatsTotalHystrixCommand usageStatsTotalHystrixCommand = new UsageStatsTotalHystrixCommand(usagestatsEvents,restTemplate);
DataRepositoriesHystrixCommand dataRepositoriesHystrixCommand = new DataRepositoriesHystrixCommand(baseAddress,restTemplate);
AggregatorsHystrixCommand aggregatorsHystrixCommand = new AggregatorsHystrixCommand(baseAddress,restTemplate);
LiteratureHystrixCommand literatureHystrixCommand = new LiteratureHystrixCommand(baseAddress,restTemplate);
JournalHystrixCommand journalHystrixCommand = new JournalHystrixCommand(baseAddress,restTemplate);
PublicationHystrixCommand publicationHystrixCommand = new PublicationHystrixCommand(baseAddress,restTemplate);
DatasetsHystrixCommand datasetsHystrixCommand = new DatasetsHystrixCommand(baseAddress,restTemplate);
SoftwareHystrixCommand softwareHystrixCommand = new SoftwareHystrixCommand(baseAddress,restTemplate);
LastYearUsageStatsHystrixCommand lastYearUsageStatsHystrixCommand = new LastYearUsageStatsHystrixCommand(usagestatsBaseAddress,restTemplate);
Map<String,Object> stats = new HashMap<>();
stats.put("aggregators",aggregatorsHystrixCommand.execute());
stats.put("dataRepositories",dataRepositoriesHystrixCommand.execute());
stats.put("literature",literatureHystrixCommand.execute());
stats.put("journal",journalHystrixCommand.execute());
stats.put("publications",publicationHystrixCommand.execute());
stats.put("datasets",datasetsHystrixCommand.execute());
stats.put("software",softwareHystrixCommand.execute());
stats.put("lastYearUsagestats", lastYearUsageStatsHystrixCommand.execute());
stats.put("usagestats",usageStatsTotalHystrixCommand.execute());
stats.put("aggregators", this.getAggregatorsStats());
stats.put("dataRepositories", this.getDataRepositoriesMetadata());
stats.put("literature", this.getLiteratureStats());
stats.put("journal", this.getJournalsStats());
stats.put("publications", this.getPublicationStats());
stats.put("datasets", this.getDatasetsStats());
stats.put("software", this.getSoftwareStats());
stats.put("lastYearUsagestats", this.getLastYearUsageStats());
stats.put("usagestats", this.getUsageStatsTotal());
return stats;
}
private String getAggregatorsStats()
{
String url = baseAddress + "/resources" +
"?query= " +
" oaftype exact datasource and " +
" ( datasourcetypename exact Institutional Repository Aggregator " +
" or datasourcetypename exact Publication Repository Aggregator )";
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(url)
.queryParam("page", 0)
.queryParam("size", 0)
.queryParam("format", "json")
.build().encode();
try {
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
return String.valueOf(metadata.get("total"));
} catch ( RestClientException rce ) {
logger.error(rce.getMessage());
return null;
} catch ( Exception e ) {
logger.error("", e);
return null;
}
}
private String getDataRepositoriesMetadata()
{
String url = baseAddress + "/resources" +
"?query= " +
" oaftype exact datasource and " +
" datasourcetypename exact Data Repository ";
return getMetadataTotals(url);
}
private String getLiteratureStats()
{
String url = baseAddress + "/resources" +
"?query= " +
" oaftype exact datasource and " +
" ( datasourcetypename exact Institutional Repository " +
" or datasourcetypename exact Publication Repository )";
return getMetadataTotals(url);
}
private String getJournalsStats()
{
String url = baseAddress + "/resources" +
"?query= " +
" oaftype exact datasource and " +
" datasourcetypename exact Journal";
return getMetadataTotals(url);
}
private String getPublicationStats()
{
String url = baseAddress + "/publications/count";
return getCommonStats(url);
}
private String getDatasetsStats()
{
String url = baseAddress + "/datasets/count";
return getCommonStats(url);
}
private String getSoftwareStats()
{
String url = baseAddress + "/software/count";
return getCommonStats(url);
}
private Map<String,Object> getLastYearUsageStats()
{
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(usagestatsBaseAddress + "/totals")
.build().encode();
try {
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
List yearly_stats = (List) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("yearly_stats");
Map lastYear = (Map) yearly_stats.get(yearly_stats.size() - 2);
Integer downloads = (Integer) lastYear.get("downloads");
Integer views = (Integer) lastYear.get("views");
Integer year = (Integer) lastYear.get("year");
Map<String, Object> usagestats = new HashMap<>();
usagestats.put("number", String.valueOf(downloads + views));
usagestats.put("year", year);
return usagestats;
} catch ( RestClientException rce ) {
logger.error(rce.getMessage());
return null;
} catch ( Exception e ) {
logger.error("", e);
return null;
}
}
private Integer getUsageStatsTotal()
{
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(usagestatsEvents)
.build().encode();
try {
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
Map statsTotals = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("totals");
if ( statsTotals == null ) {
logger.error("The statsTotals was null!");
return null;
}
// TODO - Will we ever need the following lines?
// String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
// JSONObject resultSet = new JSONObject(rs);
// JSONObject totals = resultSet.getJSONObject("totals");
return (Integer) statsTotals.get("events");
} catch ( RestClientException rce ) {
logger.error(rce.getMessage());
return null;
} catch ( Exception e ) {
logger.error("", e);
return null;
}
}
private String getMetadataTotals(String url) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(url)
.queryParam("page", 0)
.queryParam("size", 0)
.queryParam("format", "json")
.build().encode();
try {
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
Map metadata = (Map) ((Map<?, ?>) Objects.requireNonNull(rs.getBody())).get("meta");
if ( metadata == null ) {
logger.error("The metadata was null!");
return null;
}
return String.valueOf(metadata.get("total"));
} catch ( RestClientException rce ) {
logger.error(rce.getMessage());
return null;
} catch ( Exception e ) {
logger.error("", e);
return null;
}
}
private String getCommonStats(String url) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(url)
.queryParam("page", 0)
.queryParam("size", 0)
.queryParam("format", "json")
.build().encode();
try {
ResponseEntity<Map> rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
Map stats = (Map<?, ?>) rs.getBody();
if ( stats == null ) {
logger.error("The stats was null!");
return null;
}
return String.valueOf(stats.get("total"));
} catch ( RestClientException rce ) {
logger.error(rce.getMessage());
return null;
} catch ( Exception e ) {
logger.error("", e);
return null;
}
}
}

View File

@ -1,14 +1,19 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.usagestats.sushilite.domain.Customer;
import eu.dnetlib.usagestats.sushilite.domain.ReportItem;
import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper;
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.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
@ -22,7 +27,7 @@ public class SushiliteServiceImpl implements SushiliteService {
@Value("${services.provide.usagestats.sushiliteEndpoint}")
private String usagestatsSushiliteEndpoint;
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(SushiliteServiceImpl.class);
private static final Logger logger = LoggerFactory.getLogger(SushiliteServiceImpl.class);
@Override
@ -40,65 +45,79 @@ public class SushiliteServiceImpl implements SushiliteService {
String Granularity,
String Pretty) {
//build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usagestatsSushiliteEndpoint + "GetReport/")
.queryParam("Report", Report)
.queryParam("Release", Release)
.queryParam("RequestorID", RequestorID)
.queryParam("BeginDate", BeginDate)
.queryParam("EndDate", EndDate)
.queryParam("RepositoryIdentifier", RepositoryIdentifier)
.queryParam("ItemIdentifier", ItemIdentifier)
.queryParam("ItemDataType", ItemDataType)
.queryParam("Granularity", Granularity)
.queryParam("Pretty", Pretty);
//build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usagestatsSushiliteEndpoint + "GetReport/")
.queryParam("Report", Report)
.queryParam("Release", Release)
.queryParam("RequestorID", RequestorID)
.queryParam("BeginDate", BeginDate)
.queryParam("EndDate", EndDate)
.queryParam("RepositoryIdentifier", RepositoryIdentifier)
.queryParam("ItemIdentifier", ItemIdentifier)
.queryParam("ItemDataType", ItemDataType)
.queryParam("Granularity", Granularity)
.queryParam("Pretty", Pretty);
//create new template engine
RestTemplate template = new RestTemplate();
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
//create new restTemplate engine
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
ResponseEntity<ReportResponseWrapper> resp;
ResponseEntity<ReportResponseWrapper> resp;
try {
//communicate with endpoint
resp = template.exchange(
resp = restTemplate.exchange(
builder.build().encode().toUri(),
HttpMethod.GET,
null,
new ParameterizedTypeReference<ReportResponseWrapper>() {
});
new ParameterizedTypeReference<ReportResponseWrapper>() {});
} catch (RestClientException rce) {
logger.error("", rce);
return null;
}
// check remote api's response
System.out.println("sushi responded status " + resp.getStatusCode());
// check remote api's response
HttpStatus httpStatus = resp.getStatusCode();
if ( httpStatus != HttpStatus.OK ) {
logger.warn("Sushi cannot give us data! Responded status: " + httpStatus);
return null;
}
// get the items corresponding to the requested page
List<ReportItem> requestedItemList = new ArrayList<>();
if (resp.getBody().getReportResponse().getReportWrapper().getReport().getCustomer().getReportItems() != null) {
try {
int totalItems = resp.getBody().getReportResponse().getReportWrapper().getReport().getCustomer().getReportItems().size();
int size = Integer.parseInt(pageSize);
int offset = Integer.parseInt(page)*size;
ReportResponseWrapper reportResponseWrapper = resp.getBody();
if ( reportResponseWrapper == null ) {
logger.error("The \"reportResponseWrapper\" for sushi was null!");
return null;
}
if (offset < totalItems ) {
int upperIndex = offset+size;
if (upperIndex > totalItems) {
upperIndex = totalItems;
}
requestedItemList = resp.getBody().getReportResponse().getReportWrapper().getReport().getCustomer().getReportItems().subList(offset,upperIndex);
// get the items corresponding to the requested page
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();
int size = Integer.parseInt(pageSize);
int offset = (Integer.parseInt(page) * size);
if (offset < totalItems ) {
int upperIndex = (offset + size);
if (upperIndex > totalItems) {
upperIndex = totalItems;
}
} catch (NumberFormatException e) {
LOGGER.debug("Exception on getReportResults - trying to cast strings to integers", e);
//emailUtils.reportException(e);
throw e;
requestedItemList = allReportItems.subList(offset, upperIndex);
}
} catch (NumberFormatException e) {
logger.debug("Exception on getReportResults - trying to cast strings to integers", e);
//emailUtils.reportException(e);
throw e;
}
}
ReportResponseWrapper newReportResponse = resp.getBody();
newReportResponse.getReportResponse().getReportWrapper().getReport().getCustomer().setReportItems(requestedItemList);
customer.setReportItems(requestedItemList); // Setting the reportItems to the "customer"-reference, updates the "reportResponseWrapper" object.
return newReportResponse;
return reportResponseWrapper;
}
}

View File

@ -1,7 +1,9 @@
package eu.dnetlib.repo.manager.service;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.springframework.beans.factory.annotation.Value;
import org.mitre.openid.connect.model.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.GrantedAuthority;
@ -16,21 +18,24 @@ import java.util.stream.Collectors;
@Service("userService")
public class UserServiceImpl implements UserService {
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
.getLogger(UserServiceImpl.class);
private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
@Override
public ResponseEntity<Object> login() {
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
LOGGER.debug("User authentication : " + authentication);
logger.debug("User authentication : " + authentication);
Map<String,Object> body = new HashMap<>();
body.put("sub",authentication.getSub());
if(authentication.getUserInfo().getName() == null || authentication.getUserInfo().getName().equals(""))
body.put("name",authentication.getUserInfo().getGivenName() + " " + authentication.getUserInfo().getFamilyName());
else
body.put("name",authentication.getUserInfo().getName());
body.put("email",authentication.getUserInfo().getEmail());
UserInfo userInfo = authentication.getUserInfo();
String userName = userInfo.getName();
if ( userName == null || userName.isEmpty() )
body.put("name", userInfo.getGivenName() + " " + userInfo.getFamilyName());
else
body.put("name", userName);
body.put("email",userInfo.getEmail());
List<String> roles = authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
body.put("role",roles);

View File

@ -5,8 +5,8 @@ import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.domain.functionality.validator.RuleSet;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.domain.InterfaceInformation;
import eu.dnetlib.repo.manager.exception.ValidationServiceException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.exception.ValidationServiceException;
import org.json.JSONException;
import org.springframework.http.ResponseEntity;
@ -42,4 +42,6 @@ public interface ValidatorService {
InterfaceInformation getInterfaceInformation(String baseUrl) throws ValidationServiceException;
List<StoredJob> getJobsSummary(String repoId, int limit) throws ValidatorServiceException, ResourceNotFoundException, JSONException;
void onComplete(String repoId, String interfaceId, String jobId, String issuerEmail, boolean isUpdate, boolean isSuccess, int scoreUsage, int scoreContent) throws Exception;
}

View File

@ -1,19 +1,21 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.repo.manager.domain.RepositoryInterface;
import eu.dnetlib.domain.functionality.validator.*;
import eu.dnetlib.repo.manager.domain.Constants;
import eu.dnetlib.repo.manager.domain.InterfaceInformation;
import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.domain.functionality.validator.Rule;
import eu.dnetlib.domain.functionality.validator.RuleSet;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.domain.*;
import eu.dnetlib.repo.manager.exception.ValidationServiceException;
import eu.dnetlib.repo.manager.utils.CrisValidatorUtils;
import eu.dnetlib.repo.manager.utils.OaiTools;
import gr.uoa.di.driver.util.ServiceLocator;
import org.apache.log4j.Logger;
import org.eurocris.openaire.cris.validator.model.Job;
import org.eurocris.openaire.cris.validator.service.JobExecutor;
import org.eurocris.openaire.cris.validator.service.MapJobDao;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -25,6 +27,7 @@ import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ -52,10 +55,9 @@ public class ValidatorServiceImpl implements ValidatorService {
this.validatorServiceLocator = validatorServiceLocator;
}
private Map<String, List<RuleSet>> rulesetMap = new ConcurrentHashMap<String, List<RuleSet>>();
private final Map<String, List<RuleSet>> rulesetMap = new ConcurrentHashMap<String, List<RuleSet>>();
private static final Logger LOGGER = Logger
.getLogger(ValidatorServiceImpl.class);
private static final Logger logger = LoggerFactory.getLogger(ValidatorServiceImpl.class);
@Autowired
private EmailUtils emailUtils;
@ -66,20 +68,30 @@ public class ValidatorServiceImpl implements ValidatorService {
@Autowired
private MapJobDao crisJobs;
@Autowired
InterfaceComplianceService interfaceComplianceService;
public static final Pattern OPENAIRE_DATA_REGEX = Pattern.compile("^openaire[1-9].0_data$");
public static final Pattern OPENAIRE_OR_DRIVER_REGEX = Pattern.compile("^(?:openaire[1-9].0|driver)$");
public static final Pattern OPENAIRE_CRIS_REGEX = Pattern.compile("^openaire[1-9].0_cris$");
public static final Pattern FAIR_REGEX = Pattern.compile(".*fair$");
@PostConstruct
private void loadRules(){
LOGGER.debug("PostConstruct method! Load rules!");
logger.debug("PostConstruct method! Load rules!");
try {
for (RuleSet ruleSet : getValidationService().getRuleSets()) {
if (ruleSet.getVisibility() != null && ruleSet.getVisibility().contains("development")) {
String key = "";
if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0_data$"))
String guidelinesAcronym = ruleSet.getGuidelinesAcronym();
if ( OPENAIRE_DATA_REGEX.matcher(guidelinesAcronym).matches() )
key = Constants.VALIDATION_MODE_DATA;
else if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0$") || ruleSet.getGuidelinesAcronym().equals("driver"))
else if ( OPENAIRE_OR_DRIVER_REGEX.matcher(guidelinesAcronym).matches() )
key = Constants.VALIDATION_MODE_LITERATURE;
else if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0_cris$"))
else if ( OPENAIRE_CRIS_REGEX.matcher(guidelinesAcronym).matches() )
key = Constants.VALIDATION_MODE_CRIS;
else if (ruleSet.getGuidelinesAcronym().matches(".*fair$"))
else if ( FAIR_REGEX.matcher(guidelinesAcronym).matches() )
key = Constants.VALIDATION_MODE_FAIR;
if (rulesetMap.containsKey(key))
@ -121,7 +133,7 @@ public class ValidatorServiceImpl implements ValidatorService {
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
} catch (ValidatorServiceException e) {
LOGGER.error(e);
logger.error(e.getMessage(), e);
}
}
@ -129,19 +141,15 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
@PreAuthorize("hasAuthority('REGISTERED_USER')")
public JobForValidation submitJobForValidation(JobForValidation jobForValidation) throws ValidatorServiceException {
LOGGER.debug("Submit job for validation with id : " + jobForValidation.getDatasourceId());
logger.debug("Submit job for validation with id : {}", jobForValidation.getDatasourceId());
try {
try {
emailUtils.sendSubmitJobForValidationEmail(SecurityContextHolder.getContext().getAuthentication(), jobForValidation);
} catch (Exception e) {
LOGGER.error("Error sending email ", e);
}
emailUtils.sendSubmitJobForValidationEmail(SecurityContextHolder.getContext().getAuthentication(), jobForValidation);
/////////////////////////////////////////////////////////////////////////////////////////
// FIXME: this is a hack for CRIS Jan Dvorak Validator, should be implemented properly //
/////////////////////////////////////////////////////////////////////////////////////////
if (jobForValidation.getSelectedContentRules()!=null && jobForValidation.getSelectedContentRules().size() == 1 &&
jobForValidation.getSelectedContentRules().contains(-1000)
|| jobForValidation.getDesiredCompatibilityLevel().matches("openaire-cris_1.1")) {
|| jobForValidation.getDesiredCompatibilityLevel().equals("openaire-cris_1.1")) {
crisValidatorExecutor.submit(jobForValidation.getBaseUrl(), jobForValidation.getUserEmail());
} else {
this.getValidationService().submitValidationJob(jobForValidation);
@ -151,7 +159,7 @@ public class ValidatorServiceImpl implements ValidatorService {
// this.getValidationService().submitValidationJob(jobForValidation);
} catch (Exception e) { // FIXME: replaced exception with log
// throw new ValidatorServiceException(e);
LOGGER.error(e);
logger.error(e.getMessage(), e);
}
return jobForValidation;
@ -160,7 +168,7 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
public ResponseEntity<Object> reSubmitJobForValidation(String email,
String jobId) throws JSONException, ValidatorServiceException {
LOGGER.debug("Resubmit validation job with id : " + jobId);
logger.debug("Resubmit validation job with id : {}", jobId);
StoredJob job = monitorApi.getJobSummary(jobId, "all");
Set<Integer> contentRules = new HashSet<Integer>();
Set<Integer> usageRules = new HashSet<Integer>();
@ -195,20 +203,20 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
public List<RuleSet> getRuleSets(String mode) {
LOGGER.info("Getting rulesets for mode: " + mode);
logger.info("Getting ruleSets for mode: {}", mode);
return rulesetMap.get(mode);
}
@Override
public List<String> getSetsOfRepository(String url) {
LOGGER.debug("Getting sets of repository with url : " + url);
logger.debug("Getting sets of repository with url : {}", url);
List<String> sets = null;
try {
sets = OaiTools.getSetsOfRepo(url);
} catch (Exception e) {
LOGGER.error("Exception on getSetsOfRepository" , e);
logger.error("Exception on getSetsOfRepository", e);
}
return sets;
@ -216,18 +224,18 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
public boolean identifyRepo(String url) {
LOGGER.debug("Identify repository with url : " + url);
logger.debug("Identify repository with url : {}", url);
try {
return OaiTools.identifyRepository(url);
} catch (Exception e) {
LOGGER.error("Error while identifying repository with url: " + url, e);
logger.error("Error while identifying repository with url: " + url, e);
return false;
}
}
@Override
public RuleSet getRuleSet(String acronym) {
LOGGER.debug("Getting ruleset with acronym : " + acronym);
logger.debug("Getting ruleset with acronym : {}", acronym);
RuleSet ruleSet = null;
try {
for (List<RuleSet> ruleSets : this.rulesetMap.values()) {
@ -239,7 +247,7 @@ public class ValidatorServiceImpl implements ValidatorService {
}
return ruleSet;
} catch (Exception e) {
LOGGER.error("Error getting ruleset", e);
logger.error("Error getting ruleset", e);
return null;
}
}
@ -278,7 +286,7 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
public InterfaceInformation getInterfaceInformation(String baseUrl) throws ValidationServiceException {
try {
LOGGER.debug("Getting interface information with url: " + baseUrl);
logger.debug("Getting interface information with url: {}", baseUrl);
InterfaceInformation interfaceInformation = new InterfaceInformation();
interfaceInformation.setIdentified(this.identifyRepo(baseUrl));
if (interfaceInformation.isIdentified())
@ -286,7 +294,7 @@ public class ValidatorServiceImpl implements ValidatorService {
return interfaceInformation;
} catch (Exception e) {
LOGGER.error("Error getting interface information with url: " + baseUrl, e);
logger.error("Error getting interface information with url: " + baseUrl, e);
throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR);
}
}
@ -300,4 +308,19 @@ public class ValidatorServiceImpl implements ValidatorService {
.collect(Collectors.toList()), limit);
}
@Override
public void onComplete(String repoId, String interfaceId, String jobId, String issuerEmail, boolean isUpdate, boolean isSuccess, int scoreUsage, int scoreContent) throws Exception {
emailUtils.sendUponJobCompletion(repoId,interfaceId,scoreUsage,scoreContent,isSuccess,isUpdate,issuerEmail, jobId);
InterfaceComplianceRequestId requestId = InterfaceComplianceRequestId.of(repoId, interfaceId);
Optional<InterfaceComplianceRequest> request = interfaceComplianceService.getById(requestId);
if (request.isPresent()) {
logger.info("Changing compatibility level. Request: {}", request);
if (scoreContent > 50) {
repositoryService.updateInterfaceCompliance(repoId, interfaceId, request.get().getDesiredCompatibilityLevel());
}
interfaceComplianceService.delete(requestId);
}
}
}

View File

@ -3,17 +3,21 @@ package eu.dnetlib.repo.manager.service.aai.registry;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.nimbusds.jose.util.StandardCharset;
import eu.dnetlib.repo.manager.domain.dto.Role;
import eu.dnetlib.repo.manager.domain.dto.User;
import eu.dnetlib.repo.manager.service.aai.registry.utils.RegistryUtils;
import eu.dnetlib.repo.manager.utils.HttpUtils;
import org.apache.log4j.Logger;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 javax.validation.constraints.NotNull;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
@ -23,7 +27,7 @@ import java.util.Map;
@Service
public class RegistryCalls implements AaiRegistryService {
private static final Logger logger = Logger.getLogger(RegistryCalls.class);
private static final Logger logger = LoggerFactory.getLogger(RegistryCalls.class);
private final String coid;
public final HttpUtils httpUtils;
@ -98,11 +102,7 @@ public class RegistryCalls implements AaiRegistryService {
try {
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
String sub = authentication.getUserInfo().getSub();
Map<String, String> params = new HashMap<>();
params.put("coid", coid);
params.put("search.identifier", sub);
JsonElement response = httpUtils.get("co_people.json", params);
return (response != null) ? response.getAsJsonObject().get("CoPeople").getAsJsonArray().get(0).getAsJsonObject().get("Id").getAsInt() : null;
return getCoPersonIdByIdentifier(sub);
} catch (Exception e) {
logger.error("Get User info: An error occurred ", e);
return null;
@ -122,7 +122,12 @@ public class RegistryCalls implements AaiRegistryService {
Map<String, String> params = new HashMap<>();
params.put("coid", coid);
if (name != null) {
params.put("name", URLEncoder.encode(name).toLowerCase());
try {
params.put("name", URLEncoder.encode(name, StandardCharset.UTF_8.name()).toLowerCase());
} catch (UnsupportedEncodingException uee) {
logger.error(uee.getMessage());
return new JsonArray();
}
}
JsonElement response = httpUtils.get("cous.json", params);
return (response != null) ? response.getAsJsonObject().get("Cous").getAsJsonArray() : new JsonArray();
@ -165,15 +170,18 @@ public class RegistryCalls implements AaiRegistryService {
@Override
public JsonArray getRolesWithStatus(Integer coPersonId, RoleStatus status) {
JsonArray roles = getRoles(coPersonId);
if (status == null) {
return roles;
if (roles == null) {
roles = new JsonArray();
}
JsonArray activeRoles = new JsonArray();
for (JsonElement role : roles) {
if (role.getAsJsonObject().get("Status").getAsString().equalsIgnoreCase(status.toString())) {
activeRoles.add(role);
if (status != null) {
for (JsonElement role : roles) {
if (role.getAsJsonObject().get("Status").getAsString().equalsIgnoreCase(status.toString())) {
activeRoles.add(role);
}
}
}
assert activeRoles != null;
return activeRoles;
}
@ -296,8 +304,11 @@ public class RegistryCalls implements AaiRegistryService {
JsonArray infos = getUserEmailByCouId(couId, false);
infos.forEach(info -> {
JsonObject jsonInfo = info.getAsJsonObject();
User user = new User();
user.setEmail(info.getAsJsonObject().get("email").getAsString());
user.setEmail(jsonInfo.get("email").getAsString());
// TODO: should add firstname and lastname and sub of user
users.add(user);
});
@ -315,9 +326,10 @@ public class RegistryCalls implements AaiRegistryService {
JsonArray infos = (response != null) ? response.getAsJsonObject().get("Names").getAsJsonArray() : new JsonArray();
JsonArray names = new JsonArray();
infos.forEach(info -> {
JsonObject jsonInfo = info.getAsJsonObject();
JsonObject user = new JsonObject();
user.addProperty("name", info.getAsJsonObject().get("Given").getAsString() + " " + info.getAsJsonObject().get("Family").getAsString());
user.addProperty("memberSince", info.getAsJsonObject().get("Created").getAsString());
user.addProperty("name", jsonInfo.get("Given").getAsString() + " " + jsonInfo.get("Family").getAsString());
user.addProperty("memberSince", jsonInfo.get("Created").getAsString());
names.add(user);
});
return names;
@ -334,9 +346,10 @@ public class RegistryCalls implements AaiRegistryService {
JsonArray infos = (response != null) ? response.getAsJsonObject().get("Identifiers").getAsJsonArray() : new JsonArray();
JsonArray emails = new JsonArray();
infos.forEach(info -> {
JsonObject jsonInfo = info.getAsJsonObject();
JsonObject user = new JsonObject();
user.addProperty("id", info.getAsJsonObject().get("Identifier").getAsString());
user.addProperty("memberSince", info.getAsJsonObject().get("Created").getAsString());
user.addProperty("id", jsonInfo.get("Identifier").getAsString());
user.addProperty("memberSince", jsonInfo.get("Created").getAsString());
emails.add(user);
});
return emails;
@ -379,7 +392,11 @@ public class RegistryCalls implements AaiRegistryService {
params.put("copersonid", coPersonId.toString());
JsonElement response = httpUtils.get("names.json", params);
JsonObject info = (response != null) ? response.getAsJsonObject().get("Names").getAsJsonArray().get(0).getAsJsonObject() : null;
return (info != null) ? info.getAsJsonObject().get("Given").getAsString() + " " + info.getAsJsonObject().get("Family").getAsString() : null;
if ( info != null ) {
JsonObject jsonInfo = info.getAsJsonObject();
return jsonInfo.get("Given").getAsString() + " " + jsonInfo.get("Family").getAsString();
} else
return null;
}
@Override
@ -426,8 +443,9 @@ public class RegistryCalls implements AaiRegistryService {
int total = couIds.size();
for (JsonElement cou : cous) {
if (count < total) {
if (idNameMap.containsKey(cou.getAsJsonObject().get("Id").getAsInt())) {
idNameMap.put(cou.getAsJsonObject().get("Id").getAsInt(), cou.getAsJsonObject().get("Name").getAsString());
JsonObject jsonCou = cou.getAsJsonObject();
if (idNameMap.containsKey(jsonCou.get("Id").getAsInt())) {
idNameMap.put(jsonCou.get("Id").getAsInt(), jsonCou.get("Name").getAsString());
count++;
}
} else {

View File

@ -1,48 +0,0 @@
package eu.dnetlib.repo.manager.service.customHystrixCommands;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.Map;
public class AggregatorsHystrixCommand extends HystrixCommand<String> {
RestTemplate restTemplate;
String baseAddress;
public AggregatorsHystrixCommand(String baseAddress, RestTemplate restTemplate) {
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
this.baseAddress = baseAddress;
this.restTemplate = restTemplate;
}
@Override
protected String run() throws Exception {
String url = baseAddress + "/resources" +
"?query= " +
" oaftype exact datasource and " +
" ( datasourcetypename exact Institutional Repository Aggregator " +
" or datasourcetypename exact Publication Repository Aggregator )";
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(url)
.queryParam("page", 0)
.queryParam("size", 0)
.queryParam("format", "json")
.build().encode();
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
Map metadata = (Map) ((Map) rs.getBody()).get("meta");
return String.valueOf(metadata.get("total"));
}
@Override
protected String getFallback() {
return null;
}
}

View File

@ -1,47 +0,0 @@
package eu.dnetlib.repo.manager.service.customHystrixCommands;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.Map;
public class DataRepositoriesHystrixCommand extends HystrixCommand<String> {
RestTemplate restTemplate ;
private String baseAddress;
public DataRepositoriesHystrixCommand(String baseAddress,RestTemplate restTemplate) {
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
this.baseAddress = baseAddress;
this.restTemplate = restTemplate;
}
@Override
protected String run() {
String url = baseAddress+"/resources" +
"?query= " +
" oaftype exact datasource and " +
" datasourcetypename exact Data Repository ";
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(url)
.queryParam("page",0)
.queryParam("size",0)
.queryParam("format","json")
.build().encode();
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET,null,Map.class);
Map metadata = (Map) ((Map)rs.getBody()).get("meta");
return String.valueOf(metadata.get("total"));
}
@Override
protected String getFallback() {
return null;
}
}

View File

@ -1,44 +0,0 @@
package eu.dnetlib.repo.manager.service.customHystrixCommands;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.Map;
public class DatasetsHystrixCommand extends HystrixCommand<String> {
RestTemplate restTemplate;
String baseAddress;
public DatasetsHystrixCommand(String baseAddress,RestTemplate restTemplate) {
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
this.restTemplate = restTemplate;
this.baseAddress = baseAddress;
}
@Override
protected String run() throws Exception {
String url = baseAddress+"/datasets/count";
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(url)
.queryParam("page", 0)
.queryParam("size", 0)
.queryParam("format", "json")
.build().encode();
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
Map metadata = (Map) (rs.getBody());
return String.valueOf(metadata.get("total"));
}
@Override
protected String getFallback() {
return null;
}
}

View File

@ -1,48 +0,0 @@
package eu.dnetlib.repo.manager.service.customHystrixCommands;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.Map;
public class JournalHystrixCommand extends HystrixCommand<String> {
RestTemplate restTemplate;
private String baseAddress;
public JournalHystrixCommand(String baseAddress, RestTemplate restTemplate) {
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
this.baseAddress = baseAddress;
this.restTemplate = restTemplate;
}
@Override
protected String run() throws Exception {
String url = baseAddress+"/resources"+
"?query= " +
" oaftype exact datasource and " +
" datasourcetypename exact Journal";
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(url)
.queryParam("page", 0)
.queryParam("size", 0)
.queryParam("format", "json")
.build().encode();
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
Map metadata = (Map) ((Map) rs.getBody()).get("meta");
return String.valueOf(metadata.get("total"));
}
@Override
protected String getFallback() {
return null;
}
}

View File

@ -1,52 +0,0 @@
package eu.dnetlib.repo.manager.service.customHystrixCommands;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class LastYearUsageStatsHystrixCommand extends HystrixCommand<Map> {
RestTemplate restTemplate;
String usagestatsBaseAddress;
public LastYearUsageStatsHystrixCommand(String usagestatsBaseAddress,RestTemplate restTemplate) {
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
this.usagestatsBaseAddress = usagestatsBaseAddress;
this.restTemplate = restTemplate;
}
@Override
protected Map run() throws Exception {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(usagestatsBaseAddress + "/totals")
.build().encode();
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET,null,Map.class);
List yearly_stats = (List) ((Map)rs.getBody()).get("yearly_stats");
Map lastYear = (Map) yearly_stats.get(yearly_stats.size()-1);
Integer downloads = (Integer) lastYear.get("downloads");
Integer views = (Integer) lastYear.get("views");
Integer year = (Integer) lastYear.get("year");
Map<String,Object> usagestats = new HashMap<>();
usagestats.put("number",String.valueOf(downloads+views));
usagestats.put("year",year);
return usagestats;
}
@Override
protected Map getFallback() {
return null;
}
}

View File

@ -1,49 +0,0 @@
package eu.dnetlib.repo.manager.service.customHystrixCommands;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.Map;
public class LiteratureHystrixCommand extends HystrixCommand<String> {
RestTemplate restTemplate;
private String baseAddress;
public LiteratureHystrixCommand(String baseAddress , RestTemplate restTemplate) {
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
this.baseAddress = baseAddress;
this.restTemplate = restTemplate;
}
@Override
protected String run() throws Exception {
String url = baseAddress+"/resources"+
"?query= " +
" oaftype exact datasource and " +
" ( datasourcetypename exact Institutional Repository " +
" or datasourcetypename exact Publication Repository )";
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(url)
.queryParam("page", 0)
.queryParam("size", 0)
.queryParam("format", "json")
.build().encode();
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
Map metadata = (Map) ((Map) rs.getBody()).get("meta");
return String.valueOf(metadata.get("total"));
}
@Override
protected String getFallback() {
return null;
}
}

View File

@ -1,45 +0,0 @@
package eu.dnetlib.repo.manager.service.customHystrixCommands;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.Map;
public class PublicationHystrixCommand extends HystrixCommand<String> {
RestTemplate restTemplate;
private String baseAddress;
public PublicationHystrixCommand(String baseAddress, RestTemplate restTemplate) {
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
this.baseAddress = baseAddress;
this.restTemplate = restTemplate;
}
@Override
protected String run() throws Exception {
String url = baseAddress + "/publications/count";
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(url)
.queryParam("page", 0)
.queryParam("size", 0)
.queryParam("format", "json")
.build().encode();
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
Map metadata = (Map) (rs.getBody());
return String.valueOf(metadata.get("total"));
}
@Override
protected String getFallback() {
return null;
}
}

View File

@ -1,44 +0,0 @@
package eu.dnetlib.repo.manager.service.customHystrixCommands;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.Map;
public class SoftwareHystrixCommand extends HystrixCommand<String> {
String baseAddress;
RestTemplate restTemplate;
public SoftwareHystrixCommand(String baseAddress, RestTemplate restTemplate) {
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
this.baseAddress = baseAddress;
this.restTemplate = restTemplate;
}
@Override
protected String run() {
String url = baseAddress + "/software/count";
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(url)
.queryParam("page", 0)
.queryParam("size", 0)
.queryParam("format", "json")
.build().encode();
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, null, Map.class);
Map metadata = (Map) (rs.getBody());
return String.valueOf(metadata.get("total"));
}
@Override
protected String getFallback() {
return null;
}
}

View File

@ -1,43 +0,0 @@
package eu.dnetlib.repo.manager.service.customHystrixCommands;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.Map;
public class UsageStatsTotalHystrixCommand extends HystrixCommand<Integer> {
RestTemplate restTemplate ;
String usagestatsEvents;
public UsageStatsTotalHystrixCommand(String usagestatsEvents,RestTemplate restTemplate) {
super(HystrixCommandGroupKey.Factory.asKey("StatisticsGroup"));
this.usagestatsEvents = usagestatsEvents;
this.restTemplate = restTemplate;
}
@Override
protected Integer run() {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(usagestatsEvents)
.build().encode();
ResponseEntity rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET,null,Map.class);
Map metadata = (Map) ((Map)rs.getBody()).get("totals");
// String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
// JSONObject resultSet = new JSONObject(rs);
// JSONObject totals = resultSet.getJSONObject("totals");
return (Integer) metadata.get("events");
}
@Override
protected Integer getFallback() {
return null;
}
}

View File

@ -1,6 +1,7 @@
package eu.dnetlib.repo.manager.service.security;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
@ -14,7 +15,7 @@ import java.util.stream.Collectors;
@Service("roleMappingService")
public class AaiRoleMappingService implements RoleMappingService {
private static final Logger logger = Logger.getLogger(AaiRoleMappingService.class);
private static final Logger logger = LoggerFactory.getLogger(AaiRoleMappingService.class);
@Value("${services.provide.aai.registry.production:true}")
private boolean production;

View File

@ -2,10 +2,13 @@ package eu.dnetlib.repo.manager.service.security;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import org.apache.log4j.Logger;
import com.nimbusds.jose.util.StandardCharset;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.*;
import java.util.regex.Matcher;
@ -13,8 +16,8 @@ import java.util.regex.Pattern;
public class AuthoritiesMapper {
private static final Logger logger = Logger.getLogger(AuthoritiesMapper.class);
private static final String ENTITLEMENT_REGEX = "urn:geant:openaire[.]eu:group:([^:]*):?(.*)?:role=member#aai[.]openaire[.]eu";
private static final Logger logger = LoggerFactory.getLogger(AuthoritiesMapper.class);
private static final Pattern ENTITLEMENT_REGEX = Pattern.compile("urn:geant:openaire[.]eu:group:([^:]*):?(.*)?:role=member#aai[.]openaire[.]eu");
private AuthoritiesMapper() {
}
@ -25,22 +28,24 @@ public class AuthoritiesMapper {
return authorities;
}
public static List<String> entitlementRoles(JsonArray entitlements) {
public static List<String> entitlementRoles(JsonArray entitlements) throws UnsupportedEncodingException {
List<String> roles = new ArrayList<>();
if (entitlements != null) {
for (JsonElement obj : entitlements) {
Matcher matcher = Pattern.compile(ENTITLEMENT_REGEX).matcher(obj.getAsString());
Matcher matcher = ENTITLEMENT_REGEX.matcher(obj.getAsString());
if (matcher.find()) {
StringBuilder sb = new StringBuilder();
if (matcher.group(1) != null && matcher.group(1).length() > 0) {
sb.append(matcher.group(1));
String group1 = matcher.group(1);
if (group1 != null && group1.length() > 0) {
sb.append(group1);
}
if (matcher.group(2).length() > 0) {
String group2 = matcher.group(2);
if (group2.length() > 0) {
sb.append(":");
sb.append(matcher.group(2));
sb.append(group2);
}
String role = sb.toString().replace("+", " ");
roles.add(URLDecoder.decode(role));
roles.add(URLDecoder.decode(role, StandardCharset.UTF_8.name()));
}
}
}
@ -50,18 +55,20 @@ public class AuthoritiesMapper {
private static void entityRoles(JsonArray entitlements, Set<GrantedAuthority> authorities) {
if (entitlements != null) {
for (JsonElement obj : entitlements) {
Matcher matcher = Pattern.compile(ENTITLEMENT_REGEX).matcher(obj.getAsString());
Matcher matcher = ENTITLEMENT_REGEX.matcher(obj.getAsString());
if (matcher.find()) {
StringBuilder sb = new StringBuilder();
if (matcher.group(1) != null && matcher.group(1).length() > 0) {
sb.append(matcher.group(1).replace("+-+", "_").replaceAll("[+.]", "_").toUpperCase());
String group1 = matcher.group(1);
if (group1 != null && group1.length() > 0) {
sb.append(group1.replace("+-+", "_").replaceAll("[+.]", "_").toUpperCase());
}
if (matcher.group(2).length() > 0) {
String group2 = matcher.group(2);
if (group2.length() > 0) {
sb.append("_");
if (matcher.group(2).equals("admins")) {
if (group2.equals("admins")) {
sb.append("MANAGER");
} else {
sb.append(matcher.group(2).toUpperCase());
sb.append(group2.toUpperCase());
}
}
authorities.add(new SimpleGrantedAuthority(sb.toString()));

View File

@ -1,7 +1,8 @@
package eu.dnetlib.repo.manager.service.security;
import org.apache.log4j.Logger;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
@ -9,8 +10,8 @@ import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.common.exceptions.UnauthorizedClientException;
import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
import org.springframework.session.Session;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.Session;
import org.springframework.stereotype.Service;
import java.util.Collection;
@ -21,25 +22,23 @@ import java.util.Map;
@Service
public class AuthoritiesUpdater extends HttpSessionSecurityContextRepository {
private static final Logger logger = Logger.getLogger(AuthoritiesUpdater.class);
private static final Logger logger = LoggerFactory.getLogger(AuthoritiesUpdater.class);
@Autowired
FindByIndexNameSessionRepository sessions;
public void update(String id, Update update) {
if (sessions != null) {
Map<String, Session> map = sessions.
findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, id);
Map map = sessions.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, id);
if (map != null) {
logger.debug(map.values().toArray().length);
for (Session session : map.values()) {
for ( Object sessionObject : map.values()) {
Session session = (Session) sessionObject;
logger.debug(session.getId());
if (!session.isExpired()) {
SecurityContext securityContext = session.getAttribute(SPRING_SECURITY_CONTEXT_KEY);
Authentication authentication = securityContext.getAuthentication();
if (authentication instanceof OIDCAuthenticationToken) {
OIDCAuthenticationToken authOIDC = (OIDCAuthenticationToken) authentication;
logger.debug(update.authorities(authOIDC.getAuthorities()));
securityContext.setAuthentication(new OIDCAuthenticationToken(authOIDC.getSub(), authOIDC.getIssuer(),
authOIDC.getUserInfo(), update.authorities(authOIDC.getAuthorities()), authOIDC.getIdToken(),
authOIDC.getAccessTokenValue(), authOIDC.getRefreshTokenValue()));
@ -65,7 +64,7 @@ public class AuthoritiesUpdater extends HttpSessionSecurityContextRepository {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth instanceof OIDCAuthenticationToken) {
OIDCAuthenticationToken oidcAuth = (OIDCAuthenticationToken) auth;
this.addRole(oidcAuth.getUserInfo().getEmail(), role);
this.addRole(oidcAuth.getUserInfo().getSub(), role);
} else {
throw new UnauthorizedClientException("User auth is not instance of OIDCAuthenticationToken");
}
@ -83,7 +82,7 @@ public class AuthoritiesUpdater extends HttpSessionSecurityContextRepository {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth instanceof OIDCAuthenticationToken) {
OIDCAuthenticationToken oidcAuth = (OIDCAuthenticationToken) auth;
this.removeRole(oidcAuth.getUserInfo().getEmail(), role);
this.removeRole(oidcAuth.getUserInfo().getSub(), role);
}
}

View File

@ -38,22 +38,22 @@ public interface AuthorizationService {
/**
* Add a user as admin to a resource.
*
* @param id Resource id
* @param email User email
* @param resourceId Resource id
* @param email User email
* @return
* @throws ResourceNotFoundException
*/
boolean addAdmin(String id, String email) throws ResourceNotFoundException;
boolean addAdmin(String resourceId, String email) throws ResourceNotFoundException;
/**
* Remove user from resource admins.
*
* @param id Resource id
* @param email User email
* @param resourceId Resource id
* @param email User email
* @return
* @throws ResourceNotFoundException
*/
boolean removeAdmin(String id, String email) throws ResourceNotFoundException;
boolean removeAdmin(String resourceId, String email) throws ResourceNotFoundException;
/**
@ -69,6 +69,6 @@ public interface AuthorizationService {
* @param email
* @return
*/
Collection<String> getUserRoles(String email);
Collection<String> getUserRolesByEmail(String email);
}

View File

@ -1,29 +1,25 @@
package eu.dnetlib.repo.manager.service.security;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import eu.dnetlib.repo.manager.domain.dto.User;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.mitre.openid.connect.model.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
@Service("authorizationService")
public class AuthorizationServiceImpl implements AuthorizationService {
private static final Logger logger = LogManager.getLogger(AuthorizationServiceImpl.class);
private static final Logger logger = LoggerFactory.getLogger(AuthorizationServiceImpl.class);
public static final String SUPER_ADMINISTRATOR = "SUPER_ADMINISTRATOR";
public static final String CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR = "CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR";
@ -74,33 +70,26 @@ public class AuthorizationServiceImpl implements AuthorizationService {
@Override
public List<User> getAdminsOfRepo(String repoId) {
List<String> userList = new ArrayList<>();
// find couId by role name
String role = roleMappingService.getRoleIdByRepoId(repoId);
Integer couId = aaiRegistryService.getCouId(role);
if (couId != null) {
JsonArray users = aaiRegistryService.getUsersByCouId(couId);
for (JsonElement jsonElement : users) {
userList.add(jsonElement.toString());
}
}
return aaiRegistryService.getUsers(couId);
}
@Override
public boolean addAdmin(String id, String email) throws ResourceNotFoundException {
public boolean addAdmin(String resourceId, String email) throws ResourceNotFoundException {
Integer coPersonId = aaiRegistryService.getCoPersonIdByEmail(email);
if (coPersonId != null) {
String role = roleMappingService.getRoleIdByRepoId(id);
String role = roleMappingService.getRoleIdByRepoId(resourceId);
Integer couId = aaiRegistryService.getCouId(role);
if (couId != null) {
Integer roleId = aaiRegistryService.getRoleId(coPersonId, couId);
aaiRegistryService.assignMemberRole(coPersonId, couId, roleId);
// Add role to user current authorities
authoritiesUpdater.addRole(email, roleMappingService.convertRepoIdToAuthority(id));
authoritiesUpdater.addRole(email, roleMappingService.convertRepoIdToAuthority(resourceId));
return true;
} else {
@ -112,10 +101,10 @@ public class AuthorizationServiceImpl implements AuthorizationService {
}
@Override
public boolean removeAdmin(String id, String email) throws ResourceNotFoundException {
public boolean removeAdmin(String resourceId, String email) throws ResourceNotFoundException {
Integer coPersonId = aaiRegistryService.getCoPersonIdByEmail(email);
if (coPersonId != null) {
String role = roleMappingService.getRoleIdByRepoId(id);
String role = roleMappingService.getRoleIdByRepoId(resourceId);
Integer couId = aaiRegistryService.getCouId(role);
Integer roleId = null;
if (couId != null) {
@ -125,7 +114,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
aaiRegistryService.removeMemberRole(coPersonId, couId, roleId);
// Remove role from user current authorities
authoritiesUpdater.removeRole(email, roleMappingService.convertRepoIdToAuthority(id));
authoritiesUpdater.removeRole(email, roleMappingService.convertRepoIdToAuthority(resourceId));
return true;
} else {
@ -140,14 +129,16 @@ public class AuthorizationServiceImpl implements AuthorizationService {
public Collection<String> getUserRoles() {
Collection<String> roles;
UserInfo userInfo = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo();
roles = getUserRoles(userInfo.getEmail());
roles = getUserRolesByEmail(userInfo.getEmail());
logger.debug(String.format("User Roles: %s", String.join(",", roles)));
if (logger.isDebugEnabled()) {
logger.debug("User Roles: {}", String.join(",", roles));
}
return roles;
}
@Override
public Collection<String> getUserRoles(String email) {
public Collection<String> getUserRolesByEmail(String email) {
int coPersonId = aaiRegistryService.getCoPersonIdByEmail(email);
List<Integer> list = new ArrayList<>();
for (JsonElement element : aaiRegistryService.getRolesWithStatus(coPersonId, AaiRegistryService.RoleStatus.ACTIVE)) {

View File

@ -4,29 +4,29 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.repo.manager.domain.*;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Component
public class Converter {
private static final Logger LOGGER = Logger.getLogger(Converter.class);
private static final Logger logger = LoggerFactory.getLogger(Converter.class);
private final ObjectMapper objectMapper;
public Converter() {
objectMapper = new ObjectMapper();
objectMapper = new ObjectMapper()/*.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)*/;
}
public Repository toRepository(Object repositoryObject) {
@ -51,16 +51,7 @@ public class Converter {
return resultSet;
}
public List<RepositoryInterface> toRepositoryInterfaceList(JSONObject json) throws JSONException {
List<RepositoryInterface> resultSet = new ArrayList<>();
JSONArray rs = json.getJSONArray("api");
for (int i = 0; i < rs.length(); i++)
resultSet.add(toRepositoryInterface(rs.getJSONObject(i)));
return resultSet;
}
public List<RepositoryInterface> toRepositoryInterfaceList(List<ApiDetails> apiDetailsList) throws JSONException {
public List<RepositoryInterface> toRepositoryInterfaceList(List<ApiDetails> apiDetailsList) {
List<RepositoryInterface> resultSet = new ArrayList<>();
@ -85,27 +76,16 @@ public class Converter {
String line;
List<String> list = new ArrayList<>();
try {
//InputStream in = Converter.class.getResourceAsStream("resources/eu/dnetlib/repo/manager/service/utils/"+filename);
InputStream in = Converter.class.getClass().getResourceAsStream("/eu/**/" + filename);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
InputStream in = Converter.class.getResourceAsStream("/eu/**/" + filename);
BufferedReader br = new BufferedReader(new InputStreamReader(in)); // It may throw an NPE.
while ((line = br.readLine()) != null) {
list.add(line.trim());
}
br.close();
} catch (IOException e) {
LOGGER.debug("Error opening file!");
LOGGER.error(e);
} catch (Exception e) {
logger.error("Error opening file!", e);
}
return list;
}
public List<AggregationDetails> toAggregationHistory(JSONArray aggregationInfo) throws JSONException {
List<AggregationDetails> aggregationDetailsList = new ArrayList<>();
for (int i = 0; i < aggregationInfo.length(); i++)
aggregationDetailsList.add(toAggregationDetails(aggregationInfo.getJSONObject(i)));
return aggregationDetailsList;
return list; // It may be empty.
}
public List<Timezone> toTimezones(List<String> timezones) {
@ -128,29 +108,6 @@ public class Converter {
return value.equals("null") ? null : Boolean.valueOf(value);
}
private Date toDate(String date) {
if (Objects.equals(date, "null"))
return null;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
try {
return formatter.parse(date);
} catch (ParseException e) {
LOGGER.error(e);
}
return null;
}
public String toString(Date date) {
if (Objects.equals(date, null))
return null;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
return formatter.format(date);
}
private Double toDouble(String number) {
if (Objects.equals(number, "null"))
return 0.0;
@ -158,20 +115,5 @@ public class Converter {
return Double.valueOf(number);
}
private AggregationDetails toAggregationDetails(JSONObject aggregationObject) throws JSONException {
AggregationDetails aggregationDetails = new AggregationDetails();
if (aggregationObject.has("collectionMode"))
aggregationDetails.setCollectionMode(aggregationObject.get("collectionMode").toString());
if (aggregationObject.has("indexedVersion"))
aggregationDetails.setIndexedVersion(Boolean.parseBoolean(aggregationObject.get("indexedVersion").toString()));
aggregationDetails.setAggregationStage(aggregationObject.get("aggregationStage").toString());
aggregationDetails.setDate(toDate(aggregationObject.get("date").toString()));
aggregationDetails.setNumberOfRecords(Integer.parseInt(aggregationObject.get("numberOfRecords").toString()));
return aggregationDetails;
}
}

View File

@ -3,6 +3,7 @@ package eu.dnetlib.repo.manager.utils;
import eu.dnetlib.domain.functionality.validator.JobResultEntry;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import org.eurocris.openaire.cris.validator.model.Job;
import org.eurocris.openaire.cris.validator.model.Rule;
import org.eurocris.openaire.cris.validator.model.RuleResults;
import java.text.DateFormat;
@ -20,14 +21,17 @@ public class CrisValidatorUtils {
StoredJob sj = new StoredJob();
sj.setId(job.getId().hashCode());
sj.setValidationStatus(job.getStatus());
if (job.getDateFinished() != null) {
sj.setEnded(DATE_FORMATTER.format(job.getDateFinished()));
sj.setDuration(DURATION_FORMATTER.format(new Date(job.getDateFinished().getTime() - job.getDateStarted().getTime())));
Date dateFinished = job.getDateFinished();
Date dateStarted = job.getDateStarted();
if ( dateFinished != null ) {
sj.setEnded(DATE_FORMATTER.format(dateFinished));
sj.setDuration(DURATION_FORMATTER.format(new Date(dateFinished.getTime() - dateStarted.getTime())));
} else {
sj.setEnded("-");
sj.setDuration("-");
}
sj.setStarted(DATE_FORMATTER.format(job.getDateStarted()));
sj.setStarted(DATE_FORMATTER.format(dateStarted));
sj.setUserEmail(job.getUser());
sj.setCris(true);
@ -56,21 +60,24 @@ public class CrisValidatorUtils {
public static List<JobResultEntry> crisResultsToJobEntries(Job crisJob) {
List<JobResultEntry> jobResultEntries = new ArrayList<>();
for (RuleResults ruleResults : crisJob.getRuleResults()) {
Rule rule = ruleResults.getRule();
JobResultEntry jobResultEntry = new JobResultEntry();
jobResultEntry.setName(ruleResults.getRule().getName());
jobResultEntry.setRuleId(ruleResults.getRule().getId());
jobResultEntry.setDescription(ruleResults.getRule().getDescription());
jobResultEntry.setName(rule.getName());
jobResultEntry.setRuleId(rule.getId());
jobResultEntry.setDescription(rule.getDescription());
jobResultEntry.setMandatory(true);
jobResultEntry.setWeight(Math.round(ruleResults.getRule().getWeight()));
jobResultEntry.setType(ruleResults.getRule().getType());
jobResultEntry.setWeight(Math.round(rule.getWeight()));
jobResultEntry.setType(rule.getType());
jobResultEntry.setHasErrors(false);
if (ruleResults.getCount() == 0) {
long countRuleResults = ruleResults.getCount();
if (countRuleResults == 0) {
jobResultEntry.setSuccesses("-");
} else {
jobResultEntry.setSuccesses(ruleResults.getCount() - ruleResults.getFailed() + "/" + ruleResults.getCount());
jobResultEntry.setSuccesses(countRuleResults - ruleResults.getFailed() + "/" + countRuleResults);
}
if (ruleResults.getErrorMessages() != null && !ruleResults.getErrorMessages().isEmpty()) {
jobResultEntry.setErrors(ruleResults.getErrorMessages());
List<String> errorMessages = ruleResults.getErrorMessages();
if (errorMessages != null && !errorMessages.isEmpty()) {
jobResultEntry.setErrors(errorMessages);
jobResultEntry.setHasErrors(true);
}
jobResultEntries.add(jobResultEntry);

View File

@ -0,0 +1,49 @@
package eu.dnetlib.repo.manager.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;
public class DateUtils {
private static final Logger logger = LoggerFactory.getLogger(DateUtils.class);
public static Date toDate(String date) {
if (Objects.equals(date, "null"))
return null;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
try {
return formatter.parse(date);
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
return null;
}
public static String toString(Date date) {
if (Objects.equals(date, null))
return null;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
return formatter.format(date);
}
public static String getYear(String date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(Objects.requireNonNull(toDate(date)));
return String.valueOf(calendar.get(Calendar.YEAR));
}
private DateUtils() {
}
}

View File

@ -4,19 +4,20 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Map;
@Component
public class HttpUtils {
private static final Logger logger = Logger.getLogger(HttpUtils.class);
private static final Logger logger = LoggerFactory.getLogger(HttpUtils.class);
@Value("${services.provide.aai.registry.url}")
private String registryUrl;
@ -78,20 +79,24 @@ public class HttpUtils {
private HttpHeaders createHeaders(String username, String password) {
return new HttpHeaders() {{
String auth = username + ":" + password;
byte[] encodedAuth = Base64.encodeBase64(
auth.getBytes(Charset.forName("US-ASCII")));
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.US_ASCII));
String authHeader = "Basic " + new String(encodedAuth);
set("Authorization", authHeader);
}};
}
private JsonElement getResponseEntityAsJsonElement(ResponseEntity<String> responseEntity) {
if (responseEntity != null && responseEntity.getBody() != null) {
logger.debug(responseEntity.getBody());
if ( responseEntity == null )
return null;
String responseBody = responseEntity.getBody();
if ( responseBody != null ) {
logger.debug(responseBody);
try {
return new JsonParser().parse(responseEntity.getBody());
return new JsonParser().parse(responseBody);
} catch (Exception e) {
logger.warn("Could not parse response body", e);
logger.warn("Could not parse response body", e); // Will return null.
}
}
return null;

View File

@ -1,7 +1,8 @@
package eu.dnetlib.repo.manager.utils;
import org.apache.log4j.Logger;
import org.dom4j.io.DOMWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import se.kb.oai.pmh.*;
@ -24,16 +25,15 @@ public class OaiTools {
disableSslVerification();
}
private static Logger LOGGER = Logger.getLogger(OaiTools.class);
private static Logger logger = LoggerFactory.getLogger(OaiTools.class);
public static List<String> getSetsOfRepo(String baseUrl) throws Exception {
try {
LOGGER.debug("Getting sets of repository " + baseUrl);
logger.debug("Getting sets of repository: {}", baseUrl);
OaiPmhServer harvester = new OaiPmhServer(baseUrl);
SetsList setList = harvester.listSets();
ResumptionToken token = setList.getResumptionToken();
List<Set> sets = new ArrayList<Set>();
sets.addAll(setList.asList());
List<Set> sets = new ArrayList<>(setList.asList());
while (token != null) {
setList = harvester.listSets(token);
token = setList.getResumptionToken();
@ -49,14 +49,14 @@ public class OaiTools {
return ret;
} catch (Exception e) {
LOGGER.error("Error getting sets of repository " + baseUrl, e);
logger.error("Error getting sets of repository " + baseUrl, e);
return new ArrayList<String>();
//throw e;
}
}
public static boolean identifyRepository(String baseUrl) throws Exception {
LOGGER.debug("sending identify request to repo " + baseUrl);
logger.debug("sending identify request to repo: {}", baseUrl);
OaiPmhServer harvester = new OaiPmhServer(baseUrl);
@ -71,7 +71,7 @@ public class OaiTools {
return verifyIdentify(d);
} catch (Exception e) {
LOGGER.debug("Error verifying identify response", e);
logger.debug("Error verifying identify response", e);
throw e;
}
}
@ -112,7 +112,7 @@ public class OaiTools {
private static void disableSslVerification() {
try
{
LOGGER.debug("disabling ssl verification");
logger.debug("disabling ssl verification");
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
@ -140,9 +140,9 @@ public class OaiTools {
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
} catch (NoSuchAlgorithmException e) {
LOGGER.error("disabling ssl verification", e);
logger.error("disabling ssl verification", e);
} catch (KeyManagementException e) {
LOGGER.error("error while disabling ssl verification", e);
logger.error("error while disabling ssl verification", e);
}
}
}

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.controllers;
package eu.dnetlib.repo.manager.utils;
import eu.dnetlib.repo.manager.exception.EndPointException;
import org.springframework.http.HttpStatus;
@ -16,19 +16,17 @@ public class RestTemplateResponseErrorHandler implements ResponseErrorHandler {
@Override
public boolean hasError(ClientHttpResponse httpResponse) throws IOException {
return (httpResponse.getStatusCode().series() == CLIENT_ERROR
|| httpResponse.getStatusCode().series() == SERVER_ERROR);
HttpStatus.Series seriesError = httpResponse.getStatusCode().series();
return ( (seriesError == CLIENT_ERROR) || (seriesError == SERVER_ERROR) );
}
@Override
public void handleError(ClientHttpResponse httpResponse) throws IOException {
if (httpResponse.getStatusCode().series() == HttpStatus.Series.SERVER_ERROR) {
HttpStatus statusCode = httpResponse.getStatusCode();
if ( statusCode == HttpStatus.NOT_FOUND )
throw new IOException();
else if (statusCode.series() == SERVER_ERROR)
throw new EndPointException();
} else if (httpResponse.getStatusCode().series() == HttpStatus.Series.CLIENT_ERROR) {
if (httpResponse.getStatusCode() == HttpStatus.NOT_FOUND) {
throw new IOException();
}
}
}
}

View File

@ -1,9 +1,9 @@
<?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" xmlns:tx="http://www.springframework.org/schema/tx"
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 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
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/>

View File

@ -1,14 +1,30 @@
springdoc.swagger-ui:
disable-swagger-default-url: true
version: 3
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}
services:
provide:
dev-machine: 88.197.53.71
aai:
baseURL: https://aai.openaire.eu
oidc:
domain: .openaire.eu
id: XX
issuer: ${services.provide.aai.baseURL}/oidc/
redirectURL: http://88.197.53.69/api/openid_connect_login
redirectURL: http://localhost:${server.port}${server.servlet.context-path}/openid_connect_login
secret: XX
webURL: http://88.197.53.69/join
webURL: http://localhost:4200/join
registry:
coid: XX
password: XX
@ -17,21 +33,21 @@ services:
username: provide_openaire
adminEmail: XX
analyticsURL: https://analytics.openaire.eu/addsite.php?
baseUrl: https://beta.provide.openaire.eu/
baseUrl: https://dev-openaire.d4science.org/openaire
broker:
api: api/
openaire: openaireBroker
port: 8080
url: https://broker1-dev-dnet.d4science.org
clients:
dsm: https://beta.services.openaire.eu/openaire
dsm: https://dev-openaire.d4science.org/openaire
search: https://beta.services.openaire.eu/search/v2/api
usageEvents: http://beta.lbs.openaire.eu:8080/ajax/summary
usagestats: https://services.openaire.eu/usagestats
db:
driverClassName: org.postgresql.Driver
password: dnetPwd
url: jdbc:postgresql://localhost:5432/repomanager
url: jdbc:postgresql://${services.provide.dev-machine}:5432/repomanager
username: dnet
iSLookUpService:
url: https://dev-openaire.d4science.org:443/is/services/isLookUp
@ -46,8 +62,8 @@ services:
replyTo: XX
username: XX
redis:
host: localhost
password: 2106875370
host: vereniki.athenarc.gr
password: XX
port: 6379
topic_types:
url: https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:topic_types.json
@ -60,4 +76,4 @@ services:
results:
url: https://beta.provide.openaire.eu/compatibility/browseHistory/
validatorService:
url: http://88.197.53.69:8080/uoa-validator-service/services/validatorWebService
url: http://${services.provide.dev-machine}:8080/uoa-validator-service/services/validatorWebService

View File

@ -6,11 +6,11 @@
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="LogToConsole"/>
</Root>
<Logger name="org.springframework.boot" level="error" additivity="false">
<AppenderRef ref="LogToConsole"/>
</Logger>
<Root level="error">
<AppenderRef ref="LogToConsole"/>
</Root>
</Loggers>
</Configuration>

View File

@ -1,12 +1,11 @@
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<import resource="classpath*:/application-context.xml"/>

View File

@ -1,4 +1,4 @@
package metrics;
package eu.dnetlib.repo.manager.integration.metrics;
import eu.dnetlib.repo.manager.controllers.PrometheusController;
import eu.dnetlib.repo.manager.service.PiWikService;

View File

@ -0,0 +1,58 @@
package eu.dnetlib.repo.manager.integration.service;
import eu.dnetlib.repo.manager.domain.InterfaceComplianceRequest;
import eu.dnetlib.repo.manager.domain.InterfaceComplianceRequestId;
import eu.dnetlib.repo.manager.repository.InterfaceComplianceRequestsRepository;
import org.junit.Assert;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Date;
@RunWith(SpringRunner.class)
@DataJpaTest
//@AutoConfigureTestDatabase
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
//@Transactional(propagation = Propagation.NOT_SUPPORTED)
class InterfaceComplianceRequestTests {
@Autowired
private InterfaceComplianceRequestsRepository repository;
@Test
void getRequestById() {
InterfaceComplianceRequest request = createRequest("3");
repository.save(request);
long total = repository.count();
Assert.assertEquals(1, total);
InterfaceComplianceRequest r = repository.findById(createRequestId()).orElse(null);
Assert.assertNotNull(r);
}
@AfterEach
public void deleteRequestAfterTests() {
repository.deleteById(createRequestId());
}
private InterfaceComplianceRequestId createRequestId() {
InterfaceComplianceRequestId id = new InterfaceComplianceRequestId();
id.setRepositoryId("repository");
id.setInterfaceId("interface");
return id;
}
private InterfaceComplianceRequest createRequest(String compatibilityLevel) {
InterfaceComplianceRequest request = new InterfaceComplianceRequest();
InterfaceComplianceRequestId id = createRequestId();
request.setRepositoryId(id.getRepositoryId());
request.setInterfaceId(id.getInterfaceId());
request.setDesiredCompatibilityLevel(compatibilityLevel);
request.setSubmissionDate(new Date());
return request;
}
}

View File

@ -0,0 +1,27 @@
package eu.dnetlib.repo.manager.unit;
import eu.dnetlib.repo.manager.domain.InterfaceComplianceRequest;
import eu.dnetlib.repo.manager.domain.dto.InterfaceComplianceRequestDTO;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest(classes = InterfaceComplianceRequest.class)
@RunWith(SpringRunner.class)
class InterfaceComplianceRequestTest {
@Test
void interfaceComplianceRequest_contains_date_test() {
InterfaceComplianceRequest request = new InterfaceComplianceRequest();
Assert.assertNotNull(request.getSubmissionDate());
InterfaceComplianceRequestDTO dto = new InterfaceComplianceRequestDTO();
Assert.assertNull(dto.getSubmissionDate());
request = InterfaceComplianceRequest.from(dto);
Assert.assertNotNull(request.getSubmissionDate());
}
}

View File

@ -1,42 +0,0 @@
<?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" xmlns:tx="http://www.springframework.org/schema/tx"
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 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.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

@ -0,0 +1,13 @@
spring:
datasource:
url: jdbc:h2:mem:test
driverClassName: org.h2.Driver
h2:
console:
enabled: true
jpa:
show-sql: true
hibernate:
ddl-auto: update
main:
banner-mode: console

View File

@ -1,70 +0,0 @@
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<import resource="classpath*:/application-context.xml"/>
<import resource="classpath*:/eu/dnetlib/soap/cxf/applicationContext-eprbuilders.xml"/>
<import resource="classpath*:/eu/dnetlib/clients/ws/springContext-locatorFactory.xml"/>
<import resource="classpath*:/gr/uoa/di/driver/util/springContext-locators.xml"/>
<import resource="classpath*:/gr/uoa/di/driver/app/springContext-lookupFactory.xml"/>
<import resource="classpath*:/gr/uoa/di/driver/app/springContext-lookupClients.xml"/>
<import resource="classpath*:/eu/dnetlib/enabling/hcm/springContext-hcmService.xml"/>
<import resource="classpath*:/gr/uoa/di/driver/app/springContext-commons.xml"/>
<!--<import resource="classpath*:/gr/uoa/di/driver/app/springContext-registrator.xml"/>-->
<bean id="maillib" class="eu.dnetlib.utils.MailLibrary" init-method="init">
<property name="mailhost" value="${services.validator.mail.host}"/>
<property name="smtpPort" value="${services.validator.mail.port}"/>
<property name="authenticate" value="${services.validator.mail.authenticate}"/>
<property name="username" value="${services.validator.mail.username}"/>
<property name="password" value="${services.validator.mail.password}"/>
<property name="from" value="${services.validator.mail.fromAddress}"/>
<property name="replyTo" value="${services.validator.mail.replyToAddress}"/>
<property name="mode" value="${services.validator.mail.mode}"/>
<property name="debug" value="${services.validator.mail.debug}"/>
</bean>
<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-new.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>