]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-1069: Allow docType to be group or null in group mode invocations. (#355)
authorRay Lee <ray.lee@lyrasis.org>
Wed, 14 Jun 2023 19:25:41 +0000 (15:25 -0400)
committerGitHub <noreply@github.com>
Wed, 14 Jun 2023 19:25:41 +0000 (15:25 -0400)
services/batch/service/src/main/java/org/collectionspace/services/batch/nuxeo/BatchDocumentModelHandler.java
services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java

index bb2a0d8daf757b7b87832794fababe10ca8247f0..8e34182a3a749323c3f4e0e798e5a364079ec9e1 100644 (file)
@@ -250,14 +250,25 @@ public class BatchDocumentModelHandler extends NuxeoDocumentModelHandler<BatchCo
                        //
                        // Ensure the batch job supports the requested invocation context's document type
                        if (!Invocable.INVOCATION_MODE_NO_CONTEXT.equalsIgnoreCase(invocationCtx.getMode())) {
+                               String invDocType = invocationCtx.getDocType();
                                ForDocTypes forDocTypes = batchCommon.getForDocTypes();
-                               if (forDocTypes != null) {
-                                       List<String> forDocTypeList = toLowerCase(forDocTypes.getForDocType()); // convert all strings to lowercase.
-                                       if (forDocTypeList == null || !forDocTypeList.contains(invocationCtx.getDocType().toLowerCase())) {
-                                               String msg = String.format("BatchResource: The batch job '%s' CSID='%s' does not support the invocation document type '%s'.",
-                                                               batchCommon.getName(), csid, invocationCtx.getDocType());
-                                               throw new BadRequestException(msg);
-                                       }
+
+                               List<String> forDocTypeList = (forDocTypes == null)
+                                       ? new ArrayList<String>()
+                                       : toLowerCase(forDocTypes.getForDocType()); // convert all strings to lowercase.
+
+                               if (Invocable.INVOCATION_MODE_GROUP.equalsIgnoreCase(invocationCtx.getMode())) {
+                                       // In group mode, allow the context doc type to be Group or null, even if the report wasn't registered
+                                       // with those types.
+
+                                       forDocTypeList.add("group");
+                                       forDocTypeList.add(null);
+                               }
+
+                               if (!forDocTypeList.contains(invDocType.toLowerCase())) {
+                                       String msg = String.format("BatchResource: The batch job '%s' CSID='%s' does not support the invocation document type '%s'.",
+                                                       batchCommon.getName(), csid, invDocType);
+                                       throw new BadRequestException(msg);
                                }
                        }
 
index f07290c150dcc4db6b1f7fe0e1c2d24d27edbea0..cc9ae464699aabdb5f2b3a5d55296cc66b6aecc6 100644 (file)
@@ -31,6 +31,7 @@ import java.io.InputStream;
 import java.nio.file.Files;
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -272,15 +273,28 @@ public class ReportDocumentModelHandler extends NuxeoDocumentModelHandler<Report
                                                "ReportResource: This Report does not support Invocation Mode: "
                                        +invocationMode);
                        }
-               if (checkDocType) {
-                       List<String> forDocTypeList =
-                               (List<String>) NuxeoUtils.getProperyValue(docModel, InvocableJAXBSchema.FOR_DOC_TYPES); //docModel.getPropertyValue(InvocableJAXBSchema.FOR_DOC_TYPES);
-                       if (forDocTypeList==null || !forDocTypeList.contains(invContext.getDocType())) {
-                               throw new BadRequestException(
-                                               "ReportResource: Invoked with unsupported document type: "
-                                               +invContext.getDocType());
-                       }
-               }
+                       if (checkDocType) {
+                               String invDocType = invContext.getDocType();
+                               List<String> forDocTypeList = (List<String>) NuxeoUtils.getProperyValue(docModel, InvocableJAXBSchema.FOR_DOC_TYPES);
+
+                               if (forDocTypeList == null) {
+                                       forDocTypeList = new ArrayList<String>();
+                               }
+
+                               if (Invocable.INVOCATION_MODE_GROUP.equalsIgnoreCase(invocationMode)) {
+                                       // In group mode, allow the context doc type to be Group or null, even if the report wasn't registered
+                                       // with those types.
+
+                                       forDocTypeList.add("Group");
+                                       forDocTypeList.add(null);
+                               }
+
+                               if (!forDocTypeList.contains(invDocType)) {
+                                       throw new BadRequestException(
+                                               "ReportResource: Invoked with unsupported document type: "
+                                               +invDocType);
+                               }
+                       }
                reportFileNameProperty = (String) NuxeoUtils.getProperyValue(docModel, ReportJAXBSchema.FILENAME); //docModel.getPropertyValue(ReportJAXBSchema.FILENAME)); // Set the outgoing param with the report file name
                        //
                // If the invocation context contains a MIME type then use it.  Otherwise, look in the report resource.  If no MIME type in the report resource,