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.SearchCriteria; |
19 | |
import org.kuali.student.contract.model.SearchType; |
20 | |
|
21 | |
import java.util.ArrayList; |
22 | |
import java.util.Collection; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
public class SearchCriteriaValidator implements ModelValidator |
29 | |
{ |
30 | |
|
31 | |
private SearchCriteria criteria; |
32 | |
private SearchType searchType; |
33 | |
|
34 | |
public SearchCriteriaValidator (SearchCriteria criteria, SearchType searchType) |
35 | 0 | { |
36 | 0 | this.criteria = criteria; |
37 | 0 | this.searchType = searchType; |
38 | 0 | } |
39 | |
|
40 | |
private Collection errors; |
41 | |
|
42 | |
@Override |
43 | |
public Collection<String> validate () |
44 | |
{ |
45 | 0 | errors = new ArrayList (); |
46 | 0 | basicValidation (); |
47 | 0 | if (criteria.getParameters () == null) |
48 | |
{ |
49 | 0 | addError ("A parameter list is required even if no parameters"); |
50 | |
} |
51 | 0 | return errors; |
52 | |
} |
53 | |
|
54 | |
private void basicValidation () |
55 | |
{ |
56 | 0 | if (criteria.getKey ().equals ("")) |
57 | |
{ |
58 | 0 | addError ("criteria key is required"); |
59 | |
} |
60 | 0 | if ( ! criteria.getType ().equals ("Criteria")) |
61 | |
{ |
62 | 0 | addError ("'Type' column in the criteria must be 'Criteria'"); |
63 | |
} |
64 | 0 | if (criteria.getName ().equals ("")) |
65 | |
{ |
66 | 0 | addError ("Name is required"); |
67 | |
} |
68 | 0 | if (criteria.getDescription ().equals ("")) |
69 | |
{ |
70 | 0 | addError ("Description is required"); |
71 | |
} |
72 | 0 | if ( ! criteria.getDataType ().equals ("")) |
73 | |
{ |
74 | 0 | addError ("Data Type should be blank"); |
75 | |
} |
76 | 0 | } |
77 | |
|
78 | |
private void addError (String msg) |
79 | |
{ |
80 | 0 | String error = "Error in criteria entry: " + searchType.getKey () + "." + criteria.getKey () + |
81 | |
": " + msg; |
82 | 0 | if ( ! errors.contains (error)) |
83 | |
{ |
84 | 0 | errors.add (error); |
85 | |
} |
86 | 0 | } |
87 | |
|
88 | |
} |