1
|
package eu.dnetlib.parthenos.workflows.nodes;
|
2
|
|
3
|
import java.nio.charset.Charset;
|
4
|
|
5
|
import com.google.common.base.Joiner;
|
6
|
import eu.dnetlib.clients.enabling.ISLookUpClient;
|
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.msro.workflows.procs.ProcessAware;
|
12
|
import eu.dnetlib.msro.workflows.procs.WorkflowProcess;
|
13
|
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
|
14
|
import eu.dnetlib.rmi.enabling.ISLookUpException;
|
15
|
import eu.dnetlib.rmi.enabling.ISRegistryService;
|
16
|
import org.antlr.stringtemplate.StringTemplate;
|
17
|
import org.apache.commons.io.IOUtils;
|
18
|
import org.apache.commons.lang3.StringEscapeUtils;
|
19
|
import org.apache.commons.lang3.StringUtils;
|
20
|
import org.apache.commons.logging.Log;
|
21
|
import org.apache.commons.logging.LogFactory;
|
22
|
import org.springframework.beans.factory.annotation.Autowired;
|
23
|
|
24
|
/**
|
25
|
* Copied from eu.dnetlib.msro.workflows.nodes.repohi.RegisterWorkflowFromTemplateJobNode
|
26
|
*
|
27
|
* Clarin specific implementation for setting the transformation rules automatically.
|
28
|
*
|
29
|
* @author alessia
|
30
|
*/
|
31
|
public class RegisterClarinWorkflowFromTemplateJobNode extends SimpleJobNode implements ProcessAware {
|
32
|
|
33
|
private static final Log log = LogFactory.getLog(RegisterClarinWorkflowFromTemplateJobNode.class);
|
34
|
private String wfName;
|
35
|
private String wfTemplate;
|
36
|
private String description;
|
37
|
private WorkflowProcess process;
|
38
|
@Autowired
|
39
|
private UniqueServiceLocator serviceLocator;
|
40
|
@Autowired
|
41
|
private ISLookUpClient isLookUpClient;
|
42
|
|
43
|
public String getWfName() {
|
44
|
return this.wfName;
|
45
|
}
|
46
|
|
47
|
public void setWfName(final String wfName) {
|
48
|
this.wfName = wfName;
|
49
|
}
|
50
|
|
51
|
public String getWfTemplate() {
|
52
|
return this.wfTemplate;
|
53
|
}
|
54
|
|
55
|
public void setWfTemplate(final String wfTemplate) {
|
56
|
this.wfTemplate = wfTemplate;
|
57
|
}
|
58
|
|
59
|
public String getDescription() {
|
60
|
return this.description;
|
61
|
}
|
62
|
|
63
|
public void setDescription(final String description) {
|
64
|
this.description = description;
|
65
|
}
|
66
|
|
67
|
@Override
|
68
|
protected String execute(final Env env) throws Exception {
|
69
|
final String dsId = this.process.getDsId();
|
70
|
final String ifaceId = this.process.getDsInterface();
|
71
|
final String dsName = this.process.getDsName();
|
72
|
|
73
|
final StringTemplate profTemplate = new StringTemplate(IOUtils.toString(getClass().getResourceAsStream(getWfTemplate()), Charset.forName("UTF-8")));
|
74
|
profTemplate.setAttribute("name", StringEscapeUtils.escapeXml11(this.wfName));
|
75
|
profTemplate.setAttribute("desc", StringEscapeUtils.escapeXml11(this.description));
|
76
|
profTemplate.setAttribute("priority", WorkflowsConstants.DEFAULT_WF_PRIORITY);
|
77
|
profTemplate.setAttribute("dsId", StringEscapeUtils.escapeXml11(dsId));
|
78
|
profTemplate.setAttribute("interface", StringEscapeUtils.escapeXml11(ifaceId));
|
79
|
profTemplate.setAttribute("dsName", StringEscapeUtils.escapeXml11(dsName));
|
80
|
profTemplate.setAttribute("tdsCsv", getListOfTDS(ifaceId));
|
81
|
|
82
|
final String profId = this.serviceLocator.getService(ISRegistryService.class).registerProfile(profTemplate.toString());
|
83
|
|
84
|
env.setAttribute("repoWfId", profId);
|
85
|
|
86
|
log.info("A new repo wf has been registered, id: " + profId);
|
87
|
|
88
|
return Arc.DEFAULT_ARC;
|
89
|
}
|
90
|
|
91
|
private String getListOfTDS(final String ifaceId) throws ISLookUpException {
|
92
|
String lastAPIPart = StringUtils.substringAfterLast(ifaceId, "::");
|
93
|
String query = "for $x in collection('/db/DRIVER/TransformationRuleDSResources/TransformationRuleDSResourceType') return $x[starts-with(.//TITLE/text() , '"+lastAPIPart+"')]//RESOURCE_IDENTIFIER/@value/string()";
|
94
|
return Joiner.on(',').join(isLookUpClient.search(query));
|
95
|
}
|
96
|
|
97
|
public WorkflowProcess getProcess() {
|
98
|
return this.process;
|
99
|
}
|
100
|
|
101
|
@Override
|
102
|
public void setProcess(final WorkflowProcess process) {
|
103
|
this.process = process;
|
104
|
}
|
105
|
|
106
|
|
107
|
|
108
|
}
|