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.util.Iterator; |
19 | |
|
20 | |
import org.kuali.rice.kns.datadictionary.FieldDefinition; |
21 | |
import org.kuali.rice.kns.datadictionary.LookupDefinition; |
22 | |
import org.kuali.rice.kns.datadictionary.BusinessObjectEntry; |
23 | |
import org.kuali.rice.krad.datadictionary.SortDefinition; |
24 | |
import org.kuali.rice.krad.datadictionary.exporter.ExportMap; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
@Deprecated |
32 | |
public class LookupMapBuilder { |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public LookupMapBuilder() { |
38 | 0 | } |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public ExportMap buildLookupMap(BusinessObjectEntry entry) { |
47 | 0 | ExportMap lookupMap = null; |
48 | |
|
49 | 0 | if (entry.hasLookupDefinition()) { |
50 | 0 | LookupDefinition lookupDefinition = entry.getLookupDefinition(); |
51 | 0 | lookupMap = new ExportMap("lookup"); |
52 | |
|
53 | |
|
54 | 0 | if (lookupDefinition.getLookupableID() != null) { |
55 | 0 | lookupMap.set("lookupableID", lookupDefinition.getLookupableID()); |
56 | |
} |
57 | |
|
58 | 0 | lookupMap.set("title", lookupDefinition.getTitle()); |
59 | |
|
60 | 0 | if (lookupDefinition.hasMenubar()) { |
61 | 0 | lookupMap.set("menubar", lookupDefinition.getMenubar()); |
62 | |
} |
63 | |
|
64 | 0 | if (lookupDefinition.hasResultSetLimit()) { |
65 | 0 | lookupMap.set("resultSetLimit", lookupDefinition.getResultSetLimit().toString()); |
66 | |
} |
67 | |
|
68 | 0 | lookupMap.setOptional(buildDefaultSortMap(lookupDefinition)); |
69 | 0 | lookupMap.set(buildLookupFieldsMap(lookupDefinition)); |
70 | 0 | lookupMap.set(buildResultFieldsMap(lookupDefinition)); |
71 | |
} |
72 | |
|
73 | 0 | return lookupMap; |
74 | |
} |
75 | |
|
76 | |
private ExportMap buildDefaultSortMap(LookupDefinition lookupDefinition) { |
77 | 0 | ExportMap defaultSortMap = null; |
78 | |
|
79 | 0 | if (lookupDefinition.hasDefaultSort()) { |
80 | 0 | SortDefinition defaultSortDefinition = lookupDefinition.getDefaultSort(); |
81 | 0 | defaultSortMap = new ExportMap("defaultSort"); |
82 | |
|
83 | 0 | defaultSortMap.set("sortAscending", Boolean.toString(defaultSortDefinition.getSortAscending())); |
84 | 0 | defaultSortMap.set(buildSortAttributesMap(defaultSortDefinition)); |
85 | |
} |
86 | |
|
87 | 0 | return defaultSortMap; |
88 | |
} |
89 | |
|
90 | |
private ExportMap buildSortAttributesMap(SortDefinition sortDefinition) { |
91 | 0 | ExportMap sortAttributesMap = new ExportMap("sortAttributes"); |
92 | |
|
93 | 0 | for (Iterator i = sortDefinition.getAttributeNames().iterator(); i.hasNext();) { |
94 | 0 | String attributeName = (String) i.next(); |
95 | |
|
96 | 0 | ExportMap attributeMap = new ExportMap(attributeName); |
97 | 0 | attributeMap.set("attributeName", attributeName); |
98 | |
|
99 | 0 | sortAttributesMap.set(attributeMap); |
100 | 0 | } |
101 | |
|
102 | 0 | return sortAttributesMap; |
103 | |
} |
104 | |
|
105 | |
private ExportMap buildLookupFieldsMap(LookupDefinition lookupDefinition) { |
106 | 0 | ExportMap lookupFieldsMap = new ExportMap("lookupFields"); |
107 | |
|
108 | 0 | for (Iterator i = lookupDefinition.getLookupFields().iterator(); i.hasNext();) { |
109 | 0 | FieldDefinition lookupField = (FieldDefinition) i.next(); |
110 | 0 | lookupFieldsMap.set(buildLookupFieldMap(lookupField)); |
111 | 0 | } |
112 | |
|
113 | 0 | return lookupFieldsMap; |
114 | |
} |
115 | |
|
116 | |
private ExportMap buildLookupFieldMap(FieldDefinition lookupField) { |
117 | 0 | ExportMap lookupFieldMap = new ExportMap(lookupField.getAttributeName()); |
118 | |
|
119 | 0 | lookupFieldMap.set("attributeName", lookupField.getAttributeName()); |
120 | 0 | lookupFieldMap.set("required", Boolean.toString(lookupField.isRequired())); |
121 | |
|
122 | 0 | return lookupFieldMap; |
123 | |
} |
124 | |
|
125 | |
private ExportMap buildResultFieldsMap(LookupDefinition lookupDefinition) { |
126 | 0 | ExportMap resultFieldsMap = new ExportMap("resultFields"); |
127 | |
|
128 | 0 | for (Iterator i = lookupDefinition.getResultFields().iterator(); i.hasNext();) { |
129 | 0 | FieldDefinition resultField = (FieldDefinition) i.next(); |
130 | 0 | resultFieldsMap.set(MapperUtils.buildFieldMap(resultField)); |
131 | 0 | } |
132 | |
|
133 | 0 | return resultFieldsMap; |
134 | |
} |
135 | |
|
136 | |
} |