1 package eu
.etaxonomy
.cdm
.io
.abcd206
;
4 import java
.util
.ArrayList
;
8 import javax
.xml
.parsers
.DocumentBuilder
;
9 import javax
.xml
.parsers
.DocumentBuilderFactory
;
11 import org
.apache
.log4j
.Logger
;
12 import org
.springframework
.transaction
.TransactionStatus
;
13 import org
.w3c
.dom
.Document
;
14 import org
.w3c
.dom
.Element
;
15 import org
.w3c
.dom
.Node
;
16 import org
.w3c
.dom
.NodeList
;
18 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
19 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
20 import eu
.etaxonomy
.cdm
.io
.common
.ICdmIO
;
21 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
22 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
23 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
24 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
25 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
26 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentationPart
;
27 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
28 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
29 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
30 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEvent
;
31 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnitBase
;
32 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
33 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldObservation
;
34 import eu
.etaxonomy
.cdm
.model
.occurrence
.LivingBeing
;
35 import eu
.etaxonomy
.cdm
.model
.occurrence
.Observation
;
36 import eu
.etaxonomy
.cdm
.model
.occurrence
.Specimen
;
37 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
38 import eu
.etaxonomy
.cdm
.model
.reference
.Generic
;
39 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
40 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
41 import eu
.etaxonomy
.cdm
.strategy
.parser
.NonViralNameParserImpl
;
43 public class AbcdIO
extends SpecimenIoBase
implements ICdmIO
{
46 private static final Logger logger
= Logger
.getLogger(AbcdIO
.class);
48 protected String fullScientificNameString
;
49 protected String nomenclatureCode
;
50 protected String institutionCode
;
51 protected String collectionCode
;
52 protected String unitID
;
53 protected String recordBasis
;
54 protected String accessionNumber
;
55 protected String collectorsNumber
;
56 protected String fieldNumber
;
57 protected Double longitude
;
58 protected Double latitude
;
59 protected String locality
;
60 protected String languageIso
= null;
61 protected String country
;
62 protected String isocountry
;
64 protected int altitude
;
65 protected ArrayList
<String
> gatheringAgentList
;
66 protected ArrayList
<String
> identificationList
;
67 protected ArrayList
<String
> namedAreaList
;
68 protected ArrayList
<String
> referenceList
;
69 protected ArrayList
<String
> multimediaObjects
;
72 protected ArrayList
<String
> knownABCDelements
= new ArrayList
<String
>();
77 knownABCDelements
.add("Identifications");
78 knownABCDelements
.add("Identification");
79 knownABCDelements
.add("Result");
80 knownABCDelements
.add("TaxonIdentified");
81 knownABCDelements
.add("ScientificName");
82 knownABCDelements
.add("FullScientificNameString");
83 knownABCDelements
.add("NameAtomised");
84 knownABCDelements
.add("SourceInstitutionID");
85 knownABCDelements
.add("SourceID");
86 knownABCDelements
.add("UnitID");
87 knownABCDelements
.add("RecordBasis");
88 knownABCDelements
.add("AccessionNumber");
89 knownABCDelements
.add("LocalityText");
90 knownABCDelements
.add("LongitudeDecimal");
91 knownABCDelements
.add("Country");
92 knownABCDelements
.add("ISO3166Code");
93 knownABCDelements
.add("CollectorsFieldNumber");
94 knownABCDelements
.add("CollectorsNumber");
95 knownABCDelements
.add("AccessionNumber");
96 knownABCDelements
.add("Altitude_MeasurementOrFactText");
97 knownABCDelements
.add("Depth");
98 knownABCDelements
.add("NamedArea_AreaName");
99 knownABCDelements
.add("GatheringAgent_Person_FullName");
103 * Return the list of root nodes for an ABCD 2.06 XML file
104 * @param fileName: the file's location
105 * @return the list of root nodes ("Unit")
107 private static NodeList
getUnitsNodeList(String fileName
){
108 NodeList unitList
= null;
110 DocumentBuilderFactory fabrique
= DocumentBuilderFactory
.newInstance();
111 DocumentBuilder constructeur
= fabrique
.newDocumentBuilder();
112 File xml
= new File(fileName
);
113 Document document
= constructeur
.parse(xml
);
114 Element racine
= document
.getDocumentElement();
115 unitList
= racine
.getElementsByTagName("Unit");
117 System
.out
.println(e
);
123 public void afficherInfos(Node noeud
, int niv
) {
124 short type
= noeud
.getNodeType();
125 String nom
= noeud
.getNodeName();
126 String valeur
= noeud
.getNodeValue();
128 indenter(niv
, type
== Node
.TEXT_NODE
);
129 if(!knownABCDelements
.contains(nom
)){
130 System
.out
.print(nom
+ " (" + type
+ ") = '");
131 if(valeur
!= null && !valeur
.matches("^\\s+$")){
132 System
.out
.print(valeur
);
133 System
.out
.println("'");
136 if ((type
== Node
.DOCUMENT_NODE
137 || type
== Node
.ELEMENT_NODE
)
138 && noeud
.hasChildNodes()) {
139 NodeList liste
= noeud
.getChildNodes();
140 for(int i
= 0; i
< liste
.getLength(); i
++)
141 afficherInfos(liste
.item(i
), niv
+ 1);
144 public void indenter(int n
, boolean texte
){
146 for(int i
= 0; i
< n
; i
++){
147 System
.out
.print(tab
);
150 System
.out
.print(" - ");
153 System
.out
.print(" + ");
157 * Store the unit's properties into variables
158 * Look which unit is the preferred one
159 * Look what kind of name it is supposed to be, for the parsing (Botanical, Zoological)
160 * @param racine: the root node for a single unit
162 private void setUnitPropertiesXML(Element racine
){
164 NodeList group
,childs
,person
;
166 // try{afficherInfos(racine, 0);}catch (Exception e) {System.out.println(e);}
167 group
= racine
.getChildNodes();
168 // logger.info("ABCD ELEMENT not stored: "+group.item(i).getNodeName().toString()+" - value: "+group.item(i).getTextContent());
169 for (int i
=0; i
< group
.getLength(); i
++){
170 if (group
.item(i
).getNodeName() == "Identifications"){
171 group
= group
.item(i
).getChildNodes();
175 this.identificationList
= new ArrayList
<String
>();
176 this.referenceList
= new ArrayList
<String
>();
177 this.multimediaObjects
= new ArrayList
<String
>();
179 this.getScientificNames(group
);
181 // System.out.println("this.identificationList "+this.identificationList.toString());
183 this.getRecordBasis(racine
);
184 this.getMultimedia(racine
);
185 this.getNumbers(racine
);
186 this.getGeolocation(racine
);
187 this.getGatheringPeople(racine
);
189 } catch (Exception e
) {
190 logger
.info("Error occured while parsing XML file"+e
);
195 private void getScientificNames(NodeList group
){
196 NodeList identifications
,results
;
197 String tmpName
= null;
198 for (int j
=0; j
< group
.getLength(); j
++){
199 if(group
.item(j
).getNodeName() == "Identification"){
200 this.nomenclatureCode
="";
201 identifications
= group
.item(j
).getChildNodes();
202 for (int m
=0; m
<identifications
.getLength();m
++){
203 if(identifications
.item(m
).getNodeName() == "Result"){
204 results
= identifications
.item(m
).getChildNodes();
205 for(int k
=0; k
<results
.getLength();k
++)
206 if (results
.item(k
).getNodeName() == "TaxonIdentified")
207 tmpName
=this.getScientificName(results
.item(k
));
209 else if(identifications
.item(m
).getNodeName() == "PreferredFlag")
210 this.identificationList
.add(tmpName
+"_preferred_"+identifications
.item(m
).getTextContent()+"_code_"+this.nomenclatureCode
);
212 else if (identifications
.item(m
).getNodeName() == "References")
213 this.getReferences(identifications
.item(m
));
216 this.identificationList
.add(tmpName
+"_preferred_"+"0"+"_code_"+this.nomenclatureCode
);
222 private void getReferences(Node result
){
223 NodeList results
,reference
;
224 results
= result
.getChildNodes();
225 for(int k
=0; k
<results
.getLength();k
++){
226 if (results
.item(k
).getNodeName() == "Reference"){
227 reference
= results
.item(k
).getChildNodes();
228 for(int l
=0;l
<reference
.getLength();l
++){
229 if (reference
.item(l
).getNodeName()=="TitleCitation")
230 referenceList
.add(reference
.item(l
).getTextContent());
236 private String
getScientificName(Node result
){
237 NodeList taxonsIdentified
, scnames
;
239 taxonsIdentified
= result
.getChildNodes();
240 for (int l
=0; l
<taxonsIdentified
.getLength(); l
++){
241 if (taxonsIdentified
.item(l
).getNodeName() == "ScientificName"){
242 scnames
= taxonsIdentified
.item(l
).getChildNodes();
243 for (int n
=0;n
<scnames
.getLength();n
++){
244 if (scnames
.item(n
).getNodeName() == "FullScientificNameString")
245 tmpName
= scnames
.item(n
).getTextContent();
246 if (scnames
.item(n
).getNodeName() == "NameAtomised"){
248 if (scnames
.item(n
).hasChildNodes()){
250 this.nomenclatureCode
= scnames
.item(n
).getChildNodes().item(1).getNodeName();
252 } catch (Exception e
) {
253 this.nomenclatureCode
="";
261 private void getIDs(Element racine
){
264 group
= racine
.getElementsByTagName("SourceInstitutionID");
265 this.institutionCode
= group
.item(0).getTextContent();
266 } catch (NullPointerException e
) {
267 this.institutionCode
= "";
270 group
= racine
.getElementsByTagName("SourceID");
271 this.collectionCode
= group
.item(0).getTextContent();
272 } catch (NullPointerException e
) {
273 this.collectionCode
= "";
276 group
= racine
.getElementsByTagName("UnitID");
277 this.unitID
= group
.item(0).getTextContent();
278 } catch (NullPointerException e
) {
283 private void getRecordBasis(Element racine
){
286 group
= racine
.getElementsByTagName("RecordBasis");
287 this.recordBasis
= group
.item(0).getTextContent();
288 } catch (NullPointerException e
) {
289 this.recordBasis
= "";
293 private void getMultimedia(Element racine
){
294 NodeList group
, multimedias
, multimedia
;
296 group
= racine
.getElementsByTagName("MultiMediaObjects");
297 for(int i
=0;i
<group
.getLength();i
++){
298 multimedias
= group
.item(i
).getChildNodes();
299 for (int j
=0;j
<multimedias
.getLength();j
++){
300 if (multimedias
.item(j
).getNodeName() == "MultiMediaObject"){
301 multimedia
= multimedias
.item(j
).getChildNodes();
302 for (int k
=0;k
<multimedia
.getLength();k
++){
303 if(multimedia
.item(k
).getNodeName() == "FileURI")
304 this.multimediaObjects
.add(multimedia
.item(k
).getTextContent());
309 } catch (NullPointerException e
) {
310 System
.out
.println(e
);
314 private void getNumbers(Element racine
){
317 group
= racine
.getElementsByTagName("AccessionNumber");
318 this.accessionNumber
= group
.item(0).getTextContent();
319 } catch (NullPointerException e
) {
320 this.accessionNumber
= "";
323 group
= racine
.getElementsByTagName("CollectorsFieldNumber");
324 this.fieldNumber
= group
.item(0).getTextContent();
325 } catch (NullPointerException e
) {
326 this.fieldNumber
= "";
330 group
= racine
.getElementsByTagName("CollectorsNumber");
331 this.collectorsNumber
= group
.item(0).getTextContent();
332 } catch (NullPointerException e
) {
333 this.collectorsNumber
= "";
337 group
= racine
.getElementsByTagName("AccessionNumber");
338 this.accessionNumber
= group
.item(0).getTextContent();
339 } catch (NullPointerException e
) {
340 this.accessionNumber
= "";
344 private void getGeolocation(Element racine
){
345 NodeList group
, childs
;
347 group
= racine
.getElementsByTagName("LocalityText");
348 this.locality
= group
.item(0).getTextContent();
349 if (group
.item(0).hasAttributes())
350 if (group
.item(0).getAttributes().getNamedItem("lang") != null)
351 this.languageIso
= group
.item(0).getAttributes().getNamedItem("lang").getTextContent();
352 } catch (NullPointerException e
) {
356 group
= racine
.getElementsByTagName("LongitudeDecimal");
357 this.longitude
= Double
.valueOf(group
.item(0).getTextContent());
358 } catch (NullPointerException e
) {
362 group
= racine
.getElementsByTagName("LatitudeDecimal");
363 this.latitude
= Double
.valueOf(group
.item(0).getTextContent());
364 } catch (NullPointerException e
) {
368 group
= racine
.getElementsByTagName("Country");
369 this.country
= group
.item(0).getTextContent();
370 } catch (NullPointerException e
) {
374 group
= racine
.getElementsByTagName("ISO3166Code");
375 this.isocountry
= group
.item(0).getTextContent();
376 } catch (NullPointerException e
) {
377 this.isocountry
= "";
380 group
= racine
.getElementsByTagName("Altitude");
381 for (int i
=0;i
<group
.getLength();i
++){
382 childs
= group
.item(i
).getChildNodes();
383 for (int j
=0;j
<childs
.getLength();j
++){
384 if (childs
.item(j
).getNodeName() == "MeasurementOrFactText")
385 this.altitude
= Integer
.valueOf(childs
.item(j
).getTextContent());
388 } catch (NullPointerException e
) {
389 this.altitude
= -9999;
393 group
= racine
.getElementsByTagName("Depth");
394 this.depth
= Integer
.valueOf(group
.item(0).getTextContent());
395 } catch (NullPointerException e
) {
400 group
= racine
.getElementsByTagName("NamedArea");
401 this.namedAreaList
= new ArrayList
<String
>();
402 for (int i
=0;i
<group
.getLength();i
++){
403 childs
= group
.item(i
).getChildNodes();
404 for (int j
=0; j
<childs
.getLength();j
++){
405 if (childs
.item(j
).getNodeName() == "AreaName")
406 this.namedAreaList
.add(childs
.item(j
).getTextContent());
409 }catch(NullPointerException e
){
410 this.namedAreaList
= new ArrayList
<String
>();
414 private void getGatheringPeople(Element racine
){
415 NodeList group
, childs
, person
;
417 group
= racine
.getElementsByTagName("GatheringAgent");
418 this.gatheringAgentList
= new ArrayList
<String
>();
419 for (int i
=0; i
< group
.getLength(); i
++){
420 childs
= group
.item(i
).getChildNodes();
421 for (int j
=0; j
<childs
.getLength();j
++){
422 if (childs
.item(j
).getNodeName() == "Person"){
423 person
= childs
.item(j
).getChildNodes();
424 for (int k
=0; k
<person
.getLength(); k
++)
425 if (person
.item(k
).getNodeName() == "FullName")
426 this.gatheringAgentList
.add(person
.item(k
).getTextContent());
431 } catch (NullPointerException e
) {
432 this.gatheringAgentList
= new ArrayList
<String
>();
436 private Institution
getInstitution(String institutionCode
, SpecimenImportConfigurator config
){
437 Institution institution
;
438 List
<Institution
> institutions
;
440 System
.out
.println(this.institutionCode
);
441 institutions
= config
.getCdmAppController().getAgentService().searchInstitutionByCode(this.institutionCode
);
443 System
.out
.println("BLI "+e
);
444 institutions
=new ArrayList
<Institution
>();
446 if (institutions
.size() ==0 || !config
.getReUseExistingMetadata()){
447 System
.out
.println("Institution (agent) unknown or not allowed to reuse existing metadata");
449 institution
= Institution
.NewInstance();
450 institution
.setCode(this.institutionCode
);
453 System
.out
.println("Institution (agent) already in the db");
454 institution
= institutions
.get(0);
460 * Look if the Collection does already exists
461 * @param collectionCode: a string
462 * @param institution: the current Institution
464 * @return the Collection (existing or new)
466 private Collection
getCollection(String collectionCode
, Institution institution
, SpecimenImportConfigurator config
){
467 Collection collection
= Collection
.NewInstance();
468 List
<Collection
> collections
;
470 collections
= config
.getCdmAppController().getOccurrenceService().searchCollectionByCode(this.collectionCode
);
472 collections
=new ArrayList
<Collection
>();
474 if (collections
.size() ==0 || !config
.getReUseExistingMetadata()){
475 System
.out
.println("Collection not found or do not reuse existing metadata "+this.collectionCode
);
476 //create new collection
477 collection
.setCode(this.collectionCode
);
478 collection
.setCodeStandard("GBIF");
479 collection
.setInstitute(institution
);
482 boolean collectionFound
=false;
483 for (int i
=0; i
<collections
.size(); i
++){
484 collection
= collections
.get(i
);
486 if (collection
.getInstitute().getCode().equalsIgnoreCase(institution
.getCode())){
487 //found a collection with the same code and the same institution
488 collectionFound
=true;
490 } catch (NullPointerException e
) {}
492 if (!collectionFound
){
493 collection
.setCode(this.collectionCode
);
494 collection
.setCodeStandard("GBIF");
495 collection
.setInstitute(institution
);
505 * @param derivedThing
508 private void setTaxonNameBase(SpecimenImportConfigurator config
, DerivedUnitBase derivedThing
, ReferenceBase sec
){
509 TaxonNameBase taxonName
= null;
510 String fullScientificNameString
;
512 DeterminationEvent determinationEvent
= null;
513 List
<TaxonNameBase
> names
= null;
515 String scientificName
="";
516 boolean preferredFlag
=false;
518 for (int i
= 0; i
< this.identificationList
.size(); i
++) {
519 fullScientificNameString
= this.identificationList
.get(i
);
520 fullScientificNameString
= fullScientificNameString
.replaceAll(" et ", " & ");
521 if (fullScientificNameString
.indexOf("_preferred_") != -1){
522 scientificName
= fullScientificNameString
.split("_preferred_")[0];
523 String pTmp
= fullScientificNameString
.split("_preferred_")[1].split("_code_")[0];
524 if (pTmp
== "1" || pTmp
.toLowerCase().indexOf("true") != -1)
529 else scientificName
= fullScientificNameString
;
531 if (fullScientificNameString
.indexOf("_code_") != -1)
532 this.nomenclatureCode
= fullScientificNameString
.split("_code_")[1];
534 if (config
.getDoAutomaticParsing())
535 taxonName
= this.parseScientificName(scientificName
);
536 else taxonName
.setTitleCache(scientificName
);
539 names
= config
.getCdmAppController().getNameService().getNamesByName(scientificName
);
540 if (names
.size() == 0){
541 System
.out
.println("Name not found: " + scientificName
);
543 if (names
.size() > 1){
544 System
.out
.println("More then 1 name found: " + scientificName
);
546 System
.out
.println("Name found");
547 taxonName
= names
.get(0);
551 config
.getCdmAppController().getNameService().saveTaxonName(taxonName
);
552 taxon
= Taxon
.NewInstance(taxonName
, sec
); //sec set null
554 determinationEvent
= DeterminationEvent
.NewInstance();
555 determinationEvent
.setTaxon(taxon
);
556 determinationEvent
.setPreferredFlag(preferredFlag
);
557 for (int l
=0;l
<this.referenceList
.size();l
++){
558 ReferenceBase reference
= new Generic();
559 reference
.setTitleCache(this.referenceList
.get(l
));
560 determinationEvent
.addReference(reference
);
562 derivedThing
.addDetermination(determinationEvent
);
567 private TaxonNameBase
parseScientificName(String scientificName
){
568 System
.out
.println("scientificName");
569 TaxonNameBase taxonName
= null;
570 NonViralNameParserImpl nvnpi
= NonViralNameParserImpl
.NewInstance();
572 System
.out
.println("nomenclature: "+this.nomenclatureCode
);
573 if (this.nomenclatureCode
== "Zoological"){
574 taxonName
= nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICZN(),null);
575 if (taxonName
.hasProblem())
576 System
.out
.println("pb ICZN");}
577 if (this.nomenclatureCode
== "Botanical"){
578 taxonName
= nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICBN(),null);
579 if (taxonName
.hasProblem())
580 System
.out
.println("pb ICBN");}
581 if (this.nomenclatureCode
== "Bacterial"){
582 taxonName
= nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICNB(), null);
583 if (taxonName
.hasProblem())
584 System
.out
.println("pb ICNB");
586 if (this.nomenclatureCode
== "Cultivar"){
587 taxonName
= nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICNCP(), null);
588 if (taxonName
.hasProblem())
589 System
.out
.println("pb ICNCP");
591 if (this.nomenclatureCode
== "Viral"){
592 taxonName
= nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICVCN(), null);
593 if (taxonName
.hasProblem())
594 System
.out
.println("pb ICVCN");
596 try{taxonName
.hasProblem();}
597 catch (Exception e
) {
598 taxonName
= nvnpi
.parseFullName(scientificName
);
600 if (taxonName
.hasProblem())
601 taxonName
= nvnpi
.parseFullName(scientificName
);
605 * Store the unit with its Gathering informations in the CDM
607 public boolean start(SpecimenImportConfigurator config
){
608 boolean result
= true;
609 boolean withCdm
= true;
610 CdmApplicationController app
= null;
611 TransactionStatus tx
= null;
613 app
= config
.getCdmAppController();
615 // app = CdmApplicationController.NewInstance(config.getDestination(), config.getDbSchemaValidation());
616 // } catch (DataSourceNotFoundException e1) {
617 // e1.printStackTrace();
618 // System.out.println("DataSourceNotFoundException "+e1);
619 // } catch (TermNotFoundException e1) {
620 // e1.printStackTrace();
621 // System.out.println("TermNotFoundException " +e1);
624 tx
= app
.startTransaction();
626 // ReferenceBase sec = Database.NewInstance();
627 // sec.setTitleCache("XML DATA");
628 ReferenceBase sec
= null;
631 * SPECIMEN OR OBSERVATION OR LIVING
633 DerivedUnitBase derivedThing
= null;
635 if (this.recordBasis
!= null){
636 if (this.recordBasis
.toLowerCase().startsWith("s")) {//specimen
637 derivedThing
= Specimen
.NewInstance();
639 else if (this.recordBasis
.toLowerCase().startsWith("o")) {//observation
640 derivedThing
= Observation
.NewInstance();
642 else if (this.recordBasis
.toLowerCase().startsWith("l")) {//living -> fossil, herbarium sheet....???
643 derivedThing
= LivingBeing
.NewInstance();
646 if (derivedThing
== null)
647 derivedThing
= Observation
.NewInstance();
649 this.setTaxonNameBase(config
, derivedThing
, sec
);
652 //set catalogue number (unitID)
653 derivedThing
.setCatalogNumber(this.unitID
);
654 derivedThing
.setAccessionNumber(this.accessionNumber
);
655 derivedThing
.setCollectorsNumber(this.collectorsNumber
);
659 * INSTITUTION & COLLECTION
662 Institution institution
= this.getInstitution(this.institutionCode
,config
);
664 Collection collection
= this.getCollection(this.collectionCode
, institution
, config
);
665 //link specimen & collection
666 derivedThing
.setCollection(collection
);
672 UnitsGatheringEvent unitsGatheringEvent
= new UnitsGatheringEvent(config
, this.locality
, this.languageIso
, this.longitude
,
673 this.latitude
, this.gatheringAgentList
);
674 UnitsGatheringArea unitsGatheringArea
= new UnitsGatheringArea(this.isocountry
, this.country
, config
);
675 NamedArea areaCountry
= unitsGatheringArea
.getArea();
676 unitsGatheringEvent
.addArea(areaCountry
);
677 unitsGatheringArea
= new UnitsGatheringArea(this.namedAreaList
);
678 ArrayList
<NamedArea
> nas
= unitsGatheringArea
.getAreas();
679 for (int i
=0; i
<nas
.size();i
++)
680 unitsGatheringEvent
.addArea(nas
.get(i
));
683 //create field/observation
684 FieldObservation fieldObservation
= FieldObservation
.NewInstance();
686 fieldObservation
.setFieldNumber(this.fieldNumber
);
687 //join gatheringEvent to fieldObservation
688 fieldObservation
.setGatheringEvent(unitsGatheringEvent
.getGatheringEvent());
689 // //add Multimedia URLs
690 if(this.multimediaObjects
.size()>0){
691 MediaRepresentationPart part
;
692 MediaRepresentation representation
;
694 for (int i
=0;i
<this.multimediaObjects
.size();i
++){
695 part
= MediaRepresentationPart
.NewInstance(this.multimediaObjects
.get(i
),0);
696 //TODO update the Multimedia Object without size :)
697 representation
= MediaRepresentation
.NewInstance();
698 representation
.addRepresentationPart(part
);
699 media
= Media
.NewInstance();
700 media
.addRepresentation(representation
);
701 fieldObservation
.addMedia(media
);
704 // //link fieldObservation and specimen
705 DerivationEvent derivationEvent
= DerivationEvent
.NewInstance();
706 derivationEvent
.addOriginal(fieldObservation
);
707 derivedThing
.addDerivationEvent(derivationEvent
);
710 * SAVE AND STORE DATA
713 app
.getTermService().saveTerm(areaCountry
);//save it sooner
714 for (int i
=0; i
<nas
.size();i
++)
715 app
.getTermService().saveTerm(nas
.get(i
));//save it sooner (foreach area)
716 app
.getTermService().saveLanguageData(unitsGatheringEvent
.getLocality());//save it sooner
717 app
.getOccurrenceService().saveSpecimenOrObservationBase(derivedThing
);
719 logger
.info("saved new specimen ...");
722 } catch (Exception e
) {
723 logger
.warn("Error when reading record!!");
727 app
.commitTransaction(tx
);
728 System
.out
.println("commit done");
734 public boolean invoke(SpecimenImportConfigurator config
){
735 System
.out
.println("INVOKE Specimen Import from ABCD2.06 XML File");
736 AbcdIO test
= new AbcdIO();
737 String sourceName
= config
.getSourceNameString();
738 NodeList unitsList
= getUnitsNodeList(sourceName
);
739 if (unitsList
!= null)
741 System
.out
.println("nb units to insert: "+unitsList
.getLength());
742 for (int i
=0;i
<unitsList
.getLength();i
++){
743 test
.setUnitPropertiesXML((Element
)unitsList
.item(i
));
745 config
.setDbSchemaValidation(DbSchemaValidation
.UPDATE
);
754 public boolean invoke(IImportConfigurator config
, Map stores
) {
755 System
.out
.println("invoke de ABCDio");
756 invoke((SpecimenImportConfigurator
)config
);