Revision 50319
Added by Panagiotis Kanakakis about 6 years ago
BrokerApiImpl.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.repo.manager.service.controllers; |
2 | 2 |
|
3 |
import com.fasterxml.jackson.databind.JsonNode; |
|
3 | 4 |
import com.fasterxml.jackson.databind.ObjectMapper; |
4 | 5 |
import eu.dnetlib.domain.data.Repository; |
5 | 6 |
import eu.dnetlib.repo.manager.shared.BrokerException; |
7 |
import eu.dnetlib.repo.manager.shared.Term; |
|
6 | 8 |
import eu.dnetlib.repo.manager.shared.Tuple; |
7 | 9 |
import eu.dnetlib.repo.manager.shared.broker.*; |
8 | 10 |
import org.json.JSONException; |
... | ... | |
21 | 23 |
import org.springframework.web.client.RestClientException; |
22 | 24 |
import org.springframework.web.client.RestTemplate; |
23 | 25 |
import org.springframework.web.util.UriComponentsBuilder; |
24 |
import sun.reflect.generics.reflectiveObjects.LazyReflectiveObjectGenerator; |
|
25 | 26 |
|
27 |
import javax.annotation.PostConstruct; |
|
26 | 28 |
import java.io.IOException; |
29 |
import java.io.InputStream; |
|
30 |
import java.net.URL; |
|
27 | 31 |
import java.util.*; |
28 | 32 |
|
29 | 33 |
@Component |
30 | 34 |
public class BrokerApiImpl implements BrokerApi { |
31 | 35 |
|
32 |
|
|
33 | 36 |
@Autowired |
34 | 37 |
private RepositoryApiImpl repoAPI; |
35 | 38 |
@Value("${services.broker.url}:${services.broker.port}/${services.broker.api}${services.broker.openaire}") |
36 | 39 |
private String openairePath; |
37 | 40 |
@Value("${services.broker.url}:${services.broker.port}/${services.broker.api}") |
38 | 41 |
private String apiPath; |
42 |
@Value("${topic_types.url}") |
|
43 |
private String topicsURL; |
|
39 | 44 |
|
40 | 45 |
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger |
41 | 46 |
.getLogger(BrokerApiImpl.class); |
42 | 47 |
|
48 |
|
|
49 |
private HashMap<String,Term> topics = new HashMap<String, Term>(); |
|
50 |
|
|
51 |
@PostConstruct |
|
52 |
private void initDnetTopicsMap() { |
|
53 |
|
|
54 |
LOGGER.debug("Init dnet topics!"); |
|
55 |
InputStream is = null; |
|
56 |
try { |
|
57 |
is = new URL(topicsURL).openStream(); |
|
58 |
ObjectMapper mapper = new ObjectMapper(); |
|
59 |
JsonNode root = mapper.readTree(is); |
|
60 |
for (JsonNode term : root.path("terms") ) |
|
61 |
topics.put(term.path("code").textValue(), parseTerm(term)); |
|
62 |
} catch (IOException e) { |
|
63 |
e.printStackTrace(); |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
67 |
private Term parseTerm(JsonNode term) { |
|
68 |
return new Term(term.path("englishName").textValue(),term.path("nativeName").textValue(), |
|
69 |
term.path("encoding").textValue(),term.path("code").textValue()); |
|
70 |
} |
|
71 |
|
|
72 |
|
|
43 | 73 |
@Override |
44 | 74 |
public DatasourcesBroker getDatasourcesOfUser(String params) throws JSONException { |
45 | 75 |
JSONObject json_params = new JSONObject(params); |
... | ... | |
326 | 356 |
return resp.getBody(); |
327 | 357 |
} |
328 | 358 |
|
359 |
@Override |
|
360 |
public Map<String, Term> getDnetTopics() throws BrokerException { |
|
361 |
return topics; |
|
362 |
} |
|
329 | 363 |
|
330 | 364 |
|
331 | 365 |
} |
Also available in: Unified diff
1. Add Term class on shared folder
2. Add property on application file for dnet topics
3. Implement method to get dnet topics map