1
|
package eu.dnetlib.msro.openaireplus.workflows.nodes;
|
2
|
|
3
|
import javax.annotation.Resource;
|
4
|
import javax.xml.ws.wsaddressing.W3CEndpointReference;
|
5
|
|
6
|
import org.antlr.stringtemplate.StringTemplate;
|
7
|
import org.apache.commons.logging.Log;
|
8
|
import org.apache.commons.logging.LogFactory;
|
9
|
import org.springframework.beans.factory.annotation.Required;
|
10
|
|
11
|
import com.googlecode.sarasvati.Arc;
|
12
|
import com.googlecode.sarasvati.NodeToken;
|
13
|
|
14
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
15
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
16
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
17
|
import eu.dnetlib.enabling.resultset.XSLTMappedResultSetFactory;
|
18
|
import eu.dnetlib.enabling.resultset.client.utils.EPRUtils;
|
19
|
import eu.dnetlib.msro.rmi.MSROException;
|
20
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
21
|
|
22
|
public class OpenaireMdBuilderJobNode extends SimpleJobNode {
|
23
|
|
24
|
private static final Log log = LogFactory.getLog(OpenaireMdBuilderJobNode.class);
|
25
|
|
26
|
private StringTemplate mdBuilderTemplateXslt;
|
27
|
|
28
|
private String inputEprParam;
|
29
|
private String outputEprParam;
|
30
|
private String datasourceId;
|
31
|
private String datasourceInterface;
|
32
|
|
33
|
private boolean inferred = false;
|
34
|
private boolean deletedbyinference = false;
|
35
|
private String inferenceprovenance = "";
|
36
|
private String trust = "";
|
37
|
private String provenanceactionclassname = "";
|
38
|
private String provenanceactionclassid = "";
|
39
|
|
40
|
private String overridingMetadataIdentifierXPath = "";
|
41
|
|
42
|
private XSLTMappedResultSetFactory xsltMappedResultSetFactory;
|
43
|
|
44
|
@Resource
|
45
|
private UniqueServiceLocator serviceLocator;
|
46
|
|
47
|
@Override
|
48
|
protected String execute(final NodeToken token) throws MSROException {
|
49
|
final String inputEpr = token.getEnv().getAttribute(inputEprParam);
|
50
|
|
51
|
if ((inputEpr == null) || inputEpr.isEmpty()) throw new MSROException("InputEprParam (" + inputEprParam + ") not found in ENV");
|
52
|
|
53
|
try {
|
54
|
final StringTemplate st = new StringTemplate(getMdBuilderTemplateXslt().getTemplate());
|
55
|
|
56
|
st.setAttribute("xpath", getMetadataIdentifierXPath());
|
57
|
st.setAttribute("datasourceId", datasourceId);
|
58
|
if (token.getEnv().hasAttribute("namespacePrefix")) {
|
59
|
st.setAttribute("namespacePrefix", token.getEnv().getAttribute("namespacePrefix"));
|
60
|
} else {
|
61
|
st.setAttribute("namespacePrefix", datasourceId);
|
62
|
}
|
63
|
|
64
|
st.setAttribute("inferred", String.valueOf(getInferred()));
|
65
|
st.setAttribute("deletedbyinference", String.valueOf(getDeletedbyinference()));
|
66
|
st.setAttribute("inferenceprovenance", getInferenceprovenance());
|
67
|
st.setAttribute("trust", getTrust());
|
68
|
st.setAttribute("provenanceactionclassname", getProvenanceactionclassname());
|
69
|
st.setAttribute("provenanceactionclassid", getProvenanceactionclassid());
|
70
|
st.setAttribute("baseurl", getBaseUrl());
|
71
|
st.setAttribute("metadatanamespace", getMetadataNamespace());
|
72
|
|
73
|
final W3CEndpointReference epr = xsltMappedResultSetFactory.createMappedResultSet(new EPRUtils().getEpr(inputEpr), st.toString());
|
74
|
|
75
|
token.getEnv().setAttribute(outputEprParam, epr.toString());
|
76
|
|
77
|
return Arc.DEFAULT_ARC;
|
78
|
} catch (ISLookUpException e) {
|
79
|
throw new MSROException("Error while initializing mdBuilder template for datasource " + datasourceId, e);
|
80
|
}
|
81
|
}
|
82
|
|
83
|
private String getMetadataIdentifierXPath() throws ISLookUpException {
|
84
|
String xQuery =
|
85
|
String.format("for $x in collection('/db/DRIVER/RepositoryServiceResources/RepositoryServiceResourceType') "
|
86
|
+ "return $x//INTERFACE[@id='%s']/INTERFACE_EXTRA_FIELD[@name='metadata_identifier_path']/string()", getDatasourceInterface());
|
87
|
|
88
|
return hasOverridingMetadataIdentifierXPath() ? getOverridingMetadataIdentifierXPath() : serviceLocator.getService(ISLookUpService.class)
|
89
|
.getResourceProfileByQuery(xQuery);
|
90
|
}
|
91
|
|
92
|
private String getBaseUrl() throws ISLookUpException {
|
93
|
String xQuery = "/*[.//RESOURCE_IDENTIFIER/@value='{datasourceId}']//INTERFACE[@id='{interfaceId}']//BASE_URL/string()";
|
94
|
xQuery = xQuery.replace("{interfaceId}", datasourceInterface).replace("{datasourceId}", datasourceId);
|
95
|
return serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(xQuery);
|
96
|
}
|
97
|
|
98
|
private String getMetadataNamespace() {
|
99
|
try {
|
100
|
String xQuery =
|
101
|
"let $x := /*[.//RESOURCE_IDENTIFIER/@value='{datasourceId}']//INTERFACE[@id='{interfaceId}']/ACCESS_PROTOCOL/@format/string() "
|
102
|
+ "return /*[.//RESOURCE_TYPE/@value='MetadataFormatDSResourceType']//METADATAFORMAT[@Prefix=$x]/@NameSpace/string()";
|
103
|
xQuery = xQuery.replace("{interfaceId}", datasourceInterface).replace("{datasourceId}", datasourceId);
|
104
|
return serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(xQuery);
|
105
|
} catch (ISLookUpException e) {
|
106
|
log.error("The interface is not OAI or the format is not found in the MetadataFormatDSResourceType, thus metadata format in the <about> section "
|
107
|
+ "cannot managed here and it will be leaved empty (for the time being)");
|
108
|
return "";
|
109
|
}
|
110
|
}
|
111
|
|
112
|
private boolean hasOverridingMetadataIdentifierXPath() {
|
113
|
return !getOverridingMetadataIdentifierXPath().isEmpty();
|
114
|
}
|
115
|
|
116
|
public String getInputEprParam() {
|
117
|
return inputEprParam;
|
118
|
}
|
119
|
|
120
|
public void setInputEprParam(final String inputEprParam) {
|
121
|
this.inputEprParam = inputEprParam;
|
122
|
}
|
123
|
|
124
|
public String getOutputEprParam() {
|
125
|
return outputEprParam;
|
126
|
}
|
127
|
|
128
|
public void setOutputEprParam(final String outputEprParam) {
|
129
|
this.outputEprParam = outputEprParam;
|
130
|
}
|
131
|
|
132
|
public XSLTMappedResultSetFactory getXsltMappedResultSetFactory() {
|
133
|
return xsltMappedResultSetFactory;
|
134
|
}
|
135
|
|
136
|
public String getDatasourceId() {
|
137
|
return datasourceId;
|
138
|
}
|
139
|
|
140
|
public void setDatasourceId(final String datasourceId) {
|
141
|
this.datasourceId = datasourceId;
|
142
|
}
|
143
|
|
144
|
public String getDatasourceInterface() {
|
145
|
return datasourceInterface;
|
146
|
}
|
147
|
|
148
|
public void setDatasourceInterface(final String datasourceInterface) {
|
149
|
this.datasourceInterface = datasourceInterface;
|
150
|
}
|
151
|
|
152
|
@Required
|
153
|
public void setXsltMappedResultSetFactory(final XSLTMappedResultSetFactory xsltMappedResultSetFactory) {
|
154
|
this.xsltMappedResultSetFactory = xsltMappedResultSetFactory;
|
155
|
}
|
156
|
|
157
|
public StringTemplate getMdBuilderTemplateXslt() {
|
158
|
return mdBuilderTemplateXslt;
|
159
|
}
|
160
|
|
161
|
public void setMdBuilderTemplateXslt(final StringTemplate mdBuilderTemplateXslt) {
|
162
|
this.mdBuilderTemplateXslt = mdBuilderTemplateXslt;
|
163
|
}
|
164
|
|
165
|
public boolean getInferred() {
|
166
|
return inferred;
|
167
|
}
|
168
|
|
169
|
public void setInferred(final boolean inferred) {
|
170
|
this.inferred = inferred;
|
171
|
}
|
172
|
|
173
|
public boolean getDeletedbyinference() {
|
174
|
return deletedbyinference;
|
175
|
}
|
176
|
|
177
|
public void setDeletedbyinference(final boolean deletedbyinference) {
|
178
|
this.deletedbyinference = deletedbyinference;
|
179
|
}
|
180
|
|
181
|
public String getInferenceprovenance() {
|
182
|
return inferenceprovenance;
|
183
|
}
|
184
|
|
185
|
public void setInferenceprovenance(final String inferenceprovenance) {
|
186
|
this.inferenceprovenance = inferenceprovenance;
|
187
|
}
|
188
|
|
189
|
public String getTrust() {
|
190
|
return trust;
|
191
|
}
|
192
|
|
193
|
public void setTrust(final String trust) {
|
194
|
this.trust = trust;
|
195
|
}
|
196
|
|
197
|
public String getProvenanceactionclassname() {
|
198
|
return provenanceactionclassname;
|
199
|
}
|
200
|
|
201
|
public void setProvenanceactionclassname(final String provenanceactionclassname) {
|
202
|
this.provenanceactionclassname = provenanceactionclassname;
|
203
|
}
|
204
|
|
205
|
public String getProvenanceactionclassid() {
|
206
|
return provenanceactionclassid;
|
207
|
}
|
208
|
|
209
|
public void setProvenanceactionclassid(final String provenanceactionclassid) {
|
210
|
this.provenanceactionclassid = provenanceactionclassid;
|
211
|
}
|
212
|
|
213
|
public String getOverridingMetadataIdentifierXPath() {
|
214
|
return overridingMetadataIdentifierXPath;
|
215
|
}
|
216
|
|
217
|
public void setOverridingMetadataIdentifierXPath(final String overridingMetadataIdentifierXPath) {
|
218
|
this.overridingMetadataIdentifierXPath = overridingMetadataIdentifierXPath;
|
219
|
}
|
220
|
|
221
|
}
|