View Javadoc
1   /**
2    * Copyright 2005-2016 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.bo.Note;
19  import org.kuali.rice.krad.document.Document;
20  import org.kuali.rice.krad.rules.rule.AddNoteRule;
21  import org.kuali.rice.krad.rules.rule.BusinessRule;
22  
23  /**
24   * This class represents the add note event that is part of an eDoc in Kuali. This is triggered when a user presses the add button
25   * for a given note or it could happen when another piece of code calls the create note method in the document service.
26   *
27   *
28   */
29  public final class AddNoteEvent extends DocumentEventBase {
30      private Note note;
31  
32      /**
33       * Constructs an AddNoteEvent with the specified errorPathPrefix and document
34       *
35       * @param document
36       * @param errorPathPrefix
37       */
38      public AddNoteEvent(String errorPathPrefix, Document document, Note note) {
39          super("creating add note event for document " + DocumentEventBase.getDocumentId(document), errorPathPrefix, document);
40          this.note = note;
41      }
42  
43      /**
44       * Constructs an AddNoteEvent with the given document
45       *
46       * @param document
47       */
48      public AddNoteEvent(Document document, Note note) {
49          this("", document, note);
50      }
51  
52      /**
53       * This method retrieves the note associated with this event.
54       *
55       * @return note
56       */
57      public Note getNote() {
58          return note;
59      }
60  
61      @Override
62      public void validate() {
63          super.validate();
64          if (getNote() == null) {
65              throw new IllegalArgumentException("invalid (null) note");
66          }
67      }
68  
69      /**
70       * @see org.kuali.rice.krad.rules.rule.event.RuleEvent#getRuleInterfaceClass()
71       */
72      public Class<? extends BusinessRule> getRuleInterfaceClass() {
73          return AddNoteRule.class;
74      }
75  
76      /**
77       * @see org.kuali.rice.krad.rules.rule.event.RuleEvent#invokeRuleMethod(org.kuali.rice.krad.rules.rule.BusinessRule)
78       */
79      public boolean invokeRuleMethod(BusinessRule rule) {
80          return ((AddNoteRule) rule).processAddNote(getDocument(), getNote());
81      }
82  }