View Javadoc

1   /**
2    * Copyright 2004-2013 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.hr.time.timeblock.service;
17  
18  import java.util.Collections;
19  import java.util.Comparator;
20  import java.util.Iterator;
21  import java.util.List;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.kuali.hr.time.timeblock.TimeBlockHistory;
25  import org.kuali.rice.krad.bo.BusinessObject;
26  
27  public class TimeBlockHistoryLookupableHelperServiceImpl extends TimeBlockLookupableHelperServiceImpl {
28  
29      /**
30       *
31       */
32      private static final long serialVersionUID = 1L;
33  
34      @SuppressWarnings("unchecked")
35  	@Override
36      public List<? extends BusinessObject> getSearchResults(java.util.Map<String, String> fieldValues) {
37  
38          String docStatus = "", beginDateString = "";
39  
40          if (fieldValues.containsKey(DOC_STATUS_ID)) {
41              docStatus = fieldValues.get(DOC_STATUS_ID);
42              fieldValues.remove(DOC_STATUS_ID);
43          }
44          if (fieldValues.containsKey(BEGIN_DATE_ID)) {
45              beginDateString = fieldValues.get(BEGIN_DATE_ID);
46              fieldValues.remove(BEGIN_DATE_ID);
47          }
48          List<TimeBlockHistory> objectList = (List<TimeBlockHistory>) super.getSearchResults(fieldValues);
49  
50          if (!objectList.isEmpty()) {
51              Iterator<TimeBlockHistory> itr = objectList.iterator();
52              while (itr.hasNext()) {
53                  TimeBlockHistory tb = itr.next();
54  
55                  if (StringUtils.isNotEmpty(docStatus)) {
56                      if (tb.getTimesheetDocumentHeader() == null) {
57                          itr.remove();
58                          continue;
59                      } else {
60                          if (tb.getTimesheetDocumentHeader().getDocumentStatus() != null) {
61                              if (!tb.getTimesheetDocumentHeader().getDocumentStatus().equals(docStatus)) {
62                                  itr.remove();
63                                  continue;
64                              }
65                          } else {
66                              itr.remove();
67                              continue;
68                          }
69                      }
70                  }
71                  if(StringUtils.isNotEmpty(beginDateString)) {
72  					if(tb.getBeginDate() != null) {
73  						if(!this.checkDate(tb, tb.getBeginDate(), beginDateString)) {
74  							itr.remove();
75  							continue;
76  						} 
77  					} else {
78  						itr.remove();
79  						continue;
80  					}
81  				}
82              }
83          }
84  
85          sortByTimeBlockId(objectList);
86  
87          return objectList;
88      }
89  
90      private void sortByTimeBlockId(List<TimeBlockHistory> objectList) {
91          Collections.sort(objectList, new Comparator<TimeBlockHistory>() { // Sort the Time Blocks
92              @Override
93              public int compare(TimeBlockHistory timeBlockHistory, TimeBlockHistory timeBlockHistory1) {
94                  return timeBlockHistory.getTkTimeBlockId().compareTo(timeBlockHistory1.getTkTimeBlockId());
95              }
96          });
97      }
98  }