1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.docsearch.xml;
18
19 import org.junit.Test;
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.DocumentAttribute;
23 import org.kuali.rice.kew.api.document.attribute.WorkflowAttributeDefinition;
24 import org.kuali.rice.kew.api.document.lookup.DocumentLookupCriteria;
25 import org.kuali.rice.kew.api.document.lookup.DocumentLookupResult;
26 import org.kuali.rice.kew.api.document.lookup.DocumentLookupResults;
27 import org.kuali.rice.kew.docsearch.DocumentLookupInternalUtils;
28 import org.kuali.rice.kew.docsearch.DocumentSearchTestBase;
29 import org.kuali.rice.kew.docsearch.SearchableAttributeLongValue;
30 import org.kuali.rice.kew.docsearch.TestXMLSearchableAttributeDateTime;
31 import org.kuali.rice.kew.docsearch.TestXMLSearchableAttributeFloat;
32 import org.kuali.rice.kew.docsearch.TestXMLSearchableAttributeLong;
33 import org.kuali.rice.kew.docsearch.TestXMLSearchableAttributeString;
34 import org.kuali.rice.kew.docsearch.service.DocumentSearchService;
35 import org.kuali.rice.kew.doctype.bo.DocumentType;
36 import org.kuali.rice.kew.doctype.service.DocumentTypeService;
37 import org.kuali.rice.kew.exception.WorkflowException;
38 import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
39 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
40 import org.kuali.rice.kew.service.KEWServiceLocator;
41 import org.kuali.rice.kew.test.TestUtilities;
42 import org.kuali.rice.kim.api.identity.Person;
43 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
44 import org.kuali.rice.test.BaselineTestCase;
45
46 import java.sql.Timestamp;
47
48 import static org.junit.Assert.*;
49
50
51
52
53
54
55
56
57 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
58 public class StandardGenericXMLSearchableAttributeTest extends DocumentSearchTestBase {
59
60 protected void loadTestData() throws Exception {
61 loadXmlFile("XmlConfig.xml");
62 }
63
64 @Test public void testXMLStandardSearchableAttributeWithInvalidValue() throws Exception {
65 String documentTypeName = "SearchDocTypeStandardSearchDataType";
66 String userNetworkId = "rkirkend";
67 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(userNetworkId), documentTypeName);
68
69
70
71
72
73
74 WorkflowAttributeDefinition.Builder longXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttributeStdLong");
75 longXMLDef.addPropertyDefinition(TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY, "123x23");
76 workflowDocument.addSearchableDefinition(longXMLDef.build());
77
78 workflowDocument.setTitle("Routing style");
79 try {
80 workflowDocument.route("routing this document.");
81 fail("Document should be unroutable with invalid searchable attribute value");
82 } catch (Exception e) {
83 e.printStackTrace();
84 }
85
86
87
88
89
90
91
92 TestUtilities.waitForExceptionRouting();
93 }
94
95 @Test public void testXMLStandardSearchableAttributesWithDataType() throws Exception {
96 String documentTypeName = "SearchDocTypeStandardSearchDataType";
97 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
98 String userNetworkId = "rkirkend";
99 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(userNetworkId), documentTypeName);
100
101
102
103
104
105 int i = 0;
106
107 i++;
108 WorkflowAttributeDefinition.Builder stringXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttribute");
109 stringXMLDef.addPropertyDefinition(TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE);
110 workflowDocument.addSearchableDefinition(stringXMLDef.build());
111
112 i++;
113 WorkflowAttributeDefinition.Builder longXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttributeStdLong");
114 longXMLDef.addPropertyDefinition(TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE.toString());
115 workflowDocument.addSearchableDefinition(longXMLDef.build());
116
117 i++;
118 WorkflowAttributeDefinition.Builder floatXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttributeStdFloat");
119 floatXMLDef.addPropertyDefinition(TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE.toString());
120 workflowDocument.addSearchableDefinition(floatXMLDef.build());
121
122 i++;
123 WorkflowAttributeDefinition.Builder dateXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttributeStdDateTime");
124 dateXMLDef.addPropertyDefinition(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY, DocumentLookupInternalUtils
125 .getDisplayValueWithDateOnly(TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE));
126 workflowDocument.addSearchableDefinition(dateXMLDef.build());
127
128 workflowDocument.setTitle("Routing style");
129 workflowDocument.route("routing this document.");
130
131 workflowDocument = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName(userNetworkId), workflowDocument.getDocumentId());
132 DocumentRouteHeaderValue doc = KEWServiceLocator.getRouteHeaderService().getRouteHeader(workflowDocument.getDocumentId());
133
134 DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
135 Person user = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(userNetworkId);
136
137 DocumentLookupCriteria.Builder criteria = DocumentLookupCriteria.Builder.create();
138 criteria.setDocumentTypeName(documentTypeName);
139 addSearchableAttribute(criteria, TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY,
140 TestXMLSearchableAttributeString.SEARCH_STORAGE_VALUE);
141 DocumentLookupResults results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
142
143 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
144
145 DocumentLookupCriteria.Builder criteria2 = DocumentLookupCriteria.Builder.create();
146 criteria2.setDocumentTypeName(documentTypeName);
147 addSearchableAttribute(criteria2, TestXMLSearchableAttributeString.SEARCH_STORAGE_KEY, "fred");
148 DocumentLookupResults results2 = docSearchService.lookupDocuments(user.getPrincipalId(), criteria2.build());
149
150 assertEquals("Search results should be empty.", 0, results2.getLookupResults().size());
151
152 DocumentLookupCriteria.Builder criteria3 = DocumentLookupCriteria.Builder.create();
153 criteria3.setDocumentTypeName(documentTypeName);
154 addSearchableAttribute(criteria3, "fakeproperty", "doesntexist");
155 try {
156 docSearchService.lookupDocuments(user.getPrincipalId(), criteria3.build());
157 fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
158 } catch (WorkflowServiceErrorException e) {}
159
160 criteria = null;
161 criteria = DocumentLookupCriteria.Builder.create();
162 criteria.setDocumentTypeName(documentTypeName);
163 addSearchableAttribute(criteria, TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE.toString());
164 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
165 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
166
167 criteria2 = null;
168 criteria2 = DocumentLookupCriteria.Builder.create();
169 criteria2.setDocumentTypeName(documentTypeName);
170 addSearchableAttribute(criteria2, TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY, "1111111");
171 results2 = docSearchService.lookupDocuments(user.getPrincipalId(), criteria2.build());
172 assertEquals("Search results should be empty.", 0, results2.getLookupResults().size());
173
174 criteria3 = null;
175 criteria3 = DocumentLookupCriteria.Builder.create();
176 criteria3.setDocumentTypeName(documentTypeName);
177 addSearchableAttribute(criteria3, "fakeymcfakefake", "99999999");
178 try {
179 docSearchService.lookupDocuments(user.getPrincipalId(), criteria3.build());
180 fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
181 } catch (WorkflowServiceErrorException e) {}
182
183 criteria = null;
184 criteria = DocumentLookupCriteria.Builder.create();
185 criteria.setDocumentTypeName(documentTypeName);
186 addSearchableAttribute(criteria, TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY,
187 TestXMLSearchableAttributeFloat.SEARCH_STORAGE_VALUE.toString());
188 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
189 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
190
191 criteria2 = null;
192 criteria2 = DocumentLookupCriteria.Builder.create();
193 criteria2.setDocumentTypeName(documentTypeName);
194 addSearchableAttribute(criteria2, TestXMLSearchableAttributeFloat.SEARCH_STORAGE_KEY, "215.3548");
195 results2 = docSearchService.lookupDocuments(user.getPrincipalId(), criteria2.build());
196 assertEquals("Search results should be empty.", 0, results2.getLookupResults().size());
197
198 criteria3 = null;
199 criteria3 = DocumentLookupCriteria.Builder.create();
200 criteria3.setDocumentTypeName(documentTypeName);
201 addSearchableAttribute(criteria3, "fakeylostington", "9999.9999");
202 try {
203 docSearchService.lookupDocuments(user.getPrincipalId(), criteria3.build());
204 fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
205 } catch (WorkflowServiceErrorException e) {}
206
207 criteria = null;
208 criteria = DocumentLookupCriteria.Builder.create();
209 criteria.setDocumentTypeName(documentTypeName);
210 addSearchableAttribute(criteria, TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY,
211 DocumentLookupInternalUtils.getDisplayValueWithDateOnly(new Timestamp(
212 TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_VALUE_IN_MILLS)));
213 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
214 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
215
216 criteria2 = null;
217 criteria2 = DocumentLookupCriteria.Builder.create();
218 criteria2.setDocumentTypeName(documentTypeName);
219 addSearchableAttribute(criteria2, TestXMLSearchableAttributeDateTime.SEARCH_STORAGE_KEY, "07/06/1979");
220 results2 = docSearchService.lookupDocuments(user.getPrincipalId(), criteria2.build());
221 assertEquals("Search results should be empty.", 0, results2.getLookupResults().size());
222
223 criteria3 = null;
224 criteria3 = DocumentLookupCriteria.Builder.create();
225 criteria3.setDocumentTypeName(documentTypeName);
226 addSearchableAttribute(criteria3, "lastingsfakerson", "07/06/2007");
227 try {
228 docSearchService.lookupDocuments(user.getPrincipalId(), criteria3.build());
229 fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
230 } catch (WorkflowServiceErrorException e) {}
231 }
232
233 @Test public void testRouteDocumentWithSearchableAttribute() throws Exception {
234 String documentTypeName = "SearchDocType";
235 String key = "givenname";
236 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
237 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), documentTypeName);
238 WorkflowAttributeDefinition.Builder givennameXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttribute");
239
240 workflowDocument.setApplicationContent("<test></test>");
241
242 givennameXMLDef.addPropertyDefinition(key, "jack");
243 workflowDocument.addSearchableDefinition(givennameXMLDef.build());
244
245 workflowDocument.setTitle("Routing style");
246 workflowDocument.route("routing this document.");
247
248 DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
249
250 Person user = KimApiServiceLocator.getPersonService().getPersonByPrincipalName("rkirkend");
251 DocumentLookupCriteria.Builder criteria = DocumentLookupCriteria.Builder.create();
252 criteria.setDocumentTypeName(documentTypeName);
253 addSearchableAttribute(criteria, key, "jack");
254 DocumentLookupResults results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
255
256 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
257
258 criteria = null;
259 criteria = DocumentLookupCriteria.Builder.create();
260 criteria.setDocumentTypeName(documentTypeName);
261 addSearchableAttribute(criteria, key, "fred");
262 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
263
264 assertEquals("Search results should be empty.", 0, results.getLookupResults().size());
265
266 criteria = null;
267 criteria = DocumentLookupCriteria.Builder.create();
268 criteria.setDocumentTypeName(documentTypeName);
269 addSearchableAttribute(criteria, "fakeproperty", "doesntexist");
270 try {
271 docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
272 fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
273 } catch (WorkflowServiceErrorException wsee) {}
274 }
275
276 @Test public void testDocumentSearchAttributeWildcarding() throws Exception {
277 DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
278
279 String documentTypeName = "SearchDocType";
280 String key = "givenname";
281 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
282 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), documentTypeName);
283 WorkflowAttributeDefinition.Builder givennameXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttribute");
284
285 workflowDocument.setApplicationContent("<test></test>");
286
287 givennameXMLDef.addPropertyDefinition(key, "jack");
288 workflowDocument.addSearchableDefinition(givennameXMLDef.build());
289
290 workflowDocument.setTitle("Routing style");
291 workflowDocument.route("routing this document.");
292
293 Person user = KimApiServiceLocator.getPersonService().getPersonByPrincipalName("rkirkend");
294 DocumentLookupCriteria.Builder criteria = DocumentLookupCriteria.Builder.create();
295 criteria.setDocumentTypeName(documentTypeName);
296 addSearchableAttribute(criteria, key, "jack");
297 DocumentLookupResults results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
298
299 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
300
301 criteria = DocumentLookupCriteria.Builder.create();
302 criteria.setDocumentTypeName(documentTypeName);
303 addSearchableAttribute(criteria, key, "ja*");
304 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
305
306 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
307
308 criteria = DocumentLookupCriteria.Builder.create();
309 criteria.setDocumentTypeName(documentTypeName);
310 addSearchableAttribute(criteria, key, "ja");
311 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
312
313 assertEquals("Search results should have one document.", 0, results.getLookupResults().size());
314
315 criteria = DocumentLookupCriteria.Builder.create();
316 criteria.setDocumentTypeName(documentTypeName);
317 addSearchableAttribute(criteria, key, "*ack");
318 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
319
320 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
321 }
322
323 @Test public void testDocumentSearchAttributeWildcardingDisallow() throws Exception {
324 DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
325
326 String documentTypeName = "SearchDocTypeStandardSearchDataType";
327 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
328 String userNetworkId = "rkirkend";
329 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(userNetworkId), documentTypeName);
330
331
332
333
334
335 WorkflowAttributeDefinition.Builder longXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttributeStdLong");
336 longXMLDef.addPropertyDefinition(TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY, TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE.toString());
337 workflowDocument.addSearchableDefinition(longXMLDef.build());
338 workflowDocument.setTitle("Routing style");
339 workflowDocument.route("routing this document.");
340
341 Person user = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(userNetworkId);
342
343 String validSearchValue = TestXMLSearchableAttributeLong.SEARCH_STORAGE_VALUE.toString();
344 DocumentLookupCriteria.Builder criteria = null;
345 DocumentLookupResults results = null;
346 criteria = DocumentLookupCriteria.Builder.create();
347 criteria.setDocumentTypeName(documentTypeName);
348 addSearchableAttribute(criteria, TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY, validSearchValue);
349 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
350 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
351
352 criteria = DocumentLookupCriteria.Builder.create();
353 criteria.setDocumentTypeName(documentTypeName);
354 addSearchableAttribute(criteria, TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY,
355 "*" + validSearchValue.substring(2));
356
357 if ((new SearchableAttributeLongValue()).allowsWildcards()) {
358 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
359 assertEquals("Search results should be empty using wildcard '*' value.", 0, results.getLookupResults().size());
360 } else {
361 try {
362 docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
363 fail("Search results should be throwing a validation exception for use of the character '*' without allowing wildcards");
364 } catch (WorkflowServiceErrorException wsee) {}
365 }
366
367 criteria = DocumentLookupCriteria.Builder.create();
368 criteria.setDocumentTypeName(documentTypeName);
369 addSearchableAttribute(criteria, TestXMLSearchableAttributeLong.SEARCH_STORAGE_KEY, validSearchValue.substring(
370 0, (validSearchValue.length() - 2)));
371 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
372 assertEquals("Search results should be empty trying to use assumed ending wildcard.", 0, results.getLookupResults().size());
373 }
374
375 @Test public void testDocumentSearchAttributeCaseSensitivity() throws Exception {
376 DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
377 String documentTypeName = "SearchDocTypeCaseSensitivity";
378 String networkId = "rkirkend";
379 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
380
381 String key = "givenname";
382 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(networkId), documentTypeName);
383 WorkflowAttributeDefinition.Builder givennameXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttribute");
384 givennameXMLDef.addPropertyDefinition(key, "jack");
385 workflowDocument.addSearchableDefinition(givennameXMLDef.build());
386 workflowDocument.setTitle("Routing style");
387 workflowDocument.route("routing this document.");
388
389 Person user = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(networkId);
390 DocumentLookupCriteria.Builder criteria = DocumentLookupCriteria.Builder.create();
391 criteria.setDocumentTypeName(documentTypeName);
392 addSearchableAttribute(criteria, key, "jack");
393 DocumentLookupResults results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
394 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
395
396 criteria = DocumentLookupCriteria.Builder.create();
397 criteria.setDocumentTypeName(documentTypeName);
398 addSearchableAttribute(criteria, key, "JACK");
399 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
400 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
401
402 criteria = DocumentLookupCriteria.Builder.create();
403 criteria.setDocumentTypeName(documentTypeName);
404 addSearchableAttribute(criteria, key, "jAck");
405 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
406 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
407
408 criteria = DocumentLookupCriteria.Builder.create();
409 criteria.setDocumentTypeName(documentTypeName);
410 addSearchableAttribute(criteria, key, "jacK");
411 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
412 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
413
414 key = "givenname_nocase";
415 workflowDocument = WorkflowDocumentFactory.createDocument(getPrincipalIdForName(networkId), documentTypeName);
416 WorkflowAttributeDefinition.Builder givenname_nocaseXMLDef = WorkflowAttributeDefinition.Builder.create("XMLSearchableAttribute_CaseInsensitive");
417 givenname_nocaseXMLDef.addPropertyDefinition(key, "jaCk");
418 workflowDocument.addSearchableDefinition(givenname_nocaseXMLDef.build());
419 workflowDocument.setTitle("Routing style");
420 workflowDocument.route("routing this document.");
421
422 criteria = DocumentLookupCriteria.Builder.create();
423 criteria.setDocumentTypeName(documentTypeName);
424 addSearchableAttribute(criteria, key, "jack");
425 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
426 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
427
428 criteria = DocumentLookupCriteria.Builder.create();
429 criteria.setDocumentTypeName(documentTypeName);
430 addSearchableAttribute(criteria, key, "JACK");
431 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
432 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
433
434 criteria = DocumentLookupCriteria.Builder.create();
435 criteria.setDocumentTypeName(documentTypeName);
436 addSearchableAttribute(criteria, key, "jaCk");
437 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
438 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
439
440 criteria = DocumentLookupCriteria.Builder.create();
441 criteria.setDocumentTypeName(documentTypeName);
442 addSearchableAttribute(criteria, key, "jacK");
443 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
444 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
445
446 criteria = DocumentLookupCriteria.Builder.create();
447 criteria.setDocumentTypeName(documentTypeName);
448 addSearchableAttribute(criteria, key, "jAc");
449 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
450 assertEquals("Search results should have one document.", 0, results.getLookupResults().size());
451
452 criteria = DocumentLookupCriteria.Builder.create();
453 criteria.setDocumentTypeName(documentTypeName);
454 addSearchableAttribute(criteria, key, "jA*");
455 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
456 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
457
458 criteria = DocumentLookupCriteria.Builder.create();
459 criteria.setDocumentTypeName(documentTypeName);
460 addSearchableAttribute(criteria, key, "*aCk");
461 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
462 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
463 }
464
465
466
467
468
469 @Test public void testRouteDocumentWithMalformedSearchableAttributeContent() throws WorkflowException {
470 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), "SearchDocType");
471
472 workflowDocument.setApplicationContent("hey, <I'm Not ] Even & XML");
473
474 workflowDocument.setTitle("Routing style");
475 try {
476 workflowDocument.route("routing this document.");
477 fail("routeDocument succeeded with malformed XML");
478 } catch (Exception we) {
479
480
481 }
482 TestUtilities.waitForExceptionRouting();
483 }
484
485
486
487
488
489
490 @Test public void testRouteDocumentWithInvalidSearchableAttributeContent() throws Exception {
491 String documentTypeName = "SearchDocType";
492 String key = "givenname";
493 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
494 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), documentTypeName);
495
496 workflowDocument.setApplicationContent("<documentContent><searchableContent><garbage>" +
497 "<blah>not going to match anything</blah>" +
498 "</garbage></searchableContent></documentContent>");
499
500 workflowDocument.setTitle("Routing style");
501 workflowDocument.route("routing this document.");
502
503 DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
504
505 Person user = KimApiServiceLocator.getPersonService().getPersonByPrincipalName("rkirkend");
506 DocumentLookupCriteria.Builder criteria = DocumentLookupCriteria.Builder.create();
507 criteria.setDocumentTypeName(documentTypeName);
508 addSearchableAttribute(criteria, key, "jack");
509 DocumentLookupResults results = docSearchService.lookupDocuments(user.getPrincipalId(),
510 criteria.build());
511
512 assertEquals("Search results should be empty.", 0, results.getLookupResults().size());
513
514 criteria = DocumentLookupCriteria.Builder.create();
515 criteria.setDocumentTypeName(documentTypeName);
516 addSearchableAttribute(criteria, key, "fred");
517 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
518
519 assertEquals("Search results should be empty.", 0, results.getLookupResults().size());
520
521 criteria = DocumentLookupCriteria.Builder.create();
522 criteria.setDocumentTypeName(documentTypeName);
523 addSearchableAttribute(criteria, "fakeproperty", "doesntexist");
524 try {
525 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
526 fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
527 } catch (WorkflowServiceErrorException wsee) {}
528 }
529
530
531
532
533
534
535 @Test public void testRouteDocumentWithMoreInvalidSearchableAttributeContent() throws Exception {
536 String documentTypeName = "SearchDocType";
537 String key = "givenname";
538 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
539 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), documentTypeName);
540
541 workflowDocument.setApplicationContent("<documentContent><NOTsearchableContent><garbage>" +
542 "<blah>not going to match anything</blah>" +
543 "</garbage></NOTsearchableContent></documentContent>");
544
545 workflowDocument.setTitle("Routing style");
546 workflowDocument.route("routing this document.");
547
548 DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
549
550 Person user = KimApiServiceLocator.getPersonService().getPersonByPrincipalName("rkirkend");
551 DocumentLookupCriteria.Builder criteria = DocumentLookupCriteria.Builder.create();
552 criteria.setDocumentTypeName(documentTypeName);
553 addSearchableAttribute(criteria, key, "jack");
554 DocumentLookupResults results = docSearchService.lookupDocuments(user.getPrincipalId(),
555 criteria.build());
556
557 assertEquals("Search results should be empty.", 0, results.getLookupResults().size());
558
559 criteria = DocumentLookupCriteria.Builder.create();
560 criteria.setDocumentTypeName(documentTypeName);
561 addSearchableAttribute(criteria, key, "fred");
562 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
563
564 assertEquals("Search results should be empty.", 0, results.getLookupResults().size());
565
566 criteria = DocumentLookupCriteria.Builder.create();
567 criteria.setDocumentTypeName(documentTypeName);
568 addSearchableAttribute(criteria, "fakeproperty", "doesntexist");
569 try {
570 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
571 fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
572 } catch (WorkflowServiceErrorException wsee) {}
573 }
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752 private String insertCommasIfNeeded(String value, int interval) {
753 int indexOfDecimal = value.indexOf(".");
754 String decimalPointOn = value.substring(indexOfDecimal);
755 String temp = value.substring(0, indexOfDecimal);
756 StringBuffer builtValue = new StringBuffer();
757 if (temp.length() <= interval) {
758 builtValue.append(temp);
759 } else {
760 int counter = 0;
761 for (int i = temp.length() - 1; (i >= 0); i--) {
762 if (counter == interval) {
763 builtValue.insert(0, ",");
764 counter = 0;
765 }
766 counter++;
767 builtValue.insert(0, temp.substring(i, i+1));
768 }
769 }
770 return (builtValue.append(decimalPointOn)).toString();
771 }
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913 @Test public void testRouteDocumentWithXStreamSearchableAttribute() throws Exception {
914 String documentTypeName = "SearchDocType";
915 String key = "givenname";
916 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
917
918 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), "SearchDocTypeXStream");
919 WorkflowAttributeDefinition.Builder givennameXMLDef = WorkflowAttributeDefinition.Builder.create("XMLXStreamSearchableAttribute");
920
921 workflowDocument.setApplicationContent("<test></test>");
922
923 givennameXMLDef.addPropertyDefinition("givenname", "jack");
924 workflowDocument.addSearchableDefinition(givennameXMLDef.build());
925
926 workflowDocument.setTitle("Routing style");
927 workflowDocument.route("routing this document.");
928
929 DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
930
931 Person user = KimApiServiceLocator.getPersonService().getPersonByPrincipalName("rkirkend");
932 DocumentLookupCriteria.Builder criteria = DocumentLookupCriteria.Builder.create();
933 criteria.setDocumentTypeName(documentTypeName);
934 addSearchableAttribute(criteria, key, "jack");
935 DocumentLookupResults results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
936
937 assertEquals("Search results should be empty.", 0, results.getLookupResults().size());
938
939 criteria = DocumentLookupCriteria.Builder.create();
940 criteria.setDocumentTypeName(documentTypeName);
941 addSearchableAttribute(criteria, key, "fred");
942 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
943
944 assertEquals("Search results should be empty.", 0, results.getLookupResults().size());
945
946 criteria = DocumentLookupCriteria.Builder.create();
947 criteria.setDocumentTypeName(documentTypeName);
948 addSearchableAttribute(criteria, "fakeproperty", "doesntexist");
949 try {
950 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
951 fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
952 } catch (WorkflowServiceErrorException wsee) {}
953 }
954
955
956
957
958
959
960 @Test public void testSearchableAttributeWithQuickfinder() throws Exception {
961 String documentTypeName = "AttributeWithQuickfinderDocType";
962 String key = "chart";
963 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
964 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), documentTypeName);
965
966
967 WorkflowAttributeDefinition.Builder chartDef = WorkflowAttributeDefinition.Builder.create("SearchableAttributeWithQuickfinder");
968 chartDef.addPropertyDefinition(key, "BL");
969 document.addSearchableDefinition(chartDef.build());
970
971
972 document.setTitle("Routin' with style");
973 document.saveDocument("Savin' this document.");
974
975
976 DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
977 Person user = KimApiServiceLocator.getPersonService().getPersonByPrincipalName("rkirkend");
978
979
980 DocumentLookupCriteria.Builder criteria = DocumentLookupCriteria.Builder.create();
981 criteria.setDocumentTypeName(documentTypeName);
982 addSearchableAttribute(criteria, key, "BL");
983 DocumentLookupResults results = docSearchService.lookupDocuments(user.getPrincipalId(),
984 criteria.build());
985 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
986 DocumentLookupResult result = results.getLookupResults().get(0);
987 String documentId = result.getDocument().getDocumentId();
988 assertEquals("Wrong document in search results.", document.getDocumentId(), documentId);
989
990
991 criteria = DocumentLookupCriteria.Builder.create();
992 criteria.setDocumentTypeName(documentTypeName);
993 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
994 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
995 result = results.getLookupResults().get(0);
996 assertEquals("Wrong document in search results.", document.getDocumentId(), result.getDocument().getDocumentId());
997
998 }
999
1000
1001
1002
1003
1004
1005
1006
1007 @Test public void testSearchableAttributeWithHiddens() throws Exception {
1008
1009
1010 String docType = "AttributeWithHiddensDocType";
1011 DocumentType documentType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(docType);
1012
1013 String attributeName = "SearchableAttributeWithHiddens";
1014 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), docType);
1015
1016
1017 WorkflowAttributeDefinition.Builder chartDef = WorkflowAttributeDefinition.Builder.create(attributeName);
1018 chartDef.addPropertyDefinition("chart", "BL");
1019 chartDef.addPropertyDefinition("org", "ARSC");
1020 chartDef.addPropertyDefinition("dollar", "24");
1021 document.addSearchableDefinition(chartDef.build());
1022
1023
1024 document.setTitle("Routin' with style");
1025 document.saveDocument("Savin' this document.");
1026
1027
1028 DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
1029 Person user = KimApiServiceLocator.getPersonService().getPersonByPrincipalName("rkirkend");
1030
1031
1032 DocumentLookupCriteria.Builder criteria = DocumentLookupCriteria.Builder.create();
1033 criteria.setDocumentTypeName(docType);
1034 addSearchableAttribute(criteria, "chart", "BL");
1035 DocumentLookupResults results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
1036 assertEquals("Search results should have one document.", 1, results.getLookupResults().size());
1037 DocumentLookupResult result = results.getLookupResults().get(0);
1038 assertEquals("Wrong document in search results.", document.getDocumentId(), result.getDocument().getDocumentId());
1039
1040 DocumentAttribute documentAttribute = result.getSingleDocumentAttributeByName("chart");
1041 assertNull("The chart column should not be in the result set!", documentAttribute);
1042 documentAttribute = result.getSingleDocumentAttributeByName("org");
1043 assertNotNull("The org column should be in the result set", documentAttribute);
1044 assertEquals("Wrong org code.", "ARSC", documentAttribute.getValue());
1045 documentAttribute = result.getSingleDocumentAttributeByName("dollar");
1046 assertNotNull("The dollar column should be in the result set", documentAttribute);
1047 assertEquals("Wrong dollar code.", "24", documentAttribute.getValue().toString());
1048 }
1049
1050 @Test public void testSetApplicationContentXMLRoutedDocument() throws Exception {
1051 String documentTypeName = "SearchDocType";
1052 String key = "givenname";
1053 DocumentType docType = ((DocumentTypeService)KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE)).findByName(documentTypeName);
1054 WorkflowDocument workflowDocument = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), documentTypeName);
1055 workflowDocument.setApplicationContent("<documentContent><searchableContent><putWhateverWordsIwantInsideThisTag>" +
1056 "<givenname><value>jack</value></givenname>" +
1057 "</putWhateverWordsIwantInsideThisTag></searchableContent></documentContent>");
1058
1059 workflowDocument.setTitle("Routing style");
1060 workflowDocument.route("routing this document.");
1061
1062 DocumentSearchService docSearchService = (DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE);
1063
1064 Person user = KimApiServiceLocator.getPersonService().getPersonByPrincipalName("rkirkend");
1065 DocumentLookupCriteria.Builder criteria = DocumentLookupCriteria.Builder.create();
1066 criteria.setDocumentTypeName(documentTypeName);
1067 addSearchableAttribute(criteria, key, "jack");
1068 DocumentLookupResults results = docSearchService.lookupDocuments(user.getPrincipalId(),
1069 criteria.build());
1070
1071 assertEquals("Search results should be empty.", 1, results.getLookupResults().size());
1072
1073 criteria = DocumentLookupCriteria.Builder.create();
1074 criteria.setDocumentTypeName(documentTypeName);
1075 addSearchableAttribute(criteria, key, "fred");
1076 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
1077
1078 assertEquals("Search results should be empty.", 0, results.getLookupResults().size());
1079
1080 criteria = DocumentLookupCriteria.Builder.create();
1081 criteria.setDocumentTypeName(documentTypeName);
1082 addSearchableAttribute(criteria, "fakeproperty", "doesntexist");
1083 try {
1084 results = docSearchService.lookupDocuments(user.getPrincipalId(), criteria.build());
1085 fail("Search results should be throwing a validation exception for use of non-existant searchable attribute");
1086 } catch (WorkflowServiceErrorException wsee) {}
1087 }
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119 }