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
.DerivedUnit
;
32 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnitBase
;
33 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
34 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldObservation
;
35 import eu
.etaxonomy
.cdm
.model
.occurrence
.LivingBeing
;
36 import eu
.etaxonomy
.cdm
.model
.occurrence
.Observation
;
37 import eu
.etaxonomy
.cdm
.model
.occurrence
.Specimen
;
38 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
39 import eu
.etaxonomy
.cdm
.model
.reference
.Generic
;
40 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
41 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
42 import eu
.etaxonomy
.cdm
.strategy
.parser
.NonViralNameParserImpl
;
44 public class AbcdIO
extends SpecimenIoBase
implements ICdmIO
{
47 private static final Logger logger
= Logger
.getLogger(AbcdIO
.class);
49 protected String fullScientificNameString
;
50 protected String nomenclatureCode
;
51 protected String institutionCode
;
52 protected String collectionCode
;
53 protected String unitID
;
54 protected String recordBasis
;
55 protected String accessionNumber
;
56 protected String collectorsNumber
;
57 protected String fieldNumber
;
58 protected Double longitude
;
59 protected Double latitude
;
60 protected String locality
;
61 protected String languageIso
= null;
62 protected String country
;
63 protected String isocountry
;
65 protected int altitude
;
66 protected ArrayList
<String
> gatheringAgentList
;
67 protected ArrayList
<String
> identificationList
;
68 protected ArrayList
<String
> namedAreaList
;
69 protected ArrayList
<String
> referenceList
;
70 protected ArrayList
<String
> multimediaObjects
;
73 protected ArrayList
<String
> knownABCDelements
= new ArrayList
<String
>();
78 knownABCDelements
.add("Identifications");
79 knownABCDelements
.add("Identification");
80 knownABCDelements
.add("Result");
81 knownABCDelements
.add("TaxonIdentified");
82 knownABCDelements
.add("ScientificName");
83 knownABCDelements
.add("FullScientificNameString");
84 knownABCDelements
.add("NameAtomised");
85 knownABCDelements
.add("SourceInstitutionID");
86 knownABCDelements
.add("SourceID");
87 knownABCDelements
.add("UnitID");
88 knownABCDelements
.add("RecordBasis");
89 knownABCDelements
.add("AccessionNumber");
90 knownABCDelements
.add("LocalityText");
91 knownABCDelements
.add("LongitudeDecimal");
92 knownABCDelements
.add("Country");
93 knownABCDelements
.add("ISO3166Code");
94 knownABCDelements
.add("CollectorsFieldNumber");
95 knownABCDelements
.add("CollectorsNumber");
96 knownABCDelements
.add("AccessionNumber");
97 knownABCDelements
.add("Altitude_MeasurementOrFactText");
98 knownABCDelements
.add("Depth");
99 knownABCDelements
.add("NamedArea_AreaName");
100 knownABCDelements
.add("GatheringAgent_Person_FullName");
104 * Return the list of root nodes for an ABCD 2.06 XML file
105 * @param fileName: the file's location
106 * @return the list of root nodes ("Unit")
108 private static NodeList
getUnitsNodeList(String fileName
){
109 NodeList unitList
= null;
111 DocumentBuilderFactory fabrique
= DocumentBuilderFactory
.newInstance();
112 DocumentBuilder constructeur
= fabrique
.newDocumentBuilder();
113 File xml
= new File(fileName
);
114 Document document
= constructeur
.parse(xml
);
115 Element racine
= document
.getDocumentElement();
116 unitList
= racine
.getElementsByTagName("Unit");
118 System
.out
.println(e
);
124 public void afficherInfos(Node noeud
, int niv
) {
125 short type
= noeud
.getNodeType();
126 String nom
= noeud
.getNodeName();
127 String valeur
= noeud
.getNodeValue();
129 indenter(niv
, type
== Node
.TEXT_NODE
);
130 if(!knownABCDelements
.contains(nom
)){
131 System
.out
.print(nom
+ " (" + type
+ ") = '");
132 if(valeur
!= null && !valeur
.matches("^\\s+$")){
133 System
.out
.print(valeur
);
134 System
.out
.println("'");
137 if ((type
== Node
.DOCUMENT_NODE
138 || type
== Node
.ELEMENT_NODE
)
139 && noeud
.hasChildNodes()) {
140 NodeList liste
= noeud
.getChildNodes();
141 for(int i
= 0; i
< liste
.getLength(); i
++)
142 afficherInfos(liste
.item(i
), niv
+ 1);
145 public void indenter(int n
, boolean texte
){
147 for(int i
= 0; i
< n
; i
++){
148 System
.out
.print(tab
);
151 System
.out
.print(" - ");
154 System
.out
.print(" + ");
158 * Store the unit's properties into variables
159 * Look which unit is the preferred one
160 * Look what kind of name it is supposed to be, for the parsing (Botanical, Zoological)
161 * @param racine: the root node for a single unit
163 private void setUnitPropertiesXML(Element racine
){
165 NodeList group
,childs
,person
;
167 // try{afficherInfos(racine, 0);}catch (Exception e) {System.out.println(e);}
168 group
= racine
.getChildNodes();
169 // logger.info("ABCD ELEMENT not stored: "+group.item(i).getNodeName().toString()+" - value: "+group.item(i).getTextContent());
170 for (int i
=0; i
< group
.getLength(); i
++){
171 if (group
.item(i
).getNodeName() == "Identifications"){
172 group
= group
.item(i
).getChildNodes();
176 this.identificationList
= new ArrayList
<String
>();
177 this.referenceList
= new ArrayList
<String
>();
178 this.multimediaObjects
= new ArrayList
<String
>();
180 this.getScientificNames(group
);
182 // System.out.println("this.identificationList "+this.identificationList.toString());
184 this.getRecordBasis(racine
);
185 this.getMultimedia(racine
);
186 this.getNumbers(racine
);
187 this.getGeolocation(racine
);
188 this.getGatheringPeople(racine
);
190 } catch (Exception e
) {
191 logger
.info("Error occured while parsing XML file"+e
);
196 private void getScientificNames(NodeList group
){
197 NodeList identifications
,results
;
198 String tmpName
= null;
199 for (int j
=0; j
< group
.getLength(); j
++){
200 if(group
.item(j
).getNodeName() == "Identification"){
201 this.nomenclatureCode
="";
202 identifications
= group
.item(j
).getChildNodes();
203 for (int m
=0; m
<identifications
.getLength();m
++){
204 if(identifications
.item(m
).getNodeName() == "Result"){
205 results
= identifications
.item(m
).getChildNodes();
206 for(int k
=0; k
<results
.getLength();k
++)
207 if (results
.item(k
).getNodeName() == "TaxonIdentified")
208 tmpName
=this.getScientificName(results
.item(k
));
210 else if(identifications
.item(m
).getNodeName() == "PreferredFlag")
211 this.identificationList
.add(tmpName
+"_preferred_"+identifications
.item(m
).getTextContent()+"_code_"+this.nomenclatureCode
);
213 else if (identifications
.item(m
).getNodeName() == "References")
214 this.getReferences(identifications
.item(m
));
217 this.identificationList
.add(tmpName
+"_preferred_"+"0"+"_code_"+this.nomenclatureCode
);
223 private void getReferences(Node result
){
224 NodeList results
,reference
;
225 results
= result
.getChildNodes();
226 for(int k
=0; k
<results
.getLength();k
++){
227 if (results
.item(k
).getNodeName() == "Reference"){
228 reference
= results
.item(k
).getChildNodes();
229 for(int l
=0;l
<reference
.getLength();l
++){
230 if (reference
.item(l
).getNodeName()=="TitleCitation")
231 referenceList
.add(reference
.item(l
).getTextContent());
237 private String
getScientificName(Node result
){
238 NodeList taxonsIdentified
, scnames
;
240 taxonsIdentified
= result
.getChildNodes();
241 for (int l
=0; l
<taxonsIdentified
.getLength(); l
++){
242 if (taxonsIdentified
.item(l
).getNodeName() == "ScientificName"){
243 scnames
= taxonsIdentified
.item(l
).getChildNodes();
244 for (int n
=0;n
<scnames
.getLength();n
++){
245 if (scnames
.item(n
).getNodeName() == "FullScientificNameString")
246 tmpName
= scnames
.item(n
).getTextContent();
247 if (scnames
.item(n
).getNodeName() == "NameAtomised"){
249 if (scnames
.item(n
).hasChildNodes()){
251 this.nomenclatureCode
= scnames
.item(n
).getChildNodes().item(1).getNodeName();
253 } catch (Exception e
) {
254 this.nomenclatureCode
="";
262 private void getIDs(Element racine
){
265 group
= racine
.getElementsByTagName("SourceInstitutionID");
266 this.institutionCode
= group
.item(0).getTextContent();
267 } catch (NullPointerException e
) {
268 this.institutionCode
= "";
271 group
= racine
.getElementsByTagName("SourceID");
272 this.collectionCode
= group
.item(0).getTextContent();
273 } catch (NullPointerException e
) {
274 this.collectionCode
= "";
277 group
= racine
.getElementsByTagName("UnitID");
278 this.unitID
= group
.item(0).getTextContent();
279 } catch (NullPointerException e
) {
284 private void getRecordBasis(Element racine
){
287 group
= racine
.getElementsByTagName("RecordBasis");
288 this.recordBasis
= group
.item(0).getTextContent();
289 } catch (NullPointerException e
) {
290 this.recordBasis
= "";
294 private void getMultimedia(Element racine
){
295 NodeList group
, multimedias
, multimedia
;
297 group
= racine
.getElementsByTagName("MultiMediaObjects");
298 for(int i
=0;i
<group
.getLength();i
++){
299 multimedias
= group
.item(i
).getChildNodes();
300 for (int j
=0;j
<multimedias
.getLength();j
++){
301 if (multimedias
.item(j
).getNodeName() == "MultiMediaObject"){
302 multimedia
= multimedias
.item(j
).getChildNodes();
303 for (int k
=0;k
<multimedia
.getLength();k
++){
304 if(multimedia
.item(k
).getNodeName() == "FileURI")
305 this.multimediaObjects
.add(multimedia
.item(k
).getTextContent());
310 } catch (NullPointerException e
) {
311 System
.out
.println(e
);
315 private void getNumbers(Element racine
){
318 group
= racine
.getElementsByTagName("AccessionNumber");
319 this.accessionNumber
= group
.item(0).getTextContent();
320 } catch (NullPointerException e
) {
321 this.accessionNumber
= "";
324 group
= racine
.getElementsByTagName("CollectorsFieldNumber");
325 this.fieldNumber
= group
.item(0).getTextContent();
326 } catch (NullPointerException e
) {
327 this.fieldNumber
= "";
331 group
= racine
.getElementsByTagName("CollectorsNumber");
332 this.collectorsNumber
= group
.item(0).getTextContent();
333 } catch (NullPointerException e
) {
334 this.collectorsNumber
= "";
338 group
= racine
.getElementsByTagName("AccessionNumber");
339 this.accessionNumber
= group
.item(0).getTextContent();
340 } catch (NullPointerException e
) {
341 this.accessionNumber
= "";
345 private void getGeolocation(Element racine
){
346 NodeList group
, childs
;
348 group
= racine
.getElementsByTagName("LocalityText");
349 this.locality
= group
.item(0).getTextContent();
350 if (group
.item(0).hasAttributes())
351 if (group
.item(0).getAttributes().getNamedItem("lang") != null)
352 this.languageIso
= group
.item(0).getAttributes().getNamedItem("lang").getTextContent();
353 } catch (NullPointerException e
) {
357 group
= racine
.getElementsByTagName("LongitudeDecimal");
358 this.longitude
= Double
.valueOf(group
.item(0).getTextContent());
359 } catch (NullPointerException e
) {
363 group
= racine
.getElementsByTagName("LatitudeDecimal");
364 this.latitude
= Double
.valueOf(group
.item(0).getTextContent());
365 } catch (NullPointerException e
) {
369 group
= racine
.getElementsByTagName("Country");
370 this.country
= group
.item(0).getTextContent();
371 } catch (NullPointerException e
) {
375 group
= racine
.getElementsByTagName("ISO3166Code");
376 this.isocountry
= group
.item(0).getTextContent();
377 } catch (NullPointerException e
) {
378 this.isocountry
= "";
381 group
= racine
.getElementsByTagName("Altitude");
382 for (int i
=0;i
<group
.getLength();i
++){
383 childs
= group
.item(i
).getChildNodes();
384 for (int j
=0;j
<childs
.getLength();j
++){
385 if (childs
.item(j
).getNodeName() == "MeasurementOrFactText")
386 this.altitude
= Integer
.valueOf(childs
.item(j
).getTextContent());
389 } catch (NullPointerException e
) {
390 this.altitude
= -9999;
394 group
= racine
.getElementsByTagName("Depth");
395 this.depth
= Integer
.valueOf(group
.item(0).getTextContent());
396 } catch (NullPointerException e
) {
401 group
= racine
.getElementsByTagName("NamedArea");
402 this.namedAreaList
= new ArrayList
<String
>();
403 for (int i
=0;i
<group
.getLength();i
++){
404 childs
= group
.item(i
).getChildNodes();
405 for (int j
=0; j
<childs
.getLength();j
++){
406 if (childs
.item(j
).getNodeName() == "AreaName")
407 this.namedAreaList
.add(childs
.item(j
).getTextContent());
410 }catch(NullPointerException e
){
411 this.namedAreaList
= new ArrayList
<String
>();
415 private void getGatheringPeople(Element racine
){
416 NodeList group
, childs
, person
;
418 group
= racine
.getElementsByTagName("GatheringAgent");
419 this.gatheringAgentList
= new ArrayList
<String
>();
420 for (int i
=0; i
< group
.getLength(); i
++){
421 childs
= group
.item(i
).getChildNodes();
422 for (int j
=0; j
<childs
.getLength();j
++){
423 if (childs
.item(j
).getNodeName() == "Person"){
424 person
= childs
.item(j
).getChildNodes();
425 for (int k
=0; k
<person
.getLength(); k
++)
426 if (person
.item(k
).getNodeName() == "FullName")
427 this.gatheringAgentList
.add(person
.item(k
).getTextContent());
432 } catch (NullPointerException e
) {
433 this.gatheringAgentList
= new ArrayList
<String
>();
437 private Institution
getInstitution(String institutionCode
, SpecimenImportConfigurator config
){
438 Institution institution
;
439 List
<Institution
> institutions
;
441 System
.out
.println(this.institutionCode
);
442 institutions
= config
.getCdmAppController().getAgentService().searchInstitutionByCode(this.institutionCode
);
444 System
.out
.println("BLI "+e
);
445 institutions
=new ArrayList
<Institution
>();
447 if (institutions
.size() ==0 || !config
.getReUseExistingMetadata()){
448 System
.out
.println("Institution (agent) unknown or not allowed to reuse existing metadata");
450 institution
= Institution
.NewInstance();
451 institution
.setCode(this.institutionCode
);
454 System
.out
.println("Institution (agent) already in the db");
455 institution
= institutions
.get(0);
461 * Look if the Collection does already exists
462 * @param collectionCode: a string
463 * @param institution: the current Institution
465 * @return the Collection (existing or new)
467 private Collection
getCollection(String collectionCode
, Institution institution
, SpecimenImportConfigurator config
){
468 Collection collection
= Collection
.NewInstance();
469 List
<Collection
> collections
;
471 collections
= config
.getCdmAppController().getOccurrenceService().searchCollectionByCode(this.collectionCode
);
473 collections
=new ArrayList
<Collection
>();
475 if (collections
.size() ==0 || !config
.getReUseExistingMetadata()){
476 System
.out
.println("Collection not found or do not reuse existing metadata "+this.collectionCode
);
477 //create new collection
478 collection
.setCode(this.collectionCode
);
479 collection
.setCodeStandard("GBIF");
480 collection
.setInstitute(institution
);
483 boolean collectionFound
=false;
484 for (int i
=0; i
<collections
.size(); i
++){
485 collection
= collections
.get(i
);
487 if (collection
.getInstitute().getCode().equalsIgnoreCase(institution
.getCode())){
488 //found a collection with the same code and the same institution
489 collectionFound
=true;
491 } catch (NullPointerException e
) {}
493 if (!collectionFound
){
494 collection
.setCode(this.collectionCode
);
495 collection
.setCodeStandard("GBIF");
496 collection
.setInstitute(institution
);
506 * @param derivedThing
509 private void setTaxonNameBase(SpecimenImportConfigurator config
, DerivedUnitBase derivedThing
, ReferenceBase sec
){
510 TaxonNameBase taxonName
= null;
511 String fullScientificNameString
;
513 DeterminationEvent determinationEvent
= null;
514 List
<TaxonNameBase
> names
= null;
516 String scientificName
="";
517 boolean preferredFlag
=false;
519 for (int i
= 0; i
< this.identificationList
.size(); i
++) {
520 fullScientificNameString
= this.identificationList
.get(i
);
521 fullScientificNameString
= fullScientificNameString
.replaceAll(" et ", " & ");
522 if (fullScientificNameString
.indexOf("_preferred_") != -1){
523 scientificName
= fullScientificNameString
.split("_preferred_")[0];
524 String pTmp
= fullScientificNameString
.split("_preferred_")[1].split("_code_")[0];
525 if (pTmp
== "1" || pTmp
.toLowerCase().indexOf("true") != -1)
530 else scientificName
= fullScientificNameString
;
532 if (fullScientificNameString
.indexOf("_code_") != -1)
533 this.nomenclatureCode
= fullScientificNameString
.split("_code_")[1];
535 if (config
.getDoAutomaticParsing())
536 taxonName
= this.parseScientificName(scientificName
);
538 taxonName
.setTitleCache(scientificName
);
541 names
= config
.getCdmAppController().getNameService().getNamesByName(scientificName
);
542 if (names
.size() == 0){
543 System
.out
.println("Name not found: " + scientificName
);
545 if (names
.size() > 1){
546 System
.out
.println("More then 1 name found: " + scientificName
);
548 System
.out
.println("Name found");
549 taxonName
= names
.get(0);
553 config
.getCdmAppController().getNameService().saveTaxonName(taxonName
);
554 taxon
= Taxon
.NewInstance(taxonName
, sec
); //sec set null
556 determinationEvent
= DeterminationEvent
.NewInstance();
557 determinationEvent
.setTaxon(taxon
);
558 determinationEvent
.setPreferredFlag(preferredFlag
);
559 for (int l
=0;l
<this.referenceList
.size();l
++){
560 ReferenceBase reference
= new Generic();
561 reference
.setTitleCache(this.referenceList
.get(l
));
562 determinationEvent
.addReference(reference
);
564 derivedThing
.addDetermination(determinationEvent
);
569 private TaxonNameBase
parseScientificName(String scientificName
){
570 System
.out
.println("scientificName");
571 TaxonNameBase taxonName
= null;
572 NonViralNameParserImpl nvnpi
= NonViralNameParserImpl
.NewInstance();
574 System
.out
.println("nomenclature: "+this.nomenclatureCode
);
575 if (this.nomenclatureCode
== "Zoological"){
576 taxonName
= nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICZN(),null);
577 if (taxonName
.hasProblem())
578 System
.out
.println("pb ICZN");}
579 if (this.nomenclatureCode
== "Botanical"){
580 taxonName
= nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICBN(),null);
581 if (taxonName
.hasProblem())
582 System
.out
.println("pb ICBN");}
583 if (this.nomenclatureCode
== "Bacterial"){
584 taxonName
= nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICNB(), null);
585 if (taxonName
.hasProblem())
586 System
.out
.println("pb ICNB");
588 if (this.nomenclatureCode
== "Cultivar"){
589 taxonName
= nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICNCP(), null);
590 if (taxonName
.hasProblem())
591 System
.out
.println("pb ICNCP");
593 if (this.nomenclatureCode
== "Viral"){
594 taxonName
= nvnpi
.parseFullName(scientificName
,NomenclaturalCode
.ICVCN(), null);
595 if (taxonName
.hasProblem())
596 System
.out
.println("pb ICVCN");
598 try{taxonName
.hasProblem();}
599 catch (Exception e
) {
600 taxonName
= nvnpi
.parseFullName(scientificName
);
602 if (taxonName
.hasProblem())
603 taxonName
= nvnpi
.parseFullName(scientificName
);
607 * Store the unit with its Gathering informations in the CDM
609 public boolean start(SpecimenImportConfigurator config
){
610 boolean result
= true;
611 boolean withCdm
= true;
612 CdmApplicationController app
= null;
613 TransactionStatus tx
= null;
615 app
= config
.getCdmAppController();
617 // app = CdmApplicationController.NewInstance(config.getDestination(), config.getDbSchemaValidation());
618 // } catch (DataSourceNotFoundException e1) {
619 // e1.printStackTrace();
620 // System.out.println("DataSourceNotFoundException "+e1);
621 // } catch (TermNotFoundException e1) {
622 // e1.printStackTrace();
623 // System.out.println("TermNotFoundException " +e1);
626 tx
= app
.startTransaction();
628 // ReferenceBase sec = Database.NewInstance();
629 // sec.setTitleCache("XML DATA");
630 ReferenceBase sec
= null;
633 * SPECIMEN OR OBSERVATION OR LIVING
635 DerivedUnitBase derivedThing
= null;
637 boolean rbFound
=false;
638 if (this.recordBasis
!= null){
639 if (this.recordBasis
.toLowerCase().startsWith("s")) {//specimen
640 derivedThing
= Specimen
.NewInstance();
643 else if (this.recordBasis
.toLowerCase().startsWith("o")) {//observation
644 derivedThing
= Observation
.NewInstance();
647 else if (this.recordBasis
.toLowerCase().startsWith("l")) {//living -> fossil, herbarium sheet....???
648 derivedThing
= LivingBeing
.NewInstance();
652 logger
.info("The basis of record does not seem to be known: "+this.recordBasis
);
653 derivedThing
= DerivedUnit
.NewInstance();
657 logger
.info("The basis of record is null");
658 derivedThing
= DerivedUnit
.NewInstance();
660 // if(derivedThing == null)derivedThing=Observation.NewInstance();
662 this.setTaxonNameBase(config
, derivedThing
, sec
);
665 //set catalogue number (unitID)
666 derivedThing
.setCatalogNumber(this.unitID
);
667 derivedThing
.setAccessionNumber(this.accessionNumber
);
668 derivedThing
.setCollectorsNumber(this.collectorsNumber
);
672 * INSTITUTION & COLLECTION
675 Institution institution
= this.getInstitution(this.institutionCode
,config
);
677 Collection collection
= this.getCollection(this.collectionCode
, institution
, config
);
678 //link specimen & collection
679 derivedThing
.setCollection(collection
);
685 UnitsGatheringEvent unitsGatheringEvent
= new UnitsGatheringEvent(config
, this.locality
, this.languageIso
, this.longitude
,
686 this.latitude
, this.gatheringAgentList
);
687 UnitsGatheringArea unitsGatheringArea
= new UnitsGatheringArea(this.isocountry
, this.country
, config
);
688 NamedArea areaCountry
= unitsGatheringArea
.getArea();
689 unitsGatheringEvent
.addArea(areaCountry
);
690 unitsGatheringArea
= new UnitsGatheringArea(this.namedAreaList
);
691 ArrayList
<NamedArea
> nas
= unitsGatheringArea
.getAreas();
692 for (int i
=0; i
<nas
.size();i
++)
693 unitsGatheringEvent
.addArea(nas
.get(i
));
696 //create field/observation
697 FieldObservation fieldObservation
= FieldObservation
.NewInstance();
699 fieldObservation
.setFieldNumber(this.fieldNumber
);
700 //join gatheringEvent to fieldObservation
701 fieldObservation
.setGatheringEvent(unitsGatheringEvent
.getGatheringEvent());
702 // //add Multimedia URLs
703 if(this.multimediaObjects
.size()>0){
704 MediaRepresentationPart part
;
705 MediaRepresentation representation
;
707 for (int i
=0;i
<this.multimediaObjects
.size();i
++){
708 part
= MediaRepresentationPart
.NewInstance(this.multimediaObjects
.get(i
),0);
709 //TODO update the Multimedia Object without size :)
710 representation
= MediaRepresentation
.NewInstance();
711 representation
.addRepresentationPart(part
);
712 media
= Media
.NewInstance();
713 media
.addRepresentation(representation
);
714 fieldObservation
.addMedia(media
);
717 // //link fieldObservation and specimen
718 DerivationEvent derivationEvent
= DerivationEvent
.NewInstance();
719 derivationEvent
.addOriginal(fieldObservation
);
720 derivedThing
.addDerivationEvent(derivationEvent
);
723 * SAVE AND STORE DATA
726 app
.getTermService().saveTerm(areaCountry
);//save it sooner
727 for (int i
=0; i
<nas
.size();i
++)
728 app
.getTermService().saveTerm(nas
.get(i
));//save it sooner (foreach area)
729 app
.getTermService().saveLanguageData(unitsGatheringEvent
.getLocality());//save it sooner
730 app
.getOccurrenceService().saveSpecimenOrObservationBase(derivedThing
);
732 logger
.info("saved new specimen ...");
735 } catch (Exception e
) {
736 logger
.warn("Error when reading record!!");
740 app
.commitTransaction(tx
);
741 System
.out
.println("commit done");
747 public boolean invoke(SpecimenImportConfigurator config
){
748 System
.out
.println("INVOKE Specimen Import from ABCD2.06 XML File");
749 AbcdIO test
= new AbcdIO();
750 String sourceName
= config
.getSourceNameString();
751 NodeList unitsList
= getUnitsNodeList(sourceName
);
752 if (unitsList
!= null)
754 System
.out
.println("nb units to insert: "+unitsList
.getLength());
755 for (int i
=0;i
<unitsList
.getLength();i
++){
756 test
.setUnitPropertiesXML((Element
)unitsList
.item(i
));
758 config
.setDbSchemaValidation(DbSchemaValidation
.UPDATE
);
767 public boolean invoke(IImportConfigurator config
, Map stores
) {
768 System
.out
.println("invoke de ABCDio");
769 invoke((SpecimenImportConfigurator
)config
);