1 |
31965
|
alessia.ba
|
package eu.dnetlib.api.utils;
|
2 |
|
|
|
3 |
|
|
import java.util.List;
|
4 |
|
|
|
5 |
50412
|
alessia.ba
|
import com.google.common.collect.Lists;
|
6 |
31965
|
alessia.ba
|
import org.dom4j.Attribute;
|
7 |
|
|
import org.dom4j.Document;
|
8 |
|
|
import org.dom4j.Node;
|
9 |
|
|
|
10 |
|
|
public class OpenAireDocumentPage {
|
11 |
|
|
|
12 |
|
|
private Document doc;
|
13 |
|
|
private ResponseHeader responseHeader;
|
14 |
|
|
|
15 |
|
|
public List<String> getObjIdentifiers() {
|
16 |
|
|
List<String> objIds = Lists.newArrayList();
|
17 |
|
|
@SuppressWarnings("unchecked")
|
18 |
|
|
List<Node> objList = doc.selectNodes("//*[local-name() = 'objIdentifier']");
|
19 |
|
|
for (Node objNode : objList) {
|
20 |
|
|
objIds.add(objNode.getText());
|
21 |
|
|
}
|
22 |
|
|
return objIds;
|
23 |
|
|
}
|
24 |
|
|
|
25 |
50412
|
alessia.ba
|
public boolean allWithECFunding() {
|
26 |
|
|
return allWithContextId("funding", "EC");
|
27 |
31965
|
alessia.ba
|
}
|
28 |
|
|
|
29 |
50412
|
alessia.ba
|
public boolean allWithWTFunding() {
|
30 |
|
|
return allWithContextId("funding", "WT");
|
31 |
31965
|
alessia.ba
|
}
|
32 |
|
|
|
33 |
|
|
public boolean allWithContextId(final String contextType, final String contextID) {
|
34 |
|
|
@SuppressWarnings("unchecked")
|
35 |
50412
|
alessia.ba
|
List<Node> entities = doc.selectNodes("//*[local-name()='entity']");
|
36 |
|
|
for(Node e : entities){
|
37 |
|
|
List<Attribute> fundingList = e.selectNodes("//context[./@type='" + contextType + "']/@id");
|
38 |
|
|
boolean found = false;
|
39 |
|
|
for (Attribute fundingId : fundingList) {
|
40 |
|
|
if(fundingId.getValue().equals(contextID)) {
|
41 |
|
|
found = true;
|
42 |
|
|
break;
|
43 |
|
|
}
|
44 |
|
|
}
|
45 |
|
|
if(!found) return false;
|
46 |
31965
|
alessia.ba
|
}
|
47 |
|
|
return true;
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
public Document getDoc() {
|
51 |
|
|
return doc;
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
public void setDoc(final Document doc) {
|
55 |
|
|
this.doc = doc;
|
56 |
|
|
this.setResponseHeader(new ResponseHeader(this.doc));
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
public ResponseHeader getResponseHeader() {
|
60 |
|
|
return responseHeader;
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
public void setResponseHeader(final ResponseHeader responseHeader) {
|
64 |
|
|
this.responseHeader = responseHeader;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
public OpenAireDocumentPage(final Document doc) {
|
68 |
|
|
super();
|
69 |
|
|
setDoc(doc);
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
}
|