001/**
002 * Copyright 2005-2014 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.kew.framework.document.search;
017
018import org.kuali.rice.kew.api.document.search.DocumentSearchCriteria;
019import org.kuali.rice.kew.api.document.search.DocumentSearchResult;
020
021import java.util.List;
022
023/**
024 * Provides various mechanisms for an application to customize the behavior of the Document Search functionality for
025 * their document types.  Client applications should provide implementations of this interface if they need to
026 * enact some of these customizations on document searches.  These customizers then get mapped to the appropriate
027 * document types via the KEW extension framework (see
028 * {@link org.kuali.rice.kew.api.extension.ExtensionRepositoryService}).
029 *
030 * <p>The customization functionality provided by this interface includes:</p>
031 *
032 * <ul>
033 *     <li>The ability to customize document search criteria before it gets submitted.</li>
034 *     <li>The ability to customize how document search criteria is cleared.</li>
035 *     <li>The ability to customize how result data is processed and presented.</li>
036 * </ul>
037 *
038 * <p>Only one {@code DocumentSearchCustomizer} is supported for a given document type.  It is important to note however
039 * that it is permitted that an implementation of this interface could be tied to more than one document type via the
040 * extension framework.  This is why information about the specific document type for which the customizations is being
041 * applied is passed to all methods on this interface (note that the document type information is available from the
042 * {@code DocumentSearchCriteria} as well.</p>
043 *
044 * <p>Furthermore, the customization hooks afforded by this interface will only be executed when a valid document type
045 * has been specified as input to the document search.  This is because the customizer is tied to the document type and
046 * the document search must therefore be able to resolve a valid document type from the user-supplied criteria in order
047 * to perform these customizations.</p>
048 *
049 * <p>Since some of the operations on this component could potentially add expense to the overall search process in the
050 * cases where customization is only done on certain document types or only certain customization features are being
051 * utilized, this interface provides for a set of boolean operations which indicate which customization
052 * features should be activated by the document search framework for a given document type.  It's expected that KEW
053 * will check each of these flags prior to invoking the corresponding method that it "gaurds" and, if the customization
054 * flag is disabled, it should refrain from executing that method.</p>
055 *
056 * <p></p>Implementations of this interface are expected to return "true" for any of these operations for which they
057 * provide a custom implementation.  <strong>It is important to note that callers are permitted to cache the results
058 * returned from these boolean methods for an unspecified length of time.</strong>  So if there is any possibility that,
059 * for a given document type, the implementation might perform a particular customization, then "true" should be
060 * returned from the appropriate boolean method.</p>
061 *
062 * @author Kuali Rice Team (rice.collab@kuali.org)
063 */
064public interface DocumentSearchCustomizer {
065
066    /**
067     * Performs customization on the given document search criteria.  This method should return the customized version
068     * of the criteria, or null if no customizations were performed.  This customization is invoked prior the actual
069     * search being executed, and the resulting customized criteria is what gets passed to the search implementation.
070     * It is also invoked in situtations where the document search is performed via the api or via the user interface.
071     *
072     * <p>It is guaranteed that the document type name on the given criteria will never be null and will always
073     * represent a valid document type.</p>
074     *
075     * @param documentSearchCriteria the original criteria against which to perform customization, will never be null
076     *
077     * @return the customized criteria, or null if no customization was performed
078     */
079    DocumentSearchCriteria customizeCriteria(DocumentSearchCriteria documentSearchCriteria);
080
081    /**
082     * Performs a customized "clear" of the given document search criteria.  Clearing of the criteria is typically
083     * invoked whenever the user of the document search user interface clicks the "clear" button.  By default all of
084     * the search criteria is cleared, but this method allows for certain criteria data to be preserved on a clear if
085     * desired.
086     *
087     * <p>A common use of this feature is to preserve the document type that has been selected when clearing criteria
088     * for a customized document search.
089     *
090     * <p>It is guaranteed that the document type name on the given criteria will never be null and will always
091     * represent a valid document type.</p>
092     *
093     * @param documentSearchCriteria the criteria to clear
094     *
095     * @return the cleared criteria, or null if no custom criteria clearing was performed
096     */
097    DocumentSearchCriteria customizeClearCriteria(DocumentSearchCriteria documentSearchCriteria);
098
099    /**
100     * Performs customization of the given list of document search results.  This method is invoked after the search is
101     * executed but before results are returned to the caller.  It is executed when a document search is executed via
102     * the api or from the document search user interface.
103     *
104     * <p>This method returns a {@code DocumentSearchResultValues} object which contains a list of
105     * {@link DocumentSearchResultValue} objects.  Each of these result values maps to a specific document id and
106     * contains a list of {@link org.kuali.rice.kew.api.document.attribute.DocumentAttribute} values which can be used
107     * to modify existing document attributes or create new ones that are included as part of the search results.  It
108     * is important to note that in order for these custom attribute values to be displayed in the result set in the
109     * document search user interface, there must be a corresponding entry in the
110     * {@link DocumentSearchResultSetConfiguration} returned by the
111     * {@link #customizeResultSetConfiguration(org.kuali.rice.kew.api.document.search.DocumentSearchCriteria)} method
112     * on this customizer implementation.</p>
113     *
114     * <p>It is permissible that implementations of this method may not return result values for all of the document
115     * provided in the given list of document search results.  It is important to note however that ommision from the
116     * returned result values does not filter or remove the result from the search results.  Generally speaking, this
117     * method cannot be used to remove results from the result set.</p>
118     *
119     * <p>It is guaranteed that the document type name on the given criteria will never be null and will always
120     * represent a valid document type.</p>
121     *
122     * @param documentSearchCriteria the criteria against which the document search was executed
123     * @param defaultResults the results that were returned by the execution of the document search
124     * 
125     * @return customized search result values for any of the document results requiring custom values, or null if no
126     * customization was performed
127     */
128    DocumentSearchResultValues customizeResults(DocumentSearchCriteria documentSearchCriteria, List<DocumentSearchResult> defaultResults);
129
130    /**
131     * Performs customization of what result fields should be displayed in the result set.  Allows for hiding of
132     * standard fields, addition of custom fields, and the ability to override the default behavior of searchable
133     * attributes that are defined for the document type.  Generally speaking, this controls which "columns" of data are
134     * displayed in the document search results.
135     *
136     * <p>This method is only invoked by the document search user interface whenever it is rendering document search
137     * results.  It is not invoked when invoking document search using only the api.</p>
138     *
139     * <p>It is guaranteed that the document type name on the given criteria will never be null and will always
140     * represent a valid document type.</p>
141     *
142     * @param documentSearchCriteria the criteria against which the document search was executed
143     * @return the customized result set configuration, or null if no customization was performed
144     */
145    DocumentSearchResultSetConfiguration customizeResultSetConfiguration(DocumentSearchCriteria documentSearchCriteria);
146
147    /**
148     * Indicates if the {@link #customizeCriteria(org.kuali.rice.kew.api.document.search.DocumentSearchCriteria)} on
149     * this customizer should be invoked for the document type with the given name.  The caller of this method is
150     * permitted to cache the return value for a length of time of their choosing.
151     *
152     * @param documentTypeName the name of the document type against which this customizer is being applied
153     * @return true if the customization method should be executed, false otherwise
154     */
155    boolean isCustomizeCriteriaEnabled(String documentTypeName);
156
157    /**
158     * Indicates if the {@link #customizeClearCriteria(org.kuali.rice.kew.api.document.search.DocumentSearchCriteria)}
159     * on this customizer should be invoked for the document type with the given name.  The caller of this method is
160     * permitted to cache the return value for a length of time of their choosing.
161     *
162     * @param documentTypeName the name of the document type against which this customizer is being applied
163     * @return true if the customization method should be executed, false otherwise
164     */
165    boolean isCustomizeClearCriteriaEnabled(String documentTypeName);
166
167    /**
168     * Indicates if the {@link #customizeResults(org.kuali.rice.kew.api.document.search.DocumentSearchCriteria, java.util.List)}
169     * on this customizer should be invoked for the document type with the given name.  The caller of this method is
170     * permitted to cache the return value for a length of time of their choosing.
171     *
172     * @param documentTypeName the name of the document type against which this customizer is being applied
173     * @return true if the customization method should be executed, false otherwise
174     */
175    boolean isCustomizeResultsEnabled(String documentTypeName);
176
177    /**
178     * Indicates if the {@link #customizeResultSetConfiguration(org.kuali.rice.kew.api.document.search.DocumentSearchCriteria)}
179     * on this customizer should be invoked for the document type with the given name.  The caller of this method is
180     * permitted to cache the return value for a length of time of their choosing.
181     *
182     * @param documentTypeName the name of the document type against which this customizer is being applied
183     * @return true if the customization method should be executed, false otherwise
184     */
185    boolean isCustomizeResultSetFieldsEnabled(String documentTypeName);
186
187}