]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-2958 Add pagination info to return payloads for refObjs and authorityrefs...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Thu, 30 Sep 2010 05:40:49 +0000 (05:40 +0000)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Thu, 30 Sep 2010 05:40:49 +0000 (05:40 +0000)
services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java
services/common/src/main/resources/authorityrefdocs.xsd
services/jaxb/src/main/resources/authorityref.xsd

index 4f5642122ccc7dfd395d38ef1adfa50604f22e19..8a691aad43c5759fee886fe4354c4469ca443d7d 100644 (file)
@@ -48,6 +48,7 @@ import org.collectionspace.services.common.document.DocumentUtils;
 import org.collectionspace.services.common.document.DocumentWrapper;\r
 import org.collectionspace.services.common.repository.RepositoryClient;\r
 import org.collectionspace.services.common.service.ServiceBindingType;\r
+import org.collectionspace.services.jaxb.AbstractCommonList;\r
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
 \r
 /**\r
@@ -66,6 +67,10 @@ public class RefNameServiceUtils {
             String refName,\r
             int pageSize, int pageNum, boolean computeTotal) throws DocumentException, DocumentNotFoundException {\r
         AuthorityRefDocList wrapperList = new AuthorityRefDocList();\r
+        AbstractCommonList commonList = (AbstractCommonList) wrapperList;\r
+        commonList.setPageNum(pageNum);\r
+        commonList.setPageSize(pageSize);\r
+        \r
         List<AuthorityRefDocList.AuthorityRefDocItem> list =\r
                 wrapperList.getAuthorityRefDocItem();\r
         TenantBindingConfigReaderImpl tReader =\r
@@ -142,6 +147,10 @@ public class RefNameServiceUtils {
                 docTypes, whereClause.toString(), pageSize, pageNum, computeTotal);\r
         // Now we gather the info for each document into the list and return\r
         DocumentModelList docList = docListWrapper.getWrappedObject();\r
+        // Set num of items in list. this is useful to our testing framework.\r
+        commonList.setItemsInPage(docList.size());\r
+        // set the total result size\r
+        commonList.setTotalItems(docList.totalSize());\r
         Iterator<DocumentModel> iter = docList.iterator();\r
         while (iter.hasNext()) {\r
             DocumentModel docModel = iter.next();\r
index 42837f1f4b431ce541b945e9992c6fb417cb1f33..b3019c2cbd63b2ee82341a585e774c81818574c3 100644 (file)
@@ -302,10 +302,22 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
             List<String> 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<AuthorityRefList.AuthorityRefItem> 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<T, TL>
                 // 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<T, TL>
                     Collection<Property> 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<Property> 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<T, TL>
     private void appendToAuthRefsList(String refName, String schemaName,
             String fieldName, List<AuthorityRefList.AuthorityRefItem> list)
             throws Exception {
-        if (refName == null || refName.trim().isEmpty()) {
-            return;
-        }
         if (DocumentUtils.getSchemaNamePart(fieldName).isEmpty()) {
             fieldName = DocumentUtils.appendSchemaName(schemaName, fieldName);
         }
index 906bace83c864e8afe54794d6a92741ea2e01427..8bd7ad64231f383c8669da8697b9fb2449486b65 100644 (file)
 -->
 <xs:schema
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
+       xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
+       jaxb:version="1.0" elementFormDefault="unqualified"
        xmlns="http://collectionspace.org/services/common/authorityref"
        targetNamespace="http://collectionspace.org/services/common/authorityref"
        version="0.1"
        >
 
+    <!-- This is the base class for paginated lists -->
+    <xs:complexType name="abstractCommonList">
+        <xs:annotation>
+            <xs:appinfo>
+                <jaxb:class ref="org.collectionspace.services.jaxb.AbstractCommonList"/>
+            </xs:appinfo>
+        </xs:annotation>
+    </xs:complexType>
+
        <xs:element name="authority-ref-doc-list">
                <xs:complexType>
-                       <xs:sequence>
-                                <xs:element name="authority-ref-doc-item" maxOccurs="unbounded">
-                                       <xs:complexType>
-                                               <xs:sequence>
-                                                       <xs:element name="docType"         type="xs:string" minOccurs="1" />
-                                                       <xs:element name="docId"           type="xs:string" minOccurs="1" />
-                                                       <xs:element name="docNumber"       type="xs:string" minOccurs="0" />
-                                                       <xs:element name="docName"         type="xs:string" minOccurs="0" />
-                                                       <xs:element name="sourceField"     type="xs:string" minOccurs="1" />
-                                                       <xs:element name="uri"             type="xs:anyURI" minOccurs="1" />
-                                               </xs:sequence>
-                                       </xs:complexType>
-                               </xs:element>
-                       </xs:sequence>
+            <xs:complexContent>
+                <xs:extension base="abstractCommonList">
+                                       <xs:sequence>
+                                                <xs:element name="authority-ref-doc-item" maxOccurs="unbounded">
+                                                       <xs:complexType>
+                                                               <xs:sequence>
+                                                                       <xs:element name="docType"         type="xs:string" minOccurs="1" />
+                                                                       <xs:element name="docId"           type="xs:string" minOccurs="1" />
+                                                                       <xs:element name="docNumber"       type="xs:string" minOccurs="0" />
+                                                                       <xs:element name="docName"         type="xs:string" minOccurs="0" />
+                                                                       <xs:element name="sourceField"     type="xs:string" minOccurs="1" />
+                                                                       <xs:element name="uri"             type="xs:anyURI" minOccurs="1" />
+                                                               </xs:sequence>
+                                                       </xs:complexType>
+                                               </xs:element>
+                                       </xs:sequence>
+                </xs:extension>
+            </xs:complexContent>        
                </xs:complexType>
        </xs:element>
 
index 5e23bfed9fbd5f102b91258d8650e5bea9147d64..2f27ea0a1e3837d1a666331158c934f38d909559 100644 (file)
 -->
 <xs:schema
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
+       xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
+       jaxb:version="1.0" elementFormDefault="unqualified"
        xmlns="http://collectionspace.org/services/common/authorityref"
        targetNamespace="http://collectionspace.org/services/common/authorityref"
        version="0.1"
        >
 
+    <!-- This is the base class for paginated lists -->
+    <xs:complexType name="abstractCommonList">
+        <xs:annotation>
+            <xs:appinfo>
+                <jaxb:class ref="org.collectionspace.services.jaxb.AbstractCommonList"/>
+            </xs:appinfo>
+        </xs:annotation>
+    </xs:complexType>
+
        <xs:element name="authority-ref-list">
                <xs:complexType>
-                       <xs:sequence>
-                                <xs:element name="authority-ref-item" maxOccurs="unbounded">
-                                       <xs:complexType>
-                                               <xs:sequence>
-                                                       <xs:element name="sourceField"     type="xs:string" minOccurs="1" />
-                                                       <xs:element name="refName"         type="xs:string" minOccurs="1" />
-                                                       <xs:element name="authDisplayName" type="xs:string" minOccurs="1" />
-                                                       <xs:element name="itemDisplayName" type="xs:string" minOccurs="1" />
-                                                       <xs:element name="uri"             type="xs:anyURI" minOccurs="1" />
-                                               </xs:sequence>
-                                       </xs:complexType>
-                               </xs:element>
-                       </xs:sequence>
+            <xs:complexContent>
+                <xs:extension base="abstractCommonList">
+                                       <xs:sequence>
+                                                <xs:element name="authority-ref-item" maxOccurs="unbounded">
+                                                       <xs:complexType>
+                                                               <xs:sequence>
+                                                                       <xs:element name="sourceField"     type="xs:string" minOccurs="1" />
+                                                                       <xs:element name="refName"         type="xs:string" minOccurs="1" />
+                                                                       <xs:element name="authDisplayName" type="xs:string" minOccurs="1" />
+                                                                       <xs:element name="itemDisplayName" type="xs:string" minOccurs="1" />
+                                                                       <xs:element name="uri"             type="xs:anyURI" minOccurs="1" />
+                                                               </xs:sequence>
+                                                       </xs:complexType>
+                                               </xs:element>
+                                       </xs:sequence>
+                </xs:extension>
+            </xs:complexContent>        
                </xs:complexType>
        </xs:element>