1
|
package eu.dnetlib.openaire.directindex.api;
|
2
|
|
3
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
4
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
5
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
6
|
import org.apache.commons.io.IOUtils;
|
7
|
import org.apache.commons.logging.Log;
|
8
|
import org.apache.commons.logging.LogFactory;
|
9
|
import org.springframework.beans.factory.annotation.Value;
|
10
|
import org.springframework.cache.annotation.CacheEvict;
|
11
|
import org.springframework.cache.annotation.Cacheable;
|
12
|
import org.springframework.core.io.ClassPathResource;
|
13
|
|
14
|
import javax.annotation.Resource;
|
15
|
import java.io.IOException;
|
16
|
|
17
|
public class IndexDSRetriever {
|
18
|
|
19
|
private static final Log log = LogFactory.getLog(IndexDSRetriever.class);
|
20
|
@Value(value = "${openaire.api.directindex.findSolrIndexUrl.xquery}")
|
21
|
private ClassPathResource findSolrIndexUrl;
|
22
|
|
23
|
@Value(value = "${openaire.api.directindex.findIndexDsInfo.xquery}")
|
24
|
private ClassPathResource findIndexDsInfo;
|
25
|
|
26
|
@Resource
|
27
|
private UniqueServiceLocator serviceLocator;
|
28
|
|
29
|
@Cacheable("indexDsInfo")
|
30
|
public IndexDsInfo calculateCurrentIndexDsInfo() throws IOException, ISLookUpException {
|
31
|
|
32
|
log.info("Not using cache");
|
33
|
|
34
|
final String queryUrl = IOUtils.toString(findSolrIndexUrl.getInputStream());
|
35
|
final String queryDs = IOUtils.toString(findIndexDsInfo.getInputStream());
|
36
|
|
37
|
final ISLookUpService lu = serviceLocator.getService(ISLookUpService.class);
|
38
|
final String indexBaseUrl = lu.getResourceProfileByQuery(queryUrl);
|
39
|
|
40
|
final String idxDs = lu.getResourceProfileByQuery(queryDs);
|
41
|
|
42
|
if (idxDs.isEmpty()) {
|
43
|
throw new IllegalStateException(queryDs + "\n\nreturned no results, check IS profiles");
|
44
|
}
|
45
|
|
46
|
final String[] arr = idxDs.split("@@@");
|
47
|
return new IndexDsInfo(indexBaseUrl, arr[0].trim(), arr[1].trim(), arr[2].trim());
|
48
|
}
|
49
|
|
50
|
@CacheEvict(value="indexDsInfo", allEntries = true)
|
51
|
public void evictCache(){
|
52
|
log.info("Evicting indexDsInfo cache");
|
53
|
}
|
54
|
}
|