Coverage Report - org.kuali.rice.krad.datadictionary.exporter.MaintenanceDocumentEntryMapper
 
Classes in this File Line Coverage Branch Coverage Complexity
MaintenanceDocumentEntryMapper
0%
0/49
0%
0/14
2.333
 
 1  
 /*
 2  
  * Copyright 2005-2008 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.apache.commons.lang.StringUtils;
 21  
 import org.kuali.rice.krad.datadictionary.MaintainableCollectionDefinition;
 22  
 import org.kuali.rice.krad.datadictionary.MaintainableFieldDefinition;
 23  
 import org.kuali.rice.krad.datadictionary.MaintainableItemDefinition;
 24  
 import org.kuali.rice.krad.datadictionary.MaintainableSectionDefinition;
 25  
 import org.kuali.rice.krad.datadictionary.MaintainableSubSectionHeaderDefinition;
 26  
 import org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry;
 27  
 
 28  
 /**
 29  
  * MaintenanceDocumentEntryMapper
 30  
  * 
 31  
  * 
 32  
  */
 33  
 public class MaintenanceDocumentEntryMapper extends DocumentEntryMapper {
 34  
 
 35  
     /**
 36  
      * Default constructor
 37  
      */
 38  0
     public MaintenanceDocumentEntryMapper() {
 39  0
     }
 40  
 
 41  
 
 42  
     /**
 43  
      * @param entry
 44  
      * @return Map containing a String- and Map-based representation of the given entry
 45  
      */
 46  
     public ExportMap mapEntry(MaintenanceDocumentEntry entry) {
 47  0
         ExportMap entryMap = super.mapEntry(entry);
 48  
 
 49  
         // simple properties
 50  0
         entryMap.set("maintenanceDocument", "true");
 51  0
         entryMap.set("businessObjectClass", entry.getBusinessObjectClass().getName());
 52  0
         entryMap.set("maintainableClass", entry.getMaintainableClass().getName());
 53  
 
 54  
         // complex properties
 55  0
         entryMap.set(buildMaintainableSectionsMap(entry));
 56  
 
 57  0
         return entryMap;
 58  
     }
 59  
 
 60  
     private ExportMap buildMaintainableSectionsMap(MaintenanceDocumentEntry entry) {
 61  0
         ExportMap maintainableSectionsMap = new ExportMap("maintainableSections");
 62  
 
 63  0
         int index = 0;
 64  0
         for (Iterator i = entry.getMaintainableSections().iterator(); i.hasNext();) {
 65  0
             MaintainableSectionDefinition section = (MaintainableSectionDefinition) i.next();
 66  
 
 67  0
             maintainableSectionsMap.set(buildMaintainableSectionMap(section, index++));
 68  0
         }
 69  
 
 70  0
         return maintainableSectionsMap;
 71  
     }
 72  
 
 73  
     private ExportMap buildMaintainableSectionMap(MaintainableSectionDefinition section, int index) {
 74  0
         ExportMap sectionMap = new ExportMap(Integer.toString(index));
 75  
 
 76  0
         sectionMap.set("index", Integer.toString(index));
 77  0
         sectionMap.set("title", section.getTitle());
 78  
 
 79  0
         sectionMap.set(buildMaintainableItemsMap(section));
 80  
 
 81  0
         return sectionMap;
 82  
     }
 83  
 
 84  
     private ExportMap buildMaintainableItemsMap(MaintainableSectionDefinition section) {
 85  0
         ExportMap itemsMap = new ExportMap("maintainableItems");
 86  
 
 87  0
         for (Iterator i = section.getMaintainableItems().iterator(); i.hasNext();) {
 88  0
             MaintainableItemDefinition item = (MaintainableItemDefinition) i.next();
 89  0
             itemsMap.set(buildMaintainableItemMap(item));
 90  0
         }
 91  
 
 92  0
         return itemsMap;
 93  
     }
 94  
 
 95  
     private ExportMap buildMaintainableItemMap(MaintainableItemDefinition item) {
 96  0
         ExportMap itemMap = new ExportMap(item.getName());
 97  
 
 98  0
         if (item instanceof MaintainableFieldDefinition) {
 99  0
             MaintainableFieldDefinition field = (MaintainableFieldDefinition) item;
 100  
 
 101  0
             itemMap.set("field", "true");
 102  0
             itemMap.set("name", field.getName());
 103  0
             itemMap.set("required", Boolean.toString(field.isRequired()));
 104  0
                         if (StringUtils.isNotBlank(field.getAlternateDisplayAttributeName())) {
 105  0
                                 itemMap.set("alternateDisplayAttributeName", field.getAlternateDisplayAttributeName());
 106  
                         }
 107  0
                         if (StringUtils.isNotBlank(field.getAdditionalDisplayAttributeName())) {
 108  0
                                 itemMap.set("additionalDisplayAttributeName", field.getAdditionalDisplayAttributeName());
 109  
                         }
 110  0
         }
 111  0
         else if (item instanceof MaintainableCollectionDefinition) {
 112  0
             MaintainableCollectionDefinition collection = (MaintainableCollectionDefinition) item;
 113  
 
 114  0
             itemMap.set("collection", "true");
 115  0
             itemMap.set("name", collection.getName());
 116  0
             itemMap.set("businessObjectClass", collection.getBusinessObjectClass().getName());
 117  0
         }
 118  0
         else if (item instanceof MaintainableSubSectionHeaderDefinition) {
 119  0
             MaintainableSubSectionHeaderDefinition subSectionHeader = (MaintainableSubSectionHeaderDefinition) item;
 120  0
             itemMap.set("name", subSectionHeader.getName());
 121  0
         }
 122  
         else {
 123  0
             throw new IllegalStateException("unable to create itemMap for unknown MaintainableItem subclass '" + item.getClass().getName() + "'");
 124  
         }
 125  
 
 126  0
         return itemMap;
 127  
     }
 128  
 }