commit f12ac52e65806241131087baceac564b3f31d14f
Author: Katja Luther <k.luther@bgbm.org>
Date:   Mon Feb 6 09:47:45 2017 +0100

    some changes for specimen import

diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExcelNormalExplicitTaxaImportWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExcelNormalExplicitTaxaImportWizard.java
index cb463a512..d790546b3 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExcelNormalExplicitTaxaImportWizard.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExcelNormalExplicitTaxaImportWizard.java
@@ -13,8 +13,8 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.net.URI;
-import org.apache.log4j.Logger;
 
+import org.apache.log4j.Logger;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.TreeSelection;
@@ -24,7 +24,6 @@ import eu.etaxonomy.cdm.database.DbSchemaValidation;
 import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
 import eu.etaxonomy.cdm.io.excel.taxa.NormalExplicitImportConfigurator;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
-
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 
@@ -68,10 +67,10 @@ public class ExcelNormalExplicitTaxaImportWizard extends AbstractImportWizard<No
 		} catch (FileNotFoundException e) {
 			logger.error("Error while reading file" + source.toString());
 		}
-			
-	    Job job = CdmStore.getImportManager().createIOServiceJob(configurator,file , SOURCE_TYPE.INPUTSTREAM);
+
+	    Job job = CdmStore.getImportManager().createIOServiceJob(configurator,fis , SOURCE_TYPE.INPUTSTREAM);
 	    CdmStore.getImportManager().run(job);
-		
+
 		return true;
 	}
 
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SaveImportedSpecimenAction.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SaveImportedSpecimenAction.java
index 7e01d6b00..c17652394 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SaveImportedSpecimenAction.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SaveImportedSpecimenAction.java
@@ -9,14 +9,11 @@ import java.util.Comparator;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
-import java.util.UUID;
 
 import org.apache.http.client.ClientProtocolException;
 import org.apache.log4j.Logger;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jface.action.Action;
-import org.eclipse.jface.text.source.Annotation;
-import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableItem;
 import org.eclipse.ui.IWorkbenchPart;
@@ -24,8 +21,6 @@ import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PlatformUI;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
-import eu.etaxonomy.cdm.api.service.IClassificationService;
-import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.api.service.ITermService;
 import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
 import eu.etaxonomy.cdm.ext.occurrence.gbif.DataSetResponse;
@@ -33,19 +28,14 @@ import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifDataSetProtocol;
 import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifQueryServiceWrapper;
 import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
 import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
