1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.datadictionary;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.sys.businessobject.AccountingLine;
20 import org.kuali.ole.sys.context.SpringContext;
21 import org.kuali.ole.sys.document.service.AccountingLineRenderingService;
22 import org.kuali.ole.sys.document.web.AccountingLineViewCurrentBaseAmount;
23 import org.kuali.ole.sys.document.web.TableJoining;
24 import org.kuali.rice.kns.datadictionary.MaintainableFieldDefinition;
25 import org.kuali.rice.kns.service.DataDictionaryService;
26 import org.kuali.rice.kns.util.FieldUtils;
27 import org.kuali.rice.kns.web.ui.Field;
28 import org.kuali.rice.kns.web.ui.FieldBridge;
29 import org.kuali.rice.krad.datadictionary.DataDictionary;
30 import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
31
32
33
34
35 public class AccountingLineViewCurrentBaseAmountFieldDefinition extends MaintainableFieldDefinition implements AccountingLineViewRenderableElementDefinition {
36 private String currentAmountPropertyName;
37 private String baseAmountPropertyName;
38 private boolean useShortLabels = false;
39
40
41
42
43
44 public TableJoining createLayoutElement(Class<? extends AccountingLine> accountingLineClass) {
45 AccountingLineViewCurrentBaseAmount layoutElement = new AccountingLineViewCurrentBaseAmount();
46
47 layoutElement.setBaseAmountField(createFieldForPropertyName(baseAmountPropertyName, accountingLineClass));
48 layoutElement.setBaseAmountFieldDefinition(createFieldDefinitionForProperty(baseAmountPropertyName));
49
50 layoutElement.setCurrentAmountField(createFieldForPropertyName(currentAmountPropertyName, accountingLineClass));
51 layoutElement.setCurrentAmountFieldDefinition(createFieldDefinitionForProperty(currentAmountPropertyName));
52
53 layoutElement.setDefinition(this);
54
55 return layoutElement;
56 }
57
58
59
60
61
62
63
64 protected Field createFieldForPropertyName(String propertyName, Class<? extends AccountingLine> accountingLineClass) {
65 Field realField = FieldUtils.getPropertyField(accountingLineClass, propertyName, false);
66 FieldBridge.setupField(realField, this, null);
67 if (useShortLabels) {
68 org.kuali.rice.krad.datadictionary.BusinessObjectEntry boEntry = SpringContext.getBean(DataDictionaryService.class).getDataDictionary().getBusinessObjectEntry(accountingLineClass.getName());
69 realField.setFieldLabel(boEntry.getAttributeDefinition(propertyName).getShortLabel());
70 }
71 return realField;
72 }
73
74
75
76
77
78
79 protected AccountingLineViewFieldDefinition createFieldDefinitionForProperty(String propertyName) {
80 AccountingLineViewFieldDefinition fieldDefinition = SpringContext.getBean(AccountingLineRenderingService.class).createGenericAccountingLineViewFieldDefinition(this);
81 fieldDefinition.setName(propertyName);
82 return fieldDefinition;
83 }
84
85
86
87
88 @Override
89 public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
90 if (StringUtils.isBlank(currentAmountPropertyName)) {
91 throw new AttributeValidationException("The currentAmountPropertyName property must be specified on the AccountingLineView-CurentBaseAmountField definition for "+rootBusinessObjectClass.getName());
92 }
93
94 if (StringUtils.isBlank(baseAmountPropertyName)) {
95 throw new AttributeValidationException("The baseAmountPropertyName property must be specified on the AccountingLineView-CurentBaseAmountField definition for "+rootBusinessObjectClass.getName());
96 }
97
98 if (!StringUtils.isBlank(getName())) {
99 throw new AttributeValidationException("please do not specify name on the AccountingLineView-CurentBaseAmountField definition for "+rootBusinessObjectClass.getName());
100 }
101
102 if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getCurrentAmountPropertyName())) {
103 throw new AttributeValidationException("unable to find attribute or collection named '" + getCurrentAmountPropertyName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
104 }
105
106 if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getBaseAmountPropertyName())) {
107 throw new AttributeValidationException("unable to find attribute or collection named '" + getBaseAmountPropertyName() + "' in rootBusinessObjectClass '" + rootBusinessObjectClass.getName() + "' (" + "" + ")");
108 }
109
110 if (defaultValueFinderClass != null && defaultValue != null) {
111 throw new AttributeValidationException("Both defaultValue and defaultValueFinderClass can not be specified on attribute " + getName() + " in rootBusinessObjectClass " + rootBusinessObjectClass.getName());
112 }
113 }
114
115
116
117
118
119 public String getBaseAmountPropertyName() {
120 return baseAmountPropertyName;
121 }
122
123
124
125
126
127 public void setBaseAmountPropertyName(String baseAmountPropertyName) {
128 this.baseAmountPropertyName = baseAmountPropertyName;
129 }
130
131
132
133
134
135 public String getCurrentAmountPropertyName() {
136 return currentAmountPropertyName;
137 }
138
139
140
141
142
143 public void setCurrentAmountPropertyName(String currentAmountPropertyName) {
144 this.currentAmountPropertyName = currentAmountPropertyName;
145 }
146
147
148
149
150
151 public boolean isUseShortLabels() {
152 return useShortLabels;
153 }
154
155
156
157
158
159 public void setUseShortLabels(boolean useShortLabels) {
160 this.useShortLabels = useShortLabels;
161 }
162
163 }