changeset 7686:7484132b2fbb

issue1577: Add W-Wrapping of wst-names in WKmsFactory if kind is one of a kind.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 12 Dec 2013 07:57:13 +0100
parents 270946b97539
children f4b3861712a4
files artifacts/src/main/java/org/dive4elements/river/artifacts/StaticWKmsArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsFactory.java
diffstat 2 files changed, 70 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/StaticWKmsArtifact.java	Wed Dec 11 17:13:26 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/StaticWKmsArtifact.java	Thu Dec 12 07:57:13 2013 +0100
@@ -134,10 +134,14 @@
 
                 String wkmsName;
                 if (col >= 0) {
-                    wkmsName = WKmsFactory.getWKmsName(col, wst);
+                    // The W-Wrapping could be done in here (like in
+                    // StaticWQKmsArtifact), with benefit of i18nation,
+                    // but slower execution (it wrappes based on kind
+                    // which can be fetched in same sql query).
+                    wkmsName = WKmsFactory.getWKmsNameWWrapped(col, wst);
                 }
                 else {
-                    wkmsName = WKmsFactory.getWKmsName(wst);
+                    wkmsName = WKmsFactory.getWKmsNameWWrapped(wst);
                 }
 
                 String name;
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsFactory.java	Wed Dec 11 17:13:26 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsFactory.java	Thu Dec 12 07:57:13 2013 +0100
@@ -45,11 +45,22 @@
         "FROM wst_columns "+
         "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";
+
     /** Query to get name (description) for wst_id. */
     public static final String SQL_SELECT_WST_NAME =
         "SELECT description from wsts "+
         "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";
+
 
     private WKmsFactory() {
     }
@@ -86,6 +97,59 @@
         return values;
     }
 
+    /** 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;
+    }
+
+
+    /** Get name for a WKms wrapped in W, if suitable. */
+    public static String getWKmsNameWWrapped(int column, int wst_id) {
+        log.debug("WKmsFactory.getWKmsNameWWrapped c/" + column + ", wst_id/" + wst_id);
+
+        String name = null;
+        Session session = SessionHolder.HOLDER.get();
+
+        SQLQuery nameQuery = session.createSQLQuery(SQL_SELECT_NAME_KIND)
+            .addScalar("name", StandardBasicTypes.STRING)
+            .addScalar("kind", StandardBasicTypes.INTEGER);
+        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)
+                name = "W(" + name + ")";
+        }
+
+        return name;
+    }
+
+
     /** Get name for a WKms. */
     public static String getWKmsName(int wst_id) {
         log.debug("WKmsFactory.getWKmsName wst_id/" + wst_id);

http://dive4elements.wald.intevation.org