]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-4876 Added support to code to recompile reports as needed, to make upgrade...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Thu, 24 Jan 2013 20:09:00 +0000 (12:09 -0800)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Thu, 24 Jan 2013 20:09:00 +0000 (12:09 -0800)
services/common-api/src/main/java/org/collectionspace/services/common/api/Tools.java
services/report/3rdparty/build.xml
services/report/client/src/main/java/org/collectionspace/services/client/ReportClient.java
services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java

index 905127f372a5d89c99e8fadd6184fb04541451b7..933ee30d2e5bec35c97a6d2af7a4381e59263dad 100644 (file)
@@ -123,6 +123,8 @@ public class Tools {
 \r
     static boolean m_fileSystemIsDOS = "\\".equals(File.separator);\r
     static boolean m_fileSystemIsMac = ":".equals(File.separator);\r
+    \r
+    public final static String FILE_EXTENSION_SEPARATOR = ".";\r
 \r
     public static boolean fileSystemIsDOS(){return m_fileSystemIsDOS;}\r
     public static boolean fileSystemIsMac(){return m_fileSystemIsMac;}\r
@@ -153,6 +155,19 @@ public class Tools {
         }\r
         return dir + file;\r
     }\r
+    \r
+    public static String getFilenameExtension(String filename) {\r
+        int dot = filename.lastIndexOf(FILE_EXTENSION_SEPARATOR);\r
+        return (dot>=0)?filename.substring(dot + 1):null;\r
+        }\r
+\r
+    public static String getFilenameBase(String filename) {\r
+        int dot = filename.lastIndexOf(FILE_EXTENSION_SEPARATOR);\r
+        if(dot<0)\r
+               dot = filename.length();\r
+        int sep = filename.lastIndexOf(File.separator); // Note: if -1, then sep+1=0, which is right\r
+        return filename.substring(sep + 1, dot);\r
+        }\r
 \r
     public static String getStackTrace(Throwable e){\r
         return getStackTrace(e, -1);\r
index 84f0d56a50a7d41c0e4899a78f55ffd2ea6051c6..c015abc6ee96db5368bb80f051b6e9c0ac259a49 100644 (file)
                        description="Copy sample jasper files to ${jee.server.cspace}/cspace/reports">\r
         <copy todir="${jee.server.cspace}/cspace/reports">\r
                                        <fileset dir="${basedir}/jasper-cs-report/src/main/resources"\r
-                                                                       includes="*.jasper"/>\r
+                                                                       includes="*.jrxml"/>\r
         </copy>\r
     </target>\r
 \r
index 59490726b28928604ea85807d9050c714f25eab2..82d40bac5ce506ad428de45a01b849bb1a5396c4 100644 (file)
@@ -44,6 +44,8 @@ public class ReportClient extends AbstractCommonListPoxServiceClientImpl<ReportP
     public static final String CSV_MIME_TYPE = "text/csv";
     public static final String TSV_MIME_TYPE = "text/tab-separated-values";
     public static final String DEFAULT_REPORT_OUTPUT_MIME = PDF_MIME_TYPE;
+    public static final String COMPILED_REPORT_EXTENSION = ".jasper";
+    public static final String REPORT_DECSRIPTION_EXTENSION = ".jrxml";
 
     @Override
     public String getServiceName() {
index 426014e4637fc61b78cfeaba05b66987e5f88959..bd9fbfbc72adfaca691d0c799a2aaf4772446ac6 100644 (file)
@@ -44,6 +44,7 @@ import net.sf.jasperreports.engine.JRException;
 import net.sf.jasperreports.engine.JRExporter;
 import net.sf.jasperreports.engine.JRExporterParameter;
 import net.sf.jasperreports.engine.JRParameter;
+import net.sf.jasperreports.engine.JasperCompileManager;
 import net.sf.jasperreports.engine.JasperExportManager;
 import net.sf.jasperreports.engine.JasperFillManager;
 import net.sf.jasperreports.engine.JasperPrint;
@@ -53,6 +54,7 @@ import net.sf.jasperreports.engine.export.JRHtmlExporter;
 import net.sf.jasperreports.engine.export.JRPdfExporter;
 import net.sf.jasperreports.engine.export.JRXmlExporter;
 
+import org.bouncycastle.crypto.RuntimeCryptoException;
 import org.collectionspace.services.ReportJAXBSchema;
 import org.collectionspace.services.report.ReportsCommon;
 import org.collectionspace.services.client.PoxPayloadIn;
@@ -228,18 +230,39 @@ public class ReportDocumentModelHandler extends DocHandlerBase<ReportsCommon> {
                Connection conn = null;
                Response response = null;
        try {
-                       String fullPath = ServiceMain.getInstance().getServerRootDir() +
+               String fileNameBase = Tools.getFilenameBase(reportFileName);
+               String compiledReportFilename = fileNameBase+ReportClient.COMPILED_REPORT_EXTENSION;
+               String reportDescriptionFilename = fileNameBase+ReportClient.REPORT_DECSRIPTION_EXTENSION;
+               
+                       String basePath = ServiceMain.getInstance().getServerRootDir() +
                                                                File.separator + ConfigReader.CSPACE_DIR_NAME + 
                                                                File.separator + REPORTS_FOLDER +
                                                                // File.separator + tenantName +
-                                                               File.separator + reportFileName;
+                                                               File.separator; // + reportFileName;
+                       
+                       String compiledFilePath = basePath+compiledReportFilename; 
+                       File f = new File(compiledFilePath);
+                       if(!f.exists()) { // Need to compile the file
+                               // First verify that there is a source file.
+                               String sourceFilePath = basePath+reportDescriptionFilename; 
+                               File f2 = new File(sourceFilePath);
+                               if(!f2.exists()) { // Missing source file - error!
+                                       logger.error("Report for csid={} is missing the specified source file: {}",
+                                                                       reportCSID, sourceFilePath);
+                                       throw new RuntimeException("Report is missing the specified source file!");
+                               }
+               logger.info("Report for csid={} is not compiled. Compiling first, and saving to: {}",
+                               reportCSID, compiledFilePath);
+               JasperCompileManager.compileReportToFile(sourceFilePath, compiledFilePath);
+                       }                               
+                               
                        conn = getConnection();
        
             if (logger.isTraceEnabled()) {
                logger.trace("ReportResource for csid=" + reportCSID
-                               +" output as "+outputMimeType+" using report file: "+fullPath);
+                               +" output as "+outputMimeType+" using report file: "+compiledFilePath);
             }
-                       FileInputStream fileStream = new FileInputStream(fullPath);
+                       FileInputStream fileStream = new FileInputStream(compiledFilePath);
        
                        // export report to pdf and build a response with the bytes
                        //JasperExportManager.exportReportToPdf(jasperprint);