org.kuali.rice.kew.docsearch
Class StandardDocumentSearchGenerator

java.lang.Object
  extended by org.kuali.rice.kew.docsearch.StandardDocumentSearchGenerator
All Implemented Interfaces:
DocumentSearchGenerator

public class StandardDocumentSearchGenerator
extends Object
implements DocumentSearchGenerator

Author:
Kuali Rice Team (rice.collab@kuali.org)

Field Summary
 
Fields inherited from interface org.kuali.rice.kew.docsearch.DocumentSearchGenerator
DEFAULT_SEARCH_RESULT_CAP
 
Constructor Summary
StandardDocumentSearchGenerator()
           
StandardDocumentSearchGenerator(List<SearchableAttribute> searchableAttributes)
           
 
Method Summary
 void addChildDocumentTypes(StringBuffer whereSql, Collection<DocumentType> childDocumentTypes)
           
 void addDocumentTypeLikeNameToSearchOn(StringBuffer whereSql, String documentTypeName, String clause)
           
 void addDocumentTypeNameToSearchOn(StringBuffer whereSql, String documentTypeName)
           
 void addDocumentTypeNameToSearchOn(StringBuffer whereSql, String documentTypeName, String clause)
           
 void addErrorMessageToList(List<WorkflowServiceError> errors, String message)
           
 void addExtraDocumentTypesToSearch(StringBuffer whereSql, DocumentType docType)
           
 DocSearchCriteriaDTO clearSearch(DocSearchCriteriaDTO searchCriteria)
           
 StringBuffer constructWhereClauseDateElement(String clauseStarter, String queryTableColumnName, boolean inclusive, boolean valueIsLowerBound, String dateValueToSearch)
           
 StringBuffer constructWhereClauseDateElement(String clauseStarter, String queryTableColumnName, boolean inclusive, boolean valueIsLowerBound, String dateValueToSearch, boolean isAllowInlineRange)
           
 StringBuffer constructWhereClauseElement(String clauseStarter, String queryTableColumnName, String operand, String valueToSearch, String valuePrefix, String valueSuffix)
           
 String establishDateString(String fromDate, String toDate, String tableName, String tableAlias, String colName, String whereStatementClause)
           
 void filterOutNonQueryAttributes()
          TODO we should probably clean this up some, but we are going to exclude those KeyLabelPairs that have a null label.
 String generateFinalSQL(QueryComponent searchSQL, String docHeaderTableAlias, String standardSqlPrefix, String standardSqlSuffix)
          Deprecated. As of version 0.9.3 this method is no longer used. This method had been used to create multiple SQL queries if using searchable attributes and use the sql UNION function to join the queries. The replacement method #generateFinalSQL(QueryComponent, String, String) is now used instead.
 StringBuilder generateSearchableAttributeDefaultWhereSql(SearchAttributeCriteriaComponent criteriaComponent, String queryTableColumnName)
           
 StringBuffer generateSearchableAttributeFromSql(SearchableAttributeValue attributeValue, String tableIdentifier)
           
 QueryComponent generateSearchableAttributeRangeSql(String searchAttributeKeyName, List<SearchAttributeCriteriaComponent> criteriaComponents, String whereSqlStarter, int tableIndex)
           
 QueryComponent generateSearchableAttributeSql(SearchAttributeCriteriaComponent criteriaComponent, String whereSqlStarter, int tableIndex)
           
 StringBuffer generateSearchableAttributeWhereClauseJoin(String whereSqlStarter, String tableIdentifier, String attributeTableKeyColumnName)
           
 String generateSearchSql(DocSearchCriteriaDTO searchCriteria)
           
 QueryComponent generateSqlForSearchableAttributeValue(SearchableAttributeValue attributeValue, List<String> tableAliasComponentNames, String docHeaderTableAlias)
          Deprecated. As of version 0.9.3 this method is no longer used. This method had been used to generate SQL to return searchable attributes using left outer joins. The new mechanism to get search attributes from the database is to call each search attribute table individually in the populateRowSearchableAttributes(DocSearchDTO, Statement, ResultSet) method.
 String getAppDocIdSql(String appDocId, String whereClausePredicatePrefix)
           
 String getAppDocStatusSql(String appDocStatus, String whereClausePredicatePrefix, int statusTransitionWhereClauseLength)
          This method generates the where clause fragment related to Application Document Status.
 String getApproverSql(String approver, String whereClausePredicatePrefix)
           
 DocSearchCriteriaDTO getCriteria()
           
 String getDateApprovedSql(String fromDateApproved, String toDateApproved, String whereClausePredicatePrefix)
           
 String getDateCreatedSql(String fromDateCreated, String toDateCreated, String whereClausePredicatePrefix)
           
 String getDateFinalizedSql(String fromDateFinalized, String toDateFinalized, String whereClausePredicatePrefix)
           
 String getDateLastModifiedSql(String fromDateLastModified, String toDateLastModified, String whereClausePredicatePrefix)
           
 DatabasePlatform getDbPlatform()
           
 String getDocRouteNodeSql(String documentTypeFullName, String docRouteLevel, String docRouteLevelLogic, String whereClausePredicatePrefix)
           
 String getDocRouteStatusSql(String docRouteStatuses, String whereClausePredicatePrefix)
           
 String getDocSearchSQL()
           
 String getDocTitleSql(String docTitle, String whereClausePredicatePrefix)
           
 String getDocTypeFullNameWhereSql(String docTypeFullName, String whereClausePredicatePrefix)
           
 int getDocumentSearchResultSetLimit()
           
 String getGeneratedPredicatePrefix(int whereClauseSize)
           
 String getInitiatorSql(String initiator, String whereClausePredicatePrefix)
           
 MessageMap getMessageMap(DocSearchCriteriaDTO searchCriteria)
           
 String getRouteHeaderIdSql(String routeHeaderId, String whereClausePredicatePrefix, String tableAlias)
           
 SearchAttributeCriteriaComponent getSearchableAttributeByFieldName(String name)
           
 QueryComponent getSearchableAttributeJoinSql(SearchableAttributeValue attributeValue, String tableIdentifier, String whereSqlStarter, String attributeTableKeyColumnName)
           
 List<SearchableAttribute> getSearchableAttributes()
           
 QueryComponent getSearchableAttributeSql(List<SearchAttributeCriteriaComponent> searchableAttributes, String whereClausePredicatePrefix)
           
 String getSearchingUser()
           
 SqlBuilder getSqlBuilder()
           
 String getSqlOperand(boolean rangeSearch, boolean inclusive, boolean valueIsLowerBound, boolean usingWildcards)
          For the following we first check for a ranged search because a ranged search does not allow for wildcards
 String getStatusTransitionDateSql(String fromStatusTransitionDate, String toStatusTransitionDate, String whereClausePredicatePrefix)
           
 DocumentType getValidDocumentType(String documentTypeFullName)
           
 String getViewerSql(String viewer, String whereClausePredicatePrefix)
           
 String getWorkgroupViewerSql(String id, String workgroupName, String whereClausePredicatePrefix)
           
 void handleMultipleDocumentRows(DocSearchDTO existingRow, DocSearchDTO newRow)
          Handles multiple document rows by collapsing them and their data into the searchable attribute columns.
 boolean isProcessResultSet()
          This method returns if processResultSet should be called.
