View Javadoc

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