From: Richard Millet Date: Mon, 28 Oct 2019 23:58:31 +0000 (-0700) Subject: Added changes from original UCBG-444 task to AuthorityResource.java X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=6447e6c37ba632d4729fbf861301b7e23ea20659;p=tmp%2Fjakarta-migration.git Added changes from original UCBG-444 task to AuthorityResource.java --- 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 2d3252fbb..b29414e99 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 @@ -526,13 +526,20 @@ 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); + return this.getAuthorityList(null, uriInfo); + } + + public AbstractCommonList getAuthorityList(ServiceContext parentCtx, @Context UriInfo uriInfo) { uriInfo = new UriInfoWrapper(uriInfo); AbstractCommonList result = null; try { MultivaluedMap queryParams = uriInfo.getQueryParameters(); ServiceContext ctx = createServiceContext(uriInfo); - + if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) { + ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // Reuse the current repo session if one exists + } DocumentHandler handler = createDocumentHandler(ctx); DocumentFilter myFilter = handler.getDocumentFilter(); // Need to make the default sort order for authority items @@ -768,6 +775,21 @@ public abstract class AuthorityResource Boolean isProposed, Boolean isSASItem ) throws Exception { + return updateAuthorityItem(null, itemServiceCtx, resourceMap, uriInfo, parentspecifier, itemspecifier, theUpdate, shouldUpdateRevNumber, isProposed, isSASItem); + } + + public PoxPayloadOut updateAuthorityItem( + ServiceContext parentCtx, + ServiceContext itemServiceCtx, // Ok to be null. Will be null on PUT calls, but not on sync calls + ResourceMap resourceMap, + UriInfo uriInfo, + String parentspecifier, + String itemspecifier, + PoxPayloadIn theUpdate, + boolean shouldUpdateRevNumber, + Boolean isProposed, + Boolean isSASItem + ) throws Exception { PoxPayloadOut result = null; CsidAndShortIdentifier csidAndShortId = lookupParentCSIDAndShortIdentifer(itemServiceCtx, parentspecifier, "updateAuthorityItem(parent)", "UPDATE_ITEM", null); @@ -779,6 +801,9 @@ public abstract class AuthorityResource ServiceContext ctx = itemServiceCtx; if (ctx == null) { ctx = createServiceContext(getItemServiceName(), theUpdate, resourceMap, uriInfo); + if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) { + ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // Reuse the current repo session if one exists + } } else { ctx.setInput(theUpdate); // the update payload } @@ -908,8 +933,6 @@ public abstract class AuthorityResource return result.getBytes(); } - //FIXME: This method is almost identical to the method org.collectionspace.services.common.updateWorkflowWithTransition() so - // they should be consolidated -be DRY (D)on't (R)epeat (Y)ourself. @PUT @Path("{csid}/items/{itemcsid}" + WorkflowClient.SERVICE_PATH + "/{transition}") public byte[] updateItemWorkflowWithTransition( @@ -918,10 +941,23 @@ public abstract class AuthorityResource @PathParam("itemcsid") String itemIdentifier, @PathParam("transition") String transition) { uriInfo = new UriInfoWrapper(uriInfo); + return updateItemWorkflowWithTransition(null, uriInfo, parentIdentifier, itemIdentifier, transition); + } + + public byte[] updateItemWorkflowWithTransition( + ServiceContext existingContext, + UriInfo uriInfo, + String parentIdentifier, + String itemIdentifier, + String transition) { + uriInfo = new UriInfoWrapper(uriInfo); PoxPayloadOut result = null; try { ServiceContext ctx = createServiceContext(getItemServiceName(), uriInfo); + if (existingContext != null && existingContext.getCurrentRepositorySession() != null) { + ctx.setCurrentRepositorySession(existingContext.getCurrentRepositorySession());// If a repo session is already open, we need to use it and not create a new one + } result = updateItemWorkflowWithTransition(ctx, parentIdentifier, itemIdentifier, transition, AuthorityServiceUtils.UPDATE_REV); } catch (Exception e) { @@ -1044,9 +1080,18 @@ public abstract class AuthorityResource ServiceContext existingCtx, String parentIdentifier, String itemIdentifier) throws Exception { + return getAuthorityItemWithExistingContext(existingCtx, existingCtx.getUriInfo(), existingCtx.getResourceMap(), parentIdentifier, itemIdentifier); + } + + public PoxPayloadOut getAuthorityItemWithExistingContext( + ServiceContext existingCtx, + UriInfo uriInfo, + ResourceMap resourceMap, + String parentIdentifier, + String itemIdentifier) throws Exception { PoxPayloadOut result = null; - ServiceContext ctx = createServiceContext(getItemServiceName(), existingCtx.getResourceMap(), existingCtx.getUriInfo()); + ServiceContext ctx = createServiceContext(getItemServiceName(), resourceMap, uriInfo); if (existingCtx.getCurrentRepositorySession() != null) { ctx.setCurrentRepositorySession(existingCtx.getCurrentRepositorySession()); // Reuse the current repo session if one exists ctx.setProperties(existingCtx.getProperties()); @@ -1489,12 +1534,22 @@ public abstract class AuthorityResource @PathParam("csid") String parentSpecifier, @PathParam("itemcsid") String itemSpecifier, String xmlPayload) { + return updateAuthorityItem(null, resourceMap, uriInfo, parentSpecifier, itemSpecifier, xmlPayload); + } + + public byte[] updateAuthorityItem( + ServiceContext parentCtx, + ResourceMap resourceMap, + UriInfo uriInfo, + String parentSpecifier, + String itemSpecifier, + String xmlPayload) { uriInfo = new UriInfoWrapper(uriInfo); PoxPayloadOut result = null; try { PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload); - result = updateAuthorityItem(null, resourceMap, uriInfo, parentSpecifier, itemSpecifier, theUpdate, + result = updateAuthorityItem(parentCtx, null, resourceMap, uriInfo, parentSpecifier, itemSpecifier, theUpdate, AuthorityServiceUtils.UPDATE_REV, // passing TRUE so rev num increases, passing AuthorityServiceUtils.NO_CHANGE, // don't change the state of the "proposed" field -we could be performing a sync or just a plain update AuthorityServiceUtils.NO_CHANGE); // don't change the state of the "sas" field -we could be performing a sync or just a plain update @@ -1505,8 +1560,6 @@ public abstract class AuthorityResource return result.getBytes(); } - - /** * Delete authorityItem. *