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.validation.impl;
017    
018    import java.math.BigDecimal;
019    
020    import org.kuali.kfs.coa.document.validation.impl.MaintenancePreRulesBase;
021    import org.kuali.kfs.module.bc.businessobject.BudgetConstructionPosition;
022    import org.kuali.rice.kns.document.MaintenanceDocument;
023    import org.kuali.rice.kns.util.ObjectUtils;
024    
025    /**
026     * This class...
027     */
028    public class BudgetConstructionPositionPreRules extends MaintenancePreRulesBase {
029    
030    
031        protected BudgetConstructionPosition newBudgetConstructionPosition;
032        protected BudgetConstructionPosition copyBudgetConstructionPosition;
033    
034    
035        public BudgetConstructionPositionPreRules() {
036    
037        }
038    
039        protected boolean doCustomPreRules(MaintenanceDocument document) {
040            setupConvenienceObjects(document);
041    
042            computeFTE();
043    
044            return true;
045        }
046    
047    
048        protected void computeFTE() {
049            BigDecimal newPositionStandardHoursDefault = newBudgetConstructionPosition.getPositionStandardHoursDefault();
050            Integer newIuNormalWorkMonths = newBudgetConstructionPosition.getIuNormalWorkMonths();
051            Integer newIuPayMonths = newBudgetConstructionPosition.getIuPayMonths();
052            BigDecimal result;
053            if ((ObjectUtils.isNotNull(newPositionStandardHoursDefault)) && (ObjectUtils.isNotNull(newPositionStandardHoursDefault)) && (ObjectUtils.isNotNull(newPositionStandardHoursDefault))) {
054    
055                result = BudgetConstructionPosition.getCalculatedBCPositionFTE(newPositionStandardHoursDefault, newIuNormalWorkMonths, newIuPayMonths);
056                newBudgetConstructionPosition.setPositionFullTimeEquivalency(result);
057            }
058            else {
059                result = new BigDecimal(0);
060            }
061        }
062    
063        protected void setupConvenienceObjects(MaintenanceDocument document) {
064    
065            // setup newAccount convenience objects, make sure all possible sub-objects are populated
066            newBudgetConstructionPosition = (BudgetConstructionPosition) document.getNewMaintainableObject().getBusinessObject();
067            copyBudgetConstructionPosition = (BudgetConstructionPosition) ObjectUtils.deepCopy(newBudgetConstructionPosition);
068            //KFSMI-798 - refreshNonUpdatableReferences() used instead of refresh(), 
069            //BudgetConstructionPosition does not have any updatable references
070            copyBudgetConstructionPosition.refreshNonUpdateableReferences();
071        }
072    }