- derivate view shows derivate hierarchy of FieldUnits and DerivedUnits
[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.ArrayList;
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 private List<SpecimenOrObservationBase> results;
44
45 /**
46 * @param results
47 */
48 public DerivedUnitEditorInput(BioCaseQuery query) {
49 this.query = query;
50 results = new ArrayList<SpecimenOrObservationBase>();
51 }
52
53 /* (non-Javadoc)
54 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
55 */
56 @Override
57 public Object getAdapter(Class adapter) {
58 // TODO Auto-generated method stub
59 return null;
60 }
61
62 /* (non-Javadoc)
63 * @see org.eclipse.ui.IEditorInput#exists()
64 */
65 @Override
66 public boolean exists() {
67 return false;
68 }
69
70 /* (non-Javadoc)
71 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
72 */
73 @Override
74 public ImageDescriptor getImageDescriptor() {
75 // TODO Auto-generated method stub
76 return null;
77 }
78
79 /* (non-Javadoc)
80 * @see org.eclipse.ui.IEditorInput#getName()
81 */
82 @Override
83 public String getName() {
84 return query.toString();
85 }
86
87 /* (non-Javadoc)
88 * @see org.eclipse.ui.IEditorInput#getPersistable()
89 */
90 @Override
91 public IPersistableElement getPersistable() {
92 return null;
93 }
94
95 /* (non-Javadoc)
96 * @see org.eclipse.ui.IEditorInput#getToolTipText()
97 */
98 @Override
99 public String getToolTipText() {
100 return query.toString();
101 }
102
103 /**
104 * @return the results
105 */
106 public List<SpecimenOrObservationBase> getResults() {
107 if(results!=null && !results.isEmpty()){
108 return results;
109 }
110 String errorMessage = "Could not execute query " + query;
111 try {
112 InputStream resultStream = new BioCaseQueryServiceWrapper().query(query);
113 Abcd206ImportConfigurator configurator = Abcd206ImportConfigurator.NewInstance(resultStream, null, false);
114 TransientCdmRepository repo = new TransientCdmRepository(CdmStore.getCurrentApplicationConfiguration());
115 configurator.setCdmAppController(repo);
116
117 CdmDefaultImport<Abcd206ImportConfigurator> importer = new CdmDefaultImport<Abcd206ImportConfigurator>();
118 importer.invoke(configurator);
119 results = repo.getUnits();
120 // Abcd206Import abcd206Import = new Abcd206Import();
121 // Abcd206ImportState state = new Abcd206ImportState(configurator);
122 // abcd206Import.invoke(state);
123 // state.countTrees();
124 } catch (ClientProtocolException e) {
125 logger.error(errorMessage, e);
126 } catch (IOException e) {
127 logger.error(errorMessage, e);
128 } catch (URISyntaxException e) {
129 logger.error(errorMessage, e);
130 }
131 // return new BioCaseQueryServiceWrapper().dummyData();
132 return results;
133 }
134
135 /* (non-Javadoc)
136 * @see java.lang.Object#hashCode()
137 */
138 @Override
139 public int hashCode() {
140 final int prime = 31;
141 int result = 1;
142 result = prime * result + ((query == null) ? 0 : query.hashCode());
143 return result;
144 }
145
146 /* (non-Javadoc)
147 * @see java.lang.Object#equals(java.lang.Object)
148 */
149 @Override
150 public boolean equals(Object obj) {
151 if (this == obj) {
152 return true;
153 }
154 if (obj == null) {
155 return false;
156 }
157 if (getClass() != obj.getClass()) {
158 return false;
159 }
160 DerivedUnitEditorInput other = (DerivedUnitEditorInput) obj;
161 if (query == null) {
162 if (other.query != null) {
163 return false;
164 }
165 } else if (!query.equals(other.query)) {
166 return false;
167 }
168 return true;
169 }
170
171 }