01: /*
02: * Copyright 2006-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.chart.rules;
17:
18: import javax.servlet.http.HttpServletRequest;
19:
20: import org.apache.struts.action.ActionForm;
21: import org.kuali.core.document.MaintenanceDocument;
22: import org.kuali.core.rule.PreRulesCheck;
23: import org.kuali.core.rule.event.PreRulesCheckEvent;
24: import org.kuali.core.util.KualiDecimal;
25: import org.kuali.core.util.ObjectUtils;
26: import org.kuali.module.chart.bo.Delegate;
27:
28: /**
29: * PreRules checks for the {@link Delegate} that needs to occur while still in the Struts processing. This includes defaults
30: */
31: public class DelegatePreRules implements PreRulesCheck {
32:
33: protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
34: .getLogger(DelegatePreRules.class);
35:
36: /**
37: * Default no-args constructor.
38: */
39: public DelegatePreRules() {
40: }
41:
42: /**
43: * This method sets some defaults on the {@link Delegate}
44: *
45: * @see org.kuali.core.rule.PreRulesCheck#processPreRuleChecks(org.apache.struts.action.ActionForm,
46: * javax.servlet.http.HttpServletRequest, org.kuali.core.rule.event.PreRulesCheckEvent)
47: */
48: public boolean processPreRuleChecks(ActionForm form,
49: HttpServletRequest request, PreRulesCheckEvent event) {
50: LOG.info("Entering processPreRuleChecks");
51:
52: // create some references to the relevant objects being looked at
53: MaintenanceDocument document = (MaintenanceDocument) event
54: .getDocument();
55: Delegate delegate = (Delegate) document
56: .getNewMaintainableObject().getBusinessObject();
57:
58: // set the defaults on the document
59: setUnconditionalDefaults(delegate);
60:
61: return true;
62: }
63:
64: /**
65: * This method sets the approval from and to amounts to "0"
66: *
67: * @param delegate
68: */
69: private void setUnconditionalDefaults(Delegate delegate) {
70:
71: // FROM amount defaults to zero
72: if (ObjectUtils.isNull(delegate.getFinDocApprovalFromThisAmt())) {
73: delegate.setFinDocApprovalFromThisAmt(new KualiDecimal(0));
74: }
75:
76: // TO amount defaults to zero
77: if (ObjectUtils
78: .isNull(delegate.getFinDocApprovalToThisAmount())) {
79: delegate.setFinDocApprovalToThisAmount(new KualiDecimal(0));
80: }
81: }
82:
83: }
|