View Javadoc

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.SearchResult;
19  import org.kuali.student.contract.model.SearchType;
20  
21  import java.util.ArrayList;
22  import java.util.Collection;
23  
24  /**
25   * This validates a single resultinoary entry
26   * @author nwright
27   */
28  public class SearchResultValidator implements ModelValidator {
29  
30      private SearchResult result;
31      private SearchType searchType;
32  
33      public SearchResultValidator(SearchResult result, SearchType searchType) {
34          this.result = result;
35          this.searchType = searchType;
36      }
37      private Collection errors;
38  
39      @Override
40      public Collection<String> validate() {
41          errors = new ArrayList();
42          basicValidation();
43          if (result.getResultColumns() == null) {
44              addError("A result column list is required");
45          }
46          if (result.getResultColumns().size() == 0) {
47              addError("A result must have at least one column");
48          }
49          return errors;
50      }
51  
52      private void basicValidation() {
53          if (result.getKey().equals("")) {
54              addError("result key is required");
55          }
56          if (!result.getType().equals("Result")) {
57              addError("'Type' column in the result must be 'Result'");
58          }
59          if (result.getName().equals("")) {
60              addError("Name is required");
61          }
62          if (result.getDescription().equals("")) {
63              addError("Description is required");
64          }
65          if (!result.getDataType().equals("")) {
66              addError("Data Type should be blank");
67          }
68      }
69  
70      private void addError(String msg) {
71          String error = "Error in result entry: " + searchType.getKey() + "." + result.getKey()
72                  + ": " + msg;
73          if (!errors.contains(error)) {
74              errors.add(error);
75          }
76      }
77  }