View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * LookupMapBuilder
28   *
29   * @deprecated Only used by KNS classes, no replacement.
30   */
31  @Deprecated
32  public class LookupMapBuilder {
33  
34      /**
35       * Default constructor
36       */
37      public LookupMapBuilder() {
38      }
39  
40  
41      /**
42       * @param entry
43       * @return ExportMap containing the standard entries for the given entry's LookupDefinition, or null if the given entry has no
44       *         lookupDefinition
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              // simple properties
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              // complex properties
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 }