| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 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 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
public class ServiceMethodParameterValidator implements ModelValidator |
| 29 | |
{ |
| 30 | |
|
| 31 | |
private ServiceMethodParameter parameter; |
| 32 | |
private ServiceMethod method; |
| 33 | |
|
| 34 | |
public ServiceMethodParameterValidator (ServiceMethodParameter parameter, |
| 35 | |
ServiceMethod method) |
| 36 | 0 | { |
| 37 | 0 | this.parameter = parameter; |
| 38 | 0 | this.method = method; |
| 39 | 0 | } |
| 40 | |
|
| 41 | |
private Collection errors; |
| 42 | |
|
| 43 | |
@Override |
| 44 | |
public Collection<String> validate () |
| 45 | |
{ |
| 46 | 0 | errors = new ArrayList (); |
| 47 | 0 | basicValidation (); |
| 48 | 0 | return errors; |
| 49 | |
} |
| 50 | |
|
| 51 | |
private void basicValidation () |
| 52 | |
{ |
| 53 | 0 | if (parameter.getName ().equals ("")) |
| 54 | |
{ |
| 55 | 0 | addError ("Name is required"); |
| 56 | |
} |
| 57 | 0 | if (parameter.getDescription ().equals ("")) |
| 58 | |
{ |
| 59 | 0 | addError ("Description is required"); |
| 60 | |
} |
| 61 | 0 | if (parameter.getType ().equals ("")) |
| 62 | |
{ |
| 63 | 0 | addError ("Type is required"); |
| 64 | |
} |
| 65 | 0 | } |
| 66 | |
|
| 67 | |
private void addError (String msg) |
| 68 | |
{ |
| 69 | 0 | String error = "Error in parameter: " + method.getService () + "." + |
| 70 | |
method.getName () + "(" + parameter.getName () + |
| 71 | |
"): " + msg; |
| 72 | 0 | if ( ! errors.contains (error)) |
| 73 | |
{ |
| 74 | 0 | errors.add (error); |
| 75 | |
} |
| 76 | 0 | } |
| 77 | |
|
| 78 | |
} |