# HG changeset patch # User Tom Gottfried # Date 1449594618 -3600 # Node ID 6714e07e18c29b9c94e07e749a63e06069bad9e0 # Parent b251a6ad46bb2f244c17bb966c434b13e5c057f8 Issue1854: Use the real data. There is no guarantee that the overviews contain the same data. diff -r b251a6ad46bb -r 6714e07e18c2 artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityDistanceSelect.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityDistanceSelect.java Tue Dec 08 16:43:46 2015 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityDistanceSelect.java Tue Dec 08 18:10:18 2015 +0100 @@ -10,6 +10,7 @@ import java.util.Date; import java.util.List; +import java.util.Collections; import org.w3c.dom.Element; @@ -18,10 +19,8 @@ import org.dive4elements.river.artifacts.D4EArtifact; import org.dive4elements.river.artifacts.access.RiverAccess; import org.dive4elements.river.artifacts.states.DistanceSelect; -import org.dive4elements.river.utils.KMIndex; -import org.dive4elements.river.artifacts.model.minfo.BedOverview; -import org.dive4elements.river.artifacts.model.minfo.BedOverviewFactory; +import org.dive4elements.river.artifacts.model.minfo.QualityMeasurementFactory; import org.dive4elements.artifacts.common.utils.XMLUtils; import org.dive4elements.artifacts.Artifact; @@ -53,36 +52,46 @@ return ele; } - D4EArtifact arti = (D4EArtifact) artifact; - RiverAccess access = new RiverAccess(arti); + RiverAccess access = new RiverAccess((D4EArtifact)artifact); + String river = access.getRiverName(); + double [] minMax = access.getRiver().determineMinMaxDistance(); - /* Bit of an overkill here but it will be cached and accessed - * in the next state anyway. */ - BedOverview overview = BedOverviewFactory - .getOverview(access.getRiverName()); + List bKms = QualityMeasurementFactory.getBedMeasurements( + river, + minMax[0], + minMax[1], + new Date(Long.MIN_VALUE/100000), + new Date(Long.MAX_VALUE/1000) + // values expected to fit in SQL Date, though large enough + ).getKms(); - if (overview == null) { - log.warn("No overview found for river '" - + access.getRiverName() + "'"); + List blKms = QualityMeasurementFactory.getBedloadMeasurements( + river, + minMax[0], + minMax[1], + new Date(Long.MIN_VALUE/100000), + new Date(Long.MAX_VALUE/1000) + // values expected to fit in SQL Date, though large enough + ).getKms(); + + if (bKms.isEmpty() || blKms.isEmpty()) { + log.warn("Not all data found for river '" + river + "'"); return ele; } - KMIndex> entries = overview.filter(BedOverview.ACCEPT); - if (entries.size() == 0) { - log.warn("No data found for river '" - + access.getRiverName() + "'"); - return ele; - } - entries.sort(); + Collections.sort(blKms); + Collections.sort(bKms); + + double start = Math.min(bKms.get(0), blKms.get(0)); + double end = Math.max( + bKms.get(bKms.size()-1), blKms.get(blKms.size()-1)); if (data.getName().equals("ld_from")) { cr.addAttr(ele, "defaultLabel", data.getName(), true); - cr.addAttr(ele, "defaultValue", - Double.toString(entries.get(0).getKm()), true); + cr.addAttr(ele, "defaultValue", Double.toString(start), true); } else if (data.getName().equals("ld_to")) { cr.addAttr(ele, "defaultLabel", data.getName(), true); - cr.addAttr(ele, "defaultValue", - Double.toString(entries.get(entries.size()-1).getKm()), true); + cr.addAttr(ele, "defaultValue", Double.toString(end), true); } return ele;