Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQPeriodSelect.java @ 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 | af13ceeba52a |
children | 1125e598df0e |
comparison
equal
deleted
inserted
replaced
8619:156980fb3cb9 | 8620:8737de2ca763 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.artifacts.states.sq; | 9 package org.dive4elements.river.artifacts.states.sq; |
10 | 10 |
11 import java.util.Date; | |
12 import java.util.List; | |
13 import java.util.Collections; | |
14 | |
15 import org.apache.log4j.Logger; | |
16 | |
17 import org.w3c.dom.Element; | |
18 | |
11 import org.dive4elements.river.artifacts.states.PeriodsSelect; | 19 import org.dive4elements.river.artifacts.states.PeriodsSelect; |
20 import org.dive4elements.river.artifacts.access.RangeAccess; | |
21 import org.dive4elements.river.artifacts.D4EArtifact; | |
22 import org.dive4elements.river.artifacts.model.SQOverview; | |
23 import org.dive4elements.river.artifacts.model.SQOverviewFactory; | |
24 import org.dive4elements.river.artifacts.model.SQOverview.KmFilter; | |
25 | |
26 import org.dive4elements.river.utils.KMIndex; | |
27 | |
28 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
29 import org.dive4elements.artifacts.Artifact; | |
30 import org.dive4elements.artifacts.CallContext; | |
31 | |
32 import org.dive4elements.artifactdatabase.data.StateData; | |
12 | 33 |
13 public class SQPeriodSelect extends PeriodsSelect { | 34 public class SQPeriodSelect extends PeriodsSelect { |
35 | |
36 private static Logger log = Logger.getLogger(SQPeriodSelect.class); | |
14 | 37 |
15 public static final String UI_PROVIDER = "sq.period.select"; | 38 public static final String UI_PROVIDER = "sq.period.select"; |
16 | 39 |
17 private static final long serialVersionUID = 1L; | 40 private static final long serialVersionUID = 1L; |
18 | 41 |
42 /** Get either the start date of the data or the end. */ | |
43 protected long getDataMinMaxDate(Artifact artifact, boolean minDate) { | |
44 D4EArtifact arti = (D4EArtifact) artifact; | |
45 RangeAccess access = new RangeAccess(arti); | |
46 double km = access.getLocations()[0]; | |
47 | |
48 /* Bit of an overkill here but it will be cached and accessed | |
49 * in the next state anyway. */ | |
50 SQOverview overview = SQOverviewFactory.getOverview(access.getRiverName()); | |
51 | |
52 KMIndex<List<Date>> entries = overview.filter(new KmFilter(km)); | |
53 if (entries.size() == 0) { | |
54 return 0; | |
55 } | |
56 List<Date> dates = entries.get(0).getValue(); | |
57 if (dates.isEmpty()) { | |
58 return 0; | |
59 } | |
60 Collections.sort(dates); | |
61 | |
62 return minDate ? dates.get(0).getTime() : dates.get(dates.size() - 1).getTime(); | |
63 } | |
64 | |
65 @Override | |
66 protected Element[] createItems( | |
67 XMLUtils.ElementCreator cr, | |
68 Artifact artifact, | |
69 String name, | |
70 CallContext context) | |
71 { | |
72 if (!name.equals("start") && !name.equals("end")) { | |
73 return null; | |
74 } | |
75 Element def = createItem( | |
76 cr, | |
77 new String[] {"default", Long.toString( | |
78 getDataMinMaxDate(artifact, name.equals("start")))}); | |
79 | |
80 return new Element[] { def }; | |
81 } | |
19 | 82 |
20 @Override | 83 @Override |
21 public String getUIProvider() { | 84 public String getUIProvider() { |
22 return UI_PROVIDER; | 85 return UI_PROVIDER; |
23 } | 86 } |