Project

General

Profile

1
package eu.dnetlib.datasource.publisher.clients;
2

    
3
import eu.dnetlib.datasource.publisher.ApiException;
4
import eu.dnetlib.datasource.publisher.clients.utils.IndexDsInfo;
5
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
6
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
7
import org.apache.commons.io.IOUtils;
8
import org.apache.commons.logging.Log;
9
import org.apache.commons.logging.LogFactory;
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.beans.factory.annotation.Value;
12
import org.springframework.cache.annotation.Cacheable;
13
import org.springframework.core.io.ClassPathResource;
14
import org.springframework.http.HttpStatus;
15

    
16
/**
17
 * Created by claudio on 20/10/2016.
18
 */
19
public class ISLookupClient {
20

    
21
	private static final Log log = LogFactory.getLog(ISLookupClient.class);
22

    
23
	@Autowired
24
	private UniqueServiceLocator serviceLocator;
25

    
26
	@Value(value = "${datasource.publisher.findSolrIndexUrl.xquery}")
27
	private ClassPathResource findSolrIndexUrl;
28

    
29
	@Value(value = "${datasource.publisher.findIndexDsInfo.xquery}")
30
	private ClassPathResource findIndexDsInfo;
31

    
32
	@Cacheable("datasources-is-cache")
33
	public IndexDsInfo calculateCurrentIndexDsInfo() throws ApiException {
34
		log.warn("calculateCurrentIndexDsInfo(): not using cache");
35
		try {
36
			final String queryUrl = IOUtils.toString(findSolrIndexUrl.getInputStream());
37
			final String queryDs = IOUtils.toString(findIndexDsInfo.getInputStream());
38

    
39
			final ISLookUpService lookUpService = serviceLocator.getService(ISLookUpService.class);
40
			final String indexBaseUrl = lookUpService.getResourceProfileByQuery(queryUrl);
41
			final String[] arr = lookUpService.getResourceProfileByQuery(queryDs).split("@@@");
42

    
43
			return new IndexDsInfo(indexBaseUrl, arr[0].trim(), arr[1].trim(), arr[2].trim());
44
		} catch (Exception e) {
45
			throw new ApiException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Error querying information system");
46
		}
47
	}
48

    
49
}
(4-4/7)