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