001/** 002 * Copyright 2005-2016 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 */ 016package org.kuali.rice.krad.datadictionary.validation.result; 017 018import java.io.Serializable; 019import java.util.Iterator; 020import java.util.LinkedHashMap; 021import java.util.Map; 022 023public class AttributeValidationResult implements Serializable { 024 025 private String attributeName; 026 private Map<String, ConstraintValidationResult> constraintValidationResultMap; 027 028 public AttributeValidationResult(String attributeName) { 029 this.attributeName = attributeName; 030 this.constraintValidationResultMap = new LinkedHashMap<String, ConstraintValidationResult>(); 031 } 032 033 public void addConstraintValidationResult(ConstraintValidationResult constraintValidationResult) { 034 constraintValidationResultMap.put(constraintValidationResult.getConstraintName(), constraintValidationResult); 035 } 036 037 public Iterator<ConstraintValidationResult> iterator() { 038 return constraintValidationResultMap.values().iterator(); 039 } 040 041 protected ConstraintValidationResult getConstraintValidationResult(String constraintName) { 042 ConstraintValidationResult constraintValidationResult = constraintValidationResultMap.get(constraintName); 043 if (constraintValidationResult == null) { 044 constraintValidationResult = new ConstraintValidationResult(constraintName); 045 constraintValidationResultMap.put(constraintName, constraintValidationResult); 046 } 047 return constraintValidationResult; 048 } 049 050 /** 051 * @return the attributeName 052 */ 053 public String getAttributeName() { 054 return this.attributeName; 055 } 056 057 /** 058 * @param attributeName the attributeName to set 059 */ 060 public void setAttributeName(String attributeName) { 061 this.attributeName = attributeName; 062 } 063 064 /* 065 private static final long serialVersionUID = 1L; 066 067 protected String element; 068 069 protected ErrorLevel level = ErrorLevel.OK; 070 071 private String entryName; 072 private String attributeName; 073 private String errorKey; 074 private String[] errorParameters; 075 076 public AttributeValidationResult(String attributeName) { 077 this.level = ErrorLevel.OK; 078 this.attributeName = attributeName; 079 } 080 081 public AttributeValidationResult(String entryName, String attributeName) { 082 this.level = ErrorLevel.OK; 083 this.entryName = entryName; 084 this.attributeName = attributeName; 085 } 086 087 public ErrorLevel getLevel() { 088 return level; 089 } 090 091 public void setLevel(ErrorLevel level) { 092 this.level = level; 093 } 094 095 public String getElement() { 096 return element; 097 } 098 099 public void setElement(String element) { 100 this.element = element; 101 } 102 103 104 public ErrorLevel getErrorLevel() { 105 return level; 106 } 107 108 public void setError(String errorKey, String... errorParameters) { 109 this.level = ErrorLevel.ERROR; 110 this.errorKey = errorKey; 111 this.errorParameters = errorParameters; 112 } 113 114 public boolean isOk() { 115 return getErrorLevel() == ErrorLevel.OK; 116 } 117 118 119 public boolean isWarn() { 120 return getErrorLevel() == ErrorLevel.WARN; 121 } 122 123 public boolean isError() { 124 return getErrorLevel() == ErrorLevel.ERROR; 125 } 126 127 public String toString(){ 128 return "Entry: [" + entryName + "] Attribute: [" + attributeName + "] - " + errorKey + " data=[" + errorParameters + "]"; 129 } 130 131 public String getEntryName() { 132 return this.entryName; 133 } 134 135 public void setEntryName(String entryName) { 136 this.entryName = entryName; 137 } 138 139 public String getAttributeName() { 140 return this.attributeName; 141 } 142 143 public void setAttributeName(String attributeName) { 144 this.attributeName = attributeName; 145 } 146 147 public String getErrorKey() { 148 return this.errorKey; 149 } 150 151 public void setErrorKey(String errorKey) { 152 this.errorKey = errorKey; 153 } 154 155 public String[] getErrorParameters() { 156 return this.errorParameters; 157 } 158 public void setErrorParameters(String[] errorParameters) { 159 this.errorParameters = errorParameters; 160 } 161 */ 162 163}