changeset 7703:5484818087de

(issue1577, issue1494) Wrap wst name depending on Q > 0
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 17 Dec 2013 17:21:37 +0100
parents c6f89989de84
children a877d2680a4a
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsFactory.java artifacts/src/main/java/org/dive4elements/river/artifacts/states/StaticWQKmsState.java
diffstat 2 files changed, 53 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsFactory.java	Tue Dec 17 14:43:26 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsFactory.java	Tue Dec 17 17:21:37 2013 +0100
@@ -46,10 +46,24 @@
         "WHERE wst_id = :wst_id AND position = :column_pos";
 
     /** Query to get name and kind for wst_id and column_pos. */
-    public static final String SQL_SELECT_NAME_KIND =
-        "SELECT wst_columns.name, wsts.kind " +
-        "FROM wst_columns JOIN wsts on wst_id = wsts.id "+
-        "WHERE wst_id = :wst_id AND position = :column_pos";
+    public static final String SQL_SELECT_Q_NAME =
+        "SELECT wqr.q, wc.name " +
+        "FROM wst_column_q_ranges wcqr " +
+        "JOIN wst_q_ranges wqr ON wcqr.wst_q_range_id = wqr.id " +
+        "JOIN wst_columns wc ON wcqr.wst_column_id = wc.id " +
+        "JOIN wsts ON wc.wst_id = wsts.id " +
+        "WHERE wc.wst_id = :wst_id AND wc.position = :column_pos";
+/*
+ Test statement:
+    SELECT wqr.q, wc.name
+    FROM wst_column_q_ranges wcqr
+    JOIN wst_q_ranges wqr ON wcqr.wst_q_range_id = wqr.id
+    JOIN wst_columns wc ON wcqr.wst_column_id = wc.id
+    JOIN wsts ON wc.wst_id = wsts.id
+    WHERE wc.wst_id = 1817 AND wc.position = 29; 
+*/
+
+
 
     /** Query to get name (description) for wst_id. */
     public static final String SQL_SELECT_WST_NAME =
@@ -57,10 +71,13 @@
         "WHERE id = :wst_id";
 
     /** Query to get name (description) and kind for wst_id. */
-    public static final String SQL_SELECT_WST_NAME_KIND =
-        "SELECT description, kind from wsts "+
-        "WHERE id = :wst_id";
-
+    public static final String SQL_SELECT_WST_Q_NAME =
+        "SELECT wqr.q, wc.name " +
+        "FROM wst_column_q_ranges wcqr " +
+        "JOIN wst_q_ranges wqr ON wcqr.wst_q_range_id = wqr.id " +
+        "JOIN wst_columns wc ON wcqr.wst_column_id = wc.id " +
+        "JOIN wsts ON wc.wst_id = wsts.id " +
+        "WHERE wc.wst_id = :wst_id";
 
     private WKmsFactory() {
     }
@@ -99,27 +116,7 @@
 
     /** Get name for a WKms wrapped in W, if suitable. */
     public static String getWKmsNameWWrapped(int wst_id) {
-        log.debug("WKmsFactory.getWKmsNameWWrapped wst_id/" + wst_id);
-
-        String name = null;
-        Session session = SessionHolder.HOLDER.get();
-
-        SQLQuery nameQuery = session.createSQLQuery(SQL_SELECT_WST_NAME_KIND)
-            .addScalar("description", StandardBasicTypes.STRING)
-            .addScalar("kind", StandardBasicTypes.INTEGER);
-        nameQuery.setInteger("wst_id", wst_id);
-
-        List<Object[]> names = nameQuery.list();
-
-        if (names.size() >= 1) {
-            Object[] row = names.get(0);
-            name = (String) row[0];
-            Integer kind = (Integer) row[1];
-            if (kind == 0 || kind == 2 || kind == 3)
-                name = "W(" + name + ")";
-        }
-
-        return name;
+        return getWKmsNameWWrapped(-1, wst_id);
     }
 
 
@@ -130,22 +127,39 @@
         String name = null;
         Session session = SessionHolder.HOLDER.get();
 
-        SQLQuery nameQuery = session.createSQLQuery(SQL_SELECT_NAME_KIND)
-            .addScalar("name", StandardBasicTypes.STRING)
-            .addScalar("kind", StandardBasicTypes.INTEGER);
+        SQLQuery nameQuery;
+        if (column != -1) {
+            nameQuery = session.createSQLQuery(SQL_SELECT_Q_NAME);
+            nameQuery.setInteger("column_pos", column);
+        } else {
+            nameQuery = session.createSQLQuery(SQL_SELECT_WST_Q_NAME);
+        }
+
+        nameQuery.addScalar("q", StandardBasicTypes.DOUBLE)
+                 .addScalar("name", StandardBasicTypes.STRING);
         nameQuery.setInteger("wst_id",     wst_id);
-        nameQuery.setInteger("column_pos", column);
 
         List<Object[]> names = nameQuery.list();
 
         if (names.size() >= 1) {
             Object[] row = names.get(0);
-            name = (String) row[0];
-            Integer kind = (Integer) row[1];
-            if (kind == 0 || kind == 2 || kind == 3)
+            Double q = (Double) row[0];
+            name = (String) row[1];
+            if (q >= 0) {
                 name = "W(" + name + ")";
+            }
+        } else {
+            // This should handle the case of Q = NULL
+            if (column != -1) {
+                name = getWKmsName(column, wst_id);
+            } else {
+                name = getWKmsName(wst_id);
+            }
         }
 
+        log.debug("WKmsFactory.getWKmsNameWWrapped c/" + column +
+                ", wst_id/" + wst_id + " = name/ " + name);
+
         return name;
     }
 
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/StaticWQKmsState.java	Tue Dec 17 14:43:26 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/StaticWQKmsState.java	Tue Dec 17 17:21:37 2013 +0100
@@ -129,7 +129,9 @@
              wkmsName);
         facets.add(csFacet);
 
-        wkmsName = "W (" + wkmsName + ")";
+        if (!qEmpty) {
+            wkmsName = "W (" + wkmsName + ")";
+        }
 
         Facet wfacet = new WQKmsFacet(
             STATIC_WQKMS_W,

http://dive4elements.wald.intevation.org