Coverage Report - org.kuali.student.r2.core.class1.util.ValidationUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidationUtils
0%
0/15
0%
0/4
3.5
 
 1  
 /**
 2  
  * Copyright 2011 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  *
 15  
  * Created by bobhurt on 9/9/11
 16  
  */
 17  
 package org.kuali.student.r2.core.class1.util;
 18  
 
 19  
 
 20  
 
 21  
 import java.util.List;
 22  
 
 23  
 import org.kuali.student.r2.common.datadictionary.DataDictionaryValidator;
 24  
 import org.kuali.student.r2.common.dto.ContextInfo;
 25  
 import org.kuali.student.r2.common.dto.ValidationResultInfo;
 26  
 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
 27  
 import org.kuali.student.r2.common.exceptions.MissingParameterException;
 28  
 import org.kuali.student.r2.common.exceptions.OperationFailedException;
 29  
 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
 30  
 
 31  
 /**
 32  
  * This class provides static utility methods for services.
 33  
  *
 34  
  * @author Kuali Student Team
 35  
  */
 36  0
 public class ValidationUtils {
 37  
 
 38  
     public static List<ValidationResultInfo> validateInfo(  DataDictionaryValidator validator,
 39  
                                                             String validationType,
 40  
                                                             Object info,
 41  
                                                             ContextInfo context)
 42  
                     throws OperationFailedException, MissingParameterException, InvalidParameterException {
 43  0
         if (null == validator) {
 44  0
             throw new InvalidParameterException("DataDictionaryValidator parameter cannot be null");
 45  
         }
 46  
 
 47  
         List<ValidationResultInfo> errors;
 48  
         try {
 49  0
             errors = validator.validate(DataDictionaryValidator.ValidationType.fromString(validationType), info, context);
 50  0
         } catch (PermissionDeniedException ex) {
 51  0
             throw new OperationFailedException("Validation failed due to permission exception", ex);
 52  0
         }
 53  0
         return errors;
 54  
     }
 55  
     
 56  
     /**
 57  
      * Convert a list of ValidationResultInfo's into a string.
 58  
      * 
 59  
      * @param vris The list of validation results.
 60  
      * @return the semi colon then newline delimited list of results. 
 61  
      */
 62  
     public static String asString(List<ValidationResultInfo> vris) {
 63  0
         StringBuilder sb = new StringBuilder();
 64  0
         String newLine = ";";
 65  0
         for (ValidationResultInfo vri : vris) {
 66  0
             sb.append(newLine);
 67  0
             newLine = "/n";
 68  0
             sb.append(vri.getMessage());
 69  
         }
 70  0
         return sb.toString();
 71  
     }
 72  
 
 73  
 }