1. Add Term class on shared folder
2. Add property on application file for dnet topics 3. Implement method to get dnet topics map
This commit is contained in:
parent
dbd986f38f
commit
44a3e2b0ec
|
@ -1,6 +1,7 @@
|
|||
package eu.dnetlib.repo.manager.service.controllers;
|
||||
|
||||
import eu.dnetlib.repo.manager.shared.BrokerException;
|
||||
import eu.dnetlib.repo.manager.shared.Term;
|
||||
import eu.dnetlib.repo.manager.shared.broker.*;
|
||||
import io.swagger.annotations.*;
|
||||
import org.json.JSONException;
|
||||
|
@ -43,4 +44,9 @@ public interface BrokerApi {
|
|||
@RequestMapping(value = "/getSubscription/{subscriptionId}" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
Subscription getSubscription(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException;
|
||||
|
||||
|
||||
@RequestMapping(value = "/getDnetTopics" , method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
Map<String, Term> getDnetTopics() throws BrokerException;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package eu.dnetlib.repo.manager.service.controllers;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.dnetlib.domain.data.Repository;
|
||||
import eu.dnetlib.repo.manager.shared.BrokerException;
|
||||
import eu.dnetlib.repo.manager.shared.Term;
|
||||
import eu.dnetlib.repo.manager.shared.Tuple;
|
||||
import eu.dnetlib.repo.manager.shared.broker.*;
|
||||
import org.json.JSONException;
|
||||
|
@ -21,25 +23,53 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
import sun.reflect.generics.reflectiveObjects.LazyReflectiveObjectGenerator;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
public class BrokerApiImpl implements BrokerApi {
|
||||
|
||||
|
||||
@Autowired
|
||||
private RepositoryApiImpl repoAPI;
|
||||
@Value("${services.broker.url}:${services.broker.port}/${services.broker.api}${services.broker.openaire}")
|
||||
private String openairePath;
|
||||
@Value("${services.broker.url}:${services.broker.port}/${services.broker.api}")
|
||||
private String apiPath;
|
||||
@Value("${topic_types.url}")
|
||||
private String topicsURL;
|
||||
|
||||
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
|
||||
.getLogger(BrokerApiImpl.class);
|
||||
|
||||
|
||||
private HashMap<String,Term> topics = new HashMap<String, Term>();
|
||||
|
||||
@PostConstruct
|
||||
private void initDnetTopicsMap() {
|
||||
|
||||
LOGGER.debug("Init dnet topics!");
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new URL(topicsURL).openStream();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode root = mapper.readTree(is);
|
||||
for (JsonNode term : root.path("terms") )
|
||||
topics.put(term.path("code").textValue(), parseTerm(term));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private Term parseTerm(JsonNode term) {
|
||||
return new Term(term.path("englishName").textValue(),term.path("nativeName").textValue(),
|
||||
term.path("encoding").textValue(),term.path("code").textValue());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public DatasourcesBroker getDatasourcesOfUser(String params) throws JSONException {
|
||||
JSONObject json_params = new JSONObject(params);
|
||||
|
@ -326,6 +356,10 @@ public class BrokerApiImpl implements BrokerApi {
|
|||
return resp.getBody();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Term> getDnetTopics() throws BrokerException {
|
||||
return topics;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package eu.dnetlib.repo.manager.shared;
|
||||
|
||||
import com.google.gwt.user.client.rpc.IsSerializable;
|
||||
|
||||
/**
|
||||
* Created by panagiotis on 15/1/2018.
|
||||
*/
|
||||
public class Term implements IsSerializable {
|
||||
|
||||
public String englishName;
|
||||
public String nativeName;
|
||||
public String encoding;
|
||||
public String code;
|
||||
|
||||
public Term(String englishName, String nativeName, String encoding, String code) {
|
||||
this.englishName = englishName;
|
||||
this.nativeName = nativeName;
|
||||
this.encoding = encoding;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getEnglishName() {
|
||||
return englishName;
|
||||
}
|
||||
|
||||
public void setEnglishName(String englishName) {
|
||||
this.englishName = englishName;
|
||||
}
|
||||
|
||||
public String getNativeName() {
|
||||
return nativeName;
|
||||
}
|
||||
|
||||
public void setNativeName(String nativeName) {
|
||||
this.nativeName = nativeName;
|
||||
}
|
||||
|
||||
public String getEncoding() {
|
||||
return encoding;
|
||||
}
|
||||
|
||||
public void setEncoding(String encoding) {
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
|
@ -94,4 +94,6 @@ repomanager.db.url = jdbc:postgresql://194.177.192.119:5432/repomanager
|
|||
repomanager.db.username = dnet
|
||||
repomanager.db.password = dnetPwd
|
||||
|
||||
services.repomanager.analyticsURL = http://analytics.openaire.eu/addsite.php?
|
||||
services.repomanager.analyticsURL = http://analytics.openaire.eu/addsite.php?
|
||||
|
||||
topic_types.url = https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:topic_types.json
|
Loading…
Reference in New Issue