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.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.kns.service.KNSServiceLocator;
21  import org.kuali.rice.krad.service.BusinessObjectService;
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 AgendaStudentInquiryHelperServiceImpl extends KualiInquirableImpl {
36  
37      private transient KrmsRetriever krmsRetriever = new KrmsRetriever();
38  
39      private BusinessObjectService businessObjectService;
40  
41      @Override
42      public AgendaEditor retrieveDataObject(Map fieldValues) {
43          AgendaEditor agendaEditor = null;
44  
45          String agendaId = (String) fieldValues.get("id");
46          AgendaBo agenda = getBusinessObjectService().findBySinglePrimaryKey(AgendaBo.class, agendaId);
47          if (agenda != null) {
48              agendaEditor = new AgendaEditor();
49              agendaEditor.setAgenda(agenda);
50              agendaEditor.setNamespace(agenda.getContext().getNamespace());
51              agendaEditor.setContextName(agenda.getContext().getName());
52              agendaEditor.setCustomAttributesMap(agenda.getAttributes());
53          }
54  
55          return agendaEditor;
56      }
57  
58      /**
59       * Returns the AgendaEditor from the given InquiryForm
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       * @param view
71       * @param model InquiryFrom to retrieve the AgendaEditor from.
72       * @param container
73       * @return List<RemotableAttributeField>
74       */
75      public List<RemotableAttributeField> retrieveAgendaCustomAttributes(View view, Object model, Container container) {
76          AgendaEditor agendaEditor = retrieveAgendaEditor((InquiryForm) model);
77          return krmsRetriever.retrieveAgendaCustomAttributes(agendaEditor);
78      }
79  
80      /**
81       * Returns the Rule Action RemotableAttributeFields. This only supports a single action within a rule.
82       * @param view
83       * @param model InquiryFrom to retrieve the AgendaEditor from.
84       * @param container
85       * @return List<RemotableAttributeField>
86       */
87      public List<RemotableAttributeField> retrieveRuleActionCustomAttributes(View view, Object model, Container container) {
88          AgendaEditor agendaEditor = retrieveAgendaEditor((InquiryForm)model);
89          return krmsRetriever.retrieveRuleActionCustomAttributes(agendaEditor);
90      }
91  
92      /**
93       * Returns the Rule RemotableAttributeFields. This only supports a single action within a rule.
94       * @param view
95       * @param model InquiryFrom to retrieve the AgendaEditor from.
96       * @param container
97       * @return List<RemotableAttributeField>
98       */
99      public List<RemotableAttributeField> retrieveRuleCustomAttributes(View view, Object model, Container container) {
100         AgendaEditor agendaEditor = retrieveAgendaEditor((InquiryForm)model);
101         return krmsRetriever.retrieveRuleCustomAttributes(agendaEditor);
102     }
103 
104 
105     /**
106      * Retrieve a list of {@link org.kuali.rice.core.api.uif.RemotableAttributeField}s for the parameters (if any) required by the resolver for
107      * the selected term in the proposition that is under edit.  Since this method is part of the inquiry view,
108      * non of the propositions will ever be under edit when it is called, and an empty list will be returned.
109      * @param view
110      * @param model InquiryFrom to retrieve the AgendaEditor from.
111      * @param container
112      * @return List<RemotableAttributeField> Collections.emptyList()
113      */
114     public List<RemotableAttributeField> retrieveTermParameters(View view, Object model, Container container) {
115         return Collections.emptyList();
116     }
117 
118     public BusinessObjectService getBusinessObjectService() {
119         if(businessObjectService == null){
120             return KNSServiceLocator.getBusinessObjectService();
121         }
122         return businessObjectService;
123     }
124 
125     public void setBusinessObjectService(BusinessObjectService businessObjectService) {
126         this.businessObjectService = businessObjectService;
127     }
128 }