Coverage Report - org.kuali.rice.kns.datadictionary.SortDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
SortDefinition
0%
0/26
0%
0/12
2.125
 
 1  
 /*
 2  
  * Copyright 2005-2007 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  
 
 17  
 package org.kuali.rice.kns.datadictionary;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.Iterator;
 21  
 import java.util.List;
 22  
 
 23  
 import org.apache.commons.lang.StringUtils;
 24  
 import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException;
 25  
 
 26  
 /**
 27  
                 The defaultSort element specifies the sequence in which the
 28  
                 lookup search results should be displayed.  It contains an
 29  
                 ascending/descending indicator and a list of attribute names.
 30  
 
 31  
                 DD: See SortDefinition.java
 32  
 
 33  
                 JSTL: defaultSort is a Map with the following keys:
 34  
                 * sortAscending (boolean String)
 35  
                 * sortAttributes (Map)
 36  
 
 37  
                 By the time JSTL export occurs, the optional attributeName from the defaultSort
 38  
                 tag will have been converted into the first contained sortAttribute
 39  
  */
 40  
 public class SortDefinition extends DataDictionaryDefinitionBase {
 41  
     private static final long serialVersionUID = -1092811342186612461L;
 42  
     
 43  0
         protected boolean sortAscending = true;
 44  0
     protected List<String> attributeNames = new ArrayList<String>();
 45  
 
 46  0
     public SortDefinition() {}
 47  
 
 48  
 
 49  
     /**
 50  
                        The sortAttribute element defines one part of the sort key.
 51  
                         The full sort key is comprised of the sortAttribute's in the
 52  
                         order in which they have been defined.
 53  
 
 54  
                         DD: See SortAttributesDefinition.java.
 55  
 
 56  
                         JSTL: sortAttribute is a Map which is accessed using a
 57  
                         key of the attributeName of the sortAttribute.
 58  
                         It contains a single entry with the following key:
 59  
                             * "attributeName"
 60  
 
 61  
                         The associated value is the attributeName of the sortAttribute.
 62  
                         See LookupMapBuilder.java
 63  
      * @throws IllegalArgumentException if the given attributeName is blank
 64  
      */
 65  
     public void setAttributeName(String attributeName) {
 66  0
         if (StringUtils.isBlank(attributeName)) {
 67  0
             throw new IllegalArgumentException("invalid (blank) attributeName");
 68  
         }
 69  0
         if (attributeNames.size() != 0) {
 70  0
             throw new IllegalStateException("unable to set sort attributeName when sortAttributes have already been added");
 71  
         }
 72  
 
 73  0
         attributeNames.add(attributeName);
 74  0
     }
 75  
 
 76  
     /**
 77  
      * @return the List of associated attribute names as Strings
 78  
      */
 79  
     public List<String> getAttributeNames() {
 80  0
         return this.attributeNames;
 81  
     }
 82  
 
 83  
 
 84  
     /**
 85  
      * @return true if items should sort in ascending order
 86  
      */
 87  
     public boolean getSortAscending() {
 88  0
         return sortAscending;
 89  
     }
 90  
 
 91  
     public void setSortAscending(boolean sortAscending) {
 92  0
         this.sortAscending = sortAscending;
 93  0
     }
 94  
 
 95  
 
 96  
     /**
 97  
      * Directly validate simple fields.
 98  
      * 
 99  
      * @see org.kuali.rice.kns.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
 100  
      */
 101  
     public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
 102  0
         for ( String attributeName : attributeNames ) {
 103  0
             if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, attributeName)) {
 104  0
                 throw new AttributeValidationException("unable to find sort attribute '" + attributeName + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
 105  
             }            
 106  
         }
 107  0
     }
 108  
 
 109  
 
 110  
     /**
 111  
      * @see java.lang.Object#toString()
 112  
      */
 113  
     public String toString() {
 114  0
         StringBuffer attrList = new StringBuffer("[");
 115  0
         for (Iterator<String> i = attributeNames.iterator(); i.hasNext();) {
 116  0
             attrList.append(i.next());
 117  0
             if (i.hasNext()) {
 118  0
                 attrList.append(",");
 119  
             }
 120  
         }
 121  0
         attrList.append("]");
 122  
 
 123  0
         return "SortDefinition :  " + attrList.toString();
 124  
     }
 125  
 
 126  
 
 127  
     /**
 128  
                      The sortAttributes element allows a multiple-part sort key
 129  
                       to be defined
 130  
 
 131  
                       JSTL: sortAttributes is a Map which is accessed using a
 132  
                       key of "sortAttributes". This map contains an entry for
 133  
                       sort attribute.  The key is:
 134  
                       * attributeName of a sort field.
 135  
                       The associated value is a sortAttribute ExportMap.
 136  
      */
 137  
     public void setAttributeNames(List<String> attributeNames) {
 138  0
         this.attributeNames = attributeNames;
 139  0
     }
 140  
     
 141  
 }