]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
UCBG-444: Reusing Nuxeo repo connections from existing service contexts.
authorRichard Millet <remillet@gmail.com>
Tue, 29 Oct 2019 16:16:31 +0000 (09:16 -0700)
committerRichard Millet <remillet@gmail.com>
Tue, 29 Oct 2019 16:16:31 +0000 (09:16 -0700)
services/batch/service/src/main/java/org/collectionspace/services/batch/BatchResource.java
services/common/src/main/java/org/collectionspace/services/common/NuxeoBasedResource.java
services/common/src/main/java/org/collectionspace/services/common/relation/RelationResource.java
services/index/service/src/main/java/org/collectionspace/services/index/IndexResource.java
services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java
services/workflow/service/src/main/java/org/collectionspace/services/workflow/WorkflowResource.java

index ce62f98e9f31c3527ea4bc82fb583dc0564924ab..a88e1b1f6d0a7c71d2ecd31f5a7b0a07aa49080c 100644 (file)
@@ -81,16 +81,18 @@ public class BatchResource extends NuxeoBasedResource {
     }
 
     @Override
-    //public Class<BatchCommon> 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<PoxPayloadIn, PoxPayloadOut> parentCtx, UriInfo ui) {
         try {
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(ui);
+            if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) {
+                ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // Reuse the current repo session if one exists
+            }
             MultivaluedMap<String, String> queryParams = ctx.getQueryParams();
             DocumentHandler handler = createDocumentHandler(ctx);
             String docType = queryParams.getFirst(IQueryManager.SEARCH_TYPE_DOCTYPE);
index ec3edd4659ccec865677323e1820cad20a7859db..7fe0f5ddef4a2c74b6188c64589f0be6bf1144d5 100644 (file)
@@ -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<PoxPayloadIn, PoxPayloadOut> parentCtx, UriInfo uriInfo) {
         AbstractCommonList list = null;
         
         MultivaluedMap<String, String> 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<PoxPayloadIn, PoxPayloadOut> parentCtx, UriInfo uriInfo) {
         try {
             ServiceContext<PoxPayloadIn, PoxPayloadOut> 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<PoxPayloadIn, PoxPayloadOut> parentCtx,
                UriInfo uriInfo,
                String orderBy,
                String keywords,
@@ -546,6 +557,9 @@ public abstract class NuxeoBasedResource
        ServiceContext<PoxPayloadIn, PoxPayloadOut> 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) {
index 6b0947494a73c730904f4c16d7583c5241146293..46bf5587bde4777d82fe054a0c3f2624505bf17b 100644 (file)
@@ -92,7 +92,7 @@ public class RelationResource extends NuxeoBasedResource {
                return this.getList(parentCtx, parentCtx.getUriInfo());
        }
        
-       private RelationsCommonList getList(ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx, UriInfo uriInfo) {
+       public RelationsCommonList getList(ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx, UriInfo uriInfo) {
                MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
                
                String subjectCsid = queryParams.getFirst(IRelationsManager.SUBJECT_QP);
index b237b92044b3435b9c9fc60cd09f9600e304427e..4693e9363bd9c4520301c9fd7a76759876723f1c 100644 (file)
@@ -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<PoxPayloadIn, PoxPayloadOut> parentCtx, UriInfo uriInfo) {
+               throw new UnsupportedOperationException();
+       }
 }
index b0ada69b0e3e32b7694320469ad3fd552bbb69a4..686a3ed9c692bed8f3da944bdc021ceb57bed694 100644 (file)
@@ -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<PoxPayloadIn, PoxPayloadOut> parentCtx, UriInfo ui) {
         try {
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(ui);
+            if (parentCtx != null && parentCtx.getCurrentRepositorySession() != null) {
+                ctx.setCurrentRepositorySession(parentCtx.getCurrentRepositorySession()); // Reuse the current repo session if one exists
+            }
             MultivaluedMap<String, String> queryParams = ctx.getQueryParams();
             DocumentHandler handler = createDocumentHandler(ctx);
             String docType = queryParams.getFirst(IQueryManager.SEARCH_TYPE_DOCTYPE);
index 2830de30142274bcb46c67621d9b58ba68ecb987..a063ce47ed08765f1bb622ea74a9ca5753431cee 100644 (file)
  */
 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<PoxPayloadIn, PoxPayloadOut> parentCtx, UriInfo uriInfo) {
+               throw new UnsupportedOperationException();
+       }
 }