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.Arrays;
019    import java.util.List;
020    
021    import org.apache.commons.lang.StringUtils;
022    import org.apache.commons.logging.Log;
023    import org.apache.commons.logging.LogFactory;
024    import org.kuali.kfs.fp.document.DisbursementVoucherConstants;
025    import org.kuali.kfs.sys.businessobject.AccountingLine;
026    import org.kuali.kfs.sys.document.AccountingDocument;
027    import org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizerBase;
028    import org.kuali.rice.kew.exception.WorkflowException;
029    import org.kuali.rice.kns.workflow.service.KualiWorkflowDocument;
030    
031    public class DisbursementVoucherAccountingLineAuthorizer extends AccountingLineAuthorizerBase {
032        private static Log LOG = LogFactory.getLog(DisbursementVoucherAccountingLineAuthorizer.class);
033    
034        /**
035         * @see org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizer#getEditableBlocksInReadOnlyLine(org.kuali.kfs.sys.document.AccountingDocument,
036         *      org.kuali.kfs.sys.businessobject.AccountingLine, org.kuali.rice.kim.bo.Person)
037         */
038        /**
039         * Overridden to make:
040         * 1. amount read only for fiscal officer
041         */
042        @Override
043        public boolean determineEditPermissionOnField(AccountingDocument accountingDocument, AccountingLine accountingLine, String accountingLineCollectionProperty, String fieldName, boolean editablePage) {
044            boolean canModify = super.determineEditPermissionOnField(accountingDocument, accountingLine, accountingLineCollectionProperty, fieldName, editablePage);
045            final KualiWorkflowDocument workflowDocument = accountingDocument.getDocumentHeader().getWorkflowDocument();
046            List<String> currentRouteLevels = null;
047            try {
048                currentRouteLevels = Arrays.asList(workflowDocument.getNodeNames());
049            }
050            catch (WorkflowException ex) {
051                throw new RuntimeException(ex);
052            }
053            if (currentRouteLevels.contains(DisbursementVoucherConstants.RouteLevelNames.ACCOUNT)) {
054                if (StringUtils.equals(fieldName, getAmountPropertyName())) {  //FO? 
055                    canModify = false;
056                }
057            }        
058            return canModify;
059        }
060    
061    
062        /**
063         * @return the property name of the amount field, which will be set read only for fiscal officers
064         */
065        protected String getAmountPropertyName() {
066            return "amount";
067        }
068    }
069