001 /**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.krad.datadictionary.validation.result;
017
018 import org.kuali.rice.krad.datadictionary.validation.ErrorLevel;
019 import org.kuali.rice.krad.datadictionary.validation.constraint.Constraint;
020 import org.kuali.rice.krad.datadictionary.validation.processor.ConstraintProcessor;
021
022 import java.util.LinkedList;
023 import java.util.List;
024
025 /**
026 * ConstraintValidationResult is a composite class for all the different members that need to be returned when a {@link
027 * ConstraintProcessor}
028 * processes a {@link Constraint}.
029 *
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 */
032 public class ConstraintValidationResult {
033
034 private String entryName;
035 private String attributeName;
036 private String attributePath;
037 private String constraintName;
038 private ErrorLevel level;
039
040 private String errorKey;
041 private String[] errorParameters = {};
042 private String constraintLabelKey;
043
044 private List<ConstraintValidationResult> children;
045
046 /**
047 * creates a constraint validation result with the given constraint name
048 *
049 * @param constraintName - a descriptive name of the current constraint processor
050 */
051 public ConstraintValidationResult(String constraintName) {
052 this.constraintName = constraintName;
053 this.children = new LinkedList<ConstraintValidationResult>();
054 this.level = ErrorLevel.OK;
055 }
056
057 /**
058 * creates a constraint validation result with the given constraint name and error level
059 *
060 * @param constraintName - a descriptive name of the current constraint processor
061 * @param level - the applicable error level - selected from {@link ErrorLevel}
062 */
063 public ConstraintValidationResult(String constraintName, ErrorLevel level) {
064 this.constraintName = constraintName;
065 this.children = new LinkedList<ConstraintValidationResult>();
066 this.level = level;
067 }
068
069 /**
070 * allows a constraint validation result to be added as a child of the current one
071 *
072 * @param child - the 'child' constraint validation result
073 */
074 public void addChild(ConstraintValidationResult child) {
075 this.children.add(child);
076 }
077
078 /**
079 * provides information used to display error messages to the user concerning a constraint validation
080 *
081 * @param errorKey - a key used to fetch an error message to show the user
082 * @param errorParameters - parameters to substitute into the error message
083 */
084 public void setError(String errorKey, String... errorParameters) {
085 this.level = ErrorLevel.ERROR;
086 this.errorKey = errorKey;
087 this.errorParameters = errorParameters;
088 }
089
090 /**
091 * provides information used to display warning messages to the user concerning a constraint validation
092 *
093 * @param errorKey - a key used to fetch an warning message to show the user
094 * @param errorParameters - parameters to substitute into the warning message
095 */
096 public void setWarning(String errorKey, String... errorParameters) {
097 this.level = ErrorLevel.WARN;
098 this.errorKey = errorKey;
099 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 }