From: Richard Millet Date: Wed, 20 Jun 2012 01:30:45 +0000 (-0700) Subject: CSPACE-5129: Cleaned up repository session managment and transaction management when... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=db3a378a863161c64c5f027c99e66bd0d3f4d796;p=tmp%2Fjakarta-migration.git CSPACE-5129: Cleaned up repository session managment and transaction management when making resource to resource method calls. The ServiceContext is now able to keep track of RepositorySession instances and keeps reference counts on them. Only when the reference count drops to 0 is it released and the transaction closed. --- diff --git a/3rdparty/nuxeo/build.xml b/3rdparty/nuxeo/build.xml index 9c65cb2bb..e29826f69 100644 --- a/3rdparty/nuxeo/build.xml +++ b/3rdparty/nuxeo/build.xml @@ -122,7 +122,7 @@ - + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml index 4da271f92..5f166ffae 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml @@ -33,29 +33,32 @@ File below this line have been ported. --> + + + + + 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 058f67a64..fcee903af 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 @@ -59,6 +59,7 @@ import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; import org.collectionspace.services.workflow.WorkflowCommon; import org.jboss.resteasy.util.HttpResponseCodes; import org.nuxeo.ecm.core.api.DocumentModel; +import org.nuxeo.ecm.core.api.DocumentModelList; import org.nuxeo.ecm.core.api.repository.RepositoryInstance; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -71,7 +72,6 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; import javax.ws.rs.core.MultivaluedMap; @@ -80,9 +80,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; -import java.util.ArrayList; import java.util.List; -import org.collectionspace.services.client.*; import org.collectionspace.services.nuxeo.util.NuxeoUtils; /** @@ -205,7 +203,7 @@ public abstract class AuthorityResource * * @throws Exception the exception */ - protected DocumentHandler createItemDocumentHandler( + protected DocumentHandler createItemDocumentHandler( ServiceContext ctx, String inAuthority, String parentShortIdentifier) throws Exception { @@ -288,7 +286,7 @@ public abstract class AuthorityResource } else { parentShortIdentifier = parentSpec.value; String whereClause = buildWhereForAuthByName(parentSpec.value); - ServiceContext ctx = createServiceContext(getServiceName(), queryParams); + ServiceContext ctx = createServiceContext(getServiceName(), queryParams); parentcsid = getRepositoryClient(ctx).findDocCSID(null, ctx, whereClause); //FIXME: REM - If the parent has been soft-deleted, should we be looking for the item? } result.CSID = parentcsid; @@ -296,7 +294,7 @@ public abstract class AuthorityResource return result; } - public String lookupItemCSID(String itemspecifier, String parentcsid, String method, String op, ServiceContext ctx) + public String lookupItemCSID(String itemspecifier, String parentcsid, String method, String op, ServiceContext ctx) throws DocumentException { String itemcsid; Specifier itemSpec = getSpecifier(itemspecifier, method, op); @@ -322,7 +320,7 @@ public abstract class AuthorityResource } String whereClause = buildWhereForAuthByName(item.getParentShortIdentifier()); // Ensure we have the right context. - ServiceContext ctx = createServiceContext(item.inAuthority.resource); + ServiceContext ctx = createServiceContext(item.inAuthority.resource); // HACK - this really must be moved to the doc handler, not here. No Nuxeo specific stuff here! RepositoryJavaClientImpl client = (RepositoryJavaClientImpl)getRepositoryClient(ctx); @@ -341,7 +339,7 @@ public abstract class AuthorityResource try { PoxPayloadIn input = new PoxPayloadIn(xmlPayload); ServiceContext ctx = createServiceContext(input); - DocumentHandler handler = createDocumentHandler(ctx); + DocumentHandler handler = createDocumentHandler(ctx); String csid = getRepositoryClient(ctx).create(ctx, handler); UriBuilder path = UriBuilder.fromResource(resourceClass); path.path("" + csid); @@ -383,7 +381,7 @@ public abstract class AuthorityResource PoxPayloadOut result = null; try { ServiceContext ctx = createServiceContext(ui); - DocumentHandler handler = createDocumentHandler(ctx); + DocumentHandler handler = createDocumentHandler(ctx); Specifier spec = getSpecifier(specifier, "getAuthority", "GET"); if (spec.form == SpecifierForm.CSID) { @@ -426,7 +424,7 @@ public abstract class AuthorityResource try { MultivaluedMap queryParams = ui.getQueryParameters(); ServiceContext ctx = createServiceContext(queryParams); - DocumentHandler handler = createDocumentHandler(ctx); + DocumentHandler handler = createDocumentHandler(ctx); DocumentFilter myFilter = handler.getDocumentFilter(); // Need to make the default sort order for authority items // be on the displayName field @@ -441,7 +439,7 @@ public abstract class AuthorityResource myFilter.setWhereClause(authorityCommonSchemaName + ":refName='" + nameQ + "'"); } getRepositoryClient(ctx).getFiltered(ctx, handler); - return (AbstractCommonList) handler.getCommonPartList(); + return handler.getCommonPartList(); } catch (Exception e) { throw bigReThrow(e, ServiceMessages.GET_FAILED); } @@ -465,7 +463,7 @@ public abstract class AuthorityResource PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload); Specifier spec = getSpecifier(specifier, "updateAuthority", "UPDATE"); ServiceContext ctx = createServiceContext(theUpdate); - DocumentHandler handler = createDocumentHandler(ctx); + DocumentHandler handler = createDocumentHandler(ctx); String csid; if (spec.form == SpecifierForm.CSID) { csid = spec.value; @@ -497,7 +495,7 @@ public abstract class AuthorityResource try { ensureCSID(csid, ServiceMessages.DELETE_FAILED, "Authority.csid"); ServiceContext ctx = createServiceContext(); - DocumentHandler handler = createDocumentHandler(ctx); + DocumentHandler handler = createDocumentHandler(ctx); getRepositoryClient(ctx).delete(ctx, csid, handler); return Response.status(HttpResponseCodes.SC_OK).build(); } catch (Exception e) { @@ -516,13 +514,13 @@ public abstract class AuthorityResource @PathParam("csid") String specifier, String xmlPayload) { try { PoxPayloadIn input = new PoxPayloadIn(xmlPayload); - ServiceContext ctx = createServiceContext(getItemServiceName(), input); + ServiceContext ctx = createServiceContext(getItemServiceName(), input); ctx.setResourceMap(resourceMap); ctx.setUriInfo(ui); //Laramie // Note: must have the parentShortId, to do the create. CsidAndShortIdentifier parent = lookupParentCSIDAndShortIdentifer(specifier, "createAuthorityItem", "CREATE_ITEM", null); - DocumentHandler handler = createItemDocumentHandler(ctx, parent.CSID, parent.shortIdentifier); + DocumentHandler handler = createItemDocumentHandler(ctx, parent.CSID, parent.shortIdentifier); String itemcsid = getRepositoryClient(ctx).create(ctx, handler); UriBuilder path = UriBuilder.fromResource(resourceClass); path.path(parent.CSID + "/items/" + itemcsid); @@ -574,7 +572,7 @@ public abstract class AuthorityResource // Create a service context and document handler for the parent resource. ServiceContext parentCtx = createServiceContext(getItemServiceName()); - DocumentHandler parentDocHandler = this.createDocumentHandler(parentCtx); + 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 // When looking for the document, we need to use the parent's workspace name -not the "workflow" workspace name @@ -617,13 +615,13 @@ public abstract class AuthorityResource String parentcsid = lookupParentCSID(parentspecifier, "getAuthorityItem(parent)", "GET_ITEM", queryParams); RemoteServiceContext ctx = null; - ctx = (RemoteServiceContext) createServiceContext(getItemServiceName(), queryParams); + ctx = (RemoteServiceContext) createServiceContext(getItemServiceName(), queryParams); ctx.setJaxRsContext(jaxRsContext); ctx.setUriInfo(ui); //ARG! must pass this or subsequent calls will not have a ui. // We omit the parentShortId, only needed when doing a create... - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, null); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, null); Specifier itemSpec = getSpecifier(itemspecifier, "getAuthorityItem(item)", "GET_ITEM"); if (itemSpec.form == SpecifierForm.CSID) { @@ -706,7 +704,7 @@ public abstract class AuthorityResource // For the wildcard case, parentcsid is null, but docHandler will deal with this. // We omit the parentShortId, only needed when doing a create... - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, null); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, null); DocumentFilter myFilter = handler.getDocumentFilter(); // Need to make the default sort order for authority items @@ -753,7 +751,7 @@ public abstract class AuthorityResource + " and ORDER BY clause: " + myFilter.getOrderByClause()); } getRepositoryClient(ctx).getFiltered(ctx, handler); - return (AbstractCommonList) handler.getCommonPartList(); + return handler.getCommonPartList(); } catch (Exception e) { throw bigReThrow(e, ServiceMessages.LIST_FAILED); } @@ -845,8 +843,8 @@ public abstract class AuthorityResource ctx = createServiceContext(getItemServiceName(), queryParams); // We omit the parentShortId, only needed when doing a create... - DocumentModelHandler handler = - (DocumentModelHandler)createItemDocumentHandler(ctx, parentcsid, null); + DocumentModelHandler handler = + (DocumentModelHandler)createItemDocumentHandler(ctx, parentcsid, null); String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "getAuthorityItemAuthRefs(item)", "GET_ITEM_AUTH_REFS", ctx); @@ -886,7 +884,7 @@ public abstract class AuthorityResource String itemcsid = lookupItemCSID(itemspecifier, parentcsid, "updateAuthorityItem(item)", "UPDATE_ITEM", ctx); // We omit the parentShortId, only needed when doing a create... - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, null); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid, null); ctx.setUriInfo(ui); getRepositoryClient(ctx).update(ctx, itemcsid, handler); result = ctx.getOutput(); @@ -923,8 +921,8 @@ public abstract class AuthorityResource // } // try { // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName()); - DocumentHandler handler = createDocumentHandler(ctx); + ServiceContext ctx = createServiceContext(getItemServiceName()); + DocumentHandler handler = createDocumentHandler(ctx); getRepositoryClient(ctx).delete(ctx, itemcsid, handler); return Response.status(HttpResponseCodes.SC_OK).build(); } catch (Exception e) { @@ -943,7 +941,7 @@ public abstract class AuthorityResource // All items in dive can look at their child uri's to get uri. So we calculate the very first one. We could also do a GET and look at the common part uri field, but why...? String calledUri = ui.getPath(); String uri = "/" + calledUri.substring(0, (calledUri.length() - ("/" + hierarchy).length())); - ServiceContext ctx = createServiceContext(getItemServiceName()); + ServiceContext ctx = createServiceContext(getItemServiceName()); ctx.setUriInfo(ui); String direction = ui.getQueryParameters().getFirst(Hierarchy.directionQP); if (Tools.notBlank(direction) && Hierarchy.direction_parents.equals(direction)) { diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/Hierarchy.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/Hierarchy.java index 8da764722..ef862a46a 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/Hierarchy.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/Hierarchy.java @@ -24,6 +24,8 @@ package org.collectionspace.services.common.vocabulary; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.XmlTools; import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.context.ServiceContext; @@ -49,25 +51,28 @@ public class Hierarchy { * @param uri informational, optional - if not known, pass an empty String. * @return String of XML document, including xml processing instruction, root node is "<hierarchy>". */ - public static String dive(ServiceContext ctx, String itemcsid, String uri) { + public static String dive(ServiceContext ctx, String itemcsid, String uri) { String result = dive(ctx, itemcsid, uri, true); result = ""+result+""; try { result = XmlTools.prettyPrint(result); } catch (Exception e){ + // Do nothing } return result; } - private static String dive(ServiceContext ctx, String itemcsid, String uri, boolean lookupFirstName) { - MultivaluedMap queryParams = ctx.getUriInfo().getQueryParameters(); + private static String dive(ServiceContext ctx, String itemcsid, String uri, boolean lookupFirstName) { + MultivaluedMap queryParams = ctx.getUriInfo().getQueryParameters(); //Run getList() once as sent to get childListOuter: queryParams.putSingle(IRelationsManager.PREDICATE_QP, RelationshipType.HAS_BROADER.value()); queryParams.putSingle(IRelationsManager.SUBJECT_QP, null); queryParams.putSingle(IRelationsManager.SUBJECT_TYPE_QP, null); queryParams.putSingle(IRelationsManager.OBJECT_QP, itemcsid); queryParams.putSingle(IRelationsManager.OBJECT_TYPE_QP, null); - RelationsCommonList childListOuter = (new RelationResource()).getList(ctx.getUriInfo()); //magically knows all query params because they are in the context. + + RelationResource relationResource = new RelationResource(); + RelationsCommonList childListOuter = relationResource.getList(ctx); // Knows all query params because they are in the context. List childList = childListOuter.getRelationListItem(); StringBuffer sb = new StringBuffer(); @@ -80,8 +85,10 @@ public class Hierarchy { } else { sb.append("" + uri + "\r\n"); } + sb.append("" + itemcsid + "\r\n"); sb.append("\r\n"); + for (RelationsCommonList.RelationListItem item : childList) { RelationsDocListItem parent = item.getObject(); RelationsDocListItem child = item.getSubject(); @@ -98,28 +105,33 @@ public class Hierarchy { return sb.toString(); } - public static String surface(ServiceContext ctx, String itemcsid, String uri) { + public static String surface(ServiceContext ctx, String itemcsid, String uri) { String result = surface(ctx, itemcsid, uri, true).resultBuffer.toString(); result = ""+result+""; try { result = XmlTools.prettyPrint(result); } catch (Exception e){ + // Do nothing } return result; } + private static class SurfaceResultStruct { public StringBuffer resultBuffer; public boolean noParents = false; } - private static SurfaceResultStruct surface(ServiceContext ctx, String itemcsid, String uri, boolean first) { - MultivaluedMap queryParams = ctx.getUriInfo().getQueryParameters(); + + private static SurfaceResultStruct surface(ServiceContext ctx, String itemcsid, String uri, boolean first) { + MultivaluedMap queryParams = ctx.getUriInfo().getQueryParameters(); //Run getList() once as sent to get parentListOuter: queryParams.putSingle(IRelationsManager.PREDICATE_QP, RelationshipType.HAS_BROADER.value()); queryParams.putSingle(IRelationsManager.SUBJECT_QP, itemcsid); queryParams.putSingle(IRelationsManager.SUBJECT_TYPE_QP, null); queryParams.putSingle(IRelationsManager.OBJECT_QP, null); queryParams.putSingle(IRelationsManager.OBJECT_TYPE_QP, null); - RelationsCommonList parentListOuter = (new RelationResource()).getList(ctx.getUriInfo()); //magically knows all query params because they are in the context. + + RelationResource relationResource = new RelationResource(); + RelationsCommonList parentListOuter = relationResource.getList(ctx); // Knows all query params because they are in the context. List parentList = parentListOuter.getRelationListItem(); StringBuffer sbOuter = new StringBuffer(); @@ -141,6 +153,7 @@ public class Hierarchy { if (parentList.size()==0){ resultStruct.noParents = true; } + for (RelationsCommonList.RelationListItem item : parentList) { resultStruct.noParents = false; RelationsDocListItem parent = item.getObject(); @@ -188,5 +201,4 @@ public class Hierarchy { return resultStruct; } - } diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java index e2b22a664..28953ba35 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java @@ -130,7 +130,7 @@ public abstract class AuthorityDocumentModelHandler ServiceContext ctx = this.getServiceContext(); RepositoryJavaClientImpl nuxeoRepoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx); try { - repoSession = nuxeoRepoClient.getRepositorySession(); + repoSession = nuxeoRepoClient.getRepositorySession(ctx); DocumentWrapper wrapDoc = nuxeoRepoClient.getDocFromCsid(ctx, repoSession, authCSID); DocumentModel docModel = wrapDoc.getWrappedObject(); shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER); @@ -138,7 +138,7 @@ public abstract class AuthorityDocumentModelHandler throw new RuntimeException("AuthorityDocHandler Internal Error: cannot get shortId!", ce); } finally { if (repoSession != null) { - nuxeoRepoClient.releaseRepositorySession(repoSession); + nuxeoRepoClient.releaseRepositorySession(ctx, repoSession); } } 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 369db347c..56dff860e 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 @@ -30,6 +30,7 @@ import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.RelationClient; + import org.collectionspace.services.common.ResourceBase; import org.collectionspace.services.common.api.CommonAPI; import org.collectionspace.services.common.api.RefName; @@ -46,24 +47,24 @@ import org.collectionspace.services.common.repository.RepositoryClient; import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; import org.collectionspace.services.common.vocabulary.RefNameServiceUtils; + import org.collectionspace.services.config.service.ListResultField; import org.collectionspace.services.config.service.ObjectPartType; -import org.collectionspace.services.jaxb.AbstractCommonList; -import org.collectionspace.services.nuxeo.client.java.CommonList; //FIXME: REM - 5/15/2012 - CommonList should be moved out of this package and into a more "common" package + import org.collectionspace.services.nuxeo.client.java.DocHandlerBase; import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; import org.collectionspace.services.nuxeo.util.NuxeoUtils; + import org.collectionspace.services.relation.RelationResource; import org.collectionspace.services.relation.RelationsCommon; import org.collectionspace.services.relation.RelationsCommonList; import org.collectionspace.services.relation.RelationsDocListItem; import org.collectionspace.services.relation.RelationshipType; + import org.collectionspace.services.vocabulary.VocabularyItemJAXBSchema; import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; -import org.nuxeo.ecm.core.api.DocumentModelList; -import org.nuxeo.ecm.core.api.model.Property; import org.nuxeo.ecm.core.api.model.PropertyException; import org.nuxeo.ecm.core.api.repository.RepositoryInstance; @@ -71,6 +72,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; import java.util.ArrayList; @@ -441,11 +443,11 @@ public abstract class AuthorityItemDocumentModelHandler RepositoryInstance repoSession = null; boolean releaseRepoSession = false; - try { + try { RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx); repoSession = this.getRepositorySession(); if (repoSession == null) { - repoSession = repoClient.getRepositorySession(); + repoSession = repoClient.getRepositorySession(ctx); releaseRepoSession = true; } DocumentFilter myFilter = getDocumentFilter(); @@ -470,8 +472,9 @@ public abstract class AuthorityItemDocumentModelHandler } throw new DocumentException(e); } finally { + // If we got/aquired a new seesion then we're responsible for releasing it. if (releaseRepoSession && repoSession != null) { - repoClient.releaseRepositorySession(repoSession); + repoClient.releaseRepositorySession(ctx, repoSession); } } } catch (Exception e) { @@ -479,7 +482,8 @@ public abstract class AuthorityItemDocumentModelHandler logger.debug("Caught exception ", e); } throw new DocumentException(e); - } + } + return authRefDocList; } @@ -818,13 +822,13 @@ public abstract class AuthorityItemDocumentModelHandler DocumentModel docModel = wrapDoc.getWrappedObject(); String itemRefName = (String) docModel.getPropertyValue(AuthorityItemJAXBSchema.REF_NAME); - ServiceContext ctx = getServiceContext(); + ServiceContext ctx = getServiceContext(); //Do magic replacement of ${itemCSID} and fix URI's. fixupInboundListItems(ctx, inboundList, docModel, itemCSID); String HAS_BROADER = RelationshipType.HAS_BROADER.value(); UriInfo uriInfo = ctx.getUriInfo(); - MultivaluedMap queryParams = uriInfo.getQueryParameters(); + MultivaluedMap queryParams = uriInfo.getQueryParameters(); if (fUpdate) { //Run getList() once as sent to get childListOuter: @@ -834,13 +838,15 @@ public abstract class AuthorityItemDocumentModelHandler queryParams.putSingle(IRelationsManager.SUBJECT_TYPE_QP, null); queryParams.putSingle(IRelationsManager.OBJECT_QP, itemCSID); queryParams.putSingle(IRelationsManager.OBJECT_TYPE_QP, null); - RelationsCommonList childListOuter = (new RelationResource()).getList(ctx.getUriInfo()); //magically knows all query params because they are in the context. + + RelationResource relationResource = new RelationResource(); + RelationsCommonList childListOuter = relationResource.getList(ctx); // Knows all query params because they are in the context. //Now run getList() again, leaving predicate, swapping subject and object, to get parentListOuter. queryParams.putSingle(IRelationsManager.PREDICATE_QP, predicate); queryParams.putSingle(IRelationsManager.SUBJECT_QP, itemCSID); queryParams.putSingle(IRelationsManager.OBJECT_QP, null); - RelationsCommonList parentListOuter = (new RelationResource()).getList(ctx.getUriInfo()); + RelationsCommonList parentListOuter = relationResource.getList(ctx); childList = childListOuter.getRelationListItem(); @@ -855,7 +861,6 @@ public abstract class AuthorityItemDocumentModelHandler } } - for (RelationsCommonList.RelationListItem inboundItem : inboundList) { // Note that the relations may specify the other (non-item) bit with a refName, not a CSID, // and so the CSID for those may be null @@ -939,12 +944,15 @@ public abstract class AuthorityItemDocumentModelHandler return relationsCommonListBody; } - private void ensureChildHasNoOtherParents(ServiceContext ctx, MultivaluedMap queryParams, String childCSID) { + private void ensureChildHasNoOtherParents(ServiceContext ctx, + MultivaluedMap queryParams, String childCSID) { logger.trace("ensureChildHasNoOtherParents for: " + childCSID ); queryParams.putSingle(IRelationsManager.SUBJECT_QP, childCSID); queryParams.putSingle(IRelationsManager.PREDICATE_QP, RelationshipType.HAS_BROADER.value()); queryParams.putSingle(IRelationsManager.OBJECT_QP, null); //null means ANY - RelationsCommonList parentListOuter = (new RelationResource()).getList(ctx.getUriInfo()); + + RelationResource relationResource = new RelationResource(); + RelationsCommonList parentListOuter = relationResource.getList(ctx); List parentList = parentListOuter.getRelationListItem(); //logger.warn("ensureChildHasNoOtherParents preparing to delete relations on "+childCSID+"\'s parent list: \r\n"+dumpList(parentList, "duplicate parent list")); deleteRelations(parentList, ctx, "parentList-delete"); @@ -981,7 +989,6 @@ public abstract class AuthorityItemDocumentModelHandler return sb.toString(); } private final static String CR = "\r\n"; - private final static String T = " "; private String dumpList(List list, String label) { StringBuilder sb = new StringBuilder(); @@ -1045,7 +1052,8 @@ public abstract class AuthorityItemDocumentModelHandler } // this method calls the RelationResource to have it create the relations and persist them. - private void createRelations(List inboundList, ServiceContext ctx) throws Exception { + private void createRelations(List inboundList, + ServiceContext ctx) throws Exception { for (RelationsCommonList.RelationListItem item : inboundList) { RelationsCommon rc = new RelationsCommon(); //rc.setCsid(item.getCsid()); @@ -1083,12 +1091,14 @@ public abstract class AuthorityItemDocumentModelHandler PayloadOutputPart outputPart = new PayloadOutputPart(RelationClient.SERVICE_COMMONPART_NAME, rc); payloadOut.addPart(outputPart); RelationResource relationResource = new RelationResource(); - Object res = relationResource.create(ctx.getResourceMap(), + Response res = relationResource.create(ctx, ctx.getResourceMap(), ctx.getUriInfo(), payloadOut.toXML()); //NOTE ui recycled from above to pass in unknown query params. } } - private void deleteRelations(List list, ServiceContext ctx, String listName) { + private void deleteRelations(List list, + ServiceContext ctx, + String listName) { try { for (RelationsCommonList.RelationListItem item : list) { RelationResource relationResource = new RelationResource(); @@ -1097,7 +1107,10 @@ public abstract class AuthorityItemDocumentModelHandler itemToString(sb, "==== TO DELETE: ", item); logger.trace(sb.toString()); } - Object res = relationResource.delete(item.getCsid()); + Response res = relationResource.deleteWithParentCtx(ctx, item.getCsid()); + if (logger.isDebugEnabled()) { + logger.debug("Status of authority item deleteRelations method call was: " + res.getStatus()); + } } } catch (Throwable t) { String msg = "Unable to deleteRelations: " + Tools.errorToString(t, true); @@ -1206,14 +1219,14 @@ public abstract class AuthorityItemDocumentModelHandler //================= TODO: move this to common, refactoring this and CollectionObjectResource.java public RelationsCommonList getRelations(String subjectCSID, String objectCSID, String predicate) throws Exception { - ServiceContext ctx = getServiceContext(); - MultivaluedMap queryParams = ctx.getQueryParams(); + ServiceContext ctx = getServiceContext(); + MultivaluedMap queryParams = ctx.getQueryParams(); queryParams.putSingle(IRelationsManager.PREDICATE_QP, predicate); queryParams.putSingle(IRelationsManager.SUBJECT_QP, subjectCSID); queryParams.putSingle(IRelationsManager.OBJECT_QP, objectCSID); RelationResource relationResource = new RelationResource(); //is this still acting like a singleton as it should be? - RelationsCommonList relationsCommonList = relationResource.getList(ctx.getUriInfo()); + RelationsCommonList relationsCommonList = relationResource.getList(ctx); return relationsCommonList; } //============================= END TODO refactor ========================== diff --git a/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/BatchDocumentModelHandler.java b/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/BatchDocumentModelHandler.java index 4777d291f..4b2f2608d 100644 --- a/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/BatchDocumentModelHandler.java +++ b/services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/BatchDocumentModelHandler.java @@ -91,7 +91,7 @@ public class BatchDocumentModelHandler RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx); repoSession = this.getRepositorySession(); if (repoSession == null) { - repoSession = repoClient.getRepositorySession(); + repoSession = repoClient.getRepositorySession(ctx); releaseRepoSession = true; } @@ -133,7 +133,7 @@ public class BatchDocumentModelHandler throw new DocumentException(e); } finally { if (releaseRepoSession && repoSession != null) { - repoClient.releaseRepositorySession(repoSession); + repoClient.releaseRepositorySession(ctx, repoSession); } } className = className.trim(); 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 9334399d1..95f067c37 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 @@ -29,20 +29,15 @@ package org.collectionspace.services.common; import java.util.Iterator; import java.util.List; -import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Response; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.workflow.WorkflowClient; -import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.context.MultipartServiceContext; import org.collectionspace.services.common.context.MultipartServiceContextFactory; import org.collectionspace.services.common.context.ServiceContext; @@ -51,10 +46,8 @@ import org.collectionspace.services.common.document.DocumentHandler; import org.collectionspace.services.common.workflow.service.nuxeo.WorkflowDocumentModelHandler; import org.collectionspace.services.lifecycle.Lifecycle; import org.collectionspace.services.lifecycle.TransitionDef; -import org.collectionspace.services.lifecycle.TransitionDefList; import org.collectionspace.services.workflow.WorkflowCommon; import org.dom4j.DocumentException; -import org.jboss.resteasy.client.ClientResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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 38f34669a..7d8a55683 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 @@ -42,6 +42,7 @@ import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler; import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.util.HttpResponseCodes; import org.nuxeo.ecm.core.api.DocumentModel; +import org.nuxeo.ecm.core.api.DocumentModelList; import org.nuxeo.ecm.core.api.repository.RepositoryInstance; import javax.ws.rs.*; @@ -52,7 +53,7 @@ import java.util.List; /** * $LastChangedRevision: $ * $LastChangedDate: $ - * Author: laramie + * Author: Laramie Crocker */ public abstract class ResourceBase extends AbstractMultiPartCollectionSpaceResourceImpl { @@ -84,22 +85,36 @@ public abstract class ResourceBase //======================= CREATE ==================================================== @POST - public Response create(@Context ResourceMap resourceMap, @Context UriInfo ui, + public Response create(@Context ResourceMap resourceMap, + @Context UriInfo ui, String xmlPayload) { + return this.create(null, resourceMap, ui, xmlPayload); + } + + public Response create(ServiceContext parentCtx, + @Context ResourceMap resourceMap, + @Context UriInfo ui, + String xmlPayload) { + Response result = null; + try { PoxPayloadIn input = new PoxPayloadIn(xmlPayload); - //System.out.println("\r\n\r\n==============================\r\nxmlPayload:\r\n"+xmlPayload); ServiceContext ctx = createServiceContext(input); ctx.setResourceMap(resourceMap); - return create(input, ctx); + if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) { + ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // Reuse the current repo session if one exists + } + result = create(input, ctx); } catch (Exception e) { throw bigReThrow(e, ServiceMessages.CREATE_FAILED); } - } - + + return result; + } + protected Response create(PoxPayloadIn input, ServiceContext ctx) { try { - DocumentHandler handler = createDocumentHandler(ctx); + DocumentHandler handler = createDocumentHandler(ctx); UriBuilder path = UriBuilder.fromResource(this.getClass()); return create(input, ctx, handler, path); //==> CALL implementation method, which subclasses may override. } catch (Exception e) { @@ -110,7 +125,7 @@ public abstract class ResourceBase /** Subclasses may override this overload, which gets called from @see #create(MultipartInput) */ protected Response create(PoxPayloadIn input, ServiceContext ctx, - DocumentHandler handler, + DocumentHandler handler, UriBuilder path) throws Exception { String csid = getRepositoryClient(ctx).create(ctx, handler); @@ -163,7 +178,7 @@ public abstract class ResourceBase ensureCSID(csid, DELETE); try { ServiceContext ctx = createServiceContext(); - return delete(csid, ctx); //==> CALL implementation method, which subclasses may override. + return delete(ctx, csid); //==> CALL implementation method, which subclasses may override. } catch (Exception e) { throw bigReThrow(e, ServiceMessages.DELETE_FAILED, csid); } @@ -171,12 +186,27 @@ public abstract class ResourceBase /** subclasses may override this method, which is called from #delete(String) * which handles setup of ServiceContext, and does Exception handling. */ - protected Response delete(String csid, ServiceContext ctx) + protected Response delete(ServiceContext ctx, String csid) throws Exception { - DocumentHandler handler = createDocumentHandler(ctx); + DocumentHandler handler = createDocumentHandler(ctx); getRepositoryClient(ctx).delete(ctx, csid, handler); return Response.status(HttpResponseCodes.SC_OK).build(); } + + public Response deleteWithParentCtx(ServiceContext parentCtx, + String csid) + throws Exception { + ensureCSID(csid, DELETE); + try { + ServiceContext ctx = createServiceContext(); + if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) { + ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // reuse the repo session if one exists + } + return delete(ctx, csid); //==> CALL implementation method, which subclasses may override. + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.DELETE_FAILED, csid); + } + } //======================= GET ==================================================== @GET @@ -244,7 +274,7 @@ public abstract class ResourceBase } return list; } - + protected AbstractCommonList getList(MultivaluedMap queryParams) { try { ServiceContext ctx = createServiceContext(queryParams); diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java index d3fa9f3a7..1b03aa473 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java @@ -93,8 +93,12 @@ public abstract class AbstractServiceContextImpl private DocumentHandler docHandler = null; /** security context */ private SecurityContext securityContext; - + /** The sessions JAX-RS URI information */ private UriInfo uriInfo; + /** The current repository session */ + private Object currentRepositorySession; + /** A reference count for the current repository session */ + private int currentRepoSesssionRefCount = 0; /** * Instantiates a new abstract service context impl. @@ -626,8 +630,47 @@ public abstract class AbstractServiceContextImpl this.uriInfo = ui; } - @Override - public UriInfo getUriInfo(){ - return this.uriInfo; - } + @Override + public UriInfo getUriInfo() { + return this.uriInfo; + } + + /* + * We expect the 'currentRepositorySession' member to be set only once per instance. Also, we expect only one open repository session + * per HTTP request. We'll log an error if we see more than one attempt to set a service context's current repo session. + * (non-Javadoc) + * @see org.collectionspace.services.common.context.ServiceContext#setCurrentRepositorySession(java.lang.Object) + */ + @Override + public void setCurrentRepositorySession(Object repoSession) throws Exception { + if (repoSession == null) { + String errMsg = "Setting a service context's repository session to null is not allowed."; + logger.error(errMsg); + throw new Exception(errMsg); + } else if (currentRepositorySession != null && currentRepositorySession != repoSession) { + String errMsg = "The current service context's repository session was replaced. This may cause unexpected behavior and/or data loss."; + logger.error(errMsg); + throw new Exception(errMsg); + } + + currentRepositorySession = repoSession; + this.currentRepoSesssionRefCount++; + } + + @Override + public void clearCurrentRepositorySession() { + if (this.currentRepoSesssionRefCount > 0) { + currentRepoSesssionRefCount--; + } + + if (currentRepoSesssionRefCount == 0) { + this.currentRepositorySession = null; + } + } + + @Override + public Object getCurrentRepositorySession() { + // TODO Auto-generated method stub + return currentRepositorySession; + } } 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 1c5f5c422..23eee0bfc 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 @@ -163,7 +163,7 @@ public class RemoteServiceContextImpl @Override public ServiceContext getLocalContext(String localContextClassName) throws Exception { ClassLoader cloader = Thread.currentThread().getContextClassLoader(); - Class ctxClass = cloader.loadClass(localContextClassName); + Class ctxClass = cloader.loadClass(localContextClassName); if (!ServiceContext.class.isAssignableFrom(ctxClass)) { throw new IllegalArgumentException("getLocalContext requires " + " implementation of " + ServiceContext.class.getName()); @@ -172,5 +172,5 @@ public class RemoteServiceContextImpl Constructor ctor = ctxClass.getConstructor(java.lang.String.class); ServiceContext ctx = (ServiceContext) ctor.newInstance(getServiceName()); return ctx; - } + } } diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java index fee621f1b..dea896e93 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java @@ -60,6 +60,21 @@ public interface ServiceContext { /** Used to qualify document types **/ public static final String TENANT_SUFFIX = "Tenant"; + /* + * Sets the current/open repository session + */ + public void setCurrentRepositorySession(Object repoSession) throws Exception; + + /* + * Decrements the context's repo session ref count and nulls it if the count becomes 0. + */ + public void clearCurrentRepositorySession(); + + /* + * If a current repository session exists, returns it. + */ + public Object getCurrentRepositorySession(); + /** * getSecurityContext is contains security info. for the service layer */ diff --git a/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java b/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java index 7c9445070..1f5c3a4b4 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java @@ -727,7 +727,7 @@ public class NuxeoImageUtils { .getDigestAlgorithm(); // Need some way on initializing the // FileManager with a call. - logger.debug("Start --> Calling Nuxeo to create an image blob."); + logger.debug("Start --> Calling Nuxeo to create an image blob."); // See Nuxeo's DefaultPictureAdapter class for details DocumentModel documentModel = getFileManagerService() .createDocumentFromBlob(nuxeoSession, fileBlob, blobLocation.getPathAsString(), true, diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index 68b3a6e0d..623a86dc6 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -484,7 +484,7 @@ public abstract class RemoteDocumentModelHandlerImpl RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx); RepositoryInstance repoSession = this.getRepositorySession(); if (repoSession == null) { - repoSession = repoClient.getRepositorySession(); + repoSession = repoClient.getRepositorySession(ctx); releaseRepoSession = true; } @@ -504,7 +504,7 @@ public abstract class RemoteDocumentModelHandlerImpl } } finally { if (releaseRepoSession == true) { - repoClient.releaseRepositorySession(repoSession); + repoClient.releaseRepositorySession(ctx, repoSession); } } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java index 7bf986185..9992e6f98 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java @@ -154,7 +154,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient wrapDoc = null; try { - repoSession = getRepositorySession(); + repoSession = getRepositorySession(ctx); wrapDoc = findDoc(repoSession, ctx, whereClause); } catch (Exception e) { throw new DocumentException("Unable to create a Nuxeo repository session.", e); } finally { if (repoSession != null) { - releaseRepositorySession(repoSession); + releaseRepositorySession(ctx, repoSession); } } @@ -443,8 +443,8 @@ public class RepositoryJavaClientImpl implements RepositoryClient wrapDoc = findDoc(repoSession, ctx, whereClause); @@ -463,7 +463,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient wrapDoc = null; try { - repoSession = getRepositorySession(); + repoSession = getRepositorySession(ctx); wrapDoc = findDocs(ctx, repoSession, docTypes, whereClause, pageSize, pageNum, computeTotal); } catch (IllegalArgumentException iae) { @@ -532,7 +532,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient result = null; RepositoryInstance repoSession = null; try { - repoSession = getRepositorySession(); + repoSession = getRepositorySession(ctx); result = getDocFromCsid(ctx, repoSession, csid); } finally { if (repoSession != null) { - releaseRepositorySession(repoSession); + releaseRepositorySession(ctx, repoSession); } } @@ -751,7 +751,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient wrapDoc = null; try { DocumentRef docRef = NuxeoUtils.createPathRef(ctx, id); @@ -1035,7 +1035,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient getCommonPartClass() { return RelationsCommon.class; } - + @Override @GET @Produces("application/xml") - public RelationsCommonList getList(@Context UriInfo ui) { - MultivaluedMap queryParams = ui.getQueryParameters(); + public RelationsCommonList getList(@Context UriInfo uriInfo) { + return this.getList(null, uriInfo); + } + + public RelationsCommonList getList(ServiceContext parentCtx) { + return this.getList(parentCtx, parentCtx.getUriInfo()); + } + + private RelationsCommonList getList(ServiceContext parentCtx, UriInfo uriInfo) { + if (parentCtx != null) { + uriInfo = parentCtx.getUriInfo(); //Override the input param and use the parent context's UriInfo + } + MultivaluedMap queryParams = uriInfo.getQueryParameters(); String subjectCsid = queryParams.getFirst(IRelationsManager.SUBJECT_QP); String subjectType = queryParams.getFirst(IRelationsManager.SUBJECT_TYPE_QP); @@ -80,13 +92,21 @@ public class RelationResource extends ResourceBase { String objectCsid = queryParams.getFirst(IRelationsManager.OBJECT_QP); String objectType = queryParams.getFirst(IRelationsManager.OBJECT_TYPE_QP); - return this.getRelationList(queryParams, subjectCsid, subjectType, predicate, objectCsid, objectType); + return this.getRelationList(parentCtx, queryParams, subjectCsid, subjectType, predicate, objectCsid, objectType); } - private RelationsCommonList getRelationList(MultivaluedMap queryParams, String subjectCsid, String subjectType, - String predicate, String objectCsid, String objectType) throws WebApplicationException { + private RelationsCommonList getRelationList( + ServiceContext parentCtx, + MultivaluedMap queryParams, + String subjectCsid, String subjectType, + String predicate, + String objectCsid, + String objectType) throws WebApplicationException { try { ServiceContext ctx = createServiceContext(queryParams); + if (parentCtx != null) { // If the parent context has an open repository session then use it + ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); + } DocumentHandler handler = createDocumentHandler(ctx); String relationClause = RelationsUtils.buildWhereClause(subjectCsid, subjectType, predicate, objectCsid, objectType); diff --git a/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java b/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java index 6e6dbf030..b381395b2 100644 --- a/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java +++ b/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java @@ -129,7 +129,7 @@ public class ReportDocumentModelHandler extends DocHandlerBase { RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx); repoSession = this.getRepositorySession(); if (repoSession == null) { - repoSession = repoClient.getRepositorySession(); + repoSession = repoClient.getRepositorySession(ctx); releaseRepoSession = true; } @@ -172,7 +172,7 @@ public class ReportDocumentModelHandler extends DocHandlerBase { throw new DocumentException(e); } finally { if (releaseRepoSession && repoSession != null) { - repoClient.releaseRepositorySession(repoSession); + repoClient.releaseRepositorySession(ctx, repoSession); } } return buildReportResponse(csid, params, reportFileName); diff --git a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java index 444e439e5..28e9fc6c7 100644 --- a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java +++ b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java @@ -87,7 +87,7 @@ public class ServiceGroupDocumentModelHandler RepositoryJavaClientImpl repoClient = (RepositoryJavaClientImpl)this.getRepositoryClient(ctx); repoSession = this.getRepositorySession(); if (repoSession == null) { - repoSession = repoClient.getRepositorySession(); + repoSession = repoClient.getRepositorySession(ctx); releaseRepoSession = true; } DocumentFilter myFilter = getDocumentFilter(); @@ -163,7 +163,7 @@ public class ServiceGroupDocumentModelHandler throw new DocumentException(e); } finally { if (releaseRepoSession && repoSession != null) { - repoClient.releaseRepositorySession(repoSession); + repoClient.releaseRepositorySession(ctx, repoSession); } } } catch (Exception e) {