1 |
26600
|
sandro.lab
|
package eu.dnetlib.functionality.modular.ui.workflows.util;
|
2 |
|
|
|
3 |
|
|
import java.io.StringReader;
|
4 |
39947
|
michele.ar
|
import java.util.Map;
|
5 |
41838
|
michele.ar
|
|
6 |
42621
|
sandro.lab
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
7 |
|
|
import eu.dnetlib.functionality.modular.ui.workflows.objects.WorkflowNotificationInfo;
|
8 |
|
|
import eu.dnetlib.functionality.modular.ui.workflows.objects.WorkflowUpdateInfo;
|
9 |
|
|
import eu.dnetlib.msro.workflows.util.WorkflowsConstants.WorkflowStatus;
|
10 |
|
|
import eu.dnetlib.rmi.enabling.ISRegistryException;
|
11 |
|
|
import eu.dnetlib.rmi.enabling.ISRegistryService;
|
12 |
39509
|
michele.ar
|
import org.apache.commons.logging.Log;
|
13 |
|
|
import org.apache.commons.logging.LogFactory;
|
14 |
|
|
import org.dom4j.Document;
|
15 |
|
|
import org.dom4j.Element;
|
16 |
|
|
import org.dom4j.Node;
|
17 |
|
|
import org.dom4j.io.SAXReader;
|
18 |
42621
|
sandro.lab
|
import org.springframework.beans.factory.annotation.Autowired;
|
19 |
26600
|
sandro.lab
|
|
20 |
|
|
public class ISRegistryClient {
|
21 |
|
|
|
22 |
39509
|
michele.ar
|
private static final Log log = LogFactory.getLog(ISRegistryClient.class);
|
23 |
42621
|
sandro.lab
|
@Autowired
|
24 |
32665
|
michele.ar
|
private UniqueServiceLocator serviceLocator;
|
25 |
26600
|
sandro.lab
|
|
26 |
|
|
public String registerProfile(final String profile) throws ISRegistryException {
|
27 |
41838
|
michele.ar
|
return this.serviceLocator.getService(ISRegistryService.class).registerProfile(profile);
|
28 |
26600
|
sandro.lab
|
}
|
29 |
|
|
|
30 |
42174
|
michele.ar
|
public void deleteProfile(final String id) throws ISRegistryException {
|
31 |
|
|
this.serviceLocator.getService(ISRegistryService.class).deleteProfile(id);
|
32 |
|
|
}
|
33 |
|
|
|
34 |
40096
|
michele.ar
|
public boolean updateWorkflowProfile(final String wfId, final String profile, final Map<String, String> map) throws Exception {
|
35 |
32665
|
michele.ar
|
final Document doc = new SAXReader().read(new StringReader(profile));
|
36 |
41838
|
michele.ar
|
for (final Map.Entry<String, String> e : map.entrySet()) {
|
37 |
39947
|
michele.ar
|
final Node node = doc.selectSingleNode("//CONFIGURATION/PARAMETERS/PARAM[@name='" + e.getKey() + "']");
|
38 |
28130
|
michele.ar
|
if (node == null) {
|
39 |
39947
|
michele.ar
|
log.error("Param " + e.getKey() + " not found in profile " + profile);
|
40 |
28130
|
michele.ar
|
} else {
|
41 |
39947
|
michele.ar
|
final String val = e.getValue() != null ? e.getValue() : "";
|
42 |
|
|
if (node.valueOf("@managedBy").equalsIgnoreCase("user")) {
|
43 |
|
|
node.setText(val);
|
44 |
|
|
} else {
|
45 |
|
|
log.debug("Param " + e.getKey() + " not updated, it is not editable by user");
|
46 |
28130
|
michele.ar
|
}
|
47 |
39947
|
michele.ar
|
|
48 |
28130
|
michele.ar
|
}
|
49 |
|
|
}
|
50 |
32665
|
michele.ar
|
|
51 |
39947
|
michele.ar
|
// Update the Workflow status
|
52 |
|
|
if (doc.selectNodes("//CONFIGURATION/PARAMETERS/PARAM[@required='true' and string-length(normalize-space(.)) = 0]").isEmpty()) {
|
53 |
|
|
((Element) doc.selectSingleNode("//CONFIGURATION")).addAttribute("status", WorkflowStatus.EXECUTABLE.name());
|
54 |
|
|
} else {
|
55 |
|
|
((Element) doc.selectSingleNode("//CONFIGURATION")).addAttribute("status", WorkflowStatus.WAIT_USER_SETTINGS.name());
|
56 |
|
|
}
|
57 |
|
|
|
58 |
41838
|
michele.ar
|
return this.serviceLocator.getService(ISRegistryService.class).updateProfile(wfId, doc.asXML(), doc.valueOf("//RESOURCE_TYPE/@value"));
|
59 |
28130
|
michele.ar
|
}
|
60 |
26600
|
sandro.lab
|
|
61 |
40096
|
michele.ar
|
public boolean updateWorkflowProfile(final String wfId, final String profile, final WorkflowUpdateInfo info) throws Exception {
|
62 |
32665
|
michele.ar
|
final Document doc = new SAXReader().read(new StringReader(profile));
|
63 |
26600
|
sandro.lab
|
|
64 |
40101
|
michele.ar
|
doc.selectSingleNode("//CONFIGURATION/@start").setText(info.getMode().toString());
|
65 |
42276
|
michele.ar
|
|
66 |
|
|
final Element notificationsNode = (Element) doc.selectSingleNode("//NOTIFICATIONS");
|
67 |
|
|
notificationsNode.clearContent();
|
68 |
|
|
if (info.getNotifications() != null) {
|
69 |
|
|
for (final WorkflowNotificationInfo n : info.getNotifications()) {
|
70 |
|
|
final Element emailNode = notificationsNode.addElement("EMAIL");
|
71 |
|
|
emailNode.addAttribute("address", n.getEmail());
|
72 |
|
|
emailNode.addAttribute("messageProfileId", n.getMessageProfileId());
|
73 |
|
|
emailNode.addAttribute("condition", n.getCondition().toString());
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
|
77 |
39792
|
michele.ar
|
doc.selectSingleNode("//WORKFLOW_PRIORITY").setText(Integer.toString(info.getPriority()));
|
78 |
39781
|
michele.ar
|
|
79 |
|
|
final Node node = doc.selectSingleNode("//SCHEDULING");
|
80 |
|
|
((Element) node).addAttribute("enabled", Boolean.toString(info.isScheduled()));
|
81 |
|
|
if (info.isScheduled()) {
|
82 |
|
|
node.selectSingleNode("./CRON").setText(info.getCron() != null ? info.getCron() : "");
|
83 |
|
|
node.selectSingleNode("./MININTERVAL").setText(Integer.toString(info.getInterval()));
|
84 |
26600
|
sandro.lab
|
}
|
85 |
41838
|
michele.ar
|
return this.serviceLocator.getService(ISRegistryService.class).updateProfile(wfId, doc.asXML(), doc.valueOf("//RESOURCE_TYPE/@value"));
|
86 |
26600
|
sandro.lab
|
}
|
87 |
39781
|
michele.ar
|
|
88 |
39624
|
michele.ar
|
public void updateWorkflowStatus(final String id, final WorkflowStatus status) throws ISRegistryException {
|
89 |
41838
|
michele.ar
|
this.serviceLocator.getService(ISRegistryService.class).updateProfileNode(id, "//CONFIGURATION/@status", "'" + status.toString() + "'");
|
90 |
26600
|
sandro.lab
|
}
|
91 |
|
|
|
92 |
|
|
}
|