b98f89760b9d05d55df186ac14d01219815b7e88
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / dataimport / BioCaseEditorInput.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.bioCase.BioCaseQueryServiceWrapper;
23 import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
24 import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
25 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
26 import eu.etaxonomy.taxeditor.editor.view.dataimport.transientServices.TransientCdmRepository;
27 import eu.etaxonomy.taxeditor.store.CdmStore;
28
29 /**
30 * @author pplitzner
31 * @date 25.02.2014
32 *
33 */
34 public class BioCaseEditorInput extends DataImportEditorInput<SpecimenOrObservationBase<?>> {
35
36 /**
37 * @param results
38 */
39 public BioCaseEditorInput(OccurenceQuery query) {
40 super();
41 this.query = query;
42 }
43
44 @Override
45 public void query(){
46 String errorMessage = "Could not execute query " + query;
47
48 Collection<SpecimenOrObservationBase<?>> results = new ArrayList<SpecimenOrObservationBase<?>>();
49 try {
50 //FIXME move ABCD import to cdmlib -> this will also get rid of the transient services
51 InputStream resultStream;
52 resultStream = new BioCaseQueryServiceWrapper().query(query);
53 Abcd206ImportConfigurator configurator = Abcd206ImportConfigurator.NewInstance(resultStream, null, false);
54 TransientCdmRepository repo =
55 new TransientCdmRepository(CdmStore.getCurrentApplicationConfiguration());
56 configurator.setCdmAppController(repo);
57
58 CdmDefaultImport<Abcd206ImportConfigurator> importer = new CdmDefaultImport<Abcd206ImportConfigurator>();
59 importer.invoke(configurator);
60 results = repo.getUnits();
61 setResults(results);
62 } catch (ClientProtocolException e) {
63 logger.error(errorMessage, e);
64 } catch (IOException e) {
65 logger.error(errorMessage, e);
66 } catch (URISyntaxException e) {
67 logger.error(errorMessage, e);
68 }
69
70 setResults(results);
71
72 Display.getDefault().asyncExec(new Runnable() {
73
74 @Override
75 public void run() {
76 CdmStore.getContextManager().notifyContextRefresh();
77 }
78 });
79 }
80
81 /* (non-Javadoc)
82 * @see org.eclipse.ui.IEditorInput#getName()
83 */
84 @Override
85 public String getName() {
86 return "[BioCASE] " + query.toString();
87 }
88
89 /* (non-Javadoc)
90 * @see org.eclipse.ui.IEditorInput#getToolTipText()
91 */
92 @Override
93 public String getToolTipText() {
94 return "[BioCASE] " + query.toString();
95 }
96
97 /* (non-Javadoc)
98 * @see java.lang.Object#hashCode()
99 */
100 @Override
101 public int hashCode() {
102 final int prime = 31;
103 int result = 1;
104 result = prime * result + ((query == null) ? 0 : query.hashCode());
105 return result;
106 }
107
108 /* (non-Javadoc)
109 * @see java.lang.Object#equals(java.lang.Object)
110 */
111 @Override
112 public boolean equals(Object obj) {
113 if (this == obj) {
114 return true;
115 }
116 if (obj == null) {
117 return false;
118 }
119 if (getClass() != obj.getClass()) {
120 return false;
121 }
122 BioCaseEditorInput other = (BioCaseEditorInput) obj;
123 if (query == null) {
124 if (other.query != null) {
125 return false;
126 }
127 } else if (!query.equals(other.query)) {
128 return false;
129 }
130 return true;
131 }
132 }