1 |
41200
|
katerina.i
|
package eu.dnetlib.data.claims.migration.handler;
|
2 |
|
|
|
3 |
41791
|
argiro.kok
|
import eu.dnetlib.data.claims.migration.entity.Context;
|
4 |
41200
|
katerina.i
|
import eu.dnetlib.data.claims.migration.parser.DMFParser;
|
5 |
41791
|
argiro.kok
|
import eu.dnetlib.data.claimsDemo.ContextUtils;
|
6 |
41200
|
katerina.i
|
import eu.dnetlib.data.claimsDemo.QueryGenerator;
|
7 |
47219
|
argiro.kok
|
import eu.dnetlib.data.claimsDemo.SQLStoreException;
|
8 |
41200
|
katerina.i
|
import eu.dnetlib.data.claimsDemo.SqlDAO;
|
9 |
47214
|
argiro.kok
|
import org.apache.log4j.Logger;
|
10 |
41791
|
argiro.kok
|
import org.xml.sax.SAXException;
|
11 |
41200
|
katerina.i
|
|
12 |
41791
|
argiro.kok
|
import javax.xml.parsers.ParserConfigurationException;
|
13 |
|
|
import javax.xml.xpath.XPathExpressionException;
|
14 |
|
|
import java.io.IOException;
|
15 |
41200
|
katerina.i
|
import java.sql.ResultSet;
|
16 |
|
|
|
17 |
|
|
/**
|
18 |
|
|
* Created by kiatrop on 5/2/2016.
|
19 |
|
|
*/
|
20 |
|
|
public class DMFContextHandler {
|
21 |
47214
|
argiro.kok
|
private static Logger log = Logger.getLogger(DMFContextHandler.class );
|
22 |
41200
|
katerina.i
|
|
23 |
|
|
SqlDAO sqlDAO = null;
|
24 |
|
|
QueryGenerator queryGenerator = null;
|
25 |
|
|
DMFParser dmfParser = null;
|
26 |
|
|
|
27 |
53031
|
argiro.kok
|
|
28 |
47219
|
argiro.kok
|
private String fetchAllDMFContext(String id) throws Exception, SQLStoreException {
|
29 |
41350
|
argiro.kok
|
ResultSet rs = sqlDAO.executePreparedQuery(queryGenerator.generateSelectConceptDMFClaimsQuery(-1));
|
30 |
|
|
return rs.getString("xml");
|
31 |
|
|
}
|
32 |
47215
|
katerina.i
|
|
33 |
47219
|
argiro.kok
|
private String fetchDMFContext(String id) throws Exception, SQLStoreException {
|
34 |
41200
|
katerina.i
|
ResultSet rs = sqlDAO.executePreparedQuery(queryGenerator.generateSelectConceptClaimByIdQuery(id));
|
35 |
|
|
return rs.getString("xml");
|
36 |
|
|
}
|
37 |
|
|
|
38 |
53031
|
argiro.kok
|
public Context extractContextFromDMF(String xml, Boolean production) throws ParserConfigurationException, SAXException, XPathExpressionException, IOException {
|
39 |
|
|
return fetchContextById(dmfParser.getContextIdFromDMF(xml),production );
|
40 |
41200
|
katerina.i
|
}
|
41 |
|
|
|
42 |
53031
|
argiro.kok
|
public Context fetchContextByIdFromDmf(String id, Boolean production) throws Exception, SQLStoreException {
|
43 |
|
|
return extractContextFromDMF(fetchDMFContext(id), production);
|
44 |
41200
|
katerina.i
|
}
|
45 |
41350
|
argiro.kok
|
|
46 |
53031
|
argiro.kok
|
public static Context fetchContextById(String openaireId, Boolean production) {
|
47 |
41791
|
argiro.kok
|
Context context = new Context();
|
48 |
|
|
if(openaireId == null ){
|
49 |
|
|
return null;
|
50 |
|
|
}
|
51 |
|
|
context.setOpenaireId(openaireId);
|
52 |
|
|
try {
|
53 |
53031
|
argiro.kok
|
context.setTitle(ContextUtils.extractLabel(context.getOpenaireId(),production));
|
54 |
41350
|
argiro.kok
|
|
55 |
41791
|
argiro.kok
|
} catch (Exception e) {
|
56 |
47219
|
argiro.kok
|
log.error("ContextUtils: Couldn't get Egi label for id " + context.getOpenaireId(),e);
|
57 |
41791
|
argiro.kok
|
}
|
58 |
|
|
return context;
|
59 |
|
|
|
60 |
|
|
}
|
61 |
|
|
/* public String generateSaveQueryForContext(Context context){
|
62 |
|
|
|
63 |
41350
|
argiro.kok
|
return queryGenerator.generateInsertContextQuery(context.getOpenaireId(),context.getTitle());
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
public void saveContext(Context context) throws Exception {
|
67 |
|
|
|
68 |
|
|
sqlDAO.executePreparedQuery(generateSaveQueryForContext(context));
|
69 |
41791
|
argiro.kok
|
}*/
|
70 |
41350
|
argiro.kok
|
|
71 |
|
|
public SqlDAO getSqlDAO() {
|
72 |
|
|
return sqlDAO;
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
public void setSqlDAO(SqlDAO sqlDAO) {
|
76 |
|
|
this.sqlDAO = sqlDAO;
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
public QueryGenerator getQueryGenerator() {
|
80 |
|
|
return queryGenerator;
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
public void setQueryGenerator(QueryGenerator queryGenerator) {
|
84 |
|
|
this.queryGenerator = queryGenerator;
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
public DMFParser getDmfParser() {
|
88 |
|
|
return dmfParser;
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
public void setDmfParser(DMFParser dmfParser) {
|
92 |
|
|
this.dmfParser = dmfParser;
|
93 |
|
|
}
|
94 |
41200
|
katerina.i
|
}
|