Coverage Report - org.kuali.rice.krad.datadictionary.validation.result.DictionaryValidationResult
 
Classes in this File Line Coverage Branch Coverage Complexity
DictionaryValidationResult
0%
0/64
0%
0/19
2.35
DictionaryValidationResult$1
0%
0/21
0%
0/24
2.35
DictionaryValidationResult$2
0%
0/1
N/A
2.35
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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/ecl1.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.util.Iterator;
 19  
 import java.util.LinkedHashMap;
 20  
 import java.util.Map;
 21  
 
 22  
 import org.kuali.rice.krad.datadictionary.validation.AttributeValueReader;
 23  
 import org.kuali.rice.krad.datadictionary.validation.ErrorLevel;
 24  
 
 25  
 /**
 26  
  * 
 27  
  * @author Kuali Rice Team (rice.collab@kuali.org) 
 28  
  */
 29  0
 public class DictionaryValidationResult {
 30  
         
 31  
         private Map<String, EntryValidationResult> entryValidationResultMap;
 32  
         private ErrorLevel errorLevel;
 33  
         
 34  
         private int numberOfErrors;
 35  
         private int numberOfWarnings;
 36  
         
 37  
         private Iterator<ConstraintValidationResult> iterator;
 38  
         
 39  0
         public DictionaryValidationResult() {
 40  0
                 this.entryValidationResultMap = new LinkedHashMap<String, EntryValidationResult>();
 41  0
                 this.errorLevel = ErrorLevel.ERROR;
 42  0
                 this.numberOfErrors = 0;
 43  0
                 this.numberOfWarnings = 0;
 44  0
         }
 45  
         
 46  
         public void addConstraintValidationResult(AttributeValueReader attributeValueReader, ConstraintValidationResult constraintValidationResult) {
 47  
                 
 48  
                 // Don't bother to store this if the error level of the constraint validation result is lower than the level this dictionary validation result is tracking
 49  0
                 if (constraintValidationResult.getStatus().getLevel() < errorLevel.getLevel())
 50  0
                         return;
 51  
                 
 52  0
                 switch (constraintValidationResult.getStatus()) {
 53  
                 case ERROR:
 54  0
                         numberOfErrors++;
 55  0
                         break;
 56  
                 case WARN:
 57  0
                         numberOfWarnings++;
 58  0
                         break;
 59  
                 default:
 60  
                         // Do nothing
 61  
                 }
 62  
                 
 63  
                 // Give the constraint a chance to override the entry and attribute name - important if the attribute name is not the same as the one in the attribute value reader!
 64  0
                 String entryName = constraintValidationResult.getEntryName();
 65  0
                 String attributeName = constraintValidationResult.getAttributeName();
 66  
                 
 67  0
                 if (entryName == null)
 68  0
                         entryName = attributeValueReader.getEntryName();
 69  
                 
 70  0
                 if (attributeName == null)
 71  0
                         attributeName = attributeValueReader.getAttributeName();
 72  
                 
 73  0
                 constraintValidationResult.setEntryName(entryName);
 74  0
                 constraintValidationResult.setAttributeName(attributeName);
 75  
                 
 76  0
                 getEntryValidationResult(entryName).getAttributeValidationResult(attributeName).addConstraintValidationResult(constraintValidationResult);
 77  0
         }
 78  
         
 79  
         public ConstraintValidationResult addError(AttributeValueReader attributeValueReader, String constraintName, String errorKey, String... errorParameters) {
 80  0
                 ConstraintValidationResult constraintValidationResult = getConstraintValidationResult(attributeValueReader.getEntryName(), attributeValueReader.getAttributeName(), attributeValueReader.getPath(), constraintName);
 81  0
                 constraintValidationResult.setError(errorKey, errorParameters);
 82  0
                 numberOfErrors++;
 83  0
                 return constraintValidationResult;
 84  
         }
 85  
         
 86  
         public ConstraintValidationResult addWarning(AttributeValueReader attributeValueReader, String constraintName, String errorKey, String... errorParameters) {
 87  0
                 if (errorLevel.getLevel() > ErrorLevel.WARN.getLevel())
 88  0
                         return new ConstraintValidationResult(constraintName, ErrorLevel.WARN);
 89  
                 
 90  0
                 ConstraintValidationResult constraintValidationResult = getConstraintValidationResult(attributeValueReader.getEntryName(), attributeValueReader.getAttributeName(), attributeValueReader.getPath(), constraintName);
 91  0
                 constraintValidationResult.setWarning(errorKey, errorParameters);
 92  0
                 numberOfWarnings++;
 93  0
                 return constraintValidationResult;
 94  
         }
 95  
 
 96  
         public ConstraintValidationResult addSuccess(AttributeValueReader attributeValueReader, String constraintName) {
 97  0
                 if (errorLevel.getLevel() > ErrorLevel.OK.getLevel())
 98  0
                         return new ConstraintValidationResult(constraintName, ErrorLevel.OK);
 99  
                 
 100  0
                 return getConstraintValidationResult(attributeValueReader.getEntryName(), attributeValueReader.getAttributeName(), attributeValueReader.getPath(), constraintName);
 101  
         }
 102  
         
 103  
         public ConstraintValidationResult addSkipped(AttributeValueReader attributeValueReader, String constraintName) {
 104  0
                 if (errorLevel.getLevel() > ErrorLevel.OK.getLevel())
 105  0
                         return new ConstraintValidationResult(constraintName, ErrorLevel.INAPPLICABLE);
 106  
                 
 107  0
                 ConstraintValidationResult constraintValidationResult = getConstraintValidationResult(attributeValueReader.getEntryName(), attributeValueReader.getAttributeName(), attributeValueReader.getPath(), constraintName);
 108  0
                 constraintValidationResult.setStatus(ErrorLevel.INAPPLICABLE);
 109  0
                 return constraintValidationResult;
 110  
         }
 111  
         
 112  
         public ConstraintValidationResult addNoConstraint(AttributeValueReader attributeValueReader, String constraintName) {
 113  0
                 if (errorLevel.getLevel() > ErrorLevel.OK.getLevel())
 114  0
                         return new ConstraintValidationResult(constraintName, ErrorLevel.NOCONSTRAINT);
 115  
                 
 116  0
                 ConstraintValidationResult constraintValidationResult = getConstraintValidationResult(attributeValueReader.getEntryName(), attributeValueReader.getAttributeName(), attributeValueReader.getPath(), constraintName);
 117  0
                 constraintValidationResult.setStatus(ErrorLevel.NOCONSTRAINT);
 118  0
                 return constraintValidationResult;
 119  
         }
 120  
         
 121  
         public Iterator<ConstraintValidationResult> iterator() {
 122  
                 
 123  
 //                if (iterator == null || iterator.hasNext() == false) {
 124  0
                         iterator = new Iterator<ConstraintValidationResult>() {
 125  
         
 126  
                                 private Iterator<EntryValidationResult> entryIterator;
 127  
                                 private Iterator<AttributeValidationResult> attributeIterator;
 128  
                                 private Iterator<ConstraintValidationResult> constraintIterator;
 129  
                                 
 130  
                                 @Override
 131  
                                 public boolean hasNext() {        
 132  0
                                         Iterator<ConstraintValidationResult> currentConstraintIterator = getCurrentConstraintIterator();
 133  0
                                         return currentConstraintIterator != null && currentConstraintIterator.hasNext();
 134  
                                 }
 135  
         
 136  
                                 @Override
 137  
                                 public ConstraintValidationResult next() {
 138  0
                                         Iterator<ConstraintValidationResult> currentConstraintIterator = getCurrentConstraintIterator();
 139  0
                                         return currentConstraintIterator != null ? currentConstraintIterator.next() : null;
 140  
                                 }
 141  
         
 142  
                                 @Override
 143  
                                 public void remove() {
 144  0
                                         throw new RuntimeException("Can't remove from this iterator!");
 145  
                                 }
 146  
                                 
 147  
                                 private Iterator<ConstraintValidationResult> getCurrentConstraintIterator() {
 148  0
                                         if (constraintIterator == null || constraintIterator.hasNext() == false) {
 149  0
                                                 Iterator<AttributeValidationResult> currentAttributeIterator = getCurrentAttributeIterator();
 150  0
                                                 if (currentAttributeIterator != null && currentAttributeIterator.hasNext()) {
 151  0
                                                         AttributeValidationResult currentAttributeValidationResult = currentAttributeIterator.next();
 152  0
                                                         constraintIterator = currentAttributeValidationResult.iterator();
 153  
                                                 }
 154  
                                         }
 155  0
                                         return constraintIterator;
 156  
                                 }
 157  
                                 
 158  
                                 private Iterator<AttributeValidationResult> getCurrentAttributeIterator() {
 159  0
                                         if (attributeIterator == null || attributeIterator.hasNext() == false) {
 160  0
                                                 Iterator<EntryValidationResult> currentEntryIterator = getCurrentEntryIterator();
 161  0
                                                 if (currentEntryIterator != null && currentEntryIterator.hasNext()) {
 162  0
                                                         EntryValidationResult currentEntryValidationResult = currentEntryIterator.next();
 163  0
                                                         attributeIterator = currentEntryValidationResult.iterator();
 164  
                                                 }
 165  
                                         }
 166  0
                                         return attributeIterator;
 167  
                                 }
 168  
         
 169  
                                 private Iterator<EntryValidationResult> getCurrentEntryIterator() {
 170  0
                                         if (entryIterator == null) // || entryIterator.hasNext() == false)
 171  0
                                                 entryIterator = entryValidationResultMap.values().iterator();
 172  0
                                         return entryIterator;
 173  
                                 }
 174  
                                 
 175  
                         };
 176  
 //                }
 177  
                 
 178  0
                 return iterator;
 179  
         }
 180  
         
 181  
         protected EntryValidationResult getEntryValidationResult(String entryName) {
 182  0
                 EntryValidationResult entryValidationResult = entryValidationResultMap.get(entryName);
 183  0
                 if (entryValidationResult == null) {
 184  0
                         entryValidationResult = new EntryValidationResult(entryName);
 185  0
                         entryValidationResultMap.put(entryName, entryValidationResult);
 186  
                 }
 187  0
                 return entryValidationResult;
 188  
         }
 189  
         
 190  
         private ConstraintValidationResult getConstraintValidationResult(String entryName, String attributeName, String attributePath, String constraintName) {
 191  0
                 ConstraintValidationResult constraintValidationResult = getEntryValidationResult(entryName).getAttributeValidationResult(attributeName).getConstraintValidationResult(constraintName);
 192  0
                 constraintValidationResult.setEntryName(entryName);
 193  0
                 constraintValidationResult.setAttributeName(attributeName);
 194  0
                 constraintValidationResult.setAttributePath(attributePath);
 195  0
                 return constraintValidationResult;
 196  
         }
 197  
 
 198  
         /**
 199  
          * @return the errorLevel
 200  
          */
 201  
         public ErrorLevel getErrorLevel() {
 202  0
                 return this.errorLevel;
 203  
         }
 204  
 
 205  
         /**
 206  
          * @param errorLevel the errorLevel to set
 207  
          */
 208  
         public void setErrorLevel(ErrorLevel errorLevel) {
 209  0
                 this.errorLevel = errorLevel;
 210  0
         }
 211  
 
 212  
         /**
 213  
          * @return the numberOfErrors
 214  
          */
 215  
         public int getNumberOfErrors() {
 216  0
                 return this.numberOfErrors;
 217  
         }
 218  
 
 219  
         /**
 220  
          * @return the numberOfWarnings
 221  
          */
 222  
         public int getNumberOfWarnings() {
 223  0
                 return this.numberOfWarnings;
 224  
         }
 225  
         
 226  
 }