| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ValidationResultInfo |
|
| 1.1;1.1 | ||||
| ValidationResultInfo$ErrorLevel |
|
| 1.1;1.1 |
| 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.validation.dto; | |
| 17 | ||
| 18 | import java.io.Serializable; | |
| 19 | ||
| 20 | import javax.xml.bind.annotation.XmlAccessType; | |
| 21 | import javax.xml.bind.annotation.XmlAccessorType; | |
| 22 | import javax.xml.bind.annotation.XmlElement; | |
| 23 | ||
| 24 | @XmlAccessorType(XmlAccessType.FIELD) | |
| 25 | public class ValidationResultInfo implements Serializable { | |
| 26 | ||
| 27 | private static final long serialVersionUID = 1L; | |
| 28 | ||
| 29 | 0 | public enum ErrorLevel { |
| 30 | 0 | OK(0), WARN(1), ERROR(2); |
| 31 | ||
| 32 | int level; | |
| 33 | ||
| 34 | 0 | private ErrorLevel(int level) { |
| 35 | 0 | this.level = level; |
| 36 | 0 | } |
| 37 | ||
| 38 | public int getLevel() { | |
| 39 | 0 | return level; |
| 40 | } | |
| 41 | ||
| 42 | public static ErrorLevel min(ErrorLevel e1, ErrorLevel e2) { | |
| 43 | 0 | return e1.ordinal() < e2.ordinal() ? e1 : e2; |
| 44 | } | |
| 45 | ||
| 46 | public static ErrorLevel max(ErrorLevel e1, ErrorLevel e2) { | |
| 47 | 0 | return e1.ordinal() > e2.ordinal() ? e1 : e2; |
| 48 | } | |
| 49 | } | |
| 50 | ||
| 51 | 0 | private transient Object invalidData = null; |
| 52 | ||
| 53 | @XmlElement | |
| 54 | protected String element; | |
| 55 | ||
| 56 | 0 | @XmlElement |
| 57 | protected ErrorLevel level = ErrorLevel.OK; | |
| 58 | ||
| 59 | @XmlElement | |
| 60 | protected String message; | |
| 61 | ||
| 62 | public ValidationResultInfo() { | |
| 63 | 0 | super(); |
| 64 | 0 | this.level = ErrorLevel.OK; |
| 65 | 0 | } |
| 66 | ||
| 67 | public ValidationResultInfo(String element) { | |
| 68 | 0 | super(); |
| 69 | 0 | this.level = ErrorLevel.OK; |
| 70 | 0 | this.element = element; |
| 71 | 0 | } |
| 72 | ||
| 73 | public ValidationResultInfo(String element, Object invalidData) { | |
| 74 | 0 | this(element); |
| 75 | 0 | this.invalidData = invalidData; |
| 76 | 0 | } |
| 77 | ||
| 78 | /** | |
| 79 | * @return the level | |
| 80 | */ | |
| 81 | public ErrorLevel getLevel() { | |
| 82 | 0 | return level; |
| 83 | } | |
| 84 | ||
| 85 | /** | |
| 86 | * @param level | |
| 87 | * the level to set | |
| 88 | */ | |
| 89 | public void setLevel(ErrorLevel level) { | |
| 90 | 0 | this.level = level; |
| 91 | 0 | } |
| 92 | ||
| 93 | /** | |
| 94 | * @return the message | |
| 95 | */ | |
| 96 | public String getMessage() { | |
| 97 | 0 | return message; |
| 98 | } | |
| 99 | ||
| 100 | /** | |
| 101 | * @param message | |
| 102 | * the message to set | |
| 103 | */ | |
| 104 | public void setMessage(String message) { | |
| 105 | 0 | this.message = message; |
| 106 | 0 | } |
| 107 | ||
| 108 | public String getElement() { | |
| 109 | 0 | return element; |
| 110 | } | |
| 111 | ||
| 112 | public void setElement(String element) { | |
| 113 | 0 | this.element = element; |
| 114 | 0 | } |
| 115 | ||
| 116 | /** | |
| 117 | * Returns the ValidationResult's error level | |
| 118 | * | |
| 119 | * @return | |
| 120 | */ | |
| 121 | public ErrorLevel getErrorLevel() { | |
| 122 | 0 | return level; |
| 123 | } | |
| 124 | ||
| 125 | /** | |
| 126 | * Convenience method. Adds a message with an error level of WARN | |
| 127 | * | |
| 128 | * @param message | |
| 129 | * the message to add | |
| 130 | */ | |
| 131 | public void setWarning(String message) { | |
| 132 | 0 | this.level = ErrorLevel.WARN; |
| 133 | 0 | this.message = message; |
| 134 | 0 | } |
| 135 | ||
| 136 | /** | |
| 137 | * Convenience method. Adds a message with an error level of ERROR | |
| 138 | * | |
| 139 | * @param message | |
| 140 | * the message to add | |
| 141 | */ | |
| 142 | public void setError(String message) { | |
| 143 | 0 | this.level = ErrorLevel.ERROR; |
| 144 | 0 | this.message = message; |
| 145 | 0 | } |
| 146 | ||
| 147 | /** | |
| 148 | * Convenience method. Returns true if getErrorLevel() == ErrorLevel.OK | |
| 149 | * | |
| 150 | * @return true if getErrorLevel() == ErrorLevel.OK | |
| 151 | */ | |
| 152 | public boolean isOk() { | |
| 153 | 0 | return getErrorLevel() == ErrorLevel.OK; |
| 154 | } | |
| 155 | ||
| 156 | /** | |
| 157 | * Convenience method. Returns true if getErrorLevel() == ErrorLevel.WARN | |
| 158 | * | |
| 159 | * @return true if getErrorLevel() == ErrorLevel.WARN | |
| 160 | */ | |
| 161 | public boolean isWarn() { | |
| 162 | 0 | return getErrorLevel() == ErrorLevel.WARN; |
| 163 | } | |
| 164 | ||
| 165 | /** | |
| 166 | * Convenience method. Returns true if getErrorLevel() == ErrorLevel.ERROR | |
| 167 | * | |
| 168 | * @return true if getErrorLevel() == ErrorLevel.ERROR | |
| 169 | */ | |
| 170 | public boolean isError() { | |
| 171 | 0 | return getErrorLevel() == ErrorLevel.ERROR; |
| 172 | } | |
| 173 | ||
| 174 | public String toString() { | |
| 175 | 0 | return "[" + level + "] Path: [" + element + "] - " + message |
| 176 | + " data=[" + invalidData + "]"; | |
| 177 | } | |
| 178 | ||
| 179 | } |