merge-update from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / dataimport / DerivedUnitEditorInput.java
1 // $Id$
2 /**
3 * Copyright (C) 2013 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.dataimport;
11
12 import java.io.IOException;
13 import java.io.InputStream;
14 import java.net.URISyntaxException;
15 import java.util.Collections;
16 import java.util.List;
17
18 import org.apache.http.client.ClientProtocolException;
19 import org.apache.log4j.Logger;
20 import org.eclipse.jface.resource.ImageDescriptor;
21 import org.eclipse.ui.IEditorInput;
22 import org.eclipse.ui.IPersistableElement;
23
24 import eu.etaxonomy.cdm.ext.biocase.BioCaseQuery;
25 import eu.etaxonomy.cdm.ext.biocase.BioCaseQueryServiceWrapper;
26 import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
27 import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
28 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
29 import eu.etaxonomy.taxeditor.dataimport.transientServices.TransientCdmRepository;
30 import eu.etaxonomy.taxeditor.store.CdmStore;
31
32 /**
33 * @author pplitzner
34 * @date 20.09.2013
35 *
36 */
37 public class DerivedUnitEditorInput implements IEditorInput {
38
39 private static Logger logger = Logger.getLogger(DerivedUnitEditorInput.class);
40
41 private final BioCaseQuery query;
42
43 /**
44 * @param results
45 */
46 public DerivedUnitEditorInput(BioCaseQuery query) {
47 this.query = query;
48 }
49
50 /* (non-Javadoc)
51 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
52 */
53 @Override
54 public Object getAdapter(Class adapter) {
55 // TODO Auto-generated method stub
56 return null;
57 }
58
59 /* (non-Javadoc)
60 * @see org.eclipse.ui.IEditorInput#exists()
61 */
62 @Override
63 public boolean exists() {
64 return false;
65 }
66
67 /* (non-Javadoc)
68 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
69 */
70 @Override
71 public ImageDescriptor getImageDescriptor() {
72 // TODO Auto-generated method stub
73 return null;
74 }
75
76 /* (non-Javadoc)
77 * @see org.eclipse.ui.IEditorInput#getName()
78 */
79 @Override
80 public String getName() {
81 return query.toString();
82 }
83
84 /* (non-Javadoc)
85 * @see org.eclipse.ui.IEditorInput#getPersistable()
86 */
87 @Override
88 public IPersistableElement getPersistable() {
89 return null;
90 }
91
92 /* (non-Javadoc)
93 * @see org.eclipse.ui.IEditorInput#getToolTipText()
94 */
95 @Override
96 public String getToolTipText() {
97 return query.toString();
98 }
99
100 /**
101 * @return the results
102 */
103 public List<SpecimenOrObservationBase> getResults() {
104 String errorMessage = "Could not execute query " + query;
105 List<SpecimenOrObservationBase> results = Collections.EMPTY_LIST;
106 try {
107 InputStream resultStream = new BioCaseQueryServiceWrapper().query(query);
108 Abcd206ImportConfigurator configurator = Abcd206ImportConfigurator.NewInstance(resultStream, null, false);
109 TransientCdmRepository repo = new TransientCdmRepository(CdmStore.getCurrentApplicationConfiguration());
110 configurator.setCdmAppController(repo);
111
112 CdmDefaultImport<Abcd206ImportConfigurator> importer = new CdmDefaultImport<Abcd206ImportConfigurator>();
113 importer.invoke(configurator);
114 results = repo.getUnits();
115 // Abcd206Import abcd206Import = new Abcd206Import();
116 // Abcd206ImportState state = new Abcd206ImportState(configurator);
117 // abcd206Import.invoke(state);
118 // state.countTrees();
119 } catch (ClientProtocolException e) {
120 logger.error(errorMessage, e);
121 } catch (IOException e) {
122 logger.error(errorMessage, e);
123 } catch (URISyntaxException e) {
124 logger.error(errorMessage, e);
125 }
126 // return new BioCaseQueryServiceWrapper().dummyData();
127 return results;
128 }
129
130 /* (non-Javadoc)
131 * @see java.lang.Object#hashCode()
132 */
133 @Override
134 public int hashCode() {
135 final int prime = 31;
136 int result = 1;
137 result = prime * result + ((query == null) ? 0 : query.hashCode());
138 return result;
139 }
140
141 /* (non-Javadoc)
142 * @see java.lang.Object#equals(java.lang.Object)
143 */
144 @Override
145 public boolean equals(Object obj) {
146 if (this == obj) {
147 return true;
148 }
149 if (obj == null) {
150 return false;
151 }
152 if (getClass() != obj.getClass()) {
153 return false;
154 }
155 DerivedUnitEditorInput other = (DerivedUnitEditorInput) obj;
156 if (query == null) {
157 if (other.query != null) {
158 return false;
159 }
160 } else if (!query.equals(other.query)) {
161 return false;
162 }
163 return true;
164 }
165
166 }