]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-2391, 2503, 4201, 4202, 4204, 4206 Updated Reporting invocation to follow...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Mon, 11 Jul 2011 22:12:50 +0000 (22:12 +0000)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Mon, 11 Jul 2011 22:12:50 +0000 (22:12 +0000)
12 files changed:
services/batch/jaxb/src/main/java/org/collectionspace/services/BatchJAXBSchema.java
services/batch/service/src/main/java/org/collectionspace/services/batch/BatchResource.java
services/jaxb/src/main/java/org/collectionspace/services/jaxb/InvocableJAXBSchema.java [new file with mode: 0644]
services/jaxb/src/main/resources/invocationContext.xsd
services/report/3rdparty/nuxeo-platform-cs-report/src/main/resources/schemas/reports_common.xsd
services/report/jaxb/src/main/java/org/collectionspace/services/ReportJAXBSchema.java
services/report/jaxb/src/main/java/org/collectionspace/services/ReportListItemJAXBSchema.java [deleted file]
services/report/jaxb/src/main/resources/reports-common.xsd
services/report/pom.xml
services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java
services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java
src/main/resources/db/postgresql/init_db.sql

index da083363c90c136bef6d103d6cc666bcb371357f..5d2c60b08ef9c6f6cc5d84b0ad23b6e444327943 100644 (file)
@@ -3,14 +3,11 @@
  */
 package org.collectionspace.services;
 
-public interface BatchJAXBSchema {
+import org.collectionspace.services.jaxb.InvocableJAXBSchema;
+
+public interface BatchJAXBSchema extends InvocableJAXBSchema {
     final static String BATCH_NAME = "name";
     final static String BATCH_NOTES = "notes";
-    final static String BATCH_FOR_DOC_TYPE = "forDocType";
-    final static String BATCH_SUPPORTS_SINGLE_DOC = "supportsSingleDoc";
-    final static String BATCH_SUPPORTS_DOC_LIST = "supportsDocList";
-    final static String BATCH_SUPPORTS_GROUP = "supportsGroup";
-    // NYI final static String BATCH_SUPPORTS_SINGLE_DOC = "supportsSingleDoc";
     final static String BATCH_CREATES_NEW_FOCUS = "createsNewFocus";
     final static String BATCH_CLASS_NAME = "className";
 }
index c3b12682a8f33f0e4881a9dff9398541f0f21835..0db8fecb2c7599286dfff656cd81fc1b7e6bcb12 100644 (file)
@@ -26,6 +26,7 @@ package org.collectionspace.services.batch;
 import java.util.List;
 
 import org.collectionspace.services.BatchJAXBSchema;
+import org.collectionspace.services.jaxb.InvocableJAXBSchema;
 import org.collectionspace.services.client.BatchClient;
 import org.collectionspace.services.client.IQueryManager;
 import org.collectionspace.services.client.PoxPayloadIn;
@@ -151,7 +152,7 @@ public class BatchResource extends ResourceBase {
                        throw new RuntimeException("No docType specified.");
                }
                String ptClause = COMMON_SCHEMA + ":"
-               + BatchJAXBSchema.BATCH_FOR_DOC_TYPE
+               + BatchJAXBSchema.FOR_DOC_TYPE
                        + "='" + trimmed + "'";
                return ptClause;
        }
@@ -163,11 +164,11 @@ public class BatchResource extends ResourceBase {
                }
                String ptClause = COMMON_SCHEMA + ":";
                if(Invocable.INVOCATION_MODE_SINGLE.equalsIgnoreCase(trimmed)) {
-                       ptClause += BatchJAXBSchema.BATCH_SUPPORTS_SINGLE_DOC + "!=0";
+                       ptClause += BatchJAXBSchema.SUPPORTS_SINGLE_DOC + "!=0";
                } else if(Invocable.INVOCATION_MODE_LIST.equalsIgnoreCase(trimmed)) {
-                       ptClause += BatchJAXBSchema.BATCH_SUPPORTS_DOC_LIST + "!=0";
+                       ptClause += BatchJAXBSchema.SUPPORTS_DOC_LIST + "!=0";
                } else if(Invocable.INVOCATION_MODE_GROUP.equalsIgnoreCase(trimmed)) {
-                       ptClause += BatchJAXBSchema.BATCH_SUPPORTS_GROUP + "!=0";
+                       ptClause += BatchJAXBSchema.SUPPORTS_GROUP + "!=0";
                } else {
                        throw new BadRequestException("No mode specified.");
                }
