001package org.kuali.rice.krms.util; 002 003import org.kuali.rice.krad.util.ObjectUtils; 004import org.kuali.rice.krad.web.form.MaintenanceDocumentForm; 005import org.kuali.rice.krad.web.form.UifFormBase; 006import org.kuali.rice.krms.dto.AgendaEditor; 007import org.kuali.rice.krms.dto.RuleEditor; 008import org.kuali.rice.krms.dto.RuleManagementWrapper; 009import org.kuali.rice.krms.impl.repository.AgendaItemBo; 010 011import java.util.List; 012 013/** 014 * Created with IntelliJ IDEA. 015 * User: SW 016 * Date: 2013/04/05 017 * Time: 3:17 PM 018 * To change this template use File | Settings | File Templates. 019 */ 020public class AgendaUtilities { 021 022 public static RuleEditor retrieveSelectedRuleEditor(UifFormBase form) { 023 024 MaintenanceDocumentForm document = (MaintenanceDocumentForm) form; 025 RuleManagementWrapper ruleWrapper = (RuleManagementWrapper) document.getDocument().getNewMaintainableObject().getDataObject(); 026 String ruleKey = document.getActionParamaterValue("ruleKey"); 027 028 RuleEditor ruleEditor = getSelectedRuleEditor(ruleWrapper, ruleKey); 029 030 if(ruleEditor != null){ 031 ruleWrapper.setRuleEditor((RuleEditor) ObjectUtils.deepCopy(ruleEditor)); 032 }else { 033 ruleWrapper.setRuleEditor(new RuleEditor()); 034 } 035 ruleWrapper.setSelectedRuleId(ruleWrapper.getRuleEditor().getId()); 036 037 return ruleWrapper.getRuleEditor(); 038 } 039 040 public static RuleEditor getSelectedRuleEditor(RuleManagementWrapper wrapper, String ruleKey) { 041 042 for (AgendaEditor agendaEditor : wrapper.getAgendas()) { 043 for (RuleEditor ruleEditor : agendaEditor.getRuleEditors()) { 044 if ((ruleEditor.getKey() != null) && (ruleEditor.getKey().equals(ruleKey))) { 045 return ruleEditor; 046 } 047 } 048 } 049 050 return null; 051 } 052 053 public static RuleEditor getSelectedRuleEditorByType(List<RuleEditor> ruleEditors, String ruleTypeId) { 054 055 for (RuleEditor ruleEditor : ruleEditors) { 056 if ((ruleEditor.getTypeId().equals(ruleTypeId))) { 057 return ruleEditor; 058 } 059 } 060 061 return null; 062 } 063}