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