View Javadoc
1   /*
2    * Copyright 2008 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.ole.sys.document.datadictionary;
17  
18  import java.util.Comparator;
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.kuali.ole.sys.businessobject.AccountingLine;
23  import org.kuali.ole.sys.document.AccountingDocument;
24  import org.kuali.ole.sys.document.authorization.AccountingLineAuthorizer;
25  import org.kuali.ole.sys.document.web.DefaultAccountingLineGroupImpl;
26  import org.kuali.ole.sys.document.web.RenderableAccountingLineContainer;
27  import org.kuali.rice.krad.datadictionary.DataDictionaryDefinitionBase;
28  import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
29  
30  /**
31   * Data dictionary definition that includes metadata for an accounting document about one of its groups of accounting lines (typically source vs. target, but this should open things up).
32   */
33  public class AccountingLineGroupDefinition extends DataDictionaryDefinitionBase {
34      private String groupLabel;
35      private Class<? extends AccountingLine> accountingLineClass;
36      private AccountingLineViewDefinition accountingLineView;
37      private String importedLinePropertyPrefix;
38      private List<? extends TotalDefinition> totals;
39      private Class<? extends AccountingLineAuthorizer> accountingLineAuthorizerClass;
40      private int forceColumnCount = -1;
41      private String errorKey;
42      private boolean topHeadersAfterFirstLineHiding = true;
43      private boolean headerRendering = true;
44      private boolean importingAllowed = true;
45      private Class<? extends DefaultAccountingLineGroupImpl> accountingLineGroupClass = org.kuali.ole.sys.document.web.DefaultAccountingLineGroupImpl.class;
46      private Class<? extends Comparator<AccountingLine>> accountingLineComparatorClass = org.kuali.ole.sys.businessobject.AccountingLineComparator.class;
47      
48      private List<? extends AccountingLineViewActionDefinition> accountingLineGroupActions;
49      
50      private AccountingLineAuthorizer accountingLineAuthorizer;
51  
52      /**
53       * Validates that:
54       * 1) this accounting line group has an accounting line class
55       * 2) this accounting line group has an accounting line view 
56       * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Class)
57       */
58      public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
59          if (accountingLineClass == null) {
60              throw new AttributeValidationException("Please specify an accounting line class for AccountingLineGroup "+getId());
61          }
62          if (accountingLineView == null) {
63              throw new AttributeValidationException("Please specify an accountingLineView for AccountingLineGroup "+getId());
64          }
65      }
66  
67      /**
68       * Gets the accountingLineClass attribute. 
69       * @return Returns the accountingLineClass.
70       */
71      public Class<? extends AccountingLine> getAccountingLineClass() {
72          return accountingLineClass;
73      }
74  
75      /**
76       * Sets the accountingLineClass attribute value.
77       * @param accountingLineClass The accountingLineClass to set.
78       */
79      public void setAccountingLineClass(Class<? extends AccountingLine> accountingLineClass) {
80          this.accountingLineClass = accountingLineClass;
81      }
82  
83      /**
84       * Gets the accountingLineView attribute. 
85       * @return Returns the accountingLineView.
86       */
87      public AccountingLineViewDefinition getAccountingLineView() {
88          return accountingLineView;
89      }
90  
91      /**
92       * Sets the accountingLineView attribute value.
93       * @param accountingLineView The accountingLineView to set.
94       */
95      public void setAccountingLineView(AccountingLineViewDefinition accountingLineView) {
96          this.accountingLineView = accountingLineView;
97      }
98  
99      /**
100      * Gets the groupLabel attribute. 
101      * @return Returns the groupLabel.
102      */
103     public String getGroupLabel() {
104         return (groupLabel == null) ? "" : groupLabel;
105     }
106 
107     /**
108      * Sets the groupLabel attribute value.
109      * @param groupLabel The groupLabel to set.
110      */
111     public void setGroupLabel(String groupLabel) {
112         this.groupLabel = groupLabel;
113     }
114 
115     /**
116      * Gets the totals attribute. 
117      * @return Returns the totals.
118      */
119     public List<? extends TotalDefinition> getTotals() {
120         return totals;
121     }
122 
123     /**
124      * Sets the totals attribute value.
125      * @param totals The totals to set.
126      */
127     public void setTotals(List<? extends TotalDefinition> totals) {
128         this.totals = totals;
129     }
130 
131     /**
132      * Gets the accountingLineAuthorizerClass attribute. 
133      * @return Returns the accountingLineAuthorizerClass.
134      */
135     public Class<? extends AccountingLineAuthorizer> getAccountingLineAuthorizerClass() {
136         return accountingLineAuthorizerClass;
137     }
138 
139     /**
140      * Sets the accountingLineAuthorizerClass attribute value.
141      * @param accountingLineAuthorizerClass The accountingLineAuthorizerClass to set.
142      */
143     public void setAccountingLineAuthorizerClass(Class<? extends AccountingLineAuthorizer> accountingLineAuthorizerClass) {
144         this.accountingLineAuthorizerClass = accountingLineAuthorizerClass;
145     }
146     
147     /**
148      * Gets the importedLinePropertyPrefix attribute. 
149      * @return Returns the importedLinePropertyPrefix.
150      */
151     public String getImportedLinePropertyPrefix() {
152         return importedLinePropertyPrefix;
153     }
154 
155     /**
156      * Sets the importedLinePropertyPrefix attribute value.
157      * @param importedLinePropertyPrefix The importedLinePropertyPrefix to set.
158      */
159     public void setImportedLinePropertyPrefix(String importedLinePropertyPrefix) {
160         this.importedLinePropertyPrefix = importedLinePropertyPrefix;
161     }
162 
163     /**
164      * Gets the forceColumnCount attribute. 
165      * @return Returns the forceColumnCount.
166      */
167     public int getForceColumnCount() {
168         return forceColumnCount;
169     }
170 
171     /**
172      * Sets the forceColumnCount attribute value.
173      * @param forceColumnCount The forceColumnCount to set.
174      */
175     public void setForceColumnCount(int forceColumnCount) {
176         this.forceColumnCount = forceColumnCount;
177     }
178 
179     /**
180      * Gets the errorKey attribute. 
181      * @return Returns the errorKey.
182      */
183     public String getErrorKey() {
184         return errorKey;
185     }
186 
187     /**
188      * Sets the errorKey attribute value.
189      * @param errorKey The errorKey to set.
190      */
191     public void setErrorKey(String errorKey) {
192         this.errorKey = errorKey;
193     }
194 
195     /**
196      * Returns an instance of the accounting line authorizer for this group
197      * @return an instance of the accounting line authorizer
198      */
199     public AccountingLineAuthorizer getAccountingLineAuthorizer() {
200         if (accountingLineAuthorizer == null) {
201             accountingLineAuthorizer = createAccountingLineAuthorizer();
202         }
203         return accountingLineAuthorizer;
204     }
205     
206     /**
207      * Creates an instance of the accounting line authorizer
208      * @return the accounting line authorizer for this group
209      */
210     protected AccountingLineAuthorizer createAccountingLineAuthorizer() {
211         Class<? extends AccountingLineAuthorizer> authorizerClass = getAccountingLineAuthorizerClass();
212         AccountingLineAuthorizer authorizer = null;
213         try {
214             authorizer = authorizerClass.newInstance();
215         }
216         catch (InstantiationException ie) {
217             throw new IllegalArgumentException("InstantiationException while attempting to instantiate AccountingLineAuthorization class", ie);
218         }
219         catch (IllegalAccessException iae) {
220             throw new IllegalArgumentException("IllegalAccessException while attempting to instantiate AccountingLineAuthorization class", iae);
221         }
222         return authorizer;
223     }
224 
225     /**
226      * Gets the topHeadersAfterFirstLineHiding attribute. 
227      * @return Returns the topHeadersAfterFirstLineHiding.
228      */
229     public boolean isTopHeadersAfterFirstLineHiding() {
230         return topHeadersAfterFirstLineHiding;
231     }
232 
233     /**
234      * Sets the topHeadersAfterFirstLineHiding attribute value.
235      * @param topHeadersAfterFirstLineHiding The topHeadersAfterFirstLineHiding to set.
236      */
237     public void setTopHeadersAfterFirstLineHiding(boolean showTopHeadersAfterFirstLine) {
238         this.topHeadersAfterFirstLineHiding = showTopHeadersAfterFirstLine;
239     }
240 
241     /**
242      * Gets the headerRendering attribute. 
243      * @return Returns the headerRendering.
244      */
245     public boolean isHeaderRendering() {
246         return headerRendering;
247     }
248 
249     /**
250      * Sets the headerRendering attribute value.
251      * @param headerRendering The headerRendering to set.
252      */
253     public void setHeaderRendering(boolean headerRendering) {
254         this.headerRendering = headerRendering;
255     }
256 
257     /**
258      * Gets the accountingLineGroupActions attribute. 
259      * @return Returns the accountingLineGroupActions.
260      */
261     public List<? extends AccountingLineViewActionDefinition> getAccountingLineGroupActions() {
262         return accountingLineGroupActions;
263     }
264 
265     /**
266      * Sets the accountingLineGroupActions attribute value.
267      * @param accountingLineGroupActions The accountingLineGroupActions to set.
268      */
269     public void setAccountingLineGroupActions(List<? extends AccountingLineViewActionDefinition> accountingLineGroupActions) {
270         this.accountingLineGroupActions = accountingLineGroupActions;
271     }
272 
273     /**
274      * Gets the importingAllowed attribute. 
275      * @return Returns the importingAllowed.
276      */
277     public boolean isImportingAllowed() {
278         return importingAllowed;
279     }
280 
281     /**
282      * Sets the importingAllowed attribute value.
283      * @param importingAllowed The importingAllowed to set.
284      */
285     public void setImportingAllowed(boolean importingAllowed) {
286         this.importingAllowed = importingAllowed;
287     }
288 
289     /**
290      * Gets the accountingLineGroupClass attribute. 
291      * @return Returns the accountingLineGroupClass.
292      */
293     public Class<? extends DefaultAccountingLineGroupImpl> getAccountingLineGroupClass() {
294         return accountingLineGroupClass;
295     }
296 
297     /**
298      * Sets the accountingLineGroupClass attribute value.
299      * @param accountingLineGroupClass The accountingLineGroupClass to set.
300      */
301     public void setAccountingLineGroupClass(Class<? extends DefaultAccountingLineGroupImpl> accountingLineGroupClass) {
302         this.accountingLineGroupClass = accountingLineGroupClass;
303     }
304     
305     /**
306      * Sets the accountingLineComparatorClass attribute value.
307      * @param accountingLineComparatorClass The accountingLineComparatorClass to set.
308      */
309     public void setAccountingLineComparatorClass(Class<? extends Comparator<AccountingLine>> accountingLineComparatorClass) {
310         this.accountingLineComparatorClass = accountingLineComparatorClass;
311     }
312     
313     /**
314      * @return an instance of the Comparator this group should use to sort accounting lines
315      */
316     public Comparator<AccountingLine> getAccountingLineComparator() {
317         Comparator<AccountingLine> comparator = null;
318         try {
319             comparator = accountingLineComparatorClass.newInstance();
320         }
321         catch (InstantiationException ie) {
322             throw new RuntimeException("Could not instantiate class for AccountingLineComparator for group", ie);
323         }
324         catch (IllegalAccessException iae) {
325             throw new RuntimeException("Illegal access attempting to instantiate class for AccountingLineComparator for group", iae);
326         }
327         return comparator;
328     }
329 
330     /**
331      * Creates a new accounting line group for this definition
332      * @param accountingDocument the document which owns or will own the accounting line being rendered
333      * @param containers the containers within this group
334      * @param collectionPropertyName the property name of the collection of accounting lines owned by this group
335      * @param errors a List of errors keys for errors on the page
336      * @param displayedErrors a Map of errors that have already been displayed
337      * @param canEdit determines if the page can be edited or not
338      * @return a newly created and initialized accounting line group
339      */
340     public DefaultAccountingLineGroupImpl createAccountingLineGroup(AccountingDocument accountingDocument, List<RenderableAccountingLineContainer> containers, String collectionPropertyName, String collectionItemPropertyName, Map<String, Object> displayedErrors, Map<String, Object> displayedWarnings, Map<String, Object> displayedInfo, boolean canEdit) {
341         DefaultAccountingLineGroupImpl accountingLineGroup = null;
342         try {
343             accountingLineGroup = getAccountingLineGroupClass().newInstance();
344             accountingLineGroup.initialize(this, accountingDocument, containers, collectionPropertyName, collectionItemPropertyName, displayedErrors, displayedWarnings, displayedInfo, canEdit);
345         }
346         catch (InstantiationException ie) {
347             throw new RuntimeException("Could not initialize new AccountingLineGroup implementation of class: "+getAccountingLineGroupClass().getName(), ie);
348         }
349         catch (IllegalAccessException iae) {
350             throw new RuntimeException("Could not initialize new AccountingLineGroup implementation of class: "+getAccountingLineGroupClass().getName(), iae);
351         }
352         return accountingLineGroup;
353     }
354 }