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.e4;
|
10
|
|
11
|
import java.io.IOException;
|
12
|
import java.io.InputStream;
|
13
|
|
14
|
import javax.inject.Inject;
|
15
|
|
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.e4.core.contexts.ContextInjectionFactory;
|
21
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
22
|
import org.eclipse.e4.ui.model.application.MApplication;
|
23
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
24
|
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
|
25
|
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
26
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
27
|
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
|
28
|
import org.eclipse.jface.wizard.Wizard;
|
29
|
import org.eclipse.swt.widgets.Display;
|
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.AppModelId;
|
40
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
41
|
import eu.etaxonomy.taxeditor.view.dataimport.QueryType;
|
42
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
43
|
import eu.etaxonomy.taxeditor.workbench.part.IEditorAreaPart;
|
44
|
|
45
|
/**
|
46
|
* Wizard for querying specimen provider.
|
47
|
* @author pplitzner
|
48
|
* @date 11.09.2013
|
49
|
*/
|
50
|
public class SpecimenSearchWizard extends Wizard {
|
51
|
|
52
|
private OccurenceQuery query = null;
|
53
|
private SpecimenProviderSelectionWizardPage providerSelectionPage;
|
54
|
private SpecimenSearchWizardPage searchPage;
|
55
|
|
56
|
@Inject
|
57
|
private EPartService partService;
|
58
|
|
59
|
@Inject
|
60
|
private MApplication application;
|
61
|
|
62
|
@Inject
|
63
|
private EModelService modelService;
|
64
|
|
65
|
private IEclipseContext context;
|
66
|
|
67
|
/**
|
68
|
* Creates a new SpecimenSearchWizard
|
69
|
*/
|
70
|
@Inject
|
71
|
public SpecimenSearchWizard(IEclipseContext context) {
|
72
|
this.context = context;
|
73
|
//default constructor needed for RCP extension points
|
74
|
|
75
|
//check if connected to a data source. If not this will open an error dialog
|
76
|
CdmStore.getCurrentApplicationConfiguration();
|
77
|
this.setWindowTitle("Search Specimens");
|
78
|
}
|
79
|
|
80
|
@Override
|
81
|
public boolean performFinish() {
|
82
|
searchPage.getController().saveLastSate();
|
83
|
providerSelectionPage.getController().saveLastState();
|
84
|
ServiceWrapperBase serviceWrapper;
|
85
|
DataImportView<?> dataImportView = null;
|
86
|
boolean biocase = providerSelectionPage.getQueryType().equals(QueryType.BIOCASE);
|
87
|
query = searchPage.getQuery(biocase);
|
88
|
|
89
|
//query for specific dataset...<DataSets><DataSet><Metadata><Description><Representation language="EN"><Title>...
|
90
|
Abcd206ImportConfigurator configurator = CdmStore.getImportManager().AbcdConfigurator();
|
91
|
configurator.setOccurenceQuery(query);
|
92
|
configurator.setSourceUri(providerSelectionPage.getEndPoint());
|
93
|
configurator.setAddMediaAsMediaSpecimen(true);
|
94
|
configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
|
95
|
configurator.setIgnoreAuthorship(true);
|
96
|
configurator.setMoveNewTaxaToDefaultClassification(false);
|
97
|
|
98
|
try {
|
99
|
serviceWrapper = providerSelectionPage.getQueryServiceWrapper();
|
100
|
InputStream stream = null;
|
101
|
MPart part = null;
|
102
|
if (providerSelectionPage.getQueryType().equals(QueryType.BIOCASE)){
|
103
|
stream =((BioCaseQueryServiceWrapper) serviceWrapper).query(query, configurator.getSourceUri());
|
104
|
SpecimenImportReport report = new SpecimenImportReport();
|
105
|
UnitAssociationWrapper unitNodesList = AbcdParseUtility.parseUnitsNodeList(stream, report);
|
106
|
|
107
|
part = partService.createPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_VIEW_DATAIMPORT_E4_SPECIMENIMPORTVIEWE4);
|
108
|
part = partService.showPart(part, PartState.ACTIVATE);
|
109
|
SpecimenImportView specimenImportView = (SpecimenImportView) part.getObject();
|
110
|
specimenImportView.setEndpoint(providerSelectionPage.getEndPoint());
|
111
|
specimenImportView.setQuery(query);
|
112
|
|
113
|
dataImportView = specimenImportView;
|
114
|
|
115
|
} else{
|
116
|
part = partService.createPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_VIEW_DATAIMPORT_E4_GBIFRESPONSEIMPORTVIEWE4);
|
117
|
part = partService.showPart(part, PartState.ACTIVATE);
|
118
|
GbifResponseImportView gbifImportView = (GbifResponseImportView) part.getObject();
|
119
|
gbifImportView.setQuery(query);
|
120
|
|
121
|
dataImportView = gbifImportView;
|
122
|
|
123
|
}
|
124
|
if(part.getObject() instanceof IEditorAreaPart){
|
125
|
MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
|
126
|
if(editorAreaPartStack!=null){
|
127
|
editorAreaPartStack.getChildren().add(part);
|
128
|
}
|
129
|
part = partService.showPart(part, PartState.VISIBLE);
|
130
|
}
|
131
|
} catch (IOException e) {
|
132
|
e.printStackTrace();
|
133
|
}
|
134
|
// CdmStore.getImportManager().run(configurator);
|
135
|
|
136
|
// try {
|
137
|
// switch (providerSelectionPage.getQueryType()) {
|
138
|
// case BIOCASE:
|
139
|
// SpecimenImportView specimenImportView = (SpecimenImportView) TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage()
|
140
|
// .showView(SpecimenImportView.ID, "query_"+query.toString().replaceAll(",", ""),IWorkbenchPage.VIEW_ACTIVATE);
|
141
|
// specimenImportView.setEndpoint(providerSelectionPage.getEndPoint());
|
142
|
// dataImportView = specimenImportView;
|
143
|
// break;
|
144
|
// case GBIF:
|
145
|
// dataImportView = (GbifResponseImportView) TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage()
|
146
|
// .showView(GbifResponseImportView.ID, "query_"+query.toString().replaceAll(",", ""),IWorkbenchPage.VIEW_ACTIVATE);
|
147
|
// break;
|
148
|
// }
|
149
|
// } catch ( PartInitException e ) {
|
150
|
// logger.error("Could not open import view for query: " + query.toString(), e);
|
151
|
// }
|
152
|
// if(dataImportView!=null){
|
153
|
// dataImportView.setQuery(query);
|
154
|
//// dataImportView.query();
|
155
|
//// Display.getDefault().asyncExec(new Runnable() {
|
156
|
////
|
157
|
//// @Override
|
158
|
//// public void run() {
|
159
|
//// CdmStore.getContextManager().notifyContextRefresh();
|
160
|
//// }
|
161
|
//// });
|
162
|
Job queryJob = new QueryJob("Query specimen provider", dataImportView);
|
163
|
queryJob.schedule();
|
164
|
|
165
|
return true;
|
166
|
}
|
167
|
|
168
|
@Override
|
169
|
public void addPages() {
|
170
|
addPage(providerSelectionPage);
|
171
|
addPage(searchPage);
|
172
|
}
|
173
|
|
174
|
public void init() {
|
175
|
providerSelectionPage = ContextInjectionFactory.make(SpecimenProviderSelectionWizardPage.class, context);
|
176
|
// new SpecimenProviderSelectionWizardPage("Select specimen provider");
|
177
|
// searchPage = new SpecimenSearchWizardPage("Specimen Search");
|
178
|
searchPage = ContextInjectionFactory.make(SpecimenSearchWizardPage.class, context);
|
179
|
}
|
180
|
|
181
|
private class QueryJob extends Job{
|
182
|
|
183
|
private final DataImportView<?> view;
|
184
|
|
185
|
public QueryJob(String name, DataImportView<?> view) {
|
186
|
super(name);
|
187
|
this.view = view;
|
188
|
}
|
189
|
|
190
|
@Override
|
191
|
protected IStatus run(IProgressMonitor monitor) {
|
192
|
view.query();
|
193
|
Display.getDefault().asyncExec(new Runnable() {
|
194
|
|
195
|
@Override
|
196
|
public void run() {
|
197
|
CdmStore.getContextManager().notifyContextRefresh();
|
198
|
}
|
199
|
});
|
200
|
return Status.OK_STATUS;
|
201
|
}
|
202
|
|
203
|
}
|
204
|
}
|