Coverage Report - org.kuali.rice.kns.datadictionary.exporter.LookupMapBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
LookupMapBuilder
0%
0/48
0%
0/16
2.143
 
 1  
 /*
 2  
  * Copyright 2005-2007 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  
  *
 30  
  */
 31  
 @Deprecated
 32  
 public class LookupMapBuilder {
 33  
 
 34  
     /**
 35  
      * Default constructor
 36  
      */
 37  0
     public LookupMapBuilder() {
 38  0
     }
 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  0
         ExportMap lookupMap = null;
 48  
 
 49  0
         if (entry.hasLookupDefinition()) {
 50  0
             LookupDefinition lookupDefinition = entry.getLookupDefinition();
 51  0
             lookupMap = new ExportMap("lookup");
 52  
 
 53  
             // simple properties
 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  
             // complex properties
 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  
 }