001 /**
002 * Copyright 2004-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.time.calendar.dao;
017
018 import java.sql.Time;
019 import java.text.SimpleDateFormat;
020 import java.util.ArrayList;
021 import java.util.Collection;
022 import java.util.Date;
023 import java.util.List;
024
025 import org.apache.commons.lang.StringUtils;
026 import org.apache.log4j.Logger;
027 import org.apache.ojb.broker.query.Criteria;
028 import org.apache.ojb.broker.query.Query;
029 import org.apache.ojb.broker.query.QueryFactory;
030 import org.kuali.hr.time.calendar.Calendar;
031 import org.kuali.hr.time.calendar.CalendarEntries;
032 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
033 import java.text.ParseException;
034
035 public class CalendarDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements CalendarDao {
036
037 private static final Logger LOG = Logger.getLogger(CalendarDaoSpringOjbImpl.class);
038
039 public void saveOrUpdate(Calendar calendar) {
040 this.getPersistenceBrokerTemplate().store(calendar);
041 }
042
043 public void saveOrUpdate(List<Calendar> calendarList) {
044 if (calendarList != null) {
045 for (Calendar calendar : calendarList) {
046 this.getPersistenceBrokerTemplate().store(calendar);
047 }
048 }
049 }
050
051 public Calendar getCalendar(String hrPyCalendarId) {
052 Criteria currentRecordCriteria = new Criteria();
053 currentRecordCriteria.addEqualTo("hrCalendarId", hrPyCalendarId);
054
055 return (Calendar) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(Calendar.class, currentRecordCriteria));
056 }
057
058 // Is pay clendar groups alwasy unique?
059 public Calendar getCalendarByGroup(String pyCalendarGroup) {
060 Criteria currentRecordCriteria = new Criteria();
061 currentRecordCriteria.addEqualTo("calendarName", pyCalendarGroup);
062
063 return (Calendar) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(Calendar.class, currentRecordCriteria));
064 }
065
066 public CalendarEntries getPreviousCalendarEntry(String tkCalendarId, Date beginDateCurrentCalendar){
067 Criteria payEndDateCriteria = new Criteria();
068 payEndDateCriteria.addEqualTo("hr_py_calendar_id", tkCalendarId);
069 payEndDateCriteria.addLessOrEqualThan("end_period_date", beginDateCurrentCalendar);
070
071 return (CalendarEntries) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(CalendarEntries.class,payEndDateCriteria));
072
073 }
074
075 @Override
076 public List<Calendar> getCalendars(String calendarName, String calendarTypes, String flsaBeginDay, String flsaBeginTime) {
077 Criteria crit = new Criteria();
078
079 List<Calendar> results = new ArrayList<Calendar>();
080
081 if(StringUtils.isNotBlank(calendarName) && StringUtils.isNotEmpty(calendarName)){
082 crit.addLike("calendarName", calendarName);
083 }
084 if(StringUtils.isNotBlank(calendarTypes) && StringUtils.isNotEmpty(calendarTypes)){
085 crit.addLike("calendarTypes", calendarTypes);
086 }
087 if(StringUtils.isNotBlank(flsaBeginDay) && StringUtils.isNotEmpty(flsaBeginDay)){
088 crit.addLike("flsaBeginDay", flsaBeginDay);
089 }
090 if(flsaBeginTime != null){
091 SimpleDateFormat sdFormat = new SimpleDateFormat("hh:mm aa");
092 try {
093 Time flsaTime = new Time(sdFormat.parse(flsaBeginTime).getTime());
094 crit.addLike("flsaBeginTime", flsaTime);
095 } catch (ParseException e) {
096
097 }
098 }
099 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 }