\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
}\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
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;
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;
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);