001 /* 002 * Copyright 2011 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.kfs.sys.document.datadictionary; 017 018 import java.util.ArrayList; 019 import java.util.List; 020 021 import org.apache.commons.lang.StringUtils; 022 import org.kuali.kfs.sys.businessobject.AccountingLine; 023 import org.kuali.kfs.sys.document.web.AccountingLineViewColumns; 024 import org.kuali.kfs.sys.document.web.AccountingLineViewField; 025 import org.kuali.kfs.sys.document.web.AccountingLineViewLineFillingElement; 026 import org.kuali.kfs.sys.document.web.TableJoining; 027 import org.kuali.rice.kns.datadictionary.DataDictionaryDefinitionBase; 028 import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException; 029 030 /** 031 * 032 */ 033 public class AccountingLineViewColumnsDefinition extends DataDictionaryDefinitionBase implements AccountingLineViewLineFillingDefinition { 034 private int columnCount = 1; 035 private List<AccountingLineViewFieldDefinition> fields; 036 private String name; 037 038 /** 039 * 040 * @see org.kuali.kfs.sys.document.datadictionary.AccountingLineViewRenderableElementDefinition#createLayoutElement(java.lang.Class) 041 */ 042 public TableJoining createLayoutElement(Class<? extends AccountingLine> accountingLineClass) { 043 List<AccountingLineViewField> layoutFields = new ArrayList<AccountingLineViewField>(); 044 045 for (AccountingLineViewFieldDefinition fieldDefinition : fields) { 046 final AccountingLineViewField field = (AccountingLineViewField)fieldDefinition.createLayoutElement(accountingLineClass); 047 if (field != null) { 048 layoutFields.add(field); 049 } 050 } 051 052 return new AccountingLineViewColumns(this, layoutFields); 053 } 054 055 /** 056 * @see org.kuali.kfs.sys.document.datadictionary.AccountingLineViewLineFillingDefinition#createLineFillingLayoutElement(java.lang.Class) 057 */ 058 public AccountingLineViewLineFillingElement createLineFillingLayoutElement(Class<? extends AccountingLine> accountingLineClass) { 059 return (AccountingLineViewLineFillingElement)createLayoutElement(accountingLineClass); 060 } 061 062 /** 063 * 064 * @see org.kuali.rice.kns.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Class) 065 */ 066 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) { 067 if (StringUtils.isBlank(name)) { 068 throw new AttributeValidationException("name for "+rootBusinessObjectClass.getName()+" accounting line view columns definition must be defined"); 069 } 070 if (columnCount < 1) { 071 throw new AttributeValidationException("columnCount for "+rootBusinessObjectClass.getName()+" accounting line view columns data dictionary definition must be one or greater"); 072 } 073 if (fields == null || fields.size() == 0) { 074 throw new AttributeValidationException("Please add at least one field to the "+rootBusinessObjectClass.getName()+" accounting line view columns definition"); 075 } 076 } 077 078 /** 079 * Gets the columnCount attribute. 080 * @return Returns the columnCount. 081 */ 082 public int getColumnCount() { 083 return columnCount; 084 } 085 086 /** 087 * Sets the columnCount attribute value. 088 * @param columnCount The columnCount to set. 089 */ 090 public void setColumnCount(int columnCount) { 091 this.columnCount = columnCount; 092 } 093 094 /** 095 * Gets the fields attribute. 096 * @return Returns the fields. 097 */ 098 public List<AccountingLineViewFieldDefinition> getFields() { 099 return fields; 100 } 101 102 /** 103 * Sets the fields attribute value. 104 * @param fields The fields to set. 105 */ 106 public void setFields(List<AccountingLineViewFieldDefinition> fields) { 107 this.fields = fields; 108 } 109 110 /** 111 * Gets the name attribute. 112 * @return Returns the name. 113 */ 114 public String getName() { 115 return name; 116 } 117 118 /** 119 * Sets the name attribute value. 120 * @param name The name to set. 121 */ 122 public void setName(String name) { 123 this.name = name; 124 } 125 126 }