From: remillet Date: Mon, 28 Mar 2016 21:50:14 +0000 (-0700) Subject: CSPACE-6826: Reindex for a single resource type or a single document now supported. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=9aa3cd005ac1c878fe1dab079e0d235193f89642;p=tmp%2Fjakarta-migration.git CSPACE-6826: Reindex for a single resource type or a single document now supported. --- diff --git a/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java b/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java index 6856a80cb..66c72036e 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java +++ b/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java @@ -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 ctx = (RemoteServiceContext) 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; diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java index 2d37eb5aa..55f2cafb3 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java @@ -429,6 +429,16 @@ public abstract class AbstractDocumentHandlerImpl 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() 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 e7a9e2cc4..b2c2150ad 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 @@ -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. * diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java index 7c77914d0..4297ad2c6 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java @@ -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 { */ 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. diff --git a/services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java b/services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java index b660a46c7..e13d2ec77 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java +++ b/services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java @@ -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 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. * diff --git a/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java b/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java index 604f2f28f..54d42f903 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java @@ -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) { diff --git a/services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java b/services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java index afa8886f0..60f3d23b8 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java +++ b/services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java @@ -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(); diff --git a/services/common/src/main/java/org/collectionspace/services/common/security/SecurityUtils.java b/services/common/src/main/java/org/collectionspace/services/common/security/SecurityUtils.java index 42e52b11d..a5c49bfc4 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/security/SecurityUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/security/SecurityUtils.java @@ -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 index fe2251fa5..000000000 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/CSReindexFulltextRoot.java +++ /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 getInfos() throws StorageException { - getLowLevelSession(); - List infos = new ArrayList(); -// 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 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; - } - -} diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java index dfce1ff4e..a2cd09005 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java @@ -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 return result; } + @Override + public String getDocumentsToIndexQuery(String indexId, String csid) throws DocumentException, Exception { + String result = null; + + ServiceContext 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 diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryClientImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryClientImpl.java index 2ca71a3cf..6ba21460f 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryClientImpl.java @@ -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 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 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 index 000000000..36f26bb8e --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/CSReindexFulltextRoot.java @@ -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); + } +} diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java index 27b5c2659..f85a33347 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java @@ -556,7 +556,7 @@ public class NuxeoUtils { * @throws Exception if supplied values in the query are invalid. */ static public final String buildNXQLQuery(ServiceContext 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 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) { diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/ReindexFulltextRoot.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/ReindexFulltextRoot.java index 968d7a3cd..90dc86e27 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/util/ReindexFulltextRoot.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/util/ReindexFulltextRoot.java @@ -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 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 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 getInfos() throws StorageException { + protected List getInfos(String query) throws StorageException { getLowLevelSession(); List infos = new ArrayList(); - 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 { diff --git a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java index 7cfa62505..ad08d8feb 100644 --- a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java +++ b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java @@ -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 docListWrapper = nuxeoRepoClient.findDocs(ctx, this, repoSession, docTypes ); // Now we gather the info for each document into the list and return