1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
package org.kuali.student.common.dto; |
9 | |
|
10 | |
import java.io.Serializable; |
11 | |
import java.util.List; |
12 | |
|
13 | |
import javax.xml.bind.annotation.XmlAccessType; |
14 | |
import javax.xml.bind.annotation.XmlAccessorType; |
15 | |
import javax.xml.bind.annotation.XmlAnyElement; |
16 | |
import javax.xml.bind.annotation.XmlElement; |
17 | |
import javax.xml.bind.annotation.XmlType; |
18 | |
|
19 | |
import org.kuali.student.common.infc.ModelBuilder; |
20 | |
import org.kuali.student.common.infc.ValidationResult; |
21 | |
import org.w3c.dom.Element; |
22 | |
|
23 | |
@XmlAccessorType(XmlAccessType.FIELD) |
24 | |
@XmlType(name = "ValidationResultInfo", propOrder = {"element", "level", "message", "_futureElements"}) |
25 | 0 | public class ValidationResultInfo implements ValidationResult, Serializable { |
26 | |
|
27 | |
private static final long serialVersionUID = 1L; |
28 | |
|
29 | |
@XmlElement |
30 | |
private String element; |
31 | |
@XmlElement |
32 | |
private Integer level; |
33 | |
@XmlElement |
34 | |
private String message; |
35 | |
private transient Object invalidData; |
36 | |
@XmlAnyElement |
37 | |
private final List<Element> _futureElements; |
38 | |
|
39 | 0 | private ValidationResultInfo() { |
40 | 0 | this.level = null; |
41 | 0 | this.message = null; |
42 | 0 | this.invalidData = null; |
43 | 0 | this._futureElements = null; |
44 | 0 | } |
45 | |
|
46 | 0 | private ValidationResultInfo(ValidationResult builder) { |
47 | 0 | this.level = builder.getLevel(); |
48 | 0 | this.element = builder.getElement(); |
49 | 0 | this.message = builder.getMessage(); |
50 | 0 | this.invalidData = builder.getInvalidData(); |
51 | 0 | this._futureElements = null; |
52 | 0 | } |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
@Override |
60 | |
public boolean isOk() { |
61 | 0 | return getLevel() == ErrorLevel.OK.getLevel(); |
62 | |
} |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
@Override |
70 | |
public boolean isWarn() { |
71 | 0 | return getLevel() == ErrorLevel.WARN.getLevel(); |
72 | |
} |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
@Override |
80 | |
public boolean isError() { |
81 | 0 | return getLevel() == ErrorLevel.ERROR.getLevel(); |
82 | |
} |
83 | |
|
84 | |
@Override |
85 | |
public String toString() { |
86 | 0 | return "[" + level + "] Path: [" + element + "] - " + message + " data=[" + invalidData + "]"; |
87 | |
} |
88 | |
|
89 | |
@Override |
90 | |
public String getMessage() { |
91 | 0 | return message; |
92 | |
} |
93 | |
|
94 | |
@Override |
95 | |
public String getElement() { |
96 | 0 | return element; |
97 | |
} |
98 | |
|
99 | |
@Override |
100 | |
public Integer getLevel() { |
101 | 0 | return level; |
102 | |
} |
103 | |
|
104 | |
@Override |
105 | |
public Object getInvalidData() { |
106 | 0 | return invalidData; |
107 | |
} |
108 | |
|
109 | |
|
110 | 0 | public static class Builder implements ModelBuilder<ValidationResultInfo>, ValidationResult { |
111 | |
|
112 | |
private String element; |
113 | 0 | private Integer level = ErrorLevel.OK.getLevel(); |
114 | |
private String message; |
115 | 0 | private Object invalidData = null; |
116 | |
|
117 | 0 | public Builder() {} |
118 | |
|
119 | 0 | public Builder(ValidationResult validationResultInfo) { |
120 | 0 | this.element = validationResultInfo.getElement(); |
121 | 0 | this.level = validationResultInfo.getLevel(); |
122 | 0 | this.message = validationResultInfo.getMessage(); |
123 | 0 | this.invalidData = validationResultInfo.getInvalidData(); |
124 | 0 | } |
125 | |
|
126 | |
@Override |
127 | |
public ValidationResultInfo build() { |
128 | 0 | return new ValidationResultInfo(this); |
129 | |
} |
130 | |
|
131 | |
public String getElement() { |
132 | 0 | return element; |
133 | |
} |
134 | |
|
135 | |
public void setElement(String element) { |
136 | 0 | this.element = element; |
137 | 0 | } |
138 | |
|
139 | |
public Integer getLevel() { |
140 | 0 | return level; |
141 | |
} |
142 | |
|
143 | |
public void setLevel(Integer level) { |
144 | 0 | this.level = level; |
145 | 0 | } |
146 | |
|
147 | |
public String getMessage() { |
148 | 0 | return message; |
149 | |
} |
150 | |
|
151 | |
public void setMessage(String message) { |
152 | 0 | this.message = message; |
153 | 0 | } |
154 | |
|
155 | |
public Object getInvalidData() { |
156 | 0 | return invalidData; |
157 | |
} |
158 | |
|
159 | |
public void setInvalidData(Object invalidData) { |
160 | 0 | this.invalidData = invalidData; |
161 | 0 | } |
162 | |
|
163 | |
public void setError(String message) { |
164 | 0 | this.level = ErrorLevel.ERROR.getLevel(); |
165 | 0 | this.message = message; |
166 | 0 | } |
167 | |
|
168 | |
public void setWarn(String message) { |
169 | 0 | this.level = ErrorLevel.WARN.getLevel(); |
170 | 0 | this.message = message; |
171 | 0 | } |
172 | |
|
173 | |
@Override |
174 | |
public boolean isOk() { |
175 | 0 | return getLevel() == ErrorLevel.OK.getLevel(); |
176 | |
} |
177 | |
|
178 | |
@Override |
179 | |
public boolean isWarn() { |
180 | 0 | return getLevel() == ErrorLevel.WARN.getLevel(); |
181 | |
} |
182 | |
|
183 | |
@Override |
184 | |
public boolean isError() { |
185 | 0 | return getLevel() == ErrorLevel.ERROR.getLevel(); |
186 | |
} |
187 | |
} |
188 | |
} |