]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1469: Added ititial paging support to CollectionObjectResource.java.
authorRichard Millet <richard.millet@berkeley.edu>
Mon, 26 Apr 2010 23:01:10 +0000 (23:01 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Mon, 26 Apr 2010 23:01:10 +0000 (23:01 +0000)
services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/nuxeo/AcquisitionDocumentModelHandler.java
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java
services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java

index a361bcb427bf70012cde3cb2197303565519deca..df4958b0a64f340eecef70dd0bc130fd95e347f4 100644 (file)
@@ -176,6 +176,9 @@ public class AcquisitionDocumentModelHandler
     private static String NAME_VALUE_SEPARATOR = "|";
 
     private static class NameValue {
+       NameValue() {
+                       // default scoped constructor to remove "synthetic accessor" warning
+               }
         String name;
         String value;
     };
index b7bc3ffb44eb266b097b6ae5f7d0a626e4272316..ef0bf24c2ddaa4ca8a8de8cb6d8857cec13de23d 100644 (file)
@@ -42,6 +42,7 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.MultivaluedMap;
 
 import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
@@ -62,7 +63,8 @@ import org.collectionspace.services.common.security.UnauthorizedException;
 import org.collectionspace.services.common.vocabulary.RefNameServiceUtils;
 import org.collectionspace.services.intake.IntakeResource;
 import org.collectionspace.services.intake.IntakesCommonList;
-import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
+//import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
+import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
 import org.collectionspace.services.relation.NewRelationResource;
 import org.collectionspace.services.relation.RelationsCommonList;
 import org.collectionspace.services.relation.RelationshipType;
@@ -236,10 +238,11 @@ public class CollectionObjectResource
     public CollectionobjectsCommonList getCollectionObjectList(@Context UriInfo ui,
                @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords) {
        CollectionobjectsCommonList result = null;
+       MultivaluedMap queryParams = ui.getQueryParameters();
        if (keywords != null) {
-               result = searchCollectionObjects(keywords);
+               result = searchCollectionObjects(queryParams, keywords);
        } else {
-               result = getCollectionObjectList();
+               result = getCollectionObjectList(queryParams);
        }
        
        return result;
@@ -248,12 +251,12 @@ public class CollectionObjectResource
     /**
      * Gets the collection object list.
      */
-    private CollectionobjectsCommonList getCollectionObjectList() {
+    private CollectionobjectsCommonList getCollectionObjectList(MultivaluedMap queryParams) {
         CollectionobjectsCommonList collectionObjectList;
         try {
-            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             DocumentHandler handler = createDocumentHandler(ctx);
-            getRepositoryClient(ctx).getAll(ctx, handler);
+            getRepositoryClient(ctx).getFiltered(ctx, handler);
             collectionObjectList = (CollectionobjectsCommonList) handler.getCommonPartList();
         } catch (UnauthorizedException ue) {
             Response response = Response.status(
@@ -438,12 +441,12 @@ public class CollectionObjectResource
             ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentWrapper<DocumentModel> docWrapper = 
                getRepositoryClient(ctx).getDoc(ctx, csid);
-            RemoteDocumentModelHandlerImpl handler 
-               = (RemoteDocumentModelHandlerImpl)createDocumentHandler(ctx);
+            DocumentModelHandler<MultipartInput, MultipartOutput> docHandler = 
+               (DocumentModelHandler<MultipartInput, MultipartOutput>)createDocumentHandler(ctx);
             List<String> authRefFields = 
                ((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues(
                                ServiceBindingUtils.AUTH_REF_PROP, ServiceBindingUtils.QUALIFIED_PROP_NAMES);
-            authRefList = handler.getAuthorityRefs(docWrapper, authRefFields);
+            authRefList = docHandler.getAuthorityRefs(docWrapper, authRefFields);
         } catch (UnauthorizedException ue) {
             Response response = Response.status(
                     Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
@@ -487,6 +490,7 @@ public class CollectionObjectResource
     /**
      * This method is deprecated.  Use kwSearchCollectionObjects() method instead.
      * Keywords search collection objects.
+     * @param ui 
      * 
      * @param keywords the keywords
      * 
@@ -495,9 +499,10 @@ public class CollectionObjectResource
     @GET
     @Path("/search")
     @Produces("application/xml")
-    public CollectionobjectsCommonList keywordsSearchCollectionObjects(
+    public CollectionobjectsCommonList keywordsSearchCollectionObjects(@Context UriInfo ui,
             @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS) String keywords) {
-       return searchCollectionObjects(keywords);
+       MultivaluedMap queryParams = ui.getQueryParameters();
+       return searchCollectionObjects(queryParams, keywords);
     }    
     
     /**
@@ -507,27 +512,25 @@ public class CollectionObjectResource
      * 
      * @return the collectionobjects common list
      */
-    private CollectionobjectsCommonList searchCollectionObjects(String keywords) {
+    private CollectionobjectsCommonList searchCollectionObjects(
+               MultivaluedMap<String, String> queryParams,
+               String keywords) {
         CollectionobjectsCommonList collectionObjectList;
         try {
-            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             DocumentHandler handler = createDocumentHandler(ctx);
 
             // perform a keyword search
             if (keywords != null && !keywords.isEmpty()) {
                 String whereClause = QueryManager.createWhereClauseFromKeywords(keywords);
-                //DocumentFilter documentFilter = handler.createDocumentFilter(ctx);
                 DocumentFilter documentFilter = handler.getDocumentFilter();
                 documentFilter.setWhereClause(whereClause);
                 if (logger.isDebugEnabled()) {
                     logger.debug("The WHERE clause is: " + documentFilter.getWhereClause());
                 }
-                getRepositoryClient(ctx).getFiltered(ctx, handler);
-            } else {
-                getRepositoryClient(ctx).getAll(ctx, handler);
             }
+            getRepositoryClient(ctx).getFiltered(ctx, handler);
             collectionObjectList = (CollectionobjectsCommonList) handler.getCommonPartList();
-
         } catch (UnauthorizedException ue) {
             Response response = Response.status(
                     Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
index 6b81435db737db6bcec6e6ff55246b7f114951e6..c9f23e3112f1eff251e2ec9931ac54ec88e3e959 100644 (file)
@@ -56,7 +56,9 @@ public class DocumentUtils {
     private static String NAME_VALUE_SEPARATOR = "|";
 
     private static class NameValue {
-
+       NameValue() {
+               // default scoped constructor to removed "synthetic accessor" warning
+       }
         String name;
         String value;
     };
index ac2c147a50f78a696d3dff9d253b5b5d780518c5..beca05de0fcc5d0d44c1b48a1d817d1d4df7a87c 100644 (file)
@@ -23,6 +23,9 @@
  */
 package org.collectionspace.services.nuxeo.client.java;
 
+import java.util.List;
+
+import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl;
 import org.collectionspace.services.common.document.DocumentFilter;
@@ -30,6 +33,7 @@ import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.nuxeo.client.*;
 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.api.repository.RepositoryInstance;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -119,5 +123,17 @@ public abstract class DocumentModelHandler<T, TL>
        DocumentFilter filter = new NuxeoDocumentFilter(this.getServiceContext());
        return filter;
     }
+    
+    /**
+     * Gets the authority refs.
+     *
+     * @param docWrapper the doc wrapper
+     * @param authRefFields the auth ref fields
+     * @return the authority refs
+     * @throws PropertyException the property exception
+     */
+    abstract public AuthorityRefList getAuthorityRefs(
+            DocumentWrapper<DocumentModel> docWrapper,
+               List<String> authRefFields) throws PropertyException;    
 
 }
index 6e29b3467c2456733f08382289ed2f7e6ecffadf..4ea6e9309204242703d49b64458d00141d1c7802 100644 (file)
@@ -204,59 +204,54 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
         return result;
     }
     
-    /**
-     * @param docWrapper
-     * @param authRefFields list of schema-qualified field names
-     * @return
-     * @throws PropertyException
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getAuthorityRefs(org.collectionspace.services.common.document.DocumentWrapper, java.util.List)
      */
+    @Override
     public AuthorityRefList getAuthorityRefs(
-                DocumentWrapper<DocumentModel> docWrapper,
+               DocumentWrapper<DocumentModel> docWrapper,
                List<String> authRefFields) throws PropertyException {
        AuthorityRefList authRefList = new AuthorityRefList();
-        try {
-            DocumentModel docModel = docWrapper.getWrappedObject();
-            List<AuthorityRefList.AuthorityRefItem> list = 
-               authRefList.getAuthorityRefItem();
+       try {
+               DocumentModel docModel = docWrapper.getWrappedObject();
+               List<AuthorityRefList.AuthorityRefItem> list = authRefList.getAuthorityRefItem();
 
-            for(String field:authRefFields){
-                String refName = (String)docModel.getPropertyValue(field);
-                if(refName==null)
-                    continue;
-               try{
-                    RefNameUtils.AuthorityTermInfo termInfo =
-                        RefNameUtils.parseAuthorityTermInfo(refName);
-                    AuthorityRefList.AuthorityRefItem ilistItem =
-                        new AuthorityRefList.AuthorityRefItem();
-                    ilistItem.setRefName(refName);
-                    ilistItem.setAuthDisplayName(termInfo.inAuthority.displayName);
-                    ilistItem.setItemDisplayName(termInfo.displayName);
-                    ilistItem.setSourceField(field);
-                    ilistItem.setUri(termInfo.getRelativeUri());
-                    list.add(ilistItem);
-               } catch( Exception e ) {
-                    // FIXME: Do we need to throw this Exception here?
-                    if (logger.isDebugEnabled()) {
-                        logger.debug("Caught exception in getAuthorityRefs", e);
-                    }
-               }
-            }
-        } catch (PropertyException pe) {
-            String msg =
-                "Attempted to retrieve value for invalid or missing authority field. " +
-                "Check authority field properties in tenant bindings.";
-            logger.warn(msg, pe);
-            throw pe;
-        } catch (Exception e) {
-            if (logger.isDebugEnabled()) {
-                logger.debug("Caught exception in getAuthorityRefs", e);
-            }
-            Response response = Response.status(
-                    Response.Status.INTERNAL_SERVER_ERROR).entity("Failed to retrieve authority references").type("text/plain").build();
-            throw new WebApplicationException(response);
-        }
-        return authRefList;
+               for (String field : authRefFields) {
+                       String refName = (String) docModel.getPropertyValue(field);
+                       if (refName == null)
+                               continue;
+                       try {
+                               RefNameUtils.AuthorityTermInfo termInfo = RefNameUtils
+                               .parseAuthorityTermInfo(refName);
+                               AuthorityRefList.AuthorityRefItem ilistItem = new AuthorityRefList.AuthorityRefItem();
+                               ilistItem.setRefName(refName);
+                               ilistItem.setAuthDisplayName(termInfo.inAuthority.displayName);
+                               ilistItem.setItemDisplayName(termInfo.displayName);
+                               ilistItem.setSourceField(field);
+                               ilistItem.setUri(termInfo.getRelativeUri());
+                               list.add(ilistItem);
+                       } catch (Exception e) {
+                               // FIXME: Do we need to throw this Exception here?
+                               if (logger.isDebugEnabled()) {
+                                       logger.debug("Caught exception in getAuthorityRefs", e);
+                               }
+                       }
+               }
+       } catch (PropertyException pe) {
+               String msg = "Attempted to retrieve value for invalid or missing authority field. "
+                       + "Check authority field properties in tenant bindings.";
+               logger.warn(msg, pe);
+               throw pe;
+       } catch (Exception e) {
+               if (logger.isDebugEnabled()) {
+                       logger.debug("Caught exception in getAuthorityRefs", e);
+               }
+               Response response = Response.status(
+                               Response.Status.INTERNAL_SERVER_ERROR).entity(
+                               "Failed to retrieve authority references").type(
+                               "text/plain").build();
+               throw new WebApplicationException(response);
+       }
+       return authRefList;
     }
-
-
 }
index cd371656aa4caa9b8ddaa814fb8f47417e882638..d9d033033aa119682cb6691ace5b8d090f05b775 100644 (file)
@@ -745,8 +745,9 @@ public class RepositoryJavaClientImpl implements RepositoryClient {
         if ((null != where) && (where.length() > 0)) {
                // Due to an apparent bug/issue in how Nuxeo translates the NXQL query string
                // into SQL, we need to parenthesize our 'where' clause
-            query.append(" AND " + "(" + where +")" + "AND ecm:isProxy = 0");
+            query.append(" AND " + "(" + where +")");
         }
+        query.append(" AND ecm:isProxy = 0");
     }
 
     private final String buildNXQLQuery(String docType, String where, String domain ) {