diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApi.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApi.java index f4fbd17..e129b42 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApi.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApi.java @@ -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 getDnetTopics() throws BrokerException; } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApiImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApiImpl.java index a786eae..d5952a9 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApiImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/controllers/BrokerApiImpl.java @@ -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 topics = new HashMap(); + + @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 getDnetTopics() throws BrokerException { + return topics; + } } diff --git a/src/main/java/eu/dnetlib/repo/manager/shared/Term.java b/src/main/java/eu/dnetlib/repo/manager/shared/Term.java new file mode 100644 index 0000000..9f3c58a --- /dev/null +++ b/src/main/java/eu/dnetlib/repo/manager/shared/Term.java @@ -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; + } +} diff --git a/src/main/resources/eu/dnetlib/repo/manager/service/application.properties b/src/main/resources/eu/dnetlib/repo/manager/service/application.properties index cc73cf4..047ecbf 100644 --- a/src/main/resources/eu/dnetlib/repo/manager/service/application.properties +++ b/src/main/resources/eu/dnetlib/repo/manager/service/application.properties @@ -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? \ No newline at end of file +services.repomanager.analyticsURL = http://analytics.openaire.eu/addsite.php? + +topic_types.url = https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:topic_types.json \ No newline at end of file