From ba27b8f47db01b428cbb1c464fc7a702a11660fe Mon Sep 17 00:00:00 2001 From: remillet Date: Wed, 26 Oct 2016 11:37:29 -0700 Subject: [PATCH] CSPACE-7038: Added a UriInfo wrapper class to provide read-write access to query parameters. --- .../OSGI-INF/default-life-cycle-contrib.xml | 2 +- .../common/vocabulary/AuthorityResource.java | 38 +++-- .../AuthorityItemDocumentModelHandler.java | 1 + .../services/common/UriInfoWrapper.java | 134 ++++++++++++++++++ 4 files changed, 159 insertions(+), 16 deletions(-) create mode 100644 services/common/src/main/java/org/collectionspace/services/common/UriInfoWrapper.java diff --git a/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml b/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml index f1bb7a3f4..a87770312 100644 --- a/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml +++ b/3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml @@ -107,7 +107,7 @@ Replicate a document from the project state - Soft-delete the document from the project state + Deprecate the document from the project state Soft-delete the document from the project state diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index ff5f1b763..2637ec6a5 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -40,7 +40,6 @@ import javax.ws.rs.core.Request; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; -import javax.ws.rs.core.MultivaluedHashMap; import org.collectionspace.services.client.IClientQueryParams; import org.collectionspace.services.client.IQueryManager; @@ -54,6 +53,7 @@ import org.collectionspace.services.common.ResourceMap; import org.collectionspace.services.common.ServiceMain; 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; @@ -362,8 +362,9 @@ public abstract class AuthorityResource @Path("{csid}/sync") public byte[] synchronize( @Context Request request, - @Context UriInfo ui, + @Context UriInfo uriInfo, @PathParam("csid") String identifier) { + uriInfo = new UriInfoWrapper(uriInfo); byte[] result; boolean neededSync = false; PoxPayloadOut payloadOut = null; @@ -374,7 +375,7 @@ public abstract class AuthorityResource // synchronized(AuthorityResource.class) { try { - ServiceContext ctx = createServiceContext(ui); + ServiceContext ctx = createServiceContext(uriInfo); /* * Make sure this authority service supports synchronization */ @@ -418,11 +419,12 @@ public abstract class AuthorityResource @Override public byte[] get( @Context Request request, - @Context UriInfo ui, + @Context UriInfo uriInfo, @PathParam("csid") String specifier) { + uriInfo = new UriInfoWrapper(uriInfo); PoxPayloadOut result = null; try { - ServiceContext ctx = createServiceContext(ui); + ServiceContext ctx = createServiceContext(uriInfo); DocumentHandler handler = createDocumentHandler(ctx); Specifier spec = Specifier.getSpecifier(specifier, "getAuthority", "GET"); @@ -463,6 +465,7 @@ public abstract class AuthorityResource @GET @Produces("application/xml") public AbstractCommonList getAuthorityList(@Context UriInfo uriInfo) { //FIXME - REM 5/3/2012 - This is not reachable from the JAX-RS dispatcher. Instead the equivalent method in ResourceBase is getting called. + uriInfo = new UriInfoWrapper(uriInfo); AbstractCommonList result = null; try { @@ -579,14 +582,16 @@ public abstract class AuthorityResource @Path("{csid}") public Response deleteAuthority( @Context Request request, - @Context UriInfo ui, + @Context UriInfo uriInfo, @PathParam("csid") String specifier) { + uriInfo = new UriInfoWrapper(uriInfo); + if (logger.isDebugEnabled()) { logger.debug("deleteAuthority with specifier=" + specifier); } try { - ServiceContext ctx = createServiceContext(ui); + ServiceContext ctx = createServiceContext(uriInfo); DocumentHandler handler = createDocumentHandler(ctx); Specifier spec = Specifier.getSpecifier(specifier, "getAuthority", "GET"); @@ -681,6 +686,7 @@ public abstract class AuthorityResource @Context UriInfo uriInfo, @PathParam("csid") String parentIdentifier, // Either a CSID or a URN form -e.g., a8ad38ec-1d7d-4bf2-bd31 or urn:cspace:name(bugsbunny) String xmlPayload) { + uriInfo = new UriInfoWrapper(uriInfo); Response result = null; try { @@ -726,6 +732,7 @@ public abstract class AuthorityResource @PathParam("csid") String parentIdentifier, @PathParam("itemcsid") String itemIdentifier, @PathParam("transition") String transition) { + uriInfo = new UriInfoWrapper(uriInfo); PoxPayloadOut result = null; try { @@ -870,6 +877,7 @@ public abstract class AuthorityResource @Context ResourceMap resourceMap, @PathParam("csid") String parentIdentifier, @PathParam("itemcsid") String itemIdentifier) { + uriInfo = new UriInfoWrapper(uriInfo); PoxPayloadOut result = null; try { RemoteServiceContext ctx = @@ -988,6 +996,7 @@ public abstract class AuthorityResource @Produces("application/xml") public AbstractCommonList getAuthorityItemList(@PathParam("csid") String authorityIdentifier, @Context UriInfo uriInfo) { + uriInfo = new UriInfoWrapper(uriInfo); AbstractCommonList result = null; try { @@ -1028,6 +1037,7 @@ public abstract class AuthorityResource @PathParam("itemcsid") String itemSpecifier, @Context UriTemplateRegistry uriTemplateRegistry, @Context UriInfo uriInfo) { + uriInfo = new UriInfoWrapper(uriInfo); AuthorityRefDocList authRefDocList = null; try { authRefDocList = getReferencingObjects(null, parentSpecifier, itemSpecifier, uriTemplateRegistry, uriInfo); @@ -1050,6 +1060,7 @@ public abstract class AuthorityResource String itemspecifier, UriTemplateRegistry uriTemplateRegistry, UriInfo uriInfo) throws Exception { + uriInfo = new UriInfoWrapper(uriInfo); AuthorityRefDocList authRefDocList = null; ServiceContext ctx = createServiceContext(getItemServiceName(), uriInfo); @@ -1064,14 +1075,6 @@ public abstract class AuthorityResource String parentcsid = lookupParentCSID(ctx, parentspecifier, "getReferencingObjects(parent)", "GET_ITEM_REF_OBJS", uriInfo); String itemcsid = lookupItemCSID(ctx, itemspecifier, parentcsid, "getReferencingObjects(item)", "GET_ITEM_REF_OBJS"); - - // RESTEasy returns a read-only set of query params, so we need to make a read-write copy of them - MultivaluedHashMap tmpQueryParams = new MultivaluedHashMap(); - tmpQueryParams.putAll(queryParams); - // Set the original query params to the new copy - queryParams = tmpQueryParams; - // Update the service context with the new copy - ctx.setQueryParams(queryParams); // Remove the "type" property from the query params List serviceTypes = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP); @@ -1101,6 +1104,7 @@ public abstract class AuthorityResource @PathParam("csid") String parentspecifier, @PathParam("itemcsid") String itemspecifier, @Context UriInfo uriInfo) { + uriInfo = new UriInfoWrapper(uriInfo); AuthorityRefList authRefList = null; try { @@ -1203,6 +1207,7 @@ public abstract class AuthorityResource @Context UriInfo uriInfo, @PathParam("csid") String parentIdentifier, @PathParam("itemcsid") String itemIdentifier) { + uriInfo = new UriInfoWrapper(uriInfo); byte[] result; boolean neededSync = false; PoxPayloadOut payloadOut = null; @@ -1248,6 +1253,7 @@ public abstract class AuthorityResource @PathParam("csid") String parentSpecifier, @PathParam("itemcsid") String itemSpecifier, String xmlPayload) { + uriInfo = new UriInfoWrapper(uriInfo); PoxPayloadOut result = null; try { @@ -1320,6 +1326,7 @@ public abstract class AuthorityResource @Context UriInfo uriInfo, @PathParam("csid") String parentIdentifier, @PathParam("itemcsid") String itemIdentifier) { + uriInfo = new UriInfoWrapper(uriInfo); Response result = null; ensureCSID(parentIdentifier, ServiceMessages.DELETE_FAILED, "AuthorityItem.parentcsid"); @@ -1383,6 +1390,7 @@ public abstract class AuthorityResource @PathParam("csid") String parentIdentifier, @PathParam("itemcsid") String itemIdentifier, @Context UriInfo uriInfo) throws Exception { + uriInfo = new UriInfoWrapper(uriInfo); String result = null; try { diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index 2d6f74a3c..222074706 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -759,6 +759,7 @@ public abstract class AuthorityItemDocumentModelHandler // ctx.setUriInfo(this.getServiceContext().getUriInfo()); // try to get a UriInfo instance from the handler's context } + ctx.getUriInfo().getQueryParameters().addFirst(WorkflowClient.WORKFLOW_QUERY_ONLY_DELETED, Boolean.toString(onlyRefsToDeletedObjects)); // Add the wf_only_deleted query param to the resource call AuthorityRefDocList refObjs = authorityResource.getReferencingObjects(ctx, inAuthorityCsid, itemCsid, uriTemplateRegistry, ctx.getUriInfo()); diff --git a/services/common/src/main/java/org/collectionspace/services/common/UriInfoWrapper.java b/services/common/src/main/java/org/collectionspace/services/common/UriInfoWrapper.java new file mode 100644 index 000000000..e9b241a34 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/UriInfoWrapper.java @@ -0,0 +1,134 @@ +package org.collectionspace.services.common; + +import java.net.URI; +import java.util.List; + +import javax.ws.rs.core.MultivaluedHashMap; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.PathSegment; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; + +/** + * + * @author remillet + * + * The older versions of RESTEasy allowed us to modify the query parameters passed into us from the UriInfo class. There + * are many places in the existing code that rely on changes to the query parameters. But more recent versions of RESTEasy + * pass us a read-only copy of the query parameters. Therefore, this wrapper class allows us to provide the existing code + * a read-write copy of the query parameters. + * + */ +public class UriInfoWrapper implements UriInfo { + // + // Construct the UriInfoWrapper from a UriInfo instance + // + public UriInfoWrapper(UriInfo uriInfo) { + this.uriInfo = uriInfo; + // RESTEasy returns a read-only set of query params, so we need to make a read-write copy of them + queryParams.putAll(uriInfo.getQueryParameters()); + } + + private UriInfo uriInfo; + private MultivaluedHashMap queryParams = new MultivaluedHashMap(); + + @Override + public URI getAbsolutePath() { + return uriInfo.getAbsolutePath(); + } + + @Override + public UriBuilder getAbsolutePathBuilder() { + return uriInfo.getAbsolutePathBuilder(); + } + + @Override + public URI getBaseUri() { + return uriInfo.getBaseUri(); + } + + @Override + public UriBuilder getBaseUriBuilder() { + return uriInfo.getBaseUriBuilder(); + } + + @Override + public List getMatchedResources() { + return uriInfo.getMatchedResources(); + } + + @Override + public List getMatchedURIs() { + return uriInfo.getMatchedURIs(); + } + + @Override + public List getMatchedURIs(boolean arg0) { + return uriInfo.getMatchedURIs(arg0); + } + + @Override + public String getPath() { + return uriInfo.getPath(); + } + + @Override + public String getPath(boolean arg0) { + return uriInfo.getPath(); + } + + @Override + public MultivaluedMap getPathParameters() { + return uriInfo.getPathParameters(); + } + + @Override + public MultivaluedMap getPathParameters(boolean arg0) { + return uriInfo.getPathParameters(arg0); + } + + @Override + public List getPathSegments() { + return uriInfo.getPathSegments(); + } + + @Override + public List getPathSegments(boolean arg0) { + return uriInfo.getPathSegments(arg0); + } + + @Override + public MultivaluedMap getQueryParameters() { + return this.queryParams; + } + + /** + * Not implemented. + * + */ + @Override + public MultivaluedMap getQueryParameters(boolean arg0) { + throw new java.lang.UnsupportedOperationException(); + } + + @Override + public URI getRequestUri() { + return uriInfo.getRequestUri(); + } + + @Override + public UriBuilder getRequestUriBuilder() { + return uriInfo.getRequestUriBuilder(); + } + + @Override + public URI relativize(URI arg0) { + return uriInfo.relativize(arg0); + } + + @Override + public URI resolve(URI arg0) { + return uriInfo.resolve(arg0); + } + +} -- 2.47.3