]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3900 Add query params on batch list to filter by supported docType and invocat...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Sat, 28 May 2011 03:23:31 +0000 (03:23 +0000)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Sat, 28 May 2011 03:23:31 +0000 (03:23 +0000)
services/IntegrationTests/src/test/resources/test-data/xmlreplay/batch/batch.xml
services/batch/service/src/main/java/org/collectionspace/services/batch/BatchResource.java
services/client/src/main/java/org/collectionspace/services/client/IQueryManager.java

index 9a61e97b6a6a500a7e3757c0d1f49f346517d3ba..308a9355043d3ea5a0d6d8e6062af942dcc202cf 100644 (file)
                                <var ID="CollObj1">${createBatch.CSID}</var>\r
                        </vars>\r
                </test>\r
+               <test ID="testFilteredList1" auth="test">\r
+                       <method>GET</method>\r
+                       <uri>/cspace-services/batch?doctype=CollectionObject&amp;inv=single</uri>\r
+               </test>\r
+               <test ID="testFilteredList2" auth="test">\r
+                       <method>GET</method>\r
+                       <uri>/cspace-services/batch?doctype=Intake&amp;inv=group</uri>\r
+               </test>\r
        </testGroup>\r
        <!-- \r
      <testGroup ID="cleanup" autoDeletePOSTS="true">\r
index 55ef6ff0d0de3a3178b6064e5cd66a6c1d45597f..c3b12682a8f33f0e4881a9dff9398541f0f21835 100644 (file)
@@ -27,6 +27,7 @@ import java.util.List;
 
 import org.collectionspace.services.BatchJAXBSchema;
 import org.collectionspace.services.client.BatchClient;
+import org.collectionspace.services.client.IQueryManager;
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.common.ResourceBase;
@@ -34,6 +35,7 @@ import org.collectionspace.services.common.ResourceMap;
 import org.collectionspace.services.common.ServiceMessages;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.BadRequestException;
+import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.document.ValidatorHandler;
@@ -41,18 +43,24 @@ import org.collectionspace.services.common.invocable.Invocable;
 import org.collectionspace.services.common.invocable.Invocable.InvocationError;
 import org.collectionspace.services.common.invocable.InvocationContext;
 import org.collectionspace.services.common.invocable.InvocationResults;
+import org.collectionspace.services.common.query.QueryManager;
 import org.jboss.resteasy.spi.ResteasyProviderFactory;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.collectionspace.services.common.ResourceMapHolder;
+import org.collectionspace.services.jaxb.AbstractCommonList;
 
+import javax.management.BadAttributeValueExpException;
 import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 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.Application;
 import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
