Browse code

BM-13918 Fix: dateMin is incuded in calendar's search result

Mehdi Rande authored on 04/12/2018 07:18:26
Showing 2 changed files
... ...
@@ -19,6 +19,7 @@
19 19
 package net.bluemind.calendar.persistance;
20 20
 
21 21
 import static org.junit.Assert.assertEquals;
22
+import static org.junit.Assert.assertFalse;
22 23
 import static org.junit.Assert.assertNotNull;
23 24
 import static org.junit.Assert.assertTrue;
24 25
 
... ...
@@ -310,19 +311,52 @@ public class VEventIndexStoreTests {
310 310
 		res = indexStore.search(query);
311 311
 		assertEquals(2, res.values.size());
312 312
 
313
+		// create an event at dateEnd (excluded from range)
314
+		ItemValue<VEventSeries> event4 = defaultVEvent();
315
+		event4.value.main.dtstart = BmDateTimeWrapper.create(new DateTime(1983, 3, 1, 0, 0, 0), Precision.Date);
316
+		indexStore.create(event4.uid, event4.value);
317
+		indexStore.refresh();
318
+
319
+		res = indexStore.search(query);
320
+		assertEquals(2, res.values.size());
321
+		
322
+		// create an event at dateBegin (included in range)
323
+		ItemValue<VEventSeries> event5 = defaultVEvent();
324
+		event5.value.main.dtstart = BmDateTimeWrapper.create(new DateTime(1983, 2, 1, 0, 0, 0), Precision.Date);
325
+		indexStore.create(event5.uid, event5.value);
326
+		indexStore.refresh();
327
+
328
+		res = indexStore.search(query);
329
+		assertEquals(3, res.values.size());
330
+
313 331
 		boolean found1 = false;
332
+		boolean found2 = false;
314 333
 		boolean found3 = false;
334
+		boolean found4 = false;
335
+		boolean found5 = false;
315 336
 		for (String s : res.values) {
316 337
 			if (event.uid.equals(s)) {
317 338
 				found1 = true;
318 339
 			}
340
+			if (event2.uid.equals(s)) {
341
+				found2 = true;
342
+			}
319 343
 			if (event3.uid.equals(s)) {
320 344
 				found3 = true;
321 345
 			}
346
+			if (event4.uid.equals(s)) {
347
+				found4 = true;
348
+			}
349
+			if (event5.uid.equals(s)) {
350
+				found5 = true;
351
+			}
322 352
 		}
323 353
 
324 354
 		assertTrue(found1);
355
+		assertFalse(found2);
325 356
 		assertTrue(found3);
357
+		assertFalse(found4);
358
+		assertTrue(found5);
326 359
 	}
327 360
 
328 361
 	@Test
... ...
@@ -137,7 +137,7 @@ public class VEventIndexStore {
137 137
 		if (query.dateMin != null || query.dateMax != null) {
138 138
 			List<QueryBuilder> musts = new ArrayList<>(2);
139 139
 			if (query.dateMin != null) {
140
-				musts.add(fieldGreaterThan("value.dtend.iso8601", "value.dtend.timezone", query.dateMin));
140
+				musts.add(fieldGreaterOrEqualAt("value.dtend.iso8601", "value.dtend.timezone", query.dateMin));
141 141
 			}
142 142
 
143 143
 			if (query.dateMax != null) {
... ...
@@ -200,7 +200,18 @@ public class VEventIndexStore {
200 200
 
201 201
 		return Queries.and(QueryBuilders.existsQuery(field), Queries.or(inRangeNoTz, inRangeWithTz));
202 202
 	}
203
+	
204
+	private QueryBuilder fieldGreaterOrEqualAt(String field, String fieldTz, BmDateTime dt) {
205
+		QueryBuilder inRangeNoTz = Queries.and(//
206
+				Queries.missing(fieldTz), //
207
+				QueryBuilders.rangeQuery(field).gte(new BmDateTimeWrapper(dt).format("yyyy-MM-dd'T'HH:mm:ss.S")));
208
+		QueryBuilder inRangeWithTz = Queries.and(//
209
+				QueryBuilders.existsQuery(fieldTz), //
210
+				QueryBuilders.rangeQuery(field).gte(dt.iso8601));
203 211
 
212
+		return Queries.and(QueryBuilders.existsQuery(field), Queries.or(inRangeNoTz, inRangeWithTz));
213
+	}
214
+	
204 215
 	private QueryBuilder fieldLessThan(String field, String fieldTz, BmDateTime dt) {
205 216
 		QueryBuilder inRangeNoTz = Queries.and(//
206 217
 				Queries.missing(fieldTz), //