1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.web;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Map;
21
22 import javax.servlet.jsp.JspException;
23 import javax.servlet.jsp.PageContext;
24 import javax.servlet.jsp.tagext.Tag;
25
26 import org.apache.commons.beanutils.PropertyUtils;
27 import org.apache.commons.lang.StringUtils;
28 import org.kuali.ole.sys.businessobject.AccountingLine;
29 import org.kuali.ole.sys.context.SpringContext;
30 import org.kuali.ole.sys.document.AccountingDocument;
31 import org.kuali.ole.sys.document.authorization.AccountingLineAuthorizer;
32 import org.kuali.ole.sys.web.struts.KualiAccountingDocumentFormBase;
33 import org.kuali.rice.kim.api.identity.Person;
34 import org.kuali.rice.kns.service.DataDictionaryService;
35 import org.kuali.rice.kns.util.FieldUtils;
36 import org.kuali.rice.kns.web.ui.Field;
37 import org.kuali.rice.krad.util.GlobalVariables;
38 import org.kuali.rice.krad.util.KRADConstants;
39
40
41
42
43 public class RenderableAccountingLineContainer implements AccountingLineRenderingContext {
44 private List<AccountingLineTableRow> rows;
45 private List<AccountingLineViewAction> actions;
46 private AccountingLine accountingLine;
47 private String accountingLineProperty;
48 private List<Field> fields;
49 private List<String> fieldNames;
50 private KualiAccountingDocumentFormBase form;
51 private String groupLabel;
52 private Integer lineCount;
53 private List errors;
54 private AccountingLineAuthorizer accountingLineAuthorizer;
55 private boolean editableLine;
56 private boolean deletable = false;
57
58
59
60
61
62
63
64
65
66
67
68
69
70 public RenderableAccountingLineContainer(KualiAccountingDocumentFormBase form, AccountingLine accountingLine, String accountingLineProperty, List<AccountingLineTableRow> rows, Integer lineCount, String groupLabel, List errors, AccountingLineAuthorizer accountingLineAuthorizer, boolean editableLine) {
71 this.form = form;
72 this.accountingLine = accountingLine;
73 this.accountingLineProperty = accountingLineProperty;
74 this.rows = rows;
75 this.lineCount = lineCount;
76 this.groupLabel = groupLabel;
77 this.errors = errors;
78 this.accountingLineAuthorizer = accountingLineAuthorizer;
79 this.editableLine = editableLine;
80 }
81
82
83
84
85
86 public AccountingLine getAccountingLine() {
87 return accountingLine;
88 }
89
90
91
92
93
94 public String getAccountingLineProperty() {
95 return accountingLineProperty;
96 }
97
98
99
100
101
102 public List<AccountingLineViewAction> getActionsForLine() {
103 if (actions == null) {
104 actions = accountingLineAuthorizer.getActions(form.getFinancialDocument(), this, accountingLineProperty, lineCount, GlobalVariables.getUserSession().getPerson(), groupLabel);
105 }
106 return actions;
107 }
108
109
110
111
112
113 public boolean isNewLine() {
114 return lineCount == null;
115 }
116
117
118
119
120 public Integer getCurrentLineCount() {
121 return lineCount;
122 }
123
124
125
126
127
128 public List<AccountingLineTableRow> getRows() {
129 return rows;
130 }
131
132
133
134
135 public int getCellCount() {
136 int maxCells = 0;
137 for (AccountingLineTableRow row : rows) {
138 final int maxRowCellCount = row.getChildCellCount();
139 if (maxCells < maxRowCellCount) {
140 maxCells = maxRowCellCount;
141 }
142 }
143 return maxCells;
144 }
145
146
147
148
149
150 public int getRenderableCellCount() {
151 int maxCells = 0;
152 for (AccountingLineTableRow row : rows) {
153 final int maxRowCellCount = row.getChildRenderableCount();
154 if (maxCells < maxRowCellCount) {
155 maxCells = maxRowCellCount;
156 }
157 }
158 return maxCells;
159 }
160
161
162
163
164
165
166 protected void padOutRow(int cellCount, AccountingLineTableRow row) {
167 while ((cellCount - row.getChildCellCount()) > 0) {
168 row.addCell(new AccountingLineTableCell());
169 }
170 }
171
172
173
174
175
176 public boolean isActionBlock() {
177 return false;
178 }
179
180
181
182
183
184 public boolean isEmpty() {
185 return false;
186 }
187
188
189
190
191
192 public boolean isHidden() {
193 return false;
194 }
195
196
197
198
199
200 public void renderElement(PageContext pageContext, Tag parentTag, AccountingLineRenderingContext renderingContext) throws JspException {
201 for (AccountingLineTableRow row : rows) {
202 row.renderElement(pageContext, parentTag, renderingContext);
203 }
204 }
205
206
207
208
209 public String getAccountingLinePropertyPath() {
210 return accountingLineProperty;
211 }
212
213
214
215
216
217 public void appendFields(List<Field> fields) {
218 for (AccountingLineTableRow row : rows) {
219 row.appendFields(fields);
220 }
221 }
222
223
224
225
226
227
228
229 public List<Field> getFieldsForAccountingLine() {
230 if (fields == null) {
231 fields = new ArrayList<Field>();
232 appendFields(fields);
233 }
234 return fields;
235 }
236
237
238
239
240
241
242 public List<String> getFieldNamesForAccountingLine() {
243 if (fieldNames == null) {
244 fieldNames = new ArrayList<String>();
245 for (Field field : getFieldsForAccountingLine()) {
246 fieldNames.add(accountingLineProperty+"."+field.getPropertyName());
247 }
248 }
249 return fieldNames;
250 }
251
252
253
254
255 public void populateWithTabIndexIfRequested( int reallyHighIndex) {
256 for (AccountingLineTableRow row : rows) {
257 row.populateWithTabIndexIfRequested(reallyHighIndex);
258 }
259 }
260
261
262
263
264
265 public Map getUnconvertedValues() {
266 return form.getUnconvertedValues();
267 }
268
269
270
271
272
273
274 public void populateValuesForFields() {
275 FieldUtils.populateFieldsFromBusinessObject(getFieldsForAccountingLine(), accountingLine);
276
277 org.kuali.rice.krad.datadictionary.BusinessObjectEntry boDDEntry = SpringContext.getBean(DataDictionaryService.class).getDataDictionary().getBusinessObjectEntry(getAccountingLine().getClass().getName());
278
279 for (Field field : getFieldsForAccountingLine()) {
280 setUnconvertedValueIfNecessary(field);
281 setShouldShowSecure(field, boDDEntry);
282 }
283 }
284
285
286
287
288
289
290
291
292 protected void setUnconvertedValueIfNecessary(Field field) {
293 String propertyName = accountingLineProperty+"."+field.getPropertyName();
294 if (getUnconvertedValues().get(propertyName) != null) {
295 field.setPropertyValue((String)getUnconvertedValues().get(propertyName));
296 }
297 }
298
299
300
301
302
303
304
305
306 protected void setShouldShowSecure(Field field, org.kuali.rice.krad.datadictionary.BusinessObjectEntry boDDEntry) {
307
308
309
310
311 }
312
313
314
315 public AccountingDocument getAccountingDocument() {
316 return form.getFinancialDocument();
317 }
318
319
320
321
322 public boolean fieldsCanRenderDynamicLabels() {
323 return !form.isHideDetails();
324 }
325
326
327
328 public boolean fieldsShouldRenderHelp() {
329 return form.isFieldLevelHelpEnabled();
330 }
331
332
333
334 public String getTabState(String tabKey) {
335 return form.getTabState(tabKey);
336 }
337
338
339
340 public void incrementTabIndex() {
341 form.incrementTabIndex();
342 }
343
344
345
346
347 public String getGroupLabel() {
348 return this.groupLabel;
349 }
350
351
352
353
354
355 public List getErrors() {
356 return errors;
357 }
358
359
360
361
362 public KualiAccountingDocumentFormBase getForm() {
363 return form;
364 }
365
366
367
368
369 public String getAccountingLineContainingObjectPropertyName() {
370 return StringUtils.substringBeforeLast(this.getAccountingLinePropertyPath(), String.valueOf(PropertyUtils.NESTED_DELIM));
371 }
372
373
374
375
376 public boolean isFieldModifyable(String fieldName) {
377 Person currentUser = GlobalVariables.getUserSession().getPerson();
378 final boolean pageIsEditable = getForm().getDocumentActions().containsKey(KRADConstants.KUALI_ACTION_CAN_EDIT);
379 return accountingLineAuthorizer.hasEditPermissionOnField(getAccountingDocument(), accountingLine, this.accountingLineProperty, fieldName, editableLine, pageIsEditable, currentUser);
380 }
381
382
383
384
385
386 public boolean isEditableLine() {
387 return editableLine;
388 }
389
390
391
392
393
394
395 public void setEditableLine(boolean editableLine) {
396 this.editableLine = editableLine;
397 }
398
399
400
401
402
403 public boolean allowDelete() {
404 return deletable;
405 }
406
407
408
409
410 public void makeDeletable() {
411 deletable = true;
412 }
413 }
414