- refactored BioCaseQuery to more generic OccurrenceQuery
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / dataimport / SpecimenImportEditorInput.java
1 // $Id$
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 */
10 package eu.etaxonomy.taxeditor.editor.view.dataimport;
11
12 import java.io.IOException;
13 import java.io.InputStream;
14 import java.net.URISyntaxException;
15 import java.util.ArrayList;
16 import java.util.Collection;
17
18 import org.apache.http.client.ClientProtocolException;
19 import org.eclipse.swt.widgets.Display;
20
21 import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
22 import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifQueryServiceWrapper;
23 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
24 import eu.etaxonomy.taxeditor.store.CdmStore;
25
26 /**
27 * @author pplitzner
28 * @date 25.02.2014
29 *
30 */
31 public class SpecimenImportEditorInput extends DataImportEditorInput<SpecimenOrObservationBase<?>> {
32
33 private final OccurenceQuery query;
34
35 /**
36 * @param results
37 */
38 public SpecimenImportEditorInput(OccurenceQuery query) {
39 super();
40 this.query = query;
41 }
42
43 public void query(){
44 String errorMessage = "Could not execute query " + query;
45
46 Collection<SpecimenOrObservationBase<?>> results = new ArrayList<SpecimenOrObservationBase<?>>();
47 try {
48 InputStream resultStream = new GbifQueryServiceWrapper().query(query);
49 // JSONObject jsonObject = JSONObject.fromObject(dummyJson);
50 // Object java = JSONSerializer.toJava(jsonObject);
51 } catch (ClientProtocolException e) {
52 logger.error(errorMessage, e);
53 } catch (IOException e) {
54 logger.error(errorMessage, e);
55 } catch (URISyntaxException e) {
56 logger.error(errorMessage, e);
57 }
58 setResults(results);
59
60 Display.getDefault().asyncExec(new Runnable() {
61
62 @Override
63 public void run() {
64 CdmStore.getContextManager().notifyContextRefresh();
65 }
66 });
67 }
68
69 /* (non-Javadoc)
70 * @see org.eclipse.ui.IEditorInput#getName()
71 */
72 @Override
73 public String getName() {
74 return query.toString();
75 }
76
77 /* (non-Javadoc)
78 * @see org.eclipse.ui.IEditorInput#getToolTipText()
79 */
80 @Override
81 public String getToolTipText() {
82 return query.toString();
83 }
84
85 /* (non-Javadoc)
86 * @see java.lang.Object#hashCode()
87 */
88 @Override
89 public int hashCode() {
90 final int prime = 31;
91 int result = 1;
92 result = prime * result + ((query == null) ? 0 : query.hashCode());
93 return result;
94 }
95
96 /* (non-Javadoc)
97 * @see java.lang.Object#equals(java.lang.Object)
98 */
99 @Override
100 public boolean equals(Object obj) {
101 if (this == obj) {
102 return true;
103 }
104 if (obj == null) {
105 return false;
106 }
107 if (getClass() != obj.getClass()) {
108 return false;
109 }
110 SpecimenImportEditorInput other = (SpecimenImportEditorInput) obj;
111 if (query == null) {
112 if (other.query != null) {
113 return false;
114 }
115 } else if (!query.equals(other.query)) {
116 return false;
117 }
118 return true;
119 }
120 }