From 141b7e59749dcc9f1bf3252fcaf7dcdc6fec1a03 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Mon, 10 Sep 2012 11:49:20 -0700 Subject: [PATCH] CSPACE-5518: Final changes to service context setup to support existing hierarchy creation code that was moved into the common base class. --- .../collectionobject-hierarchy.xml | 2 -- .../services/account/AccountResource.java | 4 +-- .../AbstractCollectionSpaceResourceImpl.java | 27 +++++++++++++++++ ...tMultiPartCollectionSpaceResourceImpl.java | 22 ++++++++------ .../services/common/ResourceBase.java | 29 ++++++++++--------- .../context/RemoteServiceContextImpl.java | 4 ++- 6 files changed, 61 insertions(+), 27 deletions(-) diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/collectionobject/collectionobject-hierarchy.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/collectionobject/collectionobject-hierarchy.xml index 1b47e4e08..23d9212da 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/collectionobject/collectionobject-hierarchy.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/collectionobject/collectionobject-hierarchy.xml @@ -1,7 +1,5 @@ - - diff --git a/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java b/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java index 170e05612..8bca8c47f 100644 --- a/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java +++ b/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java @@ -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 ctx = createServiceContext((AccountsCommon) null, - AccountsCommon.class); + AccountsCommon.class, uriInfo); getStorageClient(ctx).delete(ctx, csid); return Response.status(HttpResponseCodes.SC_OK).build(); } catch (Exception e) { diff --git a/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java b/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java index 1388e31c8..3fbdf24e8 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java @@ -215,6 +215,17 @@ public abstract class AbstractCollectionSpaceResourceImpl return ctx; } + protected ServiceContext createServiceContext(String serviceName, + IT input, + UriInfo uriInfo) throws Exception { + ServiceContext ctx = createServiceContext(serviceName, + input, + null, // The resource map + uriInfo, /*queryParams*/ + (Class)null /*input type's Class*/); + return ctx; + } + protected ServiceContext createServiceContext(UriInfo uriInfo) throws Exception { ServiceContext ctx = createServiceContext( (IT)null, /*input*/ @@ -239,6 +250,14 @@ public abstract class AbstractCollectionSpaceResourceImpl return ctx; } + protected ServiceContext createServiceContext(IT input, UriInfo uriInfo) throws Exception { + ServiceContext ctx = createServiceContext( + input, + uriInfo, + null ); // The class param/argument + return ctx; + } + /** * Creates the service context. * @@ -257,6 +276,14 @@ public abstract class AbstractCollectionSpaceResourceImpl return ctx; } + protected ServiceContext createServiceContext(IT input, Class theClass, UriInfo uriInfo) throws Exception { + ServiceContext ctx = createServiceContext( + input, + uriInfo, + theClass); + return ctx; + } + protected ServiceContext createServiceContext( String serviceName, ResourceMap resourceMap, diff --git a/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java b/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java index d7dab54da..726b1420d 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java @@ -33,6 +33,8 @@ import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.UriInfo; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; @@ -141,13 +143,13 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr */ @GET @Path(WorkflowClient.SERVICE_PATH) - public Lifecycle getWorkflow() { + public Lifecycle getWorkflow(@Context UriInfo uriInfo) { Lifecycle result; String documentType = "undefined"; MultipartServiceContext ctx = null; try { - ctx = (MultipartServiceContext) createServiceContext(); + ctx = (MultipartServiceContext) createServiceContext(uriInfo); DocumentHandler handler = ctx.getDocumentHandler(); result = handler.getLifecycle(); } catch (Exception e) { @@ -172,14 +174,15 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr @GET @Path("{csid}" + WorkflowClient.SERVICE_PATH) public byte[] getWorkflow( + @Context UriInfo uriInfo, @PathParam("csid") String csid) { PoxPayloadOut result = null; try { - ServiceContext parentCtx = createServiceContext(); + ServiceContext parentCtx = createServiceContext(uriInfo); String parentWorkspaceName = parentCtx.getRepositoryWorkspaceName(); - MultipartServiceContext ctx = (MultipartServiceContext) createServiceContext(WorkflowClient.SERVICE_NAME); + MultipartServiceContext ctx = (MultipartServiceContext) createServiceContext(WorkflowClient.SERVICE_NAME, uriInfo); WorkflowDocumentModelHandler handler = createWorkflowDocumentHandler(ctx); ctx.setRespositoryWorkspaceName(parentWorkspaceName); //find the document in the parent's workspace getRepositoryClient(ctx).get(ctx, csid, handler); @@ -238,20 +241,21 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr @PUT @Path("{csid}" + WorkflowClient.SERVICE_PATH + "/" + "{transition}") - public byte[] updateWorkflowWithTransition(@PathParam("csid") String csid, + public byte[] updateWorkflowWithTransition( + @Context UriInfo uriInfo, + @PathParam("csid") String csid, @PathParam("transition") String transition) { PoxPayloadOut result = null; - - + try { // // Create an empty workflow_commons input part and set it into a new "workflow" sub-resource context PoxPayloadIn input = new PoxPayloadIn(WorkflowClient.SERVICE_PAYLOAD_NAME, new WorkflowCommon(), WorkflowClient.SERVICE_COMMONPART_NAME); - MultipartServiceContext ctx = (MultipartServiceContext) createServiceContext(WorkflowClient.SERVICE_NAME, input); + MultipartServiceContext ctx = (MultipartServiceContext) createServiceContext(WorkflowClient.SERVICE_NAME, input, uriInfo); // Create a service context and document handler for the parent resource. - ServiceContext parentCtx = createServiceContext(); + ServiceContext parentCtx = createServiceContext(uriInfo); DocumentHandler parentDocHandler = this.createDocumentHandler(parentCtx); 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 diff --git a/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java index 3d0c57675..e0855324c 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java +++ b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java @@ -100,13 +100,13 @@ public abstract class ResourceBase public Response create(ServiceContext parentCtx, // REM: 8/13/2012 - Some sub-classes will override this method -e.g., MediaResource does. ResourceMap resourceMap, - UriInfo ui, + UriInfo uriInfo, String xmlPayload) { Response result = null; try { PoxPayloadIn input = new PoxPayloadIn(xmlPayload); - ServiceContext ctx = createServiceContext(input, resourceMap, ui); + ServiceContext ctx = createServiceContext(input, resourceMap, uriInfo); ctx.setResourceMap(resourceMap); if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) { ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // Reuse the current repo session if one exists @@ -144,12 +144,15 @@ public abstract class ResourceBase //======================= UPDATE ==================================================== @PUT @Path("{csid}") - public byte[] update(@Context ResourceMap resourceMap, @PathParam("csid") String csid, String xmlPayload) { + public byte[] update(@Context ResourceMap resourceMap, + @Context UriInfo uriInfo, + @PathParam("csid") String csid, + String xmlPayload) { PoxPayloadOut result = null; ensureCSID(csid, UPDATE); try { PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload); - ServiceContext ctx = createServiceContext(theUpdate); + ServiceContext ctx = createServiceContext(theUpdate, uriInfo); ctx.setResourceMap(resourceMap); result = update(csid, theUpdate, ctx); //==> CALL implementation method, which subclasses may override. } catch (Exception e) { @@ -220,12 +223,12 @@ public abstract class ResourceBase @Path("{csid}") public byte[] get( @Context Request request, - @Context UriInfo ui, + @Context UriInfo uriInfo, @PathParam("csid") String csid) { PoxPayloadOut result = null; ensureCSID(csid, READ); try { - RemoteServiceContext ctx = (RemoteServiceContext) createServiceContext(ui); + RemoteServiceContext ctx = (RemoteServiceContext) createServiceContext(uriInfo); result = get(csid, ctx);// ==> CALL implementation method, which subclasses may override. if (result == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity( @@ -300,9 +303,9 @@ public abstract class ResourceBase return list; } - protected AbstractCommonList getCommonList(UriInfo ui) { + protected AbstractCommonList getCommonList(UriInfo uriInfo) { try { - ServiceContext ctx = createServiceContext(ui); + ServiceContext ctx = createServiceContext(uriInfo); DocumentHandler handler = createDocumentHandler(ctx); getRepositoryClient(ctx).getFiltered(ctx, handler); AbstractCommonList list = (AbstractCommonList) handler.getCommonPartList(); @@ -374,7 +377,7 @@ public abstract class ResourceBase } private AbstractCommonList search( - UriInfo ui, + UriInfo uriInfo, String orderBy, String keywords, String advancedSearch, @@ -383,9 +386,9 @@ public abstract class ResourceBase ServiceContext ctx; try { - ctx = createServiceContext(ui); + ctx = createServiceContext(uriInfo); DocumentHandler handler = createDocumentHandler(ctx); - result = search(ctx, handler, ui, orderBy, keywords, advancedSearch, partialTerm); + result = search(ctx, handler, uriInfo, orderBy, keywords, advancedSearch, partialTerm); } catch (Exception e) { throw bigReThrow(e, ServiceMessages.SEARCH_FAILED); } @@ -412,10 +415,10 @@ public abstract class ResourceBase @Produces("application/xml") public AuthorityRefList getAuthorityRefs( @PathParam("csid") String csid, - @Context UriInfo ui) { + @Context UriInfo uriInfo) { AuthorityRefList authRefList = null; try { - ServiceContext ctx = createServiceContext(ui); + ServiceContext ctx = createServiceContext(uriInfo); DocumentModelHandler handler = (DocumentModelHandler) createDocumentHandler(ctx); List authRefsInfo = RefNameServiceUtils.getConfiguredAuthorityRefs(ctx); authRefList = handler.getAuthorityRefs(csid, authRefsInfo); diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextImpl.java b/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextImpl.java index 614ad665c..4eee53531 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextImpl.java @@ -103,7 +103,9 @@ public class RemoteServiceContextImpl this(serviceName, theInput); this.setResourceMap(resourceMap); this.setUriInfo(uriInfo); - this.setQueryParams(uriInfo.getQueryParameters()); + if (uriInfo != null) { + this.setQueryParams(uriInfo.getQueryParameters()); + } } /* (non-Javadoc) -- 2.47.3