Meerge dev-api to trunk ( -r50861:54841 )

This commit is contained in:
Panagiotis Kanakakis 2019-02-16 10:04:41 +00:00
parent 5038a00b8b
commit ef441e826c
71 changed files with 5616 additions and 351 deletions

10
Dockerfile Normal file
View File

@ -0,0 +1,10 @@
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/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"]

211
pom.xml
View File

@ -15,52 +15,6 @@
<packaging>jar</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>
@ -206,6 +166,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>
@ -230,7 +196,20 @@
<version>9.1-901.jdbc3</version>
</dependency>
<!--<dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.mitre</groupId>
<artifactId>openid-connect-client</artifactId>
<version>1.3.0</version>
@ -240,21 +219,147 @@
<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>
</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,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_PORTAL_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_PORTAL_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_PORTAL_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_PORTAL_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,203 @@
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 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 = "/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,55 @@
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 registeredby;
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;
}
}

View File

@ -0,0 +1,67 @@
package eu.dnetlib.repo.manager.domain;
import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class RequestFilter{
private String registeredby = null;
private String typology = null;
private String country = null;
private String id = null;
private String officialname = null;
private String collectedfrom = null;
public RequestFilter() {
}
public String getTypology() {
return typology;
}
public void setTypology(String typology) {
this.typology = typology;
}
public String getRegisteredby() {
return registeredby;
}
public void setRegisteredby(String registeredby) {
this.registeredby = registeredby;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
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 getCollectedfrom() {
return collectedfrom;
}
public void setCollectedfrom(String collectedfrom) {
this.collectedfrom = collectedfrom;
}
}

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

@ -0,0 +1,392 @@
package eu.dnetlib.repo.manager.service;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.domain.data.Repository;
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 org.json.JSONException;
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.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
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.io.InputStream;
import java.net.URL;
import java.util.*;
@Service("brokerService")
public class BrokerServiceImpl implements BrokerService {
@Autowired
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}")
private String apiPath;
@Value("${topic_types.url}")
private String topicsURL;
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
.getLogger(BrokerServiceImpl.class);
@Autowired
RestTemplate restTemplate ;
private HttpHeaders httpHeaders;
private HashMap<String,Term> topics = new HashMap<String, Term>();
@Autowired
private EmailUtils emailUtils;
@PostConstruct
private void initDnetTopicsMap() {
httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type", "application/json");
LOGGER.debug("Init dnet topics!");
InputStream is = null;
try {
is = new URL(topicsURL).openStream();
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(is);
for (JsonNode term : root.path("terms") )
topics.put(term.path("code").textValue(), parseTerm(term));
} catch (IOException e) {
LOGGER.debug("Exception on initDnetTopicsMap" , e);
emailUtils.reportException(e);
}
}
private Term parseTerm(JsonNode term) {
return new Term(term.path("englishName").textValue(),term.path("nativeName").textValue(),
term.path("encoding").textValue(),term.path("code").textValue());
}
@Override
public DatasourcesBroker getDatasourcesOfUser(String user,String includeShared,String includeByOthers) throws JSONException {
DatasourcesBroker ret = new DatasourcesBroker();
try {
ret.setDatasourcesOfUser(getDatasourcesOfUserType(getRepositoriesOfUser(user)));
//TODO fix bug when values are true
if (Boolean.parseBoolean(includeShared)) {
List<String> sharedDatasourceIds = new ArrayList<String>();
ret.setSharedDatasources(getDatasourcesOfUserType(getRepositoriesByIds(sharedDatasourceIds)));
}
if (Boolean.parseBoolean(includeByOthers)) {
ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(user)));
}
} catch (BrokerException e) {
LOGGER.debug("Exception on getDatasourcesOfUser" , e);
emailUtils.reportException(e);
}
return ret;
}
@Override
public List<BrowseEntry> getTopicsForDatasource(String datasourceName) throws BrokerException {
final String service = "/topicsForDatasource";
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
.queryParam("ds", datasourceName);
ResponseEntity<List<BrowseEntry>> resp;
try {
resp = restTemplate.exchange(
builder.build().encode().toUri(),
HttpMethod.GET,
null,
new ParameterizedTypeReference<List<BrowseEntry>>() {
});
} catch (RestClientException e) {
LOGGER.debug("Exception on getTopicsForDatasource" , e);
emailUtils.reportException(e);
throw new BrokerException(e);
}
return resp.getBody();
}
@Override
public EventsPage advancedShowEvents(String page,
String size,
AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException {
final String service = "/events/{page}/{pageSize}";
Map<String, Long> uriParams = new HashMap<>();
uriParams.put("page", Long.parseLong(page));
uriParams.put("pageSize", Long.parseLong(size));
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service);
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
advQueryObject.setPage(Long.parseLong(page));
HttpEntity<AdvQueryObject> entity = new HttpEntity<>(advQueryObject, httpHeaders);
ResponseEntity<EventsPage> resp;
try {
resp = restTemplate.exchange(
builder.buildAndExpand(uriParams).encode().toUri(),
HttpMethod.POST,
entity,
new ParameterizedTypeReference<EventsPage>() {
}
);
} catch (RestClientException e) {
LOGGER.debug("Exception on advancedShowEvents" , e);
emailUtils.reportException(e);
throw new BrokerException(e);
}
return resp.getBody();
}
private List<Tuple<BrowseEntry, String>> getDatasourcesOfUserType(List<Repository> repositories) throws BrokerException {
List<Tuple<BrowseEntry, String>> entries = new ArrayList<>();
for (Repository repo : repositories) {
BrowseEntry temp = new BrowseEntry();
temp.setValue(repo.getOfficialName());
temp.setSize(new Long(0));
for (BrowseEntry e : getTopicsForDatasource(repo.getOfficialName())) {
temp.setSize(temp.getSize() + e.getSize());
}
Tuple<BrowseEntry, String> tup = new Tuple<>(temp, repo.getLogoUrl());
entries.add(tup);
}
// sort the collection by the second field of the tuple which is size
Collections.sort(entries, new Comparator<Tuple<BrowseEntry, String>>() {
@Override
public int compare(Tuple<BrowseEntry, String> e1, Tuple<BrowseEntry, String> e2) {
return (int) (e2.getFirst().getSize().longValue() - e1.getFirst().getSize().longValue());
}
});
return entries;
}
private List<Repository> getRepositoriesOfUser(String userEmail) throws JSONException {
int page = 0;
int size = 50;
List<Repository> rs ;
List<Repository> resultSet = new ArrayList<>();
while (true){
rs = repoAPI.getRepositoriesOfUser(userEmail, String.valueOf(page), String.valueOf(size));
resultSet.addAll(rs);
page+=1;
if(rs.size() == 0) break;
}
return resultSet;
}
private List<Repository> getRepositoriesByIds(List<String> sharedDatasourceIds) {
return null;
}
@Override
public EventsPage showEvents(String datasourceName,
String topic,
String page,
String size) throws BrokerException, JSONException {
final String service = "/events";
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
.queryParam("ds", datasourceName)
.queryParam("topic", topic)
.path("/{page}/{size}/");
ResponseEntity<EventsPage> resp;
try {
resp = restTemplate.exchange(
builder.build().expand(page, size).encode().toUri(),
HttpMethod.GET,
null,
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(String userEmail)
throws BrokerException {
final String service = "/subscriptions";
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
.queryParam("email", userEmail);
LOGGER.debug(builder.build().encode().toUri());
ResponseEntity<Map<String, List<SimpleSubscriptionDesc>>> resp;
try {
resp = restTemplate.exchange(
builder.build().encode().toUri(),
HttpMethod.GET,
null,
new ParameterizedTypeReference<Map<String, List<SimpleSubscriptionDesc>>>() {
});
} catch (RestClientException e) {
LOGGER.debug("Exception on getSimpleSubscriptionsOfUser" , e);
emailUtils.reportException(e);
throw new BrokerException(e);
}
return resp.getBody();
}
@Override
public Subscription subscribe(OpenaireSubscription obj) throws BrokerException {
final String service = "/subscribe";
//build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service);
HttpEntity<OpenaireSubscription> entity = new HttpEntity<>(obj, httpHeaders);
//create new template engine
RestTemplate template = new RestTemplate();
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
ResponseEntity<Subscription> resp;
try {
//communicate with endpoint
resp = restTemplate.exchange(
builder.build().encode().toUri(),
HttpMethod.POST,
entity,
new ParameterizedTypeReference<Subscription>() {
});
} catch (RestClientException e) {
LOGGER.debug("Exception on OpenaireSubscription" , e);
emailUtils.reportException(e);
throw new BrokerException(e);
}
return resp.getBody();
}
@Override
public ResponseEntity<Object> unsubscribe(String subscriptionId) throws BrokerException {
final String service = "/subscriptions/" + subscriptionId;
//build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(apiPath + service);
try {
//communicate with endpoint
restTemplate.exchange(
builder.build().encode().toUri(),
HttpMethod.DELETE,
null,
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( String subscriptionId) throws BrokerException {
final String service = "/subscriptions/" + subscriptionId;
//build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(apiPath + service);
ResponseEntity<Subscription> resp;
try {
//communicate with endpoint
resp = restTemplate.exchange(
builder.build().encode().toUri(),
HttpMethod.GET,
null,
new ParameterizedTypeReference<Subscription>() {
});
} catch (RestClientException e) {
LOGGER.debug("Exception on getSubscription" , e);
emailUtils.reportException(e);
throw new BrokerException(e);
}
return resp.getBody();
}
@Override
public Map<String, Term> getDnetTopics() throws BrokerException {
return topics;
}
@Override
public EventsPage getNotificationsBySubscriptionId(String subscriptionId,
String page,
String size) throws BrokerException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(openairePath + "/notifications/")
.path("/{id}/{page}/{size}/")
.build().expand(subscriptionId,page, size).encode();
ResponseEntity<EventsPage> resp;
try {
resp = restTemplate.exchange(
uriComponents.toUri(),
HttpMethod.GET,
null,
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(String userEmail)
throws BrokerException {
Map<String, List<SimpleSubscriptionDesc>> simpleSubs = getSimpleSubscriptionsOfUser(userEmail);
Map<String,List<Subscription>> subs = new HashMap<>();
List<Subscription> subscriptions = null;
for(String s:simpleSubs.keySet()){
List<SimpleSubscriptionDesc> simpleSubscriptionDescs = simpleSubs.get(s);
for(SimpleSubscriptionDesc simpleSubscriptionDesc : simpleSubscriptionDescs) {
subscriptions = new ArrayList<>();
subscriptions.add(getSubscription(simpleSubscriptionDesc.getId()));
}
subs.put(s,subscriptions);
}
return subs;
}
}

View File

@ -0,0 +1,26 @@
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 sendUserRegistrationEmail(Repository repository, Authentication authentication) throws Exception;
void sendUserUpdateRepositoryEmail(Repository repository, Authentication authentication) throws Exception;
void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation) throws Exception;
}

View File

@ -0,0 +1,335 @@
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 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;
import java.util.ArrayList;
import java.util.List;
@Component("emailUtils")
public class EmailUtilsImpl implements EmailUtils {
private static Logger LOGGER = Logger.getLogger(EmailUtilsImpl.class);
private List<String> specialRecipients = new ArrayList<String>();
private boolean override = false, logonly = false;
private String overrideEmail = null, from = null;
@Autowired
private MailLibrary mailLibrary;
@Autowired
private CascadingPropertyLoader pLoader;
@Value("${services.repo-manager.baseUrl}")
private String baseUrl;
@Value("${services.repo-manager.adminEmail}")
private String adminEmail;
@Value("${services.repomanager.usagestats.adminEmail}")
private String usageStatsAdminEmail;
@PostConstruct
public void init(){
System.out.println("url -> " + this.baseUrl);
}
@Override
public void reportException(Exception exception) {
Writer writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
exception.printStackTrace(printWriter);
List<String> recipients = new ArrayList<String>();
try {
recipients.add(this.adminEmail);
String message = "An exception has occurred:\n"+writer.toString();
String subject = "Automatic Bug Report";
this.sendMail(recipients, subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error sending error report", e);
}
}
@Override
public void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception {
try {
String subject = "[OpenAIRE-Usage Statistics] New request to enable usage statistics";
String message = "Dear administrator,\n" +
"\n" +
"we have received a request to enable the OpenAIRE usage statistics for the following repository \n" +
"\n" +
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
"Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" +
"Piwik ID - " + piwikInfo.getSiteId() + "\n" +
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
"\n" +
"For more information about this request, go here: \n" +
this.baseUrl + "/admin/metrics\n" +
"\n" +
"Best,\n" +
"The OpenAIRE team";
this.sendMail(this.usageStatsAdminEmail, subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending request to enable metrics email to administrator: " + this.usageStatsAdminEmail, e);
throw e;
}
}
@Override
public void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception {
try {
String subject = "[OpenAIRE-Usage Statistics] Your request to enable usage statistics";
String message = "Dear " + piwikInfo.getRequestorName() + ",\n" +
"\n" +
"we have received your request to enable the OpenAIRE usage statistics for your repository\n" +
"\n" +
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
"Piwik ID - " + piwikInfo.getSiteId() + "\n" +
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
"\n" +
"In order to enable the usage statistics, you must install the OpenAIRE's tracking code in your repository software. " +
"OpenAIRE's usage statistics service tracking code is maintained on Github as a patch for various versions of DSpace " +
"(https://github.com/openaire/OpenAIRE-Piwik-DSpace) and as an Eprints plugin for version 3 " +
"(https://github.com/openaire/EPrints-OAPiwik). In case the platform is different from DSpace or EPrints please contact " +
"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" +
"\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" +
"\n" +
"Best,\n" +
"The OpenAIRE team";
this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending request to enable metrics email to user: " + piwikInfo.getRequestorEmail(), e);
throw e;
}
}
@Override
public void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) throws Exception {
try {
String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled";
String message = "Dear administrator,\n" +
"\n" +
"The installation and configuration of OpenAIRE's tracking code for the following repository " +
"has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" +
"\n" +
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
"Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" +
"Piwik ID - " + piwikInfo.getSiteId() + "\n" +
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
"\n" +
"Best,\n" +
"The OpenAIRE team";
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);
throw e;
}
}
@Override
public void sendUserMetricsEnabled(PiwikInfo piwikInfo) throws Exception {
try {
String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled";
String message = "Dear " + piwikInfo.getRequestorName() + ",\n" +
"\n" +
"The installation and configuration of OpenAIRE's tracking code for your repository \"" + piwikInfo.getRepositoryName() +
"\" 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" +
"\n" +
" For more information and questions, you can contact the openaire support team by sending an email to " +
"repositoryusagestats@openaire.eu\n" +
"\n" +
"Best,\n" +
"The OpenAIRE team";
this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending metrics enabled notification email to user: " + piwikInfo.getRequestorEmail(), 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.\n " +
"A validation process against the OpenAIRE guidelines compatibility " +
"has been started. You will be informed in another message once the process is finished." +
"\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(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 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() + "].\n" +
"A new iteration process of the validation against the OpenAIRE guidelines compatibility has been 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(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);
this.sendMail(to,subject,message,sendToSpecial,repoAdminMails);
}
private void sendMail(List<String> recipients, String subject, String message, boolean sendToSpecial, List<String> repoAdminMails) throws Exception {
try {
if (sendToSpecial) {
recipients.addAll(this.specialRecipients);
}
if (repoAdminMails != null)
recipients.addAll(repoAdminMails);
if (this.override) {
recipients.clear();
recipients.add(overrideEmail);
}
if (!logonly)
mailLibrary.sendEmail(recipients.toArray(new String[]{}), subject, message);
LOGGER.debug("Sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message);
} 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) {
return pLoader.getProperties().getProperty(key);
}
public void setSpecialRecipients(String specialRecipients) {
String[] recps = specialRecipients.split(",");
for (String recp : recps) {
recp = recp.trim();
this.specialRecipients.add(recp);
}
}
public void setOverride(boolean override) {
this.override = override;
}
public void setOverrideEmail(String overrideEmail) {
this.overrideEmail = overrideEmail;
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public boolean isLogonly() {
return logonly;
}
public void setLogonly(boolean logonly) {
this.logonly = logonly;
}
}

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

@ -0,0 +1,111 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.api.functionality.ValidatorService;
import eu.dnetlib.api.functionality.ValidatorServiceException;
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 org.apache.log4j.Logger;
import org.json.JSONException;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service("monitorService")
public class MonitorServiceImpl implements MonitorService {
@Resource(name = "validatorServiceLocator")
private ServiceLocator<ValidatorService> validatorServiceLocator;
private ValidatorService getValidationService() {
return this.validatorServiceLocator.getService();
}
public ServiceLocator<ValidatorService> getValidatorServiceLocator() {
return validatorServiceLocator;
}
public void setValidatorServiceLocator(ServiceLocator<ValidatorService> validatorServiceLocator) {
this.validatorServiceLocator = validatorServiceLocator;
}
private static final Logger LOGGER = Logger
.getLogger(MonitorServiceImpl.class);
@Override
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();
retJobs.setJobs(getValidationService().getStoredJobsNew(user, jobType, Integer.parseInt(offset),
Integer.parseInt(limit), dateFrom, dateTo, validationStatus));
if (Boolean.parseBoolean(includeJobsTotal)) {
retJobs.setTotalJobs(this.getJobsTotalNumberOfUser(user, jobType, null));
retJobs.setTotalJobsSuccessful(this.getJobsTotalNumberOfUser(user, jobType, Constants.VALIDATION_JOB_STATUS_SUCCESSFUL));
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;
}
private int getJobsTotalNumberOfUser(String user, String jobType, String validationStatus) throws ValidatorServiceException {
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
}
@Override
public int getJobsOfUserPerValidationStatus(String user,
String jobType,
String validationStatus) throws JSONException {
LOGGER.debug("Getting job with validation status : " + validationStatus);
try {
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
} catch (ValidatorServiceException e) {
e.printStackTrace();
}
return 0;
}
@Override
public StoredJob getJobSummary(String jobId,
String groupBy) throws JSONException {
LOGGER.debug("Getting job summary with id : " + jobId);
try {
return getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy);
} catch (ValidatorServiceException e) {
e.printStackTrace();
}
return null;
}
}

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_PORTAL_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_PORTAL_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_PORTAL_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_PORTAL_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,72 @@
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<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,846 @@
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.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface;
import eu.dnetlib.domain.enabling.Vocabulary;
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 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;
@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;
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!");
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;
}
}
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);
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);
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);
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);
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;
}
}
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());
}
@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 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 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

