]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5518: Final changes to service context setup to support existing hierarchy...
authorRichard Millet <remillet@berkeley.edu>
Mon, 10 Sep 2012 18:49:20 +0000 (11:49 -0700)
committerRichard Millet <remillet@berkeley.edu>
Mon, 10 Sep 2012 18:49:20 +0000 (11:49 -0700)
services/IntegrationTests/src/test/resources/test-data/xmlreplay/collectionobject/collectionobject-hierarchy.xml
services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java
services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java
services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java
services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java
services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextImpl.java

index 1b47e4e088713a1fdae1c45164534db819c9199d..23d9212da6d1eb2e9ff5010ff35bef1a91a0906a 100644 (file)
@@ -1,7 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <xmlReplay>
-
-    <testGroup ID="HierarchicCollectionObject" autoDeletePOSTS="false">
     
     <testGroup ID="CreateCollectionObjects"> <!-- autoDeletePOSTS="true" -->
         
index 170e056120b3b541accbbdf9fd20971afb757ae9..8bca8c47f7b8ec907e7bcb67cae25ee861250bbc 100644 (file)
@@ -123,7 +123,7 @@ public class AccountResource extends SecurityResourceBase {
 
     @DELETE
     @Path("{csid}")
-    public Response deleteAccount(@PathParam("csid") String csid) {
+    public Response deleteAccount(@Context UriInfo uriInfo, @PathParam("csid") String csid) {
         logger.debug("deleteAccount with csid=" + csid);
         ensureCSID(csid, ServiceMessages.DELETE_FAILED);
         try {
@@ -139,7 +139,7 @@ public class AccountResource extends SecurityResourceBase {
             AccountRoleSubResource subResource = new AccountRoleSubResource("accounts/accountroles");
             subResource.deleteAccountRole(csid, SubjectType.ROLE);
             ServiceContext<AccountsCommon, AccountsCommon> ctx = createServiceContext((AccountsCommon) null,
-                    AccountsCommon.class);
+                    AccountsCommon.class, uriInfo);
             getStorageClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (Exception e) {
index 1388e31c890c37504ee97e784046e939ad87f414..3fbdf24e83395569e6c9a683d7b54d22520a4388 100644 (file)
@@ -215,6 +215,17 @@ public abstract class AbstractCollectionSpaceResourceImpl<IT, OT>
         return ctx;\r
     }\r
     \r
+    protected ServiceContext<IT, OT> createServiceContext(String serviceName,\r
+               IT input,\r
+               UriInfo uriInfo) throws Exception {     \r
+        ServiceContext<IT, OT> ctx = createServiceContext(serviceName,\r
+                       input,\r
+                       null, // The resource map\r
+                       uriInfo, /*queryParams*/\r
+                       (Class<?>)null  /*input type's Class*/);\r
+        return ctx;\r
+    }\r
+    \r
     protected ServiceContext<IT, OT> createServiceContext(UriInfo uriInfo) throws Exception {\r
         ServiceContext<IT, OT> ctx = createServiceContext(\r
                        (IT)null, /*input*/\r
@@ -239,6 +250,14 @@ public abstract class AbstractCollectionSpaceResourceImpl<IT, OT>
         return ctx;\r
     }\r
     \r
+    protected ServiceContext<IT, OT> createServiceContext(IT input, UriInfo uriInfo) throws Exception {        \r
+        ServiceContext<IT, OT> ctx = createServiceContext(\r
+                       input,\r
+                       uriInfo,\r
+                       null ); // The class param/argument\r
+        return ctx;\r
+    }    \r
+    \r
     /**\r
      * Creates the service context.\r
      * \r
@@ -257,6 +276,14 @@ public abstract class AbstractCollectionSpaceResourceImpl<IT, OT>
         return ctx;\r
     }\r
     \r
+    protected ServiceContext<IT, OT> createServiceContext(IT input, Class<?> theClass, UriInfo uriInfo) throws Exception {     \r
+        ServiceContext<IT, OT> ctx = createServiceContext(\r
+                       input,\r
+                       uriInfo,\r
+                       theClass);\r
+        return ctx;\r
+    }\r
+    \r
     protected ServiceContext<IT, OT> createServiceContext(\r
                String serviceName,\r
                ResourceMap resourceMap,\r
index d7dab54dab947e7caec2514538c7c7c18aabdc99..726b1420d8557805d355be61340bd0145233ae3f 100644 (file)
@@ -33,6 +33,8 @@ import javax.ws.rs.GET;
 import javax.ws.rs.PUT;\r
 import javax.ws.rs.Path;\r
 import javax.ws.rs.PathParam;\r
+import javax.ws.rs.core.Context;\r
+import javax.ws.rs.core.UriInfo;\r
 \r
 import org.collectionspace.services.client.PayloadOutputPart;\r
 import org.collectionspace.services.client.PoxPayloadIn;\r
@@ -141,13 +143,13 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr
      */\r
     @GET\r
     @Path(WorkflowClient.SERVICE_PATH)\r
-    public Lifecycle getWorkflow() {\r
+    public Lifecycle getWorkflow(@Context UriInfo uriInfo) {\r
        Lifecycle result;\r
 \r
         String documentType = "undefined";\r
         MultipartServiceContext ctx = null;\r
         try {\r
-            ctx = (MultipartServiceContext) createServiceContext();\r
+            ctx = (MultipartServiceContext) createServiceContext(uriInfo);\r
             DocumentHandler handler = ctx.getDocumentHandler();\r
             result = handler.getLifecycle();\r
         } catch (Exception e) {\r
@@ -172,14 +174,15 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr
     @GET\r
     @Path("{csid}" + WorkflowClient.SERVICE_PATH)\r
     public byte[] getWorkflow(\r
+               @Context UriInfo uriInfo,\r
             @PathParam("csid") String csid) {\r
         PoxPayloadOut result = null;\r
 \r
         try {\r
-            ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx = createServiceContext();\r
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx = createServiceContext(uriInfo);\r
             String parentWorkspaceName = parentCtx.getRepositoryWorkspaceName();\r
 \r
-            MultipartServiceContext ctx = (MultipartServiceContext) createServiceContext(WorkflowClient.SERVICE_NAME);\r
+            MultipartServiceContext ctx = (MultipartServiceContext) createServiceContext(WorkflowClient.SERVICE_NAME, uriInfo);\r
             WorkflowDocumentModelHandler handler = createWorkflowDocumentHandler(ctx);\r
             ctx.setRespositoryWorkspaceName(parentWorkspaceName); //find the document in the parent's workspace\r
             getRepositoryClient(ctx).get(ctx, csid, handler);\r
@@ -238,20 +241,21 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr
 \r
     @PUT\r
     @Path("{csid}" + WorkflowClient.SERVICE_PATH + "/" + "{transition}")\r
-    public byte[] updateWorkflowWithTransition(@PathParam("csid") String csid,\r
+    public byte[] updateWorkflowWithTransition(\r
+               @Context UriInfo uriInfo,\r
+               @PathParam("csid") String csid,\r
                @PathParam("transition") String transition) {\r
         PoxPayloadOut result = null;\r
-        \r
-        \r
+                \r
         try {\r
                //\r
                // Create an empty workflow_commons input part and set it into a new "workflow" sub-resource context\r
                PoxPayloadIn input = new PoxPayloadIn(WorkflowClient.SERVICE_PAYLOAD_NAME, new WorkflowCommon(), \r
                                WorkflowClient.SERVICE_COMMONPART_NAME);\r
-            MultipartServiceContext ctx = (MultipartServiceContext) createServiceContext(WorkflowClient.SERVICE_NAME, input);\r
+            MultipartServiceContext ctx = (MultipartServiceContext) createServiceContext(WorkflowClient.SERVICE_NAME, input, uriInfo);\r
                \r
             // Create a service context and document handler for the parent resource.\r
-            ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx = createServiceContext();\r
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx = createServiceContext(uriInfo);\r
             DocumentHandler parentDocHandler = this.createDocumentHandler(parentCtx);      \r
             ctx.setProperty(WorkflowClient.PARENT_DOCHANDLER, parentDocHandler); //added as a context param for the workflow document handler -it will call the parent's dochandler "prepareForWorkflowTranstion" method\r
 \r
index 3d0c57675e3a8a513b6b1639cb7991895fdd851f..e0855324c031bdc82d503f300b9f0ba0aa85276a 100644 (file)
@@ -100,13 +100,13 @@ public abstract class ResourceBase
     \r
     public Response create(ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx, // REM: 8/13/2012 - Some sub-classes will override this method -e.g., MediaResource does.\r
                ResourceMap resourceMap,\r
-               UriInfo ui,\r
+               UriInfo uriInfo,\r
             String xmlPayload) {\r
        Response result = null;\r
        \r
         try {\r
             PoxPayloadIn input = new PoxPayloadIn(xmlPayload);\r
-            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(input, resourceMap, ui);\r
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(input, resourceMap, uriInfo);\r
             ctx.setResourceMap(resourceMap);\r
             if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) {\r
                ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // Reuse the current repo session if one exists\r
@@ -144,12 +144,15 @@ public abstract class ResourceBase
     //======================= UPDATE ====================================================\r
     @PUT\r
     @Path("{csid}")\r
-    public byte[] update(@Context ResourceMap resourceMap, @PathParam("csid") String csid, String xmlPayload) {\r
+    public byte[] update(@Context ResourceMap resourceMap,\r
+               @Context UriInfo uriInfo,\r
+               @PathParam("csid") String csid,\r
+               String xmlPayload) {\r
         PoxPayloadOut result = null;\r
         ensureCSID(csid, UPDATE);\r
         try {\r
             PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload);\r
-            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(theUpdate);\r
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(theUpdate, uriInfo);\r
             ctx.setResourceMap(resourceMap);\r
             result = update(csid, theUpdate, ctx); //==> CALL implementation method, which subclasses may override.\r
         } catch (Exception e) {\r
@@ -220,12 +223,12 @@ public abstract class ResourceBase
     @Path("{csid}")\r
     public byte[] get(\r
             @Context Request request,                  \r
-            @Context UriInfo ui,\r
+            @Context UriInfo uriInfo,\r
             @PathParam("csid") String csid) {\r
         PoxPayloadOut result = null;\r
         ensureCSID(csid, READ);\r
         try {\r
-            RemoteServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = (RemoteServiceContext<PoxPayloadIn, PoxPayloadOut>) createServiceContext(ui);\r
+            RemoteServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = (RemoteServiceContext<PoxPayloadIn, PoxPayloadOut>) createServiceContext(uriInfo);\r
             result = get(csid, ctx);// ==> CALL implementation method, which subclasses may override.\r
             if (result == null) {\r
                 Response response = Response.status(Response.Status.NOT_FOUND).entity(\r
@@ -300,9 +303,9 @@ public abstract class ResourceBase
         return list;\r
     }\r
     \r
-    protected AbstractCommonList getCommonList(UriInfo ui) {\r
+    protected AbstractCommonList getCommonList(UriInfo uriInfo) {\r
         try {\r
-            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(ui);\r
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(uriInfo);\r
             DocumentHandler handler = createDocumentHandler(ctx);\r
             getRepositoryClient(ctx).getFiltered(ctx, handler);\r
             AbstractCommonList list = (AbstractCommonList) handler.getCommonPartList();\r
@@ -374,7 +377,7 @@ public abstract class ResourceBase
     }\r
 \r
     private AbstractCommonList search(\r
-               UriInfo ui,\r
+               UriInfo uriInfo,\r
                String orderBy,\r
                String keywords,\r
                String advancedSearch,\r
@@ -383,9 +386,9 @@ public abstract class ResourceBase
 \r
        ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx;\r
        try {\r
-               ctx = createServiceContext(ui);\r
+               ctx = createServiceContext(uriInfo);\r
                DocumentHandler handler = createDocumentHandler(ctx);\r
-               result = search(ctx, handler, ui, orderBy, keywords, advancedSearch, partialTerm);\r
+               result = search(ctx, handler, uriInfo, orderBy, keywords, advancedSearch, partialTerm);\r
        } catch (Exception e) {\r
                throw bigReThrow(e, ServiceMessages.SEARCH_FAILED);\r
        }\r
@@ -412,10 +415,10 @@ public abstract class ResourceBase
     @Produces("application/xml")\r
     public AuthorityRefList getAuthorityRefs(\r
             @PathParam("csid") String csid,\r
-            @Context UriInfo ui) {\r
+            @Context UriInfo uriInfo) {\r
         AuthorityRefList authRefList = null;\r
         try {\r
-            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(ui);\r
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(uriInfo);\r
             DocumentModelHandler<PoxPayloadIn, PoxPayloadOut> handler = (DocumentModelHandler<PoxPayloadIn, PoxPayloadOut>) createDocumentHandler(ctx);\r
             List<AuthRefConfigInfo> authRefsInfo = RefNameServiceUtils.getConfiguredAuthorityRefs(ctx);\r
             authRefList = handler.getAuthorityRefs(csid, authRefsInfo);\r
index 614ad665c00e2a07e652d1803e4c133722a423ef..4eee5353124f946a8631a281ba00f2e0e125ed97 100644 (file)
@@ -103,7 +103,9 @@ public class RemoteServiceContextImpl<IT, OT>
         this(serviceName, theInput);
         this.setResourceMap(resourceMap);
         this.setUriInfo(uriInfo);
-        this.setQueryParams(uriInfo.getQueryParameters());
+        if (uriInfo != null) {
+               this.setQueryParams(uriInfo.getQueryParameters());
+        }
     }
 
     /* (non-Javadoc)