View Javadoc
1   /**
2    * Copyright 2005-2014 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.impl.repository;
17  
18  import org.kuali.rice.core.api.uif.RemotableAttributeField;
19  import org.kuali.rice.kns.inquiry.KualiInquirableImpl;
20  import org.kuali.rice.krad.data.DataObjectService;
21  import org.kuali.rice.krad.service.KRADServiceLocator;
22  import org.kuali.rice.krad.uif.container.Container;
23  import org.kuali.rice.krad.uif.view.View;
24  import org.kuali.rice.krad.web.form.InquiryForm;
25  import org.kuali.rice.krms.impl.ui.AgendaEditor;
26  import org.kuali.rice.krms.impl.util.KrmsRetriever;
27  
28  import java.util.Collections;
29  import java.util.List;
30  import java.util.Map;
31  
32  /**
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  public class AgendaInquiryHelperServiceImpl extends KualiInquirableImpl {
36  
37      private transient KrmsRetriever krmsRetriever = new KrmsRetriever();
38  
39      private DataObjectService dataObjectService;
40  
41      @Override
42      public AgendaEditor retrieveDataObject(Map fieldValues) {
43          AgendaEditor agendaEditor = null;
44  
45          AgendaBo agenda = getDataObjectService().find(AgendaBo.class, fieldValues.get("id"));
46          if (agenda != null) {
47              agendaEditor = new AgendaEditor();
48              agendaEditor.setAgenda(agenda);
49              agendaEditor.setNamespace(agenda.getContext().getNamespace());
50              agendaEditor.setContextName(agenda.getContext().getName());
51              agendaEditor.setCustomAttributesMap(agenda.getAttributes());
52          }
53  
54          return agendaEditor;
55      }
56  
57      /**
58       * Returns the AgendaEditor from the given InquiryForm
59       *
60       * @param model InquiryFrom to retrieve the AgendaEditor from.
61       * @return AgendaEditor retrieved from the given InquiryForm.
62       */
63      private AgendaEditor retrieveAgendaEditor(InquiryForm model) {
64          InquiryForm inquiryForm = (InquiryForm) model;
65          return (AgendaEditor) inquiryForm.getDataObject();
66      }
67  
68      /**
69       * Returns the Agenda's RemotableAttributeFields
70       *
71       * @param view
72       * @param model InquiryFrom to retrieve the AgendaEditor from.
73       * @param container
74       * @return List<RemotableAttributeField>
75       */
76      public List<RemotableAttributeField> retrieveAgendaCustomAttributes(View view, Object model, Container container) {
77          AgendaEditor agendaEditor = retrieveAgendaEditor((InquiryForm) model);
78          return krmsRetriever.retrieveAgendaCustomAttributes(agendaEditor);
79      }
80  
81      /**
82       * Returns the Rule Action RemotableAttributeFields. This only supports a single action within a rule.
83       *
84       * @param view
85       * @param model InquiryFrom to retrieve the AgendaEditor from.
86       * @param container
87       * @return List<RemotableAttributeField>
88       */
89      public List<RemotableAttributeField> retrieveRuleActionCustomAttributes(View view, Object model,
90              Container container) {
91          AgendaEditor agendaEditor = retrieveAgendaEditor((InquiryForm) model);
92          return krmsRetriever.retrieveRuleActionCustomAttributes(agendaEditor);
93      }
94  
95      /**
96       * Returns the Rule RemotableAttributeFields. This only supports a single action within a rule.
97       *
98       * @param view
99       * @param model InquiryFrom to retrieve the AgendaEditor from.
100      * @param container
101      * @return List<RemotableAttributeField>
102      */
103     public List<RemotableAttributeField> retrieveRuleCustomAttributes(View view, Object model, Container container) {
104         AgendaEditor agendaEditor = retrieveAgendaEditor((InquiryForm) model);
105         return krmsRetriever.retrieveRuleCustomAttributes(agendaEditor);
106     }
107 
108     /**
109      * Retrieve a list of {@link RemotableAttributeField}s for the parameters (if any) required by the resolver for
110      * the selected term in the proposition that is under edit.  Since this method is part of the inquiry view,
111      * non of the propositions will ever be under edit when it is called, and an empty list will be returned.
112      *
113      * @param view
114      * @param model InquiryFrom to retrieve the AgendaEditor from.
115      * @param container
116      * @return List<RemotableAttributeField> Collections.emptyList()
117      */
118     public List<RemotableAttributeField> retrieveTermParameters(View view, Object model, Container container) {
119         return Collections.emptyList();
120     }
121 
122     public DataObjectService getDataObjectService() {
123         if (dataObjectService == null) {
124             return KRADServiceLocator.getDataObjectService();
125         }
126         return dataObjectService;
127     }
128 
129     public void setDataObjectService(DataObjectService dataObjectService) {
130         this.dataObjectService = dataObjectService;
131     }
132 
133 }