protected  boolean isUsingAtLeastOneSearchAttribute()
          A helper method for determining whether any searchable attributes are in use for the search.
 List<WorkflowServiceError> performPreSearchConditions(String principalId, DocSearchCriteriaDTO searchCriteria)
           
 void populateRowSearchableAttributes(DocSearchDTO docCriteriaDTO, Statement searchAttributeStatement)
          This method performs searches against the search attribute value tables (see classes implementing SearchableAttributeValue) to get data to fill in search attribute values on the given docCriteriaDTO parameter
 void populateRowSearchableAttributes(DocSearchDTO docCriteriaDTO, Statement searchAttributeStatement, ResultSet rs)
          Deprecated. As of version 0.9.3 this method is no longer used. Method populateRowSearchableAttributes(DocSearchDTO, Statement) is being used instead.
 List<DocSearchDTO> processResultSet(Statement searchAttributeStatement, ResultSet resultSet, DocSearchCriteriaDTO searchCriteria)
          Deprecated. Removed as of version 0.9.3. Use processResultSet(Statement, ResultSet, DocSearchCriteriaDTO, String) instead.
 List<DocSearchDTO> processResultSet(Statement searchAttributeStatement, ResultSet resultSet, DocSearchCriteriaDTO searchCriteria, String principalId)
          This method processes search results in the given resultSet into DocSearchDTO objects
 DocSearchDTO processRow(Statement searchAttributeStatement, ResultSet rs)
           
 void setCriteria(DocSearchCriteriaDTO criteria)
           
 void setProcessResultSet(boolean isProcessResultSet)
           
 void setSearchableAttributes(List<SearchableAttribute> searchableAttributes)
           
 void setSearchingUser(String searchingUser)
           
 void setSqlBuilder(SqlBuilder sqlBuilder)
           
 List<WorkflowAttributeValidationError> validateSearchableAttribute(SearchableAttribute searchableAttribute, Map searchAttributesParameterMap, DocumentSearchContext documentSearchContext)
           
 List<WorkflowServiceError> validateSearchableAttributes(DocSearchCriteriaDTO searchCriteria)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StandardDocumentSearchGenerator

