1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.datadictionary.exporter;
17
18 import java.math.BigDecimal;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.rice.kns.datadictionary.AttributeDefinition;
22 import org.kuali.rice.kns.datadictionary.DataDictionaryEntryBase;
23 import org.kuali.rice.kns.datadictionary.control.ButtonControlDefinition;
24 import org.kuali.rice.kns.datadictionary.control.ControlDefinition;
25 import org.kuali.rice.kns.datadictionary.control.CurrencyControlDefinition;
26 import org.kuali.rice.kns.datadictionary.control.LinkControlDefinition;
27 import org.kuali.rice.kns.datadictionary.mask.MaskFormatterLiteral;
28
29
30
31
32
33
34 public class AttributesMapBuilder {
35
36
37
38
39 public AttributesMapBuilder() {
40 }
41
42
43
44
45
46
47 public ExportMap buildAttributesMap(DataDictionaryEntryBase entry) {
48 ExportMap attributesMap = new ExportMap("attributes");
49
50 for ( AttributeDefinition attribute : entry.getAttributes() ) {
51 attributesMap.set(buildAttributeMap(attribute, entry.getFullClassName()));
52 }
53
54 return attributesMap;
55 }
56
57 private ExportMap buildAttributeMap(AttributeDefinition attribute, String fullClassName) {
58 ExportMap attributeMap = new ExportMap(attribute.getName());
59
60
61 attributeMap.set("name", attribute.getName());
62 attributeMap.set("forceUppercase", attribute.getForceUppercase().toString());
63 attributeMap.set("label", attribute.getLabel());
64 attributeMap.set("shortLabel", attribute.getShortLabel());
65
66 attributeMap.set("maxLength", attribute.getMaxLength().toString());
67 final BigDecimal exclusiveMin = attribute.getExclusiveMin();
68 if (exclusiveMin != null) {
69 attributeMap.set("exclusiveMin", exclusiveMin.toString());
70 }
71 final BigDecimal exclusiveMax = attribute.getInclusiveMax();
72 if (exclusiveMax != null) {
73 attributeMap.set("exclusiveMax", exclusiveMax.toString());
74 }
75
76 attributeMap.set("required", attribute.isRequired().toString());
77 if (attribute.getSummary() != null) {
78 attributeMap.set("summary", attribute.getSummary());
79 }
80 if (attribute.getDescription() != null) {
81 attributeMap.set("description", attribute.getDescription());
82 }
83 if (attribute.hasFormatterClass()) {
84 attributeMap.set("formatterClass", attribute.getFormatterClass());
85 }
86
87
88 if (attribute.hasValidationPattern()) {
89 attributeMap.set(attribute.getValidationPattern().buildExportMap("validationPattern"));
90 }
91
92 if(attribute.hasAttributeSecurity()){
93 attributeMap.set("attributeSecurityMask", String.valueOf(attribute.getAttributeSecurity().isMask()));
94 attributeMap.set("attributeSecurityPartialMask", String.valueOf(attribute.getAttributeSecurity().isPartialMask()));
95 attributeMap.set("attributeSecurityHide", String.valueOf(attribute.getAttributeSecurity().isHide()));
96 attributeMap.set("attributeSecurityReadOnly", String.valueOf(attribute.getAttributeSecurity().isReadOnly()));
97
98
99 }
100
101 attributeMap.set(buildControlMap(attribute));
102 attributeMap.set("fullClassName", fullClassName);
103
104 return attributeMap;
105 }
106
107
108 private ExportMap buildControlMap(AttributeDefinition attribute) {
109 ControlDefinition control = attribute.getControl();
110 ExportMap controlMap = new ExportMap("control");
111
112 if (control.isCheckbox()) {
113 controlMap.set("checkbox", "true");
114 }
115 else if (control.isHidden()) {
116 controlMap.set("hidden", "true");
117 }
118 else if (control.isKualiUser()) {
119 controlMap.set("kualiUser", "true");
120 }
121 else if (control.isRadio()) {
122 controlMap.set("radio", "true");
123 controlMap.set("valuesFinder", control.getValuesFinderClass());
124 if (control.getBusinessObjectClass() != null) {
125 controlMap.set("businessObject", control.getBusinessObjectClass());
126 }
127 if (StringUtils.isNotEmpty(control.getKeyAttribute())) {
128 controlMap.set("keyAttribute", control.getKeyAttribute());
129 }
130 if (StringUtils.isNotEmpty(control.getLabelAttribute())) {
131 controlMap.set("labelAttribute", control.getLabelAttribute());
132 }
133 if (control.getIncludeKeyInLabel() != null) {
134 controlMap.set("includeKeyInLabel", control.getIncludeKeyInLabel().toString());
135 }
136 }
137 else if (control.isSelect()) {
138 controlMap.set("select", "true");
139 controlMap.set("valuesFinder", control.getValuesFinderClass());
140 if (control.getBusinessObjectClass() != null) {
141 controlMap.set("businessObject", control.getBusinessObjectClass());
142 }
143 if (StringUtils.isNotEmpty(control.getKeyAttribute())) {
144 controlMap.set("keyAttribute", control.getKeyAttribute());
145 }
146 if (StringUtils.isNotEmpty(control.getLabelAttribute())) {
147 controlMap.set("labelAttribute", control.getLabelAttribute());
148 }
149 if (control.getIncludeBlankRow() != null) {
150 controlMap.set("includeBlankRow", control.getIncludeBlankRow().toString());
151 }
152 if (control.getIncludeKeyInLabel() != null) {
153 controlMap.set("includeKeyInLabel", control.getIncludeKeyInLabel().toString());
154 }
155 }
156 else if (control.isMultiselect()) {
157 controlMap.set("multiselect", "true");
158 controlMap.set("valuesFinder", control.getValuesFinderClass());
159 if (control.getBusinessObjectClass() != null) {
160 controlMap.set("businessObject", control.getBusinessObjectClass());
161 }
162 if (StringUtils.isNotEmpty(control.getKeyAttribute())) {
163 controlMap.set("keyAttribute", control.getKeyAttribute());
164 }
165 if (StringUtils.isNotEmpty(control.getLabelAttribute())) {
166 controlMap.set("labelAttribute", control.getLabelAttribute());
167 }
168 if (control.getIncludeKeyInLabel() != null) {
169 controlMap.set("includeKeyInLabel", control.getIncludeKeyInLabel().toString());
170 }
171 if (control.getSize() != null) {
172 controlMap.set("size", control.getSize().toString());
173 }
174 }
175 else if (control.isText()) {
176 controlMap.set("text", "true");
177 controlMap.set("size", control.getSize().toString());
178 controlMap.set("datePicker", Boolean.valueOf(control.isDatePicker()).toString());
179 controlMap.set("ranged", Boolean.valueOf(control.isRanged()).toString());
180 }
181 else if (control.isTextarea()) {
182 controlMap.set("textarea", "true");
183 controlMap.set("rows", control.getRows().toString());
184 controlMap.set("cols", control.getCols().toString());
185 controlMap.set("expandedTextArea", Boolean.valueOf(control.isExpandedTextArea()).toString());
186 }
187 else if (control.isCurrency()) {
188 controlMap.set("currency", "true");
189 controlMap.set("size", control.getSize().toString());
190 controlMap.set("formattedMaxLength", ((CurrencyControlDefinition) control).getFormattedMaxLength().toString());
191 }
192 else if (control.isLookupHidden()) {
193 controlMap.set("lookupHidden", "true");
194 }
195 else if (control.isLookupReadonly()) {
196 controlMap.set("lookupReadonly", "true");
197 }else if (control.isButton()) {
198 controlMap.set("button", "true");
199 if (StringUtils.isNotEmpty(((ButtonControlDefinition) control).getImageSrc())) {
200 controlMap.set("imageSrc", ((ButtonControlDefinition) control).getImageSrc());
201 }
202 if (StringUtils.isNotEmpty(((ButtonControlDefinition) control).getStyleClass())) {
203 controlMap.set("styleClass", ((ButtonControlDefinition) control).getStyleClass() );
204 }
205 }else if (control.isLink()) {
206 controlMap.set("link", "true");
207 if (StringUtils.isNotEmpty(((LinkControlDefinition) control).getTarget())) {
208 controlMap.set("target", ((LinkControlDefinition) control).getTarget());
209 }
210 if (StringUtils.isNotEmpty(((LinkControlDefinition) control).getStyleClass())) {
211 controlMap.set("styleClass", ((LinkControlDefinition) control).getStyleClass() );
212 }
213 if (StringUtils.isNotEmpty(((LinkControlDefinition) control).getHrefText())) {
214 controlMap.set("hrefText", ((LinkControlDefinition) control).getHrefText());
215 }
216 }
217
218 return controlMap;
219 }
220 }