1
|
package eu.dnetlib.msro.openaireplus.workflows.nodes.dhp;
|
2
|
import java.net.URI;
|
3
|
import java.util.HashMap;
|
4
|
import java.util.Map;
|
5
|
|
6
|
import com.google.gson.Gson;
|
7
|
import org.apache.commons.logging.Log;
|
8
|
import org.apache.commons.logging.LogFactory;
|
9
|
import org.springframework.beans.factory.annotation.Required;
|
10
|
import org.springframework.web.client.RestTemplate;
|
11
|
import org.springframework.web.util.UriComponentsBuilder;
|
12
|
|
13
|
import com.googlecode.sarasvati.Arc;
|
14
|
import com.googlecode.sarasvati.NodeToken;
|
15
|
|
16
|
import eu.dnetlib.data.mdstore.manager.common.model.MDStoreWithInfo;
|
17
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
18
|
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
|
19
|
|
20
|
public class CreateMDStoreHadoopJobNode extends SimpleJobNode {
|
21
|
|
22
|
private static final Log log = LogFactory.getLog(CreateMDStoreHadoopJobNode.class);
|
23
|
|
24
|
/* Workflow params */
|
25
|
private String format;
|
26
|
private String layout;
|
27
|
private String interpretation;
|
28
|
private String outputPrefix = "mdstore";
|
29
|
|
30
|
/* Spring managed params */
|
31
|
private String mdStoreManagerUrl;
|
32
|
|
33
|
@Override
|
34
|
protected String execute(final NodeToken token) throws Exception {
|
35
|
final String url = getMdStoreManagerUrl() + "/new/{format}/{layout}/{interpretation}";
|
36
|
|
37
|
final Map<String, Object> params = new HashMap<>();
|
38
|
params.put("format", getFormat());
|
39
|
params.put("layout", getLayout());
|
40
|
params.put("interpretation", getInterpretation());
|
41
|
|
42
|
final URI uri = UriComponentsBuilder.fromUriString(url)
|
43
|
.queryParam("dsName", token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_NAME))
|
44
|
.queryParam("dsId", token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_ORIGINALID))
|
45
|
.queryParam("apiId", token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE))
|
46
|
.buildAndExpand(params)
|
47
|
.toUri();
|
48
|
|
49
|
log.info("create mdstore request: " + uri.toString());
|
50
|
|
51
|
final RestTemplate restTemplate = new RestTemplate();
|
52
|
final MDStoreWithInfo result = restTemplate.getForObject(uri, MDStoreWithInfo.class);
|
53
|
|
54
|
log.info("created mdstore: " + new Gson().toJson(result));
|
55
|
|
56
|
token.getEnv().setAttribute(getOutputPrefix() + "format", format);
|
57
|
token.getEnv().setAttribute(getOutputPrefix() + "layout", layout);
|
58
|
token.getEnv().setAttribute(getOutputPrefix() + "interpretation", interpretation);
|
59
|
token.getEnv().setAttribute(getOutputPrefix() + "id", result.getId());
|
60
|
|
61
|
return Arc.DEFAULT_ARC;
|
62
|
}
|
63
|
|
64
|
public String getFormat() {
|
65
|
return format;
|
66
|
}
|
67
|
|
68
|
public void setFormat(final String format) {
|
69
|
this.format = format;
|
70
|
}
|
71
|
|
72
|
public String getLayout() {
|
73
|
return layout;
|
74
|
}
|
75
|
|
76
|
public void setLayout(final String layout) {
|
77
|
this.layout = layout;
|
78
|
}
|
79
|
|
80
|
public String getInterpretation() {
|
81
|
return interpretation;
|
82
|
}
|
83
|
|
84
|
public void setInterpretation(final String interpretation) {
|
85
|
this.interpretation = interpretation;
|
86
|
}
|
87
|
|
88
|
public String getOutputPrefix() {
|
89
|
return outputPrefix;
|
90
|
}
|
91
|
|
92
|
public void setOutputPrefix(final String outputPrefix) {
|
93
|
this.outputPrefix = outputPrefix;
|
94
|
}
|
95
|
|
96
|
public String getMdStoreManagerUrl() {
|
97
|
return mdStoreManagerUrl;
|
98
|
}
|
99
|
|
100
|
@Required
|
101
|
public void setMdStoreManagerUrl(final String mdStoreManagerUrl) {
|
102
|
this.mdStoreManagerUrl = mdStoreManagerUrl;
|
103
|
}
|
104
|
|
105
|
}
|