From 284fe3fdb214acc45a58fd5db0dacf4f67d71a60 Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Mon, 18 Jul 2011 21:14:33 +0000 Subject: [PATCH] CSPACE-4231 Adding/cleaning up support for no-context invocation of reports and batch jobs. Added some XMLReplay-based tests for reporting. --- .../test-data/xmlreplay/report/ac1.xml | 16 ++++ .../test-data/xmlreplay/report/report.xml | 83 +++++++++++++++++++ .../test-data/xmlreplay/report/report1.xml | 15 ++++ .../report/report1InvContextStandalone.xml | 10 +++ .../main/resources/schemas/batch_common.xsd | 17 ++-- .../jaxb/src/main/resources/batch_common.xsd | 1 + .../services/batch/BatchResource.java | 18 ++-- .../services/common/invocable/Invocable.java | 3 +- .../services/jaxb/InvocableJAXBSchema.java | 1 + .../main/resources/schemas/reports_common.xsd | 7 +- .../src/main/resources/reports-common.xsd | 19 +++-- .../services/report/ReportResource.java | 59 ++++++++----- 12 files changed, 203 insertions(+), 46 deletions(-) create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/ac1.xml create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/report.xml create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/report1.xml create mode 100644 services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/report1InvContextStandalone.xml diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/ac1.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/ac1.xml new file mode 100644 index 000000000..99747809b --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/ac1.xml @@ -0,0 +1,16 @@ + + + + Ac2011.1.2 + usd + 2011-07-04 + 2011-07-04 + usd + Bargain + purchase + 1 + usd + urn:cspace:org.collectionspace.demo:personauthority:id(4c300397-746f-48f0-bc29):person:id(fadd6312-486e-4ada-92c9)'Patrick+Schmitz' + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/report.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/report.xml new file mode 100644 index 000000000..ae99dd207 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/report.xml @@ -0,0 +1,83 @@ + + + + + YWRtaW5AY29yZS5jb2xsZWN0aW9uc3BhY2Uub3JnOkFkbWluaXN0cmF0b3I= + + + + POST + /cspace-services/reports/ + report/report1.xml + + + GET + /cspace-services/reports/${createReport1.CSID} + + + POST + /cspace-services/acquisitions/ + report/ac1.xml + + + + + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/report1.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/report1.xml new file mode 100644 index 000000000..0ceba0fde --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/report1.xml @@ -0,0 +1,15 @@ + + + + Acquisition Summary + Just a few fields about a single acquisition + Acquisition + true + false + false + true + acq_basic.jasper + application/pdf + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/report1InvContextStandalone.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/report1InvContextStandalone.xml new file mode 100644 index 000000000..ffed4b3ff --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/report1InvContextStandalone.xml @@ -0,0 +1,10 @@ + + + single + Acquisition + 605e9252-598d-4459-8380 + + + diff --git a/services/batch/3rdparty/nuxeo-platform-cs-batch/src/main/resources/schemas/batch_common.xsd b/services/batch/3rdparty/nuxeo-platform-cs-batch/src/main/resources/schemas/batch_common.xsd index 3e5b3f7c5..abed71e9b 100644 --- a/services/batch/3rdparty/nuxeo-platform-cs-batch/src/main/resources/schemas/batch_common.xsd +++ b/services/batch/3rdparty/nuxeo-platform-cs-batch/src/main/resources/schemas/batch_common.xsd @@ -23,12 +23,13 @@ - - - - - - - - + + + + + + + + + diff --git a/services/batch/jaxb/src/main/resources/batch_common.xsd b/services/batch/jaxb/src/main/resources/batch_common.xsd index 181e59724..c8f03741d 100644 --- a/services/batch/jaxb/src/main/resources/batch_common.xsd +++ b/services/batch/jaxb/src/main/resources/batch_common.xsd @@ -24,6 +24,7 @@ + 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 0db8fecb2..a573357c7 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 @@ -192,12 +192,16 @@ public class BatchResource extends ResourceBase { DocumentModel docModel = wrapper.getWrappedObject(); String invocationMode = invContext.getMode(); String modeProperty = null; + boolean checkDocType = true; if(BatchInvocable.INVOCATION_MODE_SINGLE.equalsIgnoreCase(invocationMode)) { modeProperty = BatchJAXBSchema.SUPPORTS_SINGLE_DOC; } else if(BatchInvocable.INVOCATION_MODE_LIST.equalsIgnoreCase(invocationMode)) { modeProperty = BatchJAXBSchema.SUPPORTS_DOC_LIST; } else if(BatchInvocable.INVOCATION_MODE_GROUP.equalsIgnoreCase(invocationMode)) { modeProperty = BatchJAXBSchema.SUPPORTS_GROUP; + } else if(Invocable.INVOCATION_MODE_NO_CONTEXT.equalsIgnoreCase(invocationMode)) { + modeProperty = InvocableJAXBSchema.SUPPORTS_NO_CONTEXT; + checkDocType = false; } else { throw new BadRequestException("BatchResource: unknown Invocation Mode: " +invocationMode); @@ -225,12 +229,14 @@ public class BatchResource extends ResourceBase { "BatchResource: Invoked with unsupported context mode: " +invocationMode); } - String forDocType = - (String)docModel.getPropertyValue(BatchJAXBSchema.FOR_DOC_TYPE); - if(!forDocType.equalsIgnoreCase(invContext.getDocType())) { - throw new BadRequestException( - "BatchResource: Invoked with unsupported document type: " - +invContext.getDocType()); + if(checkDocType) { + String forDocType = + (String)docModel.getPropertyValue(BatchJAXBSchema.FOR_DOC_TYPE); + if(!forDocType.equalsIgnoreCase(invContext.getDocType())) { + throw new BadRequestException( + "BatchResource: Invoked with unsupported document type: " + +invContext.getDocType()); + } } batchInstance.setInvocationContext(invContext); //ResourceMapHolder csapp = (ResourceMapHolder)app; diff --git a/services/common/src/main/java/org/collectionspace/services/common/invocable/Invocable.java b/services/common/src/main/java/org/collectionspace/services/common/invocable/Invocable.java index c5c2f6669..5be98d501 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/invocable/Invocable.java +++ b/services/common/src/main/java/org/collectionspace/services/common/invocable/Invocable.java @@ -62,8 +62,9 @@ public interface Invocable { } public String INVOCATION_MODE_SINGLE = "single"; - public String INVOCATION_MODE_GROUP = "group"; public String INVOCATION_MODE_LIST = "list"; + public String INVOCATION_MODE_GROUP = "group"; + public String INVOCATION_MODE_NO_CONTEXT = "nocontext"; //public String INVOCATION_MODE_QUERY = "query"; NYI public final int STATUS_ERROR = -1; diff --git a/services/jaxb/src/main/java/org/collectionspace/services/jaxb/InvocableJAXBSchema.java b/services/jaxb/src/main/java/org/collectionspace/services/jaxb/InvocableJAXBSchema.java index cfae32486..0bf74425a 100644 --- a/services/jaxb/src/main/java/org/collectionspace/services/jaxb/InvocableJAXBSchema.java +++ b/services/jaxb/src/main/java/org/collectionspace/services/jaxb/InvocableJAXBSchema.java @@ -8,5 +8,6 @@ public interface InvocableJAXBSchema { final static String SUPPORTS_SINGLE_DOC = "supportsSingleDoc"; final static String SUPPORTS_DOC_LIST = "supportsDocList"; final static String SUPPORTS_GROUP = "supportsGroup"; + final static String SUPPORTS_NO_CONTEXT = "supportsNoContext"; // NYI final static String SUPPORTS_QUERY "supportsQuery"; } diff --git a/services/report/3rdparty/nuxeo-platform-cs-report/src/main/resources/schemas/reports_common.xsd b/services/report/3rdparty/nuxeo-platform-cs-report/src/main/resources/schemas/reports_common.xsd index fe3f02c34..2baa52006 100644 --- a/services/report/3rdparty/nuxeo-platform-cs-report/src/main/resources/schemas/reports_common.xsd +++ b/services/report/3rdparty/nuxeo-platform-cs-report/src/main/resources/schemas/reports_common.xsd @@ -23,9 +23,10 @@ - - - + + + + diff --git a/services/report/jaxb/src/main/resources/reports-common.xsd b/services/report/jaxb/src/main/resources/reports-common.xsd index 8745f0a38..e477850eb 100644 --- a/services/report/jaxb/src/main/resources/reports-common.xsd +++ b/services/report/jaxb/src/main/resources/reports-common.xsd @@ -32,15 +32,16 @@ - - - - - - - - - + + + + + + + + + + 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 0de359d8f..c17ee3dcf 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 @@ -28,6 +28,7 @@ import net.sf.jasperreports.engine.JasperExportManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; +import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.jaxb.InvocableJAXBSchema; import org.collectionspace.services.ReportJAXBSchema; import org.collectionspace.services.client.PoxPayloadIn; @@ -65,6 +66,7 @@ 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.MultivaluedMap; import javax.ws.rs.core.Response; import java.io.File; import java.io.FileInputStream; @@ -100,6 +102,19 @@ public class ReportResource extends ResourceBase { return ReportsCommon.class; } + @Override + protected AbstractCommonList getList(MultivaluedMap queryParams) { + try { + ServiceContext ctx = createServiceContext(queryParams); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).getFiltered(ctx, handler); + AbstractCommonList list = (AbstractCommonList) handler.getCommonPartList(); + return list; + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.LIST_FAILED); + } + } + /* * TODO: provide a static utility that will load a report, interrogate it * for information about the properties, and return that information. @@ -121,6 +136,17 @@ public class ReportResource extends ResourceBase { @Produces("application/pdf") public Response invokeReport( @PathParam("csid") String csid) { + InvocationContext invContext = new InvocationContext(); + invContext.setMode(Invocable.INVOCATION_MODE_NO_CONTEXT); + return invokeReport(csid, invContext); + } + + @POST + @Path("{csid}") + @Produces("application/pdf") + public Response invokeReport( + @PathParam("csid") String csid, + InvocationContext invContext) { if (csid == null || "".equals(csid)) { logger.error("invokeReport: missing csid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( @@ -131,24 +157,6 @@ public class ReportResource extends ResourceBase { if (logger.isTraceEnabled()) { logger.trace("invokeReport with csid=" + csid); } - try { - ServiceContext ctx = createServiceContext(); - DocumentWrapper docWrapper = getRepositoryClient(ctx).getDoc(ctx, csid); - DocumentModel docModel = docWrapper.getWrappedObject(); - String reportFileName = (String)docModel.getPropertyValue(ReportJAXBSchema.FILENAME); - HashMap params = new HashMap(); - return buildReportResponse(csid, params, reportFileName); - } catch (Exception e) { - throw bigReThrow(e, ServiceMessages.POST_FAILED); - } - } - - @POST - @Path("{csid}") - @Produces("application/pdf") - public Response invokeReport( - @PathParam("csid") String csid, - InvocationContext invContext) { try { ServiceContext ctx = createServiceContext(); DocumentHandler handler = createDocumentHandler(ctx); @@ -158,6 +166,7 @@ public class ReportResource extends ResourceBase { String invocationMode = invContext.getMode(); String modeProperty = null; HashMap params = new HashMap(); + boolean checkDocType = true; if(Invocable.INVOCATION_MODE_SINGLE.equalsIgnoreCase(invocationMode)) { modeProperty = InvocableJAXBSchema.SUPPORTS_SINGLE_DOC; params.put("csid", invContext.getSingleCSID()); @@ -185,16 +194,28 @@ public class ReportResource extends ResourceBase { } else if(Invocable.INVOCATION_MODE_GROUP.equalsIgnoreCase(invocationMode)) { modeProperty = InvocableJAXBSchema.SUPPORTS_GROUP; params.put("groupcsid", invContext.getGroupCSID()); + } else if(Invocable.INVOCATION_MODE_NO_CONTEXT.equalsIgnoreCase(invocationMode)) { + modeProperty = InvocableJAXBSchema.SUPPORTS_NO_CONTEXT; + checkDocType = false; } else { throw new BadRequestException("ReportResource: unknown Invocation Mode: " +invocationMode); } Boolean supports = (Boolean)docModel.getPropertyValue(modeProperty); - if(!supports) { + if(supports == null || !supports) { throw new BadRequestException( "ReportResource: This Report does not support Invocation Mode: " +invocationMode); } + if(checkDocType) { + String forDocType = + (String)docModel.getPropertyValue(InvocableJAXBSchema.FOR_DOC_TYPE); + if(!forDocType.equalsIgnoreCase(invContext.getDocType())) { + throw new BadRequestException( + "ReportResource: Invoked with unsupported document type: " + +invContext.getDocType()); + } + } String reportFileName = (String)docModel.getPropertyValue(ReportJAXBSchema.FILENAME); return buildReportResponse(csid, params, reportFileName); -- 2.47.3