1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2014 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.editor.view.dataimport;
|
11
|
|
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;
|
17
|
|
18
|
import org.apache.http.client.ClientProtocolException;
|
19
|
import org.eclipse.swt.widgets.Display;
|
20
|
|
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;
|
28
|
|
29
|
/**
|
30
|
* @author pplitzner
|
31
|
* @date 25.02.2014
|
32
|
*
|
33
|
*/
|
34
|
public class BioCaseEditorInput extends DataImportEditorInput<SpecimenOrObservationBase<?>> {
|
35
|
|
36
|
private final OccurenceQuery query;
|
37
|
|
38
|
/**
|
39
|
* @param results
|
40
|
*/
|
41
|
public BioCaseEditorInput(OccurenceQuery query) {
|
42
|
super();
|
43
|
this.query = query;
|
44
|
}
|
45
|
|
46
|
@Override
|
47
|
public void query(){
|
48
|
String errorMessage = "Could not execute query " + query;
|
49
|
|
50
|
Collection<SpecimenOrObservationBase<?>> results = new ArrayList<SpecimenOrObservationBase<?>>();
|
51
|
try {
|
52
|
InputStream resultStream;
|
53
|
resultStream = new BioCaseQueryServiceWrapper().query(query);
|
54
|
Abcd206ImportConfigurator configurator = Abcd206ImportConfigurator.NewInstance(resultStream, null, false);
|
55
|
TransientCdmRepository repo =
|
56
|
new TransientCdmRepository(CdmStore.getCurrentApplicationConfiguration());
|
57
|
configurator.setCdmAppController(repo);
|
58
|
|
59
|
CdmDefaultImport<Abcd206ImportConfigurator> importer = new CdmDefaultImport<Abcd206ImportConfigurator>();
|
60
|
importer.invoke(configurator);
|
61
|
results = repo.getUnits();
|
62
|
setResults(results);
|
63
|
} catch (ClientProtocolException e) {
|
64
|
logger.error(errorMessage, e);
|
65
|
} catch (IOException e) {
|
66
|
logger.error(errorMessage, e);
|
67
|
} catch (URISyntaxException e) {
|
68
|
logger.error(errorMessage, e);
|
69
|
}
|
70
|
|
71
|
setResults(results);
|
72
|
|
73
|
Display.getDefault().asyncExec(new Runnable() {
|
74
|
|
75
|
@Override
|
76
|
public void run() {
|
77
|
CdmStore.getContextManager().notifyContextRefresh();
|
78
|
}
|
79
|
});
|
80
|
}
|
81
|
|
82
|
/* (non-Javadoc)
|
83
|
* @see org.eclipse.ui.IEditorInput#getName()
|
84
|
*/
|
85
|
@Override
|
86
|
public String getName() {
|
87
|
return "[BioCASE] " + query.toString();
|
88
|
}
|
89
|
|
90
|
/* (non-Javadoc)
|
91
|
* @see org.eclipse.ui.IEditorInput#getToolTipText()
|
92
|
*/
|
93
|
@Override
|
94
|
public String getToolTipText() {
|
95
|
return "[BioCASE] " + query.toString();
|
96
|
}
|
97
|
|
98
|
/* (non-Javadoc)
|
99
|
* @see java.lang.Object#hashCode()
|
100
|
*/
|
101
|
@Override
|
102
|
public int hashCode() {
|
103
|
final int prime = 31;
|
104
|
int result = 1;
|
105
|
result = prime * result + ((query == null) ? 0 : query.hashCode());
|
106
|
return result;
|
107
|
}
|
108
|
|
109
|
/* (non-Javadoc)
|
110
|
* @see java.lang.Object#equals(java.lang.Object)
|
111
|
*/
|
112
|
@Override
|
113
|
public boolean equals(Object obj) {
|
114
|
if (this == obj) {
|
115
|
return true;
|
116
|
}
|
117
|
if (obj == null) {
|
118
|
return false;
|
119
|
}
|
120
|
if (getClass() != obj.getClass()) {
|
121
|
return false;
|
122
|
}
|
123
|
BioCaseEditorInput other = (BioCaseEditorInput) obj;
|
124
|
if (query == null) {
|
125
|
if (other.query != null) {
|
126
|
return false;
|
127
|
}
|
128
|
} else if (!query.equals(other.query)) {
|
129
|
return false;
|
130
|
}
|
131
|
return true;
|
132
|
}
|
133
|
}
|