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