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.bc.document.authorization;
017    
018    import java.util.Set;
019    
020    import org.kuali.kfs.fp.service.FiscalYearFunctionControlService;
021    import org.kuali.kfs.module.bc.BCConstants;
022    import org.kuali.kfs.module.bc.document.BudgetConstructionDocument;
023    import org.kuali.kfs.module.bc.document.service.BudgetDocumentService;
024    import org.kuali.kfs.sys.context.SpringContext;
025    import org.kuali.kfs.sys.document.authorization.FinancialSystemTransactionalDocumentPresentationControllerBase;
026    import org.kuali.rice.kns.document.Document;
027    
028    public class BudgetConstructionDocumentPresentationController extends FinancialSystemTransactionalDocumentPresentationControllerBase {
029    
030        /**
031         * @see org.kuali.rice.kns.document.authorization.DocumentPresentationControllerBase#canEdit(org.kuali.rice.kns.document.Document)
032         */
033        @Override
034        protected boolean canEdit(Document document) {
035            BudgetConstructionDocument bcDocument = (BudgetConstructionDocument) document;
036    
037            BudgetDocumentService budgetDocumentService = SpringContext.getBean(BudgetDocumentService.class);
038            boolean accountReportsExist = budgetDocumentService.isAccountReportsExist(bcDocument.getChartOfAccountsCode(), bcDocument.getAccountNumber());
039    
040            return accountReportsExist;
041        }
042    
043        /**
044         * @see org.kuali.rice.kns.document.authorization.DocumentPresentationControllerBase#canReload(org.kuali.rice.kns.document.Document)
045         */
046        @Override
047        protected boolean canReload(Document document) {
048            return false;
049        }
050    
051        /**
052         * @see org.kuali.rice.kns.document.authorization.DocumentPresentationControllerBase#canSave(org.kuali.rice.kns.document.Document)
053         */
054        @Override
055        protected boolean canSave(Document document) {
056            BudgetConstructionDocument bcDocument = (BudgetConstructionDocument) document;
057    
058            return SpringContext.getBean(BudgetDocumentService.class).isAccountReportsExist(bcDocument.getChartOfAccountsCode(), bcDocument.getAccountNumber()) && SpringContext.getBean(FiscalYearFunctionControlService.class).isBudgetUpdateAllowed(bcDocument.getUniversityFiscalYear());
059        }
060    
061        /**
062         * @see org.kuali.kfs.sys.document.authorization.FinancialSystemTransactionalDocumentPresentationControllerBase#getEditModes(org.kuali.rice.kns.document.Document)
063         */
064        @Override
065        public Set<String> getEditModes(Document document) {
066            BudgetConstructionDocument bcDocument = (BudgetConstructionDocument) document;
067    
068            Set<String> editModes = super.getEditModes(document);
069            if (!SpringContext.getBean(FiscalYearFunctionControlService.class).isBudgetUpdateAllowed(bcDocument.getUniversityFiscalYear())) {
070                editModes.add(BCConstants.EditModes.SYSTEM_VIEW_ONLY);
071            }
072    
073            return editModes;
074        }
075    }