1
|
/**
|
2
|
* Copyright (C) 2014 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.view.dataimport;
|
10
|
|
11
|
import java.io.IOException;
|
12
|
import java.io.InputStream;
|
13
|
import java.net.URI;
|
14
|
import java.util.ArrayList;
|
15
|
import java.util.Collection;
|
16
|
|
17
|
import org.apache.http.client.ClientProtocolException;
|
18
|
import org.eclipse.swt.widgets.Display;
|
19
|
|
20
|
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
|
21
|
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
|
22
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
23
|
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
|
24
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
25
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
26
|
|
27
|
/**
|
28
|
* @author pplitzner
|
29
|
* @date 25.02.2014
|
30
|
*
|
31
|
*/
|
32
|
public class BioCaseEditorInput extends DataImportEditorInput<SpecimenOrObservationBase<?>> {
|
33
|
|
34
|
private final URI endPoint;
|
35
|
|
36
|
/**
|
37
|
* Constructs a new BioCaseEditorInput.
|
38
|
* @param query The {@link OccurenceQuery} object holding all necessary parameters.
|
39
|
* @param endPoint If the endPoint {@link URI} is <code>null</code> then the default endPoint is used
|
40
|
* (<i>http://ww3.bgbm.org/biocase/pywrapper.cgi?dsa=Herbar</i>)
|
41
|
*/
|
42
|
public BioCaseEditorInput(OccurenceQuery query, URI endPoint) {
|
43
|
super();
|
44
|
this.query = query;
|
45
|
this.endPoint = endPoint;
|
46
|
}
|
47
|
|
48
|
@Override
|
49
|
public void query(){
|
50
|
String errorMessage = "Could not execute query " + query;
|
51
|
|
52
|
Collection<SpecimenOrObservationBase<?>> results = new ArrayList<SpecimenOrObservationBase<?>>();
|
53
|
try {
|
54
|
//FIXME move ABCD import to cdmlib -> this will also get rid of the transient services
|
55
|
InputStream resultStream;
|
56
|
resultStream = new BioCaseQueryServiceWrapper().query(query, endPoint);
|
57
|
Abcd206ImportConfigurator configurator = Abcd206ImportConfigurator.NewInstance(endPoint, null, false);
|
58
|
/* TransientCdmRepository repo =
|
59
|
new TransientCdmRepository(CdmStore.getCurrentApplicationConfiguration());
|
60
|
configurator.setCdmAppController(repo);
|
61
|
*/
|
62
|
CdmDefaultImport<Abcd206ImportConfigurator> importer = new CdmDefaultImport<Abcd206ImportConfigurator>();
|
63
|
importer.invoke(configurator);
|
64
|
// results = repo.getUnits();
|
65
|
setResults(results);
|
66
|
} catch (ClientProtocolException e) {
|
67
|
logger.error(errorMessage, e);
|
68
|
} catch (IOException e) {
|
69
|
logger.error(errorMessage, e);
|
70
|
}
|
71
|
|
72
|
setResults(results);
|
73
|
|
74
|
Display.getDefault().asyncExec(new Runnable() {
|
75
|
|
76
|
@Override
|
77
|
public void run() {
|
78
|
CdmStore.getContextManager().notifyContextRefresh();
|
79
|
}
|
80
|
});
|
81
|
}
|
82
|
|
83
|
/* (non-Javadoc)
|
84
|
* @see org.eclipse.ui.IEditorInput#getName()
|
85
|
*/
|
86
|
@Override
|
87
|
public String getName() {
|
88
|
return "[BioCASE] " + query.toString();
|
89
|
}
|
90
|
|
91
|
/* (non-Javadoc)
|
92
|
* @see org.eclipse.ui.IEditorInput#getToolTipText()
|
93
|
*/
|
94
|
@Override
|
95
|
public String getToolTipText() {
|
96
|
return "[BioCASE] " + query.toString();
|
97
|
}
|
98
|
|
99
|
/* (non-Javadoc)
|
100
|
* @see java.lang.Object#hashCode()
|
101
|
*/
|
102
|
@Override
|
103
|
public int hashCode() {
|
104
|
final int prime = 31;
|
105
|
int result = 1;
|
106
|
result = prime * result + ((query == null) ? 0 : query.hashCode());
|
107
|
return result;
|
108
|
}
|
109
|
|
110
|
/* (non-Javadoc)
|
111
|
* @see java.lang.Object#equals(java.lang.Object)
|
112
|
*/
|
113
|
@Override
|
114
|
public boolean equals(Object obj) {
|
115
|
if (this == obj) {
|
116
|
return true;
|
117
|
}
|
118
|
if (obj == null) {
|
119
|
return false;
|
120
|
}
|
121
|
if (getClass() != obj.getClass()) {
|
122
|
return false;
|
123
|
}
|
124
|
BioCaseEditorInput other = (BioCaseEditorInput) obj;
|
125
|
if (query == null) {
|
126
|
if (other.query != null) {
|
127
|
return false;
|
128
|
}
|
129
|
} else if (!query.equals(other.query)) {
|
130
|
return false;
|
131
|
}
|
132
|
return true;
|
133
|
}
|
134
|
}
|