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