1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.calendar.dao;
17
18 import java.sql.Time;
19 import java.text.SimpleDateFormat;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Date;
23 import java.util.List;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.apache.log4j.Logger;
27 import org.apache.ojb.broker.query.Criteria;
28 import org.apache.ojb.broker.query.Query;
29 import org.apache.ojb.broker.query.QueryFactory;
30 import org.kuali.hr.time.calendar.Calendar;
31 import org.kuali.hr.time.calendar.CalendarEntries;
32 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
33 import java.text.ParseException;
34
35 public class CalendarDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements CalendarDao {
36
37 private static final Logger LOG = Logger.getLogger(CalendarDaoSpringOjbImpl.class);
38
39 public void saveOrUpdate(Calendar calendar) {
40 this.getPersistenceBrokerTemplate().store(calendar);
41 }
42
43 public void saveOrUpdate(List<Calendar> calendarList) {
44 if (calendarList != null) {
45 for (Calendar calendar : calendarList) {
46 this.getPersistenceBrokerTemplate().store(calendar);
47 }
48 }
49 }
50
51 public Calendar getCalendar(String hrPyCalendarId) {
52 Criteria currentRecordCriteria = new Criteria();
53 currentRecordCriteria.addEqualTo("hrCalendarId", hrPyCalendarId);
54
55 return (Calendar) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(Calendar.class, currentRecordCriteria));
56 }
57
58
59 public Calendar getCalendarByGroup(String pyCalendarGroup) {
60 Criteria currentRecordCriteria = new Criteria();
61 currentRecordCriteria.addEqualTo("calendarName", pyCalendarGroup);
62
63 return (Calendar) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(Calendar.class, currentRecordCriteria));
64 }
65
66 public CalendarEntries getPreviousCalendarEntry(String tkCalendarId, Date beginDateCurrentCalendar){
67 Criteria payEndDateCriteria = new Criteria();
68 payEndDateCriteria.addEqualTo("hr_py_calendar_id", tkCalendarId);
69 payEndDateCriteria.addLessOrEqualThan("end_period_date", beginDateCurrentCalendar);
70
71 return (CalendarEntries) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(CalendarEntries.class,payEndDateCriteria));
72
73 }
74
75 @Override
76 public List<Calendar> getCalendars(String calendarName, String calendarTypes, String flsaBeginDay, String flsaBeginTime) {
77 Criteria crit = new Criteria();
78
79 List<Calendar> results = new ArrayList<Calendar>();
80
81 if(StringUtils.isNotBlank(calendarName) && StringUtils.isNotEmpty(calendarName)){
82 crit.addLike("calendarName", calendarName);
83 }
84 if(StringUtils.isNotBlank(calendarTypes) && StringUtils.isNotEmpty(calendarTypes)){
85 crit.addLike("calendarTypes", calendarTypes);
86 }
87 if(StringUtils.isNotBlank(flsaBeginDay) && StringUtils.isNotEmpty(flsaBeginDay)){
88 crit.addLike("flsaBeginDay", flsaBeginDay);
89 }
90 if(flsaBeginTime != null){
91 SimpleDateFormat sdFormat = new SimpleDateFormat("hh:mm aa");
92 try {
93 Time flsaTime = new Time(sdFormat.parse(flsaBeginTime).getTime());
94 crit.addLike("flsaBeginTime", flsaTime);
95 } catch (ParseException e) {
96
97 }
98 }
99 Query query = QueryFactory.newQuery(Calendar.class, crit);
100 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
101 results.addAll(c);
102
103 return results;
104 }
105
106
107
108 }