]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-315: To get term list results to show the referenced field, you now need to...
authorRichard Millet <remillet@yahoo.com>
Thu, 19 Apr 2018 22:53:12 +0000 (15:53 -0700)
committerRichard Millet <remillet@yahoo.com>
Thu, 19 Apr 2018 22:53:12 +0000 (15:53 -0700)
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/client/src/main/java/org/collectionspace/services/client/AuthorityClient.java
services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java
services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java
services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java
services/common/src/main/java/org/collectionspace/services/common/repository/RepositoryClient.java
services/common/src/main/java/org/collectionspace/services/common/vocabulary/LazyAuthorityRefDocList.java
services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoRepositoryClientImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java

index 32df06b4767d2409862559fb0e612865e3757972..eaa1a0fcbc11ac51e401d30a71417a7afa821e3b 100644 (file)
@@ -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<AuthCommon, AuthItemHandler>
 
     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<AuthCommon> authCommonClass;
     protected Class<?> resourceClass;
@@ -1209,7 +1211,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
         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<AuthCommon, AuthItemHandler>
             ServiceContext<PoxPayloadIn, PoxPayloadOut> 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<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName(), uriInfo);
@@ -1250,7 +1256,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
         }
             
         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;
     }
index d3c8b2c3eb138af3ff4760fddf6d4374765af7b5..d3f7d599867342a868a038078154960d67028296 100644 (file)
@@ -90,6 +90,9 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
 
     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<AICommon>
         //
         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<AICommon>
         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<AICommon>
      * @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<AICommon>
         //
         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<AICommon>
                     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<AICommon>
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
             List<String> 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<AICommon>
                 releaseRepoSession = true;
             }
             DocumentFilter myFilter = getDocumentFilter();