@ -0,0 +1,225 @@
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.Constants;
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.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;
@Service("validatorService")
public class ValidatorServiceImpl implements ValidatorService {
@Autowired
private MonitorServiceImpl monitorApi;
@Resource(name = "validatorServiceLocator")
private ServiceLocator<eu.dnetlib.api.functionality.ValidatorService> validatorServiceLocator;
private eu.dnetlib.api.functionality.ValidatorService getValidationService() {
return this.validatorServiceLocator.getService();
}
public ServiceLocator<eu.dnetlib.api.functionality.ValidatorService> getValidatorServiceLocator() {
return 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(ValidatorServiceImpl.class);
@Autowired
private EmailUtils emailUtils;
@PostConstruct
private void loadRules(){
LOGGER.debug("PostConstruct method! Load rules!");
try {
for (RuleSet ruleSet : getValidationService().getRuleSets()) {
if (ruleSet.getVisibility() != null && ruleSet.getVisibility().contains("development")) {
String key = "";
if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0_data$"))
key = Constants.VALIDATION_MODE_DATA;
else if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0$") || ruleSet.getGuidelinesAcronym().equals("driver"))
key = Constants.VALIDATION_MODE_LITERATURE;
else if (ruleSet.getGuidelinesAcronym().matches("^openaire[1-9].0_cris$"))
key = Constants.VALIDATION_MODE_CRIS;
if (rulesetMap.containsKey(key))
rulesetMap.get(key).add(ruleSet);
else {
List<RuleSet> ruleSets = new ArrayList<RuleSet>();
ruleSets.add(ruleSet);
rulesetMap.put(key, ruleSets);
}
}
}
} catch (ValidatorServiceException e) {
e.printStackTrace();
}
}
@Override
@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
@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>();
Set<Integer> usageRules = new HashSet<Integer>();
RuleSet ruleSet = null;
for (List<RuleSet> ruleSets : this.rulesetMap.values()) {
for (RuleSet rSet : ruleSets)
if (rSet.getGuidelinesAcronym().equals(job.getDesiredCompatibilityLevel())) {
ruleSet = rSet;
break;
}
}
for (int ruleId : job.getRules()) {
if (ruleSet.getContentRulesIds().contains(ruleId))
contentRules.add(ruleId);
else if (ruleSet.getUsageRulesIds().contains(ruleId))
usageRules.add(ruleId);
}
if (!contentRules.isEmpty())
job.setSelectedContentRules(contentRules);
if (!usageRules.isEmpty())
job.setSelectedUsageRules(usageRules);
this.submitJobForValidation(job);
return new ResponseEntity<>("OK",HttpStatus.OK);
}
@Override
public List<RuleSet> getRuleSets(@PathVariable("mode") String mode) {
LOGGER.info("Getting rulesets for mode: " + mode);
return rulesetMap.get(mode);
}
@Override
public List<String> getSetsOfRepository(@RequestParam(value = "url", required = true) String url) {
LOGGER.debug("Getting sets of repository with url : " + url);
try {
return OaiTools.getSetsOfRepo(url);
} catch (Exception e) {
LOGGER.debug("Exception on getSetsOfRepository" , e);
emailUtils.reportException(e);
}
return null;
}
@Override
public boolean identifyRepo(@RequestParam(value = "url", required = true) String url) {
LOGGER.debug("Identify repository with url : " + url);
try {
return OaiTools.identifyRepository(url);
} catch (Exception e) {
LOGGER.error("Error while identifying repository with url: " + url, e);
emailUtils.reportException(e);
return false;
}
}
@Override
public RuleSet getRuleSet(@PathVariable("acronym") String acronym) {
LOGGER.debug("Getting ruleset with acronym : " + acronym);
RuleSet ruleSet = null;
try {
for (List<RuleSet> ruleSets : this.rulesetMap.values()) {
for (RuleSet rSet : ruleSets)
if (rSet.getGuidelinesAcronym().equals(acronym)) {
ruleSet = rSet;
break;
}
}
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,
@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 getValidationService().getStoredJobsNew(user, jobType, Integer.parseInt(offset), Integer.parseInt(limit), dateFrom, dateTo, validationStatus);
}
@Override
public int getStoredJobsTotalNumberNew(String user, String jobType, String validationStatus) throws ValidatorServiceException {
return getValidationService().getStoredJobsTotalNumberNew(user, jobType, validationStatus);
}
@Override
public InterfaceInformation getInterfaceInformation(@RequestParam(value = "baseUrl", required = true) String baseUrl) throws ValidationServiceException {
try {
LOGGER.debug("Getting interface information with url: " + baseUrl);
InterfaceInformation interfaceInformation = new InterfaceInformation();
interfaceInformation.setIdentified(this.identifyRepo(baseUrl));
if (interfaceInformation.isIdentified())
interfaceInformation.setSets(this.getSetsOfRepository(baseUrl));
return interfaceInformation;
} catch (Exception e) {
LOGGER.error("Error getting interface information with url: " + baseUrl, e);
emailUtils.reportException(e);
throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR);
}
}
}

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

