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
.sdd
;
13 import java
.net
.MalformedURLException
;
16 import java
.text
.SimpleDateFormat
;
17 import java
.util
.ArrayList
;
18 import java
.util
.Date
;
19 import java
.util
.HashMap
;
20 import java
.util
.HashSet
;
21 import java
.util
.Iterator
;
22 import java
.util
.List
;
26 import org
.apache
.log4j
.Logger
;
27 import org
.jdom
.Element
;
28 import org
.jdom
.Namespace
;
29 import org
.joda
.time
.DateTime
;
30 import org
.springframework
.stereotype
.Component
;
31 import org
.springframework
.transaction
.TransactionStatus
;
33 import eu
.etaxonomy
.cdm
.api
.service
.IAgentService
;
34 import eu
.etaxonomy
.cdm
.api
.service
.IVersionableService
;//rajout
35 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
36 import eu
.etaxonomy
.cdm
.api
.service
.IReferenceService
;
37 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
38 import eu
.etaxonomy
.cdm
.common
.mediaMetaData
.ImageMetaData
;
39 import eu
.etaxonomy
.cdm
.io
.common
.CdmImportBase
;
40 import eu
.etaxonomy
.cdm
.io
.common
.ICdmImport
;
41 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
42 import eu
.etaxonomy
.cdm
.io
.common
.ImportHelper
;
43 import eu
.etaxonomy
.cdm
.model
.agent
.Contact
;
44 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
45 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
46 import eu
.etaxonomy
.cdm
.model
.agent
.Address
;//rajout
47 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
48 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
49 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
50 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
51 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
52 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
53 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
54 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
55 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
56 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
57 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
58 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
59 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
60 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
61 import eu
.etaxonomy
.cdm
.model
.common
.User
;
62 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
63 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
64 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
65 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
66 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
67 import eu
.etaxonomy
.cdm
.model
.description
.MeasurementUnit
;
68 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
69 import eu
.etaxonomy
.cdm
.model
.description
.State
;
70 import eu
.etaxonomy
.cdm
.model
.description
.StateData
;
71 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasure
;
72 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasurementValue
;
73 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
74 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
75 import eu
.etaxonomy
.cdm
.model
.description
.Modifier
;
76 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonomicTree
;
77 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
78 import eu
.etaxonomy
.cdm
.model
.media
.ImageFile
;
79 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
80 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
81 import eu
.etaxonomy
.cdm
.model
.media
.IdentifiableMediaEntity
;
82 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentationPart
;
83 import eu
.etaxonomy
.cdm
.model
.media
.Rights
;
84 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
85 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
86 import eu
.etaxonomy
.cdm
.model
.reference
.IArticle
;
87 import eu
.etaxonomy
.cdm
.model
.reference
.IDatabase
;
88 import eu
.etaxonomy
.cdm
.model
.reference
.IGeneric
;
89 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
90 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
91 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
92 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
99 @Component("sddDescriptionIO")
100 public class SDDDescriptionIO
extends CdmImportBase
<SDDImportConfigurator
, SDDImportState
> implements ICdmImport
<SDDImportConfigurator
, SDDImportState
> {
101 private static final Logger logger
= Logger
.getLogger(SDDDescriptionIO
.class);
103 private static int modCount
= 1000;
105 private Map
<String
,Person
> authors
= new HashMap
<String
,Person
>();
106 private Map
<String
,String
> citations
= new HashMap
<String
,String
>();
107 private Map
<String
,String
> defaultUnitPrefixes
= new HashMap
<String
,String
>();
108 private Map
<String
,Person
> editors
= new HashMap
<String
,Person
>();
109 private Map
<String
,FeatureNode
> featureNodes
= new HashMap
<String
,FeatureNode
>();
110 private Map
<String
,Feature
> features
= new HashMap
<String
,Feature
>();
111 private Map
<String
,String
> locations
= new HashMap
<String
,String
>();
112 private Map
<String
,List
<CdmBase
>> mediaObject_ListCdmBase
= new HashMap
<String
,List
<CdmBase
>>();
113 private Map
<String
,String
> mediaObject_Role
= new HashMap
<String
,String
>();
114 private Map
<String
,FeatureNode
> nodes
= new HashMap
<String
,FeatureNode
>();
115 private Map
<String
,ReferenceBase
> publications
= new HashMap
<String
,ReferenceBase
>();
116 private Map
<String
,StateData
> stateDatas
= new HashMap
<String
,StateData
>();
117 private Map
<String
,TaxonDescription
> taxonDescriptions
= new HashMap
<String
,TaxonDescription
>();
118 private Map
<String
,NonViralName
> taxonNameBases
= new HashMap
<String
,NonViralName
>();
119 private Map
<String
,MeasurementUnit
> units
= new HashMap
<String
,MeasurementUnit
>();
120 private Map
<String
,TaxonNode
> taxonNodes
= new HashMap
<String
,TaxonNode
>();
122 private Set
<AnnotationType
> annotationTypes
= new HashSet
<AnnotationType
>();
123 private Set
<Feature
> featureSet
= new HashSet
<Feature
>();
124 ReferenceFactory refFactory
= ReferenceFactory
.newInstance();
125 private ReferenceBase sec
= refFactory
.newDatabase();
126 private ReferenceBase sourceReference
= null;
128 private Language datasetLanguage
= null;
130 private Namespace xmlNamespace
= Namespace
.getNamespace("xml","http://www.w3.org/XML/1998/namespace");
132 private String generatorName
= "";
133 private String generatorVersion
= "";
135 private Set
<StatisticalMeasure
> statisticalMeasures
= new HashSet
<StatisticalMeasure
>();
136 private Set
<VersionableEntity
> featureData
= new HashSet
<VersionableEntity
>();
137 private Set
<FeatureTree
> featureTrees
= new HashSet
<FeatureTree
>();
138 private Set
<TaxonomicTree
> taxonomicTrees
= new HashSet
<TaxonomicTree
>();
140 private Rights copyright
= null;
142 public SDDDescriptionIO(){
147 public boolean doCheck(SDDImportState state
){
148 boolean result
= true;
149 logger
.warn("No check implemented for SDD");
154 // public boolean doInvoke(IImportConfigurator config, Map<String, MapWrapper<? extends CdmBase>> stores){
156 public boolean doInvoke(SDDImportState state
){
158 TransactionStatus ts
= startTransaction();
159 SDDImportConfigurator sddConfig
= state
.getConfig();
161 logger
.info("start Datasets ...");
162 // <Datasets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://rs.tdwg.org/UBIF/2006/" xsi:schemaLocation="http://rs.tdwg.org/UBIF/2006/ ../SDD.xsd">
163 Element root
= sddConfig
.getSourceRoot();
164 boolean success
= true;
165 Namespace sddNamespace
= sddConfig
.getSddNamespace();
167 logger
.info("start TechnicalMetadata ...");
168 // <TechnicalMetadata created="2006-04-20T10:00:00">
169 importTechnicalMetadata(root
, sddNamespace
, sddConfig
);
170 List
<Element
> elDatasets
= root
.getChildren("Dataset",sddNamespace
);
174 logger
.info("start Dataset ...");
175 for (Element elDataset
: elDatasets
){
176 importDataset(elDataset
, sddNamespace
, success
, sddConfig
);
177 if ((++i
% modCount
) == 0){ logger
.info("Datasets handled: " + i
);}
178 logger
.info(i
+ " Datasets handled");
180 commitTransaction(ts
);
185 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
187 protected boolean isIgnore(SDDImportState state
){
192 // associates the reference of a media object in SDD with a CdmBase Object
193 protected void associateImageWithCdmBase(String refMO
, CdmBase cb
){
194 if ((refMO
!= null) && (cb
!=null)) {
195 if (!refMO
.equals("")) {
196 if (!mediaObject_ListCdmBase
.containsKey(refMO
)) {
197 List
<CdmBase
> lcb
= new ArrayList
<CdmBase
>();
199 mediaObject_ListCdmBase
.put(refMO
,lcb
);
201 List
<CdmBase
> lcb
= mediaObject_ListCdmBase
.get(refMO
);
203 mediaObject_ListCdmBase
.put(refMO
,lcb
);
209 // imports information about the Dataset
210 protected void importDatasetRepresentation(Element parent
, Namespace sddNamespace
){
211 logger
.info("start Representation ...");
213 <Label>The Genus Viola</Label>
214 <Detail>This is an example for a very simple SDD file, representing a single description with categorical, quantitative, and text character. Compare also the "Fragment*" examples, which contain more complex examples in the form of document fragments. Intended for version="SDD 1.1".</Detail>
217 Element elRepresentation
= parent
.getChild("Representation",sddNamespace
);
218 String label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
219 String detail
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Detail",sddNamespace
);
221 sec
.setTitleCache(label
);
223 if (detail
!= null) {
224 Annotation annotation
= Annotation
.NewInstance(detail
, datasetLanguage
);
225 annotation
.setAnnotationType(AnnotationType
.EDITORIAL());
226 sec
.addAnnotation(annotation
);
229 List
<Element
> listMediaObjects
= elRepresentation
.getChildren("MediaObject",sddNamespace
);
231 for (Element elMediaObject
: listMediaObjects
) {
234 if (elMediaObject
!= null) {
235 ref
= elMediaObject
.getAttributeValue("ref");
236 role
= elMediaObject
.getAttributeValue("role");
239 if (!ref
.equals("")) {
240 this.associateImageWithCdmBase(ref
,sourceReference
);
241 this.associateImageWithCdmBase(ref
,sec
);
242 mediaObject_Role
.put(ref
,role
);
248 // imports the representation (label, detail, lang) of a particular SDD element
249 protected void importRepresentation(Element parent
, Namespace sddNamespace
, VersionableEntity ve
, String id
, IImportConfigurator config
){
250 Element elRepresentation
= parent
.getChild("Representation",sddNamespace
);
251 // <Label xml:lang="la">Viola hederacea Labill.</Label>
252 List
<Element
> listLabels
= elRepresentation
.getChildren("Label",sddNamespace
);
253 List
<Element
> listDetails
= elRepresentation
.getChildren("Detail",sddNamespace
);
254 Map
<Language
,List
<String
>> langLabDet
= new HashMap
<Language
,List
<String
>>();
256 for (Element elLabel
: listLabels
){
257 String lang
= elLabel
.getAttributeValue("lang",xmlNamespace
);
258 Language language
= null;
260 if (!lang
.equals("")) {
261 language
= getTermService().getLanguageByIso(lang
.substring(0, 2));
263 language
= datasetLanguage
;
266 language
= datasetLanguage
;
268 String label
= elLabel
.getText();
269 List
<String
> labDet
= new ArrayList
<String
>(3);
271 langLabDet
.put(language
, labDet
);
274 for (Element elDetail
: listDetails
){
275 String lang
= elDetail
.getAttributeValue("lang",xmlNamespace
);
276 String role
= elDetail
.getAttributeValue("role");
277 Language language
= null;
279 if (!lang
.equals("")) {
280 language
= getTermService().getLanguageByIso(lang
.substring(0, 2));
282 language
= datasetLanguage
;
285 language
= datasetLanguage
;
287 String detail
= elDetail
.getText();
288 List
<String
> labDet
= langLabDet
.get(language
);
291 langLabDet
.put(language
, labDet
);
294 if (ve
instanceof TermBase
) {
295 TermBase tb
= (TermBase
) ve
;
297 for (Iterator
<Language
> l
= langLabDet
.keySet().iterator() ; l
.hasNext() ;){
298 Language lang
= l
.next();
299 List
<String
> labDet
= langLabDet
.get(lang
);
300 if (labDet
.size()>0){
301 if (labDet
.size()>1) {
302 tb
.addRepresentation(Representation
.NewInstance(labDet
.get(1), labDet
.get(0), labDet
.get(0), lang
));
304 tb
.addRepresentation(Representation
.NewInstance(labDet
.get(0), labDet
.get(0), labDet
.get(0), lang
));
310 } else if (ve
instanceof Media
) {
311 Media m
= (Media
) ve
;
313 for (Iterator
<Language
> l
= langLabDet
.keySet().iterator() ; l
.hasNext() ;){
314 Language lang
= l
.next();
315 List
<String
> labDet
= langLabDet
.get(lang
);
316 if (labDet
.get(0) != null){
317 m
.addTitle(LanguageString
.NewInstance(labDet
.get(0), lang
));
319 if (labDet
.size()>1) {
320 m
.addDescription(labDet
.get(1), lang
);
327 if (ve
instanceof IdentifiableEntity
) {
328 IdentifiableEntity ie
= (IdentifiableEntity
) ve
;
329 List
<String
> labDet
= null;
331 if (ve
instanceof TaxonNameBase
) {
332 if (langLabDet
.keySet().contains(getTermService().getLanguageByIso("la"))) {
333 labDet
= langLabDet
.get(getTermService().getLanguageByIso("la"));
334 } else if (langLabDet
.keySet().contains(datasetLanguage
)) {
335 labDet
= langLabDet
.get(datasetLanguage
);
336 logger
.info("TaxonName " + (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
) + " is not specified as a latin name.");
338 labDet
= langLabDet
.get(langLabDet
.keySet().iterator().next());
339 logger
.info("TaxonName " + (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
) + " is not specified as a latin name.");
342 labDet
= langLabDet
.get(langLabDet
.keySet().iterator().next());
345 ie
.setTitleCache(labDet
.get(0));
347 if (labDet
.size()>1) {
348 Annotation annotation
= null;
349 if (labDet
.get(1) != null) {
350 if (labDet
.get(2) != null) {
351 annotation
= Annotation
.NewInstance(labDet
.get(2) + " - " + labDet
.get(1), datasetLanguage
);
353 annotation
= Annotation
.NewInstance(labDet
.get(1), datasetLanguage
);
356 ie
.addAnnotation(annotation
);
363 if (ve
instanceof IdentifiableMediaEntity
){
364 IdentifiableMediaEntity ime
= (IdentifiableMediaEntity
) ve
;
365 Element elLinks
= parent
.getChild("Links",sddNamespace
);
367 if (elLinks
!= null) {
369 // <Link rel="Alternate" href="http://www.diversitycampus.net/people/hagedorn"/>
370 List
<Element
> listLinks
= elLinks
.getChildren("Link", sddNamespace
);
371 Media link
= Media
.NewInstance();
372 MediaRepresentation mr
= MediaRepresentation
.NewInstance();
375 for (Element elLink
: listLinks
){
379 String rel
= elLink
.getAttributeValue("rel");
380 String href
= elLink
.getAttributeValue("href");
382 mr
.addRepresentationPart(MediaRepresentationPart
.NewInstance(href
, null));
383 link
.addRepresentation(mr
);
386 } catch (Exception e
) {
388 logger
.warn("Import of Link " + k
+ " failed.");
391 if ((++k
% modCount
) == 0){ logger
.info("Links handled: " + k
);}
397 List
<Element
> listMediaObjects
= elRepresentation
.getChildren("MediaObject",sddNamespace
);
398 for (Element elMediaObject
: listMediaObjects
) {
401 if (elMediaObject
!= null) {
402 ref
= elMediaObject
.getAttributeValue("ref");
403 role
= elMediaObject
.getAttributeValue("role");
406 if (!ref
.equals("")) {
408 if (ve
instanceof TaxonDescription
) {
409 TaxonDescription td
= (TaxonDescription
) ve
;
410 //TODO: ensure that all images are imported
411 if (td
.getDescriptionSources().toArray().length
> 0) {
412 this.associateImageWithCdmBase(ref
,(ReferenceBase
) td
.getDescriptionSources().toArray()[0]);
414 ReferenceBase descriptionSource
= refFactory
.newGeneric();
415 td
.addDescriptionSource(descriptionSource
);
416 this.associateImageWithCdmBase(ref
,descriptionSource
);
419 //System.out.println(parent.getName());
420 this.associateImageWithCdmBase(ref
,ve
);
430 // imports the representation (label, detail, lang) of a particular SDD element
431 protected void importTechnicalMetadata(Element root
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
432 Element elTechnicalMetadata
= root
.getChild("TechnicalMetadata", sddNamespace
);
433 String nameCreated
= elTechnicalMetadata
.getAttributeValue("created");
434 sourceReference
= sddConfig
.getSourceReference();
436 if (nameCreated
!= null) {
437 if (!nameCreated
.equals("")) {
438 int year
= Integer
.parseInt(nameCreated
.substring(0,4));
439 int monthOfYear
= Integer
.parseInt(nameCreated
.substring(5,7));
440 int dayOfMonth
= Integer
.parseInt(nameCreated
.substring(8,10));
441 int hourOfDay
= Integer
.parseInt(nameCreated
.substring(11,13));
442 int minuteOfHour
= Integer
.parseInt(nameCreated
.substring(14,16));
443 int secondOfMinute
= Integer
.parseInt(nameCreated
.substring(17,19));
444 DateTime created
= new DateTime(year
,monthOfYear
,dayOfMonth
,hourOfDay
,minuteOfHour
,secondOfMinute
,0);
445 sourceReference
.setCreated(created
);
446 sec
.setCreated(created
);
450 // <Generator name="n/a, handcrafted instance document" version="n/a"/>
451 Element elGenerator
= elTechnicalMetadata
.getChild("Generator", sddNamespace
);
452 generatorName
= elGenerator
.getAttributeValue("name");
453 generatorVersion
= elGenerator
.getAttributeValue("version");
455 sec
.addAnnotation(Annotation
.NewDefaultLanguageInstance(generatorName
+ " - " + generatorVersion
));
456 sourceReference
.addAnnotation(Annotation
.NewDefaultLanguageInstance(generatorName
+ " - " + generatorVersion
));
460 // imports the complete dataset information
461 protected void importDataset(Element elDataset
, Namespace sddNamespace
, boolean success
, SDDImportConfigurator sddConfig
){ // <Dataset xml:lang="en-us">
463 importDatasetLanguage(elDataset
,sddConfig
);
464 importDatasetRepresentation(elDataset
, sddNamespace
);
465 importRevisionData(elDataset
, sddNamespace
);
466 importIPRStatements(elDataset
, sddNamespace
, sddConfig
);
467 importTaxonNames(elDataset
, sddNamespace
, sddConfig
);
468 importDescriptiveConcepts(elDataset
, sddNamespace
, sddConfig
);
469 importCharacters(elDataset
, sddNamespace
, sddConfig
, success
);
470 importCharacterTrees(elDataset
, sddNamespace
, sddConfig
, success
);
471 importCodedDescriptions(elDataset
, sddNamespace
, sddConfig
, success
);
472 importAgents(elDataset
, sddNamespace
, sddConfig
, success
);
473 importPublications(elDataset
, sddNamespace
, sddConfig
, success
);
474 importMediaObjects(elDataset
, sddNamespace
, sddConfig
, success
);
475 importTaxonHierarchies(elDataset
, sddNamespace
, sddConfig
, success
);
478 MarkerType editou
= MarkerType
.NewInstance("Editor", "editor", "edt") ;
479 if (authors
!= null) {
480 Team team
= Team
.NewInstance();
481 for (Iterator
<Person
> author
= authors
.values().iterator() ; author
.hasNext() ;){
482 team
.addTeamMember(author
.next());
484 if (editors
!= null) {
485 Marker marker
= Marker
.NewInstance();
486 marker
.setMarkerType(editou
);
487 for (Iterator
<Person
> editor
= editors
.values().iterator() ; editor
.hasNext() ;){
488 Person edit
= editor
.next();
489 edit
.addMarker(marker
);
490 team
.addTeamMember(edit
);
493 sec
.setAuthorTeam(team
);
494 sourceReference
.setAuthorTeam(team
);
497 if (editors
!= null) {
498 Person ed
= Person
.NewInstance();
499 for (Iterator
<Person
> editor
= editors
.values().iterator() ; editor
.hasNext() ;){
502 // TODO updatedBy refactored to use a user account, so setting a person is no longer applicable
503 // sec.setUpdatedBy(ed);
504 // sourceReference.setUpdatedBy(ed);
507 if (copyright
!= null) {
508 sourceReference
.addRights(copyright
);
509 sec
.addRights(copyright
);
512 for (Iterator
<String
> refCD
= taxonDescriptions
.keySet().iterator() ; refCD
.hasNext() ;){
513 String ref
= refCD
.next();
514 TaxonDescription td
= taxonDescriptions
.get(ref
);
515 td
.addDescriptionSource(sec
);
516 if (citations
.containsKey(ref
)) {
517 IArticle publication
= (IArticle
) publications
.get(citations
.get(ref
));
518 if (locations
.containsKey(ref
)) {
519 Annotation location
= Annotation
.NewInstance(locations
.get(ref
), datasetLanguage
);
520 AnnotationType annotationType
= AnnotationType
.NewInstance("", "location", "");
521 annotationTypes
.add(annotationType
);
522 location
.setAnnotationType(annotationType
);
523 ((ReferenceBase
)publication
).addAnnotation(location
);
525 td
.addDescriptionSource((ReferenceBase
)publication
);
528 logger
.info("end makeTaxonDescriptions ...");
530 //sddConfig.setSourceReference(sourceReference);
532 //saving of all imported data into the CDM db
533 ITermService termService
= getTermService();
534 for (Iterator
<StateData
> k
= stateDatas
.values().iterator() ; k
.hasNext() ;){
535 StateData sd
= k
.next();
536 termService
.save(sd
.getState());
538 for (Iterator
<Feature
> k
= features
.values().iterator() ; k
.hasNext() ;){
539 Feature feature
= k
.next();
540 termService
.save(feature
);
542 termService
.save(editou
);
544 for (Iterator
<MeasurementUnit
> k
= units
.values().iterator() ; k
.hasNext() ;){
545 MeasurementUnit unit
= k
.next();
547 termService
.save(unit
);
551 for (Iterator
<StatisticalMeasure
> k
= statisticalMeasures
.iterator() ; k
.hasNext() ;) {
552 StatisticalMeasure sm
= k
.next();
553 termService
.save(sm
);
556 for (Iterator
<AnnotationType
> at
= annotationTypes
.iterator() ; at
.hasNext() ;) {
557 AnnotationType annotationType
= at
.next();
558 termService
.save(annotationType
);
561 IReferenceService referenceService
= getReferenceService();
562 // referenceService.saveReference(sourceReference);
563 for (Iterator
<ReferenceBase
> k
= publications
.values().iterator() ; k
.hasNext() ;){
564 ReferenceBase publication
= (ReferenceBase
) k
.next();
565 referenceService
.save(publication
);
568 IAgentService agentService
= getAgentService();/*
569 for (Iterator<Person> p = authors.values().iterator() ; p.hasNext() ;) {
570 Contact contact = new Contact();
571 Person person = p.next();
572 Address address = Address.NewInstance();
573 address.setRegion("Ondurera");
574 contact.addAddress(address);
575 person.setContact(contact);
576 agentService.save(person);
579 /* editors.put("id10", Person.NewTitledInstance("Maxou"));
580 for (Iterator<Person> p = editors.values().iterator() ; p.hasNext() ;) {
581 Person person = p.next();
582 agentService.save(person);
584 Person mixou = Person.NewInstance();
586 agentService.save(Person.NewTitledInstance("Mixou"));
587 Institution instit = Institution.NewInstance();
588 instit.setName("Maxtitution");
589 agentService.save(instit);*/
591 // Returns a CdmApplicationController created by the values of this configuration.
592 IDescriptionService descriptionService
= getDescriptionService();
594 for (Iterator
<TaxonDescription
> k
= taxonDescriptions
.values().iterator() ; k
.hasNext() ;){
595 TaxonDescription taxonDescription
= k
.next();
596 // Persists a Description
597 descriptionService
.save(taxonDescription
);
600 //descriptionService.saveFeatureNodeAll(featureNodes.values());
602 for (Iterator
<FeatureTree
> k
= featureTrees
.iterator() ; k
.hasNext() ;) {
603 FeatureTree tree
= k
.next();
604 getFeatureTreeService().save(tree
);
607 for (Iterator
<TaxonomicTree
> k
= taxonomicTrees
.iterator() ; k
.hasNext() ;) {
608 TaxonomicTree tree
= k
.next();
609 getTaxonTreeService().save(tree
);
614 // imports the default language of the dataset
615 protected void importDatasetLanguage(Element elDataset
, SDDImportConfigurator sddConfig
){
616 String nameLang
= elDataset
.getAttributeValue("lang",xmlNamespace
);
618 if (!nameLang
.equals("")) {
619 String iso
= nameLang
.substring(0, 2);
620 datasetLanguage
= getTermService().getLanguageByIso(iso
);
622 datasetLanguage
= Language
.ENGLISH();
624 if (datasetLanguage
== null) {
625 datasetLanguage
= Language
.ENGLISH();
634 // imports the revision data associated with the Dataset (authors, modifications)
635 protected void importRevisionData(Element elDataset
, Namespace sddNamespace
){
637 logger
.info("start RevisionData ...");
638 Element elRevisionData
= elDataset
.getChild("RevisionData",sddNamespace
);
639 if (elRevisionData
!= null){
641 Element elCreators
= elRevisionData
.getChild("Creators",sddNamespace
);
643 // <Agent role="aut" ref="a1"/>
644 List
<Element
> listAgents
= elCreators
.getChildren("Agent", sddNamespace
);
648 for (Element elAgent
: listAgents
){
650 String role
= elAgent
.getAttributeValue("role");
651 String ref
= elAgent
.getAttributeValue("ref");
652 if (role
.equals("aut")) {
653 if(!ref
.equals("")) {
654 authors
.put(ref
, null);
657 if (role
.equals("edt")) {
658 if(!ref
.equals("")) {
659 editors
.put(ref
, null);
662 if ((++j
% modCount
) == 0){ logger
.info("Agents handled: " + j
);}
666 // <DateModified>2006-04-08T00:00:00</DateModified>
667 String stringDateModified
= (String
)ImportHelper
.getXmlInputValue(elRevisionData
, "DateModified",sddNamespace
);
669 if (stringDateModified
!= null) {
670 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
673 d
= sdf
.parse(stringDateModified
);
674 } catch(Exception e
) {
675 System
.err
.println("Exception :");
679 DateTime updated
= null;
681 updated
= new DateTime(d
);
682 sourceReference
.setUpdated(updated
);
683 sec
.setUpdated(updated
);
689 // imports ipr statements associated with a dataset
690 protected void importIPRStatements(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
692 logger
.info("start IPRStatements ...");
693 Element elIPRStatements
= elDataset
.getChild("IPRStatements",sddNamespace
);
694 // <IPRStatement role="Copyright">
695 if (elIPRStatements
!= null) {
696 List
<Element
> listIPRStatements
= elIPRStatements
.getChildren("IPRStatement", sddNamespace
);
698 //for each IPRStatement
700 for (Element elIPRStatement
: listIPRStatements
){
702 String role
= elIPRStatement
.getAttributeValue("role");
703 // <Label xml:lang="en-au">(c) 2003-2006 Centre for Occasional Botany.</Label>
704 Element elLabel
= elIPRStatement
.getChild("Label",sddNamespace
);
706 if (elLabel
!= null) {
707 lang
= elLabel
.getAttributeValue("lang",xmlNamespace
);
709 String label
= (String
)ImportHelper
.getXmlInputValue(elIPRStatement
, "Label",sddNamespace
);
711 if (role
.equals("Copyright")) {
712 Language iprLanguage
= null;
714 if (!lang
.equals("")) {
715 iprLanguage
= getTermService().getLanguageByIso(lang
.substring(0, 2));
716 //iprLanguage = datasetLanguage;
718 iprLanguage
= datasetLanguage
;
721 if (iprLanguage
== null) {
722 iprLanguage
= datasetLanguage
;
724 copyright
= Rights
.NewInstance(label
, iprLanguage
);
727 if (copyright
!= null) {
728 sourceReference
.addRights(copyright
);
729 sec
.addRights(copyright
);
732 if ((++j
% modCount
) == 0){ logger
.info("IPRStatements handled: " + j
);}
738 // imports the taxon names
739 protected void importTaxonNames(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
741 logger
.info("start TaxonNames ...");
742 Element elTaxonNames
= elDataset
.getChild("TaxonNames",sddNamespace
);
743 // <TaxonName id="t1" uri="urn:lsid:authority:namespace:my-own-id">
744 if (elTaxonNames
!= null) {
745 List
<Element
> listTaxonNames
= elTaxonNames
.getChildren("TaxonName", sddNamespace
);
748 for (Element elTaxonName
: listTaxonNames
){
750 String id
= elTaxonName
.getAttributeValue("id");
751 String uri
= elTaxonName
.getAttributeValue("uri");
753 NonViralName tnb
= null;
754 if (!id
.equals("")) {
755 tnb
= NonViralName
.NewInstance(null);
756 IdentifiableSource source
= null;
758 if (!uri
.equals("")) {
759 source
= IdentifiableSource
.NewInstance(id
, "TaxonName", refFactory
.newGeneric(), uri
);
762 source
= IdentifiableSource
.NewInstance(id
, "TaxonName");
764 tnb
.addSource(source
);
765 taxonNameBases
.put(id
,tnb
);
769 // <Label xml:lang="la">Viola hederacea Labill.</Label>
770 importRepresentation(elTaxonName
, sddNamespace
, tnb
, id
, sddConfig
);
772 if ((++j
% modCount
) == 0){ logger
.info("TaxonNames handled: " + j
);}
778 // imports the representation (label, detail, lang) of a particular SDD element
779 protected void importCharacters(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
781 logger
.info("start Characters ...");
782 Element elCharacters
= elDataset
.getChild("Characters", sddNamespace
);
784 // <CategoricalCharacter id="c1">
785 if (elCharacters
!= null) {
786 List
<Element
> elCategoricalCharacters
= elCharacters
.getChildren("CategoricalCharacter", sddNamespace
);
788 //for each CategoricalCharacter
789 for (Element elCategoricalCharacter
: elCategoricalCharacters
){
792 String idCC
= elCategoricalCharacter
.getAttributeValue("id");
795 // <Label> Leaf complexity</Label>
798 Feature categoricalCharacter
= Feature
.NewInstance();
799 categoricalCharacter
.setKindOf(Feature
.DESCRIPTION());
800 importRepresentation(elCategoricalCharacter
, sddNamespace
, categoricalCharacter
, idCC
, sddConfig
);
802 categoricalCharacter
.setSupportsCategoricalData(true);
805 Element elStates
= elCategoricalCharacter
.getChild("States",sddNamespace
);
807 // <StateDefinition id="s1">
808 List
<Element
> elStateDefinitions
= elStates
.getChildren("StateDefinition",sddNamespace
);
809 TermVocabulary
<State
> termVocabularyState
= new TermVocabulary
<State
>();
811 //for each StateDefinition
812 for (Element elStateDefinition
: elStateDefinitions
){
814 if ((++k
% modCount
) == 0){ logger
.info("StateDefinitions handled: " + (k
-1));}
816 String idSD
= elStateDefinition
.getAttributeValue("id");
818 // <Label>Simple</Label>
819 // <MediaObject ref="ib" role="Primary"/>
821 State state
= State
.NewInstance();
822 importRepresentation(elStateDefinition
, sddNamespace
, state
, idSD
, sddConfig
);
824 StateData stateData
= StateData
.NewInstance();
825 stateData
.setState(state
);
826 termVocabularyState
.addTerm(state
);
827 stateDatas
.put(idSD
,stateData
);
829 categoricalCharacter
.addSupportedCategoricalEnumeration(termVocabularyState
);
830 features
.put(idCC
, categoricalCharacter
);
832 } catch (Exception e
) {
834 logger
.warn("Import of CategoricalCharacter " + j
+ " failed.");
838 if ((++j
% modCount
) == 0){ logger
.info("CategoricalCharacters handled: " + j
);}
842 // <QuantitativeCharacter id="c2">
843 List
<Element
> elQuantitativeCharacters
= elCharacters
.getChildren("QuantitativeCharacter", sddNamespace
);
845 //for each QuantitativeCharacter
846 for (Element elQuantitativeCharacter
: elQuantitativeCharacters
){
850 String idQC
= elQuantitativeCharacter
.getAttributeValue("id");
853 // <Label>Leaf length</Label>
855 Feature quantitativeCharacter
= Feature
.NewInstance();
856 quantitativeCharacter
.setKindOf(Feature
.DESCRIPTION());
857 importRepresentation(elQuantitativeCharacter
, sddNamespace
, quantitativeCharacter
, idQC
, sddConfig
);
859 quantitativeCharacter
.setSupportsQuantitativeData(true);
862 // <Label role="Abbrev">m</Label>
863 // </MeasurementUnit>
864 Element elMeasurementUnit
= elQuantitativeCharacter
.getChild("MeasurementUnit",sddNamespace
);
867 if (elMeasurementUnit
!= null) {
868 Element elLabel
= elMeasurementUnit
.getChild("Label",sddNamespace
);
869 role
= elLabel
.getAttributeValue("role");
870 label
= (String
)ImportHelper
.getXmlInputValue(elMeasurementUnit
, "Label",sddNamespace
);
873 MeasurementUnit unit
= null;
874 if (!label
.equals("")){
876 if (role
.equals("Abbrev")){
877 unit
= MeasurementUnit
.NewInstance(label
,label
,label
);
880 unit
= MeasurementUnit
.NewInstance(label
,label
,label
);
885 units
.put(idQC
, unit
);
889 // <MeasurementUnitPrefix>milli</MeasurementUnitPrefix>
891 Element elDefault
= elQuantitativeCharacter
.getChild("Default",sddNamespace
);
892 if (elDefault
!= null) {
893 String measurementUnitPrefix
= (String
)ImportHelper
.getXmlInputValue(elDefault
, "MeasurementUnitPrefix",sddNamespace
);
894 if (!measurementUnitPrefix
.equals("")){
895 defaultUnitPrefixes
.put(idQC
, measurementUnitPrefix
);
899 features
.put(idQC
, quantitativeCharacter
);
901 } catch (Exception e
) {
903 logger
.warn("Import of QuantitativeCharacter " + j
+ " failed.");
907 if ((++j
% modCount
) == 0){ logger
.info("QuantitativeCharacters handled: " + j
);}
911 // <TextCharacter id="c3">
912 List
<Element
> elTextCharacters
= elCharacters
.getChildren("TextCharacter", sddNamespace
);
914 //for each TextCharacter
915 for (Element elTextCharacter
: elTextCharacters
){
919 String idTC
= elTextCharacter
.getAttributeValue("id");
922 // <Label xml:lang="en">Leaf features not covered by other characters</Label>
924 Feature textCharacter
= Feature
.NewInstance();
925 textCharacter
.setKindOf(Feature
.DESCRIPTION());
926 importRepresentation(elTextCharacter
, sddNamespace
, textCharacter
, idTC
, sddConfig
);
928 textCharacter
.setSupportsTextData(true);
930 features
.put(idTC
, textCharacter
);
932 } catch (Exception e
) {
934 logger
.warn("Import of TextCharacter " + j
+ " failed.");
938 if ((++j
% modCount
) == 0){ logger
.info("TextCharacters handled: " + j
);}
944 for (Iterator
<Feature
> f
= features
.values().iterator() ; f
.hasNext() ;){
945 featureSet
.add(f
.next());
950 // imports the descriptions of taxa (specimens TODO)
951 protected void importCodedDescriptions(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
952 // <CodedDescriptions>
953 logger
.info("start CodedDescriptions ...");
954 Element elCodedDescriptions
= elDataset
.getChild("CodedDescriptions",sddNamespace
);
956 // <CodedDescription id="D101">
958 if (elCodedDescriptions
!= null) {
959 List
<Element
> listCodedDescriptions
= elCodedDescriptions
.getChildren("CodedDescription", sddNamespace
);
961 //for each CodedDescription
963 for (Element elCodedDescription
: listCodedDescriptions
){
967 String idCD
= elCodedDescription
.getAttributeValue("id");
970 // <Label><i>Viola hederacea</i> Labill. as revised by R. Morris April 8, 2006</Label>
972 TaxonDescription taxonDescription
= TaxonDescription
.NewInstance();
973 importRepresentation(elCodedDescription
, sddNamespace
, taxonDescription
, idCD
, sddConfig
);
976 // <TaxonName ref="t1"/>
977 // <Citation ref="p1" location="p. 30"/>
979 Element elScope
= elCodedDescription
.getChild("Scope",sddNamespace
);
982 if (elScope
!= null) {
983 Element elTaxonName
= elScope
.getChild("TaxonName",sddNamespace
);
984 ref
= elTaxonName
.getAttributeValue("ref");
986 NonViralName taxonNameBase
= taxonNameBases
.get(ref
);
987 taxon
= Taxon
.NewInstance(taxonNameBase
, sec
);
990 String refCitation
= "";
991 String location
= "";
993 if (elScope
!= null) {
994 Element elCitation
= elScope
.getChild("Citation",sddNamespace
);
995 if (elCitation
!= null) {
996 refCitation
= elCitation
.getAttributeValue("ref");
997 location
= elCitation
.getAttributeValue("location");
1002 Element elSummaryData
= elCodedDescription
.getChild("SummaryData",sddNamespace
);
1004 if (elSummaryData
!= null) {
1006 // <Categorical ref="c4">
1007 List
<Element
> elCategoricals
= elSummaryData
.getChildren("Categorical", sddNamespace
);
1009 //for each Categorical
1010 for (Element elCategorical
: elCategoricals
){
1011 if ((++k
% modCount
) == 0){ logger
.info("Categorical handled: " + (k
-1));}
1012 ref
= elCategorical
.getAttributeValue("ref");
1013 Feature feature
= features
.get(ref
);
1014 CategoricalData categoricalData
= CategoricalData
.NewInstance();
1015 categoricalData
.setFeature(feature
);
1017 // <State ref="s3"/>
1018 List
<Element
> elStates
= elCategorical
.getChildren("State", sddNamespace
);
1021 for (Element elState
: elStates
){
1022 if ((++l
% modCount
) == 0){ logger
.info("States handled: " + (l
-1));}
1023 ref
= elState
.getAttributeValue("ref");
1024 StateData stateData
= stateDatas
.get(ref
);
1025 categoricalData
.addState(stateData
);
1027 taxonDescription
.addElement(categoricalData
);
1030 // <Quantitative ref="c2">
1031 List
<Element
> elQuantitatives
= elSummaryData
.getChildren("Quantitative", sddNamespace
);
1033 //for each Quantitative
1034 for (Element elQuantitative
: elQuantitatives
){
1035 if ((++k
% modCount
) == 0){ logger
.info("Quantitative handled: " + (k
-1));}
1036 ref
= elQuantitative
.getAttributeValue("ref");
1037 Feature feature
= features
.get(ref
);
1038 QuantitativeData quantitativeData
= QuantitativeData
.NewInstance();
1039 quantitativeData
.setFeature(feature
);
1041 MeasurementUnit unit
= units
.get(ref
);
1042 String prefix
= defaultUnitPrefixes
.get(ref
);
1044 String u
= unit
.getLabel();
1045 if (prefix
!= null) {
1049 quantitativeData
.setUnit(unit
);
1052 // <Measure type="Min" value="2.3"/>
1053 List
<Element
> elMeasures
= elQuantitative
.getChildren("Measure", sddNamespace
);
1056 for (Element elMeasure
: elMeasures
){
1057 if ((++l
% modCount
) == 0){ logger
.info("States handled: " + (l
-1));}
1058 String type
= elMeasure
.getAttributeValue("type");
1059 String value
= elMeasure
.getAttributeValue("value");
1060 float v
= Float
.parseFloat(value
);
1061 StatisticalMeasure t
= null;
1062 if (type
.equals("Min")) {
1063 t
= StatisticalMeasure
.MIN();
1064 } else if (type
.equals("Mean")) {
1065 t
= StatisticalMeasure
.AVERAGE();
1066 } else if (type
.equals("Max")) {
1067 t
= StatisticalMeasure
.MAX();
1068 } else if (type
.equals("SD")) {
1069 // Create a new StatisticalMeasure for standard deviation
1070 t
= StatisticalMeasure
.STANDARD_DEVIATION();
1071 } else if (type
.equals("N")) {
1072 t
= StatisticalMeasure
.SAMPLE_SIZE();
1074 t
= StatisticalMeasure
.NewInstance(type
,type
,type
);
1075 statisticalMeasures
.add(t
);
1078 StatisticalMeasurementValue statisticalValue
= StatisticalMeasurementValue
.NewInstance();
1079 statisticalValue
.setValue(v
);
1080 statisticalValue
.setType(t
);
1081 quantitativeData
.addStatisticalValue(statisticalValue
);
1082 featureData
.add(statisticalValue
);
1084 taxonDescription
.addElement(quantitativeData
);
1087 // <TextChar ref="c3">
1088 List
<Element
> elTextChars
= elSummaryData
.getChildren("TextChar", sddNamespace
);
1091 for (Element elTextChar
: elTextChars
){
1092 if ((++k
% modCount
) == 0){ logger
.info("TextChar handled: " + (k
-1));}
1093 ref
= elTextChar
.getAttributeValue("ref");
1094 Feature feature
= features
.get(ref
);
1095 TextData textData
= TextData
.NewInstance();
1096 textData
.setFeature(feature
);
1098 // <Content>Free form text</Content>
1099 String content
= (String
)ImportHelper
.getXmlInputValue(elTextChar
, "Content",sddNamespace
);
1100 textData
.putText(content
, datasetLanguage
);
1101 taxonDescription
.addElement(textData
);
1106 if (taxon
!= null) {
1107 taxon
.addDescription(taxonDescription
);
1110 if (!refCitation
.equals("")){
1111 citations
.put(idCD
,refCitation
);
1114 if (!location
.equals("")){
1115 locations
.put(idCD
, location
);
1118 taxonDescription
.setDescriptiveSystem(featureSet
);
1120 taxonDescriptions
.put(idCD
, taxonDescription
);
1122 } catch (Exception e
) {
1124 logger
.warn("Import of CodedDescription " + j
+ " failed.");
1128 if ((++j
% modCount
) == 0){ logger
.info("CodedDescriptions handled: " + j
);}
1135 // imports the persons associated with the dataset creation, modification, related publications
1136 protected void importAgents(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1138 logger
.info("start Agents ...");
1139 Element elAgents
= elDataset
.getChild("Agents",sddNamespace
);
1140 if (elAgents
!= null) {
1142 List
<Element
> listAgents
= elAgents
.getChildren("Agent", sddNamespace
);
1145 for (Element elAgent
: listAgents
){
1149 String idA
= elAgent
.getAttributeValue("id");
1152 // <Label>Kevin Thiele</Label>
1153 // <Detail role="Description">Ali Baba is also known as r.a.m.</Detail>
1154 // </Representation>
1155 Person person
= Person
.NewInstance();
1156 importRepresentation(elAgent
, sddNamespace
, person
, idA
, sddConfig
);
1157 person
.addSource(IdentifiableSource
.NewInstance(idA
, "Agent"));
1160 Element elLinks = elAgent.getChild("Links",sddNamespace);
1162 if (elLinks != null) {
1164 // <Link rel="Alternate" href="http://www.diversitycampus.net/people/hagedorn"/>
1165 List<Element> listLinks = elLinks.getChildren("Link", sddNamespace);
1168 for (Element elLink : listLinks){
1172 String rel = elLink.getAttributeValue("rel");
1173 String href = elLink.getAttributeValue("href");
1175 Media link = Media.NewInstance();
1176 MediaRepresentation mr = MediaRepresentation.NewInstance();
1177 mr.addRepresentationPart(MediaRepresentationPart.NewInstance(href, null));
1178 link.addRepresentation(mr);
1179 person.addMedia(link);
1181 } catch (Exception e) {
1183 logger.warn("Import of Link " + k + " failed.");
1187 if ((++k % modCount) == 0){ logger.info("Links handled: " + k);}
1192 if (authors
.containsKey(idA
)) {
1193 authors
.put(idA
,person
);
1196 if (editors
.containsKey(idA
)) {
1197 editors
.put(idA
, person
);
1200 } catch (Exception e
) {
1202 logger
.warn("Import of Agent " + j
+ " failed.");
1206 if ((++j
% modCount
) == 0){ logger
.info("Agents handled: " + j
);}
1212 // imports publications related with the data set
1213 protected void importPublications(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1215 logger
.info("start Publications ...");
1216 Element elPublications
= elDataset
.getChild("Publications",sddNamespace
);
1218 if (elPublications
!= null) {
1219 // <Publication id="p1">
1220 List
<Element
> listPublications
= elPublications
.getChildren("Publication", sddNamespace
);
1222 //for each Publication
1223 for (Element elPublication
: listPublications
){
1227 String idP
= elPublication
.getAttributeValue("id");
1230 // <Label>Sample Citation</Label>
1231 // </Representation>
1232 ReferenceBase publication
= refFactory
.newArticle();
1233 importRepresentation(elPublication
, sddNamespace
, publication
, idP
, sddConfig
);
1235 publications
.put(idP
,publication
);
1237 } catch (Exception e
) {
1239 logger
.warn("Import of Publication " + j
+ " failed.");
1243 if ((++j
% modCount
) == 0){ logger
.info("Publications handled: " + j
);}
1249 // imports media objects such as images
1250 protected void importMediaObjects(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1252 logger
.info("start MediaObjects ...");
1253 Element elMediaObjects
= elDataset
.getChild("MediaObjects",sddNamespace
);
1255 if (elMediaObjects
!= null) {
1256 // <MediaObject id="m1">
1257 List
<Element
> listMediaObjects
= elMediaObjects
.getChildren("MediaObject", sddNamespace
);
1259 //for each Publication
1260 for (Element elMO
: listMediaObjects
){
1265 String idMO
= elMO
.getAttributeValue("id");
1269 // <Label>Image description, e.g. to be used for alt-attribute in html.</Label>
1270 // </Representation>
1271 Media media
= Media
.NewInstance();
1272 importRepresentation(elMO
, sddNamespace
, media
, idMO
, sddConfig
);
1274 // <Type>Image</Type>
1275 // <Source href="http://test.edu/test.jpg"/>
1276 String type
= (String
)ImportHelper
.getXmlInputValue(elMO
,"Type",sddNamespace
);
1278 if ((type
!= null) && (type
.equals("Image"))) {
1279 Element elSource
= elMO
.getChild("Source",sddNamespace
);
1280 String href
= elSource
.getAttributeValue("href");
1282 ImageMetaData imageMetaData
= ImageMetaData
.newInstance();
1283 ImageFile image
= null;
1284 if (href
.substring(0,7).equals("http://")) {
1286 URL url
= new URL(href
);
1288 imageMetaData
.readMetaData(url
.toURI(), 0);
1289 image
= ImageFile
.NewInstance(url
.toString(), null, imageMetaData
);
1290 } catch (MalformedURLException e
) {
1291 logger
.error("Malformed URL", e
);
1294 String sns
= sddConfig
.getSourceNameString();
1295 File f
= new File(sns
);
1296 File parent
= f
.getParentFile();
1298 //XIMString fi = parent.toString() + File.separator + href; enlever le file:/ ou truc du genre
1299 File file
= new File(fi
);
1300 imageMetaData
.readMetaData(file
.toURI(), 0);
1301 image
= ImageFile
.NewInstance(file
.toString(), null, imageMetaData
);
1303 MediaRepresentation representation
= MediaRepresentation
.NewInstance(imageMetaData
.getMimeType(), null);
1304 representation
.addRepresentationPart(image
);
1306 media
.addRepresentation(representation
);
1308 ArrayList
<CdmBase
> lcb
= (ArrayList
<CdmBase
>) mediaObject_ListCdmBase
.get(idMO
);
1310 for (int k
= 0; k
< lcb
.size(); k
++) {
1311 if (lcb
.get(k
) instanceof DefinedTermBase
) {
1312 DefinedTermBase dtb
= (DefinedTermBase
) lcb
.get(k
);
1313 // if (lcb.get(0) instanceof DefinedTermBase) {
1314 // DefinedTermBase dtb = (DefinedTermBase) lcb.get(0);
1317 dtb
.addMedia(media
);
1318 //System.out.println(dtb.getLabel());
1320 // Media me = (Media) media.clone();
1321 // dtb.addMedia(me);
1324 } else if (lcb
.get(k
) instanceof ReferenceBase
) {
1325 ReferenceBase rb
= (ReferenceBase
) lcb
.get(k
);
1326 //} else if (lcb.get(0) instanceof ReferenceBase) {
1327 //ReferenceBase rb = (ReferenceBase) lcb.get(0);
1328 // rb.setTitleCache(label);
1332 //System.out.println(rb.getTitle());
1334 // Media me = (Media) media.clone();
1338 }/* else if (lcb.get(k) instanceof TaxonNameBase){
1339 TaxonNameBase tb = (TaxonNameBase) lcb.get(k);
1346 } catch (Exception e
) {
1348 logger
.warn("Could not attach MediaObject " + j
+ "(SDD: " + id
+ ") to several objects.");
1352 if ((++j
% modCount
) == 0){ logger
.info("MediaObjects handled: " + j
);
1359 // imports the <DescriptiveConcepts> block
1360 protected void importDescriptiveConcepts(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
1361 // <DescriptiveConcepts>
1362 logger
.info("start DescriptiveConcepts ...");
1363 Element elDescriptiveConcepts
= elDataset
.getChild("DescriptiveConcepts",sddNamespace
);
1364 // <DescriptiveConcept id="b">
1365 if (elDescriptiveConcepts
!= null) {
1366 List
<Element
> listDescriptiveConcepts
= elDescriptiveConcepts
.getChildren("DescriptiveConcept", sddNamespace
);
1368 //for each DescriptiveConcept
1371 for (Element elDescriptiveConcept
: listDescriptiveConcepts
){
1373 String id
= elDescriptiveConcept
.getAttributeValue("id");
1374 String uri
= elDescriptiveConcept
.getAttributeValue("uri");
1376 FeatureNode fn
= null;
1378 if (!id
.equals("")) {
1379 fn
= FeatureNode
.NewInstance();
1380 Feature feature
= Feature
.NewInstance();
1381 feature
.setKindOf(Feature
.DESCRIPTION());
1383 // <Label>Body</Label>
1384 importRepresentation(elDescriptiveConcept
, sddNamespace
, feature
, id
, sddConfig
);
1385 features
.put("g" + g
, feature
);
1387 Element elModifiers
= elDescriptiveConcept
.getChild("Modifiers", sddNamespace
);
1388 if (elModifiers
!=null){
1389 List
<Element
> listModifiers
= elModifiers
.getChildren("Modifier", sddNamespace
);
1390 for (Element elModifier
: listModifiers
) {
1391 TermVocabulary
<Modifier
> termVocabularyState
= new TermVocabulary
<Modifier
>("test","test","test","test");
1392 Modifier modif
= Modifier
.NewInstance();
1393 String idmod
= elModifier
.getAttributeValue("id");
1394 importRepresentation(elModifier
, sddNamespace
, modif
, idmod
, sddConfig
);
1395 termVocabularyState
.addTerm(modif
);
1396 //XIMfeature.addRecommendedModifierEnumeration(termVocabularyState);
1400 fn
.setFeature(feature
);
1402 // TODO if an OriginalSource can be attached to a FeatureNode or a Feature
1403 // OriginalSource source = null;
1404 // if (uri != null) {
1405 // if (!uri.equals("")) {
1406 // source = OriginalSource.NewInstance(id, "DescriptiveConcept", Generic.NewInstance(), uri);
1409 // source = OriginalSource.NewInstance(id, "DescriptiveConcept");
1411 // f.addSource(source);
1413 featureNodes
.put(id
,fn
);
1416 if ((++j
% modCount
) == 0){ logger
.info("DescriptiveConcepts handled: " + j
);}
1422 protected void importCharacterTrees(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1424 logger
.info("start CharacterTrees ...");
1425 Element elCharacterTrees
= elDataset
.getChild("CharacterTrees",sddNamespace
);
1429 if (elCharacterTrees
!= null) {
1430 List
<Element
> listCharacterTrees
= elCharacterTrees
.getChildren("CharacterTree", sddNamespace
);
1432 //for each CharacterTree
1433 for (Element elCharacterTree
: listCharacterTrees
){
1435 Element elRepresentation
= elCharacterTree
.getChild("Representation",sddNamespace
);
1436 String label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
,"Label",sddNamespace
);
1437 Element elDesignedFor
= elCharacterTree
.getChild("DesignedFor",sddNamespace
);
1438 /*XIMList<Element> listRoles = elDesignedFor.getChildren("Role",sddNamespace);
1439 boolean isgroups = false;
1441 for (Element elRole : listRoles){
1442 if (elRole.getText().equals("Filtering")) {
1447 // only treats the case of flat groups containing characters
1448 // should also be added: dependencies between characters,
1451 FeatureTree feattree
= FeatureTree
.NewInstance();
1452 importRepresentation(elCharacterTree
, sddNamespace
, feattree
, "", sddConfig
);
1453 FeatureNode root
= feattree
.getRoot();
1455 Element elNodes
= elCharacterTree
.getChild("Nodes", sddNamespace
);
1456 List
<Element
> listNodes
= elNodes
.getChildren("Node", sddNamespace
);
1457 for (Element elNode
: listNodes
){
1458 String idN
= elNode
.getAttributeValue("id");
1459 FeatureNode fn
= null;
1460 if (!idN
.equals("")) {
1461 Element elDescriptiveConcept
= elNode
.getChild("DescriptiveConcept", sddNamespace
);
1462 String refDC
= elDescriptiveConcept
.getAttributeValue("ref");
1463 fn
= featureNodes
.get(refDC
);
1464 Element elParent
= elNode
.getChild("Parent", sddNamespace
);
1465 if (elParent
!=null){
1466 String refP
= elParent
.getAttributeValue("ref");
1467 if (!refP
.equals("")) {
1468 FeatureNode parent
= nodes
.get(refP
);
1469 parent
.addChild(fn
);
1479 List
<Element
> listCharNodes
= elNodes
.getChildren("CharNode", sddNamespace
);
1480 for (Element elCharNode
: listCharNodes
){
1481 Element elParent
= elCharNode
.getChild("Parent", sddNamespace
);
1482 Element elCharacter
= elCharNode
.getChild("Character", sddNamespace
);
1483 FeatureNode fn
= FeatureNode
.NewInstance();
1484 if (elParent
!=null){
1485 String refP
= elParent
.getAttributeValue("ref");
1486 if (!refP
.equals("")) {
1487 FeatureNode parent
= nodes
.get(refP
);
1488 parent
.addChild(fn
);
1491 String refC
= elCharacter
.getAttributeValue("ref");
1492 if (!refC
.equals("")){
1493 Feature character
= features
.get(refC
);
1494 fn
.setFeature(character
);
1495 // if method setParent() in FeatureNode becomes visible
1496 // fn.setParent(parent);
1498 nodes
.put(refC
, fn
);
1500 featureTrees
.add(feattree
);
1503 catch (Exception e
) {
1505 logger
.warn("Import of Character tree " + j
+ " failed.");
1509 if ((++j
% modCount
) == 0){ logger
.info("CharacterTrees handled: " + j
);}
1520 protected void importTaxonHierarchies(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1522 logger
.info("start TaxonHierarchies ...");
1523 Element elTaxonHierarchies
= elDataset
.getChild("TaxonHierarchies",sddNamespace
);
1525 if (elTaxonHierarchies
!= null) {
1526 List
<Element
> listTaxonHierarchies
= elTaxonHierarchies
.getChildren("TaxonHierarchy", sddNamespace
);
1528 for (Element elTaxonHierarchy
: listTaxonHierarchies
){
1530 Element elRepresentation
= elTaxonHierarchy
.getChild("Representation",sddNamespace
);
1531 String label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
,"Label",sddNamespace
);
1533 TaxonomicTree taxonomicTree
= TaxonomicTree
.NewInstance(label
);
1534 importRepresentation(elTaxonHierarchy
, sddNamespace
, taxonomicTree
, "", sddConfig
);
1535 Set
<TaxonNode
> root
= taxonomicTree
.getRootNodes();
1536 Element elNodes
= elTaxonHierarchy
.getChild("Nodes", sddNamespace
);
1537 List
<Element
> listNodes
= elNodes
.getChildren("Node", sddNamespace
);
1538 for (Element elNode
: listNodes
){
1539 String idN
= elNode
.getAttributeValue("id");
1540 TaxonNameBase tnb
= null;
1541 if (!idN
.equals("")) {
1542 Element elTaxonName
= elNode
.getChild("TaxonName", sddNamespace
);
1543 String refTN
= elTaxonName
.getAttributeValue("ref");
1544 tnb
= taxonNameBases
.get(refTN
);
1545 Taxon taxonou
= (Taxon
) tnb
.getTaxa().iterator().next() ;
1546 Element elParent
= elNode
.getChild("Parent", sddNamespace
);
1547 if (elParent
!=null){
1548 String refP
= elParent
.getAttributeValue("ref");
1549 if (!refP
.equals("")) {
1550 TaxonNode parent
= taxonNodes
.get(refP
);
1551 //TaxonNode child = parent.addChildTaxon(Taxon.NewInstance(tnb, sec), sec, "", Synonym.NewInstance(tnb, sec));
1552 TaxonNode child
= parent
.addChildTaxon(taxonou
, sec
, "", Synonym
.NewInstance(tnb
, sec
));
1553 taxonNodes
.put(idN
,child
);
1557 //XIM addChildtaxon (taxon, referencebase ???
1558 //TaxonNode tn = taxonomicTree.addChildTaxon(Taxon.NewInstance(tnb, sec), sec, "", Synonym.NewInstance(tnb, sec));
1559 TaxonNode tn
= taxonomicTree
.addChildTaxon(taxonou
, sec
, "", Synonym
.NewInstance(tnb
, sec
));
1560 taxonNodes
.put(idN
,tn
);
1565 taxonomicTrees
.add(taxonomicTree
);
1568 catch (Exception e
) {
1570 logger
.warn("Import of Taxon Hierarchy " + j
+ " failed.");
1574 if ((++j
% modCount
) == 0){ logger
.info("TaxonHierarchies handled: " + j
);}
1589 // imports the descriptions of taxa (specimens TODO)
1590 protected void importCharacterTrees2(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1592 logger
.info("start CharacterTrees ...");
1593 Element elCharacterTrees
= elDataset
.getChild("CharacterTrees",sddNamespace
);
1597 if (elCharacterTrees
!= null) {
1598 List
<Element
> listCharacterTrees
= elCharacterTrees
.getChildren("CharacterTree", sddNamespace
);
1600 //for each CharacterTree
1601 for (Element elCharacterTree
: listCharacterTrees
){
1604 Element elRepresentation
= elCharacterTree
.getChild("Representation",sddNamespace
);
1605 String label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
,"Label",sddNamespace
);
1606 Element elDesignedFor
= elCharacterTree
.getChild("DesignedFor",sddNamespace
);
1607 List
<Element
> listRoles
= elDesignedFor
.getChildren("Role",sddNamespace
);
1608 boolean isgroups
= false;
1610 for (Element elRole
: listRoles
){
1611 if (elRole
.getText().equals("Filtering")) {
1616 // only treats the case of flat groups containing characters
1617 // should also be added: dependencies between characters,
1619 if ((label
.contains("group")) || (isgroups
) || (1==1)) {
1621 FeatureTree groups
= FeatureTree
.NewInstance();
1622 importRepresentation(elCharacterTree
, sddNamespace
, groups
, "", sddConfig
);
1623 FeatureNode root
= groups
.getRoot();
1625 Element elNodes
= elCharacterTree
.getChild("Nodes", sddNamespace
);
1626 List
<Element
> listNodes
= elNodes
.getChildren("Node", sddNamespace
);
1627 for (Element elNode
: listNodes
){
1628 String idN
= elNode
.getAttributeValue("id");
1629 FeatureNode fn
= null;
1630 if (!idN
.equals("")) {
1631 Element elDescriptiveConcept
= elNode
.getChild("DescriptiveConcept", sddNamespace
);
1632 String refDC
= elDescriptiveConcept
.getAttributeValue("ref");
1633 fn
= featureNodes
.get(refDC
);
1639 List
<Element
> listCharNodes
= elNodes
.getChildren("CharNode", sddNamespace
);
1640 for (Element elCharNode
: listCharNodes
){
1641 Element elParent
= elCharNode
.getChild("Parent", sddNamespace
);
1642 Element elCharacter
= elCharNode
.getChild("Character", sddNamespace
);
1643 FeatureNode fn
= FeatureNode
.NewInstance();
1644 if (elParent
!=null){
1645 String refP
= elParent
.getAttributeValue("ref");
1646 if (!refP
.equals("")) {
1647 FeatureNode parent
= nodes
.get(refP
);
1648 parent
.addChild(fn
);
1651 String refC
= elCharacter
.getAttributeValue("ref");
1652 if (!refC
.equals("")){
1653 Feature character
= features
.get(refC
);
1654 fn
.setFeature(character
);
1655 // if method setParent() in FeatureNode becomes visible
1656 // fn.setParent(parent);
1658 nodes
.put(refC
, fn
);
1660 featureTrees
.add(groups
);
1663 } catch (Exception e
) {
1665 logger
.warn("Import of Character tree " + j
+ " failed.");
1669 if ((++j
% modCount
) == 0){ logger
.info("CharacterTrees handled: " + j
);}