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