1 /**
2 * Copyright 2005-2012 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 java.io.Serializable;
19 import java.util.Iterator;
20 import java.util.LinkedHashMap;
21 import java.util.Map;
22
23 public class AttributeValidationResult implements Serializable {
24
25 private String attributeName;
26 private Map<String, ConstraintValidationResult> constraintValidationResultMap;
27
28 /**
29 * creates a new instance with the given attribute name
30 *
31 * @param attributeName - the attribute name
32 */
33 public AttributeValidationResult(String attributeName) {
34 this.attributeName = attributeName;
35 this.constraintValidationResultMap = new LinkedHashMap<String, ConstraintValidationResult>();
36 }
37
38 /**
39 * adds a constraint validation result
40 *
41 * @param constraintValidationResult - the constraint validation result to set
42 */
43 public void addConstraintValidationResult(ConstraintValidationResult constraintValidationResult) {
44 constraintValidationResultMap.put(constraintValidationResult.getConstraintName(), constraintValidationResult);
45 }
46
47 /**
48 * gets an iterator over the constraint validation results added to this class
49 *
50 * @return an iterator to stored constraint validation results
51 */
52 public Iterator<ConstraintValidationResult> iterator() {
53 return constraintValidationResultMap.values().iterator();
54 }
55
56 /**
57 * gets a constraint validation result with the given constraintName
58 *
59 * @param constraintName - a descriptive name of the current constraint processor
60 * @return
61 */
62 protected ConstraintValidationResult getConstraintValidationResult(String constraintName) {
63 ConstraintValidationResult constraintValidationResult = constraintValidationResultMap.get(constraintName);
64 if (constraintValidationResult == null) {
65 constraintValidationResult = new ConstraintValidationResult(constraintName);
66 constraintValidationResultMap.put(constraintName, constraintValidationResult);
67 }
68 return constraintValidationResult;
69 }
70
71 /**
72 * @return the attributeName
73 */
74 public String getAttributeName() {
75 return this.attributeName;
76 }
77
78 /**
79 * @param attributeName the attributeName to set
80 */
81 public void setAttributeName(String attributeName) {
82 this.attributeName = attributeName;
83 }
84
85 /*
86 private static final long serialVersionUID = 1L;
87
88 protected String element;
89
90 protected ErrorLevel level = ErrorLevel.OK;
91
92 private String entryName;
93 private String attributeName;
94 private String errorKey;
95 private String[] errorParameters;
96
97 public AttributeValidationResult(String attributeName) {
98 this.level = ErrorLevel.OK;
99 this.attributeName = attributeName;
100 }
101
102 public AttributeValidationResult(String entryName, String attributeName) {
103 this.level = ErrorLevel.OK;
104 this.entryName = entryName;
105 this.attributeName = attributeName;
106 }
107
108 public ErrorLevel getLevel() {
109 return level;
110 }
111
112 public void setLevel(ErrorLevel level) {
113 this.level = level;
114 }
115
116 public String getElement() {
117 return element;
118 }
119
120 public void setElement(String element) {
121 this.element = element;
122 }
123
124
125 public ErrorLevel getErrorLevel() {
126 return level;
127 }
128
129 public void setError(String errorKey, String... errorParameters) {
130 this.level = ErrorLevel.ERROR;
131 this.errorKey = errorKey;
132 this.errorParameters = errorParameters;
133 }
134
135 public boolean isOk() {
136 return getErrorLevel() == ErrorLevel.OK;
137 }
138
139
140 public boolean isWarn() {
141 return getErrorLevel() == ErrorLevel.WARN;
142 }
143
144 public boolean isError() {
145 return getErrorLevel() == ErrorLevel.ERROR;
146 }
147
148 public String toString(){
149 return "Entry: [" + entryName + "] Attribute: [" + attributeName + "] - " + errorKey + " data=[" + errorParameters + "]";
150 }
151
152 public String getEntryName() {
153 return this.entryName;
154 }
155
156 public void setEntryName(String entryName) {
157 this.entryName = entryName;
158 }
159
160 public String getAttributeName() {
161 return this.attributeName;
162 }
163
164 public void setAttributeName(String attributeName) {
165 this.attributeName = attributeName;
166 }
167
168 public String getErrorKey() {
169 return this.errorKey;
170 }
171
172 public void setErrorKey(String errorKey) {
173 this.errorKey = errorKey;
174 }
175
176 public String[] getErrorParameters() {
177 return this.errorParameters;
178 }
179 public void setErrorParameters(String[] errorParameters) {
180 this.errorParameters = errorParameters;
181 }
182 */
183
184 }