1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.clocklog.dao;
17
18 import java.util.List;
19
20 import org.apache.log4j.Logger;
21 import org.apache.ojb.broker.query.Criteria;
22 import org.apache.ojb.broker.query.Query;
23 import org.apache.ojb.broker.query.QueryFactory;
24 import org.apache.ojb.broker.query.ReportQueryByCriteria;
25 import org.kuali.hr.time.calendar.CalendarEntries;
26 import org.kuali.hr.time.clocklog.ClockLog;
27 import org.kuali.hr.time.timeblock.TimeBlock;
28 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
29
30 public class ClockLogDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements ClockLogDao {
31
32 private static final Logger LOG = Logger.getLogger(ClockLogDaoSpringOjbImpl.class);
33
34 public void saveOrUpdate(ClockLog clockLog) {
35 this.getPersistenceBrokerTemplate().store(clockLog);
36 }
37
38 public void saveOrUpdate(List<ClockLog> clockLogList) {
39 if (clockLogList != null) {
40 for (ClockLog clockLog : clockLogList) {
41 this.getPersistenceBrokerTemplate().store(clockLog);
42 }
43 }
44 }
45
46 public ClockLog getClockLog(String tkClockLogId){
47 Criteria crit = new Criteria();
48 crit.addEqualTo("tkClockLogId", tkClockLogId);
49 Query query = QueryFactory.newQuery(ClockLog.class, crit);
50 return (ClockLog)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
51 }
52
53 public ClockLog getLastClockLog(String principalId){
54 Criteria currentRecordCriteria = new Criteria();
55 currentRecordCriteria.addEqualTo("principalId", principalId);
56
57 Criteria clockTimeJoinCriteria = new Criteria();
58 clockTimeJoinCriteria.addEqualToField("principalId",Criteria.PARENT_QUERY_PREFIX +"principalId");
59
60 ReportQueryByCriteria clockTimeSubQuery = QueryFactory.newReportQuery(ClockLog.class, clockTimeJoinCriteria);
61 clockTimeSubQuery.setAttributes(new String[]{"max(clockTimestamp)"});
62
63 currentRecordCriteria.addEqualTo("clockTimestamp", clockTimeSubQuery);
64
65 Criteria timestampJoinCriteria = new Criteria();
66 timestampJoinCriteria.addEqualToField("principalId", Criteria.PARENT_QUERY_PREFIX + "principalId");
67 timestampJoinCriteria.addEqualToField("clockTimestamp", Criteria.PARENT_QUERY_PREFIX + "clockTimestamp");
68
69 ReportQueryByCriteria timeStampSubQuery = QueryFactory.newReportQuery(ClockLog.class, timestampJoinCriteria);
70 timeStampSubQuery.setAttributes(new String[]{"max(timestamp)"});
71
72 currentRecordCriteria.addEqualTo("timestamp", timeStampSubQuery);
73
74 return (ClockLog)this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(ClockLog.class,currentRecordCriteria));
75 }
76
77 @Override
78 public ClockLog getLastClockLog(String principalId, String clockAction){
79 Criteria currentRecordCriteria = new Criteria();
80 currentRecordCriteria.addEqualTo("principalId", principalId);
81 currentRecordCriteria.addEqualTo("clockAction", clockAction);
82
83 Criteria clockTimeJoinCriteria = new Criteria();
84 clockTimeJoinCriteria.addEqualToField("principalId",Criteria.PARENT_QUERY_PREFIX +"principalId");
85 clockTimeJoinCriteria.addEqualToField("clockAction",Criteria.PARENT_QUERY_PREFIX +"clockAction");
86
87 ReportQueryByCriteria clockTimeSubQuery = QueryFactory.newReportQuery(ClockLog.class, clockTimeJoinCriteria);
88 clockTimeSubQuery.setAttributes(new String[]{"max(clockTimestamp)"});
89
90 currentRecordCriteria.addEqualTo("clockTimestamp", clockTimeSubQuery);
91
92 Criteria timestampJoinCriteria = new Criteria();
93 timestampJoinCriteria.addEqualToField("principalId", Criteria.PARENT_QUERY_PREFIX + "principalId");
94 timestampJoinCriteria.addEqualToField("clockAction", Criteria.PARENT_QUERY_PREFIX + "clockAction");
95 timestampJoinCriteria.addEqualToField("clockTimestamp", Criteria.PARENT_QUERY_PREFIX + "clockTimestamp");
96
97 ReportQueryByCriteria timeStampSubQuery = QueryFactory.newReportQuery(ClockLog.class, timestampJoinCriteria);
98 timeStampSubQuery.setAttributes(new String[]{"max(timestamp)"});
99
100 currentRecordCriteria.addEqualTo("timestamp", timeStampSubQuery);
101
102 return (ClockLog)this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(ClockLog.class,currentRecordCriteria));
103 }
104
105 @Override
106 public ClockLog getLastClockLog(String principalId, String jobNumber, String workArea, String task, CalendarEntries calendarEntry) {
107 Criteria criteria = new Criteria();
108 criteria.addEqualTo("principalId", principalId);
109 criteria.addEqualTo("jobNumber", jobNumber);
110 criteria.addEqualTo("workArea", workArea);
111 criteria.addEqualTo("task", task);
112
113 Criteria clockTimeJoinCriteria = new Criteria();
114 clockTimeJoinCriteria.addEqualToField("principalId", Criteria.PARENT_QUERY_PREFIX + "principalId");
115 clockTimeJoinCriteria.addEqualToField("jobNumber", Criteria.PARENT_QUERY_PREFIX + "jobNumber");
116 clockTimeJoinCriteria.addEqualToField("workArea", Criteria.PARENT_QUERY_PREFIX + "workArea");
117 clockTimeJoinCriteria.addEqualToField("task", Criteria.PARENT_QUERY_PREFIX + "task");
118 clockTimeJoinCriteria.addBetween("clockTimestamp", calendarEntry.getBeginPeriodDate(), calendarEntry.getEndPeriodDate());
119 ReportQueryByCriteria clockTimeSubQuery = QueryFactory.newReportQuery(ClockLog.class, clockTimeJoinCriteria);
120 clockTimeSubQuery.setAttributes(new String[]{"max(clockTimestamp)"});
121 criteria.addEqualTo("clockTimestamp", clockTimeSubQuery);
122
123 Criteria timestampJoinCriteria = new Criteria();
124 timestampJoinCriteria.addEqualToField("principalId", Criteria.PARENT_QUERY_PREFIX + "principalId");
125 timestampJoinCriteria.addEqualToField("jobNumber", Criteria.PARENT_QUERY_PREFIX + "jobNumber");
126 timestampJoinCriteria.addEqualToField("workArea", Criteria.PARENT_QUERY_PREFIX + "workArea");
127 timestampJoinCriteria.addEqualToField("task", Criteria.PARENT_QUERY_PREFIX + "task");
128 timestampJoinCriteria.addBetween("clockTimestamp", calendarEntry.getBeginPeriodDate(), calendarEntry.getEndPeriodDate());
129 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(ClockLog.class, timestampJoinCriteria);
130 timestampSubQuery.setAttributes(new String[]{"max(timestamp)"});
131 criteria.addEqualTo("timestamp", timestampSubQuery);
132
133 return (ClockLog) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(ClockLog.class, criteria));
134 }
135
136 @Override
137 public void deleteClockLogsForDocumentId(String documentId) {
138 Criteria crit = new Criteria();
139 crit.addEqualTo("documentId", documentId);
140 this.getPersistenceBrokerTemplate().deleteByQuery(QueryFactory.newQuery(ClockLog.class, crit));
141 }
142
143 @Override
144 public ClockLog getLastClockLog(String principalId, String jobNumber, String workArea, String task, String timesheetId) {
145 Criteria criteria = new Criteria();
146 criteria.addEqualTo("principalId", principalId);
147 criteria.addEqualTo("jobNumber", jobNumber);
148 criteria.addEqualTo("workArea", workArea);
149 criteria.addEqualTo("task", task);
150 criteria.addEqualTo("documentId", timesheetId);
151 Criteria clockTimeJoinCriteria = new Criteria();
152 clockTimeJoinCriteria.addEqualToField("principalId", Criteria.PARENT_QUERY_PREFIX + "principalId");
153 clockTimeJoinCriteria.addEqualToField("jobNumber", Criteria.PARENT_QUERY_PREFIX + "jobNumber");
154 clockTimeJoinCriteria.addEqualToField("workArea", Criteria.PARENT_QUERY_PREFIX + "workArea");
155 clockTimeJoinCriteria.addEqualToField("task", Criteria.PARENT_QUERY_PREFIX + "task");
156 clockTimeJoinCriteria.addEqualToField("documentId", Criteria.PARENT_QUERY_PREFIX + "documentId");
157 ReportQueryByCriteria clockTimeSubQuery = QueryFactory.newReportQuery(ClockLog.class, clockTimeJoinCriteria);
158 clockTimeSubQuery.setAttributes(new String[]{"max(clockTimestamp)"});
159 criteria.addEqualTo("clockTimestamp", clockTimeSubQuery);
160
161 Criteria timestampJoinCriteria = new Criteria();
162 timestampJoinCriteria.addEqualToField("principalId", Criteria.PARENT_QUERY_PREFIX + "principalId");
163 timestampJoinCriteria.addEqualToField("jobNumber", Criteria.PARENT_QUERY_PREFIX + "jobNumber");
164 timestampJoinCriteria.addEqualToField("workArea", Criteria.PARENT_QUERY_PREFIX + "workArea");
165 timestampJoinCriteria.addEqualToField("task", Criteria.PARENT_QUERY_PREFIX + "task");
166 timestampJoinCriteria.addEqualToField("documentId", Criteria.PARENT_QUERY_PREFIX + "documentId");
167 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(ClockLog.class, timestampJoinCriteria);
168 timestampSubQuery.setAttributes(new String[]{"max(timestamp)"});
169 criteria.addEqualTo("timestamp", timestampSubQuery);
170
171 return (ClockLog) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(ClockLog.class, criteria));
172 }
173
174 }