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.kpme.core.calendar.dao;
17  
18  import java.sql.Time;
19  import java.text.ParseException;
20  import java.text.SimpleDateFormat;
21  import java.util.ArrayList;
22  import java.util.Collection;
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.joda.time.DateTime;
31  import org.kuali.kpme.core.calendar.Calendar;
32  import org.kuali.kpme.core.calendar.entry.CalendarEntry;
33  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
34  
35  public class CalendarDaoOjbImpl extends PlatformAwareDaoBaseOjb  implements CalendarDao {
36  
37  	private static final Logger LOG = Logger.getLogger(CalendarDaoOjbImpl.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  	// Is pay clendar groups alwasy unique?
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 CalendarEntry getPreviousCalendarEntry(String tkCalendarId, DateTime beginDateCurrentCalendar){
67          Criteria payEndDateCriteria = new Criteria();
68          payEndDateCriteria.addEqualTo("hr_py_calendar_id", tkCalendarId);
69          payEndDateCriteria.addLessOrEqualThan("end_period_date", beginDateCurrentCalendar.toDate());
70          
71          return (CalendarEntry) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(CalendarEntry.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("UPPER(`calendar_name`)", calendarName.toUpperCase()); // KPME-2695
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 }