1
|
/**
|
2
|
* Copyright (C) 2013 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
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.eclipse.core.runtime.IProgressMonitor;
|
17
|
import org.eclipse.core.runtime.IStatus;
|
18
|
import org.eclipse.core.runtime.Status;
|
19
|
import org.eclipse.core.runtime.jobs.Job;
|
20
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
21
|
import org.eclipse.jface.wizard.Wizard;
|
22
|
import org.eclipse.swt.widgets.Display;
|
23
|
import org.eclipse.ui.IImportWizard;
|
24
|
import org.eclipse.ui.IWorkbench;
|
25
|
import org.eclipse.ui.IWorkbenchPage;
|
26
|
import org.eclipse.ui.IWorkbenchWindow;
|
27
|
import org.eclipse.ui.PartInitException;
|
28
|
import org.eclipse.ui.PlatformUI;
|
29
|
import org.w3c.dom.NodeList;
|
30
|
|
31
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
32
|
import eu.etaxonomy.cdm.ext.common.ServiceWrapperBase;
|
33
|
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
|
34
|
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
|
35
|
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
|
36
|
import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdParseUtility;
|
37
|
import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;
|
38
|
import eu.etaxonomy.cdm.io.specimen.abcd206.in.UnitAssociationWrapper;
|
39
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
40
|
|
41
|
/**
|
42
|
* Wizard for querying specimen provider.
|
43
|
* @author pplitzner
|
44
|
* @date 11.09.2013
|
45
|
*
|
46
|
*/
|
47
|
public class SpecimenSearchWizard extends Wizard implements IImportWizard {
|
48
|
private static final Logger logger = Logger.getLogger(SpecimenSearchWizard.class);
|
49
|
|
50
|
private OccurenceQuery query = null;
|
51
|
private SpecimenProviderSelectionWizardPage providerSelectionPage;
|
52
|
private SpecimenSearchWizardPage searchPage;
|
53
|
|
54
|
/**
|
55
|
* Creates a new SpecimenSearchWizard
|
56
|
*/
|
57
|
public SpecimenSearchWizard() {
|
58
|
//default constructor needed for RCP extension points
|
59
|
|
60
|
//check if connected to a data source. If not this will open an error dialog
|
61
|
CdmStore.getCurrentApplicationConfiguration();
|
62
|
this.setWindowTitle("Search Specimens");
|
63
|
}
|
64
|
|
65
|
|
66
|
/* (non-Javadoc)
|
67
|
* @see org.eclipse.jface.wizard.Wizard#performFinish()
|
68
|
*/
|
69
|
@Override
|
70
|
public boolean performFinish() {
|
71
|
searchPage.getController().saveLastSate();
|
72
|
providerSelectionPage.getController().saveLastState();
|
73
|
ServiceWrapperBase serviceWrapper;
|
74
|
DataImportView<?> dataImportView = null;
|
75
|
query = searchPage.getQuery();
|
76
|
Abcd206ImportConfigurator configurator = CdmStore.getImportManager().AbcdConfigurator();
|
77
|
configurator.setOccurenceQuery(query);
|
78
|
configurator.setSourceUri(providerSelectionPage.getEndPoint());
|
79
|
configurator.setAddMediaAsMediaSpecimen(true);
|
80
|
configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
|
81
|
configurator.setIgnoreAuthorship(true);
|
82
|
configurator.setMoveNewTaxaToDefaultClassification(false);
|
83
|
|
84
|
|
85
|
//Job job = CdmStore.getImportManager().createIOServiceJob(configurator, new File(source), SOURCE_TYPE.INPUTSTREAM);
|
86
|
//CdmStore.getImportManager().run(job);
|
87
|
try {
|
88
|
serviceWrapper = providerSelectionPage.getQueryServiceWrapper();
|
89
|
InputStream stream = null;
|
90
|
|
91
|
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
92
|
IWorkbenchPage activePart = window.getActivePage();
|
93
|
if (providerSelectionPage.getQueryType().equals(QueryType.BIOCASE)){
|
94
|
stream =((BioCaseQueryServiceWrapper) serviceWrapper).query(query, configurator.getSourceUri());
|
95
|
SpecimenImportReport report = new SpecimenImportReport();
|
96
|
UnitAssociationWrapper unitNodesList = AbcdParseUtility.parseUnitsNodeList(stream, report);
|
97
|
NodeList nodeList = unitNodesList.getAssociatedUnits();
|
98
|
String prefix = unitNodesList.getPrefix();
|
99
|
String associationType = unitNodesList.getAssociationType();
|
100
|
if (nodeList != null){
|
101
|
URI uri =AbcdParseUtility.parseFirstUri(nodeList, report);
|
102
|
String content = AbcdParseUtility.parseFirstTextContent(nodeList);
|
103
|
System.out.println(content);
|
104
|
}
|
105
|
|
106
|
|
107
|
|
108
|
SpecimenImportView specimenImportView = new SpecimenImportView();
|
109
|
try {
|
110
|
specimenImportView = (SpecimenImportView) activePart.showView(SpecimenImportView.ID);
|
111
|
specimenImportView.setEndpoint(providerSelectionPage.getEndPoint());
|
112
|
specimenImportView.setQuery(query);
|
113
|
dataImportView = specimenImportView;
|
114
|
} catch (PartInitException e) {
|
115
|
// TODO Auto-generated catch block
|
116
|
e.printStackTrace();
|
117
|
|
118
|
}
|
119
|
|
120
|
} else{
|
121
|
try {
|
122
|
|
123
|
dataImportView = (GbifResponseImportView) activePart.showView(GbifResponseImportView.ID, "query_"+query.toString().replaceAll(",", ""), IWorkbenchPage.VIEW_ACTIVATE);
|
124
|
dataImportView.setQuery(query);
|
125
|
// (GbifResponseImportView) activePart.showView(GbifResponseImportView.ID);getWorkbench().getActiveWorkbenchWindow().getActivePage()
|
126
|
// .showView(GbifResponseImportView.ID, "query_"+query.toString().replaceAll(",", ""),IWorkbenchPage.VIEW_ACTIVATE);
|
127
|
|
128
|
} catch (PartInitException e) {
|
129
|
// TODO Auto-generated catch block
|
130
|
e.printStackTrace();
|
131
|
}
|
132
|
|
133
|
}
|
134
|
|
135
|
|
136
|
} catch (IOException e) {
|
137
|
// TODO Auto-generated catch block
|
138
|
e.printStackTrace();
|
139
|
}
|
140
|
// CdmStore.getImportManager().run(configurator);
|
141
|
|
142
|
// try {
|
143
|
// switch (providerSelectionPage.getQueryType()) {
|
144
|
// case BIOCASE:
|
145
|
// SpecimenImportView specimenImportView = (SpecimenImportView) TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage()
|
146
|
// .showView(SpecimenImportView.ID, "query_"+query.toString().replaceAll(",", ""),IWorkbenchPage.VIEW_ACTIVATE);
|
147
|
// specimenImportView.setEndpoint(providerSelectionPage.getEndPoint());
|
148
|
// dataImportView = specimenImportView;
|
149
|
// break;
|
150
|
// case GBIF:
|
151
|
// dataImportView = (GbifResponseImportView) TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage()
|
152
|
// .showView(GbifResponseImportView.ID, "query_"+query.toString().replaceAll(",", ""),IWorkbenchPage.VIEW_ACTIVATE);
|
153
|
// break;
|
154
|
// }
|
155
|
// } catch ( PartInitException e ) {
|
156
|
// logger.error("Could not open import view for query: " + query.toString(), e);
|
157
|
// }
|
158
|
// if(dataImportView!=null){
|
159
|
// dataImportView.setQuery(query);
|
160
|
//// dataImportView.query();
|
161
|
//// Display.getDefault().asyncExec(new Runnable() {
|
162
|
////
|
163
|
//// @Override
|
164
|
//// public void run() {
|
165
|
//// CdmStore.getContextManager().notifyContextRefresh();
|
166
|
//// }
|
167
|
//// });
|
168
|
Job queryJob = new QueryJob("Query specimen provider", dataImportView);
|
169
|
queryJob.schedule();
|
170
|
|
171
|
return true;
|
172
|
}
|
173
|
|
174
|
/* (non-Javadoc)
|
175
|
* @see org.eclipse.jface.wizard.Wizard#addPages()
|
176
|
*/
|
177
|
@Override
|
178
|
public void addPages() {
|
179
|
addPage(providerSelectionPage);
|
180
|
addPage(searchPage);
|
181
|
}
|
182
|
|
183
|
/* (non-Javadoc)
|
184
|
* @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
|
185
|
*/
|
186
|
@Override
|
187
|
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
188
|
providerSelectionPage = new SpecimenProviderSelectionWizardPage("Select specimen provider");
|
189
|
searchPage = new SpecimenSearchWizardPage("Specimen Search");
|
190
|
}
|
191
|
|
192
|
private class QueryJob extends Job{
|
193
|
|
194
|
private final DataImportView<?> view;
|
195
|
|
196
|
/**
|
197
|
* @param name
|
198
|
*/
|
199
|
public QueryJob(String name, DataImportView<?> view) {
|
200
|
super(name);
|
201
|
this.view = view;
|
202
|
}
|
203
|
|
204
|
/* (non-Javadoc)
|
205
|
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
|
206
|
*/
|
207
|
@Override
|
208
|
protected IStatus run(IProgressMonitor monitor) {
|
209
|
view.getConversationHolder().bind();
|
210
|
view.query();
|
211
|
Display.getDefault().asyncExec(new Runnable() {
|
212
|
|
213
|
@Override
|
214
|
public void run() {
|
215
|
CdmStore.getContextManager().notifyContextRefresh();
|
216
|
}
|
217
|
});
|
218
|
return Status.OK_STATUS;
|
219
|
}
|
220
|
|
221
|
}
|
222
|
}
|