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