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