[PATCH] bedheight datasource for salix.historical
Wald Commits
scm-commit at wald.intevation.org
Wed Jul 11 14:45:16 CEST 2018
# HG changeset patch
# User gernotbelger
# Date 1531313101 -7200
# Node ID f5cff870853196d9ec1ea0dda7dcc6f74243fe27
# Parent b9505aa78cddf70d5f3c8035d99e3e5d19bbe9e7
bedheight datasource for salix.historical
diff -r b9505aa78cdd -r f5cff8708531 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/LoadSingleEpochSelectState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/LoadSingleEpochSelectState.java Wed Jul 11 13:42:29 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/LoadSingleEpochSelectState.java Wed Jul 11 14:45:01 2018 +0200
@@ -9,7 +9,10 @@
package org.dive4elements.river.artifacts.uinfo.salix;
import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
+import java.util.TreeMap;
import org.apache.log4j.Logger;
import org.dive4elements.artifacts.Artifact;
@@ -17,6 +20,8 @@
import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
import org.dive4elements.river.artifacts.states.AddTableDataHelper;
import org.dive4elements.river.artifacts.states.DefaultState;
+import org.dive4elements.river.artifacts.uinfo.UINFOArtifact;
+import org.dive4elements.river.model.BedHeight;
import org.w3c.dom.Element;
public class LoadSingleEpochSelectState extends DefaultState {
@@ -38,32 +43,12 @@
@Override
protected void appendItems(final Artifact artifact, final ElementCreator creator, final String name, final CallContext context, final Element select) {
final String datakey = "singleepoch";
- // TODO: MAKE DATASOURCE
+
try {
if (datakey.equals(name)) {
-
- final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "year", context.getMeta());
-
- helper.addColumn(0, "pinfrom", "40", "common.client.ui.from", "ICON", "CENTER", "from");
- helper.addColumn(1, "pinto", "40", "common.client.ui.to", "ICON", "CENTER", "to");
- helper.addColumn(2, "year", "60", "year", "INTEGER", "LEFT", null);
- helper.addColumn(3, "sounding", "200", "uinfo.salix.soundings", "STRING", "LEFT", null);
- // final CollisionAccess access = new CollisionAccess((SINFOArtifact) artifact); // Der River wurde im vorigen State
- // bereits gesetzt
-
- // final List<Collision> collisions = CollisionHibernateFactory.getCollisionsByRiver(access.getRiver());
- // for (final Collision coll : collisions) { // TODO: Filter on Range (?)
- // final Integer year = coll.getYear();
- // for (final Collision coll : collisions) {
- for (int i = 0; i < 3; i++) {// : Collision.getYearsOfRiver(access.getRiver())) {
- // final Integer year = coll.getYear();
- final Map<String, String> row = new HashMap<>();
- row.put("year", String.valueOf(1995 + i)); // Nullpointer?
- row.put("sounding", "TODO: Peilungen für das Jahr in dieser Zelle auflisten.");
- helper.addRow(row);
- }
- // }
- helper.submitMapToXml();
+ final SalixLineAccess access = new SalixLineAccess((UINFOArtifact) artifact);
+ final List<BedHeight> bhs = BedHeight.getBedHeightEpochs(access.getRiver(), access.getLowerKm(), access.getUpperKm());
+ makeDataSourceYearEpoch(artifact, creator, select, context, bhs);
}
}
catch (
@@ -72,4 +57,34 @@
iae.printStackTrace();
}
}
+
+ public static final void makeDataSourceYearEpoch(final Artifact artifact, final ElementCreator creator, final Element select, final CallContext context,
+ final List<BedHeight> bedheights) { // TODO: maybe move to appropriate helper...
+
+ final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "year", context.getMeta());
+
+ helper.addColumn(0, "pinfrom", "40", "common.client.ui.from", "ICON", "CENTER", "from");
+ helper.addColumn(1, "year", "60", "year", "INTEGER", "LEFT", null);
+ helper.addColumn(2, "sounding", "500", "uinfo.salix.soundings", "STRING", "LEFT", null);
+
+ final TreeMap<Integer, String> bedHeightSorted = new TreeMap<>();
+
+ for (final BedHeight bh : bedheights) {
+ final int year = bh.getYear();
+ final String soundings = bedHeightSorted.containsKey(year) ? bedHeightSorted.get(year) + ", " : "";
+ bedHeightSorted.put(year, soundings + bh.getDescription());
+ }
+ final Iterator<Integer> iterator = bedHeightSorted.keySet().iterator();
+ while (iterator.hasNext()) {
+ final int year = iterator.next();
+ final String soundings = bedHeightSorted.get(year);
+ final Map<String, String> row = new HashMap<>();
+ row.put("year", String.valueOf(year));
+ row.put("sounding", soundings);
+ helper.addRow(row);
+ }
+
+ helper.submitMapToXml();
+ }
+
}
diff -r b9505aa78cdd -r f5cff8708531 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/LoadSingleYearSelectState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/LoadSingleYearSelectState.java Wed Jul 11 13:42:29 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/LoadSingleYearSelectState.java Wed Jul 11 14:45:01 2018 +0200
@@ -8,15 +8,15 @@
package org.dive4elements.river.artifacts.uinfo.salix;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.List;
import org.apache.log4j.Logger;
import org.dive4elements.artifacts.Artifact;
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
-import org.dive4elements.river.artifacts.states.AddTableDataHelper;
import org.dive4elements.river.artifacts.states.DefaultState;
+import org.dive4elements.river.artifacts.uinfo.UINFOArtifact;
+import org.dive4elements.river.model.BedHeight;
import org.w3c.dom.Element;
/** State in which to fetch years for sedminent load calculation. */
@@ -39,35 +39,21 @@
@Override
protected void appendItems(final Artifact artifact, final ElementCreator creator, final String name, final CallContext context, final Element select) {
- // TODO: MAKE DATASOURCE
+
+ final String dataKeyofState = "singleyear";// siehe .xml
try {
- final String dataKeyofState = "singleyear";// siehe .xml
if (dataKeyofState.equals(name)) {
-
- final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "year", context.getMeta()); // "year" not to be confused with datakey
-
- helper.addColumn(0, "pinfrom", "60", "common.client.ui.selection", "ICON", "CENTER", "from");
- helper.addColumn(1, "year", "60", "year", "INTEGER", "LEFT", null);
- helper.addColumn(2, "sounding", "200", "uinfo.salix.soundings", "STRING", "LEFT", null);
- // TODO: MAKE DATASOURCE
- // final CollisionAccess access = new CollisionAccess((SINFOArtifact) artifact); // TODO: MAKE DATASOURCE
- // TODO: MAKE DATASOURCE
- // final List<Collision> collisions = CollisionHibernateFactory.getCollisionsByRiver(access.getRiver());
- // for (final Collision coll : collisions) {
- for (int i = 0; i < 3; i++) {// : Collision.getYearsOfRiver(access.getRiver())) {
- // final Integer year = coll.getYear();
- final Map<String, String> row = new HashMap<>();
- row.put("year", String.valueOf(1995 + i)); // Nullpointer?
- row.put("sounding", "TODO: Peilungen für das Jahr in dieser Zelle auflisten.");
- helper.addRow(row);
- }
- helper.submitMapToXml();
+ final SalixLineAccess access = new SalixLineAccess((UINFOArtifact) artifact);
+ final List<BedHeight> bhs = BedHeight.getBedHeightYear(access.getRiver(), access.getLowerKm(), access.getUpperKm());
+ LoadSingleEpochSelectState.makeDataSourceYearEpoch(artifact, creator, select, context, bhs);
}
}
- catch (final IllegalArgumentException iae) {
+ catch (
+
+ final IllegalArgumentException iae) {
iae.printStackTrace();
}
+
}
-
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
diff -r b9505aa78cdd -r f5cff8708531 backend/src/main/java/org/dive4elements/river/model/BedHeight.java
--- a/backend/src/main/java/org/dive4elements/river/model/BedHeight.java Wed Jul 11 13:42:29 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/BedHeight.java Wed Jul 11 14:45:01 2018 +0200
@@ -207,11 +207,8 @@
public static List<BedHeight> getBedHeights(final River river, final double kmLo, final double kmHi) {
final Session session = SessionHolder.HOLDER.get();
- final Query query = session.createQuery("from BedHeight"
- + " where river=:river"
- + " and id in (select bedHeight.id from BedHeightValue"
- + " where station between :kmfrom and :kmto"
- + " group by bedHeight.id)");
+ final Query query = session.createQuery("from BedHeight" + " where river=:river" + " and id in (select bedHeight.id from BedHeightValue"
+ + " where station between :kmfrom and :kmto" + " group by bedHeight.id)");
query.setParameter("river", river);
query.setParameter("kmfrom", kmLo);
@@ -238,11 +235,8 @@
final Session session = SessionHolder.HOLDER.get();
- final Query query = session.createQuery("FROM BedHeight"
- + " WHERE (TRIM(description)=:description) AND river=:river"
- + " AND id IN (SELECT bedHeight.id FROM BedHeightValue"
- + " WHERE station BETWEEN :kmfrom AND :kmto"
- + " GROUP BY bedHeight.id)");
+ final Query query = session.createQuery("FROM BedHeight" + " WHERE (TRIM(description)=:description) AND river=:river"
+ + " AND id IN (SELECT bedHeight.id FROM BedHeightValue" + " WHERE station BETWEEN :kmfrom AND :kmto" + " GROUP BY bedHeight.id)");
query.setParameter("river", river);
query.setParameter("description", description);
query.setParameter("kmfrom", startKm);
@@ -252,4 +246,36 @@
return ((singles != null) && !singles.isEmpty()) ? singles.get(0) : null;
}
+
+ public static List<BedHeight> getBedHeightEpochs(final River river, final double startKm, final double endKm) {
+
+ final Session session = SessionHolder.HOLDER.get();
+ final String description = "epoch";
+ final Query query = session.createQuery("FROM BedHeight" + " WHERE lower(description) LIKE :description AND " + "river=:river"
+ + " AND id IN (SELECT bedHeight.id FROM BedHeightValue" + " WHERE station BETWEEN :kmfrom AND :kmto" + " GROUP BY bedHeight.id)");
+ query.setParameter("river", river);
+ query.setParameter("description", "%" + description + "%");
+ query.setParameter("kmfrom", startKm);
+ query.setParameter("kmto", endKm);
+
+ final List<BedHeight> singles = query.list();
+
+ return ((singles != null) && !singles.isEmpty()) ? singles : null;
+ }
+
+ public static List<BedHeight> getBedHeightYear(final River river, final double startKm, final double endKm) {
+
+ final Session session = SessionHolder.HOLDER.get();
+ final String description = "epoch";
+ final Query query = session.createQuery("FROM BedHeight" + " WHERE lower(description) NOT LIKE :description AND " + "river=:river"
+ + " AND id IN (SELECT bedHeight.id FROM BedHeightValue" + " WHERE station BETWEEN :kmfrom AND :kmto" + " GROUP BY bedHeight.id)");
+ query.setParameter("river", river);
+ query.setParameter("description", "%" + description + "%");
+ query.setParameter("kmfrom", startKm);
+ query.setParameter("kmto", endKm);
+
+ final List<BedHeight> singles = query.list();
+
+ return ((singles != null) && !singles.isEmpty()) ? singles : null;
+ }
}
\ No newline at end of file
More information about the Dive4Elements-commits
mailing list