Coverage Report - org.kuali.student.contract.model.validation.XmlTypesValidator
 
Classes in this File Line Coverage Branch Coverage Complexity
XmlTypesValidator
0%
0/23
0%
0/14
2.75
 
 1  
 /*
 2  
  * Copyright 2010 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 java.util.ArrayList;
 19  
 import java.util.Collection;
 20  
 
 21  
 import org.kuali.student.contract.model.ServiceContractModel;
 22  
 import org.kuali.student.contract.model.XmlType;
 23  
 import org.kuali.student.contract.model.util.ModelFinder;
 24  
 
 25  
 /**
 26  
  *
 27  
  * @author nwright
 28  
  */
 29  
 public class XmlTypesValidator implements ModelValidator
 30  
 {
 31  
 
 32  
  private ServiceContractModel model;
 33  
  private ModelFinder finder;
 34  
  private XmlType xmlType;
 35  
 
 36  
  public XmlTypesValidator (XmlType xmlType, ServiceContractModel model)
 37  0
  {
 38  0
   this.model = model;
 39  0
   this.finder = new ModelFinder (model);
 40  0
   this.xmlType = xmlType;
 41  0
  }
 42  
  private Collection errors;
 43  
 
 44  
  @Override
 45  
  public Collection<String> validate ()
 46  
  {
 47  
 
 48  0
   errors = new ArrayList ();
 49  0
   basicValidation ();
 50  0
   return errors;
 51  
  }
 52  
 
 53  
  private void basicValidation ()
 54  
  {
 55  0
   if (xmlType.getName ().equals (""))
 56  
   {
 57  0
    addError ("Name is required");
 58  
   }
 59  0
   if (xmlType.getName ().equalsIgnoreCase ("Object"))
 60  
   {
 61  0
    addError ("Object is reserved and cannot be used as the name of an XmlType");
 62  
   }
 63  0
   if (xmlType.getName ().equalsIgnoreCase ("ObjectList"))
 64  
   {
 65  0
    addError ("Object is reserved and cannot be used as the name of an XmlType");
 66  
   }
 67  0
   if ( ! xmlType.getService ().equals (""))
 68  
   {
 69  0
    for (String srv : xmlType.getService ().split (","))
 70  
    {
 71  0
     if (finder.findService (srv.trim ()) == null)
 72  
     {
 73  0
      addError ("Service, [" + srv
 74  
                + "] could not be found in the list of services");
 75  
     }
 76  
    }
 77  
   }
 78  0
  }
 79  
 
 80  
  private void addError (String msg)
 81  
  {
 82  0
   String error = "Error in xmlType entry: " + xmlType.getName () + ": " + msg;
 83  0
   if ( ! errors.contains (error))
 84  
   {
 85  0
    errors.add (error);
 86  
   }
 87  0
  }
 88  
 }