1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.docsearch.xml;
17
18 import org.junit.Test;
19 import org.kuali.rice.core.framework.persistence.jdbc.sql.SQLUtils;
20 import org.kuali.rice.kew.api.WorkflowDocument;
21 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
22 import org.kuali.rice.kew.api.document.attribute.WorkflowAttributeDefinition;
23 import org.kuali.rice.kew.api.document.search.DocumentSearchCriteria;
24 import org.kuali.rice.kew.api.document.search.DocumentSearchResults;
25 import org.kuali.rice.kew.docsearch.DocumentSearchInternalUtils;
26 import org.kuali.rice.kew.docsearch.DocumentSearchTestBase;
27 import org.kuali.rice.kew.docsearch.TestXMLSearchableAttributeDateTime;
28 import org.kuali.rice.kew.docsearch.TestXMLSearchableAttributeFloat;
29 import org.kuali.rice.kew.docsearch.TestXMLSearchableAttributeLong;
30 import org.kuali.rice.kew.docsearch.TestXMLSearchableAttributeString;
31 import org.kuali.rice.kew.docsearch.service.DocumentSearchService;
32 import org.kuali.rice.kew.doctype.bo.DocumentType;
33 import org.kuali.rice.kew.doctype.service.DocumentTypeService;
34 import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
35 import org.kuali.rice.kew.service.KEWServiceLocator;
36 import org.kuali.rice.kim.api.identity.Person;
37 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
38
39 import java.math.BigDecimal;
40 import java.util.Calendar;
41
42 import static org.junit.Assert.*;
43
44
45
46
47
48
49
50 public class StandardGenericXMLSearchableAttributeRangesTest extends DocumentSearchTestBase {
51
52 protected void loadTestData() throws Exception {
53 loadXmlFile("XmlConfig.xml");
54 }
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261 @Test public void testSearchableAttributeRanges() throws Exception {
262 String documentTypeName = "SearchDocTypeRangeSearchDataType";
263 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
264 String userNetworkId = "rkirkend";
265 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(userNetworkId), documentTypeName);
266
267
268
269
270
271
272 WorkflowAttributeDefinition.Builder stringXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttributeStringRange");
273 stringXMLDef.addPropertyDefinition(TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE);
274 workflowDocument.addSearchableDefinition(stringXMLDef.build());
275
276 WorkflowAttributeDefinition.Builder longXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttributeStdLongRange");
277 longXMLDef.addPropertyDefinition(TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE.toString());
278 workflowDocument.addSearchableDefinition(longXMLDef.build());
279
280 WorkflowAttributeDefinition.Builder floatXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttributeStdFloatRange");
281 floatXMLDef.addPropertyDefinition(TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE.toString());
282 workflowDocument.addSearchableDefinition(floatXMLDef.build());
283
284 WorkflowAttributeDefinition.Builder dateXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttributeStdDateTimeRange");
285 dateXMLDef.addPropertyDefinition(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY, DocumentSearchInternalUtils
286 .getDisplayValueWithDateOnly(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE));
287 workflowDocument.addSearchableDefinition(dateXMLDef.build());
288
289 workflowDocument.setTitle("Routing style");
290 workflowDocument.route("routing this document.");
291
292 workflowDocument = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName(userNetworkId), workflowDocument.getDocumentId());
293
294 DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
295 Person user = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(userNetworkId);
296
297
298 DocumentSearchCriteria.Builder criteria = null;
299 DocumentSearchResults results = null;
300
301 criteria = DocumentSearchCriteria.Builder.create();
302 criteria.setDocumentTypeName(documentTypeName);
303 addSearchableAttributeRange(criteria, TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE, null, false);
304 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
305 int size = results.getSearchResults().size();
306 assertTrue("Searching for a lower bound of 'jack'. case insensitive, inclusive. so searching for something >= 'JACK'. Should Return 1, but got" + size, 1 == size);
307
308
309
310 String searchAttributeLongKey = TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY;
311 Long searchAttributeLongValue = TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE.longValue();
312 Long longValueToUse = null;
313
314
315 criteria = DocumentSearchCriteria.Builder.create();
316 criteria.setDocumentTypeName(documentTypeName);
317 longValueToUse = searchAttributeLongValue;
318 addSearchableAttributeRange(criteria, searchAttributeLongKey, longValueToUse.toString(), null, false);
319 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
320 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
321
322 criteria = DocumentSearchCriteria.Builder.create();
323 criteria.setDocumentTypeName(documentTypeName);
324 longValueToUse = Long.valueOf(searchAttributeLongValue.longValue() - 1);
325 addSearchableAttributeRange(criteria, searchAttributeLongKey, longValueToUse.toString(), null, false);
326 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
327 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
328
329 criteria = DocumentSearchCriteria.Builder.create();
330 criteria.setDocumentTypeName(documentTypeName);
331 longValueToUse = Long.valueOf(searchAttributeLongValue.longValue() + 1);
332 addSearchableAttributeRange(criteria, searchAttributeLongKey, longValueToUse.toString(), null, false);
333 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
334 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
335
336
337 criteria = DocumentSearchCriteria.Builder.create();
338 criteria.setDocumentTypeName(documentTypeName);
339 longValueToUse = searchAttributeLongValue;
340 addSearchableAttributeRange(criteria, searchAttributeLongKey, null, longValueToUse.toString(), true);
341 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
342 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
343
344 criteria = DocumentSearchCriteria.Builder.create();
345 criteria.setDocumentTypeName(documentTypeName);
346 longValueToUse = Long.valueOf(searchAttributeLongValue.longValue() - 1);
347 addSearchableAttributeRange(criteria, searchAttributeLongKey, null, longValueToUse.toString(), true);
348 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
349 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
350
351 criteria = DocumentSearchCriteria.Builder.create();
352 criteria.setDocumentTypeName(documentTypeName);
353 longValueToUse = Long.valueOf(searchAttributeLongValue.longValue() + 1);
354 addSearchableAttributeRange(criteria, searchAttributeLongKey, null, longValueToUse.toString(), true);
355 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
356 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
357
358
359 criteria = DocumentSearchCriteria.Builder.create();
360 criteria.setDocumentTypeName(documentTypeName);
361 addSearchableAttributeRange(criteria, searchAttributeLongKey, Long.valueOf(searchAttributeLongValue.longValue())
362 .toString(), Long.valueOf(searchAttributeLongValue.longValue()).toString(), true);
363 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
364 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
365
366 criteria = DocumentSearchCriteria.Builder.create();
367 criteria.setDocumentTypeName(documentTypeName);
368 addSearchableAttributeRange(criteria, searchAttributeLongKey, Long.valueOf(
369 searchAttributeLongValue.longValue() + 2).toString(), Long.valueOf(
370 searchAttributeLongValue.longValue() + 4).toString(), true);
371 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
372 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
373
374 criteria = DocumentSearchCriteria.Builder.create();
375 criteria.setDocumentTypeName(documentTypeName);
376 addSearchableAttributeRange(criteria, searchAttributeLongKey, Long.valueOf(
377 searchAttributeLongValue.longValue() - 2).toString(), Long.valueOf(
378 searchAttributeLongValue.longValue() - 4).toString(), true);
379 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
380 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
381
382 criteria = DocumentSearchCriteria.Builder.create();
383 criteria.setDocumentTypeName(documentTypeName);
384 addSearchableAttributeRange(criteria, searchAttributeLongKey, Long.valueOf(
385 searchAttributeLongValue.longValue() - 2).toString(), Long.valueOf(
386 searchAttributeLongValue.longValue() + 2).toString(), true);
387 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
388 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
389
390 criteria = DocumentSearchCriteria.Builder.create();
391 criteria.setDocumentTypeName(documentTypeName);
392 addSearchableAttributeRange(criteria, searchAttributeLongKey, Long.valueOf(searchAttributeLongValue.longValue() + 2).toString(), Long.valueOf(searchAttributeLongValue.longValue() - 2).toString(), true);
393 try {
394 docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
395 fail("Error should have been thrown for invalid range");
396 } catch (WorkflowServiceErrorException e) {}
397
398
399 String searchAttributeFloatKey = TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY;
400 BigDecimal searchAttributeFloatValue = TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE;
401
402 BigDecimal floatValueToUse = null;
403
404 criteria = DocumentSearchCriteria.Builder.create();
405 criteria.setDocumentTypeName(documentTypeName);
406 floatValueToUse = searchAttributeFloatValue;
407 addSearchableAttributeRange(criteria, searchAttributeFloatKey, floatValueToUse.toString(), null, false);
408 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
409 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
410
411 criteria = DocumentSearchCriteria.Builder.create();
412 criteria.setDocumentTypeName(documentTypeName);
413 floatValueToUse = searchAttributeFloatValue.subtract(BigDecimal.ONE);
414 addSearchableAttributeRange(criteria, searchAttributeFloatKey, floatValueToUse.toString(), null, false);
415 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
416 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
417
418 criteria = DocumentSearchCriteria.Builder.create();
419 criteria.setDocumentTypeName(documentTypeName);
420 floatValueToUse = searchAttributeFloatValue.add(BigDecimal.ONE);
421 addSearchableAttributeRange(criteria, searchAttributeFloatKey, floatValueToUse.toString(), null, false);
422 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
423 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
424
425
426 criteria = DocumentSearchCriteria.Builder.create();
427 criteria.setDocumentTypeName(documentTypeName);
428 floatValueToUse = searchAttributeFloatValue;
429 addSearchableAttributeRange(criteria, searchAttributeFloatKey, null, floatValueToUse.toString(), true);
430 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
431 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
432
433 criteria = DocumentSearchCriteria.Builder.create();
434 criteria.setDocumentTypeName(documentTypeName);
435 floatValueToUse = searchAttributeFloatValue.subtract(BigDecimal.ONE);
436 addSearchableAttributeRange(criteria, searchAttributeFloatKey, null, floatValueToUse.toString(), true);
437 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
438 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
439
440 criteria = DocumentSearchCriteria.Builder.create();
441 criteria.setDocumentTypeName(documentTypeName);
442 floatValueToUse = searchAttributeFloatValue.add(BigDecimal.ONE);
443 addSearchableAttributeRange(criteria, searchAttributeFloatKey, null, floatValueToUse.toString(), true);
444 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
445 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
446
447
448 criteria = DocumentSearchCriteria.Builder.create();
449 criteria.setDocumentTypeName(documentTypeName);
450 addSearchableAttributeRange(criteria, searchAttributeFloatKey, searchAttributeFloatValue.toString(),
451 searchAttributeFloatValue.toString(), true);
452 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
453 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
454
455 criteria = DocumentSearchCriteria.Builder.create();
456 criteria.setDocumentTypeName(documentTypeName);
457 addSearchableAttributeRange(criteria, searchAttributeFloatKey, (searchAttributeFloatValue.add(new BigDecimal(
458 2))).toString(), (searchAttributeFloatValue.add(new BigDecimal(4))).toString(), true);
459 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
460 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
461
462 criteria = DocumentSearchCriteria.Builder.create();
463 criteria.setDocumentTypeName(documentTypeName);
464 addSearchableAttributeRange(criteria, searchAttributeFloatKey, (searchAttributeFloatValue.subtract(
465 new BigDecimal(4))).toString(), (searchAttributeFloatValue.subtract(new BigDecimal(2))).toString(),
466 true);
467 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
468 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
469
470 criteria = DocumentSearchCriteria.Builder.create();
471 criteria.setDocumentTypeName(documentTypeName);
472 addSearchableAttributeRange(criteria, searchAttributeFloatKey, (searchAttributeFloatValue.subtract(new BigDecimal(2))).toString(), (searchAttributeFloatValue.add(new BigDecimal(2))).toString(), true);
473 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
474 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
475
476 criteria = DocumentSearchCriteria.Builder.create();
477 criteria.setDocumentTypeName(documentTypeName);
478 addSearchableAttributeRange(criteria, searchAttributeFloatKey, (searchAttributeFloatValue.add(new BigDecimal(
479 2))).toString(), (searchAttributeFloatValue.subtract(new BigDecimal(2))).toString(), true);
480 try {
481 docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
482 fail("Error should have been thrown for invalid range");
483 } catch (WorkflowServiceErrorException e) {}
484
485
486
487 String searchAttributeDateTimeKey = TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY;
488 Calendar searchAttributeDateTimeValue = TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE.toGregorianCalendar();
489
490 Calendar calendarValueToUse = null;
491
492 criteria = DocumentSearchCriteria.Builder.create();
493 criteria.setDocumentTypeName(documentTypeName);
494 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
495 String valueToSearch = DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(
496 calendarValueToUse));
497 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, valueToSearch, null, false);
498 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
499 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
500
501 criteria = DocumentSearchCriteria.Builder.create();
502 criteria.setDocumentTypeName(documentTypeName);
503 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
504 calendarValueToUse.add(Calendar.DATE, -1);
505 valueToSearch = DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(
506 calendarValueToUse));
507 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, valueToSearch, null, false);
508 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
509 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
510
511 criteria = DocumentSearchCriteria.Builder.create();
512 criteria.setDocumentTypeName(documentTypeName);
513 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
514 calendarValueToUse.add(Calendar.DATE, 1);
515 valueToSearch = DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(
516 calendarValueToUse));
517 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, valueToSearch, null, false);
518 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
519 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
520
521
522 criteria = DocumentSearchCriteria.Builder.create();
523 criteria.setDocumentTypeName(documentTypeName);
524 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
525 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, null,
526 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)), true);
527 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
528 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
529
530 criteria = DocumentSearchCriteria.Builder.create();
531 criteria.setDocumentTypeName(documentTypeName);
532 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
533 calendarValueToUse.add(Calendar.DATE, -1);
534 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, null, DocumentSearchInternalUtils
535 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)), true);
536 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
537 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
538
539 criteria = DocumentSearchCriteria.Builder.create();
540 criteria.setDocumentTypeName(documentTypeName);
541 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
542 calendarValueToUse.add(Calendar.DATE, 1);
543 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, null,
544 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)), true);
545 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
546 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
547
548
549 criteria = DocumentSearchCriteria.Builder.create();
550 criteria.setDocumentTypeName(documentTypeName);
551 Calendar lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
552 Calendar upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
553 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, DocumentSearchInternalUtils
554 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils
555 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true);
556 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
557 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
558
559 criteria = DocumentSearchCriteria.Builder.create();
560 criteria.setDocumentTypeName(documentTypeName);
561 lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
562 lowerBoundValue.add(Calendar.DATE, 2);
563 upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
564 upperBoundValue.add(Calendar.DATE, 4);
565 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, DocumentSearchInternalUtils
566 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils
567 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true);
568 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
569 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
570
571 criteria = DocumentSearchCriteria.Builder.create();
572 criteria.setDocumentTypeName(documentTypeName);
573 lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
574 lowerBoundValue.add(Calendar.DATE, -4);
575 upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
576 upperBoundValue.add(Calendar.DATE, -2);
577 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, DocumentSearchInternalUtils
578 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils
579 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true);
580 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
581 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
582
583 criteria = DocumentSearchCriteria.Builder.create();
584 criteria.setDocumentTypeName(documentTypeName);
585 lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
586 lowerBoundValue.add(Calendar.DATE, -2);
587 upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
588 upperBoundValue.add(Calendar.DATE, 2);
589 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, DocumentSearchInternalUtils
590 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils
591 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true);
592 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
593 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
594
595 criteria = DocumentSearchCriteria.Builder.create();
596 criteria.setDocumentTypeName(documentTypeName);
597 lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
598 lowerBoundValue.add(Calendar.DATE, 2);
599 upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
600 upperBoundValue.add(Calendar.DATE, -2);
601 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, DocumentSearchInternalUtils
602 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils
603 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true);
604 try {
605 docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
606 fail("Error should have been thrown for invalid range");
607 } catch (WorkflowServiceErrorException e) {}
608 }
609
610
611
612
613 @Test public void testRangeDefinitionStringAttributes() throws Exception {
614 String documentTypeName = "RangeDefinitionTestDocType";
615 DocumentType docType = KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName);
616 String principalName = "rkirkend";
617 String principalId = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(principalName).getPrincipalId();
618 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(principalId, documentTypeName);
619
620
621 WorkflowAttributeDefinition.Builder inclusiveLowerXMLDef = WorkflowAttributeDefinition.Builder.create("TextFieldWithInclusiveLower");
622 inclusiveLowerXMLDef.addPropertyDefinition("textFieldWithInclusiveLower", "newvalue");
623 workflowDocument.addSearchableDefinition(inclusiveLowerXMLDef.build());
624
625 WorkflowAttributeDefinition.Builder caseSensitiveXMLDef = WorkflowAttributeDefinition.Builder.create("TextFieldWithCaseSensitivity");
626 caseSensitiveXMLDef.addPropertyDefinition("textFieldWithCaseSensitivity", "thevalue");
627 workflowDocument.addSearchableDefinition(caseSensitiveXMLDef.build());
628
629 WorkflowAttributeDefinition.Builder overridesXMLDef = WorkflowAttributeDefinition.Builder.create("TextFieldWithOverrides");
630 overridesXMLDef.addPropertyDefinition("textFieldWithOverrides", "SomeVal");
631 workflowDocument.addSearchableDefinition(overridesXMLDef.build());
632
633 workflowDocument.setTitle("Range Def Test");
634 workflowDocument.route("routing range def doc.");
635
636 workflowDocument = WorkflowDocumentFactory.loadDocument(principalId, workflowDocument.getDocumentId());
637
638
639 assertSearchBehavesAsExpected(docType, principalId, "textFieldWithInclusiveLower",
640 new String[] { "newvalue", "" , "" , "NEWVALUD", "newValuf", "newValuj", "newvaluf"},
641 new String[] { "" , "newvalue", "Newvaluf", "NEWVALUF", "newValud", "NEWVALUK", "" },
642 new int[] { 1 , 0 , 1 , 1 , -1 , 0 , 0 });
643
644
645 assertSearchBehavesAsExpected(docType, principalId, "textFieldWithCaseSensitivity",
646 new String[] { "thevalue", "" , "" , "THEVALUD", "thevalud", "Thevalud", "THEVALUF"},
647 new String[] { "" , "thevalue", "Thevalue", "THEVALUF", "THEVALUF", "Thevaluf", "" },
648 new int[] { 1 , 1 , 0 , 0 , -1 , 0 , 1 });
649
650
651
652 assertSearchBehavesAsExpected(docType, principalId, "textFieldWithOverrides",
653 new String[] { "someval", "SomeVal", "" , "" , "SOMEVAK", "SomeVam", "SOMEVAM", "somevak", "" },
654 new String[] { "" , "" , "SOMEVAL", "SomeVal", "SomeVam", "SOMEVAK", "SomeVak", "" , "SomeVak"},
655 new int[] { 0 , 0 , 0 , 1 , 1 , 0 , 0 , 1 , 0 });
656 }
657
658
659
660
661
662
663
664
665
666
667
668
669 private void assertSearchBehavesAsExpected(DocumentType docType, String principalId, String fieldDefKey, String[] lowBounds, String[] upBounds,
670 int[] resultSizes) throws Exception {
671 DocumentSearchCriteria.Builder criteria = null;
672 DocumentSearchResults results = null;
673 DocumentSearchService docSearchService = KEWServiceLocator.getDocumentSearchService();
674 for (int i = 0; i < resultSizes.length; i++) {
675 criteria = DocumentSearchCriteria.Builder.create();
676 criteria.setDocumentTypeName(docType.getName());
677 addSearchableAttributeRange(criteria, fieldDefKey, lowBounds[i], upBounds[i], true);
678 try {
679 results = docSearchService.lookupDocuments(principalId, criteria.build());
680 if (resultSizes[i] < 0) {
681 fail(fieldDefKey + "'s search at loop index " + i + " should have thrown an exception");
682 }
683 assertEquals(fieldDefKey
684 + "'s search results at loop index "
685 + i
686 + " returned the wrong number of documents.", resultSizes[i], results.getSearchResults().size());
687 } catch (Exception ex) {
688 if (resultSizes[i] >= 0) {
689 fail(fieldDefKey + "'s search at loop index " + i + " should not have thrown an exception");
690 }
691 }
692 }
693 }
694 }