Project

General

Profile

Download (63.4 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2007 EDIT
3
 * European Distributed Institute of Taxonomy 
4
 * http://www.e-taxonomy.eu
5
 * 
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.
8
 */
9

    
10
package eu.etaxonomy.cdm.io.sdd;
11

    
12
import java.io.File;
13
import java.net.MalformedURLException;
14
import java.net.URI;
15
import java.net.URL;
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.Iterator;
22
import java.util.List;
23
import java.util.Map;
24
import java.util.Set;
25

    
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;
32

    
33
import eu.etaxonomy.cdm.api.service.IAgentService;
34
import eu.etaxonomy.cdm.api.service.IVersionableService;//rajout
35
import eu.etaxonomy.cdm.api.service.IDescriptionService;
36
import eu.etaxonomy.cdm.api.service.IReferenceService;
37
import eu.etaxonomy.cdm.api.service.ITermService;
38
import eu.etaxonomy.cdm.common.mediaMetaData.ImageMetaData;
39
import eu.etaxonomy.cdm.io.common.CdmImportBase;
40
import eu.etaxonomy.cdm.io.common.ICdmImport;
41
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
42
import eu.etaxonomy.cdm.io.common.ImportHelper;
43
import eu.etaxonomy.cdm.model.agent.Contact;
44
import eu.etaxonomy.cdm.model.agent.Institution;
45
import eu.etaxonomy.cdm.model.agent.Person;
46
import eu.etaxonomy.cdm.model.agent.Address;//rajout
47
import eu.etaxonomy.cdm.model.agent.Team;
48
import eu.etaxonomy.cdm.model.common.Annotation;
49
import eu.etaxonomy.cdm.model.common.AnnotationType;
50
import eu.etaxonomy.cdm.model.common.CdmBase;
51
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
52
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
53
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
54
import eu.etaxonomy.cdm.model.common.Language;
55
import eu.etaxonomy.cdm.model.common.LanguageString;
56
import eu.etaxonomy.cdm.model.common.Marker;
57
import eu.etaxonomy.cdm.model.common.MarkerType;
58
import eu.etaxonomy.cdm.model.common.Representation;
59
import eu.etaxonomy.cdm.model.common.TermBase;
60
import eu.etaxonomy.cdm.model.common.TermVocabulary;
61
import eu.etaxonomy.cdm.model.common.User;
62
import eu.etaxonomy.cdm.model.common.VersionableEntity;
63
import eu.etaxonomy.cdm.model.description.CategoricalData;
64
import eu.etaxonomy.cdm.model.description.Feature;
65
import eu.etaxonomy.cdm.model.description.FeatureNode;
66
import eu.etaxonomy.cdm.model.description.FeatureTree;
67
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
68
import eu.etaxonomy.cdm.model.description.QuantitativeData;
69
import eu.etaxonomy.cdm.model.description.State;
70
import eu.etaxonomy.cdm.model.description.StateData;
71
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
72
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
73
import eu.etaxonomy.cdm.model.description.TaxonDescription;
74
import eu.etaxonomy.cdm.model.description.TextData;
75
import eu.etaxonomy.cdm.model.description.Modifier;
76
import eu.etaxonomy.cdm.model.taxon.TaxonomicTree;
77
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
78
import eu.etaxonomy.cdm.model.media.ImageFile;
79
import eu.etaxonomy.cdm.model.media.Media;
80
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
81
import eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity;
82
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
83
import eu.etaxonomy.cdm.model.media.Rights;
84
import eu.etaxonomy.cdm.model.name.NonViralName;
85
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
86
import eu.etaxonomy.cdm.model.occurrence.Specimen;
87
import eu.etaxonomy.cdm.model.reference.IArticle;
88
import eu.etaxonomy.cdm.model.reference.IDatabase;
89
import eu.etaxonomy.cdm.model.reference.IGeneric;
90
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
91
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
92
import eu.etaxonomy.cdm.model.taxon.Taxon;
93
import eu.etaxonomy.cdm.model.taxon.Synonym;
94
import eu.etaxonomy.cdm.model.location.NamedArea;
95

    
96
/**
97
 * @author h.fradin
98
 * @created 24.10.2008
99
 * @version 1.0
100
 */
101
@Component("sddDescriptionIO")
102
public class SDDDescriptionIO extends CdmImportBase<SDDImportConfigurator, SDDImportState> implements ICdmImport<SDDImportConfigurator, SDDImportState> {
103
	private static final Logger logger = Logger.getLogger(SDDDescriptionIO.class);
104

    
105
	private static int modCount = 1000;
106

    
107
	private Map<String,Person> authors = new HashMap<String,Person>();
108
	private Map<String,String> citations = new HashMap<String,String>();
109
	private Map<String,String> defaultUnitPrefixes = new HashMap<String,String>();
110
	private Map<String,Person> editors = new HashMap<String,Person>();
111
	private Map<String,FeatureNode> featureNodes = new HashMap<String,FeatureNode>();
112
	private Map<String,Feature> features = new HashMap<String,Feature>();
113
	private Map<String,String> locations = new HashMap<String,String>();
114
	private Map<String,List<CdmBase>> mediaObject_ListCdmBase = new HashMap<String,List<CdmBase>>();
115
	private Map<String,String> mediaObject_Role = new HashMap<String,String>();
116
	private Map<String,ReferenceBase> publications = new HashMap<String,ReferenceBase>();
117
	private Map<String,StateData> stateDatas = new HashMap<String,StateData>();
118
	private Map<String,State> states = new HashMap<String,State>();
119
	private Map<String,TaxonDescription> taxonDescriptions = new HashMap<String,TaxonDescription>();
120
	private Map<String,NonViralName> taxonNameBases = new HashMap<String,NonViralName>();
121
	private Map<String,MeasurementUnit> units = new HashMap<String,MeasurementUnit>();
122
	private Map<String,TaxonNode> taxonNodes = new HashMap<String,TaxonNode>();
123
	private Map<String,NamedArea> namedAreas = new HashMap<String,NamedArea>();
124
	private Map<String,Specimen> specimens = new HashMap<String,Specimen>();
125
	private Map<String,Modifier> modifiers = new HashMap<String,Modifier>();
126
	
127
	private Set<MarkerType> markerTypes = new HashSet<MarkerType>();
128

    
129
	private Set<Feature> descriptiveConcepts = new HashSet<Feature>();
130
	private Set<TermVocabulary<Modifier>> termVocabularyStates = new HashSet<TermVocabulary<Modifier>>();
131
	private Set<AnnotationType> annotationTypes = new HashSet<AnnotationType>();
132
	private Set<Feature> featureSet = new HashSet<Feature>();
133
	ReferenceFactory refFactory = ReferenceFactory.newInstance();
134
	private ReferenceBase sec = refFactory.newDatabase();
135
	private ReferenceBase sourceReference = null;
136

    
137
	private Language datasetLanguage = null;
138

    
139
	private Namespace xmlNamespace = Namespace.getNamespace("xml","http://www.w3.org/XML/1998/namespace");
140

    
141
	private String generatorName = "";
142
	private String generatorVersion = "";
143

    
144
	private Set<StatisticalMeasure> statisticalMeasures = new HashSet<StatisticalMeasure>();
145
	private Set<VersionableEntity> featureData = new HashSet<VersionableEntity>();
146
	private Set<FeatureTree> featureTrees = new HashSet<FeatureTree>();
147
	private Set<TaxonomicTree> taxonomicTrees = new HashSet<TaxonomicTree>();
148

    
149
	private Rights copyright = null;
150

    
151
	private int taxonNamesCount = 0; //XIM ajout
152
	
153
	public SDDDescriptionIO(){
154
		super();
155
	}
156

    
157
	@Override
158
	public boolean doCheck(SDDImportState state){
159
		boolean result = true;
160
		logger.warn("No check implemented for SDD");
161
		return result;
162
	}
163

    
164
	//	@Override
165
	//	public boolean doInvoke(IImportConfigurator config, Map<String, MapWrapper<? extends CdmBase>> stores){
166
	@Override
167
	public boolean doInvoke(SDDImportState state){
168

    
169
		TransactionStatus ts = startTransaction();
170
		SDDImportConfigurator sddConfig = state.getConfig();
171

    
172
		logger.info("start Datasets ...");
173
		// <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">
174
		Element root = sddConfig.getSourceRoot();
175
		boolean success = true;
176
		Namespace sddNamespace = sddConfig.getSddNamespace();
177

    
178
		logger.info("start TechnicalMetadata ...");
179
		// <TechnicalMetadata created="2006-04-20T10:00:00">
180
		importTechnicalMetadata(root, sddNamespace, sddConfig);
181
		List<Element> elDatasets = root.getChildren("Dataset",sddNamespace);
182
		int i = 0;
183

    
184
		//for each Dataset
185
		logger.info("start Dataset ...");
186
		for (Element elDataset : elDatasets){
187
			importDataset(elDataset, sddNamespace, success, sddConfig);			
188
			if ((++i % modCount) == 0){ logger.info("Datasets handled: " + i);}
189
			logger.info(i + " Datasets handled");
190
		}
191
		commitTransaction(ts);
192
		return success;
193
	}
194

    
195
	/* (non-Javadoc)
196
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
197
	 */
198
	protected boolean isIgnore(SDDImportState state){
199
		return false;
200
	}
201

    
202

    
203
	// associates the reference of a media object in SDD with a CdmBase Object
204
	protected void associateImageWithCdmBase(String refMO, CdmBase cb){
205
		if ((refMO != null) && (cb!=null)) {
206
			if (!refMO.equals("")) {
207
				if (!mediaObject_ListCdmBase.containsKey(refMO)) {
208
					List<CdmBase> lcb = new ArrayList<CdmBase>();
209
					lcb.add(cb);
210
					mediaObject_ListCdmBase.put(refMO,lcb);
211
				} else {
212
					List<CdmBase> lcb = mediaObject_ListCdmBase.get(refMO);
213
					lcb.add(cb);
214
					mediaObject_ListCdmBase.put(refMO,lcb);
215
				}
216
			}
217
		}
218
	}
219

    
220
	// imports information about the Dataset
221
	protected void importDatasetRepresentation(Element parent, Namespace sddNamespace){
222
		logger.info("start Representation ...");
223
		/* <Representation>
224
			<Label>The Genus Viola</Label>
225
			<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>
226
	       </Representation>
227
		 */
228
		Element elRepresentation = parent.getChild("Representation",sddNamespace);
229
		String label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace);
230
		String detail = (String)ImportHelper.getXmlInputValue(elRepresentation, "Detail",sddNamespace);
231

    
232
		sec.setTitleCache(label, true);
233

    
234
		if (detail != null) {
235
			Annotation annotation = Annotation.NewInstance(detail, datasetLanguage);
236
			annotation.setAnnotationType(AnnotationType.EDITORIAL());
237
			sec.addAnnotation(annotation);
238
		}
239

    
240
		List<Element> listMediaObjects = elRepresentation.getChildren("MediaObject",sddNamespace);
241

    
242
		for (Element elMediaObject : listMediaObjects) {
243
			String ref = null;
244
			String role = null;
245
			if (elMediaObject != null) {
246
				ref = elMediaObject.getAttributeValue("ref");
247
				role = elMediaObject.getAttributeValue("role");
248
			}
249
			if (ref != null) {
250
				if (!ref.equals("")) {
251
					this.associateImageWithCdmBase(ref,sourceReference);
252
					this.associateImageWithCdmBase(ref,sec);
253
					mediaObject_Role.put(ref,role);
254
				}
255
			}
256
		}
257
	}
258

    
259
	// imports the representation (label, detail, lang) of a particular SDD element
260
	protected void importRepresentation(Element parent, Namespace sddNamespace, VersionableEntity ve, String id, IImportConfigurator config){
261
		Element elRepresentation = parent.getChild("Representation",sddNamespace);
262
		// <Label xml:lang="la">Viola hederacea Labill.</Label>
263
		List<Element> listLabels = elRepresentation.getChildren("Label",sddNamespace);
264
		List<Element> listDetails = elRepresentation.getChildren("Detail",sddNamespace);
265
		Map<Language,List<String>> langLabDet = new HashMap<Language,List<String>>();
266

    
267
		for (Element elLabel : listLabels){
268
			String lang = elLabel.getAttributeValue("lang",xmlNamespace);
269
			Language language = null;
270
			if (lang != null) {
271
				if (!lang.equals("")) {
272
					language = getTermService().getLanguageByIso(lang.substring(0, 2));
273
				} else {
274
					language = datasetLanguage;
275
				}
276
			} else {
277
				language = datasetLanguage;
278
			}
279
			String label = elLabel.getText();
280
			List<String> labDet = new ArrayList<String>(3);
281
			labDet.add(label);
282
			langLabDet.put(language, labDet);
283
		}
284

    
285
		for (Element elDetail : listDetails){
286
			String lang = elDetail.getAttributeValue("lang",xmlNamespace);
287
			String role = elDetail.getAttributeValue("role");
288
			Language language = null;
289
			if (lang != null) {
290
				if (!lang.equals("")) {
291
					language = getTermService().getLanguageByIso(lang.substring(0, 2));
292
				} else {
293
					language = datasetLanguage;
294
				}
295
			} else {
296
				language = datasetLanguage;
297
			}
298
			String detail = elDetail.getText();
299
			List<String> labDet = langLabDet.get(language);
300
			labDet.add(detail);
301
			labDet.add(role);
302
			langLabDet.put(language, labDet);
303
		}
304

    
305
		if (ve instanceof TermBase) {
306
			TermBase tb = (TermBase) ve;
307

    
308
			for (Iterator<Language> l = langLabDet.keySet().iterator() ; l.hasNext() ;){
309
				Language lang = l.next();
310
				List<String> labDet = langLabDet.get(lang);
311
				if (labDet.size()>0){
312
					if (labDet.size()>1) {
313
						tb.addRepresentation(Representation.NewInstance(labDet.get(1), labDet.get(0), labDet.get(0), lang));
314
					} else {
315
						tb.addRepresentation(Representation.NewInstance(labDet.get(0), labDet.get(0), labDet.get(0), lang));
316
					}
317
				}
318
				ve = tb;
319
			}
320

    
321
		} else if (ve instanceof Media) {
322
			Media m = (Media) ve;
323

    
324
			for (Iterator<Language> l = langLabDet.keySet().iterator() ; l.hasNext() ;){
325
				Language lang = l.next();
326
				List<String> labDet = langLabDet.get(lang);
327
				if (labDet.get(0) != null){
328
					m.addTitle(LanguageString.NewInstance(labDet.get(0), lang));
329
				}
330
				if (labDet.size()>1) {
331
					m.addDescription(labDet.get(1), lang);
332
				}
333
				ve = m;
334
			}
335

    
336
		} 
337
		if (ve instanceof IdentifiableEntity<?>) {
338
			IdentifiableEntity<?> ie = (IdentifiableEntity<?>) ve;
339
			List<String> labDet = null;
340

    
341
			if (ve instanceof TaxonNameBase) {
342
				if (langLabDet.keySet().contains(getTermService().getLanguageByIso("la"))) {
343
					labDet = langLabDet.get(getTermService().getLanguageByIso("la"));
344
				} else if (langLabDet.keySet().contains(datasetLanguage)) {
345
					labDet = langLabDet.get(datasetLanguage);
346
					logger.info("TaxonName " + (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace) + " is not specified as a latin name.");
347
				} else {
348
					labDet = langLabDet.get(langLabDet.keySet().iterator().next());
349
					logger.info("TaxonName " + (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace) + " is not specified as a latin name.");
350
				}
351
			} else {
352
				labDet = langLabDet.get(langLabDet.keySet().iterator().next());
353
			}
354

    
355
			ie.setTitleCache(labDet.get(0), true);
356

    
357
			if (labDet.size()>1) {
358
				Annotation annotation = null;
359
				if (labDet.get(1) != null) {
360
					if (labDet.get(2) != null) {
361
						annotation = Annotation.NewInstance(labDet.get(2) + " - " + labDet.get(1), datasetLanguage);
362
					} else {
363
						annotation = Annotation.NewInstance(labDet.get(1), datasetLanguage);
364
					}
365
				}
366
				ie.addAnnotation(annotation);
367
			}
368

    
369
			ve = ie;
370

    
371
		}
372
		
373
		if (ve instanceof IdentifiableMediaEntity<?>){
374
			IdentifiableMediaEntity<?> ime = (IdentifiableMediaEntity<?>) ve;
375
			Element elLinks = parent.getChild("Links",sddNamespace);
376

    
377
			if (elLinks != null) {
378

    
379
				//  <Link rel="Alternate" href="http://www.diversitycampus.net/people/hagedorn"/>
380
				List<Element> listLinks = elLinks.getChildren("Link", sddNamespace);
381
				Media link = Media.NewInstance();
382
				MediaRepresentation mr = MediaRepresentation.NewInstance();
383
				int k = 0;
384
				//for each Link
385
				for (Element elLink : listLinks){
386

    
387
					try {
388

    
389
						String rel = elLink.getAttributeValue("rel");
390
						String href = elLink.getAttributeValue("href");
391

    
392
						mr.addRepresentationPart(MediaRepresentationPart.NewInstance(href, null));
393
						link.addRepresentation(mr);
394
						ime.addMedia(link);
395

    
396
					} catch (Exception e) {
397
						//FIXME
398
						logger.warn("Import of Link " + k + " failed.");
399
					}
400

    
401
					if ((++k % modCount) == 0){ logger.info("Links handled: " + k);}
402

    
403
				}
404
			}
405
		}
406

    
407
		List <Element> listMediaObjects = elRepresentation.getChildren("MediaObject",sddNamespace);
408
		for (Element elMediaObject : listMediaObjects) {
409
			String ref = null;
410
			String role = null;
411
			if (elMediaObject != null) {
412
				ref = elMediaObject.getAttributeValue("ref");
413
				role = elMediaObject.getAttributeValue("role");
414
			}
415
			if (ref != null) {
416
				if (!ref.equals("")) {
417
					if (ref != null) {
418
						if (ve instanceof TaxonDescription) {
419
							TaxonDescription td = (TaxonDescription) ve;
420
							//TODO: ensure that all images are imported
421
							if (td.getDescriptionSources().toArray().length > 0) {
422
								this.associateImageWithCdmBase(ref,(ReferenceBase) td.getDescriptionSources().toArray()[0]);
423
							} else {
424
								ReferenceBase descriptionSource = refFactory.newGeneric();
425
								td.addDescriptionSource(descriptionSource);
426
								this.associateImageWithCdmBase(ref,descriptionSource);
427
							}
428
						} else {
429
							this.associateImageWithCdmBase(ref,ve);
430
						}
431
					}
432

    
433
				}
434
			}
435
		}
436

    
437
	}
438
	
439

    
440
	// imports the representation (label, detail, lang) of a particular SDD element
441
	protected void importTechnicalMetadata(Element root, Namespace sddNamespace, SDDImportConfigurator sddConfig){
442
		Element elTechnicalMetadata = root.getChild("TechnicalMetadata", sddNamespace);
443
		String nameCreated = elTechnicalMetadata.getAttributeValue("created");
444
		sourceReference = sddConfig.getSourceReference();
445

    
446
		if (nameCreated != null) {
447
			if (!nameCreated.equals("")) {
448
				int year = Integer.parseInt(nameCreated.substring(0,4));
449
				int monthOfYear = Integer.parseInt(nameCreated.substring(5,7));
450
				int dayOfMonth = Integer.parseInt(nameCreated.substring(8,10));
451
				int hourOfDay = Integer.parseInt(nameCreated.substring(11,13));
452
				int minuteOfHour = Integer.parseInt(nameCreated.substring(14,16));
453
				int secondOfMinute = Integer.parseInt(nameCreated.substring(17,19));
454
				DateTime created = new DateTime(year,monthOfYear,dayOfMonth,hourOfDay,minuteOfHour,secondOfMinute,0);
455
				sourceReference.setCreated(created);
456
				sec.setCreated(created);
457
			}
458
		}
459

    
460
		// <Generator name="n/a, handcrafted instance document" version="n/a"/>
461
		Element elGenerator = elTechnicalMetadata.getChild("Generator", sddNamespace);
462
		generatorName = elGenerator.getAttributeValue("name");
463
		generatorVersion = elGenerator.getAttributeValue("version");
464

    
465
		sec.addAnnotation(Annotation.NewDefaultLanguageInstance(generatorName + " - " + generatorVersion));
466
		sourceReference.addAnnotation(Annotation.NewDefaultLanguageInstance(generatorName + " - " + generatorVersion));
467

    
468
	}
469

    
470
	// imports the complete dataset information
471
	protected void importDataset(Element elDataset, Namespace sddNamespace, boolean success, SDDImportConfigurator sddConfig){			// <Dataset xml:lang="en-us">
472

    
473
		importDatasetLanguage(elDataset,sddConfig);
474
		importDatasetRepresentation(elDataset, sddNamespace);
475
		importRevisionData(elDataset, sddNamespace);
476
		importIPRStatements(elDataset, sddNamespace, sddConfig);
477
		importTaxonNames(elDataset, sddNamespace, sddConfig);
478
		importDescriptiveConcepts(elDataset, sddNamespace, sddConfig);
479
		importCharacters(elDataset, sddNamespace, sddConfig, success);
480
		importCharacterTrees(elDataset, sddNamespace, sddConfig, success);
481
		importCodedDescriptions(elDataset, sddNamespace, sddConfig, success);
482
		importAgents(elDataset, sddNamespace, sddConfig, success);
483
		importPublications(elDataset, sddNamespace, sddConfig, success);
484
		importMediaObjects(elDataset, sddNamespace, sddConfig, success);
485
		importTaxonHierarchies(elDataset, sddNamespace, sddConfig, success);
486
		importGeographicAreas(elDataset, sddNamespace, sddConfig);
487
		importSpecimens(elDataset,sddNamespace, sddConfig);
488
			
489
		MarkerType editorMarkerType = MarkerType.NewInstance("Editor", "editor", "edt") ;
490
		MarkerType geographicAreaMarkerType = MarkerType.NewInstance("", "SDDGeographicArea", "ga");
491
		MarkerType descriptiveConceptMarkerType = MarkerType.NewInstance("Descriptive Concept", "DescriptiveConcept", "DC");
492
		markerTypes.add(editorMarkerType);
493
		markerTypes.add(geographicAreaMarkerType);
494
		markerTypes.add(descriptiveConceptMarkerType);
495
		
496
		
497
		if ((authors != null)||(editors != null)) {
498
			Team team = Team.NewInstance();
499
			if (authors != null) {
500
			for (Iterator<Person> author = authors.values().iterator() ; author.hasNext() ;){
501
				team.addTeamMember(author.next());
502
			}
503
			}
504
			if (editors != null) {
505
				Marker marker = Marker.NewInstance();
506
				marker.setMarkerType(editorMarkerType);
507
				for (Iterator<Person> editor = editors.values().iterator() ; editor.hasNext() ;){
508
					Person edit = editor.next();
509
					edit.addMarker(marker);
510
					team.addTeamMember(edit);
511
				}
512
				}
513
			sec.setAuthorTeam(team);
514
			sourceReference.setAuthorTeam(team);
515
		}
516

    
517
		if (copyright != null) {
518
			sourceReference.addRights(copyright);
519
			sec.addRights(copyright);
520
		}
521
		
522
		// Returns a CdmApplicationController created by the values of this configuration.
523
		IDescriptionService descriptionService = getDescriptionService();
524

    
525
		for (Iterator<TaxonDescription> k = taxonDescriptions.values().iterator() ; k.hasNext() ;){
526
			TaxonDescription taxonDescription = k.next();
527
			// Persists a Description
528
			descriptionService.save(taxonDescription);
529
		}
530

    
531
		
532
		for (Iterator<String> refCD = taxonDescriptions.keySet().iterator() ; refCD.hasNext() ;){
533
			String ref = refCD.next();
534
			TaxonDescription td = taxonDescriptions.get(ref);
535
			if (citations.containsKey(ref)) {
536
				IArticle publication = (IArticle) publications.get(citations.get(ref));
537
				if (locations.containsKey(ref)) {
538
					Annotation location = Annotation.NewInstance(locations.get(ref), datasetLanguage);
539
					AnnotationType annotationType = AnnotationType.NewInstance("", "location", "");
540
					annotationTypes.add(annotationType);
541
					location.setAnnotationType(annotationType);
542
					((ReferenceBase)publication).addAnnotation(location);
543
				}
544
				td.addDescriptionSource((ReferenceBase)publication);
545
			}
546
		}
547
		logger.info("end makeTaxonDescriptions ...");
548
		
549
		
550
//		for (Iterator<TermVocabulary<Modifier>> k = termVocabularyStates.iterator() ; k.hasNext() ;){
551
//			TermVocabulary<Modifier> termVocabulary = k.next();
552
//			getVocabularyService().save(termVocabulary); //XIM
553
//		}
554
		
555

    
556
		//sddConfig.setSourceReference(sourceReference);
557

    
558
		//saving of all imported data into the CDM db
559
		ITermService termService = getTermService();
560
		
561
//		Modifier odif = new Modifier("zoub","zab","zib");
562
//		Modifier odif2 = new Modifier("zouba","zaba","ziba");
563
//		modifiers.put("yy", odif);
564
//		State st = State.NewInstance();
565
//		StateData stat = StateData.NewInstance();
566
		//StateData stat2 = StateData.NewInstance();
567
		//termService.save(stat2);
568
//		stat2.setState(st);
569
//		stat.setState(st);
570
//		stateDatas.put("yy", stat);
571
//		stateDatas.put("yy", stat2);
572
//		stat.addModifier(odif);
573
//		stat.addModifier(odif2);
574
//		stat2.addModifier(odif);
575
		
576
		for (Iterator<Modifier> k = modifiers.values().iterator() ; k.hasNext() ;){
577
			Modifier modifier = k.next();
578
			termService.save(modifier);
579
		}
580
		
581
		//termService.save(descriptiveConceptMarkerType);
582
		if (descriptiveConcepts != null) {
583
			for (Iterator<Feature> feat = descriptiveConcepts.iterator() ; feat.hasNext() ;) {
584
				Marker marker = Marker.NewInstance();
585
				marker.setMarkerType(descriptiveConceptMarkerType);
586
				Feature feature = feat.next();
587
				feature.addMarker(marker);
588
			}
589
		}
590
		
591
		for (Iterator<State> k = states.values().iterator() ; k.hasNext() ;){
592
			State state = k.next();
593
			termService.save(state);
594
		}
595
		
596
		/*Marker markerd = Marker.NewInstance();
597
		markerd.setMarkerType(descriptiveConceptMarker);
598
		Feature fiture = Feature.NewInstance("Fitoure","Fitoure","Fitoure");
599
		fiture.addMarker(markerd);
600
		TermVocabulary<Modifier> termVocabularyState = new TermVocabulary<Modifier>("test","test","test","test");
601
		Modifier modif = new Modifier("zoub","zab","zib");
602
		termVocabularyState.addTerm(modif);
603
		getVocabularyService().save(termVocabularyState);
604
		fiture.addRecommendedModifierEnumeration(termVocabularyState);
605
		termService.save(modif);
606
		termService.save(fiture);*/
607
		
608
		for (Iterator<Feature> k = features.values().iterator() ; k.hasNext() ;){
609
			Feature feature = k.next();
610
			termService.save(feature); 
611
		}
612
		
613
		for(Iterator<MarkerType> k = markerTypes.iterator() ; k.hasNext() ;){
614
			MarkerType markerType = k.next();
615
			termService.save(markerType);
616
		}
617
		
618
		//XIMtermService.save(editorMarkerType);
619
		
620
		//XIMtermService.save(geographicAreaMarkerType);
621
		for (Iterator<NamedArea> k = namedAreas.values().iterator() ; k.hasNext() ;) {
622
			Marker marker = Marker.NewInstance();
623
			marker.setMarkerType(geographicAreaMarkerType);
624
			NamedArea area = k.next();
625
			area.addMarker(marker);
626
			//getTermService().save(area);
627
			termService.save(area);
628
		}		
629
		
630
		if (units != null) {
631
			for (Iterator<MeasurementUnit> k = units.values().iterator() ; k.hasNext() ;){
632
				MeasurementUnit unit = k.next();
633
				if (unit != null) {
634
					termService.save(unit); 
635
				}
636
			}
637
		}
638
		for (Iterator<StatisticalMeasure> k = statisticalMeasures.iterator() ; k.hasNext() ;) {
639
			StatisticalMeasure sm = k.next();
640
			termService.save(sm); 
641
		}
642
		for (Iterator<AnnotationType> at = annotationTypes.iterator() ; at.hasNext() ;) {
643
			AnnotationType annotationType = at.next();
644
			termService.save(annotationType); 
645
		}
646

    
647
		IReferenceService referenceService = getReferenceService();
648
		// referenceService.saveReference(sourceReference); 
649
		for (Iterator<ReferenceBase> k = publications.values().iterator() ; k.hasNext() ;){
650
			ReferenceBase publication = (ReferenceBase) k.next();
651
			referenceService.save(publication); 
652
		}
653

    
654
		for (Iterator<FeatureTree> k = featureTrees.iterator() ; k.hasNext() ;) {
655
			FeatureTree tree = k.next();
656
			getFeatureTreeService().save(tree);
657
		}
658
		for (Iterator<TaxonomicTree> k = taxonomicTrees.iterator() ; k.hasNext() ;) {
659
			TaxonomicTree tree = k.next();
660
			getTaxonTreeService().save(tree);
661
		}
662
		for (Iterator<Specimen> k = specimens.values().iterator() ; k.hasNext() ;) {
663
			Specimen specimen = k.next();
664
			getOccurrenceService().save(specimen);
665
		}
666
		logger.info("end of persistence ...");
667
		
668
	}
669

    
670
	// imports the default language of the dataset
671
	protected void importDatasetLanguage(Element elDataset, SDDImportConfigurator sddConfig){
672
		String nameLang = elDataset.getAttributeValue("lang",xmlNamespace);
673

    
674
		if (!nameLang.equals("")) {
675
			String iso = nameLang.substring(0, 2);
676
			datasetLanguage = getTermService().getLanguageByIso(iso);
677
		} else {
678
			datasetLanguage = Language.ENGLISH();
679
		}
680
		if (datasetLanguage == null) {
681
			datasetLanguage = Language.ENGLISH();
682
		}
683
	}
684
	
685
	// imports the specimens
686
	protected void importSpecimens(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig) {
687
		logger.info("start Specimens ...");
688
		/*	<Specimens>
689
        		<Specimen id="sp1">
690
           			<Representation>
691
              			<Label>TJM45337</Label>
692
           			</Representation>
693
        		</Specimen>
694
     		</Specimens>
695
		 */
696
		Element elSpecimens = elDataset.getChild("Specimens",sddNamespace);
697
		if (elSpecimens != null){
698
			List<Element> listSpecimens = elSpecimens.getChildren("Specimen", sddNamespace);
699
			int j = 0;
700
			for (Element elSpecimen : listSpecimens) {
701
				String id = elSpecimen.getAttributeValue("id");
702
				Specimen specimen = null;
703
				if (!id.equals("")) {
704
					specimen = Specimen.NewInstance();
705
					specimens.put(id,specimen);
706
					importRepresentation(elSpecimen, sddNamespace, specimen, id, sddConfig);
707
				}
708
			}
709

    
710
		}
711
	}
712

    
713
	// imports the revision data associated with the Dataset (authors, modifications)
714
	protected void importRevisionData(Element elDataset, Namespace sddNamespace){
715
		// <RevisionData>
716
		logger.info("start RevisionData ...");
717
		Element elRevisionData = elDataset.getChild("RevisionData",sddNamespace);
718
		if (elRevisionData != null){
719
			// <Creators>
720
			Element elCreators = elRevisionData.getChild("Creators",sddNamespace);
721

    
722
			// <Agent role="aut" ref="a1"/>
723
			List<Element> listAgents = elCreators.getChildren("Agent", sddNamespace);
724

    
725
			int j = 0;
726
			//for each Agent
727
			for (Element elAgent : listAgents){
728

    
729
				String role = elAgent.getAttributeValue("role");
730
				String ref = elAgent.getAttributeValue("ref");
731
				if (role.equals("aut")) {
732
					if(!ref.equals("")) {
733
						authors.put(ref, null);
734
					}
735
				}
736
				if (role.equals("edt")) {
737
					if(!ref.equals("")) {
738
						editors.put(ref, null);
739
					}
740
				}
741
				if ((++j % modCount) == 0){ logger.info("Agents handled: " + j);}
742

    
743
			}
744

    
745
			// <DateModified>2006-04-08T00:00:00</DateModified>
746
			String stringDateModified = (String)ImportHelper.getXmlInputValue(elRevisionData, "DateModified",sddNamespace);
747

    
748
			if (stringDateModified != null) {
749
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
750
				Date d = null;
751
				try {
752
					d = sdf.parse(stringDateModified);
753
				} catch(Exception e) {
754
					System.err.println("Exception :");
755
					e.printStackTrace();
756
				}
757

    
758
				DateTime updated = null;
759
				if (d != null) {
760
					updated = new DateTime(d);
761
					sourceReference.setUpdated(updated);
762
					sec.setUpdated(updated);
763
				}
764
			}
765
		}
766
	}
767

    
768
	// imports ipr statements associated with a dataset
769
	protected void importIPRStatements(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig){
770
		// <IPRStatements>
771
		logger.info("start IPRStatements ...");
772
		Element elIPRStatements = elDataset.getChild("IPRStatements",sddNamespace);
773
		// <IPRStatement role="Copyright">
774
		if (elIPRStatements != null) {
775
			List<Element> listIPRStatements = elIPRStatements.getChildren("IPRStatement", sddNamespace);
776
			int j = 0;
777
			//for each IPRStatement
778

    
779
			for (Element elIPRStatement : listIPRStatements){
780

    
781
				String role = elIPRStatement.getAttributeValue("role");
782
				// <Label xml:lang="en-au">(c) 2003-2006 Centre for Occasional Botany.</Label>
783
				Element elLabel = elIPRStatement.getChild("Label",sddNamespace);
784
				String lang = "";
785
				if (elLabel != null) {
786
					lang = elLabel.getAttributeValue("lang",xmlNamespace);
787
				}
788
				String label = (String)ImportHelper.getXmlInputValue(elIPRStatement, "Label",sddNamespace);
789

    
790
				if (role.equals("Copyright")) {
791
					Language iprLanguage = null;
792
					if (lang != null) {
793
						if (!lang.equals("")) {
794
							iprLanguage = getTermService().getLanguageByIso(lang.substring(0, 2));
795
						} else {
796
							iprLanguage = datasetLanguage;
797
						}
798
					}
799
					if (iprLanguage == null) {
800
						iprLanguage = datasetLanguage;
801
					}
802
					copyright = Rights.NewInstance(label, iprLanguage);
803
				}
804

    
805
				if (copyright != null) {
806
					sourceReference.addRights(copyright);
807
					sec.addRights(copyright);
808
				}
809

    
810
				if ((++j % modCount) == 0){ logger.info("IPRStatements handled: " + j);}
811

    
812
			}
813
		}
814
	}
815

    
816
	// imports the taxon names
817
	protected void importTaxonNames(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig){
818
		// <TaxonNames>
819
		logger.info("start TaxonNames ...");
820
		Element elTaxonNames = elDataset.getChild("TaxonNames",sddNamespace);
821
		// <TaxonName id="t1" uri="urn:lsid:authority:namespace:my-own-id">
822
		if (elTaxonNames != null) {
823
			List<Element> listTaxonNames = elTaxonNames.getChildren("TaxonName", sddNamespace);
824
			int j = 0;
825
			//for each TaxonName
826
			for (Element elTaxonName : listTaxonNames){
827

    
828
				String id = elTaxonName.getAttributeValue("id");
829
				String uri = elTaxonName.getAttributeValue("uri");
830

    
831
				NonViralName tnb = null;
832
				if (!id.equals("")) {
833
					tnb = NonViralName.NewInstance(null);
834
					IdentifiableSource source = null;
835
					if (uri != null) {
836
						if (!uri.equals("")) {
837
							source = IdentifiableSource.NewInstance(id, "TaxonName", refFactory.newGeneric(), uri);
838
						}
839
					} else {
840
						source = IdentifiableSource.NewInstance(id, "TaxonName");
841
					}
842
					tnb.addSource(source);
843
					taxonNameBases.put(id,tnb);
844
				}
845

    
846
				// <Representation>
847
				// <Label xml:lang="la">Viola hederacea Labill.</Label>
848
				importRepresentation(elTaxonName, sddNamespace, tnb, id, sddConfig);
849

    
850
				if ((++j % modCount) == 0){ logger.info("TaxonNames handled: " + j);}
851

    
852
			}
853
		}
854
	}
855

    
856
	// imports the characters (categorical, quantitative and text ; sequence characters not supported) which correspond to CDM Features
857
	protected void importCharacters(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){
858
		// <Characters>
859
		logger.info("start Characters ...");
860
		Element elCharacters = elDataset.getChild("Characters", sddNamespace);
861

    
862
		// <CategoricalCharacter id="c1">
863
		if (elCharacters != null) {
864
			List<Element> elCategoricalCharacters = elCharacters.getChildren("CategoricalCharacter", sddNamespace);
865
			int j = 0;
866
			for (Element elCategoricalCharacter : elCategoricalCharacters){
867
				try {
868

    
869
					String idCC = elCategoricalCharacter.getAttributeValue("id");
870
					Feature categoricalCharacter = Feature.NewInstance();
871
					categoricalCharacter.setKindOf(Feature.DESCRIPTION());
872
					importRepresentation(elCategoricalCharacter, sddNamespace, categoricalCharacter, idCC, sddConfig);
873
					categoricalCharacter.setSupportsCategoricalData(true);
874

    
875
					// <States>
876
					Element elStates = elCategoricalCharacter.getChild("States",sddNamespace);
877

    
878
					// <StateDefinition id="s1">
879
					List<Element> elStateDefinitions = elStates.getChildren("StateDefinition",sddNamespace);
880
					TermVocabulary<State> termVocabularyState = new TermVocabulary<State>();
881
					int k = 0;
882
					//for each StateDefinition
883
					for (Element elStateDefinition : elStateDefinitions){
884

    
885
						if ((++k % modCount) == 0){ logger.info("StateDefinitions handled: " + (k-1));}
886

    
887
						String idS = elStateDefinition.getAttributeValue("id");
888
						State state = State.NewInstance();
889
						importRepresentation(elStateDefinition, sddNamespace, state, idS, sddConfig);
890

    
891
						//StateData stateData = StateData.NewInstance();
892
						//stateData.setState(state);
893
						termVocabularyState.addTerm(state);
894
						states.put(idS,state);
895
					}
896
					categoricalCharacter.addSupportedCategoricalEnumeration(termVocabularyState);
897
					features.put(idCC, categoricalCharacter);
898

    
899
				} catch (Exception e) {
900
					logger.warn("Import of CategoricalCharacter " + j + " failed.");
901
					success = false; 
902
				}
903

    
904
				if ((++j % modCount) == 0){ logger.info("CategoricalCharacters handled: " + j);}
905

    
906
			}
907

    
908
			// <QuantitativeCharacter id="c2">
909
			List<Element> elQuantitativeCharacters = elCharacters.getChildren("QuantitativeCharacter", sddNamespace);
910
			j = 0;
911
			//for each QuantitativeCharacter
912
			for (Element elQuantitativeCharacter : elQuantitativeCharacters){
913

    
914
				try {
915

    
916
					String idQC = elQuantitativeCharacter.getAttributeValue("id");
917

    
918
					// <Representation>
919
					//  <Label>Leaf length</Label>
920
					// </Representation>
921
					Feature quantitativeCharacter = Feature.NewInstance();
922
					quantitativeCharacter.setKindOf(Feature.DESCRIPTION());
923
					importRepresentation(elQuantitativeCharacter, sddNamespace, quantitativeCharacter, idQC, sddConfig);
924

    
925
					quantitativeCharacter.setSupportsQuantitativeData(true);
926

    
927
					// <MeasurementUnit>
928
					//  <Label role="Abbrev">m</Label>
929
					// </MeasurementUnit>
930
					Element elMeasurementUnit = elQuantitativeCharacter.getChild("MeasurementUnit",sddNamespace);
931
					String label = "";
932
					String role = "";
933
					if (elMeasurementUnit != null) {
934
						Element elLabel = elMeasurementUnit.getChild("Label",sddNamespace);
935
						role = elLabel.getAttributeValue("role");
936
						label = (String)ImportHelper.getXmlInputValue(elMeasurementUnit, "Label",sddNamespace);
937
					}
938

    
939
					MeasurementUnit unit = null;
940
					if (!label.equals("")){
941
						if (role != null) {
942
							if (role.equals("Abbrev")){
943
								unit = MeasurementUnit.NewInstance(label,label,label);
944
							}
945
						} else {
946
							unit = MeasurementUnit.NewInstance(label,label,label);
947
						}
948
					}
949

    
950
					if (unit != null) {
951
						units.put(idQC, unit);
952
					}
953

    
954
					//<Default>
955
					//  <MeasurementUnitPrefix>milli</MeasurementUnitPrefix>
956
					//</Default>
957
					Element elDefault = elQuantitativeCharacter.getChild("Default",sddNamespace);
958
					if (elDefault != null) {
959
						String measurementUnitPrefix = (String)ImportHelper.getXmlInputValue(elDefault, "MeasurementUnitPrefix",sddNamespace);
960
						if (!measurementUnitPrefix.equals("")){
961
							defaultUnitPrefixes.put(idQC, measurementUnitPrefix);
962
						}
963
					}
964

    
965
					features.put(idQC, quantitativeCharacter);
966

    
967
				} catch (Exception e) {
968
					//FIXME
969
					logger.warn("Import of QuantitativeCharacter " + j + " failed.");
970
					success = false; 
971
				}
972

    
973
				if ((++j % modCount) == 0){ logger.info("QuantitativeCharacters handled: " + j);}
974

    
975
			}
976

    
977
			// <TextCharacter id="c3">
978
			List<Element> elTextCharacters = elCharacters.getChildren("TextCharacter", sddNamespace);
979
			j = 0;
980
			//for each TextCharacter
981
			for (Element elTextCharacter : elTextCharacters){
982

    
983
				try {
984

    
985
					String idTC = elTextCharacter.getAttributeValue("id");
986

    
987
					// <Representation>
988
					//  <Label xml:lang="en">Leaf features not covered by other characters</Label>
989
					// </Representation>
990
					Feature textCharacter = Feature.NewInstance();
991
					textCharacter.setKindOf(Feature.DESCRIPTION());
992
					importRepresentation(elTextCharacter, sddNamespace, textCharacter, idTC, sddConfig);
993

    
994
					textCharacter.setSupportsTextData(true);
995

    
996
					features.put(idTC, textCharacter);
997

    
998
				} catch (Exception e) {
999
					//FIXME
1000
					logger.warn("Import of TextCharacter " + j + " failed.");
1001
					success = false; 
1002
				}
1003

    
1004
				if ((++j % modCount) == 0){ logger.info("TextCharacters handled: " + j);}
1005

    
1006
			}
1007

    
1008
		}
1009

    
1010
		/*for (Iterator<Feature> f = features.values().iterator() ; f.hasNext() ;){
1011
			featureSet.add(f.next()); //XIM Why this line ?
1012
		}*/
1013

    
1014
	}
1015

    
1016
	// imports the descriptions of taxa
1017
	protected void importCodedDescriptions(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){
1018
		// <CodedDescriptions>
1019
		logger.info("start CodedDescriptions ...");
1020
		Element elCodedDescriptions = elDataset.getChild("CodedDescriptions",sddNamespace);
1021
		// <CodedDescription id="D101">
1022

    
1023
		if (elCodedDescriptions != null) {
1024
			List<Element> listCodedDescriptions = elCodedDescriptions.getChildren("CodedDescription", sddNamespace);
1025
			int j = 0;
1026
			//for each CodedDescription
1027

    
1028
			for (Element elCodedDescription : listCodedDescriptions){
1029

    
1030
				try {
1031

    
1032
					String idCD = elCodedDescription.getAttributeValue("id");
1033

    
1034
					// <Representation>
1035
					//  <Label>&lt;i&gt;Viola hederacea&lt;/i&gt; Labill. as revised by R. Morris April 8, 2006</Label>
1036
					// </Representation>
1037
					TaxonDescription taxonDescription = TaxonDescription.NewInstance();
1038
					importRepresentation(elCodedDescription, sddNamespace, taxonDescription, idCD, sddConfig);
1039

    
1040
					// <Scope>
1041
					//  <TaxonName ref="t1"/>
1042
					//  <Citation ref="p1" location="p. 30"/>
1043
					// </Scope>
1044
					Element elScope = elCodedDescription.getChild("Scope",sddNamespace);
1045
					String ref = "";
1046
					Taxon taxon = null;
1047
					if (elScope != null) {
1048
						Element elTaxonName = elScope.getChild("TaxonName",sddNamespace);
1049
						ref = elTaxonName.getAttributeValue("ref");
1050

    
1051
						NonViralName taxonNameBase = taxonNameBases.get(ref);
1052
						taxon = Taxon.NewInstance(taxonNameBase, sec);
1053
					}
1054
					else {//XIM what is it ?
1055
						NonViralName tnb = NonViralName.NewInstance(null);
1056
						String id = new String(""+taxonNamesCount);
1057
						IdentifiableSource source = IdentifiableSource.NewInstance(id, "TaxonName");
1058
						importRepresentation(elCodedDescription, sddNamespace, tnb, id, sddConfig);
1059
						tnb.addSource(source);
1060
						taxonNameBases.put(id ,tnb);
1061
						taxonNamesCount++;
1062
						taxon = Taxon.NewInstance(tnb, sec);
1063
					}
1064

    
1065
					String refCitation = "";
1066
					String location = "";
1067

    
1068
					if (elScope != null) {
1069
						Element elCitation = elScope.getChild("Citation",sddNamespace);
1070
						if (elCitation != null) {
1071
							refCitation = elCitation.getAttributeValue("ref");
1072
							location = elCitation.getAttributeValue("location");
1073
						}
1074
					}
1075

    
1076
					// <SummaryData>
1077
					Element elSummaryData = elCodedDescription.getChild("SummaryData",sddNamespace);
1078
					if (elSummaryData != null) {
1079

    
1080
						// <Categorical ref="c4">
1081
						List<Element> elCategoricals = elSummaryData.getChildren("Categorical", sddNamespace);
1082
						int k = 0;
1083
						//for each Categorical
1084
						for (Element elCategorical : elCategoricals){
1085
							if ((++k % modCount) == 0){ logger.warn("Categorical handled: " + (k-1));}
1086
							ref = elCategorical.getAttributeValue("ref");
1087
							Feature feature = features.get(ref);
1088
							CategoricalData categoricalData = CategoricalData.NewInstance();
1089
							categoricalData.setFeature(feature);
1090

    
1091
							// <State ref="s3"/>
1092
							List<Element> elStates = elCategorical.getChildren("State", sddNamespace);
1093
							int l = 0;
1094
							
1095
							//for each State
1096
							for (Element elState : elStates){
1097
								if ((++l % modCount) == 0){ logger.info("States handled: " + (l-1));}
1098
								ref = elState.getAttributeValue("ref");
1099
								State state = states.get(ref);
1100
								if (state!=null) {
1101
									StateData stateData = StateData.NewInstance();
1102
									stateData.setState(state);
1103
									List<Element> elModifiers = elState.getChildren("Modifier", sddNamespace);
1104
									for (Element elModifier : elModifiers){
1105
										ref = elModifier.getAttributeValue("ref");
1106
										Modifier modifier = modifiers.get(ref);
1107
										if (modifier!=null) {
1108
											stateData.addModifier(modifier);
1109
										}
1110
									}
1111
								categoricalData.addState(stateData);
1112
							}
1113
							taxonDescription.addElement(categoricalData);
1114
						}
1115
						}
1116
						// <Quantitative ref="c2">
1117
						List<Element> elQuantitatives = elSummaryData.getChildren("Quantitative", sddNamespace);
1118
						k = 0;
1119
						//for each Quantitative
1120
						for (Element elQuantitative : elQuantitatives){
1121
							if ((++k % modCount) == 0){ logger.warn("Quantitative handled: " + (k-1));}
1122
							ref = elQuantitative.getAttributeValue("ref");
1123
							Feature feature = features.get(ref);
1124
							QuantitativeData quantitativeData = QuantitativeData.NewInstance();
1125
							quantitativeData.setFeature(feature);
1126

    
1127
							MeasurementUnit unit = units.get(ref);
1128
							String prefix = defaultUnitPrefixes.get(ref);
1129
							if (unit != null) {
1130
								String u = unit.getLabel();
1131
								if (prefix != null) {
1132
									u = prefix + u;
1133
								}
1134
								unit.setLabel(u);
1135
								quantitativeData.setUnit(unit);
1136
							}
1137

    
1138
							// <Measure type="Min" value="2.3"/>
1139
							List<Element> elMeasures = elQuantitative.getChildren("Measure", sddNamespace);
1140
							int l = 0;
1141
							
1142
							//for each State
1143
							for (Element elMeasure : elMeasures){
1144
								if ((++l % modCount) == 0){ logger.info("States handled: " + (l-1));}
1145
								String type = elMeasure.getAttributeValue("type");
1146
								String value = elMeasure.getAttributeValue("value");
1147
								if (value.contains(",")) {
1148
									value = value.replace(',', '.');
1149
								}
1150
								Float v = Float.parseFloat(value);
1151
								//Float v = new Float(0);
1152
								StatisticalMeasure t = null;
1153
								if (type.equals("Min")) {
1154
									t = StatisticalMeasure.MIN();
1155
								} else if (type.equals("Mean")) {
1156
									t = StatisticalMeasure.AVERAGE();
1157
								} else if (type.equals("Max")) {
1158
									t = StatisticalMeasure.MAX();
1159
								} else if (type.equals("SD")) {
1160
									t = StatisticalMeasure.STANDARD_DEVIATION();
1161
								} else if (type.equals("N")) {
1162
									t = StatisticalMeasure.SAMPLE_SIZE();
1163
								} else if (type.equals("UMethLower")) {
1164
									t = StatisticalMeasure.TYPICAL_LOWER_BOUNDARY();
1165
								} else if (type.equals("UMethUpper")) {
1166
									t = StatisticalMeasure.TYPICAL_UPPER_BOUNDARY();
1167
								} else if (type.equals("Var")) {
1168
									t = StatisticalMeasure.VARIANCE();
1169
								} else {
1170
									t = StatisticalMeasure.NewInstance(type,type,type);
1171
									statisticalMeasures.add(t);
1172
								}
1173

    
1174
								StatisticalMeasurementValue statisticalValue = StatisticalMeasurementValue.NewInstance();
1175
								statisticalValue.setValue(v);
1176
								statisticalValue.setType(t);
1177
								quantitativeData.addStatisticalValue(statisticalValue);
1178
								featureData.add(statisticalValue);
1179
							}
1180
							taxonDescription.addElement(quantitativeData);
1181
						}
1182

    
1183
						// <TextChar ref="c3">
1184
						List<Element> elTextChars = elSummaryData.getChildren("TextChar", sddNamespace);
1185
						k = 0;
1186
						//for each TextChar
1187
						for (Element elTextChar : elTextChars){
1188
							if ((++k % modCount) == 0){ logger.info("TextChar handled: " + (k-1));}
1189
							ref = elTextChar.getAttributeValue("ref");
1190
							Feature feature = features.get(ref);
1191
							TextData textData = TextData.NewInstance();
1192
							textData.setFeature(feature);
1193

    
1194
							// <Content>Free form text</Content>
1195
							String content = (String)ImportHelper.getXmlInputValue(elTextChar, "Content",sddNamespace);
1196
							textData.putText(content, datasetLanguage);
1197
							taxonDescription.addElement(textData);
1198
						}
1199

    
1200
					}
1201

    
1202
					if (taxon != null) {
1203
						taxon.addDescription(taxonDescription);
1204
					}
1205

    
1206
					if (!refCitation.equals("")){
1207
						citations.put(idCD,refCitation);
1208
					}
1209

    
1210
					if (!location.equals("")){
1211
						locations.put(idCD, location);
1212
					}
1213
					
1214
					taxonDescription.setDescriptiveSystem(featureSet);
1215

    
1216
					taxonDescriptions.put(idCD, taxonDescription);//FIXME
1217

    
1218
				} catch (Exception e) {
1219
					//FIXME
1220
					logger.warn("Import of CodedDescription " + j + " failed.");
1221
					success = false;
1222
				}
1223
				if ((++j % modCount) == 0){ logger.info("CodedDescriptions handled: " + j);}
1224

    
1225
			}
1226

    
1227
		}
1228
	}
1229

    
1230
	// imports the persons associated with the dataset creation, modification, related publications
1231
	protected void importAgents(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){
1232
		// <Agents>
1233
		logger.info("start Agents ...");
1234
		Element elAgents = elDataset.getChild("Agents",sddNamespace);
1235
		if (elAgents != null) {
1236
			// <Agent id="a1">
1237
			List <Element> listAgents = elAgents.getChildren("Agent", sddNamespace);
1238
			int j = 0;
1239
			//for each Agent
1240
			for (Element elAgent : listAgents){
1241

    
1242
				try {
1243

    
1244
					String idA = elAgent.getAttributeValue("id");
1245

    
1246
					//  <Representation>
1247
					//   <Label>Kevin Thiele</Label>
1248
					//   <Detail role="Description">Ali Baba is also known as r.a.m.</Detail>
1249
					//  </Representation>
1250
					Person person = Person.NewInstance();
1251
					importRepresentation(elAgent, sddNamespace, person, idA, sddConfig);
1252
					person.addSource(IdentifiableSource.NewInstance(idA, "Agent"));
1253

    
1254
					/*XIM <Links>
1255
					Element elLinks = elAgent.getChild("Links",sddNamespace);
1256

    
1257
					if (elLinks != null) {
1258

    
1259
						//  <Link rel="Alternate" href="http://www.diversitycampus.net/people/hagedorn"/>
1260
						List<Element> listLinks = elLinks.getChildren("Link", sddNamespace);
1261
						int k = 0;
1262
						//for each Link
1263
						for (Element elLink : listLinks){
1264

    
1265
							try {
1266

    
1267
								String rel = elLink.getAttributeValue("rel");
1268
								String href = elLink.getAttributeValue("href");
1269

    
1270
								Media link = Media.NewInstance();
1271
								MediaRepresentation mr = MediaRepresentation.NewInstance();
1272
								mr.addRepresentationPart(MediaRepresentationPart.NewInstance(href, null));
1273
								link.addRepresentation(mr);
1274
								person.addMedia(link);
1275

    
1276
							} catch (Exception e) {
1277
								//FIXME
1278
								logger.warn("Import of Link " + k + " failed.");
1279
								success = false; 
1280
							}
1281

    
1282
							if ((++k % modCount) == 0){ logger.info("Links handled: " + k);}
1283

    
1284
						}
1285
					}
1286
					*/
1287
					if (authors.containsKey(idA)) {
1288
						authors.put(idA,person);
1289
					}
1290

    
1291
					if (editors.containsKey(idA)) {
1292
						editors.put(idA, person);
1293
					}
1294

    
1295
				} catch (Exception e) {
1296
					//FIXME
1297
					logger.warn("Import of Agent " + j + " failed.");
1298
					success = false; 
1299
				}
1300

    
1301
				if ((++j % modCount) == 0){ logger.info("Agents handled: " + j);}
1302

    
1303
			}
1304
		}
1305
	}
1306

    
1307
	// imports publications related with the data set
1308
	protected void importPublications(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){
1309
		/* <Publications>
1310
			  <Publication id="p112">
1311
			    <Representation>
1312
			      <Label>Gee, X. & Haa, Y. (2003). How to be happy in five minutes. Instant Gratifications, Palm Beach.</Label>
1313
			    </Representation>
1314
			    <Links>
1315
			    <Link rel="BasedOn" href="doi:10.1992/32311"/>
1316
			    <Link rel="Alternate" href="http://some.service.net/providing/bibliographic.data"/>
1317
			    </Links>
1318
			</Publications>
1319
*/
1320
		logger.info("start Publications ...");
1321
		Element elPublications = elDataset.getChild("Publications",sddNamespace);
1322

    
1323
		if (elPublications != null) {
1324
			List<Element> listPublications = elPublications.getChildren("Publication", sddNamespace);
1325
			int j = 0;
1326
			for (Element elPublication : listPublications){
1327

    
1328
				try {
1329

    
1330
					String idP = elPublication.getAttributeValue("id");
1331
					ReferenceBase publication = refFactory.newArticle();
1332
					importRepresentation(elPublication, sddNamespace, publication, idP, sddConfig);
1333

    
1334
					publications.put(idP,publication);
1335

    
1336
				} catch (Exception e) {
1337
					logger.warn("Import of Publication " + j + " failed.");
1338
					success = false; 
1339
				}
1340

    
1341
				if ((++j % modCount) == 0){ logger.info("Publications handled: " + j);}
1342

    
1343
			}
1344
		}
1345
	}
1346

    
1347
	// imports media objects such as images //FIXME check mediaobj
1348
	protected void importMediaObjects(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){
1349
		// <MediaObjects>
1350
		logger.info("start MediaObjects ...");
1351
		Element elMediaObjects = elDataset.getChild("MediaObjects",sddNamespace);
1352

    
1353
		if (elMediaObjects != null) {
1354
			// <MediaObject id="m1">
1355
			List<Element> listMediaObjects = elMediaObjects.getChildren("MediaObject", sddNamespace);
1356
			int j = 0;
1357
			for (Element elMO : listMediaObjects){
1358

    
1359
				String id = "";
1360

    
1361
				try {
1362
					String idMO = elMO.getAttributeValue("id");
1363
					id = idMO;
1364

    
1365
					//  <Representation>
1366
					//   <Label>Image description, e.g. to be used for alt-attribute in html.</Label>
1367
					//  </Representation>
1368
					Media media = Media.NewInstance();
1369
					importRepresentation(elMO, sddNamespace, media, idMO, sddConfig);
1370

    
1371
					// <Type>Image</Type>
1372
					// <Source href="http://test.edu/test.jpg"/>
1373
					String type = (String)ImportHelper.getXmlInputValue(elMO,"Type",sddNamespace);
1374

    
1375
					if ((type != null) && (type.equals("Image"))) {
1376
						Element elSource = elMO.getChild("Source",sddNamespace);
1377
						String href = elSource.getAttributeValue("href");
1378

    
1379
						ImageMetaData imageMetaData = ImageMetaData.newInstance();
1380
						ImageFile image = null;
1381
						if (href.substring(0,7).equals("http://")) {
1382
							try{
1383
								URL url = new URL(href);
1384
								
1385
								imageMetaData.readMetaData(url.toURI(), 0);
1386
								image = ImageFile.NewInstance(url.toString(), null, imageMetaData);
1387
							} catch (MalformedURLException e) {
1388
								logger.error("Malformed URL", e);
1389
							}
1390
						} else {
1391
							String sns = sddConfig.getSourceNameString();
1392
							File f = new File(sns);
1393
							File parent = f.getParentFile();
1394
							String fi = href;
1395
							//String fi = parent.toString() + File.separator + href; //TODO erase file:/
1396
							File file = new File(fi);
1397
							imageMetaData.readMetaData(file.toURI(), 0);
1398
							image = ImageFile.NewInstance(file.toString(), null, imageMetaData);
1399
						}
1400
						MediaRepresentation representation = MediaRepresentation.NewInstance(imageMetaData.getMimeType(), null);
1401
						representation.addRepresentationPart(image);
1402

    
1403
						media.addRepresentation(representation);
1404

    
1405
						ArrayList<CdmBase> lcb = (ArrayList<CdmBase>) mediaObject_ListCdmBase.get(idMO);
1406
						if (lcb != null) {
1407
							for (int k = 0; k < lcb.size(); k++) {
1408
								if (lcb.get(k) instanceof DefinedTermBase) {
1409
									DefinedTermBase dtb = (DefinedTermBase) lcb.get(k);
1410
									// if (lcb.get(0) instanceof DefinedTermBase) {
1411
									// DefinedTermBase dtb = (DefinedTermBase) lcb.get(0);
1412
									//									if (dtb!=null) {
1413
									//										if (k == 0) {
1414
									dtb.addMedia(media);
1415
									//System.out.println(dtb.getLabel());
1416
									//										} else {
1417
									//											Media me = (Media) media.clone();
1418
									//											dtb.addMedia(me);
1419
									//										}
1420
									//									}
1421
								} else if (lcb.get(k) instanceof ReferenceBase) {
1422
									ReferenceBase rb = (ReferenceBase) lcb.get(k);
1423
									//} else if (lcb.get(0) instanceof ReferenceBase) {
1424
									//ReferenceBase rb = (ReferenceBase) lcb.get(0);
1425
									// rb.setTitleCache(label);
1426
									//									if (rb!=null) {
1427
									//										if (k == 0) {
1428
									rb.addMedia(media);
1429
									//System.out.println(rb.getTitle());
1430
									//										} else {
1431
									//											Media me = (Media) media.clone();
1432
									//											rb.addMedia(me);
1433
									//										}
1434
									//									}
1435
								}/* else if (lcb.get(k) instanceof TaxonNameBase){
1436
									TaxonNameBase tb = (TaxonNameBase) lcb.get(k);
1437
									tb.addMedia(media);
1438
							}*/
1439
							}
1440
						}
1441
					}
1442

    
1443
				} catch (Exception e) {
1444
					//FIXME
1445
					logger.warn("Could not attach MediaObject " + j + "(SDD: " + id + ") to several objects.");
1446
					success = false; 
1447
				}
1448

    
1449
				if ((++j % modCount) == 0){ logger.info("MediaObjects handled: " + j);
1450

    
1451
				}
1452
			}
1453
		}
1454
	}
1455

    
1456
	// imports the <DescriptiveConcepts> block ; DescriptiveConcepts are used as nodes in CharacterTrees and Characters as leaves
1457
	// but since Modifiers can be linked to DescriptiveConcepts they are stored as features with a particular Marker
1458
	protected void importDescriptiveConcepts(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig){
1459
		/* <DescriptiveConcepts>
1460
		      <DescriptiveConcept id="dc0">
1461
			        <Representation>
1462
			          <Label>Fixed set of modifiers supported in Lucid3</Label>
1463
			        </Representation>
1464
			        <Modifiers>
1465
			          <Modifier id="mod1">
1466
			            <Representation>
1467
			              <Label>rarely</Label>
1468
			            </Representation>
1469
			            <ModifierClass>Frequency</ModifierClass>
1470
			            <ProportionRange lowerestimate="0.0" upperestimate="0.25"/>
1471
			          </Modifier>
1472
		          </Modifiers>
1473
		        </DescriptiveConcept>
1474
	         </DescriptiveConcepts>
1475
		 */
1476
		logger.info("start DescriptiveConcepts ...");
1477
		Element elDescriptiveConcepts = elDataset.getChild("DescriptiveConcepts",sddNamespace);
1478
		if (elDescriptiveConcepts != null) {
1479
			List<Element> listDescriptiveConcepts = elDescriptiveConcepts.getChildren("DescriptiveConcept", sddNamespace);
1480
			int j = 0;
1481

    
1482
			for (Element elDescriptiveConcept : listDescriptiveConcepts){
1483
				try {
1484
				String id = elDescriptiveConcept.getAttributeValue("id");
1485
					Feature feature = Feature.NewInstance();
1486
					feature.setKindOf(Feature.DESCRIPTION());
1487
					if (!id.equals("")) {
1488
					//	 <Representation>
1489
					//       <Label>Body</Label>
1490
					importRepresentation(elDescriptiveConcept, sddNamespace, feature, id, sddConfig);
1491
						features.put(id, feature);
1492
						getTermService().save(feature);//XIM
1493
						descriptiveConcepts.add(feature);
1494
						// imports the modifiers
1495
						Element elModifiers = elDescriptiveConcept.getChild("Modifiers", sddNamespace);
1496
					if (elModifiers !=null){
1497
						List<Element> listModifiers = elModifiers.getChildren("Modifier", sddNamespace);
1498
							TermVocabulary<Modifier> termVocabularyState = new TermVocabulary<Modifier>();
1499
						for (Element elModifier : listModifiers) {
1500
								Modifier modif = Modifier.NewInstance();
1501
								String idmod = elModifier.getAttributeValue("id");
1502
								importRepresentation(elModifier, sddNamespace, modif, idmod, sddConfig);
1503
								termVocabularyState.addTerm(modif);
1504
								//termVocabularyStates.add(termVocabularyState);
1505
								getVocabularyService().save(termVocabularyState);//XIM
1506
								modifiers.put(idmod, modif);
1507
						}
1508
							feature.addRecommendedModifierEnumeration(termVocabularyState);
1509
				}
1510

    
1511
					}
1512
				}
1513
				catch (Exception e) {
1514
					logger.warn("Import of DescriptiveConcept " + j + " failed.");
1515
				}
1516
				if ((++j % modCount) == 0){ logger.info("DescriptiveConcepts handled: " + j);}
1517

    
1518
			}
1519
		}
1520
	}
1521

    
1522
	// imports the <CharacterTrees> block
1523
	protected void importCharacterTrees(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){
1524
		// <CharacterTrees>
1525
		logger.info("start CharacterTrees ...");
1526
		Element elCharacterTrees = elDataset.getChild("CharacterTrees",sddNamespace);
1527

    
1528
		if (elCharacterTrees != null) {
1529
			List<Element> listCharacterTrees = elCharacterTrees.getChildren("CharacterTree", sddNamespace);
1530
			int j = 0;
1531
			for (Element elCharacterTree : listCharacterTrees){
1532
				try {
1533
					Element elRepresentation = elCharacterTree.getChild("Representation",sddNamespace);
1534
					String label = (String)ImportHelper.getXmlInputValue(elRepresentation,"Label",sddNamespace);
1535
					//Element elDesignedFor = elCharacterTree.getChild("DesignedFor",sddNamespace);//TODO ?
1536

    
1537
						FeatureTree feattree =  FeatureTree.NewInstance();
1538
						importRepresentation(elCharacterTree, sddNamespace, feattree, "", sddConfig);
1539
						FeatureNode root = feattree.getRoot();
1540
						List<Element> listelNodes = elCharacterTree.getChildren("Nodes", sddNamespace);
1541

    
1542
					//Nodes of CharacterTrees in SDD always refer to DescriptiveConcepts
1543
						for (Element elNodes : listelNodes) {
1544
							List<Element> listNodes = elNodes.getChildren("Node", sddNamespace);
1545
							if (listNodes != null) {
1546
								for (Element elNode : listNodes){
1547
									String idN = elNode.getAttributeValue("id");
1548
									FeatureNode fn = null;
1549
								Feature dc = null;
1550
								if (idN!=null) {
1551
									// DescriptiveConcepts are used as nodes in CharacterTrees
1552
										Element elDescriptiveConcept = elNode.getChild("DescriptiveConcept", sddNamespace);
1553
										if (elDescriptiveConcept != null){
1554
											String refDC = elDescriptiveConcept.getAttributeValue("ref");
1555
										dc = features.get(refDC);
1556
										fn = FeatureNode.NewInstance(dc);
1557
										}
1558
									if (fn==null){
1559
											fn = FeatureNode.NewInstance();
1560
										}
1561
										Element elParent = elNode.getChild("Parent", sddNamespace);
1562
									// in SDD links between Nodes are referenced by the <Parent> tag
1563
										if (elParent!=null){
1564
											String refP = elParent.getAttributeValue("ref");
1565
										if (refP!=null) {
1566
											FeatureNode parent = featureNodes.get(refP);
1567
											if (parent==null){
1568
												root.addChild(fn); // if no parent found or the reference is broken, add the node to the root of the tree
1569
											}
1570
											else {
1571
												parent.addChild(fn);
1572
											}
1573
										}
1574
									}
1575
										else {
1576
										root.addChild(fn); // if no parent found or the reference is broken, add the node to the root of the tree
1577
										}
1578
									}
1579
								featureNodes.put(idN, fn);
1580
								}
1581
						}
1582

    
1583
						// Leaves of CharacterTrees in SDD are always CharNodes (referring to Characters)
1584
								List<Element> listCharNodes = elNodes.getChildren("CharNode", sddNamespace);
1585
						if (listCharNodes != null) {
1586
								for (Element elCharNode : listCharNodes){
1587
									Element elParent = elCharNode.getChild("Parent", sddNamespace);
1588
									Element elCharacter = elCharNode.getChild("Character", sddNamespace);							
1589
									FeatureNode fn = FeatureNode.NewInstance();
1590
									if (elParent!=null){
1591
										String refP = elParent.getAttributeValue("ref");
1592
										if ((refP!=null)&&(!refP.equals(""))) {
1593
										FeatureNode parent = featureNodes.get(refP);
1594
											if (parent==null){
1595
											parent = root; // if no parent found or the reference is broken, add the node to the root of the tree
1596
											}
1597
											parent.addChild(fn);
1598
										}
1599
									}
1600
									String refC = elCharacter.getAttributeValue("ref");
1601
									if ((refC!=null)&&(!refC.equals(""))){
1602
										Feature character = features.get(refC);
1603
										fn.setFeature(character);
1604
								featureNodes.put(refC, fn);
1605
									}
1606
							}		
1607
									}
1608
								}
1609
						featureTrees.add(feattree);
1610
					}
1611

    
1612
				catch (Exception e) {
1613
					logger.warn("Import of Character tree " + j + " failed.");
1614
					success = false; 
1615
				}
1616
				if ((++j % modCount) == 0){ logger.info("CharacterTrees handled: " + j);}
1617

    
1618
			}
1619

    
1620
		}
1621
	}
1622

    
1623
	// imports the <TaxonHierarchies> block
1624
	protected void importTaxonHierarchies(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){
1625

    
1626
		logger.info("start TaxonHierarchies ...");
1627
		Element elTaxonHierarchies = elDataset.getChild("TaxonHierarchies",sddNamespace);
1628

    
1629
		if (elTaxonHierarchies != null) {
1630
			List<Element> listTaxonHierarchies = elTaxonHierarchies.getChildren("TaxonHierarchy", sddNamespace);
1631
			int j = 0;
1632
			for (Element elTaxonHierarchy : listTaxonHierarchies){
1633
				try {
1634
					Element elRepresentation = elTaxonHierarchy.getChild("Representation",sddNamespace);
1635
					String label = (String)ImportHelper.getXmlInputValue(elRepresentation,"Label",sddNamespace);
1636
						TaxonomicTree taxonomicTree =  TaxonomicTree.NewInstance(label);
1637
						importRepresentation(elTaxonHierarchy, sddNamespace, taxonomicTree, "", sddConfig);
1638
					
1639
						Set<TaxonNode> root = taxonomicTree.getRootNodes();
1640
						Element elNodes = elTaxonHierarchy.getChild("Nodes", sddNamespace); // There can be only one <Nodes> block for TaxonHierarchies
1641
						List<Element> listNodes = elNodes.getChildren("Node", sddNamespace);
1642
						
1643
						for (Element elNode : listNodes){
1644
							String idN = elNode.getAttributeValue("id");
1645
							TaxonNameBase tnb = null;
1646
							if (!idN.equals("")) {
1647
								Element elTaxonName = elNode.getChild("TaxonName", sddNamespace);
1648
								String refTN = elTaxonName.getAttributeValue("ref");
1649
								tnb = taxonNameBases.get(refTN);
1650
								Taxon taxon = (Taxon) tnb.getTaxa().iterator().next() ;
1651
								Element elParent = elNode.getChild("Parent", sddNamespace);
1652
								if (elParent!=null){
1653
									String refP = elParent.getAttributeValue("ref");
1654
									if (!refP.equals("")) {
1655
										TaxonNode parent = taxonNodes.get(refP);
1656
										TaxonNode child = parent.addChildTaxon(taxon, sec, "", Synonym.NewInstance(tnb, sec));
1657
										taxonNodes.put(idN,child);
1658
									}
1659
								}
1660
								else {
1661
									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
1662
									taxonNodes.put(idN,tn);
1663
								}
1664
							}
1665
						}
1666

    
1667
						taxonomicTrees.add(taxonomicTree);
1668
					}
1669

    
1670
				catch (Exception e) {
1671
					//FIXME
1672
					logger.warn("Import of Taxon Hierarchy " + j + " failed.");
1673
					success = false; 
1674
				}
1675

    
1676
				if ((++j % modCount) == 0){ logger.info("TaxonHierarchies handled: " + j);}
1677

    
1678
			}
1679

    
1680
		}
1681
	}
1682
	
1683
	
1684
	// imports the <GeographicAreas> block 
1685
	protected void importGeographicAreas(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig) {
1686
		Element elGeographicAreas = elDataset.getChild("GeographicAreas",sddNamespace);
1687
		if (elGeographicAreas != null) {
1688
			List<Element> listGeographicAreas = elGeographicAreas.getChildren("GeographicArea", sddNamespace);
1689
			int j = 0;
1690
						
1691
			for (Element elGeographicArea : listGeographicAreas){
1692

    
1693
				String id = elGeographicArea.getAttributeValue("id");
1694
				NamedArea na = new NamedArea();
1695
				importRepresentation(elGeographicArea, sddNamespace, na, id, sddConfig);
1696
				namedAreas.put(id,na);
1697
								}
1698
			if ((++j % modCount) == 0){ logger.info("GeographicAreas handled: " + j);}
1699
							}
1700
							}
1701
}
(3-3/9)