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.document.Document;
019import org.kuali.rice.krad.rules.rule.BusinessRule;
020import org.kuali.rice.krad.rules.rule.RouteDocumentRule;
021
022import java.util.ArrayList;
023import java.util.List;
024
025/**
026 * This class represents the route event that is part of an eDoc in Kuali. This could be triggered when a user presses the route
027 * button for a given document or it could happen when another piece of code calls the route method in the document service.
028 * 
029 * 
030 */
031public final class RouteDocumentEvent extends KualiDocumentEventBase {
032    /**
033     * Constructs a RouteDocumentEvent with the specified errorPathPrefix and document
034     * 
035     * @param errorPathPrefix
036     * @param document
037     */
038    public RouteDocumentEvent(String errorPathPrefix, Document document) {
039        super("creating route event for document " + getDocumentId(document), errorPathPrefix, document);
040    }
041
042    /**
043     * Constructs a RouteDocumentEvent with the given document
044     * 
045     * @param document
046     */
047    public RouteDocumentEvent(Document document) {
048        this("", document);
049    }
050
051    /**
052     * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent#getRuleInterfaceClass()
053     */
054    public Class<? extends BusinessRule> getRuleInterfaceClass() {
055        return RouteDocumentRule.class;
056    }
057
058    /**
059     * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent#invokeRuleMethod(org.kuali.rice.krad.rules.rule.BusinessRule)
060     */
061    public boolean invokeRuleMethod(BusinessRule rule) {
062        return ((RouteDocumentRule) rule).processRouteDocument(document);
063    }
064
065    /**
066     * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent#generateEvents()
067     */
068    @Override
069    public List<KualiDocumentEvent> generateEvents() {
070        List<KualiDocumentEvent> events = new ArrayList<KualiDocumentEvent>();
071        events.add(new SaveDocumentEvent(getDocument()));
072        return events;
073    }
074}