public StandardDocumentSearchGenerator()

StandardDocumentSearchGenerator

public StandardDocumentSearchGenerator(List<SearchableAttribute> searchableAttributes)
Parameters:
searchableAttributes - in a list
Method Detail

getCriteria

public DocSearchCriteriaDTO getCriteria()

setCriteria

public void setCriteria(DocSearchCriteriaDTO criteria)

getSearchableAttributes

public List<SearchableAttribute> getSearchableAttributes()

setSearchableAttributes

public void setSearchableAttributes(List<SearchableAttribute> searchableAttributes)

getSearchingUser

public String getSearchingUser()

setSearchingUser

public void setSearchingUser(String searchingUser)
Specified by:
setSearchingUser in interface DocumentSearchGenerator

clearSearch

public DocSearchCriteriaDTO clearSearch(DocSearchCriteriaDTO searchCriteria)
Specified by:
clearSearch in interface DocumentSearchGenerator

performPreSearchConditions

public List<WorkflowServiceError> performPreSearchConditions(String principalId,
                                                             DocSearchCriteriaDTO searchCriteria)
Specified by:
performPreSearchConditions in interface DocumentSearchGenerator

getSearchableAttributeByFieldName

public SearchAttributeCriteriaComponent getSearchableAttributeByFieldName(String name)

addErrorMessageToList

public void addErrorMessageToList(List<WorkflowServiceError> errors,
                                  String message)

generateSearchSql

public String generateSearchSql(DocSearchCriteriaDTO searchCriteria)
Specified by:
generateSearchSql in interface DocumentSearchGenerator

getValidDocumentType

public DocumentType getValidDocumentType(String documentTypeFullName)

validateSearchableAttributes

public List<WorkflowServiceError> validateSearchableAttributes(DocSearchCriteriaDTO searchCriteria)
Specified by:
validateSearchableAttributes in interface DocumentSearchGenerator

validateSearchableAttribute

public List<WorkflowAttributeValidationError> validateSearchableAttribute(SearchableAttribute searchableAttribute,
                                                                          Map searchAttributesParameterMap,
                                                                          DocumentSearchContext documentSearchContext)

getSearchableAttributeSql

