Coverage Report - org.kuali.student.contract.model.validation.ServiceContractModelValidator
 
Classes in this File Line Coverage Branch Coverage Complexity
ServiceContractModelValidator
0%
0/25
0%
0/10
1.833
 
 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.ServiceContractModel;
 19  
 import org.kuali.student.contract.model.ServiceMethod;
 20  
 import org.kuali.student.contract.model.XmlType;
 21  
 
 22  
 import java.util.ArrayList;
 23  
 import java.util.Collection;
 24  
 
 25  
 /**
 26  
  * This validates a single serviceMethodinoary entry
 27  
  * @author nwright
 28  
  */
 29  
 public class ServiceContractModelValidator implements ModelValidator
 30  
 {
 31  
 
 32  
  private ServiceContractModel model;
 33  
 
 34  
  public ServiceContractModelValidator (ServiceContractModel model)
 35  0
  {
 36  0
   this.model = model;
 37  0
  }
 38  
  private Collection errors;
 39  
 
 40  
  @Override
 41  
  public Collection<String> validate ()
 42  
  {
 43  0
   errors = new ArrayList ();
 44  0
   basicValidation ();
 45  0
   this.validateServiceMethods ();
 46  0
   validateXmlTypes ();
 47  0
   return errors;
 48  
  }
 49  
 
 50  
  private void validateServiceMethods ()
 51  
  {
 52  0
   for (ServiceMethod method : model.getServiceMethods ())
 53  
   {
 54  0
    errors.addAll (new ServiceMethodValidator (method, model).validate ());
 55  
   }
 56  0
  }
 57  
 
 58  
  private void validateXmlTypes ()
 59  
  {
 60  0
   if (model.getXmlTypes ().size () == 0)
 61  
   {
 62  0
    addError ("No xmlTypes found");
 63  
   }
 64  0
   for (XmlType xmlType : model.getXmlTypes ())
 65  
   {
 66  0
    XmlTypesValidator validator = new XmlTypesValidator (xmlType, model);
 67  0
    errors.addAll (validator.validate ());
 68  0
   }
 69  0
  }
 70  
 
 71  
  private void basicValidation ()
 72  
  {
 73  0
   if (model.getServiceMethods ().size () == 0)
 74  
   {
 75  0
    addError ("no service methods have been defined");
 76  
   }
 77  0
  }
 78  
 
 79  
  private void addError (String msg)
 80  
  {
 81  0
   String error = "Error in service methods: " + msg;
 82  0
   if ( ! errors.contains (error))
 83  
   {
 84  0
    errors.add (error);
 85  
   }
 86  0
  }
 87  
 }