annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelectMinfo.java @ 4357:11cf29eb002c

FacetTypes: New type: exreme_wq_curve_base (for the Stuetz-Q-Poits).
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 02 Nov 2012 11:58:11 +0100
parents edaa2297aea3
children
rev   line source
2693
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.states;
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import org.apache.log4j.Logger;
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 import org.w3c.dom.Element;
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 import de.intevation.artifacts.Artifact;
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8 import de.intevation.artifacts.CallContext;
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import de.intevation.artifacts.CallMeta;
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import de.intevation.artifacts.common.utils.XMLUtils;
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import de.intevation.artifactdatabase.data.StateData;
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import de.intevation.flys.artifacts.FLYSArtifact;
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import de.intevation.flys.artifacts.resources.Resources;
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 /**
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 */
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 public class CalculationSelectMinfo extends DefaultState {
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 /** The logger that is used in this class. */
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 private static Logger logger = Logger.getLogger(CalculationSelectMinfo.class);
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 public static final String FIELD_MODE = "calculation_mode";
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 public static final String CALC_BED_MIDDLE = "calc.bed.middle";
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 public static final String CALC_BED_DIFF = "calc.bed.diff";
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 public static final String CALC_BED_QUALITY = "calc.bed.quality";
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 public static final String CALC_SEDIMENT_LOAD = "calc.sediment.load";
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 public static final String CALC_FLOW_VELOCITY = "calc.flow.velocity";
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 public static final String CALC_SQ_RELATION = "calc.sq.relation";
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 /** An array that holds all available calculation modes. */
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 public static final String[] CALCULATIONS = {
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 CALC_BED_MIDDLE,
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 CALC_BED_DIFF,
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 CALC_BED_QUALITY,
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 CALC_SEDIMENT_LOAD,
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 CALC_FLOW_VELOCITY,
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 CALC_SQ_RELATION
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 };
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 /** Error message that is thrown if no mode has been chosen. */
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 public static final String ERROR_NO_CALCULATION_MODE =
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 "error_feed_no_calculation_mode";
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 /** Error message that is thrown if an invalid calculation mode has been
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 * chosen. */
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 public static final String ERROR_INVALID_CALCULATION_MODE =
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 "error_feed_invalid_calculation_mode";
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 public CalculationSelectMinfo() {
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 }
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 @Override
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 protected Element[] createItems(
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 XMLUtils.ElementCreator cr,
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 Artifact artifact,
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 String name,
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 CallContext context)
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 {
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 CallMeta meta = context.getMeta();
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 Element[] calcs = new Element[CALCULATIONS.length];
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 for (int i = 0; i < CALCULATIONS.length; ++i) {
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 String calc = CALCULATIONS[i];
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 calcs[i] = createItem(
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 cr, new String[] {
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 Resources.getMsg(meta, calc, calc),
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 calc
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 });
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 }
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 return calcs;
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 }
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 @Override
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 public boolean validate(Artifact artifact)
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 throws IllegalArgumentException
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 {
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 logger.debug("CalculationSelect.validate");
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 FLYSArtifact flys = (FLYSArtifact) artifact;
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 StateData data = getData(flys, FIELD_MODE);
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 String calc = (data != null) ? (String) data.getValue() : null;
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 if (calc == null) {
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE);
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 }
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 calc = calc.trim().toLowerCase();
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 for (String mode: CALCULATIONS) {
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 if (mode.equals(calc)) {
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 return true;
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 }
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 }
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 throw new IllegalArgumentException(ERROR_INVALID_CALCULATION_MODE);
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 }
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 }
edaa2297aea3 Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org