001/* 002 * Copyright 2008 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.ole.sys.document.datadictionary; 017 018import java.util.Comparator; 019import java.util.List; 020import java.util.Map; 021 022import org.kuali.ole.sys.businessobject.AccountingLine; 023import org.kuali.ole.sys.document.AccountingDocument; 024import org.kuali.ole.sys.document.authorization.AccountingLineAuthorizer; 025import org.kuali.ole.sys.document.web.DefaultAccountingLineGroupImpl; 026import org.kuali.ole.sys.document.web.RenderableAccountingLineContainer; 027import org.kuali.rice.krad.datadictionary.DataDictionaryDefinitionBase; 028import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException; 029 030/** 031 * 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). 032 */ 033public class AccountingLineGroupDefinition extends DataDictionaryDefinitionBase { 034 private String groupLabel; 035 private Class<? extends AccountingLine> accountingLineClass; 036 private AccountingLineViewDefinition accountingLineView; 037 private String importedLinePropertyPrefix; 038 private List<? extends TotalDefinition> totals; 039 private Class<? extends AccountingLineAuthorizer> accountingLineAuthorizerClass; 040 private int forceColumnCount = -1; 041 private String errorKey; 042 private boolean topHeadersAfterFirstLineHiding = true; 043 private boolean headerRendering = true; 044 private boolean importingAllowed = true; 045 private Class<? extends DefaultAccountingLineGroupImpl> accountingLineGroupClass = org.kuali.ole.sys.document.web.DefaultAccountingLineGroupImpl.class; 046 private Class<? extends Comparator<AccountingLine>> accountingLineComparatorClass = org.kuali.ole.sys.businessobject.AccountingLineComparator.class; 047 048 private List<? extends AccountingLineViewActionDefinition> accountingLineGroupActions; 049 050 private AccountingLineAuthorizer accountingLineAuthorizer; 051 052 /** 053 * Validates that: 054 * 1) this accounting line group has an accounting line class 055 * 2) this accounting line group has an accounting line view 056 * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Class) 057 */ 058 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) { 059 if (accountingLineClass == null) { 060 throw new AttributeValidationException("Please specify an accounting line class for AccountingLineGroup "+getId()); 061 } 062 if (accountingLineView == null) { 063 throw new AttributeValidationException("Please specify an accountingLineView for AccountingLineGroup "+getId()); 064 } 065 } 066 067 /** 068 * Gets the accountingLineClass attribute. 069 * @return Returns the accountingLineClass. 070 */ 071 public Class<? extends AccountingLine> getAccountingLineClass() { 072 return accountingLineClass; 073 } 074 075 /** 076 * Sets the accountingLineClass attribute value. 077 * @param accountingLineClass The accountingLineClass to set. 078 */ 079 public void setAccountingLineClass(Class<? extends AccountingLine> accountingLineClass) { 080 this.accountingLineClass = accountingLineClass; 081 } 082 083 /** 084 * Gets the accountingLineView attribute. 085 * @return Returns the accountingLineView. 086 */ 087 public AccountingLineViewDefinition getAccountingLineView() { 088 return accountingLineView; 089 } 090 091 /** 092 * Sets the accountingLineView attribute value. 093 * @param accountingLineView The accountingLineView to set. 094 */ 095 public void setAccountingLineView(AccountingLineViewDefinition accountingLineView) { 096 this.accountingLineView = accountingLineView; 097 } 098 099 /** 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}