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.kns.lookup;
17  
18  import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions;
19  import org.kuali.rice.kns.web.struts.form.LookupForm;
20  import org.kuali.rice.kns.web.ui.Column;
21  import org.kuali.rice.kns.web.ui.Field;
22  import org.kuali.rice.kns.web.ui.ResultRow;
23  import org.kuali.rice.kns.web.ui.Row;
24  import org.kuali.rice.krad.bo.BusinessObject;
25  import org.kuali.rice.kns.service.BusinessObjectDictionaryService;
26  import org.kuali.rice.krad.service.DataDictionaryService;
27  import org.kuali.rice.krad.util.KRADConstants;
28  import org.kuali.rice.krad.util.UrlFactory;
29  import org.springframework.transaction.annotation.Transactional;
30  
31  import java.util.Collection;
32  import java.util.List;
33  import java.util.Map;
34  import java.util.Properties;
35  
36  /**
37   * Kuali lookup implementation. Implements methods necessary to render the lookup and provides search and return methods.
38   */
39  @Transactional
40  public class KualiLookupableImpl implements Lookupable {
41      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KualiLookupableImpl.class);
42      protected static final String[] IGNORE_LIST = { KRADConstants.DOC_FORM_KEY, KRADConstants.BACK_LOCATION };
43  
44      protected Class businessObjectClass;
45      protected LookupableHelperService lookupableHelperService;
46      protected String extraOnLoad = ""; // This is supposed to be a javascript function.
47  
48      /**
49       * Default constructor initializes services from spring
50       */
51      public KualiLookupableImpl() {
52      }
53  
54      /**
55       * Sets the business object class for the lookup instance, then rows can be set for search render.
56       *
57       * @param boClass Class for the lookup business object
58       */
59      public void setBusinessObjectClass(Class boClass) {
60          if (boClass == null) {
61              throw new RuntimeException("Business object class is null.");
62          }
63  
64          this.businessObjectClass = boClass;
65  
66          // next line initializes the helper to return correct values for getRow();
67          getLookupableHelperService().setBusinessObjectClass(boClass);
68      }
69  
70      /**
71       * Initializes the lookup with the given Map of parameters.
72       *
73       * @param parameters
74       */
75      public void setParameters(Map<String, String[]> parameters) {
76          getLookupableHelperService().setParameters(parameters);
77      }
78  
79      /**
80       * @return Returns the parameters passed to this lookup
81       */
82      public Map<String, String[]> getParameters() {
83          return getLookupableHelperService().getParameters();
84      }
85  
86      /**
87       * Constructs the list of columns for the search results. All properties for the column objects come from the DataDictionary.
88       */
89      public List<Column> getColumns() {
90          return getLookupableHelperService().getColumns();
91      }
92  
93      /**
94       * Checks that any required search fields have value.
95       *
96       * @see Lookupable#validateSearchParameters(java.util.Map)
97       */
98      public void validateSearchParameters(Map<String, String> fieldValues) {
99          getLookupableHelperService().validateSearchParameters(fieldValues);
100     }
101 
102     /**
103      * Uses Lookup Service to provide a basic unbounded search.
104      *
105      * @param fieldValues - Map containing prop name keys and search values
106      *
107      * @return List found business objects
108      */
109     public List<? extends BusinessObject> getSearchResultsUnbounded(Map<String, String> fieldValues) {
110         return getLookupableHelperService().getSearchResultsUnbounded(fieldValues);
111     }
112 
113     /**
114      * Uses Lookup Service to provide a basic search.
115      *
116      * @param fieldValues - Map containing prop name keys and search values
117      *
118      * @return List found business objects
119      */
120     public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
121         return getLookupableHelperService().getSearchResults(fieldValues);
122     }
123 
124     /**
125      * @return the return url for each result row.
126      */
127     public HtmlData getReturnUrl(BusinessObject bo, Map fieldConversions, String lookupImpl, BusinessObjectRestrictions businessObjectRestrictions) {
128         return getLookupableHelperService().getReturnUrl(bo, fieldConversions, lookupImpl, getReturnKeys(), businessObjectRestrictions);
129     }
130 
131     /**
132      * @see Lookupable#getCreateNewUrl()
133      */
134     public String getCreateNewUrl() {
135         String url = "";
136 
137         if (getLookupableHelperService().allowsMaintenanceNewOrCopyAction()) {
138             Properties parameters = new Properties();
139             parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
140             parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, this.businessObjectClass.getName());
141 
142             url = UrlFactory.parameterizeUrl(KRADConstants.MAINTENANCE_ACTION, parameters);
143             url = "<a title=\"Create a new record\" href=\"" + url + "\"><img src=\"images/tinybutton-createnew.gif\" alt=\"create new\" width=\"70\" height=\"15\"/></a>";
144         }
145 
146         return url;
147     }
148 
149 
150     /**
151      * @see Lookupable#getHtmlMenuBar()
152      */
153     public String getHtmlMenuBar() {
154         return getBusinessObjectDictionaryService().getLookupMenuBar(getBusinessObjectClass());
155     }
156 
157     /**
158      * @see Lookupable#getSupplementalMenuBar()
159      */
160     public String getSupplementalMenuBar() {
161         return getLookupableHelperService().getSupplementalMenuBar();
162     }
163 
164     /**
165      * @see Lookupable#getRows()
166      */
167     public List<Row> getRows() {
168         return getLookupableHelperService().getRows();
169     }
170 
171     /**
172      * @see Lookupable#getTitle()
173      */
174     public String getTitle() {
175         return getLookupableHelperService().getTitle();
176     }
177 
178     /**
179      * @see Lookupable#getReturnLocation()
180      */
181     public String getReturnLocation() {
182         return getLookupableHelperService().getReturnLocation();
183     }
184 
185     /**
186      * @return Returns the dataObjectClass.
187      */
188     public Class getBusinessObjectClass() {
189         return businessObjectClass;
190     }
191 
192     /**
193      * @return a List of the names of fields which are marked in data dictionary as return fields.
194      */
195     public List<String> getReturnKeys() {
196         return getLookupableHelperService().getReturnKeys();
197     }
198 
199 
200     /**
201      * @see Lookupable#getExtraButtonSource()
202      */
203     public String getExtraButtonSource() {
204         return getBusinessObjectDictionaryService().getExtraButtonSource(getBusinessObjectClass());
205     }
206 
207     /**
208      * @see Lookupable#getExtraButtonParams()
209      */
210     public String getExtraButtonParams() {
211         return getBusinessObjectDictionaryService().getExtraButtonParams(getBusinessObjectClass());
212     }
213 
214     /**
215      * @return property names that will be used to sort on by default
216      */
217     public List<String> getDefaultSortColumns() {
218         return getLookupableHelperService().getDefaultSortColumns();
219     }
220 
221     /**
222      * @see Lookupable#checkForAdditionalFields(java.util.Map)
223      */
224     public boolean checkForAdditionalFields(Map<String, String> fieldValues) {
225         return getLookupableHelperService().checkForAdditionalFields(fieldValues);
226     }
227 
228     /**
229      * @return Returns the backLocation.
230      */
231     public String getBackLocation() {
232         return getLookupableHelperService().getBackLocation();
233     }
234 
235     /**
236      * @param backLocation The backLocation to set.
237      */
238     public void setBackLocation(String backLocation) {
239         getLookupableHelperService().setBackLocation(backLocation);
240     }
241 
242     /**
243      * @return Returns the docFormKey.
244      */
245     public String getDocFormKey() {
246         return getLookupableHelperService().getDocFormKey();
247     }
248 
249     /**
250      * // this method is public because unit tests depend upon it
251      * @param docFormKey The docFormKey to set.
252      */
253     public void setDocFormKey(String docFormKey) {
254         getLookupableHelperService().setDocFormKey(docFormKey);
255     }
256 
257     /**
258      * @return Returns the businessObjectDictionaryService.
259      */
260     protected BusinessObjectDictionaryService getBusinessObjectDictionaryService() {
261         return getLookupableHelperService().getBusinessObjectDictionaryService();
262     }
263 
264     /**
265      * @see Lookupable#setFieldConversions(java.util.Map)
266      */
267     public void setFieldConversions(Map fieldConversions) {
268         getLookupableHelperService().setFieldConversions(fieldConversions);
269     }
270 
271     /**
272      * @return Returns the dataDictionaryService.
273      */
274     protected DataDictionaryService getDataDictionaryService() {
275         return getLookupableHelperService().getDataDictionaryService();
276     }
277 
278 
279     /**
280      * Sets the readOnlyFieldsList attribute value.
281      *
282      * @param readOnlyFieldsList The readOnlyFieldsList to set.
283      */
284     public void setReadOnlyFieldsList(List<String> readOnlyFieldsList) {
285         getLookupableHelperService().setReadOnlyFieldsList(readOnlyFieldsList);
286     }
287 
288 
289     public LookupableHelperService getLookupableHelperService() {
290         return lookupableHelperService;
291     }
292 
293 
294     /**
295      * Sets the lookupableHelperService attribute value.
296      * @param lookupableHelperService The lookupableHelperService to set.
297      */
298     public void setLookupableHelperService(LookupableHelperService lookupableHelperService) {
299         this.lookupableHelperService = lookupableHelperService;
300     }
301 
302     /**
303      * Performs a lookup that can only return one row.
304      * @see Lookupable#performLookup(org.kuali.rice.krad.web.struts.form.LookupForm, java.util.List, boolean)
305      */
306     public Collection<? extends BusinessObject> performLookup(LookupForm lookupForm, List<ResultRow> resultTable, boolean bounded) {
307         return getLookupableHelperService().performLookup(lookupForm, resultTable, bounded);
308     }
309 
310 
311     public boolean isSearchUsingOnlyPrimaryKeyValues() {
312         return getLookupableHelperService().isSearchUsingOnlyPrimaryKeyValues();
313     }
314 
315 
316     public String getPrimaryKeyFieldLabels() {
317         return getLookupableHelperService().getPrimaryKeyFieldLabels();
318     }
319 
320     /**
321      * calls the lookup helper service to do "clear" behaviors
322      *
323      * @see Lookupable#performClear()
324      */
325     public void performClear(LookupForm lookupForm) {
326          getLookupableHelperService().performClear(lookupForm);
327     }
328 
329     /**
330      * calls the lookup helper service to check if non maintenance actions should be displayed
331      *
332      * @see Lookupable#shouldDisplayHeaderNonMaintActions()
333      */
334     public boolean shouldDisplayHeaderNonMaintActions() {
335         return getLookupableHelperService().shouldDisplayHeaderNonMaintActions();
336     }
337 
338     /**
339      * calls the lookup helper service to check if criteria should be displayed
340      *
341      * @see Lookupable#shouldDisplayLookupCriteria()
342      */
343     public boolean shouldDisplayLookupCriteria() {
344         return getLookupableHelperService().shouldDisplayLookupCriteria();
345     }
346 
347     protected String getCreateNewUrl(String url){
348         return "<a title=\"Create a new record\" href=\"" + url + "\"><img src=\"images/tinybutton-createnew.gif\" alt=\"create new\" width=\"70\" height=\"15\"/></a>";
349     }
350 
351     /**
352      * @see Lookupable#performCustomAction(boolean)
353      */
354     public boolean performCustomAction(boolean ignoreErrors) {
355         return getLookupableHelperService().performCustomAction(ignoreErrors);
356     }
357 
358     /**
359      * This overridden method ...
360      *
361      * @see Lookupable#getExtraField()
362      */
363     public Field getExtraField() {
364         return getLookupableHelperService().getExtraField();
365     }
366 
367     /**
368      * This overridden method ...
369      *
370      * @see Lookupable#applyFieldAuthorizationsFromNestedLookups(org.kuali.rice.krad.web.ui.Field)
371      */
372     public void applyFieldAuthorizationsFromNestedLookups(Field field) {
373         getLookupableHelperService().applyFieldAuthorizationsFromNestedLookups(field);
374     }
375 
376     /**
377      * This overridden method returns the extraOnLoad variable. The
378      * varible is currently accessed in page.tag and is called in the onLoad.
379      * it allows us to inject javascript onload.
380      *
381      * @see Lookupable#getExtraOnLoad()
382      */
383     public String getExtraOnLoad() {
384         return extraOnLoad;
385     }
386 
387     /**
388      * @param extraOnLoad the extraOnLoad to set
389      */
390     public void setExtraOnLoad(String extraOnLoad) {
391         this.extraOnLoad = extraOnLoad;
392     }
393 
394     /**
395      * @see Lookupable#applyConditionalLogicForFieldDisplay()
396      */
397     public void applyConditionalLogicForFieldDisplay() {
398         getLookupableHelperService().applyConditionalLogicForFieldDisplay();
399     }
400 
401 }