Compare commits

...

52 Commits

Author SHA1 Message Date
Ioannis Diplas 0e5372e825 Adding permissions for ROLE_PROVIDE_ADMIN to searchRegisteredRepositories 2019-07-19 09:06:51 +00:00
Ioannis Diplas 37f4dc005b - Renaming role PORTAL_PROVIDE_ADMIN to ROLE_PROVIDE_ADMIN
- Renaming the @PreAuthorize role names
2019-07-17 11:09:28 +00:00
Antonis Lempesis 70f25060d5 fixed a NPE in aggregation history 2019-07-17 08:53:40 +00:00
Ioannis Diplas 8ed868c6fb Removing old ROLE_PORTAL_ADMIN 2019-07-16 12:26:55 +00:00
Ioannis Diplas c9f47ee823 Mapping Content provider dashboard administrator to ROLE_PORTAL_ADMIN 2019-07-16 12:04:18 +00:00
Stefania Martziou 8ff0767f4b Fix in the repository summary info object (implements IsSerializable) 2019-07-10 08:01:55 +00:00
Antonis Lempesis 34bb58c60a Correctly parsing the datasources 2019-07-09 13:17:33 +00:00
Antonis Lempesis 9ca226a0b8 added a method to search registered repositories 2019-07-09 10:12:56 +00:00
Stefania Martziou a514949c7f Implemented dashboard service which gets some summary info for the repositories of the user 2019-07-08 09:20:39 +00:00
Stefania Martziou 4d79978392 Calling the sendAdmin email notifications for the registration and update of a repository - correct 2019-05-17 07:28:08 +00:00
Stefania Martziou 04995f9b50 Calling the sendAdmin email notifications for the registration and update of a repository 2019-05-17 07:27:19 +00:00
Stefania Martziou d89b15530e Added email messages to admins when a repository is registered or updated 2019-05-16 11:55:32 +00:00
Panagiotis Kanakakis d393be9432 Fixed ContentType JSON-UTF8 issue 2019-03-21 12:53:04 +00:00
Panagiotis Kanakakis 0b69cc53a2 Update headers on repository service 2019-03-19 13:45:45 +00:00
Panagiotis Kanakakis 65e32f13dd 2019-02-28 12:22:27 +00:00
Panagiotis Kanakakis c07475164d Delete wrong commited files 2019-02-16 00:03:58 +00:00
Panagiotis Kanakakis 0a57ede298 Add hystrix configuration for rest statistics calls 2019-02-16 00:01:58 +00:00
Panagiotis Kanakakis 76cd57d035 Return null instead of N/A on statistics 2019-02-12 11:41:35 +00:00
Panagiotis Kanakakis 0483f7ddb0 Bug fix on stats 2019-02-12 09:29:01 +00:00
Panagiotis Kanakakis 1ad268021a Remove last statistics call for debug purposes only 2019-02-12 09:12:27 +00:00
Panagiotis Kanakakis 9b0472bcd8 1. Repository service bug fixes
2. Stats controller bug fix
2019-02-11 09:01:28 +00:00
Panagiotis Kanakakis 99d834dc0e 1. Bug fix on spring setup
2. Bug fix on converter class
2019-02-06 00:09:13 +00:00
Panagiotis Kanakakis 09409528d3 1. Modify project structure
2. Nedds bug fix for emails
2019-02-04 12:47:04 +00:00
Panagiotis Kanakakis 130d06aa35 Update application properties file
Dele iml file
2019-01-03 12:31:46 +00:00
Panagiotis Kanakakis 499b96a9c7 New project structure 2019-01-03 12:19:45 +00:00
Panagiotis Kanakakis 3eaa39a3af Fixes on converter 2018-12-19 11:54:50 +00:00
Panagiotis Kanakakis a6ff851e7b 1. Add new email texts
2. Add indexVersioned field on aggregaton details object
2018-12-05 11:39:04 +00:00
Panagiotis Kanakakis a5887703d8 Modify log4j properties 2018-12-03 13:58:55 +00:00
Panagiotis Kanakakis 7fafa3397f Add new emails for registering/updating repository 2018-12-03 13:58:24 +00:00
Panagiotis Kanakakis d83612439f 1. Bug fix on piwik
2. Add new emails
3. Bug fix on repository api
2018-11-23 07:49:00 +00:00
Panagiotis Kanakakis 7e3c8194d5 Add number on stats 2018-09-14 11:55:35 +00:00
Panagiotis Kanakakis 54f0546fe0 Add repository snippet methods 2018-09-13 09:43:38 +00:00
Panagiotis Kanakakis 600965056b Add year on usagestats 2018-09-11 10:05:10 +00:00
Panagiotis Kanakakis 0358820465 Add usagestats statistics 2018-09-11 08:54:58 +00:00
Panagiotis Kanakakis 8e91741a6e 1. Add env var for cookies 2. Add sushi controllers 3. Bug fix on piwik/repo 4. Add stats controllers/service 2018-09-03 11:47:22 +00:00
myrto.koukouli 5b4f9bae51 fixed a bug in sushilite/getReportResults 2018-08-07 08:01:39 +00:00
myrto.koukouli c69a7d51a8 added pagination to the sushilite call 2018-08-06 08:55:53 +00:00
myrto.koukouli 596c1f84ec changed pom 2018-07-27 09:12:46 +00:00
myrto.koukouli db481624d8 added sushilite service 2018-07-27 09:08:26 +00:00
Panagiotis Kanakakis 5a38abef64 1. Dockerize service
2. Add authorization checks
3. Handle exceptions ( controller advice, exception package)
4. Login-logout operations bug fixes
2018-07-21 15:07:29 +00:00
Panagiotis Kanakakis 5c2dd36f0b 1. Commit dockerfile 2018-06-13 12:27:15 +00:00
Panagiotis Kanakakis de19920f3d 1. Dockerize service for test pourposes
2. Change cookies for aai
3. Change log4j properties with console append for test purposes.
4. Update pom.xml with gson library
2018-06-13 12:21:28 +00:00
Panagiotis Kanakakis 9d487d0773 Hardcoded application properties 2018-05-03 10:42:47 +00:00
Panagiotis Kanakakis 3150e48cab Bug fixes 2018-04-17 10:12:47 +00:00
Panagiotis Kanakakis da0136cb4b Add PreAuthorize annotation on user methods. 2018-04-04 10:28:38 +00:00
Panagiotis Kanakakis 4f5cab3a1f 1. Add dependency for mails
2. Move preauthorize dependency to applicationContext
2018-03-30 10:18:24 +00:00
Panagiotis Kanakakis 0b62a37073 1. Add admin role on aai
2. Add update method for oaiset
2018-03-28 08:52:32 +00:00
Panagiotis Kanakakis cbb0848d5c 1. Add roles for aai
2. Changes on converter file for new interface object
3. Move emailUtils to avoid bug on bean definitions
4. Add openaire provider authorities mapper class
5. Bug fixes on controllers
2018-03-26 21:39:39 +00:00
Panagiotis Kanakakis cd2e30610a 1. Create domain package. Add RequestFilter class.
2. Update converter class with new domain object
3. Update properties file and xml configuration
4. Bug fix on jobs' validation status
2018-03-19 14:31:18 +00:00
Panagiotis Kanakakis daac1ae6cd Configure aai / redis 2018-03-14 14:47:14 +00:00
Panagiotis Kanakakis edd2e4aa02 1. Change hash function on piwik.
2. Bug fixes on repository / broker / validator api
3/ Add field on simple subscription domain.
2018-02-27 13:41:12 +00:00
Panagiotis Kanakakis f8a2dbae90 1.Moving trunk folder to new branch. 2018-02-22 10:57:38 +00:00
89 changed files with 4856 additions and 2191 deletions

11
Dockerfile Normal file
View File

@ -0,0 +1,11 @@
FROM tomcat:7.0.90-jre8
MAINTAINER "pkanakakis@di.uoa.gr"
RUN ["rm", "-fr", "/usr/local/tomcat/webapps/ROOT"]
COPY ./target/uoa-repository-manager-service.war /usr/local/tomcat/webapps/uoa-repository-manager-service.war
#COPY src/main/resources/dnet-override-new.properties /usr/local/tomcat/lib/dnet-override.properties
COPY src/main/resources/application.properties /usr/local/tomcat/lib/dnet-override.properties
#COPY src/main/resources/application.properties /usr/local/tomcat/lib/application.properties
#COPY src/main/resources/email-texts.properties /usr/local/tomcat/lib/email-texts.properties
VOLUME /var/log/uoa-repository-manager-service:/var/log/uoa-repository-manager-service/
CMD ["catalina.sh", "run"]

238
pom.xml
View File

@ -15,52 +15,6 @@
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!--<plugin>
<groupId>cz.habarta.typescript-generator</groupId>
<artifactId>typescript-generator-maven-plugin</artifactId>
<version>1.29.366</version>
<executions>
<execution>
<id>generate1</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<jsonLibrary>jackson2</jsonLibrary>
<outputFileType>implementationFile</outputFileType>
<mapClasses>asClasses</mapClasses>
<classPatterns>
<pattern>eu.dnetlib.domain.data.*</pattern>
</classPatterns>
<outputFile>target/typeScriptClasses.ts</outputFile>
<outputKind>module</outputKind>
</configuration>
</execution>
</executions>
</plugin>-->
</plugins>
</build>
<dependencies>
<dependency>
@ -112,6 +66,12 @@
</exclusions>
</dependency>
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>dnet-openaire-usage-stats-sushilite</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
@ -200,6 +160,12 @@
<version>20080701</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
@ -231,8 +197,13 @@
<version>LATEST</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>LATEST</version>
</dependency>
<!--<dependency>
<dependency>
<groupId>org.mitre</groupId>
<artifactId>openid-connect-client</artifactId>
<version>1.3.0</version>
@ -242,21 +213,182 @@
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>-->
</dependency>
<!--<dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<version>1.3.1.RELEASE</version>
<type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
<groupId>biz.paluch.redis</groupId>
<artifactId>lettuce</artifactId>
<version>3.5.0.Final</version>
</dependency>-->
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>com.thetransactioncompany</groupId>
<artifactId>cors-filter</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>1.1.5.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.xml.ws/jaxws-api -->
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.jws/javax.jws-api -->
<dependency>
<groupId>javax.jws</groupId>
<artifactId>javax.jws-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1-rev-1</version>
</dependency>
</dependencies>
<build>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!--<plugin>-->
<!--<groupId>com.googlecode.maven-download-plugin</groupId>-->
<!--<artifactId>download-maven-plugin</artifactId>-->
<!--<version>1.3.0</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<phase>process-resources</phase>-->
<!--<goals>-->
<!--<goal>wget</goal>-->
<!--</goals>-->
<!--<configuration>-->
<!--<url>-->
<!--https://github.com/ostranme/swagger-ui-themes/archive/v3.0.0.zip-->
<!--</url>-->
<!--<unpack>true</unpack>-->
<!--<outputDirectory>${project.build.directory}</outputDirectory>-->
<!--</configuration>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<sequential>
<echo>Add theme</echo>
<replace token="&lt;/head&gt;"
value="&lt;link href='webjars/springfox-swagger-ui/themes/2.x/theme-feeling-blue.css' rel=&quot;stylesheet&quot;/&gt;&lt;/head&gt;"
dir="${settings.localRepository}/io/springfox/springfox-swagger-ui/2.7.0/META-INF/resources">
<include name="swagger-ui.html"/>
</replace>
</sequential>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
-->
<!--<plugin>
<groupId>cz.habarta.typescript-generator</groupId>
<artifactId>typescript-generator-maven-plugin</artifactId>
<version>1.29.366</version>
<executions>
<execution>
<id>generate1</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<jsonLibrary>jackson2</jsonLibrary>
<outputFileType>implementationFile</outputFileType>
<mapClasses>asClasses</mapClasses>
<classPatterns>
<pattern>eu.dnetlib.domain.data.*</pattern>
</classPatterns>
<outputFile>target/typeScriptClasses.ts</outputFile>
<outputKind>module</outputKind>
</configuration>
</execution>
</executions>
</plugin>-->
</plugins>
<finalName>uoa-repository-manager-service</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.config;
package eu.dnetlib.repo.manager.config;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;

View File

@ -0,0 +1,75 @@
package eu.dnetlib.repo.manager.config;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.context.annotation.*;
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;
@Configuration
@EnableRedisHttpSession
@EnableAspectJAutoProxy
@EnableCircuitBreaker
@PropertySource(value = {"classpath:application.properties"} )
@ComponentScan(basePackages = "eu.dnetlib.repo.manager.*")
public class Config {
private static Logger LOGGER = Logger.getLogger(Config.class);
@Value("${redis.host:194.177.192.121}")
private String host;
@Value("${redis.port:6379}")
private String port;
@Value("${redis.password}")
private String password;
@Value("${aai.mode}")
private String aai_mode;
@PostConstruct
private void init(){
LOGGER.info(host);
}
@Bean
JedisConnectionFactory connectionFactory() {
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));
if(password != null) jedisConnectionFactory.setPassword(password);
return jedisConnectionFactory;
}
@Bean
public CookieSerializer cookieSerializer() {
DefaultCookieSerializer serializer = new DefaultCookieSerializer();
serializer.setCookieName("openAIRESession");
serializer.setCookiePath("/");
if(aai_mode.equalsIgnoreCase("production") || aai_mode.equalsIgnoreCase("beta"))
serializer.setDomainName(".openaire.eu");
// serializer.setDomainName(".athenarc.gr");
LOGGER.info("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

@ -0,0 +1,94 @@
package eu.dnetlib.repo.manager.config;
import com.google.gson.JsonObject;
import org.apache.log4j.Logger;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import com.google.gson.*;
public class FrontEndLinkURIAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
private String frontEndURI;
private static final Logger LOGGER = Logger
.getLogger(FrontEndLinkURIAuthenticationSuccessHandler.class);
public void init(){
LOGGER.debug("Front end uri : " + frontEndURI);
}
@Value("${aai.mode}")
private String aai_mode;
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
OIDCAuthenticationToken authOIDC = (OIDCAuthenticationToken) authentication;
JsonObject userInfo = new JsonObject();
if (authOIDC.getUserInfo().getSub() == null)
userInfo.addProperty("sub", "");
else
userInfo.addProperty("sub", URLEncoder.encode(authOIDC.getUserInfo().getSub(), "UTF-8"));
if(authOIDC.getUserInfo().getName() != null)
userInfo.addProperty("fullname", URLEncoder.encode(authOIDC.getUserInfo().getName(), "UTF-8"));
if (authOIDC.getUserInfo().getGivenName() == null)
userInfo.addProperty("firstname", "");
else
userInfo.addProperty("firstname", URLEncoder.encode(authOIDC.getUserInfo().getGivenName(), "UTF-8") + "");
if (authOIDC.getUserInfo().getFamilyName() == null)
userInfo.addProperty("lastname", "");
else
userInfo.addProperty("lastname", URLEncoder.encode(authOIDC.getUserInfo().getFamilyName(), "UTF-8") + "");
userInfo.addProperty("email", authOIDC.getUserInfo().getEmail() + "");
if (authOIDC.getUserInfo().getSource().getAsJsonArray("edu_person_entitlements") == null)
userInfo.addProperty("role", "");
else
userInfo.addProperty("role", URLEncoder.encode(authOIDC.getUserInfo()
.getSource().getAsJsonArray("edu_person_entitlements").toString(), "UTF-8") + "");
Cookie openAIREUser = new Cookie("openAIREUser", new Gson().toJson(userInfo) );
openAIREUser.setMaxAge(14400);
openAIREUser.setPath("/");
if(aai_mode.equalsIgnoreCase("production") || aai_mode.equalsIgnoreCase("beta"))
openAIREUser .setDomain(".openaire.eu");
// openAIREUser.setDomain(".athenarc.gr");
response.addCookie(openAIREUser);
Cookie accessToken = new Cookie("AccessToken", authOIDC.getAccessTokenValue());
accessToken.setMaxAge(14400);
if(aai_mode.equalsIgnoreCase("production") || aai_mode.equalsIgnoreCase("beta"))
accessToken.setDomain(".openaire.eu");
accessToken.setPath("/");
// accessToken.setDomain(".athenarc.gr");
response.addCookie(accessToken);
response.sendRedirect(frontEndURI);
}
public String getFrontEndURI() {
return frontEndURI;
}
public void setFrontEndURI(String frontEndURI) {
this.frontEndURI = frontEndURI;
}
}

View File

@ -0,0 +1,42 @@
package eu.dnetlib.repo.manager.config;
import com.nimbusds.jwt.JWT;
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.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import java.util.*;
public class OpenAireProviderAuthoritiesMapper implements OIDCAuthoritiesMapper {
private static Logger logger = LoggerFactory.getLogger(OpenAireProviderAuthoritiesMapper.class);
final private static String ROLE_CLAIMS = "edu_person_entitlements";
private Map<String,SimpleGrantedAuthority> userRolesMap;
OpenAireProviderAuthoritiesMapper(Map<String,String> userRoles) {
userRolesMap = new HashMap<>();
userRoles.forEach((openaireRole, appRole) -> userRolesMap.put(openaireRole, new SimpleGrantedAuthority(appRole)));
}
@Override
public Collection<? extends GrantedAuthority> mapAuthorities(JWT idToken, UserInfo userInfo) {
Set<GrantedAuthority> out = new HashSet<>();
out.add(new SimpleGrantedAuthority("ROLE_USER"));
if(userInfo.getSource().getAsJsonArray(ROLE_CLAIMS) != null) {
userInfo.getSource().getAsJsonArray(ROLE_CLAIMS).forEach(role -> {
SimpleGrantedAuthority authority = userRolesMap.get(role.getAsString());
if (authority != null) {
logger.debug("Role mapped " + role);
out.add(authority);
}
});
}
return out;
}
}

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.config;
package eu.dnetlib.repo.manager.config;
import org.apache.commons.lang.ArrayUtils;
import org.apache.log4j.Logger;
@ -32,7 +32,7 @@ public class RepoManagerContextLoaderListener extends ContextLoaderListener {
String repoMode = props.getProperty("services.validator.mode.repo");
String userMode = props.getProperty("services.validator.mode.user");
Boolean standaloneMode = Boolean.parseBoolean(props.getProperty("services.validator.mode.standalone"));
logger.info("User mode: " + userMode);
logger.info("Repo mode: " + repoMode);
logger.info("Standalone mode: " + standaloneMode);
@ -77,7 +77,7 @@ public class RepoManagerContextLoaderListener extends ContextLoaderListener {
"classpath*:/gr/uoa/di/driver/app/springContext-commons.xml",
"classpath*:/gr/uoa/di/driver/app/springContext-registrator.xml"
};
if (standaloneMode) {
logger.debug("Loading contexts for standalone mode");
ctx.setConfigLocations((String[])ArrayUtils.addAll(springContextCore,springContextForStandalone));
@ -85,22 +85,22 @@ public class RepoManagerContextLoaderListener extends ContextLoaderListener {
logger.debug("Loading contexts for dnet");
ctx.setConfigLocations((String[])ArrayUtils.addAll(springContextCore,springContextForIS));
}
ctx.refresh();
logger.debug("done");
return ctx;
}
}
private Properties loadProperties() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {
"classpath*:/eu/dnetlib/repo/manager/server/config/springContext-repo-manager-config.xml"
});
CascadingPropertyLoader pLoader = (CascadingPropertyLoader) ctx.getBean("propertyLoader");
Properties props = pLoader.getProperties();
ctx.destroy();
ctx.close();
return props;

View File

