1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary;
17
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public class SortDefinition extends DataDictionaryDefinitionBase {
38 private static final long serialVersionUID = -1092811342186612461L;
39
40 protected boolean sortAscending = true;
41 protected List<String> attributeNames = new ArrayList<String>();
42
43 public SortDefinition() {
44
45 }
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 public void setAttributeName(String attributeName) {
65 if (StringUtils.isBlank(attributeName)) {
66 throw new IllegalArgumentException("invalid (blank) attributeName");
67 }
68 if (!attributeNames.isEmpty()) {
69 throw new IllegalStateException(
70 "unable to set sort attributeName when sortAttributes have already been added");
71 }
72
73 attributeNames.add(attributeName);
74 }
75
76
77
78
79 public List<String> getAttributeNames() {
80 return this.attributeNames;
81 }
82
83
84
85
86
87
88 public boolean getSortAscending() {
89 return sortAscending;
90 }
91
92
93
94
95
96
97 public void setSortAscending(boolean sortAscending) {
98 this.sortAscending = sortAscending;
99 }
100
101 @Override
102 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass, ValidationTrace tracer) {
103
104 if ( attributeNames == null || attributeNames.isEmpty() ) {
105 String currentValues[] = {"attributeNames = " + attributeNames, "rootBusinessObjectClass = " + rootBusinessObjectClass};
106 tracer.createError("SortDefinition may not have an empty attribute list", currentValues);
107 }
108
109 for (String attributeName : attributeNames) {
110 if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, attributeName)) {
111 String currentValues[] = {"attributeName = " + attributeName, "rootBusinessObjectClass = " + rootBusinessObjectClass};
112 tracer.createError("attribute in SortDefinition not found on business object", currentValues);
113 }
114 }
115 }
116
117 @Override
118 public String toString() {
119 StringBuilder attrList = new StringBuilder("[");
120 for (Iterator<String> i = attributeNames.iterator(); i.hasNext(); ) {
121 attrList.append(i.next());
122 if (i.hasNext()) {
123 attrList.append(",");
124 }
125 }
126 attrList.append("]");
127
128 return "SortDefinition : " + attrList;
129 }
130
131
132
133
134
135
136
137 public void setAttributeNames(List<String> attributeNames) {
138 this.attributeNames = attributeNames;
139 }
140
141 }