From ebfcaa618e4044ef9114926a817ccfd348aba2f9 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Wed, 5 Sep 2012 00:19:08 -0700 Subject: [PATCH] CSPACE-5488: More refactoring authority item partial term searches to work in resource super classes. --- .../common/vocabulary/AuthorityResource.java | 56 +++++-------------- .../services/client/CollectionSpaceProxy.java | 2 +- .../services/client/IClientQueryParams.java | 2 +- .../services/common/ResourceBase.java | 52 +++++++++++------ .../common/document/DocumentFilter.java | 2 +- .../query/nuxeo/QueryManagerNuxeoImpl.java | 2 +- .../nuxeo/client/java/DocHandlerBase.java | 30 ++++++---- .../java/RemoteDocumentModelHandlerImpl.java | 3 +- .../services/client/MovementProxy.java | 4 +- .../services/client/RelationProxy.java | 2 +- .../vocabulary/VocabularyResource.java | 9 ++- 11 files changed, 84 insertions(+), 80 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 1493735ad..9342cce0d 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 @@ -429,7 +429,7 @@ public abstract class AuthorityResource DocumentFilter myFilter = handler.getDocumentFilter(); // Need to make the default sort order for authority items // be on the displayName field - String sortBy = queryParams.getFirst(IClientQueryParams.SORT_BY_PARAM); + String sortBy = queryParams.getFirst(IClientQueryParams.ORDER_BY_PARAM); if (sortBy == null || sortBy.isEmpty()) { String qualifiedDisplayNameField = authorityCommonSchemaName + ":" + AuthorityItemJAXBSchema.DISPLAY_NAME; @@ -690,36 +690,27 @@ public abstract class AuthorityResource @Produces("application/xml") public AbstractCommonList getAuthorityItemList(@PathParam("csid") String specifier, @Context UriInfo ui) { + AbstractCommonList result = null; + try { MultivaluedMap queryParams = ui.getQueryParameters(); - String partialTerm = queryParams.getFirst(IQueryManager.SEARCH_TYPE_PARTIALTERM); + String orderBy = queryParams.getFirst(IClientQueryParams.ORDER_BY_PARAM); String termStatus = queryParams.getFirst(SEARCH_TYPE_TERMSTATUS); 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); - // Note that docType defaults to the ServiceName, so we're fine with that. - ServiceContext ctx = null; - - String parentcsid = PARENT_WILDCARD.equals(specifier)?null: - lookupParentCSID(specifier, "getAuthorityItemList", "LIST", queryParams); - - ctx = createServiceContext(getItemServiceName(), queryParams); - + ServiceContext ctx = createServiceContext(getItemServiceName(), queryParams); // For the wildcard case, parentcsid is null, but docHandler will deal with this. // We omit the parentShortId, only needed when doing a create... - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, null); + String parentcsid = PARENT_WILDCARD.equals(specifier) ? null : + lookupParentCSID(specifier, "getAuthorityItemList", "LIST", queryParams); + DocumentHandler handler = + createItemDocumentHandler(ctx, parentcsid, null); DocumentFilter myFilter = handler.getDocumentFilter(); - // Need to make the default sort order for authority items - // be on the displayName field - String sortBy = queryParams.getFirst(IClientQueryParams.SORT_BY_PARAM); - if (sortBy == null || sortBy.isEmpty()) { - String orderByField = getOrderByField(); - myFilter.setOrderByClause(orderByField); - } - // If we are not wildcarding the parent, add a restriction - if(parentcsid!=null) { + if (parentcsid != null) { myFilter.appendWhereClause(authorityItemCommonSchemaName + ":" + AuthorityItemJAXBSchema.IN_AUTHORITY + "=" + "'" + parentcsid + "'", @@ -734,30 +725,13 @@ public abstract class AuthorityResource String tsClause = QueryManager.createWhereClauseToFilterFromStringList(qualifiedTermStatusField, filterTerms, IQueryManager.FILTER_EXCLUDE); myFilter.appendWhereClause(tsClause, IQueryManager.SEARCH_QUALIFIER_AND); } - - // AND vocabularyitems_common:displayName LIKE '%partialTerm%' - // NOTE: Partial terms searches are mutually exclusive to keyword and advanced-search, but - // the PT query param trumps the KW and AS query params. - if (partialTerm != null && !partialTerm.isEmpty()) { - String partialTermMatchField = getPartialTermMatchField(); - String ptClause = QueryManager.createWhereClauseForPartialMatch( - partialTermMatchField, partialTerm); - myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); - } else if (keywords != null || advancedSearch != null) { -// String kwdClause = QueryManager.createWhereClauseFromKeywords(keywords); -// myFilter.appendWhereClause(kwdClause, IQueryManager.SEARCH_QUALIFIER_AND); - return search(ctx, handler, queryParams, keywords, advancedSearch); - } - if (logger.isDebugEnabled()) { - logger.debug("getAuthorityItemList filtered WHERE clause: " - + myFilter.getWhereClause() - + " and ORDER BY clause: " + myFilter.getOrderByClause()); - } - getRepositoryClient(ctx).getFiltered(ctx, handler); - return handler.getCommonPartList(); + + result = search(ctx, handler, queryParams, orderBy, keywords, advancedSearch, partialTerm); } catch (Exception e) { throw bigReThrow(e, ServiceMessages.LIST_FAILED); } + + return result; } /** diff --git a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceProxy.java b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceProxy.java index 18acc9ece..c9dbdda6e 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceProxy.java +++ b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceProxy.java @@ -102,7 +102,7 @@ public interface CollectionSpaceProxy { @GET @Produces({"application/xml"}) ClientResponse readList( - @QueryParam(IClientQueryParams.SORT_BY_PARAM) String sortBy, + @QueryParam(IClientQueryParams.ORDER_BY_PARAM) String sortBy, @QueryParam(IClientQueryParams.PAGE_SIZE_PARAM) Long pageSize, @QueryParam(IClientQueryParams.START_PAGE_PARAM) Long pageNumber); } diff --git a/services/client/src/main/java/org/collectionspace/services/client/IClientQueryParams.java b/services/client/src/main/java/org/collectionspace/services/client/IClientQueryParams.java index 40a67a8b8..2401c6119 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/IClientQueryParams.java +++ b/services/client/src/main/java/org/collectionspace/services/client/IClientQueryParams.java @@ -30,7 +30,7 @@ public interface IClientQueryParams { public static final String PAGE_SIZE_PARAM = "pgSz"; public static final String START_PAGE_PARAM = "pgNum"; - public static final String SORT_BY_PARAM = "sortBy"; + public static final String ORDER_BY_PARAM = "sortBy"; public static final String IMPORT_TIMEOUT_PARAM = "impTimout"; } 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 32a43a5a3..dc113ace2 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 @@ -23,6 +23,7 @@ */ package org.collectionspace.services.common; +import org.collectionspace.services.client.IClientQueryParams; import org.collectionspace.services.client.IQueryManager; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; @@ -267,13 +268,14 @@ public abstract class ResourceBase @GET public AbstractCommonList getList(@Context UriInfo ui) { MultivaluedMap queryParams = ui.getQueryParameters(); + String orderBy = queryParams.getFirst(IClientQueryParams.ORDER_BY_PARAM); 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); + list = search(queryParams, orderBy, keywords, advancedSearch, partialTerm); } else { list = getList(queryParams); } @@ -301,16 +303,26 @@ public abstract class ResourceBase } } - protected AbstractCommonList search(ServiceContext ctx, + protected AbstractCommonList search( + ServiceContext ctx, DocumentHandler handler, MultivaluedMap queryParams, + String orderBy, String keywords, String advancedSearch, String partialTerm) throws Exception { + DocumentFilter docFilter = handler.getDocumentFilter(); + if (orderBy == null || orderBy.isEmpty()) { + String orderByField = getOrderByField(ctx); + docFilter.setOrderByClause(orderByField); + } - DocumentFilter docFilter = handler.getDocumentFilter(); + // + //NOTE: Partial-term (PT) searches are mutually exclusive to keyword and advanced-search, but + // the PT query param trumps the keyword search. + // if (partialTerm != null && !partialTerm.isEmpty()) { - String partialTermMatchField = getPartialTermMatchField(); + String partialTermMatchField = getPartialTermMatchField(ctx); String ptClause = QueryManager.createWhereClauseForPartialMatch( partialTermMatchField, partialTerm); docFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); @@ -327,9 +339,9 @@ public abstract class ResourceBase } } } - + // - // Add an advance search clause if one was specified + // Add an advance search clause if one was specified -even if PT search was requested? // if (advancedSearch != null && !advancedSearch.isEmpty()) { String whereClause = QueryManager.createWhereClauseFromAdvancedSearch(advancedSearch); @@ -338,25 +350,29 @@ public abstract class ResourceBase logger.debug("The WHERE clause is: " + docFilter.getWhereClause()); } } - getRepositoryClient(ctx).getFiltered(ctx, handler); + getRepositoryClient(ctx).getFiltered(ctx, handler); return (AbstractCommonList) handler.getCommonPartList(); } - protected AbstractCommonList search(MultivaluedMap queryParams, + private AbstractCommonList search( + MultivaluedMap queryParams, + String orderBy, String keywords, String advancedSearch, String partialTerm) { - ServiceContext ctx; - AbstractCommonList result = null; - try { - ctx = createServiceContext(queryParams); - DocumentHandler handler = createDocumentHandler(ctx); - result = search(ctx, handler, queryParams, keywords, advancedSearch, partialTerm); - } catch (Exception e) { - throw bigReThrow(e, ServiceMessages.SEARCH_FAILED); - } - return result; + AbstractCommonList result = null; + + ServiceContext ctx; + try { + ctx = createServiceContext(queryParams); + DocumentHandler handler = createDocumentHandler(ctx); + result = search(ctx, handler, queryParams, orderBy, keywords, advancedSearch, partialTerm); + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.SEARCH_FAILED); + } + + return result; } //FIXME: REM - This should not be @Deprecated since we may want to implement this -it has been on the wish list. diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java index 1ff4415ea..c839030a6 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java @@ -274,7 +274,7 @@ public class DocumentFilter { } // Set the order by clause String orderByStr = null; - List list = theQueryParams.get(IClientQueryParams.SORT_BY_PARAM); + List list = theQueryParams.get(IClientQueryParams.ORDER_BY_PARAM); if (list != null) { orderByStr = list.get(0); } diff --git a/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java b/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java index d5ecc3305..61715b354 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java @@ -339,7 +339,7 @@ public class QueryManagerNuxeoImpl implements IQueryManager { public String createWhereClauseToFilterFromStringList(String qualifiedField, String[] filterTerms, boolean fExclude) { // Start with the qualified termStatus field StringBuilder filterClause = new StringBuilder(qualifiedField); - if(filterTerms.length == 1) { + if (filterTerms.length == 1) { filterClause.append(fExclude?" <> '":" = '"); filterClause.append(filterTerms[0]); filterClause.append('\''); diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java index abf6e796d..b8cdda1a5 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java @@ -38,7 +38,9 @@ import org.collectionspace.services.client.IRelationsManager; import org.collectionspace.services.common.ReflectionMapper; import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils; import org.collectionspace.services.common.api.Tools; +import org.collectionspace.services.common.config.ServiceConfigUtils; import org.collectionspace.services.common.context.AbstractServiceContextImpl; +import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentException; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.query.QueryContext; @@ -110,7 +112,8 @@ public abstract class DocHandlerBase extends RemoteDocumentModelHandlerImpl extends RemoteDocumentModelHandlerImpl getListItemsArray() throws DocumentException { - return getDocHandlerParams().getListResultsFields().getListResultField(); + ServiceContext ctx = this.getServiceContext(); + return ServiceConfigUtils.getDocHandlerParams(ctx).getListResultsFields().getListResultField(); } @Override @@ -270,7 +278,8 @@ public abstract class DocHandlerBase extends RemoteDocumentModelHandlerImpl extends RemoteDocumentModelHandlerImpl wrapDoc) throws Exception { DocHandlerParams.Params docHandlerParams = null; try { - docHandlerParams = getDocHandlerParams(); + docHandlerParams = ServiceConfigUtils.getDocHandlerParams(getServiceContext()); } catch (Exception e) { logger.warn(e.getMessage()); } if (docHandlerParams != null) { - String title = getDocHandlerParams().getDublinCoreTitle(); + String title = docHandlerParams.getDublinCoreTitle(); if (Tools.isEmpty(title) == false){ DocumentModel docModel = wrapDoc.getWrappedObject(); docModel.setPropertyValue("dublincore:title", title); @@ -350,8 +359,9 @@ public abstract class DocHandlerBase extends RemoteDocumentModelHandlerImpl DocHandlerParams.Params params = null; try { - params = getDocHandlerParams(); + ServiceContext ctx = this.getServiceContext(); + params = ServiceConfigUtils.getDocHandlerParams(ctx); Boolean bool = params.isSupportsHierarchy(); if (bool != null) { result = bool.booleanValue(); diff --git a/services/movement/client/src/main/java/org/collectionspace/services/client/MovementProxy.java b/services/movement/client/src/main/java/org/collectionspace/services/client/MovementProxy.java index 3fc883d2a..d5554a5d9 100644 --- a/services/movement/client/src/main/java/org/collectionspace/services/client/MovementProxy.java +++ b/services/movement/client/src/main/java/org/collectionspace/services/client/MovementProxy.java @@ -49,7 +49,7 @@ public interface MovementProxy extends CollectionSpaceCommonListPoxProxy { @GET @Produces({"application/xml"}) ClientResponse readListSortedBy( - @QueryParam(IClientQueryParams.SORT_BY_PARAM) String sortFieldName); + @QueryParam(IClientQueryParams.ORDER_BY_PARAM) String sortFieldName); @Override @GET @@ -68,5 +68,5 @@ public interface MovementProxy extends CollectionSpaceCommonListPoxProxy { @Produces({"application/xml"}) ClientResponse keywordSearchSortedBy( @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords, - @QueryParam(IClientQueryParams.SORT_BY_PARAM) String sortFieldName); + @QueryParam(IClientQueryParams.ORDER_BY_PARAM) String sortFieldName); } diff --git a/services/relation/client/src/main/java/org/collectionspace/services/client/RelationProxy.java b/services/relation/client/src/main/java/org/collectionspace/services/client/RelationProxy.java index 9a31e066e..0ea4d843d 100644 --- a/services/relation/client/src/main/java/org/collectionspace/services/client/RelationProxy.java +++ b/services/relation/client/src/main/java/org/collectionspace/services/client/RelationProxy.java @@ -54,7 +54,7 @@ public interface RelationProxy extends CollectionSpacePoxProxy ctx) { String result = null; result = authorityItemCommonSchemaName + ":" + VocabularyItemJAXBSchema.DISPLAY_NAME; @@ -87,8 +90,8 @@ public class VocabularyResource extends } @Override - protected String getPartialTermMatchField() { - return getOrderByField(); + protected String getPartialTermMatchField(ServiceContext ctx) { + return getOrderByField(ctx); } /* -- 2.47.3