@ -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;
@ -95,4 +97,13 @@ public class Subscription implements IsSerializable {
public void setConditionsAsList(List<MapConditions> conditionsAsList) {
this.conditionsAsList = conditionsAsList;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
}

View File

@ -0,0 +1,425 @@
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.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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
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.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.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()));
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());
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) {
repository.setOrganization(((JSONArray) datasource.get("organizations")).getJSONObject(0).get("legalname").toString());
String countryCode = ((JSONArray) datasource.get("organizations")).getJSONObject(0).get("country").toString();
repository.setCountryCode(countryCode);
}
/* identities field */
return repository;
}
public static Date convertStringToDate(String date){
if(Objects.equals(date, "null"))
return null;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
try {
return formatter.parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
public static String convertDateToString(Date date){
if(Objects.equals(date, null))
return null;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
return formatter.format(date);
}
public static Double toDouble(String number){
if(Objects.equals(number, "null"))
return 0.0;
else
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<>();
JSONArray rs = json.getJSONArray("datasourceInfo");
for(int i=0;i<rs.length();i++)
resultSet.add(jsonToRepositoryObject( rs.getJSONObject(i)) );
return resultSet;
}
public static List<RepositoryInterface> jsonToRepositoryInterfaceList(JSONObject json) throws JSONException {
List<RepositoryInterface> resultSet = new ArrayList<>();
JSONArray rs = json.getJSONArray("api");
for(int i=0;i<rs.length();i++)
resultSet.add(jsonToRepositoryInterfaceObject( rs.getJSONObject(i)) );
return resultSet;
}
public static RepositoryInterface jsonToRepositoryInterfaceObject(JSONObject repositoryInterfaceObject) throws JSONException {
RepositoryInterface repositoryInterface = new RepositoryInterface();
repositoryInterface.setId(repositoryInterfaceObject.get("id").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()));
Map<String, String> accessParams = new HashMap<>();
Map<String, String> extraFields = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
JSONArray apiparams = repositoryInterfaceObject.getJSONArray("apiParams");
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, JsonProcessingException {
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("databaseaccessrestriction",repository.getDatabaseAccessRestriction());
jsonObject.put("databaseaccesstype",repository.getDatabaseAccessType());
jsonObject.put("datauploadrestriction",repository.getDataUploadRestriction());
jsonObject.put("datauploadtype",repository.getDataUploadType());
jsonObject.put("missionstatementurl",repository.getMissionStatementUrl());
jsonObject.put("od_contenttypes",repository.getOdContentTypes());
jsonObject.put("officialname",repository.getOfficialname());
jsonObject.put("pidsystems",repository.getPidSystems());
jsonObject.put("provenanceaction",repository.getProvenanceActionClass());
jsonObject.put("qualitymanagementkind",repository.getQualityManagementKind());
jsonObject.put("releaseenddate",convertDateToString(repository.getReleaseEndDate()));
jsonObject.put("releasestartdate",convertDateToString(repository.getReleaseStartDate()));
jsonObject.put("serviceprovider",repository.getServiceProvider());
jsonObject.put("versioning",repository.getVersioning());
//datasource.get("platform");
//datasource.get("subjects");*/
return mapper.writeValueAsString(repositoryMap);
}
public static String repositoryInterfaceObjectToJson(Repository repository,RepositoryInterface repositoryInterface) throws JSONException {
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",repositoryInterface.getId());
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("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());
JSONArray apiparams = new JSONArray();
for(String param: repositoryInterface.getAccessParams().keySet()){
JSONObject jo = new JSONObject();
jo.put("param",param);
jo.put("value",repositoryInterface.getAccessParams().get(param));
apiparams.put(jo);
}
jsonObject.put("apiParams",apiparams);
// jsonObject.put("metadataIdentifierPath",repositoryInterface.getMetadataIdentifierPath());
return jsonObject.toString();
}
public static ArrayList<String> readFile(String filename) {
String line;
ArrayList<String> list = new ArrayList<String>();
try {
//InputStream in = Converter.class.getResourceAsStream("resources/eu/dnetlib/repo/manager/service/utils/"+filename);
InputStream in = Converter.class.getClass().getResourceAsStream("/eu/**/" + filename);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
while((line = br.readLine()) != null) {
list.add(line.trim());
}
br.close();
} catch (IOException e) {
LOGGER.debug("Error opening file!");
e.printStackTrace();
}
return list;
}
public static List<AggregationDetails> getAggregationHistoryFromJson(JSONObject datasourceInfo) throws JSONException {
JSONArray rs = new JSONArray(datasourceInfo.get("aggregationHistory").toString());
List<AggregationDetails> aggregationDetailsList = new ArrayList<>();
for(int i=0;i<rs.length();i++)
aggregationDetailsList.add(jsonToAggregationDetails(rs.getJSONObject(i)));
return aggregationDetailsList;
}
private static AggregationDetails jsonToAggregationDetails(JSONObject aggregationObject) throws JSONException {
AggregationDetails aggregationDetails = new AggregationDetails();
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;
}
public static AggregationDetails getLastCollectionFromJson(JSONObject datasourceInfo) throws JSONException {
if( datasourceInfo.get("lastCollection").equals(null))
return null;
return jsonToAggregationDetails(datasourceInfo.getJSONObject("lastCollection"));
}
public static AggregationDetails getLastTransformationFromJson(JSONObject datasourceInfo) throws JSONException {
if( datasourceInfo.get("lastTransformation").equals(null))
return null;
return jsonToAggregationDetails(datasourceInfo.getJSONObject("lastTransformation"));
}
public static List<Timezone> toTimezones(List<String> timezones) {
List<Timezone> tmz = new ArrayList<>();
for(String t : timezones){
String[] s = t.split("\t");
tmz.add(new Timezone(s[1],Double.parseDouble(s[0])));
}
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

@ -0,0 +1,146 @@
package eu.dnetlib.repo.manager.utils;
import org.apache.log4j.Logger;
import org.dom4j.io.DOMWriter;
import org.w3c.dom.Document;
import se.kb.oai.pmh.*;
import se.kb.oai.pmh.Set;
import javax.net.ssl.*;
import javax.xml.namespace.NamespaceContext;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.*;
public class OaiTools {
{
disableSslVerification();
}
private static Logger LOGGER = Logger.getLogger(OaiTools.class);
public static List<String> getSetsOfRepo(String baseUrl) throws Exception {
try {
LOGGER.debug("Getting sets of repository " + baseUrl);
OaiPmhServer harvester = new OaiPmhServer(baseUrl);
SetsList setList = harvester.listSets();
ResumptionToken token = setList.getResumptionToken();
List<Set> sets = new ArrayList<Set>();
sets.addAll(setList.asList());
while (token != null) {
setList = harvester.listSets(token);
token = setList.getResumptionToken();
sets.addAll(setList.asList());
}
List<String> ret = new ArrayList<String>();
for (Set set : sets) {
ret.add(set.getSpec().trim());
}
if (ret.size() > 0 )
Collections.sort(ret);
return ret;
} catch (Exception e) {
LOGGER.error("Error getting sets of repository " + baseUrl, e);
return new ArrayList<String>();
//throw e;
}
}
public static boolean identifyRepository(String baseUrl) throws Exception {
LOGGER.debug("sending identify request to repo " + baseUrl);
OaiPmhServer harvester = new OaiPmhServer(baseUrl);
if (baseUrl.trim().isEmpty()) {
return false;
}
try {
Identification identification = harvester.identify();
DOMWriter d4Writer = new DOMWriter();
Document d = d4Writer.write(identification.getResponse());
return verifyIdentify(d);
} catch (Exception e) {
LOGGER.debug("Error verifying identify response", e);
throw e;
}
}
private static boolean verifyIdentify(Document doc) throws XPathExpressionException {
NamespaceContext ctx = new NamespaceContext() {
public String getNamespaceURI(String prefix) {
String uri;
if (prefix.equals("oai"))
uri = "http://www.openarchives.org/OAI/2.0/";
else
uri = null;
return uri;
}
// Dummy implementation - not used!
public Iterator<String> getPrefixes(String val) {
return null;
}
// Dummy implemenation - not used!
public String getPrefix(String uri) {
return null;
}
};
// Now the XPath expression
String xpathStr = "//oai:OAI-PMH/oai:Identify";
XPathFactory xpathFact = XPathFactory.newInstance();
XPath xpath = xpathFact.newXPath();
xpath.setNamespaceContext(ctx);
String result = xpath.evaluate(xpathStr, doc);
return (result != null && !result.equals(""));
}
private static void disableSslVerification() {
try
{
LOGGER.debug("disabling ssl verification");
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
}
};
// Install the all-trusting trust manager
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
// Create all-trusting host name verifier
HostnameVerifier allHostsValid = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
} catch (NoSuchAlgorithmException e) {
LOGGER.error("disabling ssl verification", e);
} catch (KeyManagementException e) {
LOGGER.error("error while disabling ssl verification", e);
}
}
}

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,84 @@
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://adonis.athenarc.gr: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/
## 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 = pkanakakis@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 = pkanakakis@di.uoa.gr
services.validator.mail.specialRecipients = pkanakakis@di.uoa.gr
services.validator.repoRegistration.override = pkanakakis@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://aleka.athenarc.gr:8480/uoa-repository-manager-service/openid_connect_login
webapp.dev.front = http://aleka.athenarc.gr:4200/landing
##REDIS-AAI
redis.host = aleka.athenarc.gr
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 = pkanakakis@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

@ -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:Portal+Administrator#aai.openaire.eu" value="ROLE_PORTAL_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

@ -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,10 +1,20 @@
<?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>
@ -17,33 +27,68 @@ http://xmlns.jcp.org/xml/ns/javaee "
<param-name>log4jExposeWebAppRoot</param-name>
<param-value>false</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<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>
<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>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.headers</param-name>
<param-value>Content-Type,X-Requested-With,accept,authorization,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET, POST, PUT, DELETE, OPTIONS, HEAD</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<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>
<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>