-import eu.etaxonomy.cdm.io.specimen.gbif.in.*;
+import eu.etaxonomy.cdm.io.specimen.gbif.in.GbifImportConfigurator;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
-import eu.etaxonomy.cdm.model.common.ICdmBase;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
-import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
 
 public class SaveImportedSpecimenAction extends Action {
 
     private final Logger logger = Logger.getLogger(SaveImportedSpecimenAction.class);
-    
+
     private Comparator<GbifResponse> comparator;
 
     /* (non-Javadoc)
@@ -63,7 +53,7 @@ public class SaveImportedSpecimenAction extends Action {
             Set<String[]> unitIdsGbif = new HashSet<String[]>();
             Set<String[]> unitIdsBioCase = new HashSet<String[]>();
             List<GbifResponse> biocaseResponses = new ArrayList<GbifResponse>();
-            
+
             for(TableItem item:table.getItems()){
                 if(item.getChecked()){
                     //Save Specimen
@@ -77,21 +67,21 @@ public class SaveImportedSpecimenAction extends Action {
                 for (GbifResponse response:checkedResults){
                 	if (response != null){
                 		tripleId = response.getTripleID();
-                		
+
                 		if (response.getDataSetProtocol().equals(GbifDataSetProtocol.BIOCASE)){
                 			biocaseResponses.add(response);
-                			
+
                 		}else{
                 			unitIdsGbif.add(tripleId);
                 		}
-                		
-	                		
+
+
                 	}
                 }
-                Collections.sort(biocaseResponses, getComparator()); 
+                Collections.sort(biocaseResponses, getComparator());
                 URI dataSetUri = null;
                 Abcd206ImportConfigurator configuratorAbcd;
-                
+
                 List<Abcd206ImportConfigurator> abcdConfigurators = new ArrayList<Abcd206ImportConfigurator>();
                 DataSetResponse dataSetResponse;
                 OccurenceQuery bioCaseOccurrenceQuery = null;
@@ -109,6 +99,8 @@ public class SaveImportedSpecimenAction extends Action {
                 	if (!response.getDataSetUri().equals(dataSetUri)){
                 		configuratorAbcd = Abcd206ImportConfigurator.NewInstance(dataSetUri, null, false);
                 		configuratorAbcd.addMediaAsMediaSpecimen(true);
+                		configuratorAbcd.setIgnoreAuthorship(true);
+                		configuratorAbcd.setMoveNewTaxaToDefaultClassification(false);
                 		if (configuratorAbcd != null){
                 			abcdConfigurators.add(configuratorAbcd);
                 		}
@@ -118,32 +110,32 @@ public class SaveImportedSpecimenAction extends Action {
                 		if (dataImportView.getClassification() != null){
                 			configuratorAbcd.setClassificationUuid(dataImportView.getClassification().getUuid());
                 		}
-                		
+
                 	}
                 	tripleId = response.getTripleID();
                 	unitIdsBioCase.add(tripleId);
                 }
-              
+
                 OccurenceQuery query = new OccurenceQuery(unitIdsGbif);
                 GbifImportConfigurator configurator = GbifImportConfigurator.newInstance(query);
                 configurator.setSourceReferenceTitle("Import Gbif data");
-                
-               
-                
+
+
+
                 //  configurator.setQuery(query);
-               
+
                Job bioCaseJob = CdmStore.getImportManager().createIOServiceJob(abcdConfigurators);
                CdmStore.getImportManager().run(bioCaseJob);
-               
+
                Job gbifJob = CdmStore.getImportManager().createIOServiceJob(configurator);
                CdmStore.getImportManager().run(gbifJob);
-               
-               
-                
+
+
+
             }
         }
- 
-    
+
+
     private void persistTerm(DefinedTermBase<?> term, ITermService termService, ConversationHolder conversation){
         if(term!=null){
             //if the term does not exist in the DB save it
@@ -152,7 +144,7 @@ public class SaveImportedSpecimenAction extends Action {
             }
         }
     }
-     
+
     /* (non-Javadoc)
      * @see org.eclipse.jface.action.Action#getText()
      */
@@ -160,13 +152,13 @@ public class SaveImportedSpecimenAction extends Action {
     public String getText() {
         return "Import";
     }
-    
+
     private Comparator<GbifResponse> getComparator(){
     	if (comparator == null){
     		comparator = new GbifResponseComparator();
     	}
     	return comparator;
     }
-    
-    
+
+
 }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SpecimenImportView.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SpecimenImportView.java
index dfdb2d294..d5de5208c 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SpecimenImportView.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SpecimenImportView.java
@@ -15,21 +15,24 @@ import java.util.ArrayList;
 import java.util.Collection;
 
 import org.apache.http.client.ClientProtocolException;
-import org.eclipse.core.runtime.jobs.Job;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 
 import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
-import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
-import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206DataHolder;
 import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
-import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportParser;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportState;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206XMLFieldGetter;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdParseUtility;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.UnitAssociationWrapper;
 
 /**
  * @author pplitzner
  * @date Sep 3, 2014
  *
  */
-public class SpecimenImportView extends DataImportView<SpecimenOrObservationBase<?>> {
+public class SpecimenImportView extends DataImportView<Abcd206DataHolder> {
 
     public static final String ID = "eu.etaxonomy.taxeditor.view.dataimport.SpecimenImportView"; //$NON-NLS-1$
 
@@ -49,8 +52,9 @@ public class SpecimenImportView extends DataImportView<SpecimenOrObservationBase
      * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportView#getTextForTableItem(java.lang.Object)
      */
     @Override
-    protected String getTextForTableItem(SpecimenOrObservationBase<?> item) {
-        return item.getTitleCache();
+    protected String getTextForTableItem(Abcd206DataHolder item) {
+        //TODO: define a suitable toString method
+        return item.toString();
     }
 
     /* (non-Javadoc)
@@ -60,21 +64,38 @@ public class SpecimenImportView extends DataImportView<SpecimenOrObservationBase
     public void query() {
         String errorMessage = "Could not execute query " + query;
 
-        Collection<SpecimenOrObservationBase<?>> results = new ArrayList<SpecimenOrObservationBase<?>>();
+        Collection<Abcd206DataHolder> results = new ArrayList<Abcd206DataHolder>();
         try {
             //FIXME move ABCD import to cdmlib -> this will also get rid of the transient services
             InputStream resultStream;
             resultStream = new BioCaseQueryServiceWrapper().query(query, endPoint);
             Abcd206ImportConfigurator configurator = Abcd206ImportConfigurator.NewInstance(null, null);
-//            TransientCdmRepository repo =
+            configurator.setSourceUri(endPoint);
+
+            //            TransientCdmRepository repo =
 //                    new TransientCdmRepository(CdmStore.getCurrentApplicationConfiguration());
             //configurator.setCdmAppController(repo);
+
+            //TODO: do not query all data but with the selected triple IDs -> see GbifResponseImportView
             configurator.setAddMediaAsMediaSpecimen(true);
             configurator.setAllowReuseOtherClassifications(true);
-            
-            Job job = CdmStore.getImportManager().createIOServiceJob(configurator, resultStream, SOURCE_TYPE.INPUTSTREAM);
-            CdmStore.getImportManager().run(job);
-            
+            configurator.setMoveNewTaxaToDefaultClassification(false);
+            UnitAssociationWrapper unitAssociationWrapper = AbcdParseUtility.parseUnitsNodeList(resultStream, null);
+            NodeList unitsList = unitAssociationWrapper.getAssociatedUnits();
+            Abcd206DataHolder dataHolder = new Abcd206DataHolder();
+            Abcd206XMLFieldGetter abcdFieldGetter = new Abcd206XMLFieldGetter(dataHolder, unitAssociationWrapper.getPrefix());
+            Abcd206ImportState state = new Abcd206ImportState(configurator);
+            state.setDataHolder(dataHolder);
+            for (int i = 0; i <unitsList.getLength(); i++){
+                Element item = (Element) unitsList.item(i);
+                //dataHolder = new Abcd206DataHolder();
+                Abcd206ImportParser.setUnitPropertiesXML(item, abcdFieldGetter, state);
+                results.add(dataHolder);
+            }
+
+//            Job job = CdmStore.getImportManager().createIOServiceJob(configurator, resultStream, SOURCE_TYPE.INPUTSTREAM);
+//            CdmStore.getImportManager().run(job);
+
             setResults(results);
         } catch (ClientProtocolException e) {
             logger.error(errorMessage, e);
@@ -82,7 +103,7 @@ public class SpecimenImportView extends DataImportView<SpecimenOrObservationBase
             logger.error(errorMessage, e);
         }
 
-        setResults(results);
+       // setResults(results);
 
     }
 
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SpecimenSearchWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SpecimenSearchWizard.java
index 7a30e21f8..1d559c11c 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SpecimenSearchWizard.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SpecimenSearchWizard.java
@@ -33,7 +33,6 @@ import eu.etaxonomy.cdm.ext.common.ServiceWrapperBase;
 import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
 import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
 import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
-
 import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdParseUtility;
 import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;
 import eu.etaxonomy.cdm.io.specimen.abcd206.in.UnitAssociationWrapper;
@@ -80,7 +79,9 @@ public class SpecimenSearchWizard extends Wizard implements IImportWizard {
         configurator.setAddMediaAsMediaSpecimen(true);
         configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
         configurator.setIgnoreAuthorship(true);
-      
+        configurator.setMoveNewTaxaToDefaultClassification(false);
+
+
         //Job job = CdmStore.getImportManager().createIOServiceJob(configurator, new File(source), SOURCE_TYPE.INPUTSTREAM);
         //CdmStore.getImportManager().run(job);
         try {
@@ -96,9 +97,12 @@ public class SpecimenSearchWizard extends Wizard implements IImportWizard {
                 NodeList nodeList = unitNodesList.getAssociatedUnits();
                 String prefix = unitNodesList.getPrefix();
                 String associationType = unitNodesList.getAssociationType();
-                URI uri =AbcdParseUtility.parseFirstUri(nodeList, report);
-                String content = AbcdParseUtility.parseFirstTextContent(nodeList);
-                System.out.println(content);
+                if (nodeList != null){
+                    URI uri =AbcdParseUtility.parseFirstUri(nodeList, report);
+                    String content = AbcdParseUtility.parseFirstTextContent(nodeList);
+                    System.out.println(content);
+                }
+
 
 
                 SpecimenImportView specimenImportView = new SpecimenImportView();
@@ -115,9 +119,9 @@ public class SpecimenSearchWizard extends Wizard implements IImportWizard {
 
             } else{
                 try {
-                	
+
                     dataImportView = (GbifResponseImportView) activePart.showView(GbifResponseImportView.ID, "query_"+query.toString().replaceAll(",", ""), IWorkbenchPage.VIEW_ACTIVATE);
-                    dataImportView.setQuery(query);		
+                    dataImportView.setQuery(query);
                     	//	(GbifResponseImportView) activePart.showView(GbifResponseImportView.ID);getWorkbench().getActiveWorkbenchWindow().getActivePage()
                          // .showView(GbifResponseImportView.ID, "query_"+query.toString().replaceAll(",", ""),IWorkbenchPage.VIEW_ACTIVATE);
 
@@ -134,7 +138,7 @@ public class SpecimenSearchWizard extends Wizard implements IImportWizard {
             e.printStackTrace();
         }
        // CdmStore.getImportManager().run(configurator);
-    
+
 //        try {
 //            switch (providerSelectionPage.getQueryType()) {
 //            case BIOCASE:
@@ -162,7 +166,7 @@ public class SpecimenSearchWizard extends Wizard implements IImportWizard {
 ////                }
 ////            });
             Job queryJob = new QueryJob("Query specimen provider", dataImportView);
-            queryJob.schedule();
+           queryJob.schedule();
 
         return true;
     }
