Coverage Report - org.kuali.rice.krad.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.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  
  * LookupMapBuilder
 27  
  *
 28  
  *
 29  
  */
 30  
 public class LookupMapBuilder {
 31  
 
 32  
     /**
 33  
      * Default constructor
 34  
      */
 35  0
     public LookupMapBuilder() {
 36  0
     }
 37  
 
 38  
 
 39  
     /**
 40  
      * @param entry
 41  
      * @return ExportMap containing the standard entries for the given entry's LookupDefinition, or null if the given entry has no
 42  
      *         lookupDefinition
 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  
             // simple properties
 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  
             // complex properties
 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  
 }