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
.pesi
.indexFungorum
;
12 import java
.sql
.ResultSet
;
13 import java
.sql
.SQLException
;
14 import java
.util
.HashMap
;
15 import java
.util
.HashSet
;
19 import org
.apache
.commons
.lang
.StringUtils
;
20 import org
.apache
.log4j
.Logger
;
21 import org
.springframework
.stereotype
.Component
;
23 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
24 import eu
.etaxonomy
.cdm
.io
.common
.ResultSetPartitioner
;
25 import eu
.etaxonomy
.cdm
.io
.pesi
.out
.PesiTransformer
;
26 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
27 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
28 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
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
;
34 import eu
.etaxonomy
.cdm
.strategy
.parser
.NonViralNameParserImpl
;
42 public class IndexFungorumSpeciesImport
extends IndexFungorumImportBase
{
43 private static final Logger logger
= Logger
.getLogger(IndexFungorumSpeciesImport
.class);
45 private static final String pluralString
= "species";
46 private static final String dbTableName
= "[tblPESIfungi-IFdata]";
48 public IndexFungorumSpeciesImport(){
49 super(pluralString
, dbTableName
, null);
56 protected String
getIdQuery() {
57 String result
= " SELECT RECORD_NUMBER FROM " + getTableName() +
58 " ORDER BY PreferredName ";
66 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getRecordQuery(eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator)
69 protected String
getRecordQuery(IndexFungorumImportConfigurator config
) {
70 String strRecordQuery
=
71 " SELECT DISTINCT distribution.PreferredNameFDCnumber, species.* " +
72 " FROM tblPESIfungi AS distribution RIGHT OUTER JOIN dbo.[tblPESIfungi-IFdata] AS species ON distribution.PreferredNameIFnumber = species.RECORD_NUMBER " +
73 " WHERE ( species.RECORD_NUMBER IN (" + ID_LIST_TOKEN
+ ") )" +
75 return strRecordQuery
;
80 public boolean doPartition(ResultSetPartitioner partitioner
, IndexFungorumImportState state
) {
81 boolean success
= true;
82 Reference
<?
> sourceReference
= state
.getRelatedObject(NAMESPACE_REFERENCE
, SOURCE_REFERENCE
, Reference
.class);
83 ResultSet rs
= partitioner
.getResultSet();
85 Classification classification
= getClassification(state
);
90 //DisplayName, NomRefCache
92 Integer id
= (Integer
)rs
.getObject("RECORD_NUMBER");
94 String preferredName
= rs
.getString("PreferredName");
95 if (StringUtils
.isBlank(preferredName
)){
96 logger
.warn("Preferred name is blank. This case is not yet handled by IF import. RECORD_NUMBER" + CdmUtils
.Nz(id
));
99 Rank rank
= Rank
.SPECIES();
101 NonViralNameParserImpl parser
= NonViralNameParserImpl
.NewInstance();
102 NonViralName
<?
> name
= parser
.parseSimpleName(preferredName
, NomenclaturalCode
.ICBN
, rank
);
104 Taxon taxon
= Taxon
.NewInstance(name
, sourceReference
);
105 Taxon parent
= getParentTaxon(state
, rs
);
106 classification
.addParentChild(parent
, taxon
, null, null);
108 //author + publication
109 makeAuthorAndPublication(state
, rs
, name
);
111 makeSource(state
, taxon
, id
, NAMESPACE_SPECIES
);
113 getTaxonService().saveOrUpdate(taxon
);
117 } catch (Exception e
) {
119 logger
.error(e
.getMessage());
120 state
.setSuccess(false);
127 private Taxon
getParentTaxon(IndexFungorumImportState state
, ResultSet rs
) throws SQLException
{
128 Integer genusId
= rs
.getInt("PreferredNameFDCnumber");
130 Taxon taxon
= state
.getRelatedObject(NAMESPACE_GENERA
, String
.valueOf(genusId
), Taxon
.class);
132 logger
.warn("Taxon not found for " + genusId
);
138 * @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet)
140 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
) {
144 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<Object
, Map
<String
, ?
extends CdmBase
>>();
147 Set
<String
> taxonIdSet
= new HashSet
<String
>();
149 handleForeignKey(rs
, taxonIdSet
,"PreferredNameFDCnumber" );
153 nameSpace
= NAMESPACE_GENERA
;
154 cdmClass
= TaxonBase
.class;
156 Map
<String
, TaxonBase
> taxonMap
= (Map
<String
, TaxonBase
>)getCommonService().getSourcedObjectsByIdInSource(cdmClass
, idSet
, nameSpace
);
157 result
.put(nameSpace
, taxonMap
);
160 Reference
<?
> sourceReference
= getReferenceService().find(PesiTransformer
.uuidSourceRefIndexFungorum
);
161 Map
<String
, Reference
> referenceMap
= new HashMap
<String
, Reference
>();
162 referenceMap
.put(SOURCE_REFERENCE
, sourceReference
);
163 result
.put(NAMESPACE_REFERENCE
, referenceMap
);
165 } catch (SQLException e
) {
166 throw new RuntimeException(e
);
174 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
177 protected boolean doCheck(IndexFungorumImportState state
){
182 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
184 protected boolean isIgnore(IndexFungorumImportState state
){
185 return ! state
.getConfig().isDoTaxa();