Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java @ 325:3eff9241ea1e
Refactoring of the Transitionmodel.
Now each Transition is responsible to allocate the Data which is required to describe or feed it.
gnv-artifacts/trunk@390 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 01 Dec 2009 15:58:02 +0000 |
parents | 91c37bf28c0e |
children | 1c427acb6c76 |
comparison
equal
deleted
inserted
replaced
324:e6e172a4915e | 325:3eff9241ea1e |
---|---|
7 import java.util.ArrayList; | 7 import java.util.ArrayList; |
8 import java.util.Collection; | 8 import java.util.Collection; |
9 | 9 |
10 | 10 |
11 import org.apache.log4j.Logger; | 11 import org.apache.log4j.Logger; |
12 import org.w3c.dom.Document; | |
12 import org.w3c.dom.Element; | 13 import org.w3c.dom.Element; |
13 import org.w3c.dom.Node; | 14 import org.w3c.dom.Node; |
14 import org.w3c.dom.NodeList; | 15 import org.w3c.dom.NodeList; |
15 | 16 |
16 import de.intevation.artifactdatabase.Config; | 17 import de.intevation.artifactdatabase.Config; |
114 * @see de.intevation.gnv.transition.TransitionBase#advance() | 115 * @see de.intevation.gnv.transition.TransitionBase#advance() |
115 */ | 116 */ |
116 @Override | 117 @Override |
117 public void advance(String uuid, CallMeta callMeta) | 118 public void advance(String uuid, CallMeta callMeta) |
118 throws TransitionException { | 119 throws TransitionException { |
119 log.debug("OutputTransitionBase.advance"); | 120 } |
120 if (this.getChartResult(uuid) == null) { | 121 |
121 super.advance(uuid, callMeta); | 122 @Override |
122 } | 123 public void initialize(String uuid, CallMeta callMeta) |
124 throws TransitionException { | |
125 } | |
126 | |
127 public void out(Document format, Collection<InputData> inputData, | |
128 OutputStream outputStream, String uuid, CallMeta callMeta) | |
129 throws TransitionException { | |
123 } | 130 } |
124 | 131 |
125 /** | 132 /** |
126 * @see de.intevation.gnv.transition.OutputTransition#out(java.lang.String, | 133 * @see de.intevation.gnv.transition.OutputTransition#out(java.lang.String, |
127 * java.util.Collection, java.io.OutputStream) | 134 * java.util.Collection, java.io.OutputStream) |
133 /** | 140 /** |
134 * @return | 141 * @return |
135 */ | 142 */ |
136 protected Collection<Result> getChartResult(String uuid) { | 143 protected Collection<Result> getChartResult(String uuid) { |
137 log.debug("OutputTransitionBase.getChartResult"); | 144 log.debug("OutputTransitionBase.getChartResult"); |
145 Collection<Result> result = null; | |
138 if (CacheFactory.getInstance().isInitialized()) { | 146 if (CacheFactory.getInstance().isInitialized()) { |
139 String key = uuid + super.getID(); | 147 String key = uuid + super.getID(); |
140 log.debug("Hash for Queryelements: " + key); | 148 log.debug("Hash for Queryelements: " + key); |
141 net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key); | 149 net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key); |
142 if (value != null) { | 150 if (value != null) { |
143 return (Collection<Result>) (value.getObjectValue()); | 151 result = (Collection<Result>) (value.getObjectValue()); |
144 } | 152 }else{ |
145 } | 153 result = this.getData(this.queryID); |
146 return null; | 154 if (CacheFactory.getInstance().isInitialized()) { |
155 CacheFactory.getInstance().getCache().put(new net.sf.ehcache.Element(key, result)); | |
156 } | |
157 | |
158 } | |
159 } | |
160 return result; | |
147 } | 161 } |
148 | 162 |
149 protected Object getChartFromCache(String uuid) { | 163 protected Object getChartFromCache(String uuid) { |
150 log.debug("Fetch chart [" + uuid + "] from cache"); | 164 log.debug("Fetch chart [" + uuid + "] from cache"); |
151 CacheFactory cacheFactory = CacheFactory.getInstance(); | 165 CacheFactory cacheFactory = CacheFactory.getInstance(); |
163 protected Collection<Result> getODVResult(String uuid) { | 177 protected Collection<Result> getODVResult(String uuid) { |
164 log.debug("OutputTransitionBase.getODVResult"); | 178 log.debug("OutputTransitionBase.getODVResult"); |
165 // TODO add Caching? I think it's not nessessary | 179 // TODO add Caching? I think it's not nessessary |
166 Collection<Result> returnValue = null; | 180 Collection<Result> returnValue = null; |
167 if (this.queryODVID != null){ | 181 if (this.queryODVID != null){ |
168 try { | 182 returnValue = this.getData(this.queryODVID); |
169 String[] filterValues = this.generateFilterValuesFromInputData(); | |
170 try { | |
171 QueryExecutor queryExecutor = QueryExecutorFactory | |
172 .getInstance() | |
173 .getQueryExecutor(); | |
174 returnValue = queryExecutor.executeQuery(this.queryODVID, | |
175 filterValues); | |
176 } catch (RuntimeException e) { | |
177 log.error(e, e); | |
178 } | |
179 } catch (QueryException e) { | |
180 log.error(e, e); | |
181 } | |
182 }else{ | 183 }else{ |
183 log.warn("No Query for ODV Data is defined."); | 184 log.warn("No Query for ODV Data is defined."); |
185 } | |
186 return returnValue; | |
187 } | |
188 | |
189 /** | |
190 * @param returnValue | |
191 * @return | |
192 */ | |
193 private Collection<Result> getData(String queryID) { | |
194 log.debug("OutputTransitionBase.getData"); | |
195 Collection<Result> returnValue = null; | |
196 try { | |
197 String[] filterValues = this.generateFilterValuesFromInputData(); | |
198 try { | |
199 QueryExecutor queryExecutor = QueryExecutorFactory | |
200 .getInstance() | |
201 .getQueryExecutor(); | |
202 returnValue = queryExecutor.executeQuery(queryID,filterValues); | |
203 } catch (RuntimeException e) { | |
204 log.error(e, e); | |
205 } | |
206 } catch (QueryException e) { | |
207 log.error(e, e); | |
184 } | 208 } |
185 return returnValue; | 209 return returnValue; |
186 } | 210 } |
187 | 211 |
188 protected void removeChartResult(String uuid) { | 212 protected void removeChartResult(String uuid) { |
207 if (object != null) | 231 if (object != null) |
208 cacheFactory.getCache().remove(key); | 232 cacheFactory.getCache().remove(key); |
209 } | 233 } |
210 } | 234 } |
211 | 235 |
212 /** | |
213 * @see de.intevation.gnv.transition.TransitionBase#purifyResult(java.util.Collection, | |
214 * java.lang.String) | |
215 */ | |
216 @Override | |
217 protected void purifyResult(Collection<Result> result, String uuid) { | |
218 log.debug("OutputTransitionBase.purifyResult"); | |
219 if (CacheFactory.getInstance().isInitialized()) { | |
220 String key = uuid + super.getID(); | |
221 log.debug("Hash for Queryelements: " + key); | |
222 CacheFactory.getInstance().getCache().put(new net.sf.ehcache.Element(key, result)); | |
223 } | |
224 } | |
225 | |
226 | |
227 protected void purifyChart(Object chart, String uuid) { | 236 protected void purifyChart(Object chart, String uuid) { |
228 log.debug("Prufify chart [" + uuid + "]"); | 237 log.debug("Prufify chart [" + uuid + "]"); |
229 CacheFactory cacheFactory = CacheFactory.getInstance(); | 238 CacheFactory cacheFactory = CacheFactory.getInstance(); |
230 if (cacheFactory.isInitialized()) { | 239 if (cacheFactory.isInitialized()) { |
231 String key = "chart_" + uuid + getID(); | 240 String key = "chart_" + uuid + getID(); |