2020-04-27 14:52:31 +02:00
|
|
|
|
2020-04-08 13:18:20 +02:00
|
|
|
package eu.dnetlib.dhp.provision.update;
|
|
|
|
|
2020-04-18 12:42:58 +02:00
|
|
|
import java.io.IOException;
|
2020-04-28 11:23:29 +02:00
|
|
|
|
2020-04-08 13:18:20 +02:00
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
|
import org.apache.http.impl.client.HttpClients;
|
|
|
|
|
2020-04-28 11:23:29 +02:00
|
|
|
import eu.dnetlib.dhp.provision.scholix.ScholixResource;
|
|
|
|
|
2020-04-08 13:18:20 +02:00
|
|
|
public class DataciteClient {
|
|
|
|
|
2020-04-27 14:52:31 +02:00
|
|
|
private String host;
|
|
|
|
private String index = "datacite";
|
|
|
|
private String indexType = "dump";
|
2020-04-29 19:09:07 +02:00
|
|
|
private final Datacite2Scholix d2s;
|
2020-04-08 13:18:20 +02:00
|
|
|
|
2020-04-27 14:52:31 +02:00
|
|
|
public DataciteClient(String host) {
|
|
|
|
this.host = host;
|
2020-04-08 13:18:20 +02:00
|
|
|
|
2020-04-27 14:52:31 +02:00
|
|
|
d2s = new Datacite2Scholix(null);
|
|
|
|
d2s.setRootPath("$._source.attributes");
|
|
|
|
}
|
2020-04-08 13:18:20 +02:00
|
|
|
|
2020-04-27 14:52:31 +02:00
|
|
|
public Iterable<String> getDatasetsFromTs(final Long timestamp) {
|
|
|
|
return () -> {
|
|
|
|
try {
|
|
|
|
return new DataciteClientIterator(host, index, timestamp);
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2020-04-08 13:18:20 +02:00
|
|
|
|
2020-04-27 14:52:31 +02:00
|
|
|
public String getHost() {
|
|
|
|
return host;
|
|
|
|
}
|
2020-04-08 13:18:20 +02:00
|
|
|
|
2020-04-27 14:52:31 +02:00
|
|
|
public void setHost(String host) {
|
|
|
|
this.host = host;
|
|
|
|
}
|
2020-04-08 13:18:20 +02:00
|
|
|
|
2020-04-27 14:52:31 +02:00
|
|
|
public String getIndex() {
|
|
|
|
return index;
|
|
|
|
}
|
2020-04-08 13:18:20 +02:00
|
|
|
|
2020-04-27 14:52:31 +02:00
|
|
|
public void setIndex(String index) {
|
|
|
|
this.index = index;
|
|
|
|
}
|
2020-04-08 13:18:20 +02:00
|
|
|
|
2020-04-27 14:52:31 +02:00
|
|
|
public String getIndexType() {
|
|
|
|
return indexType;
|
|
|
|
}
|
2020-04-08 13:18:20 +02:00
|
|
|
|
2020-04-27 14:52:31 +02:00
|
|
|
public void setIndexType(String indexType) {
|
|
|
|
this.indexType = indexType;
|
|
|
|
}
|
2020-04-08 13:18:20 +02:00
|
|
|
|
2020-04-27 14:52:31 +02:00
|
|
|
public ScholixResource getDatasetByDOI(final String doi) {
|
|
|
|
try (CloseableHttpClient client = HttpClients.createDefault()) {
|
|
|
|
HttpGet httpGet = new HttpGet(
|
|
|
|
String
|
|
|
|
.format(
|
|
|
|
"http://%s:9200/%s/%s/%s", host, index, indexType, doi.replaceAll("/", "%2F")));
|
|
|
|
CloseableHttpResponse response = client.execute(httpGet);
|
|
|
|
final String json = IOUtils.toString(response.getEntity().getContent());
|
|
|
|
return d2s.generateDataciteScholixResource(json);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2020-04-08 13:18:20 +02:00
|
|
|
}
|