comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java @ 610:6484464d2059

Changed the mechanism for searching for specific parameter collections. gnv-artifacts/trunk@676 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 11 Feb 2010 11:58:39 +0000
parents cef17cc90fd0
children 93978859fa9e
comparison
equal deleted inserted replaced
609:22e65fb4c64a 610:6484464d2059
17 import de.intevation.gnv.geobackend.base.query.QueryExecutor; 17 import de.intevation.gnv.geobackend.base.query.QueryExecutor;
18 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; 18 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory;
19 19
20 import de.intevation.gnv.geobackend.base.query.exception.QueryException; 20 import de.intevation.gnv.geobackend.base.query.exception.QueryException;
21 21
22 import de.intevation.gnv.state.describedata.MinMaxDescribeData;
23
22 import de.intevation.gnv.state.exception.StateException; 24 import de.intevation.gnv.state.exception.StateException;
25
26 import de.intevation.gnv.utils.InputValidator;
23 27
24 import java.io.OutputStream; 28 import java.io.OutputStream;
25 29
26 import java.util.ArrayList; 30 import java.util.ArrayList;
27 import java.util.Collection; 31 import java.util.Collection;
32 import java.util.HashMap;
33 import java.util.Iterator;
28 import java.util.Locale; 34 import java.util.Locale;
29 35
30 import org.apache.log4j.Logger; 36 import org.apache.log4j.Logger;
31 37
32 import org.w3c.dom.Document; 38 import org.w3c.dom.Document;
168 */ 174 */
169 protected Object getChartResult(String uuid, CallContext callContext) { 175 protected Object getChartResult(String uuid, CallContext callContext) {
170 log.debug("OutputStateBase.getChartResult"); 176 log.debug("OutputStateBase.getChartResult");
171 Object result = null; 177 Object result = null;
172 if (CacheFactory.getInstance().isInitialized()) { 178 if (CacheFactory.getInstance().isInitialized()) {
173 String key = uuid + super.getID(); 179 String key = "chart_" + getHash();
174 log.debug("Hash for Queryelements: " + key); 180 log.debug("Hash for Queryelements: " + key);
175 net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key); 181 net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key);
176 if (value != null) { 182 if (value != null) {
177 result = value.getObjectValue(); 183 result = value.getObjectValue();
178 }else{ 184 }else{
188 194
189 protected Object getChartFromCache(String uuid, CallContext callContext) { 195 protected Object getChartFromCache(String uuid, CallContext callContext) {
190 log.debug("Fetch chart [" + uuid + "] from cache"); 196 log.debug("Fetch chart [" + uuid + "] from cache");
191 CacheFactory cacheFactory = CacheFactory.getInstance(); 197 CacheFactory cacheFactory = CacheFactory.getInstance();
192 if (cacheFactory.isInitialized()) { 198 if (cacheFactory.isInitialized()) {
193 String key = "chart_" + uuid + super.getID(); 199 String key = "chart_" + getHash();
194 net.sf.ehcache.Element object = cacheFactory.getCache().get(key); 200 net.sf.ehcache.Element object = cacheFactory.getCache().get(key);
195 201
196 if (object != null) { 202 if (object != null) {
197 return object.getObjectValue(); 203 return object.getObjectValue();
198 } 204 }
236 } 242 }
237 243
238 protected void removeChartResult(String uuid) { 244 protected void removeChartResult(String uuid) {
239 log.debug("OutputStateBase.getChartResult"); 245 log.debug("OutputStateBase.getChartResult");
240 if (CacheFactory.getInstance().isInitialized()) { 246 if (CacheFactory.getInstance().isInitialized()) {
241 String key = uuid + super.getID(); 247 String key = "chart_" + getHash();
242 log.debug("Hash for Queryelements: " + key); 248 log.debug("Hash for Queryelements: " + key);
243 net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key); 249 net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key);
244 if (value != null) { 250 if (value != null) {
245 CacheFactory.getInstance().getCache().remove(key); 251 CacheFactory.getInstance().getCache().remove(key);
246 } 252 }
250 protected void removeChart(String uuid) { 256 protected void removeChart(String uuid) {
251 log.debug("OutputStateBase.removeChart from cache"); 257 log.debug("OutputStateBase.removeChart from cache");
252 258
253 CacheFactory cacheFactory = CacheFactory.getInstance(); 259 CacheFactory cacheFactory = CacheFactory.getInstance();
254 if (cacheFactory.isInitialized()) { 260 if (cacheFactory.isInitialized()) {
255 String key = "chart_" + uuid + super.getID(); 261 String key = "chart_" + getHash();
256 net.sf.ehcache.Element object = cacheFactory.getCache().get(key); 262 net.sf.ehcache.Element object = cacheFactory.getCache().get(key);
257 if (object != null) 263 if (object != null)
258 cacheFactory.getCache().remove(key); 264 cacheFactory.getCache().remove(key);
259 } 265 }
260 } 266 }
261 267
262 protected void purifyChart(Object chart, String uuid) { 268 protected void purifyChart(Object chart, String uuid) {
263 log.debug("Prufify chart [" + uuid + "]"); 269 log.debug("Prufify chart [" + uuid + "]");
264 CacheFactory cacheFactory = CacheFactory.getInstance(); 270 CacheFactory cacheFactory = CacheFactory.getInstance();
265 if (cacheFactory.isInitialized()) { 271 if (cacheFactory.isInitialized()) {
266 String key = "chart_" + uuid + getID(); 272 String key = "chart_" + getHash();
267 cacheFactory.getCache().put(new net.sf.ehcache.Element(key, chart)); 273 cacheFactory.getCache().put(new net.sf.ehcache.Element(key, chart));
268 } 274 }
275 }
276
277
278 @Override
279 public void feed(Collection<InputData> inputData, String uuid)
280 throws StateException
281 {
282 putInputData(inputData, uuid);
269 } 283 }
270 284
271 /** 285 /**
272 * @see de.intevation.gnv.state.StateBase#putInputData(java.util.Collection, java.lang.String) 286 * @see de.intevation.gnv.state.StateBase#putInputData(java.util.Collection, java.lang.String)
273 */ 287 */
276 String uuid) 290 String uuid)
277 throws StateException { 291 throws StateException {
278 log.debug("OutputStateBase.putInputData"); 292 log.debug("OutputStateBase.putInputData");
279 this.removeChartResult(uuid); 293 this.removeChartResult(uuid);
280 this.removeChart(uuid); 294 this.removeChart(uuid);
281 super.putInputData(inputData, uuid); 295
296 if (inputData != null) {
297 Iterator<InputData> it = inputData.iterator();
298 InputValidator iv = new InputValidator();
299 while (it.hasNext()) {
300 InputData tmpItem = it.next();
301 Object tmpObj = tmpItem.getObject();
302 InputValue inputValue = this.inputValues.get(tmpItem.getName());
303 if (inputValue != null) {
304 if (this.inputData == null) {
305 this.inputData = new HashMap<String, InputData>(
306 inputData.size());
307 }
308
309 boolean valid = iv.isInputValid(tmpItem.getValue(),
310 inputValue.getType());
311 if (valid) {
312 if (tmpItem.getName().equals(MINVALUEFIELDNAME)){
313 String minValue = tmpItem.getValue();
314 String maxValue = getInputValue4ID(inputData, MAXVALUEFIELDNAME);
315 valid = iv.isInputValid(maxValue,inputValue.getType());
316 if (!valid){
317 String errMsg = "Wrong input for " + tmpItem.getValue()
318 + " is not an " + inputValue.getType()
319 + " Value.";
320 log.warn(errMsg);
321 throw new StateException(errMsg);
322 }
323
324 valid = iv.isInputValid(minValue,
325 maxValue,
326 inputValue.getType());
327 if (!valid){
328 String errMsg = "MaxValue-Input is less than MinValue-Input ";
329 log.warn(errMsg);
330 throw new StateException(errMsg);
331 }
332 }else if (tmpItem.getName().equals(MAXVALUEFIELDNAME)){
333 String minValue = getInputValue4ID(inputData, MINVALUEFIELDNAME);
334 String maxValue = tmpItem.getValue();
335 valid = iv.isInputValid(minValue,inputValue.getType());
336 if (!valid){
337 String errMsg = "Wrong input for " + tmpItem.getValue()
338 + " is not an " + inputValue.getType()
339 + " Value.";
340 log.warn(errMsg);
341 throw new StateException(errMsg);
342 }
343
344 valid = iv.isInputValid(minValue,
345 maxValue,
346 inputValue.getType());
347 if (!valid){
348 String errMsg = "MaxValue-Input is less than MinValue-Input ";
349 log.warn(errMsg);
350 throw new StateException(errMsg);
351 }
352 }
353 this.inputData.put(tmpItem.getName(), tmpItem);
354 } else {
355 String errMsg = "Wrong input for " + tmpItem.getValue()
356 + " is not an " + inputValue.getType()
357 + " Value.";
358 log.warn(errMsg);
359 throw new StateException(errMsg);
360 }
361
362 }
363 else if (tmpObj != null && tmpObj instanceof MinMaxDescribeData) {
364 MinMaxDescribeData data = (MinMaxDescribeData) tmpObj;
365 if (this.inputData == null) {
366 this.inputData = new HashMap<String, InputData>(inputData.size());
367 }
368 this.inputData.put(tmpItem.getName(), tmpItem);
369 this.inputData.put("minvalue", new DefaultInputData("minvalue", (String) data.getMinValue()));
370 this.inputData.put("maxvalue", new DefaultInputData("maxvalue", (String) data.getMaxValue()));
371 }
372 else {
373
374 String errMsg = "No Inputvalue given for Inputdata "
375 + tmpItem.getName();
376 log.warn(errMsg + "Value will be ignored");
377
378 }
379 }
380 } else {
381 log.warn("No Inputdata given");
382 }
282 } 383 }
283 384
284 public void out(String outputMode, Collection<InputData> inputData, 385 public void out(String outputMode, Collection<InputData> inputData,
285 OutputStream outputStream, String uuid, CallMeta callMeta) 386 OutputStream outputStream, String uuid, CallMeta callMeta)
286 throws StateException { 387 throws StateException {

http://dive4elements.wald.intevation.org