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.List;
019    
020    import org.kuali.kfs.fp.service.FiscalYearFunctionControlService;
021    import org.kuali.kfs.sys.context.SpringContext;
022    import org.kuali.kfs.sys.document.Correctable;
023    import org.kuali.kfs.sys.document.FinancialSystemTransactionalDocument;
024    import org.kuali.kfs.sys.document.authorization.AccountingDocumentPresentationControllerBase;
025    import org.kuali.kfs.sys.document.datadictionary.FinancialSystemTransactionalDocumentEntry;
026    import org.kuali.rice.kns.datadictionary.DocumentEntry;
027    import org.kuali.rice.kns.service.DataDictionaryService;
028    import org.kuali.rice.kns.workflow.service.KualiWorkflowDocument;
029    
030    /**
031     * Presentation Controller for Budget Adjustment documents
032     */
033    public class BudgetAdjustmentDocumentPresentationController extends AccountingDocumentPresentationControllerBase {
034        /**
035         * @see org.kuali.rice.kns.document.authorization.DocumentPresentationControllerBase#canInitiate(java.lang.String)
036         */
037        @Override
038        public boolean canInitiate(String documentTypeName) {
039            List<Integer> allowedYears = SpringContext.getBean(FiscalYearFunctionControlService.class).getBudgetAdjustmentAllowedYears();
040    
041            // if no allowed years found, BA document is not allowed to be initiated
042            if (allowedYears == null || allowedYears.isEmpty()) {
043                return false;
044            }
045    
046            return super.canInitiate(documentTypeName);
047        }
048    
049        // TODO is there really anything specific to the BA in this logic?
050        /**
051         * @see org.kuali.kfs.sys.document.authorization.LedgerPostingDocumentPresentationControllerBase#canErrorCorrect(org.kuali.kfs.sys.document.FinancialSystemTransactionalDocument)
052         */
053        @Override
054        public boolean canErrorCorrect(FinancialSystemTransactionalDocument document) {
055            final KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
056    
057            if (!(document instanceof Correctable)) return false;
058            if (!((FinancialSystemTransactionalDocumentEntry)SpringContext.getBean(DataDictionaryService.class).getDataDictionary().getDocumentEntry(document.getClass().getName())).getAllowsErrorCorrection()) return false;
059            if (document.getDocumentHeader().getCorrectedByDocumentId() != null) return false;
060            return (workflowDocument.stateIsApproved() || workflowDocument.stateIsProcessed() || workflowDocument.stateIsFinal());
061        }
062    
063    }