Use of the new DescriptionBase attribute 'descriptiveSystem'
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / sdd / SDDDescriptionIO.java
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.URL;
15 import java.text.SimpleDateFormat;
16 import java.util.ArrayList;
17 import java.util.Collection;
18 import java.util.Date;
19 import java.util.GregorianCalendar;
20 import java.util.HashMap;
21 import java.util.HashSet;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.Set;
26
27 import org.apache.log4j.Logger;
28 import org.jdom.Element;
29 import org.jdom.Namespace;
30 import org.joda.time.DateTime;
31 import org.springframework.stereotype.Component;
32 import org.springframework.transaction.TransactionStatus;
33
34 import eu.etaxonomy.cdm.api.service.IDescriptionService;
35 import eu.etaxonomy.cdm.api.service.IReferenceService;
36 import eu.etaxonomy.cdm.api.service.ITermService;
37 import eu.etaxonomy.cdm.common.MediaMetaData.ImageMetaData;
38 import eu.etaxonomy.cdm.io.common.ICdmIO;
39 import eu.etaxonomy.cdm.io.common.IImportConfigurator;
40 import eu.etaxonomy.cdm.io.common.ImportHelper;
41 import eu.etaxonomy.cdm.io.common.MapWrapper;
42 import eu.etaxonomy.cdm.model.agent.Person;
43 import eu.etaxonomy.cdm.model.agent.Team;
44 import eu.etaxonomy.cdm.model.common.Annotation;
45 import eu.etaxonomy.cdm.model.common.CdmBase;
46 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
47 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
48 import eu.etaxonomy.cdm.model.common.Language;
49 import eu.etaxonomy.cdm.model.common.LanguageString;
50 import eu.etaxonomy.cdm.model.common.MultilanguageText;
51 import eu.etaxonomy.cdm.model.common.OriginalSource;
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.QuantitativeData;
62 import eu.etaxonomy.cdm.model.description.State;
63 import eu.etaxonomy.cdm.model.description.StateData;
64 import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
65 import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
66 import eu.etaxonomy.cdm.model.description.TaxonDescription;
67 import eu.etaxonomy.cdm.model.description.TextData;
68 import eu.etaxonomy.cdm.model.media.ImageFile;
69 import eu.etaxonomy.cdm.model.media.Media;
70 import eu.etaxonomy.cdm.model.media.MediaRepresentation;
71 import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
72 import eu.etaxonomy.cdm.model.media.Rights;
73 import eu.etaxonomy.cdm.model.name.NonViralName;
74 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
75 import eu.etaxonomy.cdm.model.reference.Article;
76 import eu.etaxonomy.cdm.model.reference.Database;
77 import eu.etaxonomy.cdm.model.reference.Generic;
78 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
79 import eu.etaxonomy.cdm.model.taxon.Taxon;
80
81 /**
82 * @author h.fradin
83 * @created 24.10.2008
84 * @version 1.0
85 */
86 @Component("sddDescriptionIO")
87 public class SDDDescriptionIO extends SDDIoBase implements ICdmIO<IImportConfigurator> {
88 private static final Logger logger = Logger.getLogger(SDDDescriptionIO.class);
89
90 private static int modCount = 1000;
91
92 private Map<String,Person> authors = new HashMap<String,Person>();
93 private Map<String,String> citations = new HashMap<String,String>();
94 private Map<String,String> defaultUnitPrefixes = new HashMap<String,String>();
95 private Map<String,Person> editors = new HashMap<String,Person>();
96 private Map<String,FeatureNode> featureNodes = new HashMap<String,FeatureNode>();
97 private Map<String,Feature> features = new HashMap<String,Feature>();
98 private Map<String,String> locations = new HashMap<String,String>();
99 private Map<String,List<CdmBase>> mediaObject_ListCdmBase = new HashMap<String,List<CdmBase>>();
100 private Map<String,String> mediaObject_Role = new HashMap<String,String>();
101 private Map<String,FeatureNode> nodes = new HashMap<String,FeatureNode>();
102 private Map<String,ReferenceBase> publications = new HashMap<String,ReferenceBase>();
103 private Map<String,StateData> stateDatas = new HashMap<String,StateData>();
104 private Map<String,TaxonDescription> taxonDescriptions = new HashMap<String,TaxonDescription>();
105 private Map<String,NonViralName> taxonNameBases = new HashMap<String,NonViralName>();
106 private Map<String,MeasurementUnit> units = new HashMap<String,MeasurementUnit>();
107
108 private Set<Feature> featureSet = new HashSet<Feature>();
109
110 private ReferenceBase sec = Database.NewInstance();
111 private ReferenceBase sourceReference = null;
112
113 private Language datasetLanguage = null;
114
115 private Namespace xmlNamespace = Namespace.getNamespace("xml","http://www.w3.org/XML/1998/namespace");
116
117 private String generatorName = "";
118 private String generatorVersion = "";
119
120 private Set<StatisticalMeasure> statisticalMeasures = new HashSet<StatisticalMeasure>();
121 private Set<VersionableEntity> featureData = new HashSet<VersionableEntity>();
122 private Set<FeatureTree> featureTrees = new HashSet<FeatureTree>();
123
124 private Rights copyright = null;
125
126 public SDDDescriptionIO(){
127 super();
128 }
129
130 @Override
131 public boolean doCheck(IImportConfigurator config){
132 boolean result = true;
133 logger.warn("No check implemented for SDD");
134 return result;
135 }
136
137 @Override
138 public boolean doInvoke(IImportConfigurator config, Map<String, MapWrapper<? extends CdmBase>> stores){
139
140 TransactionStatus ts = startTransaction();
141 SDDImportConfigurator sddConfig = (SDDImportConfigurator)config;
142
143 logger.info("start Datasets ...");
144 // <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">
145 Element root = sddConfig.getSourceRoot();
146 boolean success = true;
147 Namespace sddNamespace = sddConfig.getSddNamespace();
148
149 logger.info("start TechnicalMetadata ...");
150 // <TechnicalMetadata created="2006-04-20T10:00:00">
151 importTechnicalMetadata(root, sddNamespace, sddConfig);
152 List<Element> elDatasets = root.getChildren("Dataset",sddNamespace);
153 int i = 0;
154
155 //for each Dataset
156 logger.info("start Dataset ...");
157 for (Element elDataset : elDatasets){
158 importDataset(elDataset, sddNamespace, success, sddConfig);
159 if ((++i % modCount) == 0){ logger.info("Datasets handled: " + i);}
160 logger.info(i + " Datasets handled");
161 }
162 commitTransaction(ts);
163 return success;
164 }
165
166 /* (non-Javadoc)
167 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
168 */
169 protected boolean isIgnore(IImportConfigurator config){
170 return false;
171 }
172
173
174 // associates the reference of a media object in SDD with a CdmBase Object
175 protected void associateImageWithCdmBase(String refMO, CdmBase cb){
176 if ((refMO != null) && (cb!=null)) {
177 if (!refMO.equals("")) {
178 if (!mediaObject_ListCdmBase.containsKey(refMO)) {
179 List<CdmBase> lcb = new ArrayList<CdmBase>();
180 lcb.add(cb);
181 mediaObject_ListCdmBase.put(refMO,lcb);
182 } else {
183 List<CdmBase> lcb = mediaObject_ListCdmBase.get(refMO);
184 lcb.add(cb);
185 mediaObject_ListCdmBase.put(refMO,lcb);
186 }
187 }
188 }
189 }
190
191 // imports information about the Dataset
192 protected void importDatasetRepresentation(Element parent, Namespace sddNamespace){
193 logger.info("start Representation ...");
194 /* <Representation>
195 <Label>The Genus Viola</Label>
196 <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>
197 </Representation>
198 */
199 Element elRepresentation = parent.getChild("Representation",sddNamespace);
200 String label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace);
201 String detail = (String)ImportHelper.getXmlInputValue(elRepresentation, "Detail",sddNamespace);
202
203 sec.setTitleCache(label);
204
205 if (detail != null) {
206 Annotation annotation = Annotation.NewInstance(detail, datasetLanguage);
207 sec.addAnnotation(annotation);
208 }
209
210 List<Element> listMediaObjects = elRepresentation.getChildren("MediaObject",sddNamespace);
211
212 for (Element elMediaObject : listMediaObjects) {
213 String ref = null;
214 String role = null;
215 if (elMediaObject != null) {
216 ref = elMediaObject.getAttributeValue("ref");
217 role = elMediaObject.getAttributeValue("role");
218 }
219 if (ref != null) {
220 if (!ref.equals("")) {
221 this.associateImageWithCdmBase(ref,sourceReference);
222 this.associateImageWithCdmBase(ref,sec);
223 mediaObject_Role.put(ref,role);
224 }
225 }
226 }
227 }
228
229 // imports the representation (label, detail, lang) of a particular SDD element
230 protected void importRepresentation(Element parent, Namespace sddNamespace, VersionableEntity ve, String id, IImportConfigurator config){
231 Element elRepresentation = parent.getChild("Representation",sddNamespace);
232 // <Label xml:lang="la">Viola hederacea Labill.</Label>
233 List<Element> listLabels = elRepresentation.getChildren("Label",sddNamespace);
234 List<Element> listDetails = elRepresentation.getChildren("Detail",sddNamespace);
235 Map<Language,List<String>> langLabDet = new HashMap<Language,List<String>>();
236
237 for (Element elLabel : listLabels){
238 String lang = elLabel.getAttributeValue("lang",xmlNamespace);
239 Language language = null;
240 if (lang != null) {
241 if (!lang.equals("")) {
242 language = getTermService().getLanguageByIso(lang.substring(0, 2));
243 } else {
244 language = datasetLanguage;
245 }
246 } else {
247 language = datasetLanguage;
248 }
249 String label = elLabel.getText();
250 List<String> labDet = new ArrayList<String>(3);
251 labDet.add(label);
252 langLabDet.put(language, labDet);
253 }
254
255 for (Element elDetail : listDetails){
256 String lang = elDetail.getAttributeValue("lang",xmlNamespace);
257 String role = elDetail.getAttributeValue("role");
258 Language language = null;
259 if (lang != null) {
260 if (!lang.equals("")) {
261 language = getTermService().getLanguageByIso(lang.substring(0, 2));
262 } else {
263 language = datasetLanguage;
264 }
265 } else {
266 language = datasetLanguage;
267 }
268 String detail = elDetail.getText();
269 List<String> labDet = langLabDet.get(language);
270 labDet.add(detail);
271 labDet.add(role);
272 langLabDet.put(language, labDet);
273 }
274
275 if (ve instanceof IdentifiableEntity) {
276 IdentifiableEntity ie = (IdentifiableEntity) ve;
277 List<String> labDet = null;
278
279 if (ve instanceof TaxonNameBase) {
280 if (langLabDet.keySet().contains(getTermService().getLanguageByIso("la"))) {
281 labDet = langLabDet.get(getTermService().getLanguageByIso("la"));
282 } else if (langLabDet.keySet().contains(datasetLanguage)) {
283 labDet = langLabDet.get(datasetLanguage);
284 logger.info("TaxonName " + (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace) + " is not specified as a latin name.");
285 } else {
286 labDet = langLabDet.get(langLabDet.keySet().iterator().next());
287 logger.info("TaxonName " + (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace) + " is not specified as a latin name.");
288 }
289 } else {
290 labDet = langLabDet.get(langLabDet.keySet().iterator().next());
291 }
292
293 ie.setTitleCache(labDet.get(0));
294
295 if (labDet.size()>1) {
296 Annotation annotation = null;
297 if (labDet.get(1) != null) {
298 if (labDet.get(2) != null) {
299 annotation = Annotation.NewInstance(labDet.get(2) + " - " + labDet.get(1), datasetLanguage);
300 } else {
301 annotation = Annotation.NewInstance(labDet.get(1), datasetLanguage);
302 }
303 }
304 ie.addAnnotation(annotation);
305 }
306
307 ve = ie;
308
309 } else if (ve instanceof TermBase) {
310 TermBase tb = (TermBase) ve;
311
312 for (Iterator<Language> l = langLabDet.keySet().iterator() ; l.hasNext() ;){
313 Language lang = l.next();
314 List<String> labDet = langLabDet.get(lang);
315 if (labDet.size()>0){
316 if (labDet.size()>1) {
317 tb.addRepresentation(Representation.NewInstance(labDet.get(1), labDet.get(0), labDet.get(0), lang));
318 } else {
319 tb.addRepresentation(Representation.NewInstance(labDet.get(0), labDet.get(0), labDet.get(0), lang));
320 }
321 }
322 ve = tb;
323 }
324
325 } else if (ve instanceof Media) {
326 Media m = (Media) ve;
327
328 for (Iterator<Language> l = langLabDet.keySet().iterator() ; l.hasNext() ;){
329 Language lang = l.next();
330 List<String> labDet = langLabDet.get(lang);
331 if (labDet.get(0) != null){
332 MultilanguageText mt = MultilanguageText.NewInstance();
333 mt.add(LanguageString.NewInstance(labDet.get(0), lang));
334 m.setTitle(mt);
335 }
336 if (labDet.size()>1) {
337 m.addDescription(labDet.get(1), lang);
338 }
339 ve = m;
340 }
341
342 }
343
344 List <Element> listMediaObjects = elRepresentation.getChildren("MediaObject",sddNamespace);
345
346 for (Element elMediaObject : listMediaObjects) {
347 String ref = null;
348 String role = null;
349 if (elMediaObject != null) {
350 ref = elMediaObject.getAttributeValue("ref");
351 role = elMediaObject.getAttributeValue("role");
352 }
353 if (ref != null) {
354 if (!ref.equals("")) {
355 if (ref != null) {
356 if (ve instanceof TaxonDescription) {
357 TaxonDescription td = (TaxonDescription) ve;
358 //TODO: ensure that all images are imported
359 if (td.getDescriptionSources().toArray().length > 0) {
360 this.associateImageWithCdmBase(ref,(ReferenceBase) td.getDescriptionSources().toArray()[0]);
361 } else {
362 ReferenceBase descriptionSource = Generic.NewInstance();
363 td.addDescriptionSource(descriptionSource);
364 this.associateImageWithCdmBase(ref,descriptionSource);
365 }
366 } else {
367 this.associateImageWithCdmBase(ref,ve);
368 }
369 }
370
371 }
372 }
373 }
374
375 }
376
377 // imports the representation (label, detail, lang) of a particular SDD element
378 protected void importTechnicalMetadata(Element root, Namespace sddNamespace, SDDImportConfigurator sddConfig){
379 Element elTechnicalMetadata = root.getChild("TechnicalMetadata", sddNamespace);
380 String nameCreated = elTechnicalMetadata.getAttributeValue("created");
381 sourceReference = sddConfig.getSourceReference();
382
383 if (nameCreated != null) {
384 if (!nameCreated.equals("")) {
385 int year = Integer.parseInt(nameCreated.substring(0,4));
386 int monthOfYear = Integer.parseInt(nameCreated.substring(5,7));
387 int dayOfMonth = Integer.parseInt(nameCreated.substring(8,10));
388 int hourOfDay = Integer.parseInt(nameCreated.substring(11,13));
389 int minuteOfHour = Integer.parseInt(nameCreated.substring(14,16));
390 int secondOfMinute = Integer.parseInt(nameCreated.substring(17,19));
391 DateTime created = new DateTime(year,monthOfYear,dayOfMonth,hourOfDay,minuteOfHour,secondOfMinute,0);
392 sourceReference.setCreated(created);
393 sec.setCreated(created);
394 }
395 }
396
397 // <Generator name="n/a, handcrafted instance document" version="n/a"/>
398 Element elGenerator = elTechnicalMetadata.getChild("Generator", sddNamespace);
399 generatorName = elGenerator.getAttributeValue("name");
400 generatorVersion = elGenerator.getAttributeValue("version");
401
402 sec.addAnnotation(Annotation.NewDefaultLanguageInstance(generatorName + " - " + generatorVersion));
403 sourceReference.addAnnotation(Annotation.NewDefaultLanguageInstance(generatorName + " - " + generatorVersion));
404
405 }
406
407 // imports the complete dataset information
408 protected void importDataset(Element elDataset, Namespace sddNamespace, boolean success, SDDImportConfigurator sddConfig){ // <Dataset xml:lang="en-us">
409
410 importDatasetLanguage(elDataset,sddConfig);
411 importDatasetRepresentation(elDataset, sddNamespace);
412 importRevisionData(elDataset, sddNamespace);
413 importIPRStatements(elDataset, sddNamespace, sddConfig);
414 importTaxonNames(elDataset, sddNamespace, sddConfig);
415 importDescriptiveConcepts(elDataset, sddNamespace, sddConfig);
416 importCharacters(elDataset, sddNamespace, sddConfig, success);
417 importCharacterTrees(elDataset, sddNamespace, sddConfig, success);
418 importCodedDescriptions(elDataset, sddNamespace, sddConfig, success);
419 importAgents(elDataset, sddNamespace, sddConfig, success);
420 importPublications(elDataset, sddNamespace, sddConfig, success);
421 importMediaObjects(elDataset, sddNamespace, sddConfig, success);
422
423 if (authors != null) {
424 Team team = Team.NewInstance();
425 for (Iterator<Person> author = authors.values().iterator() ; author.hasNext() ;){
426 team.addTeamMember(author.next());
427 }
428 sec.setAuthorTeam(team);
429 sourceReference.setAuthorTeam(team);
430 }
431
432 if (editors != null) {
433 Person ed = Person.NewInstance();
434 for (Iterator<Person> editor = editors.values().iterator() ; editor.hasNext() ;){
435 ed = editor.next();
436 }
437 sec.setUpdatedBy(ed);
438 sourceReference.setUpdatedBy(ed);
439 }
440
441 if (copyright != null) {
442 sourceReference.addRights(copyright);
443 sec.addRights(copyright);
444 }
445
446 for (Iterator<String> refCD = taxonDescriptions.keySet().iterator() ; refCD.hasNext() ;){
447 String ref = refCD.next();
448 TaxonDescription td = taxonDescriptions.get(ref);
449 td.addDescriptionSource(sec);
450 if (citations.containsKey(ref)) {
451 Article publication = (Article) publications.get(citations.get(ref));
452 if (locations.containsKey(ref)) {
453 publication.addAnnotation(Annotation.NewInstance(locations.get(ref), datasetLanguage));
454 }
455 td.addDescriptionSource(publication);
456 }
457 }
458 logger.info("end makeTaxonDescriptions ...");
459
460 sddConfig.setSourceReference(sourceReference);
461
462 //saving of all imported data into the CDM db
463 ITermService termService = getTermService();
464 for (Iterator<StateData> k = stateDatas.values().iterator() ; k.hasNext() ;){
465 StateData sd = k.next();
466 termService.saveTerm(sd.getState());
467 }
468 for (Iterator<Feature> k = features.values().iterator() ; k.hasNext() ;){
469 Feature feature = k.next();
470 termService.saveTerm(feature);
471 }
472 if (units != null) {
473 for (Iterator<MeasurementUnit> k = units.values().iterator() ; k.hasNext() ;){
474 MeasurementUnit unit = k.next();
475 if (unit != null) {
476 termService.saveTerm(unit);
477 }
478 }
479 }
480 for (Iterator<StatisticalMeasure> k = statisticalMeasures.iterator() ; k.hasNext() ;) {
481 StatisticalMeasure sm = k.next();
482 termService.saveTerm(sm);
483 }
484
485 IReferenceService referenceService = getReferenceService();
486 // referenceService.saveReference(sourceReference);
487 for (Iterator<ReferenceBase> k = publications.values().iterator() ; k.hasNext() ;){
488 Article publication = (Article) k.next();
489 referenceService.saveReference(publication);
490 }
491
492 // Returns a CdmApplicationController created by the values of this configuration.
493 IDescriptionService descriptionService = getDescriptionService();
494
495 for (Iterator<TaxonDescription> k = taxonDescriptions.values().iterator() ; k.hasNext() ;){
496 TaxonDescription taxonDescription = k.next();
497 // Persists a Description
498 descriptionService.saveDescription(taxonDescription);
499 }
500
501 // descriptionService.saveFeatureNodeAll(featureNodes.values());
502
503 for (Iterator<FeatureTree> k = featureTrees.iterator() ; k.hasNext() ;) {
504 FeatureTree tree = k.next();
505 descriptionService.saveFeatureTree(tree);
506 }
507
508 }
509
510 // imports the default language of the dataset
511 protected void importDatasetLanguage(Element elDataset, SDDImportConfigurator sddConfig){
512 String nameLang = elDataset.getAttributeValue("lang",xmlNamespace);
513
514 if (!nameLang.equals("")) {
515 String iso = nameLang.substring(0, 2);
516 datasetLanguage = getTermService().getLanguageByIso(iso);
517 } else {
518 datasetLanguage = Language.ENGLISH();
519 }
520 if (datasetLanguage == null) {
521 datasetLanguage = Language.ENGLISH();
522 }
523 }
524
525 // imports the revision data associated with the Dataset (authors, modifications)
526 protected void importRevisionData(Element elDataset, Namespace sddNamespace){
527 // <RevisionData>
528 logger.info("start RevisionData ...");
529 Element elRevisionData = elDataset.getChild("RevisionData",sddNamespace);
530
531 // <Creators>
532 Element elCreators = elRevisionData.getChild("Creators",sddNamespace);
533
534 // <Agent role="aut" ref="a1"/>
535 List<Element> listAgents = elCreators.getChildren("Agent", sddNamespace);
536
537 int j = 0;
538 //for each Agent
539 for (Element elAgent : listAgents){
540
541 String role = elAgent.getAttributeValue("role");
542 String ref = elAgent.getAttributeValue("ref");
543 if (role.equals("aut")) {
544 if(!ref.equals("")) {
545 authors.put(ref, null);
546 }
547 }
548 if (role.equals("edt")) {
549 if(!ref.equals("")) {
550 editors.put(ref, null);
551 }
552 }
553
554 if ((++j % modCount) == 0){ logger.info("Agents handled: " + j);}
555
556 }
557
558 // <DateModified>2006-04-08T00:00:00</DateModified>
559 String stringDateModified = (String)ImportHelper.getXmlInputValue(elRevisionData, "DateModified",sddNamespace);
560
561 if (stringDateModified != null) {
562 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
563 Date d = null;
564 try {
565 d = sdf.parse(stringDateModified);
566 } catch(Exception e) {
567 System.err.println("Exception :");
568 e.printStackTrace();
569 }
570
571 GregorianCalendar updated = null;
572 if (d != null) {
573 updated = new java.util.GregorianCalendar();
574 updated.setTime(d);
575 sourceReference.setUpdated(updated);
576 sec.setUpdated(updated);
577 }
578 }
579 }
580
581 // imports ipr statements associated with a dataset
582 protected void importIPRStatements(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig){
583 // <IPRStatements>
584 logger.info("start IPRStatements ...");
585 Element elIPRStatements = elDataset.getChild("IPRStatements",sddNamespace);
586 // <IPRStatement role="Copyright">
587 if (elIPRStatements != null) {
588 List<Element> listIPRStatements = elIPRStatements.getChildren("IPRStatement", sddNamespace);
589 int j = 0;
590 //for each IPRStatement
591
592 for (Element elIPRStatement : listIPRStatements){
593
594 String role = elIPRStatement.getAttributeValue("role");
595 // <Label xml:lang="en-au">(c) 2003-2006 Centre for Occasional Botany.</Label>
596 Element elLabel = elIPRStatement.getChild("Label",sddNamespace);
597 String lang = "";
598 if (elLabel != null) {
599 lang = elLabel.getAttributeValue("lang",xmlNamespace);
600 }
601 String label = (String)ImportHelper.getXmlInputValue(elIPRStatement, "Label",sddNamespace);
602
603 if (role.equals("Copyright")) {
604 Language iprLanguage = null;
605 if (lang != null) {
606 if (!lang.equals("")) {
607 iprLanguage = getTermService().getLanguageByIso(lang.substring(0, 2));
608 //iprLanguage = datasetLanguage;
609 } else {
610 iprLanguage = datasetLanguage;
611 }
612 }
613 if (iprLanguage == null) {
614 iprLanguage = datasetLanguage;
615 }
616 copyright = Rights.NewInstance(label, iprLanguage);
617 }
618
619 if (copyright != null) {
620 sourceReference.addRights(copyright);
621 sec.addRights(copyright);
622 }
623
624 if ((++j % modCount) == 0){ logger.info("IPRStatements handled: " + j);}
625
626 }
627 }
628 }
629
630 // imports the taxon names
631 protected void importTaxonNames(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig){
632 // <TaxonNames>
633 logger.info("start TaxonNames ...");
634 Element elTaxonNames = elDataset.getChild("TaxonNames",sddNamespace);
635 // <TaxonName id="t1" uri="urn:lsid:authority:namespace:my-own-id">
636 if (elTaxonNames != null) {
637 List<Element> listTaxonNames = elTaxonNames.getChildren("TaxonName", sddNamespace);
638 int j = 0;
639 //for each TaxonName
640 for (Element elTaxonName : listTaxonNames){
641
642 String id = elTaxonName.getAttributeValue("id");
643 String uri = elTaxonName.getAttributeValue("uri");
644
645 NonViralName tnb = null;
646 if (!id.equals("")) {
647 tnb = NonViralName.NewInstance(null);
648 OriginalSource source = null;
649 if (uri != null) {
650 if (!uri.equals("")) {
651 source = OriginalSource.NewInstance(id, "TaxonName", Generic.NewInstance(), uri);
652 }
653 } else {
654 source = OriginalSource.NewInstance(id, "TaxonName");
655 }
656 tnb.addSource(source);
657 taxonNameBases.put(id,tnb);
658 }
659
660 // <Representation>
661 // <Label xml:lang="la">Viola hederacea Labill.</Label>
662 importRepresentation(elTaxonName, sddNamespace, tnb, id, sddConfig);
663
664 if ((++j % modCount) == 0){ logger.info("TaxonNames handled: " + j);}
665
666 }
667 }
668 }
669
670 // imports the representation (label, detail, lang) of a particular SDD element
671 protected void importCharacters(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){
672 // <Characters>
673 logger.info("start Characters ...");
674 Element elCharacters = elDataset.getChild("Characters", sddNamespace);
675
676 // <CategoricalCharacter id="c1">
677 if (elCharacters != null) {
678 List<Element> elCategoricalCharacters = elCharacters.getChildren("CategoricalCharacter", sddNamespace);
679 int j = 0;
680 //for each CategoricalCharacter
681 for (Element elCategoricalCharacter : elCategoricalCharacters){
682
683 try {
684
685 String idCC = elCategoricalCharacter.getAttributeValue("id");
686
687 // <Representation>
688 // <Label> Leaf complexity</Label>
689 // </Representation>
690
691 Feature categoricalCharacter = Feature.NewInstance();
692 importRepresentation(elCategoricalCharacter, sddNamespace, categoricalCharacter, idCC, sddConfig);
693
694 categoricalCharacter.setSupportsQuantitativeData(false);
695 categoricalCharacter.setSupportsTextData(false);
696
697 // <States>
698 Element elStates = elCategoricalCharacter.getChild("States",sddNamespace);
699
700 // <StateDefinition id="s1">
701 List<Element> elStateDefinitions = elStates.getChildren("StateDefinition",sddNamespace);
702 TermVocabulary<State> termVocabularyState = new TermVocabulary<State>();
703
704 int k = 0;
705 //for each StateDefinition
706 for (Element elStateDefinition : elStateDefinitions){
707
708 if ((++k % modCount) == 0){ logger.info("StateDefinitions handled: " + (k-1));}
709
710 String idSD = elStateDefinition.getAttributeValue("id");
711 // <Representation>
712 // <Label>Simple</Label>
713 // <MediaObject ref="ib" role="Primary"/>
714 // </Representation>
715 State state = State.NewInstance();
716 importRepresentation(elStateDefinition, sddNamespace, state, idSD, sddConfig);
717
718 StateData stateData = StateData.NewInstance();
719 stateData.setState(state);
720 termVocabularyState.addTerm(state);
721 stateDatas.put(idSD,stateData);
722 }
723
724 categoricalCharacter.addSupportedCategoricalEnumeration(termVocabularyState);
725 features.put(idCC, categoricalCharacter);
726
727 } catch (Exception e) {
728 //FIXME
729 logger.warn("Import of CategoricalCharacter " + j + " failed.");
730 success = false;
731 }
732
733 if ((++j % modCount) == 0){ logger.info("CategoricalCharacters handled: " + j);}
734
735 }
736
737 // <QuantitativeCharacter id="c2">
738 List<Element> elQuantitativeCharacters = elCharacters.getChildren("QuantitativeCharacter", sddNamespace);
739 j = 0;
740 //for each QuantitativeCharacter
741 for (Element elQuantitativeCharacter : elQuantitativeCharacters){
742
743 try {
744
745 String idQC = elQuantitativeCharacter.getAttributeValue("id");
746
747 // <Representation>
748 // <Label>Leaf length</Label>
749 // </Representation>
750 Feature quantitativeCharacter = Feature.NewInstance();
751 importRepresentation(elQuantitativeCharacter, sddNamespace, quantitativeCharacter, idQC, sddConfig);
752
753 quantitativeCharacter.setSupportsQuantitativeData(true);
754 quantitativeCharacter.setSupportsTextData(false);
755
756 // <MeasurementUnit>
757 // <Label role="Abbrev">m</Label>
758 // </MeasurementUnit>
759 Element elMeasurementUnit = elQuantitativeCharacter.getChild("MeasurementUnit",sddNamespace);
760 String label = "";
761 String role = "";
762 if (elMeasurementUnit != null) {
763 Element elLabel = elMeasurementUnit.getChild("Label",sddNamespace);
764 role = elLabel.getAttributeValue("role");
765 label = (String)ImportHelper.getXmlInputValue(elMeasurementUnit, "Label",sddNamespace);
766 }
767
768 MeasurementUnit unit = null;
769 if (!label.equals("")){
770 if (role != null) {
771 if (role.equals("Abbrev")){
772 unit = MeasurementUnit.NewInstance(label,label,label);
773 }
774 } else {
775 unit = MeasurementUnit.NewInstance(label,label,label);
776 }
777 }
778
779 if (unit != null) {
780 units.put(idQC, unit);
781 }
782
783 //<Default>
784 // <MeasurementUnitPrefix>milli</MeasurementUnitPrefix>
785 //</Default>
786 Element elDefault = elQuantitativeCharacter.getChild("Default",sddNamespace);
787 if (elDefault != null) {
788 String measurementUnitPrefix = (String)ImportHelper.getXmlInputValue(elDefault, "MeasurementUnitPrefix",sddNamespace);
789 if (!measurementUnitPrefix.equals("")){
790 defaultUnitPrefixes.put(idQC, measurementUnitPrefix);
791 }
792 }
793
794 features.put(idQC, quantitativeCharacter);
795
796 } catch (Exception e) {
797 //FIXME
798 logger.warn("Import of QuantitativeCharacter " + j + " failed.");
799 success = false;
800 }
801
802 if ((++j % modCount) == 0){ logger.info("QuantitativeCharacters handled: " + j);}
803
804 }
805
806 // <TextCharacter id="c3">
807 List<Element> elTextCharacters = elCharacters.getChildren("TextCharacter", sddNamespace);
808 j = 0;
809 //for each TextCharacter
810 for (Element elTextCharacter : elTextCharacters){
811
812 try {
813
814 String idTC = elTextCharacter.getAttributeValue("id");
815
816 // <Representation>
817 // <Label xml:lang="en">Leaf features not covered by other characters</Label>
818 // </Representation>
819 Feature textCharacter = Feature.NewInstance();
820 importRepresentation(elTextCharacter, sddNamespace, textCharacter, idTC, sddConfig);
821
822 textCharacter.setSupportsQuantitativeData(false);
823 textCharacter.setSupportsTextData(true);
824
825 features.put(idTC, textCharacter);
826
827 } catch (Exception e) {
828 //FIXME
829 logger.warn("Import of TextCharacter " + j + " failed.");
830 success = false;
831 }
832
833 if ((++j % modCount) == 0){ logger.info("TextCharacters handled: " + j);}
834
835 }
836
837 }
838
839 for (Iterator<Feature> f = features.values().iterator() ; f.hasNext() ;){
840 featureSet.add(f.next());
841 }
842
843 }
844
845 // imports the descriptions of taxa (specimens TODO)
846 protected void importCodedDescriptions(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){
847 // <CodedDescriptions>
848 logger.info("start CodedDescriptions ...");
849 Element elCodedDescriptions = elDataset.getChild("CodedDescriptions",sddNamespace);
850
851 // <CodedDescription id="D101">
852
853 if (elCodedDescriptions != null) {
854 List<Element> listCodedDescriptions = elCodedDescriptions.getChildren("CodedDescription", sddNamespace);
855 int j = 0;
856 //for each CodedDescription
857
858 for (Element elCodedDescription : listCodedDescriptions){
859
860 try {
861
862 String idCD = elCodedDescription.getAttributeValue("id");
863
864 // <Representation>
865 // <Label>&lt;i&gt;Viola hederacea&lt;/i&gt; Labill. as revised by R. Morris April 8, 2006</Label>
866 // </Representation>
867 TaxonDescription taxonDescription = TaxonDescription.NewInstance();
868 importRepresentation(elCodedDescription, sddNamespace, taxonDescription, idCD, sddConfig);
869
870 // <Scope>
871 // <TaxonName ref="t1"/>
872 // <Citation ref="p1" location="p. 30"/>
873 // </Scope>
874 Element elScope = elCodedDescription.getChild("Scope",sddNamespace);
875 String ref = "";
876 Taxon taxon = null;
877 if (elScope != null) {
878 Element elTaxonName = elScope.getChild("TaxonName",sddNamespace);
879 ref = elTaxonName.getAttributeValue("ref");
880
881 NonViralName taxonNameBase = taxonNameBases.get(ref);
882 taxon = Taxon.NewInstance(taxonNameBase, sec);
883 }
884
885 String refCitation = "";
886 String location = "";
887
888 if (elScope != null) {
889 Element elCitation = elScope.getChild("Citation",sddNamespace);
890 if (elCitation != null) {
891 refCitation = elCitation.getAttributeValue("ref");
892 location = elCitation.getAttributeValue("location");
893 }
894 }
895
896 // <SummaryData>
897 Element elSummaryData = elCodedDescription.getChild("SummaryData",sddNamespace);
898
899 if (elSummaryData != null) {
900
901 // <Categorical ref="c4">
902 List<Element> elCategoricals = elSummaryData.getChildren("Categorical", sddNamespace);
903 int k = 0;
904 //for each Categorical
905 for (Element elCategorical : elCategoricals){
906 if ((++k % modCount) == 0){ logger.info("Categorical handled: " + (k-1));}
907 ref = elCategorical.getAttributeValue("ref");
908 Feature feature = features.get(ref);
909 CategoricalData categoricalData = CategoricalData.NewInstance();
910 categoricalData.setFeature(feature);
911
912 // <State ref="s3"/>
913 List<Element> elStates = elCategorical.getChildren("State", sddNamespace);
914 int l = 0;
915 //for each State
916 for (Element elState : elStates){
917 if ((++l % modCount) == 0){ logger.info("States handled: " + (l-1));}
918 ref = elState.getAttributeValue("ref");
919 StateData stateData = stateDatas.get(ref);
920 categoricalData.addState(stateData);
921 }
922 taxonDescription.addElement(categoricalData);
923 }
924
925 // <Quantitative ref="c2">
926 List<Element> elQuantitatives = elSummaryData.getChildren("Quantitative", sddNamespace);
927 k = 0;
928 //for each Quantitative
929 for (Element elQuantitative : elQuantitatives){
930 if ((++k % modCount) == 0){ logger.info("Quantitative handled: " + (k-1));}
931 ref = elQuantitative.getAttributeValue("ref");
932 Feature feature = features.get(ref);
933 QuantitativeData quantitativeData = QuantitativeData.NewInstance();
934 quantitativeData.setFeature(feature);
935
936 MeasurementUnit unit = units.get(ref);
937 String prefix = defaultUnitPrefixes.get(ref);
938 if (unit != null) {
939 String u = unit.getLabel();
940 if (prefix != null) {
941 u = prefix + u;
942 }
943 unit.setLabel(u);
944 quantitativeData.setUnit(unit);
945 }
946
947 // <Measure type="Min" value="2.3"/>
948 List<Element> elMeasures = elQuantitative.getChildren("Measure", sddNamespace);
949 int l = 0;
950 //for each State
951 for (Element elMeasure : elMeasures){
952 if ((++l % modCount) == 0){ logger.info("States handled: " + (l-1));}
953 String type = elMeasure.getAttributeValue("type");
954 String value = elMeasure.getAttributeValue("value");
955 float v = Float.parseFloat(value);
956 StatisticalMeasure t = null;
957 if (type.equals("Min")) {
958 t = StatisticalMeasure.MIN();
959 } else if (type.equals("Mean")) {
960 t = StatisticalMeasure.AVERAGE();
961 } else if (type.equals("Max")) {
962 t = StatisticalMeasure.MAX();
963 } else if (type.equals("SD")) {
964 // Create a new StatisticalMeasure for standard deviation
965 t = StatisticalMeasure.STANDARD_DEVIATION();
966 } else if (type.equals("N")) {
967 t = StatisticalMeasure.SAMPLE_SIZE();
968 } else {
969 t = StatisticalMeasure.NewInstance(type,type,type);
970 statisticalMeasures.add(t);
971 }
972
973 StatisticalMeasurementValue statisticalValue = StatisticalMeasurementValue.NewInstance();
974 statisticalValue.setValue(v);
975 statisticalValue.setType(t);
976 quantitativeData.addStatisticalValue(statisticalValue);
977 featureData.add(statisticalValue);
978 }
979 taxonDescription.addElement(quantitativeData);
980 }
981
982 // <TextChar ref="c3">
983 List<Element> elTextChars = elSummaryData.getChildren("TextChar", sddNamespace);
984 k = 0;
985 //for each TextChar
986 for (Element elTextChar : elTextChars){
987 if ((++k % modCount) == 0){ logger.info("TextChar handled: " + (k-1));}
988 ref = elTextChar.getAttributeValue("ref");
989 Feature feature = features.get(ref);
990 TextData textData = TextData.NewInstance();
991 textData.setFeature(feature);
992
993 // <Content>Free form text</Content>
994 String content = (String)ImportHelper.getXmlInputValue(elTextChar, "Content",sddNamespace);
995 textData.putText(content, datasetLanguage);
996 taxonDescription.addElement(textData);
997 }
998
999 }
1000
1001 if (taxon != null) {
1002 taxon.addDescription(taxonDescription);
1003 }
1004
1005 if (!refCitation.equals("")){
1006 citations.put(idCD,refCitation);
1007 }
1008
1009 if (!location.equals("")){
1010 locations.put(idCD, location);
1011 }
1012
1013 taxonDescription.setDescriptiveSystem(featureSet);
1014
1015 taxonDescriptions.put(idCD, taxonDescription);
1016
1017 } catch (Exception e) {
1018 //FIXME
1019 logger.warn("Import of CodedDescription " + j + " failed.");
1020 success = false;
1021 }
1022
1023 if ((++j % modCount) == 0){ logger.info("CodedDescriptions handled: " + j);}
1024
1025 }
1026
1027 }
1028 }
1029
1030 // imports the persons associated with the dataset creation, modification, related publications
1031 protected void importAgents(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){
1032 // <Agents>
1033 logger.info("start Agents ...");
1034 Element elAgents = elDataset.getChild("Agents",sddNamespace);
1035
1036 // <Agent id="a1">
1037 List <Element> listAgents = elAgents.getChildren("Agent", sddNamespace);
1038 int j = 0;
1039 //for each Agent
1040 for (Element elAgent : listAgents){
1041
1042 try {
1043
1044 String idA = elAgent.getAttributeValue("id");
1045
1046 // <Representation>
1047 // <Label>Kevin Thiele</Label>
1048 // <Detail role="Description">Ali Baba is also known as r.a.m.</Detail>
1049 // </Representation>
1050 Person person = Person.NewInstance();
1051 importRepresentation(elAgent, sddNamespace, person, idA, sddConfig);
1052 person.addSource(OriginalSource.NewInstance(idA, "Agent"));
1053
1054 // <Links>
1055 Element elLinks = elAgent.getChild("Links",sddNamespace);
1056
1057 if (elLinks != null) {
1058
1059 // <Link rel="Alternate" href="http://www.diversitycampus.net/people/hagedorn"/>
1060 List<Element> listLinks = elLinks.getChildren("Link", sddNamespace);
1061 int k = 0;
1062 //for each Link
1063 for (Element elLink : listLinks){
1064
1065 try {
1066
1067 String rel = elLink.getAttributeValue("rel");
1068 String href = elLink.getAttributeValue("href");
1069
1070 Media link = Media.NewInstance();
1071 MediaRepresentation mr = MediaRepresentation.NewInstance();
1072 mr.addRepresentationPart(MediaRepresentationPart.NewInstance(href, null));
1073 link.addRepresentation(mr);
1074 person.addMedia(link);
1075
1076 } catch (Exception e) {
1077 //FIXME
1078 logger.warn("Import of Link " + k + " failed.");
1079 success = false;
1080 }
1081
1082 if ((++k % modCount) == 0){ logger.info("Links handled: " + k);}
1083
1084 }
1085 }
1086 if (authors.containsKey(idA)) {
1087 authors.put(idA,person);
1088 }
1089
1090 if (editors.containsKey(idA)) {
1091 editors.put(idA, person);
1092 }
1093
1094 } catch (Exception e) {
1095 //FIXME
1096 logger.warn("Import of Agent " + j + " failed.");
1097 success = false;
1098 }
1099
1100 if ((++j % modCount) == 0){ logger.info("Agents handled: " + j);}
1101
1102 }
1103 }
1104
1105 // imports publications related with the data set
1106 protected void importPublications(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){
1107 // <Publications>
1108 logger.info("start Publications ...");
1109 Element elPublications = elDataset.getChild("Publications",sddNamespace);
1110
1111 if (elPublications != null) {
1112 // <Publication id="p1">
1113 List<Element> listPublications = elPublications.getChildren("Publication", sddNamespace);
1114 int j = 0;
1115 //for each Publication
1116 for (Element elPublication : listPublications){
1117
1118 try {
1119
1120 String idP = elPublication.getAttributeValue("id");
1121
1122 // <Representation>
1123 // <Label>Sample Citation</Label>
1124 // </Representation>
1125 Article publication = Article.NewInstance();
1126 importRepresentation(elPublication, sddNamespace, publication, idP, sddConfig);
1127
1128 publications.put(idP,publication);
1129
1130 } catch (Exception e) {
1131 //FIXME
1132 logger.warn("Import of Publication " + j + " failed.");
1133 success = false;
1134 }
1135
1136 if ((++j % modCount) == 0){ logger.info("Publications handled: " + j);}
1137
1138 }
1139 }
1140 }
1141
1142 // imports media objects such as images
1143 protected void importMediaObjects(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){
1144 // <MediaObjects>
1145 logger.info("start MediaObjects ...");
1146 Element elMediaObjects = elDataset.getChild("MediaObjects",sddNamespace);
1147
1148 if (elMediaObjects != null) {
1149 // <MediaObject id="m1">
1150 List<Element> listMediaObjects = elMediaObjects.getChildren("MediaObject", sddNamespace);
1151 int j = 0;
1152 //for each Publication
1153 for (Element elMO : listMediaObjects){
1154
1155 String id = "";
1156
1157 try {
1158
1159 String idMO = elMO.getAttributeValue("id");
1160 id = idMO;
1161
1162 // <Representation>
1163 // <Label>Image description, e.g. to be used for alt-attribute in html.</Label>
1164 // </Representation>
1165 Media media = Media.NewInstance();
1166 importRepresentation(elMO, sddNamespace, media, idMO, sddConfig);
1167
1168 // <Type>Image</Type>
1169 // <Source href="http://test.edu/test.jpg"/>
1170 String type = (String)ImportHelper.getXmlInputValue(elMO,"Type",sddNamespace);
1171
1172 if ((type != null) && (type.equals("Image"))) {
1173 Element elSource = elMO.getChild("Source",sddNamespace);
1174 String href = elSource.getAttributeValue("href");
1175
1176 ImageMetaData imageMetaData = new ImageMetaData();
1177 ImageFile image = null;
1178
1179 if (href.substring(0,7).equals("http://")) {
1180 try{
1181 URL url = new URL(href);
1182 imageMetaData.readFrom(url);
1183 image = ImageFile.NewInstance(url.toString(), null, imageMetaData);
1184 } catch (MalformedURLException e) {
1185 logger.error("Malformed URL", e);
1186 }
1187 } else {
1188 String sns = sddConfig.getSourceNameString();
1189 File f = new File(sns);
1190 File parent = f.getParentFile();
1191 String fi = parent.toString() + File.separator + href;
1192 File file = new File(fi);
1193 imageMetaData.readFrom(file);
1194 image = ImageFile.NewInstance(file.toString(), null, imageMetaData);
1195 }
1196
1197 MediaRepresentation representation = MediaRepresentation.NewInstance(imageMetaData.getMimeType(), null);
1198 representation.addRepresentationPart(image);
1199
1200 media.addRepresentation(representation);
1201
1202 ArrayList<CdmBase> lcb = (ArrayList<CdmBase>) mediaObject_ListCdmBase.get(idMO);
1203 if (lcb != null) {
1204 for (int k = 0; k < lcb.size(); k++) {
1205 if (lcb.get(k) instanceof DefinedTermBase) {
1206 DefinedTermBase dtb = (DefinedTermBase) lcb.get(k);
1207 // if (lcb.get(0) instanceof DefinedTermBase) {
1208 // DefinedTermBase dtb = (DefinedTermBase) lcb.get(0);
1209 // if (dtb!=null) {
1210 // if (k == 0) {
1211 dtb.addMedia(media);
1212 // } else {
1213 // Media me = (Media) media.clone();
1214 // dtb.addMedia(me);
1215 // }
1216 // }
1217 } else if (lcb.get(k) instanceof ReferenceBase) {
1218 ReferenceBase rb = (ReferenceBase) lcb.get(k);
1219 //} else if (lcb.get(0) instanceof ReferenceBase) {
1220 //ReferenceBase rb = (ReferenceBase) lcb.get(0);
1221 // rb.setTitleCache(label);
1222 // if (rb!=null) {
1223 // if (k == 0) {
1224 rb.addMedia(media);
1225 // } else {
1226 // Media me = (Media) media.clone();
1227 // rb.addMedia(me);
1228 // }
1229 // }
1230 }
1231 }
1232 }
1233 }
1234
1235 } catch (Exception e) {
1236 //FIXME
1237 logger.warn("Could not attached MediaObject " + j + "(SDD: " + id + ") to several objects.");
1238 success = false;
1239 }
1240
1241 if ((++j % modCount) == 0){ logger.info("MediaObjects handled: " + j);
1242
1243 }
1244 }
1245 }
1246 }
1247
1248 // imports the <DescriptiveConcepts> block
1249 protected void importDescriptiveConcepts(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig){
1250 // <DescriptiveConcepts>
1251 logger.info("start DescriptiveConcepts ...");
1252 Element elDescriptiveConcepts = elDataset.getChild("DescriptiveConcepts",sddNamespace);
1253 // <DescriptiveConcept id="b">
1254 if (elDescriptiveConcepts != null) {
1255 List<Element> listDescriptiveConcepts = elDescriptiveConcepts.getChildren("DescriptiveConcept", sddNamespace);
1256 int j = 0;
1257 //for each DescriptiveConcept
1258 int g = 1;
1259 for (Element elDescriptiveConcept : listDescriptiveConcepts){
1260
1261 String id = elDescriptiveConcept.getAttributeValue("id");
1262 String uri = elDescriptiveConcept.getAttributeValue("uri");
1263
1264 FeatureNode fn = null;
1265
1266 if (!id.equals("")) {
1267 fn = FeatureNode.NewInstance();
1268 Feature feature = Feature.NewInstance();
1269 // <Representation>
1270 // <Label>Body</Label>
1271 importRepresentation(elDescriptiveConcept, sddNamespace, feature, id, sddConfig);
1272 features.put("g" + g, feature);
1273 g++;
1274 fn.setFeature(feature);
1275
1276 // TODO if an OriginalSource can be attached to a FeatureNode or a Feature
1277 // OriginalSource source = null;
1278 // if (uri != null) {
1279 // if (!uri.equals("")) {
1280 // source = OriginalSource.NewInstance(id, "DescriptiveConcept", Generic.NewInstance(), uri);
1281 // }
1282 // } else {
1283 // source = OriginalSource.NewInstance(id, "DescriptiveConcept");
1284 // }
1285 // fn.addSource(source);
1286
1287 featureNodes.put(id,fn);
1288 }
1289
1290 if ((++j % modCount) == 0){ logger.info("DescriptiveConcepts handled: " + j);}
1291
1292 }
1293 }
1294 }
1295
1296 // imports the descriptions of taxa (specimens TODO)
1297 protected void importCharacterTrees(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){
1298 // <CharacterTrees>
1299 logger.info("start CharacterTrees ...");
1300 Element elCharacterTrees = elDataset.getChild("CharacterTrees",sddNamespace);
1301
1302 // <CharacterTree>
1303
1304 if (elCharacterTrees != null) {
1305 List<Element> listCharacterTrees = elCharacterTrees.getChildren("CharacterTree", sddNamespace);
1306 int j = 0;
1307 //for each CharacterTree
1308
1309 for (Element elCharacterTree : listCharacterTrees){
1310
1311 try {
1312 Element elRepresentation = elCharacterTree.getChild("Representation",sddNamespace);
1313 String label = (String)ImportHelper.getXmlInputValue(elRepresentation,"Label",sddNamespace);
1314 Element elDesignedFor = elCharacterTree.getChild("DesignedFor",sddNamespace);
1315 List<Element> listRoles = elDesignedFor.getChildren("Role",sddNamespace);
1316 boolean isgroups = false;
1317
1318 for (Element elRole : listRoles){
1319 if (elRole.getText().equals("Filtering")) {
1320 isgroups = true;
1321 }
1322 }
1323
1324 if ((label.contains("group")) || (isgroups)) {
1325
1326 FeatureTree groups = FeatureTree.NewInstance();
1327 importRepresentation(elCharacterTree, sddNamespace, groups, "", sddConfig);
1328 FeatureNode root = groups.getRoot();
1329
1330 Element elNodes = elCharacterTree.getChild("Nodes", sddNamespace);
1331 List<Element> listNodes = elNodes.getChildren("Node", sddNamespace);
1332 for (Element elNode : listNodes){
1333 String idN = elNode.getAttributeValue("id");
1334 FeatureNode fn = null;
1335 if (!idN.equals("")) {
1336 Element elDescriptiveConcept = elNode.getChild("DescriptiveConcept", sddNamespace);
1337 String refDC = elDescriptiveConcept.getAttributeValue("ref");
1338 fn = featureNodes.get(refDC);
1339 root.addChild(fn);
1340 }
1341 nodes.put(idN, fn);
1342 }
1343
1344 List<Element> listCharNodes = elNodes.getChildren("CharNode", sddNamespace);
1345 for (Element elCharNode : listCharNodes){
1346 Element elParent = elCharNode.getChild("Parent", sddNamespace);
1347 String refP = elParent.getAttributeValue("ref");
1348 Element elCharacter = elCharNode.getChild("Character", sddNamespace);
1349 String refC = elCharacter.getAttributeValue("ref");
1350 FeatureNode fn = FeatureNode.NewInstance();
1351 if (!refP.equals("")) {
1352 FeatureNode parent = nodes.get(refP);
1353 parent.addChild(fn);
1354 Feature character = features.get(refC);
1355 fn.setFeature(character);
1356 // if method setParent() in FeatureNode becomes visible
1357 // fn.setParent(parent);
1358 }
1359 nodes.put(refC, fn);
1360 }
1361 featureTrees.add(groups);
1362 }
1363
1364 } catch (Exception e) {
1365 //FIXME
1366 logger.warn("Import of Character tree " + j + " failed.");
1367 success = false;
1368 }
1369
1370 if ((++j % modCount) == 0){ logger.info("CharacterTrees handled: " + j);}
1371
1372 }
1373
1374 }
1375 }
1376 }