1
|
package eu.dnetlib.openaire.exporter.datasource.clients;
|
2
|
|
3
|
import eu.dnetlib.OpenaireExporterConfig;
|
4
|
import eu.dnetlib.openaire.exporter.vocabularies.Vocabulary;
|
5
|
import org.apache.commons.logging.Log;
|
6
|
import org.apache.commons.logging.LogFactory;
|
7
|
import org.springframework.beans.factory.annotation.Autowired;
|
8
|
import org.springframework.cache.annotation.CacheEvict;
|
9
|
import org.springframework.cache.annotation.Cacheable;
|
10
|
import org.springframework.http.ResponseEntity;
|
11
|
import org.springframework.stereotype.Component;
|
12
|
import org.springframework.web.client.RestTemplate;
|
13
|
|
14
|
/**
|
15
|
* Created by claudio on 15/09/2017.
|
16
|
*/
|
17
|
@Component
|
18
|
public class VocabularyClient {
|
19
|
|
20
|
private static final Log log = LogFactory.getLog(VocabularyClient.class);
|
21
|
|
22
|
@Autowired
|
23
|
private OpenaireExporterConfig config;
|
24
|
|
25
|
@Cacheable("vocabularies-cache")
|
26
|
public Vocabulary getCountries() {
|
27
|
|
28
|
final RestTemplate rt = new RestTemplate();
|
29
|
final String endpoint = config.getVocabularies().getCountriesEndpoint();
|
30
|
log.info("get countries vocabulary from " + endpoint);
|
31
|
final ResponseEntity<Vocabulary> rsp = rt.getForEntity(endpoint, Vocabulary.class);
|
32
|
|
33
|
return rsp.getBody();
|
34
|
}
|
35
|
|
36
|
@CacheEvict(cacheNames = "vocabularies-cache", allEntries = true)
|
37
|
public void dropCache() {
|
38
|
log.info("dropped dsManager vocabulary cache");
|
39
|
}
|
40
|
|
41
|
}
|