Revision 0684e761
Added by Andreas Müller almost 12 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/in/DwcTaxonCsv2CdmTaxonConverter.java | ||
---|---|---|
185 | 185 |
|
186 | 186 |
|
187 | 187 |
private void handleDataset(CsvStreamItem item, TaxonBase<?> taxonBase, List<MappedCdmBase> resultList, Reference<?> sourceReference, String sourceReferecenDetail) { |
188 |
TermUri idTerm = TermUri.DWC_DATASET_ID; |
|
189 |
TermUri strTerm = TermUri.DWC_DATASET_NAME; |
|
190 |
|
|
188 | 191 |
if (config.isDatasetsAsClassifications()){ |
189 |
String datasetId = CdmUtils.Nz(item.get(TermUri.DWC_DATASET_ID)).trim();
|
|
190 |
String datasetName = CdmUtils.Nz(item.get(TermUri.DWC_DATASET_NAME)).trim();
|
|
191 |
if (CdmUtils.areBlank(datasetId, datasetName) ){ |
|
192 |
String datasetId = CdmUtils.Nz(item.get(idTerm)).trim();
|
|
193 |
String datasetName = CdmUtils.Nz(item.get(strTerm)).trim();
|
|
194 |
if (CdmUtils.areBlank(datasetId, datasetName) ){
|
|
192 | 195 |
datasetId = NO_DATASET; |
193 | 196 |
} |
194 | 197 |
|
195 | 198 |
//check id |
196 |
boolean classificationExists = state.exists(TermUri.DWC_DATASET_ID.toString() , datasetId, Classification.class);
|
|
199 |
boolean classificationExists = state.exists(idTerm.toString() , datasetId, Classification.class);
|
|
197 | 200 |
|
198 | 201 |
//check name |
199 | 202 |
if (!classificationExists){ |
200 |
classificationExists = state.exists(TermUri.DWC_DATASET_NAME.toString() , datasetName, Classification.class);
|
|
203 |
classificationExists = state.exists(strTerm.toString() , datasetName, Classification.class);
|
|
201 | 204 |
} |
202 | 205 |
|
203 | 206 |
//if not exists, create new |
... | ... | |
212 | 215 |
//source |
213 | 216 |
IdentifiableSource source = classification.addSource(classificationId, "Dataset", sourceReference, sourceReferecenDetail); |
214 | 217 |
//add to result |
215 |
resultList.add(new MappedCdmBase(TermUri.DWC_DATASET_ID, datasetId, classification));
|
|
216 |
resultList.add(new MappedCdmBase(TermUri.DWC_DATASET_NAME, datasetName, classification));
|
|
218 |
resultList.add(new MappedCdmBase(idTerm, datasetId, classification));
|
|
219 |
resultList.add(new MappedCdmBase(strTerm, datasetName, classification));
|
|
217 | 220 |
resultList.add(new MappedCdmBase(source)); |
218 | 221 |
//TODO this is not so nice but currently necessary as classifications are requested in the same partition |
219 |
state.putMapping(TermUri.DWC_DATASET_ID.toString(), classificationId, classification);
|
|
220 |
state.putMapping(TermUri.DWC_DATASET_NAME.toString(), classificationName, classification);
|
|
222 |
state.putMapping(idTerm.toString(), classificationId, classification);
|
|
223 |
state.putMapping(strTerm.toString(), classificationName, classification);
|
|
221 | 224 |
} |
222 |
}else if (config.isDatasetsAsSecundumReference()){ |
|
223 |
//dataset as secundum reference |
|
224 |
TermUri idTerm = TermUri.DWC_DATASET_ID; |
|
225 |
TermUri strTerm = TermUri.DWC_DATASET_NAME; |
|
226 |
MappedCdmBase<Reference> mappedCitation = getReference(item, resultList, idTerm, strTerm, true); |
|
227 |
Reference<?> sec = mappedCitation.getCdmBase(); |
|
228 |
taxonBase.setSec(sec); |
|
229 |
|
|
230 |
}else if (config.isDatasetsAsOriginalSource()){ |
|
231 |
//dataset as original source |
|
232 |
TermUri idTerm = TermUri.DWC_DATASET_ID; |
|
233 |
TermUri strTerm = TermUri.DWC_DATASET_NAME; |
|
225 |
}else if (config.isDatasetsAsSecundumReference() || config.isDatasetsAsOriginalSource()){ |
|
234 | 226 |
MappedCdmBase<Reference> mappedCitation = getReference(item, resultList, idTerm, strTerm, true); |
235 |
// resultList.add(mappedCitation); |
|
236 |
taxonBase.addSource(null, null, mappedCitation.getCdmBase(), null); |
|
227 |
if (mappedCitation != null){ |
|
228 |
Reference<?> ref = mappedCitation.getCdmBase(); |
|
229 |
if (config.isDatasetsAsSecundumReference()){ |
|
230 |
//dataset as secundum reference |
|
231 |
taxonBase.setSec(ref); |
|
232 |
}else{ |
|
233 |
//dataset as original source |
|
234 |
taxonBase.addSource(null, null, ref, null); |
|
235 |
} |
|
236 |
} |
|
237 | 237 |
}else{ |
238 | 238 |
String message = "DatasetUse type not yet implemented. Can't import dataset information."; |
239 | 239 |
fireWarningEvent(message, item, 4); |
240 | 240 |
} |
241 | 241 |
|
242 | 242 |
//remove to later check if all attributes were used |
243 |
item.remove(TermUri.DWC_DATASET_ID);
|
|
244 |
item.remove(TermUri.DWC_DATASET_NAME);
|
|
243 |
item.remove(idTerm);
|
|
244 |
item.remove(strTerm);
|
|
245 | 245 |
|
246 | 246 |
} |
247 | 247 |
|
Also available in: Unified diff
Some bugfixes for the DwcA import