public QueryComponent getSearchableAttributeSql(List<SearchAttributeCriteriaComponent> searchableAttributes,
                                                String whereClausePredicatePrefix)

generateSearchableAttributeSql

public QueryComponent generateSearchableAttributeSql(SearchAttributeCriteriaComponent criteriaComponent,
                                                     String whereSqlStarter,
                                                     int tableIndex)

generateSearchableAttributeRangeSql

public QueryComponent generateSearchableAttributeRangeSql(String searchAttributeKeyName,
                                                          List<SearchAttributeCriteriaComponent> criteriaComponents,
                                                          String whereSqlStarter,
                                                          int tableIndex)

generateSearchableAttributeDefaultWhereSql

public StringBuilder generateSearchableAttributeDefaultWhereSql(SearchAttributeCriteriaComponent criteriaComponent,
                                                                String queryTableColumnName)

getSearchableAttributeJoinSql

public QueryComponent getSearchableAttributeJoinSql(SearchableAttributeValue attributeValue,
                                                    String tableIdentifier,
                                                    String whereSqlStarter,
                                                    String attributeTableKeyColumnName)

generateSearchableAttributeWhereClauseJoin

public StringBuffer generateSearchableAttributeWhereClauseJoin(String whereSqlStarter,
                                                               String tableIdentifier,
                                                               String attributeTableKeyColumnName)

generateSearchableAttributeFromSql

public StringBuffer generateSearchableAttributeFromSql(SearchableAttributeValue attributeValue,
                                                       String tableIdentifier)

constructWhereClauseDateElement

public StringBuffer constructWhereClauseDateElement(String clauseStarter,
                                                    String queryTableColumnName,
                                                    boolean inclusive,
                                                    boolean valueIsLowerBound,
                                                    String dateValueToSearch)

constructWhereClauseDateElement

public StringBuffer constructWhereClauseDateElement(String clauseStarter,
                                                    String queryTableColumnName,
                                                    boolean inclusive,
                                                    boolean valueIsLowerBound,
                                                    String dateValueToSearch,
                                                    boolean isAllowInlineRange)

constructWhereClauseElement

public StringBuffer constructWhereClauseElement(String clauseStarter,
                                                String queryTableColumnName,
                                                String operand,
                                                String valueToSearch,
                                                String valuePrefix,
                                                String valueSuffix)

getSqlOperand

public String getSqlOperand(boolean rangeSearch,
                            boolean inclusive,
                            boolean valueIsLowerBound,
                            boolean usingWildcards)
For the following we first check for a ranged search because a ranged search does not allow for wildcards


processResultSet

public List<DocSearchDTO> processResultSet(Statement searchAttributeStatement,
                                           ResultSet resultSet,
                                           DocSearchCriteriaDTO searchCriteria)
                                    throws SQLException
Deprecated. Removed as of version 0.9.3. Use processResultSet(Statement, ResultSet, DocSearchCriteriaDTO, String) instead.

Specified by:
processResultSet in interface DocumentSearchGenerator
Throws:
SQLException

processResultSet

public List<DocSearchDTO> processResultSet(Statement searchAttributeStatement,
                                           ResultSet resultSet,
                                           DocSearchCriteriaDTO searchCriteria,
                                           String principalId)
                                    throws SQLException
Description copied from interface: DocumentSearchGenerator
This method processes search results in the given resultSet into DocSearchDTO objects

Specified by:
processResultSet in interface DocumentSearchGenerator
Parameters:
resultSet -
criteria -
Returns:
Throws:
SQLException

handleMultipleDocumentRows

public void handleMultipleDocumentRows(DocSearchDTO existingRow,
                                       DocSearchDTO newRow)
Handles multiple document rows by collapsing them and their data into the searchable attribute columns. TODO this is currently concatenating strings together with HTML elements, this seems bad in this location, perhaps we should move this to the web layer (and perhaps enhance the searchable attributes portion of the DocSearchDTO data structure?)


