]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-4231 Adding/cleaning up support for no-context invocation of reports and batch...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Mon, 18 Jul 2011 21:14:33 +0000 (21:14 +0000)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Mon, 18 Jul 2011 21:14:33 +0000 (21:14 +0000)
12 files changed:
services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/ac1.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/report.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/report1.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/report/report1InvContextStandalone.xml [new file with mode: 0644]
services/batch/3rdparty/nuxeo-platform-cs-batch/src/main/resources/schemas/batch_common.xsd
services/batch/jaxb/src/main/resources/batch_common.xsd
services/batch/service/src/main/java/org/collectionspace/services/batch/BatchResource.java
services/common/src/main/java/org/collectionspace/services/common/invocable/Invocable.java
services/jaxb/src/main/java/org/collectionspace/services/jaxb/InvocableJAXBSchema.java
services/report/3rdparty/nuxeo-platform-cs-report/src/main/resources/schemas/reports_common.xsd
services/report/jaxb/src/main/resources/reports-common.xsd
services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java

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 (file)
index 0000000..9974780
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<document name="acquisitions">\r
+       <ns2:acquisitions_common xmlns:ns2="http://collectionspace.org/services/acquisition" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+               <acquisitionReferenceNumber>Ac2011.1.2</acquisitionReferenceNumber>\r
+               <objectOfferPriceCurrency>usd</objectOfferPriceCurrency>\r
+               <acquisitionAuthorizerDate>2011-07-04</acquisitionAuthorizerDate>\r
+               <accessionDate>2011-07-04</accessionDate>\r
+               <originalObjectPurchasePriceCurrency>usd</originalObjectPurchasePriceCurrency>\r
+               <acquisitionReason>Bargain</acquisitionReason>\r
+               <acquisitionMethod>purchase</acquisitionMethod>\r
+               <originalObjectPurchasePriceValue>1</originalObjectPurchasePriceValue>\r
+               <objectPurchaseOfferPriceCurrency>usd</objectPurchaseOfferPriceCurrency>\r
+               <acquisitionAuthorizer>urn:cspace:org.collectionspace.demo:personauthority:id(4c300397-746f-48f0-bc29):person:id(fadd6312-486e-4ada-92c9)'Patrick+Schmitz'</acquisitionAuthorizer>\r
+       </ns2:acquisitions_common>\r
+</document>\r
+\r
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 (file)
index 0000000..ae99dd2
--- /dev/null
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<xmlReplay>\r
+       <auths>\r
+               <!-- IMPORTANT: THESE ARE STICKY :: THEY STICK AROUND UNTIL RESET, IN EXEC ORDER OF THIS FILE. -->\r
+               <auth ID="admin@core.collectionspace.org">YWRtaW5AY29yZS5jb2xsZWN0aW9uc3BhY2Uub3JnOkFkbWluaXN0cmF0b3I=</auth>\r
+       </auths>\r
+       <testGroup ID="testSingle" autoDeletePOSTS="false">\r
+               <test ID="createReport1" auth="test">\r
+                       <method>POST</method>\r
+                       <uri>/cspace-services/reports/</uri>\r
+                       <filename>report/report1.xml</filename>\r
+               </test>\r
+               <test ID="readReport1" auth="test">\r
+                       <method>GET</method>\r
+                       <uri>/cspace-services/reports/${createReport1.CSID}</uri>\r
+               </test>\r
+               <test ID="createAcq" auth="test">\r
+                       <method>POST</method>\r
+                       <uri>/cspace-services/acquisitions/</uri>\r
+                       <filename>report/ac1.xml</filename>\r
+               </test>\r
+               <!-- XmlReplay does not know how to ask for anything except XML, so gets a 406\r
+                    Even if it could ask for PDF, it could not handle the response...\r
+               <test ID="testInvokeSingle" auth="test" autoDeletePOSTS="false">\r
+                       <method>POST</method>\r
+                       <uri>/cspace-services/reports/${createReport1.CSID}</uri>\r
+                       <filename>report/report1InvContext.xml</filename>\r
+                       <vars>\r
+                               <var ID="Acq1">${createAcq.CSID}</var>\r
+                       </vars>\r
+               </test>\r
+               -->\r
+               <!--\r
+               <test ID="testInvokeList" auth="test" autoDeletePOSTS="false">\r
+                       <method>POST</method>\r
+                       <uri>/cspace-services/batch/${createCollObj1.CSID}</uri>\r
+                       <filename>batch/batchInvContextList.xml</filename>\r
+                       <vars>\r
+                               <var ID="CollObj1">${createBatch.CSID}</var>\r
+                       </vars>\r
+               </test>\r
+               <test ID="testBadInvoke" auth="test" autoDeletePOSTS="false">\r
+                       <method>POST</method>\r
+                       <expectedCodes>400</expectedCodes>\r
+                       <uri>/cspace-services/batch/${createCollObj1.CSID}</uri>\r
+                       <filename>batch/batchBadInvContext.xml</filename>\r
+                       <vars>\r
+                               <var ID="CollObj1">${createBatch.CSID}</var>\r
+                       </vars>\r
+               </test>\r
+               <test ID="testInvokeEmptyList" auth="test" autoDeletePOSTS="false">\r
+                       <method>POST</method>\r
+                       <expectedCodes>400</expectedCodes>\r
+                       <uri>/cspace-services/batch/${createCollObj1.CSID}</uri>\r
+                       <filename>batch/batchBadInvContextList.xml</filename>\r
+                       <vars>\r
+                               <var ID="CollObj1">${createBatch.CSID}</var>\r
+                       </vars>\r
+               </test>\r
+               <test ID="testFilteredList1" auth="test">\r
+                       <method>GET</method>\r
+                       <uri>/cspace-services/batch?doctype=CollectionObject&amp;inv=single</uri>\r
+               </test>\r
+               <test ID="testFilteredList2" auth="test">\r
+                       <method>GET</method>\r
+                       <uri>/cspace-services/batch?doctype=Intake&amp;inv=group</uri>\r
+               </test>\r
+               -->\r
+       </testGroup>\r
+       <!-- \r
+     <testGroup ID="cleanup" autoDeletePOSTS="true">\r
+         <test ID="cl1"  auth="test">\r
+             <method>DELETE</method>\r
+             <uri>/cspace-services/batch/${createCollObj1.CSID}</uri>\r
+         </test>\r
+         <test ID="cl2"  auth="test">\r
+             <method>DELETE</method>\r
+             <uri>/cspace-services/collectionobjects/${createBatch.CSID}</uri>\r
+         </test>\r
+                        </testGroup>\r
+                        -->\r
+</xmlReplay>\r
+\r
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 (file)
index 0000000..0ceba0f
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r
+<document name="report">\r
+       <ns2:reports_common\r
+       xmlns:ns2="http://collectionspace.org/services/report">\r
+               <name>Acquisition Summary</name>\r
+               <notes>Just a few fields about a single acquisition</notes>\r
+               <forDocType>Acquisition</forDocType>\r
+               <supportsSingleDoc>true</supportsSingleDoc>\r
+               <supportsDocList>false</supportsDocList>\r
+               <supportsGroup>false</supportsGroup>\r
+               <supportsNoContext>true</supportsNoContext>\r
+               <filename>acq_basic.jasper</filename>\r
+               <outputMIME>application/pdf</outputMIME>\r
+       </ns2:reports_common>\r
+</document>\r
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 (file)
index 0000000..ffed4b3
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r
+<ns2:invocationContext\r
+xmlns:ns2="http://collectionspace.org/services/common/invocable"\r
+xmlns:ns3="http://collectionspace.org/services/jaxb">\r
+  <mode>single</mode>\r
+       <docType>Acquisition</docType>\r
+       <singleCSID>605e9252-598d-4459-8380</singleCSID>\r
+</ns2:invocationContext>\r
+\r
+\r
index 3e5b3f7c5357116e7e24ccf8c56d147ec3edef9f..abed71e9bb06f35612bfd3b886b659e9cf6f2686 100644 (file)
     <!--  Batch Information Group -->\r
     \r
     <xs:element name="name" type="xs:string"/>\r
