]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6826: Reindex for a single resource type or a single document now supported.
authorremillet <remillet@yahoo.com>
Mon, 28 Mar 2016 21:50:14 +0000 (14:50 -0700)
committerremillet <remillet@yahoo.com>
Mon, 28 Mar 2016 21:50:14 +0000 (14:50 -0700)
15 files changed:
services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java
services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java
services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java
services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java
services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java
services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java
services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java
services/common/src/main/java/org/collectionspace/services/common/security/SecurityUtils.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/CSReindexFulltextRoot.java [deleted file]
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryClientImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/util/CSReindexFulltextRoot.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java
services/common/src/main/java/org/collectionspace/services/nuxeo/util/ReindexFulltextRoot.java
services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java

index 6856a80cb874c61a87908f9d37eb9147c61dc32a..66c72036e72d5a278a24da4a41324d157a3eadf6 100644 (file)
@@ -101,14 +101,14 @@ public abstract class NuxeoBasedResource
             @Context UriInfo uriInfo,
             @PathParam("csid") String csid,
             @PathParam("indexid") String indexid) {
-               Response result = Response.noContent().build();
+               Response result = Response.status(Response.Status.OK).entity("Reindex complete.").type("text/plain").build();
                boolean success = false;
                
         ensureCSID(csid, READ);
         try {
             RemoteServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = (RemoteServiceContext<PoxPayloadIn, PoxPayloadOut>) createServiceContext(uriInfo);
             DocumentHandler handler = createDocumentHandler(ctx);
-            success = getRepositoryClient(ctx).reindex(handler, csid);
+            success = getRepositoryClient(ctx).reindex(handler, csid, indexid);
         } catch (Exception e) {
             throw bigReThrow(e, ServiceMessages.REINDEX_FAILED, csid);
         }
@@ -129,7 +129,7 @@ public abstract class NuxeoBasedResource
             @Context Request request,
             @Context UriInfo uriInfo,
             @PathParam("indexid") String indexid) {
-               Response result = Response.noContent().build();;
+               Response result = Response.noContent().build();
                boolean success = false;
                String docType = null;
                
index 2d37eb5aaa37ad9010ea8986550d6d79fd4b8998..55f2cafb30d8acfc0a12bcf5fa36b04ab21671a2 100644 (file)
@@ -429,6 +429,16 @@ public abstract class AbstractDocumentHandlerImpl<T, TL, WT, WTL>
         tkz.nextToken(); //skip
         return tkz.nextToken();
     }
+    
+    /**
+     * Should return
+     * @throws Exception 
+     * @throws DocumentException 
+     */
+    @Override
+    public String getDocumentsToIndexQuery(String indexId, String csid) throws DocumentException, Exception {
+       return null;
+    }
 
     /* (non-Javadoc)
      * @see org.collectionspace.services.common.document.DocumentHandler#getServiceContextPath()
index e7a9e2cc48a48279a738a1d3f3b6ba7f2c556082..b2c2150ad70eeb84f2b7eda1eddcb78bf45515e5 100644 (file)
@@ -36,11 +36,14 @@ public abstract class DocumentFilter {
     /** The Constant DEFAULT_PAGE_SIZE_INIT. */
     public static final int DEFAULT_PAGE_SIZE_INIT = 40;               // Default page size if one is specified in the service-config.xml
     public static final int DEFAULT_PAGE_SIZE_MAX_INIT = 1000; // Default page size max if one is specified in the service-config.xml
+    public static final String DEFAULT_SELECT_CLAUSE = "SELECT * FROM ";
     
     /** The Constant PAGE_SIZE_DEFAULT_PROPERTY. */
     public static final String PAGE_SIZE_DEFAULT_PROPERTY = "pageSizeDefault";
     public static final String PAGE_SIZE_MAX_PROPERTY = "pageSizeMax";
     
+    /** The select clause. */
+    protected String selectClause;
     /** The where clause. */
     protected String whereClause;      // Filtering clause. Omit the "WHERE".
     /** The order by clause. */
