// $Id$
/**
-* Copyright (C) 2014 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.
-*/
+ * Copyright (C) 2014 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.taxeditor.editor.view.dataimport;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
+import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
-import net.sf.json.JSONSerializer;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.ClientProtocolException;
import org.eclipse.swt.widgets.Display;
+import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
+import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifQueryServiceWrapper;
+import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
+import eu.etaxonomy.taxeditor.editor.view.dataimport.transientServices.TransientCdmRepository;
import eu.etaxonomy.taxeditor.store.CdmStore;
/**
Collection<SpecimenOrObservationBase<?>> results = new ArrayList<SpecimenOrObservationBase<?>>();
try {
- InputStream resultStream = new GbifQueryServiceWrapper().query(query);
- StringWriter stringWriter = new StringWriter();
- IOUtils.copy(resultStream, stringWriter);
- String jsonString = stringWriter.toString();
- JSONObject jsonObject = JSONObject.fromObject(jsonString);
- Object java = JSONSerializer.toJava(jsonObject);
- java.toString();
+ InputStream resultStream;
+ switch (queryType) {
+ case GBIF:
+ resultStream = new GbifQueryServiceWrapper().query(query);
+ StringWriter stringWriter = new StringWriter();
+ IOUtils.copy(resultStream, stringWriter);
+ String jsonString = stringWriter.toString();
+ JSONArray resultsArray = JSONObject.fromObject(jsonString).getJSONArray("results");
+ for(Object o:resultsArray){
+ //parse every record
+ if(o instanceof JSONObject){
+ DerivedUnitFacade derivedUnitFacade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
+ JSONObject record = (JSONObject)o;
+
+ if(record.has("locality")){
+ String locality = record.getString("locality");
+ derivedUnitFacade.setLocality(locality);
+ }
+ results.add(derivedUnitFacade.innerDerivedUnit());
+ }
+
+ }
+ break;
+ case BIOCASE:
+ resultStream = new BioCaseQueryServiceWrapper().query(SpecimenImportEditorInput.this.query);
+ Abcd206ImportConfigurator configurator = Abcd206ImportConfigurator.NewInstance(resultStream, null, false);
+ TransientCdmRepository repo =
+ new TransientCdmRepository(CdmStore.getCurrentApplicationConfiguration());
+ configurator.setCdmAppController(repo);
+
+ CdmDefaultImport<Abcd206ImportConfigurator> importer = new CdmDefaultImport<Abcd206ImportConfigurator>();
+ importer.invoke(configurator);
+ results = repo.getUnits();
+ setResults(results);
+ break;
+ }
} catch (ClientProtocolException e) {
logger.error(errorMessage, e);
} catch (IOException e) {
} catch (URISyntaxException e) {
logger.error(errorMessage, e);
}
+
setResults(results);
Display.getDefault().asyncExec(new Runnable() {
*/
@Override
public String getName() {
- return query.toString();
+ return queryType + " " + query.toString();
}
/* (non-Javadoc)
private static final Logger logger = Logger.getLogger(SpecimenSearchWizard.class);
private OccurenceQuery query = null;
- private SpecimenSearchWizardPage searchPage;
private SpecimenProviderSelectionWizardPage providerSelectionPage;
+ private SpecimenSearchWizardPage searchPage;
/**
* Creates a new SpecimenSearchWizard
*/
@Override
public void addPages() {
- addPage(searchPage);
addPage(providerSelectionPage);
+ addPage(searchPage);
}
/* (non-Javadoc)
*/
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
- searchPage = new SpecimenSearchWizardPage("Specimen Search");
providerSelectionPage = new SpecimenProviderSelectionWizardPage("Select specimen provider");
+ searchPage = new SpecimenSearchWizardPage("Specimen Search");
}
}
*/
package eu.etaxonomy.taxeditor.editor.view.dataimport;
+import java.util.Calendar;
+
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.widgets.Composite;
String collector = specimenSearchController.getCollector();
String collectorsNumber = specimenSearchController.getCollectorNumber();
String country = specimenSearchController.getCountry();
-// date = specimenSearchController.getDate();
+ Calendar dateFrom = specimenSearchController.getDateFrom();
+ Calendar dateTo = specimenSearchController.getDateTo();
String herbarium = specimenSearchController.getHerbarium();
String locality = specimenSearchController.getLocality();
String taxonName = specimenSearchController.getTaxonName();
- return new OccurenceQuery(taxonName, collector, collectorsNumber, accessionNumber, herbarium, country, locality, null);
+ return new OccurenceQuery(taxonName, collector, collectorsNumber, accessionNumber, herbarium, country, locality, dateFrom, dateTo);
}
}
private final ICdmApplicationConfiguration defaultApplicationConfiguration;
private TransientOccurenceService occurenceService;
- public Collection<SpecimenOrObservationBase> getUnits(){
+ public Collection<SpecimenOrObservationBase<?>> getUnits(){
return occurenceService.getUnits();
}
public class TransientOccurenceService implements IOccurrenceService {
private final IOccurrenceService defaultService;
- private final Collection<SpecimenOrObservationBase> units;
+ private final Collection<SpecimenOrObservationBase<?>> units;
/**
* @param defaultService
*/
public TransientOccurenceService(IOccurrenceService defaultService) {
this.defaultService = defaultService;
- this.units = new HashSet<SpecimenOrObservationBase>();
+ this.units = new HashSet<SpecimenOrObservationBase<?>>();
}
/**
/**
* @return
*/
- public Collection<SpecimenOrObservationBase> getUnits() {
+ public Collection<SpecimenOrObservationBase<?>> getUnits() {
return units;
}
*/
public SpecimenProviderSelectionController(Composite parent) {
composite = new SpecimenProviderSelectionComposite(parent, SWT.NONE);
- composite.addListener(SWT.SELECTED, this);
+ composite.getBtnBioCaseProvider().addListener(SWT.Selection, this);
+ composite.getBtnGbif().addListener(SWT.Selection, this);
+ composite.getBtnGbif().setSelection(true);
composite.getTxtAccessPoint().setEnabled(false);
composite.getLblAccessPointUrl().setEnabled(false);
}
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
private final Text textLocality;
private final Text textHerbarium;
private final Text textCountry;
+ private final DateTime dateFrom;
+ private final DateTime dateTo;
/**
* Create the composite.
lblCollectionDate.setText("Collection Date");
new Label(this, SWT.NONE);
+ Label lblFrom = new Label(this, SWT.NONE);
+ lblFrom.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.TOP, 1, 1));
+ lblFrom.setText("from");
+
+ dateFrom = new DateTime(this, SWT.NONE);
+ dateFrom.setLayoutData(new TableWrapData(TableWrapData.FILL, TableWrapData.TOP, 1, 1));
+ formToolkit.adapt(dateFrom);
+ formToolkit.paintBordersFor(dateFrom);
+
+ Label lblTo = new Label(this, SWT.NONE);
+ lblTo.setLayoutData(new TableWrapData(TableWrapData.RIGHT, TableWrapData.TOP, 1, 1));
+ lblTo.setText("to");
+
+ dateTo = new DateTime(this, SWT.DROP_DOWN);
+ dateTo.setLayoutData(new TableWrapData(TableWrapData.FILL, TableWrapData.TOP, 1, 1));
+ formToolkit.adapt(dateTo);
+ formToolkit.paintBordersFor(dateTo);
+
}
@Override
public Text getTextLocality() {
return textLocality;
}
+ public DateTime getDateFrom() {
+ return dateFrom;
+ }
+ public DateTime getDateTo() {
+ return dateTo;
+ }
}
*/
package eu.etaxonomy.taxeditor.view.specimenSearch;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
return specimenSearchComposite.getTextLocality().getText();
}
+ /**
+ * Returns the start date entered in the search view.
+ * @return the date as an instance of {@link Calendar}
+ * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getDateFrom()
+ */
+ public Calendar getDateFrom() {
+ Calendar dateFrom = new GregorianCalendar();
+ dateFrom.clear();
+ dateFrom.set(specimenSearchComposite.getDateFrom().getYear(), specimenSearchComposite.getDateFrom().getMonth(), specimenSearchComposite.getDateFrom().getDay());
+ return dateFrom;
+ }
+
+ /**
+ * Returns the end date entered in the search view.
+ * @return the date as an instance of {@link Calendar}
+ * @see eu.etaxonomy.taxeditor.view.specimenSearch.SpecimenSearchComposite#getDateTo()
+ */
+ public Calendar getDateTo() {
+ Calendar dateTo = new GregorianCalendar();
+ dateTo.clear();
+ dateTo.set(specimenSearchComposite.getDateTo().getYear(), specimenSearchComposite.getDateTo().getMonth(), specimenSearchComposite.getDateTo().getDay());
+ return dateTo;
+ }
+
}
\ No newline at end of file