Coverage Report - org.kuali.student.r2.common.dto.ValidationResultInfo
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidationResultInfo
0%
0/43
0%
0/8
1.048
 
 1  
 /*
 2  
  * Copyright 2010 The Kuali Foundation 
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the
 5  
  * "License"); you may not use this file except in compliance with the
 6  
  * License. You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.osedu.org/licenses/ECL-2.0
 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
 13  
  * implied. See the License for the specific language governing
 14  
  * permissions and limitations under the License.
 15  
  */
 16  
 
 17  
 package org.kuali.student.r2.common.dto;
 18  
 
 19  
 import java.io.Serializable;
 20  
 import java.util.List;
 21  
 
 22  
 import javax.xml.bind.annotation.XmlAccessType;
 23  
 import javax.xml.bind.annotation.XmlAccessorType;
 24  
 import javax.xml.bind.annotation.XmlAnyElement;
 25  
 import javax.xml.bind.annotation.XmlElement;
 26  
 import javax.xml.bind.annotation.XmlType;
 27  
 
 28  
 import org.kuali.student.r2.common.infc.ValidationResult;
 29  
 import org.w3c.dom.Element;
 30  
 
 31  
 /**
 32  
  * Information about the results of a data validation.
 33  
  *
 34  
  * @author nwright
 35  
  */
 36  
 
 37  
 @XmlAccessorType(XmlAccessType.FIELD)
 38  
 @XmlType(name = "ValidationResultInfo", propOrder = {
 39  
                 "element", "level", "message",
 40  
                 "_futureElements"})
 41  
 
 42  
 public class ValidationResultInfo
 43  
     implements ValidationResult, Serializable {
 44  
 
 45  
     private static final long serialVersionUID = 1L;
 46  
     
 47  
     @XmlElement
 48  
     private String element;
 49  
     
 50  
     @XmlElement
 51  
     private ErrorLevel level;
 52  
     
 53  
     @XmlElement
 54  
     private String message;
 55  
 
 56  
 //  used to hold debugging information 
 57  
 //  not intended to be sent over the wire          
 58  
     private transient Object invalidData;
 59  
 
 60  
     @XmlAnyElement
 61  
     private List<Element> _futureElements;
 62  
 
 63  
     /**
 64  
      * Constructs a new ValidationResultInfo.
 65  
      */
 66  0
     public ValidationResultInfo() {
 67  0
       this.level = ErrorLevel.OK;
 68  0
     }
 69  
     
 70  
     /**
 71  
      * convenience constructor carried over from R1
 72  
      */
 73  
     public ValidationResultInfo(String element) {
 74  0
         this();
 75  0
         this.element = element;
 76  0
     }
 77  
     
 78  
     /**
 79  
      * convenience constructor carried over from R1
 80  
      */
 81  
     public ValidationResultInfo(String element, Object invalidData) {
 82  0
         this(element);
 83  0
         this.invalidData = invalidData;
 84  0
     }
 85  
 
 86  
     /**
 87  
      * Constructs a new ValidationResultInfo from another
 88  
      * ValidationResult.
 89  
      *
 90  
      * @param result the ValidationResult to copy
 91  
      */
 92  0
     public ValidationResultInfo(ValidationResult result) {
 93  0
         if (result != null) {
 94  0
             this.level = result.getLevel();
 95  0
             this.element = result.getElement();
 96  0
             this.message = result.getMessage();
 97  
         }
 98  0
     }
 99  
 
 100  
     /**
 101  
      * This is for compatibility with R1.
 102  
      * Use getLevel instead
 103  
      */
 104  
     @Deprecated
 105  
     public ErrorLevel getErrorLevel() {
 106  0
         return level;
 107  
     }
 108  
 
 109  
     public void setErrorLevel(ErrorLevel errorLevel) {
 110  0
         this.level = errorLevel;
 111  0
     }
 112  
 
 113  
     /**
 114  
      * Convenience method from R1 to check if this is ok
 115  
      */
 116  
     public boolean isOk() {
 117  0
         return this.level == ErrorLevel.OK;
 118  
     }
 119  
 
 120  
     /**
 121  
      * convenience method carried over from R1
 122  
      */
 123  
     public boolean isWarn() {
 124  0
         return this.level == ErrorLevel.WARN;
 125  
     }
 126  
 
 127  
     /**
 128  
      * convenience method carried over from R1
 129  
      */
 130  
     public void setWarn(String message) {
 131  0
         this.level = ErrorLevel.WARN;
 132  0
         this.message = message;
 133  0
     }
 134  
 
 135  
     /**
 136  
      * convenience method carried over from R1
 137  
      */
 138  
     public boolean isError() {
 139  0
         return this.level == ErrorLevel.ERROR;
 140  
     }
 141  
 
 142  
     @Override
 143  
     public String getMessage() {
 144  0
         return message;
 145  
     }
 146  
 
 147  
     public void setMessage(String message) {
 148  0
         this.message = message;
 149  0
     }
 150  
 
 151  
     @Override
 152  
     public String getElement() {
 153  0
         return element;
 154  
     }
 155  
 
 156  
     public void setElement(String element) {
 157  0
         this.element = element;
 158  0
     }
 159  
 
 160  
     /**
 161  
      * convenience method carried over from R1
 162  
      * Use getErrorLevel () instead
 163  
      */
 164  
     @Override
 165  
     public ErrorLevel getLevel() {
 166  0
         return this.level;
 167  
     }
 168  
 
 169  
     public void setLevel(ErrorLevel level) {
 170  0
         this.level = level;
 171  0
     }
 172  
     
 173  
     /**
 174  
      * not part of the contract but carried over from r1
 175  
      */
 176  
     public Object getInvalidData() {
 177  0
         return invalidData;
 178  
     }
 179  
 
 180  
     /**
 181  
      * not part of the contract but carried over from r1
 182  
      */
 183  
     public void setInvalidData(Object invalidData) {
 184  0
         this.invalidData = invalidData;
 185  0
     }
 186  
 
 187  
     @Override
 188  
     public String toString() {
 189  0
         return "[" + level + "] Path: [" + element + "] - " + message + " data=[" + invalidData + "]";
 190  
     }
 191  
 
 192  
     /**
 193  
      * Convenience method. Adds a message with an error level of WARN
 194  
      *
 195  
      * @param message the warning message 
 196  
      */
 197  
     public void setWarning(String message) {
 198  0
         this.level = ErrorLevel.WARN;
 199  0
         this.message = message;
 200  0
     }
 201  
 
 202  
     /**
 203  
      * Convenience method. Adds a message with an error level of ERROR
 204  
      *
 205  
      * @param message the error message to add
 206  
      */
 207  
     public void setError(String message) {
 208  0
         this.level = ErrorLevel.ERROR;
 209  0
         this.message = message;
 210  0
     }
 211  
 }