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.
9 package eu
.etaxonomy
.cdm
.io
.mexico
;
11 import java
.sql
.ResultSet
;
12 import java
.sql
.SQLException
;
15 import org
.apache
.log4j
.Logger
;
17 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
18 import eu
.etaxonomy
.cdm
.io
.berlinModel
.in
.BerlinModelImportState
;
19 import eu
.etaxonomy
.cdm
.io
.common
.DbImportBase
;
20 import eu
.etaxonomy
.cdm
.io
.common
.ICdmIO
;
21 import eu
.etaxonomy
.cdm
.io
.common
.IPartitionedIO
;
22 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
23 import eu
.etaxonomy
.cdm
.model
.reference
.ISourceable
;
24 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
32 public abstract class MexicoEfloraImportBase
33 extends DbImportBase
<MexicoEfloraImportState
, MexicoEfloraImportConfigurator
>
34 implements ICdmIO
<MexicoEfloraImportState
>, IPartitionedIO
<MexicoEfloraImportState
> {
36 private static final long serialVersionUID
= -5229728676004248450L;
37 private static final Logger logger
= Logger
.getLogger(MexicoEfloraImportBase
.class);
39 public MexicoEfloraImportBase(String tableName
, String pluralString
) {
40 super(tableName
, pluralString
);
44 protected String
getIdQuery(MexicoEfloraImportState state
){
45 String result
= " SELECT " + getTableName() + "id FROM " + getTableName();
50 protected String
getIdInSource(MexicoEfloraImportState state
, ResultSet rs
) throws SQLException
{
55 protected Taxon
getTaxon(BerlinModelImportState state
, int taxonId
, Map
<String
, TaxonBase
> taxonMap
, int factId
) {
56 TaxonBase
<?
> taxonBase
= taxonMap
.get(String
.valueOf(taxonId
));
59 // if (taxonBase == null && ! state.getConfig().isDoTaxa()){
60 // taxonBase = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
64 if ( taxonBase
instanceof Taxon
) {
65 taxon
= (Taxon
) taxonBase
;
66 } else if (taxonBase
!= null) {
67 logger
.warn("TaxonBase (" + taxonId
+ ") for Fact(Specimen) with factId " + factId
+ " was not of type Taxon but: " + taxonBase
.getClass().getSimpleName());
70 logger
.warn("TaxonBase (" + taxonId
+ ") for Fact(Specimen) with factId " + factId
+ " is null.");
78 * Searches first in the detail maps then in the ref maps for a reference.
79 * Returns the reference as soon as it finds it in one of the map, according
80 * to the order of the map.
81 * If nomRefDetailFk is <code>null</code> no search on detail maps is performed.
82 * If one of the maps is <code>null</code> no search on the according map is
84 * You may define the order of search by the order you pass the maps but
85 * make sure to always pass the detail maps first.
86 * @param firstDetailMap
87 * @param secondDetailMap
90 * @param nomRefDetailFk
94 protected Reference
getReferenceFromMaps(
95 Map
<String
, Reference
> detailMap
,
96 Map
<String
, Reference
> refMap
,
97 String nomRefDetailFk
,
100 if (detailMap
!= null){
101 ref
= detailMap
.get(nomRefDetailFk
);
104 ref
= refMap
.get(nomRefFk
);
109 protected Reference
getSourceReference(Reference sourceReference
) {
110 Reference persistentSourceReference
= getReferenceService().find(sourceReference
.getUuid()); //just to be sure
111 if (persistentSourceReference
!= null){
112 sourceReference
= persistentSourceReference
;
114 return sourceReference
;
117 protected static <T
extends IdentifiableSource
> boolean importSourceExists(ISourceable
<T
> sourceable
, String idInSource
,
118 String namespace
, Reference ref
) {
119 for (T source
: sourceable
.getSources()){
120 if (CdmUtils
.nullSafeEqual(namespace
, source
.getIdNamespace()) &&
121 CdmUtils
.nullSafeEqual(idInSource
, source
.getIdInSource()) &&
122 CdmUtils
.nullSafeEqual(ref
, source
.getCitation())){