1
|
package eu.dnetlib.msro.openaireplus.workflows.nodes.contexts;
|
2
|
|
3
|
import java.util.Map;
|
4
|
import java.util.Map.Entry;
|
5
|
|
6
|
import com.google.common.collect.Maps;
|
7
|
import org.dom4j.DocumentHelper;
|
8
|
import org.dom4j.Element;
|
9
|
|
10
|
public class ContextPart {
|
11
|
|
12
|
private String id;
|
13
|
private String label;
|
14
|
private Map<String, String> params = Maps.newLinkedHashMap();
|
15
|
private Map<String, ContextPart> parts = Maps.newLinkedHashMap();
|
16
|
|
17
|
public ContextPart() {
|
18
|
}
|
19
|
|
20
|
public ContextPart(final String id, final String label) {
|
21
|
this.id = id;
|
22
|
this.label = label;
|
23
|
}
|
24
|
|
25
|
public String getId() {
|
26
|
return id;
|
27
|
}
|
28
|
|
29
|
public void setId(final String id) {
|
30
|
this.id = id;
|
31
|
}
|
32
|
|
33
|
public String getLabel() {
|
34
|
return label;
|
35
|
}
|
36
|
|
37
|
public void setLabel(final String label) {
|
38
|
this.label = label;
|
39
|
}
|
40
|
|
41
|
public Map<String, String> getParams() {
|
42
|
return params;
|
43
|
}
|
44
|
|
45
|
public void setParams(final Map<String, String> params) {
|
46
|
this.params = params;
|
47
|
}
|
48
|
|
49
|
public Map<String, ContextPart> getParts() {
|
50
|
return parts;
|
51
|
}
|
52
|
|
53
|
public void setParts(final Map<String, ContextPart> parts) {
|
54
|
this.parts = parts;
|
55
|
}
|
56
|
|
57
|
public void addPart(final ContextPart part) {
|
58
|
if (parts.containsKey(part.getId())) {
|
59
|
final ContextPart localChild = getParts().get(part.getId());
|
60
|
for (ContextPart child : part.getParts().values()) {
|
61
|
localChild.addPart(child);
|
62
|
}
|
63
|
} else {
|
64
|
parts.put(part.getId(), part);
|
65
|
}
|
66
|
}
|
67
|
|
68
|
public Element asDomElement(final String name) {
|
69
|
final Element elem = DocumentHelper.createElement(name);
|
70
|
elem.addAttribute("id", id);
|
71
|
elem.addAttribute("label", label);
|
72
|
elem.addAttribute("claim", "false");
|
73
|
for (Entry<String, String> e : params.entrySet()) {
|
74
|
final Element p = elem.addElement("param");
|
75
|
p.addAttribute("name", e.getKey());
|
76
|
p.setText(e.getValue());
|
77
|
}
|
78
|
for (ContextPart child : parts.values()) {
|
79
|
elem.add(child.asDomElement("concept"));
|
80
|
}
|
81
|
return elem;
|
82
|
}
|
83
|
}
|