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
;
15 import java
.text
.SimpleDateFormat
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Date
;
18 import java
.util
.HashMap
;
19 import java
.util
.HashSet
;
20 import java
.util
.List
;
24 import org
.apache
.commons
.lang
.StringUtils
;
25 import org
.apache
.log4j
.Logger
;
26 import org
.jdom
.Element
;
27 import org
.jdom
.Namespace
;
28 import org
.joda
.time
.DateTime
;
29 import org
.springframework
.stereotype
.Component
;
30 import org
.springframework
.transaction
.TransactionStatus
;
32 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
33 import eu
.etaxonomy
.cdm
.common
.mediaMetaData
.ImageMetaData
;
34 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
35 import eu
.etaxonomy
.cdm
.io
.common
.CdmImportBase
;
36 import eu
.etaxonomy
.cdm
.io
.common
.ICdmImport
;
37 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
38 import eu
.etaxonomy
.cdm
.io
.common
.ImportHelper
;
39 import eu
.etaxonomy
.cdm
.io
.sdd
.SDDTransformer
;
40 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
41 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
42 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
43 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
44 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
45 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
46 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
47 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
48 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
49 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
50 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
51 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
52 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
53 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
54 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
55 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
56 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
57 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
58 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
59 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
60 import eu
.etaxonomy
.cdm
.model
.description
.MeasurementUnit
;
61 import eu
.etaxonomy
.cdm
.model
.description
.Modifier
;
62 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
63 import eu
.etaxonomy
.cdm
.model
.description
.State
;
64 import eu
.etaxonomy
.cdm
.model
.description
.StateData
;
65 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasure
;
66 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasurementValue
;
67 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
68 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
69 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
70 import eu
.etaxonomy
.cdm
.model
.media
.IdentifiableMediaEntity
;
71 import eu
.etaxonomy
.cdm
.model
.media
.ImageFile
;
72 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
73 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
74 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentationPart
;
75 import eu
.etaxonomy
.cdm
.model
.media
.Rights
;
76 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
77 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
78 import eu
.etaxonomy
.cdm
.model
.occurrence
.Specimen
;
79 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
80 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
81 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
82 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
83 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
84 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonomicTree
;
91 @Component("sddImport")
92 public class SDDImport
extends CdmImportBase
<SDDImportConfigurator
, SDDImportState
> implements ICdmImport
<SDDImportConfigurator
, SDDImportState
> {
93 private static final Logger logger
= Logger
.getLogger(SDDImport
.class);
95 private static int modCount
= 1000;
97 private Map
<String
,Person
> authors
= new HashMap
<String
,Person
>();
98 private Map
<String
,String
> citations
= new HashMap
<String
,String
>();
99 private Map
<String
,String
> defaultUnitPrefixes
= new HashMap
<String
,String
>();
100 private Map
<String
,Person
> editors
= new HashMap
<String
,Person
>();
101 private Map
<String
,FeatureNode
> featureNodes
= new HashMap
<String
,FeatureNode
>();
102 private Map
<String
,Feature
> features
= new HashMap
<String
,Feature
>();
103 private Map
<String
,String
> locations
= new HashMap
<String
,String
>();
104 private Map
<String
,List
<CdmBase
>> mediaObject_ListCdmBase
= new HashMap
<String
,List
<CdmBase
>>();
105 private Map
<String
,String
> mediaObject_Role
= new HashMap
<String
,String
>();
106 private Map
<String
,ReferenceBase
> publications
= new HashMap
<String
,ReferenceBase
>();
107 private Map
<String
,State
> states
= new HashMap
<String
,State
>();
108 private Map
<String
,TaxonDescription
> taxonDescriptions
= new HashMap
<String
,TaxonDescription
>();
109 private Map
<String
,NonViralName
> taxonNameBases
= new HashMap
<String
,NonViralName
>();
110 private Map
<String
,MeasurementUnit
> units
= new HashMap
<String
,MeasurementUnit
>();
111 private Map
<String
,TaxonNode
> taxonNodes
= new HashMap
<String
,TaxonNode
>();
112 private Map
<String
,NamedArea
> namedAreas
= new HashMap
<String
,NamedArea
>();
113 private Map
<String
,Specimen
> specimens
= new HashMap
<String
,Specimen
>();
114 private Map
<String
,Modifier
> modifiers
= new HashMap
<String
,Modifier
>();
116 private Set
<MarkerType
> markerTypes
= new HashSet
<MarkerType
>();
117 private Set
<TermVocabulary
> vocabularies
= new HashSet
<TermVocabulary
>();
119 private Set
<Feature
> descriptiveConcepts
= new HashSet
<Feature
>();
120 private Set
<AnnotationType
> annotationTypes
= new HashSet
<AnnotationType
>();
121 private Set
<Feature
> featureSet
= new HashSet
<Feature
>();
122 private ReferenceBase sec
= ReferenceFactory
.newDatabase();
123 private ReferenceBase sourceReference
= null;
125 private Language datasetLanguage
= null;
127 private Namespace xmlNamespace
= Namespace
.getNamespace("xml","http://www.w3.org/XML/1998/namespace");
129 private String generatorName
= "";
130 private String generatorVersion
= "";
132 private Set
<StatisticalMeasure
> statisticalMeasures
= new HashSet
<StatisticalMeasure
>();
133 private Set
<VersionableEntity
> featureData
= new HashSet
<VersionableEntity
>();
134 private Set
<FeatureTree
> featureTrees
= new HashSet
<FeatureTree
>();
135 private Set
<TaxonomicTree
> taxonomicTrees
= new HashSet
<TaxonomicTree
>();
137 private Rights copyright
= null;
139 private int taxonNamesCount
= 0; //XIM ajout
146 public boolean doCheck(SDDImportState state
){
147 boolean result
= true;
148 logger
.warn("No check implemented for SDD");
153 // public boolean doInvoke(IImportConfigurator config, Map<String, MapWrapper<? extends CdmBase>> stores){
155 public boolean doInvoke(SDDImportState state
){
156 boolean success
= true;
158 TransactionStatus ts
= startTransaction();
159 SDDImportConfigurator sddConfig
= state
.getConfig();
161 logger
.info("start Datasets ...");
162 // <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">
163 Element root
= sddConfig
.getSourceRoot();
164 Namespace sddNamespace
= sddConfig
.getSddNamespace();
166 logger
.info("start TechnicalMetadata ...");
167 // <TechnicalMetadata created="2006-04-20T10:00:00">
168 importTechnicalMetadata(root
, sddNamespace
, sddConfig
);
169 List
<Element
> elDatasets
= root
.getChildren("Dataset",sddNamespace
);
173 logger
.info("start Dataset ...");
174 for (Element elDataset
: elDatasets
){
175 success
&= importDataset(elDataset
, sddNamespace
, state
);
176 if ((++i
% modCount
) == 0){ logger
.info("Datasets handled: " + i
);}
177 logger
.info(i
+ " Datasets handled");
179 commitTransaction(ts
);
184 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
186 protected boolean isIgnore(SDDImportState state
){
191 // associates the reference of a media object in SDD with a CdmBase Object
192 protected void associateImageWithCdmBase(String refMO
, CdmBase cb
){
193 if ((refMO
!= null) && (cb
!=null)) {
194 if (! refMO
.equals("")) {
195 if (! mediaObject_ListCdmBase
.containsKey(refMO
)) {
196 List
<CdmBase
> lcb
= new ArrayList
<CdmBase
>();
198 mediaObject_ListCdmBase
.put(refMO
,lcb
);
200 List
<CdmBase
> lcb
= mediaObject_ListCdmBase
.get(refMO
);
202 mediaObject_ListCdmBase
.put(refMO
,lcb
);
208 // imports information about the Dataset
209 protected void importDatasetRepresentation(Element parent
, Namespace sddNamespace
){
210 logger
.info("start Representation ...");
212 <Label>The Genus Viola</Label>
213 <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>
216 Element elRepresentation
= parent
.getChild("Representation",sddNamespace
);
217 String label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
);
218 String detail
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Detail",sddNamespace
);
220 sec
.setTitleCache(label
, true);
222 if (detail
!= null) {
223 Annotation annotation
= Annotation
.NewInstance(detail
, datasetLanguage
);
224 annotation
.setAnnotationType(AnnotationType
.EDITORIAL());
225 sec
.addAnnotation(annotation
);
228 List
<Element
> listMediaObjects
= elRepresentation
.getChildren("MediaObject",sddNamespace
);
230 for (Element elMediaObject
: listMediaObjects
) {
233 if (elMediaObject
!= null) {
234 ref
= elMediaObject
.getAttributeValue("ref");
235 role
= elMediaObject
.getAttributeValue("role");
238 if (!ref
.equals("")) {
239 this.associateImageWithCdmBase(ref
,sourceReference
);
240 this.associateImageWithCdmBase(ref
,sec
);
241 mediaObject_Role
.put(ref
,role
);
247 // imports the representation (label, detail, lang) of a particular SDD element
248 protected void importRepresentation(Element parent
, Namespace sddNamespace
, VersionableEntity ve
, String id
, IImportConfigurator config
){
249 Element elRepresentation
= parent
.getChild("Representation",sddNamespace
);
251 Map
<Language
,List
<String
>> langLabDet
= new HashMap
<Language
,List
<String
>>();
253 handleRepresentationLabels(sddNamespace
, elRepresentation
, langLabDet
);
254 handleRepresentationDetails(sddNamespace
, elRepresentation
, langLabDet
);
256 if (ve
instanceof TermBase
) {
257 makeRepresentationForTerms((TermBase
)ve
, langLabDet
);
258 }else if (ve
instanceof Media
) {
259 makeRepresentationForMedia((Media
)ve
, langLabDet
);
260 }else if (ve
instanceof IdentifiableEntity
<?
>) {
261 IdentifiableEntity
<?
> ie
= (IdentifiableEntity
<?
>)ve
;
262 makeRepresentationForIdentifiableEntity(sddNamespace
, ie
, elRepresentation
, langLabDet
);
263 if (ve
instanceof IdentifiableMediaEntity
<?
>){
264 makeRepresentationForIdentifiableMediaEntity(parent
, sddNamespace
, (IdentifiableMediaEntity
<?
>)ve
);
268 makeRepresentationMediaObjects(sddNamespace
, ve
, elRepresentation
);
274 * Handles the "Detail" children of representations. Adds the result to the langLabDet.
275 * @param sddNamespace
276 * @param elRepresentation
279 private void handleRepresentationDetails(Namespace sddNamespace
,
280 Element elRepresentation
, Map
<Language
, List
<String
>> langLabDet
) {
281 List
<Element
> listDetails
= elRepresentation
.getChildren("Detail",sddNamespace
);
282 for (Element elDetail
: listDetails
){
283 Language language
= getLanguage(elDetail
);
284 String role
= elDetail
.getAttributeValue("role");
285 String detail
= elDetail
.getText();
286 List
<String
> labDet
= langLabDet
.get(language
);
289 langLabDet
.put(language
, labDet
);
294 * Handles the "Label" children of representations. Adds the result to the langLabDet.
295 * @param sddNamespace
296 * @param elRepresentation
299 private void handleRepresentationLabels(Namespace sddNamespace
,
300 Element elRepresentation
, Map
<Language
, List
<String
>> langLabDet
) {
301 // <Label xml:lang="la">Viola hederacea Labill.</Label>
302 List
<Element
> listLabels
= elRepresentation
.getChildren("Label",sddNamespace
);
303 for (Element elLabel
: listLabels
){
304 Language language
= getLanguage(elLabel
);
305 String label
= elLabel
.getText();
306 List
<String
> labDet
= new ArrayList
<String
>(3);
308 langLabDet
.put(language
, labDet
);
317 private void makeRepresentationForMedia(Media m
, Map
<Language
, List
<String
>> langLabDet
) {
318 for (Language lang
: langLabDet
.keySet()){
319 List
<String
> labDet
= langLabDet
.get(lang
);
320 if (labDet
.get(0) != null){
321 m
.addTitle(LanguageString
.NewInstance(labDet
.get(0), lang
));
323 if (labDet
.size()>1) {
324 m
.addDescription(labDet
.get(1), lang
);
330 * Handles representations for terms. Adds one representation per language in langLabDet.
335 private void makeRepresentationForTerms(TermBase tb
, Map
<Language
, List
<String
>> langLabDet
) {
336 for (Language lang
: langLabDet
.keySet()){
337 List
<String
> labDet
= langLabDet
.get(lang
);
338 if (labDet
.size()>0){
339 if (labDet
.size()>1) {
340 tb
.addRepresentation(Representation
.NewInstance(labDet
.get(1), labDet
.get(0), labDet
.get(0), lang
));
342 tb
.addRepresentation(Representation
.NewInstance(labDet
.get(0), labDet
.get(0), labDet
.get(0), lang
));
350 * Handles the "MediaObject" children of representations.
351 * @param sddNamespace
353 * @param elRepresentation
355 private void makeRepresentationMediaObjects(Namespace sddNamespace
,
356 VersionableEntity ve
, Element elRepresentation
) {
357 List
<Element
> listMediaObjects
= elRepresentation
.getChildren("MediaObject", sddNamespace
);
358 for (Element elMediaObject
: listMediaObjects
) {
362 if (elMediaObject
!= null) {
363 ref
= elMediaObject
.getAttributeValue("ref");
364 role
= elMediaObject
.getAttributeValue("role");
366 if (StringUtils
.isNotBlank(ref
)) {
367 if (ve
instanceof TaxonDescription
) {
368 TaxonDescription td
= (TaxonDescription
) ve
;
369 //TODO: ensure that all images are imported
370 if (td
.getDescriptionSources().size() > 0) {
371 this.associateImageWithCdmBase(ref
,(ReferenceBase
) td
.getDescriptionSources().toArray()[0]);
373 ReferenceBase descriptionSource
= ReferenceFactory
.newGeneric();
374 td
.addDescriptionSource(descriptionSource
);
375 this.associateImageWithCdmBase(ref
,descriptionSource
);
378 this.associateImageWithCdmBase(ref
,ve
);
385 * Handles the "Links" element
387 * @param sddNamespace
390 private void makeRepresentationForIdentifiableMediaEntity(Element parent
,
391 Namespace sddNamespace
, IdentifiableMediaEntity ime
) {
392 Element elLinks
= parent
.getChild("Links",sddNamespace
);
394 if (elLinks
!= null) {
396 // <Link rel="Alternate" href="http://www.diversitycampus.net/people/hagedorn"/>
397 List
<Element
> listLinks
= elLinks
.getChildren("Link", sddNamespace
);
398 Media link
= Media
.NewInstance();
399 MediaRepresentation mr
= MediaRepresentation
.NewInstance();
402 for (Element elLink
: listLinks
){
406 String rel
= elLink
.getAttributeValue("rel");
407 String href
= elLink
.getAttributeValue("href");
409 mr
.addRepresentationPart(MediaRepresentationPart
.NewInstance(href
, null));
410 link
.addRepresentation(mr
);
413 } catch (Exception e
) {
415 logger
.warn("Import of Link " + k
+ " failed.");
418 if ((++k
% modCount
) == 0){ logger
.info("Links handled: " + k
);}
425 * @param sddNamespace
427 * @param elRepresentation
431 private void makeRepresentationForIdentifiableEntity(Namespace sddNamespace
, IdentifiableEntity
<?
> ie
,
432 Element elRepresentation
, Map
<Language
, List
<String
>> langLabDet
) {
433 List
<String
> labDet
= null;
435 if (ie
instanceof TaxonNameBase
) {
436 if (langLabDet
.keySet().contains(getTermService().getLanguageByIso("la"))) {
437 labDet
= langLabDet
.get(getTermService().getLanguageByIso("la"));
438 } else if (langLabDet
.keySet().contains(datasetLanguage
)) {
439 labDet
= langLabDet
.get(datasetLanguage
);
440 logger
.info("TaxonName " + (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
) + " is not specified as a latin name.");
442 labDet
= langLabDet
.get(langLabDet
.keySet().iterator().next());
443 logger
.info("TaxonName " + (String
)ImportHelper
.getXmlInputValue(elRepresentation
, "Label",sddNamespace
) + " is not specified as a latin name.");
446 labDet
= langLabDet
.get(langLabDet
.keySet().iterator().next());
449 //FIXME labDet is != null only for TaxonNameBase
450 ie
.setTitleCache(labDet
.get(0), true);
452 if (labDet
.size()>1) {
453 Annotation annotation
= null;
454 if (labDet
.get(1) != null) {
455 if (labDet
.get(2) != null) {
456 annotation
= Annotation
.NewInstance(labDet
.get(2) + " - " + labDet
.get(1), datasetLanguage
);
458 annotation
= Annotation
.NewInstance(labDet
.get(1), datasetLanguage
);
461 ie
.addAnnotation(annotation
);
470 private Language
getLanguage(Element elLanguage
) {
471 String lang
= elLanguage
.getAttributeValue("lang",xmlNamespace
);
472 Language language
= null;
473 if (StringUtils
.isNotBlank(lang
)) {
474 language
= getTermService().getLanguageByIso(lang
.substring(0, 2));
476 language
= datasetLanguage
;
482 // imports the representation (label, detail, lang) of a particular SDD element
483 protected void importTechnicalMetadata(Element root
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
484 Element elTechnicalMetadata
= root
.getChild("TechnicalMetadata", sddNamespace
);
485 String nameCreated
= elTechnicalMetadata
.getAttributeValue("created");
486 sourceReference
= sddConfig
.getSourceReference();
488 if (nameCreated
!= null) {
489 if (!nameCreated
.equals("")) {
490 int year
= Integer
.parseInt(nameCreated
.substring(0,4));
491 int monthOfYear
= Integer
.parseInt(nameCreated
.substring(5,7));
492 int dayOfMonth
= Integer
.parseInt(nameCreated
.substring(8,10));
493 int hourOfDay
= Integer
.parseInt(nameCreated
.substring(11,13));
494 int minuteOfHour
= Integer
.parseInt(nameCreated
.substring(14,16));
495 int secondOfMinute
= Integer
.parseInt(nameCreated
.substring(17,19));
496 DateTime created
= new DateTime(year
,monthOfYear
,dayOfMonth
,hourOfDay
,minuteOfHour
,secondOfMinute
,0);
497 sourceReference
.setCreated(created
);
498 sec
.setCreated(created
);
502 // <Generator name="n/a, handcrafted instance document" version="n/a"/>
503 Element elGenerator
= elTechnicalMetadata
.getChild("Generator", sddNamespace
);
504 generatorName
= elGenerator
.getAttributeValue("name");
505 generatorVersion
= elGenerator
.getAttributeValue("version");
507 sec
.addAnnotation(Annotation
.NewDefaultLanguageInstance(generatorName
+ " - " + generatorVersion
));
508 sourceReference
.addAnnotation(Annotation
.NewDefaultLanguageInstance(generatorName
+ " - " + generatorVersion
));
512 // imports the complete dataset information
513 protected boolean importDataset(Element elDataset
, Namespace sddNamespace
, SDDImportState state
){ // <Dataset xml:lang="en-us">
514 boolean success
= true;
515 SDDImportConfigurator sddConfig
= state
.getConfig();
517 importDatasetLanguage(elDataset
,sddConfig
);
518 importDatasetRepresentation(elDataset
, sddNamespace
);
519 importRevisionData(elDataset
, sddNamespace
);
520 importIPRStatements(elDataset
, sddNamespace
, sddConfig
);
521 importTaxonNames(elDataset
, sddNamespace
, sddConfig
);
523 importDescriptiveConcepts(elDataset
, sddNamespace
, sddConfig
);
525 getTermService().getLanguageByIso("la");
526 success
&= importCharacters(elDataset
, sddNamespace
, sddConfig
);
527 importCharacterTrees(elDataset
, sddNamespace
, sddConfig
, success
);
530 getTermService().getLanguageByIso("la");
533 MarkerType editorMarkerType
= getMarkerType(state
, SDDTransformer
.uuidMarkerEditor
, "editor", "Editor", "edt");
534 MarkerType geographicAreaMarkerType
= getMarkerType(state
, SDDTransformer
.uuidMarkerSDDGeographicArea
, "SDDGeographicArea", "SDDGeographicArea", "ga");
535 MarkerType descriptiveConceptMarkerType
= getMarkerType(state
, SDDTransformer
.uuidMarkerDescriptiveConcept
, "DescriptiveConcept", "Descriptive Concept", "DC");
536 markerTypes
.add(editorMarkerType
);
537 markerTypes
.add(geographicAreaMarkerType
);
538 markerTypes
.add(descriptiveConceptMarkerType
);
541 getTermService().getLanguageByIso("la");
544 //saving of all imported data into the CDM db
550 saveAreas(geographicAreaMarkerType
);
552 saveStatisticalMeasure();
553 saveAnnotationType();
556 getTermService().getLanguageByIso("la");
558 success
&= importCodedDescriptions(elDataset
, sddNamespace
, sddConfig
);
559 importAgents(elDataset
, sddNamespace
, sddConfig
, success
);
560 importPublications(elDataset
, sddNamespace
, sddConfig
, success
);
561 importMediaObjects(elDataset
, sddNamespace
, sddConfig
, success
);
562 importTaxonHierarchies(elDataset
, sddNamespace
, sddConfig
, success
);
563 importGeographicAreas(elDataset
, sddNamespace
, sddConfig
);
564 importSpecimens(elDataset
,sddNamespace
, sddConfig
);
568 if ((authors
!= null)||(editors
!= null)) {
569 Team team
= Team
.NewInstance();
570 if (authors
!= null) {
571 for (Person author
: authors
.values()){
572 team
.addTeamMember(author
);
575 if (editors
!= null) {
576 Marker marker
= Marker
.NewInstance();
577 marker
.setMarkerType(editorMarkerType
);
578 for (Person editor
: editors
.values()){
579 Person edit
= editor
;
580 edit
.addMarker(marker
);
581 team
.addTeamMember(edit
);
584 sec
.setAuthorTeam(team
);
585 sourceReference
.setAuthorTeam(team
);
588 if (copyright
!= null) {
589 sourceReference
.addRights(copyright
);
590 sec
.addRights(copyright
);
593 // Returns a CdmApplicationController created by the values of this configuration.
594 IDescriptionService descriptionService
= getDescriptionService();
596 for (TaxonDescription taxonDescription
: taxonDescriptions
.values()){
597 // Persists a Description
598 descriptionService
.save(taxonDescription
);
601 for (String ref
: taxonDescriptions
.keySet()){
602 TaxonDescription td
= taxonDescriptions
.get(ref
);
603 if (citations
.containsKey(ref
)) {
604 ReferenceBase publication
= publications
.get(citations
.get(ref
));
605 if (locations
.containsKey(ref
)) {
606 Annotation location
= Annotation
.NewInstance(locations
.get(ref
), datasetLanguage
);
607 AnnotationType annotationType
= AnnotationType
.NewInstance("", "location", "");
608 annotationTypes
.add(annotationType
);
609 location
.setAnnotationType(annotationType
);
610 (publication
).addAnnotation(location
);
612 td
.addDescriptionSource(publication
);
615 logger
.info("end makeTaxonDescriptions ...");
618 // for (Iterator<TermVocabulary<Modifier>> k = termVocabularyStates.iterator() ; k.hasNext() ;){
619 // TermVocabulary<Modifier> termVocabulary = k.next();
620 // getVocabularyService().save(termVocabulary); //XIM
624 //sddConfig.setSourceReference(sourceReference);
627 if (descriptiveConcepts
!= null) {
628 for (Feature feature
: descriptiveConcepts
) {
629 Marker marker
= Marker
.NewInstance();
630 marker
.setMarkerType(descriptiveConceptMarkerType
);
631 feature
.addMarker(marker
);
636 /*Marker markerd = Marker.NewInstance();
637 markerd.setMarkerType(descriptiveConceptMarker);
638 Feature fiture = Feature.NewInstance("Fitoure","Fitoure","Fitoure");
639 fiture.addMarker(markerd);
640 TermVocabulary<Modifier> termVocabularyState = new TermVocabulary<Modifier>("test","test","test","test");
641 Modifier modif = new Modifier("zoub","zab","zib");
642 termVocabularyState.addTerm(modif);
643 getVocabularyService().save(termVocabularyState);
644 fiture.addRecommendedModifierEnumeration(termVocabularyState);
645 termService.save(modif);
646 termService.save(fiture);*/
648 //XIMtermService.save(editorMarkerType);
650 //XIMtermService.save(geographicAreaMarkerType);
652 // referenceService.saveReference(sourceReference);
653 for (ReferenceBase publication
: publications
.values()){
654 getReferenceService().save(publication
);
657 for (FeatureTree featureTree
: featureTrees
) {
658 getFeatureTreeService().save(featureTree
);
660 for (TaxonomicTree taxonomicTree
: taxonomicTrees
) {
661 getTaxonTreeService().save(taxonomicTree
);
663 for (Specimen specimen
: specimens
.values()) {
664 getOccurrenceService().save(specimen
);
666 logger
.info("end of persistence ...");
674 private void saveVocabularies() {
675 for (TermVocabulary vocabulary
: vocabularies
){
676 getVocabularyService().save(vocabulary
);
681 private void saveAnnotationType() {
682 for (AnnotationType annotationType
: annotationTypes
){
683 getTermService().save(annotationType
);
687 private void saveStatisticalMeasure() {
688 for (StatisticalMeasure sm
: statisticalMeasures
){
689 getTermService().save(sm
);
693 private void saveUnits() {
695 for (MeasurementUnit unit
: units
.values()){
697 getTermService().save(unit
);
703 private void saveAreas(MarkerType geographicAreaMarkerType
) {
704 for (NamedArea area
: namedAreas
.values() ){
705 Marker marker
= Marker
.NewInstance();
706 marker
.setMarkerType(geographicAreaMarkerType
);
707 area
.addMarker(marker
);
708 getTermService().save(area
);
712 private void saveStates() {
713 for (State state
: states
.values() ){
714 getTermService().save(state
);
718 private void saveMarkerType() {
719 for (MarkerType markerType
: markerTypes
){
720 getTermService().save(markerType
);
724 private void saveModifiers() {
725 for (Modifier modifier
: modifiers
.values() ){
726 getTermService().save(modifier
);
730 private void saveFeatures() {
731 for (Feature feature
: features
.values() ){
732 getTermService().save(feature
);
736 // imports the default language of the dataset
737 protected void importDatasetLanguage(Element elDataset
, SDDImportConfigurator sddConfig
){
738 String nameLang
= elDataset
.getAttributeValue("lang",xmlNamespace
);
740 if (!nameLang
.equals("")) {
741 String iso
= nameLang
.substring(0, 2);
742 datasetLanguage
= getTermService().getLanguageByIso(iso
);
744 datasetLanguage
= Language
.DEFAULT();
746 if (datasetLanguage
== null) {
747 datasetLanguage
= Language
.DEFAULT();
751 // imports the specimens
752 protected void importSpecimens(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
) {
753 logger
.info("start Specimens ...");
757 <Label>TJM45337</Label>
762 Element elSpecimens
= elDataset
.getChild("Specimens",sddNamespace
);
763 if (elSpecimens
!= null){
764 List
<Element
> listSpecimens
= elSpecimens
.getChildren("Specimen", sddNamespace
);
766 for (Element elSpecimen
: listSpecimens
) {
767 String id
= elSpecimen
.getAttributeValue("id");
768 Specimen specimen
= null;
769 if (!id
.equals("")) {
770 specimen
= Specimen
.NewInstance();
771 specimens
.put(id
,specimen
);
772 importRepresentation(elSpecimen
, sddNamespace
, specimen
, id
, sddConfig
);
779 // imports the revision data associated with the Dataset (authors, modifications)
780 protected void importRevisionData(Element elDataset
, Namespace sddNamespace
){
782 logger
.info("start RevisionData ...");
783 Element elRevisionData
= elDataset
.getChild("RevisionData",sddNamespace
);
784 if (elRevisionData
!= null){
786 Element elCreators
= elRevisionData
.getChild("Creators",sddNamespace
);
788 // <Agent role="aut" ref="a1"/>
789 List
<Element
> listAgents
= elCreators
.getChildren("Agent", sddNamespace
);
793 for (Element elAgent
: listAgents
){
795 String role
= elAgent
.getAttributeValue("role");
796 String ref
= elAgent
.getAttributeValue("ref");
797 if (role
.equals("aut")) {
798 if(!ref
.equals("")) {
799 authors
.put(ref
, null);
802 if (role
.equals("edt")) {
803 if(!ref
.equals("")) {
804 editors
.put(ref
, null);
807 if ((++j
% modCount
) == 0){ logger
.info("Agents handled: " + j
);}
811 // <DateModified>2006-04-08T00:00:00</DateModified>
812 String stringDateModified
= (String
)ImportHelper
.getXmlInputValue(elRevisionData
, "DateModified",sddNamespace
);
814 if (stringDateModified
!= null) {
815 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
818 d
= sdf
.parse(stringDateModified
);
819 } catch(Exception e
) {
820 System
.err
.println("Exception :");
824 DateTime updated
= null;
826 updated
= new DateTime(d
);
827 sourceReference
.setUpdated(updated
);
828 sec
.setUpdated(updated
);
834 // imports ipr statements associated with a dataset
835 protected void importIPRStatements(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
837 logger
.info("start IPRStatements ...");
838 Element elIPRStatements
= elDataset
.getChild("IPRStatements",sddNamespace
);
839 // <IPRStatement role="Copyright">
840 if (elIPRStatements
!= null) {
841 List
<Element
> listIPRStatements
= elIPRStatements
.getChildren("IPRStatement", sddNamespace
);
843 //for each IPRStatement
845 for (Element elIPRStatement
: listIPRStatements
){
847 String role
= elIPRStatement
.getAttributeValue("role");
848 // <Label xml:lang="en-au">(c) 2003-2006 Centre for Occasional Botany.</Label>
849 Element elLabel
= elIPRStatement
.getChild("Label",sddNamespace
);
851 if (elLabel
!= null) {
852 lang
= elLabel
.getAttributeValue("lang",xmlNamespace
);
854 String label
= (String
)ImportHelper
.getXmlInputValue(elIPRStatement
, "Label",sddNamespace
);
856 if (role
.equals("Copyright")) {
857 Language iprLanguage
= null;
859 if (!lang
.equals("")) {
860 iprLanguage
= getTermService().getLanguageByIso(lang
.substring(0, 2));
862 iprLanguage
= datasetLanguage
;
865 if (iprLanguage
== null) {
866 iprLanguage
= datasetLanguage
;
868 copyright
= Rights
.NewInstance(label
, iprLanguage
);
871 if (copyright
!= null) {
872 sourceReference
.addRights(copyright
);
873 sec
.addRights(copyright
);
876 if ((++j
% modCount
) == 0){ logger
.info("IPRStatements handled: " + j
);}
882 // imports the taxon names
883 protected void importTaxonNames(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
885 logger
.info("start TaxonNames ...");
886 Element elTaxonNames
= elDataset
.getChild("TaxonNames",sddNamespace
);
887 // <TaxonName id="t1" uri="urn:lsid:authority:namespace:my-own-id">
888 if (elTaxonNames
!= null) {
889 List
<Element
> listTaxonNames
= elTaxonNames
.getChildren("TaxonName", sddNamespace
);
892 for (Element elTaxonName
: listTaxonNames
){
894 String id
= elTaxonName
.getAttributeValue("id");
895 String uri
= elTaxonName
.getAttributeValue("uri");
897 NonViralName tnb
= null;
898 if (!id
.equals("")) {
899 tnb
= NonViralName
.NewInstance(null);
900 IdentifiableSource source
= null;
902 if (!uri
.equals("")) {
903 source
= IdentifiableSource
.NewInstance(id
, "TaxonName", ReferenceFactory
.newGeneric(), uri
);
906 source
= IdentifiableSource
.NewInstance(id
, "TaxonName");
908 tnb
.addSource(source
);
909 taxonNameBases
.put(id
,tnb
);
913 // <Label xml:lang="la">Viola hederacea Labill.</Label>
914 importRepresentation(elTaxonName
, sddNamespace
, tnb
, id
, sddConfig
);
916 if ((++j
% modCount
) == 0){ logger
.info("TaxonNames handled: " + j
);}
922 // imports the characters (categorical, quantitative and text ; sequence characters not supported) which correspond to CDM Features
923 protected boolean importCharacters(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
924 boolean success
= true;
926 logger
.info("start Characters ...");
927 Element elCharacters
= elDataset
.getChild("Characters", sddNamespace
);
929 // <CategoricalCharacter id="c1">
930 if (elCharacters
!= null) {
931 success
&= handleCategoricalData(sddNamespace
, sddConfig
, elCharacters
);
932 success
&= handleQuantitativeData(sddNamespace
, sddConfig
, elCharacters
);
933 success
&= handleTextCharacters(sddNamespace
, sddConfig
, elCharacters
);
936 /*for (Iterator<Feature> f = features.values().iterator() ; f.hasNext() ;){
937 featureSet.add(f.next()); //XIM Why this line ?
945 * @param sddNamespace
948 * @param elCharacters
951 private boolean handleCategoricalData(Namespace sddNamespace
, SDDImportConfigurator sddConfig
, Element elCharacters
) {
952 boolean success
= true;
953 List
<Element
> elCategoricalCharacters
= elCharacters
.getChildren("CategoricalCharacter", sddNamespace
);
955 for (Element elCategoricalCharacter
: elCategoricalCharacters
){
958 String idCC
= elCategoricalCharacter
.getAttributeValue("id");
959 Feature categoricalCharacter
= Feature
.NewInstance();
960 categoricalCharacter
.setKindOf(Feature
.DESCRIPTION());
961 importRepresentation(elCategoricalCharacter
, sddNamespace
, categoricalCharacter
, idCC
, sddConfig
);
962 categoricalCharacter
.setSupportsCategoricalData(true);
965 Element elStates
= elCategoricalCharacter
.getChild("States",sddNamespace
);
967 // <StateDefinition id="s1">
968 List
<Element
> elStateDefinitions
= elStates
.getChildren("StateDefinition",sddNamespace
);
969 TermVocabulary
<State
> termVocabularyState
= new TermVocabulary
<State
>();
971 vocabularies
.add(termVocabularyState
);
974 //for each StateDefinition
975 for (Element elStateDefinition
: elStateDefinitions
){
977 if ((++k
% modCount
) == 0){ logger
.info("StateDefinitions handled: " + (k
-1));}
979 String idS
= elStateDefinition
.getAttributeValue("id");
980 State state
= states
.get(idS
);
982 state
= State
.NewInstance();
984 logger
.debug("State duplicate found");
986 importRepresentation(elStateDefinition
, sddNamespace
, state
, idS
, sddConfig
);
988 //StateData stateData = StateData.NewInstance();
989 //stateData.setState(state);
990 termVocabularyState
.addTerm(state
);
991 states
.put(idS
,state
);
993 categoricalCharacter
.addSupportedCategoricalEnumeration(termVocabularyState
);
994 features
.put(idCC
, categoricalCharacter
);
996 } catch (Exception e
) {
997 logger
.warn("Import of CategoricalCharacter " + j
+ " failed.");
1001 if ((++j
% modCount
) == 0){ logger
.info("CategoricalCharacters handled: " + j
);}
1008 * @param sddNamespace
1010 * @param elCharacters
1012 private boolean handleQuantitativeData(Namespace sddNamespace
, SDDImportConfigurator sddConfig
, Element elCharacters
) {
1013 boolean success
= true;
1015 // <QuantitativeCharacter id="c2">
1016 List
<Element
> elQuantitativeCharacters
= elCharacters
.getChildren("QuantitativeCharacter", sddNamespace
);
1018 //for each QuantitativeCharacter
1019 for (Element elQuantitativeCharacter
: elQuantitativeCharacters
){
1023 String idQC
= elQuantitativeCharacter
.getAttributeValue("id");
1026 // <Label>Leaf length</Label>
1027 // </Representation>
1028 Feature quantitativeCharacter
= Feature
.NewInstance();
1029 quantitativeCharacter
.setKindOf(Feature
.DESCRIPTION());
1030 importRepresentation(elQuantitativeCharacter
, sddNamespace
, quantitativeCharacter
, idQC
, sddConfig
);
1032 quantitativeCharacter
.setSupportsQuantitativeData(true);
1034 // <MeasurementUnit>
1035 // <Label role="Abbrev">m</Label>
1036 // </MeasurementUnit>
1037 Element elMeasurementUnit
= elQuantitativeCharacter
.getChild("MeasurementUnit",sddNamespace
);
1040 if (elMeasurementUnit
!= null) {
1041 Element elLabel
= elMeasurementUnit
.getChild("Label",sddNamespace
);
1042 role
= elLabel
.getAttributeValue("role");
1043 label
= (String
)ImportHelper
.getXmlInputValue(elMeasurementUnit
, "Label",sddNamespace
);
1046 MeasurementUnit unit
= null;
1047 if (!label
.equals("")){
1049 if (role
.equals("Abbrev")){
1050 unit
= MeasurementUnit
.NewInstance(label
,label
,label
);
1053 unit
= MeasurementUnit
.NewInstance(label
,label
,label
);
1058 units
.put(idQC
, unit
);
1062 // <MeasurementUnitPrefix>milli</MeasurementUnitPrefix>
1064 Element elDefault
= elQuantitativeCharacter
.getChild("Default",sddNamespace
);
1065 if (elDefault
!= null) {
1066 String measurementUnitPrefix
= (String
)ImportHelper
.getXmlInputValue(elDefault
, "MeasurementUnitPrefix",sddNamespace
);
1067 if (! measurementUnitPrefix
.equals("")){
1068 defaultUnitPrefixes
.put(idQC
, measurementUnitPrefix
);
1072 features
.put(idQC
, quantitativeCharacter
);
1074 } catch (Exception e
) {
1076 logger
.warn("Import of QuantitativeCharacter " + j
+ " failed.");
1080 if ((++j
% modCount
) == 0){ logger
.info("QuantitativeCharacters handled: " + j
);}
1086 private boolean handleTextCharacters(Namespace sddNamespace
, SDDImportConfigurator sddConfig
, Element elCharacters
) {
1087 boolean success
= true;
1089 // <TextCharacter id="c3">
1090 List
<Element
> elTextCharacters
= elCharacters
.getChildren("TextCharacter", sddNamespace
);
1092 //for each TextCharacter
1093 for (Element elTextCharacter
: elTextCharacters
){
1097 String idTC
= elTextCharacter
.getAttributeValue("id");
1100 // <Label xml:lang="en">Leaf features not covered by other characters</Label>
1101 // </Representation>
1102 Feature textCharacter
= Feature
.NewInstance();
1103 textCharacter
.setKindOf(Feature
.DESCRIPTION());
1104 importRepresentation(elTextCharacter
, sddNamespace
, textCharacter
, idTC
, sddConfig
);
1106 textCharacter
.setSupportsTextData(true);
1108 features
.put(idTC
, textCharacter
);
1110 } catch (Exception e
) {
1112 logger
.warn("Import of TextCharacter " + j
+ " failed.");
1116 if ((++j
% modCount
) == 0){ logger
.info("TextCharacters handled: " + j
);}
1122 // imports the descriptions of taxa
1123 protected boolean importCodedDescriptions(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
1124 boolean success
= true;
1126 // <CodedDescriptions>
1127 logger
.info("start CodedDescriptions ...");
1128 Element elCodedDescriptions
= elDataset
.getChild("CodedDescriptions",sddNamespace
);
1130 // <CodedDescription id="D101">
1131 if (elCodedDescriptions
!= null) {
1132 List
<Element
> listCodedDescriptions
= elCodedDescriptions
.getChildren("CodedDescription", sddNamespace
);
1134 //for each CodedDescription
1135 for (Element elCodedDescription
: listCodedDescriptions
){
1136 success
&= handleCodedDescription(sddNamespace
, sddConfig
, elCodedDescription
, j
);
1137 if ((++j
% modCount
) == 0){ logger
.info("CodedDescriptions handled: " + j
);}
1144 * @param sddNamespace
1147 * @param elCodedDescription
1150 private boolean handleCodedDescription(Namespace sddNamespace
, SDDImportConfigurator sddConfig
, Element elCodedDescription
, int j
) {
1151 boolean success
= true ;
1154 String idCD
= elCodedDescription
.getAttributeValue("id");
1157 // <Label><i>Viola hederacea</i> Labill. as revised by R. Morris April 8, 2006</Label>
1158 // </Representation>
1159 TaxonDescription taxonDescription
= TaxonDescription
.NewInstance();
1160 importRepresentation(elCodedDescription
, sddNamespace
, taxonDescription
, idCD
, sddConfig
);
1163 // <TaxonName ref="t1"/>
1164 // <Citation ref="p1" location="p. 30"/>
1166 Element elScope
= elCodedDescription
.getChild("Scope", sddNamespace
);
1168 if (elScope
!= null) {
1169 taxon
= handleCDScope(sddNamespace
, sddConfig
, idCD
, elScope
);
1170 } else {//in case no taxon is linked to the description, a new one is created
1171 taxon
= handleCDNoScope(sddNamespace
, sddConfig
, elCodedDescription
);
1175 Element elSummaryData
= elCodedDescription
.getChild("SummaryData",sddNamespace
);
1176 if (elSummaryData
!= null) {
1177 handleSummaryCategoricalData(sddNamespace
, taxonDescription
, elSummaryData
);
1178 handleSummaryQuantitativeData(sddNamespace
, taxonDescription
, elSummaryData
);
1179 handleSummaryTextData(sddNamespace
, taxonDescription
, elSummaryData
);
1182 if (taxon
!= null) {
1183 taxon
.addDescription(taxonDescription
);
1186 taxonDescription
.setDescriptiveSystem(featureSet
);
1188 taxonDescriptions
.put(idCD
, taxonDescription
);//FIXME
1190 } catch (Exception e
) {
1192 logger
.warn("Import of CodedDescription " + j
+ " failed.", e
);
1199 * @param sddNamespace
1201 * @param elCodedDescription
1205 private Taxon
handleCDNoScope(Namespace sddNamespace
,
1206 SDDImportConfigurator sddConfig
, Element elCodedDescription
) {
1208 NonViralName nonViralName
= NonViralName
.NewInstance(null);
1209 String id
= new String("" + taxonNamesCount
);
1210 IdentifiableSource source
= IdentifiableSource
.NewInstance(id
, "TaxonName");
1211 importRepresentation(elCodedDescription
, sddNamespace
, nonViralName
, id
, sddConfig
);
1213 if(sddConfig
.isDoMatchTaxa()){
1214 taxon
= getTaxonService().findBestMatchingTaxon(nonViralName
.getTitleCache());
1218 nonViralName
= HibernateProxyHelper
.deproxy(taxon
.getName(), NonViralName
.class);
1219 // taxonNameBases.put(id ,tnb);
1220 // taxonNamesCount++;
1221 logger
.info("using existing Taxon" + taxon
.getTitleCache());
1223 nonViralName
.addSource(source
);
1224 taxonNameBases
.put(id
,nonViralName
);
1226 logger
.info("creating new Taxon from TaxonName" + nonViralName
.getTitleCache());
1227 taxon
= Taxon
.NewInstance(nonViralName
, sec
);
1233 * @param sddNamespace
1240 private Taxon
handleCDScope(Namespace sddNamespace
, SDDImportConfigurator sddConfig
,
1241 String idCD
, Element elScope
) {
1243 Element elTaxonName
= elScope
.getChild("TaxonName", sddNamespace
);
1244 String ref
= elTaxonName
.getAttributeValue("ref");
1245 NonViralName nonViralName
= taxonNameBases
.get(ref
);
1247 if(sddConfig
.isDoMatchTaxa()){
1248 taxon
= getTaxonService().findBestMatchingTaxon(nonViralName
.getTitleCache());
1252 logger
.info("using existing Taxon" + taxon
.getTitleCache());
1253 if(!nonViralName
.getUuid().equals(taxon
.getName().getUuid())){
1254 logger
.warn("TaxonNameBase entity of existing taxon does not match Name in list -> replacing Name in list");
1255 nonViralName
= HibernateProxyHelper
.deproxy(taxon
.getName(), NonViralName
.class);
1258 logger
.info("creating new Taxon from TaxonName" + nonViralName
.getTitleCache());
1259 taxon
= Taxon
.NewInstance(nonViralName
, sec
);
1263 Element elCitation
= elScope
.getChild("Citation",sddNamespace
);
1264 if (elCitation
!= null) {
1265 String refCitation
= elCitation
.getAttributeValue("ref");
1266 if (! refCitation
.equals("")){
1267 citations
.put(idCD
, refCitation
);
1269 String location
= elCitation
.getAttributeValue("location");
1270 if (! location
.equals("")){
1271 locations
.put(idCD
, location
);
1278 * @param sddNamespace
1279 * @param taxonDescription
1280 * @param elSummaryData
1282 private void handleSummaryTextData(Namespace sddNamespace
,
1283 TaxonDescription taxonDescription
, Element elSummaryData
) {
1286 // <TextChar ref="c3">
1287 List
<Element
> elTextChars
= elSummaryData
.getChildren("TextChar", sddNamespace
);
1290 for (Element elTextChar
: elTextChars
){
1291 if ((++k
% modCount
) == 0){ logger
.info("TextChar handled: " + (k
-1));}
1292 ref
= elTextChar
.getAttributeValue("ref");
1293 Feature feature
= features
.get(ref
);
1294 TextData textData
= TextData
.NewInstance();
1295 textData
.setFeature(feature
);
1297 // <Content>Free form text</Content>
1298 String content
= (String
)ImportHelper
.getXmlInputValue(elTextChar
, "Content",sddNamespace
);
1299 textData
.putText(content
, datasetLanguage
);
1300 taxonDescription
.addElement(textData
);
1305 * @param sddNamespace
1306 * @param taxonDescription
1307 * @param elSummaryData
1309 private void handleSummaryQuantitativeData(Namespace sddNamespace
,
1310 TaxonDescription taxonDescription
, Element elSummaryData
) {
1313 // <Quantitative ref="c2">
1314 List
<Element
> elQuantitatives
= elSummaryData
.getChildren("Quantitative", sddNamespace
);
1316 //for each Quantitative
1317 for (Element elQuantitative
: elQuantitatives
){
1318 if ((++k
% modCount
) == 0){ logger
.warn("Quantitative handled: " + (k
-1));}
1319 ref
= elQuantitative
.getAttributeValue("ref");
1320 Feature feature
= features
.get(ref
);
1321 QuantitativeData quantitativeData
= QuantitativeData
.NewInstance();
1322 quantitativeData
.setFeature(feature
);
1324 MeasurementUnit unit
= units
.get(ref
);
1325 String prefix
= defaultUnitPrefixes
.get(ref
);
1327 String u
= unit
.getLabel();
1328 if (prefix
!= null) {
1332 quantitativeData
.setUnit(unit
);
1335 // <Measure type="Min" value="2.3"/>
1336 List
<Element
> elMeasures
= elQuantitative
.getChildren("Measure", sddNamespace
);
1340 for (Element elMeasure
: elMeasures
){
1341 if ((++l
% modCount
) == 0){ logger
.info("States handled: " + (l
-1));}
1342 String type
= elMeasure
.getAttributeValue("type");
1343 String value
= elMeasure
.getAttributeValue("value");
1344 if (value
.contains(",")) {
1345 value
= value
.replace(',', '.');
1347 Float v
= Float
.parseFloat(value
);
1348 //Float v = new Float(0);
1349 StatisticalMeasure t
= null;
1350 if (type
.equals("Min")) {
1351 t
= StatisticalMeasure
.MIN();
1352 } else if (type
.equals("Mean")) {
1353 t
= StatisticalMeasure
.AVERAGE();
1354 } else if (type
.equals("Max")) {
1355 t
= StatisticalMeasure
.MAX();
1356 } else if (type
.equals("SD")) {
1357 t
= StatisticalMeasure
.STANDARD_DEVIATION();
1358 } else if (type
.equals("N")) {
1359 t
= StatisticalMeasure
.SAMPLE_SIZE();
1360 } else if (type
.equals("UMethLower")) {
1361 t
= StatisticalMeasure
.TYPICAL_LOWER_BOUNDARY();
1362 } else if (type
.equals("UMethUpper")) {
1363 t
= StatisticalMeasure
.TYPICAL_UPPER_BOUNDARY();
1364 } else if (type
.equals("Var")) {
1365 t
= StatisticalMeasure
.VARIANCE();
1367 t
= StatisticalMeasure
.NewInstance(type
,type
,type
);
1368 statisticalMeasures
.add(t
);
1371 StatisticalMeasurementValue statisticalValue
= StatisticalMeasurementValue
.NewInstance();
1372 statisticalValue
.setValue(v
);
1373 statisticalValue
.setType(t
);
1374 quantitativeData
.addStatisticalValue(statisticalValue
);
1375 featureData
.add(statisticalValue
);
1377 taxonDescription
.addElement(quantitativeData
);
1382 * @param sddNamespace
1383 * @param taxonDescription
1384 * @param elSummaryData
1386 private void handleSummaryCategoricalData(Namespace sddNamespace
,
1387 TaxonDescription taxonDescription
, Element elSummaryData
) {
1389 // <Categorical ref="c4">
1390 List
<Element
> elCategoricals
= elSummaryData
.getChildren("Categorical", sddNamespace
);
1392 //for each Categorical
1393 for (Element elCategorical
: elCategoricals
){
1394 if ((++k
% modCount
) == 0){ logger
.warn("Categorical handled: " + (k
-1));}
1395 ref
= elCategorical
.getAttributeValue("ref");
1396 Feature feature
= features
.get(ref
);
1397 CategoricalData categoricalData
= CategoricalData
.NewInstance();
1398 categoricalData
.setFeature(feature
);
1400 // <State ref="s3"/>
1401 List
<Element
> elStates
= elCategorical
.getChildren("State", sddNamespace
);
1405 for (Element elState
: elStates
){
1406 if ((++l
% modCount
) == 0){ logger
.info("States handled: " + (l
-1));}
1407 ref
= elState
.getAttributeValue("ref");
1408 State state
= states
.get(ref
);
1409 if (state
!= null) {
1410 StateData stateData
= StateData
.NewInstance();
1411 stateData
.setState(state
);
1412 List
<Element
> elModifiers
= elState
.getChildren("Modifier", sddNamespace
);
1413 for (Element elModifier
: elModifiers
){
1414 ref
= elModifier
.getAttributeValue("ref");
1415 Modifier modifier
= modifiers
.get(ref
);
1416 if (modifier
!= null) {
1417 stateData
.addModifier(modifier
);
1420 categoricalData
.addState(stateData
);
1422 taxonDescription
.addElement(categoricalData
);
1427 // imports the persons associated with the dataset creation, modification, related publications
1428 protected void importAgents(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1430 logger
.info("start Agents ...");
1431 Element elAgents
= elDataset
.getChild("Agents",sddNamespace
);
1432 if (elAgents
!= null) {
1434 List
<Element
> listAgents
= elAgents
.getChildren("Agent", sddNamespace
);
1437 for (Element elAgent
: listAgents
){
1441 String idA
= elAgent
.getAttributeValue("id");
1444 // <Label>Kevin Thiele</Label>
1445 // <Detail role="Description">Ali Baba is also known as r.a.m.</Detail>
1446 // </Representation>
1447 Person person
= Person
.NewInstance();
1448 importRepresentation(elAgent
, sddNamespace
, person
, idA
, sddConfig
);
1449 person
.addSource(IdentifiableSource
.NewInstance(idA
, "Agent"));
1452 Element elLinks = elAgent.getChild("Links",sddNamespace);
1454 if (elLinks != null) {
1456 // <Link rel="Alternate" href="http://www.diversitycampus.net/people/hagedorn"/>
1457 List<Element> listLinks = elLinks.getChildren("Link", sddNamespace);
1460 for (Element elLink : listLinks){
1464 String rel = elLink.getAttributeValue("rel");
1465 String href = elLink.getAttributeValue("href");
1467 Media link = Media.NewInstance();
1468 MediaRepresentation mr = MediaRepresentation.NewInstance();
1469 mr.addRepresentationPart(MediaRepresentationPart.NewInstance(href, null));
1470 link.addRepresentation(mr);
1471 person.addMedia(link);
1473 } catch (Exception e) {
1475 logger.warn("Import of Link " + k + " failed.");
1479 if ((++k % modCount) == 0){ logger.info("Links handled: " + k);}
1484 if (authors
.containsKey(idA
)) {
1485 authors
.put(idA
,person
);
1488 if (editors
.containsKey(idA
)) {
1489 editors
.put(idA
, person
);
1492 } catch (Exception e
) {
1494 logger
.warn("Import of Agent " + j
+ " failed.");
1498 if ((++j
% modCount
) == 0){ logger
.info("Agents handled: " + j
);}
1504 // imports publications related with the data set
1505 protected void importPublications(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1507 <Publication id="p112">
1509 <Label>Gee, X. & Haa, Y. (2003). How to be happy in five minutes. Instant Gratifications, Palm Beach.</Label>
1512 <Link rel="BasedOn" href="doi:10.1992/32311"/>
1513 <Link rel="Alternate" href="http://some.service.net/providing/bibliographic.data"/>
1517 logger
.info("start Publications ...");
1518 Element elPublications
= elDataset
.getChild("Publications",sddNamespace
);
1520 if (elPublications
!= null) {
1521 List
<Element
> listPublications
= elPublications
.getChildren("Publication", sddNamespace
);
1523 for (Element elPublication
: listPublications
){
1527 String idP
= elPublication
.getAttributeValue("id");
1528 ReferenceBase publication
= ReferenceFactory
.newArticle();
1529 importRepresentation(elPublication
, sddNamespace
, publication
, idP
, sddConfig
);
1531 publications
.put(idP
,publication
);
1533 } catch (Exception e
) {
1534 logger
.warn("Import of Publication " + j
+ " failed.");
1538 if ((++j
% modCount
) == 0){ logger
.info("Publications handled: " + j
);}
1544 // imports media objects such as images //FIXME check mediaobj
1545 protected void importMediaObjects(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1547 logger
.info("start MediaObjects ...");
1548 Element elMediaObjects
= elDataset
.getChild("MediaObjects",sddNamespace
);
1550 if (elMediaObjects
!= null) {
1551 // <MediaObject id="m1">
1552 List
<Element
> listMediaObjects
= elMediaObjects
.getChildren("MediaObject", sddNamespace
);
1554 for (Element elMO
: listMediaObjects
){
1559 String idMO
= elMO
.getAttributeValue("id");
1563 // <Label>Image description, e.g. to be used for alt-attribute in html.</Label>
1564 // </Representation>
1565 Media media
= Media
.NewInstance();
1566 importRepresentation(elMO
, sddNamespace
, media
, idMO
, sddConfig
);
1568 // <Type>Image</Type>
1569 // <Source href="http://test.edu/test.jpg"/>
1570 String type
= (String
)ImportHelper
.getXmlInputValue(elMO
,"Type",sddNamespace
);
1572 if ((type
!= null) && (type
.equals("Image"))) {
1573 Element elSource
= elMO
.getChild("Source",sddNamespace
);
1574 String href
= elSource
.getAttributeValue("href");
1576 ImageMetaData imageMetaData
= ImageMetaData
.newInstance();
1577 ImageFile image
= null;
1578 if (href
.substring(0,7).equals("http://")) {
1580 URL url
= new URL(href
);
1582 imageMetaData
.readMetaData(url
.toURI(), 0);
1583 image
= ImageFile
.NewInstance(url
.toString(), null, imageMetaData
);
1584 } catch (MalformedURLException e
) {
1585 logger
.error("Malformed URL", e
);
1588 String sns
= sddConfig
.getSourceNameString();
1589 File f
= new File(sns
);
1590 File parent
= f
.getParentFile();
1592 //String fi = parent.toString() + File.separator + href; //TODO erase file:/
1593 File file
= new File(fi
);
1594 imageMetaData
.readMetaData(file
.toURI(), 0);
1595 image
= ImageFile
.NewInstance(file
.toString(), null, imageMetaData
);
1597 MediaRepresentation representation
= MediaRepresentation
.NewInstance(imageMetaData
.getMimeType(), null);
1598 representation
.addRepresentationPart(image
);
1600 media
.addRepresentation(representation
);
1602 ArrayList
<CdmBase
> lcb
= (ArrayList
<CdmBase
>) mediaObject_ListCdmBase
.get(idMO
);
1604 for (int k
= 0; k
< lcb
.size(); k
++) {
1605 if (lcb
.get(k
) instanceof DefinedTermBase
) {
1606 DefinedTermBase dtb
= (DefinedTermBase
) lcb
.get(k
);
1607 // if (lcb.get(0) instanceof DefinedTermBase) {
1608 // DefinedTermBase dtb = (DefinedTermBase) lcb.get(0);
1611 dtb
.addMedia(media
);
1612 //System.out.println(dtb.getLabel());
1614 // Media me = (Media) media.clone();
1615 // dtb.addMedia(me);
1618 } else if (lcb
.get(k
) instanceof ReferenceBase
) {
1619 ReferenceBase rb
= (ReferenceBase
) lcb
.get(k
);
1620 //} else if (lcb.get(0) instanceof ReferenceBase) {
1621 //ReferenceBase rb = (ReferenceBase) lcb.get(0);
1622 // rb.setTitleCache(label);
1626 //System.out.println(rb.getTitle());
1628 // Media me = (Media) media.clone();
1632 }/* else if (lcb.get(k) instanceof TaxonNameBase){
1633 TaxonNameBase tb = (TaxonNameBase) lcb.get(k);
1640 } catch (Exception e
) {
1642 logger
.warn("Could not attach MediaObject " + j
+ "(SDD: " + id
+ ") to several objects.");
1646 if ((++j
% modCount
) == 0){ logger
.info("MediaObjects handled: " + j
);
1653 // imports the <DescriptiveConcepts> block ; DescriptiveConcepts are used as nodes in CharacterTrees and Characters as leaves
1654 // but since Modifiers can be linked to DescriptiveConcepts they are stored as features with a particular Marker
1655 protected void importDescriptiveConcepts(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
){
1656 /* <DescriptiveConcepts>
1657 <DescriptiveConcept id="dc0">
1659 <Label>Fixed set of modifiers supported in Lucid3</Label>
1662 <Modifier id="mod1">
1664 <Label>rarely</Label>
1666 <ModifierClass>Frequency</ModifierClass>
1667 <ProportionRange lowerestimate="0.0" upperestimate="0.25"/>
1670 </DescriptiveConcept>
1671 </DescriptiveConcepts>
1673 logger
.info("start DescriptiveConcepts ...");
1674 Element elDescriptiveConcepts
= elDataset
.getChild("DescriptiveConcepts",sddNamespace
);
1675 if (elDescriptiveConcepts
!= null) {
1676 List
<Element
> listDescriptiveConcepts
= elDescriptiveConcepts
.getChildren("DescriptiveConcept", sddNamespace
);
1679 for (Element elDescriptiveConcept
: listDescriptiveConcepts
){
1681 String id
= elDescriptiveConcept
.getAttributeValue("id");
1682 Feature feature
= Feature
.NewInstance();
1683 feature
.setKindOf(Feature
.DESCRIPTION());
1684 if (!id
.equals("")) {
1686 // <Label>Body</Label>
1687 importRepresentation(elDescriptiveConcept
, sddNamespace
, feature
, id
, sddConfig
);
1688 features
.put(id
, feature
);
1689 getTermService().save(feature
);//XIM
1690 descriptiveConcepts
.add(feature
);
1691 // imports the modifiers
1692 Element elModifiers
= elDescriptiveConcept
.getChild("Modifiers", sddNamespace
);
1693 if (elModifiers
!=null){
1694 List
<Element
> listModifiers
= elModifiers
.getChildren("Modifier", sddNamespace
);
1695 TermVocabulary
<Modifier
> termVocabularyState
= new TermVocabulary
<Modifier
>();
1696 for (Element elModifier
: listModifiers
) {
1697 Modifier modif
= Modifier
.NewInstance();
1698 String idmod
= elModifier
.getAttributeValue("id");
1699 importRepresentation(elModifier
, sddNamespace
, modif
, idmod
, sddConfig
);
1700 termVocabularyState
.addTerm(modif
);
1701 //termVocabularyStates.add(termVocabularyState);
1702 getVocabularyService().save(termVocabularyState
);//XIM
1703 modifiers
.put(idmod
, modif
);
1705 feature
.addRecommendedModifierEnumeration(termVocabularyState
);
1710 catch (Exception e
) {
1711 logger
.warn("Import of DescriptiveConcept " + j
+ " failed.");
1713 if ((++j
% modCount
) == 0){ logger
.info("DescriptiveConcepts handled: " + j
);}
1719 // imports the <CharacterTrees> block
1720 protected void importCharacterTrees(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1722 logger
.info("start CharacterTrees ...");
1723 Element elCharacterTrees
= elDataset
.getChild("CharacterTrees",sddNamespace
);
1725 if (elCharacterTrees
!= null) {
1726 List
<Element
> listCharacterTrees
= elCharacterTrees
.getChildren("CharacterTree", sddNamespace
);
1728 for (Element elCharacterTree
: listCharacterTrees
){
1730 Element elRepresentation
= elCharacterTree
.getChild("Representation",sddNamespace
);
1731 String label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
,"Label",sddNamespace
);
1732 //Element elDesignedFor = elCharacterTree.getChild("DesignedFor",sddNamespace);//TODO ?
1734 FeatureTree feattree
= FeatureTree
.NewInstance();
1735 importRepresentation(elCharacterTree
, sddNamespace
, feattree
, "", sddConfig
);
1736 FeatureNode root
= feattree
.getRoot();
1737 List
<Element
> listelNodes
= elCharacterTree
.getChildren("Nodes", sddNamespace
);
1739 //Nodes of CharacterTrees in SDD always refer to DescriptiveConcepts
1740 for (Element elNodes
: listelNodes
) {
1741 handleCharacterNodes(sddNamespace
, root
, elNodes
);
1743 featureTrees
.add(feattree
);
1746 catch (Exception e
) {
1747 logger
.warn("Import of Character tree " + j
+ " failed.");
1750 if ((++j
% modCount
) == 0){ logger
.info("CharacterTrees handled: " + j
);}
1758 * @param sddNamespace
1762 private void handleCharacterNodes(Namespace sddNamespace
, FeatureNode root
, Element elNodes
) {
1763 List
<Element
> listNodes
= elNodes
.getChildren("Node", sddNamespace
);
1764 if (listNodes
!= null) {
1765 for (Element elNode
: listNodes
){
1766 String idN
= elNode
.getAttributeValue("id");
1767 FeatureNode fn
= null;
1770 // DescriptiveConcepts are used as nodes in CharacterTrees
1771 Element elDescriptiveConcept
= elNode
.getChild("DescriptiveConcept", sddNamespace
);
1772 if (elDescriptiveConcept
!= null){
1773 String refDC
= elDescriptiveConcept
.getAttributeValue("ref");
1774 dc
= features
.get(refDC
);
1775 fn
= FeatureNode
.NewInstance(dc
);
1778 fn
= FeatureNode
.NewInstance();
1780 Element elParent
= elNode
.getChild("Parent", sddNamespace
);
1781 // in SDD links between Nodes are referenced by the <Parent> tag
1782 if (elParent
!=null){
1783 String refP
= elParent
.getAttributeValue("ref");
1785 FeatureNode parent
= featureNodes
.get(refP
);
1787 root
.addChild(fn
); // if no parent found or the reference is broken, add the node to the root of the tree
1790 parent
.addChild(fn
);
1795 root
.addChild(fn
); // if no parent found or the reference is broken, add the node to the root of the tree
1798 featureNodes
.put(idN
, fn
);
1802 // Leaves of CharacterTrees in SDD are always CharNodes (referring to Characters)
1803 List
<Element
> listCharNodes
= elNodes
.getChildren("CharNode", sddNamespace
);
1804 if (listCharNodes
!= null) {
1805 for (Element elCharNode
: listCharNodes
){
1806 Element elParent
= elCharNode
.getChild("Parent", sddNamespace
);
1807 Element elCharacter
= elCharNode
.getChild("Character", sddNamespace
);
1808 FeatureNode fn
= FeatureNode
.NewInstance();
1809 if (elParent
!=null){
1810 String refP
= elParent
.getAttributeValue("ref");
1811 if ((refP
!=null)&&(!refP
.equals(""))) {
1812 FeatureNode parent
= featureNodes
.get(refP
);
1814 parent
= root
; // if no parent found or the reference is broken, add the node to the root of the tree
1816 parent
.addChild(fn
);
1819 String refC
= elCharacter
.getAttributeValue("ref");
1820 if ((refC
!=null)&&(!refC
.equals(""))){
1821 Feature character
= features
.get(refC
);
1822 fn
.setFeature(character
);
1823 featureNodes
.put(refC
, fn
);
1829 // imports the <TaxonHierarchies> block
1830 protected void importTaxonHierarchies(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
, boolean success
){
1832 logger
.info("start TaxonHierarchies ...");
1833 Element elTaxonHierarchies
= elDataset
.getChild("TaxonHierarchies",sddNamespace
);
1835 if (elTaxonHierarchies
!= null) {
1836 List
<Element
> listTaxonHierarchies
= elTaxonHierarchies
.getChildren("TaxonHierarchy", sddNamespace
);
1838 for (Element elTaxonHierarchy
: listTaxonHierarchies
){
1840 Element elRepresentation
= elTaxonHierarchy
.getChild("Representation",sddNamespace
);
1841 String label
= (String
)ImportHelper
.getXmlInputValue(elRepresentation
,"Label",sddNamespace
);
1842 TaxonomicTree taxonomicTree
= TaxonomicTree
.NewInstance(label
);
1843 importRepresentation(elTaxonHierarchy
, sddNamespace
, taxonomicTree
, "", sddConfig
);
1845 Set
<TaxonNode
> root
= taxonomicTree
.getChildNodes();
1846 Element elNodes
= elTaxonHierarchy
.getChild("Nodes", sddNamespace
); // There can be only one <Nodes> block for TaxonHierarchies
1847 List
<Element
> listNodes
= elNodes
.getChildren("Node", sddNamespace
);
1849 for (Element elNode
: listNodes
){
1850 String idN
= elNode
.getAttributeValue("id");
1851 TaxonNameBase tnb
= null;
1852 if (!idN
.equals("")) {
1853 Element elTaxonName
= elNode
.getChild("TaxonName", sddNamespace
);
1854 String refTN
= elTaxonName
.getAttributeValue("ref");
1855 tnb
= taxonNameBases
.get(refTN
);
1856 Taxon taxon
= (Taxon
) tnb
.getTaxa().iterator().next() ;
1857 Element elParent
= elNode
.getChild("Parent", sddNamespace
);
1858 if (elParent
!=null){
1859 String refP
= elParent
.getAttributeValue("ref");
1860 if (!refP
.equals("")) {
1861 TaxonNode parent
= taxonNodes
.get(refP
);
1862 TaxonNode child
= parent
.addChildTaxon(taxon
, sec
, "", Synonym
.NewInstance(tnb
, sec
));
1863 taxonNodes
.put(idN
,child
);
1867 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
1868 taxonNodes
.put(idN
,tn
);
1873 taxonomicTrees
.add(taxonomicTree
);
1876 catch (Exception e
) {
1878 logger
.warn("Import of Taxon Hierarchy " + j
+ " failed.");
1882 if ((++j
% modCount
) == 0){ logger
.info("TaxonHierarchies handled: " + j
);}
1890 // imports the <GeographicAreas> block
1891 protected void importGeographicAreas(Element elDataset
, Namespace sddNamespace
, SDDImportConfigurator sddConfig
) {
1892 Element elGeographicAreas
= elDataset
.getChild("GeographicAreas",sddNamespace
);
1893 if (elGeographicAreas
!= null) {
1894 List
<Element
> listGeographicAreas
= elGeographicAreas
.getChildren("GeographicArea", sddNamespace
);
1897 for (Element elGeographicArea
: listGeographicAreas
){
1899 String id
= elGeographicArea
.getAttributeValue("id");
1900 NamedArea na
= new NamedArea();
1901 importRepresentation(elGeographicArea
, sddNamespace
, na
, id
, sddConfig
);
1902 namedAreas
.put(id
,na
);
1904 if ((++j
% modCount
) == 0){ logger
.info("GeographicAreas handled: " + j
);}