001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.rules.rule.event;
017
018import org.kuali.rice.krad.bo.Note;
019import org.kuali.rice.krad.document.Document;
020import org.kuali.rice.krad.rules.rule.AddNoteRule;
021import org.kuali.rice.krad.rules.rule.BusinessRule;
022
023/**
024 * 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
025 * for a given note or it could happen when another piece of code calls the create note method in the document service.
026 * 
027 * 
028 */
029public final class AddNoteEvent extends KualiDocumentEventBase {
030    private Note note;
031
032    /**
033     * Constructs an AddNoteEvent with the specified errorPathPrefix and document
034     * 
035     * @param document
036     * @param errorPathPrefix
037     */
038    public AddNoteEvent(String errorPathPrefix, Document document, Note note) {
039        super("creating add note event for document " + KualiDocumentEventBase.getDocumentId(document), errorPathPrefix, document);
040        this.note = note;
041    }
042
043    /**
044     * Constructs an AddNoteEvent with the given document
045     * 
046     * @param document
047     */
048    public AddNoteEvent(Document document, Note note) {
049        this("", document, note);
050    }
051
052    /**
053     * This method retrieves the note associated with this event.
054     * 
055     * @return
056     */
057    public Note getNote() {
058        return note;
059    }
060
061    @Override
062    public void validate() {
063        super.validate();
064        if (getNote() == null) {
065            throw new IllegalArgumentException("invalid (null) note");
066        }
067    }
068
069    /**
070     * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent#getRuleInterfaceClass()
071     */
072    public Class<? extends BusinessRule> getRuleInterfaceClass() {
073        return AddNoteRule.class;
074    }
075
076    /**
077     * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent#invokeRuleMethod(org.kuali.rice.krad.rules.rule.BusinessRule)
078     */
079    public boolean invokeRuleMethod(BusinessRule rule) {
080        return ((AddNoteRule) rule).processAddNote(getDocument(), getNote());
081    }
082}