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 java.io.Serializable;
019    import java.util.Iterator;
020    import java.util.LinkedHashMap;
021    import java.util.Map;
022    
023    public class AttributeValidationResult implements Serializable {
024    
025        private String attributeName;
026        private Map<String, ConstraintValidationResult> constraintValidationResultMap;
027    
028        /**
029         * creates a new instance with the given attribute name
030         *
031         * @param attributeName - the attribute name
032         */
033        public AttributeValidationResult(String attributeName) {
034            this.attributeName = attributeName;
035            this.constraintValidationResultMap = new LinkedHashMap<String, ConstraintValidationResult>();
036        }
037    
038        /**
039         * adds a constraint validation result
040         *
041         * @param constraintValidationResult - the constraint validation result to set
042         */
043        public void addConstraintValidationResult(ConstraintValidationResult constraintValidationResult) {
044            constraintValidationResultMap.put(constraintValidationResult.getConstraintName(), constraintValidationResult);
045        }
046    
047        /**
048         * gets an iterator over the constraint validation results added to this class
049         *
050         * @return an iterator to stored constraint validation results
051         */
052        public Iterator<ConstraintValidationResult> iterator() {
053            return constraintValidationResultMap.values().iterator();
054        }
055    
056        /**
057         * gets a constraint validation result with the given constraintName
058         *
059         * @param constraintName - a descriptive name of the current constraint processor
060         * @return validation result
061         */
062        protected ConstraintValidationResult getConstraintValidationResult(String constraintName) {
063            ConstraintValidationResult constraintValidationResult = constraintValidationResultMap.get(constraintName);
064            if (constraintValidationResult == null) {
065                constraintValidationResult = new ConstraintValidationResult(constraintName);
066                constraintValidationResultMap.put(constraintName, constraintValidationResult);
067            }
068            return constraintValidationResult;
069        }
070    
071        /**
072         * @return the attributeName
073         */
074        public String getAttributeName() {
075            return this.attributeName;
076        }
077    
078        /**
079         * @param attributeName the attributeName to set
080         */
081        public void setAttributeName(String attributeName) {
082            this.attributeName = attributeName;
083        }
084    
085        /*
086         private static final long serialVersionUID = 1L;
087    
088         protected String element;
089    
090         protected ErrorLevel level = ErrorLevel.OK;
091    
092         private String entryName;
093         private String attributeName;
094         private String errorKey;
095         private String[] errorParameters;
096    
097         public AttributeValidationResult(String attributeName) {
098             this.level = ErrorLevel.OK;
099             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    }