1. Add env var for cookies 2. Add sushi controllers 3. Bug fix on piwik/repo 4. Add stats controllers/service

This commit is contained in:
Panagiotis Kanakakis 2018-09-03 11:47:22 +00:00
parent 5b4f9bae51
commit 8e91741a6e
15 changed files with 386 additions and 43 deletions

View File

@ -1,4 +1,4 @@
FROM tomcat:8.5-jre8-alpine
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

View File

@ -68,10 +68,11 @@
<dependency>
<groupId>eu.dnetlib</groupId>
<artifactId>dnet-openaire-usage-stats-api</artifactId>
<version>2.0.2-SNAPSHOT</version>
<artifactId>dnet-openaire-usage-stats-sushilite</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>

View File

@ -31,6 +31,9 @@ public class Config {
@Value("${redis.password}")
private String password;
@Value("${aai.mode}")
private String aai_mode;
@PostConstruct
private void init(){
LOGGER.info(host);
@ -51,7 +54,8 @@ public class Config {
DefaultCookieSerializer serializer = new DefaultCookieSerializer();
serializer.setCookieName("openAIRESession");
serializer.setCookiePath("/");
// serializer.setDomainName(".openaire.eu");
if(aai_mode.equalsIgnoreCase("production") || aai_mode.equalsIgnoreCase("beta"))
serializer.setDomainName(".openaire.eu");
// serializer.setDomainName(".athenarc.gr");
LOGGER.info("Serializer : " + serializer);
return serializer;

View File

@ -3,6 +3,7 @@ package eu.dnetlib.repo.manager.service.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;
@ -25,6 +26,10 @@ public class FrontEndLinkURIAuthenticationSuccessHandler implements Authenticati
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 {
@ -59,14 +64,16 @@ public class FrontEndLinkURIAuthenticationSuccessHandler implements Authenticati
Cookie openAIREUser = new Cookie("openAIREUser", new Gson().toJson(userInfo) );
openAIREUser.setMaxAge(14400);
openAIREUser.setPath("/");
// openAIREUser .setDomain(".openaire.eu");
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);
// accessToken.setDomain(".openaire.eu");
if(aai_mode.equalsIgnoreCase("production") || aai_mode.equalsIgnoreCase("beta"))
accessToken.setDomain(".openaire.eu");
accessToken.setPath("/");
// accessToken.setDomain(".athenarc.gr");

View File

@ -73,7 +73,7 @@ public class PiWikApiImpl implements PiWikApi{
}
@Override
@PreAuthorize("hasRole('ROLE_ADMIN')")
@PreAuthorize("hasRole('ROLE_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(),

View File

@ -24,8 +24,6 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
@ -40,7 +38,6 @@ import javax.annotation.PostConstruct;
import java.sql.Timestamp;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.stream.Collectors;
@Component

View File

@ -0,0 +1,26 @@
package eu.dnetlib.repo.manager.service.controllers;
import io.swagger.annotations.Api;
import org.json.JSONException;
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 interface StatsApi {
@RequestMapping(value = "/getStatistics" , method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
Map<String, String> getStatistics() throws JSONException;
}

View File

@ -0,0 +1,105 @@
package eu.dnetlib.repo.manager.service.controllers;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;
@Component
public class StatsApiImpl implements StatsApi {
private RestTemplate restTemplate = null;
private HttpHeaders httpHeaders;
private static final Logger LOGGER = Logger.getLogger(RepositoryApiImpl.class);
@Value("${search.api.baseAddress}")
private String baseAddress;
@PostConstruct
private void init() {
LOGGER.debug("Initialization method of statistics api!");
restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type", "application/json");
}
@Override
public Map<String, String> getStatistics() throws JSONException {
String aggregators = getTotalByType("datasource",baseAddress+"/resources",
"?query= " +
" oaftype exact datasource and " +
" ( datasourcetypename exact Institutional Repository Aggregator " +
" or datasourcetypename exact Publication Repository Aggregator )");
String dataRepositories = getTotalByType("datasource",baseAddress+"/resources",
"?query= " +
" oaftype exact datasource and " +
" datasourcetypename exact Data Repository " );
String literature = getTotalByType("datasource",baseAddress+"/resources",
"?query= " +
" oaftype exact datasource and " +
" ( datasourcetypename exact Institutional Repository " +
" or datasourcetypename exact Publication Repository )");
String journal = getTotalByType("datasource",baseAddress+"/resources",
"?query= " +
" oaftype exact datasource and " +
" datasourcetypename exact Journal");
String publications = getTotalByType("other",baseAddress,"/publications/count");
String datasets = getTotalByType("other",baseAddress,"/datasets/count");
String software = getTotalByType("other",baseAddress,"/software/count");
HashMap<String,String> stats = new HashMap<>();
stats.put("aggregators",aggregators);
stats.put("dataRepositories",dataRepositories);
stats.put("literature",literature);
stats.put("journal",journal);
stats.put("publications",publications);
stats.put("datasets",datasets);
stats.put("software",software);
return stats;
}
private String getTotalByType(String type,String url,String query) throws JSONException {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(url + query)
.queryParam("page",0)
.queryParam("size",0)
.queryParam("format","json")
.build().encode();
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
if(type.equalsIgnoreCase("datasource")){
JSONObject metadata = (JSONObject) new JSONObject(rs).get("meta");
return String.valueOf(metadata.get("total"));
}else
return String.valueOf(new JSONObject(rs).get("total"));
}
}

View File

@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
@Api(description = "Sushi-Lite API", tags = {"sushilite"})
public interface SushiliteApi {
@RequestMapping(value = "/getReportResults", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping(value = "/getReportResults/{page}/{pageSize}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
ReportResponseWrapper getReportResults(String page,
String pageSize,

View File

@ -1,16 +1,10 @@
package eu.dnetlib.repo.manager.service.controllers;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import eu.dnetlib.usagestats.sushilite.domain.ReportItem;
import eu.dnetlib.usagestats.sushilite.domain.ReportResponse;
import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper;
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.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

View File

@ -1,34 +1,39 @@
infrastructure.name=integration
#
## Container properties
container.hostname=aleka.athenarc.gr
container.context=uoa-repository-manager-service
container.port = 8480
#
## IS
ISLookUpService.url = http://node6.t.openaire.research-infrastructures.eu/is/services/isLookUp
ISRegistryService.url = http://node6.t.openaire.research-infrastructures.eu/is/services/isRegistry
ISSNService.url = http://node6.t.openaire.research-infrastructures.eu/is/services/isSN
#
#
#ISLookUpService.url = http://node6.t.openaire.research-infrastructures.eu/is/services/isLookUp
#ISRegistryService.url = http://node6.t.openaire.research-infrastructures.eu/is/services/isRegistry
#ISSNService.url = http://node6.t.openaire.research-infrastructures.eu/is/services/isSN
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
#
## 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:8080/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
@ -45,34 +50,44 @@ 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://koulis.athenarc.gr:4200/uoa-repository-manager-service/openid_connect_login
#webapp.dev.front = http://koulis.athenarc.gr:4200/landing
oidc.dev.home = http://aleka.athenarc.gr:4200/uoa-repository-manager-service/openid_connect_login
webapp.dev.front = http://aleka.athenarc.gr:4200/landing
#
oidc.dev.home = http://koulis.athenarc.gr:4200/uoa-repository-manager-service/openid_connect_login
webapp.dev.front = http://koulis.athenarc.gr:4200/landing
#oidc.dev.home = http://aleka.athenarc.gr:4200/uoa-repository-manager-service/openid_connect_login
#webapp.dev.front = http://aleka.athenarc.gr:4200/landing
##REDIS-AAI
redis.host = audrey.athenarc.gr
redis.port = 6379
redis.password = E#Szvnidd
#
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

View File

@ -19,6 +19,9 @@
<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">

View File

@ -0,0 +1,25 @@
package unitest;
import eu.dnetlib.repo.manager.service.controllers.SushiliteApi;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
//@WebAppConfiguration
public class SushiTest {
@Autowired
SushiliteApi sushiliteApi;
@Test
public void getReportResults(){
System.out.println("test");
}
}

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.service.config.CascadingPropertyLoader"
id="propertyLoader">
<property name="order" value="2"/>
<property name="properties">
<bean class="eu.dnetlib.conf.WebappContextProperyFactory">
<property name="propertyFetcher">
<bean class="eu.dnetlib.conf.PropertyFetcher"/>
</property>
</bean>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath*:/gr/**/springContext-*.properties</value>
<value>classpath*:/eu/**/springContext-*.properties</value>
<value>classpath*:/application.properties</value>
<value>classpath*:/email-texts.properties</value>
<value>classpath*:dnet-site-wizard.properties</value>
<value>classpath*:dnet-site-override.properties</value>
<value>classpath*:dnet-wizard.properties</value>
<value>classpath*:dnet-override.properties</value>
<value>classpath*:dnet-validator-wizard.properties</value>
<value>classpath*:dnet-validator-override.properties</value>
<value>classpath*:dnet-site-force-override.properties</value>
<value>classpath*:dnet-force-override.properties</value>
</list>
</property>
</bean>
<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.service.config.CascadingPropertyLoader"
id="propertyLoader">
<property name="order" value="2"/>
<property name="properties">
<bean class="eu.dnetlib.conf.WebappContextProperyFactory">
<property name="propertyFetcher">
<bean class="eu.dnetlib.conf.PropertyFetcher"/>
</property>
</bean>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath*:/gr/**/springContext-*.properties</value>
<value>classpath*:/eu/**/springContext-*.properties</value>
<value>classpath*:/application.properties</value>
<value>classpath*:/email-texts.properties</value>
<value>classpath*:dnet-site-wizard.properties</value>
<value>classpath*:dnet-site-override.properties</value>
<value>classpath*:dnet-wizard.properties</value>
<value>classpath*:dnet-override.properties</value>
<value>classpath*:dnet-validator-wizard.properties</value>
<value>classpath*:dnet-validator-override.properties</value>
<value>classpath*:dnet-site-force-override.properties</value>
<value>classpath*:dnet-force-override.properties</value>
</list>
</property>
</bean>
<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.service.config.SwaggerConfig"/>
</beans>