Coverage Report - org.kuali.rice.kns.datadictionary.exporter.AttributesMapBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
AttributesMapBuilder
0%
0/113
0%
0/80
11
 
 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 org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.kns.datadictionary.control.ButtonControlDefinition;
 20  
 import org.kuali.rice.krad.datadictionary.control.ControlDefinition;
 21  
 import org.kuali.rice.kns.datadictionary.control.CurrencyControlDefinition;
 22  
 import org.kuali.rice.kns.datadictionary.control.LinkControlDefinition;
 23  
 import org.kuali.rice.krad.datadictionary.AttributeDefinition;
 24  
 import org.kuali.rice.krad.datadictionary.DataDictionaryEntryBase;
 25  
 import org.kuali.rice.krad.datadictionary.exporter.ExportMap;
 26  
 
 27  
 /**
 28  
  * AttributesMapBuilder
 29  
  *
 30  
  *
 31  
  */
 32  
 @Deprecated
 33  
 public class AttributesMapBuilder {
 34  
 
 35  
     /**
 36  
      * Default constructor
 37  
      */
 38  0
     public AttributesMapBuilder() {
 39  0
     }
 40  
 
 41  
 
 42  
     /**
 43  
      * @param entry
 44  
      * @return ExportMap containing the standard entries for the entry's AttributesDefinition
 45  
      */
 46  
     public ExportMap buildAttributesMap(DataDictionaryEntryBase entry) {
 47  0
         ExportMap attributesMap = new ExportMap("attributes");
 48  
 
 49  0
         for ( AttributeDefinition attribute : entry.getAttributes() ) {
 50  0
             attributesMap.set(buildAttributeMap(attribute, entry.getFullClassName()));
 51  
         }
 52  
 
 53  0
         return attributesMap;
 54  
     }
 55  
 
 56  
     private ExportMap buildAttributeMap(AttributeDefinition attribute, String fullClassName) {
 57  0
         ExportMap attributeMap = new ExportMap(attribute.getName());
 58  
 
 59  
         // simple properties
 60  0
         attributeMap.set("name", attribute.getName());
 61  0
         attributeMap.set("forceUppercase", attribute.getForceUppercase().toString());
 62  0
         attributeMap.set("label", attribute.getLabel());
 63  0
         attributeMap.set("shortLabel", attribute.getShortLabel());
 64  
        
 65  0
         attributeMap.set("maxLength", attribute.getMaxLength().toString());
 66  0
         String exclusiveMin = attribute.getExclusiveMin();
 67  0
         if (exclusiveMin != null) {
 68  0
             attributeMap.set("exclusiveMin", exclusiveMin/*.toString()*/);
 69  
         }
 70  0
         String exclusiveMax = attribute.getInclusiveMax();
 71  0
         if (exclusiveMax != null) {
 72  0
             attributeMap.set("exclusiveMax", exclusiveMax/*.toString()*/);
 73  
         }
 74  
 
 75  0
         attributeMap.set("required", attribute.isRequired().toString());
 76  0
         if (attribute.getSummary() != null) {
 77  0
             attributeMap.set("summary", attribute.getSummary());
 78  
         }
 79  0
         if (attribute.getDescription() != null) {
 80  0
             attributeMap.set("description", attribute.getDescription());
 81  
         }
 82  0
         if (attribute.hasFormatterClass()) {
 83  0
             attributeMap.set("formatterClass", attribute.getFormatterClass());
 84  
         }
 85  
 
 86  
         // complex properties
 87  0
         if (attribute.hasValidationPattern()) {
 88  0
             attributeMap.set(attribute.getValidationPattern().buildExportMap("validationPattern"));
 89  
         }
 90  
 
 91  0
         if(attribute.hasAttributeSecurity()){
 92  0
                 attributeMap.set("attributeSecurityMask", String.valueOf(attribute.getAttributeSecurity().isMask()));
 93  0
                 attributeMap.set("attributeSecurityPartialMask", String.valueOf(attribute.getAttributeSecurity().isPartialMask()));
 94  0
                 attributeMap.set("attributeSecurityHide", String.valueOf(attribute.getAttributeSecurity().isHide()));
 95  0
                 attributeMap.set("attributeSecurityReadOnly", String.valueOf(attribute.getAttributeSecurity().isReadOnly()));
 96  
           
 97  
                 // TODO: consider whether to export class names from the attribute security
 98  
         }
 99  
 
 100  0
         attributeMap.set(buildControlMap(attribute));
 101  0
         attributeMap.set("fullClassName", fullClassName);
 102  
 
 103  0
         return attributeMap;
 104  
     }
 105  
 
 106  
 
 107  
     private ExportMap buildControlMap(AttributeDefinition attribute) {
 108  0
         ControlDefinition control = attribute.getControl();
 109  0
         ExportMap controlMap = new ExportMap("control");
 110  
 
 111  0
         if (control.isCheckbox()) {
 112  0
             controlMap.set("checkbox", "true");
 113  
         }
 114  0
         else if (control.isHidden()) {
 115  0
             controlMap.set("hidden", "true");
 116  
         }
 117  0
         else if (control.isKualiUser()) {
 118  0
             controlMap.set("kualiUser", "true");
 119  
         }
 120  0
         else if (control.isRadio()) {
 121  0
             controlMap.set("radio", "true");
 122  0
             controlMap.set("valuesFinder", control.getValuesFinderClass());
 123  0
             if (control.getBusinessObjectClass() != null) {
 124  0
                 controlMap.set("businessObject", control.getBusinessObjectClass());
 125  
             }
 126  0
             if (StringUtils.isNotEmpty(control.getKeyAttribute())) {
 127  0
                 controlMap.set("keyAttribute", control.getKeyAttribute());
 128  
             }
 129  0
             if (StringUtils.isNotEmpty(control.getLabelAttribute())) {
 130  0
                 controlMap.set("labelAttribute", control.getLabelAttribute());
 131  
             }
 132  0
             if (control.getIncludeKeyInLabel() != null) {
 133  0
                 controlMap.set("includeKeyInLabel", control.getIncludeKeyInLabel().toString());
 134  
             }
 135  
         }
 136  0
         else if (control.isSelect()) {
 137  0
             controlMap.set("select", "true");
 138  0
             controlMap.set("valuesFinder", control.getValuesFinderClass());
 139  0
             if (control.getBusinessObjectClass() != null) {
 140  0
                 controlMap.set("businessObject", control.getBusinessObjectClass());
 141  
             }
 142  0
             if (StringUtils.isNotEmpty(control.getKeyAttribute())) {
 143  0
                 controlMap.set("keyAttribute", control.getKeyAttribute());
 144  
             }
 145  0
             if (StringUtils.isNotEmpty(control.getLabelAttribute())) {
 146  0
                 controlMap.set("labelAttribute", control.getLabelAttribute());
 147  
             }
 148  0
             if (control.getIncludeBlankRow() != null) {
 149  0
                 controlMap.set("includeBlankRow", control.getIncludeBlankRow().toString());
 150  
             }
 151  0
             if (control.getIncludeKeyInLabel() != null) {
 152  0
                 controlMap.set("includeKeyInLabel", control.getIncludeKeyInLabel().toString());
 153  
             }
 154  
         }
 155  0
         else if (control.isMultiselect()) {
 156  0
             controlMap.set("multiselect", "true");
 157  0
             controlMap.set("valuesFinder", control.getValuesFinderClass());
 158  0
             if (control.getBusinessObjectClass() != null) {
 159  0
                 controlMap.set("businessObject", control.getBusinessObjectClass());
 160  
             }
 161  0
             if (StringUtils.isNotEmpty(control.getKeyAttribute())) {
 162  0
                 controlMap.set("keyAttribute", control.getKeyAttribute());
 163  
             }
 164  0
             if (StringUtils.isNotEmpty(control.getLabelAttribute())) {
 165  0
                 controlMap.set("labelAttribute", control.getLabelAttribute());
 166  
             }
 167  0
             if (control.getIncludeKeyInLabel() != null) {
 168  0
                 controlMap.set("includeKeyInLabel", control.getIncludeKeyInLabel().toString());
 169  
             }
 170  0
             if (control.getSize() != null) {
 171  0
                     controlMap.set("size", control.getSize().toString());
 172  
             }
 173  
         }
 174  0
         else if (control.isText()) {
 175  0
             controlMap.set("text", "true");
 176  0
             controlMap.set("size", control.getSize().toString());
 177  0
             controlMap.set("datePicker", Boolean.valueOf(control.isDatePicker()).toString());
 178  0
             controlMap.set("ranged", Boolean.valueOf(control.isRanged()).toString());
 179  
         }
 180  0
         else if (control.isTextarea()) {
 181  0
             controlMap.set("textarea", "true");
 182  0
             controlMap.set("rows", control.getRows().toString());
 183  0
             controlMap.set("cols", control.getCols().toString());
 184  0
             controlMap.set("expandedTextArea", Boolean.valueOf(control.isExpandedTextArea()).toString());
 185  
         }
 186  0
         else if (control.isCurrency()) {
 187  0
             controlMap.set("currency", "true");
 188  0
             controlMap.set("size", control.getSize().toString());
 189  0
             controlMap.set("formattedMaxLength", ((CurrencyControlDefinition) control).getFormattedMaxLength().toString());
 190  
         }
 191  0
         else if (control.isLookupHidden()) {
 192  0
             controlMap.set("lookupHidden", "true");
 193  
         }
 194  0
         else if (control.isLookupReadonly()) {
 195  0
             controlMap.set("lookupReadonly", "true");
 196  0
         }else if (control.isButton()) {
 197  0
             controlMap.set("button", "true");
 198  0
             if (StringUtils.isNotEmpty(((ButtonControlDefinition) control).getImageSrc())) {
 199  0
                     controlMap.set("imageSrc", ((ButtonControlDefinition) control).getImageSrc());
 200  
             }
 201  0
             if (StringUtils.isNotEmpty(((ButtonControlDefinition) control).getStyleClass())) {
 202  0
                     controlMap.set("styleClass", ((ButtonControlDefinition) control).getStyleClass() );
 203  
             }
 204  0
         }else if (control.isLink()) {
 205  0
             controlMap.set("link", "true");
 206  0
             if (StringUtils.isNotEmpty(((LinkControlDefinition) control).getTarget())) {
 207  0
                     controlMap.set("target", ((LinkControlDefinition) control).getTarget());
 208  
             }
 209  0
             if (StringUtils.isNotEmpty(((LinkControlDefinition) control).getStyleClass())) {
 210  0
                     controlMap.set("styleClass", ((LinkControlDefinition) control).getStyleClass() );
 211  
             }
 212  0
             if (StringUtils.isNotEmpty(((LinkControlDefinition) control).getHrefText())) {
 213  0
                     controlMap.set("hrefText", ((LinkControlDefinition) control).getHrefText());
 214  
             }
 215  
         }
 216  
 
 217  0
         return controlMap;
 218  
     }
 219  
 }