1 |
26600
|
sandro.lab
|
/**
|
2 |
|
|
*
|
3 |
|
|
*/
|
4 |
|
|
package eu.dnetlib.data.collective.transformation.engine.functions;
|
5 |
|
|
|
6 |
|
|
import java.io.StringReader;
|
7 |
|
|
|
8 |
|
|
import javax.xml.xpath.XPath;
|
9 |
|
|
import javax.xml.xpath.XPathConstants;
|
10 |
|
|
import javax.xml.xpath.XPathExpressionException;
|
11 |
|
|
import javax.xml.xpath.XPathFactory;
|
12 |
|
|
|
13 |
|
|
import org.w3c.dom.Node;
|
14 |
|
|
import org.xml.sax.InputSource;
|
15 |
|
|
|
16 |
|
|
import eu.dnetlib.data.collective.transformation.IDatabaseConnector;
|
17 |
|
|
import eu.dnetlib.data.collective.transformation.TransformationException;
|
18 |
|
|
|
19 |
|
|
/**
|
20 |
|
|
* @author jochen
|
21 |
|
|
*
|
22 |
|
|
*/
|
23 |
|
|
public class Dblookup extends AbstractTransformationFunction {
|
24 |
|
|
|
25 |
|
|
public static final String paramSqlExpr = "sqlExpr";
|
26 |
|
|
private IDatabaseConnector dbConnector;
|
27 |
|
|
/**
|
28 |
|
|
*
|
29 |
|
|
*/
|
30 |
|
|
public Dblookup() {
|
31 |
|
|
// TODO Auto-generated constructor stub
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
/* (non-Javadoc)
|
35 |
|
|
* @see eu.dnetlib.data.collective.transformation.engine.functions.AbstractTransformationFunction#execute()
|
36 |
|
|
*/
|
37 |
|
|
@Override
|
38 |
|
|
String execute() throws ProcessingException {
|
39 |
|
|
// TODO Auto-generated method stub
|
40 |
|
|
return null;
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
/**
|
44 |
|
|
* @return the dbConnector
|
45 |
|
|
*/
|
46 |
|
|
public IDatabaseConnector getDbConnector() {
|
47 |
|
|
return dbConnector;
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
/**
|
51 |
|
|
* @param dbConnector the dbConnector to set
|
52 |
|
|
*/
|
53 |
|
|
public void setDbConnector(IDatabaseConnector dbConnector) {
|
54 |
|
|
this.dbConnector = dbConnector;
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
public LookupRecord getResults(String aSqlExpression) throws TransformationException, XPathExpressionException {
|
58 |
|
|
LookupRecord lookupRecord = new LookupRecord();
|
59 |
|
|
XPath xpath = XPathFactory.newInstance().newXPath();
|
60 |
|
|
|
61 |
|
|
for (String record: dbConnector.getResult(aSqlExpression)){
|
62 |
|
|
InputSource inSource = new InputSource(new StringReader(record));
|
63 |
|
|
Node root = (Node)xpath.evaluate("/", inSource, XPathConstants.NODE);
|
64 |
|
|
lookupRecord.setRecord(xpath.evaluate("//FIELD[@name='accessinfopackage']/text()", root),
|
65 |
|
|
"officialname", xpath.evaluate("//FIELD[@name='officialname']/text()", root));
|
66 |
|
|
lookupRecord.setRecord(xpath.evaluate("//FIELD[@name='accessinfopackage']/text()", root),
|
67 |
|
|
"id", xpath.evaluate("//FIELD[@name='id']/text()", root));
|
68 |
|
|
}
|
69 |
|
|
return lookupRecord;
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
}
|