3 * Copyright (C) 2014 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.dataimport
;
12 import java
.io
.IOException
;
13 import java
.io
.InputStream
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Collection
;
18 import org
.apache
.http
.client
.ClientProtocolException
;
19 import org
.eclipse
.swt
.widgets
.Display
;
21 import eu
.etaxonomy
.cdm
.ext
.occurrence
.OccurenceQuery
;
22 import eu
.etaxonomy
.cdm
.ext
.occurrence
.bioCase
.BioCaseQueryServiceWrapper
;
23 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultImport
;
24 import eu
.etaxonomy
.cdm
.io
.specimen
.abcd206
.in
.Abcd206ImportConfigurator
;
25 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
26 import eu
.etaxonomy
.taxeditor
.editor
.view
.dataimport
.transientServices
.TransientCdmRepository
;
27 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
34 public class BioCaseEditorInput
extends DataImportEditorInput
<SpecimenOrObservationBase
<?
>> {
36 private final URI endPoint
;
39 * Constructs a new BioCaseEditorInput.
40 * @param query The {@link OccurenceQuery} object holding all necessary parameters.
41 * @param endPoint If the endPoint {@link URI} is <code>null</code> then the default endPoint is used
42 * (<i>http://ww3.bgbm.org/biocase/pywrapper.cgi?dsa=Herbar</i>)
44 public BioCaseEditorInput(OccurenceQuery query
, URI endPoint
) {
47 this.endPoint
= endPoint
;
52 String errorMessage
= "Could not execute query " + query
;
54 Collection
<SpecimenOrObservationBase
<?
>> results
= new ArrayList
<SpecimenOrObservationBase
<?
>>();
56 //FIXME move ABCD import to cdmlib -> this will also get rid of the transient services
57 InputStream resultStream
;
58 resultStream
= new BioCaseQueryServiceWrapper().query(query
, endPoint
);
59 Abcd206ImportConfigurator configurator
= Abcd206ImportConfigurator
.NewInstance(resultStream
, null, false);
60 TransientCdmRepository repo
=
61 new TransientCdmRepository(CdmStore
.getCurrentApplicationConfiguration());
62 configurator
.setCdmAppController(repo
);
64 CdmDefaultImport
<Abcd206ImportConfigurator
> importer
= new CdmDefaultImport
<Abcd206ImportConfigurator
>();
65 importer
.invoke(configurator
);
66 results
= repo
.getUnits();
68 } catch (ClientProtocolException e
) {
69 logger
.error(errorMessage
, e
);
70 } catch (IOException e
) {
71 logger
.error(errorMessage
, e
);
76 Display
.getDefault().asyncExec(new Runnable() {
80 CdmStore
.getContextManager().notifyContextRefresh();
86 * @see org.eclipse.ui.IEditorInput#getName()
89 public String
getName() {
90 return "[BioCASE] " + query
.toString();
94 * @see org.eclipse.ui.IEditorInput#getToolTipText()
97 public String
getToolTipText() {
98 return "[BioCASE] " + query
.toString();
102 * @see java.lang.Object#hashCode()
105 public int hashCode() {
106 final int prime
= 31;
108 result
= prime
* result
+ ((query
== null) ?
0 : query
.hashCode());
113 * @see java.lang.Object#equals(java.lang.Object)
116 public boolean equals(Object obj
) {
123 if (getClass() != obj
.getClass()) {
126 BioCaseEditorInput other
= (BioCaseEditorInput
) obj
;
128 if (other
.query
!= null) {
131 } else if (!query
.equals(other
.query
)) {