9276
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by Intevation GmbH |
|
3 * |
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
6 * documentation coming with Dive4Elements River for details. |
|
7 */ |
|
8 package org.dive4elements.river.artifacts.bundu.bezugswst; |
|
9 |
|
10 import org.apache.log4j.Logger; |
|
11 import org.dive4elements.artifacts.Artifact; |
9277
|
12 import org.dive4elements.artifacts.CallContext; |
|
13 import org.dive4elements.artifacts.common.utils.XMLUtils; |
9276
|
14 import org.dive4elements.river.artifacts.D4EArtifact; |
|
15 import org.dive4elements.river.artifacts.model.RangeWithValues; |
|
16 import org.dive4elements.river.artifacts.states.WQAdapted; |
9277
|
17 import org.w3c.dom.Element; |
9276
|
18 |
|
19 /** |
|
20 * State to input W/Q data for fixings |
9277
|
21 * |
9276
|
22 * @author <a href="mailto:aheinecke@intevation.de">Andre Heinecke</a> |
|
23 */ |
|
24 public class BunduWstWQFixing extends WQAdapted { |
|
25 |
|
26 /** The log used in this state. */ |
|
27 private static Logger log = Logger.getLogger(BunduWstWQFixing.class); |
|
28 |
9277
|
29 @Override |
|
30 protected String getUIProvider() { |
|
31 return "bundu_wst_wq_panel"; |
|
32 } |
|
33 |
9276
|
34 /** Simple sanity check if values are positive numbers **/ |
|
35 @Override |
|
36 public boolean validate(final Artifact artifact) throws IllegalArgumentException { |
|
37 log.debug("BunduWstWQFixing.validate"); |
|
38 |
|
39 final RangeWithValues[] rwvs = extractInput(getData((D4EArtifact) artifact, "wq_values")); |
|
40 |
|
41 if (rwvs == null) { |
|
42 throw new IllegalArgumentException("error_missing_wq_data"); |
|
43 } |
|
44 |
|
45 for (final RangeWithValues rwv : rwvs) { |
|
46 final double[] values = rwv.getValues(); |
|
47 for (final double val : values) { |
|
48 if (val <= 0) { |
|
49 throw new IllegalArgumentException("error_validate_positive"); |
|
50 } |
|
51 } |
|
52 } |
|
53 |
|
54 return true; |
|
55 } |
|
56 |
9277
|
57 // adding bezugsjahr and dauer to client |
|
58 |
9276
|
59 @Override |
9277
|
60 protected Element[] createItems(final XMLUtils.ElementCreator ec, final Artifact artifact, final String name, final CallContext context) { |
|
61 |
|
62 final Element[] defaultElements = super.createItems(ec, artifact, name, context); |
|
63 |
|
64 final BunduAccess access = new BunduAccess((D4EArtifact) artifact); |
|
65 |
|
66 final int bezugsjahr = access.getBezugsJahr(); |
|
67 final int qSeriesLength = access.getQSeriesLength(); |
|
68 final String[] keys = new String[] { "ignore_q_series_length", "ignore_bezugsjahr" }; |
|
69 final String[] values = new String[] { String.valueOf(qSeriesLength), String.valueOf(bezugsjahr) }; |
|
70 |
|
71 return FixationChoice.appendElements(ec, defaultElements, keys, values); |
|
72 |
9276
|
73 } |
9277
|
74 |
9276
|
75 } |