comparison flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java @ 2038:f73036b991e2

Bugfix: repaired broken named values in exports - the last solution had bad side effects. flys-artifacts/trunk@3515 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 21 Dec 2011 15:44:41 +0000
parents 3ebbe497d7f7
children e5f01f2325c9
comparison
equal deleted inserted replaced
2037:986820795c3b 2038:f73036b991e2
37 /** The logger that is used in this utility. */ 37 /** The logger that is used in this utility. */
38 private static Logger logger = Logger.getLogger(FLYSUtils.class); 38 private static Logger logger = Logger.getLogger(FLYSUtils.class);
39 39
40 public static enum KM_MODE { RANGE, LOCATIONS, NONE }; 40 public static enum KM_MODE { RANGE, LOCATIONS, NONE };
41 41
42 /**
43 * An enum that represents the 5 possible WQ modes in FLYS. The 5 values are
44 * <i>QFREE</i> <i>QGAUGE</i> <i>WGAUGE</i> <i>WFREE</i> and <i>NONE</i>.
45 */
46 public static enum WQ_MODE { QFREE, QGAUGE, WFREE, WGAUGE, NONE };
47
42 public static final String XPATH_RIVER_PROJECTION = 48 public static final String XPATH_RIVER_PROJECTION =
43 "/artifact-database/floodmap/river[@name=$name]/srid/@value"; 49 "/artifact-database/floodmap/river[@name=$name]/srid/@value";
44 50
45 public static final String XPATH_SHAPEFILE_DIR = 51 public static final String XPATH_SHAPEFILE_DIR =
46 "/artifact-database/floodmap/shapefile-path/@value"; 52 "/artifact-database/floodmap/shapefile-path/@value";
128 SessionFactory sf = SessionFactoryProvider.getSessionFactory(); 134 SessionFactory sf = SessionFactoryProvider.getSessionFactory();
129 135
130 String d = SessionFactoryProvider.getDriver((SessionFactoryImpl) sf); 136 String d = SessionFactoryProvider.getDriver((SessionFactoryImpl) sf);
131 137
132 return d != null ? d.indexOf("Oracle") >= 0 : false; 138 return d != null ? d.indexOf("Oracle") >= 0 : false;
139 }
140
141
142 /**
143 * This method returns an WQ_MODE enum which is based on the parameters
144 * stored in <i>flys</i> Artifact. If there is no <i>wq_mode</i> parameter
145 * existing, WQ_MODE.NONE is returned.
146 *
147 * @param flys The FLYSArtifact that stores wq mode relevant parameters.
148 *
149 * @return an enum WQ_MODE.
150 */
151 public static WQ_MODE getWQMode(FLYSArtifact flys) {
152 String mode = flys.getDataAsString("wq_mode");
153 boolean free = flys.getDataAsBoolean("wq_free");
154
155 if (mode != null && mode.equals("Q")) {
156 return free ? WQ_MODE.QFREE : WQ_MODE.QGAUGE;
157 }
158 else if (mode != null && mode.equals("W")) {
159 return free ? WQ_MODE.WFREE : WQ_MODE.WGAUGE;
160 }
161 else {
162 return WQ_MODE.NONE;
163 }
133 } 164 }
134 165
135 166
136 public static KM_MODE getKmRangeMode(FLYSArtifact flys) { 167 public static KM_MODE getKmRangeMode(FLYSArtifact flys) {
137 String mode = flys.getDataAsString("ld_mode"); 168 String mode = flys.getDataAsString("ld_mode");
351 ? "Q(" + nf.format(v) + ")" 382 ? "Q(" + nf.format(v) + ")"
352 : "Q(" + prefix + nf.format(v) + ")"; 383 : "Q(" + prefix + nf.format(v) + ")";
353 } 384 }
354 385
355 386
387 /**
388 * Returns the named main value if a Q was selected and if this Q fits to a
389 * named main value. Otherwise, this function returns null.
390 *
391 * @param winfo The WINFO Artifact.
392 * @param value The Q (or W) value.
393 *
394 * @return a named main value or null.
395 */
396 public static String getNamedMainValue(WINFOArtifact winfo, double value) {
397 WQ_MODE wqmode = getWQMode(winfo);
398
399 if (wqmode != WQ_MODE.QGAUGE) {
400 return null;
401 }
402 else {
403 return getNamedMainValue(winfo.getGauge(), value);
404 }
405 }
406
407
356 public static String getNamedMainValue(Gauge gauge, double value) { 408 public static String getNamedMainValue(Gauge gauge, double value) {
357 List<MainValue> mainValues = gauge.getMainValues(); 409 List<MainValue> mainValues = gauge.getMainValues();
358 logger.debug("Search named main value for: " + value); 410 logger.debug("Search named main value for: " + value);
359 411
360 for (MainValue mv: mainValues) { 412 for (MainValue mv: mainValues) {

http://dive4elements.wald.intevation.org