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.module.endow.document.service.impl;
017    
018    import java.util.ArrayList;
019    import java.util.Collection;
020    
021    import org.kuali.kfs.module.endow.EndowParameterKeyConstants;
022    import org.kuali.kfs.module.endow.businessobject.KemidFee;
023    import org.kuali.kfs.module.endow.document.service.KEMService;
024    import org.kuali.kfs.module.endow.document.service.KemidFeeService;
025    import org.kuali.kfs.sys.service.impl.KfsParameterConstants;
026    import org.kuali.rice.kns.service.BusinessObjectService;
027    import org.kuali.rice.kns.service.ParameterService;
028    import org.kuali.rice.kns.util.KualiDecimal;
029    
030    /**
031     * This class is the service implementation for the KemidFeeService. This is the default, Kuali provided implementation.
032     */
033    public class KemidFeeServiceImpl implements KemidFeeService {
034        protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KemidFeeServiceImpl.class);
035    
036        private BusinessObjectService businessObjectService;
037        protected KEMService kemService;
038        protected ParameterService parameterService;
039        
040        /**
041         * @see org.kuali.kfs.module.endow.document.service.KemidFeeService#getAllKemIdFee()
042         */
043        public Collection <KemidFee> getAllKemIdFee() {
044            Collection <KemidFee> kemIdFee = new ArrayList();
045            
046            kemIdFee = businessObjectService.findAll(KemidFee.class);
047            
048            return kemIdFee;
049        }
050        
051        /**
052         * Updates the END_KEMID_FEE_T table records by setting the amounts in WAIVE_FEE_YTD to zero
053         * if current date is the first day of the institution's fiscal year
054         * @see org.kuali.kfs.module.endow.document.service.KemidFeeService#updateWaiverFeeYearToDateTotals()
055         */
056        public boolean updateWaiverFeeYearToDateTotals() {
057            LOG.info("updateWaiverFeeYearToDateTotals() process started");
058           
059           boolean updated = true;
060           
061           if (!systemParametersForUpdateWaiverFeeAmounts()) {
062               return false;
063           }
064           
065           try {
066               java.sql.Date firstDayAfterFiscalYear = kemService.getFirstDayAfterFiscalYearEndDayAndMonth();
067               
068               if (firstDayAfterFiscalYear.equals(kemService.getCurrentDate())) {
069                   //update END_KEMID_FEE_T:
070                   Collection <KemidFee> kemidFeeRecords = getAllKemIdFee();
071                      
072                   for (KemidFee kemidFee : kemidFeeRecords) {
073                        kemidFee.setTotalWaivedFees(KualiDecimal.ZERO);
074                        businessObjectService.save(kemidFee);
075                   }
076               }
077               
078               return updated;
079           }
080           catch (Exception exception) {
081               return false;
082           }
083        }
084        
085        /**
086         * This method checks if the System parameters have been set up for this batch job.
087         * @result return true if the system parameters exist, else false
088         */
089        protected boolean systemParametersForUpdateWaiverFeeAmounts() {
090            LOG.info("systemParametersForUpdateWaiverFeeAmounts() started.");
091            
092            boolean systemParameterExists = true;
093            
094            // check to make sure the system parameter has been setup...
095            if (!getParameterService().parameterExists(KfsParameterConstants.ENDOWMENT_BATCH.class, EndowParameterKeyConstants.FISCAL_YEAR_END_MONTH_AND_DAY)) {
096              LOG.warn("FISCAL_YEAR_END_MONTH_AND_DAY System parameter does not exist in the parameters list.  The job can not continue without this parameter");
097              return false;
098            }
099            
100            return systemParameterExists;
101        }
102        
103        /**
104         * This method gets the businessObjectService.
105         * 
106         * @return businessObjectService
107         */
108        public BusinessObjectService getBusinessObjectService() {
109            return businessObjectService;
110        }
111    
112        /**
113         * This method sets the businessObjectService
114         * 
115         * @param businessObjectService
116         */
117        public void setBusinessObjectService(BusinessObjectService businessObjectService) {
118            this.businessObjectService = businessObjectService;
119        }
120    
121        /**
122         * Gets the kemService.
123         * @return kemService
124         */
125        protected KEMService getKemService() {
126            return kemService;
127        }
128    
129        /**
130         * Sets the kemService.
131         * @param kemService
132         */
133        public void setKemService(KEMService kemService) {
134            this.kemService = kemService;
135        }
136    
137        /**
138         * Gets the parameterService attribute.
139         * @return Returns the parameterService.
140         */    
141        protected ParameterService getParameterService() {
142            return parameterService;
143        }
144    
145        /**
146         * Sets the parameterService attribute value.
147         * @param parameterService The parameterService to set.
148         */    
149        public void setParameterService(ParameterService parameterService) {
150            this.parameterService = parameterService;
151        }
152        
153    }