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
395 docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
396 fail("Error should have been thrown for invalid range");
397 } catch (WorkflowServiceErrorException e) {}
398
399
400 String searchAttributeFloatKey = TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY;
401 BigDecimal searchAttributeFloatValue = TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE;
402
403 BigDecimal floatValueToUse = null;
404
405 criteria = DocumentSearchCriteria.Builder.create();
406 criteria.setDocumentTypeName(documentTypeName);
407 floatValueToUse = searchAttributeFloatValue;
408 addSearchableAttributeRange(criteria, searchAttributeFloatKey, floatValueToUse.toString(), null, false);
409 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
410 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
411
412 criteria = DocumentSearchCriteria.Builder.create();
413 criteria.setDocumentTypeName(documentTypeName);
414 floatValueToUse = searchAttributeFloatValue.subtract(BigDecimal.ONE);
415 addSearchableAttributeRange(criteria, searchAttributeFloatKey, floatValueToUse.toString(), null, false);
416 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
417 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
418
419 criteria = DocumentSearchCriteria.Builder.create();
420 criteria.setDocumentTypeName(documentTypeName);
421 floatValueToUse = searchAttributeFloatValue.add(BigDecimal.ONE);
422 addSearchableAttributeRange(criteria, searchAttributeFloatKey, floatValueToUse.toString(), null, false);
423 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
424 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
425
426
427 criteria = DocumentSearchCriteria.Builder.create();
428 criteria.setDocumentTypeName(documentTypeName);
429 floatValueToUse = searchAttributeFloatValue;
430 addSearchableAttributeRange(criteria, searchAttributeFloatKey, null, floatValueToUse.toString(), true);
431 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
432 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
433
434 criteria = DocumentSearchCriteria.Builder.create();
435 criteria.setDocumentTypeName(documentTypeName);
436 floatValueToUse = searchAttributeFloatValue.subtract(BigDecimal.ONE);
437 addSearchableAttributeRange(criteria, searchAttributeFloatKey, null, floatValueToUse.toString(), true);
438 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
439 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
440
441 criteria = DocumentSearchCriteria.Builder.create();
442 criteria.setDocumentTypeName(documentTypeName);
443 floatValueToUse = searchAttributeFloatValue.add(BigDecimal.ONE);
444 addSearchableAttributeRange(criteria, searchAttributeFloatKey, null, floatValueToUse.toString(), true);
445 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
446 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
447
448
449 criteria = DocumentSearchCriteria.Builder.create();
450 criteria.setDocumentTypeName(documentTypeName);
451 addSearchableAttributeRange(criteria, searchAttributeFloatKey, searchAttributeFloatValue.toString(),
452 searchAttributeFloatValue.toString(), true);
453 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
454 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
455
456 criteria = DocumentSearchCriteria.Builder.create();
457 criteria.setDocumentTypeName(documentTypeName);
458 addSearchableAttributeRange(criteria, searchAttributeFloatKey, (searchAttributeFloatValue.add(new BigDecimal(
459 2))).toString(), (searchAttributeFloatValue.add(new BigDecimal(4))).toString(), true);
460 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
461 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
462
463 criteria = DocumentSearchCriteria.Builder.create();
464 criteria.setDocumentTypeName(documentTypeName);
465 addSearchableAttributeRange(criteria, searchAttributeFloatKey, (searchAttributeFloatValue.subtract(
466 new BigDecimal(4))).toString(), (searchAttributeFloatValue.subtract(new BigDecimal(2))).toString(),
467 true);
468 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
469 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
470
471 criteria = DocumentSearchCriteria.Builder.create();
472 criteria.setDocumentTypeName(documentTypeName);
473 addSearchableAttributeRange(criteria, searchAttributeFloatKey, (searchAttributeFloatValue.subtract(new BigDecimal(2))).toString(), (searchAttributeFloatValue.add(new BigDecimal(2))).toString(), true);
474 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
475 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
476
477 criteria = DocumentSearchCriteria.Builder.create();
478 criteria.setDocumentTypeName(documentTypeName);
479 addSearchableAttributeRange(criteria, searchAttributeFloatKey, (searchAttributeFloatValue.add(new BigDecimal(
480 2))).toString(), (searchAttributeFloatValue.subtract(new BigDecimal(2))).toString(), true);
481 try {
482 docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
483 fail("Error should have been thrown for invalid range");
484 } catch (WorkflowServiceErrorException e) {}
485
486
487
488 String searchAttributeDateTimeKey = TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY;
489 Calendar searchAttributeDateTimeValue = TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE.toGregorianCalendar();
490
491 Calendar calendarValueToUse = null;
492
493 criteria = DocumentSearchCriteria.Builder.create();
494 criteria.setDocumentTypeName(documentTypeName);
495 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
496 String valueToSearch = DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(
497 calendarValueToUse));
498 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, valueToSearch, null, false);
499 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
500 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
501
502 criteria = DocumentSearchCriteria.Builder.create();
503 criteria.setDocumentTypeName(documentTypeName);
504 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
505 calendarValueToUse.add(Calendar.DATE, -1);
506 valueToSearch = DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(
507 calendarValueToUse));
508 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, valueToSearch, null, false);
509 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
510 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
511
512 criteria = DocumentSearchCriteria.Builder.create();
513 criteria.setDocumentTypeName(documentTypeName);
514 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
515 calendarValueToUse.add(Calendar.DATE, 1);
516 valueToSearch = DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(
517 calendarValueToUse));
518 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, valueToSearch, null, false);
519 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
520 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
521
522
523 criteria = DocumentSearchCriteria.Builder.create();
524 criteria.setDocumentTypeName(documentTypeName);
525 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
526 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, null,
527 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)), true);
528 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
529 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
530
531 criteria = DocumentSearchCriteria.Builder.create();
532 criteria.setDocumentTypeName(documentTypeName);
533 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
534 calendarValueToUse.add(Calendar.DATE, -1);
535 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, null, DocumentSearchInternalUtils
536 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)), true);
537 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
538 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
539
540 criteria = DocumentSearchCriteria.Builder.create();
541 criteria.setDocumentTypeName(documentTypeName);
542 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
543 calendarValueToUse.add(Calendar.DATE, 1);
544 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, null,
545 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)), true);
546 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
547 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
548
549
550 criteria = DocumentSearchCriteria.Builder.create();
551 criteria.setDocumentTypeName(documentTypeName);
552 Calendar lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
553 Calendar upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
554 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, DocumentSearchInternalUtils
555 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils
556 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true);
557 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
558 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
559
560 criteria = DocumentSearchCriteria.Builder.create();
561 criteria.setDocumentTypeName(documentTypeName);
562 lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
563 lowerBoundValue.add(Calendar.DATE, 2);
564 upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
565 upperBoundValue.add(Calendar.DATE, 4);
566 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, DocumentSearchInternalUtils
567 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils
568 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true);
569 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
570 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
571
572 criteria = DocumentSearchCriteria.Builder.create();
573 criteria.setDocumentTypeName(documentTypeName);
574 lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
575 lowerBoundValue.add(Calendar.DATE, -4);
576 upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
577 upperBoundValue.add(Calendar.DATE, -2);
578 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, DocumentSearchInternalUtils
579 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils
580 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true);
581 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
582 assertEquals("Search results should have one document.", 0, results.getSearchResults().size());
583
584 criteria = DocumentSearchCriteria.Builder.create();
585 criteria.setDocumentTypeName(documentTypeName);
586 lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
587 lowerBoundValue.add(Calendar.DATE, -2);
588 upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
589 upperBoundValue.add(Calendar.DATE, 2);
590 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, DocumentSearchInternalUtils
591 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils
592 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true);
593 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
594 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
595
596 criteria = DocumentSearchCriteria.Builder.create();
597 criteria.setDocumentTypeName(documentTypeName);
598 lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
599 lowerBoundValue.add(Calendar.DATE, 2);
600 upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
601 upperBoundValue.add(Calendar.DATE, -2);
602 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, DocumentSearchInternalUtils
603 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils
604 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true);
605 try {
606 docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
607 fail("Error should have been thrown for invalid range");
608 } catch (WorkflowServiceErrorException e) {}
609 }
610
611
612
613
614 @Test public void testRangeDefinitionStringAttributes() throws Exception {
615 String documentTypeName = "RangeDefinitionTestDocType";
616 DocumentType docType = KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName);
617 String principalName = "rkirkend";
618 String principalId = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(principalName).getPrincipalId();
619 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(principalId, documentTypeName);
620
621
622 WorkflowAttributeDefinition.Builder inclusiveLowerXMLDef = WorkflowAttributeDefinition.Builder.create("TextFieldWithInclusiveLower");
623 inclusiveLowerXMLDef.addPropertyDefinition("textFieldWithInclusiveLower", "newvalue");
624 workflowDocument.addSearchableDefinition(inclusiveLowerXMLDef.build());
625
626 WorkflowAttributeDefinition.Builder caseSensitiveXMLDef = WorkflowAttributeDefinition.Builder.create("TextFieldWithCaseSensitivity");
627 caseSensitiveXMLDef.addPropertyDefinition("textFieldWithCaseSensitivity", "thevalue");
628 workflowDocument.addSearchableDefinition(caseSensitiveXMLDef.build());
629
630 WorkflowAttributeDefinition.Builder overridesXMLDef = WorkflowAttributeDefinition.Builder.create("TextFieldWithOverrides");
631 overridesXMLDef.addPropertyDefinition("textFieldWithOverrides", "SomeVal");
632 workflowDocument.addSearchableDefinition(overridesXMLDef.build());
633
634 workflowDocument.setTitle("Range Def Test");
635 workflowDocument.route("routing range def doc.");
636
637 workflowDocument = WorkflowDocumentFactory.loadDocument(principalId, workflowDocument.getDocumentId());
638
639
640 assertSearchBehavesAsExpected(docType, principalId, "textFieldWithInclusiveLower",
641 new String[] { "newvalue", "" , "" , "NEWVALUD", "newValuf", "newValuj", "newvaluf"},
642 new String[] { "" , "newvalue", "Newvaluf", "NEWVALUF", "newValud", "NEWVALUK", "" },
643 new int[] { 1 , 0 , 1 , 1 , -1 , 0 , 0 });
644
645
646 assertSearchBehavesAsExpected(docType, principalId, "textFieldWithCaseSensitivity",
647 new String[] { "thevalue", "" , "" , "THEVALUD", "thevalud", "Thevalud", "THEVALUF"},
648 new String[] { "" , "thevalue", "Thevalue", "THEVALUF", "THEVALUF", "Thevaluf", "" },
649 new int[] { 1 , 1 , 0 , 0 , -1 , 0 , 1 });
650
651
652
653 assertSearchBehavesAsExpected(docType, principalId, "textFieldWithOverrides",
654 new String[] { "someval", "SomeVal", "" , "" , "SOMEVAK", "SomeVam", "SOMEVAM", "somevak", "" },
655 new String[] { "" , "" , "SOMEVAL", "SomeVal", "SomeVam", "SOMEVAK", "SomeVak", "" , "SomeVak"},
656 new int[] { 0 , 0 , 0 , 1 , 1 , 0 , 0 , 1 , 0 });
657 }
658
659
660
661
662
663
664
665
666
667
668
669
670 private void assertSearchBehavesAsExpected(DocumentType docType, String principalId, String fieldDefKey, String[] lowBounds, String[] upBounds,
671 int[] resultSizes) throws Exception {
672 DocumentSearchCriteria.Builder criteria = null;
673 DocumentSearchResults results = null;
674 DocumentSearchService docSearchService = KEWServiceLocator.getDocumentSearchService();
675 for (int i = 0; i < resultSizes.length; i++) {
676 criteria = DocumentSearchCriteria.Builder.create();
677 criteria.setDocumentTypeName(docType.getName());
678 addSearchableAttributeRange(criteria, fieldDefKey, lowBounds[i], upBounds[i], true);
679 try {
680 results = docSearchService.lookupDocuments(principalId, criteria.build());
681 if (resultSizes[i] < 0) {
682 fail(fieldDefKey + "'s search at loop index " + i + " should have thrown an exception");
683 }
684 assertEquals(fieldDefKey
685 + "'s search results at loop index "
686 + i
687 + " returned the wrong number of documents.", resultSizes[i], results.getSearchResults().size());
688 } catch (Exception ex) {
689 if (resultSizes[i] >= 0) {
690 fail(fieldDefKey + "'s search at loop index " + i + " should not have thrown an exception");
691 }
692 }
693 }
694 }
695 }