-       <xs:element name="notes" type="xs:string"/>\r
-       <xs:element name="forDocType" type="xs:string"/>\r
-       <xs:element name="supportsSingleDoc" type="xs:boolean"/>\r
-       <xs:element name="supportsDocList" type="xs:boolean"/>\r
-       <xs:element name="supportsGroup" type="xs:boolean"/>\r
-       <!-- NYI <xs:element name="supportsQuery" type="xs:boolean"/>  -->\r
-       <xs:element name="createsNewFocus" type="xs:boolean"/>\r
-       <xs:element name="className" type="xs:string"/>\r
+    <xs:element name="notes" type="xs:string"/>\r
+    <xs:element name="forDocType" type="xs:string"/>\r
+    <xs:element name="supportsNoContext" type="xs:boolean"/>\r
+    <xs:element name="supportsSingleDoc" type="xs:boolean"/>\r
+    <xs:element name="supportsDocList" type="xs:boolean"/>\r
+    <xs:element name="supportsGroup" type="xs:boolean"/>\r
+    <!-- NYI <xs:element name="supportsQuery" type="xs:boolean"/>  -->\r
+    <xs:element name="createsNewFocus" type="xs:boolean"/>\r
+    <xs:element name="className" type="xs:string"/>\r
 </xs:schema>\r
