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
;
14 import java
.net
.URISyntaxException
;
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
.api
.facade
.DerivedUnitFacade
;
22 import eu
.etaxonomy
.cdm
.ext
.occurrence
.OccurenceQuery
;
23 import eu
.etaxonomy
.cdm
.ext
.occurrence
.bioCase
.BioCaseQueryServiceWrapper
;
24 import eu
.etaxonomy
.cdm
.ext
.occurrence
.gbif
.GbifQueryServiceWrapper
;
25 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultImport
;
26 import eu
.etaxonomy
.cdm
.io
.specimen
.abcd206
.in
.Abcd206ImportConfigurator
;
27 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
28 import eu
.etaxonomy
.taxeditor
.editor
.view
.dataimport
.transientServices
.TransientCdmRepository
;
29 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
36 public class SpecimenImportEditorInput
extends DataImportEditorInput
<SpecimenOrObservationBase
<?
>> {
38 private final OccurenceQuery query
;
39 private final QueryType queryType
;
44 public SpecimenImportEditorInput(OccurenceQuery query
, QueryType queryType
) {
47 this.queryType
= queryType
;
51 String errorMessage
= "Could not execute query " + query
;
53 Collection
<SpecimenOrObservationBase
<?
>> results
= new ArrayList
<SpecimenOrObservationBase
<?
>>();
55 InputStream resultStream
;
58 Collection
<DerivedUnitFacade
> facades
= new GbifQueryServiceWrapper().query(query
);
59 for(DerivedUnitFacade facade
:facades
){
60 results
.add(facade
.innerDerivedUnit());
64 resultStream
= new BioCaseQueryServiceWrapper().query(query
);
65 Abcd206ImportConfigurator configurator
= Abcd206ImportConfigurator
.NewInstance(resultStream
, null, false);
66 TransientCdmRepository repo
=
67 new TransientCdmRepository(CdmStore
.getCurrentApplicationConfiguration());
68 configurator
.setCdmAppController(repo
);
70 CdmDefaultImport
<Abcd206ImportConfigurator
> importer
= new CdmDefaultImport
<Abcd206ImportConfigurator
>();
71 importer
.invoke(configurator
);
72 results
= repo
.getUnits();
76 } catch (ClientProtocolException e
) {
77 logger
.error(errorMessage
, e
);
78 } catch (IOException e
) {
79 logger
.error(errorMessage
, e
);
80 } catch (URISyntaxException e
) {
81 logger
.error(errorMessage
, e
);
86 Display
.getDefault().asyncExec(new Runnable() {
90 CdmStore
.getContextManager().notifyContextRefresh();
96 * @see org.eclipse.ui.IEditorInput#getName()
99 public String
getName() {
100 return queryType
+ " " + query
.toString();
104 * @see org.eclipse.ui.IEditorInput#getToolTipText()
107 public String
getToolTipText() {
108 return query
.toString();
112 * @see java.lang.Object#hashCode()
115 public int hashCode() {
116 final int prime
= 31;
118 result
= prime
* result
+ ((query
== null) ?
0 : query
.hashCode());
123 * @see java.lang.Object#equals(java.lang.Object)
126 public boolean equals(Object obj
) {
133 if (getClass() != obj
.getClass()) {
136 SpecimenImportEditorInput other
= (SpecimenImportEditorInput
) obj
;
138 if (other
.query
!= null) {
141 } else if (!query
.equals(other
.query
)) {