Revision 8422c0cd
Added by Andreas Müller almost 8 years ago
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/erms/ErmsDrImport.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
44 | 44 |
public class ErmsDrImport extends ErmsImportBase<Distribution> { |
45 | 45 |
@SuppressWarnings("unused") |
46 | 46 |
private static final Logger logger = Logger.getLogger(ErmsDrImport.class); |
47 |
|
|
47 |
|
|
48 | 48 |
private DbImportMapping<ErmsImportState, ErmsImportConfigurator> mapping; |
49 |
|
|
49 |
|
|
50 | 50 |
private static final String pluralString = "distributions"; |
51 | 51 |
private static final String dbTableName = "dr"; |
52 | 52 |
private static final Class<?> cdmTargetClass = Distribution.class; |
... | ... | |
57 | 57 |
|
58 | 58 |
@Override |
59 | 59 |
protected String getRecordQuery(ErmsImportConfigurator config) { |
60 |
String strRecordQuery =
|
|
61 |
" SELECT dr.*, tu.tu_acctaxon, tu.id " +
|
|
60 |
String strRecordQuery = |
|
61 |
" SELECT dr.*, tu.tu_acctaxon, tu.id " + |
|
62 | 62 |
" FROM dr INNER JOIN tu ON dr.tu_id = tu.id " + |
63 | 63 |
" WHERE ( dr.id IN (" + ID_LIST_TOKEN + ") )"; |
64 | 64 |
return strRecordQuery; |
... | ... | |
69 | 69 |
protected DbImportMapping<ErmsImportState, ErmsImportConfigurator> getMapping() { |
70 | 70 |
if (mapping == null){ |
71 | 71 |
mapping = new DbImportMapping<ErmsImportState, ErmsImportConfigurator>(); |
72 |
|
|
72 |
|
|
73 | 73 |
PresenceAbsenceTerm status = PresenceAbsenceTerm.PRESENT(); |
74 | 74 |
DbImportDistributionCreationMapper<?> distributionMapper = DbImportDistributionCreationMapper.NewFixedStatusInstance("id", DR_NAMESPACE, "tu_acctaxon", ErmsTaxonImport.TAXON_NAMESPACE, status); |
75 | 75 |
distributionMapper.setSource("source_id", REFERENCE_NAMESPACE, null); |
76 | 76 |
mapping.addMapper(distributionMapper); |
77 |
|
|
77 |
|
|
78 | 78 |
mapping.addMapper(DbImportObjectMapper.NewInstance("gu_id", "area", ErmsAreaImport.AREA_NAMESPACE)); |
79 | 79 |
mapping.addMapper(DbImportAnnotationMapper.NewInstance("note", AnnotationType.EDITORIAL())); |
80 |
|
|
80 |
|
|
81 | 81 |
mapping.addMapper(DbIgnoreMapper.NewInstance("unacceptsource_id")); |
82 | 82 |
mapping.addMapper(DbIgnoreMapper.NewInstance("unacceptreason")); |
83 | 83 |
mapping.addMapper(DbIgnoreMapper.NewInstance("valid_flag")); |
... | ... | |
100 | 100 |
mapping.addMapper(DbIgnoreMapper.NewInstance("min_abundance")); |
101 | 101 |
mapping.addMapper(DbIgnoreMapper.NewInstance("max_abundance")); |
102 | 102 |
|
103 |
|
|
103 |
|
|
104 | 104 |
} |
105 | 105 |
return mapping; |
106 | 106 |
} |
107 |
|
|
107 |
|
|
108 | 108 |
|
109 | 109 |
@Override |
110 | 110 |
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, ErmsImportState state) { |
... | ... | |
112 | 112 |
Class<?> cdmClass; |
113 | 113 |
Set<String> idSet; |
114 | 114 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>(); |
115 |
|
|
115 |
|
|
116 | 116 |
try{ |
117 | 117 |
Set<String> taxonIdSet = new HashSet<String>(); |
118 | 118 |
Set<String> areaIdSet = new HashSet<String>(); |
... | ... | |
122 | 122 |
handleForeignKey(rs, areaIdSet, "gu_id"); |
123 | 123 |
handleForeignKey(rs, sourceIdSet, "source_id"); |
124 | 124 |
} |
125 |
|
|
125 |
|
|
126 | 126 |
//taxon map |
127 | 127 |
nameSpace = ErmsTaxonImport.TAXON_NAMESPACE; |
128 | 128 |
cdmClass = TaxonBase.class; |
129 | 129 |
idSet = taxonIdSet; |
130 | 130 |
Map<String, TaxonBase<?>> taxonMap = (Map<String, TaxonBase<?>>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
131 | 131 |
result.put(nameSpace, taxonMap); |
132 |
|
|
132 |
|
|
133 | 133 |
//areas |
134 | 134 |
nameSpace = ErmsAreaImport.AREA_NAMESPACE; |
135 | 135 |
cdmClass = NamedArea.class; |
136 | 136 |
idSet = areaIdSet; |
137 | 137 |
Map<String, NamedArea> areaMap = (Map<String, NamedArea>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
138 | 138 |
result.put(nameSpace, areaMap); |
139 |
|
|
139 |
|
|
140 | 140 |
//reference map |
141 | 141 |
nameSpace = ErmsReferenceImport.REFERENCE_NAMESPACE; |
142 | 142 |
cdmClass = Reference.class; |
143 | 143 |
idSet = sourceIdSet; |
144 |
Map<String, Reference<?>> referenceMap = (Map<String, Reference<?>>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
|
144 |
Map<String, Reference> referenceMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
|
145 | 145 |
result.put(nameSpace, referenceMap); |
146 | 146 |
|
147 |
|
|
147 |
|
|
148 | 148 |
} catch (SQLException e) { |
149 | 149 |
throw new RuntimeException(e); |
150 | 150 |
} |
151 | 151 |
return result; |
152 | 152 |
} |
153 |
|
|
153 |
|
|
154 | 154 |
/** |
155 | 155 |
* @param distribution |
156 | 156 |
* @param source_id |
157 |
* @param state
|
|
157 |
* @param state |
|
158 | 158 |
*/ |
159 | 159 |
private void addSource(Distribution distribution, Integer source_id, ErmsImportState state) { |
160 |
Reference<?> ref = (Reference)state.getRelatedObject(ErmsReferenceImport.REFERENCE_NAMESPACE, String.valueOf(source_id));
|
|
160 |
Reference ref = (Reference)state.getRelatedObject(ErmsReferenceImport.REFERENCE_NAMESPACE, String.valueOf(source_id)); |
|
161 | 161 |
distribution.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, ref, null); |
162 | 162 |
} |
163 | 163 |
|
... | ... | |
178 | 178 |
IOValidator<ErmsImportState> validator = new ErmsDrImportValidator(); |
179 | 179 |
return validator.validate(state); |
180 | 180 |
} |
181 |
|
|
181 |
|
|
182 | 182 |
/* (non-Javadoc) |
183 | 183 |
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator) |
184 | 184 |
*/ |
185 |
protected boolean isIgnore(ErmsImportState state){ |
|
185 |
@Override |
|
186 |
protected boolean isIgnore(ErmsImportState state){ |
|
186 | 187 |
return ! state.getConfig().isDoOccurrence(); |
187 | 188 |
} |
188 | 189 |
|
Also available in: Unified diff
Remove generics from Reference in cdmlib-app #5830