2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.io
.berlinModel
.in
;
12 import java
.sql
.ResultSet
;
13 import java
.sql
.SQLException
;
14 import java
.util
.HashSet
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.springframework
.stereotype
.Component
;
21 import eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
;
22 import eu
.etaxonomy
.cdm
.io
.common
.ICdmIO
;
23 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
24 import eu
.etaxonomy
.cdm
.io
.common
.MapWrapper
;
25 import eu
.etaxonomy
.cdm
.io
.common
.Source
;
26 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
27 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
28 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTermBase
;
29 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
30 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
31 import eu
.etaxonomy
.cdm
.model
.location
.TdwgArea
;
32 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
33 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
35 import eu
.etaxonomy
.cdm
.strategy
.exceptions
.UnknownCdmTypeException
;
43 public class BerlinModelCommonNamesImport
extends BerlinModelImportBase
{
44 private static final Logger logger
= Logger
.getLogger(BerlinModelCommonNamesImport
.class);
46 private static int modCount
= 10000;
48 public BerlinModelCommonNamesImport(){
53 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
56 protected boolean doCheck(IImportConfigurator config
){
57 boolean result
= true;
58 logger
.warn("Checking for Occurrence not yet implemented");
59 //result &= checkArticlesWithoutJournal(bmiConfig);
60 //result &= checkPartOfJournal(bmiConfig);
66 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doInvoke(eu.etaxonomy.cdm.io.common.IImportConfigurator, eu.etaxonomy.cdm.api.application.CdmApplicationController, java.util.Map)
69 protected boolean doInvoke(BerlinModelImportState
<BerlinModelImportConfigurator
> state
){
71 MapWrapper
<TaxonBase
> taxonMap
= (MapWrapper
<TaxonBase
>)state
.getStore(ICdmIO
.TAXON_STORE
);
72 MapWrapper
<ReferenceBase
> referenceMap
= (MapWrapper
<ReferenceBase
>)state
.getStore(ICdmIO
.REFERENCE_STORE
);
73 BerlinModelImportConfigurator config
= state
.getConfig();
79 Set
<TaxonBase
> taxonStore
= new HashSet
<TaxonBase
>();
80 Source source
= config
.getSource();
85 logger
.info("start make occurrences ...");
87 boolean delete
= config
.isDeleteAll();
90 //get data from database
92 " SELECT PTaxon.RIdentifier, emOccurrence.OccurrenceId, emOccurSumCat.emOccurSumCatId, emOccurSumCat.Short, emOccurSumCat.Description, " +
93 " emOccurSumCat.OutputCode, emArea.AreaId, emArea.EMCode, emArea.ISOCode, emArea.TDWGCode, emArea.Unit, " +
94 " emArea.Status, emArea.OutputOrder, emArea.eur, emArea.EuroMedArea " +
95 " FROM emOccurrence INNER JOIN " +
96 " emArea ON emOccurrence.AreaFk = emArea.AreaId INNER JOIN " +
97 " PTaxon ON emOccurrence.PTNameFk = PTaxon.PTNameFk AND emOccurrence.PTRefFk = PTaxon.PTRefFk LEFT OUTER JOIN " +
98 " emOccurSumCat ON emOccurrence.SummaryStatus = emOccurSumCat.emOccurSumCatId LEFT OUTER JOIN " +
99 " emOccurrenceSource ON emOccurrence.OccurrenceId = emOccurrenceSource.OccurrenceFk " +
101 ResultSet rs
= source
.getResultSet(strQuery
) ;
107 if ((i
++ % modCount
) == 0 && i
!= 1 ){ logger
.info("Facts handled: " + (i
-1));}
109 int occurrenceId
= rs
.getInt("OccurrenceId");
110 int taxonId
= rs
.getInt("RIdentifier");
111 String tdwgCode
= rs
.getString("TDWGCode");
112 Integer emStatusId
= (Integer
)rs
.getObject("emOccurSumCatId");
115 TaxonBase taxonBase
= taxonMap
.get(taxonId
);
116 if (taxonBase
!= null){
119 PresenceAbsenceTermBase
<?
> status
= null;
120 if (emStatusId
!= null){
121 status
= BerlinModelTransformer
.occStatus2PresenceAbsence(emStatusId
);
124 NamedArea tdwgArea
= TdwgArea
.getAreaByTdwgLabel(tdwgCode
);
127 if ( taxonBase
instanceof Taxon
) {
128 taxon
= (Taxon
) taxonBase
;
130 logger
.warn("TaxonBase for Occurrence " + occurrenceId
+ " was not of type Taxon but: " + taxonBase
.getClass().getSimpleName());
134 if (tdwgArea
!= null){
135 Distribution distribution
= Distribution
.NewInstance(tdwgArea
, status
);
136 //TODO only one description per taxon (for all EM distributions)
137 TaxonDescription taxonDescription
= TaxonDescription
.NewInstance();
139 taxon
.addDescription(taxonDescription
);
140 taxonStore
.add(taxon
);
143 } catch (UnknownCdmTypeException e
) {
144 // TODO Auto-generated catch block
154 // //commonNames -> TODO move to separate IO
155 // String commonNameString;
156 // if (taxon.getName() != null){
157 // commonNameString = "Common " + taxon.getName().getTitleCache();
159 // commonNameString = "Common (null)";
161 // Language language = bmiConfig.getFactLanguage();
163 // CommonTaxonName commonName = CommonTaxonName.NewInstance(commonNameString, language);
164 // taxonDescription.addElement(commonName);
170 logger
.warn("Taxon for Fact " + occurrenceId
+ " does not exist in store");
174 logger
.info("Taxa to save: " + taxonStore
.size());
175 getTaxonService().saveTaxonAll(taxonStore
);
177 logger
.info("end make occurrences ...");
179 } catch (SQLException e
) {
180 logger
.error("SQLException:" + e
);
187 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
189 protected boolean isIgnore(IImportConfigurator config
){
190 return ! config
.isDoOccurrence();