X-Git-Url: https://dev.e-taxonomy.eu/gitweb/cdmlib.git/blobdiff_plain/d37cd796d8860ac6c3ecba71298beea4df419be8..1ffe31066bec4d71a980d15686061bb7a2592486:/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/SDDDescriptionIO.java diff --git a/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/SDDDescriptionIO.java b/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/SDDDescriptionIO.java index 55cb1c6d33..6fe8a9aff8 100644 --- a/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/SDDDescriptionIO.java +++ b/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/SDDDescriptionIO.java @@ -1,3 +1,12 @@ +/** + * Copyright (C) 2007 EDIT + * European Distributed Institute of Taxonomy + * http://www.e-taxonomy.eu + * + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * See LICENSE.TXT at the top of this package for the full license terms. + */ + package eu.etaxonomy.cdm.io.sdd; import java.io.File; @@ -6,7 +15,6 @@ import java.net.URL; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; -import java.util.GregorianCalendar; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -18,19 +26,25 @@ import org.apache.log4j.Logger; import org.jdom.Element; import org.jdom.Namespace; import org.joda.time.DateTime; +import org.springframework.stereotype.Component; import org.springframework.transaction.TransactionStatus; +import eu.etaxonomy.cdm.api.service.IAgentService; import eu.etaxonomy.cdm.api.service.IDescriptionService; import eu.etaxonomy.cdm.api.service.IReferenceService; import eu.etaxonomy.cdm.api.service.ITermService; import eu.etaxonomy.cdm.common.MediaMetaData.ImageMetaData; +import eu.etaxonomy.cdm.io.common.CdmImportBase; +import eu.etaxonomy.cdm.io.common.CdmIoBase; import eu.etaxonomy.cdm.io.common.ICdmIO; +import eu.etaxonomy.cdm.io.common.ICdmImport; import eu.etaxonomy.cdm.io.common.IImportConfigurator; import eu.etaxonomy.cdm.io.common.ImportHelper; import eu.etaxonomy.cdm.io.common.MapWrapper; import eu.etaxonomy.cdm.model.agent.Person; import eu.etaxonomy.cdm.model.agent.Team; import eu.etaxonomy.cdm.model.common.Annotation; +import eu.etaxonomy.cdm.model.common.AnnotationType; import eu.etaxonomy.cdm.model.common.CdmBase; import eu.etaxonomy.cdm.model.common.DefinedTermBase; import eu.etaxonomy.cdm.model.common.IdentifiableEntity; @@ -43,6 +57,8 @@ import eu.etaxonomy.cdm.model.common.TermVocabulary; import eu.etaxonomy.cdm.model.common.VersionableEntity; import eu.etaxonomy.cdm.model.description.CategoricalData; import eu.etaxonomy.cdm.model.description.Feature; +import eu.etaxonomy.cdm.model.description.FeatureNode; +import eu.etaxonomy.cdm.model.description.FeatureTree; import eu.etaxonomy.cdm.model.description.MeasurementUnit; import eu.etaxonomy.cdm.model.description.QuantitativeData; import eu.etaxonomy.cdm.model.description.State; @@ -57,31 +73,42 @@ import eu.etaxonomy.cdm.model.media.MediaRepresentation; import eu.etaxonomy.cdm.model.media.MediaRepresentationPart; import eu.etaxonomy.cdm.model.media.Rights; import eu.etaxonomy.cdm.model.name.NonViralName; +import eu.etaxonomy.cdm.model.name.TaxonNameBase; import eu.etaxonomy.cdm.model.reference.Article; import eu.etaxonomy.cdm.model.reference.Database; import eu.etaxonomy.cdm.model.reference.Generic; import eu.etaxonomy.cdm.model.reference.ReferenceBase; import eu.etaxonomy.cdm.model.taxon.Taxon; - -public class SDDDescriptionIO extends SDDIoBase implements ICdmIO { +/** + * @author h.fradin + * @created 24.10.2008 + * @version 1.0 + */ +@Component("sddDescriptionIO") +public class SDDDescriptionIO extends CdmImportBase implements ICdmImport { private static final Logger logger = Logger.getLogger(SDDDescriptionIO.class); private static int modCount = 1000; - private Map> mediaObject_ListCdmBase = new HashMap>(); - private Map mediaObject_Role = new HashMap(); - private Map taxonDescriptions = new HashMap(); - private Map stateDatas = new HashMap(); - private Map units = new HashMap(); + private Map authors = new HashMap(); + private Map citations = new HashMap(); private Map defaultUnitPrefixes = new HashMap(); + private Map editors = new HashMap(); + private Map featureNodes = new HashMap(); private Map features = new HashMap(); + private Map locations = new HashMap(); + private Map> mediaObject_ListCdmBase = new HashMap>(); + private Map mediaObject_Role = new HashMap(); + private Map nodes = new HashMap(); private Map publications = new HashMap(); - private Map authors = new HashMap(); - private Map editors = new HashMap(); + private Map stateDatas = new HashMap(); + private Map taxonDescriptions = new HashMap(); private Map taxonNameBases = new HashMap(); - private Map citations = new HashMap(); - private Map locations = new HashMap(); + private Map units = new HashMap(); + + private Set annotationTypes = new HashSet(); + private Set featureSet = new HashSet(); private ReferenceBase sec = Database.NewInstance(); private ReferenceBase sourceReference = null; @@ -95,6 +122,7 @@ public class SDDDescriptionIO extends SDDIoBase implements ICdmIO statisticalMeasures = new HashSet(); private Set featureData = new HashSet(); + private Set featureTrees = new HashSet(); private Rights copyright = null; @@ -103,17 +131,19 @@ public class SDDDescriptionIO extends SDDIoBase implements ICdmIO> stores){ +// @Override +// public boolean doInvoke(IImportConfigurator config, Map> stores){ + @Override + public boolean doInvoke(SDDImportState state){ TransactionStatus ts = startTransaction(); - SDDImportConfigurator sddConfig = (SDDImportConfigurator)config; + SDDImportConfigurator sddConfig = state.getConfig(); logger.info("start Datasets ..."); // @@ -141,7 +171,7 @@ public class SDDDescriptionIO extends SDDIoBase implements ICdmIOViola hederacea Labill. - Element elLabel = elRepresentation.getChild("Label",sddNamespace); - Element elDetail = elRepresentation.getChild("Detail",sddNamespace); - String lang = elLabel.getAttributeValue("lang",xmlNamespace); - Language language = null; - if (lang != null) { - if (!lang.equals("")) { - language = getTermService().getLanguageByIso(lang.substring(0, 2)); + List listLabels = elRepresentation.getChildren("Label",sddNamespace); + List listDetails = elRepresentation.getChildren("Detail",sddNamespace); + Map> langLabDet = new HashMap>(); + + for (Element elLabel : listLabels){ + String lang = elLabel.getAttributeValue("lang",xmlNamespace); + Language language = null; + if (lang != null) { + if (!lang.equals("")) { + language = getTermService().getLanguageByIso(lang.substring(0, 2)); + } else { + language = datasetLanguage; + } } else { language = datasetLanguage; } - } else { - language = datasetLanguage; + String label = elLabel.getText(); + List labDet = new ArrayList(3); + labDet.add(label); + langLabDet.put(language, labDet); } - String label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace); - String detail = (String)ImportHelper.getXmlInputValue(elRepresentation, "Detail",sddNamespace); - if ((lang != null) && (!lang.equals("la")) && (ve instanceof NonViralName)) { - logger.info("TaxonName " + label + " is not specified as a latin name."); + for (Element elDetail : listDetails){ + String lang = elDetail.getAttributeValue("lang",xmlNamespace); + String role = elDetail.getAttributeValue("role"); + Language language = null; + if (lang != null) { + if (!lang.equals("")) { + language = getTermService().getLanguageByIso(lang.substring(0, 2)); + } else { + language = datasetLanguage; + } + } else { + language = datasetLanguage; + } + String detail = elDetail.getText(); + List labDet = langLabDet.get(language); + labDet.add(detail); + labDet.add(role); + langLabDet.put(language, labDet); } if (ve instanceof IdentifiableEntity) { IdentifiableEntity ie = (IdentifiableEntity) ve; - ie.setTitleCache(label); + List labDet = null; + + if (ve instanceof TaxonNameBase) { + if (langLabDet.keySet().contains(getTermService().getLanguageByIso("la"))) { + labDet = langLabDet.get(getTermService().getLanguageByIso("la")); + } else if (langLabDet.keySet().contains(datasetLanguage)) { + labDet = langLabDet.get(datasetLanguage); + logger.info("TaxonName " + (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace) + " is not specified as a latin name."); + } else { + labDet = langLabDet.get(langLabDet.keySet().iterator().next()); + logger.info("TaxonName " + (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace) + " is not specified as a latin name."); + } + } else { + labDet = langLabDet.get(langLabDet.keySet().iterator().next()); + } + + ie.setTitleCache(labDet.get(0)); - if (elDetail != null) { - String role = elDetail.getAttributeValue("role"); + if (labDet.size()>1) { Annotation annotation = null; - if (detail != null) { - if (role != null) { - annotation = Annotation.NewInstance(role + " - " + detail, language); + if (labDet.get(1) != null) { + if (labDet.get(2) != null) { + annotation = Annotation.NewInstance(labDet.get(2) + " - " + labDet.get(1), datasetLanguage); } else { - annotation = Annotation.NewInstance(detail, language); + annotation = Annotation.NewInstance(labDet.get(1), datasetLanguage); } } ie.addAnnotation(annotation); @@ -247,14 +314,34 @@ public class SDDDescriptionIO extends SDDIoBase implements ICdmIO l = langLabDet.keySet().iterator() ; l.hasNext() ;){ + Language lang = l.next(); + List labDet = langLabDet.get(lang); + if (labDet.size()>0){ + if (labDet.size()>1) { + tb.addRepresentation(Representation.NewInstance(labDet.get(1), labDet.get(0), labDet.get(0), lang)); + } else { + tb.addRepresentation(Representation.NewInstance(labDet.get(0), labDet.get(0), labDet.get(0), lang)); + } + } + ve = tb; + } + + } else if (ve instanceof Media) { + Media m = (Media) ve; + + for (Iterator l = langLabDet.keySet().iterator() ; l.hasNext() ;){ + Language lang = l.next(); + List labDet = langLabDet.get(lang); + if (labDet.get(0) != null){ + m.addTitle(LanguageString.NewInstance(labDet.get(0), lang)); + } + if (labDet.size()>1) { + m.addDescription(labDet.get(1), lang); } + ve = m; } - ve = tb; + } List listMediaObjects = elRepresentation.getChildren("MediaObject",sddNamespace); @@ -314,7 +401,7 @@ public class SDDDescriptionIO extends SDDIoBase implements ICdmIO editor = editors.values().iterator() ; editor.hasNext() ;){ ed = editor.next(); } - sec.setUpdatedBy(ed); - sourceReference.setUpdatedBy(ed); + // TODO updatedBy refactored to use a user account, so setting a person is no longer applicable +// sec.setUpdatedBy(ed); +// sourceReference.setUpdatedBy(ed); } if (copyright != null) { @@ -364,7 +454,11 @@ public class SDDDescriptionIO extends SDDIoBase implements ICdmIO k = stateDatas.values().iterator() ; k.hasNext() ;){ - StateData sd = k.next(); - termService.saveTerm(sd.getState()); - } - for (Iterator k = features.values().iterator() ; k.hasNext() ;){ - Feature feature = k.next(); - termService.saveTerm(feature); - } - if (units != null) { - for (Iterator k = units.values().iterator() ; k.hasNext() ;){ - MeasurementUnit unit = k.next(); - if (unit != null) { - termService.saveTerm(unit); - } + ITermService termService = getTermService(); + for (Iterator k = stateDatas.values().iterator() ; k.hasNext() ;){ + StateData sd = k.next(); + termService.saveTerm(sd.getState()); + } + for (Iterator k = features.values().iterator() ; k.hasNext() ;){ + Feature feature = k.next(); + termService.saveTerm(feature); + } + if (units != null) { + for (Iterator k = units.values().iterator() ; k.hasNext() ;){ + MeasurementUnit unit = k.next(); + if (unit != null) { + termService.saveTerm(unit); } } - for (Iterator k = statisticalMeasures.iterator() ; k.hasNext() ;) { - StatisticalMeasure sm = k.next(); - termService.saveTerm(sm); - } + } + for (Iterator k = statisticalMeasures.iterator() ; k.hasNext() ;) { + StatisticalMeasure sm = k.next(); + termService.saveTerm(sm); + } + + for (Iterator at = annotationTypes.iterator() ; at.hasNext() ;) { + AnnotationType annotationType = at.next(); + termService.saveTerm(annotationType); + } - IReferenceService referenceService = sddConfig.getCdmAppController().getReferenceService(); - // referenceService.saveReference(sourceReference); - for (Iterator k = publications.values().iterator() ; k.hasNext() ;){ - Article publication = (Article) k.next(); - referenceService.saveReference(publication); - } + IReferenceService referenceService = getReferenceService(); + // referenceService.saveReference(sourceReference); + for (Iterator k = publications.values().iterator() ; k.hasNext() ;){ + Article publication = (Article) k.next(); + referenceService.saveReference(publication); + } - // Returns a CdmApplicationController created by the values of this configuration. - IDescriptionService descriptionService = sddConfig.getCdmAppController().getDescriptionService(); + IAgentService agentService = getAgentService(); + for (Iterator p = authors.values().iterator() ; p.hasNext() ;) { + Person person = p.next(); + agentService.saveAgent(person); + } + + for (Iterator p = editors.values().iterator() ; p.hasNext() ;) { + Person person = p.next(); + agentService.saveAgent(person); + } + + // Returns a CdmApplicationController created by the values of this configuration. + IDescriptionService descriptionService = getDescriptionService(); + + for (Iterator k = taxonDescriptions.values().iterator() ; k.hasNext() ;){ + TaxonDescription taxonDescription = k.next(); + // Persists a Description + descriptionService.saveDescription(taxonDescription); + } - for (Iterator k = taxonDescriptions.values().iterator() ; k.hasNext() ;){ - TaxonDescription taxonDescription = k.next(); - // Persists a Description - descriptionService.saveDescription(taxonDescription); - } +// descriptionService.saveFeatureNodeAll(featureNodes.values()); + + for (Iterator k = featureTrees.iterator() ; k.hasNext() ;) { + FeatureTree tree = k.next(); + descriptionService.saveFeatureTree(tree); } - // imports the default language of the dataset - protected void importDatasetLanguage(Element elDataset, SDDImportConfigurator sddConfig){ - String nameLang = elDataset.getAttributeValue("lang",xmlNamespace); +} - if (!nameLang.equals("")) { - String iso = nameLang.substring(0, 2); - datasetLanguage = sddConfig.getCdmAppController().getTermService().getLanguageByIso(iso); - } else { - datasetLanguage = Language.ENGLISH(); - } - if (datasetLanguage == null) { - datasetLanguage = Language.ENGLISH(); - } +// imports the default language of the dataset +protected void importDatasetLanguage(Element elDataset, SDDImportConfigurator sddConfig){ + String nameLang = elDataset.getAttributeValue("lang",xmlNamespace); + + if (!nameLang.equals("")) { + String iso = nameLang.substring(0, 2); + datasetLanguage = getTermService().getLanguageByIso(iso); + } else { + datasetLanguage = Language.ENGLISH(); + } + if (datasetLanguage == null) { + datasetLanguage = Language.ENGLISH(); } +} - // imports the revision data associated with the Dataset (authors, modifications) - protected void importRevisionData(Element elDataset, Namespace sddNamespace){ - // - logger.info("start RevisionData ..."); - Element elRevisionData = elDataset.getChild("RevisionData",sddNamespace); +// imports the revision data associated with the Dataset (authors, modifications) +protected void importRevisionData(Element elDataset, Namespace sddNamespace){ + // + logger.info("start RevisionData ..."); + Element elRevisionData = elDataset.getChild("RevisionData",sddNamespace); - // - Element elCreators = elRevisionData.getChild("Creators",sddNamespace); + // + Element elCreators = elRevisionData.getChild("Creators",sddNamespace); - // - List listAgents = elCreators.getChildren("Agent", sddNamespace); + // + List listAgents = elCreators.getChildren("Agent", sddNamespace); - int j = 0; - //for each Agent - for (Element elAgent : listAgents){ - - String role = elAgent.getAttributeValue("role"); - String ref = elAgent.getAttributeValue("ref"); - if (role.equals("aut")) { - if(!ref.equals("")) { - authors.put(ref, null); - } + int j = 0; + //for each Agent + for (Element elAgent : listAgents){ + + String role = elAgent.getAttributeValue("role"); + String ref = elAgent.getAttributeValue("ref"); + if (role.equals("aut")) { + if(!ref.equals("")) { + authors.put(ref, null); } - if (role.equals("edt")) { - if(!ref.equals("")) { - editors.put(ref, null); - } + } + if (role.equals("edt")) { + if(!ref.equals("")) { + editors.put(ref, null); } - - if ((++j % modCount) == 0){ logger.info("Agents handled: " + j);} - } - // 2006-04-08T00:00:00 - String stringDateModified = (String)ImportHelper.getXmlInputValue(elRevisionData, "DateModified",sddNamespace); + if ((++j % modCount) == 0){ logger.info("Agents handled: " + j);} - if (stringDateModified != null) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss"); - Date d = null; - try { - d = sdf.parse(stringDateModified); - } catch(Exception e) { - System.err.println("Exception :"); - e.printStackTrace(); - } + } - GregorianCalendar updated = null; - if (d != null) { - updated = new java.util.GregorianCalendar(); - updated.setTime(d); - sourceReference.setUpdated(updated); - sec.setUpdated(updated); - } + // 2006-04-08T00:00:00 + String stringDateModified = (String)ImportHelper.getXmlInputValue(elRevisionData, "DateModified",sddNamespace); + + if (stringDateModified != null) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss"); + Date d = null; + try { + d = sdf.parse(stringDateModified); + } catch(Exception e) { + System.err.println("Exception :"); + e.printStackTrace(); + } + + DateTime updated = null; + if (d != null) { + updated = new DateTime(d); + sourceReference.setUpdated(updated); + sec.setUpdated(updated); } } +} - // imports ipr statements associated with a dataset - protected void importIPRStatements(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig){ - // - logger.info("start IPRStatements ..."); - Element elIPRStatements = elDataset.getChild("IPRStatements",sddNamespace); - // - if (elIPRStatements != null) { - List listIPRStatements = elIPRStatements.getChildren("IPRStatement", sddNamespace); - int j = 0; - //for each IPRStatement - - for (Element elIPRStatement : listIPRStatements){ - - String role = elIPRStatement.getAttributeValue("role"); - // - Element elLabel = elIPRStatement.getChild("Label",sddNamespace); - String lang = ""; - if (elLabel != null) { - lang = elLabel.getAttributeValue("lang",xmlNamespace); - } - String label = (String)ImportHelper.getXmlInputValue(elIPRStatement, "Label",sddNamespace); - - if (role.equals("Copyright")) { - Language iprLanguage = null; - if (lang != null) { - if (!lang.equals("")) { - iprLanguage = sddConfig.getCdmAppController().getTermService().getLanguageByIso(lang.substring(0, 2)); - //iprLanguage = datasetLanguage; - } else { - iprLanguage = datasetLanguage; - } - } - if (iprLanguage == null) { +// imports ipr statements associated with a dataset +protected void importIPRStatements(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig){ + // + logger.info("start IPRStatements ..."); + Element elIPRStatements = elDataset.getChild("IPRStatements",sddNamespace); + // + if (elIPRStatements != null) { + List listIPRStatements = elIPRStatements.getChildren("IPRStatement", sddNamespace); + int j = 0; + //for each IPRStatement + + for (Element elIPRStatement : listIPRStatements){ + + String role = elIPRStatement.getAttributeValue("role"); + // + Element elLabel = elIPRStatement.getChild("Label",sddNamespace); + String lang = ""; + if (elLabel != null) { + lang = elLabel.getAttributeValue("lang",xmlNamespace); + } + String label = (String)ImportHelper.getXmlInputValue(elIPRStatement, "Label",sddNamespace); + + if (role.equals("Copyright")) { + Language iprLanguage = null; + if (lang != null) { + if (!lang.equals("")) { + iprLanguage = getTermService().getLanguageByIso(lang.substring(0, 2)); + //iprLanguage = datasetLanguage; + } else { iprLanguage = datasetLanguage; } - copyright = Rights.NewInstance(label, iprLanguage); } - - if (copyright != null) { - sourceReference.addRights(copyright); - sec.addRights(copyright); + if (iprLanguage == null) { + iprLanguage = datasetLanguage; } + copyright = Rights.NewInstance(label, iprLanguage); + } - if ((++j % modCount) == 0){ logger.info("IPRStatements handled: " + j);} - + if (copyright != null) { + sourceReference.addRights(copyright); + sec.addRights(copyright); } + + if ((++j % modCount) == 0){ logger.info("IPRStatements handled: " + j);} + } } +} - // imports the taxon names - protected void importTaxonNames(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig){ - // - logger.info("start TaxonNames ..."); - Element elTaxonNames = elDataset.getChild("TaxonNames",sddNamespace); - // - if (elTaxonNames != null) { - List listTaxonNames = elTaxonNames.getChildren("TaxonName", sddNamespace); - int j = 0; - //for each TaxonName - for (Element elTaxonName : listTaxonNames){ - - String id = elTaxonName.getAttributeValue("id"); - String uri = elTaxonName.getAttributeValue("uri"); - - NonViralName tnb = null; - if (!id.equals("")) { - tnb = NonViralName.NewInstance(null); - OriginalSource source = null; - if (uri != null) { - if (!uri.equals("")) { - source = OriginalSource.NewInstance(id, "TaxonName", Generic.NewInstance(), uri); - } - } else { - source = OriginalSource.NewInstance(id, "TaxonName"); +// imports the taxon names +protected void importTaxonNames(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig){ + // + logger.info("start TaxonNames ..."); + Element elTaxonNames = elDataset.getChild("TaxonNames",sddNamespace); + // + if (elTaxonNames != null) { + List listTaxonNames = elTaxonNames.getChildren("TaxonName", sddNamespace); + int j = 0; + //for each TaxonName + for (Element elTaxonName : listTaxonNames){ + + String id = elTaxonName.getAttributeValue("id"); + String uri = elTaxonName.getAttributeValue("uri"); + + NonViralName tnb = null; + if (!id.equals("")) { + tnb = NonViralName.NewInstance(null); + OriginalSource source = null; + if (uri != null) { + if (!uri.equals("")) { + source = OriginalSource.NewInstance(id, "TaxonName", Generic.NewInstance(), uri); } - tnb.addSource(source); - taxonNameBases.put(id,tnb); + } else { + source = OriginalSource.NewInstance(id, "TaxonName"); } + tnb.addSource(source); + taxonNameBases.put(id,tnb); + } - // - // - importRepresentation(elTaxonName, sddNamespace, tnb, id, sddConfig); + // + // + importRepresentation(elTaxonName, sddNamespace, tnb, id, sddConfig); - if ((++j % modCount) == 0){ logger.info("TaxonNames handled: " + j);} + if ((++j % modCount) == 0){ logger.info("TaxonNames handled: " + j);} - } } } +} - // imports the representation (label, detail, lang) of a particular SDD element - protected void importCharacters(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){ - // - logger.info("start Characters ..."); - Element elCharacters = elDataset.getChild("Characters", sddNamespace); +// imports the representation (label, detail, lang) of a particular SDD element +protected void importCharacters(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){ + // + logger.info("start Characters ..."); + Element elCharacters = elDataset.getChild("Characters", sddNamespace); - // - if (elCharacters != null) { - List elCategoricalCharacters = elCharacters.getChildren("CategoricalCharacter", sddNamespace); - int j = 0; - //for each CategoricalCharacter - for (Element elCategoricalCharacter : elCategoricalCharacters){ + // + if (elCharacters != null) { + List elCategoricalCharacters = elCharacters.getChildren("CategoricalCharacter", sddNamespace); + int j = 0; + //for each CategoricalCharacter + for (Element elCategoricalCharacter : elCategoricalCharacters){ - try { + try { - String idCC = elCategoricalCharacter.getAttributeValue("id"); + String idCC = elCategoricalCharacter.getAttributeValue("id"); - // - // - // + // + // + // - Feature categoricalCharacter = Feature.NewInstance(); - importRepresentation(elCategoricalCharacter, sddNamespace, categoricalCharacter, idCC, sddConfig); + Feature categoricalCharacter = Feature.NewInstance(); + importRepresentation(elCategoricalCharacter, sddNamespace, categoricalCharacter, idCC, sddConfig); - categoricalCharacter.setSupportsQuantitativeData(false); - categoricalCharacter.setSupportsTextData(true); + categoricalCharacter.setSupportsCategoricalData(true); - // - Element elStates = elCategoricalCharacter.getChild("States",sddNamespace); + // + Element elStates = elCategoricalCharacter.getChild("States",sddNamespace); - // - List elStateDefinitions = elStates.getChildren("StateDefinition",sddNamespace); - TermVocabulary termVocabularyState = new TermVocabulary(); + // + List elStateDefinitions = elStates.getChildren("StateDefinition",sddNamespace); + TermVocabulary termVocabularyState = new TermVocabulary(); - int k = 0; - //for each StateDefinition - for (Element elStateDefinition : elStateDefinitions){ - - if ((++k % modCount) == 0){ logger.info("StateDefinitions handled: " + (k-1));} - - String idSD = elStateDefinition.getAttributeValue("id"); - // - // - // - // - State state = State.NewInstance(); - importRepresentation(elStateDefinition, sddNamespace, state, idSD, sddConfig); - - StateData stateData = StateData.NewInstance(); - stateData.setState(state); - termVocabularyState.addTerm(state); - stateDatas.put(idSD,stateData); - } + int k = 0; + //for each StateDefinition + for (Element elStateDefinition : elStateDefinitions){ + + if ((++k % modCount) == 0){ logger.info("StateDefinitions handled: " + (k-1));} - categoricalCharacter.addSupportedCategoricalEnumeration(termVocabularyState); - features.put(idCC, categoricalCharacter); + String idSD = elStateDefinition.getAttributeValue("id"); + // + // + // + // + State state = State.NewInstance(); + importRepresentation(elStateDefinition, sddNamespace, state, idSD, sddConfig); - } catch (Exception e) { - //FIXME - logger.warn("Import of CategoricalCharacter " + j + " failed."); - success = false; + StateData stateData = StateData.NewInstance(); + stateData.setState(state); + termVocabularyState.addTerm(state); + stateDatas.put(idSD,stateData); } - if ((++j % modCount) == 0){ logger.info("CategoricalCharacters handled: " + j);} + categoricalCharacter.addSupportedCategoricalEnumeration(termVocabularyState); + features.put(idCC, categoricalCharacter); + } catch (Exception e) { + //FIXME + logger.warn("Import of CategoricalCharacter " + j + " failed."); + success = false; } - // - List elQuantitativeCharacters = elCharacters.getChildren("QuantitativeCharacter", sddNamespace); - j = 0; - //for each QuantitativeCharacter - for (Element elQuantitativeCharacter : elQuantitativeCharacters){ + if ((++j % modCount) == 0){ logger.info("CategoricalCharacters handled: " + j);} - try { + } - String idQC = elQuantitativeCharacter.getAttributeValue("id"); + // + List elQuantitativeCharacters = elCharacters.getChildren("QuantitativeCharacter", sddNamespace); + j = 0; + //for each QuantitativeCharacter + for (Element elQuantitativeCharacter : elQuantitativeCharacters){ - // - // - // - Feature quantitativeCharacter = Feature.NewInstance(); - importRepresentation(elQuantitativeCharacter, sddNamespace, quantitativeCharacter, idQC, sddConfig); - - quantitativeCharacter.setSupportsQuantitativeData(true); - quantitativeCharacter.setSupportsTextData(false); - - // - // - // - Element elMeasurementUnit = elQuantitativeCharacter.getChild("MeasurementUnit",sddNamespace); - String label = ""; - String role = ""; - if (elMeasurementUnit != null) { - Element elLabel = elMeasurementUnit.getChild("Label",sddNamespace); - role = elLabel.getAttributeValue("role"); - label = (String)ImportHelper.getXmlInputValue(elMeasurementUnit, "Label",sddNamespace); - } + try { - MeasurementUnit unit = null; - if (!label.equals("")){ - if (role != null) { - if (role.equals("Abbrev")){ - unit = MeasurementUnit.NewInstance(label,label,label); - } - } else { - unit = MeasurementUnit.NewInstance(label,label,label); - } - } + String idQC = elQuantitativeCharacter.getAttributeValue("id"); - if (unit != null) { - units.put(idQC, unit); - } + // + // + // + Feature quantitativeCharacter = Feature.NewInstance(); + importRepresentation(elQuantitativeCharacter, sddNamespace, quantitativeCharacter, idQC, sddConfig); + + quantitativeCharacter.setSupportsQuantitativeData(true); + + // + // + // + Element elMeasurementUnit = elQuantitativeCharacter.getChild("MeasurementUnit",sddNamespace); + String label = ""; + String role = ""; + if (elMeasurementUnit != null) { + Element elLabel = elMeasurementUnit.getChild("Label",sddNamespace); + role = elLabel.getAttributeValue("role"); + label = (String)ImportHelper.getXmlInputValue(elMeasurementUnit, "Label",sddNamespace); + } - // - // milli - // - Element elDefault = elQuantitativeCharacter.getChild("Default",sddNamespace); - if (elDefault != null) { - String measurementUnitPrefix = (String)ImportHelper.getXmlInputValue(elDefault, "MeasurementUnitPrefix",sddNamespace); - if (!measurementUnitPrefix.equals("")){ - defaultUnitPrefixes.put(idQC, measurementUnitPrefix); + MeasurementUnit unit = null; + if (!label.equals("")){ + if (role != null) { + if (role.equals("Abbrev")){ + unit = MeasurementUnit.NewInstance(label,label,label); } + } else { + unit = MeasurementUnit.NewInstance(label,label,label); } + } - features.put(idQC, quantitativeCharacter); + if (unit != null) { + units.put(idQC, unit); + } - } catch (Exception e) { - //FIXME - logger.warn("Import of QuantitativeCharacter " + j + " failed."); - success = false; + // + // milli + // + Element elDefault = elQuantitativeCharacter.getChild("Default",sddNamespace); + if (elDefault != null) { + String measurementUnitPrefix = (String)ImportHelper.getXmlInputValue(elDefault, "MeasurementUnitPrefix",sddNamespace); + if (!measurementUnitPrefix.equals("")){ + defaultUnitPrefixes.put(idQC, measurementUnitPrefix); + } } - if ((++j % modCount) == 0){ logger.info("QuantitativeCharacters handled: " + j);} + features.put(idQC, quantitativeCharacter); + } catch (Exception e) { + //FIXME + logger.warn("Import of QuantitativeCharacter " + j + " failed."); + success = false; } - // - List elTextCharacters = elCharacters.getChildren("TextCharacter", sddNamespace); - j = 0; - //for each TextCharacter - for (Element elTextCharacter : elTextCharacters){ + if ((++j % modCount) == 0){ logger.info("QuantitativeCharacters handled: " + j);} - try { + } - String idTC = elTextCharacter.getAttributeValue("id"); + // + List elTextCharacters = elCharacters.getChildren("TextCharacter", sddNamespace); + j = 0; + //for each TextCharacter + for (Element elTextCharacter : elTextCharacters){ - // - // - // - Feature textCharacter = Feature.NewInstance(); - importRepresentation(elTextCharacter, sddNamespace, textCharacter, idTC, sddConfig); + try { - textCharacter.setSupportsQuantitativeData(false); - textCharacter.setSupportsTextData(true); + String idTC = elTextCharacter.getAttributeValue("id"); - features.put(idTC, textCharacter); + // + // + // + Feature textCharacter = Feature.NewInstance(); + importRepresentation(elTextCharacter, sddNamespace, textCharacter, idTC, sddConfig); - } catch (Exception e) { - //FIXME - logger.warn("Import of TextCharacter " + j + " failed."); - success = false; - } + textCharacter.setSupportsTextData(true); - if ((++j % modCount) == 0){ logger.info("TextCharacters handled: " + j);} + features.put(idTC, textCharacter); + } catch (Exception e) { + //FIXME + logger.warn("Import of TextCharacter " + j + " failed."); + success = false; } + if ((++j % modCount) == 0){ logger.info("TextCharacters handled: " + j);} + } + } + + for (Iterator f = features.values().iterator() ; f.hasNext() ;){ + featureSet.add(f.next()); + } + +} - // imports the descriptions of taxa (specimens TODO) - protected void importCodedDescriptions(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){ - // - logger.info("start CodedDescriptions ..."); - Element elCodedDescriptions = elDataset.getChild("CodedDescriptions",sddNamespace); +// imports the descriptions of taxa (specimens TODO) +protected void importCodedDescriptions(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){ + // + logger.info("start CodedDescriptions ..."); + Element elCodedDescriptions = elDataset.getChild("CodedDescriptions",sddNamespace); - // + // - if (elCodedDescriptions != null) { - List listCodedDescriptions = elCodedDescriptions.getChildren("CodedDescription", sddNamespace); - int j = 0; - //for each CodedDescription + if (elCodedDescriptions != null) { + List listCodedDescriptions = elCodedDescriptions.getChildren("CodedDescription", sddNamespace); + int j = 0; + //for each CodedDescription - for (Element elCodedDescription : listCodedDescriptions){ + for (Element elCodedDescription : listCodedDescriptions){ - try { + try { - String idCD = elCodedDescription.getAttributeValue("id"); + String idCD = elCodedDescription.getAttributeValue("id"); - // - // - // - TaxonDescription taxonDescription = TaxonDescription.NewInstance(); - importRepresentation(elCodedDescription, sddNamespace, taxonDescription, idCD, sddConfig); - - // - // - // - // - Element elScope = elCodedDescription.getChild("Scope",sddNamespace); - String ref = ""; - Taxon taxon = null; - if (elScope != null) { - Element elTaxonName = elScope.getChild("TaxonName",sddNamespace); - ref = elTaxonName.getAttributeValue("ref"); - - NonViralName taxonNameBase = taxonNameBases.get(ref); - taxon = Taxon.NewInstance(taxonNameBase, sec); + // + // + // + TaxonDescription taxonDescription = TaxonDescription.NewInstance(); + importRepresentation(elCodedDescription, sddNamespace, taxonDescription, idCD, sddConfig); + + // + // + // + // + Element elScope = elCodedDescription.getChild("Scope",sddNamespace); + String ref = ""; + Taxon taxon = null; + if (elScope != null) { + Element elTaxonName = elScope.getChild("TaxonName",sddNamespace); + ref = elTaxonName.getAttributeValue("ref"); + + NonViralName taxonNameBase = taxonNameBases.get(ref); + taxon = Taxon.NewInstance(taxonNameBase, sec); + } + + String refCitation = ""; + String location = ""; + + if (elScope != null) { + Element elCitation = elScope.getChild("Citation",sddNamespace); + if (elCitation != null) { + refCitation = elCitation.getAttributeValue("ref"); + location = elCitation.getAttributeValue("location"); } + } + + // + Element elSummaryData = elCodedDescription.getChild("SummaryData",sddNamespace); - String refCitation = ""; - String location = ""; + if (elSummaryData != null) { - if (elScope != null) { - Element elCitation = elScope.getChild("Citation",sddNamespace); - if (elCitation != null) { - refCitation = elCitation.getAttributeValue("ref"); - location = elCitation.getAttributeValue("location"); + // + List elCategoricals = elSummaryData.getChildren("Categorical", sddNamespace); + int k = 0; + //for each Categorical + for (Element elCategorical : elCategoricals){ + if ((++k % modCount) == 0){ logger.info("Categorical handled: " + (k-1));} + ref = elCategorical.getAttributeValue("ref"); + Feature feature = features.get(ref); + CategoricalData categoricalData = CategoricalData.NewInstance(); + categoricalData.setFeature(feature); + + // + List elStates = elCategorical.getChildren("State", sddNamespace); + int l = 0; + //for each State + for (Element elState : elStates){ + if ((++l % modCount) == 0){ logger.info("States handled: " + (l-1));} + ref = elState.getAttributeValue("ref"); + StateData stateData = stateDatas.get(ref); + categoricalData.addState(stateData); } + taxonDescription.addElement(categoricalData); } - // - Element elSummaryData = elCodedDescription.getChild("SummaryData",sddNamespace); - - if (elSummaryData != null) { - - // - List elCategoricals = elSummaryData.getChildren("Categorical", sddNamespace); - int k = 0; - //for each Categorical - for (Element elCategorical : elCategoricals){ - if ((++k % modCount) == 0){ logger.info("Categorical handled: " + (k-1));} - ref = elCategorical.getAttributeValue("ref"); - Feature feature = features.get(ref); - CategoricalData categoricalData = CategoricalData.NewInstance(); - categoricalData.setFeature(feature); - - // - List elStates = elCategorical.getChildren("State", sddNamespace); - int l = 0; - //for each State - for (Element elState : elStates){ - if ((++l % modCount) == 0){ logger.info("States handled: " + (l-1));} - ref = elState.getAttributeValue("ref"); - StateData stateData = stateDatas.get(ref); - categoricalData.addState(stateData); + // + List elQuantitatives = elSummaryData.getChildren("Quantitative", sddNamespace); + k = 0; + //for each Quantitative + for (Element elQuantitative : elQuantitatives){ + if ((++k % modCount) == 0){ logger.info("Quantitative handled: " + (k-1));} + ref = elQuantitative.getAttributeValue("ref"); + Feature feature = features.get(ref); + QuantitativeData quantitativeData = QuantitativeData.NewInstance(); + quantitativeData.setFeature(feature); + + MeasurementUnit unit = units.get(ref); + String prefix = defaultUnitPrefixes.get(ref); + if (unit != null) { + String u = unit.getLabel(); + if (prefix != null) { + u = prefix + u; } - taxonDescription.addElement(categoricalData); + unit.setLabel(u); + quantitativeData.setUnit(unit); } - // - List elQuantitatives = elSummaryData.getChildren("Quantitative", sddNamespace); - k = 0; - //for each Quantitative - for (Element elQuantitative : elQuantitatives){ - if ((++k % modCount) == 0){ logger.info("Quantitative handled: " + (k-1));} - ref = elQuantitative.getAttributeValue("ref"); - Feature feature = features.get(ref); - QuantitativeData quantitativeData = QuantitativeData.NewInstance(); - quantitativeData.setFeature(feature); - - MeasurementUnit unit = units.get(ref); - String prefix = defaultUnitPrefixes.get(ref); - if (unit != null) { - String u = unit.getLabel(); - if (prefix != null) { - u = prefix + u; - } - unit.setLabel(u); - quantitativeData.setUnit(unit); - } - - // - List elMeasures = elQuantitative.getChildren("Measure", sddNamespace); - int l = 0; - //for each State - for (Element elMeasure : elMeasures){ - if ((++l % modCount) == 0){ logger.info("States handled: " + (l-1));} - String type = elMeasure.getAttributeValue("type"); - String value = elMeasure.getAttributeValue("value"); - float v = Float.parseFloat(value); - StatisticalMeasure t = null; - if (type.equals("Min")) { - t = StatisticalMeasure.MIN(); - } else if (type.equals("Mean")) { - t = StatisticalMeasure.AVERAGE(); - } else if (type.equals("Max")) { - t = StatisticalMeasure.MAX(); - } else if (type.equals("SD")) { - // Create a new StatisticalMeasure for standard deviation - t = StatisticalMeasure.STANDARD_DEVIATION(); - } else if (type.equals("N")) { - t = StatisticalMeasure.SAMPLE_SIZE(); - } else { - t = StatisticalMeasure.NewInstance(type,type,type); - statisticalMeasures.add(t); - } - - StatisticalMeasurementValue statisticalValue = StatisticalMeasurementValue.NewInstance(); - statisticalValue.setValue(v); - statisticalValue.setType(t); - quantitativeData.addStatisticalValue(statisticalValue); - featureData.add(statisticalValue); + // + List elMeasures = elQuantitative.getChildren("Measure", sddNamespace); + int l = 0; + //for each State + for (Element elMeasure : elMeasures){ + if ((++l % modCount) == 0){ logger.info("States handled: " + (l-1));} + String type = elMeasure.getAttributeValue("type"); + String value = elMeasure.getAttributeValue("value"); + float v = Float.parseFloat(value); + StatisticalMeasure t = null; + if (type.equals("Min")) { + t = StatisticalMeasure.MIN(); + } else if (type.equals("Mean")) { + t = StatisticalMeasure.AVERAGE(); + } else if (type.equals("Max")) { + t = StatisticalMeasure.MAX(); + } else if (type.equals("SD")) { + // Create a new StatisticalMeasure for standard deviation + t = StatisticalMeasure.STANDARD_DEVIATION(); + } else if (type.equals("N")) { + t = StatisticalMeasure.SAMPLE_SIZE(); + } else { + t = StatisticalMeasure.NewInstance(type,type,type); + statisticalMeasures.add(t); } - taxonDescription.addElement(quantitativeData); - } - // - List elTextChars = elSummaryData.getChildren("TextChar", sddNamespace); - k = 0; - //for each TextChar - for (Element elTextChar : elTextChars){ - if ((++k % modCount) == 0){ logger.info("TextChar handled: " + (k-1));} - ref = elTextChar.getAttributeValue("ref"); - Feature feature = features.get(ref); - TextData textData = TextData.NewInstance(); - textData.setFeature(feature); - - // Free form text - String content = (String)ImportHelper.getXmlInputValue(elTextChar, "Content",sddNamespace); - textData.putText(content, datasetLanguage); - taxonDescription.addElement(textData); + StatisticalMeasurementValue statisticalValue = StatisticalMeasurementValue.NewInstance(); + statisticalValue.setValue(v); + statisticalValue.setType(t); + quantitativeData.addStatisticalValue(statisticalValue); + featureData.add(statisticalValue); } - + taxonDescription.addElement(quantitativeData); } - if (taxon != null) { - taxon.addDescription(taxonDescription); + // + List elTextChars = elSummaryData.getChildren("TextChar", sddNamespace); + k = 0; + //for each TextChar + for (Element elTextChar : elTextChars){ + if ((++k % modCount) == 0){ logger.info("TextChar handled: " + (k-1));} + ref = elTextChar.getAttributeValue("ref"); + Feature feature = features.get(ref); + TextData textData = TextData.NewInstance(); + textData.setFeature(feature); + + // Free form text + String content = (String)ImportHelper.getXmlInputValue(elTextChar, "Content",sddNamespace); + textData.putText(content, datasetLanguage); + taxonDescription.addElement(textData); } - if (!refCitation.equals("")){ - citations.put(idCD,refCitation); - } - - if (!location.equals("")){ - locations.put(idCD, location); - } + } - taxonDescriptions.put(idCD, taxonDescription); + if (taxon != null) { + taxon.addDescription(taxonDescription); + } - } catch (Exception e) { - //FIXME - logger.warn("Import of CodedDescription " + j + " failed."); - success = false; + if (!refCitation.equals("")){ + citations.put(idCD,refCitation); } - if ((++j % modCount) == 0){ logger.info("CodedDescriptions handled: " + j);} + if (!location.equals("")){ + locations.put(idCD, location); + } + + taxonDescription.setDescriptiveSystem(featureSet); + + taxonDescriptions.put(idCD, taxonDescription); + } catch (Exception e) { + //FIXME + logger.warn("Import of CodedDescription " + j + " failed."); + success = false; } + if ((++j % modCount) == 0){ logger.info("CodedDescriptions handled: " + j);} + } + } +} - // imports the persons associated with the dataset creation, modification, related publications - protected void importAgents(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){ - // - logger.info("start Agents ..."); - Element elAgents = elDataset.getChild("Agents",sddNamespace); +// imports the persons associated with the dataset creation, modification, related publications +protected void importAgents(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){ + // + logger.info("start Agents ..."); + Element elAgents = elDataset.getChild("Agents",sddNamespace); - // - List listAgents = elAgents.getChildren("Agent", sddNamespace); - int j = 0; - //for each Agent - for (Element elAgent : listAgents){ + // + List listAgents = elAgents.getChildren("Agent", sddNamespace); + int j = 0; + //for each Agent + for (Element elAgent : listAgents){ - try { + try { - String idA = elAgent.getAttributeValue("id"); + String idA = elAgent.getAttributeValue("id"); - // - // - // Ali Baba is also known as r.a.m. - // - Person person = Person.NewInstance(); - importRepresentation(elAgent, sddNamespace, person, idA, sddConfig); - person.addSource(OriginalSource.NewInstance(idA, "Agent")); + // + // + // Ali Baba is also known as r.a.m. + // + Person person = Person.NewInstance(); + importRepresentation(elAgent, sddNamespace, person, idA, sddConfig); + person.addSource(OriginalSource.NewInstance(idA, "Agent")); - // - Element elLinks = elAgent.getChild("Links",sddNamespace); + // + Element elLinks = elAgent.getChild("Links",sddNamespace); - if (elLinks != null) { + if (elLinks != null) { - // - List listLinks = elLinks.getChildren("Link", sddNamespace); - int k = 0; - //for each Link - for (Element elLink : listLinks){ + // + List listLinks = elLinks.getChildren("Link", sddNamespace); + int k = 0; + //for each Link + for (Element elLink : listLinks){ - try { + try { - String rel = elLink.getAttributeValue("rel"); - String href = elLink.getAttributeValue("href"); + String rel = elLink.getAttributeValue("rel"); + String href = elLink.getAttributeValue("href"); - Media link = Media.NewInstance(); - MediaRepresentation mr = MediaRepresentation.NewInstance(); - mr.addRepresentationPart(MediaRepresentationPart.NewInstance(href, null)); - link.addRepresentation(mr); - person.addMedia(link); + Media link = Media.NewInstance(); + MediaRepresentation mr = MediaRepresentation.NewInstance(); + mr.addRepresentationPart(MediaRepresentationPart.NewInstance(href, null)); + link.addRepresentation(mr); + person.addMedia(link); - } catch (Exception e) { - //FIXME - logger.warn("Import of Link " + k + " failed."); - success = false; - } + } catch (Exception e) { + //FIXME + logger.warn("Import of Link " + k + " failed."); + success = false; + } - if ((++k % modCount) == 0){ logger.info("Links handled: " + k);} + if ((++k % modCount) == 0){ logger.info("Links handled: " + k);} - } - } - if (authors.containsKey(idA)) { - authors.put(idA,person); } + } + if (authors.containsKey(idA)) { + authors.put(idA,person); + } - if (editors.containsKey(idA)) { - editors.put(idA, person); - } + if (editors.containsKey(idA)) { + editors.put(idA, person); + } + + } catch (Exception e) { + //FIXME + logger.warn("Import of Agent " + j + " failed."); + success = false; + } + + if ((++j % modCount) == 0){ logger.info("Agents handled: " + j);} + + } +} + +// imports publications related with the data set +protected void importPublications(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){ + // + logger.info("start Publications ..."); + Element elPublications = elDataset.getChild("Publications",sddNamespace); + + if (elPublications != null) { + // + List listPublications = elPublications.getChildren("Publication", sddNamespace); + int j = 0; + //for each Publication + for (Element elPublication : listPublications){ + + try { + + String idP = elPublication.getAttributeValue("id"); + + // + // + // + Article publication = Article.NewInstance(); + importRepresentation(elPublication, sddNamespace, publication, idP, sddConfig); + + publications.put(idP,publication); } catch (Exception e) { //FIXME - logger.warn("Import of Agent " + j + " failed."); + logger.warn("Import of Publication " + j + " failed."); success = false; } - if ((++j % modCount) == 0){ logger.info("Agents handled: " + j);} + if ((++j % modCount) == 0){ logger.info("Publications handled: " + j);} } } +} - // imports publications related with the data set - protected void importPublications(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){ - // - logger.info("start Publications ..."); - Element elPublications = elDataset.getChild("Publications",sddNamespace); +// imports media objects such as images +protected void importMediaObjects(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){ + // + logger.info("start MediaObjects ..."); + Element elMediaObjects = elDataset.getChild("MediaObjects",sddNamespace); - if (elPublications != null) { - // - List listPublications = elPublications.getChildren("Publication", sddNamespace); - int j = 0; - //for each Publication - for (Element elPublication : listPublications){ + if (elMediaObjects != null) { + // + List listMediaObjects = elMediaObjects.getChildren("MediaObject", sddNamespace); + int j = 0; + //for each Publication + for (Element elMO : listMediaObjects){ - try { + String id = ""; - String idP = elPublication.getAttributeValue("id"); + try { - // - // - // - Article publication = Article.NewInstance(); - importRepresentation(elPublication, sddNamespace, publication, idP, sddConfig); + String idMO = elMO.getAttributeValue("id"); + id = idMO; - publications.put(idP,publication); + // + // + // + Media media = Media.NewInstance(); + importRepresentation(elMO, sddNamespace, media, idMO, sddConfig); + + // Image + // + String type = (String)ImportHelper.getXmlInputValue(elMO,"Type",sddNamespace); + + if ((type != null) && (type.equals("Image"))) { + Element elSource = elMO.getChild("Source",sddNamespace); + String href = elSource.getAttributeValue("href"); + + ImageMetaData imageMetaData = new ImageMetaData(); + ImageFile image = null; + + if (href.substring(0,7).equals("http://")) { + try{ + URL url = new URL(href); + imageMetaData.readFrom(url); + image = ImageFile.NewInstance(url.toString(), null, imageMetaData); + } catch (MalformedURLException e) { + logger.error("Malformed URL", e); + } + } else { + String sns = sddConfig.getSourceNameString(); + File f = new File(sns); + File parent = f.getParentFile(); + String fi = parent.toString() + File.separator + href; + File file = new File(fi); + imageMetaData.readFrom(file); + image = ImageFile.NewInstance(file.toString(), null, imageMetaData); + } - } catch (Exception e) { - //FIXME - logger.warn("Import of Publication " + j + " failed."); - success = false; + MediaRepresentation representation = MediaRepresentation.NewInstance(imageMetaData.getMimeType(), null); + representation.addRepresentationPart(image); + + media.addRepresentation(representation); + + ArrayList lcb = (ArrayList) mediaObject_ListCdmBase.get(idMO); + if (lcb != null) { + for (int k = 0; k < lcb.size(); k++) { + if (lcb.get(k) instanceof DefinedTermBase) { + DefinedTermBase dtb = (DefinedTermBase) lcb.get(k); + // if (lcb.get(0) instanceof DefinedTermBase) { + // DefinedTermBase dtb = (DefinedTermBase) lcb.get(0); + // if (dtb!=null) { + // if (k == 0) { + dtb.addMedia(media); + // } else { + // Media me = (Media) media.clone(); + // dtb.addMedia(me); + // } + // } + } else if (lcb.get(k) instanceof ReferenceBase) { + ReferenceBase rb = (ReferenceBase) lcb.get(k); + //} else if (lcb.get(0) instanceof ReferenceBase) { + //ReferenceBase rb = (ReferenceBase) lcb.get(0); + // rb.setTitleCache(label); + // if (rb!=null) { + // if (k == 0) { + rb.addMedia(media); + // } else { + // Media me = (Media) media.clone(); + // rb.addMedia(me); + // } + // } + } + } + } } - if ((++j % modCount) == 0){ logger.info("Publications handled: " + j);} + } catch (Exception e) { + //FIXME + logger.warn("Could not attached MediaObject " + j + "(SDD: " + id + ") to several objects."); + success = false; + } + + if ((++j % modCount) == 0){ logger.info("MediaObjects handled: " + j); } } } +} - // imports media objects such as images - protected void importMediaObjects(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){ - // - logger.info("start MediaObjects ..."); - Element elMediaObjects = elDataset.getChild("MediaObjects",sddNamespace); - - if (elMediaObjects != null) { - // - List listMediaObjects = elMediaObjects.getChildren("MediaObject", sddNamespace); - int j = 0; - //for each Publication - for (Element elMO : listMediaObjects){ - - try { - - String idMO = elMO.getAttributeValue("id"); - - // - // - // - Media media = Media.NewInstance(); - importRepresentation(elMO, sddNamespace, media, idMO, sddConfig); - - // Image - // - String type = (String)ImportHelper.getXmlInputValue(elMO,"Type",sddNamespace); - - if ((type != null) && (type.equals("Image"))) { - Element elSource = elMO.getChild("Source",sddNamespace); - String href = elSource.getAttributeValue("href"); - - ImageMetaData imageMetaData = new ImageMetaData(); - ImageFile image = null; - - if (href.substring(0,7).equals("http://")) { - try{ - URL url = new URL(href); - imageMetaData.readFrom(url); - image = ImageFile.NewInstance(url.toString(), null, imageMetaData); - } catch (MalformedURLException e) { - logger.error("Malformed URL", e); - } - } else { - String sns = sddConfig.getSourceNameString(); - File f = new File(sns); - File parent = f.getParentFile(); - String fi = parent.toString() + File.separator + href; - File file = new File(fi); - imageMetaData.readFrom(file); - image = ImageFile.NewInstance(file.toString(), null, imageMetaData); - } +// imports the block +protected void importDescriptiveConcepts(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig){ + // + logger.info("start DescriptiveConcepts ..."); + Element elDescriptiveConcepts = elDataset.getChild("DescriptiveConcepts",sddNamespace); + // + if (elDescriptiveConcepts != null) { + List listDescriptiveConcepts = elDescriptiveConcepts.getChildren("DescriptiveConcept", sddNamespace); + int j = 0; + //for each DescriptiveConcept + int g = 1; + for (Element elDescriptiveConcept : listDescriptiveConcepts){ + + String id = elDescriptiveConcept.getAttributeValue("id"); + String uri = elDescriptiveConcept.getAttributeValue("uri"); + + FeatureNode fn = null; + + if (!id.equals("")) { + fn = FeatureNode.NewInstance(); + Feature feature = Feature.NewInstance(); + // + // + importRepresentation(elDescriptiveConcept, sddNamespace, feature, id, sddConfig); + features.put("g" + g, feature); + g++; + fn.setFeature(feature); + + // TODO if an OriginalSource can be attached to a FeatureNode or a Feature + // OriginalSource source = null; + // if (uri != null) { + // if (!uri.equals("")) { + // source = OriginalSource.NewInstance(id, "DescriptiveConcept", Generic.NewInstance(), uri); + // } + // } else { + // source = OriginalSource.NewInstance(id, "DescriptiveConcept"); + // } + // fn.addSource(source); + + featureNodes.put(id,fn); + } - MediaRepresentation representation = MediaRepresentation.NewInstance(imageMetaData.getMimeType(), null); - representation.addRepresentationPart(image); - - media.addRepresentation(representation); - - ArrayList lcb = (ArrayList) mediaObject_ListCdmBase.get(idMO); - if (lcb != null) { - for (int k = 0; k < lcb.size(); k++) { - if (lcb.get(k) instanceof DefinedTermBase) { - DefinedTermBase dtb = (DefinedTermBase) lcb.get(k); - // if (lcb.get(0) instanceof DefinedTermBase) { - // DefinedTermBase dtb = (DefinedTermBase) lcb.get(0); - if (dtb!=null) { - if (k == 0) { - dtb.addMedia(media); - } else { - Media me = (Media) media.clone(); - dtb.addMedia(me); - } - } - } else if (lcb.get(k) instanceof ReferenceBase) { - ReferenceBase rb = (ReferenceBase) lcb.get(k); - //} else if (lcb.get(0) instanceof ReferenceBase) { - //ReferenceBase rb = (ReferenceBase) lcb.get(0); - // rb.setTitleCache(label); - if (rb!=null) { - if (k == 0) { - rb.addMedia(media); - } else { - Media me = (Media) media.clone(); - rb.addMedia(me); - } - } - } - } + if ((++j % modCount) == 0){ logger.info("DescriptiveConcepts handled: " + j);} + + } + } +} + +// imports the descriptions of taxa (specimens TODO) +protected void importCharacterTrees(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){ + // + logger.info("start CharacterTrees ..."); + Element elCharacterTrees = elDataset.getChild("CharacterTrees",sddNamespace); + + // + + if (elCharacterTrees != null) { + List listCharacterTrees = elCharacterTrees.getChildren("CharacterTree", sddNamespace); + int j = 0; + //for each CharacterTree + + for (Element elCharacterTree : listCharacterTrees){ + + try { + Element elRepresentation = elCharacterTree.getChild("Representation",sddNamespace); + String label = (String)ImportHelper.getXmlInputValue(elRepresentation,"Label",sddNamespace); + Element elDesignedFor = elCharacterTree.getChild("DesignedFor",sddNamespace); + List listRoles = elDesignedFor.getChildren("Role",sddNamespace); + boolean isgroups = false; + + for (Element elRole : listRoles){ + if (elRole.getText().equals("Filtering")) { + isgroups = true; + } + } + + if ((label.contains("group")) || (isgroups)) { + + FeatureTree groups = FeatureTree.NewInstance(); + importRepresentation(elCharacterTree, sddNamespace, groups, "", sddConfig); + FeatureNode root = groups.getRoot(); + + Element elNodes = elCharacterTree.getChild("Nodes", sddNamespace); + List listNodes = elNodes.getChildren("Node", sddNamespace); + for (Element elNode : listNodes){ + String idN = elNode.getAttributeValue("id"); + FeatureNode fn = null; + if (!idN.equals("")) { + Element elDescriptiveConcept = elNode.getChild("DescriptiveConcept", sddNamespace); + String refDC = elDescriptiveConcept.getAttributeValue("ref"); + fn = featureNodes.get(refDC); + root.addChild(fn); } + nodes.put(idN, fn); } - - } catch (Exception e) { - //FIXME - logger.warn("Import of MediaObject " + j + " failed."); - success = false; + + List listCharNodes = elNodes.getChildren("CharNode", sddNamespace); + for (Element elCharNode : listCharNodes){ + Element elParent = elCharNode.getChild("Parent", sddNamespace); + String refP = elParent.getAttributeValue("ref"); + Element elCharacter = elCharNode.getChild("Character", sddNamespace); + String refC = elCharacter.getAttributeValue("ref"); + FeatureNode fn = FeatureNode.NewInstance(); + if (!refP.equals("")) { + FeatureNode parent = nodes.get(refP); + parent.addChild(fn); + Feature character = features.get(refC); + fn.setFeature(character); + // if method setParent() in FeatureNode becomes visible + // fn.setParent(parent); + } + nodes.put(refC, fn); + } + featureTrees.add(groups); } - if ((++j % modCount) == 0){ logger.info("MediaObjects handled: " + j);} - + } catch (Exception e) { + //FIXME + logger.warn("Import of Character tree " + j + " failed."); + success = false; } + + if ((++j % modCount) == 0){ logger.info("CharacterTrees handled: " + j);} + } + } } +}