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
.Collection
;
18 import java
.util
.Date
;
19 import java
.util
.GregorianCalendar
;
20 import java
.util
.HashMap
;
21 import java
.util
.HashSet
;
22 import java
.util
.Iterator
;
23 import java
.util
.List
;
27 import org
.apache
.log4j
.Logger
;
28 import org
.jdom
.Element
;
29 import org
.jdom
.Namespace
;
30 import org
.joda
.time
.DateTime
;
31 import org
.springframework
.stereotype
.Component
;
32 import org
.springframework
.transaction
.TransactionStatus
;
34 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
35 import eu
.etaxonomy
.cdm
.api
.service
.IReferenceService
;
36 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
37 import eu
.etaxonomy
.cdm
.common
.MediaMetaData
.ImageMetaData
;
38 import eu
.etaxonomy
.cdm
.io
.common
.ICdmIO
;
39 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
40 import eu
.etaxonomy
.cdm
.io
.common
.ImportHelper
;
41 import eu
.etaxonomy
.cdm
.io
.common
.MapWrapper
;
42 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
43 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
44 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
45 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
46 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
47 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
48 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
49 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
50 import eu
.etaxonomy
.cdm
.model
.common
.MultilanguageText
;
51 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSource
;
52 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
53 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
54 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
55 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
56 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
57 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
58 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
59 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
60 import eu
.etaxonomy
.cdm
.model
.description
.MeasurementUnit
;
61 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
62 import eu
.etaxonomy
.cdm
.model
.description
.State
;
63 import eu
.etaxonomy
.cdm
.model
.description
.StateData
;
64 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasure
;
65 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasurementValue
;
66 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
67 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
68 import eu
.etaxonomy
.cdm
.model
.media
.ImageFile
;
69 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
70 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
71 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentationPart
;
72 import eu
.etaxonomy
.cdm
.model
.media
.Rights
;
73 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
74 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
75 import eu
.etaxonomy
.cdm
.model
.reference
.Article
;
76 import eu
.etaxonomy
.cdm
.model
.reference
.Database
;
77 import eu
.etaxonomy
.cdm
.model
.reference
.Generic
;
78 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
79 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
86 @Component("sddDescriptionIO")
87 public class SDDDescriptionIO
extends SDDIoBase
implements ICdmIO
<IImportConfigurator
> {
88 private static final Logger logger
= Logger
.getLogger(SDDDescriptionIO
.class);
90 private static int modCount
= 1000;
92 private Map
<String
,Person
> authors
= new HashMap
<String
,Person
>();
93 private Map
<String
,String
> citations
= new HashMap
<String
,String
>();
94 private Map
<String
,String
> defaultUnitPrefixes
= new HashMap
<String
,String
>();
95 private Map
<String
,Person
> editors
= new HashMap
<String
,Person
>();
96 private Map
<String
,FeatureNode
> featureNodes
= new HashMap
<String
,FeatureNode
>();
97 private Map
<String
,Feature
> features
= new HashMap
<String
,Feature
>();
98 private Map
<String
,String
> locations
= new HashMap
<String
,String
>();
99 private Map
<String
,List
<CdmBase
>> mediaObject_ListCdmBase
= new HashMap
<String
,List
<CdmBase
>>();
100 private Map
<String
,String
> mediaObject_Role
= new HashMap
<String
,String
>();
101 private Map
<String
,FeatureNode
> nodes
= new HashMap
<String
,FeatureNode
>();
102 private Map
<String
,ReferenceBase
> publications
= new HashMap
<String
,ReferenceBase
>();
103 private Map
<String
,StateData
> stateDatas
= new HashMap
<String
,StateData
>();
104 private Map
<String
,TaxonDescription
> taxonDescriptions
= new HashMap
<String
,TaxonDescription
>();
105 private Map
<String
,NonViralName
> taxonNameBases
= new HashMap
<String
,NonViralName
>();
106 private Map
<String
,MeasurementUnit
> units
= new HashMap
<String
,MeasurementUnit
>();
108 private Set
<Feature
> featureSet
= new HashSet
<Feature
>();
110 private ReferenceBase sec
= Database
.NewInstance();
111 private ReferenceBase sourceReference
= null;
113 private Language datasetLanguage
= null;
115 private Namespace xmlNamespace
= Namespace
.getNamespace("xml","http://www.w3.org/XML/1998/namespace");
117 private String generatorName
= "";
118 private String generatorVersion
= "";
120 private Set
<StatisticalMeasure
> statisticalMeasures
= new HashSet
<StatisticalMeasure
>();
121 private Set
<VersionableEntity
> featureData
= new HashSet
<VersionableEntity
>();
122 private Set
<FeatureTree
> featureTrees
= new HashSet
<FeatureTree
>();
124 private Rights copyright
= null;
126 public SDDDescriptionIO(){
131 public boolean doCheck(IImportConfigurator config
){
132 boolean result
= true;
133 logger
.warn("No check implemented for SDD");
138 public boolean doInvoke(IImportConfigurator config
, Map
<String
, MapWrapper
<?
extends CdmBase
>> stores
){
140 TransactionStatus ts
= startTransaction();
141 SDDImportConfigurator sddConfig
= (SDDImportConfigurator
)config
;
143 logger
.info("start Datasets ...");
144 // <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">
145 Element root
= sddConfig
.getSourceRoot();
146 boolean success
= true;
147 Namespace sddNamespace
= sddConfig
.getSddNamespace();
149 logger
.info("start TechnicalMetadata ...");
150 // <TechnicalMetadata created="2006-04-20T10:00:00">
151 importTechnicalMetadata(root
, sddNamespace
, sddConfig
);
152 List
<Element
> elDatasets
= root
.getChildren("Dataset",sddNamespace
);
156 logger
.info("start Dataset ...");
157 for (Element elDataset
: elDatasets
){
158 importDataset(elDataset
, sddNamespace
, success
, sddConfig
);
159 if ((++i
% modCount
) == 0){ logger
.info("Datasets handled: " + i
);}
160 logger
.info(i
+ " Datasets handled");
162 commitTransaction(ts
);
167 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
169 protected boolean isIgnore(IImportConfigurator config
){
174 // associates the reference of a media object in SDD with a CdmBase Object
175 protected void associateImageWithCdmBase(String refMO
, CdmBase cb
){
176 if ((refMO
!= null) && (cb
!=null)) {
177 if (!refMO
.equals("")) {
178 if (!mediaObject_ListCdmBase
.containsKey(refMO
)) {
179 List
<CdmBase
> lcb
= new ArrayList
<CdmBase
>();
181 mediaObject_ListCdmBase
.put(refMO
,lcb
);
183 List
<CdmBase
> lcb
= mediaObject_ListCdmBase
.get(refMO
);
185 mediaObject_ListCdmBase
.put(refMO
,lcb
);
191 // imports information about the Dataset
192 protected void importDatasetRepresentation(Element parent
, Namespace sddNamespace
){
193 logger
.info("start Representation ...");
195 <Label>The Genus Viola</Label>
196 <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>
199 Element elRepresentation
= parent
.getChild("Representation",sddNamespace
);
200 String label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
201 String detail
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Detail",sddNamespace
);
203 sec
.setTitleCache(label
);
205 if (detail
!= null) {
206 Annotation annotation
= Annotation
.NewInstance(detail
, datasetLanguage
);
207 sec
.addAnnotation(annotation
);
210 List
<Element
> listMediaObjects
= elRepresentation
.getChildren("MediaObject",sddNamespace
);
212 for (Element elMediaObject
: listMediaObjects
) {
215 if (elMediaObject
!= null) {
216 ref
= elMediaObject
.getAttributeValue("ref");
217 role
= elMediaObject
.getAttributeValue("role");
220 if (!ref
.equals("")) {
221 this.associateImageWithCdmBase(ref
,sourceReference
);
222 this.associateImageWithCdmBase(ref
,sec
);
223 mediaObject_Role
.put(ref
,role
);
229 // imports the representation (label, detail, lang) of a particular SDD element
230 protected void importRepresentation(Element parent
, Namespace sddNamespace
, VersionableEntity ve
, String id
, IImportConfigurator config
){
231 Element elRepresentation
= parent
.getChild("Representation",sddNamespace
);
232 // <Label xml:lang="la">Viola hederacea Labill.</Label>
233 List
<Element
> listLabels
= elRepresentation
.getChildren("Label",sddNamespace
);
234 List
<Element
> listDetails
= elRepresentation
.getChildren("Detail",sddNamespace
);
235 Map
<Language
,List
<String
>> langLabDet
= new HashMap
<Language
,List
<String
>>();
237 for (Element elLabel
: listLabels
){
238 String lang
= elLabel
.getAttributeValue("lang",xmlNamespace
);
239 Language language
= null;
241 if (!lang
.equals("")) {
242 language
= getTermService().getLanguageByIso(lang
.substring(0, 2));
244 language
= datasetLanguage
;
247 language
= datasetLanguage
;
249 String label
= elLabel
.getText();
250 List
<String
> labDet
= new ArrayList
<String
>(3);
252 langLabDet
.put(language
, labDet
);
255 for (Element elDetail
: listDetails
){
256 String lang
= elDetail
.getAttributeValue("lang",xmlNamespace
);
257 String role
= elDetail
.getAttributeValue("role");
258 Language language
= null;
260 if (!lang
.equals("")) {
261 language
= getTermService().getLanguageByIso(lang
.substring(0, 2));
263 language
= datasetLanguage
;
266 language
= datasetLanguage
;
268 String detail
= elDetail
.getText();
269 List
<String
> labDet
= langLabDet
.get(language
);
272 langLabDet
.put(language
, labDet
);
275 if (ve
instanceof IdentifiableEntity
) {
276 IdentifiableEntity ie
= (IdentifiableEntity
) ve
;
277 List
<String
> labDet
= null;
279 if (ve
instanceof TaxonNameBase
) {
280 if (langLabDet
.keySet().contains(getTermService().getLanguageByIso("la"))) {
281 labDet
= langLabDet
.get(getTermService().getLanguageByIso("la"));
282 } else if (langLabDet
.keySet().contains(datasetLanguage
)) {
283 labDet
= langLabDet
.get(datasetLanguage
);
284 logger
.info("TaxonName " + (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
) + " is not specified as a latin name.");
286 labDet
= langLabDet
.get(langLabDet
.keySet().iterator().next());
287 logger
.info("TaxonName " + (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
) + " is not specified as a latin name.");
290 labDet
= langLabDet
.get(langLabDet
.keySet().iterator().next());
293 ie
.setTitleCache(labDet
.get(0));
295 if (labDet
.size()>1) {
296 Annotation annotation
= null;
297 if (labDet
.get(1) != null) {
298 if (labDet
.get(2) != null) {
299 annotation
= Annotation
.NewInstance(labDet
.get(2) + " - " + labDet
.get(1), datasetLanguage
);
301 annotation
= Annotation
.NewInstance(labDet
.get(1), datasetLanguage
);
304 ie
.addAnnotation(annotation
);
309 } else if (ve
instanceof TermBase
) {
310 TermBase tb
= (TermBase
) ve
;
312 for (Iterator
<Language
> l
= langLabDet
.keySet().iterator() ; l
.hasNext() ;){
313 Language lang
= l
.next();
314 List
<String
> labDet
= langLabDet
.get(lang
);
315 if (labDet
.size()>0){
316 if (labDet
.size()>1) {
317 tb
.addRepresentation(Representation
.NewInstance(labDet
.get(1), labDet
.get(0), labDet
.get(0), lang
));
319 tb
.addRepresentation(Representation
.NewInstance(labDet
.get(0), labDet
.get(0), labDet
.get(0), lang
));
325 } else if (ve
instanceof Media
) {
326 Media m
= (Media
) ve
;
328 for (Iterator
<Language
> l
= langLabDet
.keySet().iterator() ; l
.hasNext() ;){
329 Language lang
= l
.next();
330 List
<String
> labDet
= langLabDet
.get(lang
);
331 if (labDet
.get(0) != null){
332 MultilanguageText mt
= MultilanguageText
.NewInstance();
333 mt
.add(LanguageString
.NewInstance(labDet
.get(0), lang
));
336 if (labDet
.size()>1) {
337 m
.addDescription(labDet
.get(1), lang
);
344 List
<Element
> listMediaObjects
= elRepresentation
.getChildren("MediaObject",sddNamespace
);
346 for (Element elMediaObject
: listMediaObjects
) {
349 if (elMediaObject
!= null) {
350 ref
= elMediaObject
.getAttributeValue("ref");
351 role
= elMediaObject
.getAttributeValue("role");
354 if (!ref
.equals("")) {
356 if (ve
instanceof TaxonDescription
) {
357 TaxonDescription td
= (TaxonDescription
) ve
;
358 //TODO: ensure that all images are imported
359 if (td
.getDescriptionSources().toArray().length
> 0) {
360 this.associateImageWithCdmBase(ref
,(ReferenceBase
) td
.getDescriptionSources().toArray()[0]);
362 ReferenceBase descriptionSource
= Generic
.NewInstance();
363 td
.addDescriptionSource(descriptionSource
);
364 this.associateImageWithCdmBase(ref
,descriptionSource
);
367 this.associateImageWithCdmBase(ref
,ve
);
377 // imports the representation (label, detail, lang) of a particular SDD element
378 protected void importTechnicalMetadata(Element root
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
379 Element elTechnicalMetadata
= root
.getChild("TechnicalMetadata", sddNamespace
);
380 String nameCreated
= elTechnicalMetadata
.getAttributeValue("created");
381 sourceReference
= sddConfig
.getSourceReference();
383 if (nameCreated
!= null) {
384 if (!nameCreated
.equals("")) {
385 int year
= Integer
.parseInt(nameCreated
.substring(0,4));
386 int monthOfYear
= Integer
.parseInt(nameCreated
.substring(5,7));
387 int dayOfMonth
= Integer
.parseInt(nameCreated
.substring(8,10));
388 int hourOfDay
= Integer
.parseInt(nameCreated
.substring(11,13));
389 int minuteOfHour
= Integer
.parseInt(nameCreated
.substring(14,16));
390 int secondOfMinute
= Integer
.parseInt(nameCreated
.substring(17,19));
391 DateTime created
= new DateTime(year
,monthOfYear
,dayOfMonth
,hourOfDay
,minuteOfHour
,secondOfMinute
,0);
392 sourceReference
.setCreated(created
);
393 sec
.setCreated(created
);
397 // <Generator name="n/a, handcrafted instance document" version="n/a"/>
398 Element elGenerator
= elTechnicalMetadata
.getChild("Generator", sddNamespace
);
399 generatorName
= elGenerator
.getAttributeValue("name");
400 generatorVersion
= elGenerator
.getAttributeValue("version");
402 sec
.addAnnotation(Annotation
.NewDefaultLanguageInstance(generatorName
+ " - " + generatorVersion
));
403 sourceReference
.addAnnotation(Annotation
.NewDefaultLanguageInstance(generatorName
+ " - " + generatorVersion
));
407 // imports the complete dataset information
408 protected void importDataset(Element elDataset
, Namespace sddNamespace
, boolean success
, SDDImportConfigurator sddConfig
){ // <Dataset xml:lang="en-us">
410 importDatasetLanguage(elDataset
,sddConfig
);
411 importDatasetRepresentation(elDataset
, sddNamespace
);
412 importRevisionData(elDataset
, sddNamespace
);
413 importIPRStatements(elDataset
, sddNamespace
, sddConfig
);
414 importTaxonNames(elDataset
, sddNamespace
, sddConfig
);
415 importDescriptiveConcepts(elDataset
, sddNamespace
, sddConfig
);
416 importCharacters(elDataset
, sddNamespace
, sddConfig
, success
);
417 importCharacterTrees(elDataset
, sddNamespace
, sddConfig
, success
);
418 importCodedDescriptions(elDataset
, sddNamespace
, sddConfig
, success
);
419 importAgents(elDataset
, sddNamespace
, sddConfig
, success
);
420 importPublications(elDataset
, sddNamespace
, sddConfig
, success
);
421 importMediaObjects(elDataset
, sddNamespace
, sddConfig
, success
);
423 if (authors
!= null) {
424 Team team
= Team
.NewInstance();
425 for (Iterator
<Person
> author
= authors
.values().iterator() ; author
.hasNext() ;){
426 team
.addTeamMember(author
.next());
428 sec
.setAuthorTeam(team
);
429 sourceReference
.setAuthorTeam(team
);
432 if (editors
!= null) {
433 Person ed
= Person
.NewInstance();
434 for (Iterator
<Person
> editor
= editors
.values().iterator() ; editor
.hasNext() ;){
437 sec
.setUpdatedBy(ed
);
438 sourceReference
.setUpdatedBy(ed
);
441 if (copyright
!= null) {
442 sourceReference
.addRights(copyright
);
443 sec
.addRights(copyright
);
446 for (Iterator
<String
> refCD
= taxonDescriptions
.keySet().iterator() ; refCD
.hasNext() ;){
447 String ref
= refCD
.next();
448 TaxonDescription td
= taxonDescriptions
.get(ref
);
449 td
.addDescriptionSource(sec
);
450 if (citations
.containsKey(ref
)) {
451 Article publication
= (Article
) publications
.get(citations
.get(ref
));
452 if (locations
.containsKey(ref
)) {
453 publication
.addAnnotation(Annotation
.NewInstance(locations
.get(ref
), datasetLanguage
));
455 td
.addDescriptionSource(publication
);
458 logger
.info("end makeTaxonDescriptions ...");
460 sddConfig
.setSourceReference(sourceReference
);
462 //saving of all imported data into the CDM db
463 ITermService termService
= getTermService();
464 for (Iterator
<StateData
> k
= stateDatas
.values().iterator() ; k
.hasNext() ;){
465 StateData sd
= k
.next();
466 termService
.saveTerm(sd
.getState());
468 for (Iterator
<Feature
> k
= features
.values().iterator() ; k
.hasNext() ;){
469 Feature feature
= k
.next();
470 termService
.saveTerm(feature
);
473 for (Iterator
<MeasurementUnit
> k
= units
.values().iterator() ; k
.hasNext() ;){
474 MeasurementUnit unit
= k
.next();
476 termService
.saveTerm(unit
);
480 for (Iterator
<StatisticalMeasure
> k
= statisticalMeasures
.iterator() ; k
.hasNext() ;) {
481 StatisticalMeasure sm
= k
.next();
482 termService
.saveTerm(sm
);
485 IReferenceService referenceService
= getReferenceService();
486 // referenceService.saveReference(sourceReference);
487 for (Iterator
<ReferenceBase
> k
= publications
.values().iterator() ; k
.hasNext() ;){
488 Article publication
= (Article
) k
.next();
489 referenceService
.saveReference(publication
);
492 // Returns a CdmApplicationController created by the values of this configuration.
493 IDescriptionService descriptionService
= getDescriptionService();
495 for (Iterator
<TaxonDescription
> k
= taxonDescriptions
.values().iterator() ; k
.hasNext() ;){
496 TaxonDescription taxonDescription
= k
.next();
497 // Persists a Description
498 descriptionService
.saveDescription(taxonDescription
);
501 // descriptionService.saveFeatureNodeAll(featureNodes.values());
503 for (Iterator
<FeatureTree
> k
= featureTrees
.iterator() ; k
.hasNext() ;) {
504 FeatureTree tree
= k
.next();
505 descriptionService
.saveFeatureTree(tree
);
510 // imports the default language of the dataset
511 protected void importDatasetLanguage(Element elDataset
, SDDImportConfigurator sddConfig
){
512 String nameLang
= elDataset
.getAttributeValue("lang",xmlNamespace
);
514 if (!nameLang
.equals("")) {
515 String iso
= nameLang
.substring(0, 2);
516 datasetLanguage
= getTermService().getLanguageByIso(iso
);
518 datasetLanguage
= Language
.ENGLISH();
520 if (datasetLanguage
== null) {
521 datasetLanguage
= Language
.ENGLISH();
525 // imports the revision data associated with the Dataset (authors, modifications)
526 protected void importRevisionData(Element elDataset
, Namespace sddNamespace
){
528 logger
.info("start RevisionData ...");
529 Element elRevisionData
= elDataset
.getChild("RevisionData",sddNamespace
);
532 Element elCreators
= elRevisionData
.getChild("Creators",sddNamespace
);
534 // <Agent role="aut" ref="a1"/>
535 List
<Element
> listAgents
= elCreators
.getChildren("Agent", sddNamespace
);
539 for (Element elAgent
: listAgents
){
541 String role
= elAgent
.getAttributeValue("role");
542 String ref
= elAgent
.getAttributeValue("ref");
543 if (role
.equals("aut")) {
544 if(!ref
.equals("")) {
545 authors
.put(ref
, null);
548 if (role
.equals("edt")) {
549 if(!ref
.equals("")) {
550 editors
.put(ref
, null);
554 if ((++j
% modCount
) == 0){ logger
.info("Agents handled: " + j
);}
558 // <DateModified>2006-04-08T00:00:00</DateModified>
559 String stringDateModified
= (String
)ImportHelper
.getXmlInputValue(elRevisionData
, "DateModified",sddNamespace
);
561 if (stringDateModified
!= null) {
562 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
565 d
= sdf
.parse(stringDateModified
);
566 } catch(Exception e
) {
567 System
.err
.println("Exception :");
571 GregorianCalendar updated
= null;
573 updated
= new java
.util
.GregorianCalendar();
575 sourceReference
.setUpdated(updated
);
576 sec
.setUpdated(updated
);
581 // imports ipr statements associated with a dataset
582 protected void importIPRStatements(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
584 logger
.info("start IPRStatements ...");
585 Element elIPRStatements
= elDataset
.getChild("IPRStatements",sddNamespace
);
586 // <IPRStatement role="Copyright">
587 if (elIPRStatements
!= null) {
588 List
<Element
> listIPRStatements
= elIPRStatements
.getChildren("IPRStatement", sddNamespace
);
590 //for each IPRStatement
592 for (Element elIPRStatement
: listIPRStatements
){
594 String role
= elIPRStatement
.getAttributeValue("role");
595 // <Label xml:lang="en-au">(c) 2003-2006 Centre for Occasional Botany.</Label>
596 Element elLabel
= elIPRStatement
.getChild("Label",sddNamespace
);
598 if (elLabel
!= null) {
599 lang
= elLabel
.getAttributeValue("lang",xmlNamespace
);
601 String label
= (String
)ImportHelper
.getXmlInputValue(elIPRStatement
, "Label",sddNamespace
);
603 if (role
.equals("Copyright")) {
604 Language iprLanguage
= null;
606 if (!lang
.equals("")) {
607 iprLanguage
= getTermService().getLanguageByIso(lang
.substring(0, 2));
608 //iprLanguage = datasetLanguage;
610 iprLanguage
= datasetLanguage
;
613 if (iprLanguage
== null) {
614 iprLanguage
= datasetLanguage
;
616 copyright
= Rights
.NewInstance(label
, iprLanguage
);
619 if (copyright
!= null) {
620 sourceReference
.addRights(copyright
);
621 sec
.addRights(copyright
);
624 if ((++j
% modCount
) == 0){ logger
.info("IPRStatements handled: " + j
);}
630 // imports the taxon names
631 protected void importTaxonNames(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
633 logger
.info("start TaxonNames ...");
634 Element elTaxonNames
= elDataset
.getChild("TaxonNames",sddNamespace
);
635 // <TaxonName id="t1" uri="urn:lsid:authority:namespace:my-own-id">
636 if (elTaxonNames
!= null) {
637 List
<Element
> listTaxonNames
= elTaxonNames
.getChildren("TaxonName", sddNamespace
);
640 for (Element elTaxonName
: listTaxonNames
){
642 String id
= elTaxonName
.getAttributeValue("id");
643 String uri
= elTaxonName
.getAttributeValue("uri");
645 NonViralName tnb
= null;
646 if (!id
.equals("")) {
647 tnb
= NonViralName
.NewInstance(null);
648 OriginalSource source
= null;
650 if (!uri
.equals("")) {
651 source
= OriginalSource
.NewInstance(id
, "TaxonName", Generic
.NewInstance(), uri
);
654 source
= OriginalSource
.NewInstance(id
, "TaxonName");
656 tnb
.addSource(source
);
657 taxonNameBases
.put(id
,tnb
);
661 // <Label xml:lang="la">Viola hederacea Labill.</Label>
662 importRepresentation(elTaxonName
, sddNamespace
, tnb
, id
, sddConfig
);
664 if ((++j
% modCount
) == 0){ logger
.info("TaxonNames handled: " + j
);}
670 // imports the representation (label, detail, lang) of a particular SDD element
671 protected void importCharacters(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
673 logger
.info("start Characters ...");
674 Element elCharacters
= elDataset
.getChild("Characters", sddNamespace
);
676 // <CategoricalCharacter id="c1">
677 if (elCharacters
!= null) {
678 List
<Element
> elCategoricalCharacters
= elCharacters
.getChildren("CategoricalCharacter", sddNamespace
);
680 //for each CategoricalCharacter
681 for (Element elCategoricalCharacter
: elCategoricalCharacters
){
685 String idCC
= elCategoricalCharacter
.getAttributeValue("id");
688 // <Label> Leaf complexity</Label>
691 Feature categoricalCharacter
= Feature
.NewInstance();
692 importRepresentation(elCategoricalCharacter
, sddNamespace
, categoricalCharacter
, idCC
, sddConfig
);
694 categoricalCharacter
.setSupportsQuantitativeData(false);
695 categoricalCharacter
.setSupportsTextData(false);
698 Element elStates
= elCategoricalCharacter
.getChild("States",sddNamespace
);
700 // <StateDefinition id="s1">
701 List
<Element
> elStateDefinitions
= elStates
.getChildren("StateDefinition",sddNamespace
);
702 TermVocabulary
<State
> termVocabularyState
= new TermVocabulary
<State
>();
705 //for each StateDefinition
706 for (Element elStateDefinition
: elStateDefinitions
){
708 if ((++k
% modCount
) == 0){ logger
.info("StateDefinitions handled: " + (k
-1));}
710 String idSD
= elStateDefinition
.getAttributeValue("id");
712 // <Label>Simple</Label>
713 // <MediaObject ref="ib" role="Primary"/>
715 State state
= State
.NewInstance();
716 importRepresentation(elStateDefinition
, sddNamespace
, state
, idSD
, sddConfig
);
718 StateData stateData
= StateData
.NewInstance();
719 stateData
.setState(state
);
720 termVocabularyState
.addTerm(state
);
721 stateDatas
.put(idSD
,stateData
);
724 categoricalCharacter
.addSupportedCategoricalEnumeration(termVocabularyState
);
725 features
.put(idCC
, categoricalCharacter
);
727 } catch (Exception e
) {
729 logger
.warn("Import of CategoricalCharacter " + j
+ " failed.");
733 if ((++j
% modCount
) == 0){ logger
.info("CategoricalCharacters handled: " + j
);}
737 // <QuantitativeCharacter id="c2">
738 List
<Element
> elQuantitativeCharacters
= elCharacters
.getChildren("QuantitativeCharacter", sddNamespace
);
740 //for each QuantitativeCharacter
741 for (Element elQuantitativeCharacter
: elQuantitativeCharacters
){
745 String idQC
= elQuantitativeCharacter
.getAttributeValue("id");
748 // <Label>Leaf length</Label>
750 Feature quantitativeCharacter
= Feature
.NewInstance();
751 importRepresentation(elQuantitativeCharacter
, sddNamespace
, quantitativeCharacter
, idQC
, sddConfig
);
753 quantitativeCharacter
.setSupportsQuantitativeData(true);
754 quantitativeCharacter
.setSupportsTextData(false);
757 // <Label role="Abbrev">m</Label>
758 // </MeasurementUnit>
759 Element elMeasurementUnit
= elQuantitativeCharacter
.getChild("MeasurementUnit",sddNamespace
);
762 if (elMeasurementUnit
!= null) {
763 Element elLabel
= elMeasurementUnit
.getChild("Label",sddNamespace
);
764 role
= elLabel
.getAttributeValue("role");
765 label
= (String
)ImportHelper
.getXmlInputValue(elMeasurementUnit
, "Label",sddNamespace
);
768 MeasurementUnit unit
= null;
769 if (!label
.equals("")){
771 if (role
.equals("Abbrev")){
772 unit
= MeasurementUnit
.NewInstance(label
,label
,label
);
775 unit
= MeasurementUnit
.NewInstance(label
,label
,label
);
780 units
.put(idQC
, unit
);
784 // <MeasurementUnitPrefix>milli</MeasurementUnitPrefix>
786 Element elDefault
= elQuantitativeCharacter
.getChild("Default",sddNamespace
);
787 if (elDefault
!= null) {
788 String measurementUnitPrefix
= (String
)ImportHelper
.getXmlInputValue(elDefault
, "MeasurementUnitPrefix",sddNamespace
);
789 if (!measurementUnitPrefix
.equals("")){
790 defaultUnitPrefixes
.put(idQC
, measurementUnitPrefix
);
794 features
.put(idQC
, quantitativeCharacter
);
796 } catch (Exception e
) {
798 logger
.warn("Import of QuantitativeCharacter " + j
+ " failed.");
802 if ((++j
% modCount
) == 0){ logger
.info("QuantitativeCharacters handled: " + j
);}
806 // <TextCharacter id="c3">
807 List
<Element
> elTextCharacters
= elCharacters
.getChildren("TextCharacter", sddNamespace
);
809 //for each TextCharacter
810 for (Element elTextCharacter
: elTextCharacters
){
814 String idTC
= elTextCharacter
.getAttributeValue("id");
817 // <Label xml:lang="en">Leaf features not covered by other characters</Label>
819 Feature textCharacter
= Feature
.NewInstance();
820 importRepresentation(elTextCharacter
, sddNamespace
, textCharacter
, idTC
, sddConfig
);
822 textCharacter
.setSupportsQuantitativeData(false);
823 textCharacter
.setSupportsTextData(true);
825 features
.put(idTC
, textCharacter
);
827 } catch (Exception e
) {
829 logger
.warn("Import of TextCharacter " + j
+ " failed.");
833 if ((++j
% modCount
) == 0){ logger
.info("TextCharacters handled: " + j
);}
839 for (Iterator
<Feature
> f
= features
.values().iterator() ; f
.hasNext() ;){
840 featureSet
.add(f
.next());
845 // imports the descriptions of taxa (specimens TODO)
846 protected void importCodedDescriptions(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
847 // <CodedDescriptions>
848 logger
.info("start CodedDescriptions ...");
849 Element elCodedDescriptions
= elDataset
.getChild("CodedDescriptions",sddNamespace
);
851 // <CodedDescription id="D101">
853 if (elCodedDescriptions
!= null) {
854 List
<Element
> listCodedDescriptions
= elCodedDescriptions
.getChildren("CodedDescription", sddNamespace
);
856 //for each CodedDescription
858 for (Element elCodedDescription
: listCodedDescriptions
){
862 String idCD
= elCodedDescription
.getAttributeValue("id");
865 // <Label><i>Viola hederacea</i> Labill. as revised by R. Morris April 8, 2006</Label>
867 TaxonDescription taxonDescription
= TaxonDescription
.NewInstance();
868 importRepresentation(elCodedDescription
, sddNamespace
, taxonDescription
, idCD
, sddConfig
);
871 // <TaxonName ref="t1"/>
872 // <Citation ref="p1" location="p. 30"/>
874 Element elScope
= elCodedDescription
.getChild("Scope",sddNamespace
);
877 if (elScope
!= null) {
878 Element elTaxonName
= elScope
.getChild("TaxonName",sddNamespace
);
879 ref
= elTaxonName
.getAttributeValue("ref");
881 NonViralName taxonNameBase
= taxonNameBases
.get(ref
);
882 taxon
= Taxon
.NewInstance(taxonNameBase
, sec
);
885 String refCitation
= "";
886 String location
= "";
888 if (elScope
!= null) {
889 Element elCitation
= elScope
.getChild("Citation",sddNamespace
);
890 if (elCitation
!= null) {
891 refCitation
= elCitation
.getAttributeValue("ref");
892 location
= elCitation
.getAttributeValue("location");
897 Element elSummaryData
= elCodedDescription
.getChild("SummaryData",sddNamespace
);
899 if (elSummaryData
!= null) {
901 // <Categorical ref="c4">
902 List
<Element
> elCategoricals
= elSummaryData
.getChildren("Categorical", sddNamespace
);
904 //for each Categorical
905 for (Element elCategorical
: elCategoricals
){
906 if ((++k
% modCount
) == 0){ logger
.info("Categorical handled: " + (k
-1));}
907 ref
= elCategorical
.getAttributeValue("ref");
908 Feature feature
= features
.get(ref
);
909 CategoricalData categoricalData
= CategoricalData
.NewInstance();
910 categoricalData
.setFeature(feature
);
913 List
<Element
> elStates
= elCategorical
.getChildren("State", sddNamespace
);
916 for (Element elState
: elStates
){
917 if ((++l
% modCount
) == 0){ logger
.info("States handled: " + (l
-1));}
918 ref
= elState
.getAttributeValue("ref");
919 StateData stateData
= stateDatas
.get(ref
);
920 categoricalData
.addState(stateData
);
922 taxonDescription
.addElement(categoricalData
);
925 // <Quantitative ref="c2">
926 List
<Element
> elQuantitatives
= elSummaryData
.getChildren("Quantitative", sddNamespace
);
928 //for each Quantitative
929 for (Element elQuantitative
: elQuantitatives
){
930 if ((++k
% modCount
) == 0){ logger
.info("Quantitative handled: " + (k
-1));}
931 ref
= elQuantitative
.getAttributeValue("ref");
932 Feature feature
= features
.get(ref
);
933 QuantitativeData quantitativeData
= QuantitativeData
.NewInstance();
934 quantitativeData
.setFeature(feature
);
936 MeasurementUnit unit
= units
.get(ref
);
937 String prefix
= defaultUnitPrefixes
.get(ref
);
939 String u
= unit
.getLabel();
940 if (prefix
!= null) {
944 quantitativeData
.setUnit(unit
);
947 // <Measure type="Min" value="2.3"/>
948 List
<Element
> elMeasures
= elQuantitative
.getChildren("Measure", sddNamespace
);
951 for (Element elMeasure
: elMeasures
){
952 if ((++l
% modCount
) == 0){ logger
.info("States handled: " + (l
-1));}
953 String type
= elMeasure
.getAttributeValue("type");
954 String value
= elMeasure
.getAttributeValue("value");
955 float v
= Float
.parseFloat(value
);
956 StatisticalMeasure t
= null;
957 if (type
.equals("Min")) {
958 t
= StatisticalMeasure
.MIN();
959 } else if (type
.equals("Mean")) {
960 t
= StatisticalMeasure
.AVERAGE();
961 } else if (type
.equals("Max")) {
962 t
= StatisticalMeasure
.MAX();
963 } else if (type
.equals("SD")) {
964 // Create a new StatisticalMeasure for standard deviation
965 t
= StatisticalMeasure
.STANDARD_DEVIATION();
966 } else if (type
.equals("N")) {
967 t
= StatisticalMeasure
.SAMPLE_SIZE();
969 t
= StatisticalMeasure
.NewInstance(type
,type
,type
);
970 statisticalMeasures
.add(t
);
973 StatisticalMeasurementValue statisticalValue
= StatisticalMeasurementValue
.NewInstance();
974 statisticalValue
.setValue(v
);
975 statisticalValue
.setType(t
);
976 quantitativeData
.addStatisticalValue(statisticalValue
);
977 featureData
.add(statisticalValue
);
979 taxonDescription
.addElement(quantitativeData
);
982 // <TextChar ref="c3">
983 List
<Element
> elTextChars
= elSummaryData
.getChildren("TextChar", sddNamespace
);
986 for (Element elTextChar
: elTextChars
){
987 if ((++k
% modCount
) == 0){ logger
.info("TextChar handled: " + (k
-1));}
988 ref
= elTextChar
.getAttributeValue("ref");
989 Feature feature
= features
.get(ref
);
990 TextData textData
= TextData
.NewInstance();
991 textData
.setFeature(feature
);
993 // <Content>Free form text</Content>
994 String content
= (String
)ImportHelper
.getXmlInputValue(elTextChar
, "Content",sddNamespace
);
995 textData
.putText(content
, datasetLanguage
);
996 taxonDescription
.addElement(textData
);
1001 if (taxon
!= null) {
1002 taxon
.addDescription(taxonDescription
);
1005 if (!refCitation
.equals("")){
1006 citations
.put(idCD
,refCitation
);
1009 if (!location
.equals("")){
1010 locations
.put(idCD
, location
);
1013 taxonDescription
.setDescriptiveSystem(featureSet
);
1015 taxonDescriptions
.put(idCD
, taxonDescription
);
1017 } catch (Exception e
) {
1019 logger
.warn("Import of CodedDescription " + j
+ " failed.");
1023 if ((++j
% modCount
) == 0){ logger
.info("CodedDescriptions handled: " + j
);}
1030 // imports the persons associated with the dataset creation, modification, related publications
1031 protected void importAgents(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1033 logger
.info("start Agents ...");
1034 Element elAgents
= elDataset
.getChild("Agents",sddNamespace
);
1037 List
<Element
> listAgents
= elAgents
.getChildren("Agent", sddNamespace
);
1040 for (Element elAgent
: listAgents
){
1044 String idA
= elAgent
.getAttributeValue("id");
1047 // <Label>Kevin Thiele</Label>
1048 // <Detail role="Description">Ali Baba is also known as r.a.m.</Detail>
1049 // </Representation>
1050 Person person
= Person
.NewInstance();
1051 importRepresentation(elAgent
, sddNamespace
, person
, idA
, sddConfig
);
1052 person
.addSource(OriginalSource
.NewInstance(idA
, "Agent"));
1055 Element elLinks
= elAgent
.getChild("Links",sddNamespace
);
1057 if (elLinks
!= null) {
1059 // <Link rel="Alternate" href="http://www.diversitycampus.net/people/hagedorn"/>
1060 List
<Element
> listLinks
= elLinks
.getChildren("Link", sddNamespace
);
1063 for (Element elLink
: listLinks
){
1067 String rel
= elLink
.getAttributeValue("rel");
1068 String href
= elLink
.getAttributeValue("href");
1070 Media link
= Media
.NewInstance();
1071 MediaRepresentation mr
= MediaRepresentation
.NewInstance();
1072 mr
.addRepresentationPart(MediaRepresentationPart
.NewInstance(href
, null));
1073 link
.addRepresentation(mr
);
1074 person
.addMedia(link
);
1076 } catch (Exception e
) {
1078 logger
.warn("Import of Link " + k
+ " failed.");
1082 if ((++k
% modCount
) == 0){ logger
.info("Links handled: " + k
);}
1086 if (authors
.containsKey(idA
)) {
1087 authors
.put(idA
,person
);
1090 if (editors
.containsKey(idA
)) {
1091 editors
.put(idA
, person
);
1094 } catch (Exception e
) {
1096 logger
.warn("Import of Agent " + j
+ " failed.");
1100 if ((++j
% modCount
) == 0){ logger
.info("Agents handled: " + j
);}
1105 // imports publications related with the data set
1106 protected void importPublications(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1108 logger
.info("start Publications ...");
1109 Element elPublications
= elDataset
.getChild("Publications",sddNamespace
);
1111 if (elPublications
!= null) {
1112 // <Publication id="p1">
1113 List
<Element
> listPublications
= elPublications
.getChildren("Publication", sddNamespace
);
1115 //for each Publication
1116 for (Element elPublication
: listPublications
){
1120 String idP
= elPublication
.getAttributeValue("id");
1123 // <Label>Sample Citation</Label>
1124 // </Representation>
1125 Article publication
= Article
.NewInstance();
1126 importRepresentation(elPublication
, sddNamespace
, publication
, idP
, sddConfig
);
1128 publications
.put(idP
,publication
);
1130 } catch (Exception e
) {
1132 logger
.warn("Import of Publication " + j
+ " failed.");
1136 if ((++j
% modCount
) == 0){ logger
.info("Publications handled: " + j
);}
1142 // imports media objects such as images
1143 protected void importMediaObjects(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1145 logger
.info("start MediaObjects ...");
1146 Element elMediaObjects
= elDataset
.getChild("MediaObjects",sddNamespace
);
1148 if (elMediaObjects
!= null) {
1149 // <MediaObject id="m1">
1150 List
<Element
> listMediaObjects
= elMediaObjects
.getChildren("MediaObject", sddNamespace
);
1152 //for each Publication
1153 for (Element elMO
: listMediaObjects
){
1159 String idMO
= elMO
.getAttributeValue("id");
1163 // <Label>Image description, e.g. to be used for alt-attribute in html.</Label>
1164 // </Representation>
1165 Media media
= Media
.NewInstance();
1166 importRepresentation(elMO
, sddNamespace
, media
, idMO
, sddConfig
);
1168 // <Type>Image</Type>
1169 // <Source href="http://test.edu/test.jpg"/>
1170 String type
= (String
)ImportHelper
.getXmlInputValue(elMO
,"Type",sddNamespace
);
1172 if ((type
!= null) && (type
.equals("Image"))) {
1173 Element elSource
= elMO
.getChild("Source",sddNamespace
);
1174 String href
= elSource
.getAttributeValue("href");
1176 ImageMetaData imageMetaData
= new ImageMetaData();
1177 ImageFile image
= null;
1179 if (href
.substring(0,7).equals("http://")) {
1181 URL url
= new URL(href
);
1182 imageMetaData
.readFrom(url
);
1183 image
= ImageFile
.NewInstance(url
.toString(), null, imageMetaData
);
1184 } catch (MalformedURLException e
) {
1185 logger
.error("Malformed URL", e
);
1188 String sns
= sddConfig
.getSourceNameString();
1189 File f
= new File(sns
);
1190 File parent
= f
.getParentFile();
1191 String fi
= parent
.toString() + File
.separator
+ href
;
1192 File file
= new File(fi
);
1193 imageMetaData
.readFrom(file
);
1194 image
= ImageFile
.NewInstance(file
.toString(), null, imageMetaData
);
1197 MediaRepresentation representation
= MediaRepresentation
.NewInstance(imageMetaData
.getMimeType(), null);
1198 representation
.addRepresentationPart(image
);
1200 media
.addRepresentation(representation
);
1202 ArrayList
<CdmBase
> lcb
= (ArrayList
<CdmBase
>) mediaObject_ListCdmBase
.get(idMO
);
1204 for (int k
= 0; k
< lcb
.size(); k
++) {
1205 if (lcb
.get(k
) instanceof DefinedTermBase
) {
1206 DefinedTermBase dtb
= (DefinedTermBase
) lcb
.get(k
);
1207 // if (lcb.get(0) instanceof DefinedTermBase) {
1208 // DefinedTermBase dtb = (DefinedTermBase) lcb.get(0);
1211 dtb
.addMedia(media
);
1213 // Media me = (Media) media.clone();
1214 // dtb.addMedia(me);
1217 } else if (lcb
.get(k
) instanceof ReferenceBase
) {
1218 ReferenceBase rb
= (ReferenceBase
) lcb
.get(k
);
1219 //} else if (lcb.get(0) instanceof ReferenceBase) {
1220 //ReferenceBase rb = (ReferenceBase) lcb.get(0);
1221 // rb.setTitleCache(label);
1226 // Media me = (Media) media.clone();
1235 } catch (Exception e
) {
1237 logger
.warn("Could not attached MediaObject " + j
+ "(SDD: " + id
+ ") to several objects.");
1241 if ((++j
% modCount
) == 0){ logger
.info("MediaObjects handled: " + j
);
1248 // imports the <DescriptiveConcepts> block
1249 protected void importDescriptiveConcepts(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
1250 // <DescriptiveConcepts>
1251 logger
.info("start DescriptiveConcepts ...");
1252 Element elDescriptiveConcepts
= elDataset
.getChild("DescriptiveConcepts",sddNamespace
);
1253 // <DescriptiveConcept id="b">
1254 if (elDescriptiveConcepts
!= null) {
1255 List
<Element
> listDescriptiveConcepts
= elDescriptiveConcepts
.getChildren("DescriptiveConcept", sddNamespace
);
1257 //for each DescriptiveConcept
1259 for (Element elDescriptiveConcept
: listDescriptiveConcepts
){
1261 String id
= elDescriptiveConcept
.getAttributeValue("id");
1262 String uri
= elDescriptiveConcept
.getAttributeValue("uri");
1264 FeatureNode fn
= null;
1266 if (!id
.equals("")) {
1267 fn
= FeatureNode
.NewInstance();
1268 Feature feature
= Feature
.NewInstance();
1270 // <Label>Body</Label>
1271 importRepresentation(elDescriptiveConcept
, sddNamespace
, feature
, id
, sddConfig
);
1272 features
.put("g" + g
, feature
);
1274 fn
.setFeature(feature
);
1276 // TODO if an OriginalSource can be attached to a FeatureNode or a Feature
1277 // OriginalSource source = null;
1278 // if (uri != null) {
1279 // if (!uri.equals("")) {
1280 // source = OriginalSource.NewInstance(id, "DescriptiveConcept", Generic.NewInstance(), uri);
1283 // source = OriginalSource.NewInstance(id, "DescriptiveConcept");
1285 // fn.addSource(source);
1287 featureNodes
.put(id
,fn
);
1290 if ((++j
% modCount
) == 0){ logger
.info("DescriptiveConcepts handled: " + j
);}
1296 // imports the descriptions of taxa (specimens TODO)
1297 protected void importCharacterTrees(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1299 logger
.info("start CharacterTrees ...");
1300 Element elCharacterTrees
= elDataset
.getChild("CharacterTrees",sddNamespace
);
1304 if (elCharacterTrees
!= null) {
1305 List
<Element
> listCharacterTrees
= elCharacterTrees
.getChildren("CharacterTree", sddNamespace
);
1307 //for each CharacterTree
1309 for (Element elCharacterTree
: listCharacterTrees
){
1312 Element elRepresentation
= elCharacterTree
.getChild("Representation",sddNamespace
);
1313 String label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
,"Label",sddNamespace
);
1314 Element elDesignedFor
= elCharacterTree
.getChild("DesignedFor",sddNamespace
);
1315 List
<Element
> listRoles
= elDesignedFor
.getChildren("Role",sddNamespace
);
1316 boolean isgroups
= false;
1318 for (Element elRole
: listRoles
){
1319 if (elRole
.getText().equals("Filtering")) {
1324 if ((label
.contains("group")) || (isgroups
)) {
1326 FeatureTree groups
= FeatureTree
.NewInstance();
1327 importRepresentation(elCharacterTree
, sddNamespace
, groups
, "", sddConfig
);
1328 FeatureNode root
= groups
.getRoot();
1330 Element elNodes
= elCharacterTree
.getChild("Nodes", sddNamespace
);
1331 List
<Element
> listNodes
= elNodes
.getChildren("Node", sddNamespace
);
1332 for (Element elNode
: listNodes
){
1333 String idN
= elNode
.getAttributeValue("id");
1334 FeatureNode fn
= null;
1335 if (!idN
.equals("")) {
1336 Element elDescriptiveConcept
= elNode
.getChild("DescriptiveConcept", sddNamespace
);
1337 String refDC
= elDescriptiveConcept
.getAttributeValue("ref");
1338 fn
= featureNodes
.get(refDC
);
1344 List
<Element
> listCharNodes
= elNodes
.getChildren("CharNode", sddNamespace
);
1345 for (Element elCharNode
: listCharNodes
){
1346 Element elParent
= elCharNode
.getChild("Parent", sddNamespace
);
1347 String refP
= elParent
.getAttributeValue("ref");
1348 Element elCharacter
= elCharNode
.getChild("Character", sddNamespace
);
1349 String refC
= elCharacter
.getAttributeValue("ref");
1350 FeatureNode fn
= FeatureNode
.NewInstance();
1351 if (!refP
.equals("")) {
1352 FeatureNode parent
= nodes
.get(refP
);
1353 parent
.addChild(fn
);
1354 Feature character
= features
.get(refC
);
1355 fn
.setFeature(character
);
1356 // if method setParent() in FeatureNode becomes visible
1357 // fn.setParent(parent);
1359 nodes
.put(refC
, fn
);
1361 featureTrees
.add(groups
);
1364 } catch (Exception e
) {
1366 logger
.warn("Import of Character tree " + j
+ " failed.");
1370 if ((++j
% modCount
) == 0){ logger
.info("CharacterTrees handled: " + j
);}