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