From: Richard Millet Date: Tue, 12 Jan 2010 21:56:48 +0000 (+0000) Subject: CSPACE-738: Adding term search for Vocabulary service based on Display name. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=6012391d86264bf0158814324c54271d71ad626e;p=tmp%2Fjakarta-migration.git CSPACE-738: Adding term search for Vocabulary service based on Display name. --- diff --git a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java index 3750ce684..79efa94a2 100644 --- a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java +++ b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java @@ -40,11 +40,6 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; -import java.util.Map; -import java.util.HashMap; -import java.util.StringTokenizer; - -import org.collectionspace.services.common.Version; import org.collectionspace.services.common.query.QueryManager; import org.collectionspace.services.common.query.IQueryManager; import org.collectionspace.services.collectionobject.nuxeo.CollectionObjectHandlerFactory; 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 9c768be33..0379f140b 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 @@ -18,8 +18,8 @@ package org.collectionspace.services.common.document; import java.util.List; - import javax.ws.rs.core.MultivaluedMap; +import org.collectionspace.services.common.query.IQueryManager; /** * DocumentFilter bundles simple query filtering parameters. @@ -100,6 +100,14 @@ public class DocumentFilter { this.whereClause = whereClause; } + public void appendWhereClause(String whereClause) { + String currentClause = getWhereClause(); + if (currentClause != null) { + String newClause = currentClause.concat(IQueryManager.SEARCH_TERM_SEPARATOR + whereClause); + this.setWhereClause(newClause); + } + } + /** * @return the specified (0-based) page offset */ diff --git a/services/common/src/main/java/org/collectionspace/services/common/query/IQueryManager.java b/services/common/src/main/java/org/collectionspace/services/common/query/IQueryManager.java index 017d2aac0..886c3431a 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/query/IQueryManager.java +++ b/services/common/src/main/java/org/collectionspace/services/common/query/IQueryManager.java @@ -28,8 +28,10 @@ package org.collectionspace.services.common.query; public interface IQueryManager { - final static String SEARCH_TYPE_KEYWORDS = "keywords"; - final static String ECM_FULLTEXT_LIKE = "ecm:fulltext LIKE "; + final static String SEARCH_LIKE = "LIKE"; + final static String SEARCH_TYPE_KEYWORDS = "keywords"; + final static String SEARCH_TYPE_PARTIALTERM = "pt"; + final static String ECM_FULLTEXT_LIKE = "ecm:fulltext " + SEARCH_LIKE; final static String SEARCH_QUALIFIER_AND = "AND"; final static String SEARCH_QUALIFIER_OR = "OR"; final static String SEARCH_TERM_SEPARATOR = " "; diff --git a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java index 584672463..4d386bb7b 100644 --- a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java +++ b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java @@ -8,6 +8,7 @@ package org.collectionspace.services; * */ public interface VocabularyItemJAXBSchema { + final static String VOCABULARYITEMS_COMMON="vocabularyitems_common"; final static String DISPLAY_NAME = "displayName"; final static String IN_VOCABULARY = "inVocabulary"; final static String REF_NAME = "refName"; diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java index 88fed1956..4181899eb 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java @@ -31,6 +31,7 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; import javax.ws.rs.core.MultivaluedMap; @@ -38,6 +39,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; +import org.collectionspace.services.VocabularyItemJAXBSchema; import org.collectionspace.services.common.AbstractCollectionSpaceResource; import org.collectionspace.services.common.ClientType; import org.collectionspace.services.common.ServiceMain; @@ -47,7 +49,9 @@ import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentHandler; import org.collectionspace.services.common.document.DocumentNotFoundException; +import org.collectionspace.services.common.query.IQueryManager; import org.collectionspace.services.common.security.UnauthorizedException; +import org.collectionspace.services.common.query.IQueryManager; import org.collectionspace.services.vocabulary.nuxeo.VocabularyHandlerFactory; import org.collectionspace.services.vocabulary.nuxeo.VocabularyItemDocumentModelHandler; import org.collectionspace.services.vocabulary.nuxeo.VocabularyItemHandlerFactory; @@ -403,6 +407,7 @@ public class VocabularyResource extends AbstractCollectionSpaceResource { @Produces("application/xml") public VocabularyitemsCommonList getVocabularyItemList( @PathParam("csid") String parentcsid, + @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm, @Context UriInfo ui) { VocabularyitemsCommonList vocabularyItemObjectList = new VocabularyitemsCommonList(); try { @@ -412,10 +417,30 @@ public class VocabularyResource extends AbstractCollectionSpaceResource { MultivaluedMap queryParams = ui.getQueryParameters(); DocumentFilter myFilter = DocumentFilter.CreatePaginatedDocumentFilter(queryParams); + // "vocabularyitems_common:inVocabulary='" + parentcsid + "'"); myFilter.setWhereClause( - "vocabularyitems_common:inVocabulary='" + parentcsid + "'"); + VocabularyItemJAXBSchema.VOCABULARYITEMS_COMMON + ":" + + VocabularyItemJAXBSchema.IN_VOCABULARY + "=" + + "'" + parentcsid + "'"); + + // AND vocabularyitems_common:displayName LIKE '%partialTerm%' + if (partialTerm != null && !partialTerm.isEmpty()) { + String ptClause = "AND " + + VocabularyItemJAXBSchema.VOCABULARYITEMS_COMMON + ":" + + VocabularyItemJAXBSchema.DISPLAY_NAME + + " LIKE " + + "'%" + partialTerm + "%'"; + myFilter.appendWhereClause(ptClause); + } + + if (logger.isDebugEnabled()) { + logger.debug("getVocabularyItemList filtered WHERE clause: " + + myFilter.getWhereClause()); + } + handler.setDocumentFilter(myFilter); getRepositoryClient(ctx).getFiltered(ctx, handler); + vocabularyItemObjectList = (VocabularyitemsCommonList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { Response response = Response.status(