01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.module.kra.budget.rules;
17:
18: import org.kuali.core.document.MaintenanceDocument;
19: import org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase;
20: import org.kuali.core.util.GlobalVariables;
21: import org.kuali.core.util.KualiDecimal;
22: import org.kuali.module.kra.KraKeyConstants;
23: import org.kuali.module.kra.KraPropertyConstants;
24: import org.kuali.module.kra.budget.bo.IndirectCostLookup;
25:
26: /**
27: * This class...
28: */
29: public class IndirectCostLookupRule extends MaintenanceDocumentRuleBase {
30: protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
31: .getLogger(IndirectCostLookupRule.class);
32:
33: private IndirectCostLookup icLookup;
34:
35: /**
36: * This method performs any necessary custom business rules on the document.
37: *
38: * @param document An instance of the maintenance document that is being processed.
39: * @return True if all the business rule checks succeed, false otherwise.
40: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
41: */
42: @Override
43: protected boolean processCustomSaveDocumentBusinessRules(
44: MaintenanceDocument document) {
45: boolean success = true;
46:
47: setupConvenienceObjects();
48:
49: success &= super
50: .processCustomSaveDocumentBusinessRules(document);
51: success &= validateIndirectCostRate(icLookup);
52:
53: return true;
54: }
55:
56: private boolean validateIndirectCostRate(IndirectCostLookup icLookup) {
57: boolean success = true;
58:
59: KualiDecimal rate = icLookup.getBudgetIndirectCostRate();
60: String costRate = null == rate ? "" : rate.toString();
61: // If the cost rate value does not already contain a decimal and two zeros, append them.
62: if (costRate.indexOf('.') < 0) {
63: costRate = costRate + ".00";
64: }
65: // If the cost rate value is longer than 6 characters, display an error message
66: if (costRate.length() > 6) {
67: String[] params = { costRate };
68: String propertyName = KraPropertyConstants.DOCUMENT + "."
69: + KraPropertyConstants.NEW_MAINTAINABLE_OBJECT
70: + "." + KraPropertyConstants.COST_RATE;
71: GlobalVariables.getErrorMap().putError(propertyName,
72: KraKeyConstants.ERROR_INDIRECT_COST_RATE_MALFORMED,
73: params);
74: success = false;
75: }
76:
77: return success;
78: }
79:
80: /**
81: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#setupConvenienceObjects()
82: */
83: @Override
84: public void setupConvenienceObjects() {
85: icLookup = (IndirectCostLookup) super.getNewBo();
86: }
87:
88: }
|