processRow

public DocSearchDTO processRow(Statement searchAttributeStatement,
                               ResultSet rs)
                        throws SQLException
Throws:
SQLException

populateRowSearchableAttributes

public void populateRowSearchableAttributes(DocSearchDTO docCriteriaDTO,
                                            Statement searchAttributeStatement)
                                     throws SQLException
This method performs searches against the search attribute value tables (see classes implementing SearchableAttributeValue) to get data to fill in search attribute values on the given docCriteriaDTO parameter

Parameters:
docCriteriaDTO - - document search result object getting search attributes added to it
searchAttributeStatement - - statement being used to call the database for queries
Throws:
SQLException

populateRowSearchableAttributes

@Deprecated
public void populateRowSearchableAttributes(DocSearchDTO docCriteriaDTO,
                                                       Statement searchAttributeStatement,
                                                       ResultSet rs)
                                     throws SQLException
Deprecated. As of version 0.9.3 this method is no longer used. Method populateRowSearchableAttributes(DocSearchDTO, Statement) is being used instead.

Throws:
SQLException

getDocSearchSQL

public String getDocSearchSQL()

generateFinalSQL

@Deprecated
public String generateFinalSQL(QueryComponent searchSQL,
                                          String docHeaderTableAlias,
                                          String standardSqlPrefix,
                                          String standardSqlSuffix)
Deprecated. As of version 0.9.3 this method is no longer used. This method had been used to create multiple SQL queries if using searchable attributes and use the sql UNION function to join the queries. The replacement method #generateFinalSQL(QueryComponent, String, String) is now used instead.


generateSqlForSearchableAttributeValue

@Deprecated
public QueryComponent generateSqlForSearchableAttributeValue(SearchableAttributeValue attributeValue,
                                                                        List<String> tableAliasComponentNames,
                                                                        String docHeaderTableAlias)
Deprecated. As of version 0.9.3 this method is no longer used. This method had been used to generate SQL to return searchable attributes using left outer joins. The new mechanism to get search attributes from the database is to call each search attribute table individually in the populateRowSearchableAttributes(DocSearchDTO, Statement, ResultSet) method.


getRouteHeaderIdSql

public String getRouteHeaderIdSql(String routeHeaderId,
                                  String whereClausePredicatePrefix,
                                  String tableAlias)

getInitiatorSql

public String getInitiatorSql(String initiator,
                              String whereClausePredicatePrefix)

getDocTitleSql

public String getDocTitleSql(String docTitle,
                             String whereClausePredicatePrefix)

getAppDocIdSql

public String getAppDocIdSql(String appDocId,
                             String whereClausePredicatePrefix)

getDateCreatedSql

public String getDateCreatedSql(String fromDateCreated,
                                String toDateCreated,
                                String whereClausePredicatePrefix)

getDateApprovedSql

public String getDateApprovedSql(String fromDateApproved,
                                 String toDateApproved,
                                 String whereClausePredicatePrefix)

getDateFinalizedSql

public String getDateFinalizedSql(String fromDateFinalized,
                                  String toDateFinalized,
                                  String whereClausePredicatePrefix)

getDateLastModifiedSql

public String getDateLastModifiedSql(String fromDateLastModified,
                                     String toDateLastModified,
                                     String whereClausePredicatePrefix)

getStatusTransitionDateSql

public String getStatusTransitionDateSql(String fromStatusTransitionDate,
                                         String toStatusTransitionDate,
                                         String whereClausePredicatePrefix)

getViewerSql

public String getViewerSql(String viewer,
                           String whereClausePredicatePrefix)

getWorkgroupViewerSql

public String getWorkgroupViewerSql(String id,
                                    String workgroupName,
                                    String whereClausePredicatePrefix)

getApproverSql

public String getApproverSql(String approver,
                             String whereClausePredicatePrefix)

