1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.workflow;
17
18 import java.text.DateFormat;
19 import java.text.SimpleDateFormat;
20 import java.util.*;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.ole.coa.businessobject.Account;
24 import org.kuali.ole.coa.businessobject.Organization;
25 import org.kuali.ole.module.purap.businessobject.PurApItem;
26 import org.kuali.ole.module.purap.businessobject.ReceivingItem;
27 import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
28 import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
29 import org.kuali.ole.module.purap.document.ReceivingDocument;
30 import org.kuali.ole.module.purap.document.RequisitionDocument;
31 import org.kuali.ole.select.OleSelectConstant;
32 import org.kuali.ole.select.businessobject.*;
33 import org.kuali.ole.select.document.OleCorrectionReceivingDocument;
34 import org.kuali.ole.select.document.OleInvoiceDocument;
35 import org.kuali.ole.select.document.OleLineItemReceivingDocument;
36 import org.kuali.ole.select.document.OlePaymentRequestDocument;
37 import org.kuali.ole.sys.OLEPropertyConstants;
38 import org.kuali.ole.sys.businessobject.AccountingLine;
39 import org.kuali.ole.sys.businessobject.FinancialSystemDocumentHeader;
40 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
41 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
42 import org.kuali.ole.sys.context.SpringContext;
43 import org.kuali.ole.sys.document.AccountingDocument;
44 import org.kuali.ole.sys.document.AmountTotaling;
45 import org.kuali.ole.sys.document.GeneralLedgerPostingDocument;
46 import org.kuali.ole.sys.document.datadictionary.AccountingLineGroupDefinition;
47 import org.kuali.ole.sys.document.datadictionary.FinancialSystemTransactionalDocumentEntry;
48 import org.kuali.rice.core.api.uif.RemotableAttributeError;
49 import org.kuali.rice.core.api.util.ConcreteKeyValue;
50 import org.kuali.rice.core.api.util.KeyValue;
51 import org.kuali.rice.kew.api.KewApiConstants.SearchableAttributeConstants;
52 import org.kuali.rice.kew.api.document.DocumentWithContent;
53 import org.kuali.rice.kew.api.document.attribute.DocumentAttribute;
54 import org.kuali.rice.kew.api.document.attribute.DocumentAttributeDecimal;
55 import org.kuali.rice.kew.api.document.attribute.DocumentAttributeString;
56 import org.kuali.rice.kew.api.document.search.DocumentSearchCriteria;
57 import org.kuali.rice.kew.api.exception.WorkflowException;
58 import org.kuali.rice.kew.api.extension.ExtensionDefinition;
59 import org.kuali.rice.kns.lookup.LookupUtils;
60 import org.kuali.rice.kns.service.DataDictionaryService;
61 import org.kuali.rice.kns.service.DictionaryValidationService;
62 import org.kuali.rice.kns.util.FieldUtils;
63 import org.kuali.rice.kns.web.ui.Field;
64 import org.kuali.rice.kns.web.ui.Row;
65 import org.kuali.rice.krad.bo.BusinessObject;
66 import org.kuali.rice.krad.datadictionary.DocumentEntry;
67 import org.kuali.rice.krad.document.Document;
68 import org.kuali.rice.krad.service.DocumentService;
69 import org.kuali.rice.krad.service.KRADServiceLocator;
70 import org.kuali.rice.krad.util.ObjectUtils;
71 import org.kuali.rice.krad.workflow.attribute.DataDictionarySearchableAttribute;
72
73
74 public class OLESearchableAttribute extends DataDictionarySearchableAttribute {
75 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OLESearchableAttribute.class);
76
77 protected static final String DISPLAY_TYPE_SEARCH_ATTRIBUTE_LABEL = "Search Result Type";
78 protected static final String WORKFLOW_DISPLAY_TYPE_LABEL = "Workflow Data";
79 protected static final String DOCUMENT_DISPLAY_TYPE_LABEL = "Document Specific Data";
80 protected static final String WORKFLOW_DISPLAY_TYPE_VALUE = "workflow";
81 protected static final String DOCUMENT_DISPLAY_TYPE_VALUE = "document";
82 protected static final String DISPLAY_TYPE_SEARCH_ATTRIBUTE_NAME = "displayType";
83
84 protected static final List<KeyValue> SEARCH_RESULT_TYPE_OPTION_LIST = new ArrayList<KeyValue>(2);
85 static {
86 SEARCH_RESULT_TYPE_OPTION_LIST.add(new ConcreteKeyValue(DOCUMENT_DISPLAY_TYPE_VALUE, DOCUMENT_DISPLAY_TYPE_LABEL));
87 SEARCH_RESULT_TYPE_OPTION_LIST.add(new ConcreteKeyValue(WORKFLOW_DISPLAY_TYPE_VALUE, WORKFLOW_DISPLAY_TYPE_LABEL));
88 }
89
90
91 private static final Map<String, String> magicFields = new HashMap<String, String>();
92
93 static {
94 magicFields.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, SourceAccountingLine.class.getSimpleName());
95 magicFields.put(OLEPropertyConstants.ORGANIZATION_CODE, Organization.class.getSimpleName());
96 magicFields.put(OLEPropertyConstants.ACCOUNT_NUMBER, SourceAccountingLine.class.getSimpleName());
97 magicFields.put(OLEPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE, GeneralLedgerPendingEntry.class.getSimpleName());
98 magicFields.put(OLEPropertyConstants.FINANCIAL_DOCUMENT_TOTAL_AMOUNT, FinancialSystemDocumentHeader.class.getSimpleName() );
99 }
100
101 @Override
102 protected List<Row> getSearchingRows(String documentTypeName) {
103 if ( LOG.isDebugEnabled() ) {
104 LOG.debug( "getSearchingRows( " + documentTypeName + " )" );
105 if ( LOG.isTraceEnabled() ) {
106 LOG.trace("Stack Trace at point of call", new Throwable());
107 }
108 }
109
110 DataDictionaryService ddService = SpringContext.getBean(DataDictionaryService.class);
111
112 List<Row> docSearchRows = super.getSearchingRows(documentTypeName);
113
114 DocumentEntry entry = ddService.getDataDictionary().getDocumentEntry(documentTypeName);
115
116 if (entry == null) {
117 return docSearchRows;
118 }
119 Class<? extends Document> docClass = entry.getDocumentClass();
120
121 if (AccountingDocument.class.isAssignableFrom(docClass)) {
122 Map<String, AccountingLineGroupDefinition> alGroups = ((FinancialSystemTransactionalDocumentEntry) entry).getAccountingLineGroups();
123 Class alClass = SourceAccountingLine.class;
124
125 if (ObjectUtils.isNotNull(alGroups)) {
126 if (alGroups.containsKey("source")) {
127 alClass = alGroups.get("source").getAccountingLineClass();
128 }
129 }
130
131 BusinessObject alBusinessObject = null;
132
133 try {
134 alBusinessObject = (BusinessObject) alClass.newInstance();
135 } catch (Exception cnfe) {
136 throw new RuntimeException( "Unable to instantiate accounting line class: " + alClass, cnfe);
137 }
138
139 Field chartField = FieldUtils.getPropertyField(alClass, OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, true);
140 chartField.setFieldDataType(SearchableAttributeConstants.DATA_TYPE_STRING);
141 chartField.setColumnVisible(true);
142 LookupUtils.setFieldQuickfinder(alBusinessObject, OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartField, Collections.singletonList(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE));
143 docSearchRows.add(new Row(Collections.singletonList(chartField)));
144
145 Field orgField = FieldUtils.getPropertyField(Organization.class, OLEPropertyConstants.ORGANIZATION_CODE, true);
146 orgField.setFieldDataType(SearchableAttributeConstants.DATA_TYPE_STRING);
147 orgField.setColumnVisible(true);
148 LookupUtils.setFieldQuickfinder(new Account(), OLEPropertyConstants.ORGANIZATION_CODE, orgField, Collections.singletonList(OLEPropertyConstants.ORGANIZATION_CODE));
149 docSearchRows.add(new Row(Collections.singletonList(orgField)));
150
151 Field accountField = FieldUtils.getPropertyField(alClass, OLEPropertyConstants.ACCOUNT_NUMBER, true);
152 accountField.setFieldDataType(SearchableAttributeConstants.DATA_TYPE_STRING);
153 accountField.setColumnVisible(true);
154 LookupUtils.setFieldQuickfinder(alBusinessObject, OLEPropertyConstants.ACCOUNT_NUMBER, accountField, Collections.singletonList(OLEPropertyConstants.ACCOUNT_NUMBER));
155 docSearchRows.add(new Row(Collections.singletonList(accountField)));
156 }
157
158 boolean displayedLedgerPostingDoc = false;
159
160 if (GeneralLedgerPostingDocument.class.isAssignableFrom(docClass) && !displayedLedgerPostingDoc) {
161 Field searchField = FieldUtils.getPropertyField(GeneralLedgerPendingEntry.class, OLEPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE, true);
162 searchField.setFieldDataType(SearchableAttributeConstants.DATA_TYPE_STRING);
163 LookupUtils.setFieldQuickfinder(new GeneralLedgerPendingEntry(), OLEPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE, searchField, Collections.singletonList(OLEPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE));
164 docSearchRows.add(new Row(Collections.singletonList(searchField)));
165 }
166
167 if (AmountTotaling.class.isAssignableFrom(docClass)) {
168 Field searchField = FieldUtils.getPropertyField(FinancialSystemDocumentHeader.class, OLEPropertyConstants.FINANCIAL_DOCUMENT_TOTAL_AMOUNT, true);
169 searchField.setFieldDataType(SearchableAttributeConstants.DATA_TYPE_FLOAT);
170 docSearchRows.add(new Row(Collections.singletonList(searchField)));
171 }
172
173 if(RequisitionDocument.class.isAssignableFrom(docClass)) {
174 magicFields.put("itemTitleId","OleRequisitionItem");
175 Class boClass = OleRequisitionItem.class;
176
177 Field searchField = FieldUtils.getPropertyField(boClass, "itemTitleId", true);
178 searchField.setFieldDataType(SearchableAttributeConstants.DATA_TYPE_STRING);
179
180
181
182
183 docSearchRows.add(new Row(Collections.singletonList(searchField)));
184
185 }
186
187 if(PurchaseOrderDocument.class.isAssignableFrom(docClass)) {
188 magicFields.put("itemTitleId","OlePurchaseOrderItem");
189 Class boClass = OlePurchaseOrderItem.class;
190
191 Field searchField = FieldUtils.getPropertyField(boClass, "itemTitleId", true);
192 searchField.setFieldDataType(SearchableAttributeConstants.DATA_TYPE_STRING);
193
194 List<Field> fieldList = new ArrayList<Field>();
195 fieldList.add(searchField);
196 docSearchRows.add(new Row(fieldList));
197
198 }
199 if(OlePaymentRequestDocument.class.isAssignableFrom(docClass)) {
200 magicFields.put("itemTitleId","OlePaymentRequestItem");
201 Class boClass = OlePaymentRequestItem.class;
202
203 Field searchField = FieldUtils.getPropertyField(boClass, "itemTitleId", true);
204 searchField.setFieldDataType(SearchableAttributeConstants.DATA_TYPE_STRING);
205
206
207 docSearchRows.add(new Row(Collections.singletonList(searchField)));
208
209 }
210 if (OleLineItemReceivingDocument.class.isAssignableFrom(docClass)) {
211 magicFields.put("itemTitleId", "OleLineItemReceivingItem");
212 Class boClass = OleLineItemReceivingItem.class;
213
214 Field searchField = FieldUtils.getPropertyField(boClass, "itemTitleId", true);
215 searchField.setFieldDataType(SearchableAttributeConstants.DATA_TYPE_STRING);
216
217
218 docSearchRows.add(new Row(Collections.singletonList(searchField)));
219 }
220 if (OleCorrectionReceivingDocument.class.isAssignableFrom(docClass)) {
221
222 magicFields.put("itemTitleId", "OleCorrectionReceivingItem");
223 Class boClass = OleCorrectionReceivingItem.class;
224
225 Field searchField = FieldUtils.getPropertyField(boClass, "itemTitleId", true);
226 searchField.setFieldDataType(SearchableAttributeConstants.DATA_TYPE_STRING);
227
228
229 docSearchRows.add(new Row(Collections.singletonList(searchField)));
230 }
231 if (OleInvoiceDocument.class.isAssignableFrom(docClass)) {
232 Class boClass = OleInvoiceDocument.class;
233
234 Field searchField = FieldUtils.getPropertyField(boClass, OleSelectConstant.InvoiceSearch.PURAP_ID, true);
235 searchField.setFieldDataType(SearchableAttributeConstants.DATA_TYPE_STRING);
236 searchField.setColumnVisible(true);
237 docSearchRows.add(new Row(Collections.singletonList(searchField)));
238
239 searchField = FieldUtils.getPropertyField(boClass,OleSelectConstant.InvoiceSearch.INV_DATE, true);
240 searchField.setFieldDataType(SearchableAttributeConstants.DATA_TYPE_STRING);
241 searchField.setColumnVisible(true);
242 docSearchRows.add(new Row(Collections.singletonList(searchField)));
243
244 searchField = FieldUtils.getPropertyField(boClass,OleSelectConstant.InvoiceSearch.INV_PAY_DATE, true);
245 searchField.setFieldDataType(SearchableAttributeConstants.DATA_TYPE_STRING);
246 searchField.setColumnVisible(true);
247 docSearchRows.add(new Row(Collections.singletonList(searchField)));
248
249 searchField = FieldUtils.getPropertyField(boClass, OleSelectConstant.InvoiceSearch.INV_SUB_TYP_ID, true);
250 searchField.setFieldDataType(SearchableAttributeConstants.DATA_TYPE_STRING);
251 searchField.setColumnVisible(true);
252 searchField.setFieldType("text");
253 searchField.setSize(10);
254 docSearchRows.add(new Row(Collections.singletonList(searchField)));
255
256 searchField = FieldUtils.getPropertyField(boClass, OleSelectConstant.InvoiceSearch.INV_TYP_ID, true);
257 searchField.setFieldDataType(SearchableAttributeConstants.DATA_TYPE_STRING);
258 searchField.setFieldType("text");
259 searchField.setSize(30);
260 searchField.setColumnVisible(true);
261 docSearchRows.add(new Row(Collections.singletonList(searchField)));
262
263
264 magicFields.put("itemTitleId", "oleInvoiceItem");
265
266 searchField = FieldUtils.getPropertyField(boClass, "itemTitleId", true);
267 searchField.setFieldDataType(SearchableAttributeConstants.DATA_TYPE_STRING);
268 searchField.setFieldType("text");
269 searchField.setSize(30);
270 docSearchRows.add(new Row(Collections.singletonList(searchField)));
271 }
272
273 Row resultType = createSearchResultDisplayTypeRow();
274 docSearchRows.add(resultType);
275 if ( LOG.isDebugEnabled() ) {
276 LOG.debug( "Returning Rows: " + docSearchRows );
277 }
278 return docSearchRows;
279 }
280
281
282
283
284
285 @Override
286 public List<DocumentAttribute> extractDocumentAttributes(ExtensionDefinition extensionDefinition, DocumentWithContent documentWithContent) {
287 if (LOG.isDebugEnabled()) {
288 LOG.debug("extractDocumentAttributes( " + extensionDefinition + ", " + documentWithContent + " )");
289 }
290 List<DocumentAttribute> searchAttrValues = super.extractDocumentAttributes(extensionDefinition, documentWithContent);
291
292 String docId = documentWithContent.getDocument().getDocumentId();
293 DocumentService docService = SpringContext.getBean(DocumentService.class);
294 Document doc = null;
295 try {
296 doc = docService.getByDocumentHeaderIdSessionless(docId);
297 }
298 catch (WorkflowException we) {
299
300 }
301 if (doc != null) {
302 if (doc instanceof AmountTotaling) {
303 DocumentAttributeDecimal.Builder searchableAttributeValue = DocumentAttributeDecimal.Builder.create(OLEPropertyConstants.FINANCIAL_DOCUMENT_TOTAL_AMOUNT);
304 searchableAttributeValue.setValue(((AmountTotaling) doc).getTotalDollarAmount().bigDecimalValue());
305 searchAttrValues.add(searchableAttributeValue.build());
306 }
307
308 if (doc instanceof AccountingDocument) {
309 AccountingDocument accountingDoc = (AccountingDocument) doc;
310 searchAttrValues.addAll(harvestAccountingDocumentSearchableAttributes(accountingDoc));
311 }
312
313 boolean indexedLedgerDoc = false;
314
315 if (doc instanceof GeneralLedgerPostingDocument && !indexedLedgerDoc) {
316 GeneralLedgerPostingDocument GLPostingDoc = (GeneralLedgerPostingDocument) doc;
317 searchAttrValues.addAll(harvestGLPDocumentSearchableAttributes(GLPostingDoc));
318 }
319
320 if (doc instanceof PurchasingAccountsPayableDocument) {
321 PurchasingAccountsPayableDocument purchasingAccountsPayableDocument = (PurchasingAccountsPayableDocument)doc;
322 searchAttrValues.addAll(harvestPurchasingAccountsPayableDocument(purchasingAccountsPayableDocument));
323 }
324
325 if (doc instanceof OleLineItemReceivingDocument |
326 doc instanceof OleCorrectionReceivingDocument) {
327 ReceivingDocument receivingDocument = (ReceivingDocument)doc;
328 searchAttrValues.addAll(harvestReceivingDocument(receivingDocument));
329 }
330 if(doc instanceof OleInvoiceDocument){
331 OleInvoiceDocument oleInvoiceDocument=(OleInvoiceDocument)doc;
332 searchAttrValues.addAll(harvestInvoiceSearchableAttributes(oleInvoiceDocument));
333 }
334 }
335 return searchAttrValues;
336 }
337
338
339
340
341
342 @Override
343 public List<RemotableAttributeError> validateDocumentAttributeCriteria(ExtensionDefinition extensionDefinition, DocumentSearchCriteria documentSearchCriteria) {
344 if (LOG.isDebugEnabled()) {
345 LOG.debug("validateDocumentAttributeCriteria( " + extensionDefinition + ", " + documentSearchCriteria + " )");
346 }
347
348 List<RemotableAttributeError> errors = super.validateDocumentAttributeCriteria(extensionDefinition, documentSearchCriteria);
349
350 DictionaryValidationService validationService = SpringContext.getBean(DictionaryValidationService.class);
351 Map<String,List<String>> paramMap = documentSearchCriteria.getDocumentAttributeValues();
352 for (String key : paramMap.keySet()) {
353 List<String> values = paramMap.get(key);
354 if ( values != null && !values.isEmpty() ) {
355 for ( String value : values ) {
356 if (!StringUtils.isEmpty(value)) {
357 if (magicFields.containsKey(key)) {
358 validationService.validateAttributeFormat(magicFields.get(key), key, value, key);
359 }
360 }
361 }
362 }
363 }
364
365 retrieveValidationErrorsFromGlobalVariables(errors);
366
367 return errors;
368 };
369
370
371
372
373
374
375 protected List<DocumentAttribute> harvestAccountingDocumentSearchableAttributes(AccountingDocument accountingDoc) {
376 List<DocumentAttribute> searchAttrValues = new ArrayList<DocumentAttribute>();
377
378 for ( AccountingLine line : (List<AccountingLine>)accountingDoc.getSourceAccountingLines() ) {
379 addSearchableAttributesForAccountingLine(searchAttrValues, line);
380 }
381 for ( AccountingLine line : (List<AccountingLine>)accountingDoc.getTargetAccountingLines() ) {
382 addSearchableAttributesForAccountingLine(searchAttrValues, line);
383 }
384
385 return searchAttrValues;
386 }
387
388
389
390
391
392
393 protected List<DocumentAttribute> harvestGLPDocumentSearchableAttributes(GeneralLedgerPostingDocument doc) {
394 List<DocumentAttribute> searchAttrValues = new ArrayList<DocumentAttribute>();
395
396 for ( GeneralLedgerPendingEntry glpe : doc.getGeneralLedgerPendingEntries() ) {
397 addSearchableAttributesForGLPE(searchAttrValues, glpe);
398 }
399 return searchAttrValues;
400 }
401
402
403
404
405
406
407 protected List<DocumentAttribute> harvestPurchasingAccountsPayableDocument(PurchasingAccountsPayableDocument purapDoc) {
408 List<DocumentAttribute> searchAttrValues = new ArrayList<DocumentAttribute>();
409 for (Object element : purapDoc.getItems()) {
410 PurApItem purapItem = (PurApItem)element;
411 addSearchableAttributesForPurApItemTitleId(searchAttrValues, purapItem);
412 }
413 return searchAttrValues;
414 }
415
416
417
418
419
420
421 protected List<DocumentAttribute> harvestReceivingDocument(ReceivingDocument receivingDoc) {
422 List<DocumentAttribute> searchAttrValues = new ArrayList<DocumentAttribute>();
423 for (Iterator itr = receivingDoc.getItems().iterator(); itr.hasNext();) {
424 ReceivingItem receivingItem = (ReceivingItem)itr.next();
425 addSearchableAttributesForReceivingItemTitleIds(searchAttrValues, receivingItem);
426 }
427 return searchAttrValues;
428 }
429
430
431
432
433
434
435
436 protected void addSearchableAttributesForAccountingLine(List<DocumentAttribute> searchAttrValues, AccountingLine accountingLine) {
437 DocumentAttributeString.Builder searchableAttributeValue = DocumentAttributeString.Builder.create(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE);
438 searchableAttributeValue.setValue(accountingLine.getChartOfAccountsCode());
439 searchAttrValues.add(searchableAttributeValue.build());
440
441 searchableAttributeValue = DocumentAttributeString.Builder.create(OLEPropertyConstants.ACCOUNT_NUMBER);
442 searchableAttributeValue.setValue(accountingLine.getAccountNumber());
443 searchAttrValues.add(searchableAttributeValue.build());
444
445 searchableAttributeValue = DocumentAttributeString.Builder.create(OLEPropertyConstants.ORGANIZATION_CODE);
446 searchableAttributeValue.setValue(accountingLine.getAccount().getOrganizationCode());
447 searchAttrValues.add(searchableAttributeValue.build());
448 }
449
450
451
452
453
454
455
456 protected void addSearchableAttributesForGLPE(List<DocumentAttribute> searchAttrValues, GeneralLedgerPendingEntry glpe) {
457 DocumentAttributeString.Builder searchableAttributeValue = DocumentAttributeString.Builder.create(OLEPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE);
458 searchableAttributeValue.setValue(glpe.getFinancialDocumentTypeCode());
459 searchAttrValues.add(searchableAttributeValue.build());
460
461 }
462
463
464
465
466
467
468
469 protected void addSearchableAttributesForPurApItemTitleId(List<DocumentAttribute> searchAttrValues, PurApItem purapItem) {
470 if (purapItem instanceof OleRequisitionItem ) {
471 DocumentAttributeString.Builder searchableAttributeValue = DocumentAttributeString.Builder.create(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID);
472 searchableAttributeValue.setValue(((OleRequisitionItem)purapItem).getItemTitleId());
473 searchAttrValues.add(searchableAttributeValue.build());
474 }
475 else if (purapItem instanceof OlePaymentRequestItem) {
476 DocumentAttributeString.Builder searchableAttributeValue = DocumentAttributeString.Builder.create(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID);
477 searchableAttributeValue.setValue(((OlePaymentRequestItem)purapItem).getItemTitleId());
478 searchAttrValues.add(searchableAttributeValue.build());
479 }
480 else if (purapItem instanceof OlePurchaseOrderItem){
481 DocumentAttributeString.Builder searchableAttributeValue = DocumentAttributeString.Builder.create(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID);
482 searchableAttributeValue.setValue(((OlePurchaseOrderItem)purapItem).getItemTitleId());
483 searchAttrValues.add(searchableAttributeValue.build());
484 }
485 }
486
487
488
489
490
491
492
493 protected void addSearchableAttributesForReceivingItemTitleIds(List<DocumentAttribute> searchAttrValues, ReceivingItem receivingItem) {
494 if(receivingItem instanceof OleCorrectionReceivingItem) {
495 DocumentAttributeString.Builder searchableAttributeValue = DocumentAttributeString.Builder.create(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID);
496 searchableAttributeValue.setValue(((OleCorrectionReceivingItem)receivingItem).getItemTitleId());
497 searchAttrValues.add(searchableAttributeValue.build());
498 }
499 else if(receivingItem instanceof OleLineItemReceivingItem) {
500 DocumentAttributeString.Builder searchableAttributeValue = DocumentAttributeString.Builder.create(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID);
501 searchableAttributeValue.setValue(((OleLineItemReceivingItem)receivingItem).getItemTitleId());
502 searchAttrValues.add(searchableAttributeValue.build());
503 }
504 }
505
506 protected Row createSearchResultDisplayTypeRow() {
507 Field searchField = new Field(DISPLAY_TYPE_SEARCH_ATTRIBUTE_NAME, DISPLAY_TYPE_SEARCH_ATTRIBUTE_LABEL);
508 searchField.setFieldType(Field.RADIO);
509 searchField.setIndexedForSearch(false);
510 searchField.setBusinessObjectClassName("");
511 searchField.setFieldHelpName("");
512 searchField.setFieldHelpSummary("");
513 searchField.setColumnVisible(false);
514 searchField.setFieldValidValues(SEARCH_RESULT_TYPE_OPTION_LIST);
515 searchField.setPropertyValue(DOCUMENT_DISPLAY_TYPE_VALUE);
516 searchField.setDefaultValue(DOCUMENT_DISPLAY_TYPE_VALUE);
517
518 return new Row(Collections.singletonList(searchField));
519 }
520
521 protected List<DocumentAttribute> harvestInvoiceSearchableAttributes(OleInvoiceDocument oleInvoiceDocument) {
522 List<DocumentAttribute> searchAttrValues = new ArrayList<DocumentAttribute>();
523
524
525
526
527
528
529
530
531
532 DocumentAttributeString.Builder searchableAttributeValue = DocumentAttributeString.Builder.create(OleSelectConstant.InvoiceSearch.INV_DATE);
533 if(oleInvoiceDocument.getInvoiceDate()!=null){
534 DateFormat sourceFormat = new SimpleDateFormat("MM/dd/yyyy");
535 String date=sourceFormat.format(oleInvoiceDocument.getInvoiceDate());
536 searchableAttributeValue.setValue(date);
537 } else {
538 searchableAttributeValue.setValue("");
539 }
540 searchAttrValues.add(searchableAttributeValue.build());
541
542 searchableAttributeValue = DocumentAttributeString.Builder.create(OleSelectConstant.InvoiceSearch.INV_PAY_DATE);
543 if(oleInvoiceDocument.getInvoicePayDate()!=null){
544 DateFormat sourceFormat = new SimpleDateFormat("MM/dd/yyyy");
545 String date=sourceFormat.format(oleInvoiceDocument.getInvoicePayDate());
546 searchableAttributeValue.setValue(date);
547 } else {
548 searchableAttributeValue.setValue("");
549 }
550 searchAttrValues.add(searchableAttributeValue.build());
551
552 searchableAttributeValue = DocumentAttributeString.Builder.create(OleSelectConstant.InvoiceSearch.INV_SUB_TYP_ID);
553 if(oleInvoiceDocument.getInvoiceSubTypeId()!=null){
554 Map<String, Object> invoiceSubTypeMap = new HashMap<String, Object>();
555 invoiceSubTypeMap.put("invoiceSubTypeId", oleInvoiceDocument.getInvoiceSubTypeId());
556 List<OleInvoiceSubType> oleInvoiceSubTypeList = (List<OleInvoiceSubType>) KRADServiceLocator.getBusinessObjectService().findMatching(OleInvoiceSubType.class, invoiceSubTypeMap);
557 OleInvoiceSubType oleInvoiceSubTypeObj = oleInvoiceSubTypeList.get(0);
558 oleInvoiceDocument.setInvoiceSubType(oleInvoiceSubTypeObj.getInvoiceSubType());
559 searchableAttributeValue.setValue(oleInvoiceDocument.getInvoiceSubTypeId().toString());
560 } else {
561 searchableAttributeValue.setValue(null);
562 }
563 searchAttrValues.add(searchableAttributeValue.build());
564
565 searchableAttributeValue = DocumentAttributeString.Builder.create(OleSelectConstant.InvoiceSearch.INV_TYP_ID);
566 if(oleInvoiceDocument.getInvoiceTypeHdnId()!=null){
567 Map<String, String> invoiceTypeMap = new HashMap<String, String>();
568 invoiceTypeMap.put("invoiceTypeId", oleInvoiceDocument.getInvoiceTypeHdnId());
569 List<OleInvoiceType> oleInvoiceTypeList = (List<OleInvoiceType>) KRADServiceLocator.getBusinessObjectService().findMatching(OleInvoiceType.class, invoiceTypeMap);
570 OleInvoiceType oleInvoiceTypeObj = oleInvoiceTypeList.get(0);
571 oleInvoiceDocument.setInvoiceType(oleInvoiceTypeObj.getInvoiceType());
572 searchableAttributeValue.setValue(oleInvoiceDocument.getInvoiceTypeHdnId().toString());
573 } else {
574 searchableAttributeValue.setValue(null);
575 }
576 searchAttrValues.add(searchableAttributeValue.build());
577
578 searchableAttributeValue = DocumentAttributeString.Builder.create(OleSelectConstant.InvoiceSearch.INV_TYP);
579 if(oleInvoiceDocument.getInvoiceType()!=null){
580 searchableAttributeValue.setValue(oleInvoiceDocument.getInvoiceType().toString());
581 } else {
582 searchableAttributeValue.setValue(null);
583 }
584 searchAttrValues.add(searchableAttributeValue.build());
585
586 searchableAttributeValue = DocumentAttributeString.Builder.create(OleSelectConstant.InvoiceSearch.INV_SUB_TYP);
587 if(oleInvoiceDocument.getInvoiceSubType()!=null){
588 searchableAttributeValue.setValue(oleInvoiceDocument.getInvoiceSubType().toString());
589 } else {
590 searchableAttributeValue.setValue(null);
591 }
592 searchAttrValues.add(searchableAttributeValue.build());
593
594 List<OleInvoiceItem> oleInvoiceItems=oleInvoiceDocument.getItems();
595 List<String> poIds=new ArrayList<String>();
596 for (OleInvoiceItem oleInvoiceItem:oleInvoiceItems ) {
597 if (oleInvoiceItem.getPurchaseOrderIdentifier() != null) {
598 if(!poIds.contains(oleInvoiceItem.getPurchaseOrderIdentifier().toString())){
599 poIds.add(oleInvoiceItem.getPurchaseOrderIdentifier().toString());
600 searchableAttributeValue = DocumentAttributeString.Builder.create(OleSelectConstant.InvoiceSearch.ITEM_TITLE_ID);
601 searchableAttributeValue.setValue(oleInvoiceItem.getBibUUID());
602 searchAttrValues.add(searchableAttributeValue.build());
603 }
604 }
605 }
606 for(String poId:poIds){
607 searchableAttributeValue = DocumentAttributeString.Builder.create(OleSelectConstant.InvoiceSearch.PURAP_ID);
608 searchableAttributeValue.setValue(poId);
609 searchAttrValues.add(searchableAttributeValue.build());
610 }
611 return searchAttrValues;
612 }
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633 }