Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DGMSelect.java @ 2013:9d5f339d83a3
#380 Validate the user selected DEM in the server.
flys-artifacts/trunk@3462 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 19 Dec 2011 10:01:17 +0000 |
parents | 8a2cbf947395 |
children | a075f26a516c |
comparison
equal
deleted
inserted
replaced
2012:514d26021728 | 2013:9d5f339d83a3 |
---|---|
4 | 4 |
5 import org.w3c.dom.Element; | 5 import org.w3c.dom.Element; |
6 | 6 |
7 import org.apache.log4j.Logger; | 7 import org.apache.log4j.Logger; |
8 | 8 |
9 import de.intevation.artifacts.Artifact; | |
9 import de.intevation.artifacts.CallContext; | 10 import de.intevation.artifacts.CallContext; |
10 | 11 |
11 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | 12 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; |
12 | 13 |
14 import de.intevation.flys.model.DGM; | |
15 import de.intevation.flys.model.River; | |
16 | |
13 import de.intevation.flys.artifacts.FLYSArtifact; | 17 import de.intevation.flys.artifacts.FLYSArtifact; |
14 import de.intevation.flys.model.DGM; | 18 import de.intevation.flys.utils.FLYSUtils; |
15 | 19 |
16 | 20 |
17 /** | 21 /** |
18 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
19 */ | 23 */ |
20 public class DGMSelect extends DefaultState { | 24 public class DGMSelect extends DefaultState { |
21 | 25 |
22 private static final Logger logger = Logger.getLogger(DGMSelect.class); | 26 private static final Logger logger = Logger.getLogger(DGMSelect.class); |
27 | |
28 public static final String ERR_EMPTY = "error_no_dgm_selected"; | |
29 public static final String ERR_INVALID_DGM = "error_invalid_dgm_selected"; | |
30 public static final String ERR_BAD_DGM_RANGE = "error_bad_dgm_range"; | |
31 public static final String ERR_BAD_DGM_RIVER = "error_bad_dgm_river"; | |
23 | 32 |
24 | 33 |
25 @Override | 34 @Override |
26 protected String getUIProvider() { | 35 protected String getUIProvider() { |
27 return "dgm_datacage_panel"; | 36 return "dgm_datacage_panel"; |
64 logger.warn("Cannot parse int value: '" + value + "'"); | 73 logger.warn("Cannot parse int value: '" + value + "'"); |
65 } | 74 } |
66 | 75 |
67 return ""; | 76 return ""; |
68 } | 77 } |
78 | |
79 | |
80 @Override | |
81 public boolean validate(Artifact artifact) | |
82 throws IllegalArgumentException | |
83 { | |
84 FLYSArtifact flys = (FLYSArtifact) artifact; | |
85 | |
86 DGM dgm = getDGM(flys); | |
87 | |
88 if (dgm == null) { | |
89 throw new IllegalArgumentException(ERR_INVALID_DGM); | |
90 } | |
91 | |
92 double l = dgm.getLower().doubleValue(); | |
93 double u = dgm.getUpper().doubleValue(); | |
94 | |
95 double[] range = FLYSUtils.getKmFromTo(flys); | |
96 | |
97 if (range[0] < l || range[0] > u || range[1] < l || range[1] > u) { | |
98 throw new IllegalArgumentException(ERR_BAD_DGM_RANGE); | |
99 } | |
100 | |
101 River selectedRiver = FLYSUtils.getRiver(flys); | |
102 River dgmRiver = dgm.getRiver(); | |
103 | |
104 if (selectedRiver != dgmRiver) { | |
105 throw new IllegalArgumentException(ERR_BAD_DGM_RIVER); | |
106 } | |
107 | |
108 return true; | |
109 } | |
110 | |
111 | |
112 /** | |
113 * Returns the DGM specified in the parameters of <i>flys</i>. | |
114 * | |
115 * @param flys The FLYSArtifact that knows the ID of a DGM. | |
116 * | |
117 * @throws IllegalArgumentException If the FLYSArtifact doesn't know the ID | |
118 * of a DGM. | |
119 * | |
120 * @return the DGM specified by FLYSArtifact's parameters. | |
121 */ | |
122 public static DGM getDGM(FLYSArtifact flys) | |
123 throws IllegalArgumentException | |
124 { | |
125 try { | |
126 Integer dgmId = flys.getDataAsInteger("dgm"); | |
127 if (dgmId == null) { | |
128 throw new IllegalArgumentException(ERR_EMPTY); | |
129 } | |
130 | |
131 logger.debug("Found selected dgm: '" + dgmId + "'"); | |
132 | |
133 return DGM.getDGM(dgmId); | |
134 } | |
135 catch (NumberFormatException nfe) { | |
136 throw new IllegalArgumentException(ERR_INVALID_DGM); | |
137 } | |
138 } | |
69 } | 139 } |
70 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 140 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |