1 package org.kuali.ole.docstore.common.exception;
2
3 import java.util.Iterator;
4 import java.util.Map;
5 import java.util.Set;
6 import java.util.TreeMap;
7
8
9
10
11
12
13
14
15 public class DocstoreException extends RuntimeException {
16
17 private String errorCode;
18 private String errorMessage;
19 private TreeMap<String, String> errorParams;
20
21 public DocstoreException() {
22 super();
23 }
24
25 public DocstoreException(String message) {
26 super(message);
27 setErrorMessage(message);
28 }
29
30 public DocstoreException(Exception e) {
31 super(e);
32 setErrorMessage(e.getMessage());
33 }
34
35 public DocstoreException(String errorCode, String errorMessage, TreeMap<String, String> errorParams) {
36 this.errorMessage = errorMessage;
37 this.errorCode = errorCode;
38 this.errorParams = errorParams;
39 }
40
41 public DocstoreException(String errorCode, String errorMessage) {
42 this.errorMessage = errorMessage;
43 this.errorCode = errorCode;
44 }
45
46 public String getErrorCode() {
47 return errorCode;
48 }
49
50 public void setErrorCode(String errorCode) {
51 this.errorCode = errorCode;
52 }
53
54 public String getErrorMessage() {
55 return errorMessage;
56 }
57
58 public void setErrorMessage(String errorMessage) {
59 this.errorMessage = errorMessage;
60 }
61
62 public TreeMap<String, String> getErrorParams() {
63 return errorParams;
64 }
65
66 @Override
67 public String toString() {
68 StringBuilder stb = new StringBuilder();
69 stb.append(super.toString());
70 stb.append("\n");
71 stb.append("Error Code = ");
72 stb.append(errorCode);
73 stb.append("\n");
74 stb.append("Error Message = ");
75 stb.append(errorMessage);
76 stb.append("\n");
77 if (errorParams != null) {
78 stb.append("ErrorParams = ");
79 stb.append("\n");
80 Set keySet = errorParams.keySet();
81 Iterator<String> iterator = keySet.iterator();
82 String key = null;
83 while (iterator.hasNext()) {
84 key = iterator.next();
85 stb.append("\t");
86 stb.append(key);
87 stb.append(" = ");
88 stb.append(errorParams.get(key));
89 stb.append("\n");
90 }
91 }
92 return stb.toString();
93 }
94
95 public void addErrorParams(String key, String value) {
96 if (errorParams == null) {
97 errorParams = new TreeMap<>();
98 errorParams.put(key, value);
99 } else {
100 errorParams.put(key, value);
101 }
102
103 }
104 }