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