1
|
package eu.dnetlib.msro.workflows.metawf;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.io.StringWriter;
|
5
|
import java.util.List;
|
6
|
import java.util.Map;
|
7
|
|
8
|
import javax.annotation.Resource;
|
9
|
|
10
|
import org.apache.commons.lang.StringEscapeUtils;
|
11
|
import org.springframework.beans.factory.annotation.Required;
|
12
|
|
13
|
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException;
|
14
|
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
|
15
|
import eu.dnetlib.enabling.tools.ServiceLocator;
|
16
|
|
17
|
public class WorkflowTree {
|
18
|
|
19
|
private String id;
|
20
|
|
21
|
private String name;
|
22
|
|
23
|
private String start = "auto";
|
24
|
|
25
|
private List<WorkflowTree> children;
|
26
|
|
27
|
private org.springframework.core.io.Resource template;
|
28
|
|
29
|
@Resource(name = "registryLocator")
|
30
|
private ServiceLocator<ISRegistryService> registryLocator;
|
31
|
|
32
|
public void populateMetaWfXml(final StringWriter sw) {
|
33
|
sw.append("<WORKFLOW id='" + StringEscapeUtils.escapeXml(id) + "' name='" + StringEscapeUtils.escapeXml(name) + "'");
|
34
|
|
35
|
if ((children == null) || children.isEmpty()) {
|
36
|
sw.append(" />");
|
37
|
} else {
|
38
|
sw.append(">");
|
39
|
for (WorkflowTree child : children) {
|
40
|
child.populateMetaWfXml(sw);
|
41
|
}
|
42
|
sw.append("</WORKFLOW>");
|
43
|
}
|
44
|
}
|
45
|
|
46
|
public int registerAllWorkflows(final Map<String, String> params) throws ISRegistryException, IOException {
|
47
|
int count = 0;
|
48
|
|
49
|
if ((this.id == null) || this.id.isEmpty()) {
|
50
|
final String profile = WorkflowProfileCreator.generateProfile(name, "aggregator", params, template);
|
51
|
this.id = registryLocator.getService().registerProfile(profile);
|
52
|
count++;
|
53
|
}
|
54
|
|
55
|
if (children != null) {
|
56
|
for (WorkflowTree child : children) {
|
57
|
count += child.registerAllWorkflows(params);
|
58
|
}
|
59
|
}
|
60
|
return count;
|
61
|
}
|
62
|
|
63
|
public String getId() {
|
64
|
return id;
|
65
|
}
|
66
|
|
67
|
public List<WorkflowTree> getChildren() {
|
68
|
return children;
|
69
|
}
|
70
|
|
71
|
public void setChildren(final List<WorkflowTree> children) {
|
72
|
this.children = children;
|
73
|
}
|
74
|
|
75
|
public String getName() {
|
76
|
return name;
|
77
|
}
|
78
|
|
79
|
@Required
|
80
|
public void setName(final String name) {
|
81
|
this.name = name;
|
82
|
}
|
83
|
|
84
|
public org.springframework.core.io.Resource getTemplate() {
|
85
|
return template;
|
86
|
}
|
87
|
|
88
|
@Required
|
89
|
public void setTemplate(final org.springframework.core.io.Resource template) {
|
90
|
this.template = template;
|
91
|
}
|
92
|
|
93
|
public String getStart() {
|
94
|
return start;
|
95
|
}
|
96
|
|
97
|
public void setStart(final String start) {
|
98
|
this.start = start;
|
99
|
}
|
100
|
|
101
|
}
|