]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-738: Adding term search for Vocabulary service based on Display name.
authorRichard Millet <richard.millet@berkeley.edu>
Tue, 12 Jan 2010 21:56:48 +0000 (21:56 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Tue, 12 Jan 2010 21:56:48 +0000 (21:56 +0000)
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java
services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java
services/common/src/main/java/org/collectionspace/services/common/query/IQueryManager.java
services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java
services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java

index 3750ce684c51c1d444c15a6b92fa800deee362bd..79efa94a2249462349b5c7d51c94f61aeb17b7a2 100644 (file)
@@ -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;
index 9c768be338a54df754765485b4515e04bbe36b13..0379f140b0baedd3271a085354536ee8cb7c2d87 100644 (file)
@@ -18,8 +18,8 @@
 package org.collectionspace.services.common.document;\r
 \r
 import java.util.List;\r
-\r
 import javax.ws.rs.core.MultivaluedMap;\r
+import org.collectionspace.services.common.query.IQueryManager;\r
 \r
 /**\r
  * DocumentFilter bundles simple query filtering parameters. \r
@@ -100,6 +100,14 @@ public class DocumentFilter {
                this.whereClause = whereClause;\r
        }\r
        \r
+       public void appendWhereClause(String whereClause) {\r
+               String currentClause = getWhereClause();\r
+               if (currentClause != null) {\r
+                       String newClause = currentClause.concat(IQueryManager.SEARCH_TERM_SEPARATOR + whereClause);\r
+                       this.setWhereClause(newClause);\r
+               }\r
+       }\r
+       \r
        /**\r
         * @return the specified (0-based) page offset  \r
         */\r
index 017d2aac0c6e4b778aed675b67f83374810ec00f..886c3431a8341c5144b3e39f9ea5d723dcbdd5e5 100644 (file)
@@ -28,8 +28,10 @@ package org.collectionspace.services.common.query;
 \r
 public interface IQueryManager {\r
        \r
-    final static String SEARCH_TYPE_KEYWORDS = "keywords";     \r
-       final static String ECM_FULLTEXT_LIKE = "ecm:fulltext LIKE ";\r
+       final static String SEARCH_LIKE = "LIKE";\r
+    final static String SEARCH_TYPE_KEYWORDS = "keywords";\r
+    final static String SEARCH_TYPE_PARTIALTERM = "pt";\r
+       final static String ECM_FULLTEXT_LIKE = "ecm:fulltext " + SEARCH_LIKE;\r
        final static String SEARCH_QUALIFIER_AND = "AND";\r
        final static String SEARCH_QUALIFIER_OR = "OR";\r
        final static String SEARCH_TERM_SEPARATOR = " ";\r
index 58467246336ed33e8e96a69e31a3ff8758936936..4d386bb7b680bb36551e498b51b016bf1f3bf6fb 100644 (file)
@@ -8,6 +8,7 @@ package org.collectionspace.services;
  *\r
  */\r
 public interface VocabularyItemJAXBSchema {\r
+       final static String VOCABULARYITEMS_COMMON="vocabularyitems_common";\r
        final static String DISPLAY_NAME = "displayName";\r
        final static String IN_VOCABULARY = "inVocabulary";\r
        final static String REF_NAME = "refName";\r
index 88fed1956daada909307b9c228774cea1b7cf3d0..4181899eb4cc8996040cb420ceaa2daacdf54891 100644 (file)
@@ -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<String, String> 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(