]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-682: CSPACE-683: Keyword search support for Acquisitions and Intakes.
authorRichard Millet <richard.millet@berkeley.edu>
Mon, 21 Dec 2009 18:00:25 +0000 (18:00 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Mon, 21 Dec 2009 18:00:25 +0000 (18:00 +0000)
services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java
services/common/src/main/java/org/collectionspace/services/common/query/IQueryManager.java
services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java

index aa722c1b6013eead07f2cc376f6f6ed594a6b253..cfc53eedd8840da1466e3d1a09950726e4ef994c 100644 (file)
@@ -31,6 +31,7 @@ import javax.ws.rs.DELETE;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
 import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
@@ -38,12 +39,16 @@ import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.acquisition.nuxeo.AcquisitionHandlerFactory;
+import org.collectionspace.services.acquisition.AcquisitionsCommonList;
 import org.collectionspace.services.common.AbstractCollectionSpaceResource;
 import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.context.MultipartServiceContextFactory;
 import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
 import org.collectionspace.services.common.document.DocumentHandler;
+import org.collectionspace.services.common.query.IQueryManager;
+import org.collectionspace.services.common.query.QueryManager;
 import org.collectionspace.services.common.security.UnauthorizedException;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
@@ -261,6 +266,45 @@ public class AcquisitionResource
                     Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
             throw new WebApplicationException(response);
         }
-
     }
+    
+    @GET
+    @Path("/search")    
+    @Produces("application/xml")
+    public AcquisitionsCommonList keywordsSearchAcquisitions(@Context UriInfo ui,
+               @QueryParam (IQueryManager.SEARCH_TYPE_KEYWORDS) String keywords) {
+       AcquisitionsCommonList acquisitionObjectList = new AcquisitionsCommonList();
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            DocumentHandler handler = createDocumentHandler(ctx);
+
+            // perform a keyword search
+            if (keywords != null && !keywords.isEmpty()) {
+               String whereClause = QueryManager.createWhereClauseFromKeywords(keywords);
+                   DocumentFilter documentFilter = handler.getDocumentFilter();
+                   documentFilter.setWhereClause(whereClause);
+                   if (logger.isDebugEnabled()) {
+                       logger.debug("The WHERE clause is: " + documentFilter.getWhereClause());
+                   }
+                   getRepositoryClient(ctx).getFiltered(ctx, handler);
+            } else {
+               getRepositoryClient(ctx).getAll(ctx, handler);
+            }            
+            acquisitionObjectList = (AcquisitionsCommonList) handler.getCommonPartList();
+            
+        } catch (UnauthorizedException ue) {
+            Response response = Response.status(
+                    Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
+            throw new WebApplicationException(response);
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Caught exception in search for Acquisitions", e);
+            }
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        return acquisitionObjectList;
+    }    
+    
 }
index 21b412ae67650c2b982cd93b115c094dc9911011..f5b76e18a8866dc4b274ca3b760379603c6cfac3 100644 (file)
@@ -43,6 +43,7 @@ import java.util.HashMap;
 import java.util.StringTokenizer;
 
 import org.collectionspace.services.common.query.QueryManager;
+import org.collectionspace.services.common.query.IQueryManager;
 import org.collectionspace.services.collectionobject.nuxeo.CollectionObjectHandlerFactory;
 import org.collectionspace.services.common.AbstractCollectionSpaceResource;
 import org.collectionspace.services.common.context.MultipartServiceContext;
@@ -66,11 +67,6 @@ public class CollectionObjectResource
 
     final private String serviceName = "collectionobjects";
     final Logger logger = LoggerFactory.getLogger(CollectionObjectResource.class);
-    final private static String SEARCH_TYPE_KEYWORDS = "keywords";
-    final private static String ECM_FULLTEXT_LIKE = "ecm:fulltext LIKE ";
-    final private static String SEARCH_QUALIFIER_AND = "AND";
-    final private static String SEARCH_QUALIFIER_OR = "OR";
-    final private static String SEARCH_TERM_SEPARATOR = " ";
 
     @Override
     public String getServiceName() {
@@ -272,7 +268,7 @@ public class CollectionObjectResource
     @Path("/search")    
     @Produces("application/xml")
     public CollectionobjectsCommonList keywordsSearchCollectionObjects(@Context UriInfo ui,
-               @QueryParam (SEARCH_TYPE_KEYWORDS) String keywords) {
+               @QueryParam (IQueryManager.SEARCH_TYPE_KEYWORDS) String keywords) {
         CollectionobjectsCommonList collectionObjectList = new CollectionobjectsCommonList();
         try {
             ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
index d83d7a4a047f7d11baf1407a34d587fe6b97e988..017d2aac0c6e4b778aed675b67f83374810ec00f 100644 (file)
@@ -28,6 +28,7 @@ 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_QUALIFIER_AND = "AND";\r
        final static String SEARCH_QUALIFIER_OR = "OR";\r
index f05003f0c22265f8e88d9d4a1373cfbf3ae4181d..b41f13b03b16909d7599155f4a635b7b4d90ed37 100644 (file)
@@ -31,14 +31,15 @@ import javax.ws.rs.DELETE;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
 import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
+import org.collectionspace.services.intake.IntakesCommonList;
 import org.collectionspace.services.common.AbstractCollectionSpaceResource;
-import org.collectionspace.services.intake.IntakesCommonList.*;
 
 import org.collectionspace.services.intake.nuxeo.IntakeHandlerFactory;
 import org.collectionspace.services.common.ClientType;
@@ -46,8 +47,11 @@ import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.context.MultipartServiceContextFactory;
 import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
 import org.collectionspace.services.common.document.DocumentHandler;
+import org.collectionspace.services.common.query.IQueryManager;
+import org.collectionspace.services.common.query.QueryManager;
 import org.collectionspace.services.common.security.UnauthorizedException;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
@@ -262,6 +266,45 @@ public class IntakeResource extends AbstractCollectionSpaceResource {
                     Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
             throw new WebApplicationException(response);
         }
-
     }
+    
+    @GET
+    @Path("/search")    
+    @Produces("application/xml")
+    public IntakesCommonList keywordsSearchIntakes(@Context UriInfo ui,
+               @QueryParam (IQueryManager.SEARCH_TYPE_KEYWORDS) String keywords) {
+       IntakesCommonList intakesObjectList = new IntakesCommonList();
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            DocumentHandler handler = createDocumentHandler(ctx);
+
+            // perform a keyword search
+            if (keywords != null && !keywords.isEmpty()) {
+               String whereClause = QueryManager.createWhereClauseFromKeywords(keywords);
+                   DocumentFilter documentFilter = handler.getDocumentFilter();
+                   documentFilter.setWhereClause(whereClause);
+                   if (logger.isDebugEnabled()) {
+                       logger.debug("The WHERE clause is: " + documentFilter.getWhereClause());
+                   }
+                   getRepositoryClient(ctx).getFiltered(ctx, handler);
+            } else {
+               getRepositoryClient(ctx).getAll(ctx, handler);
+            }            
+            intakesObjectList = (IntakesCommonList) handler.getCommonPartList();
+            
+        } catch (UnauthorizedException ue) {
+            Response response = Response.status(
+                    Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
+            throw new WebApplicationException(response);
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Caught exception in search for Intakes", e);
+            }
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        return intakesObjectList;
+    }    
+    
 }