1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.workflow.dao;
17
18 import java.text.DateFormat;
19 import java.text.ParseException;
20 import java.text.SimpleDateFormat;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Date;
24 import java.util.List;
25
26 import org.apache.ojb.broker.query.Criteria;
27 import org.apache.ojb.broker.query.QueryByCriteria;
28 import org.apache.ojb.broker.query.QueryFactory;
29 import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
30 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
31
32 public class TimesheetDocumentHeaderDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements TimesheetDocumentHeaderDao {
33
34 @Override
35 public TimesheetDocumentHeader getTimesheetDocumentHeader(String documentId) {
36 Criteria crit = new Criteria();
37 crit.addEqualTo("documentId", documentId);
38 return (TimesheetDocumentHeader) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(TimesheetDocumentHeader.class, crit));
39 }
40
41 @Override
42 public void saveOrUpdate(TimesheetDocumentHeader documentHeader) {
43 if (documentHeader != null) {
44 this.getPersistenceBrokerTemplate().store(documentHeader);
45 }
46 }
47
48 public void deleteTimesheetHeader(String documentId){
49 Criteria crit = new Criteria();
50 crit.addEqualTo("documentId", documentId);
51 this.getPersistenceBrokerTemplate().deleteByQuery(QueryFactory.newQuery(TimesheetDocumentHeader.class, crit));
52 }
53
54 @Override
55 public TimesheetDocumentHeader getTimesheetDocumentHeader(String principalId, Date payBeginDate, Date payEndDate) {
56 Criteria crit = new Criteria();
57 crit.addEqualTo("principalId", principalId);
58 crit.addEqualTo("payEndDate", payEndDate);
59 crit.addEqualTo("payBeginDate", payBeginDate);
60
61 return (TimesheetDocumentHeader) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(TimesheetDocumentHeader.class, crit));
62 }
63
64
65
66
67
68 public TimesheetDocumentHeader getPreviousDocumentHeader(String principalId, Date payBeginDate) {
69 Criteria crit = new Criteria();
70 crit.addEqualTo("principalId", principalId);
71
72 crit.addEqualTo("payEndDate", payBeginDate);
73 QueryByCriteria query = new QueryByCriteria(TimesheetDocumentHeader.class, crit);
74 query.addOrderByDescending("documentId");
75 query.setStartAtIndex(0);
76 query.setEndAtIndex(1);
77
78 return (TimesheetDocumentHeader) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
79 }
80
81 @Override
82 public TimesheetDocumentHeader getNextDocumentHeader(String principalId, Date payEndDate) {
83 Criteria crit = new Criteria();
84 crit.addEqualTo("principalId", principalId);
85
86 crit.addEqualTo("payBeginDate", payEndDate);
87 QueryByCriteria query = new QueryByCriteria(TimesheetDocumentHeader.class, crit);
88 query.setStartAtIndex(0);
89 query.setEndAtIndex(1);
90
91 return (TimesheetDocumentHeader) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
92 }
93
94 @Override
95 public List<TimesheetDocumentHeader> getDocumentHeaders(Date payBeginDate) {
96 Criteria crit = new Criteria();
97 List<TimesheetDocumentHeader> lstDocumentHeaders = new ArrayList<TimesheetDocumentHeader>();
98
99 crit.addEqualTo("payBeginDate", payBeginDate);
100 QueryByCriteria query = new QueryByCriteria(TimesheetDocumentHeader.class, crit);
101 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
102 if (c != null) {
103 lstDocumentHeaders.addAll(c);
104 }
105
106 return lstDocumentHeaders;
107 }
108
109 @Override
110 public List<TimesheetDocumentHeader> getDocumentHeaders(Date payBeginDate, Date payEndDate) {
111 Criteria crit = new Criteria();
112 List<TimesheetDocumentHeader> lstDocumentHeaders = new ArrayList<TimesheetDocumentHeader>();
113
114 crit.addEqualTo("payEndDate", payEndDate);
115 crit.addEqualTo("payBeginDate", payBeginDate);
116 QueryByCriteria query = new QueryByCriteria(TimesheetDocumentHeader.class, crit);
117 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
118 if (c != null) {
119 lstDocumentHeaders.addAll(c);
120 }
121
122 return lstDocumentHeaders;
123 }
124
125 public List<TimesheetDocumentHeader> getDocumentHeadersForPrincipalId(String principalId) {
126 Criteria crit = new Criteria();
127 List<TimesheetDocumentHeader> lstDocumentHeaders = new ArrayList<TimesheetDocumentHeader>();
128
129 crit.addEqualTo("principalId", principalId);
130 QueryByCriteria query = new QueryByCriteria(TimesheetDocumentHeader.class, crit);
131 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
132 if (c != null) {
133 lstDocumentHeaders.addAll(c);
134 }
135 return lstDocumentHeaders;
136 }
137
138 public List<TimesheetDocumentHeader> getDocumentHeadersForYear(String principalId, String year) {
139 Criteria crit = new Criteria();
140 List<TimesheetDocumentHeader> lstDocumentHeaders = new ArrayList<TimesheetDocumentHeader>();
141
142 try {
143 crit.addEqualTo("principalId", principalId);
144 DateFormat df = new SimpleDateFormat("yyyy");
145 java.util.Date cYear = df.parse(year);
146 String nextYear = Integer.toString((Integer.parseInt(year) + 1));
147 java.util.Date nYear = df.parse(nextYear);
148
149 crit.addGreaterOrEqualThan("payBeginDate", cYear);
150 crit.addLessThan("payBeginDate", nYear );
151 QueryByCriteria query = new QueryByCriteria(TimesheetDocumentHeader.class, crit);
152 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
153 if (c != null) {
154 lstDocumentHeaders.addAll(c);
155 }
156 } catch (ParseException e) {
157
158 e.printStackTrace();
159 }
160 return lstDocumentHeaders;
161 }
162
163 public TimesheetDocumentHeader getDocumentHeaderForDate(String principalId, Date asOfDate) {
164 Criteria crit = new Criteria();
165 crit.addEqualTo("principalId", principalId);
166 crit.addLessOrEqualThan("payBeginDate", asOfDate);
167 crit.addGreaterOrEqualThan("payEndDate", asOfDate);
168
169 QueryByCriteria query = new QueryByCriteria(TimesheetDocumentHeader.class, crit);
170
171 return (TimesheetDocumentHeader) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
172 }
173 }