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.ld.document.validation.impl;
017    
018    import org.kuali.kfs.module.ld.LaborKeyConstants;
019    import org.kuali.kfs.module.ld.businessobject.BenefitsCalculation;
020    import org.kuali.rice.kns.document.MaintenanceDocument;
021    import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
022    import org.kuali.rice.kns.util.KualiDecimal;
023    import org.kuali.rice.kns.util.ObjectUtils;
024    
025    /**
026     * Business rule(s) applicable to Benefit Calculation Documents.
027     */
028    public class BenefitsCalculationDocumentRule extends MaintenanceDocumentRuleBase {
029    
030        protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BenefitsCalculationDocumentRule.class);
031        protected BenefitsCalculation oldBenefitsCalculation;
032        protected BenefitsCalculation newBenefitsCalculation;
033    
034        /**
035         * Constructs a BenefitsCalculationDocumentRule.java.
036         */
037        public BenefitsCalculationDocumentRule() {
038            super();
039        }
040    
041        /**
042         * Processes the rules
043         * 
044         * @param document MaintenanceDocument type of document to be processed.
045         * @return boolean true when success
046         * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomApproveDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
047         */
048        @Override
049        protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
050    
051            LOG.info("Entering processCustomApproveDocumentBusinessRules()");
052    
053            // process rules
054            checkRules(document);
055    
056            return true;
057        }
058    
059        /**
060         * Processes the rules
061         * 
062         * @param document MaintenanceDocument type of document to be processed.
063         * @return boolean true when success
064         * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
065         */
066        @Override
067        protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
068    
069            boolean success = true;
070    
071            LOG.info("Entering processCustomRouteDocumentBusinessRules()");
072    
073            // process rules
074            success &= checkRules(document);
075    
076            return success;
077        }
078    
079        /**
080         * Processes the rules
081         * 
082         * @param document MaintenanceDocument type of document to be processed.
083         * @return boolean true when success
084         * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
085         */
086        @Override
087        protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
088    
089            boolean success = true;
090    
091            LOG.info("Entering processCustomSaveDocumentBusinessRules()");
092    
093            // process rules
094            success &= checkRules(document);
095    
096            return success;
097        }
098    
099        /**
100         * Checks the fringe benefit percentage cannot be equal to or over 100%
101         * 
102         * @param document MaintenanceDocument type
103         * @return boolean false when the fringe benefit percentage cannot be equal to or over 100%
104         */
105        protected boolean checkRules(MaintenanceDocument document) {
106    
107            boolean success = true;
108    
109            /* The fringe benefit percentage cannot be equal to or over 100% */
110            if (ObjectUtils.isNotNull(newBenefitsCalculation.getPositionFringeBenefitPercent())) {
111                if (newBenefitsCalculation.getPositionFringeBenefitPercent().isGreaterEqual(new KualiDecimal(100))) {
112                    putFieldError("positionFringeBenefitPercent", LaborKeyConstants.ERROR_FRINGE_BENEFIT_PERCENTAGE_INVALID);
113                    success = false;
114                }
115            }
116    
117            return success;
118        }
119    
120        /**
121         * This method sets the convenience objects like newAccount and oldAccount, so you have short and easy handles to the new and
122         * old objects contained in the maintenance document. It also calls the BusinessObjectBase.refresh(), which will attempt to load
123         * all sub-objects from the DB by their primary keys, if available.
124         * 
125         * @param document - the maintenanceDocument being evaluated
126         * @return none
127         */
128        @Override
129        public void setupConvenienceObjects() {
130    
131            // setup oldBenefitsCalculation convenience objects, make sure all possible sub-objects are populated
132            oldBenefitsCalculation = (BenefitsCalculation) super.getOldBo();
133    
134            // setup newBenefitsCalculation convenience objects, make sure all possible sub-objects are populated
135            newBenefitsCalculation = (BenefitsCalculation) super.getNewBo();
136        }
137    
138    }