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
.erms
;
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
.IOValidator
;
23 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.DbIgnoreMapper
;
24 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.DbImportAnnotationMapper
;
25 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.DbImportDistributionCreationMapper
;
26 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.DbImportMapping
;
27 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.DbImportObjectMapper
;
28 import eu
.etaxonomy
.cdm
.io
.pesi
.erms
.validation
.ErmsDrImportValidator
;
29 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
30 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
31 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
32 import eu
.etaxonomy
.cdm
.model
.description
.PresenceTerm
;
33 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
34 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
44 public class ErmsDrImport
extends ErmsImportBase
<Distribution
> {
45 @SuppressWarnings("unused")
46 private static final Logger logger
= Logger
.getLogger(ErmsDrImport
.class);
48 private DbImportMapping mapping
;
50 private int modCount
= 10000;
51 private static final String pluralString
= "distributions";
52 private static final String dbTableName
= "dr";
53 private static final Class cdmTargetClass
= Distribution
.class;
55 public ErmsDrImport(){
56 super(pluralString
, dbTableName
, cdmTargetClass
);
61 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getRecordQuery(eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator)
64 protected String
getRecordQuery(ErmsImportConfigurator config
) {
65 String strRecordQuery
=
66 " SELECT dr.*, tu.tu_acctaxon, tu.id " +
67 " FROM dr INNER JOIN tu ON dr.tu_id = tu.id " +
68 " WHERE ( dr.id IN (" + ID_LIST_TOKEN
+ ") )";
69 return strRecordQuery
;
73 * @see eu.etaxonomy.cdm.io.erms.ErmsImportBase#getMapping()
75 protected DbImportMapping
getMapping() {
77 mapping
= new DbImportMapping();
79 PresenceTerm status
= PresenceTerm
.PRESENT();
80 DbImportDistributionCreationMapper
<?
> distributionMapper
= DbImportDistributionCreationMapper
.NewFixedStatusInstance("id", DR_NAMESPACE
, "tu_acctaxon", ErmsTaxonImport
.TAXON_NAMESPACE
, status
);
81 distributionMapper
.setSource("source_id", REFERENCE_NAMESPACE
, null);
82 mapping
.addMapper(distributionMapper
);
84 mapping
.addMapper(DbImportObjectMapper
.NewInstance("gu_id", "area", ErmsAreaImport
.AREA_NAMESPACE
));
85 mapping
.addMapper(DbImportAnnotationMapper
.NewInstance("note", AnnotationType
.EDITORIAL()));
87 mapping
.addMapper(DbIgnoreMapper
.NewInstance("unacceptsource_id"));
88 mapping
.addMapper(DbIgnoreMapper
.NewInstance("unacceptreason"));
89 mapping
.addMapper(DbIgnoreMapper
.NewInstance("valid_flag"));
90 mapping
.addMapper(DbIgnoreMapper
.NewInstance("certain_flag"));
91 mapping
.addMapper(DbIgnoreMapper
.NewInstance("map_flag"));
92 mapping
.addMapper(DbIgnoreMapper
.NewInstance("endemic_flag"));
93 mapping
.addMapper(DbIgnoreMapper
.NewInstance("exotic_flag"));
94 mapping
.addMapper(DbIgnoreMapper
.NewInstance("typelocality_flag"));
95 mapping
.addMapper(DbIgnoreMapper
.NewInstance("specimenflag"));
96 mapping
.addMapper(DbIgnoreMapper
.NewInstance("lat"));
97 mapping
.addMapper(DbIgnoreMapper
.NewInstance("long"));
98 mapping
.addMapper(DbIgnoreMapper
.NewInstance("depthshallow"));
99 mapping
.addMapper(DbIgnoreMapper
.NewInstance("depthdeep"));
100 mapping
.addMapper(DbIgnoreMapper
.NewInstance("beginyear"));
101 mapping
.addMapper(DbIgnoreMapper
.NewInstance("beginmonth"));
102 mapping
.addMapper(DbIgnoreMapper
.NewInstance("beginday"));
103 mapping
.addMapper(DbIgnoreMapper
.NewInstance("endyear"));
104 mapping
.addMapper(DbIgnoreMapper
.NewInstance("endmonth"));
105 mapping
.addMapper(DbIgnoreMapper
.NewInstance("endday"));
106 mapping
.addMapper(DbIgnoreMapper
.NewInstance("min_abundance"));
107 mapping
.addMapper(DbIgnoreMapper
.NewInstance("max_abundance"));
115 * @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet)
117 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
) {
121 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<Object
, Map
<String
, ?
extends CdmBase
>>();
124 Set
<String
> taxonIdSet
= new HashSet
<String
>();
125 Set
<String
> areaIdSet
= new HashSet
<String
>();
126 Set
<String
> sourceIdSet
= new HashSet
<String
>();
128 handleForeignKey(rs
, taxonIdSet
,"tu_acctaxon" );
129 handleForeignKey(rs
, areaIdSet
, "gu_id");
130 handleForeignKey(rs
, sourceIdSet
, "source_id");
134 nameSpace
= ErmsTaxonImport
.TAXON_NAMESPACE
;
135 cdmClass
= TaxonBase
.class;
137 Map
<String
, TaxonBase
> taxonMap
= (Map
<String
, TaxonBase
>)getCommonService().getSourcedObjectsByIdInSource(cdmClass
, idSet
, nameSpace
);
138 result
.put(nameSpace
, taxonMap
);
141 nameSpace
= ErmsAreaImport
.AREA_NAMESPACE
;
142 cdmClass
= NamedArea
.class;
144 Map
<String
, NamedArea
> areaMap
= (Map
<String
, NamedArea
>)getCommonService().getSourcedObjectsByIdInSource(cdmClass
, idSet
, nameSpace
);
145 result
.put(nameSpace
, areaMap
);
148 nameSpace
= ErmsReferenceImport
.REFERENCE_NAMESPACE
;
149 cdmClass
= Reference
.class;
151 Map
<String
, Reference
> referenceMap
= (Map
<String
, Reference
>)getCommonService().getSourcedObjectsByIdInSource(cdmClass
, idSet
, nameSpace
);
152 result
.put(nameSpace
, referenceMap
);
155 } catch (SQLException e
) {
156 throw new RuntimeException(e
);
162 * @param distribution
166 private void addSource(Distribution distribution
, Integer source_id
, ErmsImportState state
) {
167 Reference ref
= (Reference
)state
.getRelatedObject(ErmsReferenceImport
.REFERENCE_NAMESPACE
, String
.valueOf(source_id
));
168 distribution
.addSource(null, null, ref
, null);
172 * @see eu.etaxonomy.cdm.io.common.mapping.IMappingImport#createObject(java.sql.ResultSet, eu.etaxonomy.cdm.io.common.ImportStateBase)
174 public Distribution
createObject(ResultSet rs
, ErmsImportState state
)
175 throws SQLException
{
176 return null; //not needed
181 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
184 protected boolean doCheck(ErmsImportState state
){
185 IOValidator
<ErmsImportState
> validator
= new ErmsDrImportValidator();
186 return validator
.validate(state
);
190 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
192 protected boolean isIgnore(ErmsImportState state
){
193 return ! state
.getConfig().isDoOccurrence();