annotate gnv-artifacts/src/main/java/de/intevation/gnv/state/SingleInputState.java @ 1129:ccfa07b88476

merged geo-backend
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:01 +0200
parents f953c9a559d8
children
rev   line source
1115
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1038
diff changeset
1 /*
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1038
diff changeset
2 * Copyright (c) 2010 by Intevation GmbH
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1038
diff changeset
3 *
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1038
diff changeset
4 * This program is free software under the LGPL (>=v2.1)
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1038
diff changeset
5 * Read the file LGPL.txt coming with the software for details
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1038
diff changeset
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1038
diff changeset
7 */
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1038
diff changeset
8
335
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
9 package de.intevation.gnv.state;
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
10
860
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
11 import de.intevation.artifacts.CallContext;
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
12
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
13 import de.intevation.gnv.artifacts.ressource.RessourceFactory;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
14 import de.intevation.gnv.geobackend.base.Result;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
15 import de.intevation.gnv.state.describedata.DefaultSingleValueDescribeData;
860
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
16 import de.intevation.gnv.state.exception.StateException;
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
17 import de.intevation.gnv.utils.InputValidator;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 778
diff changeset
18
335
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
19 import java.util.ArrayList;
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
20 import java.util.Collection;
860
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
21 import java.util.Iterator;
470
b7bb66440cc8 Added mechanism for advancing to previous states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 335
diff changeset
22 import java.util.List;
860
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
23 import java.util.Locale;
335
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
24
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
25 import org.apache.log4j.Logger;
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
26
860
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
27 import org.w3c.dom.Document;
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
28
335
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
29 /**
796
a5526908f92f Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
30 * This state handles single user input. The user is allowed to select just one
a5526908f92f Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
31 * value.
a5526908f92f Added javadoc in state package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 780
diff changeset
32 *
780
c4156275c1e1 Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 779
diff changeset
33 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 607
diff changeset
34 *
335
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
35 */
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
36 public class SingleInputState extends StateBase {
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
37
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
38 /**
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
39 * the logger, used to log exceptions and additonaly information
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
40 */
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
41 private static Logger log = Logger.getLogger(SingleInputState.class);
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
42
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
43 private static final long serialVersionUID = -6169497306324917318L;
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
44
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
45 /**
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
46 * Constructor
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
47 */
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
48 public SingleInputState() {
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
49 }
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
50
815
22c18083225e Removed compiler warnings while JavaDoc generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 796
diff changeset
51
335
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
52 @Override
607
292fbcd5e9ac Parted the cache blob into pieces and changed the way how user input is stored on each state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 473
diff changeset
53 protected List<Object> purifyResult(Collection<Result> result, String uuid) {
335
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
54 log.debug("SingleInputState.purifyResult");
607
292fbcd5e9ac Parted the cache blob into pieces and changed the way how user input is stored on each state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 473
diff changeset
55 List<Object> describeData = new ArrayList<Object>();
292fbcd5e9ac Parted the cache blob into pieces and changed the way how user input is stored on each state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 473
diff changeset
56
335
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
57 String value = null;
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
58 if (result != null && result.size() == 1) {
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
59 Result tmpItem = result.iterator().next();
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
60 value = tmpItem.getObject("MAX").toString();
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
61 } else {
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
62 value = "";
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
63 }
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
64
473
a6a33ef35809 Added support to step back to previous states. Add state names to xform nodes in describe document and append old targets to list of reachable targets.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 470
diff changeset
65 describeData.add(new DefaultSingleValueDescribeData(
a6a33ef35809 Added support to step back to previous states. Add state names to xform nodes in describe document and append old targets to list of reachable targets.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 470
diff changeset
66 this.dataName, value, getID()));
607
292fbcd5e9ac Parted the cache blob into pieces and changed the way how user input is stored on each state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 473
diff changeset
67
292fbcd5e9ac Parted the cache blob into pieces and changed the way how user input is stored on each state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 473
diff changeset
68 return describeData;
335
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
69 }
860
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
70
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
71 /**
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
72 * This feed method needs a collection of two InputData objects. These
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
73 * objects' values need to be a datetime string which is turned into a Date
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
74 * object. Afterwards, the given dates are validated. Min and max date need
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
75 * to be in range of the min and max date retrieved by
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
76 * {@link #getDescibeData(java.lang.String)}.
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
77 */
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
78 @Override
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
79 public Document feed(
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
80 CallContext context,
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
81 Collection<InputData> inputData,
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
82 String uuid)
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
83 throws StateException {
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
84 RessourceFactory resFactory = RessourceFactory.getInstance();
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
85 Locale[] serverLocales = resFactory.getLocales();
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
86 Locale locale = context.getMeta().getPreferredLocale(
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
87 serverLocales);
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
88
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
89 if (inputData == null) {
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
90 String msg = "No input data given.";
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
91 log.warn(msg);
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
92 return feedFailure(msg);
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
93 }
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
94
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
95 Iterator<InputData> it = inputData.iterator();
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
96 InputData tmpItem = it.next();
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
97 InputValue inputValue = inputValues.get(tmpItem.getName());
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
98
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
99 if (inputValue == null) {
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
100 String msg = resFactory.getRessource(
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
101 locale,
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
102 EXCEPTION_INVALID_INPUT,
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
103 EXCEPTION_INVALID_INPUT);
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
104 log.warn(msg);
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
105 return feedFailure(msg);
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
106 }
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
107
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
108 boolean valid = InputValidator.isInputValid(
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
109 tmpItem.getValue(), inputValue.getType());
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
110
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
111 if (valid) {
1038
9981452c7e75 First step: Added a new state handling the selection between vector or scalar and a new transition in timeseries to provide vector values (issue27).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 860
diff changeset
112 String[] desc = getDescriptionForInputData(tmpItem, context, uuid);
860
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
113 tmpItem.setDescription(desc);
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
114
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
115 this.inputData.put(tmpItem.getName(), tmpItem);
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
116 return feedSuccess();
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
117 }
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
118
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
119 else {
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
120 String msg = resFactory.getRessource(
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
121 locale,
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
122 EXCEPTION_INVALID_INPUT,
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
123 EXCEPTION_INVALID_INPUT);
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
124 log.warn(msg);
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
125 return feedFailure(msg);
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
126 }
f94a95009423 Improved the input validator: empty strings are invalid (issue251).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
127 }
335
e964a3d8f7bc Some Refactoring work done.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
128 }
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 815
diff changeset
129 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org