001    /**
002     * Copyright 2005-2012 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     */
016    package org.kuali.rice.krad.rules.rule.event;
017    
018    import org.kuali.rice.krad.document.Document;
019    import org.kuali.rice.krad.rules.rule.ApproveDocumentRule;
020    import org.kuali.rice.krad.rules.rule.BusinessRule;
021    
022    import java.util.ArrayList;
023    import java.util.List;
024    
025    /**
026     * This class represents the approve event that is part of an eDoc in Kuali. This could be triggered when a user presses the approve
027     * button for a given document enroute or it could happen when another piece of code calls the approve method in the document
028     * service.
029     * 
030     * 
031     */
032    public class ApproveDocumentEvent extends KualiDocumentEventBase {
033        /**
034         * Constructs an ApproveDocumentEvent with the specified errorPathPrefix and document
035         * 
036         * @param errorPathPrefix
037         * @param document
038         */
039        public ApproveDocumentEvent(String errorPathPrefix, Document document) {
040            this("approve", errorPathPrefix, document);
041        }
042    
043        /**
044         * Constructs an ApproveDocumentEvent with the given document
045         * 
046         * @param document
047         */
048        public ApproveDocumentEvent(Document document) {
049            this("approve", "", document);
050        }
051    
052        /**
053         * Constructs a ApproveDocumentEvent, allowing the eventType to be passed in so that subclasses can specify a more accurate
054         * message.
055         * 
056         * @param eventType
057         * @param errorPathPrefix
058         * @param document
059         */
060        protected ApproveDocumentEvent(String eventType, String errorPathPrefix, Document document) {
061            super("creating " + eventType + " event for document " + KualiDocumentEventBase.getDocumentId(document), errorPathPrefix, document);
062        }
063    
064    
065        /**
066         * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent#getRuleInterfaceClass()
067         */
068        public Class<? extends BusinessRule> getRuleInterfaceClass() {
069            return ApproveDocumentRule.class;
070        }
071    
072        /**
073         * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent#invokeRuleMethod(org.kuali.rice.krad.rules.rule.BusinessRule)
074         */
075        public boolean invokeRuleMethod(BusinessRule rule) {
076            return ((ApproveDocumentRule) rule).processApproveDocument(this);
077        }
078    
079        /**
080         * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent#generateEvents()
081         */
082        @Override
083        public List<KualiDocumentEvent> generateEvents() {
084            List<KualiDocumentEvent> events = new ArrayList<KualiDocumentEvent>();
085            events.add(new RouteDocumentEvent(getDocument()));
086            return events;
087        }
088    }