1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.r2.common.exceptions;
18
19 import org.apache.log4j.Logger;
20 import org.kuali.student.r2.common.dto.ValidationResultInfo;
21
22 import javax.xml.ws.WebFault;
23 import java.io.PrintStream;
24 import java.io.PrintWriter;
25 import java.util.ArrayList;
26 import java.util.List;
27
28 @WebFault(name = "DataValidationError")
29 public class DataValidationErrorException
30 extends Exception {
31
32 private static final Logger LOG = Logger.getLogger(DataValidationErrorException.class);
33
34 private static final long serialVersionUID = 1L;
35
36 private List<ValidationResultInfo> validationResults;
37
38 public DataValidationErrorException() {
39 }
40
41 public DataValidationErrorException(String message, List<ValidationResultInfo> validationResults) {
42 this(message, validationResults, null);
43 }
44
45 public DataValidationErrorException(String message, List<ValidationResultInfo> validationResults, Throwable cause) {
46 super(message, cause);
47 this.validationResults = validationResults;
48 }
49
50 public DataValidationErrorException(String message, Throwable cause) {
51 super(message, cause);
52 }
53
54 public DataValidationErrorException(String message) {
55 super(message);
56 }
57
58 public DataValidationErrorException(Throwable cause) {
59 super(cause);
60 }
61
62 public List<ValidationResultInfo> getValidationResults() {
63 if(validationResults == null){
64 validationResults = new ArrayList<ValidationResultInfo>();
65 }
66 return validationResults;
67 }
68
69 public void setValidationResults(List<ValidationResultInfo> validationResults) {
70 this.validationResults = validationResults;
71 }
72
73
74 @Override
75 public void printStackTrace(PrintStream s) {
76 super.printStackTrace(s);
77 logValidationResults();
78 }
79
80 @Override
81 public void printStackTrace(PrintWriter s) {
82 super.printStackTrace(s);
83 logValidationResults();
84 }
85
86 @Override
87 public String toString() {
88 StringBuilder sb = new StringBuilder();
89 sb.append(super.getMessage()).append("\n");
90
91 if (validationResults != null) {
92 sb.append("Validation Results: \n");
93 for (ValidationResultInfo info:validationResults) {
94 sb.append(info).append("\n");
95 }
96 } else {
97 sb.append("Validation Results: None set.");
98 }
99 return sb.toString();
100 }
101
102 private void logValidationResults() {
103 LOG.debug(toString());
104 }
105 }