1 /**
2 * Copyright 2005-2016 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.rice.krad.datadictionary.validation.result;
17
18 import org.kuali.rice.krad.datadictionary.validation.ErrorLevel;
19 import org.kuali.rice.krad.datadictionary.validation.constraint.Constraint;
20 import org.kuali.rice.krad.datadictionary.validation.processor.ConstraintProcessor;
21
22 import java.util.LinkedList;
23 import java.util.List;
24
25 /**
26 * ConstraintValidationResult is a composite class for all the different members that need to be returned when a {@link
27 * ConstraintProcessor}
28 * processes a {@link Constraint}.
29 *
30 * @author Kuali Rice Team (rice.collab@kuali.org)
31 */
32 public class ConstraintValidationResult {
33
34 private String entryName;
35 private String attributeName;
36 private String attributePath;
37 private String constraintName;
38 private ErrorLevel level;
39
40 private String errorKey;
41 private String[] errorParameters = {};
42 private String constraintLabelKey;
43
44 private List<ConstraintValidationResult> children;
45
46 /**
47 * creates a constraint validation result with the given constraint name
48 *
49 * @param constraintName - a descriptive name of the current constraint processor
50 */
51 public ConstraintValidationResult(String constraintName) {
52 this.constraintName = constraintName;
53 this.children = new LinkedList<ConstraintValidationResult>();
54 this.level = ErrorLevel.OK;
55 }
56
57 /**
58 * creates a constraint validation result with the given constraint name and error level
59 *
60 * @param constraintName - a descriptive name of the current constraint processor
61 * @param level - the applicable error level - selected from {@link ErrorLevel}
62 */
63 public ConstraintValidationResult(String constraintName, ErrorLevel level) {
64 this.constraintName = constraintName;
65 this.children = new LinkedList<ConstraintValidationResult>();
66 this.level = level;
67 }
68
69 /**
70 * allows a constraint validation result to be added as a child of the current one
71 *
72 * @param child - the 'child' constraint validation result
73 */
74 public void addChild(ConstraintValidationResult child) {
75 this.children.add(child);
76 }
77
78 /**
79 * provides information used to display error messages to the user concerning a constraint validation
80 *
81 * @param errorKey - a key used to fetch an error message to show the user
82 * @param errorParameters - parameters to substitute into the error message
83 */
84 public void setError(String errorKey, String... errorParameters) {
85 this.level = ErrorLevel.ERROR;
86 this.errorKey = errorKey;
87 this.errorParameters = errorParameters;
88 }
89
90 /**
91 * provides information used to display warning messages to the user concerning a constraint validation
92 *
93 * @param errorKey - a key used to fetch an warning message to show the user
94 * @param errorParameters - parameters to substitute into the warning message
95 */
96 public void setWarning(String errorKey, String... errorParameters) {
97 this.level = ErrorLevel.WARN;
98 this.errorKey = errorKey;
99 this.errorParameters = errorParameters;
100 }
101
102 /**
103 * @return the level
104 */
105 public ErrorLevel getStatus() {
106 return this.level;
107 }
108
109 /**
110 * @param level the level to set
111 */
112 public void setStatus(ErrorLevel level) {
113 this.level = level;
114 }
115
116 /**
117 * the error key is used to retrieve a message to display to the user
118 *
119 * @return the errorKey
120 * @see org.kuali.rice.core.api.util.RiceKeyConstants
121 */
122 public String getErrorKey() {
123 return this.errorKey;
124 }
125
126 /**
127 * @param errorKey the errorKey to set
128 */
129 public void setErrorKey(String errorKey) {
130 this.errorKey = errorKey;
131 }
132
133 /**
134 * @return the errorParameters
135 */
136 public String[] getErrorParameters() {
137 return this.errorParameters;
138 }
139
140 /**
141 * @param errorParameters the errorParameters to set
142 */
143 public void setErrorParameters(String[] errorParameters) {
144 this.errorParameters = errorParameters;
145 }
146
147 /**
148 * @return the entryName
149 */
150 public String getEntryName() {
151 return this.entryName;
152 }
153
154 /**
155 * @param entryName the entryName to set
156 */
157 public void setEntryName(String entryName) {
158 this.entryName = entryName;
159 }
160
161 /**
162 * @return the attributeName
163 */
164 public String getAttributeName() {
165 return this.attributeName;
166 }
167
168 /**
169 * @param attributeName the attributeName to set
170 */
171 public void setAttributeName(String attributeName) {
172 this.attributeName = attributeName;
173 }
174
175 /**
176 * @return the constraintName
177 */
178 public String getConstraintName() {
179 return this.constraintName;
180 }
181
182 /**
183 * @param constraintName the constraintName to set
184 */
185 public void setConstraintName(String constraintName) {
186 this.constraintName = constraintName;
187 }
188
189 /**
190 * @return the children
191 */
192 public List<ConstraintValidationResult> getChildren() {
193 return this.children;
194 }
195
196 /**
197 * @return the constraintLabelKey
198 */
199 public String getConstraintLabelKey() {
200 return this.constraintLabelKey;
201 }
202
203 /**
204 * @param constraintLabelKey the constraintLabelKey to set
205 */
206 public void setConstraintLabelKey(String constraintLabelKey) {
207 this.constraintLabelKey = constraintLabelKey;
208 }
209
210 /**
211 * @return the attributePath
212 */
213 public String getAttributePath() {
214 return this.attributePath;
215 }
216
217 /**
218 * @param attributePath the attributePath to set
219 */
220 public void setAttributePath(String attributePath) {
221 this.attributePath = attributePath;
222 }
223
224 }