3 * Copyright (C) 2013 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
.dataimport
;
12 import java
.io
.IOException
;
13 import java
.io
.InputStream
;
14 import java
.net
.URISyntaxException
;
15 import java
.util
.List
;
17 import org
.apache
.http
.client
.ClientProtocolException
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
20 import org
.eclipse
.ui
.IEditorInput
;
21 import org
.eclipse
.ui
.IPersistableElement
;
23 import eu
.etaxonomy
.cdm
.ext
.biocase
.BioCaseQuery
;
24 import eu
.etaxonomy
.cdm
.ext
.biocase
.BioCaseQueryServiceWrapper
;
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
.dataimport
.transientServices
.TransientCdmRepository
;
29 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
36 public class DataImportSpecimenEditorInput
implements IEditorInput
{
38 private static Logger logger
= Logger
.getLogger(DataImportSpecimenEditorInput
.class);
40 private BioCaseQuery query
;
45 public DataImportSpecimenEditorInput(BioCaseQuery query
) {
50 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
53 public Object
getAdapter(Class adapter
) {
54 // TODO Auto-generated method stub
59 * @see org.eclipse.ui.IEditorInput#exists()
62 public boolean exists() {
67 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
70 public ImageDescriptor
getImageDescriptor() {
71 // TODO Auto-generated method stub
76 * @see org.eclipse.ui.IEditorInput#getName()
79 public String
getName() {
80 return query
.toString();
84 * @see org.eclipse.ui.IEditorInput#getPersistable()
87 public IPersistableElement
getPersistable() {
92 * @see org.eclipse.ui.IEditorInput#getToolTipText()
95 public String
getToolTipText() {
96 return query
.toString();
100 * @return the results
102 public List
<SpecimenOrObservationBase
> getResults() {
103 List
<SpecimenOrObservationBase
> results
= null;
104 String errorMessage
= "Could not execute query " + query
;
106 InputStream resultStream
= new BioCaseQueryServiceWrapper().query(query
);
107 Abcd206ImportConfigurator configurator
= Abcd206ImportConfigurator
.NewInstance(resultStream
, null, false);
108 TransientCdmRepository repo
= new TransientCdmRepository(CdmStore
.getCurrentApplicationConfiguration());
109 configurator
.setCdmAppController(repo
);
111 CdmDefaultImport
<Abcd206ImportConfigurator
> importer
= new CdmDefaultImport
<Abcd206ImportConfigurator
>();
112 importer
.invoke(configurator
);
113 results
= repo
.getUnits();
114 // Abcd206Import abcd206Import = new Abcd206Import();
115 // Abcd206ImportState state = new Abcd206ImportState(configurator);
116 // abcd206Import.invoke(state);
117 // state.countTrees();
118 } catch (ClientProtocolException e
) {
119 logger
.error(errorMessage
, e
);
120 } catch (IOException e
) {
121 logger
.error(errorMessage
, e
);
122 } catch (URISyntaxException e
) {
123 logger
.error(errorMessage
, e
);
125 // return new BioCaseQueryServiceWrapper().dummyData();
130 * @see java.lang.Object#hashCode()
133 public int hashCode() {
134 final int prime
= 31;
136 result
= prime
* result
+ ((query
== null) ?
0 : query
.hashCode());
141 * @see java.lang.Object#equals(java.lang.Object)
144 public boolean equals(Object obj
) {
151 if (getClass() != obj
.getClass()) {
154 DataImportSpecimenEditorInput other
= (DataImportSpecimenEditorInput
) obj
;
156 if (other
.query
!= null) {
159 } else if (!query
.equals(other
.query
)) {