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
.in
;
13 import java
.net
.MalformedURLException
;
16 import java
.text
.SimpleDateFormat
;
17 import java
.util
.ArrayList
;
18 import java
.util
.Date
;
19 import java
.util
.HashMap
;
20 import java
.util
.HashSet
;
21 import java
.util
.List
;
25 import org
.apache
.commons
.lang
.StringUtils
;
26 import org
.apache
.log4j
.Logger
;
27 import org
.jdom
.Element
;
28 import org
.jdom
.Namespace
;
29 import org
.joda
.time
.DateTime
;
30 import org
.springframework
.stereotype
.Component
;
31 import org
.springframework
.transaction
.TransactionStatus
;
33 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
34 import eu
.etaxonomy
.cdm
.api
.service
.IService
;
35 import eu
.etaxonomy
.cdm
.common
.mediaMetaData
.ImageMetaData
;
36 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
37 import eu
.etaxonomy
.cdm
.io
.common
.CdmImportBase
;
38 import eu
.etaxonomy
.cdm
.io
.common
.ICdmImport
;
39 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
40 import eu
.etaxonomy
.cdm
.io
.common
.ImportHelper
;
41 import eu
.etaxonomy
.cdm
.io
.sdd
.SDDTransformer
;
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
.AnnotationType
;
46 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
47 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
48 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
49 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
50 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
51 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
52 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
53 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
54 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
55 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
56 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
57 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
58 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
59 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
60 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
61 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
62 import eu
.etaxonomy
.cdm
.model
.description
.MeasurementUnit
;
63 import eu
.etaxonomy
.cdm
.model
.description
.Modifier
;
64 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
65 import eu
.etaxonomy
.cdm
.model
.description
.State
;
66 import eu
.etaxonomy
.cdm
.model
.description
.StateData
;
67 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasure
;
68 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasurementValue
;
69 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
70 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
71 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
72 import eu
.etaxonomy
.cdm
.model
.media
.IdentifiableMediaEntity
;
73 import eu
.etaxonomy
.cdm
.model
.media
.ImageFile
;
74 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
75 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
76 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentationPart
;
77 import eu
.etaxonomy
.cdm
.model
.media
.Rights
;
78 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
79 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
80 import eu
.etaxonomy
.cdm
.model
.occurrence
.Specimen
;
81 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
82 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
83 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
84 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
85 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
86 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonomicTree
;
93 @Component("sddImport")
94 public class SDDImport
extends CdmImportBase
<SDDImportConfigurator
, SDDImportState
> implements ICdmImport
<SDDImportConfigurator
, SDDImportState
> {
95 private static final Logger logger
= Logger
.getLogger(SDDImport
.class);
97 private static int modCount
= 1000;
99 private Map
<String
,Person
> authors
= new HashMap
<String
,Person
>();
100 private Map
<String
,String
> citations
= new HashMap
<String
,String
>();
101 private Map
<String
,String
> defaultUnitPrefixes
= new HashMap
<String
,String
>();
102 private Map
<String
,Person
> editors
= new HashMap
<String
,Person
>();
103 private Map
<String
,FeatureNode
> featureNodes
= new HashMap
<String
,FeatureNode
>();
104 private Map
<String
,Feature
> features
= new HashMap
<String
,Feature
>();
105 private Map
<String
,String
> locations
= new HashMap
<String
,String
>();
106 private Map
<String
,List
<CdmBase
>> mediaObject_ListCdmBase
= new HashMap
<String
,List
<CdmBase
>>();
107 private Map
<String
,String
> mediaObject_Role
= new HashMap
<String
,String
>();
108 private Map
<String
,ReferenceBase
> publications
= new HashMap
<String
,ReferenceBase
>();
109 private Map
<String
,State
> states
= new HashMap
<String
,State
>();
110 private Map
<String
,TaxonDescription
> taxonDescriptions
= new HashMap
<String
,TaxonDescription
>();
111 private Map
<String
,NonViralName
> taxonNameBases
= new HashMap
<String
,NonViralName
>();
112 private Map
<String
,MeasurementUnit
> units
= new HashMap
<String
,MeasurementUnit
>();
113 private Map
<String
,TaxonNode
> taxonNodes
= new HashMap
<String
,TaxonNode
>();
114 private Map
<String
,NamedArea
> namedAreas
= new HashMap
<String
,NamedArea
>();
115 private Map
<String
,Specimen
> specimens
= new HashMap
<String
,Specimen
>();
116 private Map
<String
,Modifier
> modifiers
= new HashMap
<String
,Modifier
>();
118 private Set
<MarkerType
> markerTypes
= new HashSet
<MarkerType
>();
119 private Set
<TermVocabulary
> vocabularies
= new HashSet
<TermVocabulary
>();
121 private Set
<Feature
> descriptiveConcepts
= new HashSet
<Feature
>();
122 private Set
<AnnotationType
> annotationTypes
= new HashSet
<AnnotationType
>();
123 private Set
<Feature
> featureSet
= new HashSet
<Feature
>();
124 private Set
<ReferenceBase
> sources
= new HashSet
<ReferenceBase
>();
125 private ReferenceBase sec
= ReferenceFactory
.newDatabase();
126 private ReferenceBase sourceReference
= null;
128 private Language datasetLanguage
= null;
130 private Namespace xmlNamespace
= Namespace
.getNamespace("xml","http://www.w3.org/XML/1998/namespace");
132 private String generatorName
= "";
133 private String generatorVersion
= "";
135 private Set
<StatisticalMeasure
> statisticalMeasures
= new HashSet
<StatisticalMeasure
>();
136 private Set
<VersionableEntity
> featureData
= new HashSet
<VersionableEntity
>();
137 private Set
<FeatureTree
> featureTrees
= new HashSet
<FeatureTree
>();
138 private Set
<TaxonomicTree
> taxonomicTrees
= new HashSet
<TaxonomicTree
>();
140 private Rights copyright
= null;
142 private int taxonNamesCount
= 0; //XIM ajout
149 public boolean doCheck(SDDImportState state
){
150 boolean result
= true;
151 logger
.warn("No check implemented for SDD");
156 // public boolean doInvoke(IImportConfigurator config, Map<String, MapWrapper<? extends CdmBase>> stores){
158 public boolean doInvoke(SDDImportState state
){
159 boolean success
= true;
161 TransactionStatus ts
= startTransaction();
162 SDDImportConfigurator sddConfig
= state
.getConfig();
164 logger
.info("start Datasets ...");
165 // <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">
166 Element root
= sddConfig
.getSourceRoot();
167 Namespace sddNamespace
= sddConfig
.getSddNamespace();
169 logger
.info("start TechnicalMetadata ...");
170 // <TechnicalMetadata created="2006-04-20T10:00:00">
171 importTechnicalMetadata(root
, sddNamespace
, sddConfig
);
172 List
<Element
> elDatasets
= root
.getChildren("Dataset",sddNamespace
);
176 logger
.info("start Dataset ...");
177 for (Element elDataset
: elDatasets
){
178 success
&= importDataset(elDataset
, sddNamespace
, state
);
179 if ((++i
% modCount
) == 0){ logger
.info("dataset(s) handled: " + i
);}
180 logger
.info(i
+ " dataset(s) handled");
182 commitTransaction(ts
);
183 logger
.info("End of transaction");
188 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
190 protected boolean isIgnore(SDDImportState state
){
195 // associates the reference of a media object in SDD with a CdmBase Object
196 protected void associateImageWithCdmBase(String refMO
, CdmBase cb
){
197 if ((refMO
!= null) && (cb
!=null)) {
198 if (! refMO
.equals("")) {
199 if (! mediaObject_ListCdmBase
.containsKey(refMO
)) {
200 List
<CdmBase
> lcb
= new ArrayList
<CdmBase
>();
202 mediaObject_ListCdmBase
.put(refMO
,lcb
);
204 List
<CdmBase
> lcb
= mediaObject_ListCdmBase
.get(refMO
);
206 mediaObject_ListCdmBase
.put(refMO
,lcb
);
212 // imports information about the Dataset
213 protected void importDatasetRepresentation(Element parent
, Namespace sddNamespace
){
214 logger
.info("start Representation ...");
216 <Label>The Genus Viola</Label>
217 <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>
220 Element elRepresentation
= parent
.getChild("Representation",sddNamespace
);
221 String label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
222 String detail
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Detail",sddNamespace
);
224 sec
.setTitleCache(label
, true);
226 if (detail
!= null) {
227 Annotation annotation
= Annotation
.NewInstance(detail
, datasetLanguage
);
228 annotation
.setAnnotationType(AnnotationType
.EDITORIAL());
229 sec
.addAnnotation(annotation
);
232 List
<Element
> listMediaObjects
= elRepresentation
.getChildren("MediaObject",sddNamespace
);
234 for (Element elMediaObject
: listMediaObjects
) {
237 if (elMediaObject
!= null) {
238 ref
= elMediaObject
.getAttributeValue("ref");
239 role
= elMediaObject
.getAttributeValue("role");
242 if (!ref
.equals("")) {
243 this.associateImageWithCdmBase(ref
,sourceReference
);
244 this.associateImageWithCdmBase(ref
,sec
);
245 mediaObject_Role
.put(ref
,role
);
251 // imports the representation (label, detail, lang) of a particular SDD element
252 protected void importRepresentation(Element parent
, Namespace sddNamespace
, VersionableEntity ve
, String id
, IImportConfigurator config
){
253 Element elRepresentation
= parent
.getChild("Representation",sddNamespace
);
255 Map
<Language
,List
<String
>> langLabDet
= new HashMap
<Language
,List
<String
>>();
257 handleRepresentationLabels(sddNamespace
, elRepresentation
, langLabDet
);
258 handleRepresentationDetails(sddNamespace
, elRepresentation
, langLabDet
);
260 if (ve
instanceof TermBase
) {
261 makeRepresentationForTerms((TermBase
)ve
, langLabDet
);
262 }else if (ve
instanceof Media
) {
263 makeRepresentationForMedia((Media
)ve
, langLabDet
);
264 }else if (ve
instanceof IdentifiableEntity
<?
>) {
265 IdentifiableEntity
<?
> ie
= (IdentifiableEntity
<?
>)ve
;
266 makeRepresentationForIdentifiableEntity(sddNamespace
, ie
, elRepresentation
, langLabDet
);
267 if (ve
instanceof IdentifiableMediaEntity
<?
>){
268 makeRepresentationForIdentifiableMediaEntity(parent
, sddNamespace
, (IdentifiableMediaEntity
<?
>)ve
);
272 makeRepresentationMediaObjects(sddNamespace
, ve
, elRepresentation
);//FIXME
278 * Handles the "Detail" children of representations. Adds the result to the langLabDet.
279 * @param sddNamespace
280 * @param elRepresentation
283 private void handleRepresentationDetails(Namespace sddNamespace
,
284 Element elRepresentation
, Map
<Language
, List
<String
>> langLabDet
) {
285 List
<Element
> listDetails
= elRepresentation
.getChildren("Detail",sddNamespace
);
286 for (Element elDetail
: listDetails
){
287 Language language
= getLanguage(elDetail
);
288 String role
= elDetail
.getAttributeValue("role");
289 String detail
= elDetail
.getText();
290 List
<String
> labDet
= langLabDet
.get(language
);
293 langLabDet
.put(language
, labDet
);
298 * Handles the "Label" children of representations. Adds the result to the langLabDet.
299 * @param sddNamespace
300 * @param elRepresentation
303 private void handleRepresentationLabels(Namespace sddNamespace
,
304 Element elRepresentation
, Map
<Language
, List
<String
>> langLabDet
) {
305 // <Label xml:lang="la">Viola hederacea Labill.</Label>
306 List
<Element
> listLabels
= elRepresentation
.getChildren("Label",sddNamespace
);
307 for (Element elLabel
: listLabels
){
308 Language language
= getLanguage(elLabel
);
309 String label
= elLabel
.getText();
310 List
<String
> labDet
= new ArrayList
<String
>(3);
312 langLabDet
.put(language
, labDet
);
321 private void makeRepresentationForMedia(Media m
, Map
<Language
, List
<String
>> langLabDet
) {
322 for (Language lang
: langLabDet
.keySet()){
323 List
<String
> labDet
= langLabDet
.get(lang
);
324 if (labDet
.get(0) != null){
325 m
.addTitle(LanguageString
.NewInstance(labDet
.get(0), lang
));
327 if (labDet
.size()>1) {
328 m
.addDescription(labDet
.get(1), lang
);
334 * Handles representations for terms. Adds one representation per language in langLabDet.
339 private void makeRepresentationForTerms(TermBase tb
, Map
<Language
, List
<String
>> langLabDet
) {
340 for (Language lang
: langLabDet
.keySet()){
341 List
<String
> labDet
= langLabDet
.get(lang
);
342 if (labDet
.size()>0){
343 if (labDet
.size()>1) {
344 tb
.addRepresentation(Representation
.NewInstance(labDet
.get(1), labDet
.get(0), labDet
.get(0), lang
));
346 tb
.addRepresentation(Representation
.NewInstance(labDet
.get(0), labDet
.get(0), labDet
.get(0), lang
));
354 * Handles the "MediaObject" children of representations.
355 * @param sddNamespace
357 * @param elRepresentation
359 private void makeRepresentationMediaObjects(Namespace sddNamespace
, VersionableEntity ve
, Element elRepresentation
) {
360 List
<Element
> listMediaObjects
= elRepresentation
.getChildren("MediaObject", sddNamespace
);
361 for (Element elMediaObject
: listMediaObjects
) {
365 if (elMediaObject
!= null) {
366 ref
= elMediaObject
.getAttributeValue("ref");
367 role
= elMediaObject
.getAttributeValue("role");
369 if (StringUtils
.isNotBlank(ref
)) {
370 if (ve
instanceof TaxonDescription
) {
371 TaxonDescription td
= (TaxonDescription
) ve
;
372 if (td
.getDescriptionSources().size() > 0) {
373 this.associateImageWithCdmBase(ref
,(ReferenceBase
) td
.getDescriptionSources().toArray()[0]);
375 ReferenceBase descriptionSource
= ReferenceFactory
.newGeneric();
376 sources
.add(descriptionSource
);
377 td
.addDescriptionSource(descriptionSource
);
378 this.associateImageWithCdmBase(ref
,descriptionSource
);
381 this.associateImageWithCdmBase(ref
,ve
);
388 * Handles the "Links" element
390 * @param sddNamespace
393 private void makeRepresentationForIdentifiableMediaEntity(Element parent
,
394 Namespace sddNamespace
, IdentifiableMediaEntity ime
) {
395 Element elLinks
= parent
.getChild("Links",sddNamespace
);
397 if (elLinks
!= null) {
399 // <Link rel="Alternate" href="http://www.diversitycampus.net/people/hagedorn"/>
400 List
<Element
> listLinks
= elLinks
.getChildren("Link", sddNamespace
);
401 Media link
= Media
.NewInstance();
402 MediaRepresentation mr
= MediaRepresentation
.NewInstance();
405 for (Element elLink
: listLinks
){
409 String rel
= elLink
.getAttributeValue("rel");
410 String href
= elLink
.getAttributeValue("href");
412 mr
.addRepresentationPart(MediaRepresentationPart
.NewInstance(href
, null));
413 link
.addRepresentation(mr
);
416 } catch (Exception e
) {
418 logger
.warn("Import of Link " + k
+ " failed.");
421 if ((++k
% modCount
) == 0){ logger
.info("Links handled: " + k
);}
428 * @param sddNamespace
430 * @param elRepresentation
434 private void makeRepresentationForIdentifiableEntity(Namespace sddNamespace
, IdentifiableEntity
<?
> ie
,
435 Element elRepresentation
, Map
<Language
, List
<String
>> langLabDet
) {
436 List
<String
> labDet
= null;
438 if (ie
instanceof TaxonNameBase
) {
439 if (langLabDet
.keySet().contains(getTermService().getLanguageByIso("la"))) {
440 labDet
= langLabDet
.get(getTermService().getLanguageByIso("la"));
441 } else if (langLabDet
.keySet().contains(datasetLanguage
)) {
442 labDet
= langLabDet
.get(datasetLanguage
);
443 logger
.info("TaxonName " + (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
) + " is not specified as a latin name.");
445 labDet
= langLabDet
.get(langLabDet
.keySet().iterator().next());
446 logger
.info("TaxonName " + (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
) + " is not specified as a latin name.");
449 labDet
= langLabDet
.get(langLabDet
.keySet().iterator().next());
452 //FIXME labDet is != null only for TaxonNameBase
453 ie
.setTitleCache(labDet
.get(0), true);
455 if (labDet
.size()>1) {
456 Annotation annotation
= null;
457 if (labDet
.get(1) != null) {
458 if (labDet
.get(2) != null) {
459 annotation
= Annotation
.NewInstance(labDet
.get(2) + " - " + labDet
.get(1), datasetLanguage
);
461 annotation
= Annotation
.NewInstance(labDet
.get(1), datasetLanguage
);
464 ie
.addAnnotation(annotation
);
473 private Language
getLanguage(Element elLanguage
) {
474 String lang
= elLanguage
.getAttributeValue("lang",xmlNamespace
);
475 Language language
= null;
476 if (StringUtils
.isNotBlank(lang
)) {
477 language
= getTermService().getLanguageByIso(lang
.substring(0, 2));
479 language
= datasetLanguage
;
485 // imports the representation (label, detail, lang) of a particular SDD element
486 protected void importTechnicalMetadata(Element root
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
487 Element elTechnicalMetadata
= root
.getChild("TechnicalMetadata", sddNamespace
);
488 String nameCreated
= elTechnicalMetadata
.getAttributeValue("created");
489 sourceReference
= sddConfig
.getSourceReference();
491 if (nameCreated
!= null) {
492 if (!nameCreated
.equals("")) {
493 int year
= Integer
.parseInt(nameCreated
.substring(0,4));
494 int monthOfYear
= Integer
.parseInt(nameCreated
.substring(5,7));
495 int dayOfMonth
= Integer
.parseInt(nameCreated
.substring(8,10));
496 int hourOfDay
= Integer
.parseInt(nameCreated
.substring(11,13));
497 int minuteOfHour
= Integer
.parseInt(nameCreated
.substring(14,16));
498 int secondOfMinute
= Integer
.parseInt(nameCreated
.substring(17,19));
499 DateTime created
= new DateTime(year
,monthOfYear
,dayOfMonth
,hourOfDay
,minuteOfHour
,secondOfMinute
,0);
500 sourceReference
.setCreated(created
);
501 sec
.setCreated(created
);
505 // <Generator name="n/a, handcrafted instance document" version="n/a"/>
506 Element elGenerator
= elTechnicalMetadata
.getChild("Generator", sddNamespace
);
507 generatorName
= elGenerator
.getAttributeValue("name");
508 generatorVersion
= elGenerator
.getAttributeValue("version");
510 sec
.addAnnotation(Annotation
.NewDefaultLanguageInstance(generatorName
+ " - " + generatorVersion
));
511 sourceReference
.addAnnotation(Annotation
.NewDefaultLanguageInstance(generatorName
+ " - " + generatorVersion
));
515 // imports the complete dataset information
516 protected boolean importDataset(Element elDataset
, Namespace sddNamespace
, SDDImportState state
){ // <Dataset xml:lang="en-us">
517 boolean success
= true;
518 SDDImportConfigurator sddConfig
= state
.getConfig();
520 importDatasetLanguage(elDataset
,sddConfig
);
521 importDatasetRepresentation(elDataset
, sddNamespace
);
522 importRevisionData(elDataset
, sddNamespace
);
523 importIPRStatements(elDataset
, sddNamespace
, sddConfig
);
524 importTaxonNames(elDataset
, sddNamespace
, sddConfig
);
526 importDescriptiveConcepts(elDataset
, sddNamespace
, sddConfig
);
527 success
&= importCharacters(elDataset
, sddNamespace
, sddConfig
);
528 importCharacterTrees(elDataset
, sddNamespace
, sddConfig
, success
);
530 MarkerType editorMarkerType
= getMarkerType(state
, SDDTransformer
.uuidMarkerEditor
, "editor", "Editor", "edt");
531 MarkerType geographicAreaMarkerType
= getMarkerType(state
, SDDTransformer
.uuidMarkerSDDGeographicArea
, "SDDGeographicArea", "SDDGeographicArea", "ga");
532 MarkerType descriptiveConceptMarkerType
= getMarkerType(state
, SDDTransformer
.uuidMarkerDescriptiveConcept
, "DescriptiveConcept", "Descriptive Concept", "DC");
533 markerTypes
.add(editorMarkerType
);
534 markerTypes
.add(geographicAreaMarkerType
);
535 markerTypes
.add(descriptiveConceptMarkerType
);
537 //saving of all imported data into the CDM db
543 saveAreas(geographicAreaMarkerType
);
545 saveStatisticalMeasure();
546 saveAnnotationType();
548 success
&= importCodedDescriptions(elDataset
, sddNamespace
, sddConfig
);
549 importAgents(elDataset
, sddNamespace
, sddConfig
, success
);
550 importPublications(elDataset
, sddNamespace
, sddConfig
, success
);
551 importMediaObjects(elDataset
, sddNamespace
, sddConfig
, success
);
552 importTaxonHierarchies(elDataset
, sddNamespace
, sddConfig
, success
);
553 importGeographicAreas(elDataset
, sddNamespace
, sddConfig
);
554 importSpecimens(elDataset
,sddNamespace
, sddConfig
);
557 if ((authors
!= null)||(editors
!= null)) {
558 Team team
= Team
.NewInstance();
559 if (authors
!= null) {
560 for (Person author
: authors
.values()){
561 team
.addTeamMember(author
);
564 if (editors
!= null) {
565 Marker marker
= Marker
.NewInstance();
566 marker
.setMarkerType(editorMarkerType
);
567 for (Person editor
: editors
.values()){
568 Person edit
= editor
;
569 edit
.addMarker(marker
);
570 team
.addTeamMember(edit
);
573 sec
.setAuthorTeam(team
);
574 sourceReference
.setAuthorTeam(team
);
577 if (copyright
!= null) {
578 sourceReference
.addRights(copyright
);
579 sec
.addRights(copyright
);
582 // Returns a CdmApplicationController created by the values of this configuration.
583 IDescriptionService descriptionService
= getDescriptionService();
585 for (TaxonDescription taxonDescription
: taxonDescriptions
.values()){
586 // Persists a Description
587 descriptionService
.save(taxonDescription
);
590 for (String ref
: taxonDescriptions
.keySet()){
591 TaxonDescription td
= taxonDescriptions
.get(ref
);
592 if (citations
.containsKey(ref
)) {
593 ReferenceBase publication
= publications
.get(citations
.get(ref
));
594 if (locations
.containsKey(ref
)) {
595 Annotation location
= Annotation
.NewInstance(locations
.get(ref
), datasetLanguage
);
596 AnnotationType annotationType
= AnnotationType
.NewInstance("", "location", "");
597 annotationTypes
.add(annotationType
);
598 location
.setAnnotationType(annotationType
);
599 (publication
).addAnnotation(location
);
601 td
.addDescriptionSource(publication
);
604 logger
.info("end makeTaxonDescriptions ...");
606 if (descriptiveConcepts
!= null) {
607 for (Feature feature
: descriptiveConcepts
) {
608 Marker marker
= Marker
.NewInstance();
609 marker
.setMarkerType(descriptiveConceptMarkerType
);
610 feature
.addMarker(marker
);
615 for (ReferenceBase publication
: publications
.values()){
616 getReferenceService().save(publication
);
619 for (ReferenceBase source
: sources
){
620 getReferenceService().save(source
);
623 for (FeatureTree featureTree
: featureTrees
) {
624 getFeatureTreeService().save(featureTree
);
626 for (TaxonomicTree taxonomicTree
: taxonomicTrees
) {
627 getTaxonTreeService().save(taxonomicTree
);
629 for (Specimen specimen
: specimens
.values()) {
630 getOccurrenceService().save(specimen
);
632 logger
.info("end of persistence ...");
640 private void saveVocabularies() {
641 for (TermVocabulary vocabulary
: vocabularies
){
642 getVocabularyService().save(vocabulary
);
647 private void saveAnnotationType() {
648 for (AnnotationType annotationType
: annotationTypes
){
649 getTermService().save(annotationType
);
653 private void saveStatisticalMeasure() {
654 for (StatisticalMeasure sm
: statisticalMeasures
){
655 getTermService().save(sm
);
659 private void saveUnits() {
661 for (MeasurementUnit unit
: units
.values()){
663 getTermService().save(unit
);
669 private void saveAreas(MarkerType geographicAreaMarkerType
) {
670 for (NamedArea area
: namedAreas
.values() ){
671 Marker marker
= Marker
.NewInstance();
672 marker
.setMarkerType(geographicAreaMarkerType
);
673 area
.addMarker(marker
);
674 getTermService().save(area
);
678 private void saveStates() {
679 for (State state
: states
.values() ){
680 getTermService().save(state
);
684 private void saveMarkerType() {
685 for (MarkerType markerType
: markerTypes
){
686 getTermService().save(markerType
);
690 private void saveModifiers() {
691 for (Modifier modifier
: modifiers
.values() ){
692 getTermService().save(modifier
);
696 private void saveFeatures() {
697 for (Feature feature
: features
.values() ){
698 getTermService().save(feature
);
702 // imports the default language of the dataset
703 protected void importDatasetLanguage(Element elDataset
, SDDImportConfigurator sddConfig
){
704 String nameLang
= elDataset
.getAttributeValue("lang",xmlNamespace
);
706 if (!nameLang
.equals("")) {
707 String iso
= nameLang
.substring(0, 2);
708 datasetLanguage
= getTermService().getLanguageByIso(iso
);
710 datasetLanguage
= Language
.DEFAULT();
712 if (datasetLanguage
== null) {
713 datasetLanguage
= Language
.DEFAULT();
717 // imports the specimens
718 protected void importSpecimens(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
) {
719 logger
.info("start Specimens ...");
723 <Label>TJM45337</Label>
728 Element elSpecimens
= elDataset
.getChild("Specimens",sddNamespace
);
729 if (elSpecimens
!= null){
730 List
<Element
> listSpecimens
= elSpecimens
.getChildren("Specimen", sddNamespace
);
732 for (Element elSpecimen
: listSpecimens
) {
733 String id
= elSpecimen
.getAttributeValue("id");
734 Specimen specimen
= null;
735 if (!id
.equals("")) {
736 specimen
= Specimen
.NewInstance();
737 specimens
.put(id
,specimen
);
738 importRepresentation(elSpecimen
, sddNamespace
, specimen
, id
, sddConfig
);
745 // imports the revision data associated with the Dataset (authors, modifications)
746 protected void importRevisionData(Element elDataset
, Namespace sddNamespace
){
748 logger
.info("start RevisionData ...");
749 Element elRevisionData
= elDataset
.getChild("RevisionData",sddNamespace
);
750 if (elRevisionData
!= null){
752 Element elCreators
= elRevisionData
.getChild("Creators",sddNamespace
);
754 // <Agent role="aut" ref="a1"/>
755 List
<Element
> listAgents
= elCreators
.getChildren("Agent", sddNamespace
);
759 for (Element elAgent
: listAgents
){
761 String role
= elAgent
.getAttributeValue("role");
762 String ref
= elAgent
.getAttributeValue("ref");
763 if (role
.equals("aut")) {
764 if(!ref
.equals("")) {
765 authors
.put(ref
, null);
768 if (role
.equals("edt")) {
769 if(!ref
.equals("")) {
770 editors
.put(ref
, null);
773 if ((++j
% modCount
) == 0){ logger
.info("Agents handled: " + j
);}
777 // <DateModified>2006-04-08T00:00:00</DateModified>
778 String stringDateModified
= (String
)ImportHelper
.getXmlInputValue(elRevisionData
, "DateModified",sddNamespace
);
780 if (stringDateModified
!= null) {
781 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
784 d
= sdf
.parse(stringDateModified
);
785 } catch(Exception e
) {
786 System
.err
.println("Exception :");
790 DateTime updated
= null;
792 updated
= new DateTime(d
);
793 sourceReference
.setUpdated(updated
);
794 sec
.setUpdated(updated
);
800 // imports ipr statements associated with a dataset
801 protected void importIPRStatements(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
803 logger
.info("start IPRStatements ...");
804 Element elIPRStatements
= elDataset
.getChild("IPRStatements",sddNamespace
);
805 // <IPRStatement role="Copyright">
806 if (elIPRStatements
!= null) {
807 List
<Element
> listIPRStatements
= elIPRStatements
.getChildren("IPRStatement", sddNamespace
);
809 //for each IPRStatement
811 for (Element elIPRStatement
: listIPRStatements
){
813 String role
= elIPRStatement
.getAttributeValue("role");
814 // <Label xml:lang="en-au">(c) 2003-2006 Centre for Occasional Botany.</Label>
815 Element elLabel
= elIPRStatement
.getChild("Label",sddNamespace
);
817 if (elLabel
!= null) {
818 lang
= elLabel
.getAttributeValue("lang",xmlNamespace
);
820 String label
= (String
)ImportHelper
.getXmlInputValue(elIPRStatement
, "Label",sddNamespace
);
822 if (role
.equals("Copyright")) {
823 Language iprLanguage
= null;
825 if (!lang
.equals("")) {
826 iprLanguage
= getTermService().getLanguageByIso(lang
.substring(0, 2));
828 iprLanguage
= datasetLanguage
;
831 if (iprLanguage
== null) {
832 iprLanguage
= datasetLanguage
;
834 copyright
= Rights
.NewInstance(label
, iprLanguage
);
837 if (copyright
!= null) {
838 sourceReference
.addRights(copyright
);
839 sec
.addRights(copyright
);
842 if ((++j
% modCount
) == 0){ logger
.info("IPRStatements handled: " + j
);}
848 // imports the taxon names
849 protected void importTaxonNames(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
851 logger
.info("start TaxonNames ...");
852 Element elTaxonNames
= elDataset
.getChild("TaxonNames",sddNamespace
);
853 // <TaxonName id="t1" uri="urn:lsid:authority:namespace:my-own-id">
854 if (elTaxonNames
!= null) {
855 List
<Element
> listTaxonNames
= elTaxonNames
.getChildren("TaxonName", sddNamespace
);
858 for (Element elTaxonName
: listTaxonNames
){
860 String id
= elTaxonName
.getAttributeValue("id");
861 String uri
= elTaxonName
.getAttributeValue("uri");
863 NonViralName tnb
= null;
864 if (!id
.equals("")) {
865 tnb
= NonViralName
.NewInstance(null);
866 IdentifiableSource source
= null;
868 if (!uri
.equals("")) {
869 source
= IdentifiableSource
.NewInstance(id
, "TaxonName", ReferenceFactory
.newGeneric(), uri
);
872 source
= IdentifiableSource
.NewInstance(id
, "TaxonName");
874 tnb
.addSource(source
);
875 taxonNameBases
.put(id
,tnb
);
879 // <Label xml:lang="la">Viola hederacea Labill.</Label>
880 importRepresentation(elTaxonName
, sddNamespace
, tnb
, id
, sddConfig
);
882 if ((++j
% modCount
) == 0){ logger
.info("TaxonNames handled: " + j
);}
888 // imports the characters (categorical, quantitative and text ; sequence characters not supported) which correspond to CDM Features
889 protected boolean importCharacters(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
890 boolean success
= true;
892 logger
.info("start Characters ...");
893 Element elCharacters
= elDataset
.getChild("Characters", sddNamespace
);
895 // <CategoricalCharacter id="c1">
896 if (elCharacters
!= null) {
897 success
&= handleCategoricalData(sddNamespace
, sddConfig
, elCharacters
);
898 success
&= handleQuantitativeData(sddNamespace
, sddConfig
, elCharacters
);
899 success
&= handleTextCharacters(sddNamespace
, sddConfig
, elCharacters
);
902 /*for (Iterator<Feature> f = features.values().iterator() ; f.hasNext() ;){
903 featureSet.add(f.next()); //XIM Why this line ?
911 * @param sddNamespace
914 * @param elCharacters
917 private boolean handleCategoricalData(Namespace sddNamespace
, SDDImportConfigurator sddConfig
, Element elCharacters
) {
918 boolean success
= true;
919 List
<Element
> elCategoricalCharacters
= elCharacters
.getChildren("CategoricalCharacter", sddNamespace
);
921 for (Element elCategoricalCharacter
: elCategoricalCharacters
){
924 String idCC
= elCategoricalCharacter
.getAttributeValue("id");
925 Feature categoricalCharacter
= Feature
.NewInstance();
926 categoricalCharacter
.setKindOf(Feature
.DESCRIPTION());
927 importRepresentation(elCategoricalCharacter
, sddNamespace
, categoricalCharacter
, idCC
, sddConfig
);
928 categoricalCharacter
.setSupportsCategoricalData(true);
931 Element elStates
= elCategoricalCharacter
.getChild("States",sddNamespace
);
933 // <StateDefinition id="s1">
934 List
<Element
> elStateDefinitions
= elStates
.getChildren("StateDefinition",sddNamespace
);
935 TermVocabulary
<State
> termVocabularyState
= new TermVocabulary
<State
>();
937 vocabularies
.add(termVocabularyState
);
940 //for each StateDefinition
941 for (Element elStateDefinition
: elStateDefinitions
){
943 if ((++k
% modCount
) == 0){ logger
.info("StateDefinitions handled: " + (k
-1));}
945 String idS
= elStateDefinition
.getAttributeValue("id");
946 State state
= states
.get(idS
);
948 state
= State
.NewInstance();
950 logger
.debug("State duplicate found");
952 importRepresentation(elStateDefinition
, sddNamespace
, state
, idS
, sddConfig
);
954 termVocabularyState
.addTerm(state
);
955 states
.put(idS
,state
);
957 categoricalCharacter
.addSupportedCategoricalEnumeration(termVocabularyState
);
958 features
.put(idCC
, categoricalCharacter
);
960 } catch (Exception e
) {
961 logger
.warn("Import of CategoricalCharacter " + j
+ " failed.");
965 if ((++j
% modCount
) == 0){ logger
.info("CategoricalCharacters handled: " + j
);}
972 * @param sddNamespace
974 * @param elCharacters
976 private boolean handleQuantitativeData(Namespace sddNamespace
, SDDImportConfigurator sddConfig
, Element elCharacters
) {
977 boolean success
= true;
979 // <QuantitativeCharacter id="c2">
980 List
<Element
> elQuantitativeCharacters
= elCharacters
.getChildren("QuantitativeCharacter", sddNamespace
);
982 //for each QuantitativeCharacter
983 for (Element elQuantitativeCharacter
: elQuantitativeCharacters
){
987 String idQC
= elQuantitativeCharacter
.getAttributeValue("id");
990 // <Label>Leaf length</Label>
992 Feature quantitativeCharacter
= Feature
.NewInstance();
993 quantitativeCharacter
.setKindOf(Feature
.DESCRIPTION());
994 importRepresentation(elQuantitativeCharacter
, sddNamespace
, quantitativeCharacter
, idQC
, sddConfig
);
996 quantitativeCharacter
.setSupportsQuantitativeData(true);
999 // <Label role="Abbrev">m</Label>
1000 // </MeasurementUnit>
1001 Element elMeasurementUnit
= elQuantitativeCharacter
.getChild("MeasurementUnit",sddNamespace
);
1004 if (elMeasurementUnit
!= null) {
1005 Element elLabel
= elMeasurementUnit
.getChild("Label",sddNamespace
);
1006 role
= elLabel
.getAttributeValue("role");
1007 label
= (String
)ImportHelper
.getXmlInputValue(elMeasurementUnit
, "Label",sddNamespace
);
1010 MeasurementUnit unit
= null;
1011 if (!label
.equals("")){
1013 if (role
.equals("Abbrev")){
1014 unit
= MeasurementUnit
.NewInstance(label
,label
,label
);
1017 unit
= MeasurementUnit
.NewInstance(label
,label
,label
);
1022 units
.put(idQC
, unit
);
1026 // <MeasurementUnitPrefix>milli</MeasurementUnitPrefix>
1028 Element elDefault
= elQuantitativeCharacter
.getChild("Default",sddNamespace
);
1029 if (elDefault
!= null) {
1030 String measurementUnitPrefix
= (String
)ImportHelper
.getXmlInputValue(elDefault
, "MeasurementUnitPrefix",sddNamespace
);
1031 if (! measurementUnitPrefix
.equals("")){
1032 defaultUnitPrefixes
.put(idQC
, measurementUnitPrefix
);
1036 features
.put(idQC
, quantitativeCharacter
);
1038 } catch (Exception e
) {
1040 logger
.warn("Import of QuantitativeCharacter " + j
+ " failed.");
1044 if ((++j
% modCount
) == 0){ logger
.info("QuantitativeCharacters handled: " + j
);}
1050 private boolean handleTextCharacters(Namespace sddNamespace
, SDDImportConfigurator sddConfig
, Element elCharacters
) {
1051 boolean success
= true;
1053 // <TextCharacter id="c3">
1054 List
<Element
> elTextCharacters
= elCharacters
.getChildren("TextCharacter", sddNamespace
);
1056 //for each TextCharacter
1057 for (Element elTextCharacter
: elTextCharacters
){
1061 String idTC
= elTextCharacter
.getAttributeValue("id");
1064 // <Label xml:lang="en">Leaf features not covered by other characters</Label>
1065 // </Representation>
1066 Feature textCharacter
= Feature
.NewInstance();
1067 textCharacter
.setKindOf(Feature
.DESCRIPTION());
1068 importRepresentation(elTextCharacter
, sddNamespace
, textCharacter
, idTC
, sddConfig
);
1070 textCharacter
.setSupportsTextData(true);
1072 features
.put(idTC
, textCharacter
);
1074 } catch (Exception e
) {
1076 logger
.warn("Import of TextCharacter " + j
+ " failed.");
1080 if ((++j
% modCount
) == 0){ logger
.info("TextCharacters handled: " + j
);}
1086 // imports the descriptions of taxa
1087 protected boolean importCodedDescriptions(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
1088 boolean success
= true;
1090 // <CodedDescriptions>
1091 logger
.info("start CodedDescriptions ...");
1092 Element elCodedDescriptions
= elDataset
.getChild("CodedDescriptions",sddNamespace
);
1094 // <CodedDescription id="D101">
1095 if (elCodedDescriptions
!= null) {
1096 List
<Element
> listCodedDescriptions
= elCodedDescriptions
.getChildren("CodedDescription", sddNamespace
);
1098 //for each CodedDescription
1099 for (Element elCodedDescription
: listCodedDescriptions
){
1100 success
&= handleCodedDescription(sddNamespace
, sddConfig
, elCodedDescription
, j
);
1101 if ((++j
% modCount
) == 0){ logger
.info("CodedDescriptions handled: " + j
);}
1108 * @param sddNamespace
1111 * @param elCodedDescription
1114 private boolean handleCodedDescription(Namespace sddNamespace
, SDDImportConfigurator sddConfig
, Element elCodedDescription
, int j
) {
1115 boolean success
= true ;
1118 String idCD
= elCodedDescription
.getAttributeValue("id");
1121 // <Label><i>Viola hederacea</i> Labill. as revised by R. Morris April 8, 2006</Label>
1122 // </Representation>
1123 TaxonDescription taxonDescription
= TaxonDescription
.NewInstance();
1124 importRepresentation(elCodedDescription
, sddNamespace
, taxonDescription
, idCD
, sddConfig
);
1127 // <TaxonName ref="t1"/>
1128 // <Citation ref="p1" location="p. 30"/>
1130 Element elScope
= elCodedDescription
.getChild("Scope", sddNamespace
);
1132 if (elScope
!= null) {
1133 taxon
= handleCDScope(sddNamespace
, sddConfig
, idCD
, elScope
);
1134 } else {//in case no taxon is linked to the description, a new one is created
1135 taxon
= handleCDNoScope(sddNamespace
, sddConfig
, elCodedDescription
);
1139 Element elSummaryData
= elCodedDescription
.getChild("SummaryData",sddNamespace
);
1140 if (elSummaryData
!= null) {
1141 handleSummaryCategoricalData(sddNamespace
, taxonDescription
, elSummaryData
);
1142 handleSummaryQuantitativeData(sddNamespace
, taxonDescription
, elSummaryData
);
1143 handleSummaryTextData(sddNamespace
, taxonDescription
, elSummaryData
);
1146 if (taxon
!= null) {
1147 taxon
.addDescription(taxonDescription
);
1150 taxonDescription
.setDescriptiveSystem(featureSet
);
1152 taxonDescriptions
.put(idCD
, taxonDescription
);//FIXME
1154 } catch (Exception e
) {
1156 logger
.warn("Import of CodedDescription " + j
+ " failed.", e
);
1163 * @param sddNamespace
1165 * @param elCodedDescription
1169 private Taxon
handleCDNoScope(Namespace sddNamespace
,
1170 SDDImportConfigurator sddConfig
, Element elCodedDescription
) {
1172 NonViralName nonViralName
= NonViralName
.NewInstance(null);
1173 String id
= new String("" + taxonNamesCount
);
1174 IdentifiableSource source
= IdentifiableSource
.NewInstance(id
, "TaxonName");
1175 importRepresentation(elCodedDescription
, sddNamespace
, nonViralName
, id
, sddConfig
);
1177 if(sddConfig
.isDoMatchTaxa()){
1178 taxon
= getTaxonService().findBestMatchingTaxon(nonViralName
.getTitleCache());
1182 nonViralName
= HibernateProxyHelper
.deproxy(taxon
.getName(), NonViralName
.class);
1183 // taxonNameBases.put(id ,tnb);
1184 // taxonNamesCount++;
1185 logger
.info("using existing Taxon " + taxon
.getTitleCache());
1187 nonViralName
.addSource(source
);
1188 taxonNameBases
.put(id
,nonViralName
);
1190 logger
.info("creating new Taxon from TaxonName " + nonViralName
.getTitleCache());
1191 taxon
= Taxon
.NewInstance(nonViralName
, sec
);
1197 * @param sddNamespace
1204 private Taxon
handleCDScope(Namespace sddNamespace
, SDDImportConfigurator sddConfig
,
1205 String idCD
, Element elScope
) {
1207 Element elTaxonName
= elScope
.getChild("TaxonName", sddNamespace
);
1208 String ref
= elTaxonName
.getAttributeValue("ref");
1209 NonViralName nonViralName
= taxonNameBases
.get(ref
);
1211 if(sddConfig
.isDoMatchTaxa()){
1212 taxon
= getTaxonService().findBestMatchingTaxon(nonViralName
.getTitleCache());
1216 logger
.info("using existing Taxon" + taxon
.getTitleCache());
1217 if(!nonViralName
.getUuid().equals(taxon
.getName().getUuid())){
1218 logger
.warn("TaxonNameBase entity of existing taxon does not match Name in list -> replacing Name in list");
1219 nonViralName
= HibernateProxyHelper
.deproxy(taxon
.getName(), NonViralName
.class);
1222 logger
.info("creating new Taxon from TaxonName" + nonViralName
.getTitleCache());
1223 taxon
= Taxon
.NewInstance(nonViralName
, sec
);
1227 Element elCitation
= elScope
.getChild("Citation",sddNamespace
);
1228 if (elCitation
!= null) {
1229 String refCitation
= elCitation
.getAttributeValue("ref");
1230 if (! refCitation
.equals("")){
1231 citations
.put(idCD
, refCitation
);
1233 String location
= elCitation
.getAttributeValue("location");
1234 if (! location
.equals("")){
1235 locations
.put(idCD
, location
);
1242 * @param sddNamespace
1243 * @param taxonDescription
1244 * @param elSummaryData
1246 private void handleSummaryTextData(Namespace sddNamespace
,
1247 TaxonDescription taxonDescription
, Element elSummaryData
) {
1250 // <TextChar ref="c3">
1251 List
<Element
> elTextChars
= elSummaryData
.getChildren("TextChar", sddNamespace
);
1254 for (Element elTextChar
: elTextChars
){
1255 if ((++k
% modCount
) == 0){ logger
.info("TextChar handled: " + (k
-1));}
1256 ref
= elTextChar
.getAttributeValue("ref");
1257 Feature feature
= features
.get(ref
);
1258 TextData textData
= TextData
.NewInstance();
1259 textData
.setFeature(feature
);
1261 // <Content>Free form text</Content>
1262 String content
= (String
)ImportHelper
.getXmlInputValue(elTextChar
, "Content",sddNamespace
);
1263 textData
.putText(content
, datasetLanguage
);
1264 taxonDescription
.addElement(textData
);
1269 * @param sddNamespace
1270 * @param taxonDescription
1271 * @param elSummaryData
1273 private void handleSummaryQuantitativeData(Namespace sddNamespace
,
1274 TaxonDescription taxonDescription
, Element elSummaryData
) {
1277 // <Quantitative ref="c2">
1278 List
<Element
> elQuantitatives
= elSummaryData
.getChildren("Quantitative", sddNamespace
);
1280 //for each Quantitative
1281 for (Element elQuantitative
: elQuantitatives
){
1282 if ((++k
% modCount
) == 0){ logger
.warn("Quantitative handled: " + (k
-1));}
1283 ref
= elQuantitative
.getAttributeValue("ref");
1284 Feature feature
= features
.get(ref
);
1285 QuantitativeData quantitativeData
= QuantitativeData
.NewInstance();
1286 quantitativeData
.setFeature(feature
);
1288 MeasurementUnit unit
= units
.get(ref
);
1289 String prefix
= defaultUnitPrefixes
.get(ref
);
1291 String u
= unit
.getLabel();
1292 if (prefix
!= null) {
1296 quantitativeData
.setUnit(unit
);
1299 // <Measure type="Min" value="2.3"/>
1300 List
<Element
> elMeasures
= elQuantitative
.getChildren("Measure", sddNamespace
);
1304 for (Element elMeasure
: elMeasures
){
1305 if ((++l
% modCount
) == 0){ logger
.info("States handled: " + (l
-1));}
1306 String type
= elMeasure
.getAttributeValue("type");
1307 String value
= elMeasure
.getAttributeValue("value");
1308 if (value
.contains(",")) {
1309 value
= value
.replace(',', '.');
1311 Float v
= Float
.parseFloat(value
);
1312 //Float v = new Float(0);
1313 StatisticalMeasure t
= null;
1314 if (type
.equals("Min")) {
1315 t
= StatisticalMeasure
.MIN();
1316 } else if (type
.equals("Mean")) {
1317 t
= StatisticalMeasure
.AVERAGE();
1318 } else if (type
.equals("Max")) {
1319 t
= StatisticalMeasure
.MAX();
1320 } else if (type
.equals("SD")) {
1321 t
= StatisticalMeasure
.STANDARD_DEVIATION();
1322 } else if (type
.equals("N")) {
1323 t
= StatisticalMeasure
.SAMPLE_SIZE();
1324 } else if (type
.equals("UMethLower")) {
1325 t
= StatisticalMeasure
.TYPICAL_LOWER_BOUNDARY();
1326 } else if (type
.equals("UMethUpper")) {
1327 t
= StatisticalMeasure
.TYPICAL_UPPER_BOUNDARY();
1328 } else if (type
.equals("Var")) {
1329 t
= StatisticalMeasure
.VARIANCE();
1331 t
= StatisticalMeasure
.NewInstance(type
,type
,type
);
1332 statisticalMeasures
.add(t
);
1335 StatisticalMeasurementValue statisticalValue
= StatisticalMeasurementValue
.NewInstance();
1336 statisticalValue
.setValue(v
);
1337 statisticalValue
.setType(t
);
1338 quantitativeData
.addStatisticalValue(statisticalValue
);
1339 featureData
.add(statisticalValue
);
1341 taxonDescription
.addElement(quantitativeData
);
1346 * @param sddNamespace
1347 * @param taxonDescription
1348 * @param elSummaryData
1350 private void handleSummaryCategoricalData(Namespace sddNamespace
,
1351 TaxonDescription taxonDescription
, Element elSummaryData
) {
1353 // <Categorical ref="c4">
1354 List
<Element
> elCategoricals
= elSummaryData
.getChildren("Categorical", sddNamespace
);
1356 //for each Categorical
1357 for (Element elCategorical
: elCategoricals
){
1358 if ((++k
% modCount
) == 0){ logger
.warn("Categorical handled: " + (k
-1));}
1359 ref
= elCategorical
.getAttributeValue("ref");
1360 Feature feature
= features
.get(ref
);
1361 CategoricalData categoricalData
= CategoricalData
.NewInstance();
1362 categoricalData
.setFeature(feature
);
1364 // <State ref="s3"/>
1365 List
<Element
> elStates
= elCategorical
.getChildren("State", sddNamespace
);
1369 for (Element elState
: elStates
){
1370 if ((++l
% modCount
) == 0){ logger
.info("States handled: " + (l
-1));}
1371 ref
= elState
.getAttributeValue("ref");
1372 State state
= states
.get(ref
);
1373 if (state
!= null) {
1374 StateData stateData
= StateData
.NewInstance();
1375 stateData
.setState(state
);
1376 List
<Element
> elModifiers
= elState
.getChildren("Modifier", sddNamespace
);
1377 for (Element elModifier
: elModifiers
){
1378 ref
= elModifier
.getAttributeValue("ref");
1379 Modifier modifier
= modifiers
.get(ref
);
1380 if (modifier
!= null) {
1381 stateData
.addModifier(modifier
);
1384 categoricalData
.addState(stateData
);
1386 taxonDescription
.addElement(categoricalData
);
1391 // imports the persons associated with the dataset creation, modification, related publications
1392 protected void importAgents(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1394 logger
.info("start Agents ...");
1395 Element elAgents
= elDataset
.getChild("Agents",sddNamespace
);
1396 if (elAgents
!= null) {
1398 List
<Element
> listAgents
= elAgents
.getChildren("Agent", sddNamespace
);
1401 for (Element elAgent
: listAgents
){
1405 String idA
= elAgent
.getAttributeValue("id");
1408 // <Label>Kevin Thiele</Label>
1409 // <Detail role="Description">Ali Baba is also known as r.a.m.</Detail>
1410 // </Representation>
1411 Person person
= Person
.NewInstance();
1412 importRepresentation(elAgent
, sddNamespace
, person
, idA
, sddConfig
);
1413 person
.addSource(IdentifiableSource
.NewInstance(idA
, "Agent"));
1416 Element elLinks = elAgent.getChild("Links",sddNamespace);
1418 if (elLinks != null) {
1420 // <Link rel="Alternate" href="http://www.diversitycampus.net/people/hagedorn"/>
1421 List<Element> listLinks = elLinks.getChildren("Link", sddNamespace);
1424 for (Element elLink : listLinks){
1428 String rel = elLink.getAttributeValue("rel");
1429 String href = elLink.getAttributeValue("href");
1431 Media link = Media.NewInstance();
1432 MediaRepresentation mr = MediaRepresentation.NewInstance();
1433 mr.addRepresentationPart(MediaRepresentationPart.NewInstance(href, null));
1434 link.addRepresentation(mr);
1435 person.addMedia(link);
1437 } catch (Exception e) {
1439 logger.warn("Import of Link " + k + " failed.");
1443 if ((++k % modCount) == 0){ logger.info("Links handled: " + k);}
1448 if (authors
.containsKey(idA
)) {
1449 authors
.put(idA
,person
);
1452 if (editors
.containsKey(idA
)) {
1453 editors
.put(idA
, person
);
1456 } catch (Exception e
) {
1458 logger
.warn("Import of Agent " + j
+ " failed.");
1462 if ((++j
% modCount
) == 0){ logger
.info("Agents handled: " + j
);}
1468 // imports publications related with the data set
1469 protected void importPublications(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1471 <Publication id="p112">
1473 <Label>Gee, X. & Haa, Y. (2003). How to be happy in five minutes. Instant Gratifications, Palm Beach.</Label>
1476 <Link rel="BasedOn" href="doi:10.1992/32311"/>
1477 <Link rel="Alternate" href="http://some.service.net/providing/bibliographic.data"/>
1481 logger
.info("start Publications ...");
1482 Element elPublications
= elDataset
.getChild("Publications",sddNamespace
);
1484 if (elPublications
!= null) {
1485 List
<Element
> listPublications
= elPublications
.getChildren("Publication", sddNamespace
);
1487 for (Element elPublication
: listPublications
){
1491 String idP
= elPublication
.getAttributeValue("id");
1492 ReferenceBase publication
= ReferenceFactory
.newArticle();
1493 importRepresentation(elPublication
, sddNamespace
, publication
, idP
, sddConfig
);
1495 publications
.put(idP
,publication
);
1497 } catch (Exception e
) {
1498 logger
.warn("Import of Publication " + j
+ " failed.");
1502 if ((++j
% modCount
) == 0){ logger
.info("Publications handled: " + j
);}
1508 // imports media objects such as images //FIXME check mediaobj
1509 protected void importMediaObjects(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1511 logger
.info("start MediaObjects ...");
1512 Element elMediaObjects
= elDataset
.getChild("MediaObjects",sddNamespace
);
1514 if (elMediaObjects
!= null) {
1515 // <MediaObject id="m1">
1516 List
<Element
> listMediaObjects
= elMediaObjects
.getChildren("MediaObject", sddNamespace
);
1518 for (Element elMO
: listMediaObjects
){
1523 String idMO
= elMO
.getAttributeValue("id");
1527 // <Label>Image description, e.g. to be used for alt-attribute in html.</Label>
1528 // </Representation>
1529 Media media
= Media
.NewInstance();
1530 importRepresentation(elMO
, sddNamespace
, media
, idMO
, sddConfig
);
1532 // <Type>Image</Type>
1533 // <Source href="http://test.edu/test.jpg"/>
1534 String type
= (String
)ImportHelper
.getXmlInputValue(elMO
,"Type",sddNamespace
);
1536 if ((type
!= null) && (type
.equals("Image"))) {
1537 Element elSource
= elMO
.getChild("Source",sddNamespace
);
1538 String href
= elSource
.getAttributeValue("href");
1540 ImageMetaData imageMetaData
= ImageMetaData
.newInstance();
1541 ImageFile image
= null;
1542 if (href
.substring(0,7).equals("http://")) {
1544 URL url
= new URL(href
);
1546 imageMetaData
.readMetaData(url
.toURI(), 0);
1547 image
= ImageFile
.NewInstance(url
.toString(), null, imageMetaData
);
1548 } catch (MalformedURLException e
) {
1549 logger
.error("Malformed URL", e
);
1552 String sns
= sddConfig
.getSourceNameString();
1553 File f
= new File(sns
);
1554 File parent
= f
.getParentFile();
1555 String fi
= parent
.toString() + File
.separator
+ href
;
1556 File file
= new File(fi
);
1557 imageMetaData
.readMetaData(new URI(fi
), 0); //file
1558 image
= ImageFile
.NewInstance(file
.toString(), null, imageMetaData
);
1560 MediaRepresentation representation
= MediaRepresentation
.NewInstance(imageMetaData
.getMimeType(), null);
1561 representation
.addRepresentationPart(image
);
1563 media
.addRepresentation(representation
);
1565 ArrayList
<CdmBase
> lcb
= (ArrayList
<CdmBase
>) mediaObject_ListCdmBase
.get(idMO
);
1567 for (int k
= 0; k
< lcb
.size(); k
++) {
1568 if (lcb
.get(k
) instanceof DefinedTermBase
) {
1569 DefinedTermBase dtb
= (DefinedTermBase
) lcb
.get(k
);
1570 // if (lcb.get(0) instanceof DefinedTermBase) {
1571 // DefinedTermBase dtb = (DefinedTermBase) lcb.get(0);
1574 dtb
.addMedia(media
);
1575 //System.out.println(dtb.getLabel());
1577 // Media me = (Media) media.clone();
1578 // dtb.addMedia(me);
1581 } else if (lcb
.get(k
) instanceof ReferenceBase
) {
1582 ReferenceBase rb
= (ReferenceBase
) lcb
.get(k
);
1583 //} else if (lcb.get(0) instanceof ReferenceBase) {
1584 //ReferenceBase rb = (ReferenceBase) lcb.get(0);
1585 // rb.setTitleCache(label);
1589 //System.out.println(rb.getTitle());
1591 // Media me = (Media) media.clone();
1595 }/* else if (lcb.get(k) instanceof TaxonNameBase){
1596 TaxonNameBase tb = (TaxonNameBase) lcb.get(k);
1603 } catch (Exception e
) {
1605 logger
.warn("Could not attach MediaObject " + j
+ "(SDD: " + id
+ ") to several objects.");
1609 if ((++j
% modCount
) == 0){ logger
.info("MediaObjects handled: " + j
);
1616 // imports the <DescriptiveConcepts> block ; DescriptiveConcepts are used as nodes in CharacterTrees and Characters as leaves
1617 // but since Modifiers can be linked to DescriptiveConcepts they are stored as features with a particular Marker
1618 protected void importDescriptiveConcepts(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
1619 /* <DescriptiveConcepts>
1620 <DescriptiveConcept id="dc0">
1622 <Label>Fixed set of modifiers supported in Lucid3</Label>
1625 <Modifier id="mod1">
1627 <Label>rarely</Label>
1629 <ModifierClass>Frequency</ModifierClass>
1630 <ProportionRange lowerestimate="0.0" upperestimate="0.25"/>
1633 </DescriptiveConcept>
1634 </DescriptiveConcepts>
1636 logger
.info("start DescriptiveConcepts ...");
1637 Element elDescriptiveConcepts
= elDataset
.getChild("DescriptiveConcepts",sddNamespace
);
1638 if (elDescriptiveConcepts
!= null) {
1639 List
<Element
> listDescriptiveConcepts
= elDescriptiveConcepts
.getChildren("DescriptiveConcept", sddNamespace
);
1642 for (Element elDescriptiveConcept
: listDescriptiveConcepts
){
1644 String id
= elDescriptiveConcept
.getAttributeValue("id");
1645 Feature feature
= Feature
.NewInstance();
1646 feature
.setKindOf(Feature
.DESCRIPTION());
1647 if (!id
.equals("")) {
1649 // <Label>Body</Label>
1650 importRepresentation(elDescriptiveConcept
, sddNamespace
, feature
, id
, sddConfig
);
1651 features
.put(id
, feature
);
1652 getTermService().save(feature
);//XIM
1653 descriptiveConcepts
.add(feature
);
1654 // imports the modifiers
1655 Element elModifiers
= elDescriptiveConcept
.getChild("Modifiers", sddNamespace
);
1656 if (elModifiers
!=null){
1657 List
<Element
> listModifiers
= elModifiers
.getChildren("Modifier", sddNamespace
);
1658 TermVocabulary
<Modifier
> termVocabularyState
= new TermVocabulary
<Modifier
>();
1659 for (Element elModifier
: listModifiers
) {
1660 Modifier modif
= Modifier
.NewInstance();
1661 String idmod
= elModifier
.getAttributeValue("id");
1662 importRepresentation(elModifier
, sddNamespace
, modif
, idmod
, sddConfig
);
1663 termVocabularyState
.addTerm(modif
);
1664 //termVocabularyStates.add(termVocabularyState);
1665 getVocabularyService().save(termVocabularyState
);//XIM
1666 modifiers
.put(idmod
, modif
);
1668 feature
.addRecommendedModifierEnumeration(termVocabularyState
);
1673 catch (Exception e
) {
1674 logger
.warn("Import of DescriptiveConcept " + j
+ " failed: " + e
.getMessage());
1676 if ((++j
% modCount
) == 0){ logger
.info("DescriptiveConcepts handled: " + j
);}
1682 // imports the <CharacterTrees> block
1683 protected void importCharacterTrees(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1685 logger
.info("start CharacterTrees ...");
1686 Element elCharacterTrees
= elDataset
.getChild("CharacterTrees",sddNamespace
);
1688 if (elCharacterTrees
!= null) {
1689 List
<Element
> listCharacterTrees
= elCharacterTrees
.getChildren("CharacterTree", sddNamespace
);
1691 for (Element elCharacterTree
: listCharacterTrees
){
1693 Element elRepresentation
= elCharacterTree
.getChild("Representation",sddNamespace
);
1694 String label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
,"Label",sddNamespace
);
1695 //Element elDesignedFor = elCharacterTree.getChild("DesignedFor",sddNamespace);//TODO ?
1697 FeatureTree feattree
= FeatureTree
.NewInstance();
1698 importRepresentation(elCharacterTree
, sddNamespace
, feattree
, "", sddConfig
);
1699 FeatureNode root
= feattree
.getRoot();
1700 List
<Element
> listelNodes
= elCharacterTree
.getChildren("Nodes", sddNamespace
);
1702 //Nodes of CharacterTrees in SDD always refer to DescriptiveConcepts
1703 for (Element elNodes
: listelNodes
) {
1704 handleCharacterNodes(sddNamespace
, root
, elNodes
);
1706 featureTrees
.add(feattree
);
1709 catch (Exception e
) {
1710 logger
.warn("Import of Character tree " + j
+ " failed.");
1713 if ((++j
% modCount
) == 0){ logger
.info("CharacterTrees handled: " + j
);}
1721 * @param sddNamespace
1725 private void handleCharacterNodes(Namespace sddNamespace
, FeatureNode root
, Element elNodes
) {
1726 List
<Element
> listNodes
= elNodes
.getChildren("Node", sddNamespace
);
1727 if (listNodes
!= null) {
1728 for (Element elNode
: listNodes
){
1729 String idN
= elNode
.getAttributeValue("id");
1730 FeatureNode fn
= null;
1733 // DescriptiveConcepts are used as nodes in CharacterTrees
1734 Element elDescriptiveConcept
= elNode
.getChild("DescriptiveConcept", sddNamespace
);
1735 if (elDescriptiveConcept
!= null){
1736 String refDC
= elDescriptiveConcept
.getAttributeValue("ref");
1737 dc
= features
.get(refDC
);
1738 fn
= FeatureNode
.NewInstance(dc
);
1741 fn
= FeatureNode
.NewInstance();
1743 Element elParent
= elNode
.getChild("Parent", sddNamespace
);
1744 // in SDD links between Nodes are referenced by the <Parent> tag
1745 if (elParent
!=null){
1746 String refP
= elParent
.getAttributeValue("ref");
1748 FeatureNode parent
= featureNodes
.get(refP
);
1750 root
.addChild(fn
); // if no parent found or the reference is broken, add the node to the root of the tree
1753 parent
.addChild(fn
);
1758 root
.addChild(fn
); // if no parent found or the reference is broken, add the node to the root of the tree
1761 featureNodes
.put(idN
, fn
);
1765 // Leaves of CharacterTrees in SDD are always CharNodes (referring to Characters)
1766 List
<Element
> listCharNodes
= elNodes
.getChildren("CharNode", sddNamespace
);
1767 if (listCharNodes
!= null) {
1768 for (Element elCharNode
: listCharNodes
){
1769 Element elParent
= elCharNode
.getChild("Parent", sddNamespace
);
1770 Element elCharacter
= elCharNode
.getChild("Character", sddNamespace
);
1771 FeatureNode fn
= FeatureNode
.NewInstance();
1772 if (elParent
!=null){
1773 String refP
= elParent
.getAttributeValue("ref");
1774 if ((refP
!=null)&&(!refP
.equals(""))) {
1775 FeatureNode parent
= featureNodes
.get(refP
);
1777 parent
= root
; // if no parent found or the reference is broken, add the node to the root of the tree
1779 parent
.addChild(fn
);
1782 String refC
= elCharacter
.getAttributeValue("ref");
1783 if ((refC
!=null)&&(!refC
.equals(""))){
1784 Feature character
= features
.get(refC
);
1785 fn
.setFeature(character
);
1786 featureNodes
.put(refC
, fn
);
1792 // imports the <TaxonHierarchies> block
1793 protected void importTaxonHierarchies(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1795 logger
.info("start TaxonHierarchies ...");
1796 Element elTaxonHierarchies
= elDataset
.getChild("TaxonHierarchies",sddNamespace
);
1798 if (elTaxonHierarchies
!= null) {
1799 List
<Element
> listTaxonHierarchies
= elTaxonHierarchies
.getChildren("TaxonHierarchy", sddNamespace
);
1801 for (Element elTaxonHierarchy
: listTaxonHierarchies
){
1803 Element elRepresentation
= elTaxonHierarchy
.getChild("Representation",sddNamespace
);
1804 String label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
,"Label",sddNamespace
);
1805 TaxonomicTree taxonomicTree
= TaxonomicTree
.NewInstance(label
);
1806 importRepresentation(elTaxonHierarchy
, sddNamespace
, taxonomicTree
, "", sddConfig
);
1808 Set
<TaxonNode
> root
= taxonomicTree
.getChildNodes();
1809 Element elNodes
= elTaxonHierarchy
.getChild("Nodes", sddNamespace
); // There can be only one <Nodes> block for TaxonHierarchies
1810 List
<Element
> listNodes
= elNodes
.getChildren("Node", sddNamespace
);
1812 for (Element elNode
: listNodes
){
1813 String idN
= elNode
.getAttributeValue("id");
1814 TaxonNameBase tnb
= null;
1815 if (!idN
.equals("")) {
1816 Element elTaxonName
= elNode
.getChild("TaxonName", sddNamespace
);
1817 String refTN
= elTaxonName
.getAttributeValue("ref");
1818 tnb
= taxonNameBases
.get(refTN
);
1819 Taxon taxon
= (Taxon
) tnb
.getTaxa().iterator().next() ;
1820 Element elParent
= elNode
.getChild("Parent", sddNamespace
);
1821 if (elParent
!=null){
1822 String refP
= elParent
.getAttributeValue("ref");
1823 if (!refP
.equals("")) {
1824 TaxonNode parent
= taxonNodes
.get(refP
);
1825 TaxonNode child
= parent
.addChildTaxon(taxon
, sec
, "", Synonym
.NewInstance(tnb
, sec
));
1826 taxonNodes
.put(idN
,child
);
1830 TaxonNode tn
= taxonomicTree
.addChildTaxon(taxon
, sec
, "", Synonym
.NewInstance(tnb
, sec
)); // if no parent found or the reference is broken, add the node to the root of the tree
1831 taxonNodes
.put(idN
,tn
);
1836 taxonomicTrees
.add(taxonomicTree
);
1839 catch (Exception e
) {
1841 logger
.warn("Import of Taxon Hierarchy " + j
+ " failed.");
1845 if ((++j
% modCount
) == 0){ logger
.info("TaxonHierarchies handled: " + j
);}
1853 // imports the <GeographicAreas> block
1854 protected void importGeographicAreas(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
) {
1855 Element elGeographicAreas
= elDataset
.getChild("GeographicAreas",sddNamespace
);
1856 if (elGeographicAreas
!= null) {
1857 List
<Element
> listGeographicAreas
= elGeographicAreas
.getChildren("GeographicArea", sddNamespace
);
1860 for (Element elGeographicArea
: listGeographicAreas
){
1862 String id
= elGeographicArea
.getAttributeValue("id");
1863 NamedArea na
= new NamedArea();
1864 importRepresentation(elGeographicArea
, sddNamespace
, na
, id
, sddConfig
);
1865 namedAreas
.put(id
,na
);
1867 if ((++j
% modCount
) == 0){ logger
.info("GeographicAreas handled: " + j
);}