@@ -192,11 +193,11 @@ public class BatchResource extends ResourceBase {
                String invocationMode = invContext.getMode();
                String modeProperty = null;
                if(BatchInvocable.INVOCATION_MODE_SINGLE.equalsIgnoreCase(invocationMode)) {
-                       modeProperty = BatchJAXBSchema.BATCH_SUPPORTS_SINGLE_DOC;
+                       modeProperty = BatchJAXBSchema.SUPPORTS_SINGLE_DOC;
                } else if(BatchInvocable.INVOCATION_MODE_LIST.equalsIgnoreCase(invocationMode)) {
-                       modeProperty = BatchJAXBSchema.BATCH_SUPPORTS_DOC_LIST;
+                       modeProperty = BatchJAXBSchema.SUPPORTS_DOC_LIST;
                } else if(BatchInvocable.INVOCATION_MODE_GROUP.equalsIgnoreCase(invocationMode)) {
-                       modeProperty = BatchJAXBSchema.BATCH_SUPPORTS_GROUP;
+                       modeProperty = BatchJAXBSchema.SUPPORTS_GROUP;
                } else {
                        throw new BadRequestException("BatchResource: unknown Invocation Mode: "
                                +invocationMode);
@@ -225,7 +226,7 @@ public class BatchResource extends ResourceBase {
                                        +invocationMode);
                }
                        String forDocType = 
-                               (String)docModel.getPropertyValue(BatchJAXBSchema.BATCH_FOR_DOC_TYPE);
+                               (String)docModel.getPropertyValue(BatchJAXBSchema.FOR_DOC_TYPE);
                if(!forDocType.equalsIgnoreCase(invContext.getDocType())) {
                        throw new BadRequestException(
                                        "BatchResource: Invoked with unsupported document type: "
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
new file mode 100644 (file)
index 0000000..cfae324
--- /dev/null
@@ -0,0 +1,12 @@
+/**
+ * 
+ */
+package org.collectionspace.services.jaxb;
+
+public interface InvocableJAXBSchema {
+    final static String FOR_DOC_TYPE = "forDocType";
+    final static String SUPPORTS_SINGLE_DOC = "supportsSingleDoc";
+    final static String SUPPORTS_DOC_LIST = "supportsDocList";
+    final static String SUPPORTS_GROUP = "supportsGroup";
+               // NYI final static String SUPPORTS_QUERY "supportsQuery";
+}
index 8c5089af9e06a4ba67045d239c20e276f823f1b4..8c8ed9cec69662edc7ae4f5318bd24f080ef1d89 100644 (file)
                                                </xs:sequence>
                                        </xs:complexType>
                                </xs:element>
+                               <xs:element name="params">
+                                       <xs:complexType>
+                                               <xs:sequence>
+              <xs:element name="param" minOccurs="0" maxOccurs="unbounded">
+                                                               <xs:complexType>
+                                                                       <xs:sequence>
+                                                                               <xs:element name="key" type="xs:string" minOccurs="0" maxOccurs="1"/>
+                                                                               <xs:element name="value" type="xs:string" minOccurs="0" maxOccurs="1"/>
+                                                                       </xs:sequence>
+                                                               </xs:complexType>
+                                                       </xs:element>
+                                               </xs:sequence>
+                                       </xs:complexType>
+                               </xs:element>
                        </xs:sequence>
                </xs:complexType>
        </xs:element>
index 9632dad0cdf46812fc8fbd3dce0133362b7556de..fe3f02c3405aa822c31b9102539ba09cdc6216da 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="forSingleDoc" 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
 \r
index 19548d4c63395f9b3bb848c33524d4e6a09cb705..d5a461fea34d361402945506f8cc802a44842b5c 100644 (file)
@@ -3,16 +3,16 @@
  */\r
 package org.collectionspace.services;\r
 \r
+import org.collectionspace.services.jaxb.InvocableJAXBSchema;\r
+\r
 /**\r
  * @author pschmitz\r
  *\r
  */\r
-public interface ReportJAXBSchema {\r
+public interface ReportJAXBSchema extends InvocableJAXBSchema {\r
        final static String NAME = "name";\r
        final static String NOTES = "notes";\r
        final static String FILENAME = "filename";\r
-       final static String FOR_SINGLE_DOC = "forSingleDoc";\r
-       final static String FOR_DOC_TYPE = "forDocType";\r
        final static String OUTPUT_MIME = "outputMIME";\r
 }\r
 \r
diff --git a/services/report/jaxb/src/main/java/org/collectionspace/services/ReportListItemJAXBSchema.java b/services/report/jaxb/src/main/java/org/collectionspace/services/ReportListItemJAXBSchema.java
deleted file mode 100644 (file)
index 379ec85..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-package org.collectionspace.services;\r
-\r
-public interface ReportListItemJAXBSchema {\r
-       final static String NAME = "name";\r
-       final static String FOR_SINGLE_DOC = "forSingleDoc";\r
-       final static String FOR_DOC_TYPE = "forDocType";\r
-       final static String OUTPUT_MIME ="outputMIME";\r
-       final static String CSID = "csid";\r
-       final static String URI = "url";\r
-}\r
index 7e874858b4d01436749a89b714f89f0fe4812556..8745f0a385b6bd4ba43b156734687ccf1a544e94 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="forSingleDoc" 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="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>
                                         minOccurs="1" />
                                     <xs:element name="forDocType" type="xs:string"
                                         minOccurs="1" />
-                                    <xs:element name="forSingleDoc" type="xs:boolean"
+                                                                       <xs:element name="supportsSingleDoc" type="xs:boolean"
+                                        minOccurs="1" />
+                                                                       <xs:element name="supportsDocList" type="xs:boolean"
+                                        minOccurs="1" />
+                                                                       <xs:element name="supportsGroup" type="xs:boolean"
                                         minOccurs="1" />
                                    <!-- uri to retrive report details -->
                                     <xs:element name="uri" type="xs:anyURI"
index 4988437faafc5b06661b4b03cec2e6b0f7193766..18e57c4eadd414b8b9b5e583ece76ec172ba9636 100644 (file)
 \r
                <dependencies>\r
                        <dependency>\r
-                               <groupId>net.sf.jasperreports</groupId>\r
-                               <artifactId>jasperreports</artifactId>\r
-                               <version>3.7.3</version>\r
+                                       <groupId>net.sf.jasperreports</groupId>\r
+                                       <artifactId>jasperreports</artifactId>\r
+                                       <version>4.0.1</version>\r
                        </dependency>\r
                <dependency>\r
                        <groupId>org.codehaus.groovy</groupId>\r
                        <artifactId>groovy-all</artifactId>\r
-                       <version>1.5.5</version>\r
+                       <version>1.7.5</version>\r
                </dependency>\r
                </dependencies>\r
                \r
index 7935018b126bfc7665018239af2fb1fb5491abd5..58c23b3e26fa116b78e136aabd92eb40c391a648 100644 (file)
@@ -27,17 +27,28 @@ import net.sf.jasperreports.engine.JRException;
 import net.sf.jasperreports.engine.JasperExportManager;
 import net.sf.jasperreports.engine.JasperFillManager;
 import net.sf.jasperreports.engine.JasperPrint;
+
+import org.collectionspace.services.jaxb.InvocableJAXBSchema;
 import org.collectionspace.services.ReportJAXBSchema;
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.client.ReportClient;
 import org.collectionspace.services.common.ResourceBase;
+import org.collectionspace.services.common.ResourceMap;
 import org.collectionspace.services.common.ServiceMain;
+import org.collectionspace.services.common.ServiceMessages;
 import org.collectionspace.services.common.config.ConfigReader;
 import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.BadRequestException;
+import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
 import org.collectionspace.services.common.document.DocumentWrapper;
+import org.collectionspace.services.common.invocable.Invocable;
+import org.collectionspace.services.common.invocable.InvocationContext;
+import org.collectionspace.services.common.invocable.InvocationResults;
+import org.collectionspace.services.common.invocable.Invocable.InvocationError;
 import org.collectionspace.services.common.security.UnauthorizedException;
+import org.jboss.resteasy.spi.ResteasyProviderFactory;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -48,24 +59,28 @@ import javax.security.auth.login.LoginException;
 import javax.sql.DataSource;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
+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 java.io.File;
 import java.io.FileInputStream;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.HashMap;
+import java.util.List;
 
 @Path(ReportClient.SERVICE_PATH)
 @Consumes("application/xml")
 @Produces("application/xml")
 //@Produces("application/xml;charset=UTF-8")
 public class ReportResource extends ResourceBase {
-    private static String repositoryName = "NuxeoDS";
-    private static String reportsFolder = "reports";
+    private static String REPOSITORY_NAME = "NuxeoDS";
+    private static String REPORTS_FOLDER = "reports";
+    private static String CSID_LIST_SEPARATOR = ",";
     final Logger logger = LoggerFactory.getLogger(ReportResource.class);
 
     @Override
@@ -83,6 +98,17 @@ public class ReportResource extends ResourceBase {
     public Class<ReportsCommon> getCommonPartClass() {
        return ReportsCommon.class;
     }
+    
+    /*
+     * TODO: provide a static utility that will load a report, interrogate it
+     * for information about the properties, and return that information.
+     * See: http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/JasperManager.html#loadReport%28java.lang.String%29
+     * to get the report from the file.
+     * Use: http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/base/JRBaseReport.html#getParameters%28%29 
+     *  to get an array of http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/JRParameter.html
+     *  Cast each to JRBaseParameter and use isSystemDefined to filter out 
+     *    the system defined parameters.
+     */
 
     /**
      * Gets the report.
@@ -112,7 +138,7 @@ public class ReportResource extends ResourceBase {
                String reportFileName = (String)docModel.getPropertyValue(ReportJAXBSchema.FILENAME);
                String fullPath = ServiceMain.getInstance().getServerRootDir() +
                                                        File.separator + ConfigReader.CSPACE_DIR_NAME + 
-                                                       File.separator + reportsFolder +
+                                                       File.separator + REPORTS_FOLDER +
                                                        File.separator + reportFileName;
                Connection conn = getConnection();
                HashMap params = new HashMap();
@@ -176,20 +202,96 @@ public class ReportResource extends ResourceBase {
         }
         return response;
     }
+    
+    @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);
+            DocumentWrapper<DocumentModel> wrapper = 
+               getRepositoryClient(ctx).getDoc(ctx, csid);
+               DocumentModel docModel = wrapper.getWrappedObject();
+               String invocationMode = invContext.getMode();
+               String modeProperty = null;
+               HashMap params = new HashMap();
+               if(Invocable.INVOCATION_MODE_SINGLE.equalsIgnoreCase(invocationMode)) {
+                       modeProperty = InvocableJAXBSchema.SUPPORTS_SINGLE_DOC;
+                       params.put("csid", invContext.getSingleCSID());
+               } else if(Invocable.INVOCATION_MODE_LIST.equalsIgnoreCase(invocationMode)) {
+                       modeProperty = InvocableJAXBSchema.SUPPORTS_DOC_LIST;
+                       List<String> csids = null;
+                       InvocationContext.ListCSIDs listThing = invContext.getListCSIDs();
+                               if(listThing!=null) {
+                                       csids = listThing.getCsid();
+                               }
+                               if(csids==null||csids.isEmpty()){
+                               throw new BadRequestException(
+                                               "ReportResource: Report invoked in list mode, with no csids in list." );
+                               }
+                               StringBuilder sb = new StringBuilder();
+                               boolean first = true;
+                               for(String csidItem : csids) {
+                                       if(first)
+                                               first = false;
+                                       else
+                                               sb.append(CSID_LIST_SEPARATOR);
+                                       sb.append(csidItem);
+                               }
+                       params.put("csidlist", sb.toString());
+               } else if(Invocable.INVOCATION_MODE_GROUP.equalsIgnoreCase(invocationMode)) {
+                       modeProperty = InvocableJAXBSchema.SUPPORTS_GROUP;
+                       params.put("groupcsid", invContext.getGroupCSID());
+               } else {
+                       throw new BadRequestException("ReportResource: unknown Invocation Mode: "
+                               +invocationMode);
+               }
+               Boolean supports = (Boolean)docModel.getPropertyValue(modeProperty);
+               if(!supports) {
+                       throw new BadRequestException(
+                                       "ReportResource: This Report does not support Invocation Mode: "
+                               +invocationMode);
+               }
+               String reportFileName = (String)docModel.getPropertyValue(ReportJAXBSchema.FILENAME);
+               String fullPath = ServiceMain.getInstance().getServerRootDir() +
+                                                       File.separator + ConfigReader.CSPACE_DIR_NAME + 
+                                                       File.separator + REPORTS_FOLDER +
+                                                       // File.separator + tenantName +
+                                                       File.separator + reportFileName;
+               Connection conn = getConnection();
+
+               FileInputStream fileStream = new FileInputStream(fullPath);
+
+            // fill the report
+               JasperPrint jasperprint = JasperFillManager.fillReport(fileStream, params,conn);
+               // export report to pdf and build a response with the bytes
+               byte[] pdfasbytes = JasperExportManager.exportReportToPdf(jasperprint);
+               
+               // Need to set response type for what is requested...
+            Response response = Response.ok(pdfasbytes, "application/pdf").build();
+
+               return response;
+        } catch (Exception e) {
+            throw bigReThrow(e, ServiceMessages.POST_FAILED);
+        }
+    }
 
     private Connection getConnection() throws LoginException, SQLException {
         InitialContext ctx = null;
         Connection conn = null;
         try {
             ctx = new InitialContext();
-            DataSource ds = (DataSource) ctx.lookup(repositoryName);
+            DataSource ds = (DataSource) ctx.lookup(REPOSITORY_NAME);
             if (ds == null) {
-                throw new IllegalArgumentException("datasource not found: " + repositoryName);
+                throw new IllegalArgumentException("datasource not found: " + REPOSITORY_NAME);
             }
             conn = ds.getConnection();
             return conn;
         } catch (NamingException ex) {
-            LoginException le = new LoginException("Error looking up DataSource from: " + repositoryName);
+            LoginException le = new LoginException("Error looking up DataSource from: " + REPOSITORY_NAME);
             le.initCause(ex);
             throw le;
         } finally {
index 1518bc8a892872923eb5ffb8dbb7df76f209687a..db40ddf927e0165631ec5bde119200a1c015da7d 100644 (file)
@@ -132,10 +132,14 @@ public class ReportDocumentModelHandler
                     ReportJAXBSchema.NAME));
             ilistItem.setOutputMIME((String) docModel.getProperty(label,
                     ReportJAXBSchema.OUTPUT_MIME));
-            ilistItem.setForSingleDoc((Boolean) docModel.getProperty(label,
-                    ReportJAXBSchema.FOR_SINGLE_DOC));
             ilistItem.setForDocType((String) docModel.getProperty(label,
                     ReportJAXBSchema.FOR_DOC_TYPE));
+            ilistItem.setSupportsSingleDoc((Boolean) docModel.getProperty(label,
+                    ReportJAXBSchema.SUPPORTS_SINGLE_DOC));
+            ilistItem.setSupportsDocList((Boolean) docModel.getProperty(label,
+                    ReportJAXBSchema.SUPPORTS_DOC_LIST));
+            ilistItem.setSupportsGroup((Boolean) docModel.getProperty(label,
+                    ReportJAXBSchema.SUPPORTS_GROUP));
             String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
             ilistItem.setUri(getServiceContextPath() + id);
             ilistItem.setCsid(id);
index 9817d6156e4b665326d25e694dd58d5a32eda156..29d3658bd6f1152b19bd7a24f111bad1bb8491b2 100644 (file)
@@ -19,7 +19,9 @@ CREATE DATABASE nuxeo ENCODING 'UTF8' OWNER @DB_NUXEO_USER@;
 --\r
 -- Grant privileges to read-only user on Nuxeo, for reporting. \r
 --\r
--- GRANT SELECT ON ALL TABLES IN DATABASE nuxeo TO reader;\r
--- Will have to do this with a script after the nuxeo DB has been started,\r
--- since there is no wildcard syntax for grants (!). If nuxeo used a schema, \r
--- it would be easy. Check that.\r
+GRANT CONNECT ON DATABASE nuxeo TO reader;\r
+\r
+-- GRANT SELECT ON ALL TABLES IN SCHEMA public TO reader;\r
+-- This must be run by hand, after the system has already started up,\r
+-- so that it gives access to all the tables created on init.\r
+\r