1
2
3
4
5
6
7
8
9
10
11
12
13
14
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>() {
92 @Override
93 public int compare(TimeBlockHistory timeBlockHistory, TimeBlockHistory timeBlockHistory1) {
94 return timeBlockHistory.getTkTimeBlockId().compareTo(timeBlockHistory1.getTkTimeBlockId());
95 }
96 });
97 }
98 }