@@ -62,6 +70,8 @@ import javax.ws.rs.core.UriInfo;
 public class BatchResource extends ResourceBase {
        
        protected final int BAD_REQUEST_STATUS = Response.Status.BAD_REQUEST.getStatusCode();
+       
+       protected final String COMMON_SCHEMA = "batch_common";
 
     @Override
     public String getServiceName(){
@@ -84,6 +94,89 @@ public class BatchResource extends ResourceBase {
         }
     }
     
+       /**
+        * Gets the authorityItem list for the specified authority
+        * If partialPerm is specified, keywords will be ignored.
+        * 
+        * @param specifier either a CSID or one of the urn forms
+        * @param partialTerm if non-null, matches partial terms
+        * @param keywords if non-null, matches terms in the keyword index for items
+        * @param ui passed to include additional parameters, like pagination controls
+        * 
+        * @return the authorityItem list
+        */
+       @GET
+       @Produces("application/xml")
+       public AbstractCommonList getBatchList(
+                       @QueryParam(IQueryManager.SEARCH_TYPE_DOCTYPE) String docType,
+                       @QueryParam(IQueryManager.SEARCH_TYPE_INVOCATION) String mode,
+                       @Context UriInfo ui) {
+        AbstractCommonList list;
+        if (docType != null && !docType.isEmpty() && mode != null && !mode.isEmpty()) {
+            list = search(ui.getQueryParameters(), docType, mode);
+        } else {
+            list = getList(ui);
+        }
+        return list;
+       }
+
+    protected AbstractCommonList search(MultivaluedMap<String, String> queryParams, 
+                                                                               String docType, String mode) {
+        try {
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(queryParams);
+            DocumentHandler handler = createDocumentHandler(ctx);
+            // perform a search by docType and invocation mode
+            DocumentFilter documentFilter = handler.getDocumentFilter();
+            if (docType != null && !docType.isEmpty()) {
+                String whereClause = createWhereClauseForDocType(docType);
+                documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND);
+            }
+            if (mode != null && !mode.isEmpty()) {
+                String whereClause = createWhereClauseForMode(mode);
+                documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND);
+            }
+            if (logger.isDebugEnabled()) {
+                logger.debug("The WHERE clause is: " + documentFilter.getWhereClause());
+            }
+            getRepositoryClient(ctx).getFiltered(ctx, handler);
+            return (AbstractCommonList) handler.getCommonPartList();
+        } catch (Exception e) {
+            throw bigReThrow(e, ServiceMessages.SEARCH_FAILED);
+        }
+    }
+    
+       private String createWhereClauseForDocType(String docType) {
+               String trimmed = (docType == null)?"":docType.trim(); 
+               if (trimmed.isEmpty()) {
+                       throw new RuntimeException("No docType specified.");
+               }
+               String ptClause = COMMON_SCHEMA + ":"
+               + BatchJAXBSchema.BATCH_FOR_DOC_TYPE
+                       + "='" + trimmed + "'";
+               return ptClause;
+       }
+
+       private String createWhereClauseForMode(String mode) throws BadRequestException {
+               String trimmed = (mode == null)?"":mode.trim(); 
+               if (trimmed.isEmpty()) {
+                       throw new RuntimeException("No mode specified.");
+               }
+               String ptClause = COMMON_SCHEMA + ":";
+               if(Invocable.INVOCATION_MODE_SINGLE.equalsIgnoreCase(trimmed)) {
+                       ptClause += BatchJAXBSchema.BATCH_SUPPORTS_SINGLE_DOC + "!=0";
+               } else if(Invocable.INVOCATION_MODE_LIST.equalsIgnoreCase(trimmed)) {
+                       ptClause += BatchJAXBSchema.BATCH_SUPPORTS_DOC_LIST + "!=0";
+               } else if(Invocable.INVOCATION_MODE_GROUP.equalsIgnoreCase(trimmed)) {
+                       ptClause += BatchJAXBSchema.BATCH_SUPPORTS_GROUP + "!=0";
+               } else {
+                       throw new BadRequestException("No mode specified.");
+               }
+               return ptClause;
+       }
+
+
+
+    
     @POST
     @Path("{csid}")
     public InvocationResults invokeBatchJob(
index 5be8e813d4fab074cfa61642b96dd3e7e53fe2bc..ee8b42708366388567f4ac103cab5c0e28cd293e 100644 (file)
@@ -35,6 +35,8 @@ public interface IQueryManager {
     final static String SEARCH_TYPE_KEYWORDS = "keywords";\r
     final static String SEARCH_TYPE_KEYWORDS_KW = "kw";\r
     final static String SEARCH_TYPE_PARTIALTERM = "pt";\r
+    final static String SEARCH_TYPE_DOCTYPE = "doctype";\r
+    final static String SEARCH_TYPE_INVOCATION = "inv";\r
        final static String ECM_FULLTEXT_LIKE = "ecm:fulltext" + SEARCH_TERM_SEPARATOR + SEARCH_LIKE;\r
        final static String SEARCH_QUALIFIER_AND = SEARCH_TERM_SEPARATOR + "AND" + SEARCH_TERM_SEPARATOR;\r
        final static String SEARCH_QUALIFIER_OR = SEARCH_TERM_SEPARATOR + "OR" + SEARCH_TERM_SEPARATOR;\r