1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
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 }