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
.caryo
;
12 import java
.sql
.ResultSet
;
13 import java
.sql
.SQLException
;
14 import java
.util
.HashMap
;
15 import java
.util
.HashSet
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.springframework
.stereotype
.Component
;
22 import eu
.etaxonomy
.cdm
.io
.common
.DbImportBase
;
23 import eu
.etaxonomy
.cdm
.io
.common
.ResultSetPartitioner
;
24 import eu
.etaxonomy
.cdm
.io
.common
.Source
;
25 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
26 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
27 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
28 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
29 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
30 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
33 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
42 public class CaryoTaxonImport
extends DbImportBase
<CaryoImportState
, CaryoImportConfigurator
> {
43 private static final Logger logger
= Logger
.getLogger(CaryoTaxonImport
.class);
45 private int modCount
= 10000;
46 private static final String pluralString
= "taxa";
47 private static final String dbTableName
= "CARYOPHYLLALES";
48 private static final String FAMILY
= "Family";
49 private static final String PERSON
= "Person";
50 private static final String TEAM
= "Team";
51 private static final String JOURNAL
= "Journal";
52 private static final String BOOK
= "Book";
55 private Map
<String
, Taxon
> familyMap
= new HashMap
<String
, Taxon
>();
56 private Map
<String
, TeamOrPersonBase
> personMap
= new HashMap
<String
, TeamOrPersonBase
>();
57 private Map
<String
, TeamOrPersonBase
> teamMap
= new HashMap
<String
, TeamOrPersonBase
>();
58 private Map
<String
, Reference
> journalMap
= new HashMap
<String
, Reference
>();
59 private Map
<String
, Reference
> bookMap
= new HashMap
<String
, Reference
>();
62 private Classification classification
;
65 public CaryoTaxonImport(){
66 super(pluralString
, dbTableName
);
73 * @see eu.etaxonomy.cdm.io.common.DbImportBase#getIdQuery(eu.etaxonomy.cdm.io.common.DbImportStateBase)
76 protected String
getIdQuery(CaryoImportState state
) {
77 String strRecordQuery
=
79 " FROM " + dbTableName
;
80 return strRecordQuery
;
85 * @see eu.etaxonomy.cdm.io.common.DbImportBase#getRecordQuery(eu.etaxonomy.cdm.io.common.DbImportConfiguratorBase)
88 protected String
getRecordQuery(CaryoImportConfigurator config
) {
89 String strRecordQuery
=
91 " FROM " + getTableName() + " t " +
92 " WHERE ( t.ID IN (" + ID_LIST_TOKEN
+ ") )";
93 return strRecordQuery
;
99 * @see eu.etaxonomy.cdm.io.globis.GlobisImportBase#doPartition(eu.etaxonomy.cdm.io.common.ResultSetPartitioner, eu.etaxonomy.cdm.io.globis.GlobisImportState)
102 public boolean doPartition(ResultSetPartitioner partitioner
, CaryoImportState state
) {
103 boolean success
= true;
105 Set
<TaxonBase
> objectsToSave
= new HashSet
<TaxonBase
>();
107 // Map<String, Taxon> taxonMap = (Map<String, Taxon>) partitioner.getObjectMap(TAXON_NAMESPACE);
110 classification
= getClassification(state
);
118 ResultSet rs
= partitioner
.getResultSet();
125 if ((i
++ % modCount
) == 0 && i
!= 1 ){ logger
.info(pluralString
+ " handled: " + (i
-1));}
127 Integer taxonId
= rs
.getInt("IDcurrentspec");
130 //String dtSpcJahr -> ignore !
131 //empty: fiSpcLiteratur
141 // classification.addParentChild(nextHigherTaxon, species, sourceRef, null);
144 // this.doIdCreatedUpdatedNotes(state, species, rs, taxonId, TAXON_NAMESPACE);
146 // objectsToSave.add(species);
149 } catch (Exception e
) {
150 logger
.warn("Exception in current_species: IDcurrentspec " + taxonId
+ ". " + e
.getMessage());
151 // e.printStackTrace();
156 // logger.warn("Specimen: " + countSpecimen + ", Descriptions: " + countDescriptions );
158 logger
.warn(pluralString
+ " to save: " + objectsToSave
.size());
159 getTaxonService().save(objectsToSave
);
162 } catch (SQLException e
) {
163 logger
.error("SQLException:" + e
);
174 private void doAuthors(CaryoImportState state
) {
175 // TODO Auto-generated method stub
182 private void doBooks(CaryoImportState state
) {
183 // TODO Auto-generated method stub
190 private void doJournals(CaryoImportState state
) {
191 // TODO Auto-generated method stub
198 private void doFamilies(CaryoImportState state
) throws SQLException
{
199 Source source
= state
.getConfig().getSource();
200 String sqlFamily
= "SELECT DISTINCT family FROM table WHERE family IS NOT NULL";
201 ResultSet rs
= source
.getResultSet(sqlFamily
);
203 String family
= rs
.getString("family");
204 BotanicalName name
= BotanicalName
.NewInstance(Rank
.FAMILY());
205 name
.setGenusOrUninomial(family
);
206 Taxon taxon
= Taxon
.NewInstance(name
, state
.getTransactionalSourceReference());
207 classification
.addChildTaxon(taxon
, null, null, null);
208 // taxon.addSource(id, idNamespace, citation, null);
211 familyMap
.put(family
, taxon
);
216 private Classification
getClassification(CaryoImportState state
) {
217 if (this.classification
== null){
218 String name
= state
.getConfig().getClassificationName();
219 Reference
<?
> reference
= state
.getTransactionalSourceReference();
220 this.classification
= Classification
.NewInstance(name
, reference
, Language
.DEFAULT());
221 if (state
.getConfig().getClassificationUuid() != null){
222 classification
.setUuid(state
.getConfig().getClassificationUuid());
224 getClassificationService().save(classification
);
226 return this.classification
;
235 * @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet)
237 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
) {
240 // Set<String> idSet;
241 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<Object
, Map
<String
, ?
extends CdmBase
>>();
243 // Set<String> taxonIdSet = new HashSet<String>();
245 // while (rs.next()){
246 //// handleForeignKey(rs, taxonIdSet, "taxonId");
250 // nameSpace = TAXON_NAMESPACE;
251 // cdmClass = Taxon.class;
252 // idSet = taxonIdSet;
253 // Map<String, Taxon> objectMap = (Map<String, Taxon>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
254 // result.put(nameSpace, objectMap);
257 // } catch (SQLException e) {
258 // throw new RuntimeException(e);
264 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
267 protected boolean doCheck(CaryoImportState state
){
273 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
275 protected boolean isIgnore(CaryoImportState state
){
276 return ! state
.getConfig().isDoTaxa();