From: Richard Millet Date: Mon, 26 Apr 2010 23:01:10 +0000 (+0000) Subject: CSPACE-1469: Added ititial paging support to CollectionObjectResource.java. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=0829a91bd0e7ba3aed5edf71d6959a9baca4d9e2;p=tmp%2Fjakarta-migration.git CSPACE-1469: Added ititial paging support to CollectionObjectResource.java. --- diff --git a/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/nuxeo/AcquisitionDocumentModelHandler.java b/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/nuxeo/AcquisitionDocumentModelHandler.java index a361bcb42..df4958b0a 100644 --- a/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/nuxeo/AcquisitionDocumentModelHandler.java +++ b/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/nuxeo/AcquisitionDocumentModelHandler.java @@ -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; }; diff --git a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java index b7bc3ffb4..ef0bf24c2 100644 --- a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java +++ b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java @@ -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 ctx = createServiceContext(); + ServiceContext 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 ctx = createServiceContext(); DocumentWrapper docWrapper = getRepositoryClient(ctx).getDoc(ctx, csid); - RemoteDocumentModelHandlerImpl handler - = (RemoteDocumentModelHandlerImpl)createDocumentHandler(ctx); + DocumentModelHandler docHandler = + (DocumentModelHandler)createDocumentHandler(ctx); List 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 queryParams, + String keywords) { CollectionobjectsCommonList collectionObjectList; try { - ServiceContext ctx = createServiceContext(); + ServiceContext 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(); diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java index 6b81435db..c9f23e311 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java @@ -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; }; diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java index ac2c147a5..beca05de0 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java @@ -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 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 docWrapper, + List authRefFields) throws PropertyException; } 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 6e29b3467..4ea6e9309 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 @@ -204,59 +204,54 @@ public abstract class RemoteDocumentModelHandlerImpl 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 docWrapper, + DocumentWrapper docWrapper, List authRefFields) throws PropertyException { AuthorityRefList authRefList = new AuthorityRefList(); - try { - DocumentModel docModel = docWrapper.getWrappedObject(); - List list = - authRefList.getAuthorityRefItem(); + try { + DocumentModel docModel = docWrapper.getWrappedObject(); + List 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; } - - } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java index cd371656a..d9d033033 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java @@ -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 ) {