package eu.etaxonomy.cdm.io.abcd206;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import org.apache.log4j.Logger;
import org.springframework.transaction.TransactionStatus;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
+import eu.etaxonomy.cdm.common.MediaMetaData;
+import eu.etaxonomy.cdm.common.MediaMetaData.ImageMetaData;
import eu.etaxonomy.cdm.database.DbSchemaValidation;
import eu.etaxonomy.cdm.io.common.ICdmIO;
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
import eu.etaxonomy.cdm.model.agent.Institution;
+import eu.etaxonomy.cdm.model.agent.Team;
import eu.etaxonomy.cdm.model.location.NamedArea;
+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.MediaRepresentationPart;
+import eu.etaxonomy.cdm.model.name.BacterialName;
+import eu.etaxonomy.cdm.model.name.BotanicalName;
+import eu.etaxonomy.cdm.model.name.CultivarPlantName;
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.name.NonViralName;
+import eu.etaxonomy.cdm.model.name.Rank;
+import eu.etaxonomy.cdm.model.name.ZoologicalName;
import eu.etaxonomy.cdm.model.occurrence.Collection;
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
import eu.etaxonomy.cdm.model.occurrence.FieldObservation;
import eu.etaxonomy.cdm.model.occurrence.LivingBeing;
import eu.etaxonomy.cdm.model.occurrence.Observation;
import eu.etaxonomy.cdm.model.occurrence.Specimen;
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
import eu.etaxonomy.cdm.model.reference.Generic;
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
-public class AbcdIO extends SpecimenIoBase implements ICdmIO {
+
+public class AbcdIO extends SpecimenIoBase implements ICdmIO<IImportConfigurator> {
private static final Logger logger = Logger.getLogger(AbcdIO.class);
protected String fullScientificNameString;
+ protected String atomisedStr;
protected String nomenclatureCode;
protected String institutionCode;
protected String collectionCode;
protected int altitude;
protected ArrayList<String> gatheringAgentList;
protected ArrayList<String> identificationList;
+ protected ArrayList<HashMap<String, String>> atomisedIdentificationList;
protected ArrayList<String> namedAreaList;
protected ArrayList<String> referenceList;
protected ArrayList<String> multimediaObjects;
protected ArrayList<String> knownABCDelements = new ArrayList<String>();
+ protected HashMap<String,String> allABCDelements = new HashMap<String,String>();
public AbcdIO() {
super();
- knownABCDelements.add("Identifications");
- knownABCDelements.add("Identification");
- knownABCDelements.add("Result");
- knownABCDelements.add("TaxonIdentified");
- knownABCDelements.add("ScientificName");
- knownABCDelements.add("FullScientificNameString");
- knownABCDelements.add("NameAtomised");
- knownABCDelements.add("SourceInstitutionID");
- knownABCDelements.add("SourceID");
- knownABCDelements.add("UnitID");
- knownABCDelements.add("RecordBasis");
- knownABCDelements.add("AccessionNumber");
- knownABCDelements.add("LocalityText");
- knownABCDelements.add("LongitudeDecimal");
- knownABCDelements.add("Country");
- knownABCDelements.add("ISO3166Code");
- knownABCDelements.add("CollectorsFieldNumber");
- knownABCDelements.add("CollectorsNumber");
- knownABCDelements.add("AccessionNumber");
- knownABCDelements.add("Altitude_MeasurementOrFactText");
- knownABCDelements.add("Depth");
- knownABCDelements.add("NamedArea_AreaName");
- knownABCDelements.add("GatheringAgent_Person_FullName");
}
/*
* @param fileName: the file's location
* @return the list of root nodes ("Unit")
*/
- private static NodeList getUnitsNodeList(String fileName){
+ private static NodeList getUnitsNodeList(String urlFileName){
+ URL url;
NodeList unitList = null;
try {
DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
DocumentBuilder constructeur = fabrique.newDocumentBuilder();
- File xml = new File(fileName);
- Document document = constructeur.parse(xml);
+ url = new URL(urlFileName);
+ Object o = url.getContent();
+ InputStream is = (InputStream)o;
+ Document document = constructeur.parse(is);
Element racine = document.getDocumentElement();
unitList = racine.getElementsByTagName("Unit");
+
}catch(Exception e){
- System.out.println(e);
+ logger.warn(e);
}
return unitList;
}
- public void afficherInfos(Node noeud, int niv) {
- short type = noeud.getNodeType();
- String nom = noeud.getNodeName();
- String valeur = noeud.getNodeValue();
-
- indenter(niv, type == Node.TEXT_NODE);
- if(!knownABCDelements.contains(nom)){
- System.out.print(nom + " (" + type + ") = '");
- if(valeur != null && !valeur.matches("^\\s+$")){
- System.out.print(valeur);
- System.out.println("'");
- }
- }
- if ((type == Node.DOCUMENT_NODE
- || type == Node.ELEMENT_NODE)
- && noeud.hasChildNodes()) {
- NodeList liste = noeud.getChildNodes();
- for(int i = 0; i < liste.getLength(); i++)
- afficherInfos(liste.item(i), niv + 1);
- }
- }
- public void indenter(int n, boolean texte){
- String tab = "\t";
- for(int i = 0; i < n; i++){
- System.out.print(tab);
- }
- if(texte){
- System.out.print(" - ");
- }
- else
- System.out.print(" + ");
- }
-
/*
* Store the unit's properties into variables
* Look which unit is the preferred one
*/
private void setUnitPropertiesXML(Element racine){
try{
- NodeList group,childs,person;
+ NodeList group;
-// try{afficherInfos(racine, 0);}catch (Exception e) {System.out.println(e);}
+// try{afficherInfos(racine, 0);}catch (Exception e) {logger.info(e);}
group = racine.getChildNodes();
// logger.info("ABCD ELEMENT not stored: "+group.item(i).getNodeName().toString()+" - value: "+group.item(i).getTextContent());
for (int i=0; i< group.getLength(); i++){
- if (group.item(i).getNodeName() == "Identifications"){
+ if (group.item(i).getNodeName().equals("Identifications")){
group = group.item(i).getChildNodes();
break;
}
}
this.identificationList = new ArrayList<String>();
+ this.atomisedIdentificationList = new ArrayList<HashMap<String, String>>();
this.referenceList = new ArrayList<String>();
this.multimediaObjects = new ArrayList<String>();
this.getScientificNames(group);
-// System.out.println("this.identificationList "+this.identificationList.toString());
+// logger.info("this.identificationList "+this.identificationList.toString());
this.getIDs(racine);
this.getRecordBasis(racine);
this.getMultimedia(racine);
}
}
+ String path= "";
+ private void getHierarchie(Node node){
+ while (node != null && node.getNodeName() != "DataSets"){
+// logger.info(node.getParentNode().getNodeName());
+ path = node.getParentNode().getNodeName()+"/"+path;
+ node = node.getParentNode();
+ }
+// logger.info("path: "+path);
+ }
private void getScientificNames(NodeList group){
NodeList identifications,results;
String tmpName = null;
for (int j=0; j< group.getLength(); j++){
- if(group.item(j).getNodeName() == "Identification"){
+ if(group.item(j).getNodeName().equals("Identification")){
this.nomenclatureCode ="";
identifications = group.item(j).getChildNodes();
for (int m=0; m<identifications.getLength();m++){
- if(identifications.item(m).getNodeName() == "Result"){
+ if(identifications.item(m).getNodeName().equals("Result")){
results = identifications.item(m).getChildNodes();
for(int k=0; k<results.getLength();k++)
- if (results.item(k).getNodeName() == "TaxonIdentified")
+ if (results.item(k).getNodeName().equals("TaxonIdentified")){
tmpName=this.getScientificName(results.item(k));
+ }
+ }
+ else if(identifications.item(m).getNodeName().equals("PreferredFlag")){
+ if (this.nomenclatureCode != null && this.nomenclatureCode !="")
+ this.identificationList.add(tmpName+"_preferred_"+identifications.item(m).getTextContent()+"_code_"+this.nomenclatureCode);
+ else
+ this.identificationList.add(tmpName+"_preferred_"+identifications.item(m).getTextContent());
+ path=identifications.item(m).getNodeName();
+ getHierarchie(identifications.item(m));
+ knownABCDelements.add(path);
+ path="";
}
- else if(identifications.item(m).getNodeName() == "PreferredFlag")
- this.identificationList.add(tmpName+"_preferred_"+identifications.item(m).getTextContent()+"_code_"+this.nomenclatureCode);
- else if (identifications.item(m).getNodeName() == "References")
+ else if (identifications.item(m).getNodeName().equals("References"))
this.getReferences(identifications.item(m));
- else
- if (tmpName != null)
- this.identificationList.add(tmpName+"_preferred_"+"0"+"_code_"+this.nomenclatureCode);
}
}
}
+ boolean hasPref=false;
+ for (int j=0; j< group.getLength(); j++){
+ if(group.item(j).getNodeName().equals("Identification")){
+ this.nomenclatureCode ="";
+ identifications = group.item(j).getChildNodes();
+ for (int m=0; m<identifications.getLength();m++){
+ if(identifications.item(m).getNodeName().equals("Result")){
+ results = identifications.item(m).getChildNodes();
+ for(int k=0; k<results.getLength();k++)
+ if (results.item(k).getNodeName().equals("TaxonIdentified")){
+ tmpName=this.getScientificName(results.item(k));
+ }
+ }
+ if(identifications.item(m).getNodeName().equals("PreferredFlag")){
+ hasPref=true;
+ }
+ }
+ if ( !hasPref && tmpName != null)
+ if (this.nomenclatureCode != null && this.nomenclatureCode !="")
+ this.identificationList.add(tmpName+"_preferred_"+"0"+"_code_"+this.nomenclatureCode);
+ else
+ this.identificationList.add(tmpName+"_preferred_"+"0");
+ }
+ }
+
}
+
+
private void getReferences(Node result){
NodeList results,reference;
results = result.getChildNodes();
for(int k=0; k<results.getLength();k++){
- if (results.item(k).getNodeName() == "Reference"){
+ if (results.item(k).getNodeName().equals("Reference")){
reference = results.item(k).getChildNodes();
for(int l=0;l<reference.getLength();l++){
- if (reference.item(l).getNodeName()=="TitleCitation")
+ if (reference.item(l).getNodeName().equals("TitleCitation")){
+ path = reference.item(l).getNodeName();
referenceList.add(reference.item(l).getTextContent());
+ getHierarchie(reference.item(l));
+ knownABCDelements.add(path);
+ path="";
+ }
}
}
}
}
private String getScientificName(Node result){
- NodeList taxonsIdentified, scnames;
+ NodeList taxonsIdentified, scnames, atomised;
String tmpName = "";
+ atomisedStr="";
taxonsIdentified = result.getChildNodes();
for (int l=0; l<taxonsIdentified.getLength(); l++){
- if (taxonsIdentified.item(l).getNodeName() == "ScientificName"){
+ if (taxonsIdentified.item(l).getNodeName().equals("ScientificName")){
scnames = taxonsIdentified.item(l).getChildNodes();
for (int n=0;n<scnames.getLength();n++){
- if (scnames.item(n).getNodeName() == "FullScientificNameString")
+ if (scnames.item(n).getNodeName().equals("FullScientificNameString")){
+ path=scnames.item(n).getNodeName();
tmpName = scnames.item(n).getTextContent();
- if (scnames.item(n).getNodeName() == "NameAtomised"){
+ getHierarchie(scnames.item(n));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if (scnames.item(n).getNodeName().equals("NameAtomised")){
try {
if (scnames.item(n).hasChildNodes()){
-
this.nomenclatureCode = scnames.item(n).getChildNodes().item(1).getNodeName();
}
} catch (Exception e) {
this.nomenclatureCode ="";
}
+ atomised = scnames.item(n).getChildNodes().item(1).getChildNodes();
+ this.atomisedIdentificationList.add(this.getAtomisedNames(nomenclatureCode,atomised));
}
}
}
}
return tmpName;
}
+
+ private HashMap<String,String> getAtomisedNames(String code, NodeList atomised){
+ if (code.equals("Botanical"))
+ return this.getAtomisedBotanical(atomised);
+ if (code.equals("Bacterial"))
+ return this.getAtomisedBacterial(atomised);
+ if (code.equals("NameViral"))
+ return this.getAtomisedViral(atomised);
+ if (code.equals("NameZoological"))
+ return this.getAtomisedZoological(atomised);
+ return new HashMap<String,String>();
+ }
+
+ private HashMap<String,String> getAtomisedZoological(NodeList atomised){
+ HashMap<String,String> atomisedMap = new HashMap<String,String>();
+ for (int i=0;i<atomised.getLength();i++){
+ if(atomised.item(i).getNodeName().equals("GenusOrMonomial")){
+ atomisedMap.put("Genus",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("Subgenus")){
+ atomisedMap.put("Subgenus",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("SpeciesEpithet")){
+ atomisedMap.put("SpeciesEpithet",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("SubspeciesEpithet")){
+ atomisedMap.put("SubspeciesEpithet",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("AuthorTeamOriginalAndYear")){
+ atomisedMap.put("AuthorTeamOriginalAndYear",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";}
+ if(atomised.item(i).getNodeName().equals("AuthorTeamParenthesisAndYear")){
+ atomisedMap.put("AuthorTeamParenthesisAndYear",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";}
+ if(atomised.item(i).getNodeName().equals("CombinationAuthorTeamAndYear")){
+ atomisedMap.put("CombinationAuthorTeamAndYear",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";}
+ if(atomised.item(i).getNodeName().equals("Breed")){
+ atomisedMap.put("Breed",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";}
+ if(atomised.item(i).getNodeName().equals("NamedIndividual")){
+ atomisedMap.put("NamedIndividual",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ }
+ return atomisedMap;
+
+ }
+
+ private HashMap<String,String> getAtomisedViral(NodeList atomised){
+ HashMap<String,String> atomisedMap = new HashMap<String,String>();
+ for (int i=0;i<atomised.getLength();i++){
+ if(atomised.item(i).getNodeName().equals("GenusOrMonomial")){
+ atomisedMap.put("Genus",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("ViralSpeciesDesignation")){
+ atomisedMap.put("ViralSpeciesDesignation", atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("Acronym")){
+ atomisedMap.put("Acronym",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ }
+ return atomisedMap;
+ }
+
+ private HashMap<String,String> getAtomisedBotanical(NodeList atomised){
+ HashMap<String,String> atomisedMap = new HashMap<String,String>();
+ for (int i=0;i<atomised.getLength();i++){
+ if(atomised.item(i).getNodeName().equals("GenusOrMonomial")){
+ atomisedMap.put("Genus",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("FirstEpithet")){
+ atomisedMap.put("FirstEpithet",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("InfraspecificEpithet")){
+ atomisedMap.put("InfraSpeEpithet", atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("Rank")){
+ atomisedMap.put("Rank",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("HybridFlag")){
+ atomisedMap.put("HybridFlag",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("AuthorTeamParenthesis")){
+ atomisedMap.put("AuthorTeamParenthesis",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("AuthorTeam")){
+ atomisedMap.put("AuthorTeam",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("CultivarGroupName")){
+ atomisedMap.put("CultivarGroupName",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("CultivarName")){
+ atomisedMap.put("CultivarName",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("TradeDesignationNames")){
+ atomisedMap.put("Trade",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ }
+ return atomisedMap;
+ }
+
+ private HashMap<String,String> getAtomisedBacterial(NodeList atomised){
+ HashMap<String,String> atomisedMap = new HashMap<String,String>();
+ for (int i=0;i<atomised.getLength();i++){
+ if(atomised.item(i).getNodeName().equals("GenusOrMonomial")){
+ atomisedMap.put("Genus",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("Subgenus")){
+ atomisedMap.put("SubGenus",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("SubgenusAuthorAndYear")){
+ atomisedMap.put("SubgenusAuthorAndYear",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("SpeciesEpithet")){
+ atomisedMap.put("SpeciesEpithet",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("SubspeciesEpithet")){
+ atomisedMap.put("SubspeciesEpithet",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("ParentheticalAuthorTeamAndYear")){
+ atomisedMap.put("ParentheticalAuthorTeamAndYear",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("AuthorTeamAndYear")){
+ atomisedMap.put("AuthorTeamAndYear",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ if(atomised.item(i).getNodeName().equals("NameApprobation")){
+ atomisedMap.put("NameApprobation",atomised.item(i).getTextContent());
+ path=atomised.item(i).getNodeName();
+ getHierarchie(atomised.item(i));
+ knownABCDelements.add(path);
+ path="";
+ }
+ }
+ return atomisedMap;
+ }
+
private void getIDs(Element racine){
NodeList group;
try {
group = racine.getElementsByTagName("SourceInstitutionID");
+ path=group.item(0).getNodeName();
+ getHierarchie(group.item(0));
+ knownABCDelements.add(path);
+ path="";
this.institutionCode = group.item(0).getTextContent();
} catch (NullPointerException e) {
this.institutionCode= "";
}
try {
group = racine.getElementsByTagName("SourceID");
+ path=group.item(0).getNodeName();
+ getHierarchie(group.item(0));
+ knownABCDelements.add(path);
+ path="";
this.collectionCode = group.item(0).getTextContent();
} catch (NullPointerException e) {
this.collectionCode = "";
}
try {
group = racine.getElementsByTagName("UnitID");
+ path=group.item(0).getNodeName();
+ getHierarchie(group.item(0));
+ knownABCDelements.add(path);
+ path="";
this.unitID = group.item(0).getTextContent();
} catch (NullPointerException e) {
this.unitID = "";
NodeList group;
try {
group = racine.getElementsByTagName("RecordBasis");
+ path=group.item(0).getNodeName();
+ getHierarchie(group.item(0));
+ knownABCDelements.add(path);
+ path="";
this.recordBasis = group.item(0).getTextContent();
} catch (NullPointerException e) {
this.recordBasis = "";
for(int i=0;i<group.getLength();i++){
multimedias = group.item(i).getChildNodes();
for (int j=0;j<multimedias.getLength();j++){
- if (multimedias.item(j).getNodeName() == "MultiMediaObject"){
+ if (multimedias.item(j).getNodeName().equals("MultiMediaObject")){
multimedia = multimedias.item(j).getChildNodes();
for (int k=0;k<multimedia.getLength();k++){
- if(multimedia.item(k).getNodeName() == "FileURI")
+ if(multimedia.item(k).getNodeName().equals("FileURI")){
this.multimediaObjects.add(multimedia.item(k).getTextContent());
+ path = multimedia.item(k).getNodeName();
+ getHierarchie(multimedia.item(k));
+ knownABCDelements.add(path);
+ path="";
+ }
}
}
}
}
} catch (NullPointerException e) {
- System.out.println(e);
+ logger.info(e);
}
}
NodeList group;
try {
group = racine.getElementsByTagName("AccessionNumber");
+ path=group.item(0).getNodeName();
+ getHierarchie(group.item(0));
+ knownABCDelements.add(path);
+ path="";
this.accessionNumber = group.item(0).getTextContent();
} catch (NullPointerException e) {
this.accessionNumber = "";
}
try {
group = racine.getElementsByTagName("CollectorsFieldNumber");
+ path=group.item(0).getNodeName();
+ getHierarchie(group.item(0));
+ knownABCDelements.add(path);
+ path="";
this.fieldNumber = group.item(0).getTextContent();
} catch (NullPointerException e) {
this.fieldNumber = "";
try {
group = racine.getElementsByTagName("CollectorsNumber");
+ path=group.item(0).getNodeName();
+ getHierarchie(group.item(0));
+ knownABCDelements.add(path);
+ path="";
this.collectorsNumber = group.item(0).getTextContent();
} catch (NullPointerException e) {
this.collectorsNumber = "";
try {
group = racine.getElementsByTagName("AccessionNumber");
+ path=group.item(0).getNodeName();
+ getHierarchie(group.item(0));
+ knownABCDelements.add(path);
+ path="";
this.accessionNumber = group.item(0).getTextContent();
} catch (NullPointerException e) {
this.accessionNumber = "";
NodeList group, childs;
try {
group = racine.getElementsByTagName("LocalityText");
+ path=group.item(0).getNodeName();
+ getHierarchie(group.item(0));
+ knownABCDelements.add(path);
+ path="";
this.locality = group.item(0).getTextContent();
if (group.item(0).hasAttributes())
if (group.item(0).getAttributes().getNamedItem("lang") != null)
}
try {
group = racine.getElementsByTagName("LongitudeDecimal");
+ path=group.item(0).getNodeName();
+ getHierarchie(group.item(0));
+ knownABCDelements.add(path);
+ path="";
this.longitude = Double.valueOf(group.item(0).getTextContent());
} catch (NullPointerException e) {
this.longitude=0.0;
}
try {
group = racine.getElementsByTagName("LatitudeDecimal");
+ path=group.item(0).getNodeName();
+ getHierarchie(group.item(0));
+ knownABCDelements.add(path);
+ path="";
this.latitude = Double.valueOf(group.item(0).getTextContent());
} catch (NullPointerException e) {
this.latitude=0.0;
}
try {
group = racine.getElementsByTagName("Country");
- this.country = group.item(0).getTextContent();
+ childs = group.item(0).getChildNodes();
+ for (int i=0;i<childs.getLength(); i++){
+ if(childs.item(i).getNodeName() == "Name"){
+ path=childs.item(i).getNodeName();
+ getHierarchie(childs.item(i));
+ knownABCDelements.add(path);
+ path="";
+ this.country = childs.item(i).getTextContent();
+ }
+ }
} catch (NullPointerException e) {
this.country = "";
}
try {
- group = racine.getElementsByTagName("ISO3166Code");
- this.isocountry = group.item(0).getTextContent();
+ group = racine.getElementsByTagName("Country");
+ childs = group.item(0).getChildNodes();
+ for (int i=0;i<childs.getLength(); i++){
+ if(childs.item(i).getNodeName() == "ISO3166Code"){
+ path=childs.item(i).getNodeName();
+ getHierarchie(childs.item(i));
+ knownABCDelements.add(path);
+ path="";
+ this.isocountry = childs.item(i).getTextContent();
+ }
+ }
} catch (NullPointerException e) {
this.isocountry = "";
}
for (int i=0;i<group.getLength();i++){
childs = group.item(i).getChildNodes();
for (int j=0;j<childs.getLength();j++){
- if (childs.item(j).getNodeName() == "MeasurementOrFactText")
+ if (childs.item(j).getNodeName().equals("MeasurementOrFactText")){
+ path=childs.item(j).getNodeName();
+ getHierarchie(childs.item(j));
+ knownABCDelements.add(path);
+ path="";
this.altitude = Integer.valueOf(childs.item(j).getTextContent());
+ }
}
}
} catch (NullPointerException e) {
try {
group = racine.getElementsByTagName("Depth");
+ path=group.item(0).getNodeName();
+ getHierarchie(group.item(0));
+ knownABCDelements.add(path);
+ path="";
this.depth = Integer.valueOf(group.item(0).getTextContent());
} catch (NullPointerException e) {
this.depth = -9999;
for (int i=0;i<group.getLength();i++){
childs = group.item(i).getChildNodes();
for (int j=0; j<childs.getLength();j++){
- if (childs.item(j).getNodeName() == "AreaName")
+ if (childs.item(j).getNodeName().equals("AreaName")){
+ path = childs.item(j).getNodeName();
+ getHierarchie(childs.item(j));
+ knownABCDelements.add(path);
+ path="";
this.namedAreaList.add(childs.item(j).getTextContent());
+ }
}
}
}catch(NullPointerException e){
for (int i=0; i< group.getLength(); i++){
childs = group.item(i).getChildNodes();
for (int j=0; j<childs.getLength();j++){
- if (childs.item(j).getNodeName() == "Person"){
+ if (childs.item(j).getNodeName().equals("Person")){
person = childs.item(j).getChildNodes();
for (int k=0; k<person.getLength(); k++)
- if (person.item(k).getNodeName() == "FullName")
+ if (person.item(k).getNodeName().equals("FullName")){
+ path=person.item(k).getNodeName();
+ getHierarchie(person.item(k));
+ knownABCDelements.add(path);
+ path="";
this.gatheringAgentList.add(person.item(k).getTextContent());
+ }
}
}
Institution institution;
List<Institution> institutions;
try{
- System.out.println(this.institutionCode);
+ logger.info(this.institutionCode);
institutions= config.getCdmAppController().getAgentService().searchInstitutionByCode(this.institutionCode);
}catch(Exception e){
- System.out.println("BLI "+e);
institutions=new ArrayList<Institution>();
}
if (institutions.size() ==0 || !config.getReUseExistingMetadata()){
- System.out.println("Institution (agent) unknown or not allowed to reuse existing metadata");
+ logger.info("Institution (agent) unknown or not allowed to reuse existing metadata");
//create institution
institution = Institution.NewInstance();
institution.setCode(this.institutionCode);
}
else{
- System.out.println("Institution (agent) already in the db");
+ logger.info("Institution (agent) already in the db");
institution = institutions.get(0);
}
return institution;
try{
collections = config.getCdmAppController().getOccurrenceService().searchCollectionByCode(this.collectionCode);
}catch(Exception e){
- System.out.println("BLA"+e);
collections=new ArrayList<Collection>();
}
if (collections.size() ==0 || !config.getReUseExistingMetadata()){
- System.out.println("Collection not found or do not reuse existing metadata "+this.collectionCode);
+ logger.info("Collection not found or do not reuse existing metadata "+this.collectionCode);
//create new collection
collection.setCode(this.collectionCode);
collection.setCodeStandard("GBIF");
* @param sec
*/
private void setTaxonNameBase(SpecimenImportConfigurator config, DerivedUnitBase derivedThing, ReferenceBase sec){
- TaxonNameBase taxonName = null;
+ NonViralName<?> taxonName = null;
String fullScientificNameString;
Taxon taxon = null;
DeterminationEvent determinationEvent = null;
- List<TaxonNameBase> names = null;
+ List<TaxonBase> names = null;
String scientificName="";
boolean preferredFlag=false;
if (fullScientificNameString.indexOf("_preferred_") != -1){
scientificName = fullScientificNameString.split("_preferred_")[0];
String pTmp = fullScientificNameString.split("_preferred_")[1].split("_code_")[0];
- if (pTmp == "1" || pTmp.toLowerCase().indexOf("true") != -1)
+ if (pTmp.equals("1") || pTmp.toLowerCase().indexOf("true") != -1)
preferredFlag=true;
else
preferredFlag=false;
}
else scientificName = fullScientificNameString;
+ logger.info(fullScientificNameString);
if (fullScientificNameString.indexOf("_code_") != -1)
this.nomenclatureCode = fullScientificNameString.split("_code_")[1];
- if (config.getDoAutomaticParsing())
+ if (config.getDoAutomaticParsing() || this.atomisedIdentificationList == null || this.atomisedIdentificationList.size()==0)
taxonName = this.parseScientificName(scientificName);
- else taxonName.setTitleCache(scientificName);
-
- if (taxonName == null) System.out.println("ARGGGGGGGGGGGGGGGGGGGGG");
- if (true){
- names = config.getCdmAppController().getNameService().getNamesByName(scientificName);
- if (names.size() == 0){
- System.out.println("Name not found: " + scientificName);
- }else{
- if (names.size() > 1){
- System.out.println("More then 1 name found: " + scientificName);
- }
- System.out.println("Name found");
- taxonName = names.get(0);
+ else {
+ if (this.atomisedIdentificationList != null || this.atomisedIdentificationList.size()>0)
+ taxonName = this.setTaxonNameByType(this.atomisedIdentificationList.get(i), scientificName);
+ }
+ if(taxonName == null){
+ taxonName = NonViralName.NewInstance(null);
+ taxonName.setFullTitleCache(scientificName);
+ }
+ if (config.getDoReUseTaxon()){
+ try{
+ names = config.getCdmAppController().getTaxonService().searchTaxaByName(scientificName, sec);
+ taxon = (Taxon)names.get(0);
}
+ catch(Exception e){taxon=null;}
}
+// taxonName = NonViralName.NewInstance(null);
+// taxonName.setFullTitleCache(scientificName);
- config.getCdmAppController().getNameService().saveTaxonName(taxonName);
- taxon = Taxon.NewInstance(taxonName, sec); //TODO use real reference for sec
-
+ if (!config.getDoReUseTaxon() || taxon == null){
+ config.getCdmAppController().getNameService().saveTaxonName(taxonName);
+ taxon = Taxon.NewInstance(taxonName, sec); //sec set null
+ }
determinationEvent = DeterminationEvent.NewInstance();
determinationEvent.setTaxon(taxon);
determinationEvent.setPreferredFlag(preferredFlag);
}
- private TaxonNameBase parseScientificName(String scientificName){
- System.out.println("scientificName");
- TaxonNameBase taxonName = null;
+ private NonViralName<?> parseScientificName(String scientificName){
NonViralNameParserImpl nvnpi = NonViralNameParserImpl.NewInstance();
+ NonViralName<?>taxonName = null;
+ boolean problem=false;
- System.out.println("nomenclature: "+this.nomenclatureCode);
- if (this.nomenclatureCode == "Zoological"){
- taxonName = nvnpi.parseFullName(scientificName,NomenclaturalCode.ICZN(),null);
+ if (this.nomenclatureCode.toString().equals("Zoological")){
+ taxonName = (ZoologicalName)nvnpi.parseFullName(scientificName,NomenclaturalCode.ICZN(),null);
if (taxonName.hasProblem())
- System.out.println("pb ICZN");}
- if (this.nomenclatureCode == "Botanical"){
- taxonName = nvnpi.parseFullName(scientificName,NomenclaturalCode.ICBN(),null);
+ problem=true;
+ }
+ if (this.nomenclatureCode.toString().equals("Botanical")){
+ taxonName = (BotanicalName)nvnpi.parseFullName(scientificName,NomenclaturalCode.ICBN(),null);
if (taxonName.hasProblem())
- System.out.println("pb ICBN");}
- if (this.nomenclatureCode == "Bacterial"){
- taxonName = nvnpi.parseFullName(scientificName,NomenclaturalCode.ICNB(), null);
+ problem=true;;}
+ if (this.nomenclatureCode.toString().equals("Bacterial")){
+ taxonName = (BacterialName)nvnpi.parseFullName(scientificName,NomenclaturalCode.ICNB(), null);
if (taxonName.hasProblem())
- System.out.println("pb ICNB");
+ problem=true;
}
- if (this.nomenclatureCode == "Cultivar"){
- taxonName = nvnpi.parseFullName(scientificName,NomenclaturalCode.ICNCP(), null);
+ if (this.nomenclatureCode.toString().equals("Cultivar")){
+ taxonName = (CultivarPlantName)nvnpi.parseFullName(scientificName,NomenclaturalCode.ICNCP(), null);
if (taxonName.hasProblem())
- System.out.println("pb ICNCP");
+ problem=true;;
}
- if (this.nomenclatureCode == "Viral"){
- taxonName = nvnpi.parseFullName(scientificName,NomenclaturalCode.ICVCN(), null);
+// if (this.nomenclatureCode.toString().equals("Viral")){
+// ViralName taxonName = (ViralName)nvnpi.parseFullName(scientificName,NomenclaturalCode.ICVCN(), null);
+// if (taxonName.hasProblem())
+// logger.info("pb ICVCN");
+// }
+ //TODO: parsing of ViralNames?
+ if(problem){
+ taxonName = NonViralName.NewInstance(null);
+ taxonName.setTitleCache(scientificName);
+ }
+ return taxonName;
+
+ }
+
+ @SuppressWarnings("unchecked")
+ private NonViralName<?> setTaxonNameByType(HashMap<String, String> atomisedMap,String fullName){
+ if (this.nomenclatureCode.equals("Zoological")){
+ NonViralName<ZoologicalName> taxonName = ZoologicalName.NewInstance(null);
+ taxonName.setFullTitleCache(fullName, true);
+ taxonName.setGenusOrUninomial(getFromMap(atomisedMap,"Genus"));
+ taxonName.setInfraGenericEpithet(getFromMap(atomisedMap,"SubGenus"));
+ taxonName.setSpecificEpithet(getFromMap(atomisedMap,"SpeciesEpithet"));
+ taxonName.setInfraSpecificEpithet(getFromMap(atomisedMap,"SubspeciesEpithet"));
+ Team team = null;
+ if(getFromMap(atomisedMap,"AuthorTeamParenthesis") != null){
+ team = Team.NewInstance();
+ team.setTitleCache(getFromMap(atomisedMap,"AuthorTeamParenthesis"));
+ }else{
+ if (getFromMap(atomisedMap,"AuthorTeamAndYear") != null){
+ team = Team.NewInstance();
+ team.setTitleCache(getFromMap(atomisedMap,"AuthorTeamAndYear"));
+ }
+ }
+ if(team != null)
+ taxonName.setBasionymAuthorTeam(team);
+ else{
+ if(getFromMap(atomisedMap,"AuthorTeamParenthesis") != null)
+ taxonName.setAuthorshipCache(getFromMap(atomisedMap,"AuthorTeamParenthesis"));
+ else if (getFromMap(atomisedMap,"AuthorTeamAndYear") != null)
+ taxonName.setAuthorshipCache(getFromMap(atomisedMap,"AuthorTeamAndYear"));
+ }
+ if(getFromMap(atomisedMap,"CombinationAuthorTeamAndYear") != null){
+ team = Team.NewInstance();
+ team.setTitleCache(getFromMap(atomisedMap,"CombinationAuthorTeamAndYear"));
+ taxonName.setCombinationAuthorTeam(team);
+ }
if (taxonName.hasProblem())
- System.out.println("pb ICVCN");
+ logger.info("pb ICZN");
+ else return taxonName;
}
- try{taxonName.hasProblem();}
- catch (Exception e) {
- taxonName = nvnpi.parseFullName(scientificName);
+ if (this.nomenclatureCode.equals("Botanical")){
+ NonViralName<BotanicalName> taxonName = BotanicalName.NewInstance(null);
+ taxonName.setFullTitleCache(fullName, true);
+ taxonName.setGenusOrUninomial(getFromMap(atomisedMap,"Genus"));
+ taxonName.setInfraGenericEpithet(getFromMap(atomisedMap,"FirstEpithet"));
+ taxonName.setInfraSpecificEpithet(getFromMap(atomisedMap,"InfraSpeEpithet"));
+ try{taxonName.setRank(Rank.getRankByName(getFromMap(atomisedMap,"Rank")));
+ }catch(Exception e){}
+ Team team = null;
+ if(getFromMap(atomisedMap,"AuthorTeamParenthesis") != null){
+ team = Team.NewInstance();
+ team.setTitleCache(getFromMap(atomisedMap,"AuthorTeamParenthesis"));
+ if(team != null)
+ taxonName.setBasionymAuthorTeam(team);
+ }
+ if (getFromMap(atomisedMap,"AuthorTeam") != null){
+ team = Team.NewInstance();
+ team.setTitleCache(getFromMap(atomisedMap,"AuthorTeam"));
+ if(team != null)
+ taxonName.setCombinationAuthorTeam(team);
+ }
+ if (team == null) {
+ if(getFromMap(atomisedMap,"AuthorTeamParenthesis") != null)
+ taxonName.setAuthorshipCache(getFromMap(atomisedMap,"AuthorTeamParenthesis"));
+ else if (getFromMap(atomisedMap,"AuthorTeam") != null)
+ taxonName.setAuthorshipCache(getFromMap(atomisedMap,"AuthorTeam"));
+ }
+ if(getFromMap(atomisedMap,"CombinationAuthorTeamAndYear") != null){
+ team = Team.NewInstance();
+ team.setTitleCache(getFromMap(atomisedMap,"CombinationAuthorTeamAndYear"));
+ taxonName.setCombinationAuthorTeam(team);
+ }
+ if (taxonName.hasProblem())
+ logger.info("pb ICBN");
+ else return taxonName;
+ }
+ if (this.nomenclatureCode.equals("Bacterial")){
+ NonViralName<BacterialName> taxonName = BacterialName.NewInstance(null);
+ taxonName.setFullTitleCache(fullName, true);
+ taxonName.setGenusOrUninomial(getFromMap(atomisedMap,"Genus"));
+ taxonName.setInfraGenericEpithet(getFromMap(atomisedMap,"SubGenus"));
+ taxonName.setSpecificEpithet(getFromMap(atomisedMap,"Species"));
+ taxonName.setInfraSpecificEpithet(getFromMap(atomisedMap,"SubspeciesEpithet"));
+ if(getFromMap(atomisedMap,"AuthorTeamAndYear") != null){
+ Team team = Team.NewInstance();
+ team.setTitleCache(getFromMap(atomisedMap,"AuthorTeamAndYear"));
+ taxonName.setCombinationAuthorTeam(team);
+ }
+ if(getFromMap(atomisedMap,"ParentheticalAuthorTeamAndYear") != null){
+ Team team = Team.NewInstance();
+ team.setTitleCache(getFromMap(atomisedMap,"ParentheticalAuthorTeamAndYear"));
+ taxonName.setBasionymAuthorTeam(team);
+ }
+ if (taxonName.hasProblem())
+ logger.info("pb ICNB");
+ else return taxonName;
+ }
+ if (this.nomenclatureCode.equals("Cultivar")){
+ NonViralName<CultivarPlantName> taxonName = CultivarPlantName.NewInstance(null);
+
+ if (taxonName.hasProblem())
+ logger.info("pb ICNCP");
+ else return taxonName;
}
- if (taxonName.hasProblem())
- taxonName = nvnpi.parseFullName(scientificName);
+// if (this.nomenclatureCode.equals("Viral")){
+// ViralName taxonName = ViralName.NewInstance(null);
+// taxonName.setFullTitleCache(fullName, true);
+// taxonName.setAcronym(getFromMap(atomisedMap,"Acronym"));
+// if (taxonName.hasProblem())
+// logger.info("pb ICVCN");
+// else return taxonName;
+// }
+ //TODO ViralName
+ NonViralName<?>taxonName = NonViralName.NewInstance(null);
+ taxonName.setFullTitleCache(fullName, true);
return taxonName;
}
+
+ private String getFromMap(HashMap<String, String> atomisedMap, String key){
+ String value = null;
+ if (atomisedMap.containsKey(key))
+ value = atomisedMap.get(key);
+ try{
+ if (value != null && key.matches(".*Year.*")){
+ value=value.trim();
+ if (value.matches("[a-z A-Z ]*[0-9]{4}$")){
+ String tmp=value.split("[0-9]{4}$")[0];
+ int year = Integer.parseInt(value.split(tmp)[1]);
+ if (year >= 1752)
+ value=tmp;
+ else
+ value=null;
+ }
+ else
+ value=null;
+ }
+ }catch(Exception e){value=null;}
+
+ return value;
+ }
/*
* Store the unit with its Gathering informations in the CDM
*/
public boolean start(SpecimenImportConfigurator config){
boolean result = true;
- boolean withCdm = true;
CdmApplicationController app = null;
TransactionStatus tx = null;
// app = CdmApplicationController.NewInstance(config.getDestination(), config.getDbSchemaValidation());
// } catch (DataSourceNotFoundException e1) {
// e1.printStackTrace();
-// System.out.println("DataSourceNotFoundException "+e1);
+// logger.info("DataSourceNotFoundException "+e1);
// } catch (TermNotFoundException e1) {
// e1.printStackTrace();
-// System.out.println("TermNotFoundException " +e1);
+// logger.info("TermNotFoundException " +e1);
// }
tx = app.startTransaction();
try {
// ReferenceBase sec = Database.NewInstance();
// sec.setTitleCache("XML DATA");
- ReferenceBase sec = null;
+ ReferenceBase sec = config.getTaxonReference();
/**
* SPECIMEN OR OBSERVATION OR LIVING
*/
DerivedUnitBase derivedThing = null;
//create specimen
+ boolean rbFound=false;
if (this.recordBasis != null){
if (this.recordBasis.toLowerCase().startsWith("s")) {//specimen
- derivedThing = Specimen.NewInstance();
+ derivedThing = Specimen.NewInstance();
+ rbFound = true;
}
else if (this.recordBasis.toLowerCase().startsWith("o")) {//observation
- derivedThing = Observation.NewInstance();
+ derivedThing = Observation.NewInstance();
+ rbFound = true;
}
else if (this.recordBasis.toLowerCase().startsWith("l")) {//living -> fossil, herbarium sheet....???
derivedThing = LivingBeing.NewInstance();
+ rbFound = true;
+ }
+ if (! rbFound){
+ logger.info("The basis of record does not seem to be known: "+this.recordBasis);
+ derivedThing = DerivedUnit.NewInstance();
}
}
- if (derivedThing == null)
- derivedThing = Observation.NewInstance();
+ else{
+ logger.info("The basis of record is null");
+ derivedThing = DerivedUnit.NewInstance();
+ }
+// if(derivedThing == null)derivedThing=Observation.NewInstance();
this.setTaxonNameBase(config, derivedThing, sec);
* GATHERING EVENT
*/
- UnitsGatheringEvent unitsGatheringEvent = new UnitsGatheringEvent(app, this.locality, this.languageIso, this.longitude,
+ UnitsGatheringEvent unitsGatheringEvent = new UnitsGatheringEvent(config, this.locality, this.languageIso, this.longitude,
this.latitude, this.gatheringAgentList);
- UnitsGatheringArea unitsGatheringArea = new UnitsGatheringArea(this.isocountry, this.country,app);
+ UnitsGatheringArea unitsGatheringArea = new UnitsGatheringArea(this.isocountry, this.country, config);
NamedArea areaCountry = unitsGatheringArea.getArea();
unitsGatheringEvent.addArea(areaCountry);
unitsGatheringArea = new UnitsGatheringArea(this.namedAreaList);
fieldObservation.setGatheringEvent(unitsGatheringEvent.getGatheringEvent());
// //add Multimedia URLs
if(this.multimediaObjects.size()>0){
- MediaRepresentationPart part;
MediaRepresentation representation;
Media media;
+ ImageMetaData imd ;
+ URL url ;
+ ImageFile imf;
for (int i=0;i<this.multimediaObjects.size();i++){
- part= MediaRepresentationPart.NewInstance(this.multimediaObjects.get(i),0);
- //TODO update the Multimedia Object without size :)
- representation = MediaRepresentation.NewInstance();
- representation.addRepresentationPart(part);
- media = Media.NewInstance();
- media.addRepresentation(representation);
- fieldObservation.addMedia(media);
+ if(this.multimediaObjects.get(i) != null){
+ imd = new ImageMetaData();
+ url = new URL(this.multimediaObjects.get(i));
+ imd = MediaMetaData.readImageMetaData(url, imd);
+ if (imd != null){
+ representation = MediaRepresentation.NewInstance();
+ imf = ImageFile.NewInstance(this.multimediaObjects.get(i), null, imd);
+ representation.addRepresentationPart(imf);
+ media = Media.NewInstance();
+ media.addRepresentation(representation);
+ fieldObservation.addMedia(media);
+ }
+ }
}
}
// //link fieldObservation and specimen
/**
* SAVE AND STORE DATA
*/
-
app.getTermService().saveTerm(areaCountry);//save it sooner
for (int i=0; i<nas.size();i++)
app.getTermService().saveTerm(nas.get(i));//save it sooner (foreach area)
app.getTermService().saveLanguageData(unitsGatheringEvent.getLocality());//save it sooner
app.getOccurrenceService().saveSpecimenOrObservationBase(derivedThing);
-
- logger.info("saved new specimen ...");
+ logger.info("saved ABCD specimen ...");
} catch (Exception e) {
result = false;
}
app.commitTransaction(tx);
- System.out.println("commit done");
app.close();
+
return result;
}
+ private void compareABCDtoCDM(String fileName, ArrayList<String> knownElts){
+
+ try {
+ DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
+ DocumentBuilder constructeur = fabrique.newDocumentBuilder();
+ File xml = new File(fileName);
+ Document document = constructeur.parse(xml);
+ Element racine = document.getDocumentElement();
+ traverse(racine);
+ } catch (ParserConfigurationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SAXException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Set<String> elts = allABCDelements.keySet();
+ Iterator< String>it = elts.iterator();
+ String elt;
+ while (it.hasNext()){
+ elt = it.next();
+ if (knownElts.indexOf(elt) == -1)
+ logger.info("Unsaved ABCD element: "+elt+" - "+allABCDelements.get(elt));
+ }
+
+ }
+
+ private void traverse(Node node){
+ // Extract node info:
+ String test = node.getTextContent();
+
+ // Print and continue traversing.
+ if(test != null && test != "#text" && node.getNodeName() != "#text" && test.split("\n").length==1 && test.length()>0)
+ {
+ path=node.getNodeName();
+ getHierarchie(node);
+ allABCDelements.put(path,test);
+ path="";
+ }
+ // Now traverse the rest of the tree in depth-first order.
+ if (node.hasChildNodes()) {
+ // Get the children in a list.
+ NodeList nl = node.getChildNodes();
+ // How many of them?
+ int size = nl.getLength();
+ for (int i=0; i<size; i++)
+ // Recursively traverse each of the children.
+ traverse (nl.item(i));
+ }
+ }
+
public boolean invoke(SpecimenImportConfigurator config){
- System.out.println("INVOKE Specimen Import from ABCD2.06 XML File");
+ logger.info("INVOKE Specimen Import from ABCD2.06 XML File");
+ boolean result = true;
AbcdIO test = new AbcdIO();
- String sourceName = config.getSourceNameString();
+ String sourceName = config.getSource();
NodeList unitsList = getUnitsNodeList(sourceName);
if (unitsList != null)
{
- System.out.println("nb units to insert: "+unitsList.getLength());
+ logger.info("nb units to insert: "+unitsList.getLength());
for (int i=0;i<unitsList.getLength();i++){
test.setUnitPropertiesXML((Element)unitsList.item(i));
- test.start(config);
+ result &= test.start(config);
config.setDbSchemaValidation(DbSchemaValidation.UPDATE);
+ //compare the ABCD elements added in to the CDM and the unhandled ABCD elements
+ compareABCDtoCDM(sourceName,test.knownABCDelements);
+ //reset the ABCD elements added in CDM
+ //knownABCDelements = new ArrayList<String>();
+ allABCDelements = new HashMap<String,String>();
}
}
- return false;
+ return result;
}
public boolean invoke(IImportConfigurator config, Map stores) {
- System.out.println("invoke de ABCDio");
- invoke((SpecimenImportConfigurator)config);
- return false;
+ logger.info("invoke de AbcdIo");
+ return invoke((SpecimenImportConfigurator)config);
}