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.HashMap;
30  import java.util.List;
31  import java.util.Map;
32  
33  /**
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  public class AgendaInquiryHelperServiceImpl extends KualiInquirableImpl {
37  
38      private transient KrmsRetriever krmsRetriever = new KrmsRetriever();
39  
40      private BusinessObjectService businessObjectService;
41  
42      @Override
43      public AgendaEditor retrieveDataObject(Map fieldValues) {
44          AgendaEditor agendaEditor = null;
45  
46          Map<String, Object> primaryKeys = new HashMap<String, Object>();
47          primaryKeys.put("id", fieldValues.get("id"));
48  //        String agendaId = (String) fieldValues.get("id");
49          AgendaBo agenda = getBusinessObjectService().findByPrimaryKey(AgendaBo.class, primaryKeys);
50          if (agenda != null) {
51              agendaEditor = new AgendaEditor();
52              agendaEditor.setAgenda(agenda);
53              agendaEditor.setNamespace(agenda.getContext().getNamespace());
54              agendaEditor.setContextName(agenda.getContext().getName());
55              agendaEditor.setCustomAttributesMap(agenda.getAttributes());
56          }
57  
58          return agendaEditor;
59      }
60  
61      /**
62       * Returns the AgendaEditor from the given InquiryForm
63       * @param model InquiryFrom to retrieve the AgendaEditor from.
64       * @return AgendaEditor retrieved from the given InquiryForm.
65       */
66      private AgendaEditor retrieveAgendaEditor(InquiryForm model) {
67          InquiryForm inquiryForm = (InquiryForm)model;
68          return (AgendaEditor)inquiryForm.getDataObject();
69      }
70  
71      /**
72       * Returns the Agenda's RemotableAttributeFields
73       * @param view
74       * @param model InquiryFrom to retrieve the AgendaEditor from.
75       * @param container
76       * @return List<RemotableAttributeField>
77       */
78      public List<RemotableAttributeField> retrieveAgendaCustomAttributes(View view, Object model, Container container) {
79          AgendaEditor agendaEditor = retrieveAgendaEditor((InquiryForm) model);
80          return krmsRetriever.retrieveAgendaCustomAttributes(agendaEditor);
81      }
82  
83      /**
84       * Returns the Rule Action RemotableAttributeFields. This only supports a single action within a rule.
85       * @param view
86       * @param model InquiryFrom to retrieve the AgendaEditor from.
87       * @param container
88       * @return List<RemotableAttributeField>
89       */
90      public List<RemotableAttributeField> retrieveRuleActionCustomAttributes(View view, Object model, 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       * @param view
98       * @param model InquiryFrom to retrieve the AgendaEditor from.
99       * @param container
100      * @return List<RemotableAttributeField>
101      */
102     public List<RemotableAttributeField> retrieveRuleCustomAttributes(View view, Object model, Container container) {
103         AgendaEditor agendaEditor = retrieveAgendaEditor((InquiryForm)model);
104         return krmsRetriever.retrieveRuleCustomAttributes(agendaEditor);
105     }
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      * @param view
113      * @param model InquiryFrom to retrieve the AgendaEditor from.
114      * @param container
115      * @return List<RemotableAttributeField> Collections.emptyList()
116      */
117     public List<RemotableAttributeField> retrieveTermParameters(View view, Object model, Container container) {
118         return Collections.emptyList();
119     }
120 
121 
122     public BusinessObjectService getBusinessObjectService() {
123         if(businessObjectService == null){
124             return KNSServiceLocator.getBusinessObjectService();
125         }
126         return businessObjectService;
127     }
128 
129     public void setBusinessObjectService(BusinessObjectService businessObjectService) {
130         this.businessObjectService = businessObjectService;
131     }
132 
133 }