From: Ray Lee Date: Wed, 14 Jun 2023 19:25:41 +0000 (-0400) Subject: DRYD-1069: Allow docType to be group or null in group mode invocations. (#355) X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=64523cdedfdfac31c3a097d5fb56a58c3b887b39;p=tmp%2Fjakarta-migration.git DRYD-1069: Allow docType to be group or null in group mode invocations. (#355) --- 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 bb2a0d8da..8e34182a3 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 @@ -250,14 +250,25 @@ public class BatchDocumentModelHandler extends NuxeoDocumentModelHandler 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 forDocTypeList = (forDocTypes == null) + ? new ArrayList() + : 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); } } 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 f07290c15..cc9ae4646 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 @@ -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 forDocTypeList = - (List) 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 forDocTypeList = (List) NuxeoUtils.getProperyValue(docModel, InvocableJAXBSchema.FOR_DOC_TYPES); + + if (forDocTypeList == null) { + forDocTypeList = new ArrayList(); + } + + 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,