View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.rules.rule.event;
17  
18  import org.kuali.rice.krad.document.Document;
19  import org.kuali.rice.krad.rules.rule.AddCollectionLineRule;
20  import org.kuali.rice.krad.rules.rule.BusinessRule;
21  
22  /**
23   * Defines the add collection line event fired when a user adds a line in a collection in a document.
24   *
25   * @author Kuali Rice Team (rice.collab@kuali.org)
26   */
27  public class AddCollectionLineEvent extends DocumentEventBase {
28  
29      private String collectionName;
30      private Object addLine;
31  
32      /**
33       * Constructs an event for a document adding a line to the collection with the name {@code collectionName}.
34       *
35       * @param document the document containing the collection objects
36       * @param collectionName the name of the collection object
37       * @param addLine the object being added to the collection
38       */
39      public AddCollectionLineEvent(Document document, String collectionName, Object addLine) {
40          this("", document, collectionName, addLine);
41      }
42  
43      /**
44       * Constructs an event for a document adding a line to the collection with the name {@code collectionName} with a
45       * specific {@code errorPathPrefix}.
46       *
47       * @param errorPathPrefix the prefix to add to the error path for reporting messages
48       * @param document the document containing the collection objects
49       * @param collectionName the name of the collection object
50       * @param addLine the object being added to the collection
51       */
52      public AddCollectionLineEvent(String errorPathPrefix, Document document, String collectionName, Object addLine) {
53          this("approve", errorPathPrefix, document, collectionName, addLine);
54      }
55  
56      /**
57       * Constructs an event for a document adding a line to the collection with the name {@code collectionName} with a
58       * specific {@code errorPathPrefix} and {@code eventType}.
59       *
60       * @param eventType the name of the type of event
61       * @param errorPathPrefix the prefix to add to the error path for reporting messages
62       * @param document the document containing the collection objects
63       * @param collectionName the name of the collection object
64       * @param addLine the object being added to the collection
65       */
66      protected AddCollectionLineEvent(String eventType, String errorPathPrefix, Document document, String collectionName, Object addLine) {
67          super("creating " + eventType + " event for document " + DocumentEventBase.getDocumentId(document), errorPathPrefix, document);
68  
69          this.collectionName = collectionName;
70          this.addLine = addLine;
71      }
72  
73      /**
74       * {@inheritDoc}
75       *
76       * Specifies that this class returns the {@link AddCollectionLineRule} class.
77       */
78      @Override
79      public Class<AddCollectionLineRule> getRuleInterfaceClass() {
80          return AddCollectionLineRule.class;
81      }
82  
83      /**
84       * {@inheritDoc}
85       *
86       * Invokes the specific rule in {@link AddCollectionLineRule}.
87       */
88      @Override
89      public boolean invokeRuleMethod(BusinessRule rule) {
90          return ((AddCollectionLineRule) rule).processAddCollectionLine(this);
91      }
92  
93      /**
94       * The name of the collection being added to.
95       *
96       * @return the collection name
97       */
98      public String getCollectionName() {
99          return collectionName;
100     }
101 
102     /**
103      * The object being added to the collection.
104      *
105      * @return the added object
106      */
107     public Object getAddLine() {
108         return addLine;
109     }
110 
111 }