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