From 21198cd0a803579989d1b13957edcef84cf95168 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Tue, 29 Oct 2019 09:16:31 -0700 Subject: [PATCH] UCBG-444: Reusing Nuxeo repo connections from existing service contexts. --- .../services/batch/BatchResource.java | 8 +++++--- .../services/common/NuxeoBasedResource.java | 20 ++++++++++++++++--- .../common/relation/RelationResource.java | 2 +- .../services/index/IndexResource.java | 9 ++++++++- .../services/report/ReportResource.java | 6 ++++-- .../services/workflow/WorkflowResource.java | 10 ++++++++-- 6 files changed, 43 insertions(+), 12 deletions(-) diff --git a/services/batch/service/src/main/java/org/collectionspace/services/batch/BatchResource.java b/services/batch/service/src/main/java/org/collectionspace/services/batch/BatchResource.java index ce62f98e9..a88e1b1f6 100644 --- a/services/batch/service/src/main/java/org/collectionspace/services/batch/BatchResource.java +++ b/services/batch/service/src/main/java/org/collectionspace/services/batch/BatchResource.java @@ -81,16 +81,18 @@ public class BatchResource extends NuxeoBasedResource { } @Override - //public Class getCommonPartClass() { - public Class getCommonPartClass() { + public Class getCommonPartClass() { return BatchCommon.class; } // other resource methods and use the getRepositoryClient() methods. @Override - protected AbstractCommonList getCommonList(UriInfo ui) { + protected AbstractCommonList getCommonList(ServiceContext parentCtx, UriInfo ui) { try { ServiceContext ctx = createServiceContext(ui); + if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) { + ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // Reuse the current repo session if one exists + } MultivaluedMap queryParams = ctx.getQueryParams(); DocumentHandler handler = createDocumentHandler(ctx); String docType = queryParams.getFirst(IQueryManager.SEARCH_TYPE_DOCTYPE); diff --git a/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java b/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java index ec3edd465..7fe0f5dde 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java +++ b/services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java @@ -445,6 +445,10 @@ public abstract class NuxeoBasedResource @GET public AbstractCommonList getList(@Context UriInfo uriInfo) { uriInfo = new UriInfoWrapper(uriInfo); + return this.getList(null, uriInfo); + } + + public AbstractCommonList getList(ServiceContext parentCtx, UriInfo uriInfo) { AbstractCommonList list = null; MultivaluedMap queryParams = uriInfo.getQueryParameters(); @@ -453,18 +457,24 @@ public abstract class NuxeoBasedResource String keywords = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_KW); String advancedSearch = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_AS); String partialTerm = queryParams.getFirst(IQueryManager.SEARCH_TYPE_PARTIALTERM); - list = search(uriInfo, orderBy, keywords, advancedSearch, partialTerm); + list = search(parentCtx, uriInfo, orderBy, keywords, advancedSearch, partialTerm); } else { - list = getCommonList(uriInfo); + list = getCommonList(parentCtx, uriInfo); } return list; } protected AbstractCommonList getCommonList(UriInfo uriInfo) { + return getCommonList(null, uriInfo); + } + + protected AbstractCommonList getCommonList(ServiceContext parentCtx, UriInfo uriInfo) { try { ServiceContext ctx = createServiceContext(uriInfo); - DocumentHandler handler = createDocumentHandler(ctx); + if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) { + ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // Reuse the current repo session if one exists + } DocumentHandler handler = createDocumentHandler(ctx); getRepositoryClient(ctx).getFiltered(ctx, handler); AbstractCommonList list = (AbstractCommonList) handler.getCommonPartList(); return list; @@ -536,6 +546,7 @@ public abstract class NuxeoBasedResource } private AbstractCommonList search( + ServiceContext parentCtx, UriInfo uriInfo, String orderBy, String keywords, @@ -546,6 +557,9 @@ public abstract class NuxeoBasedResource ServiceContext ctx; try { 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); result = search(ctx, handler, uriInfo, orderBy, keywords, advancedSearch, partialTerm); } catch (Exception e) { diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationResource.java b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationResource.java index 6b0947494..46bf5587b 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationResource.java +++ b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationResource.java @@ -92,7 +92,7 @@ public class RelationResource extends NuxeoBasedResource { return this.getList(parentCtx, parentCtx.getUriInfo()); } - private RelationsCommonList getList(ServiceContext parentCtx, UriInfo uriInfo) { + public RelationsCommonList getList(ServiceContext parentCtx, UriInfo uriInfo) { MultivaluedMap queryParams = uriInfo.getQueryParameters(); String subjectCsid = queryParams.getFirst(IRelationsManager.SUBJECT_QP); diff --git a/services/index/service/src/main/java/org/collectionspace/services/index/IndexResource.java b/services/index/service/src/main/java/org/collectionspace/services/index/IndexResource.java index b237b9204..4693e9363 100644 --- a/services/index/service/src/main/java/org/collectionspace/services/index/IndexResource.java +++ b/services/index/service/src/main/java/org/collectionspace/services/index/IndexResource.java @@ -26,10 +26,13 @@ package org.collectionspace.services.index; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.index.IndexClient; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.CSWebApplicationException; import org.collectionspace.services.common.NuxeoBasedResource; import org.collectionspace.services.common.ResourceMap; import org.collectionspace.services.common.ServiceMessages; +import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.UriInfoWrapper; import org.collectionspace.services.common.context.RemoteServiceContext; import org.collectionspace.services.common.document.DocumentHandler; @@ -137,5 +140,9 @@ public class IndexResource extends NuxeoBasedResource { .build(); throw new CSWebApplicationException(response); } - + + @Override + public AbstractCommonList getList(ServiceContext parentCtx, UriInfo uriInfo) { + throw new UnsupportedOperationException(); + } } diff --git a/services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java b/services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java index b0ada69b0..686a3ed9c 100644 --- a/services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java +++ b/services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java @@ -65,7 +65,6 @@ import javax.ws.rs.core.Response.Status; @Path(ReportClient.SERVICE_PATH) @Consumes("application/xml") @Produces("application/xml") -//@Produces("application/xml;charset=UTF-8") public class ReportResource extends NuxeoBasedResource { final Logger logger = LoggerFactory.getLogger(ReportResource.class); @@ -86,9 +85,12 @@ public class ReportResource extends NuxeoBasedResource { } @Override - protected AbstractCommonList getCommonList(UriInfo ui) { + protected AbstractCommonList getCommonList(ServiceContext parentCtx, UriInfo ui) { try { ServiceContext ctx = createServiceContext(ui); + if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) { + ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // Reuse the current repo session if one exists + } MultivaluedMap queryParams = ctx.getQueryParams(); DocumentHandler handler = createDocumentHandler(ctx); String docType = queryParams.getFirst(IQueryManager.SEARCH_TYPE_DOCTYPE); diff --git a/services/workflow/service/src/main/java/org/collectionspace/services/workflow/WorkflowResource.java b/services/workflow/service/src/main/java/org/collectionspace/services/workflow/WorkflowResource.java index 2830de301..a063ce47e 100644 --- a/services/workflow/service/src/main/java/org/collectionspace/services/workflow/WorkflowResource.java +++ b/services/workflow/service/src/main/java/org/collectionspace/services/workflow/WorkflowResource.java @@ -23,11 +23,14 @@ */ package org.collectionspace.services.workflow; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.workflow.WorkflowClient; import org.collectionspace.services.common.CSWebApplicationException; import org.collectionspace.services.common.NuxeoBasedResource; import org.collectionspace.services.common.ResourceMap; import org.collectionspace.services.common.ServiceMessages; +import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.jaxb.AbstractCommonList; import javax.ws.rs.Consumes; @@ -37,7 +40,6 @@ import javax.ws.rs.POST; 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.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; @@ -104,5 +106,9 @@ public class WorkflowResource extends NuxeoBasedResource { .build(); throw new CSWebApplicationException(response); } - + + @Override + public AbstractCommonList getList(ServiceContext parentCtx, UriInfo uriInfo) { + throw new UnsupportedOperationException(); + } } -- 2.47.3