View Javadoc
1   /*
2    * Copyright 2007 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.ole.sys.service.impl;
17  
18  import org.apache.log4j.Logger;
19  import org.kuali.ole.sys.businessobject.UniversityDate;
20  import org.kuali.ole.sys.context.SpringContext;
21  import org.kuali.ole.sys.dataaccess.UniversityDateDao;
22  import org.kuali.ole.sys.service.NonTransactional;
23  import org.kuali.ole.sys.service.UniversityDateService;
24  import org.kuali.ole.sys.util.KfsDateUtils;
25  import org.kuali.rice.core.api.datetime.DateTimeService;
26  import org.kuali.rice.krad.service.BusinessObjectService;
27  import org.springframework.cache.annotation.Cacheable;
28  
29  /**
30   * 
31   * This is the default implementation of the UniversityDateService interface.
32   */
33  
34  @NonTransactional
35  public class UniversityDateServiceImpl implements UniversityDateService {
36  
37      private static final Logger LOG = Logger.getLogger(UniversityDateServiceImpl.class);
38  
39      protected UniversityDateDao universityDateDao;
40      protected DateTimeService dateTimeService;
41      
42      /**
43       * This method retrieves a UniversityDate object using today's date to create the instance.
44       * 
45       * @return A UniversityDate instance representing today's date.
46       * 
47       * @see org.kuali.ole.sys.service.UniversityDateService#getCurrentUniversityDate()
48       */
49      @Override
50      public UniversityDate getCurrentUniversityDate() {
51          java.util.Date now = dateTimeService.getCurrentDate();
52          return SpringContext.getBean(BusinessObjectService.class).findBySinglePrimaryKey(UniversityDate.class, new java.sql.Date( KfsDateUtils.clearTimeFields(now).getTime() ));
53      }
54  
55      /**
56       * This method retrieves the current fiscal year using today's date.
57       * 
58       * @return The current fiscal year as an Integer.
59       * 
60       * @see org.kuali.rice.core.api.datetime.DateTimeService#getCurrentFiscalYear()
61       */
62      @Override
63      public Integer getCurrentFiscalYear() {
64          java.util.Date now = dateTimeService.getCurrentDate();
65  
66          return getFiscalYear(KfsDateUtils.clearTimeFields(now));
67      }
68      
69      /**
70       * This method retrieves the fiscal year associated with the date provided.
71       * 
72       * @param date The date to be used for retrieving the associated fiscal year.
73       * @return The fiscal year that the date provided falls within.
74       * 
75       * @see org.kuali.rice.core.api.datetime.DateTimeService#getFiscalYear(java.util.Date)
76       */
77      @Override
78      @Cacheable(value=UniversityDate.CACHE_NAME, key="'{FiscalYear}'+#p0")
79      public Integer getFiscalYear(java.util.Date date) {
80          if (date == null) {
81              throw new IllegalArgumentException("invalid (null) date");
82          }
83          UniversityDate uDate = SpringContext.getBean(BusinessObjectService.class).findBySinglePrimaryKey(UniversityDate.class, new java.sql.Date( KfsDateUtils.clearTimeFields(date).getTime() ) );
84          return (uDate == null) ? null : uDate.getUniversityFiscalYear();
85      }
86  
87      /**
88       * This method retrieves the first date of the fiscal year provided.
89       * 
90       * @param fiscalYear The fiscal year to retrieve the first date for.
91       * @return A Date object representing the first date of the fiscal year given.
92       * 
93       * @see org.kuali.ole.sys.service.UniversityDateService#getFirstDateOfFiscalYear(java.lang.Integer)
94       */
95      @Override
96      @Cacheable(value=UniversityDate.CACHE_NAME, key="'{FirstDateOfFiscalYear}'+#p0")
97      public java.util.Date getFirstDateOfFiscalYear(Integer fiscalYear) {
98          UniversityDate uDate = universityDateDao.getFirstFiscalYearDate(fiscalYear);
99          return (uDate == null) ? null : uDate.getUniversityDate();
100     }
101 
102     /**
103      * This method retrieves the last date of the fiscal year provided.
104      * 
105      * @param fiscalYear The fiscal year to retrieve the last date for.
106      * @return A Date object representing the last date of the fiscal year given.
107      * 
108      * @see org.kuali.ole.sys.service.UniversityDateService#getLastDateOfFiscalYear(java.lang.Integer)
109      */
110     @Override
111     @Cacheable(value=UniversityDate.CACHE_NAME, key="'{LastDateOfFiscalYear}'+#p0")
112     public java.util.Date getLastDateOfFiscalYear(Integer fiscalYear) {
113         UniversityDate uDate = universityDateDao.getLastFiscalYearDate(fiscalYear);
114         return (uDate == null) ? null : uDate.getUniversityDate();
115     }
116     
117     public void setUniversityDateDao(UniversityDateDao universityDateDao) {
118         this.universityDateDao = universityDateDao;
119     }
120     public void setDateTimeService(DateTimeService dateTimeService) {
121         this.dateTimeService = dateTimeService;
122     }
123     
124 }