View Javadoc
1   /**
2    * Copyright 2005-2014 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   * Rule event generated for a save of a document instance.
29   *
30   * <p>This could be triggered when a user presses the save button for a given document or it could
31   * happen when another piece of code calls the save method in the document service.</p>
32   *
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  public class SaveDocumentEvent extends DocumentEventBase implements SaveEvent {
36  
37      /**
38       * Constructs a SaveDocumentEvent with the specified errorPathPrefix and document
39       *
40       * @param document
41       * @param errorPathPrefix
42       */
43      public SaveDocumentEvent(String errorPathPrefix, Document document) {
44          this("creating save event for document " + getDocumentId(document), errorPathPrefix, document);
45      }
46  
47      /**
48       * Constructs a SaveDocumentEvent with the given document
49       *
50       * @param document
51       */
52      public SaveDocumentEvent(Document document) {
53          this("", document);
54      }
55  
56      /**
57       * @see org.kuali.rice.krad.rules.rule.event.DocumentEventBase#DocumentEventBase(java.lang.String,
58       * java.lang.String, org.kuali.rice.krad.document.Document)
59       */
60      public SaveDocumentEvent(String description, String errorPathPrefix, Document document) {
61          super(description, errorPathPrefix, document);
62      }
63  
64      /**
65       * @see org.kuali.rice.krad.rules.rule.event.RuleEvent#getRuleInterfaceClass()
66       */
67      public Class<? extends BusinessRule> getRuleInterfaceClass() {
68          return SaveDocumentRule.class;
69      }
70  
71      /**
72       * @see org.kuali.rice.krad.rules.rule.event.RuleEvent#invokeRuleMethod(org.kuali.rice.krad.rules.rule.BusinessRule)
73       */
74      public boolean invokeRuleMethod(BusinessRule rule) {
75          return ((SaveDocumentRule) rule).processSaveDocument(document);
76      }
77  
78      /**
79       * @see org.kuali.rice.krad.rules.rule.event.RuleEvent#generateEvents()
80       */
81      @Override
82      public List<RuleEvent> generateEvents() {
83          KualiRuleService ruleService = KRADServiceLocatorWeb.getKualiRuleService();
84  
85          List<RuleEvent> events = new ArrayList<RuleEvent>();
86          events.addAll(ruleService.generateAdHocRoutePersonEvents(getDocument()));
87          events.addAll(ruleService.generateAdHocRouteWorkgroupEvents(getDocument()));
88  
89          events.addAll(getDocument().generateSaveEvents());
90  
91          return events;
92      }
93  }