001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.financial.service.impl;
017:
018: import org.apache.log4j.Logger;
019: import org.kuali.core.service.DateTimeService;
020: import org.kuali.core.util.DateUtils;
021: import org.kuali.core.util.Timer;
022: import org.kuali.kfs.context.SpringContext;
023: import org.kuali.module.financial.service.UniversityDateService;
024: import org.kuali.module.gl.bo.UniversityDate;
025: import org.kuali.module.gl.dao.UniversityDateDao;
026: import org.springframework.transaction.annotation.Transactional;
027:
028: /**
029: *
030: * This is the default implementation of the UniversityDateService interface.
031: */
032: @Transactional
033: public class UniversityDateServiceImpl implements UniversityDateService {
034:
035: private static final Logger LOG = Logger
036: .getLogger(UniversityDateServiceImpl.class);
037:
038: private UniversityDateDao universityDateDao;
039:
040: /**
041: * This method retrieves a UniversityDate object using today's date to create the instance.
042: *
043: * @return A UniversityDate instance representing today's date.
044: *
045: * @see org.kuali.module.financial.service.UniversityDateService#getCurrentUniversityDate()
046: */
047: public UniversityDate getCurrentUniversityDate() {
048: LOG.debug("getCurrentUniversityDate() started");
049: java.util.Date now = SpringContext.getBean(
050: DateTimeService.class).getCurrentDate();
051:
052: return universityDateDao.getByPrimaryKey(DateUtils
053: .clearTimeFields(now));
054: }
055:
056: /**
057: * This method retrieves the current fiscal year using today's date.
058: *
059: * @return The current fiscal year as an Integer.
060: *
061: * @see org.kuali.core.service.DateTimeService#getCurrentFiscalYear()
062: */
063: public Integer getCurrentFiscalYear() {
064: Timer t0 = new Timer("getCurrentFiscalYear");
065: java.util.Date now = SpringContext.getBean(
066: DateTimeService.class).getCurrentDate();
067:
068: Integer result = getFiscalYear(DateUtils.clearTimeFields(now));
069: t0.log();
070: return result;
071: }
072:
073: /**
074: * This method retrieves the fiscal year associated with the date provided.
075: *
076: * @param date The date to be used for retrieving the associated fiscal year.
077: * @return The fiscal year that the date provided falls within.
078: *
079: * @see org.kuali.core.service.DateTimeService#getFiscalYear(java.util.Date)
080: */
081: public Integer getFiscalYear(java.util.Date date) {
082: if (date == null) {
083: throw new IllegalArgumentException("invalid (null) date");
084: }
085:
086: UniversityDate uDate = universityDateDao.getByPrimaryKey(date);
087: return (uDate == null) ? null : uDate.getUniversityFiscalYear();
088: }
089:
090: /**
091: * This method retrieves the first date of the fiscal year provided.
092: *
093: * @param fiscalYear The fiscal year to retrieve the first date for.
094: * @return A Date object representing the first date of the fiscal year given.
095: *
096: * @see org.kuali.module.financial.service.UniversityDateService#getFirstDateOfFiscalYear(java.lang.Integer)
097: */
098: public java.util.Date getFirstDateOfFiscalYear(Integer fiscalYear) {
099: UniversityDate uDate = universityDateDao
100: .getFirstFiscalYearDate(fiscalYear);
101: return (uDate == null) ? null : uDate.getUniversityDate();
102: }
103:
104: /**
105: * This method retrieves the last date of the fiscal year provided.
106: *
107: * @param fiscalYear The fiscal year to retrieve the last date for.
108: * @return A Date object representing the last date of the fiscal year given.
109: *
110: * @see org.kuali.module.financial.service.UniversityDateService#getLastDateOfFiscalYear(java.lang.Integer)
111: */
112: public java.util.Date getLastDateOfFiscalYear(Integer fiscalYear) {
113: UniversityDate uDate = universityDateDao
114: .getLastFiscalYearDate(fiscalYear);
115: return (uDate == null) ? null : uDate.getUniversityDate();
116: }
117:
118: /**
119: * Sets the universityDateDao attribute value.
120: * @param universityDateDao The universityDateDao to set.
121: */
122: public void setUniversityDateDao(UniversityDateDao universityDateDao) {
123: this.universityDateDao = universityDateDao;
124: }
125:
126: }
|