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 org.apache.commons.lang.StringUtils;
019    import org.apache.log4j.Logger;
020    import org.kuali.kfs.sys.document.web.renderers.DebitCreditTotalRenderer;
021    import org.kuali.kfs.sys.document.web.renderers.Renderer;
022    import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException;
023    
024    /**
025     * Metadata that instructs the accounting line tags how to render debit/credit totals used in voucher documents
026     */
027    public class DebitCreditTotalDefinition extends TotalDefinition {
028        private static Logger LOG = Logger.getLogger(DebitCreditTotalDefinition.class);
029    
030        private String debitTotalProperty;
031        private String creditTotalProperty;
032        
033        private boolean nestedProperty;
034        private String containingPropertyName;
035    
036        private String representedProperty;
037    
038        private String debitTotalLabelProperty = "accounting.line.group.debitTotal.label";
039        private String creditTotalLabelProperty = "accounting.line.group.creditTotal.label";
040    
041        /**
042         * @see org.kuali.kfs.sys.document.datadictionary.TotalDefinition#getTotalRenderer()
043         */
044        @Override
045        public Renderer getTotalRenderer() {
046            DebitCreditTotalRenderer renderer = new DebitCreditTotalRenderer();
047    
048            String actualCreditTotalProperty = this.getActualPropertyName(containingPropertyName, creditTotalProperty);
049            renderer.setCreditTotalProperty(actualCreditTotalProperty);
050            
051            String actualDebitTotalProperty = this.getActualPropertyName(containingPropertyName, debitTotalProperty);
052            renderer.setDebitTotalProperty(actualDebitTotalProperty);
053    
054            renderer.setRepresentedCellPropertyName(representedProperty);
055    
056            renderer.setCreditTotalLabelProperty(creditTotalLabelProperty);
057            renderer.setDebitTotalLabelProperty(debitTotalLabelProperty);
058    
059            return renderer;
060        }
061    
062        /**
063         * Validates that total properties have been added
064         * 
065         * @see org.kuali.rice.kns.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Class)
066         */
067        public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
068            if (StringUtils.isBlank(debitTotalProperty) || StringUtils.isBlank(creditTotalProperty)) {
069                throw new AttributeValidationException("Please specify both debitTotalProperty and creditTotalProperty for the AccountingLineGroupTotalRenderer");
070            }
071        }
072    
073        /**
074         * Gets the debitTotalProperty attribute.
075         * 
076         * @return Returns the debitTotalProperty.
077         */
078        public String getDebitTotalProperty() {
079            return debitTotalProperty;
080        }
081    
082        /**
083         * Sets the debitTotalProperty attribute value.
084         * 
085         * @param debitTotalProperty The debitTotalProperty to set.
086         */
087        public void setDebitTotalProperty(String debitTotalProperty) {
088            this.debitTotalProperty = debitTotalProperty;
089        }
090    
091        /**
092         * Gets the creditTotalProperty attribute.
093         * 
094         * @return Returns the creditTotalProperty.
095         */
096        public String getCreditTotalProperty() {
097            return creditTotalProperty;
098        }
099    
100        /**
101         * Sets the creditTotalProperty attribute value.
102         * 
103         * @param creditTotalProperty The creditTotalProperty to set.
104         */
105        public void setCreditTotalProperty(String creditTotalProperty) {
106            this.creditTotalProperty = creditTotalProperty;
107        }
108    
109        /**
110         * Gets the debitTotalLabelProperty attribute.
111         * 
112         * @return Returns the debitTotalLabelProperty.
113         */
114        public String getDebitTotalLabelProperty() {
115            return debitTotalLabelProperty;
116        }
117    
118        /**
119         * Sets the debitTotalLabelProperty attribute value.
120         * 
121         * @param debitTotalLabelProperty The debitTotalLabelProperty to set.
122         */
123        public void setDebitTotalLabelProperty(String debitTotalLabelProperty) {
124            this.debitTotalLabelProperty = debitTotalLabelProperty;
125        }
126    
127        /**
128         * Gets the creditTotalLabelProperty attribute.
129         * 
130         * @return Returns the creditTotalLabelProperty.
131         */
132        public String getCreditTotalLabelProperty() {
133            return creditTotalLabelProperty;
134        }
135    
136        /**
137         * Sets the creditTotalLabelProperty attribute value.
138         * 
139         * @param creditTotalLabelProperty The creditTotalLabelProperty to set.
140         */
141        public void setCreditTotalLabelProperty(String creditTotalLabelProperty) {
142            this.creditTotalLabelProperty = creditTotalLabelProperty;
143        }
144    
145        /**
146         * Gets the representedProperty attribute.
147         * 
148         * @return Returns the representedProperty.
149         */
150        public String getRepresentedProperty() {
151            return representedProperty;
152        }
153    
154        /**
155         * Sets the representedProperty attribute value.
156         * 
157         * @param representedProperty The representedProperty to set.
158         */
159        public void setRepresentedProperty(String representedProperty) {
160            this.representedProperty = representedProperty;
161        }
162    
163        /**
164         * Sets the nestedProperty attribute value.
165         * @param nestedProperty The nestedProperty to set.
166         */
167        public void setNestedProperty(boolean nestedProperty) {
168            this.nestedProperty = nestedProperty;
169        }
170    
171        /**
172         * @see org.kuali.kfs.sys.document.web.NestedFieldTotaling#setContainingPropertyName(java.lang.String)
173         */
174        public void setContainingPropertyName(String containingPropertyName) {
175            this.containingPropertyName = containingPropertyName;
176        }
177    
178        /**
179         * @see org.kuali.kfs.sys.document.web.NestedFieldTotaling#isNestedProperty()
180         */
181        public boolean isNestedProperty() {
182            return this.nestedProperty;
183        }
184    }