1
|
package eu.dnetlib.msro.workflows.nodes.info;
|
2
|
|
3
|
import java.io.StringReader;
|
4
|
import java.util.HashMap;
|
5
|
import java.util.Map;
|
6
|
|
7
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
8
|
import eu.dnetlib.msro.workflows.graph.Arc;
|
9
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
10
|
import eu.dnetlib.msro.workflows.procs.Env;
|
11
|
import eu.dnetlib.rmi.datasource.DatasourceManagerService;
|
12
|
import eu.dnetlib.rmi.enabling.ISLookUpService;
|
13
|
import org.dom4j.Document;
|
14
|
import org.dom4j.Node;
|
15
|
import org.dom4j.io.SAXReader;
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
17
|
|
18
|
public class ObjectStoreToApiExtraFieldJobNode extends SimpleJobNode {
|
19
|
|
20
|
private String objId;
|
21
|
private String datasourceId;
|
22
|
private String datasourceInterface;
|
23
|
private String extraFieldForTotal;
|
24
|
private String extraFieldForDate;
|
25
|
private String extraFieldForObjId;
|
26
|
|
27
|
@Autowired
|
28
|
private UniqueServiceLocator serviceLocator;
|
29
|
|
30
|
@Override
|
31
|
protected String execute(final Env env) throws Exception {
|
32
|
final String xq = "for $x in collection('/db/DRIVER/ObjectStoreDSResources/ObjectStoreDSResourceType') " + "where $x//RESOURCE_IDENTIFIER/@value='"
|
33
|
+ this.objId + "' " + "return concat($x//COUNT_STORE, ' @=@ ', $x//LAST_STORAGE_DATE)";
|
34
|
|
35
|
final String s = this.serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(xq);
|
36
|
|
37
|
final String[] arr = s.split(" @=@ ");
|
38
|
|
39
|
final Map<String, String> map = getCurrentExtraFields(this.datasourceId, this.datasourceInterface);
|
40
|
map.put(this.extraFieldForTotal, arr[0].trim());
|
41
|
map.put(this.extraFieldForDate, arr[1].trim());
|
42
|
map.put(this.extraFieldForObjId, this.objId);
|
43
|
|
44
|
this.serviceLocator.getService(DatasourceManagerService.class).bulkUpdateApiExtraFields(this.datasourceId, this.datasourceInterface, map);
|
45
|
|
46
|
return Arc.DEFAULT_ARC;
|
47
|
}
|
48
|
|
49
|
private Map<String, String> getCurrentExtraFields(final String repoId, final String ifaceId) throws Exception {
|
50
|
final Map<String, String> res = new HashMap<>();
|
51
|
|
52
|
final String profile = this.serviceLocator.getService(ISLookUpService.class).getResourceProfile(repoId);
|
53
|
|
54
|
final SAXReader reader = new SAXReader();
|
55
|
final Document doc = reader.read(new StringReader(profile));
|
56
|
|
57
|
final Node ifcNode = doc.selectSingleNode("//INTERFACE[@id='" + ifaceId + "']");
|
58
|
if (ifcNode != null) {
|
59
|
for (final Object o : ifcNode.selectNodes("./INTERFACE_EXTRA_FIELD")) {
|
60
|
res.put(((Node) o).valueOf("@name"), ((Node) o).getText());
|
61
|
}
|
62
|
}
|
63
|
|
64
|
return res;
|
65
|
}
|
66
|
|
67
|
public String getDatasourceId() {
|
68
|
return this.datasourceId;
|
69
|
}
|
70
|
|
71
|
public void setDatasourceId(final String datasourceId) {
|
72
|
this.datasourceId = datasourceId;
|
73
|
}
|
74
|
|
75
|
public String getDatasourceInterface() {
|
76
|
return this.datasourceInterface;
|
77
|
}
|
78
|
|
79
|
public void setDatasourceInterface(final String datasourceInterface) {
|
80
|
this.datasourceInterface = datasourceInterface;
|
81
|
}
|
82
|
|
83
|
public String getExtraFieldForTotal() {
|
84
|
return this.extraFieldForTotal;
|
85
|
}
|
86
|
|
87
|
public void setExtraFieldForTotal(final String extraFieldForTotal) {
|
88
|
this.extraFieldForTotal = extraFieldForTotal;
|
89
|
}
|
90
|
|
91
|
public String getExtraFieldForDate() {
|
92
|
return this.extraFieldForDate;
|
93
|
}
|
94
|
|
95
|
public void setExtraFieldForDate(final String extraFieldForDate) {
|
96
|
this.extraFieldForDate = extraFieldForDate;
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* @return the objId
|
101
|
*/
|
102
|
public String getObjId() {
|
103
|
return this.objId;
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* @param objId
|
108
|
* the objId to set
|
109
|
*/
|
110
|
public void setObjId(final String objId) {
|
111
|
this.objId = objId;
|
112
|
}
|
113
|
|
114
|
/**
|
115
|
* @return the extraFieldForObjId
|
116
|
*/
|
117
|
public String getExtraFieldForObjId() {
|
118
|
return this.extraFieldForObjId;
|
119
|
}
|
120
|
|
121
|
/**
|
122
|
* @param extraFieldForObjId
|
123
|
* the extraFieldForObjId to set
|
124
|
*/
|
125
|
public void setExtraFieldForObjId(final String extraFieldForObjId) {
|
126
|
this.extraFieldForObjId = extraFieldForObjId;
|
127
|
}
|
128
|
|
129
|
}
|