1 /*
2 * Copyright 2007 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.kns.rule.event;
17
18 import org.kuali.rice.kns.bo.Note;
19 import org.kuali.rice.kns.document.Document;
20 import org.kuali.rice.kns.rule.AddNoteRule;
21 import org.kuali.rice.kns.rule.BusinessRule;
22 import org.kuali.rice.kns.util.ObjectUtils;
23
24 /**
25 * 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
26 * for a given note or it could happen when another piece of code calls the create note method in the document service.
27 *
28 *
29 */
30 public final class AddNoteEvent extends KualiDocumentEventBase {
31 private Note note;
32
33 /**
34 * Constructs an AddNoteEvent with the specified errorPathPrefix and document
35 *
36 * @param document
37 * @param errorPathPrefix
38 */
39 public AddNoteEvent(String errorPathPrefix, Document document, Note note) {
40 super("creating add note event for document " + getDocumentId(document), errorPathPrefix, document);
41 this.note = note;
42 }
43
44 /**
45 * Constructs an AddNoteEvent with the given document
46 *
47 * @param document
48 */
49 public AddNoteEvent(Document document, Note note) {
50 this("", document, note);
51 }
52
53 /**
54 * This method retrieves the note associated with this event.
55 *
56 * @return
57 */
58 public Note getNote() {
59 return note;
60 }
61
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.kns.rule.event.KualiDocumentEvent#getRuleInterfaceClass()
71 */
72 public Class getRuleInterfaceClass() {
73 return AddNoteRule.class;
74 }
75
76 /**
77 * @see org.kuali.rice.kns.rule.event.KualiDocumentEvent#invokeRuleMethod(org.kuali.rice.kns.rule.BusinessRule)
78 */
79 public boolean invokeRuleMethod(BusinessRule rule) {
80 return ((AddNoteRule) rule).processAddNote(getDocument(), getNote());
81 }
82 }