001 /**
002 * Copyright 2004-2012 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;
017
018 import org.joda.time.DateTime;
019 import org.joda.time.LocalTime;
020 import org.kuali.hr.core.cache.CacheUtils;
021 import org.kuali.hr.time.service.base.TkServiceLocator;
022 import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
023 import org.kuali.rice.krad.bo.PersistableBusinessObject;
024
025 public class CalendarEntryMaintainableImpl extends KualiMaintainableImpl {
026
027 /**
028 *
029 */
030 private static final long serialVersionUID = 1L;
031
032 @Override
033 public PersistableBusinessObject getBusinessObject() {
034 //used to setup the divided time/date fields
035 CalendarEntries payEntry = (CalendarEntries)super.getBusinessObject();
036 if(payEntry.getBeginPeriodTime()==null){
037 payEntry.setBeginPeriodDateTime(payEntry.getBeginPeriodDateTime());
038 payEntry.setEndPeriodDateTime(payEntry.getEndPeriodDateTime());
039 }
040 return payEntry;
041 }
042
043 @Override
044 public void saveBusinessObject() {
045 CalendarEntries payEntry = (CalendarEntries)super.getBusinessObject();
046 Calendar calendar = TkServiceLocator.getCalendarService().getCalendarByGroup(payEntry.getCalendarName());
047 payEntry.setHrCalendarId(calendar.getHrCalendarId());
048
049 java.sql.Date beginDate = payEntry.getBeginPeriodDate();
050 java.sql.Time beginTime = payEntry.getBeginPeriodTime();
051 LocalTime beginTimeLocal = new LocalTime(beginTime.getTime());
052 DateTime beginDateTime = new DateTime(beginDate.getTime());
053 beginDateTime = beginDateTime.plus(beginTimeLocal.getMillisOfDay());
054 payEntry.setBeginPeriodDateTime(new java.util.Date(beginDateTime.getMillis()));
055
056 java.sql.Date endDate = payEntry.getEndPeriodDate();
057 java.sql.Time endTime = payEntry.getEndPeriodTime();
058 LocalTime endTimeLocal = new LocalTime(endTime.getTime());
059 DateTime endDateTime = new DateTime(endDate.getTime());
060 endDateTime = endDateTime.plus(endTimeLocal.getMillisOfDay());
061 payEntry.setEndPeriodDateTime(new java.util.Date(endDateTime.getMillis()));
062
063 super.saveBusinessObject();
064 CacheUtils.flushCache(CalendarEntries.CACHE_NAME);
065 }
066
067
068
069
070
071
072 }