View Javadoc

1   /**
2    * Copyright 2004-2013 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.opensource.org/licenses/ecl2.php
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.DictionaryModel;
19  import org.kuali.student.contract.model.OrchObj;
20  import org.kuali.student.contract.model.util.ModelFinder;
21  
22  import java.util.ArrayList;
23  import java.util.Collection;
24  import java.util.List;
25  
26  /**
27   * Validates the entire spreadsheet model
28   * @author nwright
29   */
30  public class OrchestrationModelValidator implements ModelValidator {
31  
32      private DictionaryModel model;
33      private ModelFinder finder;
34  
35      public OrchestrationModelValidator(DictionaryModel model) {
36          this.model = model;
37          this.finder = new ModelFinder(model);
38      }
39      List<String> errors;
40  
41      @Override
42      public Collection<String> validate() {
43          errors = new ArrayList();
44          validateOrchObjs();
45          errors.addAll(new DictionaryModelValidator(model).validate());
46          return errors;
47      }
48  
49      private void validateOrchObjs() {
50          if (model.getOrchObjs().size() == 0) {
51              addError("No orchestration objects found");
52          }
53          for (OrchObj orch : model.getOrchObjs()) {
54              OrchObjValidator cv = new OrchObjValidator(orch);
55              errors.addAll(cv.validate());
56          }
57      }
58  
59      private void addError(String msg) {
60          String error = "Error in orchestration dictionary spreadsheet: " + msg;
61          if (!errors.contains(error)) {
62              errors.add(error);
63          }
64      }
65  }