Revision ab287c7e
Added by Patrick Plitzner almost 10 years ago
- added date support for query parameter in specimen search
- linked some more query parameters
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/SpecimenImportEditorInput.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 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 |
*/ |
|
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 | 10 |
package eu.etaxonomy.taxeditor.editor.view.dataimport; |
11 | 11 |
|
12 | 12 |
import java.io.IOException; |
... | ... | |
16 | 16 |
import java.util.ArrayList; |
17 | 17 |
import java.util.Collection; |
18 | 18 |
|
19 |
import net.sf.json.JSONArray; |
|
19 | 20 |
import net.sf.json.JSONObject; |
20 |
import net.sf.json.JSONSerializer; |
|
21 | 21 |
|
22 | 22 |
import org.apache.commons.io.IOUtils; |
23 | 23 |
import org.apache.http.client.ClientProtocolException; |
24 | 24 |
import org.eclipse.swt.widgets.Display; |
25 | 25 |
|
26 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade; |
|
26 | 27 |
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery; |
28 |
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper; |
|
27 | 29 |
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifQueryServiceWrapper; |
30 |
import eu.etaxonomy.cdm.io.common.CdmDefaultImport; |
|
31 |
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator; |
|
28 | 32 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
33 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType; |
|
34 |
import eu.etaxonomy.taxeditor.editor.view.dataimport.transientServices.TransientCdmRepository; |
|
29 | 35 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
30 | 36 |
|
31 | 37 |
/** |
... | ... | |
52 | 58 |
|
53 | 59 |
Collection<SpecimenOrObservationBase<?>> results = new ArrayList<SpecimenOrObservationBase<?>>(); |
54 | 60 |
try { |
55 |
InputStream resultStream = new GbifQueryServiceWrapper().query(query); |
|
56 |
StringWriter stringWriter = new StringWriter(); |
|
57 |
IOUtils.copy(resultStream, stringWriter); |
|
58 |
String jsonString = stringWriter.toString(); |
|
59 |
JSONObject jsonObject = JSONObject.fromObject(jsonString); |
|
60 |
Object java = JSONSerializer.toJava(jsonObject); |
|
61 |
java.toString(); |
|
61 |
InputStream resultStream; |
|
62 |
switch (queryType) { |
|
63 |
case GBIF: |
|
64 |
resultStream = new GbifQueryServiceWrapper().query(query); |
|
65 |
StringWriter stringWriter = new StringWriter(); |
|
66 |
IOUtils.copy(resultStream, stringWriter); |
|
67 |
String jsonString = stringWriter.toString(); |
|
68 |
JSONArray resultsArray = JSONObject.fromObject(jsonString).getJSONArray("results"); |
|
69 |
for(Object o:resultsArray){ |
|
70 |
//parse every record |
|
71 |
if(o instanceof JSONObject){ |
|
72 |
DerivedUnitFacade derivedUnitFacade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen); |
|
73 |
JSONObject record = (JSONObject)o; |
|
74 |
|
|
75 |
if(record.has("locality")){ |
|
76 |
String locality = record.getString("locality"); |
|
77 |
derivedUnitFacade.setLocality(locality); |
|
78 |
} |
|
79 |
results.add(derivedUnitFacade.innerDerivedUnit()); |
|
80 |
} |
|
81 |
|
|
82 |
} |
|
83 |
break; |
|
84 |
case BIOCASE: |
|
85 |
resultStream = new BioCaseQueryServiceWrapper().query(SpecimenImportEditorInput.this.query); |
|
86 |
Abcd206ImportConfigurator configurator = Abcd206ImportConfigurator.NewInstance(resultStream, null, false); |
|
87 |
TransientCdmRepository repo = |
|
88 |
new TransientCdmRepository(CdmStore.getCurrentApplicationConfiguration()); |
|
89 |
configurator.setCdmAppController(repo); |
|
90 |
|
|
91 |
CdmDefaultImport<Abcd206ImportConfigurator> importer = new CdmDefaultImport<Abcd206ImportConfigurator>(); |
|
92 |
importer.invoke(configurator); |
|
93 |
results = repo.getUnits(); |
|
94 |
setResults(results); |
|
95 |
break; |
|
96 |
} |
|
62 | 97 |
} catch (ClientProtocolException e) { |
63 | 98 |
logger.error(errorMessage, e); |
64 | 99 |
} catch (IOException e) { |
... | ... | |
66 | 101 |
} catch (URISyntaxException e) { |
67 | 102 |
logger.error(errorMessage, e); |
68 | 103 |
} |
104 |
|
|
69 | 105 |
setResults(results); |
70 | 106 |
|
71 | 107 |
Display.getDefault().asyncExec(new Runnable() { |
... | ... | |
82 | 118 |
*/ |
83 | 119 |
@Override |
84 | 120 |
public String getName() { |
85 |
return query.toString(); |
|
121 |
return queryType + " " + query.toString();
|
|
86 | 122 |
} |
87 | 123 |
|
88 | 124 |
/* (non-Javadoc) |
Also available in: Unified diff