@ -1,9 +1,12 @@
package eu.dnetlib.repo.manager.service.config;
package eu.dnetlib.repo.manager.config;
import eu.dnetlib.repo.manager.service.controllers.MonitorApi;
import eu.dnetlib.repo.manager.service.controllers.PiWikApi;
import eu.dnetlib.repo.manager.service.controllers.RepositoryApi;
import eu.dnetlib.repo.manager.service.controllers.ValidatorApi;
import eu.dnetlib.repo.manager.controllers.*;
import eu.dnetlib.repo.manager.service.MonitorService;
import eu.dnetlib.repo.manager.service.PiWikService;
import eu.dnetlib.repo.manager.service.RepositoryService;
import eu.dnetlib.repo.manager.service.ValidatorService;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@ -16,6 +19,7 @@ import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
@ -25,12 +29,17 @@ import java.util.ArrayList;
@Configuration
@EnableSwagger2
@EnableWebMvc
@EnableCircuitBreaker
@ComponentScan(basePackageClasses = {
RepositoryApi.class,
MonitorApi.class,
ValidatorApi.class,
PiWikApi.class
})
RepositoryController.class,
MonitorController.class,
ValidatorController.class,
PiWikController.class,
BrokerController.class,
StatsController.class,
UserController.class,
SushiliteController.class
},basePackages = "eu.dnetlib.repo.manager.*")
public class SwaggerConfig {
@Bean

View File

@ -0,0 +1,134 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.service.BrokerServiceImpl;
import eu.dnetlib.repo.manager.shared.BrokerException;
import eu.dnetlib.repo.manager.shared.Term;
import eu.dnetlib.repo.manager.shared.broker.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value = "/broker")
@Api(description = "Broker API", tags = {"broker"})
public class BrokerController{
@Autowired
BrokerServiceImpl brokerService;
@RequestMapping(value = "/getDatasourcesOfUser" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
DatasourcesBroker getDatasourcesOfUser(@RequestParam("user")
@ApiParam(value = "User email", required = true) String user,
@RequestParam("includeShared")
@ApiParam(value = "Include shared datasources", required = true , defaultValue = "false") String includeShared,
@RequestParam("includeByOthers")
@ApiParam(value = "Include datasources of other", required = true,defaultValue = "false") String includeByOthers) throws JSONException {
return brokerService.getDatasourcesOfUser(user, includeShared, includeByOthers);
}
@RequestMapping(value = "/getTopicsForDatasource/{datasourceName:.+}" ,
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<BrowseEntry> getTopicsForDatasource(@PathVariable("datasourceName") String datasourceName) throws BrokerException{
return brokerService.getTopicsForDatasource(datasourceName);
}
@RequestMapping(value = "/advancedShowEvents/{page}/{size}" ,
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
EventsPage advancedShowEvents(@PathVariable("page") String page,
@PathVariable("size") String size,
@RequestBody AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException{
return brokerService.advancedShowEvents(page, size, advQueryObject);
}
@RequestMapping(value = "/showEvents/{datasourceName:.+}/{topic}/{page}" ,
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
EventsPage showEvents(@RequestParam("datasourceName") String datasourceName,
@RequestParam("topic") String topic,
@RequestParam("page") String page,
@RequestParam("size") String size) throws BrokerException, JSONException{
return brokerService.showEvents(datasourceName, topic, page, size);
}
@RequestMapping(value = "/getSimpleSubscriptionsOfUser/{userEmail}" ,
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(@PathVariable("userEmail") String userEmail) throws BrokerException{
return brokerService.getSimpleSubscriptionsOfUser(userEmail);
}
@RequestMapping(value = "/subscribe" , method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER') ")
Subscription subscribe(@RequestBody OpenaireSubscription obj) throws BrokerException{
return brokerService.subscribe(obj);
}
@RequestMapping(value = "/unsubscribe/{subscriptionId}" , method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
ResponseEntity<Object> unsubscribe(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException{
return brokerService.unsubscribe(subscriptionId);
}
@RequestMapping(value = "/getSubscription/{subscriptionId}" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
Subscription getSubscription(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException{
return brokerService.getSubscription(subscriptionId);
}
@RequestMapping(value = "/getDnetTopics" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Map<String, Term> getDnetTopics() throws BrokerException{
return brokerService.getDnetTopics();
}
@RequestMapping(value = "/getNotificationsBySubscriptionId/{subscriptionId}/{page}/{size}" , method = RequestMethod.GET
,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
EventsPage getNotificationsBySubscriptionId(@PathVariable("subscriptionId") String subscriptionId,
@PathVariable("page") String page,
@PathVariable("size") String size) throws BrokerException{
return brokerService.getNotificationsBySubscriptionId(subscriptionId, page, size);
}
/*@RequestMapping(value = "/getSubscriptionsOfUser/{userEmail}" , method = RequestMethod.GET
,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody*/
Map<String, List<Subscription>> getSubscriptionsOfUser(String userEmail) throws BrokerException{
return brokerService.getSubscriptionsOfUser(userEmail);
}
}

View File

@ -0,0 +1,31 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
import eu.dnetlib.repo.manager.service.DashboardService;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(value = "/dashboard")
@Api(description = "Dashboard API", tags = {"dashboard"})
public class DashboardController {
@Autowired
DashboardService dashboardService;
@RequestMapping(value = "/getRepositoriesSummary/{userEmail}/{page}/{size}" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public List<RepositorySummaryInfo> getRepositoriesSummaryInfo(@PathVariable("userEmail") String userEmail,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
return dashboardService.getRepositoriesSummaryInfo(userEmail, page, size);
}
}

View File

@ -0,0 +1,65 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.repo.manager.exception.EndPointException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.exception.ServerError;
import eu.dnetlib.repo.manager.shared.BrokerException;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.net.UnknownHostException;
@ControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class GenericControllerAdvice {
private Logger logger = LogManager.getLogger(GenericControllerAdvice.class);
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(ResourceNotFoundException.class)
@ResponseBody
ServerError securityException(HttpServletRequest req, Exception ex) {
return new ServerError(req.getRequestURL().toString(),ex);
}
@ResponseStatus(HttpStatus.FORBIDDEN)
@ExceptionHandler(AccessDeniedException.class)
@ResponseBody
ServerError accessDeniedException(HttpServletRequest req, Exception ex) {
return new ServerError(req.getRequestURL().toString(),ex);
}
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(UnknownHostException.class)
@ResponseBody
ServerError unknownHostException(HttpServletRequest req, Exception ex) {
return new ServerError(req.getRequestURL().toString(),ex);
}
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler({JSONException.class,BrokerException.class,ValidatorServiceException.class})
@ResponseBody
ServerError internalException(HttpServletRequest req, Exception ex) {
return new ServerError(req.getRequestURL().toString(),ex);
}
@ResponseStatus(HttpStatus.GATEWAY_TIMEOUT)
@ExceptionHandler(EndPointException.class)
@ResponseBody
ServerError endPointException(HttpServletRequest req, Exception ex) {
return new ServerError(req.getRequestURL().toString(),ex);
}
}

View File

@ -0,0 +1,60 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.service.MonitorServiceImpl;
import eu.dnetlib.repo.manager.shared.JobsOfUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "/monitor")
@Api(description = "Monitor API", tags = {"monitor"})
public class MonitorController {
private static final Logger LOGGER = Logger
.getLogger(MonitorController.class);
@Autowired
MonitorServiceImpl monitorService;
@RequestMapping(value = "/getJobsOfUser" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public JobsOfUser getJobsOfUser(@RequestParam("user") @ApiParam(value = "User email", required = true) String user,
@RequestParam(value = "jobType", required = false)
@ApiParam(value = "Equals to filter job type on validation history page") String jobType,
@RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset,
@RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit,
@RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom,
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = false) String validationStatus,
@RequestParam("includeJobsTotal") @ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException {
return monitorService.getJobsOfUser(user, jobType, offset, limit, dateFrom, dateTo, validationStatus, includeJobsTotal);
}
@RequestMapping(value = "/getJobsOfUserPerValidationStatus" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public int getJobsOfUserPerValidationStatus(@RequestBody String user,
@RequestBody String jobType,
@RequestBody String validationStatus) throws JSONException {
return monitorService.getJobsOfUserPerValidationStatus(user, jobType, validationStatus);
}
@RequestMapping(value = "/getJobSummary" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public StoredJob getJobSummary(@RequestParam String jobId,
@RequestParam String groupBy) throws JSONException {
return monitorService.getJobSummary(jobId, groupBy);
}
}

View File

@ -0,0 +1,73 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.repo.manager.service.PiWikServiceImpl;
import eu.dnetlib.repo.manager.shared.RepositoryServiceException;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(value = "/piwik")
@Api(description = "Piwik API", tags = {"piwik"})
public class PiWikController {
@Autowired
PiWikServiceImpl piWikService;
@RequestMapping(value = "/getPiwikSiteForRepo/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public PiwikInfo getPiwikSiteForRepo(@PathVariable("repositoryId") String repositoryId) {
return piWikService.getPiwikSiteForRepo(repositoryId);
}
@RequestMapping(value = "/savePiwikInfo" , method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN') or (hasRole('ROLE_USER') " +
"and #piwikInfo.requestorEmail == authentication.userInfo.email)")
public PiwikInfo savePiwikInfo(@RequestBody PiwikInfo piwikInfo) {
return piWikService.savePiwikInfo(piwikInfo);
}
@RequestMapping(value = "/getPiwikSitesForRepos" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
List<PiwikInfo> getPiwikSitesForRepos(){
return piWikService.getPiwikSitesForRepos();
}
@RequestMapping(value = "/approvePiwikSite/{repositoryId}" , method = RequestMethod.GET)
@ResponseBody
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN')")
public ResponseEntity<Object> approvePiwikSite(@PathVariable("repositoryId") String repositoryId) {
return piWikService.approvePiwikSite(repositoryId);
}
@RequestMapping(value = "/getOpenaireId/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String getOpenaireId(String repositoryid){
return piWikService.getOpenaireId(repositoryid);
}
@RequestMapping(value = "/markPiwikSiteAsValidated/{repositoryId}" , method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN')")
public ResponseEntity<Object> markPiwikSiteAsValidated(@PathVariable("repositoryId") String repositoryId) throws RepositoryServiceException {
return piWikService.markPiwikSiteAsValidated(repositoryId);
}
@RequestMapping(value = "/enableMetricsForRepository", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN') or (hasRole('ROLE_USER') and #piwikInfo.requestorEmail == authentication.userInfo.email)")
public PiwikInfo enableMetricsForRepository(@RequestParam("officialName") String officialName,
@RequestParam("repoWebsite") String repoWebsite,
@RequestBody PiwikInfo piwikInfo) throws RepositoryServiceException {
return piWikService.enableMetricsForRepository(officialName, repoWebsite, piwikInfo);
}
}

View File

@ -0,0 +1,220 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface;
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.service.RepositoryServiceImpl;
import eu.dnetlib.repo.manager.shared.*;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import javax.ws.rs.Path;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value = "/repository")
@Api(description = "Repository API", tags = {"repository"})
public class RepositoryController {
@Autowired
RepositoryServiceImpl repositoryService;
@RequestMapping(value = "/getCountries", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Country[] getCountries() {
return repositoryService.getCountries();
}
@RequestMapping(value = "/getRepositoriesByCountry/{country}/{mode}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<RepositorySnippet> getRepositoriesByCountry(@PathVariable("country") String country,
@PathVariable("mode") String mode,
@RequestParam(value = "managed",required=false) Boolean managed) throws JSONException, IOException {
return repositoryService.getRepositoriesByCountry(country, mode, managed);
}
@RequestMapping(value = "/getRepositoriesOfUser/{userEmail}/{page}/{size}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public List<Repository> getRepositoriesOfUser(@PathVariable("userEmail") String userEmail,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
return repositoryService.getRepositoriesOfUser(userEmail, page, size);
}
@RequestMapping(value = "/searchRegisteredRepositories/{page}/{size}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN')")
public List<RepositorySnippet> searchRegisteredRepositories(@RequestParam(name="country", required=false) String country,
@RequestParam(name="typology", required=false) String typology,
@RequestParam(name="englishName", required=false) String englishName,
@RequestParam(name="officialName", required=false) String officialName,
@RequestParam("requestSortBy") String requestSortBy,
@RequestParam("order") String order,
@PathVariable("page") int page,
@PathVariable("size") int pageSize) throws Exception {
return repositoryService.searchRegisteredRepositories(country, typology, englishName, officialName, requestSortBy, order, page, pageSize);
}
@RequestMapping(value = "/getRepositoryById/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Repository getRepositoryById(@PathVariable("id") String id) throws JSONException,ResourceNotFoundException {
return repositoryService.getRepositoryById(id);
}
@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);
}
@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);
}
@RequestMapping(value = "/getRepositoriesByName/{name:.+}/{page}/{size}/", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<Repository> getRepositoriesByName(@PathVariable("name") String name,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
return repositoryService.getRepositoriesByName(name, page, size);
}
@RequestMapping(value = "/getRepositoryInterface/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<RepositoryInterface> getRepositoryInterface(@PathVariable("id") String id) throws JSONException {
return repositoryService.getRepositoryInterface(id);
}
@RequestMapping(value = "/addRepository", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
// @PreAuthorize("hasRole('ROLE_USER') and #repository.registeredBy == authentication.userInfo.email")
public Repository addRepository(@RequestParam("datatype") String datatype,
@RequestBody Repository repository) throws Exception {
return repositoryService.addRepository(datatype, repository);
}
@RequestMapping(value = "/getDnetCountries", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<String> getDnetCountries(){
return repositoryService.getDnetCountries();
}
@RequestMapping(value = "/getTypologies", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<String> getTypologies(){
return repositoryService.getTypologies();
}
@RequestMapping(value = "/getTimezones", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<Timezone> getTimezones(){
return repositoryService.getTimezones();
}
@RequestMapping(value = "/updateRepository", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
//@PreAuthorize("hasRole('ROLE_USER') and #repository.registeredBy == authentication.userInfo.email")
public Repository updateRepository(@RequestBody Repository repository,Authentication authentication) throws Exception {
return repositoryService.updateRepository(repository, authentication);
}
@RequestMapping(value = "/deleteInterface/", method = RequestMethod.DELETE)
@PreAuthorize("hasRole('ROLE_USER') and #registeredBy == authentication.userInfo.email")
public void deleteRepositoryInterface(@RequestParam("id") String id ,
@RequestParam("registeredBy") String registeredBy){
repositoryService.deleteRepositoryInterface(id, registeredBy);
}
@RequestMapping(value = "/addInterface", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER') and #registeredBy == authentication.userInfo.email")
public RepositoryInterface addRepositoryInterface(@RequestParam("datatype") String datatype,
@RequestParam("repoId") String repoId,
@RequestParam("registeredBy") String registeredBy,
@RequestBody RepositoryInterface repositoryInterface) throws JSONException,ResourceNotFoundException {
return repositoryService.addRepositoryInterface(datatype, repoId, registeredBy, repositoryInterface);
}
@RequestMapping(value = "/getUrlsOfUserRepos/{user_email}/{page}/{size}/",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public List<String> getUrlsOfUserRepos(@PathVariable("user_email") String userEmail,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
return repositoryService.getUrlsOfUserRepos(userEmail, page, size);
}
@RequestMapping(value = "/getDatasourceVocabularies/{mode}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<String> getDatasourceVocabularies(@PathVariable("mode") String mode) {
return repositoryService.getDatasourceVocabularies(mode);
}
@RequestMapping(value = "/getCompatibilityClasses/{mode}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, String> getCompatibilityClasses(@PathVariable("mode") String mode) {
return repositoryService.getCompatibilityClasses(mode);
}
@RequestMapping(value = "/getDatasourceClasses/{mode}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, String> getDatasourceClasses(@PathVariable("mode") String mode) {
return repositoryService.getDatasourceClasses(mode);
}
@RequestMapping(value = "/getMetricsInfoForRepository/{repoId}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public MetricsInfo getMetricsInfoForRepository(@PathVariable("repoId") String repoId) throws RepositoryServiceException {
return repositoryService.getMetricsInfoForRepository(repoId);
}
@RequestMapping(value = "/getListLatestUpdate/{mode}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, String> getListLatestUpdate(@PathVariable("mode") String mode) throws JSONException {
return repositoryService.getListLatestUpdate(mode);
}
@RequestMapping(value = "/updateRepositoryInterface", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER') and #registeredBy == authentication.userInfo.email")
public RepositoryInterface updateRepositoryInterface(@RequestParam("repoId") String repoId,
@RequestParam("registeredBy") String registeredBy,
@RequestBody RepositoryInterface repositoryInterface) throws Exception {
return repositoryService.updateRepositoryInterface(repoId, registeredBy, repositoryInterface);
}
}

View File

@ -0,0 +1,34 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.exception.EndPointException;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.client.ResponseErrorHandler;
import java.io.IOException;
import static org.springframework.http.HttpStatus.Series.CLIENT_ERROR;
import static org.springframework.http.HttpStatus.Series.SERVER_ERROR;
@Component
public class RestTemplateResponseErrorHandler implements ResponseErrorHandler {
@Override
public boolean hasError(ClientHttpResponse httpResponse) throws IOException {
return (httpResponse.getStatusCode().series() == CLIENT_ERROR
|| httpResponse.getStatusCode().series() == SERVER_ERROR);
}
@Override
public void handleError(ClientHttpResponse httpResponse) throws IOException {
if (httpResponse.getStatusCode().series() == HttpStatus.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

@ -0,0 +1,29 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.service.StatsServiceImpl;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
@RequestMapping(value = "/stats")
@Api(description = "Stats API", tags = {"statistics"})
public class StatsController {
@Autowired
StatsServiceImpl statsService;
@RequestMapping(value = "/getStatistics" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map getStatistics() throws JSONException {
return statsService.getStatistics();
}
}

View File

@ -0,0 +1,39 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.service.SushiliteServiceImpl;
import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "/sushilite")
@Api(description = "Sushi-Lite API", tags = {"sushilite"})
public class SushiliteController {
@Autowired
SushiliteServiceImpl sushiliteService;
@RequestMapping(value = "/getReportResults/{page}/{pageSize}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public ReportResponseWrapper getReportResults(@PathVariable("page") String page,
@PathVariable("pageSize") String pageSize,
@RequestParam(value = "Report") String Report,
@RequestParam(value = "Release",defaultValue="4") String Release,
@RequestParam(value = "RequestorID",required=false,defaultValue="anonymous") String RequestorID,
@RequestParam(value = "BeginDate",required=false,defaultValue="") String BeginDate,
@RequestParam(value = "EndDate",required=false,defaultValue="") String EndDate,
@RequestParam(value = "RepositoryIdentifier") String RepositoryIdentifier,
@RequestParam(value = "ItemIdentifier",required=false,defaultValue="") String ItemIdentifier,
@RequestParam(value = "ItemDataType",required=false,defaultValue="") String ItemDataType,
@RequestParam(value = "Granularity") String Granularity,
@RequestParam(value = "Pretty",required=false,defaultValue="") String Pretty) {
return sushiliteService.getReportResults(page, pageSize, Report, Release, RequestorID, BeginDate, EndDate, RepositoryIdentifier, ItemIdentifier, ItemDataType, Granularity, Pretty);
}
}

View File

@ -0,0 +1,25 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.repo.manager.service.UserServiceImpl;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/user")
@Api(description = "User API", tags = {"user"})
public class UserController {
@Autowired
UserServiceImpl userService;
@RequestMapping(value = "/login" , method = RequestMethod.GET)
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<Object> login() {
return userService.login();
}
}

View File

@ -0,0 +1,102 @@
package eu.dnetlib.repo.manager.controllers;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.service.ValidatorServiceImpl;
import eu.dnetlib.repo.manager.shared.InterfaceInformation;
import eu.dnetlib.repo.manager.shared.ValidationServiceException;
import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.domain.functionality.validator.RuleSet;
import java.util.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "/validator")
@Api(description = "Validator API", tags = {"validator"})
public class ValidatorController {
@Autowired
ValidatorServiceImpl validatorService;
@RequestMapping(value = "/submitJobForValidation",method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER') and #jobForValidation.userEmail == authentication.userInfo.email")
public JobForValidation submitJobForValidation(@RequestBody JobForValidation jobForValidation) throws ValidatorServiceException {
return validatorService.submitJobForValidation(jobForValidation);
}
@RequestMapping(value = "/reSubmitJobForValidation/{email}/{jobId}",method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER') and #email == authentication.userInfo.email")
public ResponseEntity<Object> reSubmitJobForValidation(@PathVariable("email") String email,
@PathVariable("jobId") String jobId) throws JSONException, ValidatorServiceException {
return validatorService.reSubmitJobForValidation(email, jobId);
}
@RequestMapping(value = "/getRuleSets/{mode}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<RuleSet> getRuleSets(@PathVariable("mode") String mode) {
return validatorService.getRuleSets(mode);
}
@RequestMapping(value = "/getSetsOfRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<String> getSetsOfRepository(@RequestParam(value = "url", required = true) String url) {
return validatorService.getSetsOfRepository(url);
}
@RequestMapping(value = "/identifyRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public boolean identifyRepo(@RequestParam(value = "url", required = true) String url) {
return validatorService.identifyRepo(url);
}
@RequestMapping(value = "/getRuleSet/{acronym}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public RuleSet getRuleSet(@PathVariable("acronym") String acronym) {
return validatorService.getRuleSet(acronym);
}
@RequestMapping(value = "/getStoredJobsNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public List<StoredJob> getStoredJobsNew(@RequestParam("user") @ApiParam(value = "User email", required = true) String user,
@RequestParam(value = "jobType", required = false)
@ApiParam(value = "Equals to filter job type on validation history page") String jobType,
@RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset,
@RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit,
@RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom,
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus
) throws ValidatorServiceException {
return validatorService.getStoredJobsNew(user, jobType, offset, limit, dateFrom, dateTo, validationStatus);
}
@RequestMapping(value = "/getStoredJobsTotalNumberNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public int getStoredJobsTotalNumberNew(String user, String jobType, String validationStatus) throws ValidatorServiceException {
return validatorService.getStoredJobsTotalNumberNew(user, jobType, validationStatus);
}
@RequestMapping(value = "/getInterfaceInformation" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public InterfaceInformation getInterfaceInformation(@RequestParam(value = "baseUrl", required = true) String baseUrl) throws ValidationServiceException {
return validatorService.getInterfaceInformation(baseUrl);
}
}

View File

@ -0,0 +1,51 @@
package eu.dnetlib.repo.manager.domain;
import java.io.Serializable;
public class Organization implements Serializable {
private String country;
private String legalname;
private String websiteurl;
private String legalshortname;
private String logourl;
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getLegalname() {
return legalname;
}
public void setLegalname(String legalname) {
this.legalname = legalname;
}
public String getWebsiteurl() {
return websiteurl;
}
public void setWebsiteurl(String websiteurl) {
this.websiteurl = websiteurl;
}
public String getLegalshortname() {
return legalshortname;
}
public void setLegalshortname(String legalshortname) {
this.legalshortname = legalshortname;
}
public String getLogourl() {
return logourl;
}
public void setLogourl(String logourl) {
this.logourl = logourl;
}
}

View File

@ -0,0 +1,81 @@
package eu.dnetlib.repo.manager.domain;
import com.google.gwt.user.client.rpc.IsSerializable;
public class RepositorySnippet implements IsSerializable {
private String id;
private String officialname;
private String englishname;
private String websiteurl;
private String typology;
private String registeredby;
private Organization[] organizations;
private String registrationdate;
public RepositorySnippet() {}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getOfficialname() {
return officialname;
}
public void setOfficialname(String officialname) {
this.officialname = officialname;
}
public String getEnglishname() {
return englishname;
}
public void setEnglishname(String englishname) {
this.englishname = englishname;
}
public String getWebsiteurl() {
return websiteurl;
}
public void setWebsiteurl(String websiteurl) {
this.websiteurl = websiteurl;
}
public String getRegisteredby() {
return registeredby;
}
public void setRegisteredby(String registeredby) {
this.registeredby = registeredby;
}
public String getTypology() {
return typology;
}
public void setTypology(String typology) {
this.typology = typology;
}
public Organization[] getOrganizations() {
return organizations;
}
public void setOrganizations(Organization[] organizations) {
this.organizations = organizations;
}
public String getRegistrationdate() {
return registrationdate;
}
public void setRegistrationdate(String registrationdate) {
this.registrationdate = registrationdate;
}
}

View File

@ -0,0 +1,84 @@
package eu.dnetlib.repo.manager.domain;
import com.google.gwt.user.client.rpc.IsSerializable;
import java.util.Date;
public class RepositorySummaryInfo implements IsSerializable {
String id;
String repositoryName;
String logoURL;
int recordsCollected;
Date lastIndexedVersion;
long enrichmentEvents;
String totalViews;
String totalDownloads;
public RepositorySummaryInfo() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getRepositoryName() {
return repositoryName;
}
public void setRepositoryName(String repositoryName) {
this.repositoryName = repositoryName;
}
public String getLogoURL() {
return logoURL;
}
public void setLogoURL(String logoURL) {
this.logoURL = logoURL;
}
public int getRecordsCollected() {
return recordsCollected;
}
public void setRecordsCollected(int recordsCollected) {
this.recordsCollected = recordsCollected;
}
public Date getLastIndexedVersion() {
return lastIndexedVersion;
}
public void setLastIndexedVersion(Date lastIndexedVersion) {
this.lastIndexedVersion = lastIndexedVersion;
}
public long getEnrichmentEvents() {
return enrichmentEvents;
}
public void setEnrichmentEvents(long enrichmentEvents) {
this.enrichmentEvents = enrichmentEvents;
}
public String getTotalViews() {
return totalViews;
}
public void setTotalViews(String totalViews) {
this.totalViews = totalViews;
}
public String getTotalDownloads() {
return totalDownloads;
}
public void setTotalDownloads(String totalDownloads) {
this.totalDownloads = totalDownloads;
}
}

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.utils;
package eu.dnetlib.repo.manager.domain;
import com.fasterxml.jackson.annotation.JsonInclude;
@ -10,6 +10,10 @@ public class RequestFilter{
private String country = null;
private String id = null;
private String officialname = null;
private String englishname = null;
private String collectedfrom = null;
public RequestFilter() {
@ -55,4 +59,20 @@ public class RequestFilter{
public void setOfficialname(String officialname) {
this.officialname = officialname;
}
public String getCollectedfrom() {
return collectedfrom;
}
public void setCollectedfrom(String collectedfrom) {
this.collectedfrom = collectedfrom;
}
public String getEnglishname() {
return englishname;
}
public void setEnglishname(String englishname) {
this.englishname = englishname;
}
}

View File

@ -0,0 +1,19 @@
package eu.dnetlib.repo.manager.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
import java.io.IOException;
//@ResponseStatus(HttpStatus.GATEWAY_TIMEOUT)
public class EndPointException extends IOException {
public EndPointException() {
super("Endpoint not responding!");
}
public EndPointException(String url) {
super("Endpoint with url: " + url + " not responding!");
}
}

View File

@ -0,0 +1,15 @@
package eu.dnetlib.repo.manager.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(HttpStatus.NOT_FOUND)
public class ResourceNotFoundException extends Exception {
public ResourceNotFoundException() {
super("Resource Not Found");
}
public ResourceNotFoundException(String id, String resourceType) {
super(resourceType + " with id " + id + " was not found");
}
}

View File

@ -0,0 +1,21 @@
package eu.dnetlib.repo.manager.exception;
public class ServerError {
public final String url;
public final String error;
public ServerError(String url, Exception ex) {
this.url = url;
this.error = ex.getMessage();
}
public String getUrl() {
return this.url;
}
public String getError() {
return this.error;
}
}

View File

@ -0,0 +1,48 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.repo.manager.shared.BrokerException;
import eu.dnetlib.repo.manager.shared.Term;
import eu.dnetlib.repo.manager.shared.broker.*;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public interface BrokerService {
DatasourcesBroker getDatasourcesOfUser(String user, String includeShared, String includeByOthers) throws BrokerException, JSONException;
List<BrowseEntry> getTopicsForDatasource(String datasourceName) throws BrokerException;
EventsPage advancedShowEvents(String page,
String size,
AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException;
EventsPage showEvents(String datasourceName,
String topic,
String page,
String size) throws BrokerException, JSONException;
Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(String userEmail) throws BrokerException;
Subscription subscribe(OpenaireSubscription obj) throws BrokerException;
ResponseEntity<Object> unsubscribe(String subscriptionId) throws BrokerException;
Subscription getSubscription(String subscriptionId) throws BrokerException;
Map<String, Term> getDnetTopics() throws BrokerException;
EventsPage getNotificationsBySubscriptionId(String subscriptionId, String page, String size) throws BrokerException;
Map<String, List<Subscription>> getSubscriptionsOfUser(String userEmail) throws BrokerException;
}

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.controllers;
package eu.dnetlib.repo.manager.service;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -7,23 +7,15 @@ import eu.dnetlib.repo.manager.shared.BrokerException;
import eu.dnetlib.repo.manager.shared.Term;
import eu.dnetlib.repo.manager.shared.Tuple;
import eu.dnetlib.repo.manager.shared.broker.*;
import io.swagger.annotations.ApiParam;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.*;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
@ -35,11 +27,11 @@ import java.io.InputStream;
import java.net.URL;
import java.util.*;
@Component
public class BrokerApiImpl implements BrokerApi {
@Service("brokerService")
public class BrokerServiceImpl implements BrokerService {
@Autowired
private RepositoryApiImpl repoAPI;
private RepositoryServiceImpl repoAPI;
@Value("${services.broker.url}:${services.broker.port}/${services.broker.api}${services.broker.openaire}")
private String openairePath;
@Value("${services.broker.url}:${services.broker.port}/${services.broker.api}")
@ -48,20 +40,21 @@ public class BrokerApiImpl implements BrokerApi {
private String topicsURL;
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
.getLogger(BrokerApiImpl.class);
.getLogger(BrokerServiceImpl.class);
private RestTemplate restTemplate = null;
@Autowired
RestTemplate restTemplate ;
private HttpHeaders httpHeaders;
private HashMap<String,Term> topics = new HashMap<String, Term>();
@Autowired
private EmailUtils emailUtils;
@PostConstruct
private void initDnetTopicsMap() {
restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type", "application/json");
@ -74,8 +67,8 @@ public class BrokerApiImpl implements BrokerApi {
for (JsonNode term : root.path("terms") )
topics.put(term.path("code").textValue(), parseTerm(term));
} catch (IOException e) {
LOGGER.debug(e);
e.printStackTrace();
LOGGER.debug("Exception on initDnetTopicsMap" , e);
emailUtils.reportException(e);
}
}
@ -86,12 +79,7 @@ public class BrokerApiImpl implements BrokerApi {
@Override
public DatasourcesBroker getDatasourcesOfUser(@RequestParam("user")
@ApiParam(value = "User email", required = true) String user,
@RequestParam("includeShared")
@ApiParam(value = "Include shared datasources", required = true , defaultValue = "false") String includeShared,
@RequestParam("includeByOthers")
@ApiParam(value = "Include datasources of other", required = true,defaultValue = "false") String includeByOthers) throws JSONException {
public DatasourcesBroker getDatasourcesOfUser(String user,String includeShared,String includeByOthers) throws JSONException {
DatasourcesBroker ret = new DatasourcesBroker();
try {
@ -106,14 +94,15 @@ public class BrokerApiImpl implements BrokerApi {
ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(user)));
}
} catch (BrokerException e) {
e.printStackTrace();
LOGGER.debug("Exception on getDatasourcesOfUser" , e);
emailUtils.reportException(e);
}
return ret;
}
@Override
public List<BrowseEntry> getTopicsForDatasource(@PathVariable("datasourceName") String datasourceName) throws BrokerException {
public List<BrowseEntry> getTopicsForDatasource(String datasourceName) throws BrokerException {
final String service = "/topicsForDatasource";
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
@ -128,6 +117,8 @@ public class BrokerApiImpl implements BrokerApi {
new ParameterizedTypeReference<List<BrowseEntry>>() {
});
} catch (RestClientException e) {
LOGGER.debug("Exception on getTopicsForDatasource" , e);
emailUtils.reportException(e);
throw new BrokerException(e);
}
@ -135,9 +126,9 @@ public class BrokerApiImpl implements BrokerApi {
}
@Override
public EventsPage advancedShowEvents(@PathVariable("page") String page,
@PathVariable("size") String size,
@RequestBody AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException {
public EventsPage advancedShowEvents(String page,
String size,
AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException {
final String service = "/events/{page}/{pageSize}";
@ -160,6 +151,8 @@ public class BrokerApiImpl implements BrokerApi {
}
);
} catch (RestClientException e) {
LOGGER.debug("Exception on advancedShowEvents" , e);
emailUtils.reportException(e);
throw new BrokerException(e);
}
return resp.getBody();
@ -193,8 +186,6 @@ public class BrokerApiImpl implements BrokerApi {
return entries;
}
private List<Repository> getRepositoriesOfUser(String userEmail) throws JSONException {
int page = 0;
@ -216,10 +207,10 @@ public class BrokerApiImpl implements BrokerApi {
}
@Override
public EventsPage showEvents(@RequestParam("datasourceName") String datasourceName,
@RequestParam("topic") String topic,
@RequestParam("page") String page,
@RequestParam("size") String size) throws BrokerException, JSONException {
public EventsPage showEvents(String datasourceName,
String topic,
String page,
String size) throws BrokerException, JSONException {
final String service = "/events";
@ -237,13 +228,15 @@ public class BrokerApiImpl implements BrokerApi {
new ParameterizedTypeReference<EventsPage>() {
});
} catch (RestClientException e) {
LOGGER.debug("Exception on showEvents" , e);
emailUtils.reportException(e);
throw new BrokerException(e);
}
return resp.getBody();
}
@Override
public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(@PathVariable("userEmail") String userEmail)
public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(String userEmail)
throws BrokerException {
final String service = "/subscriptions";
@ -261,14 +254,15 @@ public class BrokerApiImpl implements BrokerApi {
new ParameterizedTypeReference<Map<String, List<SimpleSubscriptionDesc>>>() {
});
} catch (RestClientException e) {
LOGGER.debug("Error " , e);
LOGGER.debug("Exception on getSimpleSubscriptionsOfUser" , e);
emailUtils.reportException(e);
throw new BrokerException(e);
}
return resp.getBody();
}
@Override
public Subscription subscribe(@RequestBody OpenaireSubscription obj) throws BrokerException {
public Subscription subscribe(OpenaireSubscription obj) throws BrokerException {
final String service = "/subscribe";
//build the uri params
@ -289,6 +283,8 @@ public class BrokerApiImpl implements BrokerApi {
new ParameterizedTypeReference<Subscription>() {
});
} catch (RestClientException e) {
LOGGER.debug("Exception on OpenaireSubscription" , e);
emailUtils.reportException(e);
throw new BrokerException(e);
}
@ -296,7 +292,7 @@ public class BrokerApiImpl implements BrokerApi {
}
@Override
public void unsubscribe(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException {
public ResponseEntity<Object> unsubscribe(String subscriptionId) throws BrokerException {
final String service = "/subscriptions/" + subscriptionId;
//build the uri params
@ -311,12 +307,15 @@ public class BrokerApiImpl implements BrokerApi {
new ParameterizedTypeReference<Void>() {
});
} catch (RestClientException e) {
LOGGER.debug("Exception on unsubscribe" , e);
emailUtils.reportException(e);
throw new BrokerException(e);
}
return new ResponseEntity<>("OK",HttpStatus.OK);
}
@Override
public Subscription getSubscription(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException {
public Subscription getSubscription( String subscriptionId) throws BrokerException {
final String service = "/subscriptions/" + subscriptionId;
//build the uri params
@ -332,6 +331,8 @@ public class BrokerApiImpl implements BrokerApi {
new ParameterizedTypeReference<Subscription>() {
});
} catch (RestClientException e) {
LOGGER.debug("Exception on getSubscription" , e);
emailUtils.reportException(e);
throw new BrokerException(e);
}
return resp.getBody();
@ -343,10 +344,9 @@ public class BrokerApiImpl implements BrokerApi {
}
@Override
public EventsPage getNotificationsBySubscriptionId(@PathVariable("subscriptionId") String subscriptionId,
@PathVariable("page") String page,
@PathVariable("size") String size
) throws BrokerException {
public EventsPage getNotificationsBySubscriptionId(String subscriptionId,
String page,
String size) throws BrokerException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(openairePath + "/notifications/")
@ -362,13 +362,15 @@ public class BrokerApiImpl implements BrokerApi {
new ParameterizedTypeReference<EventsPage>() {
});
} catch (RestClientException e) {
LOGGER.debug("Exception on getNotificationsBySubscriptionId" , e);
emailUtils.reportException(e);
throw new BrokerException(e);
}
return resp.getBody();
}
@Override
public Map<String, List<Subscription>> getSubscriptionsOfUser(@PathVariable("userEmail") String userEmail)
//@Override
public Map<String, List<Subscription>> getSubscriptionsOfUser(String userEmail)
throws BrokerException {
Map<String, List<SimpleSubscriptionDesc>> simpleSubs = getSimpleSubscriptionsOfUser(userEmail);

View File

@ -0,0 +1,14 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
import org.json.JSONException;
import org.springframework.web.bind.annotation.PathVariable;
import java.util.List;
public interface DashboardService {
List<RepositorySummaryInfo> getRepositoriesSummaryInfo(@PathVariable("userEmail") String userEmail,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException;
}

View File

@ -0,0 +1,94 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
import eu.dnetlib.repo.manager.shared.AggregationDetails;
import eu.dnetlib.repo.manager.shared.BrokerException;
import eu.dnetlib.repo.manager.shared.MetricsInfo;
import eu.dnetlib.repo.manager.shared.RepositoryServiceException;
import eu.dnetlib.repo.manager.shared.broker.BrowseEntry;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import javax.xml.ws.ServiceMode;
import java.util.ArrayList;
import java.util.List;
@Service("dashboardService")
public class DashboardServiceImpl implements DashboardService {
private static final Logger logger = Logger.getLogger(DashboardServiceImpl.class);
@Autowired
private EmailUtils emailUtils;
@Autowired
private RepositoryService repositoryService;
@Autowired
private BrokerService brokerService;
@Override
public List<RepositorySummaryInfo> getRepositoriesSummaryInfo(@PathVariable("userEmail") String userEmail,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
List<RepositorySummaryInfo> repositorySummaryInfoList = new ArrayList<>();
try {
List<Repository> repositoriesOfUser = repositoryService.getRepositoriesOfUser(userEmail, page, size);
for(Repository repository: repositoriesOfUser) {
RepositorySummaryInfo repositorySummaryInfo = new RepositorySummaryInfo();
repositorySummaryInfo.setId(repository.getId());
repositorySummaryInfo.setRepositoryName(repository.getOfficialName());
repositorySummaryInfo.setLogoURL(repository.getLogoUrl());
//TODO getRepositoryAggregations returns only the 20 more recent items. Is it positive that we will find an indexed version there?
List<AggregationDetails> aggregationDetailsList = repositoryService.getRepositoryAggregations(repository.getId());
for(AggregationDetails aggregationDetails: aggregationDetailsList) {
if(aggregationDetails.getIndexedVersion()) {
repositorySummaryInfo.setRecordsCollected(aggregationDetails.getNumberOfRecords());
repositorySummaryInfo.setLastIndexedVersion(aggregationDetails.getDate());
break;
}
}
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);
e.printStackTrace();
}
return repositorySummaryInfoList;
}
}

View File

@ -0,0 +1,30 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.functionality.validator.JobForValidation;
import org.springframework.security.core.Authentication;
public interface EmailUtils {
void reportException(Exception exception);
void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception;
void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception;
void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) throws Exception;
void sendUserMetricsEnabled(PiwikInfo piwikInfo) throws Exception;
void sendAdminRegistrationEmail(Repository repository, Authentication authentication) throws Exception;
void sendUserRegistrationEmail(Repository repository, Authentication authentication) throws Exception;
void sendAdminUpdateRepositoryEmail(Repository repository, Authentication authentication) throws Exception;
void sendUserUpdateRepositoryEmail(Repository repository, Authentication authentication) throws Exception;
void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation) throws Exception;
}

View File

@ -1,13 +1,18 @@
package eu.dnetlib.repo.manager.service.utils;
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.repo.manager.config.CascadingPropertyLoader;
import eu.dnetlib.utils.MailLibrary;
import org.apache.log4j.Logger;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
@ -15,7 +20,7 @@ import java.util.ArrayList;
import java.util.List;
@Component
@Component("emailUtils")
public class EmailUtilsImpl implements EmailUtils {
private static Logger LOGGER = Logger.getLogger(EmailUtilsImpl.class);
@ -39,6 +44,15 @@ public class EmailUtilsImpl implements EmailUtils {
@Value("${services.repomanager.usagestats.adminEmail}")
private String usageStatsAdminEmail;
@Value("${services.provide.adminEmail}")
private String provideAdminEmail;
@PostConstruct
public void init(){
System.out.println("url -> " + this.baseUrl);
}
@Override
public void reportException(Exception exception) {
@ -74,7 +88,7 @@ public class EmailUtilsImpl implements EmailUtils {
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
"\n" +
"For more information about this request, go here: \n" +
this.baseUrl + "/#admin/metrics\n" +
this.baseUrl + "/admin/metrics\n" +
"\n" +
"Best,\n" +
"The OpenAIRE team";
@ -108,7 +122,7 @@ public class EmailUtilsImpl implements EmailUtils {
"the OpenAIRE team in repositoryusagestats@openaire.eu in order to find a solution.\n" +
"\n" +
"For more information about your request and configuration details, go here: \n" +
this.baseUrl + "/#getImpact/instructions/" + piwikInfo.getRepositoryId() + "\n" +
this.baseUrl + "/getImpact/instructions/" + piwikInfo.getRepositoryId() + "\n" +
"\n" +
"Once you have finished configuring your repository or if you have any questions, please notify the OpenAIRE team by sending \n" +
"an email to repositoryusagestats@openaire.eu\n" +
@ -143,7 +157,7 @@ public class EmailUtilsImpl implements EmailUtils {
"Best,\n" +
"The OpenAIRE team";
this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null);
this.sendMail(this.usageStatsAdminEmail, subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending metrics enabled notification email to administator: " + this.usageStatsAdminEmail, e);
@ -163,7 +177,7 @@ public class EmailUtilsImpl implements EmailUtils {
"\" has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" +
"\n" +
"You can preview the statistics in your repository's dashboard: \n" +
this.baseUrl + "/#getImpact/" + piwikInfo.getRepositoryId() + "\n" +
this.baseUrl + "/getImpact/" + piwikInfo.getRepositoryId() + "\n" +
"\n" +
" For more information and questions, you can contact the openaire support team by sending an email to " +
"repositoryusagestats@openaire.eu\n" +
@ -179,6 +193,128 @@ public class EmailUtilsImpl implements EmailUtils {
}
}
@Override
public void sendAdminRegistrationEmail(Repository repository, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE content provider registration request started for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
String message = "Dear administrator" + ",\n" +
"\n" +
"We received a request to register the " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "]" +
" to the OpenAIRE compliant list of content providers. " +
"A validation process against the OpenAIRE guidelines compatibility " +
"has been started. You will be informed in another message once the process is finished." +
"\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.\n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
this.sendMail(this.provideAdminEmail, subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to the administrator", e);
throw e;
}
}
@Override
public void sendUserRegistrationEmail(Repository repository, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE content provider registration request started for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
"\n" +
"We received a request to register the " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "]" +
" to the OpenAIRE compliant list of content providers. " +
"A validation process against the OpenAIRE guidelines compatibility " +
"has been started. You will be informed in another message once the process is finished." +
"\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'. \n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
this.sendMail(repository.getRegisteredBy(), subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
throw e;
}
}
@Override
public void sendAdminUpdateRepositoryEmail(Repository repository, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE content provider update request started for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
String message = "Dear administrator" + ",\n" +
"\n" +
"We received a request to update the " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "]." +
"A new iteration process of the validation against the OpenAIRE guidelines compatibility has been started.\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.\n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
this.sendMail(this.provideAdminEmail, subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to the administrator", e);
throw e;
}
}
@Override
public void sendUserUpdateRepositoryEmail(Repository repository, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE content provider update request started for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
"\n" +
"We received a request to update the " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "]." +
"A new iteration process of the validation against the OpenAIRE guidelines compatibility has been started.\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'. \n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
this.sendMail(repository.getRegisteredBy(), subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
throw e;
}
}
@Override
public void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation) throws Exception {
try {
String subject = "OpenAIRE validator - Test submission ";
String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
"\n" +
"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'. \n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
this.sendMail(jobForValidation.getUserEmail(), subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending validation submission notification email to user: " + jobForValidation.getUserEmail(), e);
throw e;
}
}
private void sendMail(String email, String subject, String message, boolean sendToSpecial, List<String> repoAdminMails) throws Exception {
ArrayList<String> to = new ArrayList<String>();
to.add(email);
@ -187,7 +323,7 @@ public class EmailUtilsImpl implements EmailUtils {
private void sendMail(List<String> recipients, String subject, String message, boolean sendToSpecial, List<String> repoAdminMails) throws Exception {
/* try {
try {
if (sendToSpecial) {
recipients.addAll(this.specialRecipients);
}
@ -205,7 +341,7 @@ public class EmailUtilsImpl implements EmailUtils {
} catch (Exception e) {
LOGGER.error("Error sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message, e);
throw new Exception(e);
}*/
}
}
private String getEmailProperty(String key) {

View File

@ -0,0 +1,32 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.shared.JobsOfUser;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
public interface MonitorService {
JobsOfUser getJobsOfUser(String user,
String jobType,
String offset,
String limit,
String dateFrom,
String dateTo,
String validationStatus,
String includeJobsTotal) throws JSONException, ValidatorServiceException;
int getJobsOfUserPerValidationStatus(String user,
String jobType,
String validationStatus) throws JSONException;
StoredJob getJobSummary(String jobId,
String groupBy) throws JSONException;
}

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.controllers;
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.api.functionality.ValidatorService;
import eu.dnetlib.api.functionality.ValidatorServiceException;
@ -6,16 +6,14 @@ import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.shared.Constants;
import eu.dnetlib.repo.manager.shared.JobsOfUser;
import gr.uoa.di.driver.util.ServiceLocator;
import io.swagger.annotations.ApiParam;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Component
public class MonitorApiImpl implements MonitorApi {
@Service("monitorService")
public class MonitorServiceImpl implements MonitorService {
@Resource(name = "validatorServiceLocator")
private ServiceLocator<ValidatorService> validatorServiceLocator;
@ -34,24 +32,21 @@ public class MonitorApiImpl implements MonitorApi {
private static final Logger LOGGER = Logger
.getLogger(MonitorApiImpl.class);
.getLogger(MonitorServiceImpl.class);
@Override
public JobsOfUser getJobsOfUser(@RequestParam("user") @ApiParam(value = "User email", required = true) String user,
@RequestParam(value = "jobType", required = false)
@ApiParam(value = "Equals to filter job type on validation history page") String jobType,
@RequestParam("offset") @ApiParam(value = "Page number", required = true) String offset,
@RequestParam(value = "limit", required = false,defaultValue = "10") @ApiParam(value = "Null value") String limit,
@RequestParam(value = "dateFrom", required = false) @ApiParam(value = "Null value") String dateFrom,
@RequestParam(value = "dateTo", required = false) @ApiParam(value = "Null value") String dateTo,
@RequestParam("validationStatus") @ApiParam(value = "Equals to filter validation jobs", required = true) String validationStatus,
@RequestParam("includeJobsTotal") @ApiParam(value = "Always true", required = true) String includeJobsTotal) throws JSONException, ValidatorServiceException {
public JobsOfUser getJobsOfUser(String user,
String jobType,
String offset,
String limit,
String dateFrom,
String dateTo,
String validationStatus,
String includeJobsTotal) throws JSONException, ValidatorServiceException {
LOGGER.debug("Getting jobs of user : " + user);
LOGGER.debug(user + "/" + jobType + "/" + offset + "/" + dateFrom + "/" + dateTo + "/" + validationStatus + "/" + includeJobsTotal);
JobsOfUser retJobs = new JobsOfUser();
LOGGER.debug("Size fo jobs list -> " + getValidationService().getStoredJobsNew(user, jobType, Integer.parseInt(offset),
Integer.parseInt(limit), dateFrom, dateTo, validationStatus));
retJobs.setJobs(getValidationService().getStoredJobsNew(user, jobType, Integer.parseInt(offset),
Integer.parseInt(limit), dateFrom, dateTo, validationStatus));
if (Boolean.parseBoolean(includeJobsTotal)) {
@ -60,6 +55,26 @@ public class MonitorApiImpl implements MonitorApi {
retJobs.setTotalJobsFailed(this.getJobsTotalNumberOfUser(user, jobType, Constants.VALIDATION_JOB_STATUS_FAILED));
retJobs.setTotalJobsOngoing(this.getJobsTotalNumberOfUser(user, jobType,Constants.VALIDATION_JOB_STATUS_ONGOING));
}
//TODO fix status with new validator version
if(retJobs.getJobs() != null){
for(StoredJob job :retJobs.getJobs()){
if (job.getContentJobStatus().equals("ongoing") || job.getUsageJobStatus().equals("ongoing")) {
job.setValidationStatus("ongoing");
} else if ((job.getValidationType().equals("CU") && job.getContentJobStatus().equals("finished") && job.getUsageJobStatus().equals("finished") && job.getContentJobScore() > 50 && job.getUsageJobScore() > 50)
|| (job.getValidationType().equals("C") && job.getContentJobStatus().equals("finished") && job.getUsageJobStatus().equals("none") && job.getContentJobScore() > 50)
|| (job.getValidationType().equals("U") && job.getContentJobStatus().equals("none") && job.getUsageJobStatus().equals("finished") && job.getUsageJobScore() > 50)) {
job.setValidationStatus("successful");
} else if ((job.getValidationType().equals("CU") && job.getContentJobStatus().equals("finished") && job.getUsageJobStatus().equals("finished") && (job.getContentJobScore() <= 50 || job.getUsageJobScore() <= 50))
|| (job.getValidationType().equals("C") && job.getContentJobStatus().equals("finished") && job.getUsageJobStatus().equals("none") && job.getContentJobScore() <= 50)
|| (job.getValidationType().equals("U") && job.getContentJobStatus().equals("none") && job.getUsageJobStatus().equals("finished") && job.getUsageJobScore() <= 50) ) {
job.setValidationStatus("failed");
}
}
}
return retJobs;
}

View File

@ -0,0 +1,26 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.repo.manager.shared.RepositoryServiceException;
import org.springframework.http.ResponseEntity;
import java.util.List;
public interface PiWikService {
PiwikInfo getPiwikSiteForRepo(String repositoryId);
PiwikInfo savePiwikInfo(PiwikInfo piwikInfo);
List<PiwikInfo> getPiwikSitesForRepos();
ResponseEntity<Object> approvePiwikSite(String repositoryId);
String getOpenaireId(String repositoryid);
ResponseEntity<Object> markPiwikSiteAsValidated(String repositoryId) throws RepositoryServiceException;
PiwikInfo enableMetricsForRepository(String officialName, String repoWebsite, PiwikInfo piwikInfo) throws RepositoryServiceException;
}

View File

@ -0,0 +1,164 @@
package eu.dnetlib.repo.manager.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.repo.manager.shared.RepositoryServiceException;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import javax.sql.DataSource;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;
import java.sql.Types;
import java.util.List;
import java.util.Map;
@Service("piwikService")
public class PiWikServiceImpl implements PiWikService {
@Qualifier("repomanager.dataSource")
@Autowired
private DataSource dataSource;
@Value("${services.repomanager.analyticsURL}")
private String analyticsURL;
@Autowired
@Qualifier("emailUtils")
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 final static 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 order by repositoryname";
private final static String APPROVE_PIWIK_SITE = "update piwik_site set validated=true, validationdate=now() where repositoryid = ?;";
private 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"));
@Override
public PiwikInfo getPiwikSiteForRepo(@PathVariable("repositoryId") String repositoryId) {
try{
return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITE, new String[]{repositoryId}, new int[]{Types.VARCHAR}, piwikRowMapper);
}catch (EmptyResultDataAccessException e){
return null;
}
}
@Override
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN') or (hasRole('ROLE_USER') and #piwikInfo.requestorEmail == authentication.userInfo.email)")
public PiwikInfo savePiwikInfo(@RequestBody 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});
return piwikInfo;
}
@Override
public List<PiwikInfo> getPiwikSitesForRepos() {
LOGGER.debug("Getting piwik sites for repos! ");
try{
return new JdbcTemplate(dataSource).query(GET_PIWIK_SITES, piwikRowMapper);
}catch (EmptyResultDataAccessException e){
return null;
}
}
@Override
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN')")
public ResponseEntity<Object> approvePiwikSite(@PathVariable("repositoryId") String repositoryId) {
new JdbcTemplate(dataSource).update(APPROVE_PIWIK_SITE, new Object[] {repositoryId}, new int[] {Types.VARCHAR});
return new ResponseEntity<>("OK",HttpStatus.OK);
}
@Override
public String getOpenaireId(@PathVariable("repositoryId") String repositoryId) {
if (repositoryId != null && repositoryId.contains("::"))
return repositoryId.split("::")[0] + "::" + DigestUtils.md5Hex(repositoryId.split("::")[1]);
return null;
}
@Override
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN')")
public ResponseEntity<Object> markPiwikSiteAsValidated(@PathVariable("repositoryId") String repositoryId) throws RepositoryServiceException {
try {
approvePiwikSite(repositoryId);
PiwikInfo piwikInfo = getPiwikSiteForRepo(repositoryId);
emailUtils.sendAdministratorMetricsEnabled(piwikInfo);
emailUtils.sendUserMetricsEnabled(piwikInfo);
} catch (EmptyResultDataAccessException e) {
LOGGER.error("Error while approving piwik site: ", e);
emailUtils.reportException(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);
emailUtils.reportException(e);
}
return new ResponseEntity<>("OK",HttpStatus.OK);
}
@Override
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN') or (hasRole('ROLE_USER') and #piwikInfo.requestorEmail == authentication.userInfo.email)")
public PiwikInfo enableMetricsForRepository(@RequestParam("officialName") String officialName,
@RequestParam("repoWebsite") String repoWebsite,
@RequestBody PiwikInfo piwikInfo) throws RepositoryServiceException {
try {
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);
String siteId = null;
if(map.get("value")!=null) {
siteId = map.get("value").toString();
}
piwikInfo.setSiteId(siteId);
savePiwikInfo(piwikInfo);
emailUtils.sendAdministratorRequestToEnableMetrics(piwikInfo);
emailUtils.sendUserRequestToEnableMetrics(piwikInfo);
} catch (UnsupportedEncodingException uee) {
LOGGER.error("Error while creating piwikScript URL", uee);
emailUtils.reportException(uee);
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
} catch (IOException ioe) {
LOGGER.error("Error while creating piwik site", ioe);
emailUtils.reportException(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);
emailUtils.reportException(e);
}
return piwikInfo;
}
}

View File

@ -0,0 +1,76 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface;
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.shared.*;
import org.json.JSONException;
import org.springframework.security.core.Authentication;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public interface RepositoryService {
Country[] getCountries() ;
List<RepositorySnippet> getRepositoriesByCountry(String country, String mode, Boolean managed) throws JSONException, IOException;
List<Repository> getRepositoriesOfUser(String userEmail,
String page,
String size) throws JSONException;
Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException;
List<AggregationDetails> getRepositoryAggregations(String id) throws JSONException;
Map<String,List<AggregationDetails>> getRepositoryAggregationsByYear(String id) throws JSONException;
List<Repository> getRepositoriesByName(String name,
String page,
String size) throws JSONException;
List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
String officialName, String requestSortBy, String order,
int page, int pageSize) throws Exception;
List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException;
Repository addRepository(String datatype, Repository repository) throws Exception;
void deleteRepositoryInterface(String id, String registeredBy);
RepositoryInterface addRepositoryInterface(String datatype,
String repoId,
String registeredBy,
RepositoryInterface iFace) throws JSONException,ResourceNotFoundException;
List<String> getDnetCountries();
List<String> getTypologies();
List<Timezone> getTimezones();
Repository updateRepository(Repository repository, Authentication authentication) throws Exception;
List<String> getUrlsOfUserRepos(String user_email,
String page,
String size) throws JSONException;
List<String> getDatasourceVocabularies(String mode);
Map<String, String> getCompatibilityClasses(String mode);
Map<String, String> getDatasourceClasses(String mode);
String getCountryName(String countryCode);
MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException;
Map<String, String> getListLatestUpdate(String mode) throws RepositoryServiceException, JSONException;
RepositoryInterface updateRepositoryInterface(String repositoryId, String registeredBy, RepositoryInterface repositoryInterface) throws Exception;
}

View File

@ -0,0 +1,925 @@
package eu.dnetlib.repo.manager.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface;
import eu.dnetlib.domain.enabling.Vocabulary;
import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
import eu.dnetlib.repo.manager.domain.RequestFilter;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.shared.*;
import eu.dnetlib.repo.manager.utils.Converter;
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
import gr.uoa.di.driver.xml.repository.INTERFACE;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
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 javax.annotation.PostConstruct;
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 {
@Value("${api.baseAddress}")
private String baseAddress;
@Value("${services.repo-manager.adminEmail}")
private String adminEmail;
@Autowired
RestTemplate restTemplate;
private HttpHeaders httpHeaders;
private final String[] vocabularyNames = {"dnet:countries", "dnet:datasource_typologies", "dnet:compatibilityLevel"};
private static final Logger LOGGER = Logger.getLogger(RepositoryServiceImpl.class);
@Value("${services.repomanager.usageStatisticsDiagramsBaseURL}")
private String usageStatisticsDiagramsBaseURL;
@Value("${services.repomanager.usageStatisticsNumbersBaseURL}")
private String usageStatisticsNumbersBaseURL;
@Autowired
private VocabularyLoader vocabularyLoader;
@Autowired
private PiWikService piWikService;
@Autowired
private EmailUtils emailUtils;
@Autowired
ValidatorService validatorService;
private Map<String, Vocabulary> vocabularyMap = new ConcurrentHashMap<String, Vocabulary>();
private Map<String, String> countriesMap = new HashMap<>();
private Map<String, String> inverseCountriesMap = new HashMap<>();
private static Map<String,List<String>> dataSourceClass = new HashMap<String,List<String>>(){{
put("opendoar",new ArrayList<String>(){{ add("pubsrepository::institutional");
add("pubsrepository::thematic");
add("pubsrepository::unknown");
add("pubsrepository::mock");
}});
put("re3data",new ArrayList<String>(){{ add("datarepository::unknown");
}});
put("journal",new ArrayList<String>(){{ add("pubsrepository::journal");
}});
put("aggregator",new ArrayList<String>(){{ add("aggregator::pubsrepository::institutional");
add("aggregator::pubsrepository::journals");
add("aggregator::datarepository");
add("aggregator::pubsrepository::unknown");
}});
}};
private static Map<String,String> invertedDataSourceClass = new HashMap<String,String>(){{
put("pubsrepository::institutional","opendoar");
put("pubsrepository::thematic","opendoar");
put("pubsrepository::unknown","opendoar");
put("pubsrepository::mock","opendoar");
put("datarepository::unknown","re3data");
put("pubsrepository::journal","journal");
put("aggregator::pubsrepository::institutional","aggregator");
put("aggregator::pubsrepository::journals","aggregator");
put("aggregator::datarepository","aggregator");
put("aggregator::pubsrepository::unknown","aggregator");
}};
@PostConstruct
private void init() {
LOGGER.debug("Initialization method of repository api!");
LOGGER.debug("Updated version!");
httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
// httpHeaders.set("Content-Type", "application/json");
for (String vocName : vocabularyNames) {
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT));
}
Country[] countries = getCountries();
for (Country c : countries) {
countriesMap.put(c.getName(), c.getCode());
inverseCountriesMap.put(c.getCode(), c.getName());
}
}
@Override
public Country[] getCountries() {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/countries")
.build().encode();
return restTemplate.getForObject(uriComponents.toUri(), Country[].class);
}
@Override
public List<RepositorySnippet> getRepositoriesByCountry(@PathVariable("country") String country,
@PathVariable("mode") String mode,
@RequestParam(value = "managed",required=false) Boolean managed) throws JSONException, IOException {
LOGGER.debug("Getting repositories by country!");
int page = 0;
int size = 100;
List<RepositorySnippet> resultSet = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
String filterKey = "UNKNOWN";
if (mode.equalsIgnoreCase("opendoar"))
filterKey = "openaire____::opendoar";
else if (mode.equalsIgnoreCase("re3data"))
filterKey = "openaire____::re3data";
LOGGER.debug("Country code equals : " + country);
LOGGER.debug("Filter mode equals : " + filterKey);
UriComponents uriComponents = searchSnipperDatasource(String.valueOf(page),String.valueOf(size));
RequestFilter requestFilter = new RequestFilter();
requestFilter.setCountry(country);
requestFilter.setCollectedfrom(filterKey);
try{
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),
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;
}catch (Exception e){
LOGGER.debug("Exception on getRepositoriesByCountry" , e);
// emailUtils.reportException(e);
throw e;
}
}
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");
List<RepositorySnippet> resultSet = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
UriComponents uriComponents = searchRegisteredDatasource(requestSortBy, order, Integer.toString(page), Integer.toString(pageSize));
RequestFilter requestFilter = new RequestFilter();
requestFilter.setCountry(country);
requestFilter.setTypology(typology);
requestFilter.setOfficialname(officialName);
requestFilter.setEnglishname(englishName);
try {
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)));
return resultSet;
}catch (Exception e){
LOGGER.error("Error searching registered datasources" , e);
throw e;
}
}
private Repository updateRepositoryInfo(Repository r) throws JSONException {
/*
* from datasource class
* we get the datasource type form the inverted map
* */
r.setDatasourceType(getRepositoryType(r.getDatasourceClass()));
r.setInterfaces(this.getRepositoryInterface(r.getId()));
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId()));
r.setCountryName(getCountryName(r.getCountryCode()));
return r;
}
private Collection<Repository> getRepositoriesByMode(String mode, List<Repository> rs) {
List<Repository> reps = new ArrayList<>();
for (Repository r : rs) {
if (r.getCollectedFrom() != null && r.getCollectedFrom().equals(mode))
reps.add(r);
}
return reps;
}
@Override
public List<Repository> getRepositoriesOfUser(@PathVariable("userEmail") String userEmail,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
LOGGER.debug("Retreiving repositories of user : " + userEmail );
UriComponents uriComponents = searchDatasource(page,size);
RequestFilter requestFilter = new RequestFilter();
requestFilter.setRegisteredby(userEmail);
try{
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs));
for (Repository r : repos)
this.updateRepositoryInfo(r);
return repos;
}catch (Exception e){
LOGGER.debug("Exception on getRepositoriesOfUser" , e);
emailUtils.reportException(e);
throw e;
}
}
@Override
public Repository getRepositoryById(@PathVariable("id") String id) throws JSONException,ResourceNotFoundException {
LOGGER.debug("Retreiving repositories with id : " + id );
Repository repo = null;
UriComponents uriComponents = searchDatasource("0","100");
RequestFilter requestFilter = new RequestFilter();
requestFilter.setId(id);
try{
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
if(jsonArray.length() == 0)
throw new ResourceNotFoundException();
repo = Converter.jsonToRepositoryObject(jsonArray.getJSONObject(0));
return updateRepositoryInfo(repo);
}catch (JSONException e){
LOGGER.debug("Exception on getRepositoryById" , e);
emailUtils.reportException(e);
throw e;
}
}
@Override
public List<AggregationDetails> getRepositoryAggregations(@PathVariable("id") String id) throws JSONException {
LOGGER.debug("Retreiving aggregations for repository with id : " + id );
UriComponents uriComponents = searchDatasource("0","100");
RequestFilter requestFilter = new RequestFilter();
requestFilter.setId(id);
List<AggregationDetails> aggregationHistory = new ArrayList<>();
try {
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
JSONObject repository = new JSONObject(rs);
if(repository.getJSONArray("datasourceInfo").length() == 0)
return aggregationHistory;
aggregationHistory.addAll(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0)));
return aggregationHistory.size() == 0? aggregationHistory : aggregationHistory.stream()
.sorted(Comparator.comparing(AggregationDetails::getDate).reversed())
.limit(20)
.collect(Collectors.toList());
} catch (JSONException e) {
LOGGER.debug("Exception on getRepositoryAggregations" , e);
emailUtils.reportException(e);
throw e;
}
}
@Override
public Map<String, List<AggregationDetails>> getRepositoryAggregationsByYear(@PathVariable("id") String id) throws JSONException {
LOGGER.debug("Retreiving aggregations (by year) for repository with id : " + id );
UriComponents uriComponents = searchDatasource("0","100");
RequestFilter requestFilter = new RequestFilter();
requestFilter.setId(id);
List<AggregationDetails> aggregationHistory = new ArrayList<>();
Map<String, List<AggregationDetails>> aggregationByYear = new HashMap<>();
try {
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
JSONObject repository = new JSONObject(rs);
if(repository.getJSONArray("datasourceInfo").length() == 0)
return aggregationByYear;
aggregationHistory.addAll(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0)));
return aggregationHistory.size() == 0? aggregationByYear:createYearMap(aggregationHistory);
} catch (JSONException e) {
LOGGER.debug("Exception on getRepositoryAggregations" , e);
emailUtils.reportException(e);
throw e;
}
}
private Map<String,List<AggregationDetails>> createYearMap(List<AggregationDetails> aggregationHistory) {
Map<String, List<AggregationDetails>> aggregationByYear;
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(@PathVariable("name") String name,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
LOGGER.debug("Retreiving repositories with official name : " + name );
UriComponents uriComponents = searchDatasource("0","100");
RequestFilter requestFilter = new RequestFilter();
requestFilter.setOfficialname(name);
try{
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs));
for (Repository r : repos)
updateRepositoryInfo(r);
return repos;
}catch (Exception e){
LOGGER.debug("Exception on getRepositoriesByName" , e);
emailUtils.reportException(e);
throw e;
}
}
@Override
public List<RepositoryInterface> getRepositoryInterface(@PathVariable("id") String id) throws JSONException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/api/")
.path("/{id}")
.build().expand(id).encode();
try{
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
return Converter.jsonToRepositoryInterfaceList(new JSONObject(rs));
}catch (Exception e ){
LOGGER.debug("Exception on getRepositoryInterface" , e);
emailUtils.reportException(e);
throw e;
}
}
@Override
public Repository addRepository(@RequestParam("datatype") String datatype,
@RequestBody Repository repository) throws Exception {
LOGGER.debug("storing " + datatype + " repository with id: " + repository.getId());
repository.setCountryCode(countriesMap.get(repository.getCountryName()));
repository.setActivationId(UUID.randomUUID().toString());
repository.setCollectedFrom("infrastruct_::openaire");
if (datatype.equals("journal")) {
repository.setId("openaire____::issn" + repository.getIssn());
repository.setNamespacePrefix("issn" + repository.getIssn());
this.storeRepository(repository, SecurityContextHolder.getContext().getAuthentication());
}else if (datatype.equals("aggregator")) {
repository.setId("openaire____::" + com.unboundid.util.Base64.encode(repository.getOfficialName()));
repository.setNamespacePrefix(DigestUtils.md5Hex(repository.getOfficialName()).substring(0,12));
this.storeRepository(repository, SecurityContextHolder.getContext().getAuthentication());
}else {
this.latentUpdate(repository, SecurityContextHolder.getContext().getAuthentication());
}
return repository;
}
/* update method acting as add -> send email with registration topic/body*/
private Repository latentUpdate(Repository repository, Authentication authentication) throws Exception {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/update/")
.build()
.encode();
try {
String json_repository = Converter.repositoryObjectToJson(repository);
LOGGER.debug("JSON to add(update) -> " + json_repository);
//
// // TODO delete these 3 lines
// HttpHeaders temp = new HttpHeaders();
// temp.setContentType(MediaType.APPLICATION_JSON_UTF8);
HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders);
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, httpEntity, ResponseEntity.class);
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
emailUtils.sendUserRegistrationEmail(repository, authentication);
emailUtils.sendAdminRegistrationEmail(repository, authentication);
} else
LOGGER.debug(responseEntity.getBody().toString());
return repository;
} catch (Exception e) {
LOGGER.debug("Exception on updateRepository" , e);
emailUtils.reportException(e);
throw e;
}
}
@Override
public Repository updateRepository(@RequestBody Repository repository,Authentication authentication) throws Exception {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/update/")
.build()
.encode();
try {
String json_repository = Converter.repositoryObjectToJson(repository);
LOGGER.debug("JSON to update -> " + json_repository);
HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders);
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, httpEntity
, ResponseEntity.class);
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
emailUtils.sendUserUpdateRepositoryEmail(repository, authentication);
emailUtils.sendAdminUpdateRepositoryEmail(repository, authentication);
} else
LOGGER.debug(responseEntity.getBody().toString());
return repository;
} catch (Exception e) {
LOGGER.debug("Exception on updateRepository" , e);
emailUtils.reportException(e);
throw e;
}
}
private void updateInterface(String datatype,RepositoryInterface iFace) {
//TODO call update base url
//((DatasourceManagerService) this.dmService.getService()).updateBaseUrl(repo.getId(), iFace.getId(), iFace.getBaseUrl());
if (!iFace.getAccessSet().isEmpty()) {
LOGGER.debug("set not empty: " + iFace.getAccessSet());
//TODO call update method for access params
// ((DatasourceManagerService) this.dmService.getService()).updateAccessParam(repo.getId(), iFace.getId(), "set", iFace.getAccessSet(), false);
} else {
//TODO call deleteAccessParamOrExtraField
//((DatasourceManagerService) this.dmService.getService()).deleteAccessParamOrExtraField(repo.getId(), iFace.getId(), "set");
}
//TODO update content description
//((DatasourceManagerService) this.dmService.getService()).updateContentDescription(repo.getId(), iFace.getId(), "metadata");
if (datatype.equals("re3data")) {
//TODO call update access params
// ((DatasourceManagerService) this.dmService.getService()).updateAccessParam(repo.getId(), iFace.getId(), "format", "oai_datacite", false);
iFace.setAccessFormat("oai_datacite");
} else {
//TODO call update access params
//((DatasourceManagerService) this.dmService.getService()).updateAccessParam(repo.getId(), iFace.getId(), "format", "oai_dc", false);
iFace.setAccessFormat("oai_dc");
}
}
private void storeRepository(Repository repository, Authentication authentication) throws Exception {
Date utilDate = new Date();
Timestamp date = new Timestamp(utilDate.getTime());
repository.setDateOfCollection(date);
repository.setAggregator("OPENAIRE");
repository.setCountryCode(countriesMap.get(repository.getCountryName()));
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/add/")
.build()
.encode();
String json_repository = Converter.repositoryObjectToJson(repository);
HttpEntity<String> httpEntity = new HttpEntity <String> (json_repository,httpHeaders);
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, httpEntity, ResponseEntity.class);
if(responseEntity.getStatusCode().equals(HttpStatus.OK)) {
emailUtils.sendUserRegistrationEmail(repository, authentication);
emailUtils.sendAdminRegistrationEmail(repository, authentication);
} else {
LOGGER.debug(responseEntity.getBody().toString());
}
}
@Override
public void deleteRepositoryInterface(@RequestParam("id") String id ,
@RequestParam("registeredBy") String registeredBy){
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/api/")
.path("/{id}")
.build().expand(id).encode();
LOGGER.debug(uriComponents.toUri());
restTemplate.delete(uriComponents.toUri());
}
@Override
public RepositoryInterface addRepositoryInterface(@RequestParam("datatype") String datatype,
@RequestParam("repoId") String repoId,
@RequestParam("registeredBy") String registeredBy,
@RequestBody RepositoryInterface repositoryInterface) throws JSONException,ResourceNotFoundException {
try {
Repository e = this.getRepositoryById(repoId);
repositoryInterface = createRepositoryInterface(e,repositoryInterface,datatype);
String json_interface = Converter.repositoryInterfaceObjectToJson(e,repositoryInterface);
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/api/add/")
.build()
.encode();
HttpEntity<String> httpEntity = new HttpEntity <String> (json_interface,httpHeaders);
restTemplate.postForObject(uriComponents.toUri(),httpEntity,String.class);
return repositoryInterface;
} catch (JSONException e) {
LOGGER.debug("Exception on addRepositoryInterface" , e);
emailUtils.reportException(e);
throw e;
}
}
@Override
public RepositoryInterface updateRepositoryInterface(@RequestParam("repoId") String repoId,
@RequestParam("registeredBy") String registeredBy,
@RequestBody RepositoryInterface repositoryInterface) throws Exception {
this.updateBaseUrl(repoId,repositoryInterface.getId(),repositoryInterface.getBaseUrl());
this.updateCompliance(repoId,repositoryInterface.getId(),repositoryInterface.getCompliance());
this.updateValidationSet(repoId,repositoryInterface.getId(),repositoryInterface.getAccessSet());
return repositoryInterface;
}
private void submitInterfaceValidation(Repository repo, String repoType, String userEmail, RepositoryInterface iFace) 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.getDesiredCompatibilityLevel());
job.setInterfaceId(iFace.getId());
// job.setInterfaceIdOld(null);
job.setOfficialName(repo.getOfficialName());
job.setRepoType(repoType);
job.setUserEmail(userEmail);
job.setValidationSet(iFace.getAccessSet());
job.setRecords(-1);
job.setRegistration(true);
job.setUpdateExisting(false);
this.validatorService.submitJobForValidation(job);
}
private RepositoryInterface createRepositoryInterface(Repository repo, RepositoryInterface iFace, String datatype) {
iFace.setContentDescription("metadata");
iFace.setCompliance("UNKNOWN");
if (datatype.equals("re3data"))
iFace.setAccessFormat("oai_datacite");
else
iFace.setAccessFormat("oai_dc");
if (repo.getDatasourceClass() != null && !repo.getDatasourceClass().isEmpty())
iFace.setTypology(repo.getDatasourceClass());
else if (datatype.equalsIgnoreCase("journal"))
iFace.setTypology("pubsrepository::journal");
else if (datatype.equalsIgnoreCase("aggregator"))
iFace.setTypology("aggregator::pubsrepository::unknown");
else if (datatype.equalsIgnoreCase("opendoar"))
iFace.setTypology("pubsrepository::unknown");
else if (datatype.equalsIgnoreCase("re3data"))
iFace.setTypology("datarepository::unknown");
iFace.setRemovable(true);
iFace.setAccessProtocol("oai");
iFace.setMetadataIdentifierPath("//*[local-name()='header']/*[local-name()='identifier']");
iFace.setId("api_________::" + repo.getId() + "::" + UUID.randomUUID().toString().substring(0, 8));
if (iFace.getAccessSet().isEmpty()) {
LOGGER.debug("set is empty: " + iFace.getAccessSet());
iFace.removeAccessSet();
}
return iFace;
}
@Override
public List<String> getDnetCountries() {
LOGGER.debug("Getting dnet-countries!");
return Converter.readFile("countries.txt");
}
@Override
public List<String> getTypologies() {
return Converter.readFile("typologies.txt");
}
@Override
public List<Timezone> getTimezones() {
List<String> timezones = Converter.readFile("timezones.txt");
return Converter.toTimezones(timezones);
}
@Override
public List<String> getUrlsOfUserRepos(@PathVariable("user_email") String userEmail,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/api/baseurl/")
.path("/{page}/{size}")
.build().expand(page,size).encode();
try{
RequestFilter requestFilter = new RequestFilter();
requestFilter.setRegisteredby(userEmail);
return Arrays.asList(restTemplate.postForObject(uriComponents.toUri(),requestFilter, String[].class));
}catch (Exception e){
LOGGER.debug("Exception on addRepositoryInterface" , e);
emailUtils.reportException(e);
throw e;
}
}
@Override
public List<String> getDatasourceVocabularies(@PathVariable("mode") String mode) {
List<String> resultSet = new ArrayList<>();
for (Map.Entry<String, String> entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) {
if (mode.equalsIgnoreCase("aggregator")) {
if (entry.getKey().contains("aggregator"))
resultSet.add(entry.getValue());
} else if (mode.equalsIgnoreCase("journal")) {
if (entry.getKey().contains("journal"))
resultSet.add(entry.getValue());
} else if (mode.equalsIgnoreCase("opendoar")) {
if (entry.getKey().contains("pubsrepository"))
resultSet.add(entry.getValue());
} else if (mode.equalsIgnoreCase("re3data")) {
if (entry.getKey().contains("datarepository"))
resultSet.add(entry.getValue());
}
}
return resultSet;
}
private Vocabulary getVocabulary(String vocName) {
if (!vocabularyMap.containsKey(vocName)) {
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT));
}
return vocabularyMap.get(vocName);
}
@Override
public Map<String, String> getCompatibilityClasses(@PathVariable("mode") String 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();
boolean foundData = false;
for (Map.Entry<String, String> entry : compatibilityClasses.entrySet()) {
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$")) {
retMap.put(entry.getKey(), entry.getValue());
foundData = true;
}
} else {
if (entry.getKey().matches("^openaire[1-9].0$") || entry.getKey().equals("driver"))
retMap.put(entry.getKey(), entry.getValue());
}
}
//TODO TO BE REMOVED WHEN VOCABULARIES ARE UPDATED
if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA) && !foundData)
retMap.put("openaire2.0_data", "OpenAIRE Data (funded, referenced datasets)");
return retMap;
}
@Override
public Map<String, String> getDatasourceClasses(@PathVariable("mode") String mode) {
LOGGER.debug("Getting datasource classes for mode: " + mode);
Map<String, String> retMap = new HashMap<String, String>();
for (Map.Entry<String, String> entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) {
if (mode.equalsIgnoreCase("aggregator")) {
if (entry.getKey().contains("aggregator"))
retMap.put(entry.getKey(), entry.getValue());
} else if (mode.equalsIgnoreCase("journal")) {
if (entry.getKey().contains("journal"))
retMap.put(entry.getKey(), entry.getValue());
} else if (mode.equalsIgnoreCase("opendoar")) {
if (entry.getKey().contains("pubsrepository"))
retMap.put(entry.getKey(), entry.getValue());
} else if (mode.equalsIgnoreCase("re3data")) {
if (entry.getKey().contains("datarepository"))
retMap.put(entry.getKey(), entry.getValue());
}
}
return filterResults(retMap,mode);
}
private Map<String,String> filterResults(Map<String, String> map,String mode) {
HashMap<String,String> filteredMap = new HashMap<>();
for(String key:map.keySet())
if(dataSourceClass.get(mode).contains(key))
filteredMap.put(key,map.get(key));
return filteredMap;
}
@Override
public String getCountryName(String countryCode) {
return inverseCountriesMap.get(countryCode);
}
@Override
public MetricsInfo getMetricsInfoForRepository(@PathVariable("repoId") String repoId) throws RepositoryServiceException {
try {
MetricsInfo metricsInfo = new MetricsInfo();
metricsInfo.setDiagramsBaseURL(this.usageStatisticsDiagramsBaseURL);
metricsInfo.setMetricsNumbers(getMetricsNumbers(getOpenAIREId(repoId)));
return metricsInfo;
} catch (Exception e) {
LOGGER.error("Error while getting metrics info for repository: ", e);
emailUtils.reportException(e);
throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
}
}
@Override
public Map<String, String> getListLatestUpdate(@PathVariable("mode") String mode) throws JSONException {
if(mode.equals("opendoar"))
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::"+mode).get(0).getLastCollectionDate());
else
/*
* first api of re3data has null value on collection date
* */
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::"+mode).get(1).getLastCollectionDate());
}
private void updateValidationSet(String repositoryId, String repositoryInterfaceId, String validationSet) throws Exception {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/api/oaiset")
.queryParam("dsId",repositoryId)
.queryParam("apiId",repositoryInterfaceId)
.queryParam("oaiSet",validationSet)
.build().encode();
restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, null, ResponseEntity.class);
}
private void updateBaseUrl(String repositoryId, String repositoryInterfaceId, String baseUrl) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/api/baseurl")
.queryParam("dsId",repositoryId)
.queryParam("apiId",repositoryInterfaceId)
.queryParam("baseUrl",baseUrl)
.build().encode();
restTemplate.postForObject(uriComponents.toUri(),null,String.class);
}
private void updateCompliance(String repositoryId, String repositoryInterfaceId,String compliance) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/api/compliance")
.queryParam("dsId",repositoryId)
.queryParam("apiId",repositoryInterfaceId)
.queryParam("compliance",compliance)
.build().encode();
restTemplate.postForObject(uriComponents.toUri(),null,String.class);
}
private MetricsNumbers getMetricsNumbers(String openAIREID) throws BrokerException {
//build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usageStatisticsNumbersBaseURL + openAIREID + "/clicks");
//create new template engine
RestTemplate template = new RestTemplate();
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
ResponseEntity<MetricsNumbers> resp;
try {
//communicate with endpoint
resp = template.exchange(
builder.build().encode().toUri(),
HttpMethod.GET,
null,
new ParameterizedTypeReference<MetricsNumbers>() {
});
} catch (RestClientException e) {
LOGGER.debug("Exception on getMetricsNumbers" , e);
emailUtils.reportException(e);
throw e;
}
return resp.getBody();
}
private String getOpenAIREId(String repoId) {
if (repoId != null && repoId.contains("::")) {
return repoId.split("::")[0] + "::" + DigestUtils.md5Hex(repoId.split("::")[1]);
}
return null;
}
private UriComponents searchDatasource(String page,String size){
return UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/search/")
.path("/{page}/{size}/")
.queryParam("requestSortBy","officialname")
.queryParam("order","ASCENDING")
.build().expand(page, size).encode();
}
private UriComponents searchSnipperDatasource(String page,String size){
return UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/searchsnippet/")
.path("/{page}/{size}/")
.queryParam("requestSortBy","officialname")
.queryParam("order","ASCENDING")
.build().expand(page, size).encode();
}
private UriComponents searchRegisteredDatasource(String requestSortBy, String order, String page,String size){
return UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/searchregistered/")
.path("/{page}/{size}/")
.queryParam("requestSortBy",requestSortBy)
.queryParam("order",order)
.build().expand(page, size).encode();
}
private String getRepositoryType(String typology){
return invertedDataSourceClass.get(typology);
}
}

View File

@ -0,0 +1,13 @@
package eu.dnetlib.repo.manager.service;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import eu.dnetlib.repo.manager.exception.EndPointException;
import org.json.JSONException;
import java.util.Map;
public interface StatsService {
Map getStatistics() ;
}

View File

@ -0,0 +1,50 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.repo.manager.service.customHystrixCommands.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.Map;
@Service("statsService")
public class StatsServiceImpl implements StatsService {
@Autowired
RestTemplate restTemplate;
@Value("${search.api.baseAddress}")
private String baseAddress;
@Value("${search.api.usagestats}")
private String usagestatsBaseAddress;
@Value("${search.api.usageEvents}")
private String usagestatsEvents;
@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());
return stats;
}
}

View File

@ -0,0 +1,23 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper;
import org.json.JSONException;
public interface SushiliteService {
ReportResponseWrapper getReportResults(String page,
String pageSize,
String Report,
String Release,
String RequestorID,
String BeginDate,
String EndDate,
String RepositoryIdentifier,
String ItemIdentifier,
String ItemDataType,
String Granularity,
String Pretty) throws JSONException;
}

View File

@ -0,0 +1,116 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.usagestats.sushilite.domain.ReportItem;
import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
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.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.ArrayList;
import java.util.List;
@Service("sushiliteService")
public class SushiliteServiceImpl implements SushiliteService {
@Value("${services.repomanager.usagestats.sushiliteEndpoint}")
private String usagestatsSushiliteEndpoint;
@Autowired
private EmailUtils emailUtils;
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(SushiliteServiceImpl.class);
@Override
@PreAuthorize("hasRole('ROLE_USER')")
public ReportResponseWrapper getReportResults(@PathVariable("page") String page,
@PathVariable("pageSize") String pageSize,
@RequestParam(value = "Report") String Report,
@RequestParam(value = "Release",defaultValue="4") String Release,
@RequestParam(value = "RequestorID",required=false,defaultValue="anonymous") String RequestorID,
@RequestParam(value = "BeginDate",required=false,defaultValue="") String BeginDate,
@RequestParam(value = "EndDate",required=false,defaultValue="") String EndDate,
@RequestParam(value = "RepositoryIdentifier") String RepositoryIdentifier,
@RequestParam(value = "ItemIdentifier",required=false,defaultValue="") String ItemIdentifier,
@RequestParam(value = "ItemDataType",required=false,defaultValue="") String ItemDataType,
@RequestParam(value = "Granularity") String Granularity,
@RequestParam(value = "Pretty",required=false,defaultValue="") 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);
//create new template engine
RestTemplate template = new RestTemplate();
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
ResponseEntity<ReportResponseWrapper> resp;
try {
//communicate with endpoint
resp = template.exchange(
builder.build().encode().toUri(),
HttpMethod.GET,
null,
new ParameterizedTypeReference<ReportResponseWrapper>() {
});
} catch (RestClientException e) {
LOGGER.debug("Exception on getReportResults" , e);
emailUtils.reportException(e);
throw e;
}
// check remote api's response
System.out.println("sushi responded status " + resp.getStatusCode());
// 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;
if (offset < totalItems ) {
int upperIndex = offset+size;
if (upperIndex > totalItems) {
upperIndex = totalItems;
}
requestedItemList = resp.getBody().getReportResponse().getReportWrapper().getReport().getCustomer().getReportItems().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);
return newReportResponse;
}
}

View File

@ -0,0 +1,9 @@
package eu.dnetlib.repo.manager.service;
import org.springframework.http.ResponseEntity;
public interface UserService {
ResponseEntity<Object> login();
}

View File

@ -0,0 +1,42 @@
package eu.dnetlib.repo.manager.service;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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);
@Value("${oidc.issuer}")
private String oidc_issuer;
@Override
public ResponseEntity<Object> login() {
OIDCAuthenticationToken authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
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());
List<String> roles = authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
body.put("role",roles);
return new ResponseEntity<>(body, HttpStatus.OK);
}
}

View File

@ -0,0 +1,42 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.api.functionality.ValidatorServiceException;
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.shared.InterfaceInformation;
import eu.dnetlib.repo.manager.shared.ValidationServiceException;
import org.json.JSONException;
import org.springframework.http.ResponseEntity;
import java.util.List;
public interface ValidatorService {
JobForValidation submitJobForValidation(JobForValidation jobForValidation) throws ValidatorServiceException;
ResponseEntity<Object> reSubmitJobForValidation(String email, String jobId) throws JSONException, ValidatorServiceException;
List<RuleSet> getRuleSets(String mode);
List<String> getSetsOfRepository(String url);
boolean identifyRepo(String url);
RuleSet getRuleSet(String acronym);
List<StoredJob> getStoredJobsNew(String user,
String jobType,
String offset,
String limit,
String dateFrom,
String dateTo,
String validationStatus) throws ValidatorServiceException;
int getStoredJobsTotalNumberNew(String user, String jobType, String validationStatus) throws ValidatorServiceException;
InterfaceInformation getInterfaceInformation(String baseUrl) throws ValidationServiceException;
}

View File

@ -1,56 +1,61 @@
package eu.dnetlib.repo.manager.service.controllers;
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.service.utils.OaiTools;
import eu.dnetlib.repo.manager.shared.InterfaceInformation;
import eu.dnetlib.repo.manager.shared.ValidationServiceException;
import gr.uoa.di.driver.util.ServiceLocator;
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.shared.Constants;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import eu.dnetlib.api.functionality.ValidatorService;
import eu.dnetlib.repo.manager.shared.InterfaceInformation;
import eu.dnetlib.repo.manager.shared.ValidationServiceException;
import eu.dnetlib.repo.manager.utils.OaiTools;
import gr.uoa.di.driver.util.ServiceLocator;
import io.swagger.annotations.ApiParam;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@Component
public class ValidatorApiImpl implements ValidatorApi{
@Service("validatorService")
public class ValidatorServiceImpl implements ValidatorService {
@Autowired
private MonitorApiImpl monitorApi;
private MonitorServiceImpl monitorApi;
@Resource(name = "validatorServiceLocator")
private ServiceLocator<ValidatorService> validatorServiceLocator;
private ServiceLocator<eu.dnetlib.api.functionality.ValidatorService> validatorServiceLocator;
private ValidatorService getValidationService() {
private eu.dnetlib.api.functionality.ValidatorService getValidationService() {
return this.validatorServiceLocator.getService();
}
public ServiceLocator<ValidatorService> getValidatorServiceLocator() {
public ServiceLocator<eu.dnetlib.api.functionality.ValidatorService> getValidatorServiceLocator() {
return validatorServiceLocator;
}
public void setValidatorServiceLocator(ServiceLocator<ValidatorService> validatorServiceLocator) {
public void setValidatorServiceLocator(ServiceLocator<eu.dnetlib.api.functionality.ValidatorService> validatorServiceLocator) {
this.validatorServiceLocator = validatorServiceLocator;
}
private Map<String, List<RuleSet>> rulesetMap = new ConcurrentHashMap<String, List<RuleSet>>();
private static final Logger LOGGER = Logger
.getLogger(ValidatorApiImpl.class);
.getLogger(ValidatorServiceImpl.class);
@Autowired
private EmailUtils emailUtils;
@PostConstruct
private void loadRules(){
@ -82,17 +87,26 @@ public class ValidatorApiImpl implements ValidatorApi{
}
@Override
public void submitJobForValidation(@RequestBody JobForValidation jobForValidation) {
@PreAuthorize("hasRole('ROLE_USER') and #jobForValidation.userEmail == authentication.userInfo.email")
public JobForValidation submitJobForValidation(@RequestBody JobForValidation jobForValidation) throws ValidatorServiceException {
LOGGER.debug("Submit job for validation with id : " + jobForValidation.getDatasourceId());
try {
emailUtils.sendSubmitJobForValidationEmail(SecurityContextHolder.getContext().getAuthentication(),jobForValidation);
this.getValidationService().submitValidationJob(jobForValidation);
} catch (ValidatorServiceException e) {
LOGGER.debug("Exception on submitJobForValidation" , e);
emailUtils.reportException(e);
throw e;
} catch (Exception e) {
e.printStackTrace();
}
return jobForValidation;
}
@Override
public void reSubmitJobForValidation(@PathVariable("jobId") String jobId) throws JSONException {
@PreAuthorize("hasRole('ROLE_USER') and #email == authentication.userInfo.email")
public ResponseEntity<Object> reSubmitJobForValidation(@PathVariable("email") String email,
@PathVariable("jobId") String jobId) throws JSONException, ValidatorServiceException {
LOGGER.debug("Resubmit validation job with id : " + jobId);
StoredJob job = monitorApi.getJobSummary(jobId,"all");
Set<Integer> contentRules = new HashSet<Integer>();
@ -118,6 +132,7 @@ public class ValidatorApiImpl implements ValidatorApi{
if (!usageRules.isEmpty())
job.setSelectedUsageRules(usageRules);
this.submitJobForValidation(job);
return new ResponseEntity<>("OK",HttpStatus.OK);
}
@Override
@ -132,7 +147,8 @@ public class ValidatorApiImpl implements ValidatorApi{
try {
return OaiTools.getSetsOfRepo(url);
} catch (Exception e) {
e.printStackTrace();
LOGGER.debug("Exception on getSetsOfRepository" , e);
emailUtils.reportException(e);
}
return null;
}
@ -144,6 +160,7 @@ public class ValidatorApiImpl implements ValidatorApi{
return OaiTools.identifyRepository(url);
} catch (Exception e) {
LOGGER.error("Error while identifying repository with url: " + url, e);
emailUtils.reportException(e);
return false;
}
}
@ -163,11 +180,13 @@ public class ValidatorApiImpl implements ValidatorApi{
return ruleSet;
} catch (Exception e) {
LOGGER.error("Error getting ruleset", e);
emailUtils.reportException(e);
return null;
}
}
@Override
@PreAuthorize("hasRole('ROLE_USER')")
public List<StoredJob> getStoredJobsNew(@RequestParam("user") @ApiParam(value = "User email", required = true) String user,
@RequestParam(value = "jobType", required = false)
@ApiParam(value = "Equals to filter job type on validation history page") String jobType,
@ -197,7 +216,7 @@ public class ValidatorApiImpl implements ValidatorApi{
return interfaceInformation;
} catch (Exception e) {
LOGGER.error("Error getting interface information with url: " + baseUrl, e);
// emailUtils.reportException(e);
emailUtils.reportException(e);
throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR);
}
}

View File

@ -1,79 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import eu.dnetlib.repo.manager.shared.BrokerException;
import eu.dnetlib.repo.manager.shared.Term;
import eu.dnetlib.repo.manager.shared.broker.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value = "/broker")
@Api(description = "Broker API", tags = {"broker"})
public interface BrokerApi {
@RequestMapping(value = "/getDatasourcesOfUser" , method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
DatasourcesBroker getDatasourcesOfUser(String user,String includeShared,String includeByOthers) throws BrokerException, JSONException;
@RequestMapping(value = "/getTopicsForDatasource/{datasourceName}" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<BrowseEntry> getTopicsForDatasource(String datasourceName) throws BrokerException;
@RequestMapping(value = "/advancedShowEvents/{page}/{size}" , method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
EventsPage advancedShowEvents(String page,
String size,
AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException;
@RequestMapping(value = "/showEvents/{datasourceName}/{topic}/{page}" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
EventsPage showEvents(String datasourceName,
String topic,
String page,
String size) throws BrokerException, JSONException;
@RequestMapping(value = "/getSimpleSubscriptionsOfUser/{userEmail}" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(String userEmail) throws BrokerException;
@RequestMapping(value = "/subscribe" , method = RequestMethod.POST,consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Subscription subscribe(OpenaireSubscription obj) throws BrokerException;
@RequestMapping(value = "/unsubscribe/{subscriptionId}" , method = RequestMethod.POST,consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
void unsubscribe(String subscriptionId) throws BrokerException;
@RequestMapping(value = "/getSubscription/{subscriptionId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Subscription getSubscription(String subscriptionId) throws BrokerException;
@RequestMapping(value = "/getDnetTopics" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Map<String, Term> getDnetTopics() throws BrokerException;
@RequestMapping(value = "/getNotificationsBySubscriptionId/{subscriptionId}/{page}/{size}" , method = RequestMethod.GET
,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
EventsPage getNotificationsBySubscriptionId(String subscriptionId,String page,String size) throws BrokerException;
@RequestMapping(value = "/getSubscriptionsOfUser/{userEmail}" , method = RequestMethod.GET
,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Map<String, List<Subscription>> getSubscriptionsOfUser(String userEmail) throws BrokerException;
}

View File

@ -1,39 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.functionality.validator.StoredJob;
import eu.dnetlib.repo.manager.shared.JobsOfUser;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping(value = "/monitor")
@Api(description = "Monitor API", tags = {"monitor"})
public interface MonitorApi {
@RequestMapping(value = "/getJobsOfUser" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
JobsOfUser getJobsOfUser(String user,
String jobType,
String offset,
String limit,
String dateFrom,
String dateTo,
String validationStatus,
String includeJobsTotal) throws JSONException, ValidatorServiceException;
@RequestMapping(value = "/getJobsOfUserPerValidationStatus" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
int getJobsOfUserPerValidationStatus(@RequestBody String user,
@RequestBody String jobType,
@RequestBody String validationStatus) throws JSONException;
@RequestMapping(value = "/getJobSummary" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
StoredJob getJobSummary(@RequestBody String jobId,
@RequestBody String groupBy) throws JSONException;
}

View File

@ -1,34 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import eu.dnetlib.domain.data.PiwikInfo;
import io.swagger.annotations.Api;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(value = "/piwik")
@Api(description = "Piwik API", tags = {"piwik"})
public interface PiWikApi {
@RequestMapping(value = "/getPiwikSiteForRepo/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
PiwikInfo getPiwikSiteForRepo(String repositoryId);
@RequestMapping(value = "/savePiwikInfo" , method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
PiwikInfo savePiwikInfo( PiwikInfo piwikInfo);
@RequestMapping(value = "/getPiwikSitesForRepos" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
List<PiwikInfo> getPiwikSitesForRepos();
@RequestMapping(value = "/approvePiwikSite/{repositoryId}" , method = RequestMethod.GET)
@ResponseBody
void approvePiwikSite(String repositoryId);
@RequestMapping(value = "/getOpenaireId/{repositoryId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String getOpenaireId(String repositoryid);
}

View File

@ -1,96 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.utils.md5.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import java.security.NoSuchAlgorithmException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
@Component
public class PiWikApiImpl implements PiWikApi{
@Autowired
@Qualifier("repomanager.dataSource")
private DataSource dataSource;
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
.getLogger(PiWikApiImpl.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 final static 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 order by repositoryname";
private final static String APPROVE_PIWIK_SITE = "update piwik_site set validated=true, validationdate=now() where repositoryid = ?;";
private 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"));
@Override
public PiwikInfo getPiwikSiteForRepo(@PathVariable("repositoryId") String repositoryId) {
try{
return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITE, new String[]{repositoryId}, new int[]{Types.VARCHAR}, piwikRowMapper);
}catch (EmptyResultDataAccessException e){
return null;
}
}
@Override
public PiwikInfo savePiwikInfo(@RequestBody 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});
return piwikInfo;
}
@Override
public List<PiwikInfo> getPiwikSitesForRepos() {
LOGGER.debug("Getting piwik sites for repos! ");
try{
return new JdbcTemplate(dataSource).query(GET_PIWIK_SITES, piwikRowMapper);
}catch (EmptyResultDataAccessException e){
return null;
}
}
@Override
public void approvePiwikSite(@PathVariable("repositoryId") String repositoryId) {
new JdbcTemplate(dataSource).update(APPROVE_PIWIK_SITE, new Object[] {repositoryId}, new int[] {Types.VARCHAR});
}
@Override
public String getOpenaireId(@PathVariable("repositoryId") String repositoryId) {
LOGGER.debug("Getting openaire id for repository: " + repositoryId);
try {
if (repositoryId != null && repositoryId.contains("::")) {
return repositoryId.split("::")[0] + "::" + MD5.encrypt2Hex(repositoryId.split("::")[1]);
}
else
return null;
} catch (NoSuchAlgorithmException e) {
LOGGER.debug(e);
}
return null;
}
}

View File

@ -1,172 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface;
import eu.dnetlib.repo.manager.shared.*;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value = "/repository")
@Api(description = "Repository API", tags = {"repository"})
public interface RepositoryApi {
@RequestMapping(value = "/testAggregations", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<String> testAggregations() throws JSONException;
@RequestMapping(value = "/getCountries", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Country[] getCountries() ;
@RequestMapping(value = "/getRepositoriesByCountry/{country}/{mode}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<Repository> getRepositoriesByCountry(String country, String mode, Boolean managed) throws JSONException;
@RequestMapping(value = "/getRepositoriesOfUser/{userEmail}/{page}/{size}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<Repository> getRepositoriesOfUser(String userEmail,
String page,
String size) throws JSONException;
@RequestMapping(value = "/getRepositoryById/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Repository getRepositoryById(String id) throws JSONException;
@RequestMapping(value = "/getRepositoryAggregations/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Aggregations getRepositoryAggregations(String id) throws JSONException;
@RequestMapping(value = "/getRepositoriesByName/{name}/{page}/{size}/", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<Repository> getRepositoriesByName(String name,
String page,
String size) throws JSONException;
@RequestMapping(value = "/getRepositoryInterface/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException;
@RequestMapping(value = "/addRepository", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
void addRepository(String datatype, Repository repository) throws Exception;
@RequestMapping(value = "/deleteInterface", method = RequestMethod.DELETE)
@ResponseBody
void deleteRepositoryInterface(String id);
@RequestMapping(value = "/addInterface", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
RepositoryInterface addRepositoryInterface(String datatype,
String repoId,
RepositoryInterface iFace) throws JSONException;
@RequestMapping(value = "/getDnetCountries", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<String> getDnetCountries();
@RequestMapping(value = "/getTypologies", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<String> getTypologies();
@RequestMapping(value = "/getTimezones", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<Timezone> getTimezones();
@RequestMapping(value = "/updateManagedStatus", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updateManagedStatus(String id, String managed);
@RequestMapping(value = "/updateEnglishName", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updateEnglishName(String id,String officialName, String englishName);
@RequestMapping(value = "/updateLatitude", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updateLatitude(String id, String latitude);
@RequestMapping(value = "/updateLongitude", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updateLongitude(String id, String longitude);
@RequestMapping(value = "/updateOfficialName", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updateOfficialName(String id, String officialName);
@RequestMapping(value = "/updateTimezone", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updateTimezone(String id, String timezone);
@RequestMapping(value = "/updateTypology", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updateTypology(String id, String typology);
@RequestMapping(value = "/updateLogoUrl", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updateLogoUrl(String id, String logoUrl);
@RequestMapping(value = "/updatePlatform", method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
String updatePlatform(String id, String platform);
@RequestMapping(value = "/getUrlsOfUserRepos/{user_email}/{page}/{size}/",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<String> getUrlsOfUserRepos(String user_email,
String page,
String size) throws JSONException;
@RequestMapping(value = "/getDatasourceVocabularies/{mode}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<String> getDatasourceVocabularies(String mode);
@RequestMapping(value = "/getCompatibilityClasses/{mode}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Map<String, String> getCompatibilityClasses(String mode);
@RequestMapping(value = "/getDatasourceClasses/{mode}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Map<String, String> getDatasourceClasses(String mode);
String getCountryName(String countryCode);
@RequestMapping(value = "/getMetricsInfoForRepository/{repoId}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException;
}

View File

@ -1,827 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface;
import eu.dnetlib.domain.enabling.Vocabulary;
import eu.dnetlib.repo.manager.service.utils.Converter;
import eu.dnetlib.repo.manager.service.utils.RequestFilter;
import eu.dnetlib.repo.manager.shared.*;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
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 javax.annotation.PostConstruct;
import java.sql.Timestamp;
import java.text.Normalizer;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@Component
public class RepositoryApiImpl implements RepositoryApi {
@Value("${api.baseAddress}")
private String baseAddress;
private RestTemplate restTemplate = null;
private HttpHeaders httpHeaders;
private final String[] vocabularyNames = {"dnet:countries", "dnet:datasource_typologies", "dnet:compatibilityLevel"};
private static final Logger LOGGER = Logger.getLogger(RepositoryApiImpl.class);
@Value("${services.repomanager.usageStatisticsDiagramsBaseURL}")
private String usageStatisticsDiagramsBaseURL;
@Value("${services.repomanager.usageStatisticsNumbersBaseURL}")
private String usageStatisticsNumbersBaseURL;
@Autowired
private VocabularyLoader vocabularyLoader;
@Autowired
private PiWikApi piWikApi;
private Map<String, Vocabulary> vocabularyMap = new ConcurrentHashMap<String, Vocabulary>();
private Map<String, String> countriesMap = new HashMap<>();
private Map<String, String> inverseCountriesMap = new HashMap<>();
@PostConstruct
private void init() {
LOGGER.debug("Initialization method of repository api!");
restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type", "application/json");
for (String vocName : vocabularyNames) {
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT));
}
Country[] countries = getCountries();
for (Country c : countries) {
countriesMap.put(c.getName(), c.getCode());
inverseCountriesMap.put(c.getCode(), c.getName());
}
}
@Override
public List<String> testAggregations() throws JSONException {
int page = 0;
int size = 1000;
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/list/")
.path("/{page}/{size}/")
.build().expand(page, size).encode();
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
List<String> ids = new ArrayList<>();
while (!rs.equals("[]")) {
ids.addAll(getIdsWithNonEmptyAggregations(rs));
LOGGER.debug("Checked " + (page + 1) * size + " records!");
page += 1;
uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/list/")
.path("/{page}/{size}/")
.build().expand(page, size).encode();
rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
}
return ids;
}
private List<String> getIdsWithNonEmptyAggregations(String rs) throws JSONException {
JSONArray ids = new JSONArray(rs);
List<String> agg_ids = new ArrayList<>();
for (int i = 0; i < ids.length(); i++) {
String id = ids.getString(i);
Aggregations aggregations = getRepositoryAggregations(id);
if (aggregations.getAggregationHistory() != null)
agg_ids.add(id);
}
return agg_ids;
}
@Override
public Country[] getCountries() {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/countries")
.build().encode();
return restTemplate.getForObject(uriComponents.toUri(), Country[].class);
}
@Override
public List<Repository> getRepositoriesByCountry(@PathVariable("country") String country,
@PathVariable("mode") String mode,
@RequestParam(value = "managed",required=false) Boolean managed) throws JSONException {
LOGGER.debug("Getting repositories by country!");
int page = 0;
int size = 100;
List<Repository> resultSet = new ArrayList<>();
String countryCode = countriesMap.get(country);
String filterKey = "UNKNOWN";
if (mode.equalsIgnoreCase("opendoar")) {
filterKey = "openaire____::opendoar";
} else if (mode.equalsIgnoreCase("re3data")) {
filterKey = "openaire____::re3data";
} else if (mode.equalsIgnoreCase("jour_aggr")) {
filterKey = "infrastruct_::openaire";
}
LOGGER.debug("Country code equals : " + countryCode);
LOGGER.debug("Filter mode equals : " + filterKey);
UriComponents uriComponents = searchDatasource(String.valueOf(page),String.valueOf(size));
RequestFilter requestFilter = new RequestFilter();
requestFilter.setCountry(countryCode);
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
while (jsonArray.length() > 0 ) {
List<Repository> rep = Converter.jsonToRepositoryList(new JSONObject(rs));
Collection<Repository> repos = this.getRepositoriesByMode(filterKey, rep);
resultSet.addAll(repos);
page += 1;
uriComponents = searchDatasource(String.valueOf(page),String.valueOf(size));
rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
}
for (Repository r : resultSet)
this.getRepositoryInfo(r);
return resultSet;
}
private void getRepositoryInfo(Repository r) throws JSONException {
r.setInterfaces(this.getRepositoryInterface(r.getId()));
r.setPiwikInfo(piWikApi.getPiwikSiteForRepo(r.getId()));
r.setCountryName(getCountryName(r.getCountryCode()));
}
private Collection<Repository> getRepositoriesByMode(String mode, List<Repository> rs) {
List<Repository> reps = new ArrayList<>();
for (Repository r : rs) {
if (r.getCollectedFrom() != null && r.getCollectedFrom().equals(mode))
reps.add(r);
}
return reps;
}
@Override
public List<Repository> getRepositoriesOfUser(@PathVariable("userEmail") String userEmail,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
LOGGER.debug("Retreiving repositories of user : " + userEmail );
UriComponents uriComponents = searchDatasource(page,size);
RequestFilter requestFilter = new RequestFilter();
requestFilter.setRegisteredby(userEmail);
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs));
for (Repository r : repos)
this.getRepositoryInfo(r);
return repos;
}
@Override
public Repository getRepositoryById(@PathVariable("id") String id) throws JSONException {
LOGGER.debug("Retreiving repositories with id : " + id );
UriComponents uriComponents = searchDatasource("0","100");
RequestFilter requestFilter = new RequestFilter();
requestFilter.setId(id);
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
Repository repo = Converter.jsonToRepositoryObject(jsonArray.getJSONObject(0));
if (repo != null)
getRepositoryInfo(repo);
return repo;
}
@Override
public Aggregations getRepositoryAggregations(@PathVariable("id") String id) throws JSONException {
LOGGER.debug("Retreiving aggregations for repository with id : " + id );
UriComponents uriComponents = searchDatasource("0","100");
RequestFilter requestFilter = new RequestFilter();
requestFilter.setId(id);
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
JSONObject repository = new JSONObject(rs);
Aggregations aggregations = new Aggregations();
try {
LOGGER.debug(repository.getJSONArray("datasourceInfo").getJSONObject(0));
aggregations.setAggregationHistory(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0)));
aggregations.setLastCollection(Converter.getLastCollectionFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0)));
aggregations.setLastTransformation(Converter.getLastTransformationFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0)));
return aggregations;
} catch (JSONException e) {
LOGGER.debug("JSON aggregation exception ", e);
throw e;
}
}
@Override
public List<Repository> getRepositoriesByName(@PathVariable("name") String name,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
LOGGER.debug("Retreiving repositories with official name : " + name );
UriComponents uriComponents = searchDatasource("0","100");
RequestFilter requestFilter = new RequestFilter();
requestFilter.setOfficialname(name);
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs));
for (Repository r : repos)
getRepositoryInfo(r);
return repos;
}
@Override
public List<RepositoryInterface> getRepositoryInterface(@PathVariable("id") String id) throws JSONException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/api/")
.path("/{id}/")
.build().expand(id).encode();
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
return Converter.jsonToRepositoryInterfaceList(new JSONObject(rs));
}
@Override
public void addRepository(@RequestParam("datatype") String datatype,
@RequestBody Repository repository) throws Exception {
/*JSONObject json_params = new JSONObject(params);
String datatype = json_params.getString("datatype");
String json_repository = json_params.getString("repository");
Repository repository = null;*/
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
try {
String json_repo = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(repository);
LOGGER.debug("repository -> " + json_repo);
// repository = mapper.readValue(json_repository, Repository.class);
} catch (Exception e) {
LOGGER.debug("Error parsing repository ", e);
throw e;
}
repository = this.setRepositoryFeatures(datatype,repository);
LOGGER.debug("storing " + datatype + " repository with id: " + repository.getId());
if (!datatype.equalsIgnoreCase("opendoar") && !datatype.equalsIgnoreCase("re3data")) {
if (datatype.equalsIgnoreCase("journal") || datatype.equalsIgnoreCase("aggregator")) {
LOGGER.debug("looking if " + datatype + " " + repository.getOfficialName() + " is already in datasources");
if (getRepositoryById(repository.getId()) != null) {
String retMessage = datatype + " '" + repository.getOfficialName() + "' is already in datasources.";
repository.getInterfaces().clear();
LOGGER.debug(retMessage);
} else {
LOGGER.debug(datatype + " " + repository.getOfficialName() + " is not in datasources. Inserting..");
this.storeRepository(repository);
}
}
} else {
this.updateRepository(repository);
}
LOGGER.debug("Inserting Interfaces");
Iterator var11 = repository.getInterfaces().iterator();
while (var11.hasNext()) {
RepositoryInterface iFace = (RepositoryInterface) var11.next();
if (!iFace.getBaseUrl().isEmpty() && !iFace.getDesiredCompatibilityLevel().isEmpty()) {
if (iFace.getId() != null && !iFace.getId().isEmpty()) {
LOGGER.debug("updating iface..");
this.updateInterface(datatype,iFace);
LOGGER.debug("updated successfully");
} else {
LOGGER.debug("adding new iface..");
this.registerRepositoryInterface(repository.getId(),iFace,datatype);
}
}
}
}
private void updateRepository(Repository repository) {
this.updateRegisteredByValue(repository.getId(),repository.getRegisteredBy());
this.updateEnglishName(repository.getId(),repository.getOfficialName(),repository.getEnglishName());
this.updateLogoUrl(repository.getId(),repository.getLogoUrl());
this.updateTimezone(repository.getId(), String.valueOf(repository.getTimezone()));
//TODO update datasource type
}
private void updateRegisteredByValue(String id, String registeredBy) {
LOGGER.debug("Updating registered by value with : " + registeredBy );
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/registeredby/")
.queryParam("dsId",id)
.queryParam("registeredBy", registeredBy)
.build()
.encode();
restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
private Repository setRepositoryFeatures(String datatype, Repository repository) {
//TODO update map
repository.setCountryCode(countriesMap.get(repository.getCountryName()));
repository.setActivationId(UUID.randomUUID().toString());
// repo.setRegisteredBy((String) session.get(LocalVocabularies.loggedInField));
if (datatype.equals("opendoar") || datatype.equals("re3data")) {
repository.setProvenanceActionClass("sysimport:crosswalk:entityregistry");
} else if (datatype.equals("journal")) {
repository.setProvenanceActionClass("user:insert");
repository.setCollectedFrom("infrastruct_::openaire");
if (repository.getIssn() != null && repository.getIssn().length() == 0)
repository.setIssn(com.unboundid.util.Base64.encode(repository.getOfficialName()).substring(0, 8));
repository.setId("openaire____::issn" + repository.getIssn());
repository.setNamespacePrefix("issn" + repository.getIssn());
} else if (datatype.equals("aggregator")) {
repository.setProvenanceActionClass("user:insert");
repository.setCollectedFrom("infrastruct_::openaire");
repository.setId("openaire____::" + com.unboundid.util.Base64.encode(repository.getOfficialName()));
repository.setNamespacePrefix(Normalizer.normalize(repository.getOfficialName().toLowerCase().replace(" ", "_"), Normalizer.Form.NFD).replaceAll("[^a-zA-Z0-9]", ""));
if (repository.getNamespacePrefix().length() > 12) {
repository.setNamespacePrefix(repository.getNamespacePrefix().substring(0, 12));
} else {
while (repository.getNamespacePrefix().length() < 12)
repository.setNamespacePrefix(repository.getNamespacePrefix().concat("_"));
}
}
return repository;
}
private void updateInterface(String datatype,RepositoryInterface iFace) {
//TODO call update base url
//((DatasourceManagerService) this.dmService.getService()).updateBaseUrl(repo.getId(), iFace.getId(), iFace.getBaseUrl());
if (!iFace.getAccessSet().isEmpty()) {
LOGGER.debug("set not empty: " + iFace.getAccessSet());
//TODO call update method for access params
// ((DatasourceManagerService) this.dmService.getService()).updateAccessParam(repo.getId(), iFace.getId(), "set", iFace.getAccessSet(), false);
} else {
//TODO call deleteAccessParamOrExtraField
//((DatasourceManagerService) this.dmService.getService()).deleteAccessParamOrExtraField(repo.getId(), iFace.getId(), "set");
}
//TODO update content description
//((DatasourceManagerService) this.dmService.getService()).updateContentDescription(repo.getId(), iFace.getId(), "metadata");
if (datatype.equals("re3data")) {
//TODO call update access params
// ((DatasourceManagerService) this.dmService.getService()).updateAccessParam(repo.getId(), iFace.getId(), "format", "oai_datacite", false);
iFace.setAccessFormat("oai_datacite");
} else {
//TODO call update access params
//((DatasourceManagerService) this.dmService.getService()).updateAccessParam(repo.getId(), iFace.getId(), "format", "oai_dc", false);
iFace.setAccessFormat("oai_dc");
}
}
private RepositoryInterface createRepositoryInterface(Repository repo, RepositoryInterface iFace, String datatype) {
iFace.setContentDescription("metadata");
iFace.setCompliance("UNKNOWN");
if (datatype.equals("re3data")) {
iFace.setAccessFormat("oai_datacite");
} else {
iFace.setAccessFormat("oai_dc");
}
if (repo.getDatasourceClass() != null && !repo.getDatasourceClass().isEmpty()) {
iFace.setTypology(repo.getDatasourceClass());
} else if (datatype.equalsIgnoreCase("journal")) {
iFace.setTypology("pubsrepository::journal");
} else if (datatype.equalsIgnoreCase("aggregator")) {
iFace.setTypology("aggregator::pubsrepository::unknown");
} else if (datatype.equalsIgnoreCase("opendoar")) {
iFace.setTypology("pubsrepository::unknown");
} else if (datatype.equalsIgnoreCase("re3data")) {
iFace.setTypology("datarepository::unknown");
}
iFace.setRemovable(true);
iFace.setAccessProtocol("oai");
iFace.setMetadataIdentifierPath("//*[local-name()='header']/*[local-name()='identifier']");
// iFace.setId("api_________::" + repo.getId() + "::" + UUID.randomUUID().toString().substring(0, 8));
if (iFace.getAccessSet().isEmpty()) {
LOGGER.debug("set is empty: " + iFace.getAccessSet());
iFace.removeAccessSet();
}
return iFace;
}
private void storeRepository(Repository repository) throws JSONException {
Date utilDate = new Date();
Timestamp date = new Timestamp(utilDate.getTime());
repository.setDateOfCollection(date);
repository.setAggregator("OPENAIRE");
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/add/")
.build()
.encode();
String json_repository = Converter.repositoryObjectToJson(repository);
HttpEntity<String> httpEntity = new HttpEntity <String> (json_repository,httpHeaders);
restTemplate.postForObject(uriComponents.toUri(),httpEntity,String.class);
}
@Override
public void deleteRepositoryInterface(@PathVariable("id") String id){
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/api/")
.path("/{id}/")
.build().expand(id).encode();
restTemplate.delete(uriComponents.toUri());
}
@Override
public RepositoryInterface addRepositoryInterface(@RequestParam("datatype") String datatype,
@RequestParam("repoId") String repoId,
@RequestBody RepositoryInterface repositoryInterface) throws JSONException {
/* JSONObject json_params = new JSONObject(params);
// LOGGER.debug(params);
//TODO iFace parameter from gui. Object to json
String datatype = json_params.getString("datatype");
String repoId = json_params.getString("repoId");
String json_iFace = json_params.getString("iFace");
RepositoryInterface iFace = null;
ObjectMapper mapper = new ObjectMapper();
try {
iFace = mapper.readValue(json_iFace, RepositoryInterface.class);
} catch (Exception e1) {
LOGGER.debug("Error parsing repository interface ", e1);
}*/
return registerRepositoryInterface(repoId,repositoryInterface,datatype);
}
private RepositoryInterface registerRepositoryInterface(String repoId, RepositoryInterface iFace, String datatype) {
Repository e = null;
try {
e = this.getRepositoryById(repoId);
iFace = createRepositoryInterface(e,iFace,datatype);
ObjectMapper mapper = new ObjectMapper();
String json_interface = Converter.repositoryInterfaceObjectToJson(e,iFace);
LOGGER.debug("iFace equals -> " + json_interface);
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/api/add/")
.build()
.encode();
HttpEntity<String> httpEntity = new HttpEntity <String> (json_interface,httpHeaders);
restTemplate.postForObject(uriComponents.toUri(),httpEntity,String.class);
return iFace;
} catch (JSONException e1) {
LOGGER.debug("Error parsing json ",e1);
}
return null;
}
@Override
public List<String> getDnetCountries() {
LOGGER.debug("Getting dnet-countries!");
return Converter.readFile("countries.txt");
}
@Override
public List<String> getTypologies() {
return Converter.readFile("typologies.txt");
}
@Override
public List<Timezone> getTimezones() {
List<String> timezones = Converter.readFile("timezones.txt");
return Converter.toTimezones(timezones);
}
@Override
public String updateManagedStatus(@RequestParam(value = "id") String id,
@RequestParam(value = "managed") String managed) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/manage/")
.queryParam("id",id)
.queryParam("managed",managed)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public String updateEnglishName(@RequestParam(value = "id") String id,
@RequestParam(value = "officialName") String officialName,
@RequestParam(value = "englishname") String englishName) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/name/")
.queryParam("dsId",id)
.queryParam("officialname",officialName)
.queryParam("englishname",englishName)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public String updateLatitude(@RequestParam(value = "id") String id,
@RequestParam(value = "latitude") String latitude) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/latitude/")
.queryParam("dsId",id)
.queryParam("latitude",latitude)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public String updateLongitude(@RequestParam(value = "id") String id,
@RequestParam(value = "longitude") String longitude) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/longitude/")
.queryParam("dsId",id)
.queryParam("longitude",longitude)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public String updateOfficialName(@RequestParam(value = "id") String id,
@RequestParam(value = "officialname") String officialname) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/officialname/")
.queryParam("dsId",id)
.queryParam("officialname",officialname)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public String updateTimezone(@RequestParam(value = "id") String id,
@RequestParam(value = "timezone") String timezone) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/timezone")
.queryParam("dsId",id)
.queryParam("timezone",timezone)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public String updateTypology(@RequestParam(value = "id") String id,
@RequestParam(value = "typology") String typology) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/typology")
.queryParam("dsId",id)
.queryParam("typology",typology)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public String updateLogoUrl(@RequestParam(value = "id") String id,
@RequestParam(value = "logoUrl") String logoUrl) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/logourl")
.queryParam("dsId",id)
.queryParam("logourl",logoUrl)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public String updatePlatform(String id, String platform) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/platform")
.queryParam("dsId",id)
.queryParam("platform",platform)
.build().encode();
return restTemplate.postForObject(uriComponents.toUri(), null,String.class);
}
@Override
public List<String> getUrlsOfUserRepos(@PathVariable("user_email") String userEmail,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/api/baseurl/")
.path("/{page}/{size}")
.build().expand(page,size).encode();
RequestFilter requestFilter = new RequestFilter();
requestFilter.setRegisteredby(userEmail);
return Arrays.asList(restTemplate.postForObject(uriComponents.toUri(),requestFilter, String[].class));
}
@Override
public List<String> getDatasourceVocabularies(@PathVariable("mode") String mode) {
List<String> resultSet = new ArrayList<>();
for (Map.Entry<String, String> entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) {
if (mode.equalsIgnoreCase("aggregator")) {
if (entry.getKey().contains("aggregator"))
resultSet.add(entry.getValue());
} else if (mode.equalsIgnoreCase("journal")) {
if (entry.getKey().contains("journal"))
resultSet.add(entry.getValue());
} else if (mode.equalsIgnoreCase("opendoar")) {
if (entry.getKey().contains("pubsrepository"))
resultSet.add(entry.getValue());
} else if (mode.equalsIgnoreCase("re3data")) {
if (entry.getKey().contains("datarepository"))
resultSet.add(entry.getValue());
}
}
return resultSet;
}
private Vocabulary getVocabulary(String vocName) {
if (!vocabularyMap.containsKey(vocName)) {
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT));
}
return vocabularyMap.get(vocName);
}
@Override
public Map<String, String> getCompatibilityClasses(@PathVariable("mode") String 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();
boolean foundData = false;
for (Map.Entry<String, String> entry : compatibilityClasses.entrySet()) {
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$")) {
retMap.put(entry.getKey(), entry.getValue());
foundData = true;
}
} else {
if (entry.getKey().matches("^openaire[1-9].0$") || entry.getKey().equals("driver"))
retMap.put(entry.getKey(), entry.getValue());
}
}
//TODO TO BE REMOVED WHEN VOCABULARIES ARE UPDATED
if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA) && !foundData)
retMap.put("openaire2.0_data", "OpenAIRE Data (funded, referenced datasets)");
return retMap;
}
@Override
public Map<String, String> getDatasourceClasses(@PathVariable("mode") String mode) {
LOGGER.debug("Getting datasource classes for mode: " + mode);
Map<String, String> retMap = new HashMap<String, String>();
for (Map.Entry<String, String> entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) {
if (mode.equalsIgnoreCase("aggregator")) {
if (entry.getKey().contains("aggregator"))
retMap.put(entry.getKey(), entry.getValue());
} else if (mode.equalsIgnoreCase("journal")) {
if (entry.getKey().contains("journal"))
retMap.put(entry.getKey(), entry.getValue());
} else if (mode.equalsIgnoreCase("opendoar")) {
if (entry.getKey().contains("pubsrepository"))
retMap.put(entry.getKey(), entry.getValue());
} else if (mode.equalsIgnoreCase("re3data")) {
if (entry.getKey().contains("datarepository"))
retMap.put(entry.getKey(), entry.getValue());
}
}
return retMap;
}
@Override
public String getCountryName(String countryCode) {
return inverseCountriesMap.get(countryCode);
}
@Override
public MetricsInfo getMetricsInfoForRepository(@PathVariable("repoId") String repoId) throws RepositoryServiceException {
try {
MetricsInfo metricsInfo = new MetricsInfo();
metricsInfo.setDiagramsBaseURL(this.usageStatisticsDiagramsBaseURL);
metricsInfo.setMetricsNumbers(getMetricsNumbers(getOpenAIREId(repoId)));
return metricsInfo;
} catch (Exception e) {
LOGGER.error("Error while getting metrics info for repository: ", e);
//emailUtils.reportException(e);
throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
}
}
private MetricsNumbers getMetricsNumbers(String openAIREID) throws BrokerException {
//build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usageStatisticsNumbersBaseURL + openAIREID + "/clicks");
//create new template engine
RestTemplate template = new RestTemplate();
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
ResponseEntity<MetricsNumbers> resp;
try {
//communicate with endpoint
resp = template.exchange(
builder.build().encode().toUri(),
HttpMethod.GET,
null,
new ParameterizedTypeReference<MetricsNumbers>() {
});
} catch (RestClientException e) {
throw e;
}
return resp.getBody();
}
private String getOpenAIREId(String repoId) {
if (repoId != null && repoId.contains("::")) {
return repoId.split("::")[0] + "::" + DigestUtils.md5Hex(repoId.split("::")[1]);
}
return null;
}
private UriComponents searchDatasource(String page,String size){
return UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/search/")
.path("/{page}/{size}/")
.queryParam("requestSortBy","id")
.queryParam("order","ASCENDING")
.build().expand(page, size).encode();
}
}

View File

@ -1,23 +0,0 @@
/*
package eu.dnetlib.repo.manager.service.controllers;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@RestController
@RequestMapping(value = "/user")
@Api(description = "User API", tags = {"user"})
public interface UserApi {
@RequestMapping(value = "/login" , method = RequestMethod.GET)
void login(HttpServletRequest req,
HttpServletResponse resp);
}
*/

View File

@ -1,27 +0,0 @@
/*
package eu.dnetlib.repo.manager.service.controllers;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class UserApiImpl implements UserApi {
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
.getLogger(UserApiImpl.class);
@Value("${oidc.issuer}")
private String oidc_issuer;
@Override
public void login(HttpServletRequest req,
HttpServletResponse resp) {
LOGGER.debug(oidc_issuer);
resp.setStatus(HttpServletResponse.SC_FOUND);
resp.setHeader("Location", oidc_issuer);
}
}
*/

View File

@ -1,64 +0,0 @@
package eu.dnetlib.repo.manager.service.controllers;
import eu.dnetlib.api.functionality.ValidatorServiceException;
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.shared.InterfaceInformation;
import eu.dnetlib.repo.manager.shared.ValidationServiceException;
import io.swagger.annotations.Api;
import org.json.JSONException;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping(value = "/validator")
@Api(description = "Validator API", tags = {"validator"})
public interface ValidatorApi {
@RequestMapping(value = "/submitJobForValidation",method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE )
@ResponseBody
void submitJobForValidation(JobForValidation jobForValidation);
@RequestMapping(value = "/reSubmitJobForValidation/{jobId}",method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE )
@ResponseBody
void reSubmitJobForValidation(String jobId) throws JSONException;
@RequestMapping(value = "/getRuleSets/{mode}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<RuleSet> getRuleSets(String mode);
@RequestMapping(value = "/getSetsOfRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<String> getSetsOfRepository(String url);
@RequestMapping(value = "/identifyRepository" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
boolean identifyRepo(String url);
@RequestMapping(value = "/getRuleSet/{acronym}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
RuleSet getRuleSet(String acronym);
@RequestMapping(value = "/getStoredJobsNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
List<StoredJob> getStoredJobsNew(String user,
String jobType,
String offset,
String limit,
String dateFrom,
String dateTo,
String validationStatus) throws ValidatorServiceException;
@RequestMapping(value = "/getStoredJobsTotalNumberNew" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
int getStoredJobsTotalNumberNew(String user, String jobType, String validationStatus) throws ValidatorServiceException;
@RequestMapping(value = "/getInterfaceInformation/" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
InterfaceInformation getInterfaceInformation(String baseUrl) throws ValidationServiceException;
}

View File

@ -0,0 +1,48 @@
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

@ -0,0 +1,47 @@
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

@ -0,0 +1,44 @@
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

@ -0,0 +1,48 @@
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

@ -0,0 +1,52 @@
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

@ -0,0 +1,49 @@
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

@ -0,0 +1,45 @@
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

@ -0,0 +1,44 @@
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

@ -0,0 +1,43 @@
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,56 +0,0 @@
/*
package eu.dnetlib.repo.manager.service.utils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
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 javax.annotation.PostConstruct;
import java.util.logging.Logger;
@Configuration
@EnableRedisHttpSession
@PropertySource(value = { "classpath:eu/dnetlib/repo/manager/service/application.properties", "classpath:application.properties"} )
@ComponentScan(basePackages = "eu.dnetlib.repo.manager")
public class Config {
private static Logger LOGGER = Logger.getLogger(String.valueOf(Config.class));
@Value("${redis.host}")
private String host;
@Value("${redis.port:6379}")
private String port;
@Value("${redis.password:#{null}}")
private String password;
@PostConstruct
private void init(){
LOGGER.info(host);
}
@Bean
public LettuceConnectionFactory connectionFactory() {
LOGGER.info(String.format("Redis connection listens to %s:%s",host,port));
LettuceConnectionFactory factory = new LettuceConnectionFactory(host,Integer.parseInt(port));
if(password != null) factory.setPassword(password);
return factory;
}
@Bean
public CookieSerializer cookieSerializer() {
DefaultCookieSerializer serializer = new DefaultCookieSerializer();
serializer.setCookieName("SESSION"); // <1>
serializer.setCookiePath("/"); // <2>
return serializer;
}
}
*/

View File

@ -1,18 +0,0 @@
package eu.dnetlib.repo.manager.service.utils;
import eu.dnetlib.domain.data.PiwikInfo;
import eu.dnetlib.domain.functionality.UserProfile;
public interface EmailUtils {
void reportException(Exception exception);
void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception;
void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception;
void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) throws Exception;
void sendUserMetricsEnabled(PiwikInfo piwikInfo) throws Exception;
}

View File

@ -1,38 +0,0 @@
/*
package eu.dnetlib.repo.manager.service.utils;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class FrontEndLinkURIAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
private String frontEndURI;
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
OIDCAuthenticationToken authOIDC = (OIDCAuthenticationToken) authentication;
Cookie sessionCookie = new Cookie("currentUser", authOIDC.getSub());
int expireSec = -1;
sessionCookie.setMaxAge(expireSec);
sessionCookie.setPath("/");
response.addCookie(sessionCookie);
response.sendRedirect(frontEndURI);
}
public String getFrontEndURI() {
return frontEndURI;
}
public void setFrontEndURI(String frontEndURI) {
this.frontEndURI = frontEndURI;
}
}
*/

View File

@ -2,6 +2,7 @@ package eu.dnetlib.repo.manager.shared;
import com.google.gwt.user.client.rpc.IsSerializable;
import java.util.Calendar;
import java.util.Date;
public class AggregationDetails implements IsSerializable{
@ -11,6 +12,7 @@ public class AggregationDetails implements IsSerializable{
private Date date;
private int numberOfRecords;
private String collectionMode;
private Boolean indexedVersion;
public AggregationDetails() {
}
@ -46,4 +48,18 @@ public class AggregationDetails implements IsSerializable{
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

@ -2,6 +2,8 @@ package eu.dnetlib.repo.manager.shared.broker;
import com.google.gwt.user.client.rpc.IsSerializable;
import java.util.Date;
/**
* Created by stefanos on 10-Mar-17.
*/
@ -11,6 +13,8 @@ public class SimpleSubscriptionDesc implements IsSerializable {
private String datasource;
private String topic;
private long count;
private Date creationDate;
private Date lastNotificationDate;
public SimpleSubscriptionDesc() {
}
@ -54,4 +58,19 @@ public class SimpleSubscriptionDesc implements IsSerializable {
this.count = count;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Date getLastNotificationDate() {
return lastNotificationDate;
}
public void setLastNotificationDate(Date lastNotificationDate) {
this.lastNotificationDate = lastNotificationDate;
}
}

View File

@ -25,6 +25,8 @@ public class Subscription implements IsSerializable {
private Date lastNotificationDate;
private Date creationDate;
private String conditions;
private List<MapConditions> conditionsAsList;
@ -96,5 +98,12 @@ public class Subscription implements IsSerializable {
this.conditionsAsList = conditionsAsList;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
}

View File

@ -1,16 +1,23 @@
package eu.dnetlib.repo.manager.service.utils;
package eu.dnetlib.repo.manager.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface;
import eu.dnetlib.repo.manager.shared.*;
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
import eu.dnetlib.repo.manager.shared.AggregationDetails;
import eu.dnetlib.repo.manager.shared.Timezone;
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 java.io.*;
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.*;
@ -18,83 +25,75 @@ import java.util.*;
public class Converter {
private static final Logger LOGGER = Logger.getLogger(Converter.class);
public static Repository jsonToRepositoryObject(JSONObject repositoryObject) throws JSONException {
Repository repository = new Repository();
JSONObject datasource = repositoryObject.getJSONObject("datasource");
if( datasource.equals(null))
return null;
repository.setActivationId(datasource.get("activationId").toString());
repository.setAggregator(datasource.get("aggregator").toString());
// repository.setCertificates(datasource.get("certificates").toString());
// repository.setCitationGuidelineUrl(datasource.get("citationguidelineurl").toString());
repository.setCollectedFrom( datasource.get("collectedfrom").toString());
//if( datasource.equals(null))
// return null;
repository.setContactEmail(datasource.get("contactemail").toString());
if(repository.getContactEmail().equals("null"))
repository.setContactEmail("");
// repository.setDatabaseAccessRestriction(datasource.get("databaseaccessrestriction").toString());
// repository.setDatabaseAccessType(datasource.get("databaseaccesstype").toString());
// repository.setDataUploadRestriction(datasource.get("datauploadrestriction").toString());
// repository.setDataUploadType(datasource.get("datauploadtype").toString());
repository.setDateOfCollection(convertStringToDate( datasource.get("dateofcollection").toString()));
repository.setDateOfValidation(convertStringToDate( datasource.get("dateofvalidation").toString()));
repository.setDescription(datasource.get("description").toString());
if(repository.getDescription().equals("null"))
repository.setDescription("");
repository.setEissn(datasource.get("eissn").toString());
repository.setId(datasource.get("id").toString());
repository.setOfficialName(datasource.get("officialname").toString());
repository.setEnglishName( datasource.get("englishname").toString());
if(repository.getEnglishName().equals("null"))
repository.setEnglishName("");
repository.setId(datasource.get("id").toString());
repository.setIssn(datasource.get("issn").toString());
repository.setOdLanguages(datasource.get("languages").toString());
repository.setLatitude( toDouble(datasource.get("latitude").toString()));
repository.setLissn(datasource.get("lissn").toString());
repository.setWebsiteUrl(datasource.get("websiteurl").toString());
if(repository.getWebsiteUrl().equals("null"))
repository.setWebsiteUrl("");
repository.setLogoUrl(datasource.get("logourl").toString());
if(repository.getLogoUrl().equals("null"))
repository.setLogoUrl("");
repository.setContactEmail(datasource.get("contactemail").toString());
if(repository.getContactEmail().equals("null"))
repository.setContactEmail("");
repository.setLatitude( toDouble(datasource.get("latitude").toString()));
repository.setLongitude(toDouble(datasource.get("longitude").toString()));
//datasource.get("managed");
// repository.setMissionStatementUrl(datasource.get("missionstatementurl").toString());
repository.setNamespacePrefix(datasource.get("namespaceprefix").toString());
// repository.setOdContentTypes(datasource.get("od_contenttypes").toString());
repository.setOfficialName(datasource.get("officialname").toString());
if(repository.getOfficialName().equals("null"))
repository.setOfficialName("");
// repository.setPidSystems(datasource.get("pidsystems").toString());
//datasource.get("platform");
// repository.setProvenanceActionClass( datasource.get("provenanceaction").toString());
// repository.setQualityManagementKind(datasource.get("qualitymanagementkind").toString());
repository.setRegisteredBy(datasource.get("registeredby").toString());
if(Objects.equals(repository.getRegisteredBy(),"null"))
repository.setRegistered(true);
// repository.setReleaseEndDate(convertStringToDate(datasource.get("releaseenddate").toString()));
// repository.setReleaseStartDate(convertStringToDate(datasource.get("releasestartdate").toString()));
// repository.setServiceProvider(Boolean.valueOf(datasource.get("serviceprovider").toString()));
//datasource.get("subjects");
Double timezone = toDouble(datasource.get("timezone").toString());
repository.setTimezone(timezone!=null?timezone:0.0);
repository.setNamespacePrefix(datasource.get("namespaceprefix").toString());
repository.setOdLanguages(datasource.get("languages").toString());
repository.setDateOfValidation(convertStringToDate( datasource.get("dateofvalidation").toString()));
/* typology -> platform
* datasource class -> typology */
repository.setTypology(datasource.get("platform").toString());
// repository.setVersioning(Boolean.valueOf(datasource.get("versioning").toString()));
repository.setWebsiteUrl(datasource.get("websiteurl").toString());
if(repository.getTypology().equals("null"))
repository.setTypology("");
repository.setDatasourceClass(datasource.get("typology").toString());
repository.setDateOfCollection(convertStringToDate( datasource.get("dateofcollection").toString()));
repository.setActivationId(datasource.get("activationId").toString());
repository.setDescription(datasource.get("description").toString());
if(repository.getDescription().equals("null"))
repository.setDescription("");
repository.setIssn(datasource.get("issn").toString());
repository.setLissn(datasource.get("lissn").toString());
if(repository.getLissn().equals("null"))
repository.setLissn("");
repository.setEissn(datasource.get("eissn").toString());
if(repository.getEissn().equals("null"))
repository.setEissn("");
repository.setRegisteredBy(datasource.get("registeredby").toString());
/* managed field */
repository.setRegistered(Boolean.parseBoolean(datasource.get("managed").toString()));
//subjects
repository.setAggregator(datasource.get("aggregator").toString());
repository.setCollectedFrom(datasource.get("collectedfrom").toString());
//TODO change organization to list
JSONArray organizations = ((JSONArray)datasource.get("organizations"));
if(organizations.length() != 0) {
@ -103,23 +102,11 @@ public class Converter {
repository.setCountryCode(countryCode);
}
String collectedFrom = datasource.get("collectedfrom").toString();
//TODO check data consistency
String type = "UNKNOWN";
if (collectedFrom.equalsIgnoreCase("openaire____::opendoar")) {
type = "opendoar";
} else if (collectedFrom.equalsIgnoreCase("openaire____::re3data")) {
type = "re3data";
} else if (collectedFrom.equalsIgnoreCase("infrastruct_::openaire")) {
type = "journal";
}
repository.setDatasourceType(type);
/* identities field */
return repository;
}
public static Date convertStringToDate(String date){
if(Objects.equals(date, "null"))
@ -150,6 +137,41 @@ public class Converter {
return Double.valueOf(number);
}
public static List<RepositorySnippet> jsonToRepositorySnippetList(JSONObject json) throws JSONException {
List<RepositorySnippet> resultSet = new ArrayList<>();
JSONArray rs = json.getJSONArray("datasourceInfo");
for(int i=0;i<rs.length();i++)
resultSet.add(jsonToRepositorySnippetObject( rs.getJSONObject(i)) );
return resultSet;
}
private static RepositorySnippet jsonToRepositorySnippetObject(JSONObject repositorySnippetObject) throws JSONException {
RepositorySnippet repositorySnippet = new RepositorySnippet();
// JSONObject datasource = repositorySnippetObject.getJSONObject("datasource");
repositorySnippet.setId(repositorySnippetObject.get("id").toString());
repositorySnippet.setOfficialname(repositorySnippetObject.get("officialname").toString());
repositorySnippet.setEnglishname( repositorySnippetObject.get("englishname").toString());
if(repositorySnippet.getEnglishname().equals("null"))
repositorySnippet.setEnglishname("");
repositorySnippet.setWebsiteurl(repositorySnippetObject.get("websiteurl").toString());
if(repositorySnippet.getWebsiteurl().equals("null"))
repositorySnippet.setWebsiteurl("");
repositorySnippet.setRegisteredby(repositorySnippetObject.get("registeredby").toString());
if(repositorySnippet.getRegisteredby().equals("null"))
repositorySnippet.setRegisteredby("");
return repositorySnippet;
}
public static List<Repository> jsonToRepositoryList(JSONObject json) throws JSONException {
List<Repository> resultSet = new ArrayList<>();
@ -172,16 +194,21 @@ public class Converter {
RepositoryInterface repositoryInterface = new RepositoryInterface();
repositoryInterface.setBaseUrl(repositoryInterfaceObject.get("baseurl").toString());
repositoryInterface.setContentDescription(repositoryInterfaceObject.get("contentdescription").toString());
repositoryInterface.setId(repositoryInterfaceObject.get("id").toString());
// repositoryInterface.setMetadataIdentifierPath(repositoryInterfaceObject.get("metadataIdentifierPath").toString());
repositoryInterface.setAccessProtocol(repositoryInterfaceObject.get("protocol").toString());
repositoryInterface.setContentDescription(repositoryInterfaceObject.get("contentdescription").toString());
repositoryInterface.setTypology(repositoryInterfaceObject.get("typology").toString());
repositoryInterface.setCompliance(repositoryInterfaceObject.get("compatibility").toString());
repositoryInterface.setLastCollectionDate(repositoryInterfaceObject.get("lastCollectionDate").toString());
repositoryInterface.setBaseUrl(repositoryInterfaceObject.get("baseurl").toString());
repositoryInterface.setRemovable(Boolean.parseBoolean(repositoryInterfaceObject.get("removable").toString()));
// repositoryInterface.setMetadataIdentifierPath(repositoryInterfaceObject.get("metadataIdentifierPath").toString());
repositoryInterface.setDesiredCompatibilityLevel(repositoryInterfaceObject.get("compatibility").toString());
//repositoryInterface.setActive(Boolean.parseBoolean(repositoryInterfaceObject.get("active").toString()));
repositoryInterface.setRemovable(Boolean.parseBoolean(repositoryInterfaceObject.get("removable").toString()));
repositoryInterface.setCompliance(repositoryInterfaceObject.get("compatibility").toString());
Map<String, String> accessParams = new HashMap<>();
Map<String, String> extraFields = new HashMap<>();
@ -192,74 +219,120 @@ public class Converter {
for(int i=0;i<apiparams.length();i++)
accessParams.put(apiparams.getJSONObject(i).getString("param"),apiparams.getJSONObject(i).getString("value"));
repositoryInterface.setAccessParams(accessParams);
return repositoryInterface;
}
public static String repositoryObjectToJson(Repository repository) throws JSONException {
public static String repositoryObjectToJson(Repository repository) throws JSONException, JsonProcessingException {
JSONObject jsonObject = new JSONObject();
jsonObject.put("activationId",repository.getActivationId());
jsonObject.put("aggregator",repository.getAggregator());
jsonObject.put("certificates",repository.getCertificates());
HashMap<String,Object> repositoryMap = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
repositoryMap.put("id",repository.getId());
repositoryMap.put("openaireId",getOpenaireId(repository.getId()));
repositoryMap.put("officialname",repository.getOfficialName());
repositoryMap.put("englishname",repository.getEnglishName());
repositoryMap.put("websiteurl",repository.getWebsiteUrl());
repositoryMap.put("logourl",repository.getLogoUrl());
repositoryMap.put("contactemail",repository.getContactEmail());
repositoryMap.put("longitude",repository.getLongitude().toString());
repositoryMap.put("latitude",repository.getLatitude().toString());
repositoryMap.put("timezone",repository.getTimezone());
repositoryMap.put("namespaceprefix",repository.getNamespacePrefix()!=null?repository.getNamespacePrefix():"");
repositoryMap.put("languages",repository.getOdLanguages()!=null?repository.getOdLanguages():"");
repositoryMap.put("dateofcollection",repository.getDateOfCollection()!=null?convertDateToString(repository.getDateOfCollection()):"");
/*
* typology -> platform
* datasource class -> typology
* */
repositoryMap.put("typology",repository.getDatasourceClass());
repositoryMap.put("platform",repository.getTypology());
repositoryMap.put("dateofvalidation",repository.getDateOfCollection()!=null?convertDateToString(repository.getDateOfCollection()):"");
repositoryMap.put("activationId",repository.getActivationId()!=null?repository.getActivationId():"");
repositoryMap.put("description",repository.getDescription());
repositoryMap.put("eissn",repository.getEissn()!=null?repository.getEissn():"");
repositoryMap.put("issn",repository.getIssn()!=null?repository.getIssn():"");
repositoryMap.put("lissn",repository.getLissn()!=null?repository.getLissn():"");
repositoryMap.put("registeredby",repository.getRegisteredBy());
repositoryMap.put("aggregator",repository.getAggregator()!=null?repository.getAggregator():"");
repositoryMap.put("collectedfrom",repository.getCollectedFrom()!=null?repository.getCollectedFrom():"");
repositoryMap.put("managed",repository.isRegistered());
Map<String,String> organization = new HashMap<>();
organization.put("legalname",repository.getOrganization());
organization.put("country",repository.getCountryCode());
organization.put("legalshortname","");
organization.put("websiteurl","");
organization.put("logourl","");
List organizations = new ArrayList();
organizations.add(organization);
repositoryMap.put("organizations",organizations);
//TODO check identitites
//Map<String,String> identity = new HashMap<>();
List identities = new ArrayList();
// identities.add(identities);
repositoryMap.put("identities",identities);
repositoryMap.put("subjects","");
//TODO check fields
/* jsonObject.put("certificates",repository.getCertificates());
jsonObject.put("citationguidelineurl",repository.getCitationGuidelineUrl());
jsonObject.put("collectedfrom",repository.getCollectedFrom());
jsonObject.put("contactemail",repository.getContactEmail());
jsonObject.put("databaseaccessrestriction",repository.getDatabaseAccessRestriction());
jsonObject.put("databaseaccesstype",repository.getDatabaseAccessType());
jsonObject.put("datauploadrestriction",repository.getDataUploadRestriction());
jsonObject.put("datauploadtype",repository.getDataUploadType());
jsonObject.put("dateofcollection",convertDateToString(repository.getDateOfCollection()));
jsonObject.put("dateofvalidation",convertDateToString(repository.getDateOfValidation()));
jsonObject.put("description",repository.getDescription());
jsonObject.put("eissn",repository.getEissn());
jsonObject.put("englishname",repository.getEnglishName());
jsonObject.put("id",repository.getId());
jsonObject.put("issn",repository.getIssn());
jsonObject.put("languages",repository.getOdLanguages());
jsonObject.put("latitude",repository.getLatitude().toString());
jsonObject.put("lissn",repository.getLissn());
jsonObject.put("logourl",repository.getLogoUrl());
jsonObject.put("longitude",repository.getLongitude().toString());
jsonObject.put("missionstatementurl",repository.getMissionStatementUrl());
jsonObject.put("namespaceprefix",repository.getNamespacePrefix());
jsonObject.put("od_contenttypes",repository.getOdContentTypes());
jsonObject.put("officialname",repository.getOfficialName());
jsonObject.put("officialname",repository.getOfficialname());
jsonObject.put("pidsystems",repository.getPidSystems());
jsonObject.put("provenanceaction",repository.getProvenanceActionClass());
jsonObject.put("qualitymanagementkind",repository.getQualityManagementKind());
jsonObject.put("registeredby",repository.getRegisteredBy());
jsonObject.put("releaseenddate",convertDateToString(repository.getReleaseEndDate()));
jsonObject.put("releasestartdate",convertDateToString(repository.getReleaseStartDate()));
jsonObject.put("serviceprovider",repository.getServiceProvider());
jsonObject.put("timezone",repository.getTimezone());
jsonObject.put("typology",repository.getTypology());
jsonObject.put("versioning",repository.getVersioning());
jsonObject.put("websiteurl",repository.getWebsiteUrl());
//datasource.get("managed");
//datasource.get("platform");
//datasource.get("subjects");
return jsonObject.toString();
//datasource.get("subjects");*/
return mapper.writeValueAsString(repositoryMap);
}
public static String repositoryInterfaceObjectToJson(Repository repository,RepositoryInterface repositoryInterface) throws JSONException {
JSONObject jsonObject = new JSONObject();
jsonObject.put("baseurl",repositoryInterface.getBaseUrl());
jsonObject.put("contentdescription",repositoryInterface.getContentDescription());
jsonObject.put("id",repositoryInterface.getId());
jsonObject.put("metadataIdentifierPath",repositoryInterface.getMetadataIdentifierPath());
jsonObject.put("protocol",repositoryInterface.getAccessProtocol());
jsonObject.put("datasource",repository.getId());
jsonObject.put("contentdescription",repositoryInterface.getContentDescription());
jsonObject.put("typology",repositoryInterface.getTypology());
jsonObject.put("compatibility",repositoryInterface.getDesiredCompatibilityLevel());
jsonObject.put("datasource",repository.getId());
jsonObject.put("metadataIdentifierPath",repositoryInterface.getMetadataIdentifierPath());
jsonObject.put("protocol",repositoryInterface.getAccessProtocol());
jsonObject.put("compatibilityOverride",repositoryInterface.getDesiredCompatibilityLevel());
jsonObject.put("lastCollectionTotal","");
jsonObject.put("lastCollectionDate",repositoryInterface.getLastCollectionDate());
jsonObject.put("lastAggregationTotal","");
jsonObject.put("lastAggregationDate","");
jsonObject.put("lastDownloadTotal","");
jsonObject.put("lastDownloadDate","");
jsonObject.put("baseurl",repositoryInterface.getBaseUrl());
jsonObject.put("removable",repositoryInterface.isRemovable());
jsonObject.put("active",repositoryInterface.isActive());
JSONArray apiparams = new JSONArray();
for(String param: repositoryInterface.getAccessParams().keySet()){
JSONObject jo = new JSONObject();
@ -267,19 +340,11 @@ public class Converter {
jo.put("value",repositoryInterface.getAccessParams().get(param));
apiparams.put(jo);
}
jsonObject.put("apiparam",apiparams);
jsonObject.put("apiParams",apiparams);
jsonObject.put("lastCollectionDate",repositoryInterface.getLastCollectionDate());
//jsonObject.put("lastCollectionMdid",repositoryInterface);
//jsonObject.put("lastCollectionTotal");
//jsonObject.put("lastDownloadDate");
// jsonObject.put("lastDownloadMdid");
// jsonObject.put("lastDownloadTotal");
// jsonObject.put("lastValidationJob");
//jsonObject.put("lastAggregationDate");
//jsonObject.put("lastAggregationMdid");
//jsonObject.put("lastAggregationTotal");
// jsonObject.put("metadataIdentifierPath",repositoryInterface.getMetadataIdentifierPath());
return jsonObject.toString();
}
@ -303,15 +368,16 @@ public class Converter {
}
public static List<AggregationDetails> getAggregationHistoryFromJson(JSONObject datasourceInfo) throws JSONException {
if(datasourceInfo.get("aggregationHistory").toString().equals("[]"))
return null;
JSONArray rs = new JSONArray(datasourceInfo.get("aggregationHistory").toString());
JSONArray rs;
List<AggregationDetails> aggregationDetailsList = new ArrayList<>();
for(int i=0;i<rs.length();i++)
aggregationDetailsList.add(jsonToAggregationDetails(rs.getJSONObject(i)));
if (datasourceInfo.get("aggregationHistory") != null && !datasourceInfo.get("aggregationHistory").toString().equals("null")) {
rs = new JSONArray(datasourceInfo.get("aggregationHistory").toString());
for (int i = 0; i < rs.length(); i++)
aggregationDetailsList.add(jsonToAggregationDetails(rs.getJSONObject(i)));
}
return aggregationDetailsList;
}
@ -322,6 +388,8 @@ public class Converter {
aggregationDetails.setAggregationStage(aggregationObject.get("aggregationStage").toString());
if(aggregationObject.has("collectionMode"))
aggregationDetails.setCollectionMode(aggregationObject.get("collectionMode").toString());
if(aggregationObject.has("indexedVersion"))
aggregationDetails.setIndexedVersion(Boolean.parseBoolean(aggregationObject.get("indexedVersion").toString()));
aggregationDetails.setDate(convertStringToDate(aggregationObject.get("date").toString()));
aggregationDetails.setNumberOfRecords(Integer.parseInt(aggregationObject.get("numberOfRecords").toString()));
return aggregationDetails;
@ -352,4 +420,11 @@ public class Converter {
}
return tmz;
}
}
public static String getOpenaireId(String repositoryId) {
if (repositoryId != null && repositoryId.contains("::"))
return repositoryId.split("::")[0] + "::" + DigestUtils.md5Hex(repositoryId.split("::")[1]);
return null;
}
}

View File

@ -1,4 +1,4 @@
package eu.dnetlib.repo.manager.service.utils;
package eu.dnetlib.repo.manager.utils;
import org.apache.log4j.Logger;
import org.dom4j.io.DOMWriter;

View File

@ -1,50 +1,33 @@
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task" 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-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
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">
<!--<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-jaxws.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<import resource="classpath*:/cxf.xml"/>
<import resource="classpath*:/eu/dnetlib/repos/ehcacher/springContext-repos-ehcacher.xml"/>
<import resource="classpath*:/eu/dnetlib/soap/cxf/applicationContext-eprbuilders.xml"/>
<import resource="classpath*:/eu/dnetlib/clients/ws/springContext-locatorFactory.xml"/>
<import resource="classpath*:/eu/dnetlib/users/springContext-users-ldap.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"/>
<import resource="classpath*:/eu/dnetlib/repos/springContext-repos-dms-cached.xml"/>-->
<context:property-placeholder location="classpath*:/eu/**/application.properties" />
<context:annotation-config/>
<context:component-scan base-package="eu.dnetlib.repo.manager.service.*"/>
<tx:annotation-driven transaction-manager="txManager"/>
<bean class="eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader" id="propertyLoader">
<property name="order" value="2" />
<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" />
<bean class="eu.dnetlib.conf.PropertyFetcher"/>
</property>
</bean>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath*:/gr/**/springContext-*.properties</value>
<value>classpath*:/eu/**/springContext-*.properties</value>
<value>classpath*:/eu/dnetlib/repo/manager/service/email-texts.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>

View File

@ -0,0 +1,96 @@
infrastructure.name=integration
## Container properties
container.hostname=localhost
container.context=uoa-repository-manager-service
container.port = 8480
IS.url = https://dev-openaire.d4science.org/is/services
ISLookUpService.url = ${IS.url}/isLookUp
ISRegistryService.url = ${IS.url}/isRegistry
ISSNService.url = ${IS.url}/services/isSN
ValidatorService.url=http://localhost:8080/validator-service/services/validatorWebService
#ValidatorService.url=http://beta.services.openaire.eu/validator-service/services/validatorWebService
#ValidatorService.url=http://88.197.53.69:8080/validator-service/
services.provide.adminEmail=antleb@di.uoa.gr
## Broker Service
services.broker.url = http://broker1-dev-dnet.d4science.org
services.broker.port = 8080
services.broker.api = api/
services.broker.openaire = openaireBroker
#api.baseAddress=https://dev-openaire.d4science.org/openaire
api.baseAddress=http://beta.services.openaire.eu/openaire
service.repository-rest-api.baseUrl =http://${container.hostname}:${container.port}
services.repo-manager.baseUrl = http://${container.hostname}:${container.port}/${container.context}
transport.soap.baseAddress = http://${container.hostname}:${container.port}/${container.context}
transport.soap.force.local.address = false
services.repo-manager.adminEmail = antleb@di.uoa.gr
services.repo-manager.repository.testing.mode = false
services.repo-manager.deploy.environment = development
services.validator.mail.host = smtp.gmail.com
services.validator.mail.port = 465
services.validator.mail.fromAddress = no-reply@openaire.eu
services.validator.mail.replyToAddress = no-reply@openaire.eu
services.validator.mail.username = test.openaire@gmail.com
services.validator.mail.password = ^($*@$)*!$
services.validator.mail.authenticate = true
services.validator.mail.override = false
services.validator.mail.logonly = false
services.validator.mail.mode = ssl
services.validator.mail.debug = false
services.validator.mail.overrideEmail = antleb@di.uoa.gr
services.validator.mail.specialRecipients = antleb@di.uoa.gr
services.validator.repoRegistration.override = antleb@di.uoa.gr
repomanager.db.driverClassName = org.postgresql.Driver
repomanager.db.url = jdbc:postgresql://194.177.192.119:5432/repomanager
repomanager.db.username = dnet
repomanager.db.password = dnetPwd
services.repomanager.analyticsURL = http://analytics.openaire.eu/addsite.php?
topic_types.url = https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:topic_types.json
oidc.issuer = https://aai.openaire.eu/oidc/
oidc.id = 767422b9-5461-4807-a80a-f9a2072d3a7d
oidc.secret = AMQtGlbTXNjwjhF0st28LmM6V0XypMdaVS7tJmGuYFlmH36iIv4t7tVqYuLYrNPkhnZ_GPUJvhymBhFupdgb6aU
oidc.dev.home = http://localhost:8480/uoa-repository-manager-service/openid_connect_login
webapp.dev.front = http://localhost:4200/landing
##REDIS-AAI
redis.host=vereniki.athenarc.gr
redis.port=6379
redis.password=redis01041992s
aai.mode=develop
#redis.host = aleka.athenarc.gr
#redis.port = 6379
#redis.password =
#aai.mode = develop
#redis.host=localhost
#redis.port=6379
#redis.password=
#aai.mode=develop
services.repomanager.usageStatisticsDiagramsBaseURL = https://beta.openaire.eu/stats3/
services.repomanager.usageStatisticsNumbersBaseURL = https://beta.services.openaire.eu/usagestats/datasources/
services.repomanager.usagestats.adminEmail = antleb@di.uoa.gr
##SUSHI
services.repomanager.usagestats.sushiliteEndpoint = http://beta.services.openaire.eu/usagestats/sushilite/
##SEARCH API
search.api.baseAddress=https://beta.services.openaire.eu/search/v2/api
search.api.usagestats=https://services.openaire.eu/usagestats
search.api.usageEvents=http://beta.lbs.openaire.eu:8080/ajax/summary

View File

@ -1,179 +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:security="http://www.springframework.org/schema/security"
xmlns:util="http://www.springframework.org/schema/util" xmlns:task="http://www.springframework.org/schema/task"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.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"
default-autowire="byType">
<bean id="webexpressionHandler"
class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler"/>
<security:global-method-security pre-post-annotations="enabled" proxy-target-class="true"
authentication-manager-ref="authenticationManager"/>
<security:http auto-config="false" use-expressions="true"
disable-url-rewriting="true" entry-point-ref="authenticationEntryPoint"
pattern="/**">
<security:custom-filter before="PRE_AUTH_FILTER" ref="openIdConnectAuthenticationFilter" />
<security:logout />
</security:http>
<bean id="authenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint" >
<constructor-arg type="java.lang.String" value="/openid_connect_login"/>
</bean>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider ref="openIdConnectAuthenticationProvider" />
</security:authentication-manager>
<bean id="openIdConnectAuthenticationProvider" class="org.mitre.openid.connect.client.OIDCAuthenticationProvider">
<property name="authoritiesMapper">
<bean class="org.mitre.openid.connect.client.NamedAdminAuthoritiesMapper">
<property name="admins" ref="namedAdmins" />
</bean>
</property>
</bean>
<util:set id="namedAdmins" value-type="org.mitre.openid.connect.client.SubjectIssuerGrantedAuthority">
&lt;!&ndash;
This is an example of how quantity set up a user as an administrator: they'll be given ROLE_ADMIN in addition quantity ROLE_USER.
Note that having an administrator role on the IdP doesn't grant administrator access on this client.
These are values from the demo "openid-connect-server-webapp" project of MITREid Connect.
&ndash;&gt;
<bean class="org.mitre.openid.connect.client.SubjectIssuerGrantedAuthority">
<constructor-arg name="subject" value="90342.ASDFJWFA" />
<constructor-arg name="issuer" value="${oidc.issuer}" />
</bean>
</util:set>
<bean class="eu.dnetlib.repo.manager.service.utils.FrontEndLinkURIAuthenticationSuccessHandler" id="frontEndRedirect">
<property name="frontEndURI" value="${webapp.front}"/>
</bean>
&lt;!&ndash;
-
- The authentication filter
-
&ndash;&gt;
<bean id="openIdConnectAuthenticationFilter" class="org.mitre.openid.connect.client.OIDCAuthenticationFilter">
<property name="authenticationManager" ref="authenticationManager" />
<property name="issuerService" ref="staticIssuerService" />
<property name="serverConfigurationService" ref="staticServerConfigurationService" />
<property name="clientConfigurationService" ref="staticClientConfigurationService" />
<property name="authRequestOptionsService" ref="staticAuthRequestOptionsService" />
<property name="authRequestUrlBuilder" ref="plainAuthRequestUrlBuilder" />
<property name="authenticationSuccessHandler" ref="frontEndRedirect"/>
</bean>
&lt;!&ndash;
-
- Issuer Services: Determine which identity provider issuer is used.
-
&ndash;&gt;
&lt;!&ndash;
Static issuer service, returns the same issuer for every request.
&ndash;&gt;
<bean class="org.mitre.openid.connect.client.service.impl.StaticSingleIssuerService" id="staticIssuerService">
<property name="issuer" value="${oidc.issuer}" />
</bean>
<bean class="org.mitre.openid.connect.client.service.impl.HybridIssuerService" id="hybridIssuerService">
<property name="loginPageUrl" value="login" />
<property name="forceHttps" value="false" /> &lt;!&ndash; this default property forces the webfinger issuer URL quantity be HTTPS, turn off for development work &ndash;&gt;
</bean>
&lt;!&ndash;
Dynamic server configuration, fetches the server's information using OIDC Discovery.
&ndash;&gt;
<bean class="org.mitre.openid.connect.client.service.impl.StaticServerConfigurationService" id="staticServerConfigurationService">
<property name="servers">
<map>
<entry key="${oidc.issuer}">
<bean class="org.mitre.openid.connect.config.ServerConfiguration">
<property name="issuer" value="${oidc.issuer}" />
<property name="authorizationEndpointUri" value="${oidc.issuer}authorize" />
<property name="tokenEndpointUri" value="${oidc.issuer}token" />
<property name="userInfoUri" value="${oidc.issuer}userinfo" />
<property name="jwksUri" value="${oidc.issuer}jwk" />
<property name="revocationEndpointUri" value="${oidc.issuer}revoke" />
</bean>
</entry>
</map>
</property>
</bean>
&lt;!&ndash;
Static Client Configuration. Configures a client statically by storing configuration on a per-issuer basis.
&ndash;&gt;
<bean class="org.mitre.openid.connect.client.service.impl.StaticClientConfigurationService" id="staticClientConfigurationService">
<property name="clients">
<map>
<entry key="${oidc.issuer}">
<bean class="org.mitre.oauth2.model.RegisteredClient">
<property name="clientId" value="${oidc.id}" />
<property name="clientSecret" value="${oidc.secret}" />
<property name="scope">
<set value-type="java.lang.String">
<value>openid</value>
</set>
</property>
<property name="tokenEndpointAuthMethod" value="SECRET_BASIC" />
<property name="redirectUris">
<set>
<value>${webapp.home}</value>
</set>
</property>
</bean>
</entry>
</map>
</property>
</bean>
&lt;!&ndash;
-
- Auth request options service: returns the optional components of the request
-
&ndash;&gt;
<bean class="org.mitre.openid.connect.client.service.impl.StaticAuthRequestOptionsService" id="staticAuthRequestOptionsService">
<property name="options">
<map>
&lt;!&ndash; Entries in this map are sent as key-value parameters quantity the auth request &ndash;&gt;
&lt;!&ndash;
<entry key="display" value="page" />
<entry key="max_age" value="30" />
<entry key="prompt" value="none" />
&ndash;&gt;
</map>
</property>
</bean>
&lt;!&ndash;
-
- Authorization URL Builders: create the URL quantity redirect the user quantity for authorization.
-
&ndash;&gt;
&lt;!&ndash;
Plain authorization request builder, puts all options as query parameters on the GET request
&ndash;&gt;
<bean class="org.mitre.openid.connect.client.service.impl.PlainAuthRequestUrlBuilder" id="plainAuthRequestUrlBuilder" />
</beans>-->

View File

@ -1,113 +0,0 @@
infrastructure.name=integration
# Container properties
container.hostname = localhost
container.context=repoManager
container.port = 8080
# IS
ISLookUpService.url = http://node6.t.openaire.research-infrastructures.eu/is/services/isLookUp
ISRegistryService.url = http://node6.t.openaire.research-infrastructures.eu/is/services/isRegistry
ISSNService.url = http://node6.t.openaire.research-infrastructures.eu/is/services/isSN
#ISLookUpService.url = http://localhost:9190/is/services/isLookUp
#ISRegistryService.url = http://localhost:9190/is/services/isRegistry
#ISSNService.url = http://localhost:9190/is/services/isSN
# LDAP
services.users.ldap.address = 194.177.192.119
services.users.ldap.port = 389
services.users.ldap.username = cn=admin,dc=openaire,dc=eu
services.users.ldap.password = serenata
services.users.ldap.usersDN = ou=users,dc=openaire,dc=eu
#services.repo-manager.repository.testing.mode = true
ValidatorService.url=http://adonis.athenarc.gr:8080/validator-service/services/validatorWebService
# Broker Service
services.broker.url = http://broker1-dev-dnet.d4science.org
#services.broker.url = http://localhost
services.broker.port = 8080
#services.broker.port = 9090
services.broker.api = api/
services.broker.openaire = openaireBroker
#
# Configuration file classpath
configurationFileClassPath=classpath:application-context.xml
api.baseAddress=https://dev-openaire.d4science.org/openaire
service.repository-rest-api.baseUrl = http://localhost:8080
# the address where validator is running and is accessible from the controllers of the web
services.repo-manager.baseUrl = http://${container.hostname}:${container.port}/${container.context}
# base address for soap web services
transport.soap.baseAddress = http://${container.hostname}:${container.port}/${container.context}
transport.soap.force.local.address = false
# the email of the administrator
# he will receive all the automatic bug reports and feedback created
services.repo-manager.adminEmail = nikonas@di.uoa.gr
# if set to true, getRepositories will return dummy repositories
services.repo-manager.repository.testing.mode = false
services.repo-manager.deploy.environment = development
# the mailhost for the mail service
services.validator.mail.host = smtp.gmail.com
# the port where the mail service is running
services.validator.mail.port = 465
# the address that appears in the from field in the mails send by the validator
services.validator.mail.fromAddress = no-reply@openaire.eu
# the reply-to field value in the mails send by the validator
services.validator.mail.replyToAddress = no-reply@openaire.eu
# the username of the account used to login in the mail server
services.validator.mail.username = test.openaire@gmail.com
# the password of the account used to login in the mail server
services.validator.mail.password = ^($*@$)*!$
# if authentication should take place
# if set to false username and password is not needed
services.validator.mail.authenticate = true
# is set to yes then all mails will not be sent to their targets but to the address specified in services.validator.mail.overrideEmail
services.validator.mail.override = false
# if set to true then no mails are send, they are only logged as a debug message
services.validator.mail.logonly = false
# the mode used for the mails send by the validator
services.validator.mail.mode = ssl
# used by eu.dnetlib.utils.MailLibrary to control debuggin messages
services.validator.mail.debug = false
# if services.validator.mail.override is true then all mails will be send only to this address
services.validator.mail.overrideEmail = nikonas@di.uoa.gr
# a comma-seperated list of address that will receive all mails about validations and repo registrations
services.validator.mail.specialRecipients = nikonas@di.uoa.gr
# a comma-seperated list of addresses that have the ability to register repos without the need for validation and registration
services.validator.repoRegistration.override = nikonas@di.uoa.gr
repomanager.db.driverClassName = org.postgresql.Driver
repomanager.db.url = jdbc:postgresql://194.177.192.119:5432/repomanager
repomanager.db.username = dnet
repomanager.db.password = dnetPwd
services.repomanager.analyticsURL = http://analytics.openaire.eu/addsite.php?
topic_types.url = https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:topic_types.json
oidc.issuer = https://aai.openminted.eu/oidc/
oidc.id = 24e83176-1312-4ba3-bc0b-ffeebea1603e
oidc.secret = U_gLOupYu2trYIOwfxGgZkkZoOHG_zGfaViOUsXcZ7qVQuF1rcJeQYKIDX1TY3z27CIoHaqq9ht2rmAiUmBRYQ
webapp.home = http://localhost:8380/repomanager-service/openid_connect_login
webapp.front=http://localhost:8380/
redis.host = 83.212.101.85
#redis.port = 6379
#redis.password
services.repomanager.usageStatisticsDiagramsBaseURL = https://beta.openaire.eu/stats3/
services.repomanager.usageStatisticsNumbersBaseURL = https://beta.services.openaire.eu/usagestats/datasources/
services.repomanager.usagestats.adminEmail = repositoryusagestats@openaire.eu

View File

@ -0,0 +1,157 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.1.xsd"
default-autowire="byType">
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="268435456"/>
</bean>
<!--<bean id="webexpressionHandler"
class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler"/>-->
<security:global-method-security pre-post-annotations="enabled" proxy-target-class="true" authentication-manager-ref="authenticationManager"/>
<security:http auto-config="false" use-expressions="true"
disable-url-rewriting="true" entry-point-ref="authenticationEntryPoint"
pattern="/**">
<security:custom-filter before="PRE_AUTH_FILTER" ref="openIdConnectAuthenticationFilter" />
<security:logout logout-url="/openid_logout" invalidate-session="true"
delete-cookies="openAIRESession" logout-success-url="${webapp.dev.front}"/>
</security:http>
<bean id="authenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint" >
<constructor-arg type="java.lang.String" value="/openid_connect_login"/>
</bean>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider ref="openIdConnectAuthenticationProvider" />
</security:authentication-manager>
<bean id="openIdConnectAuthenticationProvider" class="org.mitre.openid.connect.client.OIDCAuthenticationProvider">
<property name="authoritiesMapper">
<bean class="eu.dnetlib.repo.manager.config.OpenAireProviderAuthoritiesMapper">
<constructor-arg name="userRoles" ref="userRoles"/>
</bean>
</property>
</bean>
<util:map id="userRoles">
<entry key="urn:geant:openaire.eu:group:Super+Administrator#aai.openaire.eu" value="ROLE_ADMIN"/>
<entry key="urn:geant:openaire.eu:group:Content+Provider+Dashboard+Administrator#aai.openaire.eu" value="ROLE_PROVIDE_ADMIN"/>
</util:map>
<bean class="eu.dnetlib.repo.manager.config.FrontEndLinkURIAuthenticationSuccessHandler" id="frontEndRedirect"
init-method="init">
<property name="frontEndURI" value="${webapp.dev.front}"/>
</bean>
<!--
-
- The authentication filter
-
-->
<bean id="openIdConnectAuthenticationFilter" class="org.mitre.openid.connect.client.OIDCAuthenticationFilter">
<property name="authenticationManager" ref="authenticationManager" />
<property name="issuerService" ref="staticIssuerService" />
<property name="serverConfigurationService" ref="staticServerConfigurationService" />
<property name="clientConfigurationService" ref="staticClientConfigurationService" />
<property name="authRequestOptionsService" ref="staticAuthRequestOptionsService" />
<property name="authRequestUrlBuilder" ref="plainAuthRequestUrlBuilder" />
<property name="authenticationSuccessHandler" ref="frontEndRedirect"/>
</bean>
<!--
Static issuer service, returns the same issuer for every request.
-->
<bean class="org.mitre.openid.connect.client.service.impl.StaticSingleIssuerService" id="staticIssuerService">
<property name="issuer" value="${oidc.issuer}" />
</bean>
<!--
Dynamic server configuration, fetches the server's information using OIDC Discovery.
-->
<bean class="org.mitre.openid.connect.client.service.impl.StaticServerConfigurationService" id="staticServerConfigurationService">
<property name="servers">
<map>
<entry key="${oidc.issuer}">
<bean class="org.mitre.openid.connect.config.ServerConfiguration">
<property name="issuer" value="${oidc.issuer}" />
<property name="authorizationEndpointUri" value="${oidc.issuer}authorize" />
<property name="tokenEndpointUri" value="${oidc.issuer}token" />
<property name="userInfoUri" value="${oidc.issuer}userinfo" />
<property name="jwksUri" value="${oidc.issuer}jwk" />
<property name="revocationEndpointUri" value="${oidc.issuer}revoke" />
</bean>
</entry>
</map>
</property>
</bean>
<!--
Static Client Configuration. Configures a client statically by storing configuration on a per-issuer basis.
-->
<bean class="org.mitre.openid.connect.client.service.impl.StaticClientConfigurationService" id="staticClientConfigurationService">
<property name="clients">
<map>
<entry key="${oidc.issuer}">
<bean class="org.mitre.oauth2.model.RegisteredClient">
<property name="clientId" value="${oidc.id}" />
<property name="clientSecret" value="${oidc.secret}" />
<property name="scope">
<set value-type="java.lang.String">
<value>openid</value>
</set>
</property>
<property name="tokenEndpointAuthMethod" value="SECRET_BASIC" />
<property name="redirectUris">
<set>
<value>${oidc.dev.home}</value>
</set>
</property>
</bean>
</entry>
</map>
</property>
</bean>
<!--
-
- Auth request options service: returns the optional components of the request
-
-->
<bean class="org.mitre.openid.connect.client.service.impl.StaticAuthRequestOptionsService" id="staticAuthRequestOptionsService">
<property name="options">
<map>
<!-- Entries in this map are sent as key-value parameters to the auth request -->
<!--
<entry key="display" value="page" />
<entry key="max_age" value="30" />
<entry key="prompt" value="none" />
-->
</map>
</property>
</bean>
<!--
Plain authorization request builder, puts all options as query parameters on the GET request
-->
<bean class="org.mitre.openid.connect.client.service.impl.PlainAuthRequestUrlBuilder" id="plainAuthRequestUrlBuilder" />
</beans>

View File

@ -1,54 +1,59 @@
<?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: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/context
http://www.springframework.org/schema/context/spring-context-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:META-INF/cxf/cxf-extension-soap.xml"/>-->
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-jaxws.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<import resource="classpath*:/cxf.xml"/>
<import resource="classpath*:/eu/dnetlib/repos/ehcacher/springContext-repos-ehcacher.xml"/>
<import resource="classpath*:/eu/dnetlib/soap/cxf/applicationContext-eprbuilders.xml"/>
<import resource="classpath*:/eu/dnetlib/clients/ws/springContext-locatorFactory.xml"/>
<import resource="classpath*:/eu/dnetlib/users/springContext-users-ldap.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"/>
<!--<import resource="classpath*:/eu/dnetlib/repos/springContext-repos-dms-cached.xml"/>-->
<context:property-placeholder location="classpath*:/eu/**/application.properties" />
<!--<import resource="classpath*:/gr/uoa/di/driver/app/springContext-registrator.xml"/>-->
<bean class="eu.dnetlib.repo.manager.service.config.CascadingPropertyLoader" id="propertyLoader">
<property name="order" value="2" />
<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" />
<bean class="eu.dnetlib.conf.PropertyFetcher"/>
</property>
</bean>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath*:/gr/**/springContext-*.properties</value>
<value>classpath*:/eu/**/springContext-*.properties</value>
<value>classpath*:/eu/dnetlib/repo/manager/service/email-texts.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>
@ -89,5 +94,6 @@
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
<bean class="eu.dnetlib.repo.manager.service.config.SwaggerConfig"/>
</beans>
<bean class="eu.dnetlib.repo.manager.config.SwaggerConfig"/>
</beans>

View File

@ -2,7 +2,7 @@ log4j.rootLogger = WARN, R
log4j.logger.eu.dnetlib = DEBUG
log4j.logger.eu.dnetlib.clients.data.datasourcemanager.ws.Converter = FATAL
log4j.logger.org.springframework = DEBUG, S
log4j.logger.org.springframework = INFO, S
log4j.additivity.org.springframework = false
log4j.logger.com.opensymphony.xwork2.ognl.OgnlValueStack = FATAL
@ -11,27 +11,35 @@ log4j.logger.com.opensymphony.xwork2.ObjectFactory = FATAL
log4j.logger.eu.dnetlib.repo.manager=DEBUG
log4j.appender.R=org.apache.log4j.RollingFileAppender
#log4j.appender.R.File=/var/log/dnet/repo-manager/repo-manager-gui.log
log4j.appender.R.File=/tmp/repo-manager-service.log
log4j.appender.R.File=/tmp/repository-service.log
#log4j.appender.R.File=/var/log/tomcat_dnet/8780/repository-service.log
log4j.appender.R.MaxFileSize=10MB
log4j.appender.R.MaxBackupIndex=10
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern= %d %p %t [%c] - %m%n
log4j.appender.S=org.apache.log4j.RollingFileAppender
#log4j.appender.S.File=/var/log/dnet/repo-manager/repo-manager-gui-spring.log
log4j.appender.S.File=/tmp/repo-manager-service-spring.log
log4j.appender.S.File=/tmp/repository-service-spring.log
#log4j.appender.S.File=/var/log/tomcat_dnet/8780/repository-service-spring.log
log4j.appender.S.MaxFileSize=10MB
log4j.appender.S.MaxBackupIndex=10
log4j.appender.S.layout=org.apache.log4j.PatternLayout
log4j.appender.S.layout.ConversionPattern= %d %p %t [%c] - %m%n
#org.apache.cxf.Logger=org.apache.cxf.common.logging.Log4jLogger
#log4j.rootLogger = WARN, R
#
#log4j.rootLogger=INFO, CONSOLE
#log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
#log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
#log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
#log4j.logger.org.springframework = DEBUG, S
#log4j.additivity.org.springframework = false
#
#log4j.logger.eu.dnetlib.repo.manager=DEBUG
#log4j.logger.com.opensymphony.xwork2.ognl.OgnlValueStack = FATAL
#log4j.logger.com.opensymphony.xwork2.ObjectFactory = FATAL
#
#log4j.logger.eu.dnetlib.repo.manager=DEBUG
#
#log4j.appender.R=org.apache.log4j.ConsoleAppender
#log4j.appender.R.layout=org.apache.log4j.PatternLayout
#log4j.appender.R.layout.ConversionPattern= %d %p %t [%c] - %m%n
#
#log4j.appender.S=org.apache.log4j.ConsoleAppender
#log4j.appender.S.layout=org.apache.log4j.PatternLayout
#log4j.appender.S.layout.ConversionPattern= %d %p %t [%c] - %m%n

View File

@ -1,16 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd"
>
<security:global-method-security pre-post-annotations="enabled" proxy-target-class="true"
authentication-manager-ref="authenticationManager">
</security:global-method-security>
<bean id="webexpressionHandler"
class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler"/>
<context:property-placeholder location="classpath*:/eu/**/application.properties" />
<context:annotation-config/>
<context:component-scan base-package="eu.dnetlib.repo.manager.service.controllers"/>
<mvc:annotation-driven/>
</beans:beans>
<mvc:annotation-driven />
</beans>

View File

@ -1,9 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd
http://xmlns.jcp.org/xml/ns/javaee "
version="3.1">
<web-app>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/aai-security.xml
</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>1000</param-value>
</context-param>
<context-param>
<param-name>log4jExposeWebAppRoot</param-name>
<param-value>false</param-value>
</context-param>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>throwExceptionIfNoHandlerFound</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>contextAttribute</param-name>
<param-value>org.springframework.web.servlet.FrameworkServlet.CONTEXT.spring</param-value>
</init-param>
</filter>
<filter>
<filter-name>CorsFilter</filter-name>
@ -27,45 +71,24 @@ http://xmlns.jcp.org/xml/ns/javaee "
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>1000</param-value>
</context-param>
<context-param>
<param-name>log4jExposeWebAppRoot</param-name>
<param-value>false</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<filter>
<filter-name>springSessionRepositoryFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSessionRepositoryFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
</web-app>

View File

@ -0,0 +1,72 @@
/*
package unitest;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.repo.manager.config.RepoManagerContextLoaderListener;
import org.apache.commons.lang.StringEscapeUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Map;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = RepoManagerContextLoaderListener.class)
public class PiwikTest {
String analyticsURL = "https://analytics.openaire.eu/addsite.php?";
@Test
public void enableMetricsRepo1(){
String officialName = "BỘ SƯU TẬP SỐ";
String repoWebsite = "http://www.vnulib.edu.vn:8000/dspace/";
enableMetrics(officialName, repoWebsite, analyticsURL);
}
@Test
public void enableMetricsRepo2(){
String officialName = "ILC4CLARIN repository of language resources and tools";
String repoWebsite = "https://dspace-clarin-it.ilc.cnr.it/repository/xmlui";
enableMetrics(officialName, repoWebsite, analyticsURL);
}
@Test
public void enableMetricsRepo3(){
String officialName = "ANSTO Publications Online";
String repoWebsite = "http://apo.ansto.gov.au/dspace/";
enableMetrics(officialName, repoWebsite, analyticsURL);
}
private void enableMetrics(String officialName, String repoWebsite, String analyticsURL) {
String url;
try {
url = analyticsURL + "siteName=" + URLEncoder.encode(officialName, "UTF-8") + "&url="
+ URLEncoder.encode(repoWebsite, "UTF-8");
url = StringEscapeUtils.escapeJava(url);
Map map = null;
String siteId = null;
URL u = new URL(url);
map = new ObjectMapper().readValue(u, Map.class);
if(map.get("value")!=null) {
siteId = map.get("value").toString();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}*/

View File

@ -0,0 +1,31 @@
//package unitest;
//
//import eu.dnetlib.repo.manager.config.RepoManagerContextLoaderListener;
//import eu.dnetlib.repo.manager.utils.OaiTools;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.springframework.test.context.ContextConfiguration;
//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
//
//@RunWith(SpringJUnit4ClassRunner.class)
//@ContextConfiguration(classes = RepoManagerContextLoaderListener.class)
////@WebAppConfiguration
//public class ValidatorTest {
//
//
// @Test
// public void identiFy(){
//
// String url = "https://repozitorij.srce.unizg.hr/oai";
//
//
// System.out.println("Identify repository with url : " + url);
// try {
// System.out.println(OaiTools.identifyRepository(url));
// } catch (Exception e) {
// System.out.println(e);
// }
// }
//
//
//}

View File

@ -0,0 +1,67 @@
<?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.*"/>
<tx:annotation-driven transaction-manager="txManager"/>
<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>
<bean id="repomanager.dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${repomanager.db.driverClassName}" />
<property name="url" value="${repomanager.db.url}" />
<property name="username" value="${repomanager.db.username}" />
<property name="password" value="${repomanager.db.password}" />
<property name="maxIdle" value="10" />
<property name="maxActive" value="100" />
<property name="maxWait" value="10000" />
<property name="validationQuery" value="SELECT 1;" />
<property name="testOnBorrow" value="true" />
<property name="testOnReturn" value="true" />
<property name="testWhileIdle" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="1200000" />
<property name="minEvictableIdleTimeMillis" value="1800000" />
<property name="numTestsPerEvictionRun" value="5" />
<property name="poolPreparedStatements" value="true" />
<property name="defaultAutoCommit" value="true" />
</bean>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="repomanager.dataSource"/>
</bean>
</beans>

View File

@ -0,0 +1,99 @@
<?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>
<bean id="repomanager.dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${repomanager.db.driverClassName}" />
<property name="url" value="${repomanager.db.url}" />
<property name="username" value="${repomanager.db.username}" />
<property name="password" value="${repomanager.db.password}" />
<property name="maxIdle" value="10" />
<property name="maxActive" value="100" />
<property name="maxWait" value="10000" />
<property name="validationQuery" value="SELECT 1;" />
<property name="testOnBorrow" value="true" />
<property name="testOnReturn" value="true" />
<property name="testWhileIdle" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="1200000" />
<property name="minEvictableIdleTimeMillis" value="1800000" />
<property name="numTestsPerEvictionRun" value="5" />
<property name="poolPreparedStatements" value="true" />
<property name="defaultAutoCommit" value="true" />
</bean>
<tx:annotation-driven transaction-manager="txManager"/>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="repomanager.dataSource"/>
</bean>
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
<bean class="eu.dnetlib.repo.manager.config.SwaggerConfig"/>
</beans>