Revision 49184
Added by Sandro La Bruzzo over 6 years ago
DataciteResolver.java | ||
---|---|---|
7 | 7 |
import com.google.gson.JsonElement; |
8 | 8 |
import com.google.gson.JsonObject; |
9 | 9 |
import com.google.gson.JsonParser; |
10 |
import eu.dnetlib.dli.DLIUtils; |
|
11 | 10 |
import eu.dnetlib.dli.resolver.model.*; |
11 |
import eu.dnetlib.pid.resolver.AbstractPIDResolver; |
|
12 |
import eu.dnetlib.pid.resolver.model.ObjectProvenance; |
|
13 |
import eu.dnetlib.pid.resolver.model.ObjectType; |
|
12 | 14 |
import org.apache.commons.logging.Log; |
13 | 15 |
import org.apache.commons.logging.LogFactory; |
14 | 16 |
|
... | ... | |
30 | 32 |
*/ |
31 | 33 |
private final static String baseURL = "http://search.datacite.org/api?wt=json&q=doi:"; |
32 | 34 |
|
33 |
private ResolvedObject parseResponse(final String response) { |
|
35 |
private DLIResolvedObject parseResponse(final String response) {
|
|
34 | 36 |
if (response == null) return null; |
35 | 37 |
JsonElement jElement = new JsonParser().parse(response); |
36 | 38 |
JsonObject jobject = jElement.getAsJsonObject(); |
... | ... | |
39 | 41 |
long total = jobject.get("response").getAsJsonObject().get("numFound").getAsLong(); |
40 | 42 |
|
41 | 43 |
if (total == 0) return null; |
42 |
ResolvedObject responseObj = new ResolvedObject();
|
|
44 |
DLIResolvedObject responseObj = new DLIResolvedObject();
|
|
43 | 45 |
|
44 | 46 |
JsonElement hits = ((JsonObject) jobject.get("response")).get("docs"); |
45 | 47 |
|
... | ... | |
102 | 104 |
} |
103 | 105 |
responseObj.setAuthors(authors); |
104 | 106 |
|
105 |
ObjectProvenance provenance = new ObjectProvenance();
|
|
106 |
setDatasourceProvenance(provenance, DATACITE_NS_PREFIX); |
|
107 |
final DLIObjectProvenance provenance = new DLIObjectProvenance();
|
|
108 |
DLIPIDResolver.setDatasourceProvenance(provenance, DATACITE_NS_PREFIX);
|
|
107 | 109 |
|
108 | 110 |
final String dataCenter_symbol = ((JsonObject) elem).get("datacentre_symbol").getAsString(); |
109 | 111 |
final String datacenter = ((JsonObject) elem).get("datacentre").getAsString(); |
... | ... | |
130 | 132 |
} |
131 | 133 |
|
132 | 134 |
@Override |
133 |
protected ResolvedObject resolve(final String pid, final String pidType) { |
|
135 |
protected DLIResolvedObject resolve(final String pid, final String pidType) {
|
|
134 | 136 |
try { |
135 | 137 |
final String response = requestURL(baseURL + pid.replace(" ", "%20")); |
136 | 138 |
return parseResponse(response); |
Also available in: Unified diff
Refactored Pid resolver