From: Patrick Schmitz Date: Thu, 30 Sep 2010 05:40:49 +0000 (+0000) Subject: CSPACE-2958 Add pagination info to return payloads for refObjs and authorityrefs... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=a7b1f1b98cd86b025775da088161a1ca3591983c;p=tmp%2Fjakarta-migration.git CSPACE-2958 Add pagination info to return payloads for refObjs and authorityrefs. The latter also support pagination now, where it did not before. This may seem silly, given that it is just for a given object, but it may be useful to limit the number that are shown on the right side of the UI. --- 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 4f5642122..8a691aad4 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 @@ -48,6 +48,7 @@ import org.collectionspace.services.common.document.DocumentUtils; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.repository.RepositoryClient; import org.collectionspace.services.common.service.ServiceBindingType; +import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.nuxeo.util.NuxeoUtils; /** @@ -66,6 +67,10 @@ public class RefNameServiceUtils { String refName, int pageSize, int pageNum, boolean computeTotal) throws DocumentException, DocumentNotFoundException { AuthorityRefDocList wrapperList = new AuthorityRefDocList(); + AbstractCommonList commonList = (AbstractCommonList) wrapperList; + commonList.setPageNum(pageNum); + commonList.setPageSize(pageSize); + List list = wrapperList.getAuthorityRefDocItem(); TenantBindingConfigReaderImpl tReader = @@ -142,6 +147,10 @@ public class RefNameServiceUtils { docTypes, whereClause.toString(), pageSize, pageNum, computeTotal); // Now we gather the info for each document into the list and return DocumentModelList docList = docListWrapper.getWrappedObject(); + // Set num of items in list. this is useful to our testing framework. + commonList.setItemsInPage(docList.size()); + // set the total result size + commonList.setTotalItems(docList.totalSize()); Iterator iter = docList.iterator(); while (iter.hasNext()) { DocumentModel docModel = iter.next(); diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index 42837f1f4..b3019c2cb 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -302,10 +302,22 @@ public abstract class RemoteDocumentModelHandlerImpl List authRefFieldNames) throws PropertyException { AuthorityRefList authRefList = new AuthorityRefList(); + AbstractCommonList commonList = (AbstractCommonList) authRefList; + + DocumentFilter docFilter = this.getDocumentFilter(); + long pageSize = docFilter.getPageSize(); + long pageNum = pageSize != 0 ? docFilter.getOffset() / pageSize : pageSize; + // set the page size and page number + commonList.setPageNum(pageNum); + commonList.setPageSize(pageSize); + List list = authRefList.getAuthorityRefItem(); DocumentModel docModel = docWrapper.getWrappedObject(); try { + int iFirstToUse = (int)(pageSize*pageNum); + int nFoundInPage = 0; + int nFoundTotal = 0; for (String authRefFieldName : authRefFieldNames) { // FIXME: Can use the schema to validate field existence, @@ -327,7 +339,22 @@ public abstract class RemoteDocumentModelHandlerImpl // If this is a single scalar field, with no children, // add an item with its values to the authRefs list. if (DocumentUtils.isSimpleType(prop)) { - appendToAuthRefsList(prop.getValue(String.class), schemaName, authRefFieldName, list); + String refName = prop.getValue(String.class); + if (refName == null) { + continue; + } + refName = refName.trim(); + if (refName.isEmpty()) { + continue; + } + if((nFoundTotal < iFirstToUse) + || (nFoundInPage >= pageSize)) { + nFoundTotal++; + continue; + } + nFoundTotal++; + nFoundInPage++; + appendToAuthRefsList(refName, schemaName, authRefFieldName, list); // Otherwise, if this field has children, cycle through each child. // @@ -343,22 +370,53 @@ public abstract class RemoteDocumentModelHandlerImpl Collection childProp = prop.getChildren(); for (Property cProp : childProp) { if (DocumentUtils.isSimpleType(cProp) && cProp.getName().equals(descendantAuthRefFieldName)) { - appendToAuthRefsList(cProp.getValue(String.class), schemaName, descendantAuthRefFieldName, list); + String refName = cProp.getValue(String.class); + if (refName == null) { + continue; + } + refName = refName.trim(); + if (refName.isEmpty()) { + continue; + } + if((nFoundTotal < iFirstToUse) + || (nFoundInPage >= pageSize)) { + nFoundTotal++; + continue; + } + nFoundTotal++; + nFoundInPage++; + appendToAuthRefsList(refName, schemaName, descendantAuthRefFieldName, list); } else if ((DocumentUtils.isListType(cProp) || DocumentUtils.isComplexType(cProp)) && prop.size() > 0) { Collection grandChildProp = cProp.getChildren(); for (Property gProp : grandChildProp) { if (DocumentUtils.isSimpleType(gProp) && gProp.getName().equals(descendantAuthRefFieldName)) { - appendToAuthRefsList(gProp.getValue(String.class), schemaName, descendantAuthRefFieldName, list); + String refName = gProp.getValue(String.class); + if (refName == null) { + continue; + } + refName = refName.trim(); + if (refName.isEmpty()) { + continue; + } + if((nFoundTotal < iFirstToUse) + || (nFoundInPage >= pageSize)) { + nFoundTotal++; + continue; + } + nFoundTotal++; + nFoundInPage++; + appendToAuthRefsList(refName, schemaName, descendantAuthRefFieldName, list); } } } } - } - } - + // Set num of items in list. this is useful to our testing framework. + commonList.setItemsInPage(nFoundInPage); + // set the total result size + commonList.setTotalItems(nFoundTotal); } catch (PropertyException pe) { String msg = "Attempted to retrieve value for invalid or missing authority field. " @@ -382,9 +440,6 @@ public abstract class RemoteDocumentModelHandlerImpl private void appendToAuthRefsList(String refName, String schemaName, String fieldName, List list) throws Exception { - if (refName == null || refName.trim().isEmpty()) { - return; - } if (DocumentUtils.getSchemaNamePart(fieldName).isEmpty()) { fieldName = DocumentUtils.appendSchemaName(schemaName, fieldName); } diff --git a/services/common/src/main/resources/authorityrefdocs.xsd b/services/common/src/main/resources/authorityrefdocs.xsd index 906bace83..8bd7ad642 100644 --- a/services/common/src/main/resources/authorityrefdocs.xsd +++ b/services/common/src/main/resources/authorityrefdocs.xsd @@ -17,27 +17,42 @@ --> + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/services/jaxb/src/main/resources/authorityref.xsd b/services/jaxb/src/main/resources/authorityref.xsd index 5e23bfed9..2f27ea0a1 100644 --- a/services/jaxb/src/main/resources/authorityref.xsd +++ b/services/jaxb/src/main/resources/authorityref.xsd @@ -17,26 +17,41 @@ --> + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + +