View Javadoc

1   package org.kuali.rice.krms.util;
2   
3   import org.kuali.rice.krad.util.ObjectUtils;
4   import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
5   import org.kuali.rice.krad.web.form.UifFormBase;
6   import org.kuali.rice.krms.dto.AgendaEditor;
7   import org.kuali.rice.krms.dto.RuleEditor;
8   import org.kuali.rice.krms.dto.RuleManagementWrapper;
9   import org.kuali.rice.krms.impl.repository.AgendaItemBo;
10  
11  import java.util.List;
12  
13  /**
14   * Created with IntelliJ IDEA.
15   * User: SW
16   * Date: 2013/04/05
17   * Time: 3:17 PM
18   * To change this template use File | Settings | File Templates.
19   */
20  public class AgendaUtilities {
21  
22      public static RuleEditor retrieveSelectedRuleEditor(UifFormBase form) {
23  
24          MaintenanceDocumentForm document = (MaintenanceDocumentForm) form;
25          RuleManagementWrapper ruleWrapper = (RuleManagementWrapper) document.getDocument().getNewMaintainableObject().getDataObject();
26          String ruleKey = document.getActionParamaterValue("ruleKey");
27  
28          RuleEditor ruleEditor = getSelectedRuleEditor(ruleWrapper, ruleKey);
29  
30          if(ruleEditor != null){
31              ruleWrapper.setRuleEditor((RuleEditor) ObjectUtils.deepCopy(ruleEditor));
32          }else {
33              ruleWrapper.setRuleEditor(new RuleEditor());
34          }
35          ruleWrapper.setSelectedRuleId(ruleWrapper.getRuleEditor().getId());
36  
37          return ruleWrapper.getRuleEditor();
38      }
39  
40      public static RuleEditor getSelectedRuleEditor(RuleManagementWrapper wrapper, String ruleKey) {
41  
42          for (AgendaEditor agendaEditor : wrapper.getAgendas()) {
43              for (RuleEditor ruleEditor : agendaEditor.getRuleEditors()) {
44                  if ((ruleEditor.getKey() != null) && (ruleEditor.getKey().equals(ruleKey))) {
45                      return ruleEditor;
46                  }
47              }
48          }
49  
50          return null;
51      }
52  
53      public static RuleEditor getSelectedRuleEditorByType(List<RuleEditor> ruleEditors, String ruleTypeId) {
54  
55          for (RuleEditor ruleEditor : ruleEditors) {
56              if ((ruleEditor.getTypeId().equals(ruleTypeId))) {
57                  return ruleEditor;
58              }
59          }
60  
61          return null;
62      }
63  }