1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.krms;
17
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.kuali.rice.core.api.lifecycle.Lifecycle;
21 import org.kuali.rice.core.framework.resourceloader.SpringResourceLoader;
22 import org.kuali.rice.krad.service.BusinessObjectService;
23 import org.kuali.rice.krad.service.KRADServiceLocator;
24 import org.kuali.rice.krms.api.repository.LogicalOperator;
25 import org.kuali.rice.krms.api.repository.agenda.AgendaDefinition;
26 import org.kuali.rice.krms.api.repository.agenda.AgendaItemDefinition;
27 import org.kuali.rice.krms.api.repository.context.ContextDefinition;
28 import org.kuali.rice.krms.api.repository.proposition.PropositionDefinition;
29 import org.kuali.rice.krms.api.repository.proposition.PropositionParameter;
30 import org.kuali.rice.krms.api.repository.proposition.PropositionParameterType;
31 import org.kuali.rice.krms.api.repository.proposition.PropositionType;
32 import org.kuali.rice.krms.api.repository.rule.RuleDefinition;
33 import org.kuali.rice.krms.api.repository.term.TermDefinition;
34 import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
35 import org.kuali.rice.krms.api.repository.type.KrmsTypeRepositoryService;
36 import org.kuali.rice.krms.impl.repository.*;
37 import org.kuali.rice.test.BaselineTestCase.BaselineMode;
38 import org.kuali.rice.test.BaselineTestCase.Mode;
39
40 import javax.xml.namespace.QName;
41 import java.util.*;
42 import java.util.Map.Entry;
43
44 public class TestKRMSCreateAgendasPhase2 extends KSKRMSUploadTestCase {
45
46 public TestKRMSCreateAgendasPhase2() {
47 super();
48 this.setClearTables(false);
49 }
50
51 static final String KSNAMESPACE = "KR-RULE-TEST";
52 protected ContextBoService contextRepository;
53 protected KrmsTypeRepositoryService krmsTypeRepository;
54 private AgendaBoService agendaBoService;
55 private RuleBoService ruleBoService;
56 private FunctionBoServiceImpl functionBoService;
57
58
59 private TermBoService termBoService;
60 private SpringResourceLoader krmsTestResourceLoader;
61
62 Map<String, ContextDefinition> phase1ContextDefs = new HashMap<String, ContextDefinition>();
63 KrmsTypeDefinition krmsTypeDefinition;
64 ContextDefinition contextStudElig;
65 static final String EARTHQUAKE_EVENT = "Earthquake";
66 public static final String CAMPUS_CODE_TERM_NAME = "campusCodeTermSpec";
67 static final String BOOL1 = "bool1";
68 static final String BOOL2 = "bool2";
69 static final String PREREQ_TERM_NAME = "prereqTermSpec";
70
71 @Before
72 public void setup() {
73 getLoadApplicationLifecycle();
74 termBoService = KrmsRepositoryServiceLocator.getTermBoService();
75 agendaBoService = KrmsRepositoryServiceLocator.getAgendaBoService();
76 contextRepository = KrmsRepositoryServiceLocator.getContextBoService();
77 ruleBoService = KrmsRepositoryServiceLocator.getRuleBoService();
78 krmsTypeRepository = KrmsRepositoryServiceLocator
79 .getKrmsTypeRepositoryService();
80 functionBoService = KrmsRepositoryServiceLocator
81 .getBean("functionRepositoryService");
82
83 }
84
85 @Override
86 protected void loadSuiteTestData() throws Exception {
87
88 }
89
90 @Override
91 protected List<String> getPerTestTablesNotToClear() {
92 List<String> tablesNotToClear = super.getPerTestTablesNotToClear();
93
94 return tablesNotToClear;
95 }
96
97 @Override
98 protected Lifecycle getLoadApplicationLifecycle() {
99 if (krmsTestResourceLoader == null) {
100 krmsTestResourceLoader = new SpringResourceLoader(new QName(
101 "KRMSTestHarnessApplicationResourceLoader"),
102 "classpath:KRMSTestHarnessSpringBeans.xml", null);
103 krmsTestResourceLoader
104 .setParentSpringResourceLoader(getTestHarnessSpringResourceLoader());
105 getTestHarnessSpringResourceLoader().addResourceLoader(
106 krmsTestResourceLoader);
107 }
108 return krmsTestResourceLoader;
109 }
110
111
112 @Test
113 public void createAllAgendasAndRulesPhase1() {
114 Map<String, PropositionParameterType> propositionsMap = new HashMap<String, PropositionParameterType>();
115
116
117 PropositionParametersBuilder proposition20_1 = createProposition(
118 KSKRMSConstants.TERM_NUMBER_OF_CREDITS, "5", "=");
119 PropositionParametersBuilder proposition20_2 = createProposition(
120 KSKRMSConstants.TERM_DEPT_NUMBER, "1", "=");
121 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA20,
122 contextRepository.getContextByNameAndNamespace(
123 KSKRMSConstants.CONTEXT_STUD_ELIGIBILITY, KSNAMESPACE),
124 null, KSNAMESPACE, proposition20_1, proposition20_2);
125
126
127 PropositionParametersBuilder proposition21_1 = createProposition(
128 KSKRMSConstants.TERM_ADMIN_ORG_NUMBER, "5", "=");
129 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA21,
130 contextRepository.getContextByNameAndNamespace(
131 KSKRMSConstants.CONTEXT_STUD_ELIGIBILITY, KSNAMESPACE),
132 null, KSNAMESPACE, proposition21_1);
133
134
135 PropositionParametersBuilder proposition22_1 = createProposition(
136 KSKRMSConstants.TERM_TEST, "2nd", "=");
137 PropositionParametersBuilder proposition22_2 = createProposition(
138 KSKRMSConstants.TERM_SCORE, "5", "=");
139 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA22,
140 contextRepository.getContextByNameAndNamespace(
141 KSKRMSConstants.CONTEXT_STUD_ELIGIBILITY, KSNAMESPACE),
142 null, KSNAMESPACE, proposition22_1, proposition22_2);
143
144
145 PropositionParametersBuilder proposition24_1 = createProposition(
146 KSKRMSConstants.TERM_ENROLLED_COURSE, "MATH111", "=");
147 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA24,
148 contextRepository.getContextByNameAndNamespace(
149 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
150 null, KSNAMESPACE, proposition24_1);
151
152
153 PropositionParametersBuilder proposition24_1_1 = createProposition(
154 KSKRMSConstants.TERM_NUMBER_OF_COURSES, "2", "=");
155 PropositionParametersBuilder proposition24_1_2 = createProposition(
156 KSKRMSConstants.TERM_ENROLLED_COURSES, "MATH111", "=");
157 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA24,
158 contextRepository.getContextByNameAndNamespace(
159 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
160 null, KSNAMESPACE, proposition24_1_1, proposition24_1_2);
161
162
163 PropositionParametersBuilder proposition24_2_2 = createProposition(
164 KSKRMSConstants.TERM_ENROLLED_SET, "MATHS", "=");
165 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA24,
166 contextRepository.getContextByNameAndNamespace(
167 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
168 null, KSNAMESPACE, proposition24_1_1, proposition24_2_2);
169
170
171 PropositionParametersBuilder proposition24_3_2 = createProposition(
172 KSKRMSConstants.TERM_ENROLLED_COURSE_NUMBER_RANGE, "111", "=");
173 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA24,
174 contextRepository.getContextByNameAndNamespace(
175 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
176 null, KSNAMESPACE, proposition24_1_1, proposition24_3_2);
177
178
179 PropositionParametersBuilder proposition24_4_2 = createProposition(
180 KSKRMSConstants.TERM_ENROLLED_COURSE_NUMBER_SUBJECT_CODE, "MATH", "=");
181 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA24,
182 contextRepository.getContextByNameAndNamespace(
183 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
184 null, KSNAMESPACE, proposition24_1_1, proposition24_4_2);
185
186
187 PropositionParametersBuilder proposition24_5_2 = createProposition(
188 KSKRMSConstants.TERM_ENROLLED_EFFECTIVE_DATE_FROM, "12/12/12", "=");
189 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA24,
190 contextRepository.getContextByNameAndNamespace(
191 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
192 null, KSNAMESPACE, proposition24_1_1, proposition24_5_2);
193
194
195 PropositionParametersBuilder proposition24_6_2 = createProposition(
196 KSKRMSConstants.TERM_ENROLLED_EFFECTIVE_DATE_TO, "12/12/12", "=");
197 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA24,
198 contextRepository.getContextByNameAndNamespace(
199 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
200 null, KSNAMESPACE, proposition24_1_1, proposition24_6_2);
201
202
203 PropositionParametersBuilder proposition24_7_2 = createProposition(
204 KSKRMSConstants.TERM_NUMBER_OF_COURSES, "12/12/12", "=");
205 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA24,
206 contextRepository.getContextByNameAndNamespace(
207 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
208 null, KSNAMESPACE, proposition24_1_1, proposition24_7_2);
209
210
211
212 PropositionParametersBuilder proposition26_1 = createProposition(
213 KSKRMSConstants.TERM_NUMBER_OF_CREDITS, "5", "=");
214 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA26,
215 contextRepository.getContextByNameAndNamespace(
216 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
217 null, KSNAMESPACE, proposition26_1);
218
219
220 PropositionParametersBuilder proposition25_1_1 = createProposition(
221 KSKRMSConstants.TERM_ENROLLED_COURSES, "MATH111", "=");
222 PropositionParametersBuilder proposition25_1_2 = createProposition(
223 KSKRMSConstants.TERM_ENROLLED_COURSES, "MATH112", "=");
224 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA25,
225 contextRepository.getContextByNameAndNamespace(
226 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
227 null, KSNAMESPACE, proposition25_1_1, proposition25_1_2);
228
229 PropositionParametersBuilder proposition25_2 = createProposition(
230 KSKRMSConstants.TERM_ENROLLED_SET, "MATH", "=");
231 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA25,
232 contextRepository.getContextByNameAndNamespace(
233 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
234 null, KSNAMESPACE, proposition25_2);
235
236 PropositionParametersBuilder proposition25_3 = createProposition(
237 KSKRMSConstants.TERM_ENROLLED_COURSE_NUMBER_RANGE, "112", "=");
238 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA25,
239 contextRepository.getContextByNameAndNamespace(
240 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
241 null, KSNAMESPACE, proposition25_3);
242
243 PropositionParametersBuilder proposition25_4 = createProposition(
244 KSKRMSConstants.TERM_ENROLLED_LEARNING_OBJ_DESCR, "Skill", "=");
245 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA25,
246 contextRepository.getContextByNameAndNamespace(
247 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
248 null, KSNAMESPACE, proposition25_4);
249
250 PropositionParametersBuilder proposition25_5 = createProposition(
251 KSKRMSConstants.TERM_ENROLLED_EFFECTIVE_DATE_FROM, "12/12/12", "=");
252 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA25,
253 contextRepository.getContextByNameAndNamespace(
254 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
255 null, KSNAMESPACE, proposition25_5);
256
257 PropositionParametersBuilder proposition25_6 = createProposition(
258 KSKRMSConstants.TERM_ENROLLED_COURSE_NUMBER_SUBJECT_CODE, "MATH", "=");
259 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA25,
260 contextRepository.getContextByNameAndNamespace(
261 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
262 null, KSNAMESPACE, proposition25_6);
263
264
265 PropositionParametersBuilder proposition27_1 = createProposition(
266 KSKRMSConstants.TERM_GPA, "5", "=");
267 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA27,
268 contextRepository.getContextByNameAndNamespace(
269 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
270 null, KSNAMESPACE, proposition27_1);
271
272
273
274 PropositionParametersBuilder proposition28_1 = createProposition(
275 KSKRMSConstants.TERM_COMPLETED_COURSES, "5", "=");
276 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA28,
277 contextRepository.getContextByNameAndNamespace(
278 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
279 null, KSNAMESPACE, proposition28_1);
280
281
282 PropositionParametersBuilder proposition29_1 = createProposition(
283 KSKRMSConstants.TERM_NUMBER_OF_CREDITS, "5", "=");
284 PropositionParametersBuilder proposition29_2 = createProposition(
285 KSKRMSConstants.TERM_DEPT_NUMBER, "5", "=");
286 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA29,
287 contextRepository.getContextByNameAndNamespace(
288 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
289 null, KSNAMESPACE, proposition29_1, proposition29_2);
290
291
292 PropositionParametersBuilder proposition30_1 = createProposition(
293 KSKRMSConstants.TERM_COMPLETED_COURSES, "MATH111", "=");
294 PropositionParametersBuilder proposition30_2 = createProposition(
295 KSKRMSConstants.TERM_COMPLETED_COURSES, "MATH111", "=");
296 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA30,
297 contextRepository.getContextByNameAndNamespace(
298 KSKRMSConstants.CONTEXT_ANTI_REQUISITE, KSNAMESPACE),
299 null, KSNAMESPACE, proposition30_1, proposition30_2);
300
301
302
303 PropositionParametersBuilder proposition31_1 = createProposition(
304 KSKRMSConstants.TERM_COMPLETED_COURSES, "AASP111", "=");
305 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA31,
306 contextRepository.getContextByNameAndNamespace(
307 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
308 null, KSNAMESPACE, proposition31_1);
309
310 PropositionParametersBuilder proposition31_2 = createProposition(
311 KSKRMSConstants.TERM_COMPLETED_COURSE_NUMBER, "AASP111", "=");
312 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA31,
313 contextRepository.getContextByNameAndNamespace(
314 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
315 null, KSNAMESPACE, proposition31_2);
316
317 PropositionParametersBuilder proposition31_3 = createProposition(
318 KSKRMSConstants.TERM_COMPLETED_COURSE_CODE, "AASP111", "=");
319 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA31,
320 contextRepository.getContextByNameAndNamespace(
321 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
322 null, KSNAMESPACE, proposition31_3);
323
324 PropositionParametersBuilder proposition31_4 = createProposition(
325 KSKRMSConstants.TERM_COMPLETED_COURSE_SET, "AASP", "=");
326 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA31,
327 contextRepository.getContextByNameAndNamespace(
328 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
329 null, KSNAMESPACE, proposition31_4);
330
331 PropositionParametersBuilder proposition31_5 = createProposition(
332 KSKRMSConstants.TERM_COMPLETED_EFFECTIVE_DATE_FROM, "12/12/12", "=");
333 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA31,
334 contextRepository.getContextByNameAndNamespace(
335 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
336 null, KSNAMESPACE, proposition31_5);
337
338
339
340 PropositionParametersBuilder proposition32_1 = createProposition(
341 KSKRMSConstants.TERM_COMPLETED_COURSES, "AASP111", "=");
342 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA32,
343 contextRepository.getContextByNameAndNamespace(
344 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
345 null, KSNAMESPACE, proposition31_1);
346
347 PropositionParametersBuilder proposition32_2 = createProposition(
348 KSKRMSConstants.TERM_COMPLETED_COURSE_NUMBER, "AASP111", "=");
349 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA32,
350 contextRepository.getContextByNameAndNamespace(
351 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
352 null, KSNAMESPACE, proposition32_2);
353
354 PropositionParametersBuilder proposition32_3 = createProposition(
355 KSKRMSConstants.TERM_COMPLETED_COURSE_CODE, "AASP111", "=");
356 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA32,
357 contextRepository.getContextByNameAndNamespace(
358 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
359 null, KSNAMESPACE, proposition32_3);
360
361 PropositionParametersBuilder proposition32_4 = createProposition(
362 KSKRMSConstants.TERM_COMPLETED_COURSE_SET, "AASP", "=");
363 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA32,
364 contextRepository.getContextByNameAndNamespace(
365 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
366 null, KSNAMESPACE, proposition32_4);
367
368 PropositionParametersBuilder proposition32_5 = createProposition(
369 KSKRMSConstants.TERM_COMPLETED_EFFECTIVE_DATE_FROM, "12/12/12", "=");
370 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA32,
371 contextRepository.getContextByNameAndNamespace(
372 KSKRMSConstants.CONTEXT_CORE_REQUISITE, KSNAMESPACE),
373 null, KSNAMESPACE, proposition32_5);
374
375
376 PropositionParametersBuilder proposition33_1_1 = createProposition(
377 KSKRMSConstants.TERM_COMPLETED_COURSES, "MATH111", "=");
378 PropositionParametersBuilder proposition33_1_2 = createProposition(
379 KSKRMSConstants.TERM_COMPLETED_COURSES, "MATH112", "=");
380 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA33,
381 contextRepository.getContextByNameAndNamespace(
382 KSKRMSConstants.CONTEXT_ANTI_REQUISITE, KSNAMESPACE),
383 null, KSNAMESPACE, proposition25_1_1, proposition25_1_2);
384
385 PropositionParametersBuilder proposition33_2 = createProposition(
386 KSKRMSConstants.TERM_COMPLETED_COURSE_SET, "MATH", "=");
387 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA33,
388 contextRepository.getContextByNameAndNamespace(
389 KSKRMSConstants.CONTEXT_ANTI_REQUISITE, KSNAMESPACE),
390 null, KSNAMESPACE, proposition33_2);
391
392 PropositionParametersBuilder proposition33_3 = createProposition(
393 KSKRMSConstants.TERM_COMPLETED_COURSE_NUMBER, "112", "=");
394 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA33,
395 contextRepository.getContextByNameAndNamespace(
396 KSKRMSConstants.CONTEXT_ANTI_REQUISITE, KSNAMESPACE),
397 null, KSNAMESPACE, proposition33_3);
398
399 PropositionParametersBuilder proposition33_4 = createProposition(
400 KSKRMSConstants.TERM_COMPLETED_LEARNING_OBJ_DESCR, "Skill", "=");
401 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA33,
402 contextRepository.getContextByNameAndNamespace(
403 KSKRMSConstants.CONTEXT_ANTI_REQUISITE, KSNAMESPACE),
404 null, KSNAMESPACE, proposition33_4);
405
406 PropositionParametersBuilder proposition33_5 = createProposition(
407 KSKRMSConstants.TERM_COMPLETED_EFFECTIVE_DATE_FROM, "12/12/12", "=");
408 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA33,
409 contextRepository.getContextByNameAndNamespace(
410 KSKRMSConstants.CONTEXT_ANTI_REQUISITE, KSNAMESPACE),
411 null, KSNAMESPACE, proposition33_5);
412
413 PropositionParametersBuilder proposition33_6 = createProposition(
414 KSKRMSConstants.TERM_COMPLETED_COURSE_CODE, "MATH", "=");
415 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA33,
416 contextRepository.getContextByNameAndNamespace(
417 KSKRMSConstants.CONTEXT_ANTI_REQUISITE, KSNAMESPACE),
418 null, KSNAMESPACE, proposition33_6);
419
420
421
422 PropositionParametersBuilder proposition34_1 = createProposition(
423 KSKRMSConstants.TERM_SCORE, "5", "=");
424 PropositionParametersBuilder proposition34_2 = createProposition(
425 KSKRMSConstants.TERM_TEST, "3rd", "=");
426 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA34,
427 contextRepository.getContextByNameAndNamespace(
428 KSKRMSConstants.CONTEXT_ANTI_REQUISITE, KSNAMESPACE),
429 null, KSNAMESPACE, proposition34_1, proposition34_2);
430
431
432 PropositionParametersBuilder proposition35_1 = createProposition(
433 KSKRMSConstants.TERM_COMPLETED_COURSE_CODE, "MATH", "=");
434 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA35,
435 contextRepository.getContextByNameAndNamespace(
436 KSKRMSConstants.CONTEXT_COURSE_RESTRICTS, KSNAMESPACE),
437 null, KSNAMESPACE, proposition35_1);
438
439
440 PropositionParametersBuilder proposition36_1 = createProposition(
441 KSKRMSConstants.TERM_COMPLETED_COURSES, "MATH112", "=");
442 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA36,
443 contextRepository.getContextByNameAndNamespace(
444 KSKRMSConstants.CONTEXT_ANTI_REQUISITE, KSNAMESPACE),
445 null, KSNAMESPACE, proposition36_1);
446
447 PropositionParametersBuilder proposition36_2 = createProposition(
448 KSKRMSConstants.TERM_COMPLETED_COURSE_SET, "MATH", "=");
449 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA36,
450 contextRepository.getContextByNameAndNamespace(
451 KSKRMSConstants.CONTEXT_ANTI_REQUISITE, KSNAMESPACE),
452 null, KSNAMESPACE, proposition36_2);
453
454 PropositionParametersBuilder proposition36_3 = createProposition(
455 KSKRMSConstants.TERM_COMPLETED_COURSE_NUMBER, "112", "=");
456 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA36,
457 contextRepository.getContextByNameAndNamespace(
458 KSKRMSConstants.CONTEXT_ANTI_REQUISITE, KSNAMESPACE),
459 null, KSNAMESPACE, proposition36_3);
460
461 PropositionParametersBuilder proposition36_4 = createProposition(
462 KSKRMSConstants.TERM_COMPLETED_LEARNING_OBJ_DESCR, "Skill", "=");
463 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA36,
464 contextRepository.getContextByNameAndNamespace(
465 KSKRMSConstants.CONTEXT_ANTI_REQUISITE, KSNAMESPACE),
466 null, KSNAMESPACE, proposition36_4);
467
468 PropositionParametersBuilder proposition36_5 = createProposition(
469 KSKRMSConstants.TERM_COMPLETED_EFFECTIVE_DATE_FROM, "12/12/12", "=");
470 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA36,
471 contextRepository.getContextByNameAndNamespace(
472 KSKRMSConstants.CONTEXT_ANTI_REQUISITE, KSNAMESPACE),
473 null, KSNAMESPACE, proposition36_5);
474
475 PropositionParametersBuilder proposition36_6 = createProposition(
476 KSKRMSConstants.TERM_COMPLETED_COURSE_CODE, "MATH", "=");
477 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA36,
478 contextRepository.getContextByNameAndNamespace(
479 KSKRMSConstants.CONTEXT_ANTI_REQUISITE, KSNAMESPACE),
480 null, KSNAMESPACE, proposition36_6);
481
482
483 PropositionParametersBuilder proposition37_1 = createProposition(
484 KSKRMSConstants.TERM_NUMBER_OF_CREDITS, "5", "=");
485 createAgendaAndRuleAndPropositions(KSKRMSConstants.AGENDA37,
486 contextRepository.getContextByNameAndNamespace(
487 KSKRMSConstants.CONTEXT_COURSE_RESTRICTS, KSNAMESPACE),
488 null, KSNAMESPACE, proposition37_1);
489
490 }
491
492 private PropositionParametersBuilder createProposition(String termUsed,
493 String PropositionConstant, String Operator) {
494 Map<String, PropositionParameterType> propositionsMap;
495 propositionsMap = new HashMap<String, PropositionParameterType>();
496 propositionsMap.put(krmsTermLookup(termUsed).getId(),
497 PropositionParameterType.TERM);
498 propositionsMap.put(PropositionConstant,
499 PropositionParameterType.CONSTANT);
500 propositionsMap.put(Operator, PropositionParameterType.OPERATOR);
501 PropositionParametersBuilder proposition = buildKRMSProposition(propositionsMap);
502 return proposition;
503 }
504
505 private void createAgendaAndRuleAndPropositions(String agendaName,
506 ContextDefinition contextDefinition, String eventName,
507 String nameSpace, PropositionParametersBuilder... proposition) {
508
509 AgendaDefinition agendaDef = createKRMSAgendaDefinition(agendaName,
510 contextDefinition);
511
512
513 AgendaItemDefinition.Builder agendaItemBuilder1 = AgendaItemDefinition.Builder
514 .create(null, agendaDef.getId());
515
516
517 String ruleDefinitionID = createKRMSRuleDefinition(nameSpace,
518 agendaName + "::Rule1", contextDefinition, LogicalOperator.OR,
519 proposition).getId();
520
521 agendaItemBuilder1.setRuleId(ruleDefinitionID);
522
523
524 AgendaItemDefinition agendaItem1 = agendaBoService
525 .createAgendaItem(agendaItemBuilder1.build());
526 AgendaDefinition.Builder agendaDefBuilder1 = AgendaDefinition.Builder
527 .create(agendaDef);
528
529
530 agendaDefBuilder1.setFirstItemId(agendaItem1.getId());
531 agendaDef = agendaDefBuilder1.build();
532
533 agendaBoService.updateAgenda(agendaDef);
534
535 }
536
537 private AgendaDefinition createKRMSAgendaDefinition(String agendaName,
538 ContextDefinition contextDefinition) {
539 AgendaDefinition agendaDef = agendaBoService
540 .getAgendaByNameAndContextId(agendaName,
541 contextDefinition.getId());
542 if (krmsTypeDefinition == null) {
543 krmsTypeDefinition = getKSKRMSType(KSNAMESPACE);
544 }
545 if (agendaDef == null) {
546 agendaDef = AgendaDefinition.Builder.create(null, agendaName,
547 krmsTypeDefinition.getId(), contextDefinition.getId())
548 .build();
549 agendaDef = agendaBoService.createAgenda(agendaDef);
550
551 }
552 return agendaDef;
553 }
554
555 private PropositionParametersBuilder buildKRMSProposition(
556 Map<String, PropositionParameterType> propositionsMap) {
557 int orderOfEntries = 0;
558 PropositionParametersBuilder params1 = new PropositionParametersBuilder();
559 Set<Entry<String, PropositionParameterType>> allValues = propositionsMap
560 .entrySet();
561
562 for (Entry<String, PropositionParameterType> entry : allValues) {
563 System.out.println(entry.getKey() + " " + entry.getValue());
564 if (entry.getValue() == PropositionParameterType.TERM
565 && orderOfEntries == 0) {
566 params1.add(entry.getKey(), entry.getValue());
567 orderOfEntries = 1;
568 } else if (entry.getValue() == PropositionParameterType.CONSTANT
569 && orderOfEntries == 1) {
570 params1.add(entry.getKey(), entry.getValue());
571 orderOfEntries = 2;
572 } else if (entry.getValue() == PropositionParameterType.OPERATOR
573 && orderOfEntries == 2) {
574 params1.add(entry.getKey(), entry.getValue());
575 orderOfEntries = 3;
576 }
577 }
578 if (orderOfEntries == 1) {
579 for (Entry<String, PropositionParameterType> entry : allValues) {
580 System.out.println(entry.getKey() + " " + entry.getValue());
581 if (entry.getValue() == PropositionParameterType.CONSTANT
582 && orderOfEntries == 1) {
583 params1.add(entry.getKey(), entry.getValue());
584 orderOfEntries = 2;
585 } else if (entry.getValue() == PropositionParameterType.OPERATOR
586 && orderOfEntries == 2) {
587 params1.add(entry.getKey(), entry.getValue());
588 orderOfEntries = 3;
589 }
590 }
591 }
592 if (orderOfEntries == 2) {
593 for (Entry<String, PropositionParameterType> entry : allValues) {
594 System.out.println(entry.getKey() + " " + entry.getValue());
595 if (entry.getValue() == PropositionParameterType.OPERATOR
596 && orderOfEntries == 2) {
597 params1.add(entry.getKey(), entry.getValue());
598 orderOfEntries = 3;
599 }
600 }
601 }
602 return params1;
603 }
604
605 private PropositionDefinition.Builder createKRMSPropositionDefinition(
606 String propDescription, PropositionParametersBuilder params,
607 RuleDefinition parentRule) {
608
609 PropositionDefinition.Builder propositionDefBuilder1 = PropositionDefinition.Builder
610 .create(null, PropositionType.SIMPLE.getCode(),
611 parentRule.getId(), null
612
613
614 ,
615 Collections.<PropositionParameter.Builder> emptyList());
616 propositionDefBuilder1.setDescription(propDescription);
617
618
619 List<PropositionParameter.Builder> propositionParams1 = params.build();
620
621
622 for (PropositionParameter.Builder propositionParamBuilder : propositionParams1) {
623 propositionParamBuilder.setProposition(propositionDefBuilder1);
624 }
625
626 propositionDefBuilder1.setParameters(propositionParams1);
627
628 return propositionDefBuilder1;
629 }
630
631 private RuleDefinition createKRMSRuleDefinition(String nameSpace,
632 String ruleName, ContextDefinition contextDefinition,
633 LogicalOperator operator, PropositionParametersBuilder... pbs) {
634
635 RuleDefinition.Builder ruleDefBuilder = RuleDefinition.Builder.create(
636 null, ruleName, nameSpace, null, null);
637 ruleDefBuilder.setDescription(ruleName + "::Description");
638
639
640 RuleDefinition ruleDef = ruleBoService.getRuleByNameAndNamespace(
641 ruleName, KSNAMESPACE);
642
643 if (ruleDef == null) {
644 ruleDef = ruleBoService.createRule(ruleDefBuilder.build());
645 }
646
647
648 PropositionDefinition.Builder parentProposition = PropositionDefinition.Builder
649 .create(null, PropositionType.COMPOUND.getCode(),
650 ruleDef.getId(), null, null);
651 parentProposition
652 .setCompoundComponents(new ArrayList<PropositionDefinition.Builder>());
653
654 if (operator != null) {
655 parentProposition.setCompoundOpCode(operator.getCode());
656 }
657
658 ruleDefBuilder = RuleDefinition.Builder.create(ruleDef);
659
660
661 ArrayList<PropositionDefinition.Builder> newComponentList = new ArrayList<PropositionDefinition.Builder>();
662 for (PropositionParametersBuilder params : pbs) {
663
664 StringBuilder propositionNameBuilder = new StringBuilder(
665 "Proposition");
666
667 propositionNameBuilder.append("::");
668 for (Object[] param : params.params) {
669 propositionNameBuilder.append(param[0].toString());
670 propositionNameBuilder.append("--");
671 }
672
673 PropositionDefinition.Builder propositionBuilder = createKRMSPropositionDefinition(
674 propositionNameBuilder.toString(), params, ruleDef);
675
676 if (pbs.length > 1) {
677
678
679
680
681 newComponentList.add(propositionBuilder);
682 } else {
683
684 parentProposition = propositionBuilder;
685 }
686
687 }
688 if (newComponentList.size() > 0) {
689 parentProposition.setCompoundComponents(newComponentList);
690
691 }
692 ruleDefBuilder.setProposition(parentProposition);
693 ruleDef = ruleDefBuilder.build();
694 ruleBoService.updateRule(ruleDef);
695
696
697
698
699
700
701
702
703
704
705 return ruleDef;
706 }
707
708 public TermDefinition krmsTermLookup(String termName) {
709
710 Map<String, String> queryArgs = new HashMap<String, String>();
711 queryArgs.put("desc_txt", termName);
712 TermBo termBo = getBoService()
713 .findByPrimaryKey(TermBo.class, queryArgs);
714 if (termBo != null) {
715 return TermBo.to(termBo);
716 }
717 return null;
718 }
719
720 private static class PropositionParametersBuilder {
721
722
723 private List<Object[]> params = new ArrayList<Object[]>();
724
725 public PropositionParametersBuilder add(String value,
726 PropositionParameterType type) {
727 if (type == null)
728 throw new IllegalArgumentException("type must not be null");
729 params.add(new Object[] { value, type });
730 return this;
731 }
732
733 public List<PropositionParameter.Builder> build() {
734 int seqCounter = 0;
735
736 List<PropositionParameter.Builder> results = new ArrayList<PropositionParameter.Builder>();
737
738 for (Object[] param : params) {
739 results.add(PropositionParameter.Builder.create(null, null,
740 (String) param[0],
741 ((PropositionParameterType) param[1]).getCode(),
742 seqCounter++));
743 }
744
745 return results;
746 }
747 }
748
749
750 private KrmsTypeDefinition getKSKRMSType(String nameSpace) {
751 KrmsTypeDefinition krmsContextTypeDefinition = krmsTypeRepository
752 .getTypeByName(nameSpace, KSKRMSConstants.KS_AGENDA_TYPE);
753
754 if (krmsContextTypeDefinition == null) {
755
756 KrmsTypeDefinition.Builder krmsContextTypeDefnBuilder = KrmsTypeDefinition.Builder
757 .create(KSKRMSConstants.KS_AGENDA_TYPE, nameSpace);
758 krmsContextTypeDefnBuilder.setServiceName("myKSService");
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775 krmsContextTypeDefinition = krmsTypeRepository
776 .createKrmsType(krmsContextTypeDefnBuilder.build());
777 return krmsContextTypeDefinition;
778 }
779
780 return krmsContextTypeDefinition;
781 }
782
783 protected BusinessObjectService getBoService() {
784 return KRADServiceLocator.getBusinessObjectService();
785 }
786 }