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.Before;
19 import org.junit.Ignore;
20 import org.junit.Test;
21 import org.kuali.rice.core.api.uif.RemotableAttributeError;
22 import org.kuali.rice.core.framework.persistence.jdbc.sql.SQLUtils;
23 import org.kuali.rice.kew.api.KewApiConstants;
24 import org.kuali.rice.kew.api.WorkflowDocument;
25 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
26 import org.kuali.rice.kew.api.document.attribute.WorkflowAttributeDefinition;
27 import org.kuali.rice.kew.api.document.search.DocumentSearchCriteria;
28 import org.kuali.rice.kew.api.document.search.DocumentSearchResults;
29 import org.kuali.rice.kew.api.extension.ExtensionDefinition;
30 import org.kuali.rice.kew.docsearch.DocumentSearchInternalUtils;
31 import org.kuali.rice.kew.docsearch.DocumentSearchTestBase;
32 import org.kuali.rice.kew.docsearch.TestXMLSearchableAttributeDateTime;
33 import org.kuali.rice.kew.docsearch.TestXMLSearchableAttributeFloat;
34 import org.kuali.rice.kew.docsearch.TestXMLSearchableAttributeLong;
35 import org.kuali.rice.kew.docsearch.TestXMLSearchableAttributeString;
36 import org.kuali.rice.kew.docsearch.service.DocumentSearchService;
37 import org.kuali.rice.kew.doctype.bo.DocumentType;
38 import org.kuali.rice.kew.doctype.service.DocumentTypeService;
39 import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
40 import org.kuali.rice.kew.service.KEWServiceLocator;
41 import org.kuali.rice.kim.api.identity.Person;
42 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
43
44 import java.math.BigDecimal;
45 import java.util.Calendar;
46 import java.util.List;
47
48 import static org.junit.Assert.*;
49 import static org.junit.Assert.assertEquals;
50
51
52
53
54
55
56
57 public class StandardGenericXMLSearchableAttributeRangesTest extends DocumentSearchTestBase {
58 private DocumentSearchService docSearchService;
59
60 protected void loadTestData() throws Exception {
61 loadXmlFile("XmlConfig.xml");
62 }
63
64 @Before
65 public void retrieveDocSearchSvc() {
66 docSearchService = (DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
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 @Test public void testValidateUserSearchRangeInputs() {
189
190 StandardGenericXMLSearchableAttribute searchAttribute = getAttribute("XMLSearchableAttributeStringRange");
191 ExtensionDefinition ed = createExtensionDefinition("XMLSearchableAttributeStringRange");
192
193 String documentTypeName = "SearchDocType";
194
195 assertDocumentSearchCriteriaValidation(searchAttribute, ed, TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, ">= jack", false);
196
197 RemotableAttributeError error = assertDocumentSearchCriteriaValidation(searchAttribute, ed, TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, "<= jack.jack", true);
198 assertEquals("Validation error should match xml attribute message", "Invalid first name", error.getMessage());
199
200 assertDocumentSearchCriteriaValidation(searchAttribute, ed, TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, ">= jack*jack", false);
201
202 searchAttribute = getAttribute("XMLSearchableAttributeStdLongRange");
203 ed = createExtensionDefinition("XMLSearchableAttributeStdLongRange");
204 assertDocumentSearchCriteriaValidation(searchAttribute, ed, TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY, "<= " + TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE.toString(), false);
205 error = assertDocumentSearchCriteriaValidation(searchAttribute, ed, TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY, ">= " + TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE.toString() + ".33", true);
206 assertTrue("Validation error is incorrect", error.getMessage().endsWith("does not conform to standard validation for field type."));
207 error = assertDocumentSearchCriteriaValidation(searchAttribute, ed, TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY, "<= jack*jack", true);
208 assertTrue("Validation error is incorrect", error.getMessage().endsWith("does not conform to standard validation for field type."));
209
210 searchAttribute = getAttribute("XMLSearchableAttributeStdFloatRange");
211 ed = createExtensionDefinition("XMLSearchableAttributeStdFloatRange");
212 assertDocumentSearchCriteriaValidation(searchAttribute, ed, TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY, ">= " + TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE.toString(), false);
213 error = assertDocumentSearchCriteriaValidation(searchAttribute, ed, TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY, "<= " + TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE.toString() + "a", true);
214 assertTrue("Validation error is incorrect", error.getMessage().endsWith("does not conform to standard validation for field type."));
215 error = assertDocumentSearchCriteriaValidation(searchAttribute, ed, TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY, ">= " + TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE.toString() + "*", true);
216 assertTrue("Validation error is incorrect", error.getMessage().endsWith("does not conform to standard validation for field type."));
217
218 searchAttribute = getAttribute("XMLSearchableAttributeStdDateTimeRange");
219 ed = createExtensionDefinition("XMLSearchableAttributeStdDateTimeRange");
220 assertDocumentSearchCriteriaValidation(searchAttribute, ed, TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY, "<= " + DocumentSearchInternalUtils.getDisplayValueWithDateOnly(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE), false);
221 assertDocumentSearchCriteriaValidation(searchAttribute, ed, TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY, ">= 001/5/08", false);
222 error = assertDocumentSearchCriteriaValidation(searchAttribute, ed, TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY, ">= 41/5/08", true);
223 assertTrue("Validation error is incorrect", error.getMessage().endsWith("does not conform to standard validation for field type."));
224 error = assertDocumentSearchCriteriaValidation(searchAttribute, ed, TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY, "<= 01/02/20*", true);
225 assertTrue("Validation error is incorrect", error.getMessage().endsWith("does not conform to standard validation for field type."));
226 }
227
228
229
230
231 protected RemotableAttributeError assertDocumentSearchCriteriaValidation(StandardGenericXMLSearchableAttribute attribute, ExtensionDefinition ed, String attrkey, String attrvalue, boolean expectError) {
232 DocumentSearchCriteria.Builder dscb = DocumentSearchCriteria.Builder.create();
233 dscb.addDocumentAttributeValue(attrkey, attrvalue);
234
235 List<RemotableAttributeError> errors = attribute.validateDocumentAttributeCriteria(ed, dscb.build());
236
237 if (expectError) {
238 assertEquals("Validation should return a single error message.", 1, errors.size());
239 return errors.get(0);
240 } else {
241 assertEquals("Validation should not have returned an error.", 0, errors.size());
242 return null;
243 }
244 }
245
246
247
248
249 protected static ExtensionDefinition createExtensionDefinition(String attrName) {
250 ExtensionDefinition.Builder edb = ExtensionDefinition.Builder.create(attrName, KewApiConstants.SEARCHABLE_XML_ATTRIBUTE_TYPE, StandardGenericXMLSearchableAttribute.class.getName());
251 edb.getConfiguration().put(KewApiConstants.ATTRIBUTE_XML_CONFIG_DATA, KEWServiceLocator.getRuleAttributeService().findByName(attrName).getXmlConfigData());
252 return edb.build();
253 }
254
255
256
257
258 protected WorkflowDocument setUpSearchableDoc() {
259 String documentTypeName = "SearchDocTypeRangeSearchDataType";
260 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
261 String userNetworkId = "rkirkend";
262 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(userNetworkId), documentTypeName);
263
264
265
266
267
268
269 WorkflowAttributeDefinition.Builder stringXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttributeStringRange");
270 stringXMLDef.addPropertyDefinition(TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE);
271 workflowDocument.addSearchableDefinition(stringXMLDef.build());
272
273 WorkflowAttributeDefinition.Builder longXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttributeStdLongRange");
274 longXMLDef.addPropertyDefinition(TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE.toString());
275 workflowDocument.addSearchableDefinition(longXMLDef.build());
276
277 WorkflowAttributeDefinition.Builder floatXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttributeStdFloatRange");
278 floatXMLDef.addPropertyDefinition(TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE.toString());
279 workflowDocument.addSearchableDefinition(floatXMLDef.build());
280
281 WorkflowAttributeDefinition.Builder dateXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttributeStdDateTimeRange");
282 dateXMLDef.addPropertyDefinition(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY, DocumentSearchInternalUtils
283 .getDisplayValueWithDateOnly(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE));
284 workflowDocument.addSearchableDefinition(dateXMLDef.build());
285
286 workflowDocument.setTitle("Routing style");
287 workflowDocument.route("routing this document.");
288
289 return WorkflowDocumentFactory.loadDocument(getPrincipalIdForName(userNetworkId), workflowDocument.getDocumentId());
290 }
291
292
293
294
295 private static final int EXPECT_EXCEPTION = -1;
296
297
298
299
300 protected void assertRangeSearchResults(String docType, String userId, String attrKey, String lowerBound, String upperBound, boolean upperBoundInclusive, int expected) throws WorkflowServiceErrorException {
301 DocumentSearchCriteria.Builder criteria = DocumentSearchCriteria.Builder.create();
302 criteria.setDocumentTypeName(docType);
303
304 addSearchableAttributeRange(criteria, attrKey, lowerBound, upperBound, upperBoundInclusive);
305
306 DocumentSearchResults results;
307 try {
308 results = docSearchService.lookupDocuments(userId, criteria.build());
309 if (expected == EXPECT_EXCEPTION) fail("Error should have been thrown for invalid range");
310 } catch (WorkflowServiceErrorException e) {
311 if (expected == EXPECT_EXCEPTION) return;
312 else throw e;
313 }
314
315 assertEquals("Search results should have " + expected + " document(s).", expected, results.getSearchResults().size());
316 }
317
318 @Test public void testStringRanges() throws Exception {
319 WorkflowDocument doc = setUpSearchableDoc();
320 String userId = doc.getInitiatorPrincipalId();
321 String docType = doc.getDocumentTypeName();
322
323 assertRangeSearchResults(docType, userId, TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE, null, false, 1);
324 }
325
326 @Test public void testLongRanges() throws Exception {
327 WorkflowDocument doc = setUpSearchableDoc();
328 String userId = doc.getInitiatorPrincipalId();
329 String docType = doc.getDocumentTypeName();
330
331 String searchAttributeLongKey = TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY;
332 Long searchAttributeLongValue = TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE.longValue();
333 Long longValueToUse = null;
334
335
336 longValueToUse = searchAttributeLongValue;
337 assertRangeSearchResults(docType, userId, searchAttributeLongKey, longValueToUse.toString(), null, false, 1);
338
339 longValueToUse = Long.valueOf(searchAttributeLongValue.longValue() - 1);
340 assertRangeSearchResults(docType, userId, searchAttributeLongKey, longValueToUse.toString(), null, false, 1);
341
342 longValueToUse = Long.valueOf(searchAttributeLongValue.longValue() + 1);
343 assertRangeSearchResults(docType, userId, searchAttributeLongKey, longValueToUse.toString(), null, false, 0);
344
345
346 longValueToUse = searchAttributeLongValue;
347 assertRangeSearchResults(docType, userId, searchAttributeLongKey, null, longValueToUse.toString(), true, 1);
348
349 longValueToUse = Long.valueOf(searchAttributeLongValue.longValue() - 1);
350 assertRangeSearchResults(docType, userId, searchAttributeLongKey, null, longValueToUse.toString(), true, 0);
351
352 longValueToUse = Long.valueOf(searchAttributeLongValue.longValue() + 1);
353 assertRangeSearchResults(docType, userId, searchAttributeLongKey, null, longValueToUse.toString(), true, 1);
354
355
356
357 assertRangeSearchResults(docType, userId, searchAttributeLongKey,
358 Long.valueOf(searchAttributeLongValue.longValue()).toString(),
359 Long.valueOf(searchAttributeLongValue.longValue()).toString(), true, 1);
360
361
362 assertRangeSearchResults(docType, userId, searchAttributeLongKey,
363 Long.valueOf(searchAttributeLongValue.longValue() + 2).toString(),
364 Long.valueOf(searchAttributeLongValue.longValue() + 4).toString(), true, 0);
365
366
367 assertRangeSearchResults(docType, userId, searchAttributeLongKey,
368 Long.valueOf(searchAttributeLongValue.longValue() - 2).toString(),
369 Long.valueOf(searchAttributeLongValue.longValue() - 4).toString(), true, EXPECT_EXCEPTION);
370
371 assertRangeSearchResults(docType, userId, searchAttributeLongKey,
372 Long.valueOf(searchAttributeLongValue.longValue() - 4).toString(),
373 Long.valueOf(searchAttributeLongValue.longValue() - 2).toString(), true, 0);
374
375
376 assertRangeSearchResults(docType, userId, searchAttributeLongKey,
377 Long.valueOf(searchAttributeLongValue.longValue() - 2).toString(),
378 Long.valueOf(searchAttributeLongValue.longValue() + 2).toString(), true, 1);
379
380
381 assertRangeSearchResults(docType, userId, searchAttributeLongKey,
382 Long.valueOf(searchAttributeLongValue.longValue() + 2).toString(),
383 Long.valueOf(searchAttributeLongValue.longValue() - 2).toString(), true, EXPECT_EXCEPTION);
384 }
385
386 @Test public void testFloatRanges() throws Exception {
387 WorkflowDocument doc = setUpSearchableDoc();
388 String userId = doc.getInitiatorPrincipalId();
389 String docType = doc.getDocumentTypeName();
390
391 String searchAttributeFloatKey = TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY;
392 BigDecimal searchAttributeFloatValue = TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE;
393
394 BigDecimal floatValueToUse = null;
395
396 floatValueToUse = searchAttributeFloatValue;
397
398 assertRangeSearchResults(docType, userId, searchAttributeFloatKey, floatValueToUse.toString(), null, false, 1);
399
400 floatValueToUse = searchAttributeFloatValue.subtract(BigDecimal.ONE);
401 assertRangeSearchResults(docType, userId, searchAttributeFloatKey, floatValueToUse.toString(), null, false, 1);
402
403 floatValueToUse = searchAttributeFloatValue.add(BigDecimal.ONE);
404 assertRangeSearchResults(docType, userId, searchAttributeFloatKey, floatValueToUse.toString(), null, false, 0);
405
406
407 floatValueToUse = searchAttributeFloatValue;
408
409 assertRangeSearchResults(docType, userId, searchAttributeFloatKey, null, floatValueToUse.toString(), true, 1);
410
411 floatValueToUse = searchAttributeFloatValue.subtract(BigDecimal.ONE);
412 assertRangeSearchResults(docType, userId, searchAttributeFloatKey, null, floatValueToUse.toString(), true, 0);
413
414 floatValueToUse = searchAttributeFloatValue.add(BigDecimal.ONE);
415 assertRangeSearchResults(docType, userId, searchAttributeFloatKey, null, floatValueToUse.toString(), true, 1);
416
417
418
419
420
421 assertRangeSearchResults(docType, userId, searchAttributeFloatKey, searchAttributeFloatValue.toString(), searchAttributeFloatValue.toString(), true, 1);
422
423
424 assertRangeSearchResults(docType, userId, searchAttributeFloatKey,
425 searchAttributeFloatValue.add(new BigDecimal(2)).toString(),
426 searchAttributeFloatValue.add(new BigDecimal(4)).toString(), true, 0);
427
428
429 assertRangeSearchResults(docType, userId, searchAttributeFloatKey,
430 searchAttributeFloatValue.subtract(new BigDecimal(4)).toString(),
431 searchAttributeFloatValue.subtract(new BigDecimal(2)).toString(), true, 0);
432
433
434 assertRangeSearchResults(docType, userId, searchAttributeFloatKey,
435 searchAttributeFloatValue.subtract(new BigDecimal(2)).toString(),
436 searchAttributeFloatValue.add(new BigDecimal(2)).toString(), true, 1);
437
438
439 assertRangeSearchResults(docType, userId, searchAttributeFloatKey,
440 searchAttributeFloatValue.add(new BigDecimal(2)).toString(),
441 searchAttributeFloatValue.subtract(new BigDecimal(2)).toString(), true, EXPECT_EXCEPTION);
442 }
443
444 @Test public void testDateRanges() throws Exception {
445 WorkflowDocument doc = setUpSearchableDoc();
446 String userId = doc.getInitiatorPrincipalId();
447 String docType = doc.getDocumentTypeName();
448
449
450
451 String searchAttributeDateTimeKey = TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY;
452 Calendar searchAttributeDateTimeValue = TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE.toGregorianCalendar();
453
454 Calendar calendarValueToUse = null;
455
456 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
457 String valueToSearch = DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse));
458
459 assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey, valueToSearch, null, false, 1);
460
461 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
462 calendarValueToUse.add(Calendar.DATE, -1);
463 valueToSearch = DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse));
464 assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey, valueToSearch, null, false, 1);
465
466 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
467 calendarValueToUse.add(Calendar.DATE, 1);
468 valueToSearch = DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse));
469 assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey, valueToSearch, null, false, 0);
470
471
472 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
473 assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey,
474 null,
475 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)), true, 1);
476
477 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
478 calendarValueToUse.add(Calendar.DATE, -1);
479 assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey,
480 null,
481 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)), true, 0);
482
483 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
484 calendarValueToUse.add(Calendar.DATE, 1);
485 assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey,
486 null,
487 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)), true, 1);
488
489
490 Calendar lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
491 Calendar upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
492
493 assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey,
494 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)),
495 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true, 1);
496
497 lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
498 lowerBoundValue.add(Calendar.DATE, 2);
499 upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
500 upperBoundValue.add(Calendar.DATE, 4);
501 assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey,
502 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)),
503 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true, 0);
504
505 lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
506 lowerBoundValue.add(Calendar.DATE, -4);
507 upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
508 upperBoundValue.add(Calendar.DATE, -2);
509 assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey,
510 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)),
511 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true, 0);
512
513 lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
514 lowerBoundValue.add(Calendar.DATE, -2);
515 upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
516 upperBoundValue.add(Calendar.DATE, 2);
517 assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey,
518 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)),
519 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true, 1);
520
521 lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
522 lowerBoundValue.add(Calendar.DATE, 2);
523 upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
524 upperBoundValue.add(Calendar.DATE, -2);
525 assertRangeSearchResults(docType, userId, searchAttributeDateTimeKey,
526 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)),
527 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true, EXPECT_EXCEPTION);
528 }
529
530
531
532
533 @Ignore
534 @Test public void testSearchableAttributeRanges() throws Exception {
535 String documentTypeName = "SearchDocTypeRangeSearchDataType";
536 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
537 String userNetworkId = "rkirkend";
538 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(userNetworkId), documentTypeName);
539
540
541
542
543
544
545 WorkflowAttributeDefinition.Builder stringXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttributeStringRange");
546 stringXMLDef.addPropertyDefinition(TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE);
547 workflowDocument.addSearchableDefinition(stringXMLDef.build());
548
549 WorkflowAttributeDefinition.Builder longXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttributeStdLongRange");
550 longXMLDef.addPropertyDefinition(TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE.toString());
551 workflowDocument.addSearchableDefinition(longXMLDef.build());
552
553 WorkflowAttributeDefinition.Builder floatXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttributeStdFloatRange");
554 floatXMLDef.addPropertyDefinition(TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE.toString());
555 workflowDocument.addSearchableDefinition(floatXMLDef.build());
556
557 WorkflowAttributeDefinition.Builder dateXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttributeStdDateTimeRange");
558 dateXMLDef.addPropertyDefinition(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY, DocumentSearchInternalUtils
559 .getDisplayValueWithDateOnly(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE));
560 workflowDocument.addSearchableDefinition(dateXMLDef.build());
561
562 workflowDocument.setTitle("Routing style");
563 workflowDocument.route("routing this document.");
564
565 workflowDocument = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName(userNetworkId), workflowDocument.getDocumentId());
566
567 DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
568 Person user = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(userNetworkId);
569
570
571 DocumentSearchCriteria.Builder criteria = null;
572 DocumentSearchResults results = null;
573
574 criteria = DocumentSearchCriteria.Builder.create();
575 criteria.setDocumentTypeName(documentTypeName);
576 addSearchableAttributeRange(criteria, TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE, null, false);
577 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
578 int size = results.getSearchResults().size();
579 assertTrue("Searching for a lower bound of 'jack'. case insensitive, inclusive. so searching for something >= 'JACK'. Should Return 1, but got" + size, 1 == size);
580
581
582
583 String searchAttributeLongKey = TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY;
584 Long searchAttributeLongValue = TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE.longValue();
585 Long longValueToUse = null;
586
587
588 criteria = DocumentSearchCriteria.Builder.create();
589 criteria.setDocumentTypeName(documentTypeName);
590 longValueToUse = searchAttributeLongValue;
591 addSearchableAttributeRange(criteria, searchAttributeLongKey, longValueToUse.toString(), null, false);
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 longValueToUse = Long.valueOf(searchAttributeLongValue.longValue() - 1);
598 addSearchableAttributeRange(criteria, searchAttributeLongKey, longValueToUse.toString(), null, false);
599 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
600 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
601
602 criteria = DocumentSearchCriteria.Builder.create();
603 criteria.setDocumentTypeName(documentTypeName);
604 longValueToUse = Long.valueOf(searchAttributeLongValue.longValue() + 1);
605 addSearchableAttributeRange(criteria, searchAttributeLongKey, longValueToUse.toString(), null, false);
606 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
607 assertEquals("Search results should have zero documents.", 0, results.getSearchResults().size());
608
609
610 criteria = DocumentSearchCriteria.Builder.create();
611 criteria.setDocumentTypeName(documentTypeName);
612 longValueToUse = searchAttributeLongValue;
613 addSearchableAttributeRange(criteria, searchAttributeLongKey, null, longValueToUse.toString(), true);
614 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
615 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
616
617 criteria = DocumentSearchCriteria.Builder.create();
618 criteria.setDocumentTypeName(documentTypeName);
619 longValueToUse = Long.valueOf(searchAttributeLongValue.longValue() - 1);
620 addSearchableAttributeRange(criteria, searchAttributeLongKey, null, longValueToUse.toString(), true);
621 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
622 assertEquals("Search results should have zero documents.", 0, results.getSearchResults().size());
623
624 criteria = DocumentSearchCriteria.Builder.create();
625 criteria.setDocumentTypeName(documentTypeName);
626 longValueToUse = Long.valueOf(searchAttributeLongValue.longValue() + 1);
627 addSearchableAttributeRange(criteria, searchAttributeLongKey, null, longValueToUse.toString(), true);
628 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
629 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
630
631
632 criteria = DocumentSearchCriteria.Builder.create();
633 criteria.setDocumentTypeName(documentTypeName);
634
635 addSearchableAttributeRange(criteria, searchAttributeLongKey, Long.valueOf(searchAttributeLongValue.longValue())
636 .toString(), Long.valueOf(searchAttributeLongValue.longValue()).toString(), true);
637 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
638 assertEquals("Search results should have zero documents.", 1, results.getSearchResults().size());
639
640 criteria = DocumentSearchCriteria.Builder.create();
641 criteria.setDocumentTypeName(documentTypeName);
642
643 addSearchableAttributeRange(criteria, searchAttributeLongKey, Long.valueOf(
644 searchAttributeLongValue.longValue() + 2).toString(), Long.valueOf(
645 searchAttributeLongValue.longValue() + 4).toString(), true);
646 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
647 assertEquals("Search results should have zero documents.", 0, results.getSearchResults().size());
648
649 criteria = DocumentSearchCriteria.Builder.create();
650 criteria.setDocumentTypeName(documentTypeName);
651
652 addSearchableAttributeRange(criteria, searchAttributeLongKey, Long.valueOf(
653 searchAttributeLongValue.longValue() - 2).toString(), Long.valueOf(
654 searchAttributeLongValue.longValue() - 4).toString(), true);
655 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
656 assertEquals("Search results should have zero documents.", 0, results.getSearchResults().size());
657
658 criteria = DocumentSearchCriteria.Builder.create();
659 criteria.setDocumentTypeName(documentTypeName);
660
661 addSearchableAttributeRange(criteria, searchAttributeLongKey, Long.valueOf(
662 searchAttributeLongValue.longValue() - 2).toString(), Long.valueOf(
663 searchAttributeLongValue.longValue() + 2).toString(), true);
664 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
665 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
666
667 criteria = DocumentSearchCriteria.Builder.create();
668 criteria.setDocumentTypeName(documentTypeName);
669
670 addSearchableAttributeRange(criteria, searchAttributeLongKey, Long.valueOf(searchAttributeLongValue.longValue() + 2).toString(), Long.valueOf(searchAttributeLongValue.longValue() - 2).toString(), true);
671 try {
672
673 docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
674
675 } catch (WorkflowServiceErrorException e) {}
676
677
678 String searchAttributeFloatKey = TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY;
679 BigDecimal searchAttributeFloatValue = TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE;
680
681 BigDecimal floatValueToUse = null;
682
683 criteria = DocumentSearchCriteria.Builder.create();
684 criteria.setDocumentTypeName(documentTypeName);
685 floatValueToUse = searchAttributeFloatValue;
686 addSearchableAttributeRange(criteria, searchAttributeFloatKey, floatValueToUse.toString(), null, false);
687
688 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
689 assertEquals("Search results should have zero documents.", 0, results.getSearchResults().size());
690
691 criteria = DocumentSearchCriteria.Builder.create();
692 criteria.setDocumentTypeName(documentTypeName);
693 floatValueToUse = searchAttributeFloatValue.subtract(BigDecimal.ONE);
694 addSearchableAttributeRange(criteria, searchAttributeFloatKey, floatValueToUse.toString(), null, false);
695 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
696 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
697
698 criteria = DocumentSearchCriteria.Builder.create();
699 criteria.setDocumentTypeName(documentTypeName);
700 floatValueToUse = searchAttributeFloatValue.add(BigDecimal.ONE);
701 addSearchableAttributeRange(criteria, searchAttributeFloatKey, floatValueToUse.toString(), null, false);
702 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
703 assertEquals("Search results should have zero documents.", 0, results.getSearchResults().size());
704
705
706 criteria = DocumentSearchCriteria.Builder.create();
707 criteria.setDocumentTypeName(documentTypeName);
708 floatValueToUse = searchAttributeFloatValue;
709 addSearchableAttributeRange(criteria, searchAttributeFloatKey, null, floatValueToUse.toString(), true);
710 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
711 assertEquals("Search results should have zero documents.", 0, results.getSearchResults().size());
712
713 criteria = DocumentSearchCriteria.Builder.create();
714 criteria.setDocumentTypeName(documentTypeName);
715 floatValueToUse = searchAttributeFloatValue.subtract(BigDecimal.ONE);
716 addSearchableAttributeRange(criteria, searchAttributeFloatKey, null, floatValueToUse.toString(), true);
717 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
718 assertEquals("Search results should have zero documents.", 0, results.getSearchResults().size());
719
720 criteria = DocumentSearchCriteria.Builder.create();
721 criteria.setDocumentTypeName(documentTypeName);
722 floatValueToUse = searchAttributeFloatValue.add(BigDecimal.ONE);
723 addSearchableAttributeRange(criteria, searchAttributeFloatKey, null, floatValueToUse.toString(), true);
724 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
725 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
726
727
728 criteria = DocumentSearchCriteria.Builder.create();
729 criteria.setDocumentTypeName(documentTypeName);
730 addSearchableAttributeRange(criteria, searchAttributeFloatKey, searchAttributeFloatValue.toString(),
731 searchAttributeFloatValue.toString(), true);
732 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
733 assertEquals("Search results should have zero documents.", 0, results.getSearchResults().size());
734
735 criteria = DocumentSearchCriteria.Builder.create();
736 criteria.setDocumentTypeName(documentTypeName);
737
738 addSearchableAttributeRange(criteria, searchAttributeFloatKey, (searchAttributeFloatValue.add(new BigDecimal(
739 2))).toString(), (searchAttributeFloatValue.add(new BigDecimal(4))).toString(), true);
740 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
741 assertEquals("Search results should have zero documents.", 0, results.getSearchResults().size());
742
743 criteria = DocumentSearchCriteria.Builder.create();
744 criteria.setDocumentTypeName(documentTypeName);
745
746 addSearchableAttributeRange(criteria, searchAttributeFloatKey, (searchAttributeFloatValue.subtract(
747 new BigDecimal(4))).toString(), (searchAttributeFloatValue.subtract(new BigDecimal(2))).toString(),
748 true);
749 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
750 assertEquals("Search results should have zero documents.", 0, results.getSearchResults().size());
751
752 criteria = DocumentSearchCriteria.Builder.create();
753 criteria.setDocumentTypeName(documentTypeName);
754
755 addSearchableAttributeRange(criteria, searchAttributeFloatKey, (searchAttributeFloatValue.subtract(new BigDecimal(2))).toString(), (searchAttributeFloatValue.add(new BigDecimal(2))).toString(), true);
756 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
757 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
758
759 criteria = DocumentSearchCriteria.Builder.create();
760 criteria.setDocumentTypeName(documentTypeName);
761
762 addSearchableAttributeRange(criteria, searchAttributeFloatKey, (searchAttributeFloatValue.add(new BigDecimal(
763 2))).toString(), (searchAttributeFloatValue.subtract(new BigDecimal(2))).toString(), true);
764 try {
765 docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
766
767 } catch (WorkflowServiceErrorException e) {}
768
769
770
771 String searchAttributeDateTimeKey = TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY;
772 Calendar searchAttributeDateTimeValue = TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE.toGregorianCalendar();
773
774 Calendar calendarValueToUse = null;
775
776 criteria = DocumentSearchCriteria.Builder.create();
777 criteria.setDocumentTypeName(documentTypeName);
778 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
779 String valueToSearch = DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(
780 calendarValueToUse));
781
782 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, valueToSearch, null, false);
783 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
784 assertEquals("Search results should have zero documents.", 0, results.getSearchResults().size());
785
786 criteria = DocumentSearchCriteria.Builder.create();
787 criteria.setDocumentTypeName(documentTypeName);
788 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
789 calendarValueToUse.add(Calendar.DATE, -1);
790 valueToSearch = DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(
791 calendarValueToUse));
792 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, valueToSearch, null, false);
793 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
794 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
795
796 criteria = DocumentSearchCriteria.Builder.create();
797 criteria.setDocumentTypeName(documentTypeName);
798 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
799 calendarValueToUse.add(Calendar.DATE, 1);
800 valueToSearch = DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(
801 calendarValueToUse));
802 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, valueToSearch, null, false);
803 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
804 assertEquals("Search results should have zero documents.", 0, results.getSearchResults().size());
805
806
807 criteria = DocumentSearchCriteria.Builder.create();
808 criteria.setDocumentTypeName(documentTypeName);
809 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
810 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, null,
811 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)), true);
812 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
813 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
814
815 criteria = DocumentSearchCriteria.Builder.create();
816 criteria.setDocumentTypeName(documentTypeName);
817 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
818 calendarValueToUse.add(Calendar.DATE, -1);
819 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, null, DocumentSearchInternalUtils
820 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)), true);
821 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
822 assertEquals("Search results should have zero documents.", 0, results.getSearchResults().size());
823
824 criteria = DocumentSearchCriteria.Builder.create();
825 criteria.setDocumentTypeName(documentTypeName);
826 calendarValueToUse = (Calendar) searchAttributeDateTimeValue.clone();
827 calendarValueToUse.add(Calendar.DATE, 1);
828 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, null,
829 DocumentSearchInternalUtils.getDisplayValueWithDateOnly(SQLUtils.convertCalendar(calendarValueToUse)), true);
830 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
831 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
832
833
834 criteria = DocumentSearchCriteria.Builder.create();
835 criteria.setDocumentTypeName(documentTypeName);
836 Calendar lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
837 Calendar upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
838 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, DocumentSearchInternalUtils
839 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils
840 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true);
841 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
842 assertEquals("Search results should have zer documents.", 0, results.getSearchResults().size());
843
844 criteria = DocumentSearchCriteria.Builder.create();
845 criteria.setDocumentTypeName(documentTypeName);
846 lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
847 lowerBoundValue.add(Calendar.DATE, 2);
848 upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
849 upperBoundValue.add(Calendar.DATE, 4);
850 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, DocumentSearchInternalUtils
851 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils
852 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true);
853 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
854 assertEquals("Search results should have zero documents.", 0, results.getSearchResults().size());
855
856 criteria = DocumentSearchCriteria.Builder.create();
857 criteria.setDocumentTypeName(documentTypeName);
858 lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
859 lowerBoundValue.add(Calendar.DATE, -4);
860 upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
861 upperBoundValue.add(Calendar.DATE, -2);
862 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, DocumentSearchInternalUtils
863 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils
864 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true);
865 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
866 assertEquals("Search results should have zero documents.", 0, results.getSearchResults().size());
867
868 criteria = DocumentSearchCriteria.Builder.create();
869 criteria.setDocumentTypeName(documentTypeName);
870 lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
871 lowerBoundValue.add(Calendar.DATE, -2);
872 upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
873 upperBoundValue.add(Calendar.DATE, 2);
874 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, DocumentSearchInternalUtils
875 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils
876 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true);
877 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
878 assertEquals("Search results should have one document.", 1, results.getSearchResults().size());
879
880 criteria = DocumentSearchCriteria.Builder.create();
881 criteria.setDocumentTypeName(documentTypeName);
882 lowerBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
883 lowerBoundValue.add(Calendar.DATE, 2);
884 upperBoundValue = (Calendar) searchAttributeDateTimeValue.clone();
885 upperBoundValue.add(Calendar.DATE, -2);
886 addSearchableAttributeRange(criteria, searchAttributeDateTimeKey, DocumentSearchInternalUtils
887 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(lowerBoundValue)), DocumentSearchInternalUtils
888 .getDisplayValueWithDateOnly(SQLUtils.convertCalendar(upperBoundValue)), true);
889 try {
890 docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
891
892 } catch (WorkflowServiceErrorException e) {}
893 }
894
895
896
897
898 @Test public void testRangeDefinitionStringAttributes() throws Exception {
899 String documentTypeName = "RangeDefinitionTestDocType";
900 DocumentType docType = KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName);
901 String principalName = "rkirkend";
902 String principalId = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(principalName).getPrincipalId();
903 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(principalId, documentTypeName);
904
905
906 WorkflowAttributeDefinition.Builder inclusiveLowerXMLDef = WorkflowAttributeDefinition.Builder.create("TextFieldWithInclusiveLower");
907 inclusiveLowerXMLDef.addPropertyDefinition("textFieldWithInclusiveLower", "newvalue");
908 workflowDocument.addSearchableDefinition(inclusiveLowerXMLDef.build());
909
910 WorkflowAttributeDefinition.Builder caseSensitiveXMLDef = WorkflowAttributeDefinition.Builder.create("TextFieldWithCaseSensitivity");
911 caseSensitiveXMLDef.addPropertyDefinition("textFieldWithCaseSensitivity", "thevalue");
912 workflowDocument.addSearchableDefinition(caseSensitiveXMLDef.build());
913
914 WorkflowAttributeDefinition.Builder overridesXMLDef = WorkflowAttributeDefinition.Builder.create("TextFieldWithOverrides");
915 overridesXMLDef.addPropertyDefinition("textFieldWithOverrides", "SomeVal");
916 workflowDocument.addSearchableDefinition(overridesXMLDef.build());
917
918 workflowDocument.setTitle("Range Def Test");
919 workflowDocument.route("routing range def doc.");
920
921 workflowDocument = WorkflowDocumentFactory.loadDocument(principalId, workflowDocument.getDocumentId());
922
923
924
925 assertSearchBehavesAsExpected(docType, principalId, "textFieldWithInclusiveLower",
926 new String[] { "newvalue", "" , "" , "NEWVALUD", "newValuf", "newValuj", "newvaluf"},
927 new String[] { "" , "newvalue", "Newvaluf", "NEWVALUF", "newValud", "NEWVALUK", "" },
928 new int[] { 1 , 1 , 1 , 1 , -1 , 0 , 0 });
929
930
931 assertSearchBehavesAsExpected(docType, principalId, "textFieldWithCaseSensitivity",
932 new String[] { "thevalue", "" , "" , "THEVALUD", "thevalud", "Thevalud", "THEVALUF"},
933 new String[] { "" , "thevalue", "Thevalue", "THEVALUF", "THEVALUF", "Thevaluf", "" },
934 new int[] { 1 , 1 , 0 , 0 , -1 , 0 , 1 });
935
936
937
938
939 assertSearchBehavesAsExpected(docType, principalId, "textFieldWithOverrides",
940 new String[] { "someval", "SomeVal", "" , "" , "SOMEVAK", "SomeVam", "SOMEVAM", "somevak", "" },
941 new String[] { "" , "" , "SOMEVAL", "SomeVal", "SomeVam", "SOMEVAK", "SomeVak", "" , "SomeVak"},
942 new int[] { 0 , 0 , 0 , 1 , 1 , 0 , 0 , 1 , 0 });
943 }
944
945
946
947
948
949
950
951
952
953
954
955
956 private void assertSearchBehavesAsExpected(DocumentType docType, String principalId, String fieldDefKey, String[] lowBounds, String[] upBounds,
957 int[] resultSizes) throws Exception {
958 DocumentSearchCriteria.Builder criteria = null;
959 DocumentSearchResults results = null;
960 DocumentSearchService docSearchService = KEWServiceLocator.getDocumentSearchService();
961 for (int i = 0; i < resultSizes.length; i++) {
962 criteria = DocumentSearchCriteria.Builder.create();
963 criteria.setDocumentTypeName(docType.getName());
964 addSearchableAttributeRange(criteria, fieldDefKey, lowBounds[i], upBounds[i], true);
965 try {
966 results = docSearchService.lookupDocuments(principalId, criteria.build());
967 if (resultSizes[i] < 0) {
968 fail(fieldDefKey + "'s search at loop index " + i + " should have thrown an exception");
969 }
970 assertEquals(fieldDefKey
971 + "'s search results at loop index "
972 + i
973 + " returned the wrong number of documents.", resultSizes[i], results.getSearchResults().size());
974 } catch (Exception ex) {
975 if (resultSizes[i] >= 0) {
976 fail(fieldDefKey + "'s search at loop index " + i + " should not have thrown an exception");
977 }
978 }
979 }
980 }
981 }