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("endDate", payEndDate);
59 crit.addEqualTo("beginDate", 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("endDate", 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("beginDate", 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, Date payEndDate) {
96 Criteria crit = new Criteria();
97 List<TimesheetDocumentHeader> lstDocumentHeaders = new ArrayList<TimesheetDocumentHeader>();
98
99 crit.addEqualTo("endDate", payEndDate);
100 crit.addEqualTo("beginDate", payBeginDate);
101 QueryByCriteria query = new QueryByCriteria(TimesheetDocumentHeader.class, crit);
102 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
103 if (c != null) {
104 lstDocumentHeaders.addAll(c);
105 }
106
107 return lstDocumentHeaders;
108 }
109
110 public List<TimesheetDocumentHeader> getDocumentHeadersForPrincipalId(String principalId) {
111 Criteria crit = new Criteria();
112 List<TimesheetDocumentHeader> lstDocumentHeaders = new ArrayList<TimesheetDocumentHeader>();
113
114 crit.addEqualTo("principalId", principalId);
115 QueryByCriteria query = new QueryByCriteria(TimesheetDocumentHeader.class, crit);
116 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
117 if (c != null) {
118 lstDocumentHeaders.addAll(c);
119 }
120 return lstDocumentHeaders;
121 }
122
123 public List<TimesheetDocumentHeader> getDocumentHeadersForYear(String principalId, String year) {
124 Criteria crit = new Criteria();
125 List<TimesheetDocumentHeader> lstDocumentHeaders = new ArrayList<TimesheetDocumentHeader>();
126
127 try {
128 crit.addEqualTo("principalId", principalId);
129 DateFormat df = new SimpleDateFormat("yyyy");
130 java.util.Date cYear = df.parse(year);
131 String nextYear = Integer.toString((Integer.parseInt(year) + 1));
132 java.util.Date nYear = df.parse(nextYear);
133
134 crit.addGreaterOrEqualThan("beginDate", cYear);
135 crit.addLessThan("beginDate", nYear );
136 QueryByCriteria query = new QueryByCriteria(TimesheetDocumentHeader.class, crit);
137 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
138 if (c != null) {
139 lstDocumentHeaders.addAll(c);
140 }
141 } catch (ParseException e) {
142
143 e.printStackTrace();
144 }
145 return lstDocumentHeaders;
146 }
147
148 public TimesheetDocumentHeader getDocumentHeaderForDate(String principalId, Date asOfDate) {
149 Criteria crit = new Criteria();
150 crit.addEqualTo("principalId", principalId);
151 crit.addLessOrEqualThan("beginDate", asOfDate);
152 crit.addGreaterOrEqualThan("endDate", asOfDate);
153
154 QueryByCriteria query = new QueryByCriteria(TimesheetDocumentHeader.class, crit);
155
156 return (TimesheetDocumentHeader) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
157 }
158 }