Revision 786696e3
Added by Andreas Müller over 10 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/in/DwcTaxonStreamItem2CdmTaxonConverter.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.cdm.io.dwca.in; |
11 | 11 |
|
12 |
import java.net.URI; |
|
12 | 13 |
import java.util.ArrayList; |
13 | 14 |
import java.util.HashSet; |
14 | 15 |
import java.util.List; |
... | ... | |
27 | 28 |
import eu.etaxonomy.cdm.io.stream.StreamItem; |
28 | 29 |
import eu.etaxonomy.cdm.model.common.Annotation; |
29 | 30 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
31 |
import eu.etaxonomy.cdm.model.common.Extension; |
|
32 |
import eu.etaxonomy.cdm.model.common.ExtensionType; |
|
30 | 33 |
import eu.etaxonomy.cdm.model.common.IdentifiableSource; |
31 | 34 |
import eu.etaxonomy.cdm.model.common.LSID; |
32 | 35 |
import eu.etaxonomy.cdm.model.common.Language; |
... | ... | |
58 | 61 |
* |
59 | 62 |
*/ |
60 | 63 |
public class DwcTaxonStreamItem2CdmTaxonConverter<CONFIG extends DwcaDataImportConfiguratorBase, STATE extends StreamImportStateBase<CONFIG, StreamImportBase>> extends PartitionableConverterBase<CONFIG, STATE> implements IPartitionableConverter<StreamItem, IReader<CdmBase>, String>{ |
61 |
@SuppressWarnings("unused") |
|
62 |
private static Logger logger = Logger.getLogger(DwcTaxonStreamItem2CdmTaxonConverter.class); |
|
64 |
private static final Logger logger = Logger.getLogger(DwcTaxonStreamItem2CdmTaxonConverter.class); |
|
63 | 65 |
|
64 | 66 |
private static final String ID = "id"; |
65 | 67 |
// temporary key for the case that no dataset information is supplied, TODO use something better |
... | ... | |
104 | 106 |
|
105 | 107 |
//nameAccordingTo |
106 | 108 |
MappedCdmBase<Reference> sec = getNameAccordingTo(csvTaxonRecord, resultList); |
109 |
|
|
107 | 110 |
if (sec == null && state.getConfig().isUseSourceReferenceAsSec()){ |
108 | 111 |
sec = new MappedCdmBase<Reference>(state.getTransactionalSourceReference()); |
109 | 112 |
} |
... | ... | |
187 | 190 |
* @param taxonBase |
188 | 191 |
*/ |
189 | 192 |
private void handleIdentifiableObjects(StreamItem item,TaxonBase<?> taxonBase) { |
193 |
|
|
194 |
|
|
195 |
String references = item.get(TermUri.DC_REFERENCES); |
|
196 |
|
|
197 |
if (references == null || references == "") { |
|
198 |
references = item.get(TermUri.DWC_NAME_PUBLISHED_IN_ID);//lorna temporary until Scratchpads move the reference to the correct place. |
|
199 |
} |
|
200 |
|
|
201 |
if (StringUtils.isNotBlank(references)){ |
|
202 |
URI uri = makeUriIfIs(references); |
|
203 |
if (uri != null){ |
|
204 |
Extension.NewInstance(taxonBase, references, ExtensionType.URL()); |
|
205 |
}else{ |
|
206 |
String message = "Non-URI Dublin Core References not yet handled for taxa. References is: %s"; |
|
207 |
fireWarningEvent(String.format(message, references), item, 6); |
|
208 |
} |
|
209 |
} |
|
210 |
|
|
211 |
|
|
190 | 212 |
//TODO: Finish properly |
191 | 213 |
String id = item.get(TermUri.CDM_SOURCE_IDINSOURCE); |
192 | 214 |
String idNamespace = item.get(TermUri.CDM_SOURCE_IDNAMESPACE); |
... | ... | |
197 | 219 |
Taxon taxon = (Taxon) taxonBase; |
198 | 220 |
taxon.addSource(OriginalSourceType.Import, id, idNamespace, ref, null); |
199 | 221 |
} |
222 |
|
|
223 |
|
|
224 |
|
|
225 |
} |
|
226 |
|
|
227 |
|
|
228 |
/** |
|
229 |
* If str is an uri it returns is as an {@link URI}. If not it returns <code>null</code>. |
|
230 |
* @param str |
|
231 |
* @return the URI. |
|
232 |
*/ |
|
233 |
private URI makeUriIfIs(String str) { |
|
234 |
if (! str.startsWith("http:")){ |
|
235 |
return null; |
|
236 |
}else{ |
|
237 |
try { |
|
238 |
URI uri = URI.create(str); |
|
239 |
return uri; |
|
240 |
} catch (Exception e) { |
|
241 |
return null; |
|
242 |
} |
|
243 |
} |
|
244 |
|
|
200 | 245 |
} |
201 | 246 |
|
202 | 247 |
|
... | ... | |
226 | 271 |
private void handleTdwgArea(StreamItem item, TaxonBase<?> taxonBase) { |
227 | 272 |
// TODO Auto-generated method stub |
228 | 273 |
String tdwg_area = item.get(TermUri.DWC_COUNTRY_CODE); |
274 |
if (tdwg_area != null){ |
|
229 | 275 |
if(taxonBase instanceof Synonym){ |
230 | 276 |
Synonym synonym = CdmBase.deproxy(taxonBase, Synonym.class); |
231 | 277 |
Set<Taxon> acceptedTaxaList = synonym.getAcceptedTaxa(); |
... | ... | |
236 | 282 |
for(Taxon taxon : acceptedTaxaList){ |
237 | 283 |
TaxonDescription td = getTaxonDescription(taxon, false); |
238 | 284 |
NamedArea area = NamedArea.getAreaByTdwgAbbreviation(tdwg_area); |
239 |
|
|
285 |
|
|
240 | 286 |
if (area == null){ |
241 | 287 |
area = NamedArea.getAreaByTdwgLabel(tdwg_area); |
242 | 288 |
} |
... | ... | |
251 | 297 |
Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class); |
252 | 298 |
TaxonDescription td = getTaxonDescription(taxon, false); |
253 | 299 |
NamedArea area = NamedArea.getAreaByTdwgAbbreviation(tdwg_area); |
254 |
|
|
300 |
|
|
255 | 301 |
if (area == null){ |
256 | 302 |
area = NamedArea.getAreaByTdwgLabel(tdwg_area); |
257 | 303 |
} |
... | ... | |
261 | 307 |
} |
262 | 308 |
} |
263 | 309 |
} |
310 |
} |
|
264 | 311 |
|
265 | 312 |
|
266 | 313 |
/** |
... | ... | |
327 | 374 |
//if not exists, create new |
328 | 375 |
if (! classificationExists){ |
329 | 376 |
String classificationName = StringUtils.isBlank(datasetName)? datasetId : datasetName; |
330 |
if (classificationName.equals(NO_DATASET)){ |
|
331 |
classificationName = "Classification (no name)"; //TODO define by config or zipfile or metadata |
|
377 |
if (classificationName.equals(NO_DATASET)){ |
|
378 |
classificationName = config.getClassificationName(); |
|
379 |
//classificationName = "Classification (no name)"; //TODO define by config or zipfile or metadata |
|
332 | 380 |
} |
333 | 381 |
|
334 | 382 |
String classificationId = StringUtils.isBlank(datasetId)? datasetName : datasetId; |
... | ... | |
497 | 545 |
if (! idIsInternal){ |
498 | 546 |
//references should already exist in store if not linking to external links like URLs |
499 | 547 |
String message = "External namePublishedInIDs are not yet supported"; |
500 |
fireWarningEvent(message, item, 4); |
|
548 |
fireWarningEvent(message, item, 4);//set to DEBUG
|
|
501 | 549 |
}else{ |
502 | 550 |
newRef = ReferenceFactory.newGeneric(); //TODO handle other types if possible |
503 | 551 |
newRef.addSource(OriginalSourceType.Import, refId, idTerm.toString(), sourceCitation, null); |
Also available in: Unified diff
merge trunk into cdm3.3 branch