View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.hr.time.calendar;
17  
18  import java.util.Date;
19  
20  import org.joda.time.DateTime;
21  import org.joda.time.LocalDate;
22  import org.joda.time.LocalDateTime;
23  import org.joda.time.LocalTime;
24  import org.kuali.hr.core.KPMEConstants;
25  import org.kuali.hr.time.service.base.TkServiceLocator;
26  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
27  
28  /**
29   * This class uses java.sql.Time and java.sql.Date because for each respective component
30   * we are only interested in a partial Date or Time, that is for example:
31   * <p/>
32   * 3:55 pm   (at any date)
33   * 6/22/2010 (at any time)
34   *
35   * Make sure you are aware of whether or not you need a Local Relative time or
36   * an absolute server time.
37   *
38   * Local Relative Time Methods: (Time/Date without Timezone)
39   *
40   * LocalDateTime : getBeginLocalDateTime()
41   * LocalDateTime : getEndLocalDateTime()
42   *
43   * Absolute Methods:
44   *
45   * java.util.Date : getEndPeriodDateTime()
46   * java.util.Date : getBeginPeriodDateTime()
47   *
48   */
49  public class CalendarEntries extends PersistableBusinessObjectBase implements Comparable<CalendarEntries>{
50  
51  	private static final long serialVersionUID = -1977756526579659122L;
52  
53  	public static final String CACHE_NAME = KPMEConstants.APPLICATION_NAMESPACE_CODE + "/" + "CalendarEntries";
54  
55      private String hrCalendarEntriesId;
56      private String hrCalendarId;
57      private String calendarName;
58  
59      private Date beginPeriodDateTime;
60      private Date endPeriodDateTime;
61      private Date batchInitiateDateTime;
62      private Date batchEndPayPeriodDateTime;
63      private Date batchEmployeeApprovalDateTime;
64      private Date batchSupervisorApprovalDateTime;
65  
66      private Calendar calendarObj;
67  
68      public String getHrCalendarId() {
69          calendarObj = TkServiceLocator.getCalendarService().getCalendarByGroup(this.getCalendarName());
70          if (calendarObj != null) {
71              this.setHrCalendarId(calendarObj.getHrCalendarId());
72          }
73          return hrCalendarId;
74      }
75  
76      public void setHrCalendarId(String hrCalendarId) {
77          this.hrCalendarId = hrCalendarId;
78      }
79  
80      public String getHrCalendarEntriesId() {
81  		return hrCalendarEntriesId;
82  	}
83  
84  	public void setHrCalendarEntriesId(String hrCalendarEntriesId) {
85  		this.hrCalendarEntriesId = hrCalendarEntriesId;
86  	}
87  
88  	public String getCalendarName() {
89  		return calendarName;
90  	}
91  
92  	public void setCalendarName(String calendarName) {
93  		this.calendarName = calendarName;
94  	}
95  	
96  	public Date getBeginPeriodDateTime() {
97          return beginPeriodDateTime;
98      }
99  
100     public void setBeginPeriodDateTime(Date beginPeriodDateTime) {
101         this.beginPeriodDateTime = beginPeriodDateTime;
102     }
103     
104     /**
105      * Provides the Begin Period time without timezone information, used for relative calculations.
106      *
107      * @return A LocalDateTime representation of the begin period date/time.
108      */
109     public LocalDateTime getBeginLocalDateTime() {
110         return new DateTime(beginPeriodDateTime).toLocalDateTime();
111     }
112 
113     public java.sql.Date getBeginPeriodDate() {
114     	java.sql.Date beginPeriodDate = null;
115     	
116     	if (beginPeriodDateTime != null) {
117     		beginPeriodDate = new java.sql.Date(beginPeriodDateTime.getTime());
118     	}
119     	
120     	return beginPeriodDate;
121     }
122     
123     public void setBeginPeriodDate(java.sql.Date beginPeriodDate) {
124     	DateTime dateTime = new DateTime(beginPeriodDateTime);
125     	LocalDate localDate = new LocalDate(beginPeriodDate);
126     	LocalTime localTime = new LocalTime(beginPeriodDateTime);
127     	beginPeriodDateTime = localDate.toDateTime(localTime, dateTime.getZone()).toDate();
128     }
129     
130     public java.sql.Time getBeginPeriodTime() {
131     	java.sql.Time beginPeriodTime = null;
132     	
133     	if (beginPeriodDateTime != null) {
134     		beginPeriodTime = new java.sql.Time(beginPeriodDateTime.getTime());
135     	}
136     	
137     	return beginPeriodTime;
138     }
139     
140     public void setBeginPeriodTime(java.sql.Time beginPeriodTime) {
141     	DateTime dateTime = new DateTime(beginPeriodDateTime);
142     	LocalDate localDate = new LocalDate(beginPeriodDateTime);
143     	LocalTime localTime = new LocalTime(beginPeriodTime);
144     	beginPeriodDateTime = localDate.toDateTime(localTime, dateTime.getZone()).toDate();
145     }
146     
147     public java.util.Date getEndPeriodDateTime() {
148         return endPeriodDateTime;
149     }
150 
151     public void setEndPeriodDateTime(Date endPeriodDateTime) {
152         this.endPeriodDateTime = endPeriodDateTime;
153     }
154 
155     /**
156      * Provides the End Period time without timezone information, used for relative calculations.
157      *
158      * @return A LocalDateTime representation of the end period date/time.
159      */
160     public LocalDateTime getEndLocalDateTime() {
161         return new DateTime(endPeriodDateTime).toLocalDateTime();
162     }
163 
164     public java.sql.Date getEndPeriodDate() {
165     	java.sql.Date endPeriodDate = null;
166     	
167     	if (endPeriodDateTime != null) {
168     		endPeriodDate = new java.sql.Date(endPeriodDateTime.getTime());
169     	}
170     	
171     	return endPeriodDate;
172     }
173     
174     public void setEndPeriodDate(java.sql.Date endPeriodDate) {
175     	DateTime dateTime = new DateTime(endPeriodDateTime);
176     	LocalDate localDate = new LocalDate(endPeriodDate);
177     	LocalTime localTime = new LocalTime(endPeriodDateTime);
178     	endPeriodDateTime = localDate.toDateTime(localTime, dateTime.getZone()).toDate();
179     }
180 
181     public java.sql.Time getEndPeriodTime() {
182     	java.sql.Time endPeriodTime = null;
183     	
184     	if (endPeriodDateTime != null) {
185     		endPeriodTime = new java.sql.Time(endPeriodDateTime.getTime());
186     	}
187     	
188     	return endPeriodTime;
189     }
190     
191     public void setEndPeriodTime(java.sql.Time endPeriodDate) {
192     	DateTime dateTime = new DateTime(endPeriodDateTime);
193     	LocalDate localDate = new LocalDate(endPeriodDateTime);
194     	LocalTime localTime = new LocalTime(endPeriodDate);
195     	endPeriodDateTime = localDate.toDateTime(localTime, dateTime.getZone()).toDate();
196     }
197 
198     public Date getBatchInitiateDateTime() {
199         return batchInitiateDateTime;
200     }
201     
202     public void setBatchInitiateDateTime(Date batchInitiateDateTime) {
203         this.batchInitiateDateTime = batchInitiateDateTime;
204     }
205     
206     public java.sql.Date getBatchInitiateDate() {
207     	java.sql.Date batchInitiateDate = null;
208     	
209     	if (batchInitiateDateTime != null) {
210     		batchInitiateDate = new java.sql.Date(batchInitiateDateTime.getTime());
211     	}
212     	
213     	return batchInitiateDate;
214     }
215     
216     public void setBatchInitiateDate(java.sql.Date batchInitiateDate) {
217     	DateTime dateTime = new DateTime(batchInitiateDateTime);
218     	LocalDate localDate = new LocalDate(batchInitiateDate);
219     	LocalTime localTime = new LocalTime(batchInitiateDateTime);
220     	batchInitiateDateTime = localDate.toDateTime(localTime, dateTime.getZone()).toDate();
221     }
222 
223     public java.sql.Time getBatchInitiateTime() {
224     	java.sql.Time batchInitiateTime = null;
225     	
226     	if (batchInitiateDateTime != null) {
227     		batchInitiateTime = new java.sql.Time(batchInitiateDateTime.getTime());
228     	}
229     	
230     	return batchInitiateTime;
231     }
232     
233     public void setBatchInitiateTime(java.sql.Time batchInitiateDate) {
234     	DateTime dateTime = new DateTime(batchInitiateDateTime);
235     	LocalDate localDate = new LocalDate(batchInitiateDateTime);
236     	LocalTime localTime = new LocalTime(batchInitiateDate);
237     	batchInitiateDateTime = localDate.toDateTime(localTime, dateTime.getZone()).toDate();
238     }
239 
240     public Date getBatchEndPayPeriodDateTime() {
241         return batchEndPayPeriodDateTime;
242     }
243 
244     public void setBatchEndPayPeriodDateTime(Date batchEndPayPeriodDateTime) {
245         this.batchEndPayPeriodDateTime = batchEndPayPeriodDateTime;
246     }
247     
248     public java.sql.Date getBatchEndPayPeriodDate() {
249     	java.sql.Date batchEndPayPeriodDate = null;
250     	
251     	if (batchEndPayPeriodDateTime != null) {
252     		batchEndPayPeriodDate = new java.sql.Date(batchEndPayPeriodDateTime.getTime());
253     	}
254     	
255     	return batchEndPayPeriodDate;
256     }
257     
258     public void setBatchEndPayPeriodDate(java.sql.Date batchEndPayPeriodDate) {
259     	DateTime dateTime = new DateTime(batchEndPayPeriodDateTime);
260     	LocalDate localDate = new LocalDate(batchEndPayPeriodDate);
261     	LocalTime localTime = new LocalTime(batchEndPayPeriodDateTime);
262     	batchEndPayPeriodDateTime = localDate.toDateTime(localTime, dateTime.getZone()).toDate();
263     }
264 
265     public java.sql.Time getBatchEndPayPeriodTime() {
266     	java.sql.Time batchEndPayPeriodTime = null;
267     	
268     	if (batchEndPayPeriodDateTime != null) {
269     		batchEndPayPeriodTime = new java.sql.Time(batchEndPayPeriodDateTime.getTime());
270     	}
271     	
272     	return batchEndPayPeriodTime;
273     }
274     
275     public void setBatchEndPayPeriodTime(java.sql.Time batchEndPayPeriodDate) {
276     	DateTime dateTime = new DateTime(batchEndPayPeriodDateTime);
277     	LocalDate localDate = new LocalDate(batchEndPayPeriodDateTime);
278     	LocalTime localTime = new LocalTime(batchEndPayPeriodDate);
279     	batchEndPayPeriodDateTime = localDate.toDateTime(localTime, dateTime.getZone()).toDate();
280     }
281 
282     public Date getBatchEmployeeApprovalDateTime() {
283         return batchEmployeeApprovalDateTime;
284     }
285 
286     public void setBatchEmployeeApprovalDateTime(Date batchEmployeeApprovalDateTime) {
287         this.batchEmployeeApprovalDateTime = batchEmployeeApprovalDateTime;
288     }
289     
290     public java.sql.Date getBatchEmployeeApprovalDate() {
291     	java.sql.Date batchEmployeeApprovalDate = null;
292     	
293     	if (batchEmployeeApprovalDateTime != null) {
294     		batchEmployeeApprovalDate = new java.sql.Date(batchEmployeeApprovalDateTime.getTime());
295     	}
296     	
297     	return batchEmployeeApprovalDate;
298     }
299     
300     public void setBatchEmployeeApprovalDate(java.sql.Date batchEmployeeApprovalDate) {
301     	DateTime dateTime = new DateTime(batchEmployeeApprovalDateTime);
302     	LocalDate localDate = new LocalDate(batchEmployeeApprovalDate);
303     	LocalTime localTime = new LocalTime(batchEmployeeApprovalDateTime);
304     	batchEmployeeApprovalDateTime = localDate.toDateTime(localTime, dateTime.getZone()).toDate();
305     }
306 
307     public java.sql.Time getBatchEmployeeApprovalTime() {
308     	java.sql.Time batchEmployeeApprovalTime = null;
309     	
310     	if (batchEmployeeApprovalDateTime != null) {
311     		batchEmployeeApprovalTime = new java.sql.Time(batchEmployeeApprovalDateTime.getTime());
312     	}
313     	
314     	return batchEmployeeApprovalTime;
315     }
316     
317     public void setBatchEmployeeApprovalTime(java.sql.Time batchEmployeeApprovalDate) {
318     	DateTime dateTime = new DateTime(batchEmployeeApprovalDateTime);
319     	LocalDate localDate = new LocalDate(batchEmployeeApprovalDateTime);
320     	LocalTime localTime = new LocalTime(batchEmployeeApprovalDate);
321     	batchEmployeeApprovalDateTime = localDate.toDateTime(localTime, dateTime.getZone()).toDate();
322     }
323 
324     public Date getBatchSupervisorApprovalDateTime() {
325         return batchSupervisorApprovalDateTime;
326     }
327 
328     public void setBatchSupervisorApprovalDateTime(Date batchSupervisorApprovalDateTime) {
329         this.batchSupervisorApprovalDateTime = batchSupervisorApprovalDateTime;
330     }
331     
332     public java.sql.Date getBatchSupervisorApprovalDate() {
333     	java.sql.Date batchSupervisorApprovalDate = null;
334     	
335     	if (batchSupervisorApprovalDateTime != null) {
336     		batchSupervisorApprovalDate = new java.sql.Date(batchSupervisorApprovalDateTime.getTime());
337     	}
338     	
339     	return batchSupervisorApprovalDate;
340     }
341     
342     public void setBatchSupervisorApprovalDate(java.sql.Date batchSupervisorApprovalDate) {
343     	DateTime dateTime = new DateTime(batchSupervisorApprovalDateTime);
344     	LocalDate localDate = new LocalDate(batchSupervisorApprovalDate);
345     	LocalTime localTime = new LocalTime(batchSupervisorApprovalDateTime);
346     	batchSupervisorApprovalDateTime = localDate.toDateTime(localTime, dateTime.getZone()).toDate();
347     }
348 
349     public java.sql.Time getBatchSupervisorApprovalTime() {
350     	java.sql.Time batchSupervisorApprovalTime = null;
351     	
352     	if (batchSupervisorApprovalDateTime != null) {
353     		batchSupervisorApprovalTime = new java.sql.Time(batchSupervisorApprovalDateTime.getTime());
354     	}
355     	
356     	return batchSupervisorApprovalTime;
357     }
358     
359     public void setBatchSupervisorApprovalTime(java.sql.Time batchSupervisorApprovalDate) {
360     	DateTime dateTime = new DateTime(batchSupervisorApprovalDateTime);
361     	LocalDate localDate = new LocalDate(batchSupervisorApprovalDateTime);
362     	LocalTime localTime = new LocalTime(batchSupervisorApprovalDate);
363     	batchSupervisorApprovalDateTime = localDate.toDateTime(localTime, dateTime.getZone()).toDate();
364     }
365 
366 	public Calendar getCalendarObj() {
367 		return calendarObj;
368 	}
369 
370 	public void setCalendarObj(Calendar calendarObj) {
371 		this.calendarObj = calendarObj;
372 	}
373 
374     public int compareTo(CalendarEntries pce) {
375         return this.getBeginPeriodDate().compareTo(pce.getBeginPeriodDate());
376     }
377 
378 }