From d406bc022ba36fd86bcec7a48a3a77614c745261 Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Thu, 24 Jan 2013 12:09:00 -0800 Subject: [PATCH] CSPACE-4876 Added support to code to recompile reports as needed, to make upgrade path much easier for users. Changed our build script to copy the jrxml file, rather than the .jasper file. --- .../services/common/api/Tools.java | 15 +++++++++ services/report/3rdparty/build.xml | 2 +- .../services/client/ReportClient.java | 2 ++ .../nuxeo/ReportDocumentModelHandler.java | 31 ++++++++++++++++--- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/services/common-api/src/main/java/org/collectionspace/services/common/api/Tools.java b/services/common-api/src/main/java/org/collectionspace/services/common/api/Tools.java index 905127f37..933ee30d2 100644 --- a/services/common-api/src/main/java/org/collectionspace/services/common/api/Tools.java +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/Tools.java @@ -123,6 +123,8 @@ public class Tools { static boolean m_fileSystemIsDOS = "\\".equals(File.separator); static boolean m_fileSystemIsMac = ":".equals(File.separator); + + public final static String FILE_EXTENSION_SEPARATOR = "."; public static boolean fileSystemIsDOS(){return m_fileSystemIsDOS;} public static boolean fileSystemIsMac(){return m_fileSystemIsMac;} @@ -153,6 +155,19 @@ public class Tools { } return dir + file; } + + public static String getFilenameExtension(String filename) { + int dot = filename.lastIndexOf(FILE_EXTENSION_SEPARATOR); + return (dot>=0)?filename.substring(dot + 1):null; + } + + public static String getFilenameBase(String filename) { + int dot = filename.lastIndexOf(FILE_EXTENSION_SEPARATOR); + if(dot<0) + dot = filename.length(); + int sep = filename.lastIndexOf(File.separator); // Note: if -1, then sep+1=0, which is right + return filename.substring(sep + 1, dot); + } public static String getStackTrace(Throwable e){ return getStackTrace(e, -1); diff --git a/services/report/3rdparty/build.xml b/services/report/3rdparty/build.xml index 84f0d56a5..c015abc6e 100644 --- a/services/report/3rdparty/build.xml +++ b/services/report/3rdparty/build.xml @@ -112,7 +112,7 @@ description="Copy sample jasper files to ${jee.server.cspace}/cspace/reports"> + includes="*.jrxml"/> diff --git a/services/report/client/src/main/java/org/collectionspace/services/client/ReportClient.java b/services/report/client/src/main/java/org/collectionspace/services/client/ReportClient.java index 59490726b..82d40bac5 100644 --- a/services/report/client/src/main/java/org/collectionspace/services/client/ReportClient.java +++ b/services/report/client/src/main/java/org/collectionspace/services/client/ReportClient.java @@ -44,6 +44,8 @@ public class ReportClient extends AbstractCommonListPoxServiceClientImpl { 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); -- 2.47.3