1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2013 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.dataimport;
|
11
|
|
12
|
import java.io.IOException;
|
13
|
import java.io.InputStream;
|
14
|
import java.net.URISyntaxException;
|
15
|
import java.util.List;
|
16
|
|
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;
|
22
|
|
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.store.CdmStore;
|
29
|
|
30
|
/**
|
31
|
* @author pplitzner
|
32
|
* @date 20.09.2013
|
33
|
*
|
34
|
*/
|
35
|
public class DataImportSpecimenEditorInput implements IEditorInput {
|
36
|
|
37
|
private static Logger logger = Logger.getLogger(DataImportSpecimenEditorInput.class);
|
38
|
|
39
|
private BioCaseQuery query;
|
40
|
|
41
|
/**
|
42
|
* @param results
|
43
|
*/
|
44
|
public DataImportSpecimenEditorInput(BioCaseQuery query) {
|
45
|
this.query = query;
|
46
|
this.query.taxonName = "Campanula*";
|
47
|
}
|
48
|
|
49
|
/* (non-Javadoc)
|
50
|
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
|
51
|
*/
|
52
|
@Override
|
53
|
public Object getAdapter(Class adapter) {
|
54
|
// TODO Auto-generated method stub
|
55
|
return null;
|
56
|
}
|
57
|
|
58
|
/* (non-Javadoc)
|
59
|
* @see org.eclipse.ui.IEditorInput#exists()
|
60
|
*/
|
61
|
@Override
|
62
|
public boolean exists() {
|
63
|
return false;
|
64
|
}
|
65
|
|
66
|
/* (non-Javadoc)
|
67
|
* @see org.eclipse.ui.IEditorInput#getImageDescriptor()
|
68
|
*/
|
69
|
@Override
|
70
|
public ImageDescriptor getImageDescriptor() {
|
71
|
// TODO Auto-generated method stub
|
72
|
return null;
|
73
|
}
|
74
|
|
75
|
/* (non-Javadoc)
|
76
|
* @see org.eclipse.ui.IEditorInput#getName()
|
77
|
*/
|
78
|
@Override
|
79
|
public String getName() {
|
80
|
return query.toString();
|
81
|
}
|
82
|
|
83
|
/* (non-Javadoc)
|
84
|
* @see org.eclipse.ui.IEditorInput#getPersistable()
|
85
|
*/
|
86
|
@Override
|
87
|
public IPersistableElement getPersistable() {
|
88
|
return null;
|
89
|
}
|
90
|
|
91
|
/* (non-Javadoc)
|
92
|
* @see org.eclipse.ui.IEditorInput#getToolTipText()
|
93
|
*/
|
94
|
@Override
|
95
|
public String getToolTipText() {
|
96
|
return query.toString();
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* @return the results
|
101
|
*/
|
102
|
public List<SpecimenOrObservationBase> getResults() {
|
103
|
List<SpecimenOrObservationBase> results = null;
|
104
|
String errorMessage = "Could not execute query " + query;
|
105
|
try {
|
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);
|
110
|
|
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);
|
124
|
}
|
125
|
// return new BioCaseQueryServiceWrapper().dummyData();
|
126
|
return results;
|
127
|
}
|
128
|
|
129
|
/* (non-Javadoc)
|
130
|
* @see java.lang.Object#hashCode()
|
131
|
*/
|
132
|
@Override
|
133
|
public int hashCode() {
|
134
|
final int prime = 31;
|
135
|
int result = 1;
|
136
|
result = prime * result + ((query == null) ? 0 : query.hashCode());
|
137
|
return result;
|
138
|
}
|
139
|
|
140
|
/* (non-Javadoc)
|
141
|
* @see java.lang.Object#equals(java.lang.Object)
|
142
|
*/
|
143
|
@Override
|
144
|
public boolean equals(Object obj) {
|
145
|
if (this == obj) {
|
146
|
return true;
|
147
|
}
|
148
|
if (obj == null) {
|
149
|
return false;
|
150
|
}
|
151
|
if (getClass() != obj.getClass()) {
|
152
|
return false;
|
153
|
}
|
154
|
DataImportSpecimenEditorInput other = (DataImportSpecimenEditorInput) obj;
|
155
|
if (query == null) {
|
156
|
if (other.query != null) {
|
157
|
return false;
|
158
|
}
|
159
|
} else if (!query.equals(other.query)) {
|
160
|
return false;
|
161
|
}
|
162
|
return true;
|
163
|
}
|
164
|
|
165
|
}
|