X-Git-Url: https://dev.e-taxonomy.eu/gitweb/cdmlib.git/blobdiff_plain/83383bc9445516e34dcd856bd9940dea6c30e02b..1fa935e85ea39aab2d1e87d3f0c914c37c64c7d7:/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 5ca49450aa..4702340781 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,8 +1,21 @@ +/** + * 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; +import java.net.MalformedURLException; +import java.net.URI; +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; @@ -14,74 +27,437 @@ 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.IVersionableService;//rajout 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.io.common.ICdmIO; +import eu.etaxonomy.cdm.common.mediaMetaData.ImageMetaData; +import eu.etaxonomy.cdm.io.common.CdmImportBase; +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.Contact; +import eu.etaxonomy.cdm.model.agent.Institution; import eu.etaxonomy.cdm.model.agent.Person; +import eu.etaxonomy.cdm.model.agent.Address;//rajout 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; +import eu.etaxonomy.cdm.model.common.IdentifiableSource; import eu.etaxonomy.cdm.model.common.Language; -import eu.etaxonomy.cdm.model.common.OriginalSource; +import eu.etaxonomy.cdm.model.common.LanguageString; +import eu.etaxonomy.cdm.model.common.Marker; +import eu.etaxonomy.cdm.model.common.MarkerType; +import eu.etaxonomy.cdm.model.common.Representation; +import eu.etaxonomy.cdm.model.common.TermBase; import eu.etaxonomy.cdm.model.common.TermVocabulary; +import eu.etaxonomy.cdm.model.common.User; 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; +import eu.etaxonomy.cdm.model.description.StateData; import eu.etaxonomy.cdm.model.description.StatisticalMeasure; import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue; import eu.etaxonomy.cdm.model.description.TaxonDescription; import eu.etaxonomy.cdm.model.description.TextData; +import eu.etaxonomy.cdm.model.description.Modifier; +import eu.etaxonomy.cdm.model.taxon.TaxonomicTree; +import eu.etaxonomy.cdm.model.taxon.TaxonNode; +import eu.etaxonomy.cdm.model.media.ImageFile; +import eu.etaxonomy.cdm.model.media.Media; +import eu.etaxonomy.cdm.model.media.MediaRepresentation; +import eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity; +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.reference.Article; +import eu.etaxonomy.cdm.model.name.TaxonNameBase; +import eu.etaxonomy.cdm.model.occurrence.Specimen; +import eu.etaxonomy.cdm.model.reference.IArticle; +import eu.etaxonomy.cdm.model.reference.IDatabase; +import eu.etaxonomy.cdm.model.reference.IGeneric; import eu.etaxonomy.cdm.model.reference.ReferenceBase; +import eu.etaxonomy.cdm.model.reference.ReferenceFactory; import eu.etaxonomy.cdm.model.taxon.Taxon; - - -public class SDDDescriptionIO extends SDDIoBase implements ICdmIO { +import eu.etaxonomy.cdm.model.taxon.Synonym; +import eu.etaxonomy.cdm.model.location.NamedArea; + +/** + * @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 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 stateDatas = new HashMap(); + private Map taxonDescriptions = new HashMap(); + private Map taxonNameBases = new HashMap(); + private Map units = new HashMap(); + private Map taxonNodes = new HashMap(); + private Map namedAreas = new HashMap(); + private Map specimens = new HashMap(); + + private Set annotationTypes = new HashSet(); + private Set featureSet = new HashSet(); + ReferenceFactory refFactory = ReferenceFactory.newInstance(); + private ReferenceBase sec = refFactory.newDatabase(); + private ReferenceBase sourceReference = null; + + private Language datasetLanguage = null; + + private Namespace xmlNamespace = Namespace.getNamespace("xml","http://www.w3.org/XML/1998/namespace"); + + private String generatorName = ""; + private String generatorVersion = ""; + + private Set statisticalMeasures = new HashSet(); + private Set featureData = new HashSet(); + private Set featureTrees = new HashSet(); + private Set taxonomicTrees = new HashSet(); + + private Rights copyright = null; + + private int taxonNamesCount = 0; //XIM ajout + + public SDDDescriptionIO(){ super(); } @Override - public boolean doCheck(IImportConfigurator config){ + public boolean doCheck(SDDImportState state){ boolean result = true; logger.warn("No check implemented for SDD"); return result; } + // @Override + // public boolean doInvoke(IImportConfigurator config, Map> stores){ @Override - public boolean doInvoke(IImportConfigurator config, Map> stores){ + public boolean doInvoke(SDDImportState state){ - String value; - logger.info("start Datasets ..."); - SDDImportConfigurator sddConfig = (SDDImportConfigurator)config; + TransactionStatus ts = startTransaction(); + SDDImportConfigurator sddConfig = state.getConfig(); + logger.info("start Datasets ..."); // Element root = sddConfig.getSourceRoot(); - boolean success =true; - + boolean success = true; Namespace sddNamespace = sddConfig.getSddNamespace(); - Namespace xmlNamespace = Namespace.getNamespace("xml","http://www.w3.org/XML/1998/namespace"); logger.info("start TechnicalMetadata ..."); // + importTechnicalMetadata(root, sddNamespace, sddConfig); + List elDatasets = root.getChildren("Dataset",sddNamespace); + int i = 0; + + //for each Dataset + logger.info("start Dataset ..."); + for (Element elDataset : elDatasets){ + importDataset(elDataset, sddNamespace, success, sddConfig); + if ((++i % modCount) == 0){ logger.info("Datasets handled: " + i);} + logger.info(i + " Datasets handled"); + } + commitTransaction(ts); + return success; + } + + /* (non-Javadoc) + * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator) + */ + protected boolean isIgnore(SDDImportState state){ + return false; + } + + + // associates the reference of a media object in SDD with a CdmBase Object + protected void associateImageWithCdmBase(String refMO, CdmBase cb){ + if ((refMO != null) && (cb!=null)) { + if (!refMO.equals("")) { + if (!mediaObject_ListCdmBase.containsKey(refMO)) { + List lcb = new ArrayList(); + lcb.add(cb); + mediaObject_ListCdmBase.put(refMO,lcb); + } else { + List lcb = mediaObject_ListCdmBase.get(refMO); + lcb.add(cb); + mediaObject_ListCdmBase.put(refMO,lcb); + } + } + } + } + + // imports information about the Dataset + protected void importDatasetRepresentation(Element parent, Namespace sddNamespace){ + logger.info("start Representation ..."); + /* + + 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". + + */ + Element elRepresentation = parent.getChild("Representation",sddNamespace); + String label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace); + String detail = (String)ImportHelper.getXmlInputValue(elRepresentation, "Detail",sddNamespace); + + sec.setTitleCache(label); + + if (detail != null) { + Annotation annotation = Annotation.NewInstance(detail, datasetLanguage); + annotation.setAnnotationType(AnnotationType.EDITORIAL()); + sec.addAnnotation(annotation); + } + + List listMediaObjects = elRepresentation.getChildren("MediaObject",sddNamespace); + + for (Element elMediaObject : listMediaObjects) { + String ref = null; + String role = null; + if (elMediaObject != null) { + ref = elMediaObject.getAttributeValue("ref"); + role = elMediaObject.getAttributeValue("role"); + } + if (ref != null) { + if (!ref.equals("")) { + this.associateImageWithCdmBase(ref,sourceReference); + this.associateImageWithCdmBase(ref,sec); + mediaObject_Role.put(ref,role); + } + } + } + } + + // imports the representation (label, detail, lang) of a particular SDD element + protected void importRepresentation(Element parent, Namespace sddNamespace, VersionableEntity ve, String id, IImportConfigurator config){ + Element elRepresentation = parent.getChild("Representation",sddNamespace); + // + 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; + } + String label = elLabel.getText(); + List labDet = new ArrayList(3); + labDet.add(label); + langLabDet.put(language, labDet); + } + + 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 TermBase) { + TermBase tb = (TermBase) ve; + + for (Iterator 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; + } + + } + //XIM else if + if (ve instanceof IdentifiableEntity) { + IdentifiableEntity ie = (IdentifiableEntity) ve; + 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 (labDet.size()>1) { + Annotation annotation = null; + if (labDet.get(1) != null) { + if (labDet.get(2) != null) { + annotation = Annotation.NewInstance(labDet.get(2) + " - " + labDet.get(1), datasetLanguage); + } else { + annotation = Annotation.NewInstance(labDet.get(1), datasetLanguage); + } + } + ie.addAnnotation(annotation); + } + + ve = ie; + + } + + if (ve instanceof IdentifiableMediaEntity){ + IdentifiableMediaEntity ime = (IdentifiableMediaEntity) ve; + Element elLinks = parent.getChild("Links",sddNamespace); + + if (elLinks != null) { + + // + List listLinks = elLinks.getChildren("Link", sddNamespace); + Media link = Media.NewInstance(); + MediaRepresentation mr = MediaRepresentation.NewInstance(); + int k = 0; + //for each Link + for (Element elLink : listLinks){ + + try { + + String rel = elLink.getAttributeValue("rel"); + String href = elLink.getAttributeValue("href"); + + mr.addRepresentationPart(MediaRepresentationPart.NewInstance(href, null)); + link.addRepresentation(mr); + ime.addMedia(link); + + } catch (Exception e) { + //FIXME + logger.warn("Import of Link " + k + " failed."); + } + + if ((++k % modCount) == 0){ logger.info("Links handled: " + k);} + + } + } + } + + List listMediaObjects = elRepresentation.getChildren("MediaObject",sddNamespace); + for (Element elMediaObject : listMediaObjects) { + String ref = null; + String role = null; + if (elMediaObject != null) { + ref = elMediaObject.getAttributeValue("ref"); + role = elMediaObject.getAttributeValue("role"); + } + if (ref != null) { + if (!ref.equals("")) { + if (ref != null) { + if (ve instanceof TaxonDescription) { + TaxonDescription td = (TaxonDescription) ve; + //TODO: ensure that all images are imported + if (td.getDescriptionSources().toArray().length > 0) { + this.associateImageWithCdmBase(ref,(ReferenceBase) td.getDescriptionSources().toArray()[0]); + } else { + ReferenceBase descriptionSource = refFactory.newGeneric(); + td.addDescriptionSource(descriptionSource); + this.associateImageWithCdmBase(ref,descriptionSource); + } + } else { + //System.out.println(parent.getName()); + this.associateImageWithCdmBase(ref,ve); + } + } + + } + } + } + + } + + protected void importGeographicAreas(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig) { + Element elGeographicAreas = elDataset.getChild("GeographicAreas",sddNamespace); + if (elGeographicAreas != null) { + List listGeographicAreas = elGeographicAreas.getChildren("GeographicArea", sddNamespace); + int j = 0; + + for (Element elGeographicArea : listGeographicAreas){ + + String id = elGeographicArea.getAttributeValue("id"); + NamedArea na = new NamedArea(); + importRepresentation(elGeographicArea, sddNamespace, na, id, sddConfig); + namedAreas.put(id,na); + } + if ((++j % modCount) == 0){ logger.info("TaxonNames handled: " + j);} + } + } + + + // imports the representation (label, detail, lang) of a particular SDD element + protected void importTechnicalMetadata(Element root, Namespace sddNamespace, SDDImportConfigurator sddConfig){ Element elTechnicalMetadata = root.getChild("TechnicalMetadata", sddNamespace); String nameCreated = elTechnicalMetadata.getAttributeValue("created"); - ReferenceBase sourceReference = config.getSourceReference(); + sourceReference = sddConfig.getSourceReference(); + if (nameCreated != null) { if (!nameCreated.equals("")) { int year = Integer.parseInt(nameCreated.substring(0,4)); @@ -92,74 +468,225 @@ public class SDDDescriptionIO extends SDDIoBase implements ICdmIO { int secondOfMinute = Integer.parseInt(nameCreated.substring(17,19)); DateTime created = new DateTime(year,monthOfYear,dayOfMonth,hourOfDay,minuteOfHour,secondOfMinute,0); sourceReference.setCreated(created); + sec.setCreated(created); } } // Element elGenerator = elTechnicalMetadata.getChild("Generator", sddNamespace); - String generatorName = elGenerator.getAttributeValue("name"); - String generatorVersion = elGenerator.getAttributeValue("version"); + generatorName = elGenerator.getAttributeValue("name"); + generatorVersion = elGenerator.getAttributeValue("version"); - List elDatasets = root.getChildren("Dataset",sddNamespace); + sec.addAnnotation(Annotation.NewDefaultLanguageInstance(generatorName + " - " + generatorVersion)); + sourceReference.addAnnotation(Annotation.NewDefaultLanguageInstance(generatorName + " - " + generatorVersion)); - Map taxonDescriptions = new HashMap(); - Map states = new HashMap(); - Map units = new HashMap(); - Map defaultUnitPrefixes = new HashMap(); - Map features = new HashMap(); - Map publications = new HashMap(); + } - Set statisticalMeasures = new HashSet(); - Set featureData = new HashSet(); + // imports the complete dataset information + protected void importDataset(Element elDataset, Namespace sddNamespace, boolean success, SDDImportConfigurator sddConfig){ // + + importDatasetLanguage(elDataset,sddConfig); + importDatasetRepresentation(elDataset, sddNamespace); + importRevisionData(elDataset, sddNamespace); + importIPRStatements(elDataset, sddNamespace, sddConfig); + importTaxonNames(elDataset, sddNamespace, sddConfig); + importDescriptiveConcepts(elDataset, sddNamespace, sddConfig); + importCharacters(elDataset, sddNamespace, sddConfig, success); + importCharacterTrees(elDataset, sddNamespace, sddConfig, success); + importCodedDescriptions(elDataset, sddNamespace, sddConfig, success); + importAgents(elDataset, sddNamespace, sddConfig, success); + importPublications(elDataset, sddNamespace, sddConfig, success); + importMediaObjects(elDataset, sddNamespace, sddConfig, success); + importTaxonHierarchies(elDataset, sddNamespace, sddConfig, success); + importGeographicAreas(elDataset, sddNamespace, sddConfig); + importSpecimens(elDataset,sddNamespace, sddConfig); + + MarkerType editou = MarkerType.NewInstance("Editor", "editor", "edt") ; + if (authors != null) { + Team team = Team.NewInstance(); + for (Iterator author = authors.values().iterator() ; author.hasNext() ;){ + team.addTeamMember(author.next()); + } + if (editors != null) { + Marker marker = Marker.NewInstance(); + marker.setMarkerType(editou); + for (Iterator editor = editors.values().iterator() ; editor.hasNext() ;){ + Person edit = editor.next(); + edit.addMarker(marker); + team.addTeamMember(edit); + } + } + sec.setAuthorTeam(team); + sourceReference.setAuthorTeam(team); + } + + if (editors != null) { + Person ed = Person.NewInstance(); + for (Iterator editor = editors.values().iterator() ; editor.hasNext() ;){ + ed = editor.next(); + } + // TODO updatedBy refactored to use a user account, so setting a person is no longer applicable + // sec.setUpdatedBy(ed); + // sourceReference.setUpdatedBy(ed); + } - int i = 0; - //for each Dataset - logger.info("start Dataset ..."); - for (Element elDataset : elDatasets){ + if (copyright != null) { + sourceReference.addRights(copyright); + sec.addRights(copyright); + } + + // Returns a CdmApplicationController created by the values of this configuration. + IDescriptionService descriptionService = getDescriptionService(); - // - String nameLang = elDataset.getAttributeValue("lang",xmlNamespace); - Language datasetLanguage = null; - if (!nameLang.equals("")) { -// config.getCdmAppController().getTermService().getLanguageByIso(nameLang); - datasetLanguage = Language.ENGLISH(); - } else { - datasetLanguage = Language.ENGLISH(); + for (Iterator k = taxonDescriptions.values().iterator() ; k.hasNext() ;){ + TaxonDescription taxonDescription = k.next(); + // Persists a Description + descriptionService.save(taxonDescription); + } + + //descriptionService.saveFeatureNodeAll(featureNodes.values()); + + for (Iterator refCD = taxonDescriptions.keySet().iterator() ; refCD.hasNext() ;){ + String ref = refCD.next(); + TaxonDescription td = taxonDescriptions.get(ref); + //XIM BUG ONAFILE td.addDescriptionSource(sec); + if (citations.containsKey(ref)) { + IArticle publication = (IArticle) publications.get(citations.get(ref)); + if (locations.containsKey(ref)) { + Annotation location = Annotation.NewInstance(locations.get(ref), datasetLanguage); + AnnotationType annotationType = AnnotationType.NewInstance("", "location", ""); + annotationTypes.add(annotationType); + location.setAnnotationType(annotationType); + ((ReferenceBase)publication).addAnnotation(location); + } + td.addDescriptionSource((ReferenceBase)publication); } - if (datasetLanguage == null) { - datasetLanguage = Language.ENGLISH(); + } + logger.info("end makeTaxonDescriptions ..."); + + //sddConfig.setSourceReference(sourceReference); + + //saving of all imported data into the CDM db + ITermService termService = getTermService(); + for (Iterator k = stateDatas.values().iterator() ; k.hasNext() ;){ + StateData sd = k.next(); + termService.save(sd.getState()); + } + for (Iterator k = features.values().iterator() ; k.hasNext() ;){ + Feature feature = k.next(); + termService.save(feature); + } + + + termService.save(editou); + + MarkerType sddGeographicArea = MarkerType.NewInstance("", "SDDGeographicArea", ""); + termService.save(sddGeographicArea); + for (Iterator k = namedAreas.values().iterator() ; k.hasNext() ;) { + Marker areamarker = Marker.NewInstance(); + areamarker.setMarkerType(sddGeographicArea); + NamedArea area = k.next(); + area.addMarker(areamarker); + getTermService().save(area); + } + + if (units != null) { + for (Iterator k = units.values().iterator() ; k.hasNext() ;){ + MeasurementUnit unit = k.next(); + if (unit != null) { + termService.save(unit); + } } + } + for (Iterator k = statisticalMeasures.iterator() ; k.hasNext() ;) { + StatisticalMeasure sm = k.next(); + termService.save(sm); + } - /* - - 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". - - */ - logger.info("start Representation ..."); - Element elRepresentation = elDataset.getChild("Representation",sddNamespace); - String label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace); - String detail = (String)ImportHelper.getXmlInputValue(elRepresentation, "Detail",sddNamespace); + for (Iterator at = annotationTypes.iterator() ; at.hasNext() ;) { + AnnotationType annotationType = at.next(); + termService.save(annotationType); + } - sourceReference.setTitleCache(generatorName + " - " + generatorVersion + " - " + label); + IReferenceService referenceService = getReferenceService(); + // referenceService.saveReference(sourceReference); + for (Iterator k = publications.values().iterator() ; k.hasNext() ;){ + ReferenceBase publication = (ReferenceBase) k.next(); + referenceService.save(publication); + } - Annotation annotation = Annotation.NewInstance(detail, datasetLanguage); + for (Iterator k = featureTrees.iterator() ; k.hasNext() ;) { + FeatureTree tree = k.next(); + getFeatureTreeService().save(tree); + } + + for (Iterator k = taxonomicTrees.iterator() ; k.hasNext() ;) { + TaxonomicTree tree = k.next(); + getTaxonTreeService().save(tree); + } + + for (Iterator k = specimens.values().iterator() ; k.hasNext() ;) { + Specimen specimen = k.next(); + getOccurrenceService().save(specimen); + } + + } - // - logger.info("start RevisionData ..."); - Element elRevisionData = elDataset.getChild("RevisionData",sddNamespace); + // 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(); + } + } + + protected void importSpecimens(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig) { + logger.info("start Specimens ..."); + Element elSpecimens = elDataset.getChild("Specimens",sddNamespace); + if (elSpecimens != null){ + List listSpecimens = elSpecimens.getChildren("Specimen", sddNamespace); + int j = 0; + for (Element elSpecimen : listSpecimens) { + String id = elSpecimen.getAttributeValue("id"); + Specimen speci = null; + if (!id.equals("")) { + speci = Specimen.NewInstance(); + specimens.put(id,speci); + importRepresentation(elSpecimen, sddNamespace, speci, id, sddConfig); + } + } + + } + } + + + + + + + // 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); + if (elRevisionData != null){ // Element elCreators = elRevisionData.getChild("Creators",sddNamespace); - + // List listAgents = elCreators.getChildren("Agent", sddNamespace); - + int j = 0; //for each Agent - Map authors = new HashMap(); - Map editors = new HashMap(); for (Element elAgent : listAgents){ - + String role = elAgent.getAttributeValue("role"); String ref = elAgent.getAttributeValue("ref"); if (role.equals("aut")) { @@ -172,14 +699,13 @@ public class SDDDescriptionIO extends SDDIoBase implements ICdmIO { 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 (stringDateModified != null) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss"); Date d = null; @@ -189,487 +715,492 @@ public class SDDDescriptionIO extends SDDIoBase implements ICdmIO { System.err.println("Exception :"); e.printStackTrace(); } - - GregorianCalendar updated = null; + + DateTime updated = null; if (d != null) { - updated = new java.util.GregorianCalendar(); - updated.setTime(d); + updated = new DateTime(d); sourceReference.setUpdated(updated); + sec.setUpdated(updated); } } + } + } - // - logger.info("start IPRStatements ..."); - Element elIPRStatements = elDataset.getChild("IPRStatements",sddNamespace); - // - Rights copyright = null; - if (elIPRStatements != null) { - List listIPRStatements = elIPRStatements.getChildren("IPRStatement", sddNamespace); - j = 0; - //for each IPRStatement + // 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){ + 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); - } - label = (String)ImportHelper.getXmlInputValue(elIPRStatement, "Label",sddNamespace); - - if (role.equals("Copyright")) { - Language iprLanguage = null; - if (lang != null) { - if (!lang.equals("")) { - //iprLanguage = termService.getLanguageByIso(nameLang); - iprLanguage = datasetLanguage; - } else { - iprLanguage = datasetLanguage; - } - } - if (iprLanguage == null) { + 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); + 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); } - } - // - logger.info("start TaxonNames ..."); - Element elTaxonNames = elDataset.getChild("TaxonNames",sddNamespace); - // - Map taxonNameBases = new HashMap(); - if (elTaxonNames != null) { - List listTaxonNames = elTaxonNames.getChildren("TaxonName", sddNamespace); - j = 0; - //for each TaxonName - for (Element elTaxonName : listTaxonNames){ + if ((++j % modCount) == 0){ logger.info("IPRStatements handled: " + j);} - String id = elTaxonName.getAttributeValue("id"); - String uri = elTaxonName.getAttributeValue("uri"); - // - elRepresentation = elTaxonName.getChild("Representation",sddNamespace); - // - Element elLabel = elRepresentation.getChild("Label",sddNamespace); - String lang = elLabel.getAttributeValue("lang",xmlNamespace); - label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace); - NonViralName tnb = NonViralName.NewInstance(null); - if ((lang != null) && (!lang.equals("la"))) { - logger.info("TaxonName " + j + " is not specified as a latin name."); + } + } + } + + // 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); + IdentifiableSource source = null; + if (uri != null) { + if (!uri.equals("")) { + source = IdentifiableSource.NewInstance(id, "TaxonName", refFactory.newGeneric(), uri); + } + } else { + source = IdentifiableSource.NewInstance(id, "TaxonName"); } - tnb.setTitleCache(label); - OriginalSource source = OriginalSource.NewInstance(id, "TaxonName"); tnb.addSource(source); - if (!id.equals("")) { - taxonNameBases.put(id,tnb); - } + taxonNameBases.put(id,tnb); + } - if ((++j % modCount) == 0){ logger.info("TaxonNames handled: " + j);} + // + // + importRepresentation(elTaxonName, sddNamespace, tnb, id, sddConfig); + + if ((++j % modCount) == 0){ logger.info("TaxonNames handled: " + j);} - } } + } + } - // - 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); - 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"); + // + // + // - // - // - // - elRepresentation = elCategoricalCharacter.getChild("Representation",sddNamespace); - label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace); + Feature categoricalCharacter = Feature.NewInstance(); + categoricalCharacter.setKindOf(Feature.DESCRIPTION()); + importRepresentation(elCategoricalCharacter, sddNamespace, categoricalCharacter, idCC, sddConfig); - Feature categoricalCharacter = null; - if (label != null){ - categoricalCharacter = Feature.NewInstance(label, label, label); - } - 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){ - 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"); - // - // - // - elRepresentation = elStateDefinition.getChild("Representation",sddNamespace); - label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace); - State state = new State(label,label,label); - states.put(idSD, state); - termVocabularyState.addTerm(state); - } + 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); } + categoricalCharacter.addSupportedCategoricalEnumeration(termVocabularyState); + features.put(idCC, categoricalCharacter); - if ((++j % modCount) == 0){ logger.info("CategoricalCharacters handled: " + j);} - + } 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){ - // - // - // - elRepresentation = elQuantitativeCharacter.getChild("Representation",sddNamespace); - label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace); + try { - Feature quantitativeCharacter = Feature.NewInstance(); + String idQC = elQuantitativeCharacter.getAttributeValue("id"); - if (!label.equals("")){ - quantitativeCharacter = Feature.NewInstance(label, label, label); - } - quantitativeCharacter.setSupportsQuantitativeData(true); - quantitativeCharacter.setSupportsTextData(false); - - // - // - // - Element elMeasurementUnit = elQuantitativeCharacter.getChild("MeasurementUnit",sddNamespace); - label = ""; - String role = ""; - if (elMeasurementUnit != null) { - Element elLabel = elMeasurementUnit.getChild("Label",sddNamespace); - role = elLabel.getAttributeValue("role"); - label = (String)ImportHelper.getXmlInputValue(elMeasurementUnit, "Label",sddNamespace); - } + // + // + // + Feature quantitativeCharacter = Feature.NewInstance(); + quantitativeCharacter.setKindOf(Feature.DESCRIPTION()); + 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); + } - MeasurementUnit unit = null; - if (!label.equals("")){ - if (role != null) { - if (role.equals("Abbrev")){ - unit = MeasurementUnit.NewInstance(label,label,label); - } - } else { + 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); } + } - if (unit != null) { - units.put(idQC, unit); - } + if (unit != null) { + units.put(idQC, unit); + } - // - // 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); - } + // + // 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); } - - features.put(idQC, quantitativeCharacter); - - } catch (Exception e) { - //FIXME - logger.warn("Import of QuantitativeCharacter " + j + " failed."); - success = false; } - 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){ - // - // - // - elRepresentation = elTextCharacter.getChild("Representation",sddNamespace); - Element elLabel = elRepresentation.getChild("Label",sddNamespace); - nameLang = elLabel.getAttributeValue("lang",xmlNamespace); - Language language = null; - if (nameLang != null) { - if (!nameLang.equals("")) { - // language = termService.getLanguageByIso(nameLang); - language = datasetLanguage; - } else { - language = datasetLanguage; - } - } else { - language = datasetLanguage; - } + try { - label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace); + String idTC = elTextCharacter.getAttributeValue("id"); - Feature textCharacter = Feature.NewInstance(); + // + // + // + Feature textCharacter = Feature.NewInstance(); + textCharacter.setKindOf(Feature.DESCRIPTION()); + importRepresentation(elTextCharacter, sddNamespace, textCharacter, idTC, sddConfig); - if (label != null) { - if (!label.equals("")){ - textCharacter = Feature.NewInstance(label, label, label); - textCharacter.setLabel(label, language); - } - } + textCharacter.setSupportsTextData(true); - textCharacter.setSupportsQuantitativeData(false); - textCharacter.setSupportsTextData(true); + features.put(idTC, textCharacter); - features.put(idTC, textCharacter); + } catch (Exception e) { + //FIXME + logger.warn("Import of TextCharacter " + j + " failed."); + success = false; + } - } catch (Exception e) { - //FIXME - logger.warn("Import of TextCharacter " + j + " failed."); - success = false; - } + if ((++j % modCount) == 0){ logger.info("TextCharacters handled: " + j);} - if ((++j % modCount) == 0){ logger.info("TextCharacters handled: " + j);} + } - } + } - } + for (Iterator f = features.values().iterator() ; f.hasNext() ;){ + featureSet.add(f.next()); + } - // - 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); - Map citations = new HashMap(); - Map locations = new HashMap(); + // - if (elCodedDescriptions != null) { - List listCodedDescriptions = elCodedDescriptions.getChildren("CodedDescription", sddNamespace); - 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"); - // - // - // - elRepresentation = elCodedDescription.getChild("Representation",sddNamespace); - Element elLabel = elRepresentation.getChild("Label",sddNamespace); - label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace); - - TaxonDescription taxonDescription = TaxonDescription.NewInstance(); - taxonDescription.setTitleCache(label); - OriginalSource source = OriginalSource.NewInstance(idCD, "CodedDescription"); - taxonDescription.addSource(source); - - // - // - // - // - 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, null); + // + // + // + 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); + } + else { + NonViralName tnb = NonViralName.NewInstance(null); + String id = new String(""+taxonNamesCount); + IdentifiableSource source = IdentifiableSource.NewInstance(id, "TaxonName"); + importRepresentation(elCodedDescription, sddNamespace, tnb, id, sddConfig); + tnb.addSource(source); + taxonNameBases.put(id ,tnb); + taxonNamesCount++; + taxon = Taxon.NewInstance(tnb, 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.warn("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"); - State state = states.get(ref); - categoricalData.addState(state); + // + List elQuantitatives = elSummaryData.getChildren("Quantitative", sddNamespace); + k = 0; + //for each Quantitative + for (Element elQuantitative : elQuantitatives){ + if ((++k % modCount) == 0){ logger.warn("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"); + if (value.contains(",")) { + value = value.replace(',', '.'); } - - // - 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"); - 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); + Float v = Float.parseFloat(value); + //Float v = new Float(0); + 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")) { + t = StatisticalMeasure.STANDARD_DEVIATION(); + } else if (type.equals("N")) { + t = StatisticalMeasure.SAMPLE_SIZE(); + } else if (type.equals("UMethLower")) { + t = StatisticalMeasure.TYPICAL_LOWER_BOUNDARY(); + } else if (type.equals("UMethUpper")) { + t = StatisticalMeasure.TYPICAL_UPPER_BOUNDARY(); + } else if (type.equals("Var")) { + t = StatisticalMeasure.VARIANCE(); + } 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); - } + if (taxon != null) { + taxon.addDescription(taxonDescription); + } - taxonDescriptions.put(idCD, taxonDescription); + if (!refCitation.equals("")){ + citations.put(idCD,refCitation); + } - } catch (Exception e) { - //FIXME - logger.warn("Import of CodedDescription " + j + " failed."); - success = false; + if (!location.equals("")){ + locations.put(idCD, location); } + + taxonDescription.setDescriptiveSystem(featureSet); - if ((++j % modCount) == 0){ logger.info("CodedDescriptions handled: " + j);} + taxonDescriptions.put(idCD, taxonDescription);//XIM PB ici + } catch (Exception e) { + //FIXME + logger.warn("Import of CodedDescription " + j + " failed."); + success = false; } + if ((++j % modCount) == 0){ logger.info("CodedDescriptions handled: " + j);} + } - // - 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); + if (elAgents != null) { // - listAgents = elAgents.getChildren("Agent", sddNamespace); - j = 0; + List listAgents = elAgents.getChildren("Agent", sddNamespace); + int j = 0; //for each Agent for (Element elAgent : listAgents){ @@ -681,22 +1212,11 @@ public class SDDDescriptionIO extends SDDIoBase implements ICdmIO { // // Ali Baba is also known as r.a.m. // - elRepresentation = elAgent.getChild("Representation",sddNamespace); - label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace); - Element elDetail = elRepresentation.getChild("Detail",sddNamespace); - - Person person = Person.NewTitledInstance(label); - OriginalSource source = OriginalSource.NewInstance(idA, "Agent"); - person.addSource(source); - - if (elDetail != null) { - String role = elDetail.getAttributeValue("role"); - detail = (String)ImportHelper.getXmlInputValue(elRepresentation, "Detail",sddNamespace); - annotation = Annotation.NewInstance(role + " - " + detail, datasetLanguage); - person.addAnnotation(annotation); - } + Person person = Person.NewInstance(); + importRepresentation(elAgent, sddNamespace, person, idA, sddConfig); + person.addSource(IdentifiableSource.NewInstance(idA, "Agent")); - // + /*XIM Element elLinks = elAgent.getChild("Links",sddNamespace); if (elLinks != null) { @@ -712,10 +1232,11 @@ public class SDDDescriptionIO extends SDDIoBase implements ICdmIO { String rel = elLink.getAttributeValue("rel"); String href = elLink.getAttributeValue("href"); - if (k==1) { - source = OriginalSource.NewInstance(rel, href); - person.addSource(source); - } + Media link = Media.NewInstance(); + MediaRepresentation mr = MediaRepresentation.NewInstance(); + mr.addRepresentationPart(MediaRepresentationPart.NewInstance(href, null)); + link.addRepresentation(mr); + person.addMedia(link); } catch (Exception e) { //FIXME @@ -727,6 +1248,7 @@ public class SDDDescriptionIO extends SDDIoBase implements ICdmIO { } } + */ if (authors.containsKey(idA)) { authors.put(idA,person); } @@ -744,147 +1266,490 @@ public class SDDDescriptionIO extends SDDIoBase implements ICdmIO { if ((++j % modCount) == 0){ logger.info("Agents handled: " + j);} } + } + } - // - logger.info("start Publications ..."); - Element elPublications = elDataset.getChild("Publications",sddNamespace); + // 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); - j = 0; - //for each Publication - for (Element elPublication : listPublications){ + if (elPublications != null) { + // + List listPublications = elPublications.getChildren("Publication", sddNamespace); + int j = 0; + //for each Publication + for (Element elPublication : listPublications){ - try { + try { - String idP = elPublication.getAttributeValue("id"); + String idP = elPublication.getAttributeValue("id"); - // - // - // - elRepresentation = elPublication.getChild("Representation",sddNamespace); - label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace); - Article publication = Article.NewInstance(); - publication.setTitle(label); - OriginalSource source = OriginalSource.NewInstance(idP, "Publication"); - publication.addSource(source); + // + // + // + ReferenceBase publication = refFactory.newArticle(); + importRepresentation(elPublication, sddNamespace, publication, idP, sddConfig); - publications.put(idP,publication); + publications.put(idP,publication); - } catch (Exception e) { - //FIXME - logger.warn("Import of Publication " + j + " failed."); - success = false; - } + } catch (Exception e) { + //FIXME + logger.warn("Import of Publication " + j + " failed."); + success = false; + } - if ((++j % modCount) == 0){ logger.info("Publications handled: " + j);} + if ((++j % modCount) == 0){ logger.info("Publications handled: " + j);} - } } + } + } - logger.info("MediaObjects to implement still"); + // 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); - /* - // when several authors are supported - if (authors.size()>1) { - for (Iterator author = authors.values().iterator() ; author.hasNext() ;){ - sourceReference.setCreatedBy(author.next()); - } - } else { - Team team = Team.NewInstance(); - for (Iterator author = authors.values().iterator() ; author.hasNext() ;){ - team.addTeamMember(author.next()); + if (elMediaObjects != null) { + // + List listMediaObjects = elMediaObjects.getChildren("MediaObject", sddNamespace); + int j = 0; + //for each Publication + for (Element elMO : listMediaObjects){ + + String id = ""; + + try { + String idMO = elMO.getAttributeValue("id"); + id = idMO; + + // + // + // + 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 = ImageMetaData.newInstance(); + ImageFile image = null; + if (href.substring(0,7).equals("http://")) { + try{ + URL url = new URL(href); + + imageMetaData.readMetaData(url.toURI(), 0); + 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 = href; + //XIMString fi = parent.toString() + File.separator + href; enlever le file:/ ou truc du genre + File file = new File(fi); + imageMetaData.readMetaData(file.toURI(), 0); + image = ImageFile.NewInstance(file.toString(), null, imageMetaData); + } + 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); + //System.out.println(dtb.getLabel()); + // } 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); + //System.out.println(rb.getTitle()); + // } else { + // Media me = (Media) media.clone(); + // rb.addMedia(me); + // } + // } + }/* else if (lcb.get(k) instanceof TaxonNameBase){ + TaxonNameBase tb = (TaxonNameBase) lcb.get(k); + tb.addMedia(media); + }*/ + } + } } - sourceReference.setCreatedBy(team); + + } catch (Exception e) { + //FIXME + logger.warn("Could not attach MediaObject " + j + "(SDD: " + id + ") to several objects."); + success = false; } - */ - Iterator author = authors.values().iterator(); - if (author.hasNext()){ - sourceReference.setCreatedBy(author.next()); - } + if ((++j % modCount) == 0){ logger.info("MediaObjects handled: " + j); - Iterator editor = editors.values().iterator(); - if (editor.hasNext()){ - sourceReference.setCreatedBy(editor.next()); + } } + } + } + + // 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(); + feature.setKindOf(Feature.DESCRIPTION()); + // + // + importRepresentation(elDescriptiveConcept, sddNamespace, feature, id, sddConfig); + //System.out.println(feature.getLabel()+id); + features.put("g" + g, feature); + g++; + /*Element elModifiers = elDescriptiveConcept.getChild("Modifiers", sddNamespace); + if (elModifiers !=null){ + List listModifiers = elModifiers.getChildren("Modifier", sddNamespace); + for (Element elModifier : listModifiers) { + TermVocabulary termVocabularyState = new TermVocabulary("test","test","test","test"); + Modifier modif = Modifier.NewInstance(); + String idmod = elModifier.getAttributeValue("id"); + importRepresentation(elModifier, sddNamespace, modif, idmod, sddConfig); + termVocabularyState.addTerm(modif); + //XIMfeature.addRecommendedModifierEnumeration(termVocabularyState); + } + }*/ + + 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"); + // } + // f.addSource(source); + + featureNodes.put(id,fn); + } + + if ((++j % modCount) == 0){ logger.info("DescriptiveConcepts handled: " + j);} - if (copyright != null) { - sourceReference.addRights(copyright); } + } + } + + protected void importCharacterTrees(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){ + // + logger.info("start CharacterTrees ..."); + Element elCharacterTrees = elDataset.getChild("CharacterTrees",sddNamespace); - for (Iterator refCD = taxonDescriptions.keySet().iterator() ; refCD.hasNext() ;){ - String ref = refCD.next(); - TaxonDescription td = taxonDescriptions.get(ref); - if (citations.containsKey(ref)) { - Article publication = (Article) publications.get(citations.get(ref)); - if (locations.containsKey(ref)) { - publication.addAnnotation(Annotation.NewInstance(locations.get(ref), datasetLanguage)); + // + + 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); + /*XIMList listRoles = elDesignedFor.getChildren("Role",sddNamespace); + boolean isgroups = false; + + for (Element elRole : listRoles){ + if (elRole.getText().equals("Filtering")) { + isgroups = true; + } + }*/ + + // only treats the case of flat groups containing characters + // should also be added: dependencies between characters, + //XIM + + FeatureTree feattree = FeatureTree.NewInstance(); + importRepresentation(elCharacterTree, sddNamespace, feattree, "", sddConfig); + FeatureNode root = feattree.getRoot(); + //XIM several found in some files, is it correct ? + List listelNodes = elCharacterTree.getChildren("Nodes", sddNamespace); + for (Element elNodes : listelNodes) { + List listNodes = elNodes.getChildren("Node", sddNamespace); + if (listNodes != null) { + for (Element elNode : listNodes){ + String idN = elNode.getAttributeValue("id"); + FeatureNode fn = null; + if (!idN.equals("")) { + Element elDescriptiveConcept = elNode.getChild("DescriptiveConcept", sddNamespace); + if (elDescriptiveConcept != null){ + String refDC = elDescriptiveConcept.getAttributeValue("ref"); + //System.out.println(refDC); + fn = featureNodes.get(refDC); + } + else { + fn = FeatureNode.NewInstance(); + featureNodes.put(idN,fn); + } + Element elParent = elNode.getChild("Parent", sddNamespace); + if (elParent!=null){ + String refP = elParent.getAttributeValue("ref"); + if (!refP.equals("")) { + FeatureNode parent = nodes.get(refP); + parent.addChild(fn); + } + } + else { + fn = FeatureNode.NewInstance(); + root.addChild(fn); + } + } + nodes.put(idN, fn); + } + //System.out.println("zic"); + List listCharNodes = elNodes.getChildren("CharNode", sddNamespace); + for (Element elCharNode : listCharNodes){ + Element elParent = elCharNode.getChild("Parent", sddNamespace); + Element elCharacter = elCharNode.getChild("Character", sddNamespace); + FeatureNode fn = FeatureNode.NewInstance(); + if (elParent!=null){ + String refP = elParent.getAttributeValue("ref"); + if ((refP!=null)&&(!refP.equals(""))) { + FeatureNode parent = nodes.get(refP); + if (parent==null){ + parent = root; // because of Delta example + } + parent.addChild(fn); + } + } + String refC = elCharacter.getAttributeValue("ref"); + if ((refC!=null)&&(!refC.equals(""))){ + Feature character = features.get(refC); + fn.setFeature(character); + // if method setParent() in FeatureNode becomes visible + // fn.setParent(parent); + } + else { + refC = String.valueOf(taxonNamesCount); + taxonNamesCount++; + } + nodes.put(refC, fn); + } + } + } + featureTrees.add(feattree); } - td.addDescriptionSource(publication); + + catch (Exception e) { + //FIXME + logger.warn("Import of Character tree " + j + " failed."); + success = false; } - } - if ((++i % modCount) == 0){ logger.info("Datasets handled: " + i);} + if ((++j % modCount) == 0){ logger.info("CharacterTrees handled: " + j);} - config.setSourceReference(sourceReference); + } } - logger.info(i + " Datasets handled"); + } - TransactionStatus ts = config.getCdmAppController().startTransaction(); - - ITermService termService = config.getCdmAppController().getTermService(); - for (Iterator k = states.values().iterator() ; k.hasNext() ;){ - State state = k.next(); - termService.saveTerm(state); - } - 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); + + + + + protected void importTaxonHierarchies(Element elDataset, Namespace sddNamespace, SDDImportConfigurator sddConfig, boolean success){ + + logger.info("start TaxonHierarchies ..."); + Element elTaxonHierarchies = elDataset.getChild("TaxonHierarchies",sddNamespace); + + if (elTaxonHierarchies != null) { + List listTaxonHierarchies = elTaxonHierarchies.getChildren("TaxonHierarchy", sddNamespace); + int j = 0; + for (Element elTaxonHierarchy : listTaxonHierarchies){ + try { + Element elRepresentation = elTaxonHierarchy.getChild("Representation",sddNamespace); + String label = (String)ImportHelper.getXmlInputValue(elRepresentation,"Label",sddNamespace); + + TaxonomicTree taxonomicTree = TaxonomicTree.NewInstance(label); + importRepresentation(elTaxonHierarchy, sddNamespace, taxonomicTree, "", sddConfig); + Set root = taxonomicTree.getRootNodes(); + Element elNodes = elTaxonHierarchy.getChild("Nodes", sddNamespace); + List listNodes = elNodes.getChildren("Node", sddNamespace); + for (Element elNode : listNodes){ + String idN = elNode.getAttributeValue("id"); + TaxonNameBase tnb = null; + if (!idN.equals("")) { + Element elTaxonName = elNode.getChild("TaxonName", sddNamespace); + String refTN = elTaxonName.getAttributeValue("ref"); + tnb = taxonNameBases.get(refTN); + Taxon taxonou = (Taxon) tnb.getTaxa().iterator().next() ; + Element elParent = elNode.getChild("Parent", sddNamespace); + if (elParent!=null){ + String refP = elParent.getAttributeValue("ref"); + if (!refP.equals("")) { + TaxonNode parent = taxonNodes.get(refP); + //TaxonNode child = parent.addChildTaxon(Taxon.NewInstance(tnb, sec), sec, "", Synonym.NewInstance(tnb, sec)); + TaxonNode child = parent.addChildTaxon(taxonou, sec, "", Synonym.NewInstance(tnb, sec)); + taxonNodes.put(idN,child); + } + } + else { + //XIM addChildtaxon (taxon, referencebase ??? + //TaxonNode tn = taxonomicTree.addChildTaxon(Taxon.NewInstance(tnb, sec), sec, "", Synonym.NewInstance(tnb, sec)); + TaxonNode tn = taxonomicTree.addChildTaxon(taxonou, sec, "", Synonym.NewInstance(tnb, sec)); + taxonNodes.put(idN,tn); + } + } + } + + taxonomicTrees.add(taxonomicTree); + } + + catch (Exception e) { + //FIXME + logger.warn("Import of Taxon Hierarchy " + j + " failed."); + success = false; } + + if ((++j % modCount) == 0){ logger.info("TaxonHierarchies handled: " + j);} + } + } - for (Iterator k = statisticalMeasures.iterator() ; k.hasNext() ;) { - StatisticalMeasure sm = k.next(); - termService.saveTerm(sm); - } + } + + + + + + + + + + // imports the descriptions of taxa (specimens TODO) + protected void importCharacterTrees2(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){ - IReferenceService referenceService = config.getCdmAppController().getReferenceService(); + 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; + } + } - for (Iterator k = publications.values().iterator() ; k.hasNext() ;){ - Article publication = (Article) k.next(); - referenceService.saveReference(publication); - } + // only treats the case of flat groups containing characters + // should also be added: dependencies between characters, + //XIM + if ((label.contains("group")) || (isgroups) || (1==1)) { + + 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); + } - // Returns a CdmApplicationController created by the values of this configuration. - IDescriptionService descriptionService = config.getCdmAppController().getDescriptionService(); + List listCharNodes = elNodes.getChildren("CharNode", sddNamespace); + for (Element elCharNode : listCharNodes){ + Element elParent = elCharNode.getChild("Parent", sddNamespace); + Element elCharacter = elCharNode.getChild("Character", sddNamespace); + FeatureNode fn = FeatureNode.NewInstance(); + if (elParent!=null){ + String refP = elParent.getAttributeValue("ref"); + if (!refP.equals("")) { + FeatureNode parent = nodes.get(refP); + parent.addChild(fn); + } + } + String refC = elCharacter.getAttributeValue("ref"); + if (!refC.equals("")){ + 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); + } - for (Iterator k = taxonDescriptions.values().iterator() ; k.hasNext() ;){ - TaxonDescription taxonDescription = k.next(); - // Persists a Description - descriptionService.saveDescription(taxonDescription); - } + } catch (Exception e) { + //FIXME + logger.warn("Import of Character tree " + j + " failed."); + success = false; + } - config.getCdmAppController().commitTransaction(ts); + if ((++j % modCount) == 0){ logger.info("CharacterTrees handled: " + j);} - // makeNameSpecificData(nameMap); - logger.info("end makeTaxonDescriptions ..."); - return success; + } + } } - /* (non-Javadoc) - * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator) - */ - protected boolean isIgnore(IImportConfigurator config){ - return false; - } - }