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 java.util.HashMap;
23 import java.util.LinkedHashSet;
24 import java.util.Map;
25 import java.util.Set;
26 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
27 import org.kuali.rice.krms.api.repository.term.TermRepositoryService;
28 import org.kuali.rice.krms.api.repository.term.TermResolverDefinition;
29 import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition;
30
31
32
33
34
35 public class KrmsTermResolverLoader {
36
37 private TermRepositoryService termRepositoryService = null;
38
39 public TermRepositoryService getTermRepositoryService() {
40 return termRepositoryService;
41 }
42
43 public void setTermRepositoryService(TermRepositoryService termRepositoryService) {
44 this.termRepositoryService = termRepositoryService;
45 }
46
47 public void loadTermResolver(String id,
48 String namespace,
49 String name,
50 String typeId,
51 String outputId,
52 String prereqId1,
53 String prereqId2,
54 String prereqId3) {
55 TermSpecificationDefinition.Builder output =
56 TermSpecificationDefinition.Builder.create(this.getTermRepositoryService().getTermSpecificationById(outputId));
57 Set<TermSpecificationDefinition.Builder> prerequisites =
58 new LinkedHashSet<TermSpecificationDefinition.Builder>();
59 if (prereqId1 != null && !prereqId1.isEmpty()) {
60 prerequisites.add(TermSpecificationDefinition.Builder.create(this.getTermRepositoryService().getTermSpecificationById(prereqId1)));
61 }
62 if (prereqId2 != null && !prereqId2.isEmpty()) {
63 prerequisites.add(TermSpecificationDefinition.Builder.create(this.getTermRepositoryService().getTermSpecificationById(prereqId2)));
64 }
65 if (prereqId3 != null && !prereqId3.isEmpty()) {
66 prerequisites.add(TermSpecificationDefinition.Builder.create(this.getTermRepositoryService().getTermSpecificationById(prereqId3)));
67 }
68 Map<String, String> attributes = new HashMap<String, String>();
69
70 Set<String> parameterNames = new LinkedHashSet<String>();
71
72
73
74
75
76
77
78
79 TermResolverDefinition.Builder bldr = TermResolverDefinition.Builder.create(id,
80 namespace,
81 name,
82 typeId,
83 output,
84 prerequisites,
85 attributes,
86 parameterNames);
87 bldr.setActive(true);
88 TermResolverDefinition existing = this.findExisting(bldr);
89 if (existing == null) {
90 this.getTermRepositoryService().createTermResolver(bldr.build());
91 } else {
92 bldr.setVersionNumber(existing.getVersionNumber());
93 this.getTermRepositoryService().updateTermResolver(bldr.build());
94 }
95 }
96
97 private TermResolverDefinition findExisting(TermResolverDefinition.Builder bldr) {
98 if (bldr.getId() != null) {
99 try {
100 return this.getTermRepositoryService().getTermResolverById(bldr.getId());
101 } catch (RiceIllegalArgumentException ex) {
102 return null;
103 }
104 }
105 return this.getTermRepositoryService().getTermResolverByNameAndNamespace(bldr.getName(), bldr.getNamespace());
106 }
107
108 public void load() {
109 loadTermResolver("10000", "KS-SYS", "CompletedCourse", "10000", "10000", "", "", "");
110 loadTermResolver("10001", "KS-SYS", "CompletedCourses", "10000", "10001", "", "", "");
111 loadTermResolver("10002", "KS-SYS", "NumberOfCompletedCourses", "10000", "10002", "", "", "");
112 loadTermResolver("10003", "KS-SYS", "NumberOfCreditsFromCompletedCourses", "10000", "10003", "", "", "");
113 loadTermResolver("10004", "KS-SYS", "EnrolledCourses", "10000", "10004", "", "", "");
114 loadTermResolver("10005", "KS-SYS", "GPAForCourses", "10000", "10005", "", "", "");
115 loadTermResolver("10006", "KS-SYS", "GradeTypeForCourses", "10000", "10006", "", "", "");
116 loadTermResolver("10007", "KS-SYS", "NumberOfCredits", "10000", "10007", "", "", "");
117 loadTermResolver("10008", "KS-SYS", "NumberOfCreditsFromOrganization", "10000", "10008", "", "", "");
118 loadTermResolver("10009", "KS-SYS", "AdminOrganizationPermissionRequired", "10000", "10009", "", "", "");
119 loadTermResolver("10010", "KS-SYS", "ScoreOnTest", "10000", "10010", "", "", "");
120 loadTermResolver("10011", "KS-SYS", "AdmittedToProgram", "10000", "10011", "", "", "");
121 loadTermResolver("10012", "KS-SYS", "AdmittedToProgramLimitCoursesInOrgForDuration", "10000", "10012", "", "", "");
122 loadTermResolver("10013", "KS-SYS", "FreeFormText", "10000", "10013", "", "", "");
123 }
124 }