(no commit message)
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / berlinModel / BerlinModelImport.java
1 package eu.etaxonomy.cdm.io.berlinModel;
2
3 import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.*;
4 import java.lang.reflect.InvocationTargetException;
5 import java.lang.reflect.Method;
6 import java.sql.ResultSet;
7 import java.sql.SQLException;
8 import java.util.HashMap;
9 import java.util.List;
10 import java.util.Map;
11 import java.util.UUID;
12
13 import org.apache.log4j.Logger;
14
15 import eu.etaxonomy.cdm.api.application.CdmApplicationController;
16 import eu.etaxonomy.cdm.api.service.IAgentService;
17 import eu.etaxonomy.cdm.api.service.INameService;
18 import eu.etaxonomy.cdm.api.service.IReferenceService;
19 import eu.etaxonomy.cdm.api.service.IService;
20 import eu.etaxonomy.cdm.api.service.ITaxonService;
21 import eu.etaxonomy.cdm.database.CdmDataSource;
22 import eu.etaxonomy.cdm.database.DataSourceNotFoundException;
23 import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
24 import eu.etaxonomy.cdm.io.source.Source;
25 import eu.etaxonomy.cdm.model.agent.Agent;
26 import eu.etaxonomy.cdm.model.name.BotanicalName;
27 import eu.etaxonomy.cdm.model.name.Rank;
28 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
29 import eu.etaxonomy.cdm.model.reference.Article;
30 import eu.etaxonomy.cdm.model.reference.Book;
31 import eu.etaxonomy.cdm.model.reference.BookSection;
32 import eu.etaxonomy.cdm.model.reference.Database;
33 import eu.etaxonomy.cdm.model.reference.Generic;
34 import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
35 import eu.etaxonomy.cdm.model.reference.Journal;
36 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
37 import eu.etaxonomy.cdm.model.reference.StrictReferenceBase;
38 import eu.etaxonomy.cdm.model.taxon.Synonym;
39 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
40 import eu.etaxonomy.cdm.model.taxon.Taxon;
41 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
42 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
43 import eu.etaxonomy.cdm.strategy.exceptions.UnknownRankException;
44
45 public class BerlinModelImport {
46 private static final Logger logger = Logger.getLogger(BerlinModelImport.class);
47
48 private boolean deleteAll = false;
49
50 //Connection
51 private Source source;
52
53 //CdmApplication
54 private CdmApplicationController cdmApp;
55
56 // DatabaseData
57 static String dbms = "SQLServer";
58 static String strServer = "BGBM111";
59 static String strDB = "EuroPlusMed_00_Edit";
60 static int port = 1247;
61 static String userName = "webUser";
62 static String pwd = "";
63
64 static DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
65 static String cdmServer = "192.168.2.10";
66 static String cdmDB = "cdm_test_lib";
67 //static int cdmPort = 1247;
68 static String cdmUserName = "edit";
69 static String cdmPwd = "wp5";
70
71 //Constants
72 //final boolean OBLIGATORY = true;
73 //final boolean FACULTATIVE = false;
74 final int modCount = 100;
75
76
77 //Hashmaps for Joins
78 private Map<Integer, UUID> referenceMap = new HashMap<Integer, UUID>();
79 private Map<Integer, UUID> taxonNameMap = new HashMap<Integer, UUID>();
80 private Map<Integer, UUID> taxonMap = new HashMap<Integer, UUID>();
81
82
83
84 /**
85 * @param args
86 */
87 public static void main(String[] args) {
88 System.out.println("Start import from BerlinModel ...");
89 BerlinModelImport bmImport = new BerlinModelImport();
90 bmImport.doImport();
91 System.out.println("End import from BerlinModel ...");
92 }
93
94 /**
95 * Executes the whole
96 */
97 private void doImport(){
98 makeSource(dbms, strServer, strDB, port, userName, pwd);
99
100 //Start
101 String dataSourceName = "cdmImportLibrary";
102 CdmDataSource dataSource;
103 try {
104 dataSource = CdmDataSource.NewInstance(dataSourceName);
105 } catch (DataSourceNotFoundException e1) {
106 dataSource = CdmDataSource.save(dataSourceName, dbType, cdmServer, cdmDB, cdmUserName, cdmPwd);
107 }
108 try {
109 cdmApp = new CdmApplicationController(dataSource);
110 } catch (DataSourceNotFoundException e) {
111 logger.error(e.getMessage());
112 return;
113 }
114
115 //make and save Authors
116 makeAuthors();
117
118
119 //make and save References
120 makeReferences();
121
122
123 //make and save Names
124 makeTaxonNames();
125
126 //make and save Taxa
127 makeTaxa();
128
129
130 //make and save Facts
131 makeRelTaxa();
132
133 //make and save Facts
134 makeFacts();
135
136
137 if (false){
138 //make and save publications
139 /* makePublications(root);
140 saveToXml(root.getChild("Publications", nsTcs), outputPath, outputFileName + "Publications", format);
141
142 saveToXml(root.getChild("TaxonNames", nsTcs), outputPath, outputFileName + "_TaxonNames", format);
143
144 //make and save Concepts
145 makeConcepts(root);
146 saveToXml(root.getChild("TaxonConcepts", nsTcs), outputPath, outputFileName + "_TaxonConcepts", format);
147 */ }
148 }
149
150
151
152 /**
153 * @return
154 */
155 private boolean makeAuthors(){
156 String dbAttrName;
157 String cdmAttrName;
158
159 logger.info("start makeAuthors ...");
160 logger.warn("Authors not yet implemented !!");
161
162 IAgentService agentService = cdmApp.getAgentService();
163 boolean delete = deleteAll;
164
165 if (delete){
166 List<Agent> listAllAgents = agentService.getAllAgents(0, 1000);
167 while(listAllAgents.size() > 0 ){
168 for (Agent name : listAllAgents ){
169 //FIXME
170 //nameService.remove(name);
171 }
172 listAllAgents = agentService.getAllAgents(0, 1000);
173 }
174 }
175 try {
176 //get data from database
177 String strQuery =
178 " SELECT * " +
179 " FROM AuthorTeam " ;
180 ResultSet rs = source.getResultSet(strQuery) ;
181
182
183
184
185
186 logger.info("end makeAuthors ...");
187 return true;
188 } catch (SQLException e) {
189 logger.error("SQLException:" + e);
190 return false;
191 }
192 }
193
194
195 /**
196 * @return
197 */
198 private boolean makeReferences(){
199 String dbAttrName;
200 String cdmAttrName;
201
202 logger.info("start makeReferences ...");
203 IReferenceService referenceService = cdmApp.getReferenceService();
204 boolean delete = deleteAll;
205
206 if (delete){
207 List<TaxonNameBase> listAllReferences = referenceService.getAllReferences(0, 1000);
208 while(listAllReferences.size() > 0 ){
209 for (TaxonNameBase name : listAllReferences ){
210 //FIXME
211 //nameService.remove(name);
212 }
213 listAllReferences = referenceService.getAllReferences(0, 1000);
214 }
215 }
216 try {
217
218
219 //get data from database
220 String strQuery =
221 " SELECT * " +
222 " FROM References " ;
223 ResultSet rs = source.getResultSet(strQuery) ;
224
225 int i = 0;
226 //for each reference
227 while (rs.next()){
228
229 if ((i++ % modCount) == 0){ logger.info("References handled: " + (i-1));}
230
231 //create TaxonName element
232 int refId = rs.getInt("refId");
233 int categoryId = rs.getInt("categoryFk");
234 int inRefFk = rs.getInt("inRefFk");
235
236 StrictReferenceBase ref;
237 try {
238 logger.info(categoryId);
239
240 if (categoryId == REF_JOURNAL){
241 ref = new Journal();
242 }else if(categoryId == REF_BOOK){
243 ref = new Book();
244 }else if(categoryId == REF_ARTICLE){
245 ref = new Article();
246 }else if(categoryId == REF_DATABASE){
247 ref = new Database();
248 }else if(categoryId == REF_PART_OF_OTHER_TITLE){
249 if (inRefFk == REF_BOOK){
250 //TODO
251 ref = new BookSection();
252 }else{
253 logger.warn("Reference type of part-of-reference not recognized");
254 ref = new Generic();
255 }
256 }else if(categoryId == REF_UNKNOWN){
257 ref = new Generic();
258 }else{
259 ref = new Generic();
260 }
261
262
263 dbAttrName = "refCache";
264 cdmAttrName = "";
265 ImportHelper.addStringValue(rs, ref, dbAttrName, cdmAttrName);
266
267 dbAttrName = "nomRefCache";
268 cdmAttrName = "titleCache";
269 ImportHelper.addStringValue(rs, ref, dbAttrName, cdmAttrName);
270
271
272 // dbAttrName = "BinomHybFlag";
273 // cdmAttrName = "isBinomHybrid";
274 // ImportHelper.addBooleanValue(rs, ref, dbAttrName, cdmAttrName);
275
276 //TODO
277 // all attributes
278
279
280 UUID refUuid = referenceService.saveReference(ref);
281 referenceMap.put(refId, refUuid);
282
283 } catch (Exception e) {
284 logger.warn("Reference with id threw Exception and could not be saved");
285 }
286
287 }
288
289
290 logger.info("end makeReferences ...");
291 return true;
292 } catch (SQLException e) {
293 logger.error("SQLException:" + e);
294 return false;
295 }
296 }
297
298
299
300 /**
301 * @return
302 */
303 private boolean makeTaxonNames(){
304 String dbAttrName;
305 String cdmAttrName;
306
307 logger.info("start makeTaxonNames ...");
308 INameService nameService = cdmApp.getNameService();
309 boolean delete = deleteAll;
310
311 if (delete){
312 List<TaxonNameBase> listAllNames = nameService.getAllNames(0, 1000);
313 while(listAllNames.size() > 0 ){
314 for (TaxonNameBase name : listAllNames ){
315 //FIXME
316 //nameService.remove(name);
317 }
318 listAllNames = nameService.getAllNames(0, 1000);
319 }
320 }
321
322 try {
323
324
325 //get data from database
326 String strQuery =
327 "SELECT TOP 102 Name.* , RefDetail.RefDetailId, RefDetail.RefFk, " +
328 " RefDetail.FullRefCache, RefDetail.FullNomRefCache, RefDetail.PreliminaryFlag AS RefDetailPrelim, RefDetail.Details, " +
329 " RefDetail.SecondarySources, RefDetail.IdInSource " +
330 " FROM Name LEFT OUTER JOIN RefDetail ON Name.NomRefDetailFk = RefDetail.RefDetailId AND Name.NomRefDetailFk = RefDetail.RefDetailId AND " +
331 " Name.NomRefFk = RefDetail.RefFk AND Name.NomRefFk = RefDetail.RefFk";
332 ResultSet rs = source.getResultSet(strQuery) ;
333
334 int i = 0;
335 //for each reference
336 while (rs.next()){
337
338 if ((i++ % modCount) == 0){ logger.info("Names handled: " + (i-1));}
339
340 //create TaxonName element
341 int nameId = rs.getInt("nameId");
342 int rankId = rs.getInt("rankFk");
343
344 try {
345 logger.info(rankId);
346 Rank rank = BerlinModelTransformer.rankId2Rank(rankId);
347 //FIXME
348 //BotanicalName name = BotanicalName.NewInstance(BerlinModelTransformer.rankId2Rank(rankId));
349 BotanicalName botanicalName = new BotanicalName(rank);
350
351 if (rankId < 40){
352 dbAttrName = "supraGenericName";
353 }else{
354 dbAttrName = "genus";
355 }
356 cdmAttrName = "genusOrUninomial";
357 ImportHelper.addStringValue(rs, botanicalName, dbAttrName, cdmAttrName);
358
359 dbAttrName = "genusSubdivisionEpi";
360 cdmAttrName = "infraGenericEpithet";
361 ImportHelper.addStringValue(rs, botanicalName, dbAttrName, cdmAttrName);
362
363 dbAttrName = "speciesEpi";
364 cdmAttrName = "specificEpithet";
365 ImportHelper.addStringValue(rs, botanicalName, dbAttrName, cdmAttrName);
366
367
368 dbAttrName = "infraSpeciesEpi";
369 cdmAttrName = "infraSpecificEpithet";
370 ImportHelper.addStringValue(rs, botanicalName, dbAttrName, cdmAttrName);
371
372 dbAttrName = "unnamedNamePhrase";
373 cdmAttrName = "appendedPhrase";
374 ImportHelper.addStringValue(rs, botanicalName, dbAttrName, cdmAttrName);
375
376 dbAttrName = "preliminaryFlag";
377 cdmAttrName = "XX" + "protectedTitleCache";
378 ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
379
380 dbAttrName = "HybridFormulaFlag";
381 cdmAttrName = "isHybridFormula";
382 ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
383
384 dbAttrName = "MonomHybFlag";
385 cdmAttrName = "isMonomHybrid";
386 ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
387
388 dbAttrName = "BinomHybFlag";
389 cdmAttrName = "isBinomHybrid";
390 ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
391
392 dbAttrName = "TrinomHybFlag";
393 cdmAttrName = "isTrinomHybrid";
394 ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
395
396 //botanicalName.s
397
398 // dbAttrName = "notes";
399 // cdmAttrName = "isTrinomHybrid";
400 // ImportHelper.addStringValue(rs, botanicalName, dbAttrName, cdmAttrName);
401
402 //TODO
403 //Created
404 //Note
405 //makeAuthorTeams
406 //CultivarGroupName
407 //CultivarName
408 //Source_Acc
409 //OrthoProjection
410
411 //Details
412
413 dbAttrName = "details";
414 cdmAttrName = "nomenclaturalMicroReference";
415 ImportHelper.addStringValue(rs, botanicalName, dbAttrName, cdmAttrName);
416
417 //TODO
418 //preliminaryFlag
419
420
421 UUID nameUuid = nameService.saveTaxonName(botanicalName);
422 taxonNameMap.put(nameId, nameUuid);
423
424 } catch (UnknownRankException e) {
425 logger.warn("Name with id " + nameId + " has unknown rankId " + rankId + " and could not be saved.");
426 }
427
428 }
429
430 // //id
431 // strDbAttr = "NameId";
432 // //save id for later
433 // int intID = rs.getInt(strDbAttr);
434 //
435 // String nameId = rs.getString(strDbAttr);
436 //
437 // //add TaxonName to nameMap
438 // nameMap.put(nameId, elTaxonName);
439 //
440 //
441 // strValue = nameId;
442 // strAttrName = "id";
443 // parent = elTaxonName;
444 // xml.addStringAttribute(strValue, parent, strAttrName, NS_NULL);
445 //
446 // //Code
447 // strAttrName = "nomenclaturalCode";
448 // strValue = "Botanical";
449 // parent = elTaxonName;
450 // xml.addStringAttribute(strValue, parent, strAttrName, NS_NULL);
451 //
452 // //Simple
453 // strDbAttr = "FullNameCache";
454 // strElName = "Simple";
455 // parent = elTaxonName;
456 // xml.addElement(rs,strDbAttr, parent, strElName, nsTcs, OBLIGATORY);
457 //
458 // if (fullVersion){
459 // //Rank
460 // strDbAttr = "RankAbbrev";
461 // strElName = "Rank";
462 // parent = elTaxonName;
463 // xml.addElement(rs,strDbAttr, parent, strElName, nsTcs, OBLIGATORY);
464 //
465 // //CanonicalName
466 // parent = elTaxonName;
467 // makeCanonicalName(rs, parent);
468 //
469 //
470 // //CanonicalAuthorship
471 // parent = elTaxonName;
472 // makeCanonicalAuthorship(rs, parent);
473 //
474 // } //fi fullVersion
475 //
476 // //PublishedIn
477 // strDbAttr = "NomRefFk";
478 // strAttrName = "ref";
479 // strElName = "PublishedIn";
480 // parent = elTaxonName;
481 // Attribute attrPublRef = xml.addAttributeInElement(rs, strDbAttr, parent, strAttrName, strElName, nsTcs, FACULTATIVE);
482 //
483 // if (attrPublRef != null){
484 // //does Publication exist?
485 // String ref = attrPublRef.getValue();
486 // if (! publicationMap.containsKey(ref)){
487 // logger.error("PublishedIn ref " + ref + " for " + nameId + " does not exist.");
488 // }
489 // }
490 //
491 //
492 // if (fullVersion){
493 // //Year
494 // String year = rs.getString("RefYear");
495 // if (year == null) {
496 // year = rs.getString("HigherRefYear");
497 // }
498 // strValue = year;
499 // strElName = "Year";
500 // parent = elTaxonName;
501 // xml.addStringElement(strValue, parent, strElName, nsTcs, FACULTATIVE);
502 //
503 // //MicroReference
504 // strDbAttr = "Details";
505 // strElName = "MicroReference";
506 // parent = elTaxonName;
507 // xml.addElement(rs,strDbAttr, parent, strElName, nsTcs, FACULTATIVE);
508 //
509 // }//fi fullversion
510 // }//while
511 //
512 // //insert related Names (Basionyms, ReplacedSyns, etc.
513 // makeSpellingCorrections(nameMap);
514 // makeBasionyms(nameMap);
515 // makeLaterHomonyms(nameMap);
516 // makeReplacedNames(nameMap);
517 //
518 // //insert Status infos
519 // makeNameSpecificData(nameMap);
520 //cdmApp.flush();
521 logger.info("end makeTaxonNames ...");
522 return true;
523 } catch (SQLException e) {
524 logger.error("SQLException:" + e);
525 return false;
526 }
527 }
528
529
530
531 /**
532 * @return
533 */
534 private boolean makeTaxa(){
535 String dbAttrName;
536 String cdmAttrName;
537
538 logger.info("start makeTaxa ...");
539
540 ITaxonService taxonService = cdmApp.getTaxonService();
541 INameService nameService = cdmApp.getNameService();
542 IReferenceService referenceService = cdmApp.getReferenceService();
543 boolean delete = deleteAll;
544
545 if (delete){
546 List<TaxonBase> listAllTaxa = taxonService.getAllTaxa(0, 1000);
547 while(listAllTaxa.size() > 0 ){
548 for (TaxonBase taxon : listAllTaxa ){
549 //FIXME
550 //nameService.remove(name);
551 }
552 listAllTaxa = taxonService.getAllTaxa(0, 1000);
553 }
554 }
555 try {
556 //get data from database
557 String strQuery =
558 " SELECT * " +
559 " FROM PTaxon " ;
560 ResultSet rs = source.getResultSet(strQuery) ;
561
562
563 int i = 0;
564 //for each reference
565 while (rs.next()){
566
567 if ((i++ % modCount) == 0){ logger.info("Names handled: " + (i-1));}
568
569 //create TaxonName element
570 int taxonId = rs.getInt("taxonId");
571 int statusFk = rs.getInt("statusFk");
572
573 int nameFk = rs.getInt("nameFk");
574 int refFk = rs.getInt("refFk");
575
576 TaxonNameBase taxonName;
577 UUID nameUuid = taxonNameMap.get(nameFk);
578 if (nameUuid == null){
579 taxonName = null;
580 }else{
581 taxonName = nameService.getTaxonNameByUuid(nameUuid);
582 }
583
584
585 ReferenceBase reference;
586 UUID refUuid = referenceMap.get(refFk);
587 if (refUuid == null){
588 reference = null;
589 }else{
590 reference = referenceService.getReferenceByUuid(refUuid);
591 }
592
593 TaxonBase taxonBase;
594 try {
595 logger.info(statusFk);
596 if (statusFk == 1){
597 taxonBase = Taxon.NewInstance(taxonName, reference);
598 }else if (statusFk == 2){
599 taxonBase = Synonym.NewInstance(taxonName, reference);
600 }
601
602 dbAttrName = "xxx";
603 cdmAttrName = "yyy";
604 ImportHelper.addStringValue(rs, taxonBase, dbAttrName, cdmAttrName);
605
606 dbAttrName = "genusSubdivisionEpi";
607 cdmAttrName = "infraGenericEpithet";
608 ImportHelper.addStringValue(rs, taxonBase, dbAttrName, cdmAttrName);
609
610 dbAttrName = "isDoubtful";
611 cdmAttrName = "isDoubtful";
612 ImportHelper.addBooleanValue(rs, taxonBase, dbAttrName, cdmAttrName);
613
614
615 //TODO
616 //Created
617 //Note
618 //ALL
619
620 UUID taxonUuid = taxonService.saveTaxon(taxonBase);
621 taxonMap.put(taxonId, taxonUuid);
622
623 } catch (Exception e) {
624 logger.warn("An exception occurred when creating taxon with id " + taxonId + ". Taxon could not be saved.");
625 }
626
627 }
628
629 logger.info("end makeTaxa ...");
630 return true;
631 } catch (SQLException e) {
632 logger.error("SQLException:" + e);
633 return false;
634 }
635 }
636
637
638 /**
639 * @return
640 */
641 private boolean makeRelTaxa(){
642 String dbAttrName;
643 String cdmAttrName;
644
645 logger.info("start makeTaxonRelationships ...");
646 logger.warn("RelTaxa not yet implemented !!");
647
648 ITaxonService taxonService = cdmApp.getTaxonService();
649 boolean delete = deleteAll;
650
651 // if (delete){
652 // List<Agent> listAllAgents = agentService.getAllAgents(0, 1000);
653 // while(listAllAgents.size() > 0 ){
654 // for (Agent name : listAllAgents ){
655 // //FIXME
656 // //nameService.remove(name);
657 // }
658 // listAllAgents = agentService.getAllAgents(0, 1000);
659 // }
660 // }
661 try {
662 //get data from database
663 String strQuery =
664 " SELECT * " +
665 " FROM RelPTaxon Join Taxon1 Join Taxon2" ;
666 ResultSet rs = source.getResultSet(strQuery) ;
667 int i = 0;
668 //for each reference
669 while (rs.next()){
670
671 if ((i++ % modCount) == 0){ logger.info("RelPTaxa handled: " + (i-1));}
672
673
674 int taxon1Id = rs.getInt("taxon1Id");
675 int taxon2Id = rs.getInt("taxon2Id");
676 int factId = rs.getInt("factId");
677 int relTypeFk = rs.getInt("relTypeFk");
678
679 TaxonBase taxon1 = getTaxonById(taxon1Id, taxonService);
680 TaxonBase taxon2 = getTaxonById(taxon2Id, taxonService);
681
682 //TODO
683 ReferenceBase citation = null;
684 String microcitation = null;
685
686
687 if (relTypeFk == IS_INCLUDED_IN){
688 ((Taxon)taxon2).addTaxonomicChild((Taxon)taxon1, citation, microcitation);
689 }else if (relTypeFk == IS_SYNONYM_OF){
690 ((Taxon)taxon2).addSynonym((Synonym)taxon1, SynonymRelationshipType.SYNONYM_OF());
691 }else if (relTypeFk == IS_HOMOTYPIC_SYNONYM_OF){
692 ((Taxon)taxon2).addSynonym((Synonym)taxon1, SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF());
693 }else if (relTypeFk == IS_HETEROTYPIC_SYNONYM_OF){
694 ((Taxon)taxon2).addSynonym((Synonym)taxon1, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
695 }else if (relTypeFk == IS_MISAPPLIED_NAME_OF){
696 ((Taxon)taxon2).addMisappliedName((Taxon)taxon1, citation, microcitation);
697 }else {
698 //TODO
699 logger.warn("TaxonRelationShipType " + relTypeFk + " not yet implemented");
700 }
701
702
703 //....
704
705
706
707 }
708 logger.info("end makeFacts ...");
709 return true;
710 } catch (SQLException e) {
711 logger.error("SQLException:" + e);
712 return false;
713 }
714 }
715
716
717 private TaxonBase getTaxonById(int id, IService<TaxonBase> service){
718 TaxonBase result;
719 UUID uuid = taxonMap.get(id);
720 if (uuid == null){
721 result = null;
722 }else{
723 result = service.getCdmObjectByUuid(uuid);// taxonService.getTaxonByUuid(taxonUuid);
724 }
725
726 }
727
728 /**
729 * @return
730 */
731 private boolean makeFacts(){
732 String dbAttrName;
733 String cdmAttrName;
734
735 logger.info("start makeFacts ...");
736 logger.warn("Facts not yet implemented !!");
737
738 //IAgentService agentService = cdmApp.getAgentService();
739 boolean delete = deleteAll;
740
741 // if (delete){
742 // List<Agent> listAllAgents = agentService.getAllAgents(0, 1000);
743 // while(listAllAgents.size() > 0 ){
744 // for (Agent name : listAllAgents ){
745 // //FIXME
746 // //nameService.remove(name);
747 // }
748 // listAllAgents = agentService.getAllAgents(0, 1000);
749 // }
750 // }
751 try {
752 //get data from database
753 String strQuery =
754 " SELECT * " +
755 " FROM Facts " ;
756 ResultSet rs = source.getResultSet(strQuery) ;
757 int i = 0;
758 //for each reference
759 while (rs.next()){
760
761 if ((i++ % modCount) == 0){ logger.info("Facts handled: " + (i-1));}
762
763 //create TaxonName element
764 int factId = rs.getInt("factId");
765
766 //....
767
768
769
770 }
771 logger.info("end makeFacts ...");
772 return true;
773 } catch (SQLException e) {
774 logger.error("SQLException:" + e);
775 return false;
776 }
777 }
778
779
780
781
782
783 /**
784 * initializes source
785 * @return true, if connection establisehd
786 */
787 private boolean makeSource(String dbms, String strServer, String strDB, int port, String userName, String pwd){
788 //establish connection
789 try {
790 source = new Source(dbms, strServer, strDB);
791 source.setPort(port);
792 source.setUserAndPwd(userName, pwd);
793 return true;
794 } catch (Exception e) {
795 logger.error(e);
796 return false;
797 }
798 }
799
800 }