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.AdHocRouteWorkgroup;
019import org.kuali.rice.krad.document.Document;
020import org.kuali.rice.krad.rules.rule.AddAdHocRouteWorkgroupRule;
021import org.kuali.rice.krad.rules.rule.BusinessRule;
022
023/**
024 * This class represents the add AdHocRouteWorkgroup event that is part of an eDoc in Kuali. This is triggered when a user presses
025 * the add button for a given adHocRouteWorkgroup.
026 *
027 *
028 */
029public final class AddAdHocRouteWorkgroupEvent extends KualiDocumentEventBase {
030    private AdHocRouteWorkgroup adHocRouteWorkgroup;
031
032    /**
033     * Constructs an AddAdHocRouteWorkgroupEvent with the specified errorPathPrefix, document, and adHocRouteWorkgroup
034     *
035     * @param document
036     * @param adHocRouteWorkgroup
037     * @param errorPathPrefix
038     */
039    public AddAdHocRouteWorkgroupEvent(String errorPathPrefix, Document document, AdHocRouteWorkgroup adHocRouteWorkgroup) {
040        super("creating add ad hoc route workgroup event for document " + KualiDocumentEventBase.getDocumentId(document), errorPathPrefix, document);
041        this.adHocRouteWorkgroup = adHocRouteWorkgroup;
042    }
043
044    /**
045     * Constructs an AddAdHocRouteWorkgroupEvent with the given document
046     *
047     * @param document
048     * @param adHocRouteWorkgroup
049     */
050    public AddAdHocRouteWorkgroupEvent(Document document, AdHocRouteWorkgroup adHocRouteWorkgroup) {
051        this("", document, adHocRouteWorkgroup);
052    }
053
054    /**
055     * This method retrieves the document adHocRouteWorkgroup associated with this event.
056     *
057     * @return AdHocRouteWorkgroup
058     */
059    public AdHocRouteWorkgroup getAdHocRouteWorkgroup() {
060        return adHocRouteWorkgroup;
061    }
062
063    /**
064     * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent#validate()
065     */
066    @Override
067    public void validate() {
068        super.validate();
069        if (this.adHocRouteWorkgroup == null) {
070            throw new IllegalArgumentException("invalid (null) document adHocRouteWorkgroup");
071        }
072    }
073
074    /**
075     * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent#getRuleInterfaceClass()
076     */
077    public Class<? extends BusinessRule> getRuleInterfaceClass() {
078        return AddAdHocRouteWorkgroupRule.class;
079    }
080
081    /**
082     * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent#invokeRuleMethod(org.kuali.rice.krad.rules.rule.BusinessRule)
083     */
084    public boolean invokeRuleMethod(BusinessRule rule) {
085        return ((AddAdHocRouteWorkgroupRule) rule).processAddAdHocRouteWorkgroup(getDocument(), this.adHocRouteWorkgroup);
086    }
087}