Clover Coverage Report - KS Contract Documentation Generator 0.0.1-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
26   93   12   5.2
14   64   0.46   5
5     2.4  
1    
 
  ServiceMethodValidator       Line # 33 26 0% 12 45 0% 0.0
 
No Tests
 
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    private ServiceMethod method;
36    private ServiceContractModel model;
37   
 
38  0 toggle public ServiceMethodValidator(ServiceMethod method, ServiceContractModel model) {
39  0 this.method = method;
40  0 this.model = model;
41    }
42    private Collection errors;
43   
 
44  0 toggle @Override
45    public Collection<String> validate() {
46  0 errors = new ArrayList();
47  0 basicValidation();
48  0 for (ServiceMethodParameter param : method.getParameters()) {
49  0 errors.addAll(new ServiceMethodParameterValidator(param, method).validate());
50    }
51  0 errors.addAll(new ServiceMethodReturnValueValidator(method.getReturnValue(), method).validate());
52  0 for (ServiceMethodError param : method.getErrors()) {
53  0 errors.addAll(new ServiceMethodErrorValidator(param, method).validate());
54    }
55  0 return errors;
56    }
57   
 
58  0 toggle private void basicValidation() {
59  0 if (method.getService().equals("")) {
60  0 addError("Service is required");
61    } else {
62  0 if (findService(method.getService()) == null) {
63  0 addError("Service, [" + method.getService()
64    + "] could not be found in the list of services");
65    }
66    }
67  0 if (method.getName().equals("")) {
68  0 addError("Name is required");
69    }
70  0 if (method.getDescription().equals("")) {
71  0 addError("Description is required");
72    }
73  0 if (method.getReturnValue() == null) {
74  0 addError("Return value is required");
75    }
76    }
77   
 
78  0 toggle private Service findService(String service) {
79    // if we are only working with the searchModel then can't validate service
80  0 if (!(model instanceof ServiceContractModel)) {
81  0 return null;
82    }
83  0 return new ModelFinder(model).findService(service);
84    }
85   
 
86  0 toggle private void addError(String msg) {
87  0 String error = "Error in service method: " + method.getService() + "."
88    + method.getName() + ": " + msg;
89  0 if (!errors.contains(error)) {
90  0 errors.add(error);
91    }
92    }
93    }