001    /*
002     * Copyright 2011 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.kfs.sys.service.impl;
017    
018    import java.io.File;
019    
020    import org.apache.commons.lang.StringUtils;
021    import org.kuali.kfs.sys.service.FiscalYearAwareReportWriterService;
022    import org.kuali.rice.kns.util.KNSConstants;
023    
024    /**
025     * Ensures that balance summary reports have the fiscal year included in the filename.
026     */
027    public class BalanceSummaryReportWriterTextServiceImpl extends ReportWriterTextServiceImpl implements FiscalYearAwareReportWriterService {
028        private Integer fiscalYear;
029        
030        /**
031         * @see org.kuali.kfs.sys.service.impl.ReportWriterTextServiceImpl#destroy()
032         */
033        @Override
034        public void destroy() {
035            super.destroy();
036            
037            fiscalYear = null;
038        }
039    
040        /**
041         * @see org.kuali.kfs.sys.service.impl.ReportWriterTextServiceImpl#initialize()
042         */
043        @Override
044        public void initialize() {
045            super.initialize();
046        }
047    
048        /**
049         * @see org.kuali.kfs.sys.service.FiscalYearAwareReportWriterService#setFiscalYear(java.lang.Integer)
050         */
051        public void setFiscalYear(Integer fiscalYear) {
052            this.fiscalYear = fiscalYear;
053        }
054    
055        @Override
056        protected String generateFullFilePath() {
057            if (fiscalYear == null) {
058                throw new RuntimeException("fiscal year is blank");
059            }
060            if (isAggregationModeOn()) {
061                return filePath + File.separator + this.fileNamePrefix + fiscalYear.toString() + fileNameSuffix;            
062            }
063            else {
064                return filePath + File.separator + this.fileNamePrefix + fiscalYear.toString() + "_" + dateTimeService.toDateTimeStringForFilename(dateTimeService.getCurrentDate()) + fileNameSuffix;
065            }
066        }
067    }