View Javadoc

1   /**
2    * Copyright 2005-2014 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.RuleManagementService;
24  import org.kuali.rice.krms.api.repository.language.NaturalLanguageUsage;
25  
26  /**
27   *
28   * @author nwright
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  }