[PATCH 2 of 2] Send default values for SQ Period selection to the client
Wald Commits
scm-commit at wald.intevation.org
Wed Mar 25 19:21:08 CET 2015
# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1427307613 -3600
# Node ID 8737de2ca76384ace91e1b9ba6d504f7180c7bfb
# Parent 156980fb3cb9f7afc284917ca01f032cd884d88a
Send default values for SQ Period selection to the client.
diff -r 156980fb3cb9 -r 8737de2ca763 artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQPeriodSelect.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQPeriodSelect.java Wed Mar 25 19:18:43 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQPeriodSelect.java Wed Mar 25 19:20:13 2015 +0100
@@ -8,14 +8,77 @@
package org.dive4elements.river.artifacts.states.sq;
+import java.util.Date;
+import java.util.List;
+import java.util.Collections;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Element;
+
import org.dive4elements.river.artifacts.states.PeriodsSelect;
+import org.dive4elements.river.artifacts.access.RangeAccess;
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.model.SQOverview;
+import org.dive4elements.river.artifacts.model.SQOverviewFactory;
+import org.dive4elements.river.artifacts.model.SQOverview.KmFilter;
+
+import org.dive4elements.river.utils.KMIndex;
+
+import org.dive4elements.artifacts.common.utils.XMLUtils;
+import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.CallContext;
+
+import org.dive4elements.artifactdatabase.data.StateData;
public class SQPeriodSelect extends PeriodsSelect {
+ private static Logger log = Logger.getLogger(SQPeriodSelect.class);
+
public static final String UI_PROVIDER = "sq.period.select";
private static final long serialVersionUID = 1L;
+ /** Get either the start date of the data or the end. */
+ protected long getDataMinMaxDate(Artifact artifact, boolean minDate) {
+ D4EArtifact arti = (D4EArtifact) artifact;
+ RangeAccess access = new RangeAccess(arti);
+ double km = access.getLocations()[0];
+
+ /* Bit of an overkill here but it will be cached and accessed
+ * in the next state anyway. */
+ SQOverview overview = SQOverviewFactory.getOverview(access.getRiverName());
+
+ KMIndex<List<Date>> entries = overview.filter(new KmFilter(km));
+ if (entries.size() == 0) {
+ return 0;
+ }
+ List<Date> dates = entries.get(0).getValue();
+ if (dates.isEmpty()) {
+ return 0;
+ }
+ Collections.sort(dates);
+
+ return minDate ? dates.get(0).getTime() : dates.get(dates.size() - 1).getTime();
+ }
+
+ @Override
+ protected Element[] createItems(
+ XMLUtils.ElementCreator cr,
+ Artifact artifact,
+ String name,
+ CallContext context)
+ {
+ if (!name.equals("start") && !name.equals("end")) {
+ return null;
+ }
+ Element def = createItem(
+ cr,
+ new String[] {"default", Long.toString(
+ getDataMinMaxDate(artifact, name.equals("start")))});
+
+ return new Element[] { def };
+ }
@Override
public String getUIProvider() {
More information about the Dive4Elements-commits
mailing list