View Javadoc
1   /**
2    * Copyright 2004-2014 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.opensource.org/licenses/ecl2.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.student.contract.model.validation;
17  
18  import org.kuali.student.contract.model.ServiceMethod;
19  import org.kuali.student.contract.model.ServiceMethodParameter;
20  
21  import java.util.ArrayList;
22  import java.util.Collection;
23  
24  /**
25   * This validates a single criteriainoary entry
26   * @author nwright
27   */
28  public class ServiceMethodParameterValidator implements ModelValidator {
29  
30      private ServiceMethodParameter parameter;
31      private ServiceMethod method;
32  
33      public ServiceMethodParameterValidator(ServiceMethodParameter parameter,
34              ServiceMethod method) {
35          this.parameter = parameter;
36          this.method = method;
37      }
38      private Collection<String> errors;
39  
40      @Override
41      public Collection<String> validate() {
42          errors = new ArrayList<String>();
43          basicValidation();
44          return errors;
45      }
46  
47      private void basicValidation() {
48      	String methodName = method.getService() + "." + method.getName();
49      	
50      	
51          if (parameter.getName().equals("")) {
52              addError(methodName + ": parameter name is required");
53          }
54          if (parameter.getDescription().equals("")) {
55              addError(methodName + ": parameter description is required");
56          }
57          if (parameter.getType().equals("")) {
58              addError(methodName + ": parameter Type is required");
59          }
60      }
61  
62      private void addError(String msg) {
63          String error = "Error in parameter: " + method.getService() + "."
64                  + method.getName() + "(" + parameter.getName()
65                  + "): " + msg;
66          if (!errors.contains(error)) {
67              errors.add(error);
68          }
69      }
70  }