View Javadoc

1   package org.kuali.rice.krms.keyvalues;
2   
3   import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
4   import org.kuali.rice.krms.api.KrmsConstants;
5   import org.kuali.rice.krms.api.repository.RuleManagementService;
6   import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplate;
7   import org.kuali.rice.krms.api.repository.language.NaturalLanguageUsage;
8   import org.kuali.rice.krms.api.repository.type.KrmsTypeRepositoryService;
9   import org.kuali.rice.krms.api.repository.typerelation.TypeTypeRelation;
10  import org.kuali.rice.krms.impl.repository.KrmsRepositoryServiceLocator;
11  import org.kuali.rice.krms.impl.repository.NaturalLanguageTemplateBoService;
12  import org.kuali.rice.krms.impl.repository.NaturalLanguageUsageBoService;
13  import org.kuali.rice.krms.impl.repository.TypeTypeRelationBoService;
14  import org.kuali.student.enrollment.class2.courseoffering.service.decorators.PermissionServiceConstants;
15  import org.kuali.student.krms.naturallanguage.util.KsKrmsConstants;
16  
17  import javax.xml.namespace.QName;
18  import java.io.Serializable;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  import java.util.Set;
23  
24  public class RuleInstructionKeyValues implements Serializable {
25  
26      private static final long serialVersionUID = 1L;
27  
28      private transient RuleManagementService ruleManagementService;
29  
30  
31      public Map<String, String> getKeyValues(Set<String> ruleTypeIds) {
32          Map<String, String> keyValuesInstruction = new HashMap<String, String>();
33          NaturalLanguageUsage usageInstruction = getRuleManagementService().getNaturalLanguageUsageByNameAndNamespace(PermissionServiceConstants.KS_SYS_NAMESPACE, KsKrmsConstants.KRMS_NL_TYPE_INSTRUCTION);
34           //Use Type Type Relation to get Rule Types
35          try {
36              for(String ruleTypeId : ruleTypeIds) {
37                  NaturalLanguageTemplate templateInstruction = null;
38                  try{
39                      templateInstruction = getRuleManagementService().findNaturalLanguageTemplateByLanguageCodeTypeIdAndNluId("en", ruleTypeId, usageInstruction.getId());
40                  }catch (IndexOutOfBoundsException e){
41                      //Ignore, rice error in NaturalLanguageTemplateBoServiceImpl line l
42                  }
43  
44                  if (templateInstruction != null) {
45                      keyValuesInstruction.put(ruleTypeId, templateInstruction.getTemplate());
46                  } else {
47                      keyValuesInstruction.put(ruleTypeId, KsKrmsConstants.KRMS_NL_TYPE_INSTRUCTION);
48                  }
49              };
50          } catch (Exception ex) {}
51          return keyValuesInstruction;
52      }
53  
54      public RuleManagementService getRuleManagementService() {
55          if (ruleManagementService == null) {
56              ruleManagementService = (RuleManagementService) GlobalResourceLoader.getService(new QName(KrmsConstants.Namespaces.KRMS_NAMESPACE_2_0, "ruleManagementService"));
57          }
58          return ruleManagementService;
59      }
60  }