[PATCH 13 of 45] (issue1750) Take Static SQ Relations based on a range and merge them together
Wald Commits
scm-commit at wald.intevation.org
Tue Mar 10 17:05:41 CET 2015
# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1423835956 -3600
# Node ID 9a5b3079aad49fc55a1f238ffbea20798904b06e
# Parent 7b210881d6dbb38efc3842a03fa9c52c9cf0a855
(issue1750) Take Static SQ Relations based on a range and merge them together
diff -r 7b210881d6db -r 9a5b3079aad4 artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/StaticSQFactory.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/StaticSQFactory.java Fri Feb 13 13:44:52 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/StaticSQFactory.java Fri Feb 13 14:59:16 2015 +0100
@@ -28,6 +28,17 @@
private static final Logger log =
Logger.getLogger(StaticSQFactory.class);
+ public static final String SQL_STATIONS_AT_RANGE =
+ "SELECT "+
+ "ms.id AS ms_id " +
+ "FROM measurement_station ms " +
+ "JOIN ranges ra ON ra.id = ms.range_id " +
+ "JOIN rivers r ON r.id = ra.river_id " +
+ "WHERE r.name = :river AND " +
+ "ms.range_id = (SELECT range_id " +
+ "FROM measurement_station " +
+ "WHERE id = :ms_id)";
+
public static final String SQL_SQ =
"SELECT " +
"sq.description AS description,"+
@@ -63,6 +74,64 @@
private StaticSQFactory() {
}
+ /** Get SQ relations for a measurement station's location.
+ * Returns all SQRelations for the location of the station and
+ * not just for the station. E.g. for a "Geschiebemessstelle"
+ * and a "Schwebstoffmesstelle" at the same place.*/
+ public static StaticSQContainer getSQRelationsForLocation(
+ String river,
+ int measurementStation
+ ) {
+ Session session = SessionHolder.HOLDER.get();
+ Query query = session.createSQLQuery(SQL_STATIONS_AT_RANGE)
+ .setParameter("river", river)
+ .setParameter("ms_id", measurementStation);
+ /* Take the first container for the station requested. */
+ StaticSQContainer retval = getSQRelations(river, measurementStation);
+
+ /* And some others */
+ List<Integer> list = query.list();
+ if (list == null || list.isEmpty()) {
+ log.error("Did not even find one measurement station. Broken Query?");
+ return retval;
+ }
+
+ for (Integer stationId: list) {
+ log.debug("Collecting SQ Relations for: "+ stationId);
+ if (stationId == measurementStation) {
+ /* Skip the same station */
+ continue;
+ }
+
+ StaticSQContainer additional = getSQRelations(river, stationId);
+ if (additional == null || additional.getSQRelations() == null) {
+ continue;
+ }
+
+ if (retval == null || retval.getSQRelations() == null || retval.getSQRelations().isEmpty()) {
+ /* Old one is empty, just take the new one. */
+ retval = additional;
+ continue;
+ }
+
+ for (StaticSQRelation rel: additional.getSQRelations()) {
+ /* Check if we already have one for this parameter.
+ * This is highly unlikely in the data scheme of things. */
+ List<StaticSQRelation> old = retval.getRelationsByParameter(
+ rel.getParameter());
+ if (old != null || !old.isEmpty()) {
+ log.warn("Multiple SQ relation Parameters found for different " +
+ "measurement_stations at the same range. This should not happen.");
+ continue;
+ }
+ retval.addSQRelation(rel);
+ }
+
+ }
+ return retval;
+ }
+
+
public static StaticSQContainer getSQRelations(
String river,
int measurementStation
@@ -75,7 +144,7 @@
cacheKey = new StaticSQCacheKey(river, measurementStation);
Element element = cache.get(cacheKey);
if (element != null) {
- log.debug("Got static bedheight values from cache");
+ log.debug("Got static sq relations from cache");
return (StaticSQContainer)element.getValue();
}
}
diff -r 7b210881d6db -r 9a5b3079aad4 artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQStaticState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQStaticState.java Fri Feb 13 13:44:52 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQStaticState.java Fri Feb 13 14:59:16 2015 +0100
@@ -68,7 +68,7 @@
}
log.debug("Parsed measurement station: " + ms);
- sqRelations = StaticSQFactory.getSQRelations(river, ms);
+ sqRelations = StaticSQFactory.getSQRelationsForLocation(river, ms);
DateFormat df = new SimpleDateFormat("yyyy");
for (StaticSQRelation.Parameter p: StaticSQRelation.Parameter.values()) {
@@ -143,7 +143,7 @@
}
log.debug("Parsed measurement station: " + ms);
- sqRelations = StaticSQFactory.getSQRelations(river, ms);
+ sqRelations = StaticSQFactory.getSQRelationsForLocation(river, ms);
}
DateFormat df = new SimpleDateFormat("yyyy");
More information about the Dive4Elements-commits
mailing list