1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
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 | |
public static ErrorLevel max(ErrorLevel e1, ErrorLevel e2) { |
46 | 0 | return e1.ordinal() > e2.ordinal() ? e1 : e2; |
47 | |
} |
48 | |
} |
49 | |
|
50 | |
public ValidationResultInfo() { |
51 | 0 | super(); |
52 | 0 | this.level = ErrorLevel.OK; |
53 | 0 | } |
54 | |
|
55 | 0 | private transient Object invalidData = null; |
56 | |
|
57 | |
public ValidationResultInfo(String element) { |
58 | 0 | super(); |
59 | 0 | this.level = ErrorLevel.OK; |
60 | 0 | this.element = element; |
61 | 0 | } |
62 | |
|
63 | |
public ValidationResultInfo(String element, Object invalidData) { |
64 | 0 | this(element); |
65 | 0 | this.invalidData = invalidData; |
66 | 0 | } |
67 | |
|
68 | |
|
69 | |
@XmlElement |
70 | |
protected String element; |
71 | |
|
72 | 0 | @XmlElement |
73 | |
protected ErrorLevel level = ErrorLevel.OK; |
74 | |
|
75 | |
@XmlElement |
76 | |
protected String message; |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public ErrorLevel getLevel() { |
82 | 0 | return level; |
83 | |
} |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
public void setLevel(ErrorLevel level) { |
89 | 0 | this.level = level; |
90 | 0 | } |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
public String getMessage() { |
96 | 0 | return message; |
97 | |
} |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
public void setMessage(String message) { |
103 | 0 | this.message = message; |
104 | 0 | } |
105 | |
|
106 | |
public String getElement() { |
107 | 0 | return element; |
108 | |
} |
109 | |
|
110 | |
public void setElement(String element) { |
111 | 0 | this.element = element; |
112 | 0 | } |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
public ErrorLevel getErrorLevel() { |
120 | 0 | return level; |
121 | |
} |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
public void setWarning(String message) { |
130 | 0 | this.level = ErrorLevel.WARN; |
131 | 0 | this.message = message; |
132 | 0 | } |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
public void setError(String message) { |
141 | 0 | this.level = ErrorLevel.ERROR; |
142 | 0 | this.message = message; |
143 | 0 | } |
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
public boolean isOk() { |
151 | 0 | return getErrorLevel() == ErrorLevel.OK; |
152 | |
} |
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
public boolean isWarn() { |
160 | 0 | return getErrorLevel() == ErrorLevel.WARN; |
161 | |
} |
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
public boolean isError() { |
169 | 0 | return getErrorLevel() == ErrorLevel.ERROR; |
170 | |
} |
171 | |
|
172 | |
public String toString(){ |
173 | 0 | return "[" + level + "] Path: [" + element + "] - " + message + " data=[" + invalidData + "]"; |
174 | |
} |
175 | |
|
176 | |
} |