View Javadoc
1   /**
2    * Copyright 2005-2015 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  /*
17   * To change this template, choose Tools | Templates
18   * and open the template in the editor.
19   */
20  package org.kuali.rice.krms.impl.repository.mock;
21  
22  import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
23  import org.kuali.rice.krms.api.repository.term.TermRepositoryService;
24  import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition;
25  
26  /**
27   *
28   * @author nwright
29   */
30  public class KrmsTermSpecificationLoader {
31      
32      private TermRepositoryService termRepositoryService = null;
33      
34      public TermRepositoryService getTermRepositoryService() {
35          return termRepositoryService;
36      }
37      
38      public void setTermRepositoryService(TermRepositoryService termRepositoryService) {
39          this.termRepositoryService = termRepositoryService;
40      }
41      
42      public void loadTermSpec(String id, String name, String type, String description, String namespace) {
43          TermSpecificationDefinition.Builder bldr = TermSpecificationDefinition.Builder.create(id, name, namespace, type);
44          bldr.setDescription(description);
45          bldr.setId(id);
46          bldr.setActive(true);
47          TermSpecificationDefinition existing = this.findExisting(bldr);
48          if (existing == null) {
49              this.getTermRepositoryService().createTermSpecification(bldr.build());
50          } else {
51              bldr.setVersionNumber(existing.getVersionNumber());
52              this.getTermRepositoryService().updateTermSpecification(bldr.build());
53          }
54      }
55      
56      private TermSpecificationDefinition findExisting(TermSpecificationDefinition.Builder bldr) {
57          if (bldr.getId() != null) {
58              try {
59                  return this.getTermRepositoryService().getTermSpecificationById(bldr.getId());
60              } catch (RiceIllegalArgumentException ex) {
61                  return null;
62              }
63          }
64          return this.getTermRepositoryService().getTermSpecificationByNameAndNamespace(bldr.getName(), bldr.getNamespace());
65      }
66      
67      public void load() {
68          loadTermSpec("10000", "CompletedCourse", "java.lang.Boolean", "Completed course", "KS-SYS");
69          loadTermSpec("10001", "CompletedCourses", "java.lang.Boolean", "Completed courses", "KS-SYS");
70          loadTermSpec("10002", "NumberOfCompletedCourses", "java.lang.Integer", " Number of completed courses", "KS-SYS");
71          loadTermSpec("10003", "NumberOfCreditsFromCompletedCourses", "java.lang.Integer", "Number of credits from completed courses", "KS-SYS");
72          loadTermSpec("10004", "EnrolledCourses", "java.lang.Integer", "Enrolled courses", "KS-SYS");
73          loadTermSpec("10005", "GPAForCourses", "java.lang.Integer", "GPA for courses", "KS-SYS");
74          loadTermSpec("10006", "GradeTypeForCourses", "java.lang.Integer", "Grade type for courses", "KS-SYS");
75          loadTermSpec("10007", "NumberOfCredits", "java.lang.Integer", "Number of credits", "KS-SYS");
76          loadTermSpec("10008", "NumberOfCreditsFromOrganization", "java.lang.Integer", "Number of credits from organization", "KS-SYS");
77          loadTermSpec("10009", "AdminOrganizationPermissionRequired", "java.lang.Boolean", "Admin organization permission required", "KS-SYS");
78          loadTermSpec("10010", "ScoreOnTest", "java.lang.Integer", "Score on test", "KS-SYS");
79          loadTermSpec("10011", "AdmittedToProgram", "java.lang.Boolean", "Admitted to program", "KS-SYS");
80          loadTermSpec("10012", "AdmittedToProgramLimitCoursesInOrgForDuration", "java.lang.Integer", "Admitted to program limit courses in organization for duration", "KS-SYS");
81          loadTermSpec("10013", "FreeFormText", "java.lang.Boolean", "Free Form Text", "KS-SYS");
82      }
83  }