1
|
package eu.dnetlib.openaire.exporter.datasource.clients;
|
2
|
|
3
|
import java.nio.charset.Charset;
|
4
|
|
5
|
import eu.dnetlib.OpenaireExporterConfig;
|
6
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
7
|
import eu.dnetlib.openaire.exporter.datasource.ApiException;
|
8
|
import eu.dnetlib.openaire.exporter.datasource.clients.utils.IndexDsInfo;
|
9
|
import org.apache.commons.io.IOUtils;
|
10
|
import org.apache.commons.logging.Log;
|
11
|
import org.apache.commons.logging.LogFactory;
|
12
|
import org.springframework.beans.factory.annotation.Autowired;
|
13
|
import org.springframework.cache.annotation.Cacheable;
|
14
|
import org.springframework.http.HttpStatus;
|
15
|
import org.springframework.stereotype.Component;
|
16
|
|
17
|
/**
|
18
|
* Created by claudio on 20/10/2016.
|
19
|
*/
|
20
|
@Component
|
21
|
public class ISLookupClient {
|
22
|
|
23
|
private static final Log log = LogFactory.getLog(ISLookupClient.class);
|
24
|
|
25
|
@Autowired
|
26
|
private OpenaireExporterConfig config;
|
27
|
|
28
|
@Autowired
|
29
|
private ISLookUpService isLookUpService;
|
30
|
|
31
|
@Cacheable("datasources-is-cache")
|
32
|
public IndexDsInfo calculateCurrentIndexDsInfo() throws ApiException {
|
33
|
log.warn("calculateCurrentIndexDsInfo(): not using cache");
|
34
|
try {
|
35
|
final String queryUrl = IOUtils.toString(config.getFindSolrIndexUrl().getInputStream(), Charset.defaultCharset());
|
36
|
final String queryDs = IOUtils.toString(config.getFindIndexDsInfo().getInputStream(), Charset.defaultCharset());
|
37
|
|
38
|
final String indexBaseUrl = isLookUpService.getResourceProfileByQuery(queryUrl);
|
39
|
final String[] arr = isLookUpService.getResourceProfileByQuery(queryDs).split("@@@");
|
40
|
|
41
|
return new IndexDsInfo(indexBaseUrl, arr[0].trim(), arr[1].trim(), arr[2].trim());
|
42
|
} catch (Exception e) {
|
43
|
throw new ApiException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Error querying information system");
|
44
|
}
|
45
|
}
|
46
|
|
47
|
}
|