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