1 |
41128
|
alessia.ba
|
package eu.dnetlib.msro.openaireplus.workflows.nodes.hostedby;
|
2 |
|
|
|
3 |
|
|
import com.googlecode.sarasvati.Arc;
|
4 |
|
|
import com.googlecode.sarasvati.NodeToken;
|
5 |
|
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
6 |
|
|
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
|
7 |
|
|
import org.antlr.stringtemplate.StringTemplate;
|
8 |
|
|
import org.apache.commons.io.IOUtils;
|
9 |
|
|
import org.apache.commons.logging.Log;
|
10 |
|
|
import org.apache.commons.logging.LogFactory;
|
11 |
|
|
import org.springframework.core.io.ClassPathResource;
|
12 |
|
|
import org.springframework.core.io.Resource;
|
13 |
|
|
|
14 |
|
|
/**
|
15 |
|
|
* Created by alessia on 01/02/16.
|
16 |
|
|
*/
|
17 |
|
|
public class PrepareHostedbyUpdateSQL extends SimpleJobNode {
|
18 |
|
|
|
19 |
|
|
private static final Log log = LogFactory.getLog(PrepareHostedbyUpdateSQL.class);
|
20 |
|
|
private String updateSqlTemplatePath;
|
21 |
|
|
private String theQueryParamName = "hostedByUpdateSQL";
|
22 |
|
|
|
23 |
|
|
@Override
|
24 |
|
|
protected String execute(final NodeToken token) throws Exception {
|
25 |
|
|
final String datasourceId = token.getEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_ORIGINALID);
|
26 |
|
|
final String datasourceNamespacePrefix = token.getEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_NAMESPACE_PREFIX);
|
27 |
|
|
final Resource updateSqlTemplate = new ClassPathResource(updateSqlTemplatePath);
|
28 |
|
|
final StringTemplate st = new StringTemplate(IOUtils.toString(updateSqlTemplate.getInputStream()));
|
29 |
|
|
st.setAttribute("datasourceId", datasourceId);
|
30 |
|
|
st.setAttribute("datasourceNamespacePrefix", datasourceNamespacePrefix);
|
31 |
|
|
final String theQuery = st.toString();
|
32 |
|
|
log.debug("Generated query: " + theQuery);
|
33 |
|
|
token.getFullEnv().setAttribute(theQueryParamName, theQuery);
|
34 |
|
|
return Arc.DEFAULT_ARC;
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
public String getUpdateSqlTemplatePath() {
|
38 |
|
|
return updateSqlTemplatePath;
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
public void setUpdateSqlTemplatePath(final String updateSqlTemplatePath) {
|
42 |
|
|
this.updateSqlTemplatePath = updateSqlTemplatePath;
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
public String getTheQueryParamName() {
|
46 |
|
|
return theQueryParamName;
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
public void setTheQueryParamName(final String theQueryParamName) {
|
50 |
|
|
this.theQueryParamName = theQueryParamName;
|
51 |
|
|
}
|
52 |
|
|
}
|