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
|
public static final String MDSTORE_CREATE_URL_AND_PARAMS = "/new/{format}/{layout}/{interpretation}?dsName={dsName}&dsId={dsid}&apiId={apiId}";
|
30
|
|
31
|
/* Workflow params */
|
32
|
private String format;
|
33
|
private String layout;
|
34
|
private String interpretation;
|
35
|
private String outputPrefix = "mdstore";
|
36
|
|
37
|
/* Spring managed params */
|
38
|
private String mdStoreManagerUrl;
|
39
|
|
40
|
@Resource
|
41
|
private UniqueServiceLocator serviceLocator;
|
42
|
|
43
|
@Override
|
44
|
protected String execute(final NodeToken token) throws Exception {
|
45
|
|
46
|
final String repositoryId = token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_ID);
|
47
|
final String xquery = String.format(
|
48
|
"for $x in collection('/db/DRIVER/RepositoryServiceResources/RepositoryServiceResourceType') \n" +
|
49
|
"where .//RESOURCE_IDENTIFIER[./@value='%s']\n" +
|
50
|
"return $x//EXTRA_FIELDS/FIELD[./key/text() = 'OpenAireDataSourceId']/value/text()",
|
51
|
repositoryId);
|
52
|
|
53
|
log.info("resolving openaAireDatasourceId: " + xquery);
|
54
|
|
55
|
final String openAireDataSourceId = serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(xquery);
|
56
|
|
57
|
if (StringUtils.isBlank(openAireDataSourceId)) {
|
58
|
throw new MSROException("unable to find openAireDataSourceId in repository profile " + repositoryId);
|
59
|
}
|
60
|
|
61
|
log.info(String.format("got OpenAIRE datasource id '%s' for repository profile '%s'", openAireDataSourceId, repositoryId));
|
62
|
|
63
|
final String urlTemplate = getMdStoreManagerUrl() + MDSTORE_CREATE_URL_AND_PARAMS;
|
64
|
|
65
|
final RestTemplate restTemplate = new RestTemplate();
|
66
|
final MDStoreWithInfo result = restTemplate.getForObject(
|
67
|
urlTemplate,
|
68
|
MDStoreWithInfo.class,
|
69
|
getFormat(),
|
70
|
getLayout(),
|
71
|
getInterpretation(),
|
72
|
token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_NAME),
|
73
|
openAireDataSourceId,
|
74
|
token.getFullEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE));
|
75
|
|
76
|
log.info("created mdstore: " + new Gson().toJson(result));
|
77
|
|
78
|
token.getEnv().setAttribute(getOutputPrefix() + "format", format);
|
79
|
token.getEnv().setAttribute(getOutputPrefix() + "layout", layout);
|
80
|
token.getEnv().setAttribute(getOutputPrefix() + "interpretation", interpretation);
|
81
|
token.getEnv().setAttribute(getOutputPrefix() + "id", result.getId());
|
82
|
|
83
|
return Arc.DEFAULT_ARC;
|
84
|
}
|
85
|
|
86
|
public String getFormat() {
|
87
|
return format;
|
88
|
}
|
89
|
|
90
|
public void setFormat(final String format) {
|
91
|
this.format = format;
|
92
|
}
|
93
|
|
94
|
public String getLayout() {
|
95
|
return layout;
|
96
|
}
|
97
|
|
98
|
public void setLayout(final String layout) {
|
99
|
this.layout = layout;
|
100
|
}
|
101
|
|
102
|
public String getInterpretation() {
|
103
|
return interpretation;
|
104
|
}
|
105
|
|
106
|
public void setInterpretation(final String interpretation) {
|
107
|
this.interpretation = interpretation;
|
108
|
}
|
109
|
|
110
|
public String getOutputPrefix() {
|
111
|
return outputPrefix;
|
112
|
}
|
113
|
|
114
|
public void setOutputPrefix(final String outputPrefix) {
|
115
|
this.outputPrefix = outputPrefix;
|
116
|
}
|
117
|
|
118
|
public String getMdStoreManagerUrl() {
|
119
|
return mdStoreManagerUrl;
|
120
|
}
|
121
|
|
122
|
@Required
|
123
|
public void setMdStoreManagerUrl(final String mdStoreManagerUrl) {
|
124
|
this.mdStoreManagerUrl = mdStoreManagerUrl;
|
125
|
}
|
126
|
|
127
|
}
|