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.SearchResult; |
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 SearchResultValidator implements ModelValidator |
29 | |
{ |
30 | |
|
31 | |
private SearchResult result; |
32 | |
private SearchType searchType; |
33 | |
|
34 | |
public SearchResultValidator (SearchResult result, SearchType searchType) |
35 | 0 | { |
36 | 0 | this.result = result; |
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 (result.getResultColumns () == null) |
48 | |
{ |
49 | 0 | addError ("A result column list is required"); |
50 | |
} |
51 | 0 | if (result.getResultColumns ().size () == 0) |
52 | |
{ |
53 | 0 | addError ("A result must have at least one column"); |
54 | |
} |
55 | 0 | return errors; |
56 | |
} |
57 | |
|
58 | |
private void basicValidation () |
59 | |
{ |
60 | 0 | if (result.getKey ().equals ("")) |
61 | |
{ |
62 | 0 | addError ("result key is required"); |
63 | |
} |
64 | 0 | if ( ! result.getType ().equals ("Result")) |
65 | |
{ |
66 | 0 | addError ("'Type' column in the result must be 'Result'"); |
67 | |
} |
68 | 0 | if (result.getName ().equals ("")) |
69 | |
{ |
70 | 0 | addError ("Name is required"); |
71 | |
} |
72 | 0 | if (result.getDescription ().equals ("")) |
73 | |
{ |
74 | 0 | addError ("Description is required"); |
75 | |
} |
76 | 0 | if ( ! result.getDataType ().equals ("")) |
77 | |
{ |
78 | 0 | addError ("Data Type should be blank"); |
79 | |
} |
80 | 0 | } |
81 | |
|
82 | |
private void addError (String msg) |
83 | |
{ |
84 | 0 | String error = "Error in result entry: " +searchType.getKey () + "." + result.getKey () + |
85 | |
": " + msg; |
86 | 0 | if ( ! errors.contains (error)) |
87 | |
{ |
88 | 0 | errors.add (error); |
89 | |
} |
90 | 0 | } |
91 | |
|
92 | |
} |