1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.dnetlib.dli.resolver;
|
5
|
|
6
|
import com.google.common.collect.Lists;
|
7
|
import eu.dnetlib.dli.resolver.model.CompletionStatus;
|
8
|
import eu.dnetlib.dli.resolver.model.DLIObjectProvenance;
|
9
|
import eu.dnetlib.dli.resolver.model.DLIResolvedObject;
|
10
|
|
11
|
import eu.dnetlib.pid.resolver.model.ObjectType;
|
12
|
import org.apache.commons.logging.Log;
|
13
|
import org.apache.commons.logging.LogFactory;
|
14
|
|
15
|
import java.util.List;
|
16
|
import java.util.Scanner;
|
17
|
|
18
|
/**
|
19
|
* @author sandro
|
20
|
*/
|
21
|
public class ANDSResolver extends DLIPIDResolver {
|
22
|
|
23
|
private static final String url = "http://researchdata.ands.org.au/registry/registry_object/exportToEndnote/%s.ris";
|
24
|
private static final Log log = LogFactory.getLog(ANDSResolver.class);
|
25
|
|
26
|
private static final String ANDS_NS_PREFIX = "r3d100010464";
|
27
|
private static final String ANDS_EXPECTED_TYPE = "url";
|
28
|
|
29
|
|
30
|
@Override
|
31
|
protected boolean canResolvePid(final String pidType) {
|
32
|
if (log.isDebugEnabled()) {
|
33
|
log.debug(String.format("Request resolve pidType :%s", pidType));
|
34
|
}
|
35
|
return (pidType != null && pidType.trim().toLowerCase().equals(ANDS_EXPECTED_TYPE));
|
36
|
}
|
37
|
|
38
|
@Override
|
39
|
protected DLIResolvedObject resolve(final String pid, final String pidType) {
|
40
|
if (!pid.contains("https://researchdata.ands.org.au/registry/registry_object/view/")) {
|
41
|
if (log.isDebugEnabled()) {
|
42
|
log.debug(String.format("the Pid:%s of type:%s cannot be resolved by ANDSDataciteResolver", pid, pidType));
|
43
|
}
|
44
|
return null;
|
45
|
}
|
46
|
String[] splitted = pid.split("/");
|
47
|
if (splitted == null || splitted.length == 0) return null;
|
48
|
final String identifier = splitted[splitted.length - 1];
|
49
|
try {
|
50
|
final String myString = requestURL(String.format(url, identifier));
|
51
|
log.debug("Found object " + myString);
|
52
|
Scanner scanner = new Scanner(myString);
|
53
|
DLIResolvedObject object = new DLIResolvedObject();
|
54
|
object.setCompletionStatus(CompletionStatus.complete.toString());
|
55
|
object.setPid(pid);
|
56
|
object.setPidType(pidType);
|
57
|
DLIObjectProvenance provenance = new DLIObjectProvenance();
|
58
|
setDatasourceProvenance(provenance, ANDS_NS_PREFIX);
|
59
|
object.setDatasourceProvenance(Lists.newArrayList(provenance));
|
60
|
object.fixContribution(provenance);
|
61
|
object.setType(ObjectType.dataset);
|
62
|
object.setCompletionStatus(CompletionStatus.complete.toString());
|
63
|
object.setDatasourceProvenance(Lists.newArrayList(provenance));
|
64
|
final List<String> authors = Lists.newArrayList();
|
65
|
final List<String> titles = Lists.newArrayList();
|
66
|
String date = null;
|
67
|
while (scanner.hasNextLine()) {
|
68
|
String line = scanner.nextLine();
|
69
|
if (line.contains("AU -")) {
|
70
|
authors.add(line.replace("AU -", ""));
|
71
|
}
|
72
|
|
73
|
if (line.contains("TI -")) {
|
74
|
titles.add(line.replace("TI -", ""));
|
75
|
}
|
76
|
|
77
|
if (line.contains("Y2 -")) {
|
78
|
date = line.replace("Y2 -", "");
|
79
|
}
|
80
|
}
|
81
|
object.setAuthors(authors);
|
82
|
object.setTitles(titles);
|
83
|
object.setCompletionStatus(CompletionStatus.complete.toString());
|
84
|
object.setDate(date);
|
85
|
scanner.close();
|
86
|
return object;
|
87
|
} catch (Throwable e) {
|
88
|
log.error(String.format("Error on resolving %s of type %s", pid, pidType));
|
89
|
return null;
|
90
|
}
|
91
|
}
|
92
|
|
93
|
}
|