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
;
15 import java
.text
.SimpleDateFormat
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Date
;
18 import java
.util
.HashMap
;
19 import java
.util
.HashSet
;
20 import java
.util
.Iterator
;
21 import java
.util
.List
;
25 import org
.apache
.log4j
.Logger
;
26 import org
.jdom
.Element
;
27 import org
.jdom
.Namespace
;
28 import org
.joda
.time
.DateTime
;
29 import org
.springframework
.stereotype
.Component
;
30 import org
.springframework
.transaction
.TransactionStatus
;
32 import eu
.etaxonomy
.cdm
.api
.service
.IAgentService
;
33 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
34 import eu
.etaxonomy
.cdm
.api
.service
.IReferenceService
;
35 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
36 import eu
.etaxonomy
.cdm
.common
.MediaMetaData
.ImageMetaData
;
37 import eu
.etaxonomy
.cdm
.io
.common
.CdmImportBase
;
38 import eu
.etaxonomy
.cdm
.io
.common
.CdmIoBase
;
39 import eu
.etaxonomy
.cdm
.io
.common
.ICdmIO
;
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
.io
.common
.MapWrapper
;
44 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
45 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
46 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
47 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
48 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
49 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
50 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
51 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
52 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
53 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSource
;
54 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
55 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
56 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
57 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
58 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
59 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
60 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
61 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
62 import eu
.etaxonomy
.cdm
.model
.description
.MeasurementUnit
;
63 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
64 import eu
.etaxonomy
.cdm
.model
.description
.State
;
65 import eu
.etaxonomy
.cdm
.model
.description
.StateData
;
66 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasure
;
67 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasurementValue
;
68 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
69 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
70 import eu
.etaxonomy
.cdm
.model
.media
.ImageFile
;
71 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
72 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
73 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentationPart
;
74 import eu
.etaxonomy
.cdm
.model
.media
.Rights
;
75 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
76 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
77 import eu
.etaxonomy
.cdm
.model
.reference
.Article
;
78 import eu
.etaxonomy
.cdm
.model
.reference
.Database
;
79 import eu
.etaxonomy
.cdm
.model
.reference
.Generic
;
80 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
81 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
88 @Component("sddDescriptionIO")
89 public class SDDDescriptionIO
extends CdmImportBase
<SDDImportConfigurator
, SDDImportState
> implements ICdmImport
<SDDImportConfigurator
, SDDImportState
> {
90 private static final Logger logger
= Logger
.getLogger(SDDDescriptionIO
.class);
92 private static int modCount
= 1000;
94 private Map
<String
,Person
> authors
= new HashMap
<String
,Person
>();
95 private Map
<String
,String
> citations
= new HashMap
<String
,String
>();
96 private Map
<String
,String
> defaultUnitPrefixes
= new HashMap
<String
,String
>();
97 private Map
<String
,Person
> editors
= new HashMap
<String
,Person
>();
98 private Map
<String
,FeatureNode
> featureNodes
= new HashMap
<String
,FeatureNode
>();
99 private Map
<String
,Feature
> features
= new HashMap
<String
,Feature
>();
100 private Map
<String
,String
> locations
= new HashMap
<String
,String
>();
101 private Map
<String
,List
<CdmBase
>> mediaObject_ListCdmBase
= new HashMap
<String
,List
<CdmBase
>>();
102 private Map
<String
,String
> mediaObject_Role
= new HashMap
<String
,String
>();
103 private Map
<String
,FeatureNode
> nodes
= new HashMap
<String
,FeatureNode
>();
104 private Map
<String
,ReferenceBase
> publications
= new HashMap
<String
,ReferenceBase
>();
105 private Map
<String
,StateData
> stateDatas
= new HashMap
<String
,StateData
>();
106 private Map
<String
,TaxonDescription
> taxonDescriptions
= new HashMap
<String
,TaxonDescription
>();
107 private Map
<String
,NonViralName
> taxonNameBases
= new HashMap
<String
,NonViralName
>();
108 private Map
<String
,MeasurementUnit
> units
= new HashMap
<String
,MeasurementUnit
>();
110 private Set
<AnnotationType
> annotationTypes
= new HashSet
<AnnotationType
>();
111 private Set
<Feature
> featureSet
= new HashSet
<Feature
>();
113 private ReferenceBase sec
= Database
.NewInstance();
114 private ReferenceBase sourceReference
= null;
116 private Language datasetLanguage
= null;
118 private Namespace xmlNamespace
= Namespace
.getNamespace("xml","http://www.w3.org/XML/1998/namespace");
120 private String generatorName
= "";
121 private String generatorVersion
= "";
123 private Set
<StatisticalMeasure
> statisticalMeasures
= new HashSet
<StatisticalMeasure
>();
124 private Set
<VersionableEntity
> featureData
= new HashSet
<VersionableEntity
>();
125 private Set
<FeatureTree
> featureTrees
= new HashSet
<FeatureTree
>();
127 private Rights copyright
= null;
129 public SDDDescriptionIO(){
134 public boolean doCheck(SDDImportState state
){
135 boolean result
= true;
136 logger
.warn("No check implemented for SDD");
141 // public boolean doInvoke(IImportConfigurator config, Map<String, MapWrapper<? extends CdmBase>> stores){
143 public boolean doInvoke(SDDImportState state
){
145 TransactionStatus ts
= startTransaction();
146 SDDImportConfigurator sddConfig
= state
.getConfig();
148 logger
.info("start Datasets ...");
149 // <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">
150 Element root
= sddConfig
.getSourceRoot();
151 boolean success
= true;
152 Namespace sddNamespace
= sddConfig
.getSddNamespace();
154 logger
.info("start TechnicalMetadata ...");
155 // <TechnicalMetadata created="2006-04-20T10:00:00">
156 importTechnicalMetadata(root
, sddNamespace
, sddConfig
);
157 List
<Element
> elDatasets
= root
.getChildren("Dataset",sddNamespace
);
161 logger
.info("start Dataset ...");
162 for (Element elDataset
: elDatasets
){
163 importDataset(elDataset
, sddNamespace
, success
, sddConfig
);
164 if ((++i
% modCount
) == 0){ logger
.info("Datasets handled: " + i
);}
165 logger
.info(i
+ " Datasets handled");
167 commitTransaction(ts
);
172 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
174 protected boolean isIgnore(SDDImportState state
){
179 // associates the reference of a media object in SDD with a CdmBase Object
180 protected void associateImageWithCdmBase(String refMO
, CdmBase cb
){
181 if ((refMO
!= null) && (cb
!=null)) {
182 if (!refMO
.equals("")) {
183 if (!mediaObject_ListCdmBase
.containsKey(refMO
)) {
184 List
<CdmBase
> lcb
= new ArrayList
<CdmBase
>();
186 mediaObject_ListCdmBase
.put(refMO
,lcb
);
188 List
<CdmBase
> lcb
= mediaObject_ListCdmBase
.get(refMO
);
190 mediaObject_ListCdmBase
.put(refMO
,lcb
);
196 // imports information about the Dataset
197 protected void importDatasetRepresentation(Element parent
, Namespace sddNamespace
){
198 logger
.info("start Representation ...");
200 <Label>The Genus Viola</Label>
201 <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>
204 Element elRepresentation
= parent
.getChild("Representation",sddNamespace
);
205 String label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
206 String detail
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Detail",sddNamespace
);
208 sec
.setTitleCache(label
);
210 if (detail
!= null) {
211 Annotation annotation
= Annotation
.NewInstance(detail
, datasetLanguage
);
212 sec
.addAnnotation(annotation
);
215 List
<Element
> listMediaObjects
= elRepresentation
.getChildren("MediaObject",sddNamespace
);
217 for (Element elMediaObject
: listMediaObjects
) {
220 if (elMediaObject
!= null) {
221 ref
= elMediaObject
.getAttributeValue("ref");
222 role
= elMediaObject
.getAttributeValue("role");
225 if (!ref
.equals("")) {
226 this.associateImageWithCdmBase(ref
,sourceReference
);
227 this.associateImageWithCdmBase(ref
,sec
);
228 mediaObject_Role
.put(ref
,role
);
234 // imports the representation (label, detail, lang) of a particular SDD element
235 protected void importRepresentation(Element parent
, Namespace sddNamespace
, VersionableEntity ve
, String id
, IImportConfigurator config
){
236 Element elRepresentation
= parent
.getChild("Representation",sddNamespace
);
237 // <Label xml:lang="la">Viola hederacea Labill.</Label>
238 List
<Element
> listLabels
= elRepresentation
.getChildren("Label",sddNamespace
);
239 List
<Element
> listDetails
= elRepresentation
.getChildren("Detail",sddNamespace
);
240 Map
<Language
,List
<String
>> langLabDet
= new HashMap
<Language
,List
<String
>>();
242 for (Element elLabel
: listLabels
){
243 String lang
= elLabel
.getAttributeValue("lang",xmlNamespace
);
244 Language language
= null;
246 if (!lang
.equals("")) {
247 language
= getTermService().getLanguageByIso(lang
.substring(0, 2));
249 language
= datasetLanguage
;
252 language
= datasetLanguage
;
254 String label
= elLabel
.getText();
255 List
<String
> labDet
= new ArrayList
<String
>(3);
257 langLabDet
.put(language
, labDet
);
260 for (Element elDetail
: listDetails
){
261 String lang
= elDetail
.getAttributeValue("lang",xmlNamespace
);
262 String role
= elDetail
.getAttributeValue("role");
263 Language language
= null;
265 if (!lang
.equals("")) {
266 language
= getTermService().getLanguageByIso(lang
.substring(0, 2));
268 language
= datasetLanguage
;
271 language
= datasetLanguage
;
273 String detail
= elDetail
.getText();
274 List
<String
> labDet
= langLabDet
.get(language
);
277 langLabDet
.put(language
, labDet
);
280 if (ve
instanceof IdentifiableEntity
) {
281 IdentifiableEntity ie
= (IdentifiableEntity
) ve
;
282 List
<String
> labDet
= null;
284 if (ve
instanceof TaxonNameBase
) {
285 if (langLabDet
.keySet().contains(getTermService().getLanguageByIso("la"))) {
286 labDet
= langLabDet
.get(getTermService().getLanguageByIso("la"));
287 } else if (langLabDet
.keySet().contains(datasetLanguage
)) {
288 labDet
= langLabDet
.get(datasetLanguage
);
289 logger
.info("TaxonName " + (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
) + " is not specified as a latin name.");
291 labDet
= langLabDet
.get(langLabDet
.keySet().iterator().next());
292 logger
.info("TaxonName " + (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
) + " is not specified as a latin name.");
295 labDet
= langLabDet
.get(langLabDet
.keySet().iterator().next());
298 ie
.setTitleCache(labDet
.get(0));
300 if (labDet
.size()>1) {
301 Annotation annotation
= null;
302 if (labDet
.get(1) != null) {
303 if (labDet
.get(2) != null) {
304 annotation
= Annotation
.NewInstance(labDet
.get(2) + " - " + labDet
.get(1), datasetLanguage
);
306 annotation
= Annotation
.NewInstance(labDet
.get(1), datasetLanguage
);
309 ie
.addAnnotation(annotation
);
314 } else if (ve
instanceof TermBase
) {
315 TermBase tb
= (TermBase
) ve
;
317 for (Iterator
<Language
> l
= langLabDet
.keySet().iterator() ; l
.hasNext() ;){
318 Language lang
= l
.next();
319 List
<String
> labDet
= langLabDet
.get(lang
);
320 if (labDet
.size()>0){
321 if (labDet
.size()>1) {
322 tb
.addRepresentation(Representation
.NewInstance(labDet
.get(1), labDet
.get(0), labDet
.get(0), lang
));
324 tb
.addRepresentation(Representation
.NewInstance(labDet
.get(0), labDet
.get(0), labDet
.get(0), lang
));
330 } else if (ve
instanceof Media
) {
331 Media m
= (Media
) ve
;
333 for (Iterator
<Language
> l
= langLabDet
.keySet().iterator() ; l
.hasNext() ;){
334 Language lang
= l
.next();
335 List
<String
> labDet
= langLabDet
.get(lang
);
336 if (labDet
.get(0) != null){
337 m
.addTitle(LanguageString
.NewInstance(labDet
.get(0), lang
));
339 if (labDet
.size()>1) {
340 m
.addDescription(labDet
.get(1), lang
);
347 List
<Element
> listMediaObjects
= elRepresentation
.getChildren("MediaObject",sddNamespace
);
349 for (Element elMediaObject
: listMediaObjects
) {
352 if (elMediaObject
!= null) {
353 ref
= elMediaObject
.getAttributeValue("ref");
354 role
= elMediaObject
.getAttributeValue("role");
357 if (!ref
.equals("")) {
359 if (ve
instanceof TaxonDescription
) {
360 TaxonDescription td
= (TaxonDescription
) ve
;
361 //TODO: ensure that all images are imported
362 if (td
.getDescriptionSources().toArray().length
> 0) {
363 this.associateImageWithCdmBase(ref
,(ReferenceBase
) td
.getDescriptionSources().toArray()[0]);
365 ReferenceBase descriptionSource
= Generic
.NewInstance();
366 td
.addDescriptionSource(descriptionSource
);
367 this.associateImageWithCdmBase(ref
,descriptionSource
);
370 this.associateImageWithCdmBase(ref
,ve
);
380 // imports the representation (label, detail, lang) of a particular SDD element
381 protected void importTechnicalMetadata(Element root
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
382 Element elTechnicalMetadata
= root
.getChild("TechnicalMetadata", sddNamespace
);
383 String nameCreated
= elTechnicalMetadata
.getAttributeValue("created");
384 sourceReference
= sddConfig
.getSourceReference();
386 if (nameCreated
!= null) {
387 if (!nameCreated
.equals("")) {
388 int year
= Integer
.parseInt(nameCreated
.substring(0,4));
389 int monthOfYear
= Integer
.parseInt(nameCreated
.substring(5,7));
390 int dayOfMonth
= Integer
.parseInt(nameCreated
.substring(8,10));
391 int hourOfDay
= Integer
.parseInt(nameCreated
.substring(11,13));
392 int minuteOfHour
= Integer
.parseInt(nameCreated
.substring(14,16));
393 int secondOfMinute
= Integer
.parseInt(nameCreated
.substring(17,19));
394 DateTime created
= new DateTime(year
,monthOfYear
,dayOfMonth
,hourOfDay
,minuteOfHour
,secondOfMinute
,0);
395 sourceReference
.setCreated(created
);
396 sec
.setCreated(created
);
400 // <Generator name="n/a, handcrafted instance document" version="n/a"/>
401 Element elGenerator
= elTechnicalMetadata
.getChild("Generator", sddNamespace
);
402 generatorName
= elGenerator
.getAttributeValue("name");
403 generatorVersion
= elGenerator
.getAttributeValue("version");
405 sec
.addAnnotation(Annotation
.NewDefaultLanguageInstance(generatorName
+ " - " + generatorVersion
));
406 sourceReference
.addAnnotation(Annotation
.NewDefaultLanguageInstance(generatorName
+ " - " + generatorVersion
));
410 // imports the complete dataset information
411 protected void importDataset(Element elDataset
, Namespace sddNamespace
, boolean success
, SDDImportConfigurator sddConfig
){ // <Dataset xml:lang="en-us">
413 importDatasetLanguage(elDataset
,sddConfig
);
414 importDatasetRepresentation(elDataset
, sddNamespace
);
415 importRevisionData(elDataset
, sddNamespace
);
416 importIPRStatements(elDataset
, sddNamespace
, sddConfig
);
417 importTaxonNames(elDataset
, sddNamespace
, sddConfig
);
418 importDescriptiveConcepts(elDataset
, sddNamespace
, sddConfig
);
419 importCharacters(elDataset
, sddNamespace
, sddConfig
, success
);
420 importCharacterTrees(elDataset
, sddNamespace
, sddConfig
, success
);
421 importCodedDescriptions(elDataset
, sddNamespace
, sddConfig
, success
);
422 importAgents(elDataset
, sddNamespace
, sddConfig
, success
);
423 importPublications(elDataset
, sddNamespace
, sddConfig
, success
);
424 importMediaObjects(elDataset
, sddNamespace
, sddConfig
, success
);
426 if (authors
!= null) {
427 Team team
= Team
.NewInstance();
428 for (Iterator
<Person
> author
= authors
.values().iterator() ; author
.hasNext() ;){
429 team
.addTeamMember(author
.next());
431 sec
.setAuthorTeam(team
);
432 sourceReference
.setAuthorTeam(team
);
435 if (editors
!= null) {
436 Person ed
= Person
.NewInstance();
437 for (Iterator
<Person
> editor
= editors
.values().iterator() ; editor
.hasNext() ;){
440 // TODO updatedBy refactored to use a user account, so setting a person is no longer applicable
441 // sec.setUpdatedBy(ed);
442 // sourceReference.setUpdatedBy(ed);
445 if (copyright
!= null) {
446 sourceReference
.addRights(copyright
);
447 sec
.addRights(copyright
);
450 for (Iterator
<String
> refCD
= taxonDescriptions
.keySet().iterator() ; refCD
.hasNext() ;){
451 String ref
= refCD
.next();
452 TaxonDescription td
= taxonDescriptions
.get(ref
);
453 td
.addDescriptionSource(sec
);
454 if (citations
.containsKey(ref
)) {
455 Article publication
= (Article
) publications
.get(citations
.get(ref
));
456 if (locations
.containsKey(ref
)) {
457 Annotation location
= Annotation
.NewInstance(locations
.get(ref
), datasetLanguage
);
458 AnnotationType annotationType
= AnnotationType
.NewInstance("", "location", "");
459 annotationTypes
.add(annotationType
);
460 location
.setAnnotationType(annotationType
);
461 publication
.addAnnotation(location
);
463 td
.addDescriptionSource(publication
);
466 logger
.info("end makeTaxonDescriptions ...");
468 sddConfig
.setSourceReference(sourceReference
);
470 //saving of all imported data into the CDM db
471 ITermService termService
= getTermService();
472 for (Iterator
<StateData
> k
= stateDatas
.values().iterator() ; k
.hasNext() ;){
473 StateData sd
= k
.next();
474 termService
.saveTerm(sd
.getState());
476 for (Iterator
<Feature
> k
= features
.values().iterator() ; k
.hasNext() ;){
477 Feature feature
= k
.next();
478 termService
.saveTerm(feature
);
481 for (Iterator
<MeasurementUnit
> k
= units
.values().iterator() ; k
.hasNext() ;){
482 MeasurementUnit unit
= k
.next();
484 termService
.saveTerm(unit
);
488 for (Iterator
<StatisticalMeasure
> k
= statisticalMeasures
.iterator() ; k
.hasNext() ;) {
489 StatisticalMeasure sm
= k
.next();
490 termService
.saveTerm(sm
);
493 for (Iterator
<AnnotationType
> at
= annotationTypes
.iterator() ; at
.hasNext() ;) {
494 AnnotationType annotationType
= at
.next();
495 termService
.saveTerm(annotationType
);
498 IReferenceService referenceService
= getReferenceService();
499 // referenceService.saveReference(sourceReference);
500 for (Iterator
<ReferenceBase
> k
= publications
.values().iterator() ; k
.hasNext() ;){
501 Article publication
= (Article
) k
.next();
502 referenceService
.saveReference(publication
);
505 IAgentService agentService
= getAgentService();
506 for (Iterator
<Person
> p
= authors
.values().iterator() ; p
.hasNext() ;) {
507 Person person
= p
.next();
508 agentService
.saveAgent(person
);
511 for (Iterator
<Person
> p
= editors
.values().iterator() ; p
.hasNext() ;) {
512 Person person
= p
.next();
513 agentService
.saveAgent(person
);
516 // Returns a CdmApplicationController created by the values of this configuration.
517 IDescriptionService descriptionService
= getDescriptionService();
519 for (Iterator
<TaxonDescription
> k
= taxonDescriptions
.values().iterator() ; k
.hasNext() ;){
520 TaxonDescription taxonDescription
= k
.next();
521 // Persists a Description
522 descriptionService
.saveDescription(taxonDescription
);
525 // descriptionService.saveFeatureNodeAll(featureNodes.values());
527 for (Iterator
<FeatureTree
> k
= featureTrees
.iterator() ; k
.hasNext() ;) {
528 FeatureTree tree
= k
.next();
529 descriptionService
.saveFeatureTree(tree
);
534 // imports the default language of the dataset
535 protected void importDatasetLanguage(Element elDataset
, SDDImportConfigurator sddConfig
){
536 String nameLang
= elDataset
.getAttributeValue("lang",xmlNamespace
);
538 if (!nameLang
.equals("")) {
539 String iso
= nameLang
.substring(0, 2);
540 datasetLanguage
= getTermService().getLanguageByIso(iso
);
542 datasetLanguage
= Language
.ENGLISH();
544 if (datasetLanguage
== null) {
545 datasetLanguage
= Language
.ENGLISH();
549 // imports the revision data associated with the Dataset (authors, modifications)
550 protected void importRevisionData(Element elDataset
, Namespace sddNamespace
){
552 logger
.info("start RevisionData ...");
553 Element elRevisionData
= elDataset
.getChild("RevisionData",sddNamespace
);
556 Element elCreators
= elRevisionData
.getChild("Creators",sddNamespace
);
558 // <Agent role="aut" ref="a1"/>
559 List
<Element
> listAgents
= elCreators
.getChildren("Agent", sddNamespace
);
563 for (Element elAgent
: listAgents
){
565 String role
= elAgent
.getAttributeValue("role");
566 String ref
= elAgent
.getAttributeValue("ref");
567 if (role
.equals("aut")) {
568 if(!ref
.equals("")) {
569 authors
.put(ref
, null);
572 if (role
.equals("edt")) {
573 if(!ref
.equals("")) {
574 editors
.put(ref
, null);
578 if ((++j
% modCount
) == 0){ logger
.info("Agents handled: " + j
);}
582 // <DateModified>2006-04-08T00:00:00</DateModified>
583 String stringDateModified
= (String
)ImportHelper
.getXmlInputValue(elRevisionData
, "DateModified",sddNamespace
);
585 if (stringDateModified
!= null) {
586 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
589 d
= sdf
.parse(stringDateModified
);
590 } catch(Exception e
) {
591 System
.err
.println("Exception :");
595 DateTime updated
= null;
597 updated
= new DateTime(d
);
598 sourceReference
.setUpdated(updated
);
599 sec
.setUpdated(updated
);
604 // imports ipr statements associated with a dataset
605 protected void importIPRStatements(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
607 logger
.info("start IPRStatements ...");
608 Element elIPRStatements
= elDataset
.getChild("IPRStatements",sddNamespace
);
609 // <IPRStatement role="Copyright">
610 if (elIPRStatements
!= null) {
611 List
<Element
> listIPRStatements
= elIPRStatements
.getChildren("IPRStatement", sddNamespace
);
613 //for each IPRStatement
615 for (Element elIPRStatement
: listIPRStatements
){
617 String role
= elIPRStatement
.getAttributeValue("role");
618 // <Label xml:lang="en-au">(c) 2003-2006 Centre for Occasional Botany.</Label>
619 Element elLabel
= elIPRStatement
.getChild("Label",sddNamespace
);
621 if (elLabel
!= null) {
622 lang
= elLabel
.getAttributeValue("lang",xmlNamespace
);
624 String label
= (String
)ImportHelper
.getXmlInputValue(elIPRStatement
, "Label",sddNamespace
);
626 if (role
.equals("Copyright")) {
627 Language iprLanguage
= null;
629 if (!lang
.equals("")) {
630 iprLanguage
= getTermService().getLanguageByIso(lang
.substring(0, 2));
631 //iprLanguage = datasetLanguage;
633 iprLanguage
= datasetLanguage
;
636 if (iprLanguage
== null) {
637 iprLanguage
= datasetLanguage
;
639 copyright
= Rights
.NewInstance(label
, iprLanguage
);
642 if (copyright
!= null) {
643 sourceReference
.addRights(copyright
);
644 sec
.addRights(copyright
);
647 if ((++j
% modCount
) == 0){ logger
.info("IPRStatements handled: " + j
);}
653 // imports the taxon names
654 protected void importTaxonNames(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
656 logger
.info("start TaxonNames ...");
657 Element elTaxonNames
= elDataset
.getChild("TaxonNames",sddNamespace
);
658 // <TaxonName id="t1" uri="urn:lsid:authority:namespace:my-own-id">
659 if (elTaxonNames
!= null) {
660 List
<Element
> listTaxonNames
= elTaxonNames
.getChildren("TaxonName", sddNamespace
);
663 for (Element elTaxonName
: listTaxonNames
){
665 String id
= elTaxonName
.getAttributeValue("id");
666 String uri
= elTaxonName
.getAttributeValue("uri");
668 NonViralName tnb
= null;
669 if (!id
.equals("")) {
670 tnb
= NonViralName
.NewInstance(null);
671 OriginalSource source
= null;
673 if (!uri
.equals("")) {
674 source
= OriginalSource
.NewInstance(id
, "TaxonName", Generic
.NewInstance(), uri
);
677 source
= OriginalSource
.NewInstance(id
, "TaxonName");
679 tnb
.addSource(source
);
680 taxonNameBases
.put(id
,tnb
);
684 // <Label xml:lang="la">Viola hederacea Labill.</Label>
685 importRepresentation(elTaxonName
, sddNamespace
, tnb
, id
, sddConfig
);
687 if ((++j
% modCount
) == 0){ logger
.info("TaxonNames handled: " + j
);}
693 // imports the representation (label, detail, lang) of a particular SDD element
694 protected void importCharacters(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
696 logger
.info("start Characters ...");
697 Element elCharacters
= elDataset
.getChild("Characters", sddNamespace
);
699 // <CategoricalCharacter id="c1">
700 if (elCharacters
!= null) {
701 List
<Element
> elCategoricalCharacters
= elCharacters
.getChildren("CategoricalCharacter", sddNamespace
);
703 //for each CategoricalCharacter
704 for (Element elCategoricalCharacter
: elCategoricalCharacters
){
708 String idCC
= elCategoricalCharacter
.getAttributeValue("id");
711 // <Label> Leaf complexity</Label>
714 Feature categoricalCharacter
= Feature
.NewInstance();
715 categoricalCharacter
.setKindOf(Feature
.DESCRIPTION());
716 importRepresentation(elCategoricalCharacter
, sddNamespace
, categoricalCharacter
, idCC
, sddConfig
);
718 categoricalCharacter
.setSupportsCategoricalData(true);
721 Element elStates
= elCategoricalCharacter
.getChild("States",sddNamespace
);
723 // <StateDefinition id="s1">
724 List
<Element
> elStateDefinitions
= elStates
.getChildren("StateDefinition",sddNamespace
);
725 TermVocabulary
<State
> termVocabularyState
= new TermVocabulary
<State
>();
728 //for each StateDefinition
729 for (Element elStateDefinition
: elStateDefinitions
){
731 if ((++k
% modCount
) == 0){ logger
.info("StateDefinitions handled: " + (k
-1));}
733 String idSD
= elStateDefinition
.getAttributeValue("id");
735 // <Label>Simple</Label>
736 // <MediaObject ref="ib" role="Primary"/>
738 State state
= State
.NewInstance();
739 importRepresentation(elStateDefinition
, sddNamespace
, state
, idSD
, sddConfig
);
741 StateData stateData
= StateData
.NewInstance();
742 stateData
.setState(state
);
743 termVocabularyState
.addTerm(state
);
744 stateDatas
.put(idSD
,stateData
);
747 categoricalCharacter
.addSupportedCategoricalEnumeration(termVocabularyState
);
748 features
.put(idCC
, categoricalCharacter
);
750 } catch (Exception e
) {
752 logger
.warn("Import of CategoricalCharacter " + j
+ " failed.");
756 if ((++j
% modCount
) == 0){ logger
.info("CategoricalCharacters handled: " + j
);}
760 // <QuantitativeCharacter id="c2">
761 List
<Element
> elQuantitativeCharacters
= elCharacters
.getChildren("QuantitativeCharacter", sddNamespace
);
763 //for each QuantitativeCharacter
764 for (Element elQuantitativeCharacter
: elQuantitativeCharacters
){
768 String idQC
= elQuantitativeCharacter
.getAttributeValue("id");
771 // <Label>Leaf length</Label>
773 Feature quantitativeCharacter
= Feature
.NewInstance();
774 quantitativeCharacter
.setKindOf(Feature
.DESCRIPTION());
775 importRepresentation(elQuantitativeCharacter
, sddNamespace
, quantitativeCharacter
, idQC
, sddConfig
);
777 quantitativeCharacter
.setSupportsQuantitativeData(true);
780 // <Label role="Abbrev">m</Label>
781 // </MeasurementUnit>
782 Element elMeasurementUnit
= elQuantitativeCharacter
.getChild("MeasurementUnit",sddNamespace
);
785 if (elMeasurementUnit
!= null) {
786 Element elLabel
= elMeasurementUnit
.getChild("Label",sddNamespace
);
787 role
= elLabel
.getAttributeValue("role");
788 label
= (String
)ImportHelper
.getXmlInputValue(elMeasurementUnit
, "Label",sddNamespace
);
791 MeasurementUnit unit
= null;
792 if (!label
.equals("")){
794 if (role
.equals("Abbrev")){
795 unit
= MeasurementUnit
.NewInstance(label
,label
,label
);
798 unit
= MeasurementUnit
.NewInstance(label
,label
,label
);
803 units
.put(idQC
, unit
);
807 // <MeasurementUnitPrefix>milli</MeasurementUnitPrefix>
809 Element elDefault
= elQuantitativeCharacter
.getChild("Default",sddNamespace
);
810 if (elDefault
!= null) {
811 String measurementUnitPrefix
= (String
)ImportHelper
.getXmlInputValue(elDefault
, "MeasurementUnitPrefix",sddNamespace
);
812 if (!measurementUnitPrefix
.equals("")){
813 defaultUnitPrefixes
.put(idQC
, measurementUnitPrefix
);
817 features
.put(idQC
, quantitativeCharacter
);
819 } catch (Exception e
) {
821 logger
.warn("Import of QuantitativeCharacter " + j
+ " failed.");
825 if ((++j
% modCount
) == 0){ logger
.info("QuantitativeCharacters handled: " + j
);}
829 // <TextCharacter id="c3">
830 List
<Element
> elTextCharacters
= elCharacters
.getChildren("TextCharacter", sddNamespace
);
832 //for each TextCharacter
833 for (Element elTextCharacter
: elTextCharacters
){
837 String idTC
= elTextCharacter
.getAttributeValue("id");
840 // <Label xml:lang="en">Leaf features not covered by other characters</Label>
842 Feature textCharacter
= Feature
.NewInstance();
843 textCharacter
.setKindOf(Feature
.DESCRIPTION());
844 importRepresentation(elTextCharacter
, sddNamespace
, textCharacter
, idTC
, sddConfig
);
846 textCharacter
.setSupportsTextData(true);
848 features
.put(idTC
, textCharacter
);
850 } catch (Exception e
) {
852 logger
.warn("Import of TextCharacter " + j
+ " failed.");
856 if ((++j
% modCount
) == 0){ logger
.info("TextCharacters handled: " + j
);}
862 for (Iterator
<Feature
> f
= features
.values().iterator() ; f
.hasNext() ;){
863 featureSet
.add(f
.next());
868 // imports the descriptions of taxa (specimens TODO)
869 protected void importCodedDescriptions(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
870 // <CodedDescriptions>
871 logger
.info("start CodedDescriptions ...");
872 Element elCodedDescriptions
= elDataset
.getChild("CodedDescriptions",sddNamespace
);
874 // <CodedDescription id="D101">
876 if (elCodedDescriptions
!= null) {
877 List
<Element
> listCodedDescriptions
= elCodedDescriptions
.getChildren("CodedDescription", sddNamespace
);
879 //for each CodedDescription
881 for (Element elCodedDescription
: listCodedDescriptions
){
885 String idCD
= elCodedDescription
.getAttributeValue("id");
888 // <Label><i>Viola hederacea</i> Labill. as revised by R. Morris April 8, 2006</Label>
890 TaxonDescription taxonDescription
= TaxonDescription
.NewInstance();
891 importRepresentation(elCodedDescription
, sddNamespace
, taxonDescription
, idCD
, sddConfig
);
894 // <TaxonName ref="t1"/>
895 // <Citation ref="p1" location="p. 30"/>
897 Element elScope
= elCodedDescription
.getChild("Scope",sddNamespace
);
900 if (elScope
!= null) {
901 Element elTaxonName
= elScope
.getChild("TaxonName",sddNamespace
);
902 ref
= elTaxonName
.getAttributeValue("ref");
904 NonViralName taxonNameBase
= taxonNameBases
.get(ref
);
905 taxon
= Taxon
.NewInstance(taxonNameBase
, sec
);
908 String refCitation
= "";
909 String location
= "";
911 if (elScope
!= null) {
912 Element elCitation
= elScope
.getChild("Citation",sddNamespace
);
913 if (elCitation
!= null) {
914 refCitation
= elCitation
.getAttributeValue("ref");
915 location
= elCitation
.getAttributeValue("location");
920 Element elSummaryData
= elCodedDescription
.getChild("SummaryData",sddNamespace
);
922 if (elSummaryData
!= null) {
924 // <Categorical ref="c4">
925 List
<Element
> elCategoricals
= elSummaryData
.getChildren("Categorical", sddNamespace
);
927 //for each Categorical
928 for (Element elCategorical
: elCategoricals
){
929 if ((++k
% modCount
) == 0){ logger
.info("Categorical handled: " + (k
-1));}
930 ref
= elCategorical
.getAttributeValue("ref");
931 Feature feature
= features
.get(ref
);
932 CategoricalData categoricalData
= CategoricalData
.NewInstance();
933 categoricalData
.setFeature(feature
);
936 List
<Element
> elStates
= elCategorical
.getChildren("State", sddNamespace
);
939 for (Element elState
: elStates
){
940 if ((++l
% modCount
) == 0){ logger
.info("States handled: " + (l
-1));}
941 ref
= elState
.getAttributeValue("ref");
942 StateData stateData
= stateDatas
.get(ref
);
943 categoricalData
.addState(stateData
);
945 taxonDescription
.addElement(categoricalData
);
948 // <Quantitative ref="c2">
949 List
<Element
> elQuantitatives
= elSummaryData
.getChildren("Quantitative", sddNamespace
);
951 //for each Quantitative
952 for (Element elQuantitative
: elQuantitatives
){
953 if ((++k
% modCount
) == 0){ logger
.info("Quantitative handled: " + (k
-1));}
954 ref
= elQuantitative
.getAttributeValue("ref");
955 Feature feature
= features
.get(ref
);
956 QuantitativeData quantitativeData
= QuantitativeData
.NewInstance();
957 quantitativeData
.setFeature(feature
);
959 MeasurementUnit unit
= units
.get(ref
);
960 String prefix
= defaultUnitPrefixes
.get(ref
);
962 String u
= unit
.getLabel();
963 if (prefix
!= null) {
967 quantitativeData
.setUnit(unit
);
970 // <Measure type="Min" value="2.3"/>
971 List
<Element
> elMeasures
= elQuantitative
.getChildren("Measure", sddNamespace
);
974 for (Element elMeasure
: elMeasures
){
975 if ((++l
% modCount
) == 0){ logger
.info("States handled: " + (l
-1));}
976 String type
= elMeasure
.getAttributeValue("type");
977 String value
= elMeasure
.getAttributeValue("value");
978 float v
= Float
.parseFloat(value
);
979 StatisticalMeasure t
= null;
980 if (type
.equals("Min")) {
981 t
= StatisticalMeasure
.MIN();
982 } else if (type
.equals("Mean")) {
983 t
= StatisticalMeasure
.AVERAGE();
984 } else if (type
.equals("Max")) {
985 t
= StatisticalMeasure
.MAX();
986 } else if (type
.equals("SD")) {
987 // Create a new StatisticalMeasure for standard deviation
988 t
= StatisticalMeasure
.STANDARD_DEVIATION();
989 } else if (type
.equals("N")) {
990 t
= StatisticalMeasure
.SAMPLE_SIZE();
992 t
= StatisticalMeasure
.NewInstance(type
,type
,type
);
993 statisticalMeasures
.add(t
);
996 StatisticalMeasurementValue statisticalValue
= StatisticalMeasurementValue
.NewInstance();
997 statisticalValue
.setValue(v
);
998 statisticalValue
.setType(t
);
999 quantitativeData
.addStatisticalValue(statisticalValue
);
1000 featureData
.add(statisticalValue
);
1002 taxonDescription
.addElement(quantitativeData
);
1005 // <TextChar ref="c3">
1006 List
<Element
> elTextChars
= elSummaryData
.getChildren("TextChar", sddNamespace
);
1009 for (Element elTextChar
: elTextChars
){
1010 if ((++k
% modCount
) == 0){ logger
.info("TextChar handled: " + (k
-1));}
1011 ref
= elTextChar
.getAttributeValue("ref");
1012 Feature feature
= features
.get(ref
);
1013 TextData textData
= TextData
.NewInstance();
1014 textData
.setFeature(feature
);
1016 // <Content>Free form text</Content>
1017 String content
= (String
)ImportHelper
.getXmlInputValue(elTextChar
, "Content",sddNamespace
);
1018 textData
.putText(content
, datasetLanguage
);
1019 taxonDescription
.addElement(textData
);
1024 if (taxon
!= null) {
1025 taxon
.addDescription(taxonDescription
);
1028 if (!refCitation
.equals("")){
1029 citations
.put(idCD
,refCitation
);
1032 if (!location
.equals("")){
1033 locations
.put(idCD
, location
);
1036 taxonDescription
.setDescriptiveSystem(featureSet
);
1038 taxonDescriptions
.put(idCD
, taxonDescription
);
1040 } catch (Exception e
) {
1042 logger
.warn("Import of CodedDescription " + j
+ " failed.");
1046 if ((++j
% modCount
) == 0){ logger
.info("CodedDescriptions handled: " + j
);}
1053 // imports the persons associated with the dataset creation, modification, related publications
1054 protected void importAgents(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1056 logger
.info("start Agents ...");
1057 Element elAgents
= elDataset
.getChild("Agents",sddNamespace
);
1060 List
<Element
> listAgents
= elAgents
.getChildren("Agent", sddNamespace
);
1063 for (Element elAgent
: listAgents
){
1067 String idA
= elAgent
.getAttributeValue("id");
1070 // <Label>Kevin Thiele</Label>
1071 // <Detail role="Description">Ali Baba is also known as r.a.m.</Detail>
1072 // </Representation>
1073 Person person
= Person
.NewInstance();
1074 importRepresentation(elAgent
, sddNamespace
, person
, idA
, sddConfig
);
1075 person
.addSource(OriginalSource
.NewInstance(idA
, "Agent"));
1078 Element elLinks
= elAgent
.getChild("Links",sddNamespace
);
1080 if (elLinks
!= null) {
1082 // <Link rel="Alternate" href="http://www.diversitycampus.net/people/hagedorn"/>
1083 List
<Element
> listLinks
= elLinks
.getChildren("Link", sddNamespace
);
1086 for (Element elLink
: listLinks
){
1090 String rel
= elLink
.getAttributeValue("rel");
1091 String href
= elLink
.getAttributeValue("href");
1093 Media link
= Media
.NewInstance();
1094 MediaRepresentation mr
= MediaRepresentation
.NewInstance();
1095 mr
.addRepresentationPart(MediaRepresentationPart
.NewInstance(href
, null));
1096 link
.addRepresentation(mr
);
1097 person
.addMedia(link
);
1099 } catch (Exception e
) {
1101 logger
.warn("Import of Link " + k
+ " failed.");
1105 if ((++k
% modCount
) == 0){ logger
.info("Links handled: " + k
);}
1109 if (authors
.containsKey(idA
)) {
1110 authors
.put(idA
,person
);
1113 if (editors
.containsKey(idA
)) {
1114 editors
.put(idA
, person
);
1117 } catch (Exception e
) {
1119 logger
.warn("Import of Agent " + j
+ " failed.");
1123 if ((++j
% modCount
) == 0){ logger
.info("Agents handled: " + j
);}
1128 // imports publications related with the data set
1129 protected void importPublications(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1131 logger
.info("start Publications ...");
1132 Element elPublications
= elDataset
.getChild("Publications",sddNamespace
);
1134 if (elPublications
!= null) {
1135 // <Publication id="p1">
1136 List
<Element
> listPublications
= elPublications
.getChildren("Publication", sddNamespace
);
1138 //for each Publication
1139 for (Element elPublication
: listPublications
){
1143 String idP
= elPublication
.getAttributeValue("id");
1146 // <Label>Sample Citation</Label>
1147 // </Representation>
1148 Article publication
= Article
.NewInstance();
1149 importRepresentation(elPublication
, sddNamespace
, publication
, idP
, sddConfig
);
1151 publications
.put(idP
,publication
);
1153 } catch (Exception e
) {
1155 logger
.warn("Import of Publication " + j
+ " failed.");
1159 if ((++j
% modCount
) == 0){ logger
.info("Publications handled: " + j
);}
1165 // imports media objects such as images
1166 protected void importMediaObjects(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1168 logger
.info("start MediaObjects ...");
1169 Element elMediaObjects
= elDataset
.getChild("MediaObjects",sddNamespace
);
1171 if (elMediaObjects
!= null) {
1172 // <MediaObject id="m1">
1173 List
<Element
> listMediaObjects
= elMediaObjects
.getChildren("MediaObject", sddNamespace
);
1175 //for each Publication
1176 for (Element elMO
: listMediaObjects
){
1182 String idMO
= elMO
.getAttributeValue("id");
1186 // <Label>Image description, e.g. to be used for alt-attribute in html.</Label>
1187 // </Representation>
1188 Media media
= Media
.NewInstance();
1189 importRepresentation(elMO
, sddNamespace
, media
, idMO
, sddConfig
);
1191 // <Type>Image</Type>
1192 // <Source href="http://test.edu/test.jpg"/>
1193 String type
= (String
)ImportHelper
.getXmlInputValue(elMO
,"Type",sddNamespace
);
1195 if ((type
!= null) && (type
.equals("Image"))) {
1196 Element elSource
= elMO
.getChild("Source",sddNamespace
);
1197 String href
= elSource
.getAttributeValue("href");
1199 ImageMetaData imageMetaData
= new ImageMetaData();
1200 ImageFile image
= null;
1202 if (href
.substring(0,7).equals("http://")) {
1204 URL url
= new URL(href
);
1205 imageMetaData
.readFrom(url
);
1206 image
= ImageFile
.NewInstance(url
.toString(), null, imageMetaData
);
1207 } catch (MalformedURLException e
) {
1208 logger
.error("Malformed URL", e
);
1211 String sns
= sddConfig
.getSourceNameString();
1212 File f
= new File(sns
);
1213 File parent
= f
.getParentFile();
1214 String fi
= parent
.toString() + File
.separator
+ href
;
1215 File file
= new File(fi
);
1216 imageMetaData
.readFrom(file
);
1217 image
= ImageFile
.NewInstance(file
.toString(), null, imageMetaData
);
1220 MediaRepresentation representation
= MediaRepresentation
.NewInstance(imageMetaData
.getMimeType(), null);
1221 representation
.addRepresentationPart(image
);
1223 media
.addRepresentation(representation
);
1225 ArrayList
<CdmBase
> lcb
= (ArrayList
<CdmBase
>) mediaObject_ListCdmBase
.get(idMO
);
1227 for (int k
= 0; k
< lcb
.size(); k
++) {
1228 if (lcb
.get(k
) instanceof DefinedTermBase
) {
1229 DefinedTermBase dtb
= (DefinedTermBase
) lcb
.get(k
);
1230 // if (lcb.get(0) instanceof DefinedTermBase) {
1231 // DefinedTermBase dtb = (DefinedTermBase) lcb.get(0);
1234 dtb
.addMedia(media
);
1236 // Media me = (Media) media.clone();
1237 // dtb.addMedia(me);
1240 } else if (lcb
.get(k
) instanceof ReferenceBase
) {
1241 ReferenceBase rb
= (ReferenceBase
) lcb
.get(k
);
1242 //} else if (lcb.get(0) instanceof ReferenceBase) {
1243 //ReferenceBase rb = (ReferenceBase) lcb.get(0);
1244 // rb.setTitleCache(label);
1249 // Media me = (Media) media.clone();
1258 } catch (Exception e
) {
1260 logger
.warn("Could not attached MediaObject " + j
+ "(SDD: " + id
+ ") to several objects.");
1264 if ((++j
% modCount
) == 0){ logger
.info("MediaObjects handled: " + j
);
1271 // imports the <DescriptiveConcepts> block
1272 protected void importDescriptiveConcepts(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
1273 // <DescriptiveConcepts>
1274 logger
.info("start DescriptiveConcepts ...");
1275 Element elDescriptiveConcepts
= elDataset
.getChild("DescriptiveConcepts",sddNamespace
);
1276 // <DescriptiveConcept id="b">
1277 if (elDescriptiveConcepts
!= null) {
1278 List
<Element
> listDescriptiveConcepts
= elDescriptiveConcepts
.getChildren("DescriptiveConcept", sddNamespace
);
1280 //for each DescriptiveConcept
1282 for (Element elDescriptiveConcept
: listDescriptiveConcepts
){
1284 String id
= elDescriptiveConcept
.getAttributeValue("id");
1285 String uri
= elDescriptiveConcept
.getAttributeValue("uri");
1287 FeatureNode fn
= null;
1289 if (!id
.equals("")) {
1290 fn
= FeatureNode
.NewInstance();
1291 Feature feature
= Feature
.NewInstance();
1292 feature
.setKindOf(Feature
.DESCRIPTION());
1294 // <Label>Body</Label>
1295 importRepresentation(elDescriptiveConcept
, sddNamespace
, feature
, id
, sddConfig
);
1296 features
.put("g" + g
, feature
);
1298 fn
.setFeature(feature
);
1300 // TODO if an OriginalSource can be attached to a FeatureNode or a Feature
1301 // OriginalSource source = null;
1302 // if (uri != null) {
1303 // if (!uri.equals("")) {
1304 // source = OriginalSource.NewInstance(id, "DescriptiveConcept", Generic.NewInstance(), uri);
1307 // source = OriginalSource.NewInstance(id, "DescriptiveConcept");
1309 // fn.addSource(source);
1311 featureNodes
.put(id
,fn
);
1314 if ((++j
% modCount
) == 0){ logger
.info("DescriptiveConcepts handled: " + j
);}
1320 // imports the descriptions of taxa (specimens TODO)
1321 protected void importCharacterTrees(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1323 logger
.info("start CharacterTrees ...");
1324 Element elCharacterTrees
= elDataset
.getChild("CharacterTrees",sddNamespace
);
1328 if (elCharacterTrees
!= null) {
1329 List
<Element
> listCharacterTrees
= elCharacterTrees
.getChildren("CharacterTree", sddNamespace
);
1331 //for each CharacterTree
1333 for (Element elCharacterTree
: listCharacterTrees
){
1336 Element elRepresentation
= elCharacterTree
.getChild("Representation",sddNamespace
);
1337 String label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
,"Label",sddNamespace
);
1338 Element elDesignedFor
= elCharacterTree
.getChild("DesignedFor",sddNamespace
);
1339 List
<Element
> listRoles
= elDesignedFor
.getChildren("Role",sddNamespace
);
1340 boolean isgroups
= false;
1342 for (Element elRole
: listRoles
){
1343 if (elRole
.getText().equals("Filtering")) {
1348 // only treats the case of flat groups containing characters
1349 // should also be added: dependencies between characters,
1351 if ((label
.contains("group")) || (isgroups
)) {
1353 FeatureTree groups
= FeatureTree
.NewInstance();
1354 importRepresentation(elCharacterTree
, sddNamespace
, groups
, "", sddConfig
);
1355 FeatureNode root
= groups
.getRoot();
1357 Element elNodes
= elCharacterTree
.getChild("Nodes", sddNamespace
);
1358 List
<Element
> listNodes
= elNodes
.getChildren("Node", sddNamespace
);
1359 for (Element elNode
: listNodes
){
1360 String idN
= elNode
.getAttributeValue("id");
1361 FeatureNode fn
= null;
1362 if (!idN
.equals("")) {
1363 Element elDescriptiveConcept
= elNode
.getChild("DescriptiveConcept", sddNamespace
);
1364 String refDC
= elDescriptiveConcept
.getAttributeValue("ref");
1365 fn
= featureNodes
.get(refDC
);
1371 List
<Element
> listCharNodes
= elNodes
.getChildren("CharNode", sddNamespace
);
1372 for (Element elCharNode
: listCharNodes
){
1373 Element elParent
= elCharNode
.getChild("Parent", sddNamespace
);
1374 String refP
= elParent
.getAttributeValue("ref");
1375 Element elCharacter
= elCharNode
.getChild("Character", sddNamespace
);
1376 String refC
= elCharacter
.getAttributeValue("ref");
1377 FeatureNode fn
= FeatureNode
.NewInstance();
1378 if (!refP
.equals("")) {
1379 FeatureNode parent
= nodes
.get(refP
);
1380 parent
.addChild(fn
);
1381 Feature character
= features
.get(refC
);
1382 fn
.setFeature(character
);
1383 // if method setParent() in FeatureNode becomes visible
1384 // fn.setParent(parent);
1386 nodes
.put(refC
, fn
);
1388 featureTrees
.add(groups
);
1391 } catch (Exception e
) {
1393 logger
.warn("Import of Character tree " + j
+ " failed.");
1397 if ((++j
% modCount
) == 0){ logger
.info("CharacterTrees handled: " + j
);}