comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQPeriodSelect.java @ 8622:124efb3eea94

Handle surprising filter behaivor of *Overviews. Don't create items for unavailable data.
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 26 Mar 2015 11:06:13 +0100
parents 1125e598df0e
children 3b85c8cee94b
comparison
equal deleted inserted replaced
8621:1125e598df0e 8622:124efb3eea94
28 import org.dive4elements.artifacts.common.utils.XMLUtils; 28 import org.dive4elements.artifacts.common.utils.XMLUtils;
29 import org.dive4elements.artifacts.Artifact; 29 import org.dive4elements.artifacts.Artifact;
30 import org.dive4elements.artifacts.CallContext; 30 import org.dive4elements.artifacts.CallContext;
31 31
32 import org.dive4elements.artifactdatabase.data.StateData; 32 import org.dive4elements.artifactdatabase.data.StateData;
33 import org.dive4elements.river.backend.utils.EpsilonComparator;
33 34
34 public class SQPeriodSelect extends PeriodsSelect { 35 public class SQPeriodSelect extends PeriodsSelect {
35 36
36 private static Logger log = Logger.getLogger(SQPeriodSelect.class); 37 private static Logger log = Logger.getLogger(SQPeriodSelect.class);
37 38
38 public static final String UI_PROVIDER = "sq.period.select"; 39 public static final String UI_PROVIDER = "sq.period.select";
39 40
40 private static final long serialVersionUID = 1L; 41 private static final long serialVersionUID = 1L;
41 42
42 /** Get either the start date of the data or the end. */ 43 /** Get either the start date of the data or the end. */
43 protected long getDataMinMaxDate(Artifact artifact, boolean minDate) { 44 protected Long getDataMinMaxDate(Artifact artifact, boolean minDate) {
44 D4EArtifact arti = (D4EArtifact) artifact; 45 D4EArtifact arti = (D4EArtifact) artifact;
45 RangeAccess access = new RangeAccess(arti); 46 RangeAccess access = new RangeAccess(arti);
46 double km = access.getLocations()[0]; 47 double km = access.getLocations()[0];
47 48
48 /* Bit of an overkill here but it will be cached and accessed 49 /* Bit of an overkill here but it will be cached and accessed
49 * in the next state anyway. */ 50 * in the next state anyway. */
50 SQOverview overview = SQOverviewFactory.getOverview(access.getRiverName()); 51 SQOverview overview = SQOverviewFactory.getOverview(access.getRiverName());
51 52
52 KMIndex<List<Date>> entries = overview.filter(new KmFilter(km)); 53 /* Filter is not implemented and only checks if a complete
54 * KMIndex list is acceptable or not. So KMFiltering wont work */
55 KMIndex<List<Date>> entries = overview.filter(SQOverview.ACCEPT);
53 TreeSet<Date> allDates = new TreeSet<Date>(); 56 TreeSet<Date> allDates = new TreeSet<Date>();
54 57
55 for (int i = 0; i < entries.size(); i++) { 58 for (int i = 0; i < entries.size(); i++) {
56 allDates.addAll(entries.get(i).getValue()); 59 if (EpsilonComparator.CMP.compare(entries.get(i).getKm(), km) == 0) {
60 allDates.addAll(entries.get(i).getValue());
61 }
62 }
63 if (allDates.size() < 2) {
64 return null;
57 } 65 }
58 66
59 return minDate ? allDates.first().getTime() : allDates.last().getTime(); 67 return minDate ? allDates.first().getTime() : allDates.last().getTime();
60 } 68 }
61 69
67 CallContext context) 75 CallContext context)
68 { 76 {
69 if (!name.equals("start") && !name.equals("end")) { 77 if (!name.equals("start") && !name.equals("end")) {
70 return null; 78 return null;
71 } 79 }
80 Long value = getDataMinMaxDate(artifact, name.equals("start"));
81 if (value == null) {
82 return null;
83 }
72 Element def = createItem( 84 Element def = createItem(
73 cr, 85 cr,
74 new String[] {"default", Long.toString( 86 new String[] {"default", value.toString()});
75 getDataMinMaxDate(artifact, name.equals("start")))});
76 87
77 return new Element[] { def }; 88 return new Element[] { def };
78 } 89 }
79 90
80 @Override 91 @Override

http://dive4elements.wald.intevation.org