1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.leave.block.dao;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.Collections;
21 import java.util.List;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.log4j.Logger;
25 import org.apache.ojb.broker.query.Criteria;
26 import org.apache.ojb.broker.query.Query;
27 import org.apache.ojb.broker.query.QueryFactory;
28 import org.joda.time.LocalDate;
29 import org.kuali.kpme.core.util.HrConstants;
30 import org.kuali.kpme.tklm.common.LMConstants;
31 import org.kuali.kpme.tklm.leave.block.LeaveBlock;
32 import org.kuali.kpme.tklm.leave.block.LeaveBlockHistory;
33 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
34 import org.kuali.kpme.tklm.time.workflow.TimesheetDocumentHeader;
35 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
36
37 public class LeaveBlockHistoryDaoOjbImpl extends PlatformAwareDaoBaseOjb implements LeaveBlockHistoryDao {
38
39 @SuppressWarnings("unused")
40 private static final Logger LOG = Logger
41 .getLogger(LeaveBlockHistoryDaoOjbImpl.class);
42
43 @Override
44 public void saveOrUpdate(LeaveBlockHistory leaveBlockHistory) {
45 this.getPersistenceBrokerTemplate().store(leaveBlockHistory);
46 }
47
48 @Override
49 public void saveOrUpdate(List<LeaveBlockHistory> leaveBlockHistoryList) {
50 if (leaveBlockHistoryList != null) {
51 for (LeaveBlockHistory leaveBlockHistory : leaveBlockHistoryList) {
52 this.getPersistenceBrokerTemplate().store(leaveBlockHistory);
53 }
54
55 }
56 }
57
58 @Override
59 public List<LeaveBlockHistory> getLeaveBlockHistoryByLmLeaveBlockId(
60 String lmLeaveBlockId) {
61 Criteria recordCriteria = new Criteria();
62 recordCriteria.addEqualTo("lmLeaveBlockId", lmLeaveBlockId);
63 Query query = QueryFactory.newQuery(LeaveBlockHistory.class,
64 recordCriteria);
65 return (List<LeaveBlockHistory>) this.getPersistenceBrokerTemplate()
66 .getCollectionByQuery(query);
67 }
68
69 @Override
70 public List<LeaveBlockHistory> getLeaveBlockHistories(String principalId,
71 List<String> requestStatus) {
72 Criteria recordCriteria = new Criteria();
73 recordCriteria.addEqualTo("principalId", principalId);
74 if (requestStatus != null) {
75 recordCriteria.addIn("requestStatus", requestStatus);
76 }
77 Query query = QueryFactory.newQuery(LeaveBlockHistory.class,
78 recordCriteria);
79 return (List<LeaveBlockHistory>) this.getPersistenceBrokerTemplate()
80 .getCollectionByQuery(query);
81 }
82
83 @Override
84 public List<LeaveBlockHistory> getLeaveBlockHistories(String principalId,String requestStatus, String action, LocalDate currentDate) {
85 Criteria recordCriteria = new Criteria();
86 recordCriteria.addEqualTo("principalId", principalId);
87 if (requestStatus != null) {
88 recordCriteria.addEqualTo("requestStatus", requestStatus);
89 }
90 if(currentDate != null) {
91 recordCriteria.addGreaterThan("leaveDate", currentDate.toDate());
92 }
93 if(action != null) {
94 recordCriteria.addEqualTo("action", action);
95 }
96 Query query = QueryFactory.newQuery(LeaveBlockHistory.class,
97 recordCriteria);
98 return (List<LeaveBlockHistory>) this.getPersistenceBrokerTemplate()
99 .getCollectionByQuery(query);
100 }
101
102 @Override
103 public List<LeaveBlockHistory> getLeaveBlockHistoriesForLeaveDisplay(String principalId,
104 LocalDate beginDate, LocalDate endDate, boolean considerModifiedUser) {
105
106 List<LeaveBlockHistory> leaveBlockHistories = new ArrayList<LeaveBlockHistory>();
107
108 Criteria root = new Criteria();
109 root.addEqualTo("principalId", principalId);
110 root.addGreaterOrEqualThan("leaveDate", beginDate.toDate());
111 root.addLessOrEqualThan("leaveDate", endDate.toDate());
112 root.addEqualTo("action",HrConstants.ACTION.MODIFIED);
113 if(considerModifiedUser) {
114 root.addNotEqualTo("principalIdModified", principalId);
115 }
116
117 Criteria root1 = new Criteria();
118 root1.addEqualTo("principalId", principalId);
119 root1.addGreaterOrEqualThan("leaveDate", beginDate.toDate());
120 root1.addLessOrEqualThan("leaveDate", endDate.toDate());
121 root1.addEqualTo("action",HrConstants.ACTION.DELETE);
122 if(considerModifiedUser) {
123 root1.addNotEqualTo("principalIdDeleted", principalId);
124 }
125
126 root.addOrCriteria(root1);
127
128 Query query = QueryFactory.newQuery(LeaveBlockHistory.class, root);
129 Collection c = this.getPersistenceBrokerTemplate()
130 .getCollectionByQuery(query);
131
132 if (c != null) {
133 leaveBlockHistories.addAll(c);
134 }
135 return leaveBlockHistories;
136 }
137
138 @Override
139 public List<LeaveBlockHistory> getLeaveBlockHistoriesForLookup(String documentId,
140 String principalId, String userPrincipalId, LocalDate fromDate,
141 LocalDate toDate) {
142 List<LeaveBlockHistory> leaveBlocks = new ArrayList<LeaveBlockHistory>();
143 Criteria criteria = new Criteria();
144
145
146
147 if (StringUtils.isNotBlank(documentId)) {
148 TimesheetDocumentHeader tsdh = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeader(documentId);
149 if (tsdh == null) {
150 return Collections.emptyList();
151 }
152 criteria.addGreaterOrEqualThan("beginTimestamp", tsdh.getBeginDate());
153 criteria.addLessOrEqualThan("endTimestamp",tsdh.getEndDate());
154 criteria.addEqualTo("principalId", tsdh.getPrincipalId());
155 }
156
157
158 if(fromDate != null) {
159 criteria.addGreaterOrEqualThan("beginTimestamp", fromDate.toDate());
160 }
161 if(toDate != null) {
162 criteria.addLessOrEqualThan("endTimestamp",toDate.toDate());
163 }
164 if(StringUtils.isNotBlank(principalId)) {
165 criteria.addEqualTo("principalId", principalId);
166 }
167 if(StringUtils.isNotBlank(userPrincipalId)) {
168 criteria.addEqualTo("principalIdModified", userPrincipalId);
169 }
170 criteria.addEqualTo("leaveBlockType",LMConstants.LEAVE_BLOCK_TYPE.TIME_CALENDAR);
171 Query query = QueryFactory.newQuery(LeaveBlockHistory.class, criteria);
172 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
173 if (c != null) {
174 leaveBlocks.addAll(c);
175 }
176 return leaveBlocks;
177 }
178 @Override
179 public List<LeaveBlockHistory> getLeaveBlockHistoriesForLookup(String documentId,
180 String principalId, String userPrincipalId, LocalDate fromDate,
181 LocalDate toDate, String leaveBlockType) {
182 List<LeaveBlockHistory> leaveBlocks = new ArrayList<LeaveBlockHistory>();
183 Criteria criteria = new Criteria();
184
185
186
187 if (StringUtils.isNotBlank(documentId)) {
188 TimesheetDocumentHeader tsdh = TkServiceLocator.getTimesheetDocumentHeaderService().getDocumentHeader(documentId);
189 if (tsdh == null) {
190 return Collections.emptyList();
191 }
192 criteria.addGreaterOrEqualThan("beginTimestamp", tsdh.getBeginDate());
193 criteria.addLessOrEqualThan("endTimestamp",tsdh.getEndDate());
194 criteria.addEqualTo("principalId", tsdh.getPrincipalId());
195 }
196
197
198 if(fromDate != null) {
199 criteria.addGreaterOrEqualThan("beginTimestamp", fromDate.toDate());
200 }
201 if(toDate != null) {
202 criteria.addLessOrEqualThan("endTimestamp",toDate.toDate());
203 }
204 if(StringUtils.isNotBlank(principalId)) {
205 criteria.addEqualTo("principalId", principalId);
206 }
207 if(StringUtils.isNotBlank(userPrincipalId)) {
208 criteria.addEqualTo("principalIdModified", userPrincipalId);
209 }
210 criteria.addEqualTo("leaveBlockType",leaveBlockType);
211 Query query = QueryFactory.newQuery(LeaveBlockHistory.class, criteria);
212 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
213 if (c != null) {
214 leaveBlocks.addAll(c);
215 }
216 return leaveBlocks;
217 }
218 }