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(IImportConfigurator config
,
70 Map
<String
, MapWrapper
<?
extends CdmBase
>> stores
){
72 MapWrapper
<TaxonBase
> taxonMap
= (MapWrapper
<TaxonBase
>)stores
.get(ICdmIO
.TAXON_STORE
);
73 MapWrapper
<ReferenceBase
> referenceMap
= (MapWrapper
<ReferenceBase
>)stores
.get(ICdmIO
.REFERENCE_STORE
);
74 BerlinModelImportConfigurator bmiConfig
= (BerlinModelImportConfigurator
)config
;
80 Set
<TaxonBase
> taxonStore
= new HashSet
<TaxonBase
>();
81 Source source
= bmiConfig
.getSource();
86 logger
.info("start make occurrences ...");
88 boolean delete
= bmiConfig
.isDeleteAll();
91 //get data from database
93 " SELECT PTaxon.RIdentifier, emOccurrence.OccurrenceId, emOccurSumCat.emOccurSumCatId, emOccurSumCat.Short, emOccurSumCat.Description, " +
94 " emOccurSumCat.OutputCode, emArea.AreaId, emArea.EMCode, emArea.ISOCode, emArea.TDWGCode, emArea.Unit, " +
95 " emArea.Status, emArea.OutputOrder, emArea.eur, emArea.EuroMedArea " +
96 " FROM emOccurrence INNER JOIN " +
97 " emArea ON emOccurrence.AreaFk = emArea.AreaId INNER JOIN " +
98 " PTaxon ON emOccurrence.PTNameFk = PTaxon.PTNameFk AND emOccurrence.PTRefFk = PTaxon.PTRefFk LEFT OUTER JOIN " +
99 " emOccurSumCat ON emOccurrence.SummaryStatus = emOccurSumCat.emOccurSumCatId LEFT OUTER JOIN " +
100 " emOccurrenceSource ON emOccurrence.OccurrenceId = emOccurrenceSource.OccurrenceFk " +
102 ResultSet rs
= source
.getResultSet(strQuery
) ;
108 if ((i
++ % modCount
) == 0 && i
!= 1 ){ logger
.info("Facts handled: " + (i
-1));}
110 int occurrenceId
= rs
.getInt("OccurrenceId");
111 int taxonId
= rs
.getInt("RIdentifier");
112 String tdwgCode
= rs
.getString("TDWGCode");
113 Integer emStatusId
= (Integer
)rs
.getObject("emOccurSumCatId");
116 TaxonBase taxonBase
= taxonMap
.get(taxonId
);
117 if (taxonBase
!= null){
120 PresenceAbsenceTermBase
<?
> status
= null;
121 if (emStatusId
!= null){
122 status
= BerlinModelTransformer
.occStatus2PresenceAbsence(emStatusId
);
125 NamedArea tdwgArea
= TdwgArea
.getAreaByTdwgLabel(tdwgCode
);
128 if ( taxonBase
instanceof Taxon
) {
129 taxon
= (Taxon
) taxonBase
;
131 logger
.warn("TaxonBase for Occurrence " + occurrenceId
+ " was not of type Taxon but: " + taxonBase
.getClass().getSimpleName());
135 if (tdwgArea
!= null){
136 Distribution distribution
= Distribution
.NewInstance(tdwgArea
, status
);
137 //TODO only one description per taxon (for all EM distributions)
138 TaxonDescription taxonDescription
= TaxonDescription
.NewInstance();
140 taxon
.addDescription(taxonDescription
);
141 taxonStore
.add(taxon
);
144 } catch (UnknownCdmTypeException e
) {
145 // TODO Auto-generated catch block
155 // //commonNames -> TODO move to separate IO
156 // String commonNameString;
157 // if (taxon.getName() != null){
158 // commonNameString = "Common " + taxon.getName().getTitleCache();
160 // commonNameString = "Common (null)";
162 // Language language = bmiConfig.getFactLanguage();
164 // CommonTaxonName commonName = CommonTaxonName.NewInstance(commonNameString, language);
165 // taxonDescription.addElement(commonName);
171 logger
.warn("Taxon for Fact " + occurrenceId
+ " does not exist in store");
175 logger
.info("Taxa to save: " + taxonStore
.size());
176 getTaxonService().saveTaxonAll(taxonStore
);
178 logger
.info("end make occurrences ...");
180 } catch (SQLException e
) {
181 logger
.error("SQLException:" + e
);
188 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
190 protected boolean isIgnore(IImportConfigurator config
){
191 return ! config
.isDoOccurrence();