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
.erms
.ErmsTransformer
;
26 import eu
.etaxonomy
.cdm
.io
.pesi
.out
.PesiTransformer
;
27 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
28 import eu
.etaxonomy
.cdm
.model
.common
.Extension
;
29 import eu
.etaxonomy
.cdm
.model
.common
.ExtensionType
;
30 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
31 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
32 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
33 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
34 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
37 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
38 import eu
.etaxonomy
.cdm
.strategy
.parser
.NonViralNameParserImpl
;
46 public class IndexFungorumSpeciesImport
extends IndexFungorumImportBase
{
47 private static final Logger logger
= Logger
.getLogger(IndexFungorumSpeciesImport
.class);
49 private static final String pluralString
= "species";
50 private static final String dbTableName
= "[tblPESIfungi-IFdata]";
52 public IndexFungorumSpeciesImport(){
53 super(pluralString
, dbTableName
, null);
60 protected String
getIdQuery() {
61 String result
= " SELECT RECORD_NUMBER FROM " + getTableName() +
62 " ORDER BY PreferredName ";
70 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getRecordQuery(eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator)
73 protected String
getRecordQuery(IndexFungorumImportConfigurator config
) {
74 String strRecordQuery
=
75 " SELECT DISTINCT distribution.PreferredNameFDCnumber, species.* , cl.PhylumName" +
76 " FROM tblPESIfungi AS distribution RIGHT OUTER JOIN dbo.[tblPESIfungi-IFdata] AS species ON distribution.PreferredNameIFnumber = species.RECORD_NUMBER " +
77 " LEFT OUTER JOIN [tblPESIfungi-Classification] cl ON species.PreferredName = cl.PreferredName " +
78 " WHERE ( species.RECORD_NUMBER IN (" + ID_LIST_TOKEN
+ ") )" +
80 return strRecordQuery
;
85 public boolean doPartition(ResultSetPartitioner partitioner
, IndexFungorumImportState state
) {
86 boolean success
= true;
87 Reference
<?
> sourceReference
= state
.getRelatedObject(NAMESPACE_REFERENCE
, SOURCE_REFERENCE
, Reference
.class);
88 ResultSet rs
= partitioner
.getResultSet();
90 Classification classification
= getClassification(state
);
94 //DisplayName, NomRefCache -> don't use, created by Marc
96 Integer id
= (Integer
)rs
.getObject("RECORD_NUMBER");
97 String phylumName
= rs
.getString("PhylumName");
99 String preferredName
= rs
.getString("PreferredName");
100 if (StringUtils
.isBlank(preferredName
)){
101 logger
.warn("Preferred name is blank. This case is not yet handled by IF import. RECORD_NUMBER" + CdmUtils
.Nz(id
));
104 Rank rank
= Rank
.SPECIES();
106 NonViralNameParserImpl parser
= NonViralNameParserImpl
.NewInstance();
107 NonViralName
<?
> name
= parser
.parseSimpleName(preferredName
, NomenclaturalCode
.ICBN
, rank
);
109 Taxon taxon
= Taxon
.NewInstance(name
, sourceReference
);
110 Taxon parent
= getParentTaxon(state
, rs
);
111 classification
.addParentChild(parent
, taxon
, null, null);
113 //author + publication
114 makeAuthorAndPublication(state
, rs
, name
);
116 makeSource(state
, taxon
, id
, NAMESPACE_SPECIES
);
119 if (FOSSIL_FUNGI
.equalsIgnoreCase(phylumName
)){
120 ExtensionType fossilExtType
= getExtensionType(state
, ErmsTransformer
.uuidFossilStatus
, "fossil status", "fossil status", "fos. stat.");
121 Extension
.NewInstance(taxon
, PesiTransformer
.STR_FOSSIL_ONLY
, fossilExtType
);
124 getTaxonService().saveOrUpdate(taxon
);
128 } catch (Exception e
) {
130 logger
.error(e
.getMessage());
131 state
.setSuccess(false);
138 private Taxon
getParentTaxon(IndexFungorumImportState state
, ResultSet rs
) throws SQLException
{
139 Integer genusId
= rs
.getInt("PreferredNameFDCnumber");
141 Taxon taxon
= state
.getRelatedObject(NAMESPACE_GENERA
, String
.valueOf(genusId
), Taxon
.class);
143 logger
.warn("Taxon not found for " + genusId
);
149 * @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet)
151 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
) {
155 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<Object
, Map
<String
, ?
extends CdmBase
>>();
158 Set
<String
> taxonIdSet
= new HashSet
<String
>();
160 handleForeignKey(rs
, taxonIdSet
,"PreferredNameFDCnumber" );
164 nameSpace
= NAMESPACE_GENERA
;
165 cdmClass
= TaxonBase
.class;
167 Map
<String
, TaxonBase
> taxonMap
= (Map
<String
, TaxonBase
>)getCommonService().getSourcedObjectsByIdInSource(cdmClass
, idSet
, nameSpace
);
168 result
.put(nameSpace
, taxonMap
);
171 Reference
<?
> sourceReference
= getReferenceService().find(PesiTransformer
.uuidSourceRefIndexFungorum
);
172 Map
<String
, Reference
> referenceMap
= new HashMap
<String
, Reference
>();
173 referenceMap
.put(SOURCE_REFERENCE
, sourceReference
);
174 result
.put(NAMESPACE_REFERENCE
, referenceMap
);
176 } catch (SQLException e
) {
177 throw new RuntimeException(e
);
185 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
188 protected boolean doCheck(IndexFungorumImportState state
){
193 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
195 protected boolean isIgnore(IndexFungorumImportState state
){
196 return ! state
.getConfig().isDoTaxa();