1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary.validation;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
20 import org.kuali.rice.krad.datadictionary.validation.capability.Constrainable;
21 import org.kuali.rice.krad.uif.UifPropertyPaths;
22 import org.kuali.rice.krad.uif.field.InputField;
23 import org.kuali.rice.krad.uif.util.ComponentUtils;
24 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
25 import org.kuali.rice.krad.uif.view.View;
26
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31
32
33
34
35
36
37 public class ViewAttributeValueReader extends BaseAttributeValueReader {
38 private View view;
39 private Object form;
40
41 private List<Constrainable> inputFields = new ArrayList<Constrainable>();
42 private Map<String, InputField> inputFieldMap = new HashMap<String, InputField>();
43
44
45
46
47
48
49
50
51 public ViewAttributeValueReader(View view, Object form) {
52 this.view = view;
53 this.form = form;
54
55 List<InputField> containerInputFields = ComponentUtils.getAllInputFieldsWithinContainer(view);
56 for (InputField field : containerInputFields) {
57 if (StringUtils.isNotBlank(field.getName())) {
58 inputFields.add(field);
59 inputFieldMap.put(field.getName(), field);
60 }
61 }
62 }
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 @Override
79 public Constrainable getDefinition(String attributeName) {
80 InputField field = inputFieldMap.get(attributeName);
81 if (field != null) {
82 return field;
83 } else {
84 return null;
85 }
86 }
87
88
89
90
91
92
93 @Override
94 public List<Constrainable> getDefinitions() {
95 return inputFields;
96 }
97
98
99
100
101
102
103
104 @Override
105 public String getLabel(String attributeName) {
106 InputField field = inputFieldMap.get(attributeName);
107 if (field != null) {
108 return field.getLabel();
109 } else {
110 return null;
111 }
112 }
113
114
115
116
117
118
119 @Override
120 public Object getObject() {
121 return view;
122 }
123
124
125
126
127
128
129 @Override
130 public Constrainable getEntry() {
131 return null;
132 }
133
134
135
136
137
138
139 @Override
140 public String getPath() {
141 return this.attributeName;
142 }
143
144
145
146
147
148
149
150 @Override
151 public Class<?> getType(String attributeName) {
152 Object fieldValue = ObjectPropertyUtils.getPropertyValue(form, attributeName);
153 return fieldValue.getClass();
154 }
155
156
157
158
159
160
161
162 @Override
163 public boolean isReadable() {
164 if (attributeName != null && attributeName.contains(UifPropertyPaths.NEW_COLLECTION_LINES)) {
165 return false;
166 }
167 return true;
168 }
169
170
171
172
173
174
175
176
177 @Override
178 public <X> X getValue() throws AttributeValidationException {
179 X fieldValue = null;
180 if (StringUtils.isNotBlank(this.attributeName)) {
181 fieldValue = ObjectPropertyUtils.<X>getPropertyValue(form, this.attributeName);
182 }
183 return fieldValue;
184 }
185
186
187
188
189
190
191
192
193
194 @Override
195 public <X> X getValue(String attributeName) throws AttributeValidationException {
196 X fieldValue = null;
197 if (StringUtils.isNotBlank(attributeName)) {
198 fieldValue = ObjectPropertyUtils.<X>getPropertyValue(form, this.attributeName);
199 }
200 return fieldValue;
201 }
202
203
204
205
206
207
208 @Override
209 public AttributeValueReader clone() {
210 ViewAttributeValueReader clone = new ViewAttributeValueReader(view, form);
211 clone.setAttributeName(this.attributeName);
212 return clone;
213 }
214
215 }