Mercurial > dive4elements > river
changeset 8620:8737de2ca763
Send default values for SQ Period selection to the client.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 25 Mar 2015 19:20:13 +0100 |
parents | 156980fb3cb9 |
children | 1125e598df0e |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQPeriodSelect.java |
diffstat | 1 files changed, 63 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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() {