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
;
16 import java
.util
.ArrayList
;
17 import java
.util
.HashMap
;
18 import java
.util
.Iterator
;
19 import java
.util
.List
;
21 import java
.util
.UUID
;
23 import javax
.xml
.parsers
.DocumentBuilder
;
24 import javax
.xml
.parsers
.DocumentBuilderFactory
;
25 import javax
.xml
.parsers
.ParserConfigurationException
;
27 import org
.apache
.log4j
.Logger
;
28 import org
.springframework
.stereotype
.Component
;
29 import org
.springframework
.transaction
.TransactionStatus
;
30 import org
.w3c
.dom
.Document
;
31 import org
.w3c
.dom
.Element
;
32 import org
.w3c
.dom
.Node
;
33 import org
.w3c
.dom
.NodeList
;
34 import org
.xml
.sax
.SAXException
;
36 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
37 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
.DerivedUnitType
;
38 import eu
.etaxonomy
.cdm
.io
.common
.ICdmIO
;
39 import eu
.etaxonomy
.cdm
.io
.specimen
.SpecimenImportBase
;
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
.Media
;
50 import eu
.etaxonomy
.cdm
.model
.name
.BacterialName
;
51 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
52 import eu
.etaxonomy
.cdm
.model
.name
.CultivarPlantName
;
53 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
54 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
55 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
56 import eu
.etaxonomy
.cdm
.model
.name
.ZoologicalName
;
57 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
58 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
59 import eu
.etaxonomy
.cdm
.model
.occurrence
.GatheringEvent
;
60 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
61 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
62 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
63 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
64 import eu
.etaxonomy
.cdm
.strategy
.parser
.NonViralNameParserImpl
;
73 public class Abcd206Import
extends SpecimenImportBase
<Abcd206ImportConfigurator
, Abcd206ImportState
> implements ICdmIO
<Abcd206ImportState
> {
74 private static final Logger logger
= Logger
.getLogger(Abcd206Import
.class);
77 public Abcd206Import() {
83 protected boolean doCheck(Abcd206ImportState state
) {
84 logger
.warn("Checking not yet implemented for " + this.getClass().getSimpleName());
90 public boolean doInvoke(Abcd206ImportState state
){
91 logger
.info("INVOKE Specimen Import from ABCD2.06 XML File");
92 boolean result
= true;
93 //AbcdIO test = new AbcdIO();
94 URI sourceName
= state
.getConfig().getSource();
95 NodeList unitsList
= getUnitsNodeList(sourceName
);
96 if (unitsList
!= null){
97 String message
= "nb units to insert: "+unitsList
.getLength();
99 updateProgress(state
, message
);
101 Abcd206DataHolder dataHolder
= new Abcd206DataHolder();
103 for (int i
=0 ; i
<unitsList
.getLength() ; i
++){
104 this.setUnitPropertiesXML((Element
)unitsList
.item(i
), dataHolder
);
105 result
&= this.handleSingleUnit(state
, dataHolder
);
107 //compare the ABCD elements added in to the CDM and the unhandled ABCD elements
108 compareABCDtoCDM(sourceName
, dataHolder
.knownABCDelements
, dataHolder
);
110 //reset the ABCD elements added in CDM
111 //knownABCDelements = new ArrayList<String>();
112 dataHolder
.allABCDelements
= new HashMap
<String
,String
>();
121 * Store the unit with its Gathering informations in the CDM
123 private boolean handleSingleUnit(Abcd206ImportState state
, Abcd206DataHolder dataHolder
){
124 boolean result
= true;
126 Abcd206ImportConfigurator config
= state
.getConfig();
128 TransactionStatus tx
= startTransaction();
130 updateProgress(state
, "Importing data for unit: " + dataHolder
.unitID
);
132 // ReferenceBase sec = Database.NewInstance();
133 // sec.setTitleCache("XML DATA");
134 ReferenceBase sec
= config
.getTaxonReference();
137 DerivedUnitFacade derivedUnitFacade
= getFacade(dataHolder
);
140 //handle identifications
141 handleIdentifications(config
, derivedUnitFacade
, sec
, dataHolder
);
143 //handle collection data
144 setCollectionData(config
, dataHolder
, derivedUnitFacade
);
151 UnitsGatheringEvent unitsGatheringEvent
= new UnitsGatheringEvent(
152 getTermService(), dataHolder
.locality
, dataHolder
.languageIso
, dataHolder
.longitude
,
153 dataHolder
.latitude
, dataHolder
.gatheringAgentList
);
156 UnitsGatheringArea unitsGatheringArea
=
157 new UnitsGatheringArea(dataHolder
.isocountry
, dataHolder
.country
, getOccurrenceService());
158 NamedArea areaCountry
= unitsGatheringArea
.getArea();
161 unitsGatheringArea
= new UnitsGatheringArea(dataHolder
.namedAreaList
);
162 ArrayList
<NamedArea
> nas
= unitsGatheringArea
.getAreas();
163 for (NamedArea namedArea
: nas
){
164 unitsGatheringEvent
.addArea(namedArea
);
167 //copy gathering event to facade
168 GatheringEvent gatheringEvent
= unitsGatheringEvent
.getGatheringEvent();
169 derivedUnitFacade
.setLocality(gatheringEvent
.getLocality());
170 derivedUnitFacade
.setExactLocation(gatheringEvent
.getExactLocation());
171 derivedUnitFacade
.setCollector(gatheringEvent
.getCollector());
172 derivedUnitFacade
.setCountry(areaCountry
);
173 derivedUnitFacade
.addCollectingAreas(unitsGatheringArea
.getAreas());
179 derivedUnitFacade
.setFieldNumber(dataHolder
.fieldNumber
);
181 //join gatheringEvent to fieldObservation
183 // //add Multimedia URLs
184 if(dataHolder
.multimediaObjects
.size() > 0){
185 for (String multimediaObject
: dataHolder
.multimediaObjects
){
186 Media media
= getImageMedia(multimediaObject
, true);
187 derivedUnitFacade
.addDerivedUnitMedia(media
);
192 * SAVE AND STORE DATA
194 getTermService().save(areaCountry
);//TODO save area sooner
195 for (NamedArea area
: nas
){
196 getTermService().save(area
);//save it sooner (foreach area)
198 getTermService().saveLanguageData(unitsGatheringEvent
.getLocality());//TODO needs to be saved ?? save it sooner
200 getOccurrenceService().save(derivedUnitFacade
.getDerivedUnit());
201 logger
.info("saved ABCD specimen ...");
204 } catch (Exception e
) {
205 logger
.warn("Error when reading record!!");
209 commitTransaction(tx
);
214 private void setCollectionData(Abcd206ImportConfigurator config
,
215 Abcd206DataHolder dataHolder
, DerivedUnitFacade derivedUnitFacade
) {
216 //set catalogue number (unitID)
217 derivedUnitFacade
.setCatalogNumber(dataHolder
.unitID
);
218 derivedUnitFacade
.setAccessionNumber(dataHolder
.accessionNumber
);
219 derivedUnitFacade
.setCollectorsNumber(dataHolder
.collectorsNumber
);
223 * INSTITUTION & COLLECTION
226 Institution institution
= this.getInstitution(dataHolder
.institutionCode
, config
, dataHolder
);
228 Collection collection
= this.getCollection(dataHolder
.collectionCode
, institution
, config
, dataHolder
);
229 //link specimen & collection
230 derivedUnitFacade
.setCollection(collection
);
234 private DerivedUnitFacade
getFacade(Abcd206DataHolder dataHolder
) {
236 * SPECIMEN OR OBSERVATION OR LIVING
238 // DerivedUnitBase derivedThing = null;
239 DerivedUnitType type
= null;
242 if (dataHolder
.recordBasis
!= null){
243 if (dataHolder
.recordBasis
.toLowerCase().startsWith("s")) {//specimen
244 type
= DerivedUnitType
.Specimen
;
245 }else if (dataHolder
.recordBasis
.toLowerCase().startsWith("o")) {//observation
246 type
= DerivedUnitType
.Observation
;
247 }else if (dataHolder
.recordBasis
.toLowerCase().startsWith("l")) {//living -> fossil, herbarium sheet....???
248 type
= DerivedUnitType
.LivingBeing
;
251 logger
.info("The basis of record does not seem to be known: " + dataHolder
.recordBasis
);
252 type
= DerivedUnitType
.DerivedUnit
;
256 logger
.info("The basis of record is null");
257 type
= DerivedUnitType
.DerivedUnit
;
259 DerivedUnitFacade derivedUnitFacade
= DerivedUnitFacade
.NewInstance(type
);
260 return derivedUnitFacade
;
265 * Return the list of root nodes for an ABCD 2.06 XML file
266 * @param fileName: the file's location
267 * @return the list of root nodes ("Unit")
269 private static NodeList
getUnitsNodeList(URI urlFileName
){
270 NodeList unitList
= null;
272 DocumentBuilderFactory factory
= DocumentBuilderFactory
.newInstance();
273 DocumentBuilder builder
= factory
.newDocumentBuilder();
274 URL url
= urlFileName
.toURL();
275 Object o
= url
.getContent();
276 InputStream is
= (InputStream
)o
;
277 Document document
= builder
.parse(is
);
278 Element root
= document
.getDocumentElement();
279 unitList
= root
.getElementsByTagName("Unit");
289 * Store the unit's properties into variables
290 * Look which unit is the preferred one
291 * Look what kind of name it is supposed to be, for the parsing (Botanical, Zoological)
292 * @param racine: the root node for a single unit
294 private void setUnitPropertiesXML(Element root
, Abcd206DataHolder dataHolder
){
298 // try{afficherInfos(racine, 0);}catch (Exception e) {logger.info(e);}
299 group
= root
.getChildNodes();
300 // logger.info("ABCD ELEMENT not stored: "+group.item(i).getNodeName().toString()+" - value: "+group.item(i).getTextContent());
301 for (int i
= 0; i
< group
.getLength(); i
++){
302 if (group
.item(i
).getNodeName().equals("Identifications")){
303 group
= group
.item(i
).getChildNodes();
307 dataHolder
.identificationList
= new ArrayList
<String
>();
308 dataHolder
.atomisedIdentificationList
= new ArrayList
<HashMap
<String
, String
>>();
309 dataHolder
.referenceList
= new ArrayList
<String
>();
310 dataHolder
.multimediaObjects
= new ArrayList
<String
>();
312 this.getScientificNames(group
, dataHolder
);
314 // logger.info("this.identificationList "+this.identificationList.toString());
315 this.getIDs(root
, dataHolder
);
316 this.getRecordBasis(root
, dataHolder
);
317 this.getMultimedia(root
, dataHolder
);
318 this.getNumbers(root
, dataHolder
);
319 this.getGeolocation(root
, dataHolder
);
320 this.getGatheringPeople(root
, dataHolder
);
322 } catch (Exception e
) {
323 logger
.info("Error occured while parsing XML file"+e
);
328 private void getHierarchie(Node node
){
329 while (node
!= null && node
.getNodeName() != "DataSets"){
330 // logger.info(node.getParentNode().getNodeName());
331 path
= node
.getParentNode().getNodeName()+"/"+path
;
332 node
= node
.getParentNode();
334 // logger.info("path: "+path);
337 private void getScientificNames(NodeList group
, Abcd206DataHolder dataHolder
){
338 NodeList identifications
,results
;
339 String tmpName
= null;
340 for (int j
=0; j
< group
.getLength(); j
++){
341 if(group
.item(j
).getNodeName().equals("Identification")){
342 dataHolder
.nomenclatureCode
="";
343 identifications
= group
.item(j
).getChildNodes();
344 for (int m
=0; m
<identifications
.getLength();m
++){
345 if(identifications
.item(m
).getNodeName().equals("Result")){
346 results
= identifications
.item(m
).getChildNodes();
347 for(int k
=0; k
<results
.getLength();k
++){
348 if (results
.item(k
).getNodeName().equals("TaxonIdentified")){
349 tmpName
=this.getScientificName(results
.item(k
), dataHolder
);
352 }else if(identifications
.item(m
).getNodeName().equals("PreferredFlag")){
353 if (dataHolder
.nomenclatureCode
!= null && dataHolder
.nomenclatureCode
!=""){
354 dataHolder
.identificationList
.add(tmpName
+"_preferred_"+identifications
.item(m
).getTextContent()+"_code_" + dataHolder
.nomenclatureCode
);
356 dataHolder
.identificationList
.add(tmpName
+"_preferred_"+identifications
.item(m
).getTextContent());
358 path
=identifications
.item(m
).getNodeName();
359 getHierarchie(identifications
.item(m
));
360 dataHolder
.knownABCDelements
.add(path
);
362 }else if (identifications
.item(m
).getNodeName().equals("References")){
363 this.getReferences(identifications
.item(m
), dataHolder
);
368 boolean hasPref
=false;
369 for (int j
=0; j
< group
.getLength(); j
++){
370 if(group
.item(j
).getNodeName().equals("Identification")){
371 dataHolder
.nomenclatureCode
="";
372 identifications
= group
.item(j
).getChildNodes();
373 for (int m
=0; m
<identifications
.getLength();m
++){
374 if(identifications
.item(m
).getNodeName().equals("Result")){
375 results
= identifications
.item(m
).getChildNodes();
376 for(int k
=0; k
<results
.getLength();k
++){
377 if (results
.item(k
).getNodeName().equals("TaxonIdentified")){
378 tmpName
=this.getScientificName(results
.item(k
), dataHolder
);
382 if(identifications
.item(m
).getNodeName().equals("PreferredFlag")){
386 if ( !hasPref
&& tmpName
!= null){
387 if (dataHolder
.nomenclatureCode
!= null && dataHolder
.nomenclatureCode
!=""){
388 dataHolder
.identificationList
.add(tmpName
+"_preferred_"+"0"+"_code_" + dataHolder
.nomenclatureCode
);
390 dataHolder
.identificationList
.add(tmpName
+"_preferred_"+"0");
399 private void getReferences(Node result
, Abcd206DataHolder dataHolder
){
400 NodeList results
,reference
;
401 results
= result
.getChildNodes();
402 for(int k
=0; k
<results
.getLength();k
++){
403 if (results
.item(k
).getNodeName().equals("Reference")){
404 reference
= results
.item(k
).getChildNodes();
405 for(int l
=0;l
<reference
.getLength();l
++){
406 if (reference
.item(l
).getNodeName().equals("TitleCitation")){
407 path
= reference
.item(l
).getNodeName();
408 dataHolder
.referenceList
.add(reference
.item(l
).getTextContent());
409 getHierarchie(reference
.item(l
));
410 dataHolder
.knownABCDelements
.add(path
);
418 private String
getScientificName(Node result
, Abcd206DataHolder dataHolder
){
419 NodeList taxonsIdentified
, scnames
, atomised
;
421 dataHolder
.atomisedStr
= "";
422 taxonsIdentified
= result
.getChildNodes();
423 for (int l
=0; l
<taxonsIdentified
.getLength(); l
++){
424 if (taxonsIdentified
.item(l
).getNodeName().equals("ScientificName")){
425 scnames
= taxonsIdentified
.item(l
).getChildNodes();
426 for (int n
=0;n
<scnames
.getLength();n
++){
427 if (scnames
.item(n
).getNodeName().equals("FullScientificNameString")){
428 path
=scnames
.item(n
).getNodeName();
429 tmpName
= scnames
.item(n
).getTextContent();
430 getHierarchie(scnames
.item(n
));
431 dataHolder
.knownABCDelements
.add(path
);
434 if (scnames
.item(n
).getNodeName().equals("NameAtomised")){
436 if (scnames
.item(n
).hasChildNodes()){
437 dataHolder
.nomenclatureCode
= scnames
.item(n
).getChildNodes().item(1).getNodeName();
439 } catch (Exception e
) {
440 dataHolder
.nomenclatureCode
="";
442 atomised
= scnames
.item(n
).getChildNodes().item(1).getChildNodes();
443 dataHolder
.atomisedIdentificationList
.add(this.getAtomisedNames(dataHolder
.nomenclatureCode
, atomised
, dataHolder
));
451 private HashMap
<String
,String
> getAtomisedNames(String code
, NodeList atomised
, Abcd206DataHolder dataHolder
){
452 if (code
.equals("Botanical")){
453 return this.getAtomisedBotanical(atomised
, dataHolder
);
455 if (code
.equals("Bacterial")){
456 return this.getAtomisedBacterial(atomised
, dataHolder
);
458 if (code
.equals("NameViral")){
459 return this.getAtomisedViral(atomised
, dataHolder
);
461 if (code
.equals("NameZoological")){
462 return this.getAtomisedZoological(atomised
,dataHolder
);
464 return new HashMap
<String
,String
>();
467 private HashMap
<String
,String
> getAtomisedZoological(NodeList atomised
, Abcd206DataHolder dataHolder
){
468 HashMap
<String
,String
> atomisedMap
= new HashMap
<String
,String
>();
469 for (int i
=0;i
<atomised
.getLength();i
++){
470 if(atomised
.item(i
).getNodeName().equals("GenusOrMonomial")){
471 atomisedMap
.put("Genus",atomised
.item(i
).getTextContent());
472 path
=atomised
.item(i
).getNodeName();
473 getHierarchie(atomised
.item(i
));
474 dataHolder
.knownABCDelements
.add(path
);
477 if(atomised
.item(i
).getNodeName().equals("Subgenus")){
478 atomisedMap
.put("Subgenus",atomised
.item(i
).getTextContent());
479 path
=atomised
.item(i
).getNodeName();
480 getHierarchie(atomised
.item(i
));
481 dataHolder
.knownABCDelements
.add(path
);
484 if(atomised
.item(i
).getNodeName().equals("SpeciesEpithet")){
485 atomisedMap
.put("SpeciesEpithet",atomised
.item(i
).getTextContent());
486 path
=atomised
.item(i
).getNodeName();
487 getHierarchie(atomised
.item(i
));
488 dataHolder
.knownABCDelements
.add(path
);
491 if(atomised
.item(i
).getNodeName().equals("SubspeciesEpithet")){
492 atomisedMap
.put("SubspeciesEpithet",atomised
.item(i
).getTextContent());
493 path
=atomised
.item(i
).getNodeName();
494 getHierarchie(atomised
.item(i
));
495 dataHolder
.knownABCDelements
.add(path
);
498 if(atomised
.item(i
).getNodeName().equals("AuthorTeamOriginalAndYear")){
499 atomisedMap
.put("AuthorTeamOriginalAndYear",atomised
.item(i
).getTextContent());
500 path
=atomised
.item(i
).getNodeName();
501 getHierarchie(atomised
.item(i
));
502 dataHolder
.knownABCDelements
.add(path
);
505 if(atomised
.item(i
).getNodeName().equals("AuthorTeamParenthesisAndYear")){
506 atomisedMap
.put("AuthorTeamParenthesisAndYear",atomised
.item(i
).getTextContent());
507 path
=atomised
.item(i
).getNodeName();
508 getHierarchie(atomised
.item(i
));
509 dataHolder
.knownABCDelements
.add(path
);
512 if(atomised
.item(i
).getNodeName().equals("CombinationAuthorTeamAndYear")){
513 atomisedMap
.put("CombinationAuthorTeamAndYear",atomised
.item(i
).getTextContent());
514 path
=atomised
.item(i
).getNodeName();
515 getHierarchie(atomised
.item(i
));
516 dataHolder
.knownABCDelements
.add(path
);
519 if(atomised
.item(i
).getNodeName().equals("Breed")){
520 atomisedMap
.put("Breed",atomised
.item(i
).getTextContent());
521 path
=atomised
.item(i
).getNodeName();
522 getHierarchie(atomised
.item(i
));
523 dataHolder
.knownABCDelements
.add(path
);
526 if(atomised
.item(i
).getNodeName().equals("NamedIndividual")){
527 atomisedMap
.put("NamedIndividual",atomised
.item(i
).getTextContent());
528 path
=atomised
.item(i
).getNodeName();
529 getHierarchie(atomised
.item(i
));
530 dataHolder
.knownABCDelements
.add(path
);
537 private HashMap
<String
,String
> getAtomisedViral(NodeList atomised
, Abcd206DataHolder dataHolder
){
538 HashMap
<String
,String
> atomisedMap
= new HashMap
<String
,String
>();
539 for (int i
=0;i
<atomised
.getLength();i
++){
540 if(atomised
.item(i
).getNodeName().equals("GenusOrMonomial")){
541 atomisedMap
.put("Genus",atomised
.item(i
).getTextContent());
542 path
=atomised
.item(i
).getNodeName();
543 getHierarchie(atomised
.item(i
));
544 dataHolder
.knownABCDelements
.add(path
);
547 if(atomised
.item(i
).getNodeName().equals("ViralSpeciesDesignation")){
548 atomisedMap
.put("ViralSpeciesDesignation", atomised
.item(i
).getTextContent());
549 path
=atomised
.item(i
).getNodeName();
550 getHierarchie(atomised
.item(i
));
551 dataHolder
.knownABCDelements
.add(path
);
554 if(atomised
.item(i
).getNodeName().equals("Acronym")){
555 atomisedMap
.put("Acronym",atomised
.item(i
).getTextContent());
556 path
=atomised
.item(i
).getNodeName();
557 getHierarchie(atomised
.item(i
));
558 dataHolder
.knownABCDelements
.add(path
);
565 private HashMap
<String
,String
> getAtomisedBotanical(NodeList atomised
, Abcd206DataHolder dataHolder
){
566 HashMap
<String
,String
> atomisedMap
= new HashMap
<String
,String
>();
567 for (int i
=0;i
<atomised
.getLength();i
++){
568 if(atomised
.item(i
).getNodeName().equals("GenusOrMonomial")){
569 atomisedMap
.put("Genus",atomised
.item(i
).getTextContent());
570 path
=atomised
.item(i
).getNodeName();
571 getHierarchie(atomised
.item(i
));
572 dataHolder
.knownABCDelements
.add(path
);
575 if(atomised
.item(i
).getNodeName().equals("FirstEpithet")){
576 atomisedMap
.put("FirstEpithet",atomised
.item(i
).getTextContent());
577 path
=atomised
.item(i
).getNodeName();
578 getHierarchie(atomised
.item(i
));
579 dataHolder
.knownABCDelements
.add(path
);
582 if(atomised
.item(i
).getNodeName().equals("InfraspecificEpithet")){
583 atomisedMap
.put("InfraSpeEpithet", atomised
.item(i
).getTextContent());
584 path
=atomised
.item(i
).getNodeName();
585 getHierarchie(atomised
.item(i
));
586 dataHolder
.knownABCDelements
.add(path
);
589 if(atomised
.item(i
).getNodeName().equals("Rank")){
590 atomisedMap
.put("Rank",atomised
.item(i
).getTextContent());
591 path
=atomised
.item(i
).getNodeName();
592 getHierarchie(atomised
.item(i
));
593 dataHolder
.knownABCDelements
.add(path
);
596 if(atomised
.item(i
).getNodeName().equals("HybridFlag")){
597 atomisedMap
.put("HybridFlag",atomised
.item(i
).getTextContent());
598 path
=atomised
.item(i
).getNodeName();
599 getHierarchie(atomised
.item(i
));
600 dataHolder
.knownABCDelements
.add(path
);
603 if(atomised
.item(i
).getNodeName().equals("AuthorTeamParenthesis")){
604 atomisedMap
.put("AuthorTeamParenthesis",atomised
.item(i
).getTextContent());
605 path
=atomised
.item(i
).getNodeName();
606 getHierarchie(atomised
.item(i
));
607 dataHolder
.knownABCDelements
.add(path
);
610 if(atomised
.item(i
).getNodeName().equals("AuthorTeam")){
611 atomisedMap
.put("AuthorTeam",atomised
.item(i
).getTextContent());
612 path
=atomised
.item(i
).getNodeName();
613 getHierarchie(atomised
.item(i
));
614 dataHolder
.knownABCDelements
.add(path
);
617 if(atomised
.item(i
).getNodeName().equals("CultivarGroupName")){
618 atomisedMap
.put("CultivarGroupName",atomised
.item(i
).getTextContent());
619 path
=atomised
.item(i
).getNodeName();
620 getHierarchie(atomised
.item(i
));
621 dataHolder
.knownABCDelements
.add(path
);
624 if(atomised
.item(i
).getNodeName().equals("CultivarName")){
625 atomisedMap
.put("CultivarName",atomised
.item(i
).getTextContent());
626 path
=atomised
.item(i
).getNodeName();
627 getHierarchie(atomised
.item(i
));
628 dataHolder
.knownABCDelements
.add(path
);
631 if(atomised
.item(i
).getNodeName().equals("TradeDesignationNames")){
632 atomisedMap
.put("Trade",atomised
.item(i
).getTextContent());
633 path
=atomised
.item(i
).getNodeName();
634 getHierarchie(atomised
.item(i
));
635 dataHolder
.knownABCDelements
.add(path
);
642 private HashMap
<String
,String
> getAtomisedBacterial(NodeList atomised
, Abcd206DataHolder dataHolder
){
643 HashMap
<String
,String
> atomisedMap
= new HashMap
<String
,String
>();
644 for (int i
=0;i
<atomised
.getLength();i
++){
645 if(atomised
.item(i
).getNodeName().equals("GenusOrMonomial")){
646 atomisedMap
.put("Genus",atomised
.item(i
).getTextContent());
647 path
=atomised
.item(i
).getNodeName();
648 getHierarchie(atomised
.item(i
));
649 dataHolder
.knownABCDelements
.add(path
);
652 if(atomised
.item(i
).getNodeName().equals("Subgenus")){
653 atomisedMap
.put("SubGenus",atomised
.item(i
).getTextContent());
654 path
=atomised
.item(i
).getNodeName();
655 getHierarchie(atomised
.item(i
));
656 dataHolder
.knownABCDelements
.add(path
);
659 if(atomised
.item(i
).getNodeName().equals("SubgenusAuthorAndYear")){
660 atomisedMap
.put("SubgenusAuthorAndYear",atomised
.item(i
).getTextContent());
661 path
=atomised
.item(i
).getNodeName();
662 getHierarchie(atomised
.item(i
));
663 dataHolder
.knownABCDelements
.add(path
);
666 if(atomised
.item(i
).getNodeName().equals("SpeciesEpithet")){
667 atomisedMap
.put("SpeciesEpithet",atomised
.item(i
).getTextContent());
668 path
=atomised
.item(i
).getNodeName();
669 getHierarchie(atomised
.item(i
));
670 dataHolder
.knownABCDelements
.add(path
);
673 if(atomised
.item(i
).getNodeName().equals("SubspeciesEpithet")){
674 atomisedMap
.put("SubspeciesEpithet",atomised
.item(i
).getTextContent());
675 path
=atomised
.item(i
).getNodeName();
676 getHierarchie(atomised
.item(i
));
677 dataHolder
.knownABCDelements
.add(path
);
680 if(atomised
.item(i
).getNodeName().equals("ParentheticalAuthorTeamAndYear")){
681 atomisedMap
.put("ParentheticalAuthorTeamAndYear",atomised
.item(i
).getTextContent());
682 path
=atomised
.item(i
).getNodeName();
683 getHierarchie(atomised
.item(i
));
684 dataHolder
.knownABCDelements
.add(path
);
687 if(atomised
.item(i
).getNodeName().equals("AuthorTeamAndYear")){
688 atomisedMap
.put("AuthorTeamAndYear",atomised
.item(i
).getTextContent());
689 path
=atomised
.item(i
).getNodeName();
690 getHierarchie(atomised
.item(i
));
691 dataHolder
.knownABCDelements
.add(path
);
694 if(atomised
.item(i
).getNodeName().equals("NameApprobation")){
695 atomisedMap
.put("NameApprobation",atomised
.item(i
).getTextContent());
696 path
=atomised
.item(i
).getNodeName();
697 getHierarchie(atomised
.item(i
));
698 dataHolder
.knownABCDelements
.add(path
);
705 private void getIDs(Element root
, Abcd206DataHolder dataHolder
){
708 group
= root
.getElementsByTagName("SourceInstitutionID");
709 path
=group
.item(0).getNodeName();
710 getHierarchie(group
.item(0));
711 dataHolder
.knownABCDelements
.add(path
);
713 dataHolder
.institutionCode
= group
.item(0).getTextContent();
714 } catch (NullPointerException e
) {
715 dataHolder
.institutionCode
= "";
718 group
= root
.getElementsByTagName("SourceID");
719 path
=group
.item(0).getNodeName();
720 getHierarchie(group
.item(0));
721 dataHolder
.knownABCDelements
.add(path
);
723 dataHolder
.collectionCode
= group
.item(0).getTextContent();
724 } catch (NullPointerException e
) {
725 dataHolder
.collectionCode
= "";
728 group
= root
.getElementsByTagName("UnitID");
729 path
=group
.item(0).getNodeName();
730 getHierarchie(group
.item(0));
731 dataHolder
.knownABCDelements
.add(path
);
733 dataHolder
.unitID
= group
.item(0).getTextContent();
734 } catch (NullPointerException e
) {
735 dataHolder
.unitID
= "";
739 private void getRecordBasis(Element root
, Abcd206DataHolder dataHolder
){
742 group
= root
.getElementsByTagName("RecordBasis");
743 path
=group
.item(0).getNodeName();
744 getHierarchie(group
.item(0));
745 dataHolder
.knownABCDelements
.add(path
);
747 dataHolder
.recordBasis
= group
.item(0).getTextContent();
748 } catch (NullPointerException e
) {
749 dataHolder
.recordBasis
= "";
753 private void getMultimedia(Element root
, Abcd206DataHolder dataHolder
){
754 NodeList group
, multimedias
, multimedia
;
756 group
= root
.getElementsByTagName("MultiMediaObjects");
757 for(int i
=0;i
<group
.getLength();i
++){
758 multimedias
= group
.item(i
).getChildNodes();
759 for (int j
=0;j
<multimedias
.getLength();j
++){
760 if (multimedias
.item(j
).getNodeName().equals("MultiMediaObject")){
761 multimedia
= multimedias
.item(j
).getChildNodes();
762 for (int k
=0;k
<multimedia
.getLength();k
++){
763 if(multimedia
.item(k
).getNodeName().equals("FileURI")){
764 dataHolder
.multimediaObjects
.add(multimedia
.item(k
).getTextContent());
765 path
= multimedia
.item(k
).getNodeName();
766 getHierarchie(multimedia
.item(k
));
767 dataHolder
.knownABCDelements
.add(path
);
774 } catch (NullPointerException e
) {
779 private void getNumbers(Element root
, Abcd206DataHolder dataHolder
){
782 group
= root
.getElementsByTagName("AccessionNumber");
783 path
=group
.item(0).getNodeName();
784 getHierarchie(group
.item(0));
785 dataHolder
.knownABCDelements
.add(path
);
787 dataHolder
.accessionNumber
= group
.item(0).getTextContent();
788 } catch (NullPointerException e
) {
789 dataHolder
.accessionNumber
= "";
792 group
= root
.getElementsByTagName("CollectorsFieldNumber");
793 path
=group
.item(0).getNodeName();
794 getHierarchie(group
.item(0));
795 dataHolder
.knownABCDelements
.add(path
);
797 dataHolder
.fieldNumber
= group
.item(0).getTextContent();
798 } catch (NullPointerException e
) {
799 dataHolder
.fieldNumber
= "";
803 group
= root
.getElementsByTagName("CollectorsNumber");
804 path
=group
.item(0).getNodeName();
805 getHierarchie(group
.item(0));
806 dataHolder
.knownABCDelements
.add(path
);
808 dataHolder
.collectorsNumber
= group
.item(0).getTextContent();
809 } catch (NullPointerException e
) {
810 dataHolder
.collectorsNumber
= "";
814 group
= root
.getElementsByTagName("AccessionNumber");
815 path
=group
.item(0).getNodeName();
816 getHierarchie(group
.item(0));
817 dataHolder
.knownABCDelements
.add(path
);
819 dataHolder
.accessionNumber
= group
.item(0).getTextContent();
820 } catch (NullPointerException e
) {
821 dataHolder
.accessionNumber
= "";
825 private void getGeolocation(Element root
, Abcd206DataHolder dataHolder
){
826 NodeList group
, childs
;
828 group
= root
.getElementsByTagName("LocalityText");
829 path
=group
.item(0).getNodeName();
830 getHierarchie(group
.item(0));
831 dataHolder
.knownABCDelements
.add(path
);
833 dataHolder
.locality
= group
.item(0).getTextContent();
834 if (group
.item(0).hasAttributes())
835 if (group
.item(0).getAttributes().getNamedItem("lang") != null)
836 dataHolder
.languageIso
= group
.item(0).getAttributes().getNamedItem("lang").getTextContent();
837 } catch (NullPointerException e
) {
838 dataHolder
.locality
= "";
841 group
= root
.getElementsByTagName("LongitudeDecimal");
842 path
=group
.item(0).getNodeName();
843 getHierarchie(group
.item(0));
844 dataHolder
.knownABCDelements
.add(path
);
846 dataHolder
.longitude
= Double
.valueOf(group
.item(0).getTextContent());
847 } catch (NullPointerException e
) {
848 dataHolder
.longitude
=null;
851 group
= root
.getElementsByTagName("LatitudeDecimal");
852 path
=group
.item(0).getNodeName();
853 getHierarchie(group
.item(0));
854 dataHolder
.knownABCDelements
.add(path
);
856 dataHolder
.latitude
= Double
.valueOf(group
.item(0).getTextContent());
857 } catch (NullPointerException e
) {
858 dataHolder
.latitude
=null;
861 group
= root
.getElementsByTagName("Country");
862 childs
= group
.item(0).getChildNodes();
863 for (int i
=0;i
<childs
.getLength(); i
++){
864 if(childs
.item(i
).getNodeName() == "Name"){
865 path
=childs
.item(i
).getNodeName();
866 getHierarchie(childs
.item(i
));
867 dataHolder
.knownABCDelements
.add(path
);
869 dataHolder
.country
= childs
.item(i
).getTextContent();
872 } catch (NullPointerException e
) {
873 dataHolder
.country
= "";
876 group
= root
.getElementsByTagName("Country");
877 childs
= group
.item(0).getChildNodes();
878 for (int i
=0;i
<childs
.getLength(); i
++){
879 if(childs
.item(i
).getNodeName() == "ISO3166Code"){
880 path
=childs
.item(i
).getNodeName();
881 getHierarchie(childs
.item(i
));
882 dataHolder
.knownABCDelements
.add(path
);
884 dataHolder
.isocountry
= childs
.item(i
).getTextContent();
887 } catch (NullPointerException e
) {
888 dataHolder
.isocountry
= "";
891 group
= root
.getElementsByTagName("Altitude");
892 for (int i
=0;i
<group
.getLength();i
++){
893 childs
= group
.item(i
).getChildNodes();
894 for (int j
=0;j
<childs
.getLength();j
++){
895 if (childs
.item(j
).getNodeName().equals("MeasurementOrFactText")){
896 path
=childs
.item(j
).getNodeName();
897 getHierarchie(childs
.item(j
));
898 dataHolder
.knownABCDelements
.add(path
);
900 dataHolder
.altitude
= Integer
.valueOf(childs
.item(j
).getTextContent());
904 } catch (NullPointerException e
) {
905 dataHolder
.altitude
= -9999;
909 group
= root
.getElementsByTagName("Depth");
910 path
=group
.item(0).getNodeName();
911 getHierarchie(group
.item(0));
912 dataHolder
.knownABCDelements
.add(path
);
914 dataHolder
.depth
= Integer
.valueOf(group
.item(0).getTextContent());
915 } catch (NullPointerException e
) {
916 dataHolder
.depth
= -9999;
920 group
= root
.getElementsByTagName("NamedArea");
921 dataHolder
.namedAreaList
= new ArrayList
<String
>();
922 for (int i
=0;i
<group
.getLength();i
++){
923 childs
= group
.item(i
).getChildNodes();
924 for (int j
=0; j
<childs
.getLength();j
++){
925 if (childs
.item(j
).getNodeName().equals("AreaName")){
926 path
= childs
.item(j
).getNodeName();
927 getHierarchie(childs
.item(j
));
928 dataHolder
.knownABCDelements
.add(path
);
930 dataHolder
.namedAreaList
.add(childs
.item(j
).getTextContent());
934 }catch(NullPointerException e
){
935 dataHolder
.namedAreaList
= new ArrayList
<String
>();
939 private void getGatheringPeople(Element root
, Abcd206DataHolder dataHolder
){
940 NodeList group
, childs
, person
;
942 group
= root
.getElementsByTagName("GatheringAgent");
943 dataHolder
.gatheringAgentList
= new ArrayList
<String
>();
944 for (int i
=0; i
< group
.getLength(); i
++){
945 childs
= group
.item(i
).getChildNodes();
946 for (int j
=0; j
<childs
.getLength();j
++){
947 if (childs
.item(j
).getNodeName().equals("Person")){
948 person
= childs
.item(j
).getChildNodes();
949 for (int k
=0; k
<person
.getLength(); k
++){
950 if (person
.item(k
).getNodeName().equals("FullName")){
951 path
=person
.item(k
).getNodeName();
952 getHierarchie(person
.item(k
));
953 dataHolder
.knownABCDelements
.add(path
);
955 dataHolder
.gatheringAgentList
.add(person
.item(k
).getTextContent());
962 } catch (NullPointerException e
) {
963 dataHolder
.gatheringAgentList
= new ArrayList
<String
>();
967 private Institution
getInstitution(String institutionCode
, Abcd206ImportConfigurator config
, Abcd206DataHolder dataHolder
){
968 Institution institution
;
969 List
<Institution
> institutions
;
971 logger
.info(dataHolder
.institutionCode
);
972 institutions
= getAgentService().searchInstitutionByCode(dataHolder
.institutionCode
);
974 institutions
=new ArrayList
<Institution
>();
976 if (institutions
.size() ==0 || !config
.isReUseExistingMetadata()){
977 logger
.info("Institution (agent) unknown or not allowed to reuse existing metadata");
979 institution
= Institution
.NewInstance();
980 institution
.setCode(dataHolder
.institutionCode
);
983 logger
.info("Institution (agent) already in the db");
984 institution
= institutions
.get(0);
990 * Look if the Collection does already exists
991 * @param collectionCode: a string
992 * @param institution: the current Institution
994 * @return the Collection (existing or new)
996 private Collection
getCollection(String collectionCode
, Institution institution
, Abcd206ImportConfigurator config
, Abcd206DataHolder dataHolder
){
997 Collection collection
= Collection
.NewInstance();
998 List
<Collection
> collections
;
1000 collections
= getCollectionService().searchByCode(dataHolder
.collectionCode
);
1001 }catch(Exception e
){
1002 collections
=new ArrayList
<Collection
>();
1004 if (collections
.size() ==0 || !config
.isReUseExistingMetadata()){
1005 logger
.info("Collection not found or do not reuse existing metadata " + dataHolder
.collectionCode
);
1006 //create new collection
1007 collection
.setCode(dataHolder
.collectionCode
);
1008 collection
.setCodeStandard("GBIF");
1009 collection
.setInstitute(institution
);
1012 boolean collectionFound
=false;
1013 for (int i
=0; i
<collections
.size(); i
++){
1014 collection
= collections
.get(i
);
1016 if (collection
.getInstitute().getCode().equalsIgnoreCase(institution
.getCode())){
1017 //found a collection with the same code and the same institution
1018 collectionFound
=true;
1020 } catch (NullPointerException e
) {}
1022 if (!collectionFound
){
1023 collection
.setCode(dataHolder
.collectionCode
);
1024 collection
.setCodeStandard("GBIF");
1025 collection
.setInstitute(institution
);
1035 * @param derivedThing
1038 private void handleIdentifications(Abcd206ImportConfigurator config
, DerivedUnitFacade facade
, ReferenceBase sec
, Abcd206DataHolder dataHolder
){
1039 NonViralName
<?
> taxonName
= null;
1040 String fullScientificNameString
;
1042 DeterminationEvent determinationEvent
= null;
1043 List
<TaxonBase
> names
= null;
1045 String scientificName
="";
1046 boolean preferredFlag
=false;
1048 for (int i
= 0; i
< dataHolder
.identificationList
.size(); i
++) {
1049 fullScientificNameString
= dataHolder
.identificationList
.get(i
);
1050 fullScientificNameString
= fullScientificNameString
.replaceAll(" et ", " & ");
1051 if (fullScientificNameString
.indexOf("_preferred_") != -1){
1052 scientificName
= fullScientificNameString
.split("_preferred_")[0];
1053 String pTmp
= fullScientificNameString
.split("_preferred_")[1].split("_code_")[0];
1054 if (pTmp
.equals("1") || pTmp
.toLowerCase().indexOf("true") != -1){
1057 preferredFlag
=false;
1061 scientificName
= fullScientificNameString
;
1063 logger
.info(fullScientificNameString
);
1064 if (fullScientificNameString
.indexOf("_code_") != -1){
1065 dataHolder
.nomenclatureCode
= fullScientificNameString
.split("_code_")[1];
1067 if (config
.isDoAutomaticParsing() || dataHolder
.atomisedIdentificationList
== null || dataHolder
.atomisedIdentificationList
.size()==0){
1068 taxonName
= this.parseScientificName(scientificName
, dataHolder
);
1070 if (dataHolder
.atomisedIdentificationList
!= null || dataHolder
.atomisedIdentificationList
.size()>0){
1071 taxonName
= this.setTaxonNameByType(dataHolder
.atomisedIdentificationList
.get(i
), scientificName
, dataHolder
);
1074 if(taxonName
== null){
1075 taxonName
= NonViralName
.NewInstance(null);
1076 taxonName
.setFullTitleCache(scientificName
);
1079 // --- cascade through several options in order to find an appropriate taxon ---
1081 if (config
.isDoMatchTaxa()){
1082 taxon
= getTaxonService().findBestMatchingTaxon(scientificName
);
1085 if (taxon
== null && config
.isDoReUseTaxon()){
1087 names
= getTaxonService().searchTaxaByName(scientificName
, sec
);
1088 taxon
= (Taxon
)names
.get(0);
1089 } catch(Exception e
){
1093 logger
.info("Matching to existing Taxon : " + taxon
.getTitleCache());
1096 if (!config
.isDoReUseTaxon() || taxon
== null){
1097 getNameService().save(taxonName
);
1098 taxon
= Taxon
.NewInstance(taxonName
, sec
); //TODO sec set null
1101 // taxonName = NonViralName.NewInstance(null);
1102 // taxonName.setFullTitleCache(scientificName);
1104 // --- taxon is found now ---
1106 determinationEvent
= DeterminationEvent
.NewInstance();
1107 determinationEvent
.setTaxon(taxon
);
1108 determinationEvent
.setPreferredFlag(preferredFlag
);
1110 for (String strReference
: dataHolder
.referenceList
){
1112 ReferenceBase reference
= ReferenceFactory
.newGeneric();
1113 reference
.setTitleCache(strReference
, true);
1114 determinationEvent
.addReference(reference
);
1116 facade
.addDetermination(determinationEvent
);
1118 if(config
.isDoCreateIndividualsAssociations()){
1119 TaxonDescription taxonDescription
= null;
1120 if(config
.isDoMatchToExistingDescription()){
1121 logger
.error("The import option 'DoMatchToExistingDescription' is not yet implemented.");
1123 UUID taxonDescriptionUUID
= config
.getTaxonToDescriptionMap().get(taxon
.getUuid()); // rather put in state
1124 taxonDescription
= (TaxonDescription
) getDescriptionService().load(taxonDescriptionUUID
);
1125 if(taxonDescription
== null){
1126 taxonDescription
= TaxonDescription
.NewInstance(taxon
);
1127 config
.getTaxonToDescriptionMap().put(taxon
.getUuid(), taxonDescription
.getUuid());
1128 if(taxonDescriptionUUID
== null){
1129 logger
.info("Creating new TaxonDescription for " + taxon
.getTitleCache());
1131 logger
.fatal("TaxonDescription with UUID " + taxonDescriptionUUID
+ " not found --> creating a new one.");
1135 IndividualsAssociation individualsAssociation
= IndividualsAssociation
.NewInstance();
1136 individualsAssociation
.setAssociatedSpecimenOrObservation(facade
.getDerivedUnit());
1137 individualsAssociation
.setFeature(Feature
.INDIVIDUALS_ASSOCIATION());
1138 for(ReferenceBase citation
: determinationEvent
.getReferences()){
1139 individualsAssociation
.addSource(DescriptionElementSource
.NewInstance(null, null, citation
, null));
1141 taxonDescription
.addElement(individualsAssociation
);
1142 getDescriptionService().saveOrUpdate(taxonDescription
);
1148 private NonViralName
<?
> parseScientificName(String scientificName
, Abcd206DataHolder dataHolder
){
1149 NonViralNameParserImpl nvnpi
= NonViralNameParserImpl
.NewInstance();
1150 NonViralName
<?
>taxonName
= null;
1151 boolean problem
=false;
1153 if (dataHolder
.nomenclatureCode
.toString().equals("Zoological")){
1154 taxonName
= (ZoologicalName
)nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICZN
,null);
1155 if (taxonName
.hasProblem()){
1159 if (dataHolder
.nomenclatureCode
.toString().equals("Botanical")){
1160 taxonName
= (BotanicalName
)nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICBN
,null);
1161 if (taxonName
.hasProblem()){
1165 if (dataHolder
.nomenclatureCode
.toString().equals("Bacterial")){
1166 taxonName
= (BacterialName
)nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICNB
, null);
1167 if (taxonName
.hasProblem()){
1171 if (dataHolder
.nomenclatureCode
.toString().equals("Cultivar")){
1172 taxonName
= (CultivarPlantName
)nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICNCP
, null);
1173 if (taxonName
.hasProblem()){
1177 // if (this.nomenclatureCode.toString().equals("Viral")){
1178 // ViralName taxonName = (ViralName)nvnpi.parseFullName(scientificName,NomenclaturalCode.ICVCN(), null);
1179 // if (taxonName.hasProblem())
1180 // logger.info("pb ICVCN");
1182 //TODO: parsing of ViralNames?
1184 taxonName
= NonViralName
.NewInstance(null);
1185 taxonName
.setTitleCache(scientificName
, true);
1191 private NonViralName
<?
> setTaxonNameByType(HashMap
<String
, String
> atomisedMap
,String fullName
, Abcd206DataHolder dataHolder
){
1192 if (dataHolder
.nomenclatureCode
.equals("Zoological")){
1193 NonViralName
<ZoologicalName
> taxonName
= ZoologicalName
.NewInstance(null);
1194 taxonName
.setFullTitleCache(fullName
, true);
1195 taxonName
.setGenusOrUninomial(getFromMap(atomisedMap
,"Genus"));
1196 taxonName
.setInfraGenericEpithet(getFromMap(atomisedMap
,"SubGenus"));
1197 taxonName
.setSpecificEpithet(getFromMap(atomisedMap
,"SpeciesEpithet"));
1198 taxonName
.setInfraSpecificEpithet(getFromMap(atomisedMap
,"SubspeciesEpithet"));
1200 if(getFromMap(atomisedMap
,"AuthorTeamParenthesis") != null){
1201 team
= Team
.NewInstance();
1202 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeamParenthesis"), true);
1204 if (getFromMap(atomisedMap
,"AuthorTeamAndYear") != null){
1205 team
= Team
.NewInstance();
1206 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeamAndYear"), true);
1210 taxonName
.setBasionymAuthorTeam(team
);
1212 if(getFromMap(atomisedMap
,"AuthorTeamParenthesis") != null){
1213 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
,"AuthorTeamParenthesis"));
1214 } else if (getFromMap(atomisedMap
,"AuthorTeamAndYear") != null){
1215 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
,"AuthorTeamAndYear"));
1218 if(getFromMap(atomisedMap
,"CombinationAuthorTeamAndYear") != null){
1219 team
= Team
.NewInstance();
1220 team
.setTitleCache(getFromMap(atomisedMap
,"CombinationAuthorTeamAndYear"), true);
1221 taxonName
.setCombinationAuthorTeam(team
);
1223 if (taxonName
.hasProblem()){
1224 logger
.info("pb ICZN");
1229 if (dataHolder
.nomenclatureCode
.equals("Botanical")){
1230 NonViralName
<BotanicalName
> taxonName
= BotanicalName
.NewInstance(null);
1231 taxonName
.setFullTitleCache(fullName
, true);
1232 taxonName
.setGenusOrUninomial(getFromMap(atomisedMap
,"Genus"));
1233 taxonName
.setInfraGenericEpithet(getFromMap(atomisedMap
,"FirstEpithet"));
1234 taxonName
.setInfraSpecificEpithet(getFromMap(atomisedMap
,"InfraSpeEpithet"));
1235 try{taxonName
.setRank(Rank
.getRankByName(getFromMap(atomisedMap
,"Rank")));
1236 }catch(Exception e
){}
1238 if(getFromMap(atomisedMap
,"AuthorTeamParenthesis") != null){
1239 team
= Team
.NewInstance();
1240 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeamParenthesis"), true);
1242 taxonName
.setBasionymAuthorTeam(team
);
1245 if (getFromMap(atomisedMap
,"AuthorTeam") != null){
1246 team
= Team
.NewInstance();
1247 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeam"), true);
1249 taxonName
.setCombinationAuthorTeam(team
);
1253 if(getFromMap(atomisedMap
,"AuthorTeamParenthesis") != null){
1254 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
,"AuthorTeamParenthesis"));
1255 }else if (getFromMap(atomisedMap
,"AuthorTeam") != null){
1256 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
,"AuthorTeam"));
1259 if(getFromMap(atomisedMap
,"CombinationAuthorTeamAndYear") != null){
1260 team
= Team
.NewInstance();
1261 team
.setTitleCache(getFromMap(atomisedMap
,"CombinationAuthorTeamAndYear"), true);
1262 taxonName
.setCombinationAuthorTeam(team
);
1264 if (taxonName
.hasProblem()){
1265 logger
.info("pb ICBN");
1270 if (dataHolder
.nomenclatureCode
.equals("Bacterial")){
1271 NonViralName
<BacterialName
> taxonName
= BacterialName
.NewInstance(null);
1272 taxonName
.setFullTitleCache(fullName
, true);
1273 taxonName
.setGenusOrUninomial(getFromMap(atomisedMap
,"Genus"));
1274 taxonName
.setInfraGenericEpithet(getFromMap(atomisedMap
,"SubGenus"));
1275 taxonName
.setSpecificEpithet(getFromMap(atomisedMap
,"Species"));
1276 taxonName
.setInfraSpecificEpithet(getFromMap(atomisedMap
,"SubspeciesEpithet"));
1277 if(getFromMap(atomisedMap
,"AuthorTeamAndYear") != null){
1278 Team team
= Team
.NewInstance();
1279 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeamAndYear"), true);
1280 taxonName
.setCombinationAuthorTeam(team
);
1282 if(getFromMap(atomisedMap
,"ParentheticalAuthorTeamAndYear") != null){
1283 Team team
= Team
.NewInstance();
1284 team
.setTitleCache(getFromMap(atomisedMap
,"ParentheticalAuthorTeamAndYear"), true);
1285 taxonName
.setBasionymAuthorTeam(team
);
1287 if (taxonName
.hasProblem()){
1288 logger
.info("pb ICNB");
1293 if (dataHolder
.nomenclatureCode
.equals("Cultivar")){
1294 CultivarPlantName taxonName
= CultivarPlantName
.NewInstance(null);
1296 if (taxonName
.hasProblem()){
1297 logger
.info("pb ICNCP");
1302 // if (this.nomenclatureCode.equals("Viral")){
1303 // ViralName taxonName = ViralName.NewInstance(null);
1304 // taxonName.setFullTitleCache(fullName, true);
1305 // taxonName.setAcronym(getFromMap(atomisedMap,"Acronym"));
1306 // if (taxonName.hasProblem())
1307 // logger.info("pb ICVCN");
1308 // else return taxonName;
1311 NonViralName
<?
>taxonName
= NonViralName
.NewInstance(null);
1312 taxonName
.setFullTitleCache(fullName
, true);
1316 private String
getFromMap(HashMap
<String
, String
> atomisedMap
, String key
){
1317 String value
= null;
1318 if (atomisedMap
.containsKey(key
)){
1319 value
= atomisedMap
.get(key
);
1322 if (value
!= null && key
.matches(".*Year.*")){
1324 if (value
.matches("[a-z A-Z ]*[0-9]{4}$")){
1325 String tmp
=value
.split("[0-9]{4}$")[0];
1326 int year
= Integer
.parseInt(value
.split(tmp
)[1]);
1336 }catch(Exception e
){value
=null;}
1341 private void compareABCDtoCDM(URI urlFileName
, ArrayList
<String
> knownElts
, Abcd206DataHolder dataHolder
){
1344 DocumentBuilderFactory factory
= DocumentBuilderFactory
.newInstance();
1345 DocumentBuilder constructeur
= factory
.newDocumentBuilder();
1346 URL url
= urlFileName
.toURL();
1347 Object o
= url
.getContent();
1348 InputStream is
= (InputStream
)o
;
1349 Document document
= constructeur
.parse(is
);
1350 Element root
= document
.getDocumentElement();
1351 traverse(root
, dataHolder
);
1352 } catch (ParserConfigurationException e
) {
1353 e
.printStackTrace();
1354 } catch (SAXException e
) {
1355 e
.printStackTrace();
1356 } catch (IOException e
) {
1357 e
.printStackTrace();
1359 Set
<String
> elts
= dataHolder
.allABCDelements
.keySet();
1360 Iterator
< String
>it
= elts
.iterator();
1362 while (it
.hasNext()){
1364 if (knownElts
.indexOf(elt
) == -1){
1365 logger
.info("Unsaved ABCD element: " + elt
+ " - " + dataHolder
.allABCDelements
.get(elt
));
1373 * Traverses the tree for compareABCDtoCDM
1377 private void traverse(Node node
, Abcd206DataHolder dataHolder
){
1378 // Extract node info:
1379 String test
= node
.getTextContent();
1381 // Print and continue traversing.
1382 if(test
!= null && test
!= "#text" && node
.getNodeName() != "#text" && test
.split("\n").length
==1 && test
.length()>0){
1383 path
=node
.getNodeName();
1384 getHierarchie(node
);
1385 dataHolder
.allABCDelements
.put(path
,test
);
1388 // Now traverse the rest of the tree in depth-first order.
1389 if (node
.hasChildNodes()) {
1390 // Get the children in a list.
1391 NodeList nl
= node
.getChildNodes();
1392 // How many of them?
1393 int size
= nl
.getLength();
1394 for (int i
=0; i
<size
; i
++){
1395 // Recursively traverse each of the children.
1396 traverse (nl
.item(i
), dataHolder
);
1404 protected boolean isIgnore(Abcd206ImportState state
) {
1405 //return ! config.isDoNameFacts();