View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.select.document;
17  
18  import org.apache.commons.beanutils.PropertyUtils;
19  import org.apache.cxf.common.util.StringUtils;
20  import org.joda.time.DateTime;
21  import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
22  import org.kuali.ole.select.OleSelectConstant;
23  import org.kuali.ole.select.businessobject.OleFormatType;
24  import org.kuali.ole.select.businessobject.OleRequisitionItem;
25  import org.kuali.ole.sys.OLEConstants;
26  import org.kuali.ole.sys.OLEKeyConstants;
27  import org.kuali.ole.sys.context.SpringContext;
28  import org.kuali.rice.core.api.datetime.DateTimeService;
29  import org.kuali.rice.core.api.util.RiceKeyConstants;
30  import org.kuali.rice.core.api.util.type.KualiDecimal;
31  import org.kuali.rice.kew.actionitem.ActionItem;
32  import org.kuali.rice.kew.actionlist.service.ActionListService;
33  import org.kuali.rice.kew.actionrequest.ActionRequestValue;
34  import org.kuali.rice.kew.actionrequest.KimPrincipalRecipient;
35  import org.kuali.rice.kew.actionrequest.service.ActionRequestService;
36  import org.kuali.rice.kew.api.KewApiConstants;
37  import org.kuali.rice.kew.api.KewApiServiceLocator;
38  import org.kuali.rice.kew.api.WorkflowDocument;
39  import org.kuali.rice.kew.api.document.DocumentStatus;
40  import org.kuali.rice.kew.api.document.search.DocumentSearchCriteria;
41  import org.kuali.rice.kew.api.document.search.DocumentSearchResult;
42  import org.kuali.rice.kew.api.document.search.DocumentSearchResults;
43  import org.kuali.rice.kew.api.exception.WorkflowException;
44  import org.kuali.rice.kew.exception.WorkflowServiceError;
45  import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
46  import org.kuali.rice.kew.service.KEWServiceLocator;
47  import org.kuali.rice.kim.api.identity.Person;
48  import org.kuali.rice.kim.api.identity.PersonService;
49  import org.kuali.rice.kim.api.identity.principal.Principal;
50  import org.kuali.rice.kim.api.role.RoleService;
51  import org.kuali.rice.kim.api.services.IdentityManagementService;
52  import org.kuali.rice.kns.service.DataDictionaryService;
53  import org.kuali.rice.krad.datadictionary.DocumentEntry;
54  import org.kuali.rice.krad.document.TransactionalDocumentBase;
55  import org.kuali.rice.krad.service.BusinessObjectService;
56  import org.kuali.rice.krad.service.DocumentHeaderService;
57  import org.kuali.rice.krad.service.DocumentService;
58  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
59  import org.kuali.rice.krad.util.GlobalVariables;
60  import org.kuali.rice.krad.util.ObjectUtils;
61  import org.kuali.rice.krad.workflow.service.WorkflowDocumentService;
62  
63  import java.sql.Timestamp;
64  import java.text.ParseException;
65  import java.util.*;
66  
67  /**
68   * This class is the document class for Order Holding Queue.
69   */
70  public class OleOrderQueueDocument extends TransactionalDocumentBase {
71  
72      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleOrderQueueDocument.class);
73  
74      private String documentNumber;
75  
76      private String selectedUserId;
77  
78      private String selectorUserId;
79  
80      private String principalName;
81  
82  	/*private Timestamp createdDate;
83  
84      private Timestamp modifiedDate;*/
85  
86      private String statusCode;
87  
88      private Integer totalPrice;
89  
90      private String active;
91  
92      public List<OleRequisitionItem> requisitionItems = new ArrayList<OleRequisitionItem>();
93  
94      // Added for OLE-1976 Order Queue Search Enhancements
95      private String title;
96  
97      private String author;
98  
99      private String publisher;
100 
101     private String isbn;
102 
103     private String requisitionDocNumber;
104 
105     private String internalRequestorId;
106 
107     private String externalRequestorId;
108 
109     private String requestorName;
110 
111     private String requisitionStatus;
112 
113     private String requisitionStatusCode;
114 
115     private String vendorName;
116 
117     private String formatTypeId;
118 
119     private OleFormatType oleFormatType;
120 
121     private Timestamp workflowStatusChangeDateFrom;
122 
123     private Timestamp workflowStatusChangeDateTo;
124 
125     private String requisitionSelectorUserId;
126 
127     private String requisitionSelectorPrincipalName;
128 
129     /**
130      * Stores the value of selectorUserName.
131      */
132     private String selectorUserName;
133 
134     /**
135      * Stores the value of accountNumber.
136      */
137     private String accountNumber;
138 
139     /**
140      * Stores the value of objectCode.
141      */
142     private String objectCode;
143 
144     /**
145      * Stores the value of chartOfAccountsCode.
146      */
147     private String chartOfAccountsCode;
148 
149     //private String selectorRoleName;
150 
151     // Added for OLE-1976 Order Queue Search Enhancements Ends
152 
153     @Override
154     public String getDocumentNumber() {
155         return documentNumber;
156     }
157 
158     @Override
159     public void setDocumentNumber(String documentNumber) {
160         this.documentNumber = documentNumber;
161     }
162 
163     public String getSelectedUserId() {
164         return selectedUserId;
165     }
166 
167     public void setSelectedUserId(String selectedUserId) {
168         this.selectedUserId = selectedUserId;
169     }
170 
171     public String getSelectorUserId() {
172         return selectorUserId;
173     }
174 
175     public void setSelectorUserId(String selectorUserId) {
176         this.selectorUserId = selectorUserId;
177     }
178 
179     /*public Timestamp getCreatedDate() {
180         return createdDate;
181     }
182     public void setCreatedDate(Timestamp createdDate) {
183         this.createdDate = createdDate;
184     }
185     public Timestamp getModifiedDate() {
186         return modifiedDate;
187     }
188     public void setModifiedDate(Timestamp modifiedDate) {
189         this.modifiedDate = modifiedDate;
190     }*/
191     public String getStatusCode() {
192         return statusCode;
193     }
194 
195     public void setStatusCode(String statusCode) {
196         this.statusCode = statusCode;
197     }
198 
199     public Integer getTotalPrice() {
200         return totalPrice;
201     }
202 
203     public void setTotalPrice(Integer totalPrice) {
204         this.totalPrice = totalPrice;
205     }
206 
207     public String getActive() {
208         return active;
209     }
210 
211     public void setActive(String active) {
212         this.active = active;
213     }
214 
215     /**
216      * Gets the principalName attribute.
217      *
218      * @return Returns the principalName.
219      */
220     public String getPrincipalName() {
221         return principalName;
222     }
223 
224     /**
225      * Sets the principalName attribute value.
226      *
227      * @param principalName The principalName to set.
228      */
229     public void setPrincipalName(String principalName) {
230         this.principalName = principalName;
231     }
232 
233     /**
234      * Gets the requisitions attribute.
235      *
236      * @return Returns the requisitions.
237      */
238     public List<OleRequisitionItem> getRequisitionItems() {
239         return requisitionItems;
240     }
241 
242     /**
243      * Sets the requisitions attribute value.
244      *
245      * @param requisitions The requisitions to set.
246      */
247     public void setRequisitionItems(List<OleRequisitionItem> requisitionItems) {
248         this.requisitionItems = requisitionItems;
249     }
250 
251     public void addRequisitions(OleRequisitionItem data) {
252         this.requisitionItems.add(data);
253     }
254 
255     public boolean isRequisitionAdded() {
256         if (this.requisitionItems != null) {
257             return this.requisitionItems.size() > 0;
258         } else {
259             return false;
260         }
261     }
262 
263     // Added for OLE-1976 Order Queue Search Enhancements
264     public String getTitle() {
265         return title;
266     }
267 
268     public void setTitle(String title) {
269         this.title = title;
270     }
271 
272     public String getAuthor() {
273         return author;
274     }
275 
276     public void setAuthor(String author) {
277         this.author = author;
278     }
279 
280     public String getPublisher() {
281         return publisher;
282     }
283 
284     public void setPublisher(String publisher) {
285         this.publisher = publisher;
286     }
287 
288     public String getIsbn() {
289         return isbn;
290     }
291 
292     public void setIsbn(String isbn) {
293         this.isbn = isbn;
294     }
295 
296     public String getRequisitionDocNumber() {
297         return requisitionDocNumber;
298     }
299 
300     public void setRequisitionDocNumber(String requisitionDocNumber) {
301         this.requisitionDocNumber = requisitionDocNumber;
302     }
303 
304     public String getInternalRequestorId() {
305         return internalRequestorId;
306     }
307 
308     public void setInternalRequestorId(String internalRequestorId) {
309         this.internalRequestorId = internalRequestorId;
310     }
311 
312     public String getExternalRequestorId() {
313         return externalRequestorId;
314     }
315 
316     public void setExternalRequestorId(String externalRequestorId) {
317         this.externalRequestorId = externalRequestorId;
318     }
319 
320     public String getRequestorName() {
321         return requestorName;
322     }
323 
324     public void setRequestorName(String requestorName) {
325         this.requestorName = requestorName;
326     }
327 
328     public String getRequisitionStatus() {
329         return requisitionStatus;
330     }
331 
332     public void setRequisitionStatus(String requisitionStatus) {
333         this.requisitionStatus = requisitionStatus;
334     }
335 
336     public String getRequisitionStatusCode() {
337         return requisitionStatusCode;
338     }
339 
340     public void setRequisitionStatusCode(String requisitionStatusCode) {
341         this.requisitionStatusCode = requisitionStatusCode;
342     }
343 
344     public String getVendorName() {
345         return vendorName;
346     }
347 
348     public void setVendorName(String vendorName) {
349         this.vendorName = vendorName;
350     }
351 
352     public String getFormatTypeId() {
353         return formatTypeId;
354     }
355 
356     public void setFormatTypeId(String formatTypeId) {
357         this.formatTypeId = formatTypeId;
358     }
359 
360     public OleFormatType getOleFormatType() {
361         return oleFormatType;
362     }
363 
364     public void setOleFormatType(OleFormatType oleFormatType) {
365         this.oleFormatType = oleFormatType;
366     }
367 
368     public Timestamp getWorkflowStatusChangeDateFrom() {
369         return workflowStatusChangeDateFrom;
370     }
371 
372     public void setWorkflowStatusChangeDateFrom(Timestamp workflowStatusChangeDateFrom) {
373         this.workflowStatusChangeDateFrom = workflowStatusChangeDateFrom;
374     }
375 
376     public Timestamp getWorkflowStatusChangeDateTo() {
377         return workflowStatusChangeDateTo;
378     }
379 
380     public void setWorkflowStatusChangeDateTo(Timestamp workflowStatusChangeDateTo) {
381         this.workflowStatusChangeDateTo = workflowStatusChangeDateTo;
382     }
383 
384     public String getRequisitionSelectorUserId() {
385         return requisitionSelectorUserId;
386     }
387 
388     public void setRequisitionSelectorUserId(String requisitionSelectorUserId) {
389         this.requisitionSelectorUserId = requisitionSelectorUserId;
390     }
391 
392     public String getRequisitionSelectorPrincipalName() {
393         return requisitionSelectorPrincipalName;
394     }
395 
396     public void setRequisitionSelectorPrincipalName(String requisitionSelectorPrincipalName) {
397         this.requisitionSelectorPrincipalName = requisitionSelectorPrincipalName;
398     }
399 
400     /**
401      * Getter for property: selectorUserName.<br/>
402      * Stores the value of selectorUserName.
403      */
404     public String getSelectorUserName() {
405         return selectorUserName;
406     }
407 
408     /**
409      * Setter for property: selectorUserName.<br/>
410      * Stores the value of selectorUserName.
411      */
412     public void setSelectorUserName(String selectorUserName) {
413         this.selectorUserName = selectorUserName;
414     }
415 
416     /**
417      * Getter for property: accountNumber.<br/>
418      * Stores the value of accountNumber.
419      */
420     public String getAccountNumber() {
421         return accountNumber;
422     }
423 
424     /**
425      * Setter for property: accountNumber.<br/>
426      * Stores the value of accountNumber.
427      */
428     public void setAccountNumber(String accountNumber) {
429         this.accountNumber = accountNumber;
430     }
431 
432     /**
433      * Getter for property: objectCode.<br/>
434      * Stores the value of objectCode.
435      */
436     public String getObjectCode() {
437         return objectCode;
438     }
439 
440     /**
441      * Setter for property: objectCode.<br/>
442      * Stores the value of objectCode.
443      */
444     public void setObjectCode(String objectCode) {
445         this.objectCode = objectCode;
446     }
447 
448     /**
449      * Getter for property: chartOfAccountsCode.<br/>
450      * Stores the value of chartOfAccountsCode.
451      */
452     public String getChartOfAccountsCode() {
453         return chartOfAccountsCode;
454     }
455 
456     /**
457      * Setter for property: chartOfAccountsCode.<br/>
458      * Stores the value of chartOfAccountsCode.
459      */
460     public void setChartOfAccountsCode(String chartOfAccountsCode) {
461         this.chartOfAccountsCode = chartOfAccountsCode;
462     }
463     // Added for OLE-1976 Order Queue Search Enhancements Ends
464 
465     /**
466      * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper()
467      */
468     @SuppressWarnings("rawtypes")
469 
470     protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
471         LinkedHashMap m = new LinkedHashMap();
472         return m;
473     }
474 
475     /**
476      * This method invokes approveDocument of DocumentService to approve selected requisitions
477      * and sets errors appriopriately if approval fails.
478      */
479     public void massApprove() {
480         LOG.debug("Inside massApprove of OleOrderQueueDocument");
481         ActionListService actionListSrv = KEWServiceLocator.getActionListService();
482         ActionRequestService actionReqSrv = KEWServiceLocator.getActionRequestService();
483         boolean orderQueue = false;
484         boolean orderQueueNotApproved = false;
485         WorkflowDocumentService workflowDocumentService = KRADServiceLocatorWeb.getWorkflowDocumentService();
486         Person person = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
487         WorkflowDocument workflowDocument;
488         String docNum = null;
489         StringBuilder orderQueueRequisitionApproved = new StringBuilder();
490         StringBuilder orderQueueRequisitionNotApproved = new StringBuilder();
491         List<OleRequisitionItem> refreshItems = new ArrayList<OleRequisitionItem>();
492         for (OleRequisitionItem item : requisitionItems) {
493             boolean itemAdded = item.isItemAdded();
494             if (itemAdded) {
495                 try {
496                     workflowDocument = workflowDocumentService.loadWorkflowDocument(item.getRequisition().getDocumentNumber(), person);
497                     if (workflowDocument.getInitiatorPrincipalId().equals(GlobalVariables.getUserSession().getPerson().getPrincipalId())) {
498                         if (DocumentStatus.ENROUTE.equals(workflowDocument.getStatus())) {
499                             List<ActionRequestValue> actionReqValues = actionReqSrv.findAllPendingRequests(item.getRequisition().getDocumentNumber());
500                             for (ActionRequestValue actionRequest : actionReqValues) {
501                                 if (KewApiConstants.ACTION_REQUEST_APPROVE_REQ.equals(actionRequest.getActionRequested())) {
502                                     Timestamp currentTime = SpringContext.getBean(DateTimeService.class).getCurrentTimestamp();
503                                     List<ActionItem> actionItems = actionRequest.getActionItems();
504                                     for (ActionItem actionItem : actionItems) {
505                                         if (KewApiConstants.ACTION_REQUEST_APPROVE_REQ_LABEL.equals(actionItem.getActionRequestLabel())) {
506                                             actionItem.setPrincipalId(GlobalVariables.getUserSession().getPerson().getPrincipalId());
507                                             actionItem.setDateAssigned(currentTime);
508                                             actionListSrv.saveActionItem(actionItem);
509                                         }
510                                     }
511                                     actionRequest.setPrincipalId(GlobalVariables.getUserSession().getPerson().getPrincipalId());
512                                     actionRequest.setCreateDate(currentTime);
513                                     actionReqSrv.saveActionRequest(actionRequest);
514 
515 
516                                     boolean documentApproved = approveDocument(new Long(item.getRequisition().getPurapDocumentIdentifier()), item.getRequisition().getDocumentNumber(), actionRequest.getAnnotation());
517                                     if (!documentApproved) {
518                                         refreshItems.add(item);
519                                     } else {
520                                         if (!item.getRequisition().getDocumentNumber().equalsIgnoreCase(docNum)) {
521                                             orderQueueRequisitionApproved.append(item.getRequisition().getDocumentNumber()).append(",");
522                                             orderQueue = true;
523                                             docNum = item.getRequisition().getDocumentNumber();
524                                         }
525                                     }
526                                 } else {
527                                     GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.ERROR_ORDERQUEUE_REQUISITIONS_NOAPPROVALS_REQD, new String[]{item.getRequisition().getDocumentNumber()});
528                                     refreshItems.add(item);
529                                 }
530                             }
531                         } else if (workflowDocument.isSaved()) {
532                             boolean documentSubmitted = submitDocument(Long.valueOf(item.getRequisition().getPurapDocumentIdentifier()), item.getRequisition().getDocumentNumber(), OLEConstants.OrderQueue.SUBMIT_ANNOTATION);
533                             if (!documentSubmitted) {
534                                 refreshItems.add(item);
535                             } else {
536                                 orderQueueRequisitionApproved.append(item.getRequisition().getDocumentNumber()).append(",");
537                                 orderQueue = true;
538                             }
539                         } else {
540                             GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.ERROR_ORDERQUEUE_REQUISITIONS_APPROVE, new String[]{workflowDocument.getStatus().toString(), item.getRequisition().getDocumentNumber()});
541                             refreshItems.add(item);
542                         }
543                     } else {
544                         orderQueueRequisitionNotApproved.append(item.getRequisition().getDocumentNumber()).append(",");
545                         orderQueueNotApproved = true;
546                     }
547                 } catch (WorkflowException ex) {
548                     GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, RiceKeyConstants.ERROR_CUSTOM, ex.getMessage());
549                     refreshItems.add(item);
550                 }
551             } else {
552                 refreshItems.add(item);
553             }
554         }
555         int len = orderQueueRequisitionApproved.lastIndexOf(",");
556         if (orderQueue) {
557             orderQueueRequisitionApproved.replace(len, len + 1, " ");
558             GlobalVariables.getMessageMap().putInfo(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.MESSAGE_ORDERQUEUE_REQUISITIONS_APPROVED, new String[]{orderQueueRequisitionApproved.toString()});
559         }
560 
561         int length = orderQueueRequisitionNotApproved.lastIndexOf(",");
562         if (orderQueueNotApproved) {
563             orderQueueRequisitionNotApproved.replace(length, length + 1, " ");
564             GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.ERROR_ORDERQUEUE_REQUISITIONS_APPROVE_NOT_INITIATOR, new String[]{orderQueueRequisitionNotApproved.toString()});
565         }
566         requisitionItems = refreshItems;
567         LOG.debug("Leaving massApprove of OleOrderQueueDocument");
568     }
569 
570     /**
571      * This method invokes approveDocument of DocumentService on the specified requisition document
572      * and sets errors appriopriately if approval fails. Approves a document that is in enroute status.
573      */
574     private boolean approveDocument(Long requisitionDocumentId, String documentNumber, String annotation) {
575         LOG.debug("Inside approveDocument of OleOrderQueueDocument");
576         OleRequisitionDocument requisitionDocument = SpringContext.getBean(BusinessObjectService.class).findBySinglePrimaryKey(OleRequisitionDocument.class, requisitionDocumentId);
577         requisitionDocument.setDocumentHeader(SpringContext.getBean(DocumentHeaderService.class).getDocumentHeaderById(documentNumber));
578         Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
579         try {
580             requisitionDocument.getDocumentHeader().setWorkflowDocument(KRADServiceLocatorWeb.getWorkflowDocumentService().createWorkflowDocument(requisitionDocument.getDocumentHeader().getWorkflowDocument().getDocumentTypeName(), principalPerson));
581             SpringContext.getBean(DocumentService.class).approveDocument(requisitionDocument, principalPerson.getName() + OLEConstants.OrderQueue.APPROVE_ANNOTATION + annotation, null);
582             return true;
583         } catch (WorkflowException wfe) {
584             GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.ERROR_ORDERQUEUE_REQUISITIONS_APPROVE_WFE, new String[]{documentNumber, wfe.getMessage()});
585             return false;
586         }
587     }
588 
589     /**
590      * This method invokes routeDocument of DocumentService on the specified requisition document
591      * and sets errors appriopriately if approval fails. Submits a document that is in saved status.
592      */
593     private boolean submitDocument(Long requisitionDocumentId, String documentNumber, String annotation) {
594         LOG.debug("Inside submitDocument of OleOrderQueueDocument");
595         OleRequisitionDocument requisitionDocument = SpringContext.getBean(BusinessObjectService.class).findBySinglePrimaryKey(OleRequisitionDocument.class, requisitionDocumentId);
596         requisitionDocument.setDocumentHeader(SpringContext.getBean(DocumentHeaderService.class).getDocumentHeaderById(documentNumber));
597         Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
598         try {
599             requisitionDocument.getDocumentHeader().setWorkflowDocument(KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(requisitionDocument.getDocumentNumber(), principalPerson));
600             SpringContext.getBean(DocumentService.class).routeDocument(requisitionDocument, annotation, null);
601             return true;
602         } catch (WorkflowException wfe) {
603             GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.ERROR_ORDERQUEUE_REQUISITIONS_SUBMIT_WFE, new String[]{documentNumber, wfe.getMessage()});
604             return false;
605         }
606     }
607 
608     /**
609      * This method validates for selector and assigns selected requisitions to the selector.
610      */
611     public void assign() {
612         LOG.debug("Inside assign of OleOrderQueueDocument");
613         if (selectedUserId == null || StringUtils.isEmpty(selectedUserId)) {
614             Principal principalInfo = SpringContext.getBean(IdentityManagementService.class).getPrincipalByPrincipalName(GlobalVariables.getUserSession().getPerson().getPrincipalName());
615             if (principalInfo != null) {
616                 selectedUserId = principalInfo.getPrincipalId();
617             } else {
618                 GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.ERROR_ORDERQUEUE_INVALID_PRINCIPAL_NAME,
619                         new String[]{});
620                 return;
621             }
622             RoleService roleService = SpringContext.getBean(RoleService.class);
623             // Check if the Selector actually has the role of SELECTOR
624             String roleId = roleService.getRoleIdByNamespaceCodeAndName(OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_ROLE_NAMESPACE, OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_ROLE);
625             List<String> roleIds = new ArrayList<String>();
626             roleIds.add(roleId);
627             if (!roleService.principalHasRole(selectedUserId, roleIds, null)) {
628                 GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.ERROR_ORDERQUEUE_INVALID_SELECTOR, new String[]{principalName});
629                 return;
630             }
631         }
632 
633         Long documentNumber;
634         WorkflowDocumentService workflowDocumentService = KRADServiceLocatorWeb.getWorkflowDocumentService();
635         Person person = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
636         WorkflowDocument workflowDocument;
637         List<OleRequisitionItem> refreshItems = new ArrayList<OleRequisitionItem>();
638         for (OleRequisitionItem item : requisitionItems) {
639             boolean itemAdded = item.isItemAdded();
640             if (itemAdded) {
641                 try {
642                     workflowDocument = workflowDocumentService.loadWorkflowDocument(item.getRequisition().getDocumentNumber(), person);
643 
644                     // DocumentRouteHeaderValue routeHeader = SpringContext.getBean(RouteHeaderService.class).getRouteHeader(documentNumber);
645                     Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(selectedUserId);
646                     if (workflowDocument.isSaved() || workflowDocument.isEnroute()) {
647                         assignActionRequests(workflowDocument.getDocumentId().toString());
648                         GlobalVariables.getMessageMap().putInfo(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.MESSAGE_ORDERQUEUE_REQUISITIONS_ASSIGNED, new String[]{item.getRequisition().getDocumentNumber(), principalName});
649                     } else {
650                         GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.ERROR_ORDERQUEUE_REQUISITIONS_ASSIGN, new String[]{workflowDocument.getStatus().toString(), item.getRequisition().getDocumentNumber()});
651                         refreshItems.add(item);
652                     }
653                 } catch (WorkflowException ex) {
654                     GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, RiceKeyConstants.ERROR_CUSTOM, ex.getMessage());
655                     refreshItems.add(item);
656                 }
657 
658             } else {
659                 refreshItems.add(item);
660             }
661         }
662         requisitionItems = refreshItems;
663         LOG.debug("Leaving assign of OleOrderQueueDocument");
664     }
665 
666     /**
667      * This method assigns specified document to the selector.
668      */
669     private void assignActionRequests(String routeHeaderId) {
670         LOG.debug("Inside assignActionRequests of OleOrderQueueDocument");
671         Timestamp currentTime = SpringContext.getBean(DateTimeService.class).getCurrentTimestamp();
672         ActionListService actionListSrv = KEWServiceLocator.getActionListService();
673         ActionRequestService actionReqSrv = KEWServiceLocator.getActionRequestService();
674         List<ActionRequestValue> actionReqValues = actionReqSrv.findAllPendingRequests(routeHeaderId);
675         for (ActionRequestValue actionRequest : actionReqValues) {
676             List<ActionItem> actionItems = actionRequest.getActionItems();
677             for (ActionItem actionItem : actionItems) {
678                 actionItem.setPrincipalId(selectedUserId);
679                 actionItem.setDateAssigned(currentTime);
680                 actionListSrv.saveActionItem(actionItem);
681             }
682             actionRequest.setPrincipalId(selectedUserId);
683             actionRequest.setCreateDate(currentTime);
684             actionReqSrv.saveActionRequest(actionRequest);
685         }
686         LOG.debug("Leaving assignActionRequests of OleOrderQueueDocument");
687     }
688 
689     /**
690      * This method invokes cancelDocument of DocumentService to delete selected requisitions.
691      * Sets error message appriopriately if this action fails.
692      */
693     public void delete() {
694         LOG.debug("Inside delete of OleOrderQueueDocument");
695         WorkflowDocumentService workflowDocumentService = SpringContext.getBean(WorkflowDocumentService.class);
696         Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
697         WorkflowDocument workflowDocument;
698         List<OleRequisitionItem> refreshItems = new ArrayList<OleRequisitionItem>();
699         OleRequisitionDocument requisitionDocument;
700         StringBuilder orderQueueRequisitionDeleted = new StringBuilder();
701         boolean isErrorMsg = false;
702         for (OleRequisitionItem item : requisitionItems) {
703             boolean itemAdded = item.isItemAdded();
704             if (itemAdded) {
705                 try {
706                     workflowDocument = workflowDocumentService.loadWorkflowDocument(item.getRequisition().getDocumentNumber(), principalPerson);
707                     if (workflowDocument.isSaved()) {
708                         requisitionDocument = SpringContext.getBean(BusinessObjectService.class).findBySinglePrimaryKey(OleRequisitionDocument.class, Long.valueOf(item.getRequisition().getPurapDocumentIdentifier()));
709                         requisitionDocument.setDocumentHeader(SpringContext.getBean(DocumentHeaderService.class).getDocumentHeaderById(item.getRequisition().getDocumentNumber()));
710 
711                         try {
712                             requisitionDocument.getDocumentHeader().setWorkflowDocument(workflowDocument);
713                             SpringContext.getBean(DocumentService.class).cancelDocument(requisitionDocument, OLEConstants.OrderQueue.CANCEL_ANNOTATION);
714                             orderQueueRequisitionDeleted.append(item.getRequisition().getDocumentNumber()).append(",");
715                             isErrorMsg = true;
716                         } catch (WorkflowException wfe) {
717                             GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.ERROR_ORDERQUEUE_REQUISITIONS_CANCELED_WFE, new String[]{requisitionDocument.getDocumentNumber(), wfe.getMessage()});
718                             refreshItems.add(item);
719                         }
720                     } else {
721                         GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.ERROR_ORDERQUEUE_REQUISITIONS_CANCELED, new String[]{workflowDocument.getStatus().toString(), item.getRequisition().getDocumentNumber()});
722                         refreshItems.add(item);
723                     }
724                 } catch (WorkflowException ex) {
725                     GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, RiceKeyConstants.ERROR_CUSTOM, ex.getMessage());
726                     refreshItems.add(item);
727                 }
728             } else {
729                 refreshItems.add(item);
730             }
731         }
732 
733         int len = orderQueueRequisitionDeleted.lastIndexOf(",");
734         if (isErrorMsg) {
735             orderQueueRequisitionDeleted.replace(len, len + 1, " ");
736             GlobalVariables.getMessageMap().putInfo(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.MESSAGE_ORDERQUEUE_REQUISITIONS_CANCELED, new String[]{orderQueueRequisitionDeleted.toString()});
737         }
738         requisitionItems = refreshItems;
739         LOG.debug("Leaving delete of OleOrderQueueDocument");
740     }
741 
742     /**
743      * This method returns total price of the selected requisition items.
744      *
745      * @return Total Price of selected items
746      */
747     public KualiDecimal getTotalSelectedItemsPrice() {
748         LOG.debug("Inside totalSelectedItems of OleOrderQueueDocument");
749         KualiDecimal totalPrice = KualiDecimal.ZERO;
750         ;
751         StringBuilder orderQueueRequisitionHasNoPrice = new StringBuilder();
752         boolean isInfoMsg = false;
753         List<OleRequisitionItem> refreshItems = new ArrayList<OleRequisitionItem>();
754         for (OleRequisitionItem item : requisitionItems) {
755             if (item.isItemAdded()) {
756                 if (item.getSourceAccountingLines().size() > 0) {
757                     if (item.getTotalAmount().equals(KualiDecimal.ZERO)) {
758                         orderQueueRequisitionHasNoPrice.append(item.getRequisition().getDocumentNumber()).append(",");
759                         isInfoMsg = true;
760                     }
761                     for (int i = 0; i < item.getSourceAccountingLines().size(); i++) {
762                         KualiDecimal amount = item.getSourceAccountingLines().get(i).getAmount();
763                         totalPrice = totalPrice.add(amount);
764                     }
765                 } else {
766                     if (item.getItemListPrice().equals(KualiDecimal.ZERO)) {
767                         orderQueueRequisitionHasNoPrice.append(item.getRequisition().getDocumentNumber()).append(",");
768                         isInfoMsg = true;
769                     }
770                     totalPrice = totalPrice.add(item.getItemListPrice());
771                 }
772             }
773             refreshItems.add(item);
774         }
775         requisitionItems = refreshItems;
776         int len = orderQueueRequisitionHasNoPrice.lastIndexOf(",");
777         if (isInfoMsg) {
778             orderQueueRequisitionHasNoPrice.replace(len, len + 1, " ");
779             GlobalVariables.getMessageMap().putInfo(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.MESSAGE_ORDERQUEUE_REQUISITIONS_HAS_NO_PRICE, new String[]{orderQueueRequisitionHasNoPrice.toString()});
780         }
781         LOG.debug("Leaving totalSelectedItems of OleOrderQueueDocument");
782         return totalPrice;
783     }
784 
785     /**
786      * This method populates a map with OleRequisitionItem fields for search criteria entered
787      * from Order Holding Queue Page
788      *
789      * @return Map containing OleRequisitionItem fieldname and fieldvalue
790      */
791     public Map<String, String> populateRequisitionFields() throws Exception {
792         LOG.debug("Inside populateRequisitionFields of OleOrderQueueDocument");
793         Map<String, String> searchCriteriaMap = new HashMap<String, String>();
794         DocumentEntry documentEntry = SpringContext.getBean(DataDictionaryService.class).getDataDictionary().getDocumentEntry(OleOrderQueueDocument.class.getName());
795 
796         Set attributeNames = documentEntry.getAttributeNames();
797         for (Object attributeName : attributeNames) {
798             String attr = (String) attributeName;
799             if (!(OLEConstants.OrderQueue.selectorField.equals(attr) || OLEConstants.OrderQueue.workflowStatusChangeDateFrom.equals(attr) || OLEConstants.OrderQueue.workflowStatusChangeDateTo.equals(attr))) {
800                 String attrValue = (String) PropertyUtils.getProperty(this, attr);
801                 attr = OLEConstants.OrderQueue.REQUISITION_FIELDS.get(attr);
802                 if (ObjectUtils.isNotNull(attr) && ObjectUtils.isNotNull(attrValue)) {
803                     searchCriteriaMap.put(attr, attrValue);
804                 }
805             }
806             if (LOG.isDebugEnabled()) {
807                 LOG.debug("Search Criteria Size in OleOrderQueueDocument.populateRequisitionFields - " + searchCriteriaMap.size());
808             }
809         }
810         LOG.debug("Leaving populateRequisitionFields of OleOrderQueueDocument");
811         return searchCriteriaMap;
812     }
813 
814     /**
815      * This method filters the result list for other search criteria entered that are not a part of
816      * Requisiton and Requisition Item related table.
817      *
818      * @param results
819      * @return
820      */
821     public List<OleRequisitionItem> filterOtherSearchCriteria(List<OleRequisitionItem> results) {
822         LOG.debug("Inside filterOtherSearchCriteria of OleOrderQueueDocument");
823         boolean isSelectorLookup = false;
824         if (this.selectorUserId != null) {
825             isSelectorLookup = true;
826         /*if(this.selectorUserId != null && !StringUtils.isEmpty(this.selectorUserId)){
827             RoleService roleService = SpringContext.getBean(RoleService.class);
828             // Check if the Selector actually has the role of SELECTOR
829             String roleId = roleService.getRoleIdByNamespaceCodeAndName(OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_ROLE_NAMESPACE, OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_ROLE);
830             List<String> roleIds = new ArrayList<String>();
831             roleIds.add(roleId);
832             if(roleService.principalHasRole(this.selectorUserId, roleIds, null)) {
833                 isSelectorLookup = true;
834             }
835             else{
836                 GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, OLEKeyConstants.ERROR_ORDERQUEUE_INVALID_SELECTOR, new String[]{this.selectorUserId});
837                 return new ArrayList();
838             }
839         }*/
840         }
841 
842         if (LOG.isDebugEnabled()) {
843             LOG.debug("Selector Lookup value in OleOrderQueueDocument.filterOtherSearchCriteria - " + isSelectorLookup);
844         }
845 
846         // date lookup
847         Map<String, List<String>> fixedParameters = preprocessDateFields();
848 
849         boolean isDateLookup = false;
850         Map<String, Timestamp> workflowStatusChangeDate = new HashMap<String, Timestamp>();
851         if (!((fixedParameters.get(OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_FROM_DATE_LAST_MODIFIED) == null || fixedParameters.get(OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_FROM_DATE_LAST_MODIFIED).get(0).isEmpty()) &&
852                 (fixedParameters.get(OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_TO_DATE_LAST_MODIFIED) == null || fixedParameters.get(OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_TO_DATE_LAST_MODIFIED).get(0).isEmpty()) &&
853                 (fixedParameters.get(OleSelectConstant.AcquisitionsSearch.INITIATOR) == null || fixedParameters.get(OleSelectConstant.AcquisitionsSearch.INITIATOR).get(0).isEmpty()))) {
854             workflowStatusChangeDate = filterWorkflowStatusDate(results, fixedParameters);
855             isDateLookup = true;
856         }
857         // date lookup
858         if (LOG.isDebugEnabled()) {
859             LOG.debug("Date Lookup value in OleOrderQueueDocument.filterOtherSearchCriteria - " + isDateLookup);
860         }
861         WorkflowDocumentService workflowDocumentService = SpringContext.getBean(WorkflowDocumentService.class);
862         Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
863         WorkflowDocument workflowDocument;
864 
865         List<OleRequisitionItem> finalResult = new ArrayList<OleRequisitionItem>();
866         boolean isValid = false;
867         for (OleRequisitionItem item : results) {
868             isValid = true;
869             try {
870 
871                 if (item.getRequisition().getDocumentHeader().getDocumentNumber() == null) {
872                     item.getRequisition().setDocumentHeader(SpringContext.getBean(DocumentHeaderService.class).getDocumentHeaderById(item.getRequisition().getDocumentNumber()));
873                 }
874                 workflowDocument = workflowDocumentService.loadWorkflowDocument(item.getRequisition().getDocumentNumber(), principalPerson);
875                 //item.setApplicationDocumentStatus(workflowDocument.getApplicationDocumentStatus());
876                 if ((this.requisitionStatus != null)
877                         && !workflowDocument.getApplicationDocumentStatus().equalsIgnoreCase(this.requisitionStatus)) {
878                     isValid = false;
879                 }
880                 if (workflowDocument.isCanceled() ||
881                         workflowDocument.isFinal()) {
882                     isValid = false;
883                 }
884                 if (isValid && isSelectorLookup) {
885                     if (selectorLookup(item, this.selectorUserId)) {
886                         isValid = true;
887                     } else {
888                         isValid = false;
889                     }
890                 }
891 
892                 if (isValid && this.requestorName != null && !StringUtils.isEmpty(this.requestorName)) {
893                     if (this.internalRequestorId != null) {
894                         if (this.internalRequestorId.equals(item.getInternalRequestorId())) {
895                             isValid = true;
896                         } else {
897                             isValid = false;
898                         }
899                     } else if (this.externalRequestorId != null) {
900                         if (this.externalRequestorId.equals(item.getRequestorId())) {
901                             isValid = true;
902                         } else {
903                             isValid = false;
904                         }
905                     } else {
906                         isValid = false;
907                     }
908 
909                 }
910 
911                 if (isValid && isDateLookup) {
912                     if (workflowStatusChangeDate.get(item.getRequisition().getDocumentNumber()) != null) {
913                         item.setDateModified(convertTimestampToString(workflowStatusChangeDate.get(item.getRequisition().getDocumentNumber())));
914                         isValid = true;
915                     } else {
916                         isValid = false;
917                     }
918                 } else {
919                     populateWorkflowStatusDate(item);
920                 }
921                 if (isValid) {
922                     // jira OLE-2363 validation for order holding queue.
923                     List<PurApAccountingLine> lines = item.getSourceAccountingLines();
924                     if (lines.size() > 0) {
925                         for (int i = 0; i < lines.size(); i++) {
926                             OleRequisitionItem tempItem = new OleRequisitionItem();
927                             tempItem = (OleRequisitionItem) ObjectUtils.deepCopy(item);
928                             List<PurApAccountingLine> line = new ArrayList<PurApAccountingLine>();
929                             line.add(lines.get(i));
930                             tempItem.setSourceAccountingLines(null);
931                             tempItem.setSourceAccountingLines(line);
932                             finalResult.add(tempItem);
933                         }
934                     } else {
935                         finalResult.add(item);
936                     }
937 
938                 }
939             } catch (WorkflowException ex) {
940                 GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, RiceKeyConstants.ERROR_CUSTOM, ex.getMessage());
941             }
942         }
943         if (LOG.isDebugEnabled()) {
944             LOG.debug("Search Result size from OleOrderQueueDocument.filterOtherSearchCriteria after filtering - " + finalResult.size());
945             LOG.debug("Leaving filterOtherSearchCriteria of OleOrderQueueDocument");
946         }
947         return finalResult;
948     }
949 
950     protected Map<String, List<String>> preprocessDateFields() {
951         LOG.debug("Inside preprocessDateFields of OleOrderQueueDocument");
952         Map<String, List<String>> fieldsToUpdate = new HashMap<String, List<String>>();
953 
954         if (ObjectUtils.isNotNull(this.workflowStatusChangeDateFrom)) {
955             fieldsToUpdate.put(OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_FROM_DATE_LAST_MODIFIED, Collections.singletonList(convertTimestampToString(this.workflowStatusChangeDateFrom)));
956         } else {
957             fieldsToUpdate.put(OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_FROM_DATE_LAST_MODIFIED, Collections.singletonList(""));
958         }
959         if (ObjectUtils.isNotNull(this.workflowStatusChangeDateTo)) {
960             fieldsToUpdate.put(OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_TO_DATE_LAST_MODIFIED, Collections.singletonList(convertTimestampToString(this.workflowStatusChangeDateTo)));
961         }
962         if (isInitiatorOfREQS()) {
963             fieldsToUpdate.put(OleSelectConstant.AcquisitionsSearch.INITIATOR, Collections.singletonList(GlobalVariables.getUserSession().getPrincipalName()));
964         }
965         LOG.debug("Leaving preprocessDateFields of OleOrderQueueDocument");
966         return fieldsToUpdate;
967     }
968 
969     /**
970      * This method returns the true if the logined User has selector or super_selector role
971      *
972      * @return boolean
973      */
974     public boolean isInitiatorOfREQS() {
975         boolean hasPermission = true;
976         RoleService roleService = SpringContext.getBean(RoleService.class);
977         List roleIds = new ArrayList<String>();
978         String nameSpaceCode = OLEConstants.OleRequisition.REQUISITION_NAMESPACE;
979         hasPermission = SpringContext.getBean(IdentityManagementService.class).hasPermission(GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode,
980                 OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_ASSIGN_OWN_REQ);
981         if (hasPermission) {
982             String roleId = roleService.getRoleIdByNamespaceCodeAndName(nameSpaceCode, OLEConstants.OrderQueue.OLE_SUPER_SELECTOR);
983             roleIds.add(roleId);
984             if (roleService.principalHasRole(GlobalVariables.getUserSession().getPerson().getPrincipalId(), roleIds, null)) {
985                 hasPermission = false;
986             }
987         }
988         return hasPermission;
989     }
990 
991     /**
992      * This method returns true if the selector is in the document's route log.
993      *
994      * @param item     Document containing this item will be validated for the selector.
995      * @param selector Principal Id to be checked against the requisition document.
996      * @return If the requisition item is valid to be returned with the search result.
997      */
998     public boolean selectorLookup(OleRequisitionItem item, String selector) {
999         LOG.debug("Inside selectorLookup of OleRequisitionItemLookupableHelperServiceImpl");
1000         boolean isValid = false;
1001         WorkflowDocumentService workflowDocumentService = KRADServiceLocatorWeb.getWorkflowDocumentService();
1002         Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
1003         WorkflowDocument workflowDocument;
1004         try {
1005             workflowDocument = workflowDocumentService.createWorkflowDocument(item.getRequisition().getDocumentHeader().getWorkflowDocument().getDocumentTypeName(), principalPerson);
1006             // Modified for OLE - 2541 starts
1007             Principal principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(selector);
1008             List actionRequests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByDocumentId(
1009                     item.getRequisition().getDocumentNumber());
1010             if (actionRequestListHasPrincipal(principal, actionRequests)) {
1011                 isValid = true;
1012             }
1013             // Modified for OLE - 2541 ends
1014             // isValid = SpringContext.getBean(WorkflowDocumentService.class).isUserAuthenticatedByRouteLog(workflowDocument.getRouteHeaderId(), selector, true);
1015         } catch (WorkflowException wfe) {
1016             LOG.error("Workflow exception in selectorLookup :" + wfe.getMessage());
1017         }
1018         LOG.debug("Leaving selectorLookup of OleRequisitionItemLookupableHelperServiceImpl");
1019         return isValid;
1020     }
1021 
1022     // Modified for OLE - 2541
1023     private boolean actionRequestListHasPrincipal(Principal principal, List actionRequests) throws WorkflowException {
1024         for (Iterator iter = actionRequests.iterator(); iter.hasNext(); ) {
1025             ActionRequestValue actionRequest = (ActionRequestValue) iter.next();
1026             if (actionRequest.isRecipientRoutedRequest(new KimPrincipalRecipient(principal))) {
1027                 return true;
1028             }
1029         }
1030         return false;
1031     }
1032 
1033     /**
1034      * This method filters search results from OleRequisitionItem search based on workflow status change from/to date.
1035      *
1036      * @param searchResults   Search Result list from Requisition Item Lookup.
1037      * @param fixedParameters Map containing workflow status change From/To date search criteria.
1038      * @return Map containing document number and workflow status modified date for searchResults
1039      *         that passed the search criteria.
1040      */
1041     public Map<String, Timestamp> filterWorkflowStatusDate(List searchResults, Map<String, List<String>> fixedParameters) {
1042         DocumentSearchCriteria.Builder criteria = DocumentSearchCriteria.Builder.create();
1043         criteria.setDocumentAttributeValues(fixedParameters);
1044         DateTime dateTimeFrom = new DateTime(workflowStatusChangeDateFrom);
1045         DateTime dateTimeTo = new DateTime(workflowStatusChangeDateTo);
1046         criteria.setDateApplicationDocumentStatusChangedTo(dateTimeTo);
1047         if (workflowStatusChangeDateFrom == null && workflowStatusChangeDateTo != null) {
1048             criteria.setDateApplicationDocumentStatusChangedFrom(null);
1049         } else {
1050             criteria.setDateApplicationDocumentStatusChangedFrom(dateTimeFrom);
1051         }
1052         HashMap<String, Timestamp> map = new HashMap<String, Timestamp>();
1053         try {
1054             DocumentSearchResults components = KewApiServiceLocator.getWorkflowDocumentService().documentSearch(GlobalVariables.getUserSession().getPrincipalId(), criteria.build());
1055             List<DocumentSearchResult> docSearchResults = components.getSearchResults();
1056             for (DocumentSearchResult docSearchResult : docSearchResults) {
1057                 map.put(docSearchResult.getDocument().getDocumentId(), new Timestamp(docSearchResult.getDocument()
1058                         .getApplicationDocumentStatusDate().getMillis()));
1059             }
1060         } catch (WorkflowServiceErrorException wsee) {
1061             for (WorkflowServiceError workflowServiceError : (List<WorkflowServiceError>) wsee.getServiceErrors()) {
1062                 if (workflowServiceError.getMessageMap() != null && workflowServiceError.getMessageMap().hasErrors()) {
1063                     // merge the message maps
1064                     GlobalVariables.getMessageMap().merge(workflowServiceError.getMessageMap());
1065                 } else {
1066                     //TODO: can we add something to this to get it to highlight the right field too?  Maybe in arg1
1067                     GlobalVariables.getMessageMap().putError(workflowServiceError.getMessage(), RiceKeyConstants.ERROR_CUSTOM, workflowServiceError.getMessage());
1068                 }
1069             }
1070             ;
1071         } catch (Exception ex) {
1072             GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, RiceKeyConstants.ERROR_CUSTOM, ex.getMessage());
1073             LOG.error("Error filtering search results", ex);
1074         }
1075         return map;
1076     }
1077 
1078     /**
1079      * This method populates workflow status change date for a requisition item.
1080      *
1081      * @param item Requisition Item to populate workflow status date.
1082      * @return
1083      */
1084     public void populateWorkflowStatusDate(OleRequisitionItem item) {
1085         LOG.debug("Inside populateWorkflowStatusDate of OleRequisitionItemLookupableHelperServiceImpl");
1086         Long documentNumber = Long.valueOf(item.getRequisition().getDocumentNumber());
1087         WorkflowDocumentService workflowDocumentService = SpringContext.getBean(WorkflowDocumentService.class);
1088         Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
1089         WorkflowDocument workflowDocument;
1090         try {
1091             workflowDocument = workflowDocumentService.loadWorkflowDocument(item.getRequisition().getDocumentNumber(), principalPerson);
1092             item.setDateModified(convertTimestampToString(new Timestamp(workflowDocument
1093                     .getApplicationDocumentStatusDate().getMillis())));
1094         } catch (WorkflowException ex) {
1095             GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, RiceKeyConstants.ERROR_CUSTOM, ex.getMessage());
1096         }
1097         LOG.debug("Leaving populateWorkflowStatusDate of OleRequisitionItemLookupableHelperServiceImpl");
1098     }
1099 
1100     /**
1101      * This method converts specified timestamp to String
1102      *
1103      * @param dateTime
1104      * @return
1105      */
1106     public String convertTimestampToString(Timestamp timestamp) {
1107         LOG.debug("Inside convertTimestampToString of OleRequisitionItemLookupableHelperServiceImpl");
1108         String dateString = null;
1109         if (ObjectUtils.isNotNull(timestamp)) {
1110             try {
1111                 DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
1112                 java.sql.Date date = dateTimeService.convertToSqlDate(timestamp);
1113                 dateString = dateTimeService.toDateString(date);
1114             } catch (ParseException exception) {
1115                 GlobalVariables.getMessageMap().putError(OLEConstants.OrderQueue.REQUISITIONS, RiceKeyConstants.ERROR_CUSTOM, exception.getMessage());
1116             }
1117         }
1118         LOG.debug("Leaving convertTimestampToString of OleRequisitionItemLookupableHelperServiceImpl");
1119         return dateString;
1120     }
1121    /* /**
1122      * Gets the selectorRoleName attribute.
1123      * @return Returns the selectorRoleName.
1124      *//*
1125     public String getSelectorRoleName() {
1126         return selectorRoleName;
1127     }
1128     /**
1129      * Sets the selectorRoleName attribute value.
1130      * @param selectorRoleName The selectorRoleName to set.
1131      *//*
1132     public void setSelectorRoleName(String selectorRoleName) {
1133         this.selectorRoleName = selectorRoleName;
1134     }*/
1135 
1136 }
1137