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