View Javadoc

1   /**
2    * Copyright 2004-2012 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 org.joda.time.DateTime;
19  import org.joda.time.LocalTime;
20  import org.kuali.hr.core.cache.CacheUtils;
21  import org.kuali.hr.time.service.base.TkServiceLocator;
22  import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
23  import org.kuali.rice.krad.bo.PersistableBusinessObject;
24  
25  public class CalendarEntryMaintainableImpl extends KualiMaintainableImpl {
26  
27  	/**
28  	 *
29  	 */
30  	private static final long serialVersionUID = 1L;
31  
32  	@Override
33  	public PersistableBusinessObject getBusinessObject() {
34  		//used to setup the divided time/date fields
35  		CalendarEntries payEntry = (CalendarEntries)super.getBusinessObject();
36  		if(payEntry.getBeginPeriodTime()==null){
37  			payEntry.setBeginPeriodDateTime(payEntry.getBeginPeriodDateTime());
38  			payEntry.setEndPeriodDateTime(payEntry.getEndPeriodDateTime());
39  		}
40  		return payEntry;
41  	}
42  
43  	@Override
44  	public void saveBusinessObject() {
45  		CalendarEntries payEntry = (CalendarEntries)super.getBusinessObject();
46  		Calendar calendar = TkServiceLocator.getCalendarService().getCalendarByGroup(payEntry.getCalendarName());
47  		payEntry.setHrCalendarId(calendar.getHrCalendarId());
48  		
49  		java.sql.Date beginDate = payEntry.getBeginPeriodDate();
50  		java.sql.Time beginTime = payEntry.getBeginPeriodTime();
51  		LocalTime beginTimeLocal = new LocalTime(beginTime.getTime());
52  		DateTime beginDateTime = new DateTime(beginDate.getTime());
53  		beginDateTime = beginDateTime.plus(beginTimeLocal.getMillisOfDay());
54  		payEntry.setBeginPeriodDateTime(new java.util.Date(beginDateTime.getMillis()));
55  
56  		java.sql.Date endDate = payEntry.getEndPeriodDate();
57  		java.sql.Time endTime = payEntry.getEndPeriodTime();
58  		LocalTime endTimeLocal = new LocalTime(endTime.getTime());
59  		DateTime endDateTime = new DateTime(endDate.getTime());
60  		endDateTime = endDateTime.plus(endTimeLocal.getMillisOfDay());
61  		payEntry.setEndPeriodDateTime(new java.util.Date(endDateTime.getMillis()));
62  		
63  		super.saveBusinessObject();
64          CacheUtils.flushCache(CalendarEntries.CACHE_NAME);
65  	}
66  
67  
68  
69  
70  
71  
72  }