1
|
package eu.dnetlib.resolver;
|
2
|
|
3
|
import com.googlecode.protobuf.format.JsonFormat;
|
4
|
import com.mongodb.MongoClient;
|
5
|
import com.mongodb.client.MongoCollection;
|
6
|
import eu.dnetlib.data.proto.dli.ScholixObjectProtos;
|
7
|
import eu.dnetlib.dli.resolver.*;
|
8
|
|
9
|
import java.net.URI;
|
10
|
|
11
|
import eu.dnetlib.dli.resolver.model.DLIResolvedObject;
|
12
|
import eu.dnetlib.msro.workflows.nodes.ResolveAndIndexJobNode;
|
13
|
import org.apache.commons.io.IOUtils;
|
14
|
import org.apache.commons.logging.Log;
|
15
|
import org.apache.commons.logging.LogFactory;
|
16
|
import org.bson.Document;
|
17
|
import org.junit.Test;
|
18
|
|
19
|
import java.io.IOException;
|
20
|
import java.io.InputStream;
|
21
|
import java.net.URISyntaxException;
|
22
|
import java.time.LocalDateTime;
|
23
|
import java.util.Arrays;
|
24
|
import java.util.List;
|
25
|
|
26
|
/**
|
27
|
* Created by sandro on 9/8/16.
|
28
|
*/
|
29
|
|
30
|
public class DLIResolverTest extends DLIAbstractTest {
|
31
|
|
32
|
private static final Log log = LogFactory.getLog(DLIResolverTest.class);
|
33
|
|
34
|
|
35
|
@Test
|
36
|
public void TestNCBIResolver() throws IOException, URISyntaxException {
|
37
|
NCBINResolver resolver = new NCBINResolver();
|
38
|
NCBINParser parser = new NCBINParser();
|
39
|
resolver.setNCBINParser(parser);
|
40
|
DLIResolvedObject resolve = resolver.resolve("mg456816", "ncbi");
|
41
|
CrossRefParserJSON parserJSON = new CrossRefParserJSON();
|
42
|
final String json = IOUtils.toString(this.getClass().getResourceAsStream("/eu/dnetlib/dli/parser/crossRefItem.json"));
|
43
|
|
44
|
DLIResolvedObject dliResolvedObject = parserJSON.parseRecord(json);
|
45
|
final ScholixObjectProtos.ScholixResource source = ResolveAndIndexJobNode.generateResource(resolve);
|
46
|
final ScholixObjectProtos.ScholixResource target = ResolveAndIndexJobNode.generateResource(dliResolvedObject);
|
47
|
|
48
|
final ScholixObjectProtos.Scholix.Builder scholix = ScholixObjectProtos.Scholix.newBuilder();
|
49
|
|
50
|
scholix.addLinkproviderBuilder()
|
51
|
.setName("Elsevier")
|
52
|
.addIdentifiersBuilder()
|
53
|
.setIdentifier("dli_________::elsevier")
|
54
|
.setSchema("dnetIdentifier");
|
55
|
|
56
|
scholix.setRelationship(ScholixObjectProtos.ScholixRelationship.newBuilder()
|
57
|
.setName("IsRelatedTo")
|
58
|
.setInverse("IsRelatedTo")
|
59
|
.setSchema("datacite")
|
60
|
.build());
|
61
|
|
62
|
|
63
|
scholix.setSource(source);
|
64
|
scholix.setTarget(target);
|
65
|
scholix.setPublicationDate(LocalDateTime.now().toString());
|
66
|
|
67
|
String id ="AWWmUI5Q653lpHSHRYaq";
|
68
|
|
69
|
final String curlString =String.format("curl -X PUT \"10.0.6.47:9200/dli/scholix/%s \" -H 'Content-Type: application/json' -d'%s'",id,JsonFormat.printToString(scholix.build()));
|
70
|
|
71
|
System.out.println(curlString);
|
72
|
}
|
73
|
|
74
|
|
75
|
@Test
|
76
|
public void testDataciteOfflineResolver() {
|
77
|
MongoClient client = new MongoClient();
|
78
|
MongoCollection<Document> collection = client.getDatabase("datacite_resolver").getCollection("datacite");
|
79
|
|
80
|
|
81
|
List<String> dois = Arrays.asList(
|
82
|
"10.1594/pangaea.230638");
|
83
|
|
84
|
DataciteOfflineResolver resolver = new DataciteOfflineResolver();
|
85
|
resolver.setMongoClient(client);
|
86
|
resolver.setDatabaseName("datacite_resolver");
|
87
|
resolver.setCollectionName("datacite");
|
88
|
dois.forEach(it -> System.out.println(resolver.resolve(it, "doi")));
|
89
|
|
90
|
|
91
|
|
92
|
}
|
93
|
|
94
|
@Test
|
95
|
public void testDataciteResolver() {
|
96
|
DataciteResolver resolver = new DataciteResolver();
|
97
|
System.out.println(resolver.resolve("10.5438/0012", "doi"));
|
98
|
}
|
99
|
|
100
|
}
|
101
|
|