1 package eu
.etaxonomy
.cdm
.io
.sdd
;
3 import java
.text
.SimpleDateFormat
;
5 import java
.util
.GregorianCalendar
;
6 import java
.util
.HashMap
;
7 import java
.util
.HashSet
;
8 import java
.util
.Iterator
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.jdom
.Element
;
15 import org
.jdom
.Namespace
;
16 import org
.joda
.time
.DateTime
;
17 import org
.springframework
.transaction
.TransactionStatus
;
19 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
20 import eu
.etaxonomy
.cdm
.api
.service
.IReferenceService
;
21 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
22 import eu
.etaxonomy
.cdm
.io
.common
.ICdmIO
;
23 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
24 import eu
.etaxonomy
.cdm
.io
.common
.ImportHelper
;
25 import eu
.etaxonomy
.cdm
.io
.common
.MapWrapper
;
26 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
27 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
28 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
29 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
30 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
31 import eu
.etaxonomy
.cdm
.model
.common
.MultilanguageText
;
32 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSource
;
33 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
34 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
35 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
36 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
37 import eu
.etaxonomy
.cdm
.model
.description
.MeasurementUnit
;
38 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
39 import eu
.etaxonomy
.cdm
.model
.description
.State
;
40 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasure
;
41 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasurementValue
;
42 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
43 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
44 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
45 import eu
.etaxonomy
.cdm
.model
.media
.Rights
;
46 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
47 import eu
.etaxonomy
.cdm
.model
.reference
.Article
;
48 import eu
.etaxonomy
.cdm
.model
.reference
.Database
;
49 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
50 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
53 public class SDDDescriptionIO
extends SDDIoBase
implements ICdmIO
{
54 private static final Logger logger
= Logger
.getLogger(SDDDescriptionIO
.class);
56 private static int modCount
= 1000;
58 public SDDDescriptionIO(){
63 public boolean doCheck(IImportConfigurator config
){
64 boolean result
= true;
65 logger
.warn("No check implemented for SDD");
70 public boolean doInvoke(IImportConfigurator config
, Map
<String
, MapWrapper
<?
extends CdmBase
>> stores
){
73 logger
.info("start Datasets ...");
74 SDDImportConfigurator sddConfig
= (SDDImportConfigurator
)config
;
76 // <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">
77 Element root
= sddConfig
.getSourceRoot();
78 boolean success
=true;
80 Namespace sddNamespace
= sddConfig
.getSddNamespace();
81 Namespace xmlNamespace
= Namespace
.getNamespace("xml","http://www.w3.org/XML/1998/namespace");
83 logger
.info("start TechnicalMetadata ...");
84 // <TechnicalMetadata created="2006-04-20T10:00:00">
85 Element elTechnicalMetadata
= root
.getChild("TechnicalMetadata", sddNamespace
);
86 String nameCreated
= elTechnicalMetadata
.getAttributeValue("created");
87 ReferenceBase sourceReference
= config
.getSourceReference();
88 ReferenceBase sec
= Database
.NewInstance();
89 if (nameCreated
!= null) {
90 if (!nameCreated
.equals("")) {
91 int year
= Integer
.parseInt(nameCreated
.substring(0,4));
92 int monthOfYear
= Integer
.parseInt(nameCreated
.substring(5,7));
93 int dayOfMonth
= Integer
.parseInt(nameCreated
.substring(8,10));
94 int hourOfDay
= Integer
.parseInt(nameCreated
.substring(11,13));
95 int minuteOfHour
= Integer
.parseInt(nameCreated
.substring(14,16));
96 int secondOfMinute
= Integer
.parseInt(nameCreated
.substring(17,19));
97 DateTime created
= new DateTime(year
,monthOfYear
,dayOfMonth
,hourOfDay
,minuteOfHour
,secondOfMinute
,0);
98 sourceReference
.setCreated(created
);
99 sec
.setCreated(created
);
103 // <Generator name="n/a, handcrafted instance document" version="n/a"/>
104 Element elGenerator
= elTechnicalMetadata
.getChild("Generator", sddNamespace
);
105 String generatorName
= elGenerator
.getAttributeValue("name");
106 String generatorVersion
= elGenerator
.getAttributeValue("version");
108 List
<Element
> elDatasets
= root
.getChildren("Dataset",sddNamespace
);
110 Map
<String
,TaxonDescription
> taxonDescriptions
= new HashMap
<String
,TaxonDescription
>();
111 Map
<String
,State
> states
= new HashMap
<String
,State
>();
112 Map
<String
,MeasurementUnit
> units
= new HashMap
<String
,MeasurementUnit
>();
113 Map
<String
,String
> defaultUnitPrefixes
= new HashMap
<String
,String
>();
114 Map
<String
,Feature
> features
= new HashMap
<String
,Feature
>();
115 Map
<String
,ReferenceBase
> publications
= new HashMap
<String
,ReferenceBase
>();
116 Map
<String
,Media
> mediaObjects
= new HashMap
<String
,Media
>();
118 Set
<StatisticalMeasure
> statisticalMeasures
= new HashSet
<StatisticalMeasure
>();
119 Set
<VersionableEntity
> featureData
= new HashSet
<VersionableEntity
>();
123 logger
.info("start Dataset ...");
124 for (Element elDataset
: elDatasets
){
126 // <Dataset xml:lang="en-us">
127 String nameLang
= elDataset
.getAttributeValue("lang",xmlNamespace
);
128 Language datasetLanguage
= null;
129 if (!nameLang
.equals("")) {
130 // config.getCdmAppController().getTermService().getLanguageByIso(nameLang);
131 datasetLanguage
= Language
.ENGLISH();
133 datasetLanguage
= Language
.ENGLISH();
135 if (datasetLanguage
== null) {
136 datasetLanguage
= Language
.ENGLISH();
140 <Label>The Genus Viola</Label>
141 <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>
144 logger
.info("start Representation ...");
145 Element elRepresentation
= elDataset
.getChild("Representation",sddNamespace
);
146 String label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
147 String detail
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Detail",sddNamespace
);
149 sourceReference
.setTitleCache(generatorName
+ " - " + generatorVersion
+ " - " + label
);
150 sec
.setTitleCache(generatorName
+ " - " + generatorVersion
+ " - " + label
);
152 Annotation annotation
= Annotation
.NewInstance(detail
, datasetLanguage
);
155 logger
.info("start RevisionData ...");
156 Element elRevisionData
= elDataset
.getChild("RevisionData",sddNamespace
);
159 Element elCreators
= elRevisionData
.getChild("Creators",sddNamespace
);
161 // <Agent role="aut" ref="a1"/>
162 List
<Element
> listAgents
= elCreators
.getChildren("Agent", sddNamespace
);
166 Map
<String
,Person
> authors
= new HashMap
<String
,Person
>();
167 Map
<String
,Person
> editors
= new HashMap
<String
,Person
>();
168 for (Element elAgent
: listAgents
){
170 String role
= elAgent
.getAttributeValue("role");
171 String ref
= elAgent
.getAttributeValue("ref");
172 if (role
.equals("aut")) {
173 if(!ref
.equals("")) {
174 authors
.put(ref
, null);
177 if (role
.equals("edt")) {
178 if(!ref
.equals("")) {
179 editors
.put(ref
, null);
183 if ((++j
% modCount
) == 0){ logger
.info("Agents handled: " + j
);}
187 // <DateModified>2006-04-08T00:00:00</DateModified>
188 String stringDateModified
= (String
)ImportHelper
.getXmlInputValue(elRevisionData
, "DateModified",sddNamespace
);
190 if (stringDateModified
!= null) {
191 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
194 d
= sdf
.parse(stringDateModified
);
195 } catch(Exception e
) {
196 System
.err
.println("Exception :");
200 GregorianCalendar updated
= null;
202 updated
= new java
.util
.GregorianCalendar();
204 sourceReference
.setUpdated(updated
);
205 sec
.setUpdated(updated
);
210 logger
.info("start IPRStatements ...");
211 Element elIPRStatements
= elDataset
.getChild("IPRStatements",sddNamespace
);
212 // <IPRStatement role="Copyright">
213 Rights copyright
= null;
214 if (elIPRStatements
!= null) {
215 List
<Element
> listIPRStatements
= elIPRStatements
.getChildren("IPRStatement", sddNamespace
);
217 //for each IPRStatement
219 for (Element elIPRStatement
: listIPRStatements
){
221 String role
= elIPRStatement
.getAttributeValue("role");
222 // <Label xml:lang="en-au">(c) 2003-2006 Centre for Occasional Botany.</Label>
223 Element elLabel
= elIPRStatement
.getChild("Label",sddNamespace
);
225 if (elLabel
!= null) {
226 lang
= elLabel
.getAttributeValue("lang",xmlNamespace
);
228 label
= (String
)ImportHelper
.getXmlInputValue(elIPRStatement
, "Label",sddNamespace
);
230 if (role
.equals("Copyright")) {
231 Language iprLanguage
= null;
233 if (!lang
.equals("")) {
234 //iprLanguage = termService.getLanguageByIso(nameLang);
235 iprLanguage
= datasetLanguage
;
237 iprLanguage
= datasetLanguage
;
240 if (iprLanguage
== null) {
241 iprLanguage
= datasetLanguage
;
243 copyright
= Rights
.NewInstance(label
, iprLanguage
);
246 if (copyright
!= null) {
247 sourceReference
.addRights(copyright
);
248 sec
.addRights(copyright
);
251 if ((++j
% modCount
) == 0){ logger
.info("IPRStatements handled: " + j
);}
257 logger
.info("start TaxonNames ...");
258 Element elTaxonNames
= elDataset
.getChild("TaxonNames",sddNamespace
);
259 // <TaxonName id="t1" uri="urn:lsid:authority:namespace:my-own-id">
260 Map
<String
,NonViralName
> taxonNameBases
= new HashMap
<String
,NonViralName
>();
261 if (elTaxonNames
!= null) {
262 List
<Element
> listTaxonNames
= elTaxonNames
.getChildren("TaxonName", sddNamespace
);
265 for (Element elTaxonName
: listTaxonNames
){
267 String id
= elTaxonName
.getAttributeValue("id");
268 String uri
= elTaxonName
.getAttributeValue("uri");
270 elRepresentation
= elTaxonName
.getChild("Representation",sddNamespace
);
271 // <Label xml:lang="la">Viola hederacea Labill.</Label>
272 Element elLabel
= elRepresentation
.getChild("Label",sddNamespace
);
273 String lang
= elLabel
.getAttributeValue("lang",xmlNamespace
);
274 label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
275 NonViralName tnb
= NonViralName
.NewInstance(null);
276 if ((lang
!= null) && (!lang
.equals("la"))) {
277 logger
.info("TaxonName " + j
+ " is not specified as a latin name.");
279 tnb
.setTitleCache(label
);
280 OriginalSource source
= OriginalSource
.NewInstance(id
, "TaxonName");
281 tnb
.addSource(source
);
282 if (!id
.equals("")) {
283 taxonNameBases
.put(id
,tnb
);
286 if ((++j
% modCount
) == 0){ logger
.info("TaxonNames handled: " + j
);}
292 logger
.info("start Characters ...");
293 Element elCharacters
= elDataset
.getChild("Characters", sddNamespace
);
295 // <CategoricalCharacter id="c1">
296 if (elCharacters
!= null) {
297 List
<Element
> elCategoricalCharacters
= elCharacters
.getChildren("CategoricalCharacter", sddNamespace
);
299 //for each CategoricalCharacter
300 for (Element elCategoricalCharacter
: elCategoricalCharacters
){
304 String idCC
= elCategoricalCharacter
.getAttributeValue("id");
307 // <Label> Leaf complexity</Label>
309 elRepresentation
= elCategoricalCharacter
.getChild("Representation",sddNamespace
);
310 label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
312 Feature categoricalCharacter
= null;
314 categoricalCharacter
= Feature
.NewInstance(label
, label
, label
);
316 categoricalCharacter
.setSupportsQuantitativeData(false);
317 categoricalCharacter
.setSupportsTextData(true);
320 Element elStates
= elCategoricalCharacter
.getChild("States",sddNamespace
);
322 // <StateDefinition id="s1">
323 List
<Element
> elStateDefinitions
= elStates
.getChildren("StateDefinition",sddNamespace
);
324 TermVocabulary
<State
> termVocabularyState
= new TermVocabulary
<State
>();
327 //for each StateDefinition
328 for (Element elStateDefinition
: elStateDefinitions
){
330 if ((++k
% modCount
) == 0){ logger
.info("StateDefinitions handled: " + (k
-1));}
332 String idSD
= elStateDefinition
.getAttributeValue("id");
334 // <Label>Simple</Label>
336 elRepresentation
= elStateDefinition
.getChild("Representation",sddNamespace
);
337 label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
338 State state
= new State(label
,label
,label
);
339 states
.put(idSD
, state
);
340 termVocabularyState
.addTerm(state
);
343 categoricalCharacter
.addSupportedCategoricalEnumeration(termVocabularyState
);
344 features
.put(idCC
, categoricalCharacter
);
346 } catch (Exception e
) {
348 logger
.warn("Import of CategoricalCharacter " + j
+ " failed.");
352 if ((++j
% modCount
) == 0){ logger
.info("CategoricalCharacters handled: " + j
);}
356 // <QuantitativeCharacter id="c2">
357 List
<Element
> elQuantitativeCharacters
= elCharacters
.getChildren("QuantitativeCharacter", sddNamespace
);
359 //for each QuantitativeCharacter
360 for (Element elQuantitativeCharacter
: elQuantitativeCharacters
){
364 String idQC
= elQuantitativeCharacter
.getAttributeValue("id");
367 // <Label>Leaf length</Label>
369 elRepresentation
= elQuantitativeCharacter
.getChild("Representation",sddNamespace
);
370 label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
372 Feature quantitativeCharacter
= Feature
.NewInstance();
374 if (!label
.equals("")){
375 quantitativeCharacter
= Feature
.NewInstance(label
, label
, label
);
377 quantitativeCharacter
.setSupportsQuantitativeData(true);
378 quantitativeCharacter
.setSupportsTextData(false);
381 // <Label role="Abbrev">m</Label>
382 // </MeasurementUnit>
383 Element elMeasurementUnit
= elQuantitativeCharacter
.getChild("MeasurementUnit",sddNamespace
);
386 if (elMeasurementUnit
!= null) {
387 Element elLabel
= elMeasurementUnit
.getChild("Label",sddNamespace
);
388 role
= elLabel
.getAttributeValue("role");
389 label
= (String
)ImportHelper
.getXmlInputValue(elMeasurementUnit
, "Label",sddNamespace
);
392 MeasurementUnit unit
= null;
393 if (!label
.equals("")){
395 if (role
.equals("Abbrev")){
396 unit
= MeasurementUnit
.NewInstance(label
,label
,label
);
399 unit
= MeasurementUnit
.NewInstance(label
,label
,label
);
404 units
.put(idQC
, unit
);
408 // <MeasurementUnitPrefix>milli</MeasurementUnitPrefix>
410 Element elDefault
= elQuantitativeCharacter
.getChild("Default",sddNamespace
);
411 if (elDefault
!= null) {
412 String measurementUnitPrefix
= (String
)ImportHelper
.getXmlInputValue(elDefault
, "MeasurementUnitPrefix",sddNamespace
);
413 if (!measurementUnitPrefix
.equals("")){
414 defaultUnitPrefixes
.put(idQC
, measurementUnitPrefix
);
418 features
.put(idQC
, quantitativeCharacter
);
420 } catch (Exception e
) {
422 logger
.warn("Import of QuantitativeCharacter " + j
+ " failed.");
426 if ((++j
% modCount
) == 0){ logger
.info("QuantitativeCharacters handled: " + j
);}
430 // <TextCharacter id="c3">
431 List
<Element
> elTextCharacters
= elCharacters
.getChildren("TextCharacter", sddNamespace
);
433 //for each TextCharacter
434 for (Element elTextCharacter
: elTextCharacters
){
438 String idTC
= elTextCharacter
.getAttributeValue("id");
441 // <Label xml:lang="en">Leaf features not covered by other characters</Label>
443 elRepresentation
= elTextCharacter
.getChild("Representation",sddNamespace
);
444 Element elLabel
= elRepresentation
.getChild("Label",sddNamespace
);
445 nameLang
= elLabel
.getAttributeValue("lang",xmlNamespace
);
446 Language language
= null;
447 if (nameLang
!= null) {
448 if (!nameLang
.equals("")) {
449 // language = termService.getLanguageByIso(nameLang);
450 language
= datasetLanguage
;
452 language
= datasetLanguage
;
455 language
= datasetLanguage
;
458 label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
460 Feature textCharacter
= Feature
.NewInstance();
463 if (!label
.equals("")){
464 textCharacter
= Feature
.NewInstance(label
, label
, label
);
465 textCharacter
.setLabel(label
, language
);
469 textCharacter
.setSupportsQuantitativeData(false);
470 textCharacter
.setSupportsTextData(true);
472 features
.put(idTC
, textCharacter
);
474 } catch (Exception e
) {
476 logger
.warn("Import of TextCharacter " + j
+ " failed.");
480 if ((++j
% modCount
) == 0){ logger
.info("TextCharacters handled: " + j
);}
486 // <CodedDescriptions>
487 logger
.info("start CodedDescriptions ...");
488 Element elCodedDescriptions
= elDataset
.getChild("CodedDescriptions",sddNamespace
);
490 // <CodedDescription id="D101">
492 Map
<String
,String
> citations
= new HashMap
<String
,String
>();
493 Map
<String
,String
> locations
= new HashMap
<String
,String
>();
495 if (elCodedDescriptions
!= null) {
496 List
<Element
> listCodedDescriptions
= elCodedDescriptions
.getChildren("CodedDescription", sddNamespace
);
498 //for each CodedDescription
500 for (Element elCodedDescription
: listCodedDescriptions
){
504 String idCD
= elCodedDescription
.getAttributeValue("id");
507 // <Label><i>Viola hederacea</i> Labill. as revised by R. Morris April 8, 2006</Label>
509 elRepresentation
= elCodedDescription
.getChild("Representation",sddNamespace
);
510 Element elLabel
= elRepresentation
.getChild("Label",sddNamespace
);
511 label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
513 TaxonDescription taxonDescription
= TaxonDescription
.NewInstance();
514 taxonDescription
.setTitleCache(label
);
515 OriginalSource source
= OriginalSource
.NewInstance(idCD
, "CodedDescription");
516 taxonDescription
.addSource(source
);
519 // <TaxonName ref="t1"/>
520 // <Citation ref="p1" location="p. 30"/>
522 Element elScope
= elCodedDescription
.getChild("Scope",sddNamespace
);
525 if (elScope
!= null) {
526 Element elTaxonName
= elScope
.getChild("TaxonName",sddNamespace
);
527 ref
= elTaxonName
.getAttributeValue("ref");
529 NonViralName taxonNameBase
= taxonNameBases
.get(ref
);
530 taxon
= Taxon
.NewInstance(taxonNameBase
, sec
);
533 String refCitation
= "";
534 String location
= "";
536 if (elScope
!= null) {
537 Element elCitation
= elScope
.getChild("Citation",sddNamespace
);
538 if (elCitation
!= null) {
539 refCitation
= elCitation
.getAttributeValue("ref");
540 location
= elCitation
.getAttributeValue("location");
545 Element elSummaryData
= elCodedDescription
.getChild("SummaryData",sddNamespace
);
547 if (elSummaryData
!= null) {
549 // <Categorical ref="c4">
550 List
<Element
> elCategoricals
= elSummaryData
.getChildren("Categorical", sddNamespace
);
552 //for each Categorical
553 for (Element elCategorical
: elCategoricals
){
554 if ((++k
% modCount
) == 0){ logger
.info("Categorical handled: " + (k
-1));}
555 ref
= elCategorical
.getAttributeValue("ref");
556 Feature feature
= features
.get(ref
);
557 CategoricalData categoricalData
= CategoricalData
.NewInstance();
558 categoricalData
.setFeature(feature
);
561 List
<Element
> elStates
= elCategorical
.getChildren("State", sddNamespace
);
564 for (Element elState
: elStates
){
565 if ((++l
% modCount
) == 0){ logger
.info("States handled: " + (l
-1));}
566 ref
= elState
.getAttributeValue("ref");
567 State state
= states
.get(ref
);
568 categoricalData
.addState(state
);
570 taxonDescription
.addElement(categoricalData
);
573 // <Quantitative ref="c2">
574 List
<Element
> elQuantitatives
= elSummaryData
.getChildren("Quantitative", sddNamespace
);
576 //for each Quantitative
577 for (Element elQuantitative
: elQuantitatives
){
578 if ((++k
% modCount
) == 0){ logger
.info("Quantitative handled: " + (k
-1));}
579 ref
= elQuantitative
.getAttributeValue("ref");
580 Feature feature
= features
.get(ref
);
581 QuantitativeData quantitativeData
= QuantitativeData
.NewInstance();
582 quantitativeData
.setFeature(feature
);
584 MeasurementUnit unit
= units
.get(ref
);
585 String prefix
= defaultUnitPrefixes
.get(ref
);
587 String u
= unit
.getLabel();
588 if (prefix
!= null) {
592 quantitativeData
.setUnit(unit
);
595 // <Measure type="Min" value="2.3"/>
596 List
<Element
> elMeasures
= elQuantitative
.getChildren("Measure", sddNamespace
);
599 for (Element elMeasure
: elMeasures
){
600 if ((++l
% modCount
) == 0){ logger
.info("States handled: " + (l
-1));}
601 String type
= elMeasure
.getAttributeValue("type");
602 value
= elMeasure
.getAttributeValue("value");
603 float v
= Float
.parseFloat(value
);
604 StatisticalMeasure t
= null;
605 if (type
.equals("Min")) {
606 t
= StatisticalMeasure
.MIN();
607 } else if (type
.equals("Mean")) {
608 t
= StatisticalMeasure
.AVERAGE();
609 } else if (type
.equals("Max")) {
610 t
= StatisticalMeasure
.MAX();
611 } else if (type
.equals("SD")) {
612 // Create a new StatisticalMeasure for standard deviation
613 t
= StatisticalMeasure
.STANDARD_DEVIATION();
614 } else if (type
.equals("N")) {
615 t
= StatisticalMeasure
.SAMPLE_SIZE();
617 t
= StatisticalMeasure
.NewInstance(type
,type
,type
);
618 statisticalMeasures
.add(t
);
621 StatisticalMeasurementValue statisticalValue
= StatisticalMeasurementValue
.NewInstance();
622 statisticalValue
.setValue(v
);
623 statisticalValue
.setType(t
);
624 quantitativeData
.addStatisticalValue(statisticalValue
);
625 featureData
.add(statisticalValue
);
627 taxonDescription
.addElement(quantitativeData
);
630 // <TextChar ref="c3">
631 List
<Element
> elTextChars
= elSummaryData
.getChildren("TextChar", sddNamespace
);
634 for (Element elTextChar
: elTextChars
){
635 if ((++k
% modCount
) == 0){ logger
.info("TextChar handled: " + (k
-1));}
636 ref
= elTextChar
.getAttributeValue("ref");
637 Feature feature
= features
.get(ref
);
638 TextData textData
= TextData
.NewInstance();
639 textData
.setFeature(feature
);
641 // <Content>Free form text</Content>
642 String content
= (String
)ImportHelper
.getXmlInputValue(elTextChar
, "Content",sddNamespace
);
643 textData
.putText(content
, datasetLanguage
);
644 taxonDescription
.addElement(textData
);
650 taxon
.addDescription(taxonDescription
);
653 if (!refCitation
.equals("")){
654 citations
.put(idCD
,refCitation
);
657 if (!location
.equals("")){
658 locations
.put(idCD
, location
);
661 taxonDescriptions
.put(idCD
, taxonDescription
);
663 } catch (Exception e
) {
665 logger
.warn("Import of CodedDescription " + j
+ " failed.");
669 if ((++j
% modCount
) == 0){ logger
.info("CodedDescriptions handled: " + j
);}
676 logger
.info("start Agents ...");
677 Element elAgents
= elDataset
.getChild("Agents",sddNamespace
);
680 listAgents
= elAgents
.getChildren("Agent", sddNamespace
);
683 for (Element elAgent
: listAgents
){
687 String idA
= elAgent
.getAttributeValue("id");
690 // <Label>Kevin Thiele</Label>
691 // <Detail role="Description">Ali Baba is also known as r.a.m.</Detail>
693 elRepresentation
= elAgent
.getChild("Representation",sddNamespace
);
694 label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
695 Element elDetail
= elRepresentation
.getChild("Detail",sddNamespace
);
697 Person person
= Person
.NewTitledInstance(label
);
698 OriginalSource source
= OriginalSource
.NewInstance(idA
, "Agent");
699 person
.addSource(source
);
701 if (elDetail
!= null) {
702 String role
= elDetail
.getAttributeValue("role");
703 detail
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Detail",sddNamespace
);
704 annotation
= Annotation
.NewInstance(role
+ " - " + detail
, datasetLanguage
);
705 person
.addAnnotation(annotation
);
709 Element elLinks
= elAgent
.getChild("Links",sddNamespace
);
711 if (elLinks
!= null) {
713 // <Link rel="Alternate" href="http://www.diversitycampus.net/people/hagedorn"/>
714 List
<Element
> listLinks
= elLinks
.getChildren("Link", sddNamespace
);
717 for (Element elLink
: listLinks
){
721 String rel
= elLink
.getAttributeValue("rel");
722 String href
= elLink
.getAttributeValue("href");
725 source
= OriginalSource
.NewInstance(rel
, href
);
726 person
.addSource(source
);
729 } catch (Exception e
) {
731 logger
.warn("Import of Link " + k
+ " failed.");
735 if ((++k
% modCount
) == 0){ logger
.info("Links handled: " + k
);}
739 if (authors
.containsKey(idA
)) {
740 authors
.put(idA
,person
);
743 if (editors
.containsKey(idA
)) {
744 editors
.put(idA
, person
);
747 } catch (Exception e
) {
749 logger
.warn("Import of Agent " + j
+ " failed.");
753 if ((++j
% modCount
) == 0){ logger
.info("Agents handled: " + j
);}
758 logger
.info("start Publications ...");
759 Element elPublications
= elDataset
.getChild("Publications",sddNamespace
);
761 if (elPublications
!= null) {
762 // <Publication id="p1">
763 List
<Element
> listPublications
= elPublications
.getChildren("Publication", sddNamespace
);
765 //for each Publication
766 for (Element elPublication
: listPublications
){
770 String idP
= elPublication
.getAttributeValue("id");
773 // <Label>Sample Citation</Label>
775 elRepresentation
= elPublication
.getChild("Representation",sddNamespace
);
776 label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
777 Article publication
= Article
.NewInstance();
778 publication
.setTitle(label
);
779 OriginalSource source
= OriginalSource
.NewInstance(idP
, "Publication");
780 publication
.addSource(source
);
782 publications
.put(idP
,publication
);
784 } catch (Exception e
) {
786 logger
.warn("Import of Publication " + j
+ " failed.");
790 if ((++j
% modCount
) == 0){ logger
.info("Publications handled: " + j
);}
796 logger
.info("start MediaObjects ...");
797 Element elMediaObjects
= elDataset
.getChild("MediaObjects",sddNamespace
);
799 if (elMediaObjects
!= null) {
800 // <MediaObject id="m1">
801 List
<Element
> listMediaObjects
= elMediaObjects
.getChildren("elMediaObject", sddNamespace
);
803 //for each Publication
804 for (Element elMediaObject
: listMediaObjects
){
808 String idMO
= elMediaObject
.getAttributeValue("id");
811 // <Label>Image description, e.g. to be used for alt-attribute in html.</Label>
813 elRepresentation
= elMediaObject
.getChild("Representation",sddNamespace
);
814 label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
815 Media mediaObject
= Media
.NewInstance();
816 MultilanguageText m
= MultilanguageText
.NewInstance(LanguageString
.NewInstance(label
, datasetLanguage
));
817 mediaObject
.setTitle(m
);
818 OriginalSource source
= OriginalSource
.NewInstance(idMO
, "MediaObject");
819 // mediaObject.addSource(source);
821 mediaObjects
.put(idMO
,mediaObject
);
823 } catch (Exception e
) {
825 logger
.warn("Import of MediaObject " + j
+ " failed.");
829 if ((++j
% modCount
) == 0){ logger
.info("Publications handled: " + j
);}
835 // when several authors are supported
836 if (authors.size()>1) {
837 for (Iterator<Person> author = authors.values().iterator() ; author.hasNext() ;){
838 sourceReference.setCreatedBy(author.next());
841 Team team = Team.NewInstance();
842 for (Iterator<Person> author = authors.values().iterator() ; author.hasNext() ;){
843 team.addTeamMember(author.next());
845 sourceReference.setCreatedBy(team);
849 Iterator
<Person
> author
= authors
.values().iterator();
850 if (author
.hasNext()){
851 Person a
= author
.next();
852 sourceReference
.setCreatedBy(a
);
856 Iterator
<Person
> editor
= editors
.values().iterator();
857 if (editor
.hasNext()){
858 Person e
= editor
.next();
859 sourceReference
.setUpdatedBy(e
);
863 if (copyright
!= null) {
864 sourceReference
.addRights(copyright
);
865 sec
.addRights(copyright
);
868 for (Iterator
<String
> refCD
= taxonDescriptions
.keySet().iterator() ; refCD
.hasNext() ;){
869 String ref
= refCD
.next();
870 TaxonDescription td
= taxonDescriptions
.get(ref
);
871 if (citations
.containsKey(ref
)) {
872 Article publication
= (Article
) publications
.get(citations
.get(ref
));
873 if (locations
.containsKey(ref
)) {
874 publication
.addAnnotation(Annotation
.NewInstance(locations
.get(ref
), datasetLanguage
));
876 td
.addDescriptionSource(publication
);
880 if ((++i
% modCount
) == 0){ logger
.info("Datasets handled: " + i
);}
882 config
.setSourceReference(sourceReference
);
885 logger
.info(i
+ " Datasets handled");
887 TransactionStatus ts
= config
.getCdmAppController().startTransaction();
889 ITermService termService
= config
.getCdmAppController().getTermService();
890 for (Iterator
<State
> k
= states
.values().iterator() ; k
.hasNext() ;){
891 State state
= k
.next();
892 termService
.saveTerm(state
);
894 for (Iterator
<Feature
> k
= features
.values().iterator() ; k
.hasNext() ;){
895 Feature feature
= k
.next();
896 termService
.saveTerm(feature
);
899 for (Iterator
<MeasurementUnit
> k
= units
.values().iterator() ; k
.hasNext() ;){
900 MeasurementUnit unit
= k
.next();
902 termService
.saveTerm(unit
);
906 for (Iterator
<StatisticalMeasure
> k
= statisticalMeasures
.iterator() ; k
.hasNext() ;) {
907 StatisticalMeasure sm
= k
.next();
908 termService
.saveTerm(sm
);
911 IReferenceService referenceService
= config
.getCdmAppController().getReferenceService();
913 for (Iterator
<ReferenceBase
> k
= publications
.values().iterator() ; k
.hasNext() ;){
914 Article publication
= (Article
) k
.next();
915 referenceService
.saveReference(publication
);
918 // Returns a CdmApplicationController created by the values of this configuration.
919 IDescriptionService descriptionService
= config
.getCdmAppController().getDescriptionService();
921 for (Iterator
<TaxonDescription
> k
= taxonDescriptions
.values().iterator() ; k
.hasNext() ;){
922 TaxonDescription taxonDescription
= k
.next();
923 // Persists a Description
924 descriptionService
.saveDescription(taxonDescription
);
927 config
.getCdmAppController().commitTransaction(ts
);
929 // makeNameSpecificData(nameMap);
930 logger
.info("end makeTaxonDescriptions ...");
935 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
937 protected boolean isIgnore(IImportConfigurator config
){