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
.OriginalSource
;
31 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
32 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
33 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
34 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
35 import eu
.etaxonomy
.cdm
.model
.description
.MeasurementUnit
;
36 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
37 import eu
.etaxonomy
.cdm
.model
.description
.State
;
38 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasure
;
39 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasurementValue
;
40 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
41 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
42 import eu
.etaxonomy
.cdm
.model
.media
.Rights
;
43 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
44 import eu
.etaxonomy
.cdm
.model
.reference
.Article
;
45 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
46 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
49 public class SDDDescriptionIO
extends SDDIoBase
implements ICdmIO
{
50 private static final Logger logger
= Logger
.getLogger(SDDDescriptionIO
.class);
52 private static int modCount
= 10;
54 public SDDDescriptionIO(){
59 public boolean doCheck(IImportConfigurator config
){
60 boolean result
= true;
61 logger
.warn("No check implemented for SDD");
66 public boolean doInvoke(IImportConfigurator config
, Map
<String
, MapWrapper
<?
extends CdmBase
>> stores
){
69 logger
.info("start Datasets ...");
70 SDDImportConfigurator sddConfig
= (SDDImportConfigurator
)config
;
72 // <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">
73 Element root
= sddConfig
.getSourceRoot();
74 boolean success
=true;
76 Namespace sddNamespace
= sddConfig
.getSddNamespace();
77 Namespace xmlNamespace
= Namespace
.getNamespace("xml","http://www.w3.org/XML/1998/namespace");
79 // <TechnicalMetadata created="2006-04-20T10:00:00">
80 Element elTechnicalMetadata
= root
.getChild("TechnicalMetadata", sddNamespace
);
81 String nameCreated
= elTechnicalMetadata
.getAttributeValue("created");
82 int year
= Integer
.parseInt(nameCreated
.substring(0,4));
83 int monthOfYear
= Integer
.parseInt(nameCreated
.substring(5,7));
84 int dayOfMonth
= Integer
.parseInt(nameCreated
.substring(8,10));
85 int hourOfDay
= Integer
.parseInt(nameCreated
.substring(11,13));
86 int minuteOfHour
= Integer
.parseInt(nameCreated
.substring(14,16));
87 int secondOfMinute
= Integer
.parseInt(nameCreated
.substring(17,19));
88 DateTime created
= new DateTime(year
,monthOfYear
,dayOfMonth
,hourOfDay
,minuteOfHour
,secondOfMinute
,0);
90 GregorianCalendar updated
= null;
92 // <Generator name="n/a, handcrafted instance document" version="n/a"/>
93 Element elGenerator
= elTechnicalMetadata
.getChild("Generator", sddNamespace
);
94 String generatorName
= elGenerator
.getAttributeValue("name");
95 String generatorVersion
= elGenerator
.getAttributeValue("version");
97 List
<Element
> elDatasets
= root
.getChildren("Dataset",sddNamespace
);
99 Map
<String
,TaxonDescription
> taxonDescriptions
= new HashMap
<String
,TaxonDescription
>();
100 Map
<String
,State
> states
= new HashMap
<String
,State
>();
101 Map
<String
,MeasurementUnit
> units
= new HashMap
<String
,MeasurementUnit
>();
102 Map
<String
,String
> defaultUnitPrefixes
= new HashMap
<String
,String
>();
103 Map
<String
,Feature
> features
= new HashMap
<String
,Feature
>();
104 Map
<String
,ReferenceBase
> publications
= new HashMap
<String
,ReferenceBase
>();
106 Set
<StatisticalMeasure
> statisticalMeasures
= new HashSet
<StatisticalMeasure
>();
107 Set
<VersionableEntity
> featureData
= new HashSet
<VersionableEntity
>();
109 NonViralName taxonName
= null;
110 Taxon taxon
= Taxon
.NewInstance(taxonName
, null);
111 Rights copyright
= null;
115 for (Element elDataset
: elDatasets
){
117 if ((++i
% modCount
) == 0){ logger
.info("Datasets handled: " + (i
-1));}
119 // <Dataset xml:lang="en-us">
120 String nameLang
= elDataset
.getAttributeValue("lang",xmlNamespace
);
121 Language datasetLanguage
= Language
.NewInstance();
122 if (!nameLang
.equals("")) {
123 if(nameLang
.equals("en-us")) {
124 datasetLanguage
= Language
.ENGLISH();
126 if(nameLang
.equals("en-au")) {
127 datasetLanguage
= Language
.ENGLISH();
132 <Label>The Genus Viola</Label>
133 <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>
136 Element elRepresentation
= elDataset
.getChild("Representation",sddNamespace
);
137 String label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
138 String detail
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Detail",sddNamespace
);
140 OriginalSource originalSource
= OriginalSource
.NewInstance(" ", generatorName
+ " - " + generatorVersion
+ " - " + label
);
141 // originalSource.setCitation(citation)
142 Annotation annotation
= Annotation
.NewInstance(detail
, datasetLanguage
);
145 Element elRevisionData
= elDataset
.getChild("RevisionData",sddNamespace
);
148 Element elCreators
= elRevisionData
.getChild("Creators",sddNamespace
);
150 // <Agent role="aut" ref="a1"/>
151 List
<Element
> listAgents
= elCreators
.getChildren("Agent", sddNamespace
);
155 Map
<String
,Person
> authors
= new HashMap
<String
,Person
>();
156 Map
<String
,Person
> editors
= new HashMap
<String
,Person
>();
157 for (Element elAgent
: listAgents
){
158 if ((++j
% modCount
) == 0){ logger
.info("Agents handled: " + (j
-1));}
159 String role
= elAgent
.getAttributeValue("role");
160 String ref
= elAgent
.getAttributeValue("ref");
161 if (role
.equals("aut")) {
162 if(!ref
.equals("")) {
163 authors
.put(ref
, null);
166 if (role
.equals("edt")) {
167 if(!ref
.equals("")) {
168 editors
.put(ref
, null);
173 // <DateModified>2006-04-08T00:00:00</DateModified>
174 String stringDateModified
= (String
)ImportHelper
.getXmlInputValue(elRevisionData
, "DateModified",sddNamespace
);
176 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
179 d
= sdf
.parse(stringDateModified
);
180 } catch(Exception e
) {
181 System
.err
.println("Exception :");
185 updated
= new java
.util
.GregorianCalendar();
189 Element elIPRStatements
= elDataset
.getChild("IPRStatements",sddNamespace
);
190 // <IPRStatement role="Copyright">
191 List
<Element
> listIPRStatements
= elIPRStatements
.getChildren("IPRStatement", sddNamespace
);
193 //for each IPRStatement
194 for (Element elIPRStatement
: listIPRStatements
){
195 if ((++j
% modCount
) == 0){ logger
.info("IPRStatements handled: " + (j
-1));}
196 String role
= elIPRStatement
.getAttributeValue("role");
197 // <Label xml:lang="en-au">(c) 2003-2006 Centre for Occasional Botany.</Label>
198 Element elLabel
= elIPRStatement
.getChild("Label",sddNamespace
);
199 String lang
= elLabel
.getAttributeValue("lang",xmlNamespace
);
200 label
= (String
)ImportHelper
.getXmlInputValue(elIPRStatement
, "Label",sddNamespace
);
201 if (role
.equals("Copyright")) {
202 Language iprLanguage
= Language
.NewInstance();
203 if (!lang
.equals("")) {
204 if(lang
.equals("en-us")) {
205 iprLanguage
= Language
.ENGLISH();
207 if(lang
.equals("en-au")) {
208 iprLanguage
= Language
.ENGLISH();
211 copyright
= Rights
.NewInstance(label
, iprLanguage
);
216 Element elTaxonNames
= elDataset
.getChild("TaxonNames",sddNamespace
);
217 // <TaxonName id="t1" uri="urn:lsid:authority:namespace:my-own-id">
218 List
<Element
> listTaxonNames
= elTaxonNames
.getChildren("TaxonName", sddNamespace
);
220 Map
<String
,NonViralName
> taxonNameBases
= new HashMap
<String
,NonViralName
>();
222 for (Element elTaxonName
: listTaxonNames
){
223 if ((++j
% modCount
) == 0){ logger
.info("TaxonNames handled: " + (j
-1));}
224 String id
= elTaxonName
.getAttributeValue("id");
225 String uri
= elTaxonName
.getAttributeValue("uri");
227 elRepresentation
= elTaxonName
.getChild("Representation",sddNamespace
);
228 // <Label xml:lang="la">Viola hederacea Labill.</Label>
229 Element elLabel
= elRepresentation
.getChild("Label",sddNamespace
);
230 String lang
= elLabel
.getAttributeValue("lang",xmlNamespace
);
231 label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
232 NonViralName tnb
= NonViralName
.NewInstance(null);
233 tnb
.setCreated(created
);
234 tnb
.setUpdated(updated
);
235 if ((lang
.equals("la")) || (lang
.equals(""))) {
236 tnb
.setTitleCache(label
);
238 if (!id
.equals("")) {
239 taxonNameBases
.put(id
,tnb
);
245 Element elCharacters
= elDataset
.getChild("Characters", sddNamespace
);
247 // <CategoricalCharacter id="c1">
248 List
<Element
> elCategoricalCharacters
= elCharacters
.getChildren("CategoricalCharacter", sddNamespace
);
250 //for each CategoricalCharacter
251 for (Element elCategoricalCharacter
: elCategoricalCharacters
){
253 if ((++j
% modCount
) == 0){ logger
.info("CategoricalCharacters handled: " + (j
-1));}
257 String idCC
= elCategoricalCharacter
.getAttributeValue("id");
260 // <Label> Leaf complexity</Label>
262 elRepresentation
= elCategoricalCharacter
.getChild("Representation",sddNamespace
);
263 label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
265 Feature categoricalCharacter
= null;
267 categoricalCharacter
= Feature
.NewInstance(label
, label
, label
);
269 categoricalCharacter
.setSupportsQuantitativeData(false);
270 categoricalCharacter
.setSupportsTextData(true);
273 Element elStates
= elCategoricalCharacter
.getChild("States",sddNamespace
);
275 // <StateDefinition id="s1">
276 List
<Element
> elStateDefinitions
= elStates
.getChildren("StateDefinition",sddNamespace
);
277 TermVocabulary
<State
> termVocabularyState
= new TermVocabulary
<State
>();
280 //for each StateDefinition
281 for (Element elStateDefinition
: elStateDefinitions
){
283 if ((++k
% modCount
) == 0){ logger
.info("StateDefinitions handled: " + (k
-1));}
285 String idSD
= elStateDefinition
.getAttributeValue("id");
287 // <Label>Simple</Label>
289 elRepresentation
= elStateDefinition
.getChild("Representation",sddNamespace
);
290 label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
291 State state
= new State(label
,label
,label
);
292 states
.put(idSD
, state
);
293 termVocabularyState
.addTerm(state
);
296 categoricalCharacter
.addSupportedCategoricalEnumeration(termVocabularyState
);
297 features
.put(idCC
, categoricalCharacter
);
299 } catch (Exception e
) {
301 logger
.warn("Import of CategoricalCharacter " + j
+ " failed.");
307 // <QuantitativeCharacter id="c2">
308 List
<Element
> elQuantitativeCharacters
= elCharacters
.getChildren("QuantitativeCharacter", sddNamespace
);
310 //for each QuantitativeCharacter
311 for (Element elQuantitativeCharacter
: elQuantitativeCharacters
){
313 if ((++j
% modCount
) == 0){ logger
.info("QuantitativeCharacters handled: " + (j
-1));}
317 String idQC
= elQuantitativeCharacter
.getAttributeValue("id");
320 // <Label>Leaf length</Label>
322 elRepresentation
= elQuantitativeCharacter
.getChild("Representation",sddNamespace
);
323 label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
325 Feature quantitativeCharacter
= Feature
.NewInstance();
327 if (!label
.equals("")){
328 quantitativeCharacter
= Feature
.NewInstance(label
, label
, label
);
330 quantitativeCharacter
.setSupportsQuantitativeData(true);
331 quantitativeCharacter
.setSupportsTextData(false);
334 // <Label role="Abbrev">m</Label>
335 // </MeasurementUnit>
336 Element elMeasurementUnit
= elQuantitativeCharacter
.getChild("MeasurementUnit",sddNamespace
);
337 Element elLabel
= elMeasurementUnit
.getChild("Label",sddNamespace
);
338 String role
= elLabel
.getAttributeValue("role");
339 label
= (String
)ImportHelper
.getXmlInputValue(elMeasurementUnit
, "Label",sddNamespace
);
341 MeasurementUnit unit
= null;
342 if (!label
.equals("")){
343 if (role
.equals("Abbrev")){
344 unit
= MeasurementUnit
.NewInstance(label
,label
,label
);
346 unit
= MeasurementUnit
.NewInstance(label
,label
,label
);
350 units
.put(idQC
, unit
);
353 // <MeasurementUnitPrefix>milli</MeasurementUnitPrefix>
355 Element elDefault
= elQuantitativeCharacter
.getChild("Default",sddNamespace
);
356 String measurementUnitPrefix
= (String
)ImportHelper
.getXmlInputValue(elDefault
, "MeasurementUnitPrefix",sddNamespace
);
357 if (!measurementUnitPrefix
.equals("")){
358 defaultUnitPrefixes
.put(idQC
, measurementUnitPrefix
);
361 features
.put(idQC
, quantitativeCharacter
);
363 } catch (Exception e
) {
365 logger
.warn("Import of QuantitativeCharacter " + j
+ " failed.");
371 // <TextCharacter id="c3">
372 List
<Element
> elTextCharacters
= elCharacters
.getChildren("TextCharacter", sddNamespace
);
374 //for each TextCharacter
375 for (Element elTextCharacter
: elTextCharacters
){
377 if ((++j
% modCount
) == 0){ logger
.info("TextCharacters handled: " + (j
-1));}
381 String idTC
= elTextCharacter
.getAttributeValue("id");
384 // <Label xml:lang="en">Leaf features not covered by other characters</Label>
386 elRepresentation
= elTextCharacter
.getChild("Representation",sddNamespace
);
387 Element elLabel
= elRepresentation
.getChild("Label",sddNamespace
);
388 nameLang
= elLabel
.getAttributeValue("lang",xmlNamespace
);
389 Language language
= Language
.NewInstance();
390 if (!nameLang
.equals("")) {
391 if(nameLang
.equals("en")) {
392 language
= Language
.ENGLISH();
395 label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
397 Feature textCharacter
= Feature
.NewInstance();
399 if (!idTC
.equals("")){
400 textCharacter
= Feature
.NewInstance(label
, label
, label
);
402 textCharacter
.setSupportsQuantitativeData(false);
403 textCharacter
.setSupportsTextData(true);
404 textCharacter
.setLabel(label
, language
);
406 Map
<String
,String
> textCharacters
= new HashMap
<String
,String
>();
407 Map
<String
,Language
> textCharactersLang
= new HashMap
<String
,Language
>();
408 if ((!idTC
.equals("")) && (!label
.equals(""))){
409 textCharacters
.put(idTC
, label
);
411 if (!idTC
.equals("")){
412 textCharactersLang
.put(idTC
, language
);
415 features
.put(idTC
, textCharacter
);
417 } catch (Exception e
) {
419 logger
.warn("Import of TextCharacter " + j
+ " failed.");
425 // <CodedDescriptions>
426 Element elCodedDescriptions
= elDataset
.getChild("CodedDescriptions",sddNamespace
);
428 // <CodedDescription id="D101">
429 List
<Element
> listCodedDescriptions
= elCodedDescriptions
.getChildren("CodedDescription", sddNamespace
);
431 //for each CodedDescription
432 Map
<String
,String
> citations
= new HashMap
<String
,String
>();
433 Map
<String
,String
> locations
= new HashMap
<String
,String
>();
434 for (Element elCodedDescription
: listCodedDescriptions
){
436 if ((++j
% modCount
) == 0){ logger
.info("CodedDescriptions handled: " + (j
-1));}
440 String idCD
= elCodedDescription
.getAttributeValue("id");
443 // <Label><i>Viola hederacea</i> Labill. as revised by R. Morris April 8, 2006</Label>
445 elRepresentation
= elCodedDescription
.getChild("Representation",sddNamespace
);
446 Element elLabel
= elRepresentation
.getChild("Label",sddNamespace
);
447 label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
449 TaxonDescription taxonDescription
= TaxonDescription
.NewInstance();
450 taxonDescription
.setTitleCache(label
);
453 // <TaxonName ref="t1"/>
454 // <Citation ref="p1" location="p. 30"/>
456 Element elScope
= elCodedDescription
.getChild("Scope",sddNamespace
);
457 Element elTaxonName
= elScope
.getChild("TaxonName",sddNamespace
);
458 String ref
= elTaxonName
.getAttributeValue("ref");
460 NonViralName taxonNameBase
= taxonNameBases
.get(ref
);
461 taxon
= Taxon
.NewInstance(taxonNameBase
, null);
462 taxon
.setCreated(created
);
463 taxon
.setUpdated(updated
);
465 Element elCitation
= elScope
.getChild("Citation",sddNamespace
);
466 String refCitation
= elCitation
.getAttributeValue("ref");
467 String location
= elCitation
.getAttributeValue("location");
470 Element elSummaryData
= elCodedDescription
.getChild("SummaryData",sddNamespace
);
472 // <Categorical ref="c4">
473 List
<Element
> elCategoricals
= elSummaryData
.getChildren("Categorical", sddNamespace
);
475 //for each Categorical
476 for (Element elCategorical
: elCategoricals
){
477 if ((++k
% modCount
) == 0){ logger
.info("Categorical handled: " + (k
-1));}
478 ref
= elCategorical
.getAttributeValue("ref");
479 Feature feature
= features
.get(ref
);
480 CategoricalData categoricalData
= CategoricalData
.NewInstance();
481 categoricalData
.setFeature(feature
);
484 List
<Element
> elStates
= elCategorical
.getChildren("State", sddNamespace
);
487 for (Element elState
: elStates
){
488 if ((++l
% modCount
) == 0){ logger
.info("States handled: " + (l
-1));}
489 ref
= elState
.getAttributeValue("ref");
490 State state
= states
.get(ref
);
491 categoricalData
.addState(state
);
493 taxonDescription
.addElement(categoricalData
);
496 // <Quantitative ref="c2">
497 List
<Element
> elQuantitatives
= elSummaryData
.getChildren("Quantitative", sddNamespace
);
499 //for each Quantitative
500 for (Element elQuantitative
: elQuantitatives
){
501 if ((++k
% modCount
) == 0){ logger
.info("Quantitative handled: " + (k
-1));}
502 ref
= elQuantitative
.getAttributeValue("ref");
503 Feature feature
= features
.get(ref
);
504 QuantitativeData quantitativeData
= QuantitativeData
.NewInstance();
505 quantitativeData
.setFeature(feature
);
507 MeasurementUnit unit
= units
.get(ref
);
508 String prefix
= defaultUnitPrefixes
.get(ref
);
509 String u
= unit
.getLabel();
512 quantitativeData
.setUnit(unit
);
514 // <Measure type="Min" value="2.3"/>
515 List
<Element
> elMeasures
= elQuantitative
.getChildren("Measure", sddNamespace
);
518 for (Element elMeasure
: elMeasures
){
519 if ((++l
% modCount
) == 0){ logger
.info("States handled: " + (l
-1));}
520 String type
= elMeasure
.getAttributeValue("type");
521 value
= elMeasure
.getAttributeValue("value");
522 float v
= Float
.parseFloat(value
);
523 StatisticalMeasure t
= null;
524 if (type
.equals("Min")) {
525 t
= StatisticalMeasure
.MIN();
526 } else if (type
.equals("Mean")) {
527 t
= StatisticalMeasure
.AVERAGE();
528 } else if (type
.equals("Max")) {
529 t
= StatisticalMeasure
.MAX();
530 } else if (type
.equals("SD")) {
531 // Create a new StatisticalMeasure for standard deviation
532 t
= StatisticalMeasure
.STANDARD_DEVIATION();
533 } else if (type
.equals("N")) {
534 t
= StatisticalMeasure
.SAMPLE_SIZE();
536 t
= StatisticalMeasure
.NewInstance(type
,type
,type
);
537 statisticalMeasures
.add(t
);
540 StatisticalMeasurementValue statisticalValue
= StatisticalMeasurementValue
.NewInstance();
541 statisticalValue
.setValue(v
);
542 statisticalValue
.setType(t
);
543 quantitativeData
.addStatisticalValue(statisticalValue
);
544 featureData
.add(statisticalValue
);
546 taxonDescription
.addElement(quantitativeData
);
549 // <TextChar ref="c3">
550 List
<Element
> elTextChars
= elSummaryData
.getChildren("TextChar", sddNamespace
);
553 for (Element elTextChar
: elTextChars
){
554 if ((++k
% modCount
) == 0){ logger
.info("TextChar handled: " + (k
-1));}
555 ref
= elTextChar
.getAttributeValue("ref");
556 Feature feature
= features
.get(ref
);
557 TextData textData
= TextData
.NewInstance();
558 textData
.setFeature(feature
);
560 // <Content>Free form text</Content>
561 String content
= (String
)ImportHelper
.getXmlInputValue(elTextChar
, "Content",sddNamespace
);
562 textData
.putText(content
, datasetLanguage
);
563 taxonDescription
.addElement(textData
);
566 taxonDescription
.addSource(originalSource
);
567 taxon
.addDescription(taxonDescription
);
569 if (!ref
.equals("")){
570 citations
.put(idCD
,refCitation
);
573 if (!location
.equals("")){
574 locations
.put(idCD
, location
);
577 taxonDescriptions
.put(idCD
, taxonDescription
);
579 } catch (Exception e
) {
581 logger
.warn("Import of CodedDescription " + j
+ " failed.");
588 Element elAgents
= elDataset
.getChild("Agents",sddNamespace
);
591 listAgents
= elAgents
.getChildren("Agent", sddNamespace
);
594 for (Element elAgent
: listAgents
){
596 if ((++j
% modCount
) == 0){ logger
.info("elAgent handled: " + (j
-1));}
600 String idA
= elAgent
.getAttributeValue("id");
603 // <Label>Kevin Thiele</Label>
604 // <Detail role="Description">Ali Baba is also known as r.a.m.</Detail>
606 elRepresentation
= elAgent
.getChild("Representation",sddNamespace
);
607 label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
608 Element elDetail
= elRepresentation
.getChild("Detail",sddNamespace
);
610 Person person
= Person
.NewTitledInstance(label
);
614 String role
= elDetail
.getAttributeValue("role");
615 detail
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Detail",sddNamespace
);
616 annotation
= Annotation
.NewInstance(role
+ " - " + detail
, datasetLanguage
);
617 person
.addAnnotation(annotation
);
619 person
.setCreated(created
);
620 person
.setUpdated(updated
);
624 Element elLinks
= elAgent
.getChild("Links",sddNamespace
);
626 // <Link rel="Alternate" href="http://www.diversitycampus.net/people/hagedorn"/>
627 List
<Element
> listLinks
= elLinks
.getChildren("Link", sddNamespace
);
630 for (Element elLink
: listLinks
){
632 if ((++k
% modCount
) == 0){ logger
.info("elLink handled: " + (k
-1));}
636 String rel
= elLink
.getAttributeValue("rel");
637 String href
= elLink
.getAttributeValue("href");
640 OriginalSource source
= OriginalSource
.NewInstance(rel
, href
);
641 person
.addSource(source
);
644 } catch (Exception e
) {
646 logger
.warn("Import of Link " + k
+ " failed.");
653 if (authors
.containsKey(idA
)) {
654 authors
.put(idA
,person
);
657 if (editors
.containsKey(idA
)) {
658 editors
.put(idA
, person
);
661 } catch (Exception e
) {
663 logger
.warn("Import of Agent " + j
+ " failed.");
671 Element elPublications
= elDataset
.getChild("Publications",sddNamespace
);
673 // <Publication id="p1">
674 List
<Element
> listPublications
= elPublications
.getChildren("Publication", sddNamespace
);
676 //for each Publication
677 for (Element elPublication
: listPublications
){
679 if ((++j
% modCount
) == 0){ logger
.info("elAgent handled: " + (j
-1));}
683 String idP
= elPublication
.getAttributeValue("id");
686 // <Label>Sample Citation</Label>
688 elRepresentation
= elPublication
.getChild("Representation",sddNamespace
);
689 label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
690 Article publication
= Article
.NewInstance();
691 publication
.setTitle(label
);
693 publications
.put(idP
,publication
);
695 } catch (Exception e
) {
697 logger
.warn("Import of Agent " + j
+ " failed.");
703 for (Iterator
<TaxonDescription
> taxonDescription
= taxonDescriptions
.values().iterator() ; taxonDescription
.hasNext() ;){
704 TaxonDescription td
= taxonDescription
.next();
706 if (authors.size()>1) {
707 for (Iterator<Person> author = authors.values().iterator() ; author.hasNext() ;){
708 td.setCreatedBy(author.next());
711 Team team = Team.NewInstance();
712 for (Iterator<Person> author = authors.values().iterator() ; author.hasNext() ;){
713 team.addTeamMember(author.next());
715 td.setCreatedBy(team);
719 Iterator
<Person
> author
= authors
.values().iterator();
720 if (author
.hasNext()){
721 td
.setCreatedBy(author
.next());
724 Iterator
<Person
> editor
= editors
.values().iterator();
725 if (editor
.hasNext()){
726 td
.setUpdatedBy(editor
.next());
729 if (copyright
!= null) {
730 td
.addRights(copyright
);
735 for (Iterator
<String
> refCD
= taxonDescriptions
.keySet().iterator() ; refCD
.hasNext() ;){
736 String ref
= refCD
.next();
737 TaxonDescription td
= taxonDescriptions
.get(ref
);
738 if (citations
.containsKey(ref
)) {
739 Article publication
= (Article
) publications
.get(citations
.get(ref
));
740 if (locations
.containsKey(ref
)) {
741 publication
.addAnnotation(Annotation
.NewInstance(locations
.get(ref
), datasetLanguage
));
743 td
.addDescriptionSource(publication
);
748 logger
.info(i
+ " Datasets handled");
750 ITermService termService
= config
.getCdmAppController().getTermService();
751 TransactionStatus ts
= config
.getCdmAppController().startTransaction();
752 for (Iterator
<State
> k
= states
.values().iterator() ; k
.hasNext() ;){
753 State state
= k
.next();
754 state
.setCreated(created
);
755 state
.setUpdated(updated
);
756 termService
.saveTerm(state
);
758 for (Iterator
<Feature
> k
= features
.values().iterator() ; k
.hasNext() ;){
759 Feature feature
= k
.next();
760 feature
.setCreated(created
);
761 feature
.setUpdated(updated
);
762 termService
.saveTerm(feature
);
764 for (Iterator
<MeasurementUnit
> k
= units
.values().iterator() ; k
.hasNext() ;){
765 MeasurementUnit unit
= k
.next();
766 unit
.setCreated(created
);
767 unit
.setUpdated(updated
);
768 termService
.saveTerm(unit
);
770 for (Iterator
<StatisticalMeasure
> k
= statisticalMeasures
.iterator() ; k
.hasNext() ;) {
771 StatisticalMeasure sm
= k
.next();
772 sm
.setCreated(created
);
773 sm
.setUpdated(updated
);
774 termService
.saveTerm(sm
);
777 config
.getCdmAppController().commitTransaction(ts
);
779 IReferenceService referenceService
= config
.getCdmAppController().getReferenceService();
781 for (Iterator
<ReferenceBase
> k
= publications
.values().iterator() ; k
.hasNext() ;){
782 Article publication
= (Article
) k
.next();
783 publication
.setCreated(created
);
784 publication
.setUpdated(updated
);
785 referenceService
.saveReference(publication
);
788 // Returns a CdmApplicationController created by the values of this configuration.
789 IDescriptionService descriptionService
= config
.getCdmAppController().getDescriptionService();
791 for (Iterator
<TaxonDescription
> k
= taxonDescriptions
.values().iterator() ; k
.hasNext() ;){
792 TaxonDescription taxonDescription
= k
.next();
793 taxonDescription
.setCreated(created
);
794 taxonDescription
.setUpdated(updated
);
795 // Persists a Description
796 descriptionService
.saveDescription(taxonDescription
);
799 // makeNameSpecificData(nameMap);
800 logger
.info("end makeTaxonDescriptions ...");
805 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
807 protected boolean isIgnore(IImportConfigurator config
){