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 eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
8
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
9
|
import eu.dnetlib.msro.rmi.MSROException;
|
10
|
import org.apache.commons.lang3.StringUtils;
|
11
|
import org.apache.commons.logging.Log;
|
12
|
import org.apache.commons.logging.LogFactory;
|
13
|
import org.springframework.beans.factory.annotation.Required;
|
14
|
import org.springframework.web.client.RestTemplate;
|
15
|
import org.springframework.web.util.UriComponentsBuilder;
|
16
|
|
17
|
import com.googlecode.sarasvati.Arc;
|
18
|
import com.googlecode.sarasvati.NodeToken;
|
19
|
|
20
|
import eu.dnetlib.data.mdstore.manager.common.model.MDStoreWithInfo;
|
21
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
22
|
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
|
23
|
|
24
|
import javax.annotation.Resource;
|
25
|
|
26
|
public class CreateMDStoreHadoopJobNode extends SimpleJobNode {
|
27
|
|
28
|
private static final Log log = LogFactory.getLog(CreateMDStoreHadoopJobNode.class);
|
29
|
|
30
|
/* Workflow params */
|
31
|
private String format;
|
32
|
private String layout;
|
33
|
private String interpretation;
|
34
|
private String outputPrefix = "mdstore";
|
35
|
|
36
|
/* Spring managed params */
|
37
|
private String mdStoreManagerUrl;
|
38
|
|
39
|
@Resource
|
40
|
private UniqueServiceLocator serviceLocator;
|
41
|
|
42
|
@Override
|
43
|
protected String execute(final NodeToken token) throws Exception {
|
44
|
final String url = getMdStoreManagerUrl() + "/new/{format}/{layout}/{interpretation}";
|
45
|
|
46
|
final Map<String, Object> params = new HashMap<>();
|
47
|
params.put("format", getFormat());
|
48
|
params.put("layout", getLayout());
|
49
|
params.put("interpretation", getInterpretation());
|
50
|
|
51
|
final String repositoryId = token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_ORIGINALID);
|
52
|
final String xquery = String.format(
|
53
|
"for $x in collection('/db/DRIVER/RepositoryServiceResources/RepositoryServiceResourceType') \n" +
|
54
|
"where .//RESOURCE_IDENTIFIER[./@value='%s']\n" +
|
55
|
"return $x//EXTRA_FIELDS/FIELD[./key/text() = 'OpenAireDataSourceId']/value/text()",
|
56
|
repositoryId);
|
57
|
|
58
|
final String openAireDataSourceId = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(xquery);
|
59
|
|
60
|
if (StringUtils.isBlank(openAireDataSourceId)) {
|
61
|
throw new MSROException("unable to find openAireDataSourceId in repository profile " + repositoryId);
|
62
|
}
|
63
|
|
64
|
log.info(String.format("got OpenAIRE datasource id '%s' for repository profile '%s'", openAireDataSourceId, repositoryId));
|
65
|
|
66
|
final URI uri = UriComponentsBuilder.fromUriString(url)
|
67
|
.queryParam("dsName", token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_NAME))
|
68
|
.queryParam("dsId", openAireDataSourceId)
|
69
|
.queryParam("apiId", token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE))
|
70
|
.buildAndExpand(params)
|
71
|
.toUri();
|
72
|
|
73
|
final String requestUri = uri.toASCIIString();
|
74
|
log.info("create mdstore request: " + requestUri);
|
75
|
|
76
|
final RestTemplate restTemplate = new RestTemplate();
|
77
|
final MDStoreWithInfo result = restTemplate.getForObject(requestUri, MDStoreWithInfo.class);
|
78
|
|
79
|
log.info("created mdstore: " + new Gson().toJson(result));
|
80
|
|
81
|
token.getEnv().setAttribute(getOutputPrefix() + "format", format);
|
82
|
token.getEnv().setAttribute(getOutputPrefix() + "layout", layout);
|
83
|
token.getEnv().setAttribute(getOutputPrefix() + "interpretation", interpretation);
|
84
|
token.getEnv().setAttribute(getOutputPrefix() + "id", result.getId());
|
85
|
|
86
|
return Arc.DEFAULT_ARC;
|
87
|
}
|
88
|
|
89
|
public String getFormat() {
|
90
|
return format;
|
91
|
}
|
92
|
|
93
|
public void setFormat(final String format) {
|
94
|
this.format = format;
|
95
|
}
|
96
|
|
97
|
public String getLayout() {
|
98
|
return layout;
|
99
|
}
|
100
|
|
101
|
public void setLayout(final String layout) {
|
102
|
this.layout = layout;
|
103
|
}
|
104
|
|
105
|
public String getInterpretation() {
|
106
|
return interpretation;
|
107
|
}
|
108
|
|
109
|
public void setInterpretation(final String interpretation) {
|
110
|
this.interpretation = interpretation;
|
111
|
}
|
112
|
|
113
|
public String getOutputPrefix() {
|
114
|
return outputPrefix;
|
115
|
}
|
116
|
|
117
|
public void setOutputPrefix(final String outputPrefix) {
|
118
|
this.outputPrefix = outputPrefix;
|
119
|
}
|
120
|
|
121
|
public String getMdStoreManagerUrl() {
|
122
|
return mdStoreManagerUrl;
|
123
|
}
|
124
|
|
125
|
@Required
|
126
|
public void setMdStoreManagerUrl(final String mdStoreManagerUrl) {
|
127
|
this.mdStoreManagerUrl = mdStoreManagerUrl;
|
128
|
}
|
129
|
|
130
|
}
|