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
.abcd206
;
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
;
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
.common
.MediaMetaData
;
36 import eu
.etaxonomy
.cdm
.common
.MediaMetaData
.ImageMetaData
;
37 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
38 import eu
.etaxonomy
.cdm
.io
.common
.ICdmIO
;
39 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
40 import eu
.etaxonomy
.cdm
.io
.common
.MapWrapper
;
41 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
42 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
43 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
44 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
45 import eu
.etaxonomy
.cdm
.model
.media
.ImageFile
;
46 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
47 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
48 import eu
.etaxonomy
.cdm
.model
.name
.BacterialName
;
49 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
50 import eu
.etaxonomy
.cdm
.model
.name
.CultivarPlantName
;
51 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
52 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
53 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
54 import eu
.etaxonomy
.cdm
.model
.name
.ZoologicalName
;
55 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
56 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEvent
;
57 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
58 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnitBase
;
59 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
60 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldObservation
;
61 import eu
.etaxonomy
.cdm
.model
.occurrence
.LivingBeing
;
62 import eu
.etaxonomy
.cdm
.model
.occurrence
.Observation
;
63 import eu
.etaxonomy
.cdm
.model
.occurrence
.Specimen
;
64 import eu
.etaxonomy
.cdm
.model
.reference
.Generic
;
65 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
66 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
67 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
68 import eu
.etaxonomy
.cdm
.strategy
.parser
.NonViralNameParserImpl
;
77 public class AbcdIO
extends SpecimenIoBase
implements ICdmIO
<IImportConfigurator
> {
78 private static final Logger logger
= Logger
.getLogger(AbcdIO
.class);
80 protected String fullScientificNameString
;
81 protected String atomisedStr
;
82 protected String nomenclatureCode
;
83 protected String institutionCode
;
84 protected String collectionCode
;
85 protected String unitID
;
86 protected String recordBasis
;
87 protected String accessionNumber
;
88 protected String collectorsNumber
;
89 protected String fieldNumber
;
90 protected Double longitude
;
91 protected Double latitude
;
92 protected String locality
;
93 protected String languageIso
= null;
94 protected String country
;
95 protected String isocountry
;
97 protected int altitude
;
98 protected ArrayList
<String
> gatheringAgentList
;
99 protected ArrayList
<String
> identificationList
;
100 protected ArrayList
<HashMap
<String
, String
>> atomisedIdentificationList
;
101 protected ArrayList
<String
> namedAreaList
;
102 protected ArrayList
<String
> referenceList
;
103 protected ArrayList
<String
> multimediaObjects
;
106 protected ArrayList
<String
> knownABCDelements
= new ArrayList
<String
>();
107 protected HashMap
<String
,String
> allABCDelements
= new HashMap
<String
,String
>();
116 protected boolean doCheck(IImportConfigurator config
) {
117 logger
.warn("Checking not yet implemented for AbcdIO.class");
122 * Return the list of root nodes for an ABCD 2.06 XML file
123 * @param fileName: the file's location
124 * @return the list of root nodes ("Unit")
126 private static NodeList
getUnitsNodeList(String urlFileName
){
127 NodeList unitList
= null;
129 DocumentBuilderFactory fabrique
= DocumentBuilderFactory
.newInstance();
130 DocumentBuilder constructeur
= fabrique
.newDocumentBuilder();
131 URL url
= new URL(urlFileName
);
132 Object o
= url
.getContent();
133 InputStream is
= (InputStream
)o
;
134 Document document
= constructeur
.parse(is
);
135 Element racine
= document
.getDocumentElement();
136 unitList
= racine
.getElementsByTagName("Unit");
146 * Store the unit's properties into variables
147 * Look which unit is the preferred one
148 * Look what kind of name it is supposed to be, for the parsing (Botanical, Zoological)
149 * @param racine: the root node for a single unit
151 private void setUnitPropertiesXML(Element racine
){
155 // try{afficherInfos(racine, 0);}catch (Exception e) {logger.info(e);}
156 group
= racine
.getChildNodes();
157 // logger.info("ABCD ELEMENT not stored: "+group.item(i).getNodeName().toString()+" - value: "+group.item(i).getTextContent());
158 for (int i
=0; i
< group
.getLength(); i
++){
159 if (group
.item(i
).getNodeName().equals("Identifications")){
160 group
= group
.item(i
).getChildNodes();
164 this.identificationList
= new ArrayList
<String
>();
165 this.atomisedIdentificationList
= new ArrayList
<HashMap
<String
, String
>>();
166 this.referenceList
= new ArrayList
<String
>();
167 this.multimediaObjects
= new ArrayList
<String
>();
169 this.getScientificNames(group
);
171 // logger.info("this.identificationList "+this.identificationList.toString());
173 this.getRecordBasis(racine
);
174 this.getMultimedia(racine
);
175 this.getNumbers(racine
);
176 this.getGeolocation(racine
);
177 this.getGatheringPeople(racine
);
179 } catch (Exception e
) {
180 logger
.info("Error occured while parsing XML file"+e
);
185 private void getHierarchie(Node node
){
186 while (node
!= null && node
.getNodeName() != "DataSets"){
187 // logger.info(node.getParentNode().getNodeName());
188 path
= node
.getParentNode().getNodeName()+"/"+path
;
189 node
= node
.getParentNode();
191 // logger.info("path: "+path);
194 private void getScientificNames(NodeList group
){
195 NodeList identifications
,results
;
196 String tmpName
= null;
197 for (int j
=0; j
< group
.getLength(); j
++){
198 if(group
.item(j
).getNodeName().equals("Identification")){
199 this.nomenclatureCode
="";
200 identifications
= group
.item(j
).getChildNodes();
201 for (int m
=0; m
<identifications
.getLength();m
++){
202 if(identifications
.item(m
).getNodeName().equals("Result")){
203 results
= identifications
.item(m
).getChildNodes();
204 for(int k
=0; k
<results
.getLength();k
++)
205 if (results
.item(k
).getNodeName().equals("TaxonIdentified")){
206 tmpName
=this.getScientificName(results
.item(k
));
209 else if(identifications
.item(m
).getNodeName().equals("PreferredFlag")){
210 if (this.nomenclatureCode
!= null && this.nomenclatureCode
!="")
211 this.identificationList
.add(tmpName
+"_preferred_"+identifications
.item(m
).getTextContent()+"_code_"+this.nomenclatureCode
);
213 this.identificationList
.add(tmpName
+"_preferred_"+identifications
.item(m
).getTextContent());
214 path
=identifications
.item(m
).getNodeName();
215 getHierarchie(identifications
.item(m
));
216 knownABCDelements
.add(path
);
220 else if (identifications
.item(m
).getNodeName().equals("References"))
221 this.getReferences(identifications
.item(m
));
225 boolean hasPref
=false;
226 for (int j
=0; j
< group
.getLength(); j
++){
227 if(group
.item(j
).getNodeName().equals("Identification")){
228 this.nomenclatureCode
="";
229 identifications
= group
.item(j
).getChildNodes();
230 for (int m
=0; m
<identifications
.getLength();m
++){
231 if(identifications
.item(m
).getNodeName().equals("Result")){
232 results
= identifications
.item(m
).getChildNodes();
233 for(int k
=0; k
<results
.getLength();k
++)
234 if (results
.item(k
).getNodeName().equals("TaxonIdentified")){
235 tmpName
=this.getScientificName(results
.item(k
));
238 if(identifications
.item(m
).getNodeName().equals("PreferredFlag")){
242 if ( !hasPref
&& tmpName
!= null)
243 if (this.nomenclatureCode
!= null && this.nomenclatureCode
!="")
244 this.identificationList
.add(tmpName
+"_preferred_"+"0"+"_code_"+this.nomenclatureCode
);
246 this.identificationList
.add(tmpName
+"_preferred_"+"0");
254 private void getReferences(Node result
){
255 NodeList results
,reference
;
256 results
= result
.getChildNodes();
257 for(int k
=0; k
<results
.getLength();k
++){
258 if (results
.item(k
).getNodeName().equals("Reference")){
259 reference
= results
.item(k
).getChildNodes();
260 for(int l
=0;l
<reference
.getLength();l
++){
261 if (reference
.item(l
).getNodeName().equals("TitleCitation")){
262 path
= reference
.item(l
).getNodeName();
263 referenceList
.add(reference
.item(l
).getTextContent());
264 getHierarchie(reference
.item(l
));
265 knownABCDelements
.add(path
);
273 private String
getScientificName(Node result
){
274 NodeList taxonsIdentified
, scnames
, atomised
;
277 taxonsIdentified
= result
.getChildNodes();
278 for (int l
=0; l
<taxonsIdentified
.getLength(); l
++){
279 if (taxonsIdentified
.item(l
).getNodeName().equals("ScientificName")){
280 scnames
= taxonsIdentified
.item(l
).getChildNodes();
281 for (int n
=0;n
<scnames
.getLength();n
++){
282 if (scnames
.item(n
).getNodeName().equals("FullScientificNameString")){
283 path
=scnames
.item(n
).getNodeName();
284 tmpName
= scnames
.item(n
).getTextContent();
285 getHierarchie(scnames
.item(n
));
286 knownABCDelements
.add(path
);
289 if (scnames
.item(n
).getNodeName().equals("NameAtomised")){
291 if (scnames
.item(n
).hasChildNodes()){
292 this.nomenclatureCode
= scnames
.item(n
).getChildNodes().item(1).getNodeName();
294 } catch (Exception e
) {
295 this.nomenclatureCode
="";
297 atomised
= scnames
.item(n
).getChildNodes().item(1).getChildNodes();
298 this.atomisedIdentificationList
.add(this.getAtomisedNames(nomenclatureCode
,atomised
));
306 private HashMap
<String
,String
> getAtomisedNames(String code
, NodeList atomised
){
307 if (code
.equals("Botanical"))
308 return this.getAtomisedBotanical(atomised
);
309 if (code
.equals("Bacterial"))
310 return this.getAtomisedBacterial(atomised
);
311 if (code
.equals("NameViral"))
312 return this.getAtomisedViral(atomised
);
313 if (code
.equals("NameZoological"))
314 return this.getAtomisedZoological(atomised
);
315 return new HashMap
<String
,String
>();
318 private HashMap
<String
,String
> getAtomisedZoological(NodeList atomised
){
319 HashMap
<String
,String
> atomisedMap
= new HashMap
<String
,String
>();
320 for (int i
=0;i
<atomised
.getLength();i
++){
321 if(atomised
.item(i
).getNodeName().equals("GenusOrMonomial")){
322 atomisedMap
.put("Genus",atomised
.item(i
).getTextContent());
323 path
=atomised
.item(i
).getNodeName();
324 getHierarchie(atomised
.item(i
));
325 knownABCDelements
.add(path
);
328 if(atomised
.item(i
).getNodeName().equals("Subgenus")){
329 atomisedMap
.put("Subgenus",atomised
.item(i
).getTextContent());
330 path
=atomised
.item(i
).getNodeName();
331 getHierarchie(atomised
.item(i
));
332 knownABCDelements
.add(path
);
335 if(atomised
.item(i
).getNodeName().equals("SpeciesEpithet")){
336 atomisedMap
.put("SpeciesEpithet",atomised
.item(i
).getTextContent());
337 path
=atomised
.item(i
).getNodeName();
338 getHierarchie(atomised
.item(i
));
339 knownABCDelements
.add(path
);
342 if(atomised
.item(i
).getNodeName().equals("SubspeciesEpithet")){
343 atomisedMap
.put("SubspeciesEpithet",atomised
.item(i
).getTextContent());
344 path
=atomised
.item(i
).getNodeName();
345 getHierarchie(atomised
.item(i
));
346 knownABCDelements
.add(path
);
349 if(atomised
.item(i
).getNodeName().equals("AuthorTeamOriginalAndYear")){
350 atomisedMap
.put("AuthorTeamOriginalAndYear",atomised
.item(i
).getTextContent());
351 path
=atomised
.item(i
).getNodeName();
352 getHierarchie(atomised
.item(i
));
353 knownABCDelements
.add(path
);
355 if(atomised
.item(i
).getNodeName().equals("AuthorTeamParenthesisAndYear")){
356 atomisedMap
.put("AuthorTeamParenthesisAndYear",atomised
.item(i
).getTextContent());
357 path
=atomised
.item(i
).getNodeName();
358 getHierarchie(atomised
.item(i
));
359 knownABCDelements
.add(path
);
361 if(atomised
.item(i
).getNodeName().equals("CombinationAuthorTeamAndYear")){
362 atomisedMap
.put("CombinationAuthorTeamAndYear",atomised
.item(i
).getTextContent());
363 path
=atomised
.item(i
).getNodeName();
364 getHierarchie(atomised
.item(i
));
365 knownABCDelements
.add(path
);
367 if(atomised
.item(i
).getNodeName().equals("Breed")){
368 atomisedMap
.put("Breed",atomised
.item(i
).getTextContent());
369 path
=atomised
.item(i
).getNodeName();
370 getHierarchie(atomised
.item(i
));
371 knownABCDelements
.add(path
);
373 if(atomised
.item(i
).getNodeName().equals("NamedIndividual")){
374 atomisedMap
.put("NamedIndividual",atomised
.item(i
).getTextContent());
375 path
=atomised
.item(i
).getNodeName();
376 getHierarchie(atomised
.item(i
));
377 knownABCDelements
.add(path
);
385 private HashMap
<String
,String
> getAtomisedViral(NodeList atomised
){
386 HashMap
<String
,String
> atomisedMap
= new HashMap
<String
,String
>();
387 for (int i
=0;i
<atomised
.getLength();i
++){
388 if(atomised
.item(i
).getNodeName().equals("GenusOrMonomial")){
389 atomisedMap
.put("Genus",atomised
.item(i
).getTextContent());
390 path
=atomised
.item(i
).getNodeName();
391 getHierarchie(atomised
.item(i
));
392 knownABCDelements
.add(path
);
395 if(atomised
.item(i
).getNodeName().equals("ViralSpeciesDesignation")){
396 atomisedMap
.put("ViralSpeciesDesignation", atomised
.item(i
).getTextContent());
397 path
=atomised
.item(i
).getNodeName();
398 getHierarchie(atomised
.item(i
));
399 knownABCDelements
.add(path
);
402 if(atomised
.item(i
).getNodeName().equals("Acronym")){
403 atomisedMap
.put("Acronym",atomised
.item(i
).getTextContent());
404 path
=atomised
.item(i
).getNodeName();
405 getHierarchie(atomised
.item(i
));
406 knownABCDelements
.add(path
);
413 private HashMap
<String
,String
> getAtomisedBotanical(NodeList atomised
){
414 HashMap
<String
,String
> atomisedMap
= new HashMap
<String
,String
>();
415 for (int i
=0;i
<atomised
.getLength();i
++){
416 if(atomised
.item(i
).getNodeName().equals("GenusOrMonomial")){
417 atomisedMap
.put("Genus",atomised
.item(i
).getTextContent());
418 path
=atomised
.item(i
).getNodeName();
419 getHierarchie(atomised
.item(i
));
420 knownABCDelements
.add(path
);
423 if(atomised
.item(i
).getNodeName().equals("FirstEpithet")){
424 atomisedMap
.put("FirstEpithet",atomised
.item(i
).getTextContent());
425 path
=atomised
.item(i
).getNodeName();
426 getHierarchie(atomised
.item(i
));
427 knownABCDelements
.add(path
);
430 if(atomised
.item(i
).getNodeName().equals("InfraspecificEpithet")){
431 atomisedMap
.put("InfraSpeEpithet", atomised
.item(i
).getTextContent());
432 path
=atomised
.item(i
).getNodeName();
433 getHierarchie(atomised
.item(i
));
434 knownABCDelements
.add(path
);
437 if(atomised
.item(i
).getNodeName().equals("Rank")){
438 atomisedMap
.put("Rank",atomised
.item(i
).getTextContent());
439 path
=atomised
.item(i
).getNodeName();
440 getHierarchie(atomised
.item(i
));
441 knownABCDelements
.add(path
);
444 if(atomised
.item(i
).getNodeName().equals("HybridFlag")){
445 atomisedMap
.put("HybridFlag",atomised
.item(i
).getTextContent());
446 path
=atomised
.item(i
).getNodeName();
447 getHierarchie(atomised
.item(i
));
448 knownABCDelements
.add(path
);
451 if(atomised
.item(i
).getNodeName().equals("AuthorTeamParenthesis")){
452 atomisedMap
.put("AuthorTeamParenthesis",atomised
.item(i
).getTextContent());
453 path
=atomised
.item(i
).getNodeName();
454 getHierarchie(atomised
.item(i
));
455 knownABCDelements
.add(path
);
458 if(atomised
.item(i
).getNodeName().equals("AuthorTeam")){
459 atomisedMap
.put("AuthorTeam",atomised
.item(i
).getTextContent());
460 path
=atomised
.item(i
).getNodeName();
461 getHierarchie(atomised
.item(i
));
462 knownABCDelements
.add(path
);
465 if(atomised
.item(i
).getNodeName().equals("CultivarGroupName")){
466 atomisedMap
.put("CultivarGroupName",atomised
.item(i
).getTextContent());
467 path
=atomised
.item(i
).getNodeName();
468 getHierarchie(atomised
.item(i
));
469 knownABCDelements
.add(path
);
472 if(atomised
.item(i
).getNodeName().equals("CultivarName")){
473 atomisedMap
.put("CultivarName",atomised
.item(i
).getTextContent());
474 path
=atomised
.item(i
).getNodeName();
475 getHierarchie(atomised
.item(i
));
476 knownABCDelements
.add(path
);
479 if(atomised
.item(i
).getNodeName().equals("TradeDesignationNames")){
480 atomisedMap
.put("Trade",atomised
.item(i
).getTextContent());
481 path
=atomised
.item(i
).getNodeName();
482 getHierarchie(atomised
.item(i
));
483 knownABCDelements
.add(path
);
490 private HashMap
<String
,String
> getAtomisedBacterial(NodeList atomised
){
491 HashMap
<String
,String
> atomisedMap
= new HashMap
<String
,String
>();
492 for (int i
=0;i
<atomised
.getLength();i
++){
493 if(atomised
.item(i
).getNodeName().equals("GenusOrMonomial")){
494 atomisedMap
.put("Genus",atomised
.item(i
).getTextContent());
495 path
=atomised
.item(i
).getNodeName();
496 getHierarchie(atomised
.item(i
));
497 knownABCDelements
.add(path
);
500 if(atomised
.item(i
).getNodeName().equals("Subgenus")){
501 atomisedMap
.put("SubGenus",atomised
.item(i
).getTextContent());
502 path
=atomised
.item(i
).getNodeName();
503 getHierarchie(atomised
.item(i
));
504 knownABCDelements
.add(path
);
507 if(atomised
.item(i
).getNodeName().equals("SubgenusAuthorAndYear")){
508 atomisedMap
.put("SubgenusAuthorAndYear",atomised
.item(i
).getTextContent());
509 path
=atomised
.item(i
).getNodeName();
510 getHierarchie(atomised
.item(i
));
511 knownABCDelements
.add(path
);
514 if(atomised
.item(i
).getNodeName().equals("SpeciesEpithet")){
515 atomisedMap
.put("SpeciesEpithet",atomised
.item(i
).getTextContent());
516 path
=atomised
.item(i
).getNodeName();
517 getHierarchie(atomised
.item(i
));
518 knownABCDelements
.add(path
);
521 if(atomised
.item(i
).getNodeName().equals("SubspeciesEpithet")){
522 atomisedMap
.put("SubspeciesEpithet",atomised
.item(i
).getTextContent());
523 path
=atomised
.item(i
).getNodeName();
524 getHierarchie(atomised
.item(i
));
525 knownABCDelements
.add(path
);
528 if(atomised
.item(i
).getNodeName().equals("ParentheticalAuthorTeamAndYear")){
529 atomisedMap
.put("ParentheticalAuthorTeamAndYear",atomised
.item(i
).getTextContent());
530 path
=atomised
.item(i
).getNodeName();
531 getHierarchie(atomised
.item(i
));
532 knownABCDelements
.add(path
);
535 if(atomised
.item(i
).getNodeName().equals("AuthorTeamAndYear")){
536 atomisedMap
.put("AuthorTeamAndYear",atomised
.item(i
).getTextContent());
537 path
=atomised
.item(i
).getNodeName();
538 getHierarchie(atomised
.item(i
));
539 knownABCDelements
.add(path
);
542 if(atomised
.item(i
).getNodeName().equals("NameApprobation")){
543 atomisedMap
.put("NameApprobation",atomised
.item(i
).getTextContent());
544 path
=atomised
.item(i
).getNodeName();
545 getHierarchie(atomised
.item(i
));
546 knownABCDelements
.add(path
);
553 private void getIDs(Element racine
){
556 group
= racine
.getElementsByTagName("SourceInstitutionID");
557 path
=group
.item(0).getNodeName();
558 getHierarchie(group
.item(0));
559 knownABCDelements
.add(path
);
561 this.institutionCode
= group
.item(0).getTextContent();
562 } catch (NullPointerException e
) {
563 this.institutionCode
= "";
566 group
= racine
.getElementsByTagName("SourceID");
567 path
=group
.item(0).getNodeName();
568 getHierarchie(group
.item(0));
569 knownABCDelements
.add(path
);
571 this.collectionCode
= group
.item(0).getTextContent();
572 } catch (NullPointerException e
) {
573 this.collectionCode
= "";
576 group
= racine
.getElementsByTagName("UnitID");
577 path
=group
.item(0).getNodeName();
578 getHierarchie(group
.item(0));
579 knownABCDelements
.add(path
);
581 this.unitID
= group
.item(0).getTextContent();
582 } catch (NullPointerException e
) {
587 private void getRecordBasis(Element racine
){
590 group
= racine
.getElementsByTagName("RecordBasis");
591 path
=group
.item(0).getNodeName();
592 getHierarchie(group
.item(0));
593 knownABCDelements
.add(path
);
595 this.recordBasis
= group
.item(0).getTextContent();
596 } catch (NullPointerException e
) {
597 this.recordBasis
= "";
601 private void getMultimedia(Element racine
){
602 NodeList group
, multimedias
, multimedia
;
604 group
= racine
.getElementsByTagName("MultiMediaObjects");
605 for(int i
=0;i
<group
.getLength();i
++){
606 multimedias
= group
.item(i
).getChildNodes();
607 for (int j
=0;j
<multimedias
.getLength();j
++){
608 if (multimedias
.item(j
).getNodeName().equals("MultiMediaObject")){
609 multimedia
= multimedias
.item(j
).getChildNodes();
610 for (int k
=0;k
<multimedia
.getLength();k
++){
611 if(multimedia
.item(k
).getNodeName().equals("FileURI")){
612 this.multimediaObjects
.add(multimedia
.item(k
).getTextContent());
613 path
= multimedia
.item(k
).getNodeName();
614 getHierarchie(multimedia
.item(k
));
615 knownABCDelements
.add(path
);
622 } catch (NullPointerException e
) {
627 private void getNumbers(Element racine
){
630 group
= racine
.getElementsByTagName("AccessionNumber");
631 path
=group
.item(0).getNodeName();
632 getHierarchie(group
.item(0));
633 knownABCDelements
.add(path
);
635 this.accessionNumber
= group
.item(0).getTextContent();
636 } catch (NullPointerException e
) {
637 this.accessionNumber
= "";
640 group
= racine
.getElementsByTagName("CollectorsFieldNumber");
641 path
=group
.item(0).getNodeName();
642 getHierarchie(group
.item(0));
643 knownABCDelements
.add(path
);
645 this.fieldNumber
= group
.item(0).getTextContent();
646 } catch (NullPointerException e
) {
647 this.fieldNumber
= "";
651 group
= racine
.getElementsByTagName("CollectorsNumber");
652 path
=group
.item(0).getNodeName();
653 getHierarchie(group
.item(0));
654 knownABCDelements
.add(path
);
656 this.collectorsNumber
= group
.item(0).getTextContent();
657 } catch (NullPointerException e
) {
658 this.collectorsNumber
= "";
662 group
= racine
.getElementsByTagName("AccessionNumber");
663 path
=group
.item(0).getNodeName();
664 getHierarchie(group
.item(0));
665 knownABCDelements
.add(path
);
667 this.accessionNumber
= group
.item(0).getTextContent();
668 } catch (NullPointerException e
) {
669 this.accessionNumber
= "";
673 private void getGeolocation(Element racine
){
674 NodeList group
, childs
;
676 group
= racine
.getElementsByTagName("LocalityText");
677 path
=group
.item(0).getNodeName();
678 getHierarchie(group
.item(0));
679 knownABCDelements
.add(path
);
681 this.locality
= group
.item(0).getTextContent();
682 if (group
.item(0).hasAttributes())
683 if (group
.item(0).getAttributes().getNamedItem("lang") != null)
684 this.languageIso
= group
.item(0).getAttributes().getNamedItem("lang").getTextContent();
685 } catch (NullPointerException e
) {
689 group
= racine
.getElementsByTagName("LongitudeDecimal");
690 path
=group
.item(0).getNodeName();
691 getHierarchie(group
.item(0));
692 knownABCDelements
.add(path
);
694 this.longitude
= Double
.valueOf(group
.item(0).getTextContent());
695 } catch (NullPointerException e
) {
699 group
= racine
.getElementsByTagName("LatitudeDecimal");
700 path
=group
.item(0).getNodeName();
701 getHierarchie(group
.item(0));
702 knownABCDelements
.add(path
);
704 this.latitude
= Double
.valueOf(group
.item(0).getTextContent());
705 } catch (NullPointerException e
) {
709 group
= racine
.getElementsByTagName("Country");
710 childs
= group
.item(0).getChildNodes();
711 for (int i
=0;i
<childs
.getLength(); i
++){
712 if(childs
.item(i
).getNodeName() == "Name"){
713 path
=childs
.item(i
).getNodeName();
714 getHierarchie(childs
.item(i
));
715 knownABCDelements
.add(path
);
717 this.country
= childs
.item(i
).getTextContent();
720 } catch (NullPointerException e
) {
724 group
= racine
.getElementsByTagName("Country");
725 childs
= group
.item(0).getChildNodes();
726 for (int i
=0;i
<childs
.getLength(); i
++){
727 if(childs
.item(i
).getNodeName() == "ISO3166Code"){
728 path
=childs
.item(i
).getNodeName();
729 getHierarchie(childs
.item(i
));
730 knownABCDelements
.add(path
);
732 this.isocountry
= childs
.item(i
).getTextContent();
735 } catch (NullPointerException e
) {
736 this.isocountry
= "";
739 group
= racine
.getElementsByTagName("Altitude");
740 for (int i
=0;i
<group
.getLength();i
++){
741 childs
= group
.item(i
).getChildNodes();
742 for (int j
=0;j
<childs
.getLength();j
++){
743 if (childs
.item(j
).getNodeName().equals("MeasurementOrFactText")){
744 path
=childs
.item(j
).getNodeName();
745 getHierarchie(childs
.item(j
));
746 knownABCDelements
.add(path
);
748 this.altitude
= Integer
.valueOf(childs
.item(j
).getTextContent());
752 } catch (NullPointerException e
) {
753 this.altitude
= -9999;
757 group
= racine
.getElementsByTagName("Depth");
758 path
=group
.item(0).getNodeName();
759 getHierarchie(group
.item(0));
760 knownABCDelements
.add(path
);
762 this.depth
= Integer
.valueOf(group
.item(0).getTextContent());
763 } catch (NullPointerException e
) {
768 group
= racine
.getElementsByTagName("NamedArea");
769 this.namedAreaList
= new ArrayList
<String
>();
770 for (int i
=0;i
<group
.getLength();i
++){
771 childs
= group
.item(i
).getChildNodes();
772 for (int j
=0; j
<childs
.getLength();j
++){
773 if (childs
.item(j
).getNodeName().equals("AreaName")){
774 path
= childs
.item(j
).getNodeName();
775 getHierarchie(childs
.item(j
));
776 knownABCDelements
.add(path
);
778 this.namedAreaList
.add(childs
.item(j
).getTextContent());
782 }catch(NullPointerException e
){
783 this.namedAreaList
= new ArrayList
<String
>();
787 private void getGatheringPeople(Element racine
){
788 NodeList group
, childs
, person
;
790 group
= racine
.getElementsByTagName("GatheringAgent");
791 this.gatheringAgentList
= new ArrayList
<String
>();
792 for (int i
=0; i
< group
.getLength(); i
++){
793 childs
= group
.item(i
).getChildNodes();
794 for (int j
=0; j
<childs
.getLength();j
++){
795 if (childs
.item(j
).getNodeName().equals("Person")){
796 person
= childs
.item(j
).getChildNodes();
797 for (int k
=0; k
<person
.getLength(); k
++)
798 if (person
.item(k
).getNodeName().equals("FullName")){
799 path
=person
.item(k
).getNodeName();
800 getHierarchie(person
.item(k
));
801 knownABCDelements
.add(path
);
803 this.gatheringAgentList
.add(person
.item(k
).getTextContent());
809 } catch (NullPointerException e
) {
810 this.gatheringAgentList
= new ArrayList
<String
>();
814 private Institution
getInstitution(String institutionCode
, SpecimenImportConfigurator config
){
815 Institution institution
;
816 List
<Institution
> institutions
;
818 logger
.info(this.institutionCode
);
819 institutions
= getAgentService().searchInstitutionByCode(this.institutionCode
);
821 institutions
=new ArrayList
<Institution
>();
823 if (institutions
.size() ==0 || !config
.getReUseExistingMetadata()){
824 logger
.info("Institution (agent) unknown or not allowed to reuse existing metadata");
826 institution
= Institution
.NewInstance();
827 institution
.setCode(this.institutionCode
);
830 logger
.info("Institution (agent) already in the db");
831 institution
= institutions
.get(0);
837 * Look if the Collection does already exists
838 * @param collectionCode: a string
839 * @param institution: the current Institution
841 * @return the Collection (existing or new)
843 private Collection
getCollection(String collectionCode
, Institution institution
, SpecimenImportConfigurator config
){
844 Collection collection
= Collection
.NewInstance();
845 List
<Collection
> collections
;
847 collections
= getOccurrenceService().searchCollectionByCode(this.collectionCode
);
849 collections
=new ArrayList
<Collection
>();
851 if (collections
.size() ==0 || !config
.getReUseExistingMetadata()){
852 logger
.info("Collection not found or do not reuse existing metadata "+this.collectionCode
);
853 //create new collection
854 collection
.setCode(this.collectionCode
);
855 collection
.setCodeStandard("GBIF");
856 collection
.setInstitute(institution
);
859 boolean collectionFound
=false;
860 for (int i
=0; i
<collections
.size(); i
++){
861 collection
= collections
.get(i
);
863 if (collection
.getInstitute().getCode().equalsIgnoreCase(institution
.getCode())){
864 //found a collection with the same code and the same institution
865 collectionFound
=true;
867 } catch (NullPointerException e
) {}
869 if (!collectionFound
){
870 collection
.setCode(this.collectionCode
);
871 collection
.setCodeStandard("GBIF");
872 collection
.setInstitute(institution
);
882 * @param derivedThing
885 private void setTaxonNameBase(SpecimenImportConfigurator config
, DerivedUnitBase derivedThing
, ReferenceBase sec
){
886 NonViralName
<?
> taxonName
= null;
887 String fullScientificNameString
;
889 DeterminationEvent determinationEvent
= null;
890 List
<TaxonBase
> names
= null;
892 String scientificName
="";
893 boolean preferredFlag
=false;
895 for (int i
= 0; i
< this.identificationList
.size(); i
++) {
896 fullScientificNameString
= this.identificationList
.get(i
);
897 fullScientificNameString
= fullScientificNameString
.replaceAll(" et ", " & ");
898 if (fullScientificNameString
.indexOf("_preferred_") != -1){
899 scientificName
= fullScientificNameString
.split("_preferred_")[0];
900 String pTmp
= fullScientificNameString
.split("_preferred_")[1].split("_code_")[0];
901 if (pTmp
.equals("1") || pTmp
.toLowerCase().indexOf("true") != -1)
906 else scientificName
= fullScientificNameString
;
908 logger
.info(fullScientificNameString
);
909 if (fullScientificNameString
.indexOf("_code_") != -1)
910 this.nomenclatureCode
= fullScientificNameString
.split("_code_")[1];
912 if (config
.getDoAutomaticParsing() || this.atomisedIdentificationList
== null || this.atomisedIdentificationList
.size()==0)
913 taxonName
= this.parseScientificName(scientificName
);
915 if (this.atomisedIdentificationList
!= null || this.atomisedIdentificationList
.size()>0)
916 taxonName
= this.setTaxonNameByType(this.atomisedIdentificationList
.get(i
), scientificName
);
918 if(taxonName
== null){
919 taxonName
= NonViralName
.NewInstance(null);
920 taxonName
.setFullTitleCache(scientificName
);
922 if (config
.getDoReUseTaxon()){
924 names
= getTaxonService().searchTaxaByName(scientificName
, sec
);
925 taxon
= (Taxon
)names
.get(0);
927 catch(Exception e
){taxon
=null;}
929 // taxonName = NonViralName.NewInstance(null);
930 // taxonName.setFullTitleCache(scientificName);
932 if (!config
.getDoReUseTaxon() || taxon
== null){
933 getNameService().saveTaxonName(taxonName
);
934 taxon
= Taxon
.NewInstance(taxonName
, sec
); //sec set null
936 determinationEvent
= DeterminationEvent
.NewInstance();
937 determinationEvent
.setTaxon(taxon
);
938 determinationEvent
.setPreferredFlag(preferredFlag
);
939 for (int l
=0;l
<this.referenceList
.size();l
++){
940 ReferenceBase reference
= new Generic();
941 reference
.setTitleCache(this.referenceList
.get(l
));
942 determinationEvent
.addReference(reference
);
944 derivedThing
.addDetermination(determinationEvent
);
949 private NonViralName
<?
> parseScientificName(String scientificName
){
950 NonViralNameParserImpl nvnpi
= NonViralNameParserImpl
.NewInstance();
951 NonViralName
<?
>taxonName
= null;
952 boolean problem
=false;
954 if (this.nomenclatureCode
.toString().equals("Zoological")){
955 taxonName
= (ZoologicalName
)nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICZN
,null);
956 if (taxonName
.hasProblem())
959 if (this.nomenclatureCode
.toString().equals("Botanical")){
960 taxonName
= (BotanicalName
)nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICBN
,null);
961 if (taxonName
.hasProblem())
963 if (this.nomenclatureCode
.toString().equals("Bacterial")){
964 taxonName
= (BacterialName
)nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICNB
, null);
965 if (taxonName
.hasProblem())
968 if (this.nomenclatureCode
.toString().equals("Cultivar")){
969 taxonName
= (CultivarPlantName
)nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICNCP
, null);
970 if (taxonName
.hasProblem())
973 // if (this.nomenclatureCode.toString().equals("Viral")){
974 // ViralName taxonName = (ViralName)nvnpi.parseFullName(scientificName,NomenclaturalCode.ICVCN(), null);
975 // if (taxonName.hasProblem())
976 // logger.info("pb ICVCN");
978 //TODO: parsing of ViralNames?
980 taxonName
= NonViralName
.NewInstance(null);
981 taxonName
.setTitleCache(scientificName
);
987 @SuppressWarnings("unchecked")
988 private NonViralName
<?
> setTaxonNameByType(HashMap
<String
, String
> atomisedMap
,String fullName
){
989 if (this.nomenclatureCode
.equals("Zoological")){
990 NonViralName
<ZoologicalName
> taxonName
= ZoologicalName
.NewInstance(null);
991 taxonName
.setFullTitleCache(fullName
, true);
992 taxonName
.setGenusOrUninomial(getFromMap(atomisedMap
,"Genus"));
993 taxonName
.setInfraGenericEpithet(getFromMap(atomisedMap
,"SubGenus"));
994 taxonName
.setSpecificEpithet(getFromMap(atomisedMap
,"SpeciesEpithet"));
995 taxonName
.setInfraSpecificEpithet(getFromMap(atomisedMap
,"SubspeciesEpithet"));
997 if(getFromMap(atomisedMap
,"AuthorTeamParenthesis") != null){
998 team
= Team
.NewInstance();
999 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeamParenthesis"));
1001 if (getFromMap(atomisedMap
,"AuthorTeamAndYear") != null){
1002 team
= Team
.NewInstance();
1003 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeamAndYear"));
1007 taxonName
.setBasionymAuthorTeam(team
);
1009 if(getFromMap(atomisedMap
,"AuthorTeamParenthesis") != null)
1010 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
,"AuthorTeamParenthesis"));
1011 else if (getFromMap(atomisedMap
,"AuthorTeamAndYear") != null)
1012 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
,"AuthorTeamAndYear"));
1014 if(getFromMap(atomisedMap
,"CombinationAuthorTeamAndYear") != null){
1015 team
= Team
.NewInstance();
1016 team
.setTitleCache(getFromMap(atomisedMap
,"CombinationAuthorTeamAndYear"));
1017 taxonName
.setCombinationAuthorTeam(team
);
1019 if (taxonName
.hasProblem())
1020 logger
.info("pb ICZN");
1021 else return taxonName
;
1023 if (this.nomenclatureCode
.equals("Botanical")){
1024 NonViralName
<BotanicalName
> taxonName
= BotanicalName
.NewInstance(null);
1025 taxonName
.setFullTitleCache(fullName
, true);
1026 taxonName
.setGenusOrUninomial(getFromMap(atomisedMap
,"Genus"));
1027 taxonName
.setInfraGenericEpithet(getFromMap(atomisedMap
,"FirstEpithet"));
1028 taxonName
.setInfraSpecificEpithet(getFromMap(atomisedMap
,"InfraSpeEpithet"));
1029 try{taxonName
.setRank(Rank
.getRankByName(getFromMap(atomisedMap
,"Rank")));
1030 }catch(Exception e
){}
1032 if(getFromMap(atomisedMap
,"AuthorTeamParenthesis") != null){
1033 team
= Team
.NewInstance();
1034 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeamParenthesis"));
1036 taxonName
.setBasionymAuthorTeam(team
);
1038 if (getFromMap(atomisedMap
,"AuthorTeam") != null){
1039 team
= Team
.NewInstance();
1040 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeam"));
1042 taxonName
.setCombinationAuthorTeam(team
);
1045 if(getFromMap(atomisedMap
,"AuthorTeamParenthesis") != null)
1046 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
,"AuthorTeamParenthesis"));
1047 else if (getFromMap(atomisedMap
,"AuthorTeam") != null)
1048 taxonName
.setAuthorshipCache(getFromMap(atomisedMap
,"AuthorTeam"));
1050 if(getFromMap(atomisedMap
,"CombinationAuthorTeamAndYear") != null){
1051 team
= Team
.NewInstance();
1052 team
.setTitleCache(getFromMap(atomisedMap
,"CombinationAuthorTeamAndYear"));
1053 taxonName
.setCombinationAuthorTeam(team
);
1055 if (taxonName
.hasProblem())
1056 logger
.info("pb ICBN");
1057 else return taxonName
;
1059 if (this.nomenclatureCode
.equals("Bacterial")){
1060 NonViralName
<BacterialName
> taxonName
= BacterialName
.NewInstance(null);
1061 taxonName
.setFullTitleCache(fullName
, true);
1062 taxonName
.setGenusOrUninomial(getFromMap(atomisedMap
,"Genus"));
1063 taxonName
.setInfraGenericEpithet(getFromMap(atomisedMap
,"SubGenus"));
1064 taxonName
.setSpecificEpithet(getFromMap(atomisedMap
,"Species"));
1065 taxonName
.setInfraSpecificEpithet(getFromMap(atomisedMap
,"SubspeciesEpithet"));
1066 if(getFromMap(atomisedMap
,"AuthorTeamAndYear") != null){
1067 Team team
= Team
.NewInstance();
1068 team
.setTitleCache(getFromMap(atomisedMap
,"AuthorTeamAndYear"));
1069 taxonName
.setCombinationAuthorTeam(team
);
1071 if(getFromMap(atomisedMap
,"ParentheticalAuthorTeamAndYear") != null){
1072 Team team
= Team
.NewInstance();
1073 team
.setTitleCache(getFromMap(atomisedMap
,"ParentheticalAuthorTeamAndYear"));
1074 taxonName
.setBasionymAuthorTeam(team
);
1076 if (taxonName
.hasProblem())
1077 logger
.info("pb ICNB");
1078 else return taxonName
;
1080 if (this.nomenclatureCode
.equals("Cultivar")){
1081 NonViralName
<CultivarPlantName
> taxonName
= CultivarPlantName
.NewInstance(null);
1083 if (taxonName
.hasProblem())
1084 logger
.info("pb ICNCP");
1085 else return taxonName
;
1087 // if (this.nomenclatureCode.equals("Viral")){
1088 // ViralName taxonName = ViralName.NewInstance(null);
1089 // taxonName.setFullTitleCache(fullName, true);
1090 // taxonName.setAcronym(getFromMap(atomisedMap,"Acronym"));
1091 // if (taxonName.hasProblem())
1092 // logger.info("pb ICVCN");
1093 // else return taxonName;
1096 NonViralName
<?
>taxonName
= NonViralName
.NewInstance(null);
1097 taxonName
.setFullTitleCache(fullName
, true);
1101 private String
getFromMap(HashMap
<String
, String
> atomisedMap
, String key
){
1102 String value
= null;
1103 if (atomisedMap
.containsKey(key
))
1104 value
= atomisedMap
.get(key
);
1106 if (value
!= null && key
.matches(".*Year.*")){
1108 if (value
.matches("[a-z A-Z ]*[0-9]{4}$")){
1109 String tmp
=value
.split("[0-9]{4}$")[0];
1110 int year
= Integer
.parseInt(value
.split(tmp
)[1]);
1119 }catch(Exception e
){value
=null;}
1124 * Store the unit with its Gathering informations in the CDM
1126 public boolean start(SpecimenImportConfigurator config
){
1127 boolean result
= true;
1129 TransactionStatus tx
= null;
1132 // app = CdmApplicationController.NewInstance(config.getDestination(), config.getDbSchemaValidation());
1133 // } catch (DataSourceNotFoundException e1) {
1134 // e1.printStackTrace();
1135 // logger.info("DataSourceNotFoundException "+e1);
1136 // } catch (TermNotFoundException e1) {
1137 // e1.printStackTrace();
1138 // logger.info("TermNotFoundException " +e1);
1141 tx
= startTransaction();
1143 // ReferenceBase sec = Database.NewInstance();
1144 // sec.setTitleCache("XML DATA");
1145 ReferenceBase sec
= config
.getTaxonReference();
1148 * SPECIMEN OR OBSERVATION OR LIVING
1150 DerivedUnitBase derivedThing
= null;
1152 boolean rbFound
=false;
1153 if (this.recordBasis
!= null){
1154 if (this.recordBasis
.toLowerCase().startsWith("s")) {//specimen
1155 derivedThing
= Specimen
.NewInstance();
1158 else if (this.recordBasis
.toLowerCase().startsWith("o")) {//observation
1159 derivedThing
= Observation
.NewInstance();
1162 else if (this.recordBasis
.toLowerCase().startsWith("l")) {//living -> fossil, herbarium sheet....???
1163 derivedThing
= LivingBeing
.NewInstance();
1167 logger
.info("The basis of record does not seem to be known: "+this.recordBasis
);
1168 derivedThing
= DerivedUnit
.NewInstance();
1172 logger
.info("The basis of record is null");
1173 derivedThing
= DerivedUnit
.NewInstance();
1175 // if(derivedThing == null)derivedThing=Observation.NewInstance();
1177 this.setTaxonNameBase(config
, derivedThing
, sec
);
1180 //set catalogue number (unitID)
1181 derivedThing
.setCatalogNumber(this.unitID
);
1182 derivedThing
.setAccessionNumber(this.accessionNumber
);
1183 derivedThing
.setCollectorsNumber(this.collectorsNumber
);
1187 * INSTITUTION & COLLECTION
1189 //manage institution
1190 Institution institution
= this.getInstitution(this.institutionCode
,config
);
1192 Collection collection
= this.getCollection(this.collectionCode
, institution
, config
);
1193 //link specimen & collection
1194 derivedThing
.setCollection(collection
);
1200 UnitsGatheringEvent unitsGatheringEvent
= new UnitsGatheringEvent(this, this.locality
, this.languageIso
, this.longitude
,
1201 this.latitude
, this.gatheringAgentList
);
1202 UnitsGatheringArea unitsGatheringArea
= new UnitsGatheringArea(this.isocountry
, this.country
, this);
1203 NamedArea areaCountry
= unitsGatheringArea
.getArea();
1204 unitsGatheringEvent
.addArea(areaCountry
);
1205 unitsGatheringArea
= new UnitsGatheringArea(this.namedAreaList
);
1206 ArrayList
<NamedArea
> nas
= unitsGatheringArea
.getAreas();
1207 for (int i
=0; i
<nas
.size();i
++)
1208 unitsGatheringEvent
.addArea(nas
.get(i
));
1211 //create field/observation
1212 FieldObservation fieldObservation
= FieldObservation
.NewInstance();
1214 fieldObservation
.setFieldNumber(this.fieldNumber
);
1215 //join gatheringEvent to fieldObservation
1216 fieldObservation
.setGatheringEvent(unitsGatheringEvent
.getGatheringEvent());
1217 // //add Multimedia URLs
1218 if(this.multimediaObjects
.size()>0){
1219 MediaRepresentation representation
;
1224 for (int i
=0;i
<this.multimediaObjects
.size();i
++){
1225 if(this.multimediaObjects
.get(i
) != null){
1226 imd
= new ImageMetaData();
1227 url
= new URL(this.multimediaObjects
.get(i
));
1228 imd
= MediaMetaData
.readImageMetaData(url
, imd
);
1230 representation
= MediaRepresentation
.NewInstance();
1231 imf
= ImageFile
.NewInstance(this.multimediaObjects
.get(i
), null, imd
);
1232 representation
.addRepresentationPart(imf
);
1233 media
= Media
.NewInstance();
1234 media
.addRepresentation(representation
);
1235 fieldObservation
.addMedia(media
);
1240 // //link fieldObservation and specimen
1241 DerivationEvent derivationEvent
= DerivationEvent
.NewInstance();
1242 derivationEvent
.addOriginal(fieldObservation
);
1243 derivedThing
.addDerivationEvent(derivationEvent
);
1246 * SAVE AND STORE DATA
1248 getTermService().saveTerm(areaCountry
);//save it sooner
1249 for (int i
=0; i
<nas
.size();i
++)
1250 getTermService().saveTerm(nas
.get(i
));//save it sooner (foreach area)
1251 getTermService().saveLanguageData(unitsGatheringEvent
.getLocality());//save it sooner
1252 getOccurrenceService().saveSpecimenOrObservationBase(derivedThing
);
1253 logger
.info("saved ABCD specimen ...");
1256 } catch (Exception e
) {
1257 logger
.warn("Error when reading record!!");
1258 e
.printStackTrace();
1261 commitTransaction(tx
);
1266 private void compareABCDtoCDM(String urlFileName
, ArrayList
<String
> knownElts
){
1269 DocumentBuilderFactory fabrique
= DocumentBuilderFactory
.newInstance();
1270 DocumentBuilder constructeur
= fabrique
.newDocumentBuilder();
1271 URL url
= new URL(urlFileName
);
1272 Object o
= url
.getContent();
1273 InputStream is
= (InputStream
)o
;
1274 Document document
= constructeur
.parse(is
);
1275 Element racine
= document
.getDocumentElement();
1277 } catch (ParserConfigurationException e
) {
1278 // TODO Auto-generated catch block
1279 e
.printStackTrace();
1280 } catch (SAXException e
) {
1281 // TODO Auto-generated catch block
1282 e
.printStackTrace();
1283 } catch (IOException e
) {
1284 // TODO Auto-generated catch block
1285 e
.printStackTrace();
1287 Set
<String
> elts
= allABCDelements
.keySet();
1288 Iterator
< String
>it
= elts
.iterator();
1290 while (it
.hasNext()){
1292 if (knownElts
.indexOf(elt
) == -1)
1293 logger
.info("Unsaved ABCD element: "+elt
+" - "+allABCDelements
.get(elt
));
1299 private void traverse(Node node
){
1300 // Extract node info:
1301 String test
= node
.getTextContent();
1303 // Print and continue traversing.
1304 if(test
!= null && test
!= "#text" && node
.getNodeName() != "#text" && test
.split("\n").length
==1 && test
.length()>0)
1306 path
=node
.getNodeName();
1307 getHierarchie(node
);
1308 allABCDelements
.put(path
,test
);
1311 // Now traverse the rest of the tree in depth-first order.
1312 if (node
.hasChildNodes()) {
1313 // Get the children in a list.
1314 NodeList nl
= node
.getChildNodes();
1315 // How many of them?
1316 int size
= nl
.getLength();
1317 for (int i
=0; i
<size
; i
++)
1318 // Recursively traverse each of the children.
1319 traverse (nl
.item(i
));
1325 protected boolean doInvoke(IImportConfigurator config
,
1326 Map
<String
, MapWrapper
<?
extends CdmBase
>> stores
) {
1327 logger
.info("INVOKE Specimen Import from ABCD2.06 XML File");
1328 boolean result
= true;
1329 SpecimenImportConfigurator specimenImportConfig
= (SpecimenImportConfigurator
)config
;
1330 //AbcdIO test = new AbcdIO();
1331 String sourceName
= specimenImportConfig
.getSource();
1332 NodeList unitsList
= getUnitsNodeList(sourceName
);
1333 if (unitsList
!= null)
1335 logger
.info("nb units to insert: "+unitsList
.getLength());
1336 for (int i
=0;i
<unitsList
.getLength();i
++){
1337 this.setUnitPropertiesXML((Element
)unitsList
.item(i
));
1338 result
&= this.start(specimenImportConfig
);
1339 config
.setDbSchemaValidation(DbSchemaValidation
.UPDATE
);
1340 //compare the ABCD elements added in to the CDM and the unhandled ABCD elements
1341 compareABCDtoCDM(sourceName
,this.knownABCDelements
);
1342 //reset the ABCD elements added in CDM
1343 //knownABCDelements = new ArrayList<String>();
1344 allABCDelements
= new HashMap
<String
,String
>();
1353 // public boolean invoke(IImportConfigurator config, Map stores) {
1354 // logger.info("invoke AbcdIO");
1355 // return invoke((SpecimenImportConfigurator)config);
1360 protected boolean isIgnore(IImportConfigurator config
) {
1361 //return ! config.isDoNameFacts();