|
1 |
/**
|
|
2 |
*
|
|
3 |
*/
|
|
4 |
package eu.etaxonomy.cdm.io.berlinModel;
|
|
5 |
|
|
6 |
import java.sql.ResultSet;
|
|
7 |
import java.sql.SQLException;
|
|
8 |
|
|
9 |
import org.apache.log4j.Logger;
|
|
10 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.*;
|
|
11 |
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
|
12 |
import eu.etaxonomy.cdm.io.source.Source;
|
|
13 |
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
|
14 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
|
15 |
|
|
16 |
|
|
17 |
/**
|
|
18 |
* @author a.mueller
|
|
19 |
*
|
|
20 |
*/
|
|
21 |
public class BerlinModelFactsIO {
|
|
22 |
private static final Logger logger = Logger.getLogger(BerlinModelFactsIO.class);
|
|
23 |
|
|
24 |
private static int modCount = 10000;
|
|
25 |
|
|
26 |
|
|
27 |
public static boolean invoke(Source source, CdmApplicationController cdmApp, boolean deleteAll,
|
|
28 |
MapWrapper<TaxonBase> taxonMap, MapWrapper<ReferenceBase> referenceMap){
|
|
29 |
|
|
30 |
String dbAttrName;
|
|
31 |
String cdmAttrName;
|
|
32 |
|
|
33 |
logger.info("start makeFacts ...");
|
|
34 |
|
|
35 |
boolean delete = deleteAll;
|
|
36 |
|
|
37 |
try {
|
|
38 |
//get data from database
|
|
39 |
String strQuery =
|
|
40 |
" SELECT Fact.*, PTaxon.RIdentifier as taxonId " +
|
|
41 |
" FROM Fact INNER JOIN " +
|
|
42 |
" dbo.PTaxon ON Fact.PTNameFk = PTaxon.PTNameFk AND Fact.PTRefFk = PTaxon.PTRefFk "+
|
|
43 |
" WHERE (1=1)";
|
|
44 |
ResultSet rs = source.getResultSet(strQuery) ;
|
|
45 |
|
|
46 |
int i = 0;
|
|
47 |
//for each reference
|
|
48 |
while (rs.next()){
|
|
49 |
|
|
50 |
if ((i++ % modCount) == 0){ logger.info("Facts handled: " + (i-1));}
|
|
51 |
|
|
52 |
int factId = rs.getInt("factId");
|
|
53 |
int taxonId = rs.getInt("taxonId");
|
|
54 |
int factRefFk = rs.getInt("factRefFk");
|
|
55 |
int ptDesignationRefFk = rs.getInt("PTDesignationRefFk");
|
|
56 |
int categoryFk = rs.getInt("factCategoryFk");
|
|
57 |
|
|
58 |
TaxonBase taxon = taxonMap.get(taxonId);
|
|
59 |
|
|
60 |
if (taxon != null){
|
|
61 |
if (categoryFk == FACT_DESCRIPTION){
|
|
62 |
//;
|
|
63 |
}else if (categoryFk == FACT_OBSERVATION){
|
|
64 |
//;
|
|
65 |
}else if (categoryFk == FACT_DISTIRBUTION_EM){
|
|
66 |
//
|
|
67 |
}else {
|
|
68 |
//TODO
|
|
69 |
logger.warn("FactCategory " + categoryFk + " not yet implemented");
|
|
70 |
}
|
|
71 |
|
|
72 |
//TODO
|
|
73 |
//References
|
|
74 |
//etc.
|
|
75 |
}else{
|
|
76 |
//TODO
|
|
77 |
//logger.warn("Taxa for RelPTaxon " + relPTaxonId + " do not exist in store");
|
|
78 |
}
|
|
79 |
//put
|
|
80 |
}
|
|
81 |
//taxonService.saveTaxonAll(taxonMap.objects());
|
|
82 |
|
|
83 |
logger.info("end makeFacts ...");
|
|
84 |
return true;
|
|
85 |
} catch (SQLException e) {
|
|
86 |
logger.error("SQLException:" + e);
|
|
87 |
return false;
|
|
88 |
}
|
|
89 |
|
|
90 |
}
|
|
91 |
|
|
92 |
|
|
93 |
}
|