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