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