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
.specimen
.abcd206
.in
;
12 import java
.io
.IOException
;
13 import java
.io
.InputStream
;
15 import java
.util
.ArrayList
;
16 import java
.util
.HashMap
;
17 import java
.util
.Iterator
;
18 import java
.util
.List
;
20 import java
.util
.UUID
;
22 import javax
.xml
.parsers
.DocumentBuilder
;
23 import javax
.xml
.parsers
.DocumentBuilderFactory
;
24 import javax
.xml
.parsers
.ParserConfigurationException
;
26 import org
.apache
.log4j
.Logger
;
27 import org
.springframework
.stereotype
.Component
;
28 import org
.springframework
.transaction
.TransactionStatus
;
29 import org
.w3c
.dom
.Document
;
30 import org
.w3c
.dom
.Element
;
31 import org
.w3c
.dom
.Node
;
32 import org
.w3c
.dom
.NodeList
;
33 import org
.xml
.sax
.SAXException
;
35 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
36 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
.DerivedUnitType
;
37 import eu
.etaxonomy
.cdm
.common
.mediaMetaData
.ImageMetaData
;
38 import eu
.etaxonomy
.cdm
.io
.common
.ICdmIO
;
39 import eu
.etaxonomy
.cdm
.io
.specimen
.SpecimenIoBase
;
40 import eu
.etaxonomy
.cdm
.io
.specimen
.UnitsGatheringArea
;
41 import eu
.etaxonomy
.cdm
.io
.specimen
.UnitsGatheringEvent
;
42 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
43 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
44 import eu
.etaxonomy
.cdm
.model
.common
.DescriptionElementSource
;
45 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
46 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
47 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
48 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
49 import eu
.etaxonomy
.cdm
.model
.media
.ImageFile
;
50 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
51 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
52 import eu
.etaxonomy
.cdm
.model
.name
.BacterialName
;
53 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
54 import eu
.etaxonomy
.cdm
.model
.name
.CultivarPlantName
;
55 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
56 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
57 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
58 import eu
.etaxonomy
.cdm
.model
.name
.ZoologicalName
;
59 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
60 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
61 import eu
.etaxonomy
.cdm
.model
.occurrence
.GatheringEvent
;
62 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
63 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
64 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
65 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
66 import eu
.etaxonomy
.cdm
.strategy
.parser
.NonViralNameParserImpl
;
75 public class Abcd206Import
extends SpecimenIoBase
<Abcd206ImportConfigurator
, Abcd206ImportState
> implements ICdmIO
<Abcd206ImportState
> {
76 private static final Logger logger
= Logger
.getLogger(Abcd206Import
.class);
79 public Abcd206Import() {
85 protected boolean doCheck(Abcd206ImportState state
) {
86 logger
.warn("Checking not yet implemented for " + this.getClass().getSimpleName());
92 public boolean doInvoke(Abcd206ImportState state
){
93 logger
.info("INVOKE Specimen Import from ABCD2.06 XML File");
94 boolean result
= true;
95 //AbcdIO test = new AbcdIO();
96 String sourceName
= state
.getConfig().getSource();
97 NodeList unitsList
= getUnitsNodeList(sourceName
);
98 if (unitsList
!= null){
99 String message
= "nb units to insert: "+unitsList
.getLength();
100 logger
.info(message
);
101 updateProgress(state
, message
);
103 Abcd206DataHolder dataHolder
= new Abcd206DataHolder();
105 for (int i
=0 ; i
<unitsList
.getLength() ; i
++){
106 this.setUnitPropertiesXML((Element
)unitsList
.item(i
), dataHolder
);
107 result
&= this.handleSingleUnit(state
, dataHolder
);
109 //compare the ABCD elements added in to the CDM and the unhandled ABCD elements
110 compareABCDtoCDM(sourceName
, dataHolder
.knownABCDelements
, dataHolder
);
112 //reset the ABCD elements added in CDM
113 //knownABCDelements = new ArrayList<String>();
114 dataHolder
.allABCDelements
= new HashMap
<String
,String
>();
123 * Store the unit with its Gathering informations in the CDM
125 private boolean handleSingleUnit(Abcd206ImportState state
, Abcd206DataHolder dataHolder
){
126 boolean result
= true;
128 Abcd206ImportConfigurator config
= state
.getConfig();
130 TransactionStatus tx
= startTransaction();
132 updateProgress(state
, "Importing data for unit: " + dataHolder
.unitID
);
134 // ReferenceBase sec = Database.NewInstance();
135 // sec.setTitleCache("XML DATA");
136 ReferenceBase sec
= config
.getTaxonReference();
139 DerivedUnitFacade derivedUnitFacade
= getFacade(dataHolder
);
142 //handle identifications
143 handleIdentifications(config
, derivedUnitFacade
, sec
, dataHolder
);
145 //handle collection data
146 setCollectionData(config
, dataHolder
, derivedUnitFacade
);
153 UnitsGatheringEvent unitsGatheringEvent
= new UnitsGatheringEvent(
154 getTermService(), dataHolder
.locality
, dataHolder
.languageIso
, dataHolder
.longitude
,
155 dataHolder
.latitude
, dataHolder
.gatheringAgentList
);
158 UnitsGatheringArea unitsGatheringArea
=
159 new UnitsGatheringArea(dataHolder
.isocountry
, dataHolder
.country
, getOccurrenceService());
160 NamedArea areaCountry
= unitsGatheringArea
.getArea();
163 unitsGatheringArea
= new UnitsGatheringArea(dataHolder
.namedAreaList
);
164 ArrayList
<NamedArea
> nas
= unitsGatheringArea
.getAreas();
165 for (NamedArea namedArea
: nas
){
166 unitsGatheringEvent
.addArea(namedArea
);
169 //copy gathering event to facade
170 GatheringEvent gatheringEvent
= unitsGatheringEvent
.getGatheringEvent();
171 derivedUnitFacade
.setLocality(gatheringEvent
.getLocality());
172 derivedUnitFacade
.setExactLocation(gatheringEvent
.getExactLocation());
173 derivedUnitFacade
.setCollector(gatheringEvent
.getCollector());
174 derivedUnitFacade
.setCountry(areaCountry
);
175 derivedUnitFacade
.addCollectingAreas(unitsGatheringArea
.getAreas());
181 derivedUnitFacade
.setFieldNumber(dataHolder
.fieldNumber
);
183 //join gatheringEvent to fieldObservation
185 // //add Multimedia URLs
186 if(dataHolder
.multimediaObjects
.size() > 0){
187 MediaRepresentation representation
;
192 for (String multimediaObject
: dataHolder
.multimediaObjects
){
193 if( multimediaObject
!= null){
194 imd
= ImageMetaData
.newInstance();
195 url
= new URL(multimediaObject
);
197 imd
.readMetaData(url
.toURI(), 0);
198 } catch (Exception e
) {
199 String message
= "An error occurred when trying to read image meta data: " + e
.getMessage();
200 logger
.warn(message
);
202 //TODO do we really want to check the url?
204 imf
= ImageFile
.NewInstance(multimediaObject
, null, imd
);
205 representation
= MediaRepresentation
.NewInstance();
206 representation
.addRepresentationPart(imf
);
207 media
= Media
.NewInstance();
208 media
.addRepresentation(representation
);
210 derivedUnitFacade
.addFieldObjectMedia(media
);
217 * SAVE AND STORE DATA
219 getTermService().save(areaCountry
);//TODO save area sooner
220 for (NamedArea area
: nas
){
221 getTermService().save(area
);//save it sooner (foreach area)
223 getTermService().saveLanguageData(unitsGatheringEvent
.getLocality());//TODO needs to be saved ?? save it sooner
225 getOccurrenceService().save(derivedUnitFacade
.getDerivedUnit());
226 logger
.info("saved ABCD specimen ...");
229 } catch (Exception e
) {
230 logger
.warn("Error when reading record!!");
234 commitTransaction(tx
);
240 private void setCollectionData(Abcd206ImportConfigurator config
,
241 Abcd206DataHolder dataHolder
, DerivedUnitFacade derivedUnitFacade
) {
242 //set catalogue number (unitID)
243 derivedUnitFacade
.setCatalogNumber(dataHolder
.unitID
);
244 derivedUnitFacade
.setAccessionNumber(dataHolder
.accessionNumber
);
245 derivedUnitFacade
.setCollectorsNumber(dataHolder
.collectorsNumber
);
249 * INSTITUTION & COLLECTION
252 Institution institution
= this.getInstitution(dataHolder
.institutionCode
, config
, dataHolder
);
254 Collection collection
= this.getCollection(dataHolder
.collectionCode
, institution
, config
, dataHolder
);
255 //link specimen & collection
256 derivedUnitFacade
.setCollection(collection
);
260 private DerivedUnitFacade
getFacade(Abcd206DataHolder dataHolder
) {
262 * SPECIMEN OR OBSERVATION OR LIVING
264 // DerivedUnitBase derivedThing = null;
265 DerivedUnitType type
= null;
268 if (dataHolder
.recordBasis
!= null){
269 if (dataHolder
.recordBasis
.toLowerCase().startsWith("s")) {//specimen
270 type
= DerivedUnitType
.Specimen
;
271 }else if (dataHolder
.recordBasis
.toLowerCase().startsWith("o")) {//observation
272 type
= DerivedUnitType
.Observation
;
273 }else if (dataHolder
.recordBasis
.toLowerCase().startsWith("l")) {//living -> fossil, herbarium sheet....???
274 type
= DerivedUnitType
.LivingBeing
;
277 logger
.info("The basis of record does not seem to be known: " + dataHolder
.recordBasis
);
278 type
= DerivedUnitType
.DerivedUnit
;
282 logger
.info("The basis of record is null");
283 type
= DerivedUnitType
.DerivedUnit
;
285 DerivedUnitFacade derivedUnitFacade
= DerivedUnitFacade
.NewInstance(type
);
286 return derivedUnitFacade
;
291 * Return the list of root nodes for an ABCD 2.06 XML file
292 * @param fileName: the file's location
293 * @return the list of root nodes ("Unit")
295 private static NodeList
getUnitsNodeList(String urlFileName
){
296 NodeList unitList
= null;
298 DocumentBuilderFactory factory
= DocumentBuilderFactory
.newInstance();
299 DocumentBuilder builder
= factory
.newDocumentBuilder();
300 URL url
= new URL(urlFileName
);
301 Object o
= url
.getContent();
302 InputStream is
= (InputStream
)o
;
303 Document document
= builder
.parse(is
);
304 Element root
= document
.getDocumentElement();
305 unitList
= root
.getElementsByTagName("Unit");
315 * Store the unit's properties into variables
316 * Look which unit is the preferred one
317 * Look what kind of name it is supposed to be, for the parsing (Botanical, Zoological)
318 * @param racine: the root node for a single unit
320 private void setUnitPropertiesXML(Element root
, Abcd206DataHolder dataHolder
){
324 // try{afficherInfos(racine, 0);}catch (Exception e) {logger.info(e);}
325 group
= root
.getChildNodes();
326 // logger.info("ABCD ELEMENT not stored: "+group.item(i).getNodeName().toString()+" - value: "+group.item(i).getTextContent());
327 for (int i
= 0; i
< group
.getLength(); i
++){
328 if (group
.item(i
).getNodeName().equals("Identifications")){
329 group
= group
.item(i
).getChildNodes();
333 dataHolder
.identificationList
= new ArrayList
<String
>();
334 dataHolder
.atomisedIdentificationList
= new ArrayList
<HashMap
<String
, String
>>();
335 dataHolder
.referenceList
= new ArrayList
<String
>();
336 dataHolder
.multimediaObjects
= new ArrayList
<String
>();
338 this.getScientificNames(group
, dataHolder
);
340 // logger.info("this.identificationList "+this.identificationList.toString());
341 this.getIDs(root
, dataHolder
);
342 this.getRecordBasis(root
, dataHolder
);
343 this.getMultimedia(root
, dataHolder
);
344 this.getNumbers(root
, dataHolder
);
345 this.getGeolocation(root
, dataHolder
);
346 this.getGatheringPeople(root
, dataHolder
);
348 } catch (Exception e
) {
349 logger
.info("Error occured while parsing XML file"+e
);
354 private void getHierarchie(Node node
){
355 while (node
!= null && node
.getNodeName() != "DataSets"){
356 // logger.info(node.getParentNode().getNodeName());
357 path
= node
.getParentNode().getNodeName()+"/"+path
;
358 node
= node
.getParentNode();
360 // logger.info("path: "+path);
363 private void getScientificNames(NodeList group
, Abcd206DataHolder dataHolder
){
364 NodeList identifications
,results
;
365 String tmpName
= null;
366 for (int j
=0; j
< group
.getLength(); j
++){
367 if(group
.item(j
).getNodeName().equals("Identification")){
368 dataHolder
.nomenclatureCode
="";
369 identifications
= group
.item(j
).getChildNodes();
370 for (int m
=0; m
<identifications
.getLength();m
++){
371 if(identifications
.item(m
).getNodeName().equals("Result")){
372 results
= identifications
.item(m
).getChildNodes();
373 for(int k
=0; k
<results
.getLength();k
++){
374 if (results
.item(k
).getNodeName().equals("TaxonIdentified")){
375 tmpName
=this.getScientificName(results
.item(k
), dataHolder
);
378 }else if(identifications
.item(m
).getNodeName().equals("PreferredFlag")){
379 if (dataHolder
.nomenclatureCode
!= null && dataHolder
.nomenclatureCode
!=""){
380 dataHolder
.identificationList
.add(tmpName
+"_preferred_"+identifications
.item(m
).getTextContent()+"_code_" + dataHolder
.nomenclatureCode
);
382 dataHolder
.identificationList
.add(tmpName
+"_preferred_"+identifications
.item(m
).getTextContent());
384 path
=identifications
.item(m
).getNodeName();
385 getHierarchie(identifications
.item(m
));
386 dataHolder
.knownABCDelements
.add(path
);
388 }else if (identifications
.item(m
).getNodeName().equals("References")){
389 this.getReferences(identifications
.item(m
), dataHolder
);
394 boolean hasPref
=false;
395 for (int j
=0; j
< group
.getLength(); j
++){
396 if(group
.item(j
).getNodeName().equals("Identification")){
397 dataHolder
.nomenclatureCode
="";
398 identifications
= group
.item(j
).getChildNodes();
399 for (int m
=0; m
<identifications
.getLength();m
++){
400 if(identifications
.item(m
).getNodeName().equals("Result")){
401 results
= identifications
.item(m
).getChildNodes();
402 for(int k
=0; k
<results
.getLength();k
++){
403 if (results
.item(k
).getNodeName().equals("TaxonIdentified")){
404 tmpName
=this.getScientificName(results
.item(k
), dataHolder
);
408 if(identifications
.item(m
).getNodeName().equals("PreferredFlag")){
412 if ( !hasPref
&& tmpName
!= null){
413 if (dataHolder
.nomenclatureCode
!= null && dataHolder
.nomenclatureCode
!=""){
414 dataHolder
.identificationList
.add(tmpName
+"_preferred_"+"0"+"_code_" + dataHolder
.nomenclatureCode
);
416 dataHolder
.identificationList
.add(tmpName
+"_preferred_"+"0");
425 private void getReferences(Node result
, Abcd206DataHolder dataHolder
){
426 NodeList results
,reference
;
427 results
= result
.getChildNodes();
428 for(int k
=0; k
<results
.getLength();k
++){
429 if (results
.item(k
).getNodeName().equals("Reference")){
430 reference
= results
.item(k
).getChildNodes();
431 for(int l
=0;l
<reference
.getLength();l
++){
432 if (reference
.item(l
).getNodeName().equals("TitleCitation")){
433 path
= reference
.item(l
).getNodeName();
434 dataHolder
.referenceList
.add(reference
.item(l
).getTextContent());
435 getHierarchie(reference
.item(l
));
436 dataHolder
.knownABCDelements
.add(path
);
444 private String
getScientificName(Node result
, Abcd206DataHolder dataHolder
){
445 NodeList taxonsIdentified
, scnames
, atomised
;
447 dataHolder
.atomisedStr
= "";
448 taxonsIdentified
= result
.getChildNodes();
449 for (int l
=0; l
<taxonsIdentified
.getLength(); l
++){
450 if (taxonsIdentified
.item(l
).getNodeName().equals("ScientificName")){
451 scnames
= taxonsIdentified
.item(l
).getChildNodes();
452 for (int n
=0;n
<scnames
.getLength();n
++){
453 if (scnames
.item(n
).getNodeName().equals("FullScientificNameString")){
454 path
=scnames
.item(n
).getNodeName();
455 tmpName
= scnames
.item(n
).getTextContent();
456 getHierarchie(scnames
.item(n
));
457 dataHolder
.knownABCDelements
.add(path
);
460 if (scnames
.item(n
).getNodeName().equals("NameAtomised")){
462 if (scnames
.item(n
).hasChildNodes()){
463 dataHolder
.nomenclatureCode
= scnames
.item(n
).getChildNodes().item(1).getNodeName();
465 } catch (Exception e
) {
466 dataHolder
.nomenclatureCode
="";
468 atomised
= scnames
.item(n
).getChildNodes().item(1).getChildNodes();
469 dataHolder
.atomisedIdentificationList
.add(this.getAtomisedNames(dataHolder
.nomenclatureCode
, atomised
, dataHolder
));
477 private HashMap
<String
,String
> getAtomisedNames(String code
, NodeList atomised
, Abcd206DataHolder dataHolder
){
478 if (code
.equals("Botanical")){
479 return this.getAtomisedBotanical(atomised
, dataHolder
);
481 if (code
.equals("Bacterial")){
482 return this.getAtomisedBacterial(atomised
, dataHolder
);
484 if (code
.equals("NameViral")){
485 return this.getAtomisedViral(atomised
, dataHolder
);
487 if (code
.equals("NameZoological")){
488 return this.getAtomisedZoological(atomised
,dataHolder
);
490 return new HashMap
<String
,String
>();
493 private HashMap
<String
,String
> getAtomisedZoological(NodeList atomised
, Abcd206DataHolder dataHolder
){
494 HashMap
<String
,String
> atomisedMap
= new HashMap
<String
,String
>();
495 for (int i
=0;i
<atomised
.getLength();i
++){
496 if(atomised
.item(i
).getNodeName().equals("GenusOrMonomial")){
497 atomisedMap
.put("Genus",atomised
.item(i
).getTextContent());
498 path
=atomised
.item(i
).getNodeName();
499 getHierarchie(atomised
.item(i
));
500 dataHolder
.knownABCDelements
.add(path
);
503 if(atomised
.item(i
).getNodeName().equals("Subgenus")){
504 atomisedMap
.put("Subgenus",atomised
.item(i
).getTextContent());
505 path
=atomised
.item(i
).getNodeName();
506 getHierarchie(atomised
.item(i
));
507 dataHolder
.knownABCDelements
.add(path
);
510 if(atomised
.item(i
).getNodeName().equals("SpeciesEpithet")){
511 atomisedMap
.put("SpeciesEpithet",atomised
.item(i
).getTextContent());
512 path
=atomised
.item(i
).getNodeName();
513 getHierarchie(atomised
.item(i
));
514 dataHolder
.knownABCDelements
.add(path
);
517 if(atomised
.item(i
).getNodeName().equals("SubspeciesEpithet")){
518 atomisedMap
.put("SubspeciesEpithet",atomised
.item(i
).getTextContent());
519 path
=atomised
.item(i
).getNodeName();
520 getHierarchie(atomised
.item(i
));
521 dataHolder
.knownABCDelements
.add(path
);
524 if(atomised
.item(i
).getNodeName().equals("AuthorTeamOriginalAndYear")){
525 atomisedMap
.put("AuthorTeamOriginalAndYear",atomised
.item(i
).getTextContent());
526 path
=atomised
.item(i
).getNodeName();
527 getHierarchie(atomised
.item(i
));
528 dataHolder
.knownABCDelements
.add(path
);
531 if(atomised
.item(i
).getNodeName().equals("AuthorTeamParenthesisAndYear")){
532 atomisedMap
.put("AuthorTeamParenthesisAndYear",atomised
.item(i
).getTextContent());
533 path
=atomised
.item(i
).getNodeName();
534 getHierarchie(atomised
.item(i
));
535 dataHolder
.knownABCDelements
.add(path
);
538 if(atomised
.item(i
).getNodeName().equals("CombinationAuthorTeamAndYear")){
539 atomisedMap
.put("CombinationAuthorTeamAndYear",atomised
.item(i
).getTextContent());
540 path
=atomised
.item(i
).getNodeName();
541 getHierarchie(atomised
.item(i
));
542 dataHolder
.knownABCDelements
.add(path
);
545 if(atomised
.item(i
).getNodeName().equals("Breed")){
546 atomisedMap
.put("Breed",atomised
.item(i
).getTextContent());
547 path
=atomised
.item(i
).getNodeName();
548 getHierarchie(atomised
.item(i
));
549 dataHolder
.knownABCDelements
.add(path
);
552 if(atomised
.item(i
).getNodeName().equals("NamedIndividual")){
553 atomisedMap
.put("NamedIndividual",atomised
.item(i
).getTextContent());
554 path
=atomised
.item(i
).getNodeName();
555 getHierarchie(atomised
.item(i
));
556 dataHolder
.knownABCDelements
.add(path
);
563 private HashMap
<String
,String
> getAtomisedViral(NodeList atomised
, Abcd206DataHolder dataHolder
){
564 HashMap
<String
,String
> atomisedMap
= new HashMap
<String
,String
>();
565 for (int i
=0;i
<atomised
.getLength();i
++){
566 if(atomised
.item(i
).getNodeName().equals("GenusOrMonomial")){
567 atomisedMap
.put("Genus",atomised
.item(i
).getTextContent());
568 path
=atomised
.item(i
).getNodeName();
569 getHierarchie(atomised
.item(i
));
570 dataHolder
.knownABCDelements
.add(path
);
573 if(atomised
.item(i
).getNodeName().equals("ViralSpeciesDesignation")){
574 atomisedMap
.put("ViralSpeciesDesignation", atomised
.item(i
).getTextContent());
575 path
=atomised
.item(i
).getNodeName();
576 getHierarchie(atomised
.item(i
));
577 dataHolder
.knownABCDelements
.add(path
);
580 if(atomised
.item(i
).getNodeName().equals("Acronym")){
581 atomisedMap
.put("Acronym",atomised
.item(i
).getTextContent());
582 path
=atomised
.item(i
).getNodeName();
583 getHierarchie(atomised
.item(i
));
584 dataHolder
.knownABCDelements
.add(path
);
591 private HashMap
<String
,String
> getAtomisedBotanical(NodeList atomised
, Abcd206DataHolder dataHolder
){
592 HashMap
<String
,String
> atomisedMap
= new HashMap
<String
,String
>();
593 for (int i
=0;i
<atomised
.getLength();i
++){
594 if(atomised
.item(i
).getNodeName().equals("GenusOrMonomial")){
595 atomisedMap
.put("Genus",atomised
.item(i
).getTextContent());
596 path
=atomised
.item(i
).getNodeName();
597 getHierarchie(atomised
.item(i
));
598 dataHolder
.knownABCDelements
.add(path
);
601 if(atomised
.item(i
).getNodeName().equals("FirstEpithet")){
602 atomisedMap
.put("FirstEpithet",atomised
.item(i
).getTextContent());
603 path
=atomised
.item(i
).getNodeName();
604 getHierarchie(atomised
.item(i
));
605 dataHolder
.knownABCDelements
.add(path
);
608 if(atomised
.item(i
).getNodeName().equals("InfraspecificEpithet")){
609 atomisedMap
.put("InfraSpeEpithet", atomised
.item(i
).getTextContent());
610 path
=atomised
.item(i
).getNodeName();
611 getHierarchie(atomised
.item(i
));
612 dataHolder
.knownABCDelements
.add(path
);
615 if(atomised
.item(i
).getNodeName().equals("Rank")){
616 atomisedMap
.put("Rank",atomised
.item(i
).getTextContent());
617 path
=atomised
.item(i
).getNodeName();
618 getHierarchie(atomised
.item(i
));
619 dataHolder
.knownABCDelements
.add(path
);
622 if(atomised
.item(i
).getNodeName().equals("HybridFlag")){
623 atomisedMap
.put("HybridFlag",atomised
.item(i
).getTextContent());
624 path
=atomised
.item(i
).getNodeName();
625 getHierarchie(atomised
.item(i
));
626 dataHolder
.knownABCDelements
.add(path
);
629 if(atomised
.item(i
).getNodeName().equals("AuthorTeamParenthesis")){
630 atomisedMap
.put("AuthorTeamParenthesis",atomised
.item(i
).getTextContent());
631 path
=atomised
.item(i
).getNodeName();
632 getHierarchie(atomised
.item(i
));
633 dataHolder
.knownABCDelements
.add(path
);
636 if(atomised
.item(i
).getNodeName().equals("AuthorTeam")){
637 atomisedMap
.put("AuthorTeam",atomised
.item(i
).getTextContent());
638 path
=atomised
.item(i
).getNodeName();
639 getHierarchie(atomised
.item(i
));
640 dataHolder
.knownABCDelements
.add(path
);
643 if(atomised
.item(i
).getNodeName().equals("CultivarGroupName")){
644 atomisedMap
.put("CultivarGroupName",atomised
.item(i
).getTextContent());
645 path
=atomised
.item(i
).getNodeName();
646 getHierarchie(atomised
.item(i
));
647 dataHolder
.knownABCDelements
.add(path
);
650 if(atomised
.item(i
).getNodeName().equals("CultivarName")){
651 atomisedMap
.put("CultivarName",atomised
.item(i
).getTextContent());
652 path
=atomised
.item(i
).getNodeName();
653 getHierarchie(atomised
.item(i
));
654 dataHolder
.knownABCDelements
.add(path
);
657 if(atomised
.item(i
).getNodeName().equals("TradeDesignationNames")){
658 atomisedMap
.put("Trade",atomised
.item(i
).getTextContent());
659 path
=atomised
.item(i
).getNodeName();
660 getHierarchie(atomised
.item(i
));
661 dataHolder
.knownABCDelements
.add(path
);
668 private HashMap
<String
,String
> getAtomisedBacterial(NodeList atomised
, Abcd206DataHolder dataHolder
){
669 HashMap
<String
,String
> atomisedMap
= new HashMap
<String
,String
>();
670 for (int i
=0;i
<atomised
.getLength();i
++){
671 if(atomised
.item(i
).getNodeName().equals("GenusOrMonomial")){
672 atomisedMap
.put("Genus",atomised
.item(i
).getTextContent());
673 path
=atomised
.item(i
).getNodeName();
674 getHierarchie(atomised
.item(i
));
675 dataHolder
.knownABCDelements
.add(path
);
678 if(atomised
.item(i
).getNodeName().equals("Subgenus")){
679 atomisedMap
.put("SubGenus",atomised
.item(i
).getTextContent());
680 path
=atomised
.item(i
).getNodeName();
681 getHierarchie(atomised
.item(i
));
682 dataHolder
.knownABCDelements
.add(path
);
685 if(atomised
.item(i
).getNodeName().equals("SubgenusAuthorAndYear")){
686 atomisedMap
.put("SubgenusAuthorAndYear",atomised
.item(i
).getTextContent());
687 path
=atomised
.item(i
).getNodeName();
688 getHierarchie(atomised
.item(i
));
689 dataHolder
.knownABCDelements
.add(path
);
692 if(atomised
.item(i
).getNodeName().equals("SpeciesEpithet")){
693 atomisedMap
.put("SpeciesEpithet",atomised
.item(i
).getTextContent());
694 path
=atomised
.item(i
).getNodeName();
695 getHierarchie(atomised
.item(i
));
696 dataHolder
.knownABCDelements
.add(path
);
699 if(atomised
.item(i
).getNodeName().equals("SubspeciesEpithet")){
700 atomisedMap
.put("SubspeciesEpithet",atomised
.item(i
).getTextContent());
701 path
=atomised
.item(i
).getNodeName();
702 getHierarchie(atomised
.item(i
));
703 dataHolder
.knownABCDelements
.add(path
);
706 if(atomised
.item(i
).getNodeName().equals("ParentheticalAuthorTeamAndYear")){
707 atomisedMap
.put("ParentheticalAuthorTeamAndYear",atomised
.item(i
).getTextContent());
708 path
=atomised
.item(i
).getNodeName();
709 getHierarchie(atomised
.item(i
));
710 dataHolder
.knownABCDelements
.add(path
);
713 if(atomised
.item(i
).getNodeName().equals("AuthorTeamAndYear")){
714 atomisedMap
.put("AuthorTeamAndYear",atomised
.item(i
).getTextContent());
715 path
=atomised
.item(i
).getNodeName();
716 getHierarchie(atomised
.item(i
));
717 dataHolder
.knownABCDelements
.add(path
);
720 if(atomised
.item(i
).getNodeName().equals("NameApprobation")){
721 atomisedMap
.put("NameApprobation",atomised
.item(i
).getTextContent());
722 path
=atomised
.item(i
).getNodeName();
723 getHierarchie(atomised
.item(i
));
724 dataHolder
.knownABCDelements
.add(path
);
731 private void getIDs(Element root
, Abcd206DataHolder dataHolder
){
734 group
= root
.getElementsByTagName("SourceInstitutionID");
735 path
=group
.item(0).getNodeName();
736 getHierarchie(group
.item(0));
737 dataHolder
.knownABCDelements
.add(path
);
739 dataHolder
.institutionCode
= group
.item(0).getTextContent();
740 } catch (NullPointerException e
) {
741 dataHolder
.institutionCode
= "";
744 group
= root
.getElementsByTagName("SourceID");
745 path
=group
.item(0).getNodeName();
746 getHierarchie(group
.item(0));
747 dataHolder
.knownABCDelements
.add(path
);
749 dataHolder
.collectionCode
= group
.item(0).getTextContent();
750 } catch (NullPointerException e
) {
751 dataHolder
.collectionCode
= "";
754 group
= root
.getElementsByTagName("UnitID");
755 path
=group
.item(0).getNodeName();
756 getHierarchie(group
.item(0));
757 dataHolder
.knownABCDelements
.add(path
);
759 dataHolder
.unitID
= group
.item(0).getTextContent();
760 } catch (NullPointerException e
) {
761 dataHolder
.unitID
= "";
765 private void getRecordBasis(Element root
, Abcd206DataHolder dataHolder
){
768 group
= root
.getElementsByTagName("RecordBasis");
769 path
=group
.item(0).getNodeName();
770 getHierarchie(group
.item(0));
771 dataHolder
.knownABCDelements
.add(path
);
773 dataHolder
.recordBasis
= group
.item(0).getTextContent();
774 } catch (NullPointerException e
) {
775 dataHolder
.recordBasis
= "";
779 private void getMultimedia(Element root
, Abcd206DataHolder dataHolder
){
780 NodeList group
, multimedias
, multimedia
;
782 group
= root
.getElementsByTagName("MultiMediaObjects");
783 for(int i
=0;i
<group
.getLength();i
++){
784 multimedias
= group
.item(i
).getChildNodes();
785 for (int j
=0;j
<multimedias
.getLength();j
++){
786 if (multimedias
.item(j
).getNodeName().equals("MultiMediaObject")){
787 multimedia
= multimedias
.item(j
).getChildNodes();
788 for (int k
=0;k
<multimedia
.getLength();k
++){
789 if(multimedia
.item(k
).getNodeName().equals("FileURI")){
790 dataHolder
.multimediaObjects
.add(multimedia
.item(k
).getTextContent());
791 path
= multimedia
.item(k
).getNodeName();
792 getHierarchie(multimedia
.item(k
));
793 dataHolder
.knownABCDelements
.add(path
);
800 } catch (NullPointerException e
) {
805 private void getNumbers(Element root
, Abcd206DataHolder dataHolder
){
808 group
= root
.getElementsByTagName("AccessionNumber");
809 path
=group
.item(0).getNodeName();
810 getHierarchie(group
.item(0));
811 dataHolder
.knownABCDelements
.add(path
);
813 dataHolder
.accessionNumber
= group
.item(0).getTextContent();
814 } catch (NullPointerException e
) {
815 dataHolder
.accessionNumber
= "";
818 group
= root
.getElementsByTagName("CollectorsFieldNumber");
819 path
=group
.item(0).getNodeName();
820 getHierarchie(group
.item(0));
821 dataHolder
.knownABCDelements
.add(path
);
823 dataHolder
.fieldNumber
= group
.item(0).getTextContent();
824 } catch (NullPointerException e
) {
825 dataHolder
.fieldNumber
= "";
829 group
= root
.getElementsByTagName("CollectorsNumber");
830 path
=group
.item(0).getNodeName();
831 getHierarchie(group
.item(0));
832 dataHolder
.knownABCDelements
.add(path
);
834 dataHolder
.collectorsNumber
= group
.item(0).getTextContent();
835 } catch (NullPointerException e
) {
836 dataHolder
.collectorsNumber
= "";
840 group
= root
.getElementsByTagName("AccessionNumber");
841 path
=group
.item(0).getNodeName();
842 getHierarchie(group
.item(0));
843 dataHolder
.knownABCDelements
.add(path
);
845 dataHolder
.accessionNumber
= group
.item(0).getTextContent();
846 } catch (NullPointerException e
) {
847 dataHolder
.accessionNumber
= "";
851 private void getGeolocation(Element root
, Abcd206DataHolder dataHolder
){
852 NodeList group
, childs
;
854 group
= root
.getElementsByTagName("LocalityText");
855 path
=group
.item(0).getNodeName();
856 getHierarchie(group
.item(0));
857 dataHolder
.knownABCDelements
.add(path
);
859 dataHolder
.locality
= group
.item(0).getTextContent();
860 if (group
.item(0).hasAttributes())
861 if (group
.item(0).getAttributes().getNamedItem("lang") != null)
862 dataHolder
.languageIso
= group
.item(0).getAttributes().getNamedItem("lang").getTextContent();
863 } catch (NullPointerException e
) {
864 dataHolder
.locality
= "";
867 group
= root
.getElementsByTagName("LongitudeDecimal");
868 path
=group
.item(0).getNodeName();
869 getHierarchie(group
.item(0));
870 dataHolder
.knownABCDelements
.add(path
);
872 dataHolder
.longitude
= Double
.valueOf(group
.item(0).getTextContent());
873 } catch (NullPointerException e
) {
874 dataHolder
.longitude
=0.0;
877 group
= root
.getElementsByTagName("LatitudeDecimal");
878 path
=group
.item(0).getNodeName();
879 getHierarchie(group
.item(0));
880 dataHolder
.knownABCDelements
.add(path
);
882 dataHolder
.latitude
= Double
.valueOf(group
.item(0).getTextContent());
883 } catch (NullPointerException e
) {
884 dataHolder
.latitude
=0.0;
887 group
= root
.getElementsByTagName("Country");
888 childs
= group
.item(0).getChildNodes();
889 for (int i
=0;i
<childs
.getLength(); i
++){
890 if(childs
.item(i
).getNodeName() == "Name"){
891 path
=childs
.item(i
).getNodeName();
892 getHierarchie(childs
.item(i
));
893 dataHolder
.knownABCDelements
.add(path
);
895 dataHolder
.country
= childs
.item(i
).getTextContent();
898 } catch (NullPointerException e
) {
899 dataHolder
.country
= "";
902 group
= root
.getElementsByTagName("Country");
903 childs
= group
.item(0).getChildNodes();
904 for (int i
=0;i
<childs
.getLength(); i
++){
905 if(childs
.item(i
).getNodeName() == "ISO3166Code"){
906 path
=childs
.item(i
).getNodeName();
907 getHierarchie(childs
.item(i
));
908 dataHolder
.knownABCDelements
.add(path
);
910 dataHolder
.isocountry
= childs
.item(i
).getTextContent();
913 } catch (NullPointerException e
) {
914 dataHolder
.isocountry
= "";
917 group
= root
.getElementsByTagName("Altitude");
918 for (int i
=0;i
<group
.getLength();i
++){
919 childs
= group
.item(i
).getChildNodes();
920 for (int j
=0;j
<childs
.getLength();j
++){
921 if (childs
.item(j
).getNodeName().equals("MeasurementOrFactText")){
922 path
=childs
.item(j
).getNodeName();
923 getHierarchie(childs
.item(j
));
924 dataHolder
.knownABCDelements
.add(path
);
926 dataHolder
.altitude
= Integer
.valueOf(childs
.item(j
).getTextContent());
930 } catch (NullPointerException e
) {
931 dataHolder
.altitude
= -9999;
935 group
= root
.getElementsByTagName("Depth");
936 path
=group
.item(0).getNodeName();
937 getHierarchie(group
.item(0));
938 dataHolder
.knownABCDelements
.add(path
);
940 dataHolder
.depth
= Integer
.valueOf(group
.item(0).getTextContent());
941 } catch (NullPointerException e
) {
942 dataHolder
.depth
= -9999;
946 group
= root
.getElementsByTagName("NamedArea");
947 dataHolder
.namedAreaList
= new ArrayList
<String
>();
948 for (int i
=0;i
<group
.getLength();i
++){
949 childs
= group
.item(i
).getChildNodes();
950 for (int j
=0; j
<childs
.getLength();j
++){
951 if (childs
.item(j
).getNodeName().equals("AreaName")){
952 path
= childs
.item(j
).getNodeName();
953 getHierarchie(childs
.item(j
));
954 dataHolder
.knownABCDelements
.add(path
);
956 dataHolder
.namedAreaList
.add(childs
.item(j
).getTextContent());
960 }catch(NullPointerException e
){
961 dataHolder
.namedAreaList
= new ArrayList
<String
>();
965 private void getGatheringPeople(Element root
, Abcd206DataHolder dataHolder
){
966 NodeList group
, childs
, person
;
968 group
= root
.getElementsByTagName("GatheringAgent");
969 dataHolder
.gatheringAgentList
= new ArrayList
<String
>();
970 for (int i
=0; i
< group
.getLength(); i
++){
971 childs
= group
.item(i
).getChildNodes();
972 for (int j
=0; j
<childs
.getLength();j
++){
973 if (childs
.item(j
).getNodeName().equals("Person")){
974 person
= childs
.item(j
).getChildNodes();
975 for (int k
=0; k
<person
.getLength(); k
++){
976 if (person
.item(k
).getNodeName().equals("FullName")){
977 path
=person
.item(k
).getNodeName();
978 getHierarchie(person
.item(k
));
979 dataHolder
.knownABCDelements
.add(path
);
981 dataHolder
.gatheringAgentList
.add(person
.item(k
).getTextContent());
988 } catch (NullPointerException e
) {
989 dataHolder
.gatheringAgentList
= new ArrayList
<String
>();
993 private Institution
getInstitution(String institutionCode
, Abcd206ImportConfigurator config
, Abcd206DataHolder dataHolder
){
994 Institution institution
;
995 List
<Institution
> institutions
;
997 logger
.info(dataHolder
.institutionCode
);
998 institutions
= getAgentService().searchInstitutionByCode(dataHolder
.institutionCode
);
1000 institutions
=new ArrayList
<Institution
>();
1002 if (institutions
.size() ==0 || !config
.isReUseExistingMetadata()){
1003 logger
.info("Institution (agent) unknown or not allowed to reuse existing metadata");
1004 //create institution
1005 institution
= Institution
.NewInstance();
1006 institution
.setCode(dataHolder
.institutionCode
);
1009 logger
.info("Institution (agent) already in the db");
1010 institution
= institutions
.get(0);
1016 * Look if the Collection does already exists
1017 * @param collectionCode: a string
1018 * @param institution: the current Institution
1020 * @return the Collection (existing or new)
1022 private Collection
getCollection(String collectionCode
, Institution institution
, Abcd206ImportConfigurator config
, Abcd206DataHolder dataHolder
){
1023 Collection collection
= Collection
.NewInstance();
1024 List
<Collection
> collections
;
1026 collections
= getCollectionService().searchByCode(dataHolder
.collectionCode
);
1027 }catch(Exception e
){
1028 collections
=new ArrayList
<Collection
>();
1030 if (collections
.size() ==0 || !config
.isReUseExistingMetadata()){
1031 logger
.info("Collection not found or do not reuse existing metadata " + dataHolder
.collectionCode
);
1032 //create new collection
1033 collection
.setCode(dataHolder
.collectionCode
);
1034 collection
.setCodeStandard("GBIF");
1035 collection
.setInstitute(institution
);
1038 boolean collectionFound
=false;
1039 for (int i
=0; i
<collections
.size(); i
++){
1040 collection
= collections
.get(i
);
1042 if (collection
.getInstitute().getCode().equalsIgnoreCase(institution
.getCode())){
1043 //found a collection with the same code and the same institution
1044 collectionFound
=true;
1046 } catch (NullPointerException e
) {}
1048 if (!collectionFound
){
1049 collection
.setCode(dataHolder
.collectionCode
);
1050 collection
.setCodeStandard("GBIF");
1051 collection
.setInstitute(institution
);
1061 * @param derivedThing
1064 private void handleIdentifications(Abcd206ImportConfigurator config
, DerivedUnitFacade facade
, ReferenceBase sec
, Abcd206DataHolder dataHolder
){
1065 NonViralName
<?
> taxonName
= null;
1066 String fullScientificNameString
;
1068 DeterminationEvent determinationEvent
= null;
1069 List
<TaxonBase
> names
= null;
1071 String scientificName
="";
1072 boolean preferredFlag
=false;
1074 for (int i
= 0; i
< dataHolder
.identificationList
.size(); i
++) {
1075 fullScientificNameString
= dataHolder
.identificationList
.get(i
);
1076 fullScientificNameString
= fullScientificNameString
.replaceAll(" et ", " & ");
1077 if (fullScientificNameString
.indexOf("_preferred_") != -1){
1078 scientificName
= fullScientificNameString
.split("_preferred_")[0];
1079 String pTmp
= fullScientificNameString
.split("_preferred_")[1].split("_code_")[0];
1080 if (pTmp
.equals("1") || pTmp
.toLowerCase().indexOf("true") != -1){
1083 preferredFlag
=false;
1087 scientificName
= fullScientificNameString
;
1089 logger
.info(fullScientificNameString
);
1090 if (fullScientificNameString
.indexOf("_code_") != -1){
1091 dataHolder
.nomenclatureCode
= fullScientificNameString
.split("_code_")[1];
1093 if (config
.isDoAutomaticParsing() || dataHolder
.atomisedIdentificationList
== null || dataHolder
.atomisedIdentificationList
.size()==0){
1094 taxonName
= this.parseScientificName(scientificName
, dataHolder
);
1096 if (dataHolder
.atomisedIdentificationList
!= null || dataHolder
.atomisedIdentificationList
.size()>0){
1097 taxonName
= this.setTaxonNameByType(dataHolder
.atomisedIdentificationList
.get(i
), scientificName
, dataHolder
);
1100 if(taxonName
== null){
1101 taxonName
= NonViralName
.NewInstance(null);
1102 taxonName
.setFullTitleCache(scientificName
);
1105 // --- cascade through several options in order to find an appropriate taxon ---
1107 if (config
.isDoMatchTaxa()){
1108 taxon
= getTaxonService().findBestMatchingTaxon(scientificName
);
1110 if (taxon
== null && config
.isDoReUseTaxon()){
1112 names
= getTaxonService().searchTaxaByName(scientificName
, sec
);
1113 taxon
= (Taxon
)names
.get(0);
1114 } catch(Exception e
){
1118 logger
.info("Matching to existing Taxon : " + taxon
.getTitleCache());
1121 if (!config
.isDoReUseTaxon() || taxon
== null){
1122 getNameService().save(taxonName
);
1123 taxon
= Taxon
.NewInstance(taxonName
, sec
); //TODO sec set null
1126 // taxonName = NonViralName.NewInstance(null);
1127 // taxonName.setFullTitleCache(scientificName);
1129 // --- taxon is found now ---
1131 determinationEvent
= DeterminationEvent
.NewInstance();
1132 determinationEvent
.setTaxon(taxon
);
1133 determinationEvent
.setPreferredFlag(preferredFlag
);
1135 for (String strReference
: dataHolder
.referenceList
){
1137 ReferenceBase reference
= ReferenceFactory
.newGeneric();
1138 reference
.setTitleCache(strReference
, true);
1139 determinationEvent
.addReference(reference
);
1141 facade
.addDetermination(determinationEvent
);
1143 if(config
.isDoCreateIndividualsAssociations()){
1144 TaxonDescription taxonDescription
= null;
1145 if(config
.isDoMatchToExistingDescription()){
1146 logger
.error("The import option 'DoMatchToExistingDescription' is not yet implemented.");
1148 UUID taxonDescriptionUUID
= config
.getTaxonToDescriptionMap().get(taxon
.getUuid()); // rather put in state
1149 taxonDescription
= (TaxonDescription
) getDescriptionService().load(taxonDescriptionUUID
);
1150 if(taxonDescription
== null){
1151 taxonDescription
= TaxonDescription
.NewInstance(taxon
);
1152 config
.getTaxonToDescriptionMap().put(taxon
.getUuid(), taxonDescription
.getUuid());
1153 if(taxonDescriptionUUID
== null){
1154 logger
.info("Creating new TaxonDescription for " + taxon
.getTitleCache());
1156 logger
.fatal("TaxonDescription with UUID " + taxonDescriptionUUID
+ " not found --> creating a new one.");
1160 IndividualsAssociation individualsAssociation
= IndividualsAssociation
.NewInstance();
1161 individualsAssociation
.setAssociatedSpecimenOrObservation(facade
.getDerivedUnit());
1162 individualsAssociation
.setFeature(Feature
.INDIVIDUALS_ASSOCIATION());
1163 for(ReferenceBase citation
: determinationEvent
.getReferences()){
1164 individualsAssociation
.addSource(DescriptionElementSource
.NewInstance(null, null, citation
, null));
1166 taxonDescription
.addElement(individualsAssociation
);
1167 getDescriptionService().saveOrUpdate(taxonDescription
);
1173 private NonViralName
<?
> parseScientificName(String scientificName
, Abcd206DataHolder dataHolder
){
1174 NonViralNameParserImpl nvnpi
= NonViralNameParserImpl
.NewInstance();
1175 NonViralName
<?
>taxonName
= null;
1176 boolean problem
=false;
1178 if (dataHolder
.nomenclatureCode
.toString().equals("Zoological")){
1179 taxonName
= (ZoologicalName
)nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICZN
,null);
1180 if (taxonName
.hasProblem()){
1184 if (dataHolder
.nomenclatureCode
.toString().equals("Botanical")){
1185 taxonName
= (BotanicalName
)nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICBN
,null);
1186 if (taxonName
.hasProblem()){
1190 if (dataHolder
.nomenclatureCode
.toString().equals("Bacterial")){
1191 taxonName
= (BacterialName
)nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICNB
, null);
1192 if (taxonName
.hasProblem()){
1196 if (dataHolder
.nomenclatureCode
.toString().equals("Cultivar")){
1197 taxonName
= (CultivarPlantName
)nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICNCP
, null);
1198 if (taxonName
.hasProblem()){
1202 // if (this.nomenclatureCode.toString().equals("Viral")){
1203 // ViralName taxonName = (ViralName)nvnpi.parseFullName(scientificName,NomenclaturalCode.ICVCN(), null);
1204 // if (taxonName.hasProblem())
1205 // logger.info("pb ICVCN");
1207 //TODO: parsing of ViralNames?
1209 taxonName
= NonViralName
.NewInstance(null);
1210 taxonName
.setTitleCache(scientificName
, true);
1216 private NonViralName
<?
> setTaxonNameByType(HashMap
<String
, String
> atomisedMap
,String fullName
, Abcd206DataHolder dataHolder
){
1217 if (dataHolder
.nomenclatureCode
.equals("Zoological")){
1218 NonViralName
<ZoologicalName
> taxonName
= ZoologicalName
.NewInstance(null);
1219 taxonName
.setFullTitleCache(fullName
, true);
1220 taxonName
.setGenusOrUninomial(getFromMap(atomisedMap
,"Genus"));
1221 taxonName
.setInfraGenericEpithet(getFromMap(atomisedMap
,"SubGenus"));
1222 taxonName
.setSpecificEpithet(getFromMap(atomisedMap
,"SpeciesEpithet"));
1223 taxonName
.setInfraSpecificEpithet(getFromMap(atomisedMap
,"SubspeciesEpithet"));
1225 if(getFromMap(atomisedMap
,"AuthorTeamParenthesis") != null){
1226 team
= Team
.NewInstance();
1227 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeamParenthesis"), true);
1229 if (getFromMap(atomisedMap
,"AuthorTeamAndYear") != null){
1230 team
= Team
.NewInstance();
1231 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeamAndYear"), true);
1235 taxonName
.setBasionymAuthorTeam(team
);
1237 if(getFromMap(atomisedMap
,"AuthorTeamParenthesis") != null){
1238 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
,"AuthorTeamParenthesis"));
1239 } else if (getFromMap(atomisedMap
,"AuthorTeamAndYear") != null){
1240 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
,"AuthorTeamAndYear"));
1243 if(getFromMap(atomisedMap
,"CombinationAuthorTeamAndYear") != null){
1244 team
= Team
.NewInstance();
1245 team
.setTitleCache(getFromMap(atomisedMap
,"CombinationAuthorTeamAndYear"), true);
1246 taxonName
.setCombinationAuthorTeam(team
);
1248 if (taxonName
.hasProblem()){
1249 logger
.info("pb ICZN");
1254 if (dataHolder
.nomenclatureCode
.equals("Botanical")){
1255 NonViralName
<BotanicalName
> taxonName
= BotanicalName
.NewInstance(null);
1256 taxonName
.setFullTitleCache(fullName
, true);
1257 taxonName
.setGenusOrUninomial(getFromMap(atomisedMap
,"Genus"));
1258 taxonName
.setInfraGenericEpithet(getFromMap(atomisedMap
,"FirstEpithet"));
1259 taxonName
.setInfraSpecificEpithet(getFromMap(atomisedMap
,"InfraSpeEpithet"));
1260 try{taxonName
.setRank(Rank
.getRankByName(getFromMap(atomisedMap
,"Rank")));
1261 }catch(Exception e
){}
1263 if(getFromMap(atomisedMap
,"AuthorTeamParenthesis") != null){
1264 team
= Team
.NewInstance();
1265 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeamParenthesis"), true);
1267 taxonName
.setBasionymAuthorTeam(team
);
1270 if (getFromMap(atomisedMap
,"AuthorTeam") != null){
1271 team
= Team
.NewInstance();
1272 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeam"), true);
1274 taxonName
.setCombinationAuthorTeam(team
);
1278 if(getFromMap(atomisedMap
,"AuthorTeamParenthesis") != null){
1279 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
,"AuthorTeamParenthesis"));
1280 }else if (getFromMap(atomisedMap
,"AuthorTeam") != null){
1281 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
,"AuthorTeam"));
1284 if(getFromMap(atomisedMap
,"CombinationAuthorTeamAndYear") != null){
1285 team
= Team
.NewInstance();
1286 team
.setTitleCache(getFromMap(atomisedMap
,"CombinationAuthorTeamAndYear"), true);
1287 taxonName
.setCombinationAuthorTeam(team
);
1289 if (taxonName
.hasProblem()){
1290 logger
.info("pb ICBN");
1295 if (dataHolder
.nomenclatureCode
.equals("Bacterial")){
1296 NonViralName
<BacterialName
> taxonName
= BacterialName
.NewInstance(null);
1297 taxonName
.setFullTitleCache(fullName
, true);
1298 taxonName
.setGenusOrUninomial(getFromMap(atomisedMap
,"Genus"));
1299 taxonName
.setInfraGenericEpithet(getFromMap(atomisedMap
,"SubGenus"));
1300 taxonName
.setSpecificEpithet(getFromMap(atomisedMap
,"Species"));
1301 taxonName
.setInfraSpecificEpithet(getFromMap(atomisedMap
,"SubspeciesEpithet"));
1302 if(getFromMap(atomisedMap
,"AuthorTeamAndYear") != null){
1303 Team team
= Team
.NewInstance();
1304 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeamAndYear"), true);
1305 taxonName
.setCombinationAuthorTeam(team
);
1307 if(getFromMap(atomisedMap
,"ParentheticalAuthorTeamAndYear") != null){
1308 Team team
= Team
.NewInstance();
1309 team
.setTitleCache(getFromMap(atomisedMap
,"ParentheticalAuthorTeamAndYear"), true);
1310 taxonName
.setBasionymAuthorTeam(team
);
1312 if (taxonName
.hasProblem()){
1313 logger
.info("pb ICNB");
1318 if (dataHolder
.nomenclatureCode
.equals("Cultivar")){
1319 CultivarPlantName taxonName
= CultivarPlantName
.NewInstance(null);
1321 if (taxonName
.hasProblem()){
1322 logger
.info("pb ICNCP");
1327 // if (this.nomenclatureCode.equals("Viral")){
1328 // ViralName taxonName = ViralName.NewInstance(null);
1329 // taxonName.setFullTitleCache(fullName, true);
1330 // taxonName.setAcronym(getFromMap(atomisedMap,"Acronym"));
1331 // if (taxonName.hasProblem())
1332 // logger.info("pb ICVCN");
1333 // else return taxonName;
1336 NonViralName
<?
>taxonName
= NonViralName
.NewInstance(null);
1337 taxonName
.setFullTitleCache(fullName
, true);
1341 private String
getFromMap(HashMap
<String
, String
> atomisedMap
, String key
){
1342 String value
= null;
1343 if (atomisedMap
.containsKey(key
)){
1344 value
= atomisedMap
.get(key
);
1347 if (value
!= null && key
.matches(".*Year.*")){
1349 if (value
.matches("[a-z A-Z ]*[0-9]{4}$")){
1350 String tmp
=value
.split("[0-9]{4}$")[0];
1351 int year
= Integer
.parseInt(value
.split(tmp
)[1]);
1361 }catch(Exception e
){value
=null;}
1366 private void compareABCDtoCDM(String urlFileName
, ArrayList
<String
> knownElts
, Abcd206DataHolder dataHolder
){
1369 DocumentBuilderFactory factory
= DocumentBuilderFactory
.newInstance();
1370 DocumentBuilder constructeur
= factory
.newDocumentBuilder();
1371 URL url
= new URL(urlFileName
);
1372 Object o
= url
.getContent();
1373 InputStream is
= (InputStream
)o
;
1374 Document document
= constructeur
.parse(is
);
1375 Element root
= document
.getDocumentElement();
1376 traverse(root
, dataHolder
);
1377 } catch (ParserConfigurationException e
) {
1378 e
.printStackTrace();
1379 } catch (SAXException e
) {
1380 e
.printStackTrace();
1381 } catch (IOException e
) {
1382 e
.printStackTrace();
1384 Set
<String
> elts
= dataHolder
.allABCDelements
.keySet();
1385 Iterator
< String
>it
= elts
.iterator();
1387 while (it
.hasNext()){
1389 if (knownElts
.indexOf(elt
) == -1){
1390 logger
.info("Unsaved ABCD element: " + elt
+ " - " + dataHolder
.allABCDelements
.get(elt
));
1398 * Traverses the tree for compareABCDtoCDM
1402 private void traverse(Node node
, Abcd206DataHolder dataHolder
){
1403 // Extract node info:
1404 String test
= node
.getTextContent();
1406 // Print and continue traversing.
1407 if(test
!= null && test
!= "#text" && node
.getNodeName() != "#text" && test
.split("\n").length
==1 && test
.length()>0){
1408 path
=node
.getNodeName();
1409 getHierarchie(node
);
1410 dataHolder
.allABCDelements
.put(path
,test
);
1413 // Now traverse the rest of the tree in depth-first order.
1414 if (node
.hasChildNodes()) {
1415 // Get the children in a list.
1416 NodeList nl
= node
.getChildNodes();
1417 // How many of them?
1418 int size
= nl
.getLength();
1419 for (int i
=0; i
<size
; i
++){
1420 // Recursively traverse each of the children.
1421 traverse (nl
.item(i
), dataHolder
);
1429 protected boolean isIgnore(Abcd206ImportState state
) {
1430 //return ! config.isDoNameFacts();