1 |
30840
|
claudio.at
|
package eu.dnetlib.msro.openaireplus.workflows.nodes;
|
2 |
|
|
|
3 |
32798
|
michele.ar
|
import javax.annotation.Resource;
|
4 |
30840
|
claudio.at
|
import javax.xml.ws.wsaddressing.W3CEndpointReference;
|
5 |
|
|
|
6 |
|
|
import com.googlecode.sarasvati.Arc;
|
7 |
|
|
import com.googlecode.sarasvati.NodeToken;
|
8 |
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
9 |
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
10 |
32798
|
michele.ar
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
11 |
30840
|
claudio.at
|
import eu.dnetlib.enabling.resultset.XSLTMappedResultSetFactory;
|
12 |
|
|
import eu.dnetlib.enabling.resultset.client.utils.EPRUtils;
|
13 |
|
|
import eu.dnetlib.msro.rmi.MSROException;
|
14 |
|
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
15 |
48139
|
alessia.ba
|
import org.antlr.stringtemplate.StringTemplate;
|
16 |
|
|
import org.apache.commons.logging.Log;
|
17 |
|
|
import org.apache.commons.logging.LogFactory;
|
18 |
|
|
import org.springframework.beans.factory.annotation.Required;
|
19 |
30840
|
claudio.at
|
|
20 |
56861
|
alessia.ba
|
import java.io.UnsupportedEncodingException;
|
21 |
|
|
import java.net.URLEncoder;
|
22 |
|
|
|
23 |
30840
|
claudio.at
|
public class OpenaireMdBuilderJobNode extends SimpleJobNode {
|
24 |
|
|
|
25 |
34843
|
andrea.man
|
private static final Log log = LogFactory.getLog(OpenaireMdBuilderJobNode.class);
|
26 |
|
|
|
27 |
30840
|
claudio.at
|
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 |
32798
|
michele.ar
|
@Resource
|
46 |
|
|
private UniqueServiceLocator serviceLocator;
|
47 |
30840
|
claudio.at
|
|
48 |
|
|
@Override
|
49 |
|
|
protected String execute(final NodeToken token) throws MSROException {
|
50 |
|
|
final String inputEpr = token.getEnv().getAttribute(inputEprParam);
|
51 |
|
|
|
52 |
34843
|
andrea.man
|
if ((inputEpr == null) || inputEpr.isEmpty()) throw new MSROException("InputEprParam (" + inputEprParam + ") not found in ENV");
|
53 |
56861
|
alessia.ba
|
final StringTemplate st = new StringTemplate(getMdBuilderTemplateXslt().getTemplate());
|
54 |
30840
|
claudio.at
|
try {
|
55 |
|
|
st.setAttribute("xpath", getMetadataIdentifierXPath());
|
56 |
|
|
st.setAttribute("datasourceId", datasourceId);
|
57 |
|
|
if (token.getEnv().hasAttribute("namespacePrefix")) {
|
58 |
|
|
st.setAttribute("namespacePrefix", token.getEnv().getAttribute("namespacePrefix"));
|
59 |
|
|
} else {
|
60 |
|
|
st.setAttribute("namespacePrefix", datasourceId);
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
st.setAttribute("inferred", String.valueOf(getInferred()));
|
64 |
|
|
st.setAttribute("deletedbyinference", String.valueOf(getDeletedbyinference()));
|
65 |
|
|
st.setAttribute("inferenceprovenance", getInferenceprovenance());
|
66 |
|
|
st.setAttribute("trust", getTrust());
|
67 |
|
|
st.setAttribute("provenanceactionclassname", getProvenanceactionclassname());
|
68 |
|
|
st.setAttribute("provenanceactionclassid", getProvenanceactionclassid());
|
69 |
56861
|
alessia.ba
|
st.setAttribute("baseurl", URLEncoder.encode(getBaseUrl(), "UTF-8"));
|
70 |
34843
|
andrea.man
|
st.setAttribute("metadatanamespace", getMetadataNamespace());
|
71 |
30840
|
claudio.at
|
|
72 |
32798
|
michele.ar
|
final W3CEndpointReference epr = xsltMappedResultSetFactory.createMappedResultSet(new EPRUtils().getEpr(inputEpr), st.toString());
|
73 |
30840
|
claudio.at
|
|
74 |
|
|
token.getEnv().setAttribute(outputEprParam, epr.toString());
|
75 |
|
|
|
76 |
|
|
return Arc.DEFAULT_ARC;
|
77 |
|
|
} catch (ISLookUpException e) {
|
78 |
34854
|
andrea.man
|
throw new MSROException("Error while initializing mdBuilder template for datasource " + datasourceId, e);
|
79 |
56861
|
alessia.ba
|
} catch (UnsupportedEncodingException e) {
|
80 |
|
|
log.error("Cannot encode baseUrl in UTF-8");
|
81 |
|
|
throw new MSROException(e);
|
82 |
30840
|
claudio.at
|
}
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
private String getMetadataIdentifierXPath() throws ISLookUpException {
|
86 |
|
|
String xQuery =
|
87 |
|
|
String.format("for $x in collection('/db/DRIVER/RepositoryServiceResources/RepositoryServiceResourceType') "
|
88 |
|
|
+ "return $x//INTERFACE[@id='%s']/INTERFACE_EXTRA_FIELD[@name='metadata_identifier_path']/string()", getDatasourceInterface());
|
89 |
|
|
|
90 |
32798
|
michele.ar
|
return hasOverridingMetadataIdentifierXPath() ? getOverridingMetadataIdentifierXPath() : serviceLocator.getService(ISLookUpService.class)
|
91 |
|
|
.getResourceProfileByQuery(xQuery);
|
92 |
30840
|
claudio.at
|
}
|
93 |
|
|
|
94 |
34843
|
andrea.man
|
private String getBaseUrl() throws ISLookUpException {
|
95 |
|
|
String xQuery = "/*[.//RESOURCE_IDENTIFIER/@value='{datasourceId}']//INTERFACE[@id='{interfaceId}']//BASE_URL/string()";
|
96 |
|
|
xQuery = xQuery.replace("{interfaceId}", datasourceInterface).replace("{datasourceId}", datasourceId);
|
97 |
|
|
return serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(xQuery);
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
private String getMetadataNamespace() {
|
101 |
|
|
try {
|
102 |
|
|
String xQuery =
|
103 |
|
|
"let $x := /*[.//RESOURCE_IDENTIFIER/@value='{datasourceId}']//INTERFACE[@id='{interfaceId}']/ACCESS_PROTOCOL/@format/string() "
|
104 |
|
|
+ "return /*[.//RESOURCE_TYPE/@value='MetadataFormatDSResourceType']//METADATAFORMAT[@Prefix=$x]/@NameSpace/string()";
|
105 |
|
|
xQuery = xQuery.replace("{interfaceId}", datasourceInterface).replace("{datasourceId}", datasourceId);
|
106 |
|
|
return serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(xQuery);
|
107 |
|
|
} catch (ISLookUpException e) {
|
108 |
34864
|
andrea.man
|
log.error("The interface is not OAI or the format is not found in the MetadataFormatDSResourceType, thus metadata format in the <about> section "
|
109 |
|
|
+ "cannot managed here and it will be leaved empty (for the time being)");
|
110 |
34843
|
andrea.man
|
return "";
|
111 |
|
|
}
|
112 |
|
|
}
|
113 |
|
|
|
114 |
30840
|
claudio.at
|
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 |
|
|
}
|