This is an automated email from the git hooks/post-receive script. New commit to branch feature/1184_Lima_ne_demarre_pas in repository lima. See http://git.chorem.org/lima.git commit 4fdca9845b80ea8146d373f3dbf7b92a2fe7e8a2 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Mar 2 10:36:29 2015 +0100 debut de correction sur les resources --- .../chorem/lima/business/LimaServiceConfig.java | 29 +++++++++++-- .../main/java/org/chorem/lima/LimaSwingConfig.java | 2 +- .../org/chorem/lima/web/action/ReportBuilder.java | 47 +++++++++++++++------- 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/lima-business/src/main/java/org/chorem/lima/business/LimaServiceConfig.java b/lima-business/src/main/java/org/chorem/lima/business/LimaServiceConfig.java index fd36487..dc06d48 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/LimaServiceConfig.java +++ b/lima-business/src/main/java/org/chorem/lima/business/LimaServiceConfig.java @@ -37,6 +37,8 @@ import org.nuiton.topia.flyway.TopiaFlywayService; import org.nuiton.topia.persistence.TopiaConfigurationConstants; import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Map; import java.util.Properties; @@ -68,6 +70,7 @@ public class LimaServiceConfig { protected static volatile LimaServiceConfig instance; + //TODO Remove protected final static String ROOT_PATH = new File("").getAbsolutePath(); private LimaServiceConfig(String configFileName) { @@ -277,9 +280,28 @@ public class LimaServiceConfig { config.saveForUser(); } - public String getBalanceDocumentReportModelPath() { - String result = config.getOption(ServiceConfigOption.BALANCE_DOCUMENT_REPORT_MODEL_PATH.getKey()); + public URL getBalanceDocumentReportModelUrl() { + + String optionValue = config.getOption(ServiceConfigOption.BALANCE_DOCUMENT_REPORT_MODEL_PATH.getKey()); + File file = new File(optionValue); + + URL result; + if (file.exists()) { + try { + result = file.toURI().toURL(); + } catch (MalformedURLException e) { + throw new LimaTechnicalException("Could not get url of file: "+file); + } + } else { + result = getClass().getResource(optionValue); + } + + if (result == null) { + throw new LimaTechnicalException("Could not find balanceDocumentReportModelUrl from option: " + optionValue); + } + return result; + } public void setBalanceDocumentReportModelPath(String path) { @@ -434,9 +456,10 @@ public class LimaServiceConfig { REPORTS_MODEL_DIR("lima.reports.dir",n("lima.config.reports.dir.description"),"${lima.data.dir}/reports", File.class, false, false), + //TODO ACCOUNT_DOCUMENT_REPORT_MODEL_PATH("lima.config.documentReport.account.documentReportModelPath", n("lima.config.documentReport.account.documentReportModelPath.description"), ROOT_PATH +"/lima-web/src/main/jasperreports/accounts/DocumentReport.jrxml",String.class, false, false), - BALANCE_DOCUMENT_REPORT_MODEL_PATH("lima.config.documentReport.balance.documentReportModelPath", n("lima.config.documentReport.balance.documentReportModelPath.description"), ROOT_PATH + "/lima-web/src/main/jasperreports/balance/DocumentReport.jrxml", String.class, false, false), + BALANCE_DOCUMENT_REPORT_MODEL_PATH("lima.config.documentReport.balance.documentReportModelPath", n("lima.config.documentReport.balance.documentReportModelPath.description"), "/jasperreports/balance/DocumentReport.jrxml", String.class, false, false), BALANCE_ACCOUNT_REPORT_MODEL_PATH("lima.config.documentReport.balance.balanceAccountReportModelPath", n("lima.config.documentReport.balance.balanceAccountReportModelPath.description"), ROOT_PATH + "/lima-web/src/main/jasperreports/balance/BalanceReportAccountReport.jrxml", String.class, false, false), BALANCE_SUB_ACCOUNT_REPORT_MODEL_PATH("lima.config.documentReport.balance.balanceSubAccountReportModelPath", n("lima.config.documentReport.balance.balanceSubAccountReportModelPath.description"), ROOT_PATH + "/lima-web/src/main/jasperreports/balance/BalanceSubAccountsReport.jrxml", String.class, false, false), diff --git a/lima-swing/src/main/java/org/chorem/lima/LimaSwingConfig.java b/lima-swing/src/main/java/org/chorem/lima/LimaSwingConfig.java index c38c9a2..826db4a 100644 --- a/lima-swing/src/main/java/org/chorem/lima/LimaSwingConfig.java +++ b/lima-swing/src/main/java/org/chorem/lima/LimaSwingConfig.java @@ -39,7 +39,7 @@ import org.nuiton.topia.persistence.TopiaConfigurationConstants; import org.nuiton.util.version.Version; import org.nuiton.util.version.VersionBuilder; -import java.awt.*; +import java.awt.Color; import java.beans.PropertyChangeListener; import java.io.File; import java.io.IOException; diff --git a/lima-web/src/main/java/org/chorem/lima/web/action/ReportBuilder.java b/lima-web/src/main/java/org/chorem/lima/web/action/ReportBuilder.java index df16484..8e7f35f 100644 --- a/lima-web/src/main/java/org/chorem/lima/web/action/ReportBuilder.java +++ b/lima-web/src/main/java/org/chorem/lima/web/action/ReportBuilder.java @@ -37,6 +37,9 @@ import org.chorem.lima.beans.DocumentReport; import org.chorem.lima.business.LimaServiceConfig; import org.chorem.lima.business.utils.DocumentsEnum; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -49,30 +52,46 @@ public class ReportBuilder { private static final Log log = LogFactory.getLog(ReportBuilder.class); protected JasperReport balanceDocumentReport; + protected JasperReport generalEntryBookDocumentReport; + protected JasperReport entryBookDocumentReport; + protected JasperReport generalLedgerDocumentReport; + protected Map<DocumentsEnum, JasperReport> reportsByDocumentType; public ReportBuilder() { - try { - LimaServiceConfig config = LimaServiceConfig.getInstance(); - // compile phase - balanceDocumentReport = JasperCompileManager.compileReport(config.getBalanceDocumentReportModelPath()); - generalEntryBookDocumentReport = JasperCompileManager.compileReport(config.getGeneralEntryBookDocumentReportModelPath()); - entryBookDocumentReport = JasperCompileManager.compileReport(config.getEntryBookDocumentReportModelPath()); - generalLedgerDocumentReport = JasperCompileManager.compileReport(config.getGeneralLedgerDocumentReportModelPath()); + LimaServiceConfig config = LimaServiceConfig.getInstance(); + + // compile phase + balanceDocumentReport = createReport(config.getBalanceDocumentReportModelUrl()); + //TODO +// generalEntryBookDocumentReport = JasperCompileManager.compileReport(config.getGeneralEntryBookDocumentReportModelPath()); +// entryBookDocumentReport = JasperCompileManager.compileReport(config.getEntryBookDocumentReportModelPath()); +// generalLedgerDocumentReport = JasperCompileManager.compileReport(config.getGeneralLedgerDocumentReportModelPath()); - reportsByDocumentType = Maps.newHashMap(); - reportsByDocumentType.put(DocumentsEnum.BALANCE, balanceDocumentReport); - reportsByDocumentType.put(DocumentsEnum.GENERAL_ENTRYBOOK, generalEntryBookDocumentReport); - reportsByDocumentType.put(DocumentsEnum.ENTRYBOOKS, entryBookDocumentReport); - reportsByDocumentType.put(DocumentsEnum.LEDGER, generalLedgerDocumentReport); + reportsByDocumentType = Maps.newHashMap(); + reportsByDocumentType.put(DocumentsEnum.BALANCE, balanceDocumentReport); + reportsByDocumentType.put(DocumentsEnum.GENERAL_ENTRYBOOK, generalEntryBookDocumentReport); + reportsByDocumentType.put(DocumentsEnum.ENTRYBOOKS, entryBookDocumentReport); + reportsByDocumentType.put(DocumentsEnum.LEDGER, generalLedgerDocumentReport); + + } + + protected JasperReport createReport(URL url) { + + try (InputStream inputStream = url.openStream()) { + JasperReport jasperReport = JasperCompileManager.compileReport(inputStream); + return jasperReport; + } catch (IOException e) { + throw new LimaTechnicalException("Could not close inputStream for " + url, e); } catch (JRException e) { - throw new LimaTechnicalException(e); + throw new LimaTechnicalException("Could not compile jaspert report for " + url, e); } + } public void generatePDFReport(DocumentsEnum reportType, String path, List<DocumentReport> reports) { @@ -83,7 +102,7 @@ public class ReportBuilder { JasperPrint jasperPrint = JasperFillManager.fillReport(report, new HashMap(), new JRBeanCollectionDataSource(reports)); JasperExportManager.exportReportToPdfFile(jasperPrint, path); if (log.isInfoEnabled()) { - log.info("Rapport généré:"+path); + log.info("Rapport généré:" + path); } } else { throw new LimaTechnicalException("JasperReport not found for " + reportType); -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.