# HG changeset patch # User gernotbelger # Date 1531386942 -7200 # Node ID c08d5cfa4981b915499dba897a3d35109ad0b81f # Parent f5cff870853196d9ec1ea0dda7dcc6f74243fe27 some hibernate queries on bedheigts for salix diff -r f5cff8708531 -r c08d5cfa4981 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/DistanceOnlyPartHistoricalSelect.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/DistanceOnlyPartHistoricalSelect.java Thu Jul 12 11:15:42 2018 +0200 @@ -0,0 +1,161 @@ +/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ + +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; +import org.dive4elements.artifacts.CallContext; +import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; +import org.dive4elements.river.artifacts.resources.Resources; +import org.dive4elements.river.artifacts.states.AddTableDataHelper; +import org.dive4elements.river.artifacts.states.DistanceOnlySelect; +import org.dive4elements.river.artifacts.uinfo.UINFOArtifact; +import org.dive4elements.river.model.BedHeight; +import org.w3c.dom.Element; + +public class DistanceOnlyPartHistoricalSelect extends DistanceOnlySelect { + + private static final long serialVersionUID = 1L; + private static Logger log = Logger.getLogger(DistanceOnlyPartHistoricalSelect.class); + + List bhs = null; + + @Override + protected String getUIProvider() { + return "distance_only_part_historical_panel"; + } + + @Override + protected String getTitle(final CallContext context) { + // REMARK: that is how it should be: return Resources.getMsg(context.getMeta(), getID()); + return Resources.getMsg(context.getMeta(), "state.title.distance_part_state"); + } + + @Override + protected void appendItems(final Artifact artifact, final ElementCreator creator, final String name, final CallContext context, final Element select) { + final String datakey = "bedheights_for_part"; + + try { + if (datakey.equals(name)) { + makeDataSourceYearEpoch(artifact, creator, select, context, getBedheights(artifact)); // ist nur n test + } else if (name.equals("ld_from_part")) { + + final SalixLineAccess access = new SalixLineAccess((UINFOArtifact) artifact); + final double lowerSoundings = this.getLowerUpperKmRange(getBedheights(artifact))[0]; + final double lowerKm = access.getLowerKm() > lowerSoundings ? access.getLowerKm() : lowerSoundings; + + creator.addAttr(select, "type", "options", true); + + final Element item = creator.create("item"); + creator.addAttr(item, "label", "from_test", true); + creator.addAttr(item, "value", String.valueOf(lowerKm), true); + + select.appendChild(item); + } + + else if (name.equals("ld_to_part")) { + final SalixLineAccess access = new SalixLineAccess((UINFOArtifact) artifact); + final double upperSoundings = this.getLowerUpperKmRange(getBedheights(artifact))[1]; + final double upperKm = access.getUpperKm() < upperSoundings ? access.getUpperKm() : upperSoundings; + + creator.addAttr(select, "type", "options", true); + + final Element item = creator.create("item"); + creator.addAttr(item, "label", "to_test", true); + creator.addAttr(item, "value", String.valueOf(upperKm), true); + + select.appendChild(item); + + } + } + catch ( + + final IllegalArgumentException iae) { + iae.printStackTrace(); + } + } + + private List getBedheights(final Artifact artifact) { + if (this.bhs == null) { + final SalixLineAccess access = new SalixLineAccess((UINFOArtifact) artifact); + final Integer year = access.getYear(); + + final Integer epoch = access.getEpoch(); + final boolean isEpoch = epoch == null ? false : true; + this.bhs = BedHeight.getBedHeightYearEpoch(isEpoch, isEpoch ? epoch : year, access.getRiver(), access.getLowerKm(), access.getUpperKm()); + } + return this.bhs; + + } + + private static final void makeDataSourceYearEpoch(final Artifact artifact, final ElementCreator creator, final Element select, final CallContext context, + final List bedheights) { + + final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "year", context.getMeta()); + + helper.addColumn(0, "from_to", "100", "year", "INTEGER", "LEFT", null); + helper.addColumn(1, "description", "500", "uinfo.salix.soundings", "STRING", "LEFT", null); + + final TreeMap bedHeightSorted = new TreeMap<>(); + final double min = Double.MAX_VALUE; + final double max = -Double.MAX_VALUE; + + for (final BedHeight bh : bedheights) { + final org.dive4elements.river.model.Range range = BedHeight.getRangeFromBedHeights(bh); + final Double from = range.getA().doubleValue(); // NullPointer check?? + final Double to = range.getB().doubleValue(); + + bedHeightSorted.put(bh.getDescription(), String.valueOf(from) + " - " + String.valueOf(to)); + } + final Iterator iterator = bedHeightSorted.keySet().iterator(); + while (iterator.hasNext()) { + final String descr = iterator.next(); + final String fromTo = bedHeightSorted.get(descr); + final Map row = new HashMap<>(); + row.put("from_to", String.valueOf(fromTo)); + row.put("description", descr); + helper.addRow(row); + } + + helper.submitMapToXml(); + } + + private double[] getLowerUpperKmRange(final List bedheights) { + double min = Double.MAX_VALUE; + double max = -Double.MAX_VALUE; + + for (final BedHeight bh : bedheights) { + final org.dive4elements.river.model.Range range = BedHeight.getRangeFromBedHeights(bh); + try { + final Double from = range.getA().doubleValue(); // NullPointer check?? -> try catch + final Double to = range.getB().doubleValue(); + + final double upper = to > from ? to : from; + final double lower = from < to ? from : to; + if (upper > max) + max = upper; + + if (lower < min) + min = lower; + } + catch (final Exception e) { + e.printStackTrace(); + } + + } + return new double[] { min, max }; + } + +} diff -r f5cff8708531 -r c08d5cfa4981 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/LoadScenarioSelectLimit5.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/LoadScenarioSelectLimit5.java Wed Jul 11 14:45:01 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/LoadScenarioSelectLimit5.java Thu Jul 12 11:15:42 2018 +0200 @@ -45,16 +45,10 @@ if (datakey.equals(name)) { final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "cm", context.getMeta()); - // no input help wanted - // 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(1, "cm", "60", "Delta [cm]", "INTEGER", "RIGHT", null); - for (int i = -200; i < 210; i = i + 10) { final Map row = new HashMap<>(); row.put("cm", Integer.toString(i)); helper.addRow(row); - } helper.submitMapToXml(); } diff -r f5cff8708531 -r c08d5cfa4981 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineAccess.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineAccess.java Wed Jul 11 14:45:01 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineAccess.java Thu Jul 12 11:15:42 2018 +0200 @@ -76,4 +76,18 @@ public String getSupraRegionalString() { return super.getString("supraregional_table"); } + + public Integer getYear() { + if (getString("ye_select").equals("state.uinfo.year")) { + return super.getInteger("singleyear"); + } + return null; + } + + public Integer getEpoch() { + if (getString("ye_select").equals("state.uinfo.epoch")) { + return super.getInteger("singleepoch"); + } + return null; + } } \ No newline at end of file diff -r f5cff8708531 -r c08d5cfa4981 artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculation.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculation.java Wed Jul 11 14:45:01 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineCalculation.java Thu Jul 12 11:15:42 2018 +0200 @@ -83,7 +83,7 @@ result = new SalixLineCalculationNoScenarioResult("Ergebnis 1", null, rows); } else { - if (scenario.equals("scenarioType.option1")) { + if (scenario.equals("scenarioType.option1")) { // REGIONAL final int[] scenarios = accessSalix.getRegionalScenarioIntegers(); final List list = new ArrayList<>(); @@ -93,8 +93,8 @@ row1.putValue(UInfoResultType.customMultiRowColSalixRegionalValue_Dwspl, list);// rows.add(row1); result = new SalixLineCalculationRegionalResult("Ergebnis 1 regional test", null, rows, scenarios); - } else if (scenario.equals("scenarioType.option2")) { - // SupraRegional + + } else if (scenario.equals("scenarioType.option2")) { // SUPRA-REGIONAL final String supraRegional = accessSalix.getSupraRegionalString(); final List list = SalixZone.parse(supraRegional); @@ -112,9 +112,9 @@ rangeScenarioMap.put(zonerange, salixscen); } - // make calculation (replace + // make calculation double currentKm = range.getMinimumDouble(); - final double step = 0.1; + final double step = 0.1; // TODO: get from global setting? while (currentKm < range.getMaximumDouble()) { final ResultRow rowSupraRegional = ResultRow.create(). // putValue(GeneralResultType.station, currentKm).// @@ -123,7 +123,7 @@ final SalixScenario scenarioCurrentKm = findScenarioByKm(currentKm, rangeScenarioMap); - if (scenarioCurrentKm != null) { // should not happen, scenarioCurrentKm == 0 -> BUG + if (scenarioCurrentKm != null) { // should not happen, scenarioCurrentKm == null -> BUG rowSupraRegional.putValue(UInfoResultType.salix_line_scenario, scenarioCurrentKm.getSalixValue()); rowSupraRegional.putValue(UInfoResultType.salix_line_scenario_dwspl, scenarioCurrentKm.getDwspl()); } @@ -134,16 +134,12 @@ result = new SalixLineCalculationSupraRegionalResult("Ergebnis 1 supra regional test", null, rows); - } else if (scenario.equals("scenarioType.option3")) { - // historisch + } else if (scenario.equals("scenarioType.option3")) { // HISTORICAL row1.putValue(UInfoResultType.salixlinehist, 2).// putValue(UInfoResultType.salixlinescen, 82); } - } - results.addResult(result, problems); - return new CalculationResult(results, problems); } @@ -157,5 +153,4 @@ } return null; } - } \ No newline at end of file diff -r f5cff8708531 -r c08d5cfa4981 backend/src/main/java/org/dive4elements/river/model/BedHeight.java --- a/backend/src/main/java/org/dive4elements/river/model/BedHeight.java Wed Jul 11 14:45:01 2018 +0200 +++ b/backend/src/main/java/org/dive4elements/river/model/BedHeight.java Thu Jul 12 11:15:42 2018 +0200 @@ -9,6 +9,7 @@ package org.dive4elements.river.model; import java.io.Serializable; +import java.util.ArrayList; import java.util.List; import javax.persistence.Column; @@ -278,4 +279,46 @@ return ((singles != null) && !singles.isEmpty()) ? singles : null; } + + public static Range getRangeFromBedHeights(final BedHeight bh) { + final List ranges = new ArrayList<>(); + + final Session session = SessionHolder.HOLDER.get(); + + final Query query = session.createQuery("FROM Range" + " WHERE id=:range_id)"); + query.setParameter("range_id", bh.getRange().getId()); + + final List singles = query.list(); + + return ((singles != null) && !singles.isEmpty()) ? singles.get(0) : null; + } + + public static List getBedHeightYearEpoch(final boolean isEpoch, final Integer year, final River river, final double lowerKm, + final double upperKm) { + + final Session session = SessionHolder.HOLDER.get(); + final String description = "epoch"; + + final StringBuilder builder = new StringBuilder(); + builder.append("FROM BedHeight"); + if (isEpoch) { + builder.append(" WHERE lower(description) LIKE :description "); + } else { + builder.append(" WHERE lower(description) NOT LIKE :description "); + } + builder.append(" AND year =:year"); + + builder.append( + " 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(builder.toString()); + query.setParameter("river", river); + query.setParameter("year", year); + query.setParameter("description", "%" + description + "%"); + query.setParameter("kmfrom", lowerKm); + query.setParameter("kmto", upperKm); + + final List singles = query.list(); + + return ((singles != null) && !singles.isEmpty()) ? singles : null; + } } \ No newline at end of file diff -r f5cff8708531 -r c08d5cfa4981 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistanceOnlyPartHistoricalPanel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistanceOnlyPartHistoricalPanel.java Thu Jul 12 11:15:42 2018 +0200 @@ -0,0 +1,61 @@ +/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ + +package org.dive4elements.river.client.client.ui; + +import java.util.List; + +import org.dive4elements.river.client.shared.model.Data; +import org.dive4elements.river.client.shared.model.DataList; + +import com.smartgwt.client.widgets.Canvas; + +public class DistanceOnlyPartHistoricalPanel extends DistanceOnlyPartPanel { + + private static final long serialVersionUID = 1L; + private List validInputs; + + @Override + protected void initHelperPanel(final DataList data) { + final FromToTableHelperPanel helper = new FromToTableHelperPanel(data, "bedheights_for_part", this.MSG, null, null); + final Canvas table = helper.getTable(); + this.validInputs = helper.getKeycolEntries(); + + this.helperContainer.addMember(table); + + } + + @Override + protected void initMinMaxValues(final DataList data) { + try { + for (final Data item : data.getAll()) { + if (item.getLabel().equals("ld_from_part"))// misuse ld_from_part for max container + this.min = Double.valueOf(item.getItems()[0].getStringValue()); + + if (item.getLabel().equals("ld_to_part"))// misuse ld_to_part for max container + this.max = Double.valueOf(item.getItems()[0].getStringValue()); + } + } + catch (final NumberFormatException nfe) { + this.min = -Double.MAX_VALUE; + this.max = Double.MAX_VALUE; + } + } + + @Override + protected void initDefaultFrom(final DataList data) { + final double from = (this.min < -99999.) ? 0 : this.min; + this.distancePanel.setFrom(from); + } + + @Override + protected void initDefaultTo(final DataList data) { + final double to = (this.max > 99999.) ? 0 : this.max; + this.distancePanel.setTo(to); + } +} diff -r f5cff8708531 -r c08d5cfa4981 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistancePanel.java --- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistancePanel.java Wed Jul 11 14:45:01 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistancePanel.java Thu Jul 12 11:15:42 2018 +0200 @@ -89,7 +89,7 @@ initMinMaxValues(data); initDefaultValues(data); - initHelperPanel(); + initHelperPanel(data); return layout; } @@ -366,7 +366,7 @@ return Double.valueOf(defValue); } - protected void initHelperPanel() { + protected void initHelperPanel(final DataList data) { final DistancePanelInputHelper helper = new DistancePanelInputHelper(this.MSG, this.helperContainer, this.getRiverName()); diff -r f5cff8708531 -r c08d5cfa4981 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java --- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java Wed Jul 11 14:45:01 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java Thu Jul 12 11:15:42 2018 +0200 @@ -72,6 +72,8 @@ return new DistanceOnlyPanel(); } else if (uiProvider.equals("distance_only_part_panel")) { return new DistanceOnlyPartPanel(); + } else if (uiProvider.equals("distance_only_part_historical_panel")) { + return new DistanceOnlyPartHistoricalPanel(); } else if (uiProvider.equals("waterlevel_ground_panel")) { return new WaterlevelGroundPanel(); } else if (uiProvider.equals("wq_panel")) { diff -r f5cff8708531 -r c08d5cfa4981 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WaterlevelGroundPanel.java --- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WaterlevelGroundPanel.java Wed Jul 11 14:45:01 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WaterlevelGroundPanel.java Thu Jul 12 11:15:42 2018 +0200 @@ -121,7 +121,7 @@ } @Override - protected void initHelperPanel() { + protected void initHelperPanel(final DataList data) { // We don't need a helper panel here. But we have to override this // method to avoid the table creation in the parent class. } diff -r f5cff8708531 -r c08d5cfa4981 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/LoadSingleYearPanel.java --- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/LoadSingleYearPanel.java Wed Jul 11 14:45:01 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/LoadSingleYearPanel.java Thu Jul 12 11:15:42 2018 +0200 @@ -19,6 +19,8 @@ public class LoadSingleYearPanel extends AbstractSingleItemPanel { + private static final long serialVersionUID = 1L; + public LoadSingleYearPanel() { super(Type.single); } diff -r f5cff8708531 -r c08d5cfa4981 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/SupraRegionalTablePanel.java --- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/SupraRegionalTablePanel.java Wed Jul 11 14:45:01 2018 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/SupraRegionalTablePanel.java Thu Jul 12 11:15:42 2018 +0200 @@ -277,8 +277,8 @@ } } }); - final ListGridField fromField = createDoubleTableField("from", this.MSG.from()); - final ListGridField toField = createDoubleTableField("to", this.MSG.to()); + final ListGridField fromField = createDoubleTableField("from", getLabelFromTo(this.MSG.from())); + final ListGridField toField = createDoubleTableField("to", getLabelFromTo(this.MSG.to())); final ListGridField removeField = PanelHelper.createRemoveField(elements, GWT.getHostPageBaseURL() + this.MSG.removeFeature()); elements.addRecordClickHandler(new RecordClickHandler() { // adding another custom record-Remove-Handler which is not included in the Panelhelper @Override