1 package eu
.etaxonomy
.cdm
.io
.berlinModel
;
3 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.*;
4 import java
.sql
.ResultSet
;
5 import java
.sql
.SQLException
;
6 import java
.util
.ArrayList
;
7 import java
.util
.Collection
;
8 import java
.util
.HashMap
;
9 import java
.util
.Iterator
;
10 import java
.util
.List
;
12 import java
.util
.UUID
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.springframework
.stereotype
.Service
;
17 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
18 import eu
.etaxonomy
.cdm
.api
.service
.IAgentService
;
19 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
20 import eu
.etaxonomy
.cdm
.api
.service
.IReferenceService
;
21 import eu
.etaxonomy
.cdm
.api
.service
.IService
;
22 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
23 import eu
.etaxonomy
.cdm
.io
.source
.Source
;
24 import eu
.etaxonomy
.cdm
.model
.agent
.Agent
;
25 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
26 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
27 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
28 import eu
.etaxonomy
.cdm
.model
.reference
.Article
;
29 import eu
.etaxonomy
.cdm
.model
.reference
.Book
;
30 import eu
.etaxonomy
.cdm
.model
.reference
.BookSection
;
31 import eu
.etaxonomy
.cdm
.model
.reference
.Database
;
32 import eu
.etaxonomy
.cdm
.model
.reference
.Generic
;
33 import eu
.etaxonomy
.cdm
.model
.reference
.Journal
;
34 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
35 import eu
.etaxonomy
.cdm
.model
.reference
.StrictReferenceBase
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
37 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
38 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
39 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
40 import eu
.etaxonomy
.cdm
.strategy
.exceptions
.UnknownRankException
;
43 public class BerlinModelImport
{
44 private static final Logger logger
= Logger
.getLogger(BerlinModelImport
.class);
46 private boolean deleteAll
= false;
49 private Source source
;
52 private CdmApplicationController cdmApp
;
55 //final boolean OBLIGATORY = true;
56 //final boolean FACULTATIVE = false;
57 final int modCount
= 1000;
61 //OLD: private Map<Integer, UUID> referenceMap = new HashMap<Integer, UUID>();
62 private MapWrapper
<Agent
> authorStore
= new MapWrapper
<Agent
>(null);
63 private MapWrapper
<ReferenceBase
> referenceStore
= new MapWrapper
<ReferenceBase
>(null);
64 private MapWrapper
<TaxonNameBase
> taxonNameStore
= new MapWrapper
<TaxonNameBase
>(null);
65 private MapWrapper
<TaxonBase
> taxonStore
= new MapWrapper
<TaxonBase
>(null);
71 public boolean doImport(Source source
, CdmApplicationController cdmApp
){
72 if (source
== null || cdmApp
== null){
73 throw new NullPointerException("Source and CdmApplicationController must not be null");
78 //make and save Authors
80 if (! BerlinModelAuthorIO
.invoke(source
, cdmApp
, deleteAll
, authorStore
)){
84 referenceStore
= null;
86 //make and save References
88 if (! BerlinModelReferenceIO
.invoke(source
, cdmApp
, deleteAll
, referenceStore
, authorStore
)){
92 referenceStore
= null;
96 if (! BerlinModelTaxonNameIO
.invoke(source
, cdmApp
, deleteAll
, taxonNameStore
, referenceStore
, authorStore
)){
105 if (! BerlinModelTaxonIO
.invoke(source
, cdmApp
, deleteAll
, taxonStore
, taxonNameStore
, referenceStore
)){
109 //make and save Facts
112 //make and save Facts
116 //make and save publications
117 /* makePublications(root);
118 saveToXml(root.getChild("Publications", nsTcs), outputPath, outputFileName + "Publications", format);
120 saveToXml(root.getChild("TaxonNames", nsTcs), outputPath, outputFileName + "_TaxonNames", format);
122 //make and save Concepts
124 saveToXml(root.getChild("TaxonConcepts", nsTcs), outputPath, outputFileName + "_TaxonConcepts", format);
132 private boolean makeRelTaxa(){
136 logger
.info("start makeTaxonRelationships ...");
137 logger
.warn("RelTaxa not yet implemented !!");
139 ITaxonService taxonService
= cdmApp
.getTaxonService();
140 boolean delete
= deleteAll
;
143 // List<Agent> listAllAgents = agentService.getAllAgents(0, 1000);
144 // while(listAllAgents.size() > 0 ){
145 // for (Agent name : listAllAgents ){
147 // //nameService.remove(name);
149 // listAllAgents = agentService.getAllAgents(0, 1000);
153 //get data from database
156 " FROM RelPTaxon Join Taxon1 Join Taxon2" ;
157 ResultSet rs
= source
.getResultSet(strQuery
) ;
162 if ((i
++ % modCount
) == 0){ logger
.info("RelPTaxa handled: " + (i
-1));}
165 int taxon1Id
= rs
.getInt("taxon1Id");
166 int taxon2Id
= rs
.getInt("taxon2Id");
167 int factId
= rs
.getInt("factId");
168 int relTypeFk
= rs
.getInt("relTypeFk");
170 TaxonBase taxon1
= taxonStore
.get(taxon1Id
);
171 TaxonBase taxon2
= taxonStore
.get(taxon2Id
);
174 ReferenceBase citation
= null;
175 String microcitation
= null;
178 if (relTypeFk
== IS_INCLUDED_IN
){
179 ((Taxon
)taxon2
).addTaxonomicChild((Taxon
)taxon1
, citation
, microcitation
);
180 }else if (relTypeFk
== IS_SYNONYM_OF
){
181 ((Taxon
)taxon2
).addSynonym((Synonym
)taxon1
, SynonymRelationshipType
.SYNONYM_OF());
182 }else if (relTypeFk
== IS_HOMOTYPIC_SYNONYM_OF
){
183 ((Taxon
)taxon2
).addSynonym((Synonym
)taxon1
, SynonymRelationshipType
.HOMOTYPIC_SYNONYM_OF());
184 }else if (relTypeFk
== IS_HETEROTYPIC_SYNONYM_OF
){
185 ((Taxon
)taxon2
).addSynonym((Synonym
)taxon1
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
186 }else if (relTypeFk
== IS_MISAPPLIED_NAME_OF
){
187 ((Taxon
)taxon2
).addMisappliedName((Taxon
)taxon1
, citation
, microcitation
);
190 logger
.warn("TaxonRelationShipType " + relTypeFk
+ " not yet implemented");
199 logger
.info("end makeFacts ...");
201 } catch (SQLException e
) {
202 logger
.error("SQLException:" + e
);
211 private boolean makeFacts(){
215 logger
.info("start makeFacts ...");
216 logger
.warn("Facts not yet implemented !!");
218 //IAgentService agentService = cdmApp.getAgentService();
219 boolean delete
= deleteAll
;
222 // List<Agent> listAllAgents = agentService.getAllAgents(0, 1000);
223 // while(listAllAgents.size() > 0 ){
224 // for (Agent name : listAllAgents ){
226 // //nameService.remove(name);
228 // listAllAgents = agentService.getAllAgents(0, 1000);
232 //get data from database
236 ResultSet rs
= source
.getResultSet(strQuery
) ;
241 if ((i
++ % modCount
) == 0){ logger
.info("Facts handled: " + (i
-1));}
243 //create TaxonName element
244 int factId
= rs
.getInt("factId");
251 logger
.info("end makeFacts ...");
253 } catch (SQLException e
) {
254 logger
.error("SQLException:" + e
);