1
|
package eu.dnetlib.functionality.modular.ui.workflows.util;
|
2
|
|
3
|
import java.io.StringReader;
|
4
|
import java.util.List;
|
5
|
|
6
|
import javax.annotation.Resource;
|
7
|
|
8
|
import org.apache.commons.logging.Log;
|
9
|
import org.apache.commons.logging.LogFactory;
|
10
|
import org.dom4j.Document;
|
11
|
import org.dom4j.Element;
|
12
|
import org.dom4j.Node;
|
13
|
import org.dom4j.io.SAXReader;
|
14
|
|
15
|
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException;
|
16
|
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
|
17
|
import eu.dnetlib.enabling.tools.ServiceLocator;
|
18
|
import eu.dnetlib.functionality.modular.ui.workflows.objects.AdvancedMetaWorkflowDescriptor;
|
19
|
import eu.dnetlib.functionality.modular.ui.workflows.objects.NodeInfo;
|
20
|
import eu.dnetlib.functionality.modular.ui.workflows.objects.NodeWithUserParams;
|
21
|
import eu.dnetlib.msro.workflows.util.WorkflowParam;
|
22
|
import eu.dnetlib.msro.workflows.util.WorkflowsConstants.WorkflowStatus;
|
23
|
|
24
|
public class ISRegistryClient {
|
25
|
|
26
|
@Resource(name = "registryLocator")
|
27
|
private ServiceLocator<ISRegistryService> registryLocator;
|
28
|
|
29
|
private static final Log log = LogFactory.getLog(ISRegistryClient.class);
|
30
|
|
31
|
public String registerProfile(final String profile) throws ISRegistryException {
|
32
|
return registryLocator.getService().registerProfile(profile);
|
33
|
}
|
34
|
|
35
|
public boolean updateSarasvatiWorkflow(final String wfId, final String profile, final NodeInfo info) throws Exception {
|
36
|
final Document doc = (new SAXReader()).read(new StringReader(profile));
|
37
|
|
38
|
final Node node = doc.selectSingleNode("//NODE[@name='" + info.getName() + "']");
|
39
|
if (node == null) {
|
40
|
log.error("Node " + info.getName() + " not found in profile " + profile);
|
41
|
} else {
|
42
|
node.selectSingleNode("./DESCRIPTION").setText(info.getDescription());
|
43
|
for (WorkflowParam param : info.getParams()) {
|
44
|
if (param.isUserParam()) {
|
45
|
final String val = (param.getValue() != null) ? param.getValue() : "";
|
46
|
node.selectSingleNode(".//PARAM[@name='" + param.getName() + "']").setText(val);
|
47
|
}
|
48
|
}
|
49
|
}
|
50
|
|
51
|
return registryLocator.getService().updateProfile(wfId, doc.asXML(), doc.valueOf("//RESOURCE_TYPE/@value"));
|
52
|
}
|
53
|
|
54
|
|
55
|
public boolean updateSarasvatiWorkflow(final String wfId, final String profile, final List<NodeWithUserParams> list) throws Exception {
|
56
|
final Document doc = (new SAXReader()).read(new StringReader(profile));
|
57
|
for (NodeWithUserParams n : list) {
|
58
|
final Node node = doc.selectSingleNode("//NODE[@name='" + n.getNode() + "']");
|
59
|
if (node == null) {
|
60
|
log.error("Node " + n.getNode() + " not found in profile " + profile);
|
61
|
} else {
|
62
|
for (WorkflowParam param : n.getParams()) {
|
63
|
final String val = (param.getValue() != null) ? param.getValue() : "";
|
64
|
node.selectSingleNode(".//PARAM[@name='" + param.getName() + "']").setText(val);
|
65
|
}
|
66
|
}
|
67
|
}
|
68
|
|
69
|
return registryLocator.getService().updateProfile(wfId, doc.asXML(), doc.valueOf("//RESOURCE_TYPE/@value"));
|
70
|
}
|
71
|
|
72
|
public boolean updateSarasvatiMetaWorkflow(final String wfId, final String profile, final AdvancedMetaWorkflowDescriptor info) throws Exception {
|
73
|
final Document doc = (new SAXReader()).read(new StringReader(profile));
|
74
|
|
75
|
doc.selectSingleNode("//METAWORKFLOW_NAME").setText(info.getName());
|
76
|
if (info.getEmail() != null) {
|
77
|
doc.selectSingleNode("//ADMIN_EMAIL").setText(info.getEmail());
|
78
|
} else {
|
79
|
doc.selectSingleNode("//ADMIN_EMAIL").setText("");
|
80
|
}
|
81
|
Node node = doc.selectSingleNode("//SCHEDULING");
|
82
|
((Element) node).addAttribute("enabled", Boolean.toString(info.isScheduled()));
|
83
|
node.selectSingleNode("./CRON").setText(info.getCronExpression());
|
84
|
node.selectSingleNode("./MININTERVAL").setText(Integer.toString(info.getMinInterval()));
|
85
|
|
86
|
return registryLocator.getService().updateProfile(wfId, doc.asXML(), doc.valueOf("//RESOURCE_TYPE/@value"));
|
87
|
}
|
88
|
|
89
|
public void configureWorkflowStart(final String id, final String value) throws ISRegistryException {
|
90
|
registryLocator.getService().updateProfileNode(id, "//CONFIGURATION/@start", "'" + value + "'");
|
91
|
}
|
92
|
|
93
|
public void updateMetaWorkflowStatus(final String id, final WorkflowStatus status) throws ISRegistryException {
|
94
|
registryLocator.getService().updateProfileNode(id, "//CONFIGURATION/@status", "'" + status.toString() + "'");
|
95
|
}
|
96
|
|
97
|
}
|