1
|
package eu.dnetlib.msro.workflows.nodes.repohi;
|
2
|
|
3
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
4
|
import eu.dnetlib.msro.workflows.graph.Arc;
|
5
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
6
|
import eu.dnetlib.msro.workflows.procs.Env;
|
7
|
import eu.dnetlib.msro.workflows.procs.ProcessAware;
|
8
|
import eu.dnetlib.msro.workflows.procs.WorkflowProcess;
|
9
|
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
|
10
|
import eu.dnetlib.rmi.enabling.ISRegistryService;
|
11
|
import org.antlr.stringtemplate.StringTemplate;
|
12
|
import org.apache.commons.io.IOUtils;
|
13
|
import org.apache.commons.lang3.StringEscapeUtils;
|
14
|
import org.apache.commons.logging.Log;
|
15
|
import org.apache.commons.logging.LogFactory;
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
17
|
|
18
|
public class RegisterWorkflowFromTemplateJobNode extends SimpleJobNode implements ProcessAware {
|
19
|
|
20
|
private static final Log log = LogFactory.getLog(RegisterWorkflowFromTemplateJobNode.class);
|
21
|
private String wfName;
|
22
|
private String wfTemplate;
|
23
|
private String description;
|
24
|
private WorkflowProcess process;
|
25
|
@Autowired
|
26
|
private UniqueServiceLocator serviceLocator;
|
27
|
|
28
|
public String getWfName() {
|
29
|
return this.wfName;
|
30
|
}
|
31
|
|
32
|
public void setWfName(final String wfName) {
|
33
|
this.wfName = wfName;
|
34
|
}
|
35
|
|
36
|
public String getWfTemplate() {
|
37
|
return this.wfTemplate;
|
38
|
}
|
39
|
|
40
|
public void setWfTemplate(final String wfTemplate) {
|
41
|
this.wfTemplate = wfTemplate;
|
42
|
}
|
43
|
|
44
|
public String getDescription() {
|
45
|
return this.description;
|
46
|
}
|
47
|
|
48
|
public void setDescription(final String description) {
|
49
|
this.description = description;
|
50
|
}
|
51
|
|
52
|
@Override
|
53
|
protected String execute(final Env env) throws Exception {
|
54
|
final String dsId = this.process.getDsId();
|
55
|
final String ifaceId = this.process.getDsInterface();
|
56
|
|
57
|
final StringTemplate profTemplate = new StringTemplate(IOUtils.toString(getClass().getResourceAsStream(getWfTemplate())));
|
58
|
profTemplate.setAttribute("name", StringEscapeUtils.escapeXml11(this.wfName));
|
59
|
profTemplate.setAttribute("desc", StringEscapeUtils.escapeXml11(this.description));
|
60
|
profTemplate.setAttribute("priority", WorkflowsConstants.DEFAULT_WF_PRIORITY);
|
61
|
profTemplate.setAttribute("dsId", StringEscapeUtils.escapeXml11(dsId));
|
62
|
profTemplate.setAttribute("interface", StringEscapeUtils.escapeXml11(ifaceId));
|
63
|
|
64
|
final String profId = this.serviceLocator.getService(ISRegistryService.class).registerProfile(profTemplate.toString());
|
65
|
|
66
|
env.setAttribute("repoWfId", profId);
|
67
|
|
68
|
log.info("A new repo wf has been registered, id: " + profId);
|
69
|
|
70
|
return Arc.DEFAULT_ARC;
|
71
|
}
|
72
|
|
73
|
public WorkflowProcess getProcess() {
|
74
|
return this.process;
|
75
|
}
|
76
|
|
77
|
@Override
|
78
|
public void setProcess(final WorkflowProcess process) {
|
79
|
this.process = process;
|
80
|
}
|
81
|
|
82
|
}
|