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.chart.rules;
017:
018: import javax.servlet.http.HttpServletRequest;
019:
020: import org.apache.struts.action.ActionForm;
021: import org.kuali.core.document.MaintenanceDocument;
022: import org.kuali.core.rule.PreRulesCheck;
023: import org.kuali.core.rule.event.PreRulesCheckEvent;
024: import org.kuali.core.util.KualiDecimal;
025: import org.kuali.core.util.ObjectUtils;
026: import org.kuali.module.chart.bo.DelegateGlobal;
027: import org.kuali.module.chart.bo.DelegateGlobalDetail;
028:
029: /**
030: * This class executes specific pre-rules for the {@link DelegateGlobalMaintenanceDocument}
031: */
032: public class DelegateGlobalPreRules implements PreRulesCheck {
033:
034: protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
035: .getLogger(DelegatePreRules.class);
036:
037: public DelegateGlobalPreRules() {
038: super ();
039: }
040:
041: /**
042: * This sets some defaults on the {@link DelegateGlobal} object
043: *
044: * @see org.kuali.core.rule.PreRulesCheck#processPreRuleChecks(org.apache.struts.action.ActionForm,
045: * javax.servlet.http.HttpServletRequest, org.kuali.core.rule.event.PreRulesCheckEvent)
046: */
047: public boolean processPreRuleChecks(ActionForm form,
048: HttpServletRequest request, PreRulesCheckEvent event) {
049: LOG.info("Entering processPreRuleChecks");
050:
051: // create some references to the relevant objects being looked at
052: MaintenanceDocument document = (MaintenanceDocument) event
053: .getDocument();
054: DelegateGlobal newDelegateGlobal = (DelegateGlobal) document
055: .getNewMaintainableObject().getBusinessObject();
056:
057: // set the defaults on the document
058:
059: setUnconditionalDefaults(newDelegateGlobal);
060:
061: return true;
062: }
063:
064: /**
065: * This method checks to see if a string is empty or not
066: *
067: * @param s
068: * @return
069: */
070: private boolean empty(String s) {
071: if (s == null)
072: return true;
073: return s.length() == 0;
074: }
075:
076: /**
077: * This method sets the approval from and to amount to "0"
078: *
079: * @param newDelegateGlobal
080: */
081: private void setUnconditionalDefaults(
082: DelegateGlobal newDelegateGlobal) {
083:
084: for (DelegateGlobalDetail newDelegateGlobalDetail : newDelegateGlobal
085: .getDelegateGlobals()) {
086: // FROM amount defaults to zero
087: if (ObjectUtils.isNull(newDelegateGlobalDetail
088: .getApprovalFromThisAmount())) {
089: newDelegateGlobalDetail
090: .setApprovalFromThisAmount(new KualiDecimal(0));
091: }
092:
093: // TO amount defaults to zero
094: if (ObjectUtils.isNull(newDelegateGlobalDetail
095: .getApprovalToThisAmount())) {
096: newDelegateGlobalDetail
097: .setApprovalToThisAmount(new KualiDecimal(0));
098: }
099: }
100:
101: }
102: }
|