View Javadoc

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