+            if (pageSize != null) {
+                myFilter.setPageSize(pageSize);
+            }
+            if (pageNum != null) {
+                myFilter.setStartPage(pageNum);
+            }
+            myFilter.setUseDefaultOrderByClause(useDefaultOrderByClause);
 
             try {
                 DocumentWrapper<DocumentModel> 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<AICommon>
 
         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 <referenced> element as null since they're not asking for it
+            } else try {
+                return Boolean.toString(isTermReferenced(docModel)); // set the <referenced> 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);
index 6fa4762320db5db71bfa0ce89f711846730a4b81..17602660ca3b94c740e61d6ec779a5ab43247644 100644 (file)
@@ -24,6 +24,7 @@ public interface AuthorityClient<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE, P e
     public static final Boolean INCLUDE_DELETED_ITEMS = true;
     public static final Boolean INCLUDE_RELATIONS = true;
     public static final Boolean DONT_INCLUDE_RELATIONS = !INCLUDE_RELATIONS;
+    public static final String MARK_IF_REFERENCED_QP = "markIfReferenced";
 
        /*
         * Basic CRUD operations
index 24e43f1757f0c39c989203bbb556d123b25f44ac..fb7c7c2dab856ef3918faab1e8ecf64bcc5d237d 100644 (file)
@@ -54,13 +54,19 @@ public abstract class DocumentFilter {
 
     /** The max page size. */
     protected int pageSizeMax = DEFAULT_PAGE_SIZE_MAX_INIT;            // The largest page size allowed.  Can be overridden in the service-config.xml
+    
     /** The default page size. */
     public static int defaultPageSize = DEFAULT_PAGE_SIZE_INIT; // Default page size if one is specified in the service-config.xml
+    
     /** The start page. */
     protected int startPage;           // Pagination offset for list results
+    
     /** The page size. */
     protected int pageSize;                    // Pagination limit for list results
     
+    /** Flag to see if we should use default orderBy clause */
+    protected boolean useDefaultOrderByClause = true;
+    
     /** The total number of items for a query result -independent of paging restrictions.
      * 
      */
@@ -183,6 +189,14 @@ public abstract class DocumentFilter {
         this.startPage = (theStartPage > 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.
index 84faf175bc349ffbffc462651484adef49caad7d..8df70af0f387d280d55dfb98bc6cd68b57afabad 100644 (file)
@@ -172,7 +172,7 @@ public class QueryContext {
      * @return the order by clause
      */
     public String getOrderByClause() {
-       return this.orderByClause;
+           return this.orderByClause;
     }
     
     /**
index b245b098a92b2a3d583c1ab3946861d81aa86009..bb3ee993fb25511b3ac798c0859df2dfac403d20 100644 (file)
@@ -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<String> 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<DocumentModelList> docListWrapper = nuxeoRepoClient.findDocs(ctx, repoSession,
-                docTypes, query, orderByClause, pageSize, pageNum, computeTotal);
+        DocumentWrapper<DocumentModelList> 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) {
index 4b674a190810d6c59bb5e3ca25175017d8ed679d..5cce0ca2d92688017bcb90e3f486ccb94be3413f 100644 (file)
@@ -156,8 +156,10 @@ public interface RepositoryClient<IT, OT> extends StorageClient {
             ServiceContext<IT, OT> ctx,
             List<String> 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.
index 4f97aada403c01bd2d241ffbc336d33e5e342dda..a67fa584d7fcbd50021d8459efa7d1fcc0ad69ec 100644 (file)
@@ -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) {}
                        
index 563792c0e522fc7b360e50e1947eb01dd68afb07..3d07d672aa51924b706a765224e19610219327d9 100644 (file)
@@ -392,8 +392,9 @@ public class RefNameServiceUtils {
             List<String> 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<String, List<AuthRefConfigInfo>> 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<ServiceBindingType> 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<DocumentModelList> docListWrapper = nuxeoRepoClient.findDocs(ctx, repoSession,
-                docTypes, query, orderByClause, pageSize, pageNum, computeTotal);
+        DocumentWrapper<DocumentModelList> 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(
index 0d6c00facb6760d3c5a60abd96b2e78587a203d4..1822f3fdb8452d12a0a11022b113deead8513734 100644 (file)
@@ -652,8 +652,9 @@ public class NuxeoRepositoryClientImpl implements RepositoryClient<PoxPayloadIn,
             List<String> docTypes,
             String whereClause,
             String orderByClause,
-            int pageSize,
             int pageNum,
+            int pageSize,
+            boolean useDefaultOrderByClause,
             boolean computeTotal)
             throws DocumentNotFoundException, DocumentException {
         DocumentWrapper<DocumentModelList> wrapDoc = null;
@@ -665,7 +666,7 @@ public class NuxeoRepositoryClientImpl implements RepositoryClient<PoxPayloadIn,
             }
             DocumentModelList docList = null;
             QueryContext queryContext = new QueryContext(ctx, whereClause, orderByClause);
-            String query = NuxeoUtils.buildNXQLQuery(docTypes, queryContext);
+            String query = NuxeoUtils.buildNXQLQuery(docTypes, queryContext, useDefaultOrderByClause);
             if (logger.isDebugEnabled()) {
                 logger.debug("findDocs() NXQL: " + query);
             }
@@ -705,8 +706,7 @@ public class NuxeoRepositoryClientImpl implements RepositoryClient<PoxPayloadIn,
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
             DocumentHandler handler,
             CoreSessionInterface repoSession,
-            List<String> docTypes)
-            throws DocumentNotFoundException, DocumentException {
+            List<String> docTypes) throws DocumentNotFoundException, DocumentException {
         DocumentWrapper<DocumentModelList> wrapDoc = null;
 
         DocumentFilter filter = handler.getDocumentFilter();
@@ -858,15 +858,24 @@ public class NuxeoRepositoryClientImpl implements RepositoryClient<PoxPayloadIn,
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
             List<String> 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<DocumentModelList> 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) {
index 51b914d237a6c6912a6246c943feb7512403d274..66c53b116fb2724f5b37df4f6880b771e822cbb1 100644 (file)
@@ -670,7 +670,7 @@ public class NuxeoUtils {
      * @param queryContext the query context
      * @return an NXQL query
      */
-    static public final String buildNXQLQuery(List<String> docTypes, QueryContext queryContext) throws Exception {
+    static public final String buildNXQLQuery(List<String> 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<String> docTypes, QueryContext queryContext) throws Exception {
+        return buildNXQLQuery(docTypes, queryContext, true);
+    }    
+    
     static public DocumentModel getDocFromCsid(
                ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
                CoreSessionInterface repoSession,