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