@@ -157,7 +160,7 @@ public abstract class DocumentFilter {
      * @param thePageSize the page size
      */
     public DocumentFilter(String theWhereClause, int theStartPage, int thePageSize) {
-        this(theWhereClause, EMPTY_ORDER_BY_CLAUSE, theStartPage, thePageSize);
+        this(DEFAULT_SELECT_CLAUSE, theWhereClause, EMPTY_ORDER_BY_CLAUSE, theStartPage, thePageSize);
     }
 
     /**
@@ -168,7 +171,8 @@ public abstract class DocumentFilter {
      * @param theStartPage the start page
      * @param thePageSize the page size
      */
-    public DocumentFilter(String theWhereClause, String theOrderByClause, int theStartPage, int thePageSize) {
+    public DocumentFilter(String theSelectClause, String theWhereClause, String theOrderByClause, int theStartPage, int thePageSize) {
+       this.selectClause = theSelectClause;
         this.whereClause = theWhereClause;
         this.orderByClause = theOrderByClause;
         this.startPage = (theStartPage > 0) ? theStartPage : 0;
@@ -225,6 +229,15 @@ public abstract class DocumentFilter {
         DocumentFilter.defaultPageSize = theDefaultPageSize;
     }
 
+    /**
+     * Gets the select clause.
+     *
+     * @return the select clause
+     */
+    public String getSelectClause() {
+        return selectClause != null ? selectClause : DEFAULT_SELECT_CLAUSE;
+    }
+    
     /**
      * Gets the where clause.
      *
@@ -234,6 +247,15 @@ public abstract class DocumentFilter {
         return whereClause;
     }
 
+    /**
+     * Sets the select clause.
+     *
+     * @param theSelectClause the new select clause
+     */
+    public void setSelectClause(String theSelectClause) {
+        this.selectClause = theSelectClause;
+    }
+
     /**
      * Sets the where clause.
      *
index 7c77914d03b3312ba7efdc67fb18af3102e992df..4297ad2c6223deb8c52a81d3824f29732ced431e 100644 (file)
@@ -18,6 +18,7 @@
 package org.collectionspace.services.common.document;
 
 import java.util.Map;
+
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.query.QueryContext;
 import org.collectionspace.services.lifecycle.Lifecycle;
@@ -331,6 +332,13 @@ public interface DocumentHandler<T, TL, WT, WTL> {
      */
     public String getUnQProperty(String qProp);
     
+    /**
+     * get a query string that will be used to return a set of documents that should be indexed/re-index
+     * @throws Exception 
+     * @throws DocumentException 
+     */
+    public String getDocumentsToIndexQuery(String indexId, String csid) throws DocumentException, Exception;
+    
     /**
      * Creates the CMIS query from the service context.  Each document handler is responsible for returning a valid CMIS query using the
      * information in the current service context -which includes things like the query parameters, etc.
index b660a46c756d598fff75d9cb31c06a87e7524458..e13d2ec77c056522f6e4e46fa24f3fda05e87027 100644 (file)
@@ -18,6 +18,8 @@ public class QueryContext {
     String docType;
     /** The doc filter. */
     DocumentFilter docFilter;
+    /** The Select clause. */
+    String selectClause;
     /** The where clause. */
     String whereClause;
     /** The order by clause. */
@@ -81,6 +83,14 @@ public class QueryContext {
         whereClause = theWhereClause;
         orderByClause = theOrderByClause;
     }
+    
+    public QueryContext(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
+            String theSelectClause, String theWhereClause, String theOrderByClause) throws DocumentNotFoundException, DocumentException {
+        this(ctx);
+        selectClause = theSelectClause;
+        whereClause = theWhereClause;
+        orderByClause = theOrderByClause;
+    }    
 
     /**
      * Instantiates a new query context.
@@ -94,14 +104,13 @@ public class QueryContext {
             DocumentHandler handler) throws DocumentNotFoundException, DocumentException {
         this(ctx);
         if (handler == null) {
-            throw new IllegalArgumentException(
-                    "Document handler is missing.");
+            throw new IllegalArgumentException("Document handler is missing.");
         }
         docFilter = handler.getDocumentFilter();
         if (docFilter == null) {
-            throw new IllegalArgumentException(
-                    "Document handler has no Filter specified.");
+            throw new IllegalArgumentException("Document handler has no Filter specified.");
         }
+        selectClause = docFilter.getSelectClause();
         whereClause = docFilter.getWhereClause();
         orderByClause = docFilter.getOrderByClause();
     }
@@ -115,6 +124,24 @@ public class QueryContext {
        return docFilter;
     }
     
+    /**
+     * Sets/changes the select clause
+     * 
+     * @param newSelectClause
+     */
+    public void setSelectClause(String newSelectClause) {
+       this.selectClause = newSelectClause;
+    }
+    
+    /**
+     * Gets the select clause.
+     *
+     * @return the select clause
+     */
+    public String getSelectClause() {
+       return selectClause;
+    }
+    
     /**
      * Gets the where clause.
      *
index 604f2f28f0184fc038a66c1ce5dfd081a69ec899..54d42f903d9155a7275efda61ece49a503e68c57 100644 (file)
@@ -34,6 +34,7 @@ import java.util.regex.Pattern;
 
 //import org.nuxeo.ecm.core.client.NuxeoClient;
 
+
 import org.collectionspace.services.jaxb.InvocableJAXBSchema;
 //import org.collectionspace.services.nuxeo.client.java.NuxeoConnector;
 //import org.collectionspace.services.nuxeo.client.java.NxConnect;
@@ -64,6 +65,9 @@ public class QueryManagerNuxeoImpl implements IQueryManager {
        private static Pattern kwdSearchProblemChars = Pattern.compile("[\\:\\(\\)\\*\\%\\.]");
        private static Pattern kwdSearchHyphen = Pattern.compile(" - ");
        private static Pattern advSearchSqlWildcard = Pattern.compile(".*?[I]*LIKE\\s*\\\"\\%\\\".*?");
+       // Base Nuxeo document type for all CollectionSpace documents/resources
+       public static String COLLECTIONSPACE_DOCUMENT_TYPE = "CollectionSpaceDocument";
+       public static final String NUXEO_DOCUMENT_TYPE = "Document";
 
 
        private static String getLikeForm(String dataSourceName, String repositoryName, String cspaceInstanceId) {
index afa8886f0ec2b25f1fce87b76ade47cefc6835c3..60f3d23b89a2d6931161c46ac4ba475b75caa56c 100644 (file)
@@ -125,7 +125,7 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn
                                return result;
                        }
                        
-                       final String servicesResource = "/cspace-services/"; // HACK - this is configured in war
+                       final String servicesResource = "/cspace-services/"; // HACK - this is configured in war, get this from tomcat instead
                        final int servicesResourceLen = servicesResource.length();
                        String httpMethod = request.getHttpMethod();
                        String uriPath = request.getUri().getPath();
index 42e52b11db22e956047de7478baf07077f90920c..a5c49bfc406156119da766cff7bbd472dea6f10c 100644 (file)
@@ -134,7 +134,7 @@ public class SecurityUtils {
                result = resEntity + "/*/" + IndexClient.SERVICE_NAME + "/" + indexId;
                } else if (indexId != null) {
                        // e.g., intakes/index/fulltext
-               result = resEntity + IndexClient.SERVICE_NAME + "/" + indexId;                  
+               result = resEntity + "/" + IndexClient.SERVICE_NAME + "/" + indexId;                    
                } else {
                        // e.g., intakes
                        result = resEntity;
@@ -170,7 +170,7 @@ public class SecurityUtils {
                                uriPath = uriPath.replace(pathParamValue, "*");
                        }
                        if ((pathParamName.toLowerCase().indexOf("predicate") > -1)) {
-                               //replace csids with wildcard
+                               //replace predicates with wildcard
                                uriPath = uriPath.replace(pathParamValue, "*");
                        }
                        if (pathParamName.toLowerCase().indexOf("specifier") > -1) {
@@ -179,9 +179,13 @@ public class SecurityUtils {
                                                + ")", "*");
                        }
                        if ((pathParamName.toLowerCase().indexOf("ms") > -1)) {
-                               //replace csids with wildcard
+                               //replace ms with wildcard
                                uriPath = uriPath.replace(pathParamValue, "*");
                        }
+                       if ((pathParamName.toLowerCase().indexOf("indexid") > -1)) {
+                               //replace indexid with wildcard
+                               uriPath = uriPath.replace(pathParamValue, "*");
+                       }                       
                }
                
                // FIXME: REM
@@ -233,9 +237,9 @@ public class SecurityUtils {
            String pathSegment = null;
            while (strTok.hasMoreTokens() == true) {
                pathSegment = strTok.nextToken();
-               if (pathSegment.equals("*") == true) {
+               if (pathSegment.equals("*") == true || pathSegment.equals("index") == true) {
                        //
-                       // leave the loop if we hit a wildcard character
+                       // leave the loop if we hit a wildcard character or the "index" subresource
                        //
                        break;
                }
diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/CSReindexFulltextRoot.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/CSReindexFulltextRoot.java
deleted file mode 100644 (file)
index fe2251f..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-package org.collectionspace.services.nuxeo.client.java;
-
-import java.io.Serializable;
-import java.security.Principal;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.collectionspace.services.common.context.ServiceContext;
-import org.collectionspace.services.common.document.DocumentHandler;
-import org.collectionspace.services.nuxeo.util.ReindexFulltextRoot;
-import org.collectionspace.services.nuxeo.util.ReindexFulltextRoot.ReindexInfo;
-import org.nuxeo.ecm.core.api.IterableQueryResult;
-import org.nuxeo.ecm.core.api.NuxeoException;
-import org.nuxeo.ecm.core.api.NuxeoPrincipal;
-import org.nuxeo.ecm.core.query.QueryFilter;
-import org.nuxeo.ecm.core.query.sql.NXQL;
-import org.nuxeo.ecm.core.storage.StorageException;
-import org.nuxeo.runtime.transaction.TransactionHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/*
- * Use the inherited reindexFulltext() method to reindex the Nuxeo full-text index.
- */
-public class CSReindexFulltextRoot extends ReindexFulltextRoot {
-
-       /** The logger. */
-       private final Logger logger = LoggerFactory.getLogger(CSReindexFulltextRoot.class);
-       protected String repoQuery;
-
-       public CSReindexFulltextRoot(CoreSessionInterface repoSession, String repoQuery) {
-               this.coreSession = repoSession.getCoreSession();
-               this.repoQuery = repoQuery;
-       }
-       
-       
-       @Override
-    protected List<ReindexInfo> getInfos() throws StorageException {
-        getLowLevelSession();
-        List<ReindexInfo> infos = new ArrayList<ReindexInfo>();
-//        String query = "SELECT ecm:uuid, ecm:primaryType FROM Document"
-//                + " WHERE ecm:isProxy = 0"
-//                + " AND ecm:currentLifeCycleState <> 'deleted'"
-//                + " ORDER BY ecm:uuid";
-        IterableQueryResult it = session.queryAndFetch(this.repoQuery, NXQL.NXQL,
-                QueryFilter.EMPTY);
-        try {
-            for (Map<String, Serializable> map : it) {
-                Serializable id = map.get(NXQL.ECM_UUID);
-                String type = (String) map.get(NXQL.ECM_PRIMARYTYPE);
-                infos.add(new ReindexInfo(id, type));
-            }
-        } finally {
-            it.close();
-        }
-        return infos;
-    }    
-
-}
index dfce1ff4e19919a0a03e813f760d8082bdc68246..a2cd09005273a7b575e4543900000ca4d857e7b5 100644 (file)
@@ -29,7 +29,6 @@ import java.util.List;
 import javax.ws.rs.core.MultivaluedMap;
 
 import org.apache.commons.lang.StringUtils;
-
 import org.collectionspace.services.client.Profiler;
 import org.collectionspace.services.client.CollectionSpaceClient;
 import org.collectionspace.services.client.IQueryManager;
@@ -60,14 +59,12 @@ import org.collectionspace.services.lifecycle.StateList;
 import org.collectionspace.services.lifecycle.TransitionDef;
 import org.collectionspace.services.lifecycle.TransitionDefList;
 import org.collectionspace.services.lifecycle.TransitionList;
-
 import org.nuxeo.ecm.core.NXCore;
 import org.nuxeo.ecm.core.api.ClientException;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
 import org.nuxeo.ecm.core.api.model.PropertyException;
 import org.nuxeo.ecm.core.lifecycle.LifeCycleService;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -458,6 +455,40 @@ public abstract class DocumentModelHandler<T, TL>
        return result;
     }
     
+    @Override
+    public String getDocumentsToIndexQuery(String indexId, String csid) throws DocumentException, Exception {
+       String result = null;
+       
+       ServiceContext<PoxPayloadIn,PoxPayloadOut> ctx = this.getServiceContext();
+       String selectClause = "SELECT ecm:uuid, ecm:primaryType FROM ";
+       String docFilterWhereClause = this.getDocumentFilter().getWhereClause();
+       //
+       // The where clause could be a combination of the document filter's where clause plus a CSID qualifier
+       //
+       String whereClause = (csid == null) ? null : String.format("ecm:name = '%s'", csid); // AND ecm:currentLifeCycleState <> 'deleted'"
+        if (whereClause != null && !whereClause.trim().isEmpty()) {
+            // Due to an apparent bug/issue in how Nuxeo translates the NXQL query string
+            // into SQL, we need to parenthesize our 'where' clause
+               if (docFilterWhereClause != null && !docFilterWhereClause.trim().isEmpty()) {
+                       whereClause = whereClause + IQueryManager.SEARCH_QUALIFIER_AND + "(" + docFilterWhereClause + ")";
+               }
+        } else {
+               whereClause = docFilterWhereClause;
+        }
+       String orderByClause = "ecm:uuid";
+       
+       try {
+               QueryContext queryContext = new QueryContext(ctx, selectClause, whereClause, orderByClause);
+               result = NuxeoUtils.buildNXQLQuery(ctx, queryContext);
+       } catch (DocumentException de) {
+               throw de;
+       } catch (Exception x) {
+               throw x;
+       }
+
+       return result;
+    }
+    
        /**
         * Creates the CMIS query from the service context. Each document handler is
         * responsible for returning (can override) a valid CMIS query using the information in the
index 2ca71a3cfdb6a459af10624f7e9fd524b3a77170..6ba21460f4b0ff348c0fdcae6d95e6afb9007075 100644 (file)
@@ -33,6 +33,7 @@ import javax.sql.rowset.CachedRowSet;
 import javax.ws.rs.core.MultivaluedMap;
 
 import org.collectionspace.services.lifecycle.TransitionDef;
+import org.collectionspace.services.nuxeo.util.CSReindexFulltextRoot;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.collectionspace.services.client.CollectionSpaceClient;
 import org.collectionspace.services.client.IQueryManager;
@@ -221,25 +222,23 @@ public class RepositoryClientImpl implements RepositoryClient<PoxPayloadIn, PoxP
     
 
     @Override
-    public boolean reindex(DocumentHandler handler, String csid, String indexid) throws DocumentNotFoundException, DocumentException
+    public boolean reindex(DocumentHandler handler, String indexid) throws DocumentNotFoundException, DocumentException
     {
-       boolean result = true;
-       ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = handler.getServiceContext();
-       return result;
+       return reindex(handler, null, indexid);
     }
     
     @Override
-    public boolean reindex(DocumentHandler handler, String indexid) throws DocumentNotFoundException, DocumentException
+    public boolean reindex(DocumentHandler handler, String csid, String indexid) throws DocumentNotFoundException, DocumentException
     {
        boolean result = true;
         CoreSessionInterface repoSession = null;
         ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = handler.getServiceContext();
         
         try {
+            String queryString = handler.getDocumentsToIndexQuery(indexid, csid);
             repoSession = getRepositorySession(ctx);
-            try {
-            } catch (ClientException ce) {
-            }
+            CSReindexFulltextRoot indexer = new CSReindexFulltextRoot(repoSession);
+            indexer.reindexFulltext(0, 0, queryString);
             //
             // Set repository session to handle the document
             //
diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/CSReindexFulltextRoot.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/CSReindexFulltextRoot.java
new file mode 100644 (file)
index 0000000..36f26bb
--- /dev/null
@@ -0,0 +1,24 @@
+package org.collectionspace.services.nuxeo.util;
+
+import org.collectionspace.services.nuxeo.client.java.CoreSessionInterface;
+import org.collectionspace.services.nuxeo.util.ReindexFulltextRoot;
+import org.nuxeo.ecm.core.storage.StorageException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Use the inherited reindexFulltext() method to reindex the Nuxeo full-text index.
+ */
+public class CSReindexFulltextRoot extends ReindexFulltextRoot {
+
+       /** The logger. */
+       private final Logger logger = LoggerFactory.getLogger(CSReindexFulltextRoot.class);
+
+       public CSReindexFulltextRoot(CoreSessionInterface repoSession) {
+               this.coreSession = repoSession.getCoreSession();
+       }
+
+    public String reindexFulltext(int batchSize, int batch, String query) throws StorageException {
+               return super.reindexFulltext(batchSize, batch, query);
+       }
+}
index 27b5c2659c01ad3afb27b3d2f3641f7ac1d8a7b1..f85a33347973ba3fc3c9e3dfee7216b36786acf9 100644 (file)
@@ -556,7 +556,7 @@ public class NuxeoUtils {
      * @throws Exception if supplied values in the query are invalid.
      */
     static public final String buildNXQLQuery(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, QueryContext queryContext) throws Exception {
-        StringBuilder query = new StringBuilder("SELECT * FROM ");
+        StringBuilder query = new StringBuilder(queryContext.getSelectClause());
         // Since we have a tenant qualification in the WHERE clause, we do not need 
         // tenant-specific doc types
         // query.append(NuxeoUtils.getTenantQualifiedDocType(queryContext)); // Nuxeo doctype must be tenant qualified.
@@ -589,7 +589,7 @@ public class NuxeoUtils {
      * @return an NXQL query
      */
     static public final String buildNXQLQuery(List<String> docTypes, QueryContext queryContext) throws Exception {
-        StringBuilder query = new StringBuilder("SELECT * FROM "); 
+        StringBuilder query = new StringBuilder(queryContext.getSelectClause()); 
         boolean fFirst = true;
         for (String docType : docTypes) {
             if (fFirst) {
index 968d7a3cde89322c6006d09036c697a2468bb9fd..90dc86e27cb445ae500596c13b9c1f2a67af5375 100644 (file)
@@ -101,7 +101,7 @@ public class ReindexFulltextRoot {
     @GET
     public String get(@QueryParam("batchSize") int batchSize, @QueryParam("batch") int batch) throws StorageException {
         coreSession = SessionFactory.getSession(request);
-        return reindexFulltext(batchSize, batch);
+        return reindexFulltext(batchSize, batch, null);
     }
 
     /**
@@ -113,7 +113,7 @@ public class ReindexFulltextRoot {
      * @return when done, ok + the total number of docs
      * @throws StorageException 
      */
-    public String reindexFulltext(int batchSize, int batch) throws StorageException {
+    public String reindexFulltext(int batchSize, int batch, String query) throws StorageException {
         Principal principal = coreSession.getPrincipal();
         if (!(principal instanceof NuxeoPrincipal)) {
             return "unauthorized";
@@ -127,7 +127,18 @@ public class ReindexFulltextRoot {
         if (batchSize <= 0) {
             batchSize = DEFAULT_BATCH_SIZE;
         }
-        List<ReindexInfo> infos = getInfos();
+        
+        //
+        // A default query that gets ALL the documents
+        //
+        if (query == null) {
+               query = "SELECT ecm:uuid, ecm:primaryType FROM Document"
+                       + " WHERE ecm:isProxy = 0"
+                       + " AND ecm:currentLifeCycleState <> 'deleted'"
+                       + " ORDER BY ecm:uuid";
+        }
+
+        List<ReindexInfo> infos = getInfos(query);
         int size = infos.size();
         int numBatches = (size + batchSize - 1) / batchSize;
         if (batch < 0 || batch > numBatches) {
@@ -196,13 +207,9 @@ public class ReindexFulltextRoot {
         }
     }
 
-    protected List<ReindexInfo> getInfos() throws StorageException {
+    protected List<ReindexInfo> getInfos(String query) throws StorageException {
         getLowLevelSession();
         List<ReindexInfo> infos = new ArrayList<ReindexInfo>();
-        String query = "SELECT ecm:uuid, ecm:primaryType FROM Document"
-                + " WHERE ecm:isProxy = 0"
-                + " AND ecm:currentLifeCycleState <> 'deleted'"
-                + " ORDER BY ecm:uuid";
         IterableQueryResult it = session.queryAndFetch(query, NXQL.NXQL,
                 QueryFilter.EMPTY);
         try {
index 7cfa62505330199bf95051f4ae17dc4425439eaf..ad08d8febce052c25b40d49546983cf0d793fe4a 100644 (file)
@@ -55,6 +55,7 @@ import org.collectionspace.services.common.document.DocumentException;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.security.SecurityUtils;
+import org.collectionspace.services.common.query.nuxeo.QueryManagerNuxeoImpl;
 
 import org.collectionspace.services.config.service.ServiceBindingType;
 import org.collectionspace.services.config.service.ServiceObjectType;
@@ -126,11 +127,11 @@ public class ServiceGroupDocumentModelHandler
                }
                
                // This should be "Document" but CMIS is gagging on that right now.
-               ctx.getQueryParams().add(IQueryManager.SELECT_DOC_TYPE_FIELD, "CollectionSpaceDocument");
+               ctx.getQueryParams().add(IQueryManager.SELECT_DOC_TYPE_FIELD, QueryManagerNuxeoImpl.COLLECTIONSPACE_DOCUMENT_TYPE);
                
                // Now we have to issue the search
-               // findDocs qill build a QueryContext, which wants to see a docType for our context
-               ctx.setDocumentType("Document");
+               // findDocs will build a QueryContext, which wants to see a docType for our context
+               ctx.setDocumentType(QueryManagerNuxeoImpl.NUXEO_DOCUMENT_TYPE);
                DocumentWrapper<DocumentModelList> docListWrapper = 
                                nuxeoRepoClient.findDocs(ctx, this, repoSession, docTypes );
                // Now we gather the info for each document into the list and return