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