getDocTypeFullNameWhereSql

public String getDocTypeFullNameWhereSql(String docTypeFullName,
                                         String whereClausePredicatePrefix)

addChildDocumentTypes

public void addChildDocumentTypes(StringBuffer whereSql,
                                  Collection<DocumentType> childDocumentTypes)

addExtraDocumentTypesToSearch

public void addExtraDocumentTypesToSearch(StringBuffer whereSql,
                                          DocumentType docType)

addDocumentTypeNameToSearchOn

public void addDocumentTypeNameToSearchOn(StringBuffer whereSql,
                                          String documentTypeName)

addDocumentTypeNameToSearchOn

public void addDocumentTypeNameToSearchOn(StringBuffer whereSql,
                                          String documentTypeName,
                                          String clause)

addDocumentTypeLikeNameToSearchOn

public void addDocumentTypeLikeNameToSearchOn(StringBuffer whereSql,
                                              String documentTypeName,
                                              String clause)

getDocRouteNodeSql

public String getDocRouteNodeSql(String documentTypeFullName,
                                 String docRouteLevel,
                                 String docRouteLevelLogic,
                                 String whereClausePredicatePrefix)

getDocRouteStatusSql

public String getDocRouteStatusSql(String docRouteStatuses,
                                   String whereClausePredicatePrefix)

getAppDocStatusSql

public String getAppDocStatusSql(String appDocStatus,
                                 String whereClausePredicatePrefix,
                                 int statusTransitionWhereClauseLength)
This method generates the where clause fragment related to Application Document Status. If the Status value only is defined, search for the appDocStatus value in the route header. If either the transition from/to dates are defined, search agains the status transition history.

Parameters:
appDocStatus -
whereClausePredicatePrefix -
statusTransitionWhereClauseLength -
Returns:

filterOutNonQueryAttributes

public void filterOutNonQueryAttributes()
TODO we should probably clean this up some, but we are going to exclude those KeyLabelPairs that have a null label. This will happen in the case of Quickfinders which don't really represent criteria anyway. Note however, that it is legal for the label to be the empty string. At some point we will probably need to do some more work to untangle this mess


getGeneratedPredicatePrefix

public String getGeneratedPredicatePrefix(int whereClauseSize)

establishDateString

public String establishDateString(String fromDate,
                                  String toDate,
                                  String tableName,
                                  String tableAlias,
                                  String colName,
                                  String whereStatementClause)

getDocumentSearchResultSetLimit

public int getDocumentSearchResultSetLimit()
Specified by:
getDocumentSearchResultSetLimit in interface DocumentSearchGenerator

isProcessResultSet

public boolean isProcessResultSet()
Description copied from interface: DocumentSearchGenerator
This method returns if processResultSet should be called.

Specified by:
isProcessResultSet in interface DocumentSearchGenerator
Returns:

setProcessResultSet

public void setProcessResultSet(boolean isProcessResultSet)
Specified by:
setProcessResultSet in interface DocumentSearchGenerator

getDbPlatform

public DatabasePlatform getDbPlatform()

getMessageMap

public MessageMap getMessageMap(DocSearchCriteriaDTO searchCriteria)
Specified by:
getMessageMap in interface DocumentSearchGenerator

getSqlBuilder

public SqlBuilder getSqlBuilder()
Returns:
the sqlBuilder

setSqlBuilder

public void setSqlBuilder(SqlBuilder sqlBuilder)
Parameters:
sqlBuilder - the sqlBuilder to set

isUsingAtLeastOneSearchAttribute

protected boolean isUsingAtLeastOneSearchAttribute()
A helper method for determining whether any searchable attributes are in use for the search. Subclasses can override this method to add their own logic for checking searchable attribute existence.

Returns:
True if the search criteria contains at least one searchable attribute or the criteria's doc type name is non-blank; false otherwise.


Copyright © 2004-2011 The Kuali Foundation. All Rights Reserved.