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.kfs.rule.event;
17:
18: import java.util.List;
19:
20: import org.kuali.core.document.Document;
21: import org.kuali.core.document.TransactionalDocument;
22: import org.kuali.core.rule.BusinessRule;
23: import org.kuali.core.rule.event.KualiDocumentEventBase;
24: import org.kuali.core.util.GlobalVariables;
25: import org.kuali.kfs.KFSKeyConstants;
26: import org.kuali.kfs.context.SpringContext;
27: import org.kuali.kfs.document.GeneralLedgerPostingDocument;
28: import org.kuali.kfs.rule.SufficientFundsCheckingPreparationRule;
29: import org.kuali.module.gl.service.SufficientFundsService;
30: import org.kuali.module.gl.util.SufficientFundsItem;
31:
32: /**
33: * This class represents the Sufficient Funds Checking Preparation event that is part of an eDoc in Kuali. This is triggered on
34: * route or approval
35: */
36: public final class SufficientFundsCheckingPreparationEvent extends
37: KualiDocumentEventBase {
38: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
39: .getLogger(SufficientFundsCheckingPreparationEvent.class);
40:
41: public SufficientFundsCheckingPreparationEvent(
42: String errorPathPrefix, Document document) {
43: super (
44: "creating sufficient funds checking preparation event for "
45: + getDocumentId(document), errorPathPrefix,
46: document);
47: }
48:
49: public SufficientFundsCheckingPreparationEvent(
50: TransactionalDocument document) {
51: this ("", document);
52: }
53:
54: /**
55: * @see org.kuali.core.rule.event.KualiDocumentEvent#getRuleInterfaceClass()
56: */
57: public Class getRuleInterfaceClass() {
58: return SufficientFundsCheckingPreparationRule.class;
59: }
60:
61: /**
62: * @see org.kuali.core.rule.event.KualiDocumentEvent#invokeRuleMethod(org.kuali.core.rule.BusinessRule)
63: */
64: public boolean invokeRuleMethod(BusinessRule rule) {
65: LOG.debug("invokeRuleMethod() started");
66:
67: if (document instanceof GeneralLedgerPostingDocument) {
68: LOG.debug("invokeRuleMethod() gl document");
69:
70: GeneralLedgerPostingDocument doc = (GeneralLedgerPostingDocument) document;
71:
72: SufficientFundsService sufficientFundsService = SpringContext
73: .getBean(SufficientFundsService.class);
74:
75: List<SufficientFundsItem> items = sufficientFundsService
76: .checkSufficientFunds(doc);
77:
78: // if ( items.size() > 0 ) {
79: LOG.error("invokeRuleMethod() No sufficient funds");
80:
81: GlobalVariables.getErrorMap().putError("chartOrg",
82: KFSKeyConstants.ERROR_MISSING,
83: new String[] { "Sufficient Funds" });
84:
85: return false;
86: // }
87: }
88: return true;
89: }
90: }
|