1
|
package eu.dnetlib;
|
2
|
|
3
|
import javax.sql.DataSource;
|
4
|
|
5
|
import com.mongodb.MongoClient;
|
6
|
import com.mongodb.MongoClientOptions;
|
7
|
import com.mongodb.ServerAddress;
|
8
|
import eu.dnetlib.OpenaireExporterConfig.Jdbc;
|
9
|
import eu.dnetlib.data.objectstore.rmi.ObjectStoreService;
|
10
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
11
|
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
|
12
|
import org.apache.commons.dbcp2.BasicDataSource;
|
13
|
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
|
14
|
import org.springframework.beans.factory.annotation.Autowired;
|
15
|
import org.springframework.context.annotation.Bean;
|
16
|
import org.springframework.context.annotation.Configuration;
|
17
|
|
18
|
/**
|
19
|
* Created by claudio on 07/07/2017.
|
20
|
*/
|
21
|
@Configuration
|
22
|
public class DNetOpenaireExporterBeanFactory {
|
23
|
|
24
|
@Autowired
|
25
|
private OpenaireExporterConfig config;
|
26
|
|
27
|
@Bean
|
28
|
public ISLookUpService getLookUpService() {
|
29
|
return getServiceStub(ISLookUpService.class, config.getIsLookupUrl());
|
30
|
}
|
31
|
|
32
|
@Bean
|
33
|
public ObjectStoreService getObjectStoreService() {
|
34
|
return getServiceStub(ObjectStoreService.class, config.getObjectStoreServiceUrl());
|
35
|
}
|
36
|
|
37
|
@Bean
|
38
|
public ISRegistryService getRegistryService() {
|
39
|
return getServiceStub(ISRegistryService.class, config.getIsRegistryServiceUrl());
|
40
|
}
|
41
|
|
42
|
@SuppressWarnings("unchecked")
|
43
|
private <T> T getServiceStub(final Class<T> clazz, final String endpoint) {
|
44
|
final JaxWsProxyFactoryBean jaxWsProxyFactory = new JaxWsProxyFactoryBean();
|
45
|
jaxWsProxyFactory.setServiceClass(clazz);
|
46
|
jaxWsProxyFactory.setAddress(endpoint);
|
47
|
return (T) jaxWsProxyFactory.create();
|
48
|
}
|
49
|
|
50
|
@Bean
|
51
|
public DataSource getSqlDataSource() {
|
52
|
final Jdbc jdbc = config.getJdbc();
|
53
|
return getDatasource(
|
54
|
jdbc.getDriverClassName(),
|
55
|
jdbc.getUrl(),
|
56
|
jdbc.getUser(),
|
57
|
jdbc.getPwd(),
|
58
|
jdbc.getMinIdle(),
|
59
|
jdbc.getMaxRows());
|
60
|
}
|
61
|
|
62
|
private BasicDataSource getDatasource(String driverClassName, String jdbcUrl, String jdbcUser, String jdbcPwd, int jdbcMinIdle, int jdbcMaxIdle) {
|
63
|
final BasicDataSource d = new BasicDataSource();
|
64
|
d.setDriverClassName(driverClassName);
|
65
|
d.setUrl(jdbcUrl);
|
66
|
d.setUsername(jdbcUser);
|
67
|
d.setPassword(jdbcPwd);
|
68
|
d.setMinIdle(jdbcMinIdle);
|
69
|
d.setMaxIdle(jdbcMaxIdle);
|
70
|
return d;
|
71
|
}
|
72
|
|
73
|
@Bean
|
74
|
public MongoClient getMongoClient() {
|
75
|
return new MongoClient(
|
76
|
new ServerAddress(config.getDatasource().getMongoHost(), config.getDatasource().getMongoPort()),
|
77
|
MongoClientOptions.builder().connectionsPerHost(config.getDatasource().getMongoConnectionsPerHost()).build());
|
78
|
}
|
79
|
|
80
|
}
|