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.DictionaryModel; |
19 | |
import org.kuali.student.contract.model.SearchModel; |
20 | |
import org.kuali.student.contract.model.SearchType; |
21 | |
import org.kuali.student.contract.model.Service; |
22 | |
import org.kuali.student.contract.model.util.ModelFinder; |
23 | |
|
24 | |
import java.util.ArrayList; |
25 | |
import java.util.Collection; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class SearchTypeValidator implements ModelValidator |
32 | |
{ |
33 | |
|
34 | |
private SearchType searchType; |
35 | |
private SearchModel model; |
36 | |
|
37 | |
public SearchTypeValidator (SearchType searchType, SearchModel model) |
38 | 0 | { |
39 | 0 | this.searchType = searchType; |
40 | 0 | this.model = model; |
41 | 0 | } |
42 | |
|
43 | |
private Collection errors; |
44 | |
|
45 | |
@Override |
46 | |
public Collection<String> validate () |
47 | |
{ |
48 | 0 | errors = new ArrayList (); |
49 | 0 | basicValidation (); |
50 | 0 | if (searchType.getImplementation () == null) |
51 | |
{ |
52 | 0 | addError ("JPQL implementation is required"); |
53 | |
} |
54 | 0 | if (searchType.getSearchCriteria () == null) |
55 | |
{ |
56 | 0 | addError ("Criteria is required"); |
57 | |
} |
58 | 0 | ModelValidator validator = |
59 | |
new SearchCriteriaValidator (searchType.getSearchCriteria (), searchType); |
60 | 0 | errors.addAll (validator.validate ()); |
61 | 0 | if (searchType.getSearchResult () == null) |
62 | |
{ |
63 | 0 | addError ("Results is required"); |
64 | |
} |
65 | 0 | validator = |
66 | |
new SearchResultValidator (searchType.getSearchResult (), searchType); |
67 | 0 | errors.addAll (validator.validate ()); |
68 | 0 | return errors; |
69 | |
} |
70 | |
|
71 | |
private void basicValidation () |
72 | |
{ |
73 | 0 | if (searchType.getKey ().equals ("")) |
74 | |
{ |
75 | 0 | addError ("search type key is required"); |
76 | |
} |
77 | 0 | if ( ! searchType.getType ().equals ("Search")) |
78 | |
{ |
79 | 0 | addError ("'Type' column in the search type must be 'Search'"); |
80 | |
} |
81 | 0 | if (searchType.getName ().equals ("")) |
82 | |
{ |
83 | 0 | addError ("Name is required"); |
84 | |
} |
85 | 0 | if (searchType.getDescription ().equals ("")) |
86 | |
{ |
87 | 0 | addError ("Description is required"); |
88 | |
} |
89 | 0 | if ( ! searchType.getDataType ().equals ("")) |
90 | |
{ |
91 | 0 | addError ("Data Type should be blank"); |
92 | |
} |
93 | 0 | if ( ! searchType.getService ().equals ("")) |
94 | |
{ |
95 | 0 | if (findService (searchType.getService ()) == null) |
96 | |
{ |
97 | 0 | addError ("Service, [" + searchType.getService () |
98 | |
+ "] could not be found in the list of services"); |
99 | |
} |
100 | |
} |
101 | 0 | } |
102 | |
|
103 | |
private Service findService (String service) |
104 | |
{ |
105 | |
|
106 | 0 | if ( ! (model instanceof DictionaryModel)) |
107 | |
{ |
108 | 0 | return null; |
109 | |
} |
110 | 0 | return new ModelFinder ((DictionaryModel) model).findService (service); |
111 | |
} |
112 | |
|
113 | |
private void addError (String msg) |
114 | |
{ |
115 | 0 | String error = "Error in searchType entry: " + searchType.getKey () + |
116 | |
": " + msg; |
117 | 0 | if ( ! errors.contains (error)) |
118 | |
{ |
119 | 0 | errors.add (error); |
120 | |
} |
121 | 0 | } |
122 | |
|
123 | |
} |