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.fp.document.authorization;
017    
018    import java.util.Iterator;
019    import java.util.List;
020    
021    import org.kuali.kfs.fp.businessobject.FiscalYearFunctionControl;
022    import org.kuali.kfs.fp.service.FiscalYearFunctionControlService;
023    import org.kuali.kfs.sys.context.SpringContext;
024    import org.kuali.kfs.sys.service.UniversityDateService;
025    import org.kuali.rice.kim.bo.Person;
026    import org.kuali.rice.kns.exception.InactiveDocumentTypeAuthorizationException;
027    
028    /**
029     * Document Authorizer for the Year End Budget Adjustment document.
030     */
031    public class YearEndBudgetAdjustmentDocumentPresentationController extends BudgetAdjustmentDocumentPresentationController {
032    
033        /**
034         * Checks whether the BA document is active for the year end posting year.
035         * 
036         * @see org.kuali.rice.kns.authorization.DocumentAuthorizer#canInitiate(java.lang.String, org.kuali.rice.kns.bo.user.KualiUser)
037         */
038        @Override
039        public boolean canInitiate(String documentTypeName) {
040            List allowedYears = SpringContext.getBean(FiscalYearFunctionControlService.class).getBudgetAdjustmentAllowedYears();
041            Integer previousPostingYear = new Integer(SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear().intValue() - 1);
042            boolean previousActive = false;
043                    if (allowedYears != null) {
044                for (Iterator iter = allowedYears.iterator(); iter.hasNext();) {
045                    FiscalYearFunctionControl fyControl = (FiscalYearFunctionControl) iter.next();
046                    if (fyControl.getUniversityFiscalYear().equals(previousPostingYear)) {
047                        previousActive = true;
048                    }
049                }
050            }
051            return super.canInitiate(documentTypeName) && previousActive;
052        }
053    }
054