ed7c89cc0cf3313004d0ee90754c186585ec99ec
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / dataimport / GbifImportEditorInput.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.net.URISyntaxException;
14 import java.util.Collection;
15
16 import org.apache.http.client.ClientProtocolException;
17
18 import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
19 import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifQueryServiceWrapper;
20 import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
21
22 /**
23 * @author pplitzner
24 * @date 27.05.2014
25 *
26 */
27 public class GbifImportEditorInput extends DataImportEditorInput<GbifResponse> {
28
29 /**
30 * @param query
31 */
32 public GbifImportEditorInput(OccurenceQuery query) {
33 super();
34 this.query = query;
35 }
36
37 @Override
38 public void query(){
39 String errorMessage = "Could not execute query " + query;
40 try{
41 Collection<GbifResponse> results = new GbifQueryServiceWrapper().query(query);
42 setResults(results);
43 } catch (ClientProtocolException e) {
44 logger.error(errorMessage, e);
45 } catch (IOException e) {
46 logger.error(errorMessage, e);
47 } catch (URISyntaxException e) {
48 logger.error(errorMessage, e);
49 }
50 }
51
52
53 /* (non-Javadoc)
54 * @see org.eclipse.ui.IEditorInput#getName()
55 */
56 @Override
57 public String getName() {
58 return "[GBIF] " + query.toString();
59 }
60
61 /* (non-Javadoc)
62 * @see org.eclipse.ui.IEditorInput#getToolTipText()
63 */
64 @Override
65 public String getToolTipText() {
66 return "[GBIF] " + query.toString();
67 }
68
69 /* (non-Javadoc)
70 * @see java.lang.Object#hashCode()
71 */
72 @Override
73 public int hashCode() {
74 final int prime = 31;
75 int result = 1;
76 result = prime * result + ((query == null) ? 0 : query.hashCode());
77 return result;
78 }
79
80 /* (non-Javadoc)
81 * @see java.lang.Object#equals(java.lang.Object)
82 */
83 @Override
84 public boolean equals(Object obj) {
85 if (this == obj) {
86 return true;
87 }
88 if (obj == null) {
89 return false;
90 }
91 if (getClass() != obj.getClass()) {
92 return false;
93 }
94 DataImportEditorInput<GbifResponse> other = (DataImportEditorInput<GbifResponse>) obj;
95 if (query == null) {
96 if (other.query != null) {
97 return false;
98 }
99 } else if (!query.equals(other.query)) {
100 return false;
101 }
102 return true;
103 }
104
105 }