]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-7038: Added a UriInfo wrapper class to provide read-write access to query...
authorremillet <remillet@yahoo.com>
Wed, 26 Oct 2016 18:37:29 +0000 (11:37 -0700)
committerremillet <remillet@yahoo.com>
Wed, 26 Oct 2016 18:37:29 +0000 (11:37 -0700)
3rdparty/nuxeo/nuxeo-platform-collectionspace/src/main/resources/OSGI-INF/default-life-cycle-contrib.xml
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/common/UriInfoWrapper.java [new file with mode: 0644]

index f1bb7a3f412afebb56a88b65a1bb771d470b89ce..a87770312a4a96a9a11b6ea661d54d4425114cf3 100644 (file)
                                        <description>Replicate a document from the project state</description>
                                </transition>
                                <transition name="deprecate" destinationState="deprecated">
-                                       <description>Soft-delete the document from the project state</description>
+                                       <description>Deprecate the document from the project state</description>
                                </transition>
                                <transition name="delete" destinationState="deleted">
                                        <description>Soft-delete the document from the project state</description>
index ff5f1b763a34a1a3653462b428897dcbd0bed251..2637ec6a53bb94ba883430b29a62cfb170180993 100644 (file)
@@ -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<AuthCommon, AuthItemHandler>
     @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<AuthCommon, AuthItemHandler>
         //
        synchronized(AuthorityResource.class) {        
                try {
-                   ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(ui);
+                   ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(uriInfo);
                    /*
                     * Make sure this authority service supports synchronization
                     */
@@ -418,11 +419,12 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     @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<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(ui);
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(uriInfo);
             DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createDocumentHandler(ctx);
 
             Specifier spec = Specifier.getSpecifier(specifier, "getAuthority", "GET");
@@ -463,6 +465,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     @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<AuthCommon, AuthItemHandler>
     @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<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(ui);
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(uriInfo);
             DocumentHandler<?, AbstractCommonList, DocumentModel, DocumentModelList> handler = createDocumentHandler(ctx);
 
             Specifier spec = Specifier.getSpecifier(specifier, "getAuthority", "GET");
@@ -681,6 +686,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
                @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<AuthCommon, AuthItemHandler>
             @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<AuthCommon, AuthItemHandler>
                @Context ResourceMap resourceMap,            
             @PathParam("csid") String parentIdentifier,
             @PathParam("itemcsid") String itemIdentifier) {
+       uriInfo = new UriInfoWrapper(uriInfo);
         PoxPayloadOut result = null;
         try {
             RemoteServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = 
@@ -988,6 +996,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     @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<AuthCommon, AuthItemHandler>
             @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<AuthCommon, AuthItemHandler>
             String itemspecifier,
             UriTemplateRegistry uriTemplateRegistry,
             UriInfo uriInfo) throws Exception {
+       uriInfo = new UriInfoWrapper(uriInfo);
        AuthorityRefDocList authRefDocList = null;
  
         ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName(), uriInfo);
@@ -1064,14 +1075,6 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
 
         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<String, String> tmpQueryParams = new MultivaluedHashMap<String, String>();
-        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<String> serviceTypes = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP);        
@@ -1101,6 +1104,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
             @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<AuthCommon, AuthItemHandler>
             @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<AuthCommon, AuthItemHandler>
             @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<AuthCommon, AuthItemHandler>
             @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<AuthCommon, AuthItemHandler>
                @PathParam("csid") String parentIdentifier,
             @PathParam("itemcsid") String itemIdentifier,
             @Context UriInfo uriInfo) throws Exception {
+       uriInfo = new UriInfoWrapper(uriInfo);
        String result = null;
 
         try {
index 2d6f74a3c0dd7af08ee76635251d681427008b39..2220747063ac075574d64844cbed7b87e7f42ece 100644 (file)
@@ -759,6 +759,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
                //
                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 (file)
index 0000000..e9b241a
--- /dev/null
@@ -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<String, String> queryParams = new MultivaluedHashMap<String, String>();
+
+       @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<Object> getMatchedResources() {
+               return uriInfo.getMatchedResources();
+       }
+
+       @Override
+       public List<String> getMatchedURIs() {
+               return uriInfo.getMatchedURIs();
+       }
+
+       @Override
+       public List<String> 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<String, String> getPathParameters() {
+               return uriInfo.getPathParameters();
+       }
+
+       @Override
+       public MultivaluedMap<String, String> getPathParameters(boolean arg0) {
+               return uriInfo.getPathParameters(arg0);
+       }
+
+       @Override
+       public List<PathSegment> getPathSegments() {
+               return uriInfo.getPathSegments();
+       }
+
+       @Override
+       public List<PathSegment> getPathSegments(boolean arg0) {
+               return uriInfo.getPathSegments(arg0);
+       }
+
+       @Override
+       public MultivaluedMap<String, String> getQueryParameters() {
+               return this.queryParams;
+       }
+
+       /**
+        * Not implemented.
+        * 
+        */
+       @Override
+       public MultivaluedMap<String, String> 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);
+       }
+
+}