001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kns.lookup;
017
018import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions;
019import org.kuali.rice.kns.web.struts.form.LookupForm;
020import org.kuali.rice.kns.web.ui.Column;
021import org.kuali.rice.kns.web.ui.Field;
022import org.kuali.rice.kns.web.ui.ResultRow;
023import org.kuali.rice.kns.web.ui.Row;
024import org.kuali.rice.krad.bo.BusinessObject;
025import org.kuali.rice.kns.service.BusinessObjectDictionaryService;
026import org.kuali.rice.krad.service.DataDictionaryService;
027
028import java.io.Serializable;
029import java.util.Collection;
030import java.util.List;
031import java.util.Map;
032
033public interface LookupableHelperService extends Serializable{
034
035    /**
036     * Initializes the lookup with a business object class.  This is set
037     * via the LookupableHelperService's consumer, namely the Lookupable
038     * implementation (or in cases of nesting a wrapping LookupableHelperService).
039     * The Lookupable in turn receives this value from the UI via
040     * LookupForm population.
041     *
042     * @param businessObjectClass
043     */
044    public void setBusinessObjectClass(Class businessObjectClass);
045
046    /**
047     * @return Returns the dataObjectClass this lookupable is representing
048     */
049    // NOTE: used in exactly one place in RuleBaseValuesLookupableHelperServiceImpl to conditionally initialize
050    // an internal lookup helper service reference; this reference should in theory be a unique instance or prototype
051    // so the check should not be necessary
052    public Class getBusinessObjectClass();
053
054    /**
055     * Initializes the lookup with the given Map of parameters.
056     *
057     * @param parameters
058     */
059    public void setParameters(Map<String, String[]> parameters);
060
061    /**
062     * @return Returns the parameters passed to this lookup
063     */
064    public Map<String, String[]> getParameters();
065
066    /**
067     * @return String url for the location to return to after the lookup
068     */
069    public String getReturnLocation();
070
071    /**
072     * @return List of Column objects used to render the result table
073     */
074    public List<Column> getColumns();
075
076    /**
077     * Validates the values filled in as search criteria, also checks for required field values.
078     *
079     * @param fieldValues - Map of property/value pairs
080     */
081    public void validateSearchParameters(Map<String, String> fieldValues);
082
083    /**
084     * Performs a search and returns result list.
085     *
086     * @param fieldValues - Map of property/value pairs
087     * @return List of business objects found by the search
088     * @throws Exception
089     */
090    public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues);
091
092    /**
093     * Similar to getSearchResults, but the number of returned rows is not bounded
094     *
095     * @param fieldValues
096     * @return
097     */
098    public List<? extends BusinessObject> getSearchResultsUnbounded(Map<String, String> fieldValues);
099
100    /**
101     * Determines if there should be more search fields rendered based on already entered search criteria.
102     *
103     * @param fieldValues - Map of property/value pairs
104     * @return boolean
105     */
106    public boolean checkForAdditionalFields(Map<String, String> fieldValues);
107
108    /**
109     * Builds the return value url.
110     *
111     * @param businessObject - Instance of a business object containing the return values
112     * @param fieldConversions - Map of conversions mapping bo names to caller field names.
113     * @param lookupImpl - Current lookup impl name
114     * @param returnKeys - Keys to return
115     * @return String url called when selecting a row from the result set
116     */
117    public HtmlData getReturnUrl(BusinessObject businessObject, Map fieldConversions, String lookupImpl, List returnKeys, BusinessObjectRestrictions businessObjectRestrictions);
118
119    /**
120     * This method builds the return url
121     * 
122     * @param businessObject
123     * @param lookupForm
124     * @param returnKeys
125     * @return
126     */
127    public HtmlData getReturnUrl(BusinessObject businessObject, LookupForm lookupForm, List returnKeys, BusinessObjectRestrictions businessObjectRestrictions);
128    
129    /**
130     * Builds string of action urls that can take place for a result row
131     *
132     * @param businessObject - Instance of a business object containing the return values
133     * @param pkNames - List of primary key names
134     * @return String rendered in actions column of result set
135     */
136    public String getActionUrls(BusinessObject businessObject, List pkNames, BusinessObjectRestrictions businessObjectRestrictions);
137
138    /**
139     * 
140     * This method is a template method that allows child classes to return their own custom action html data.
141     * 
142     * @param businessObject
143     * @param pkNames
144     * @return
145     */
146    public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames);
147
148    /**
149     * Builds string an inquiry url for drill down on a result field
150     *
151     * @param businessObject - Instance of a business object containing the return values
152     * @param propertyName - Name of the property in the business object
153     * @return String url called on selection of the result field
154     */
155    public HtmlData getInquiryUrl(BusinessObject businessObject, String propertyName);
156
157    /**
158     * Sets the requested fields conversions in the lookupable
159     *
160     * @param fieldConversions
161     */
162    public void setFieldConversions(Map fieldConversions);
163
164    /**
165     * Gets the readOnlyFieldsList attribute.
166     * @return Returns the readOnlyFieldsList.
167     */
168    public List<String> getReadOnlyFieldsList();
169
170    /**
171     * Sets the requested read only fields list in the lookupable
172     *
173     * @param readOnlyFieldsList
174     */
175    public void setReadOnlyFieldsList(List<String> readOnlyFieldsList);
176
177    /**
178     * This method is public because some unit tests depend on it.
179     *
180     * @return a List of the names of fields which are marked in data dictionary as return fields.
181     */
182    public List<String> getReturnKeys();
183
184    public String getDocFormKey();
185
186    public void setDocFormKey(String docFormKey);
187
188    public String getDocNum();
189
190    public void setDocNum(String docNum);
191
192    /**
193     * 
194     * This method builds a maintenance url.
195     * 
196     * @param businessObject
197     * @param htmlData
198     * @param pkNames
199     * @return
200     */
201    public String getMaintenanceUrl(BusinessObject businessObject, HtmlData htmlData, List pkNames, BusinessObjectRestrictions businessObjectRestrictions);
202
203    /**
204     * Determines if underlying lookup bo has associated maintenance document that allows new or copy maintenance actions.
205     *
206     * @return true if bo has maint doc that allows new or copy actions
207     */
208    public boolean allowsMaintenanceNewOrCopyAction();
209
210    /**
211     * Determines if underlying lookup bo has associated document that allows new or copy maintenance actions.
212     *
213     * @return true if bo has doc that allows new or copy actions
214     */
215    public boolean allowsNewOrCopyAction(String documentTypeName);
216
217    /**
218     * Returns a list of Row objects to be used to generate the search query screen
219     *
220     * Generally, setDataObjectClass needs to be called with a non-null value for proper operation
221     * @return
222     */
223    public List<Row> getRows();
224
225    /**
226     * This method returns the DataDictionaryService used to initialize this helper service and is used by Lookupable implementations to
227     * retrieve the proper service.
228     *
229     * @return
230     */
231    public DataDictionaryService getDataDictionaryService();
232
233    /**
234     * This method returns the BusinessObjectDictionaryService used to initialize this helper service and is used by Lookupable implementations to
235     * retrieve the proper service.
236     *
237     * @return
238     */
239    public BusinessObjectDictionaryService getBusinessObjectDictionaryService();
240
241    public void setBackLocation(String backLocation);
242
243    public String getBackLocation();
244
245    /**
246     *
247     * This method performs the lookup and returns a collection of BO items
248     * @param lookupForm
249     * @param resultTable
250     * @param bounded
251     * @return the list of result BOs, possibly bounded
252     */
253    public Collection<? extends BusinessObject> performLookup(LookupForm lookupForm, Collection<ResultRow> resultTable, boolean bounded);
254
255    /**
256     * This method returns a list of the default columns used to sort the result set.  For multiple value lookups,
257     * this method does not change when different columns are sorted.
258     *
259     * @return
260     */
261    public List<String> getDefaultSortColumns();
262
263    /**
264     * This method returns whether the previously executed getSearchResults used the primary key values to search, ignoring all non key values
265     *
266     * @return
267     * @see LookupableHelperService#getPrimaryKeyFieldLabels()
268     */
269    public boolean isSearchUsingOnlyPrimaryKeyValues();
270
271    /**
272     * Returns a comma delimited list of primary key field labels, to be used on the UI to tell the user which fields were used to search
273     *
274     * @return
275     * @see LookupableHelperService#isSearchUsingOnlyPrimaryKeyValues()
276     */
277    public String getPrimaryKeyFieldLabels();
278
279    /**
280     * Determines whether a given BusinessObject that's returned as one of the lookup's results is considered returnable, which means that for
281     * single-value lookups, a "return value" link may be rendered, and for multiple value lookups, a checkbox is rendered.
282     *
283     * Note that this can be part of an authorization mechanism, but not the complete authorization mechanism.  The component that invoked the lookup/
284     * lookup caller (e.g. document, nesting lookup, etc.) needs to check that the object that was passed to it was returnable as well because there
285     * are ways around this method (e.g. crafting a custom return URL).
286     *
287     * @param object an object from the search result set
288     * @return
289     */
290    public boolean isResultReturnable(BusinessObject object);
291    
292    /**
293     * 
294     * This method allows for overriding the clear behavior
295     *
296     */
297    public void performClear(LookupForm lookupForm);
298    
299    public boolean shouldDisplayHeaderNonMaintActions();
300    
301    public boolean shouldDisplayLookupCriteria();
302
303        /**
304         * This method gets the supplemental lookup menu if any
305         * 
306         * @return supplemental menu bar
307         */
308        public String getSupplementalMenuBar();
309    
310    /**
311     * @return String displayed as title for the lookup
312     */
313    public String getTitle();
314    
315    /**
316     * 
317     * performs custom actions.  return true to reperform search
318     * 
319     * @param ignoreErrors
320     * @return boolean to reperform search
321     */
322    public boolean performCustomAction(boolean ignoreErrors);
323    
324    /**
325     * get an extra field
326     * @return
327     */
328    public Field getExtraField();
329    
330    public void applyFieldAuthorizationsFromNestedLookups(Field field);
331    
332    /**
333     * Performs conditional logic (based on current search values or other parameters) to
334     * override field hidden, read-only, and required attributes previously set.
335     */
336    public void applyConditionalLogicForFieldDisplay();
337}