Coverage Report - org.kuali.student.contract.model.validation.ServiceMethodValidator
 
Classes in this File Line Coverage Branch Coverage Complexity
ServiceMethodValidator
0%
0/30
0%
0/18
3
 
 1  
 /*
 2  
  * Copyright 2009 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.osedu.org/licenses/ECL-2.0
 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.student.contract.model.validation;
 17  
 
 18  
 import org.kuali.student.contract.model.DictionaryModel;
 19  
 import org.kuali.student.contract.model.Service;
 20  
 import org.kuali.student.contract.model.ServiceContractModel;
 21  
 import org.kuali.student.contract.model.ServiceMethod;
 22  
 import org.kuali.student.contract.model.ServiceMethodError;
 23  
 import org.kuali.student.contract.model.ServiceMethodParameter;
 24  
 import org.kuali.student.contract.model.util.ModelFinder;
 25  
 
 26  
 import java.util.ArrayList;
 27  
 import java.util.Collection;
 28  
 
 29  
 /**
 30  
  * This validates a single serviceMethodinoary entry
 31  
  * @author nwright
 32  
  */
 33  
 public class ServiceMethodValidator implements ModelValidator
 34  
 {
 35  
 
 36  
  private ServiceMethod method;
 37  
  private ServiceContractModel model;
 38  
 
 39  
  public ServiceMethodValidator (ServiceMethod method, ServiceContractModel model)
 40  0
  {
 41  0
   this.method = method;
 42  0
   this.model = model;
 43  0
  }
 44  
 
 45  
  private Collection errors;
 46  
 
 47  
  @Override
 48  
  public Collection<String> validate ()
 49  
  {
 50  0
   errors = new ArrayList ();
 51  0
   basicValidation ();
 52  0
   for (ServiceMethodParameter param : method.getParameters ())
 53  
   {
 54  0
    errors.addAll (new ServiceMethodParameterValidator (param, method).validate ());
 55  
   }
 56  0
   errors.addAll (new ServiceMethodReturnValueValidator (method.getReturnValue (), method).
 57  
    validate ());
 58  0
   for (ServiceMethodError param : method.getErrors ())
 59  
   {
 60  0
    errors.addAll (new ServiceMethodErrorValidator (param, method).validate ());
 61  
   }
 62  0
   return errors;
 63  
  }
 64  
 
 65  
  private void basicValidation ()
 66  
  {
 67  0
   if (method.getService ().equals (""))
 68  
   {
 69  0
    addError ("Service is required");
 70  
   }
 71  
   else
 72  
   {
 73  0
    if (findService (method.getService ()) == null)
 74  
    {
 75  0
     addError ("Service, [" + method.getService () +
 76  
      "] could not be found in the list of services");
 77  
    }
 78  
   }
 79  0
   if (method.getName ().equals (""))
 80  
   {
 81  0
    addError ("Name is required");
 82  
   }
 83  0
   if (method.getDescription ().equals (""))
 84  
   {
 85  0
    addError ("Description is required");
 86  
   }
 87  0
   if (method.getReturnValue () == null)
 88  
   {
 89  0
    addError ("Return value is required");
 90  
   }
 91  0
  }
 92  
 
 93  
  private Service findService (String service)
 94  
  {
 95  
   // if we are only working with the searchModel then can't validate service
 96  0
   if ( ! (model instanceof ServiceContractModel))
 97  
   {
 98  0
    return null;
 99  
   }
 100  0
   return new ModelFinder (model).findService (service);
 101  
  }
 102  
 
 103  
  private void addError (String msg)
 104  
  {
 105  0
   String error = "Error in service method: " + method.getService () + "." +
 106  
    method.getName () + ": " + msg;
 107  0
   if ( ! errors.contains (error))
 108  
   {
 109  0
    errors.add (error);
 110  
   }
 111  0
  }
 112  
 
 113  
 }