Coverage Report - org.kuali.student.common.assembly.data.Metadata
 
Classes in this File Line Coverage Branch Coverage Complexity
Metadata
72%
90/124
55%
19/34
1.415
Metadata$WriteAccess
100%
3/3
N/A
1.415
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.common.assembly.data;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.ArrayList;
 20  
 import java.util.HashMap;
 21  
 import java.util.LinkedHashMap;
 22  
 import java.util.List;
 23  
 import java.util.Map;
 24  
 import java.util.Map.Entry;
 25  
 
 26  
 public class Metadata implements Serializable {
 27  
 
 28  
     private static final long serialVersionUID = 1L;
 29  
 
 30  192
     public enum WriteAccess {
 31  1
         ON_CREATE, /* must also be required */
 32  1
         ALWAYS, NEVER, WHEN_NULL, REQUIRED
 33  
     }
 34  
 
 35  
     private String name;
 36  
     private String labelKey;
 37  
     private WriteAccess writeAccess;
 38  
     
 39  588
     private boolean canUnmask = false;
 40  588
     private boolean canView = true;
 41  588
     private boolean canEdit = true;
 42  588
     private boolean dynamic = false;
 43  
     
 44  
         protected String partialMaskFormatter;//Regex replace to do a partial mask          
 45  
         protected String maskFormatter;//Regex replace to do a mask
 46  
         
 47  
         private boolean onChangeRefreshMetadata;
 48  
 
 49  
     private Data.DataType dataType;
 50  
     
 51  
     private Data.Value defaultValue;
 52  
     
 53  
     private String defaultValuePath;
 54  
     
 55  
     //TODO: When all dictionaries have been updated, this needs to be changed to a single value object.
 56  
     //No need for it to be a list with new dictionary structure. 
 57  
     private List<ConstraintMetadata> constraints;
 58  
     
 59  
     private LookupMetadata initialLookup;
 60  
 
 61  
     private String lookupContextPath;
 62  
     
 63  
     private List<LookupMetadata> additionalLookups;
 64  
 
 65  
     private Map<String, Metadata> childProperties;
 66  
     
 67  282
     public Metadata() {
 68  
         
 69  282
     }
 70  
     
 71  
     /**
 72  
      * 
 73  
      * This constructs a new Metadata instance. References to non-Metadata objects are maintained, as no permissions are applied to them.
 74  
      * 
 75  
      * @param toClone the Metadata instance to be cloned
 76  
      */
 77  306
     public Metadata(Metadata toClone) {
 78  306
         this.additionalLookups = toClone.additionalLookups;
 79  306
         this.canEdit = toClone.canEdit;
 80  306
         this.canUnmask = toClone.canUnmask;
 81  306
         this.canView = toClone.canView;
 82  306
         if(toClone.childProperties != null) {
 83  88
             this.childProperties = new HashMap<String, Metadata>();
 84  88
             for(Map.Entry<String, Metadata> childProperty : toClone.childProperties.entrySet()) {
 85  304
                 this.childProperties.put(childProperty.getKey(), new Metadata(childProperty.getValue()));
 86  
             }
 87  
             
 88  
         }
 89  306
         this.constraints = toClone.constraints;
 90  306
         this.dataType = toClone.dataType;
 91  306
         this.defaultValue = toClone.defaultValue;
 92  306
         this.defaultValuePath = toClone.defaultValuePath;
 93  306
         this.dynamic = toClone.dynamic;
 94  306
         this.initialLookup = toClone.initialLookup;
 95  306
         this.labelKey = toClone.labelKey;
 96  306
         this.lookupContextPath = toClone.lookupContextPath;
 97  306
         this.maskFormatter = toClone.maskFormatter;
 98  306
         this.name = toClone.name;
 99  306
         this.onChangeRefreshMetadata = toClone.onChangeRefreshMetadata;
 100  306
         this.partialMaskFormatter = toClone.partialMaskFormatter;
 101  306
         this.writeAccess = toClone.writeAccess;
 102  306
     }
 103  
     
 104  
     @Override
 105  
     public String toString() {
 106  0
         StringBuilder sb = new StringBuilder();
 107  0
         _toString(sb);
 108  0
         return sb.toString();
 109  
     }
 110  
     
 111  
     protected void _toString(StringBuilder sb) {
 112  0
         Data.DataType type = (null == dataType) ? Data.DataType.DATA : dataType;
 113  0
         sb.append("type: " + type.toString());
 114  0
         sb.append(", canEdit: " + canEdit);
 115  0
         sb.append(", canView: " + canView);
 116  0
         sb.append(", defaultValue: ");
 117  0
         sb.append(null == defaultValue ? "null" : defaultValue.toString());
 118  0
         sb.append(", constraints: {");
 119  0
         if (null != constraints) {
 120  0
             for (ConstraintMetadata constraint : constraints) {
 121  0
                 sb.append(constraint.toString());
 122  
             }
 123  
         }
 124  0
         sb.append("}");
 125  0
         sb.append(", Properties: {");
 126  0
         if (null != childProperties) {
 127  0
             for (Entry<String, Metadata> e : childProperties.entrySet()) {
 128  0
                 sb.append("(");
 129  0
                 sb.append(e.getKey());
 130  0
                 sb.append(" = ");
 131  0
                 Metadata m = e.getValue();
 132  0
                 if (m == null) {
 133  0
                     sb.append("null");
 134  
                 } else {
 135  0
                     m._toString(sb);
 136  
                 }
 137  0
                 sb.append(");");
 138  0
             }
 139  
         }
 140  0
         sb.append("}");
 141  
         // TODO dump lookup/etc info as well
 142  0
     }
 143  
 
 144  
     public List<ConstraintMetadata> getConstraints() {
 145  223
         if (constraints == null) {
 146  0
             constraints = new ArrayList<ConstraintMetadata>();
 147  
         }
 148  223
         return constraints;
 149  
     }
 150  
 
 151  
     public void setConstraints(List<ConstraintMetadata> constraints) {
 152  93
             this.constraints = constraints;
 153  93
     }
 154  
 
 155  
     /**
 156  
      * This is used to set all non-server side constraints for the metadata.
 157  
      * 
 158  
      * @param constraints
 159  
      */
 160  
     public void setNonServerConstraints(List<ConstraintMetadata> constraints) {
 161  149
             if (constraints != null){
 162  148
                     List<ConstraintMetadata> metadataConstraints = new ArrayList<ConstraintMetadata>();
 163  148
                     for (ConstraintMetadata constraint:constraints){
 164  508
                             if (!"single".equals(constraint.getId()) && 
 165  
                                     !"optional".equals(constraint.getId()) &&
 166  
                                     !constraint.isServerSide()){
 167  193
                                     metadataConstraints.add(constraint);
 168  
                             }
 169  
                     }
 170  148
             this.constraints = metadataConstraints;
 171  
             }
 172  149
     }
 173  
 
 174  
     public Data.DataType getDataType() {
 175  364
         return dataType;
 176  
     }
 177  
 
 178  
     public void setDataType(Data.DataType dataType) {
 179  300
         this.dataType = dataType;
 180  300
     }
 181  
 
 182  
     public Data.Value getDefaultValue() {
 183  25
         return defaultValue;
 184  
     }
 185  
 
 186  
     public void setDefaultValue(Data.Value defaultValue) {
 187  238
         this.defaultValue = defaultValue;
 188  238
     }
 189  
 
 190  
     public String getDefaultValuePath() {
 191  0
         return defaultValuePath;
 192  
     }
 193  
 
 194  
     public void setDefaultValuePath(String defaultValuePath) {
 195  93
         this.defaultValuePath = defaultValuePath;
 196  93
     }
 197  
 
 198  
     public LookupMetadata getInitialLookup() {
 199  54
         return initialLookup;
 200  
     }
 201  
 
 202  
     public void setInitialLookup(LookupMetadata initialLookup) {
 203  150
         this.initialLookup = initialLookup;
 204  150
     }
 205  
 
 206  
     public String getLookupContextPath() {
 207  0
         return lookupContextPath;
 208  
     }
 209  
 
 210  
     public void setLookupContextPath(String lookupContextPath) {
 211  145
         this.lookupContextPath = lookupContextPath;
 212  145
     }
 213  
 
 214  
     public List<LookupMetadata> getAdditionalLookups() {
 215  75
         if (additionalLookups == null) {
 216  25
             additionalLookups = new ArrayList<LookupMetadata>();
 217  
         }
 218  75
         return additionalLookups;
 219  
     }
 220  
 
 221  
     public void setAdditionalLookups(List<LookupMetadata> additionalLookups) {
 222  145
         this.additionalLookups = additionalLookups;
 223  145
     }
 224  
 
 225  
     public Map<String, Metadata> getProperties() {
 226  71
         if (childProperties == null) {
 227  11
             childProperties = new LinkedHashMap<String, Metadata>();
 228  
         }
 229  71
         return childProperties;
 230  
     }
 231  
 
 232  
     public void setProperties(Map<String, Metadata> properties) {
 233  79
         this.childProperties = properties;
 234  79
     }
 235  
 
 236  
     public WriteAccess getWriteAccess() {
 237  0
         return writeAccess;
 238  
     }
 239  
 
 240  
     public void setWriteAccess(WriteAccess writeAccess) {
 241  281
         this.writeAccess = writeAccess;
 242  281
     }
 243  
 
 244  
     
 245  
     public boolean isOnChangeRefreshMetadata() {
 246  0
         return onChangeRefreshMetadata;
 247  
     }
 248  
 
 249  
     public void setOnChangeRefreshMetadata(boolean onChangeRefereshMetadata) {
 250  21
         this.onChangeRefreshMetadata = onChangeRefereshMetadata;
 251  21
     }
 252  
 
 253  
     public boolean isCanUnmask() {
 254  25
         return canUnmask;
 255  
     }
 256  
 
 257  
     public void setCanUnmask(boolean canUnmask) {
 258  238
         this.canUnmask = canUnmask;
 259  238
     }
 260  
 
 261  
     public boolean isCanView() {
 262  25
         return canView;
 263  
     }
 264  
 
 265  
     public void setCanView(boolean canView) {
 266  238
         this.canView = canView;
 267  238
     }
 268  
 
 269  
     public boolean isCanEdit() {
 270  45
         return canEdit;
 271  
     }
 272  
 
 273  
     public void setCanEdit(boolean canEdit) {
 274  245
         this.canEdit = canEdit;
 275  245
     }
 276  
 
 277  
     public String getName() {
 278  0
         return name;
 279  
     }
 280  
 
 281  
     public void setName(String name) {
 282  145
         this.name = name;
 283  145
     }
 284  
 
 285  
         public boolean isDynamic() {
 286  25
                 return dynamic;
 287  
         }
 288  
 
 289  
         public void setDynamic(boolean dynamic) {
 290  93
                 this.dynamic = dynamic;
 291  93
         }
 292  
 
 293  
         public String getLabelKey() {
 294  25
                 return labelKey;
 295  
         }
 296  
 
 297  
         public void setLabelKey(String labelKey) {
 298  93
                 this.labelKey = labelKey;
 299  93
         }
 300  
 
 301  
     public String getPartialMaskFormatter() {
 302  3
                 return partialMaskFormatter;
 303  
         }
 304  
 
 305  
         public void setPartialMaskFormatter(String partialMaskFormatter) {
 306  11
                 this.partialMaskFormatter = partialMaskFormatter;
 307  11
         }
 308  
 
 309  
         public String getMaskFormatter() {
 310  4
                 return maskFormatter;
 311  
         }
 312  
 
 313  
         public void setMaskFormatter(String maskFormatter) {
 314  12
                 this.maskFormatter = maskFormatter;
 315  12
         }
 316  
 }