[PATCH] (issue1577, issue1494) Wrap wst name depending on Q > 0
Wald Commits
scm-commit at wald.intevation.org
Tue Dec 17 17:21:40 CET 2013
# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1387297297 -3600
# Node ID 5484818087de311c53a23fd268197ff8d0ddbbf1
# Parent c6f89989de8494e6e9280e59ce3fa5f5778a1d9c
(issue1577, issue1494) Wrap wst name depending on Q > 0
diff -r c6f89989de84 -r 5484818087de artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsFactory.java
--- 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;
}
diff -r c6f89989de84 -r 5484818087de artifacts/src/main/java/org/dive4elements/river/artifacts/states/StaticWQKmsState.java
--- 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,
More information about the Dive4elements-commits
mailing list