1 /**
2 * Copyright 2005-2013 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
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.rice.krad.rules.rule.event;
17
18 import org.kuali.rice.krad.document.Document;
19 import org.kuali.rice.krad.rules.rule.BusinessRule;
20 import org.kuali.rice.krad.rules.rule.SaveDocumentRule;
21 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
22 import org.kuali.rice.krad.service.KualiRuleService;
23
24 import java.util.ArrayList;
25 import java.util.List;
26
27 /**
28 * This class represents the save event that is part of an eDoc in Kuali. This could be triggered when a user presses the save
29 * button for a given document or it could happen when another piece of code calls the save method in the document service.
30 *
31 *
32 */
33 public class SaveDocumentEvent extends KualiDocumentEventBase implements SaveEvent {
34 /**
35 * Constructs a SaveDocumentEvent with the specified errorPathPrefix and document
36 *
37 * @param document
38 * @param errorPathPrefix
39 */
40 public SaveDocumentEvent(String errorPathPrefix, Document document) {
41 this("creating save event for document " + getDocumentId(document), errorPathPrefix, document);
42 }
43
44 /**
45 * Constructs a SaveDocumentEvent with the given document
46 *
47 * @param document
48 */
49 public SaveDocumentEvent(Document document) {
50 this("", document);
51 }
52
53 /**
54 * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEventBase#KualiDocumentEventBase(java.lang.String, java.lang.String, org.kuali.rice.krad.document.Document)
55 */
56 public SaveDocumentEvent(String description, String errorPathPrefix, Document document) {
57 super(description, errorPathPrefix, document);
58 }
59
60 /**
61 * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent#getRuleInterfaceClass()
62 */
63 public Class<? extends BusinessRule> getRuleInterfaceClass() {
64 return SaveDocumentRule.class;
65 }
66
67 /**
68 * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent#invokeRuleMethod(org.kuali.rice.krad.rules.rule.BusinessRule)
69 */
70 public boolean invokeRuleMethod(BusinessRule rule) {
71 return ((SaveDocumentRule) rule).processSaveDocument(document);
72 }
73
74 /**
75 * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent#generateEvents()
76 */
77 @Override
78 public List<KualiDocumentEvent> generateEvents() {
79 KualiRuleService ruleService = KRADServiceLocatorWeb.getKualiRuleService();
80
81 List<KualiDocumentEvent> events = new ArrayList<KualiDocumentEvent>();
82 events.addAll(ruleService.generateAdHocRoutePersonEvents(getDocument()));
83 events.addAll(ruleService.generateAdHocRouteWorkgroupEvents(getDocument()));
84
85 events.addAll(getDocument().generateSaveEvents());
86
87 /*
88 if (getDocument() instanceof CashReceiptDocument) {
89 events.addAll(ruleService.generateCheckEvents((CashReceiptDocument) getDocument()));
90 }
91
92 if (getDocument() instanceof AccountingDocument) {
93 events.addAll(ruleService.generateAccountingLineEvents((AccountingDocument) getDocument()));
94 }
95 */
96 return events;
97 }
98 }