From 15eb66910000eb165f63002c77c275e44fd0d1a1 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Tue, 4 Sep 2012 23:00:28 -0700 Subject: [PATCH] =?utf8?q?=20CSPACE-5488:=20Refactoring=20authority=20item?= =?utf8?q?=20partial=20term=20searches=20to=20work=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../common/vocabulary/AuthorityResource.java | 1 - .../services/common/ResourceBase.java | 43 ++++++++++++------- .../java/RemoteDocumentModelHandlerImpl.java | 10 +---- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index febb685fd..1852ce0f4 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -652,7 +652,6 @@ public abstract class AuthorityResource * Most of the authority child classes will/should use this implementation. However, the Vocabulary service's item schema is * different enough that it will have to override this method in it's resource class. */ - @Override protected String getOrderByField() { String result = null; diff --git a/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java index 8c21ffb1a..c6251add3 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java +++ b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java @@ -266,6 +266,8 @@ public abstract class ResourceBase MultivaluedMap queryParams = ui.getQueryParameters(); String keywords = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_KW); String advancedSearch = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_AS); + String partialTerm = queryParams.getFirst(IQueryManager.SEARCH_TYPE_PARTIALTERM); + AbstractCommonList list; if (keywords != null || advancedSearch != null) { list = search(queryParams, keywords, advancedSearch); @@ -300,29 +302,37 @@ public abstract class ResourceBase DocumentHandler handler, MultivaluedMap queryParams, String keywords, - String advancedSearch) throws Exception { + String advancedSearch, + String partialTerm) throws Exception { - // perform a keyword search - if (keywords != null && !keywords.isEmpty()) { + DocumentFilter docFilter = handler.getDocumentFilter(); + if (partialTerm != null && !partialTerm.isEmpty()) { + String partialTermMatchField = getPartialTermMatchField(); + String ptClause = QueryManager.createWhereClauseForPartialMatch( + partialTermMatchField, partialTerm); + docFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); + } else if (keywords != null && !keywords.isEmpty()) { String whereClause = QueryManager.createWhereClauseFromKeywords(keywords); - if(Tools.isEmpty(whereClause)) { - if (logger.isDebugEnabled()) { - logger.debug("The WHERE clause is empty for keywords: ["+keywords+"]"); - } - } else { - DocumentFilter documentFilter = handler.getDocumentFilter(); - documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND); + if (Tools.isEmpty(whereClause) == false) { + docFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND); if (logger.isDebugEnabled()) { - logger.debug("The WHERE clause is: " + documentFilter.getWhereClause()); + logger.debug("The WHERE clause is: " + docFilter.getWhereClause()); } + } else { + if (logger.isWarnEnabled()) { + logger.warn("The WHERE clause is empty for keywords: ["+keywords+"]"); + } } } + + // + // Add an advance search clause if one was specified + // if (advancedSearch != null && !advancedSearch.isEmpty()) { String whereClause = QueryManager.createWhereClauseFromAdvancedSearch(advancedSearch); - DocumentFilter documentFilter = handler.getDocumentFilter(); - documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND); + docFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND); if (logger.isDebugEnabled()) { - logger.debug("The WHERE clause is: " + documentFilter.getWhereClause()); + logger.debug("The WHERE clause is: " + docFilter.getWhereClause()); } } getRepositoryClient(ctx).getFiltered(ctx, handler); @@ -332,13 +342,14 @@ public abstract class ResourceBase protected AbstractCommonList search(MultivaluedMap queryParams, String keywords, - String advancedSearch) { + String advancedSearch, + String partialTerm) { ServiceContext ctx; AbstractCommonList result = null; try { ctx = createServiceContext(queryParams); DocumentHandler handler = createDocumentHandler(ctx); - result = search(ctx, handler, queryParams, keywords, advancedSearch); + result = search(ctx, handler, queryParams, keywords, advancedSearch, partialTerm); } catch (Exception e) { throw bigReThrow(e, ServiceMessages.SEARCH_FAILED); } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index f4d1f4598..2572d92e8 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -50,6 +50,7 @@ import org.collectionspace.services.client.RelationClient; import org.collectionspace.services.client.workflow.WorkflowClient; import org.collectionspace.services.common.ResourceBase; import org.collectionspace.services.common.authorityref.AuthorityRefList; +import org.collectionspace.services.common.config.ServiceConfigUtils; import org.collectionspace.services.common.context.JaxRsContext; import org.collectionspace.services.common.context.MultipartServiceContext; import org.collectionspace.services.common.context.ServiceBindingUtils; @@ -125,14 +126,7 @@ public abstract class RemoteDocumentModelHandlerImpl * tenant bindings config file. */ public DocHandlerParams.Params getDocHandlerParams() throws DocumentException { - MultipartServiceContext sc = (MultipartServiceContext) getServiceContext(); - ServiceBindingType sb = sc.getServiceBinding(); - DocHandlerParams dhb = sb.getDocHandlerParams(); - if (dhb != null && dhb.getParams() != null) { - return dhb.getParams(); - } - throw new DocumentException("No DocHandlerParams configured for: " - + sb.getName()); + return ServiceConfigUtils.getDocHandlerParams(this.getServiceContext()); } @Override -- 2.47.3