View Javadoc
1   /**
2    * Copyright 2005-2013 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  package org.kuali.rice.krms.util;
17  
18  import org.kuali.rice.krad.util.ObjectUtils;
19  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
20  import org.kuali.rice.krms.dto.AgendaEditor;
21  import org.kuali.rice.krms.dto.RuleEditor;
22  import org.kuali.rice.krms.dto.RuleManagementWrapper;
23  import org.kuali.rice.krms.dto.RuleManager;
24  
25  /**
26   * @author Kuali Student Team
27   */
28  public class AgendaUtilities {
29  
30      public static RuleEditor retrieveSelectedRuleEditor(MaintenanceDocumentForm document) {
31  
32          RuleManager ruleWrapper = getRuleWrapper(document);
33          RuleEditor ruleEditor = getSelectedRuleEditor(ruleWrapper, getRuleKey(document));
34          ruleWrapper.setRuleEditor((RuleEditor) ObjectUtils.deepCopy(ruleEditor));
35  
36          return ruleWrapper.getRuleEditor();
37      }
38  
39      public static RuleEditor getSelectedRuleEditor(MaintenanceDocumentForm document) {
40          return AgendaUtilities.getSelectedRuleEditor(getRuleWrapper(document), getRuleKey(document));
41      }
42  
43      public static RuleEditor getSelectedRuleEditor(RuleManager wrapper, String ruleKey) {
44  
45          AgendaEditor agendaEditor = getSelectedAgendaEditor(wrapper, ruleKey);
46          if (agendaEditor != null) {
47              return agendaEditor.getRuleEditors().get(ruleKey);
48          }
49  
50          return null;
51      }
52  
53      public static AgendaEditor getSelectedAgendaEditor(MaintenanceDocumentForm document) {
54          return AgendaUtilities.getSelectedAgendaEditor(getRuleWrapper(document), getRuleKey(document));
55      }
56  
57      public static AgendaEditor getSelectedAgendaEditor(RuleManager wrapper, String ruleKey) {
58  
59          for (AgendaEditor agendaEditor : wrapper.getAgendas()) {
60              if (agendaEditor.getRuleEditors().containsKey(ruleKey)) {
61                  return agendaEditor;
62              }
63          }
64  
65          return null;
66      }
67  
68      public static String getRuleKey(MaintenanceDocumentForm document) {
69          return document.getActionParamaterValue("ruleKey");
70      }
71  
72      public static RuleManager getRuleWrapper(MaintenanceDocumentForm document) {
73          return (RuleManager) document.getDocument().getNewMaintainableObject().getDataObject();
74      }
75  
76  }