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