From 283c383b38e6d5817ee2247dc1915698895f73df Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Thu, 19 Apr 2018 15:53:12 -0700 Subject: [PATCH] DRYD-315: To get term list results to show the referenced field, you now need to use the query param 'markIfReferenced' set to true. --- .../common/vocabulary/AuthorityResource.java | 14 +- .../AuthorityItemDocumentModelHandler.java | 151 +++++++++++++----- .../services/client/AuthorityClient.java | 1 + .../common/document/DocumentFilter.java | 14 ++ .../services/common/query/QueryContext.java | 2 +- .../common/relation/RelationUtils.java | 15 +- .../common/repository/RepositoryClient.java | 6 +- .../vocabulary/LazyAuthorityRefDocList.java | 24 ++- .../vocabulary/RefNameServiceUtils.java | 75 +++++++-- .../java/NuxeoRepositoryClientImpl.java | 25 ++- .../services/nuxeo/util/NuxeoUtils.java | 8 +- 11 files changed, 253 insertions(+), 82 deletions(-) diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index 32df06b47..eaa1a0fcb 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -58,7 +58,6 @@ import org.collectionspace.services.common.ServiceMessages; import org.collectionspace.services.common.StoredValuesUriTemplate; import org.collectionspace.services.common.UriInfoWrapper; import org.collectionspace.services.common.UriTemplateFactory; -import org.collectionspace.services.common.UriTemplateRegistry; import org.collectionspace.services.common.UriTemplateRegistryKey; import org.collectionspace.services.common.api.RefName; import org.collectionspace.services.common.api.Tools; @@ -119,6 +118,9 @@ public abstract class AuthorityResource final static String SEARCH_TYPE_TERMSTATUS = "ts"; public final static String hierarchy = "hierarchy"; + + private static final Integer PAGE_NUM_FROM_QUERYPARAMS = null; + private static final Integer PAGE_SIZE_FROM_QUERYPARAMS = null; protected Class authCommonClass; protected Class resourceClass; @@ -1209,7 +1211,7 @@ public abstract class AuthorityResource uriInfo = new UriInfoWrapper(uriInfo); AuthorityRefDocList authRefDocList = null; try { - authRefDocList = getReferencingObjects(null, parentSpecifier, itemSpecifier, uriInfo); + authRefDocList = getReferencingObjects(null, parentSpecifier, itemSpecifier, uriInfo, PAGE_NUM_FROM_QUERYPARAMS, PAGE_SIZE_FROM_QUERYPARAMS, true, true); } catch (Exception e) { throw bigReThrow(e, ServiceMessages.GET_FAILED); } @@ -1227,7 +1229,11 @@ public abstract class AuthorityResource ServiceContext existingContext, String parentspecifier, String itemspecifier, - UriInfo uriInfo) throws Exception { + UriInfo uriInfo, + Integer pageNum, + Integer pageSize, + boolean useDefaultOrderByClause, + boolean computeTotal) throws Exception { AuthorityRefDocList authRefDocList = null; ServiceContext ctx = createServiceContext(getItemServiceName(), uriInfo); @@ -1250,7 +1256,7 @@ public abstract class AuthorityResource } AuthorityItemDocumentModelHandler handler = (AuthorityItemDocumentModelHandler)createItemDocumentHandler(ctx, parentcsid, null); - authRefDocList = handler.getReferencingObjects(ctx, serviceTypes, getRefPropName(), itemcsid); + authRefDocList = handler.getReferencingObjects(ctx, serviceTypes, getRefPropName(), itemcsid, pageNum, pageSize, useDefaultOrderByClause, computeTotal); return authRefDocList; } diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index d3c8b2c3e..d3f7d5998 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -90,6 +90,9 @@ public abstract class AuthorityItemDocumentModelHandler private final Logger logger = LoggerFactory.getLogger(AuthorityItemDocumentModelHandler.class); + private static final Integer PAGE_SIZE_FROM_QUERYPARAMS = null; + private static final Integer PAGE_NUM_FROM_QUERYPARAMS = null; + protected String authorityCommonSchemaName; protected String authorityItemCommonSchemaName; private String authorityItemTermGroupXPathBase; @@ -417,8 +420,8 @@ public abstract class AuthorityItemDocumentModelHandler // DocumentModel docModel = wrapDoc.getWrappedObject(); if (transitionDef.getName().equalsIgnoreCase(WorkflowClient.WORKFLOWTRANSITION_DELETE)) { - AuthorityRefDocList refsToAllObjects = getReferencingObjects(ctx, docModel, RefObjsSearchType.ALL); - AuthorityRefDocList refsToSoftDeletedObjects = getReferencingObjects(ctx, docModel, RefObjsSearchType.DELETED_ONLY); + AuthorityRefDocList refsToAllObjects = getReferencingObjectsForStateTransitions(ctx, docModel, RefObjsSearchType.ALL); + AuthorityRefDocList refsToSoftDeletedObjects = getReferencingObjectsForStateTransitions(ctx, docModel, RefObjsSearchType.DELETED_ONLY); if (refsToAllObjects.getTotalItems() > 0) { if (refsToAllObjects.getTotalItems() > refsToSoftDeletedObjects.getTotalItems()) { // @@ -728,8 +731,8 @@ public abstract class AuthorityItemDocumentModelHandler ServiceContext ctx = getServiceContext(); DocumentModel docModel = wrapDoc.getWrappedObject(); - AuthorityRefDocList refsToAllObjects = getReferencingObjects(ctx, docModel, RefObjsSearchType.ALL); - AuthorityRefDocList refsToSoftDeletedObjects = getReferencingObjects(ctx, docModel, RefObjsSearchType.DELETED_ONLY); + AuthorityRefDocList refsToAllObjects = getReferencingObjectsForStateTransitions(ctx, docModel, RefObjsSearchType.ALL); + AuthorityRefDocList refsToSoftDeletedObjects = getReferencingObjectsForStateTransitions(ctx, docModel, RefObjsSearchType.DELETED_ONLY); if (refsToAllObjects.getTotalItems() > 0) { if (refsToAllObjects.getTotalItems() > refsToSoftDeletedObjects.getTotalItems()) { // @@ -776,8 +779,11 @@ public abstract class AuthorityItemDocumentModelHandler * @throws Exception */ @SuppressWarnings("rawtypes") - private AuthorityRefDocList getReferencingObjects(ServiceContext ctx, DocumentModel docModel, RefObjsSearchType searchType) throws Exception { - AuthorityRefDocList result = null; + private AuthorityRefDocList getReferencingObjectsForStateTransitions( + ServiceContext ctx, + DocumentModel docModel, + RefObjsSearchType searchType) throws Exception { + AuthorityRefDocList referenceList = null; if (ctx.getUriInfo() == null) { // @@ -792,23 +798,68 @@ public abstract class AuthorityItemDocumentModelHandler // boolean doesContainValue = ctx.getUriInfo().getQueryParameters().containsKey(WorkflowClient.WORKFLOW_QUERY_DELETED_QP); String previousValue = ctx.getUriInfo().getQueryParameters().getFirst(WorkflowClient.WORKFLOW_QUERY_DELETED_QP); + try { if (doesContainValue) { ctx.getUriInfo().getQueryParameters().remove(WorkflowClient.WORKFLOW_QUERY_DELETED_QP); } AuthorityResource authorityResource = (AuthorityResource)ctx.getResource(getAuthorityServicePath()); - result = getReferencingObjects(authorityResource, ctx, docModel, searchType); + referenceList = getReferencingObjects(authorityResource, ctx, docModel, searchType, PAGE_NUM_FROM_QUERYPARAMS, PAGE_SIZE_FROM_QUERYPARAMS, true, true); // useDefaultOrderByClause=true, computeTotal=true } finally { if (doesContainValue) { ctx.getUriInfo().getQueryParameters().addFirst(WorkflowClient.WORKFLOW_QUERY_DELETED_QP, previousValue); } } - return result; + return referenceList; } + @SuppressWarnings("rawtypes") + private AuthorityRefDocList getReferencingObjectsForMarkingTerm( + ServiceContext ctx, + DocumentModel docModel, + RefObjsSearchType searchType) throws Exception { + AuthorityRefDocList referenceList = null; + + if (ctx.getUriInfo() == null) { + // + // We need a UriInfo object so we can pass "query" params to the AuthorityResource's getReferencingObjects() method + // + ctx.setUriInfo(this.getServiceContext().getUriInfo()); // try to get a UriInfo instance from the handler's context + } + + // + // Since the call to get referencing objects might indirectly use the WorkflowClient.WORKFLOW_QUERY_NONDELETED query param, we need to + // temporarily remove that query param if it is set. If set, we'll save the value and reset once we're finished. + // + boolean doesContainValue = ctx.getUriInfo().getQueryParameters().containsKey(WorkflowClient.WORKFLOW_QUERY_DELETED_QP); + String previousValue = ctx.getUriInfo().getQueryParameters().getFirst(WorkflowClient.WORKFLOW_QUERY_DELETED_QP); + + try { + if (doesContainValue) { + ctx.getUriInfo().getQueryParameters().remove(WorkflowClient.WORKFLOW_QUERY_DELETED_QP); + } + AuthorityResource authorityResource = (AuthorityResource)ctx.getResource(getAuthorityServicePath()); + referenceList = getReferencingObjects(authorityResource, ctx, docModel, searchType, 0, 1, false, false); // pageNum=0, pageSize=1, useDefaultOrderClause=false, computeTotal=false + } finally { + if (doesContainValue) { + ctx.getUriInfo().getQueryParameters().addFirst(WorkflowClient.WORKFLOW_QUERY_DELETED_QP, previousValue); + } + } + + return referenceList; + } + @SuppressWarnings({ "rawtypes", "unchecked" }) - private AuthorityRefDocList getReferencingObjects(AuthorityResource authorityResource, ServiceContext ctx, DocumentModel docModel, RefObjsSearchType searchType) throws Exception { + private AuthorityRefDocList getReferencingObjects( + AuthorityResource authorityResource, + ServiceContext ctx, + DocumentModel docModel, + RefObjsSearchType searchType, + Integer pageNum, + Integer pageSize, + boolean useDefaultOrderByClause, + boolean computeTotal) throws Exception { AuthorityRefDocList result = null; String inAuthorityCsid = (String) docModel.getProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.IN_AUTHORITY); @@ -828,7 +879,7 @@ public abstract class AuthorityItemDocumentModelHandler ctx.getUriInfo().getQueryParameters().addFirst(WorkflowClient.WORKFLOW_QUERY_ONLY_DELETED_QP, Boolean.TRUE.toString()); // Add the wf_only_deleted query param to get only soft-deleted items break; } - result = authorityResource.getReferencingObjects(ctx, inAuthorityCsid, itemCsid, ctx.getUriInfo()); + result = authorityResource.getReferencingObjects(ctx, inAuthorityCsid, itemCsid, ctx.getUriInfo(), pageNum, pageSize, useDefaultOrderByClause, computeTotal); } finally { // @@ -1079,7 +1130,11 @@ public abstract class AuthorityItemDocumentModelHandler ServiceContext ctx, List serviceTypes, String propertyName, - String itemcsid) throws Exception { + String itemcsid, + Integer pageNum, + Integer pageSize, + boolean useDefaultOrderByClause, + boolean computeTotal) throws Exception { AuthorityRefDocList authRefDocList = null; CoreSessionInterface repoSession = (CoreSessionInterface) ctx.getCurrentRepositorySession(); boolean releaseRepoSession = false; @@ -1092,17 +1147,28 @@ public abstract class AuthorityItemDocumentModelHandler releaseRepoSession = true; } DocumentFilter myFilter = getDocumentFilter(); + if (pageSize != null) { + myFilter.setPageSize(pageSize); + } + if (pageNum != null) { + myFilter.setStartPage(pageNum); + } + myFilter.setUseDefaultOrderByClause(useDefaultOrderByClause); try { DocumentWrapper wrapper = repoClient.getDoc(repoSession, ctx, itemcsid); DocumentModel docModel = wrapper.getWrappedObject(); String refName = (String) NuxeoUtils.getProperyValue(docModel, AuthorityItemJAXBSchema.REF_NAME); //docModel.getPropertyValue(AuthorityItemJAXBSchema.REF_NAME); authRefDocList = RefNameServiceUtils.getAuthorityRefDocs( - repoSession, ctx, repoClient, + repoSession, + ctx, + repoClient, serviceTypes, refName, propertyName, - myFilter, true /*computeTotal*/); + myFilter, + useDefaultOrderByClause, + computeTotal /*computeTotal*/); } catch (PropertyException pe) { throw pe; } catch (DocumentException de) { @@ -1303,43 +1369,50 @@ public abstract class AuthorityItemDocumentModelHandler return result; } + + private boolean isTermReferenced(DocumentModel docModel) throws Exception { + boolean result = false; + + AuthorityRefDocList referenceList = null; + String wf_deletedStr = (String) getServiceContext().getQueryParams().getFirst(WorkflowClient.WORKFLOW_QUERY_DELETED_QP); + if (wf_deletedStr != null && Tools.isFalse(wf_deletedStr)) { + // + // if query param 'wf_deleted=false', we won't count references to soft-deleted records + // + referenceList = getReferencingObjectsForMarkingTerm(getServiceContext(), docModel, RefObjsSearchType.NON_DELETED); + } else { + // + // if query param 'wf_deleted=true' or missing, we count references to soft-deleted and active records + // + referenceList = getReferencingObjectsForMarkingTerm(getServiceContext(), docModel, RefObjsSearchType.ALL); + } + + if (referenceList.getTotalItems() > 0) { + result = true; + } + + return result; + } + + @SuppressWarnings("unchecked") @Override protected Object getListResultValue(DocumentModel docModel, // REM - CSPACE-5133 String schema, ListResultField field) throws DocumentException { - Object result = null; + Object result = null; String fieldXPath = field.getXpath(); if (fieldXPath.equalsIgnoreCase(AuthorityClient.REFERENCED) == false) { result = NuxeoUtils.getXPathValue(docModel, schema, field.getXpath()); } else { // - // Special case for the 'referenced' list result field. + // Check to see if the request is asking us to mark terms as referenced or not. // - // Set result value of field 'referenced' to 'true' if item is being referenced; otherwise, 'false' - // - try { - result = Boolean.FALSE.toString(); - AuthorityRefDocList referenceList = null; - - String wf_deletedStr = (String) getServiceContext().getQueryParams().getFirst(WorkflowClient.WORKFLOW_QUERY_DELETED_QP); - if (wf_deletedStr != null && Tools.isFalse(wf_deletedStr)) { - // - // if query param 'wf_deleted=false', we won't count references to soft-deleted records - // - referenceList = getReferencingObjects(getServiceContext(), docModel, RefObjsSearchType.NON_DELETED); - } else { - // - // if query param 'wf_deleted=true' or missing, we count references to soft-deleted and active records - // - referenceList = getReferencingObjects(getServiceContext(), docModel, RefObjsSearchType.ALL); - } - - if (referenceList.getTotalItems() > 0) { - result = Boolean.TRUE.toString(); - } - - return result; + String markIfReferencedStr = (String) getServiceContext().getQueryParams().getFirst(AuthorityClient.MARK_IF_REFERENCED_QP); + if (Tools.isTrue(markIfReferencedStr) == false) { + return null; // leave the element as null since they're not asking for it + } else try { + return Boolean.toString(isTermReferenced(docModel)); // set the element to either 'true' or 'false' } catch (Exception e) { String msg = String.format("Failed while trying to find records referencing term CSID='%s'.", docModel.getName()); throw new DocumentException(msg, e); diff --git a/services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java b/services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java index 6fa476232..17602660c 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java @@ -24,6 +24,7 @@ public interface AuthorityClient 0) ? theStartPage : 0; this.pageSize = (thePageSize > 0) ? thePageSize : defaultPageSize; } + + public void setUseDefaultOrderByClause(boolean flag) { + this.useDefaultOrderByClause = flag; + } + + public boolean getUseDefaultOrderByClause() { + return this.useDefaultOrderByClause; + } /** * Sets the pagination. 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 84faf175b..8df70af0f 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 @@ -172,7 +172,7 @@ public class QueryContext { * @return the order by clause */ public String getOrderByClause() { - return this.orderByClause; + return this.orderByClause; } /** diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java index b245b098a..bb3ee993f 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java @@ -39,8 +39,8 @@ public class RelationUtils { String refName, String targetField, String orderByClause, - int pageSize, int pageNum, + int pageSize, boolean computeTotal) throws DocumentException, DocumentNotFoundException { List docTypes = Arrays.asList(IRelationsManager.DOC_TYPE); @@ -52,8 +52,15 @@ public class RelationUtils { String query = String.format("%s:%s = '%s'", IRelationsManager.SERVICE_COMMONPART_NAME, targetField, escapedRefName); NuxeoRepositoryClientImpl nuxeoRepoClient = (NuxeoRepositoryClientImpl) repoClient; - DocumentWrapper docListWrapper = nuxeoRepoClient.findDocs(ctx, repoSession, - docTypes, query, orderByClause, pageSize, pageNum, computeTotal); + DocumentWrapper docListWrapper = nuxeoRepoClient.findDocs(ctx, + repoSession, + docTypes, + query, + orderByClause, + pageNum, + pageSize, + true, // useDefaultOrderByClause if 'orderByClause' is null + computeTotal); DocumentModelList docList = docListWrapper.getWrappedObject(); return docList; @@ -88,8 +95,8 @@ public class RelationUtils { oldRefName, targetField, ORDER_BY_VALUE, - DEFAULT_PAGE_SIZE, currentPage, + DEFAULT_PAGE_SIZE, true); if (docModelList == null) { diff --git a/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClient.java b/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClient.java index 4b674a190..5cce0ca2d 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClient.java +++ b/services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClient.java @@ -156,8 +156,10 @@ public interface RepositoryClient extends StorageClient { ServiceContext ctx, List docTypes, String where, - int pageSize, int pageNum, boolean computeTotal) - throws DocumentNotFoundException, DocumentException; + int pageNum, + int pageSize, + boolean useDefaultOrderByClause, + boolean computeTotal) throws DocumentNotFoundException, DocumentException; /** * Reindex a single resource/document. diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/LazyAuthorityRefDocList.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/LazyAuthorityRefDocList.java index 4f97aada4..a67fa584d 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/LazyAuthorityRefDocList.java +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/LazyAuthorityRefDocList.java @@ -78,6 +78,7 @@ public class LazyAuthorityRefDocList extends DocumentModelListImpl { String whereClauseAdditions, String orderByClause, int pageSize, + boolean useDefaultOrderByClause, boolean computeTotal) throws DocumentException, DocumentNotFoundException { this.ctx = ctx; @@ -97,7 +98,7 @@ public class LazyAuthorityRefDocList extends DocumentModelListImpl { // into this initial page fetch. There's no need to compute totals // when fetching subsequent pages. - firstPageDocList = fetchPage(0, computeTotal); + firstPageDocList = fetchPage(0, computeTotal, useDefaultOrderByClause); } /** @@ -109,10 +110,21 @@ public class LazyAuthorityRefDocList extends DocumentModelListImpl { * @throws DocumentNotFoundException * @throws DocumentException */ - private DocumentModelList fetchPage(int pageNum, boolean computeTotal) throws DocumentNotFoundException, DocumentException { - return RefNameServiceUtils.findAuthorityRefDocs(ctx, repoClient, repoSession, - serviceTypes, refName, refPropName, queriedServiceBindings, authRefFieldsByService, - whereClauseAdditions, orderByClause, pageSize, pageNum, computeTotal); + private DocumentModelList fetchPage(int pageNum, boolean computeTotal, boolean useDefaultOrderByClause) throws DocumentNotFoundException, DocumentException { + return RefNameServiceUtils.findAuthorityRefDocs(ctx, + repoClient, + repoSession, + serviceTypes, + refName, + refPropName, + queriedServiceBindings, + authRefFieldsByService, + whereClauseAdditions, + orderByClause, + pageNum, + pageSize, + useDefaultOrderByClause, + computeTotal); } @Override @@ -184,7 +196,7 @@ public class LazyAuthorityRefDocList extends DocumentModelListImpl { DocumentModelList nextPageDocList = null; try { - nextPageDocList = fetchPage(nextPageNum, false); + nextPageDocList = fetchPage(nextPageNum, false, true); } catch(DocumentException e) {} diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java index 563792c0e..3d07d672a 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java @@ -392,8 +392,9 @@ public class RefNameServiceUtils { List serviceTypes, String refName, String refPropName, // authRef or termRef, authorities or vocab terms. - DocumentFilter filter, boolean computeTotal) - throws DocumentException, DocumentNotFoundException { + DocumentFilter filter, + boolean useDefaultOrderByClause, + boolean computeTotal) throws DocumentException, DocumentNotFoundException { AuthorityRefDocList wrapperList = new AuthorityRefDocList(); AbstractCommonList commonList = (AbstractCommonList) wrapperList; int pageNum = filter.getStartPage(); @@ -418,9 +419,19 @@ public class RefNameServiceUtils { // of possibly referencing documents will be false positives, // so use a page size of double the requested page size to // account for those. - DocumentModelList docList = findAllAuthorityRefDocs(ctx, repoClient, repoSession, - serviceTypes, refName, refPropName, queriedServiceBindings, authRefFieldsByService, - filter.getWhereClause(), null, 2*pageSize, computeTotal); + DocumentModelList docList = findAllAuthorityRefDocs(ctx, + repoClient, + repoSession, + serviceTypes, + refName, + refPropName, + queriedServiceBindings, + authRefFieldsByService, + filter.getWhereClause(), + null, // orderByClause + 2*pageSize, + useDefaultOrderByClause, + computeTotal); if (docList == null) { // found no authRef fields - nothing to process return wrapperList; @@ -511,9 +522,20 @@ public class RefNameServiceUtils { boolean morePages = true; while (morePages) { - docList = findAuthorityRefDocs(ctx, repoClient, repoSession, - getRefNameServiceTypes(), oldRefName, refPropName, - queriedServiceBindings, authRefFieldsByService, WHERE_CLAUSE_ADDITIONS_VALUE, ORDER_BY_VALUE, pageSize, currentPage, false); + docList = findAuthorityRefDocs(ctx, + repoClient, + repoSession, + getRefNameServiceTypes(), + oldRefName, + refPropName, + queriedServiceBindings, + authRefFieldsByService, + WHERE_CLAUSE_ADDITIONS_VALUE, + ORDER_BY_VALUE, + currentPage, + pageSize, + true, // useDefaultOrderByClause + false); // computeTotal if (docList == null) { logger.debug("updateAuthorityRefDocs: no documents could be found that referenced the old refName"); @@ -568,11 +590,22 @@ public class RefNameServiceUtils { String whereClauseAdditions, String orderByClause, int pageSize, + boolean useDefaultOrderByClause, boolean computeTotal) throws DocumentException, DocumentNotFoundException { - return new LazyAuthorityRefDocList(ctx, repoClient, repoSession, - serviceTypes, refName, refPropName, queriedServiceBindings, authRefFieldsByService, - whereClauseAdditions, orderByClause, pageSize, computeTotal); + return new LazyAuthorityRefDocList(ctx, + repoClient, + repoSession, + serviceTypes, + refName, + refPropName, + queriedServiceBindings, + authRefFieldsByService, + whereClauseAdditions, + orderByClause, + pageSize, + useDefaultOrderByClause, + computeTotal); } protected static DocumentModelList findAuthorityRefDocs( @@ -585,13 +618,14 @@ public class RefNameServiceUtils { Map> authRefFieldsByService, String whereClauseAdditions, String orderByClause, - int pageSize, int pageNum, + int pageSize, + boolean useDefaultOrderByClause, boolean computeTotal) throws DocumentException, DocumentNotFoundException { // Get the service bindings for this tenant - TenantBindingConfigReaderImpl tReader = - ServiceMain.getInstance().getTenantBindingConfigReader(); + TenantBindingConfigReaderImpl tReader = ServiceMain.getInstance().getTenantBindingConfigReader(); + // We need to get all the procedures, authorities, and objects. List servicebindings = tReader.getServiceBindingsByType(ctx.getTenantId(), serviceTypes); if (servicebindings == null || servicebindings.isEmpty()) { @@ -614,12 +648,21 @@ public class RefNameServiceUtils { } // Now we have to issue the search NuxeoRepositoryClientImpl nuxeoRepoClient = (NuxeoRepositoryClientImpl) repoClient; - DocumentWrapper docListWrapper = nuxeoRepoClient.findDocs(ctx, repoSession, - docTypes, query, orderByClause, pageSize, pageNum, computeTotal); + DocumentWrapper docListWrapper = nuxeoRepoClient.findDocs( + ctx, + repoSession, + docTypes, + query, + orderByClause, + pageNum, + pageSize, + useDefaultOrderByClause, + computeTotal); // Now we gather the info for each document into the list and return DocumentModelList docList = docListWrapper.getWrappedObject(); return docList; } + private static final boolean READY_FOR_COMPLEX_QUERY = true; private static String computeWhereClauseForAuthorityRefDocs( diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoRepositoryClientImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoRepositoryClientImpl.java index 0d6c00fac..1822f3fdb 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoRepositoryClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoRepositoryClientImpl.java @@ -652,8 +652,9 @@ public class NuxeoRepositoryClientImpl implements RepositoryClient docTypes, String whereClause, String orderByClause, - int pageSize, int pageNum, + int pageSize, + boolean useDefaultOrderByClause, boolean computeTotal) throws DocumentNotFoundException, DocumentException { DocumentWrapper wrapDoc = null; @@ -665,7 +666,7 @@ public class NuxeoRepositoryClientImpl implements RepositoryClient ctx, DocumentHandler handler, CoreSessionInterface repoSession, - List docTypes) - throws DocumentNotFoundException, DocumentException { + List docTypes) throws DocumentNotFoundException, DocumentException { DocumentWrapper wrapDoc = null; DocumentFilter filter = handler.getDocumentFilter(); @@ -858,15 +858,24 @@ public class NuxeoRepositoryClientImpl implements RepositoryClient ctx, List docTypes, String whereClause, - int pageSize, int pageNum, boolean computeTotal) - throws DocumentNotFoundException, TransactionException, DocumentException { + int pageNum, + int pageSize, + boolean useDefaultOrderByClause, + boolean computeTotal) throws DocumentNotFoundException, TransactionException, DocumentException { CoreSessionInterface repoSession = null; DocumentWrapper wrapDoc = null; try { repoSession = getRepositorySession(ctx); - wrapDoc = findDocs(ctx, repoSession, docTypes, whereClause, null, - pageSize, pageNum, computeTotal); + wrapDoc = findDocs(ctx, + repoSession, + docTypes, + whereClause, + null, + pageNum, + pageSize, + useDefaultOrderByClause, + computeTotal); } catch (IllegalArgumentException iae) { throw iae; } catch (Exception e) { 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 51b914d23..66c53b116 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 @@ -670,7 +670,7 @@ public class NuxeoUtils { * @param queryContext the query context * @return an NXQL query */ - static public final String buildNXQLQuery(List docTypes, QueryContext queryContext) throws Exception { + static public final String buildNXQLQuery(List docTypes, QueryContext queryContext, boolean useDefaultOrderByClause) throws Exception { StringBuilder query = new StringBuilder(queryContext.getSelectClause()); boolean fFirst = true; for (String docType : docTypes) { @@ -688,7 +688,7 @@ public class NuxeoUtils { appendNXQLWhere(query, queryContext); if (Tools.notBlank(queryContext.getOrderByClause())) { appendNXQLOrderBy(query, queryContext.getOrderByClause(), null); - } else { + } else if (useDefaultOrderByClause == true) { // Across a set of mixed DocTypes, updatedAt is the most sensible default ordering appendNXQLOrderBy(query, DocumentFilter.ORDER_BY_LAST_UPDATED, null); } @@ -696,6 +696,10 @@ public class NuxeoUtils { return query.toString(); } + static public final String buildNXQLQuery(List docTypes, QueryContext queryContext) throws Exception { + return buildNXQLQuery(docTypes, queryContext, true); + } + static public DocumentModel getDocFromCsid( ServiceContext ctx, CoreSessionInterface repoSession, -- 2.47.3