4 package eu
.etaxonomy
.cdm
.io
.berlinModel
;
6 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.T_STATUS_ACCEPTED
;
7 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.T_STATUS_SYNONYM
;
8 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.T_STATUS_PRO_PARTE_SYN
;
9 import static eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
.T_STATUS_PARTIAL_SYN
;
12 import java
.sql
.ResultSet
;
13 import java
.sql
.SQLException
;
16 import org
.apache
.log4j
.Logger
;
18 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
19 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
20 import eu
.etaxonomy
.cdm
.io
.common
.ICdmIO
;
21 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
22 import eu
.etaxonomy
.cdm
.io
.common
.ImportHelper
;
23 import eu
.etaxonomy
.cdm
.io
.common
.MapWrapper
;
24 import eu
.etaxonomy
.cdm
.io
.common
.Source
;
25 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
26 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
27 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
37 public class BerlinModelTaxonIO
extends BerlinModelIOBase
{
38 private static final Logger logger
= Logger
.getLogger(BerlinModelTaxonIO
.class);
40 private int modCount
= 30000;
42 public BerlinModelTaxonIO(){
47 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
50 protected boolean doCheck(IImportConfigurator config
){
51 boolean result
= true;
52 BerlinModelImportConfigurator bmiConfig
= (BerlinModelImportConfigurator
)config
;
53 logger
.warn("Checking for Taxa not yet fully implemented");
54 result
&= checkTaxonStatus(bmiConfig
);
55 //result &= checkArticlesWithoutJournal(bmiConfig);
60 private boolean checkTaxonStatus(BerlinModelImportConfigurator bmiConfig
){
62 boolean result
= true;
63 Source source
= bmiConfig
.getSource();
64 String strSQL
= " SELECT RelPTaxon.RelQualifierFk, RelPTaxon.relPTaxonId, PTaxon.PTNameFk, PTaxon.PTRefFk, PTaxon_1.PTNameFk AS Expr1, PTaxon.RIdentifier, PTaxon_1.RIdentifier AS Expr3, Name.FullNameCache " +
66 " INNER JOIN PTaxon ON RelPTaxon.PTNameFk1 = PTaxon.PTNameFk AND RelPTaxon.PTRefFk1 = PTaxon.PTRefFk " +
67 " INNER JOIN PTaxon AS PTaxon_1 ON RelPTaxon.PTNameFk2 = PTaxon_1.PTNameFk AND RelPTaxon.PTRefFk2 = PTaxon_1.PTRefFk " +
68 " INNER JOIN Name ON PTaxon.PTNameFk = Name.NameId " +
69 " WHERE (dbo.PTaxon.StatusFk = 1) AND ((RelPTaxon.RelQualifierFk = 7) OR (RelPTaxon.RelQualifierFk = 6) OR (RelPTaxon.RelQualifierFk = 2)) ";
70 ResultSet rs
= source
.getResultSet(strSQL
);
71 boolean firstRow
= true;
76 System
.out
.println("========================================================");
77 logger
.warn("There are taxa that have a 'is synonym of' - relationship but having taxon status 'accepted'!");
78 System
.out
.println("========================================================");
80 int rIdentifier
= rs
.getInt("RIdentifier");
81 int nameFk
= rs
.getInt("PTNameFk");
82 int refFk
= rs
.getInt("PTRefFk");
83 int relPTaxonId
= rs
.getInt("relPTaxonId");
84 String taxonName
= rs
.getString("FullNameCache");
86 System
.out
.println("RIdentifier:" + rIdentifier
+ "\n name: " + nameFk
+
87 "\n taxonName: " + taxonName
+ "\n refId: " + refFk
+ "\n RelPTaxonId: " + relPTaxonId
);
88 result
= firstRow
= false;
91 System
.out
.println(" ");
95 } catch (SQLException e
) {
102 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doInvoke(eu.etaxonomy.cdm.io.common.IImportConfigurator, eu.etaxonomy.cdm.api.application.CdmApplicationController, java.util.Map)
105 protected boolean doInvoke(IImportConfigurator config
, CdmApplicationController cdmApp
,
106 Map
<String
, MapWrapper
<?
extends CdmBase
>> stores
){
108 MapWrapper
<TaxonNameBase
> taxonNameMap
= (MapWrapper
<TaxonNameBase
>)stores
.get(ICdmIO
.TAXONNAME_STORE
);
109 MapWrapper
<ReferenceBase
> referenceMap
= (MapWrapper
<ReferenceBase
>)stores
.get(ICdmIO
.REFERENCE_STORE
);
110 MapWrapper
<ReferenceBase
> nomRefMap
= (MapWrapper
<ReferenceBase
>)stores
.get(ICdmIO
.NOMREF_STORE
);
111 MapWrapper
<TaxonBase
> taxonMap
= (MapWrapper
<TaxonBase
>)stores
.get(ICdmIO
.TAXON_STORE
);
113 BerlinModelImportConfigurator bmiConfig
= (BerlinModelImportConfigurator
)config
;
114 Source source
= bmiConfig
.getSource();
118 logger
.info("start makeTaxa ...");
120 ITaxonService taxonService
= cdmApp
.getTaxonService();
123 //get data from database
129 ResultSet rs
= source
.getResultSet(strQuery
) ;
135 if ((i
++ % modCount
) == 0 && i
!= 1 ){ logger
.info("PTaxa handled: " + (i
-1));}
137 //create TaxonName element
138 int taxonId
= rs
.getInt("RIdentifier");
139 int statusFk
= rs
.getInt("statusFk");
141 int nameFk
= rs
.getInt("PTNameFk");
142 int refFk
= rs
.getInt("PTRefFk");
143 String doubtful
= rs
.getString("DoubtfulFlag");
145 TaxonNameBase taxonName
= null;
146 if (taxonNameMap
!= null){
147 taxonName
= taxonNameMap
.get(nameFk
);
150 ReferenceBase reference
= null;
151 if (referenceMap
!= null){
152 reference
= referenceMap
.get(refFk
);
153 if (reference
== null){
154 reference
= nomRefMap
.get(refFk
);
158 if(! config
.isIgnoreNull()){
159 if (taxonName
== null ){
160 logger
.warn("TaxonName belonging to taxon (RIdentifier = " + taxonId
+ ") could not be found in store. Taxon will not be transported");
161 continue; //next taxon
162 }else if (reference
== null ){
163 logger
.warn("Reference belonging to taxon could not be found in store. Taxon will not be imported");
164 continue; //next taxon
171 logger
.debug(statusFk
);
172 if (statusFk
== T_STATUS_ACCEPTED
){
173 taxon
= Taxon
.NewInstance(taxonName
, reference
);
175 }else if (statusFk
== T_STATUS_SYNONYM
|| statusFk
== T_STATUS_PRO_PARTE_SYN
|| statusFk
== T_STATUS_PARTIAL_SYN
){
176 synonym
= Synonym
.NewInstance(taxonName
, reference
);
178 if (statusFk
== T_STATUS_PRO_PARTE_SYN
){
179 bmiConfig
.addProParteSynonym(synonym
);
181 if (statusFk
== T_STATUS_PARTIAL_SYN
){
182 bmiConfig
.addPartialSynonym(synonym
);
185 logger
.warn("TaxonStatus " + statusFk
+ " not yet implemented. Taxon (RIdentifier = " + taxonId
+ ") left out.");
190 // dbAttrName = "Detail";
191 // cdmAttrName = "Micro";
192 // ImportHelper.addStringValue(rs, taxonBase, dbAttrName, cdmAttrName);
194 if (doubtful
.equals("a")){
195 taxonBase
.setDoubtful(false);
196 }else if(doubtful
.equals("d")){
197 taxonBase
.setDoubtful(true);
198 }else if(doubtful
.equals("i")){
200 logger
.warn("Doubtful = i (inactivated) not yet implemented. Doubtful set to false");
204 ImportHelper
.setOriginalSource(taxonBase
, bmiConfig
.getSourceReference(), taxonId
);
213 taxonMap
.put(taxonId
, taxonBase
);
214 } catch (Exception e
) {
215 logger
.warn("An exception occurred when creating taxon with id " + taxonId
+ ". Taxon could not be saved.");
218 //invokeRelations(source, cdmApp, deleteAll, taxonMap, referenceMap);
219 logger
.info("saving taxa ...");
220 taxonService
.saveTaxonAll(taxonMap
.objects());
222 logger
.info("end makeTaxa ...");
225 } catch (SQLException e
) {
226 logger
.error("SQLException:" + e
);
233 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
235 protected boolean isIgnore(IImportConfigurator config
){
236 return ! config
.isDoTaxa();