index 181e5972423c27c6bd23d31e3787fc759c86d6cf..c8f03741d34ab80b33be4bce7caf1a769144f94c 100644 (file)
@@ -24,6 +24,7 @@
                 <xs:element name="name" type="xs:string"/>
                 <xs:element name="notes" type="xs:string"/>
                 <xs:element name="forDocType" type="xs:string"/>
+                <xs:element name="supportsNoContext" type="xs:boolean"/>
                 <xs:element name="forSingleDoc" type="xs:boolean"/>
                 <xs:element name="createsNewFocus" type="xs:boolean"/>
                 <xs:element name="className" type="xs:string"/>
index 0db8fecb2c7599286dfff656cd81fc1b7e6bcb12..a573357c77b607e5af91886af8fd01683787559b 100644 (file)
@@ -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;
index c5c2f6669a2898f05ea0f15fcf17ae5163345a23..5be98d501d8062847d6ee5c82fef663c2484787f 100644 (file)
@@ -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;
index cfae3248650d3b561d50db79a1cf781eb0fd460c..0bf74425af2172c0708e23e7f9f3b8128f5fe4a2 100644 (file)
@@ -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";
 }
index fe3f02c3405aa822c31b9102539ba09cdc6216da..2baa520069514fd8cb9d7fcb4f667eab17475795 100644 (file)
     <xs:element name="name" type="xs:string"/>\r
     <xs:element name="notes" type="xs:string"/>\r
     <xs:element name="forDocType" type="xs:string"/>\r
-       <xs:element name="supportsSingleDoc" type="xs:boolean"/>\r
-       <xs:element name="supportsDocList" type="xs:boolean"/>\r
-       <xs:element name="supportsGroup" type="xs:boolean"/>\r
+    <xs:element name="supportsNoContext" type="xs:boolean"/>\r
+    <xs:element name="supportsSingleDoc" type="xs:boolean"/>\r
+    <xs:element name="supportsDocList" type="xs:boolean"/>\r
+    <xs:element name="supportsGroup" type="xs:boolean"/>\r
        <!-- NYI <xs:element name="supportsQuery" type="xs:boolean"/>  -->\r
     <xs:element name="filename" type="xs:string"/>\r
     <xs:element name="outputMIME" type="xs:string"/>\r
index 8745f0a385b6bd4ba43b156734687ccf1a544e94..e477850eb65ec7b9391f6df1bf4c28f1d4f3d2ab 100644 (file)
         <xs:complexType>
             <xs:sequence>
                 <xs:element name="csid" type="xs:string" />
-                                       <xs:element name="name" type="xs:string"/>
-                                       <xs:element name="notes" type="xs:string"/>
-                                   <xs:element name="forDocType" type="xs:string"/>
-                                       <xs:element name="supportsSingleDoc" type="xs:boolean"/>
-                                       <xs:element name="supportsDocList" type="xs:boolean"/>
-                                       <xs:element name="supportsGroup" type="xs:boolean"/>
-                                       <!-- NYI <xs:element name="supportsQuery" type="xs:boolean"/>  -->
-                                   <xs:element name="filename" type="xs:string"/>
-                                   <xs:element name="outputMIME" type="xs:string"/>
+                <xs:element name="name" type="xs:string"/>
+                <xs:element name="notes" type="xs:string"/>
+                <xs:element name="forDocType" type="xs:string"/>
+                <xs:element name="supportsNoContext" type="xs:boolean"/>
+                <xs:element name="supportsSingleDoc" type="xs:boolean"/>
+                <xs:element name="supportsDocList" type="xs:boolean"/>
+                <xs:element name="supportsGroup" type="xs:boolean"/>
+                <!-- NYI <xs:element name="supportsQuery" type="xs:boolean"/>  -->
+                <xs:element name="filename" type="xs:string"/>
+                <xs:element name="outputMIME" type="xs:string"/>
             </xs:sequence>
         </xs:complexType>
     </xs:element>
index 0de359d8fa84c2c0de0d63f81d8ccc1a6bb3a54f..c17ee3dcfb9486aaa65ba4d0eb03faaa84af29b4 100644 (file)
@@ -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<String, String> queryParams) {
+        try {
+            ServiceContext<PoxPayloadIn, PoxPayloadOut> 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<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
-            DocumentWrapper<DocumentModel> 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<PoxPayloadIn, PoxPayloadOut> 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);