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.RuleManagementService;
24 import org.kuali.rice.krms.api.repository.language.NaturalLanguageUsage;
25
26
27
28
29
30 public class KrmsNaturalLanguageUsageLoader {
31
32 private RuleManagementService ruleManagementService = null;
33
34 public RuleManagementService getRuleManagementService() {
35 return ruleManagementService;
36 }
37
38 public void setRuleManagementService(RuleManagementService ruleManagementService) {
39 this.ruleManagementService = ruleManagementService;
40 }
41
42 public void loadNlUsage(String id, String name, String nameSpace, String description) {
43 NaturalLanguageUsage.Builder bldr = NaturalLanguageUsage.Builder.create(name, nameSpace);
44 bldr.setId(id);
45 bldr.setActive(true);
46 bldr.setDescription(description);
47 NaturalLanguageUsage existing = this.findExisting(bldr);
48 if (existing == null) {
49 this.getRuleManagementService().createNaturalLanguageUsage(bldr.build());
50 } else {
51 bldr.setVersionNumber(existing.getVersionNumber());
52 this.getRuleManagementService().updateNaturalLanguageUsage(bldr.build());
53 }
54 }
55
56 private NaturalLanguageUsage findExisting(NaturalLanguageUsage.Builder bldr) {
57 if (bldr.getId() != null) {
58 try {
59 return this.getRuleManagementService().getNaturalLanguageUsage(bldr.getId());
60 } catch (RiceIllegalArgumentException ex) {
61 return null;
62 }
63 }
64 return this.getRuleManagementService().getNaturalLanguageUsageByNameAndNamespace(bldr.getName(), bldr.getNamespace());
65 }
66
67 public void load() {
68 loadNlUsage("KS-KRMS-NL-USAGE-1000", "kuali.krms.edit", "KS-SYS", "Kuali Rule Edit");
69 loadNlUsage("KS-KRMS-NL-USAGE-1001", "kuali.krms.composition", "KS-SYS", "Kuali Rule Composition");
70 loadNlUsage("KS-KRMS-NL-USAGE-1002", "kuali.krms.example", "KS-SYS", "Kuali Rule Example");
71 loadNlUsage("KS-KRMS-NL-USAGE-1003", "kuali.krms.preview", "KS-SYS", "Kuali Rule Preview");
72 loadNlUsage("KS-KRMS-NL-USAGE-1004", "kuali.krms.type.description", "KS-SYS", "Kuali Rule Type Description");
73 loadNlUsage("KS-KRMS-NL-USAGE-1005", "kuali.krms.catalog", "KS-SYS", "Kuali Rule Catalog");
74 loadNlUsage("KS-KRMS-NL-USAGE-1006", "kuali.krms.type.instruction", "KS-SYS", "Kuali Rule Type Instructions");
75 }
76 }