001    /**
002     * Copyright 2005-2014 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.BusinessRule;
020    import org.kuali.rice.krad.rules.rule.SendAdHocRequestsRule;
021    import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
022    import org.kuali.rice.krad.service.KualiRuleService;
023    
024    import java.util.ArrayList;
025    import java.util.List;
026    
027    /**
028     * This is a description of what this class does - wliang don't forget to fill this in.
029     *
030     * @author Kuali Rice Team (rice.collab@kuali.org)
031     *
032     */
033    public class SendAdHocRequestsEvent extends KualiDocumentEventBase {
034    
035        public SendAdHocRequestsEvent(String errorPathPrefix, Document document) {
036            this("creating send adhoc requests event for document " + getDocumentId(document), errorPathPrefix, document);
037        }
038    
039        /**
040         * Constructs a SaveDocumentEvent with the given document
041         *
042         * @param document
043         */
044        public SendAdHocRequestsEvent(Document document) {
045            this("", document);
046        }
047    
048        public SendAdHocRequestsEvent(String description, String errorPathPrefix, Document document) {
049            super(description, errorPathPrefix, document);
050        }
051    
052            /**
053             * This overridden method ...
054             *
055             * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent#getRuleInterfaceClass()
056             */
057            public Class<? extends BusinessRule> getRuleInterfaceClass() {
058                    return SendAdHocRequestsRule.class;
059            }
060    
061            /**
062             * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent#invokeRuleMethod(org.kuali.rice.krad.rules.rule.BusinessRule)
063             */
064            public boolean invokeRuleMethod(BusinessRule rule) {
065                    return ((SendAdHocRequestsRule) rule).processSendAdHocRequests(document);
066            }
067    
068            /**
069             * @see org.kuali.rice.krad.rules.rule.event.KualiDocumentEventBase#generateEvents()
070             */
071            @Override
072            public List<KualiDocumentEvent> generateEvents() {
073                    KualiRuleService ruleService = KRADServiceLocatorWeb.getKualiRuleService();
074    
075                    List<KualiDocumentEvent> events = new ArrayList<KualiDocumentEvent>();
076            events.addAll(ruleService.generateAdHocRoutePersonEvents(getDocument()));
077            events.addAll(ruleService.generateAdHocRouteWorkgroupEvents(getDocument()));
078            return events;
079            }
080    }