01/01: refs #1197 Le module serveur est responsable du lancement du serveur web
This is an automated email from the git hooks/post-receive script. New commit to branch feature/1197-modularisation in repository lima. See http://git.chorem.org/lima.git commit a2ea31a92dee4c0b96bd5dd974af8e7d41e01949 Author: dcosse <cosse@codelutin.com> Date: Sun Mar 15 01:50:14 2015 +0100 refs #1197 Le module serveur est responsable du lancement du serveur web --- .../chorem/lima/business/api/OptionsService.java | 27 -- lima-business/pom.xml | 11 + .../chorem/lima/business/LimaBusinessConfig.java | 325 ++------------------- .../lima/business/ejb/OptionsServiceImpl.java | 70 ----- .../chorem/lima/service/LimaServiceFactory.java | 6 +- .../org/chorem/lima/business/AbstractLimaTest.java | 2 +- lima-report/pom.xml | 27 +- .../chorem/lima/report/action/ReportBuilder.java | 4 +- .../lima/report/service/DocumentService.java | 9 +- .../lima/report/service/LimaReportConfig.java | 285 +++--------------- .../resources/i18n/lima-report_en_GB.properties | 19 ++ .../resources/i18n/lima-report_fr_FR.properties | 19 ++ lima-server/pom.xml | 56 ++++ .../src/main/java/org.chorem.lima/LimaServer.java | 51 ++-- .../org.chorem.lima/server}/HttpServerService.java | 25 +- .../org.chorem.lima/server/LimaServerConfig.java | 264 +++++------------ lima-swing/pom.xml | 8 +- .../src/main/java/org/chorem/lima/LimaMain.java | 40 +-- .../chorem/lima/LimaSwingApplicationContext.java | 6 - .../main/java/org/chorem/lima/LimaSwingConfig.java | 14 +- .../java/org/chorem/lima/ui/MainViewHandler.java | 7 +- .../java/org/chorem/lima/ui/AbstractLimaTest.java | 3 +- pom.xml | 1 - 23 files changed, 323 insertions(+), 956 deletions(-) diff --git a/lima-business-api/src/main/java/org/chorem/lima/business/api/OptionsService.java b/lima-business-api/src/main/java/org/chorem/lima/business/api/OptionsService.java index 7128260..481077a 100644 --- a/lima-business-api/src/main/java/org/chorem/lima/business/api/OptionsService.java +++ b/lima-business-api/src/main/java/org/chorem/lima/business/api/OptionsService.java @@ -54,31 +54,4 @@ public interface OptionsService { */ int getScale(); - void setReportsDir(String url); - - void setAccountReportPath(String path); - - void setBalanceReportPath(String path); - - void setBalanceReportAccountReportPath(String path); - - void setBalanceSubAccountReportPath(String path); - - void setGeneralEntryBookEntryBookMainReportPath(String path); - - void setGeneralEntryBookPeriodReportPath(String path); - - void setGeneralEntryBookGeneralEntryBookReportPath(String path); - - void setProvisionalEntryBookEntryBookMainReportPath(String path); - - void setProvisionalEntryBookEntryBookReportPath(String path); - - void setProvisionalEntryBookFinancialPeriodReportPath(String path); - - void setProvisionalEntryBookTransactionReportPath(String path); -// void setBigDecimalFormat(String format); -// -// String getBigDecimalFormat(); - } diff --git a/lima-business/pom.xml b/lima-business/pom.xml index 40454b3..f4a6965 100644 --- a/lima-business/pom.xml +++ b/lima-business/pom.xml @@ -80,6 +80,17 @@ <artifactId>openejb-ejbd</artifactId> </dependency> <dependency> + <groupId>org.apache.openejb</groupId> + <artifactId>openejb-core</artifactId> + <scope>compile</scope> + </dependency> + + <!-- for remote mode only --> + <dependency> + <groupId>org.apache.openejb</groupId> + <artifactId>openejb-client</artifactId> + </dependency> + <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </dependency> diff --git a/lima-business/src/main/java/org/chorem/lima/business/LimaBusinessConfig.java b/lima-business/src/main/java/org/chorem/lima/business/LimaBusinessConfig.java index 02876e8..a25d44e 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/LimaBusinessConfig.java +++ b/lima-business/src/main/java/org/chorem/lima/business/LimaBusinessConfig.java @@ -28,7 +28,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaTechnicalException; import org.chorem.lima.business.accountingrules.FranceAccountingRules; -import org.chorem.lima.business.utils.DocumentReportTypes; import org.chorem.lima.entity.LimaCallaoEntityEnum; import org.chorem.lima.entity.LimaFlywayServiceImpl; import org.nuiton.config.ApplicationConfig; @@ -38,8 +37,6 @@ 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; @@ -92,6 +89,29 @@ public class LimaBusinessConfig { } } + private LimaBusinessConfig(final ApplicationConfig config) { + try { + ApplicationConfig defaultConfig = new ApplicationConfig(ServiceConfigOption.CONFIG_FILE.getDefaultValue()); + defaultConfig.loadDefaultOptions(ServiceConfigOption.values()); + defaultConfig.parse(); + + if (config != null) { + Properties flatOptions = defaultConfig.getFlatOptions(); + flatOptions.putAll(config.getFlatOptions(true)); + this.config = new ApplicationConfig(flatOptions, ServiceConfigOption.CONFIG_FILE.getDefaultValue()); + this.config.parse(); + } else { + if (log.isWarnEnabled()) { + log.warn("No specific configuration provided, using the default one"); + } + this.config = defaultConfig; + } + instance = this; + } catch (ArgumentsParserException ex) { + throw new LimaTechnicalException("Can't read configuration", ex); + } + } + protected static Properties getRootContextProperties() { if (getInstance().rootContextProperties == null) { Properties result = instance.getFlatOptions(); @@ -128,7 +148,14 @@ public class LimaBusinessConfig { public static LimaBusinessConfig getInstance() { if (instance == null) { - instance= new LimaBusinessConfig(null); + instance= new LimaBusinessConfig(""); + } + return instance; + } + + public static LimaBusinessConfig getInstance(ApplicationConfig config) { + if (instance == null) { + instance= new LimaBusinessConfig(config); } return instance; } @@ -198,49 +225,7 @@ public class LimaBusinessConfig { loadAccountingRules(); } - public File getDataDir() { - File datadir = config.getOptionAsFile(ServiceConfigOption.DATA_DIR.getKey()); - return datadir; - } - - public String getAddressServer() { - String serverAddress = config.getOption(ServiceConfigOption.SERVER_ADRESS.getKey()); - return serverAddress; - } - - public int getHttpPort() { - String httpPort = config.getOption(ServiceConfigOption.HTTP_PORT.getKey()); - Integer port = Integer.valueOf(httpPort); - return port; - } - - public String getVatPDFUrl() { - String vatPDFUrl = config.getOption(ServiceConfigOption.VAT_PDF_URL.getKey()); - return vatPDFUrl; - } - - public void setVatPDFUrl(String url) { - config.setOption(ServiceConfigOption.VAT_PDF_URL.key, url); - config.saveForUser(); - } - - // ** REPORT PART ** - - public File getReportsModelDir() { - String reportsDirPath = config.getOption(ServiceConfigOption.REPORTS_MODEL_DIR.key); - File result = new File(reportsDirPath); - return result; - } - - public void setReportsModelDir(String url) { - config.setOption(ServiceConfigOption.REPORTS_MODEL_DIR.key, url); - config.saveForUser(); - } - public String getAccountReportModelPath() { - String vatPDFUrl = config.getOption(ServiceConfigOption.ACCOUNT_DOCUMENT_REPORT_MODEL_PATH.getKey()); - return vatPDFUrl; - } public int getScale() { return config.getOptionAsInt(ServiceConfigOption.SCALE.key); @@ -279,225 +264,6 @@ public class LimaBusinessConfig { config.saveForUser(); } - public void setAccountReportModelPath(String path) { - config.setOption(ServiceConfigOption.ACCOUNT_DOCUMENT_REPORT_MODEL_PATH.key, path); - config.saveForUser(); - } - - public URL getReportModelUrl(DocumentReportTypes documentType) { - URL mainReportBuilderPath = null; - switch (documentType) { - case ACCOUNT: - mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.ACCOUNT_DOCUMENT_REPORT_MODEL_PATH.key); - break; - - case BALANCE: - mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.BALANCE_DOCUMENT_REPORT_MODEL_PATH.key); - break; - case BALANCE_MAIN_ACCOUNTS: - mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.BALANCE_ACCOUNT_REPORT_MODEL_PATH.key); - break; - case BALANCE_SUB_ACCOUNTS: - mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.BALANCE_SUB_ACCOUNT_REPORT_MODEL_PATH.key); - break; - - case ENTRY_BOOKS: - mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.ENTRY_BOOK_DOCUMENT_REPORT_MODEL_PATH.key); - break; - case ENTRY_BOOKS_ENTRY_BOOKS: - mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.ENTRY_BOOK_ENTRY_BOOK_REPORT_MODEL_PATH.key); - break; - case ENTRY_BOOKS_FINANCIAL_PERIODS: - mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.ENTRY_BOOK_FINANCIAL_PERIOD_REPORT_MODEL_PATH.key); - break; - case ENTRY_BOOKS_TRANSACTION: - mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.ENTRY_BOOK_TRANSACTION_REPORT_MODEL_PATH.key); - break; - - case GENERAL_ENTRY_BOOK: - mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.GENERAL_ENTRY_BOOK_DOCUMENT_REPORT_MODEL_PATH.key); - break; - case GENERAL_ENTRY_BOOK_GENERAL_ENTRY_BOOKS: - mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.GENERAL_ENTRY_BOOK_REPORT_MODEL_PATH.key); - break; - case GENERAL_ENTRY_BOOK_ENTRIES: - mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.GENERAL_ENTRY_BOOK_ENTRY_REPORT_MODEL_PATH.key); - break; - - case LEDGER: - mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.GENERAL_LEDGER_DOCUMENT_REPORT_MODEL_PATH.key); - break; - case LEDGER_GENERAL_LEDGERS: - mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.GENERAL_LEDGER_MODEL_PATH.key); - break; - case LEDGER_ENTRIES: - mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.GENERAL_LEDGER_ENTRY_MODEL_PATH.key); - break; - } - return mainReportBuilderPath; - } - - protected URL getReportModelUrl(String documentReportKey) { - - String optionValue = config.getOption(documentReportKey); - 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(String.format("Could not find option: %s", documentReportKey)); - } - - return result; - - } - - public void setBalanceDocumentReportModelPath(String path) { - config.setOption(ServiceConfigOption.BALANCE_DOCUMENT_REPORT_MODEL_PATH.key, path); - config.saveForUser(); - } - - public String getBalanceAccountReportModelPath() { - String result = config.getOption(ServiceConfigOption.BALANCE_ACCOUNT_REPORT_MODEL_PATH.getKey()); - return result; - } - - public void setBalanceAccountReportModelPath(String path) { - config.setOption(ServiceConfigOption.BALANCE_ACCOUNT_REPORT_MODEL_PATH.key, path); - config.saveForUser(); - } - - public String getBalanceSubAccountReportModelPath() { - String result = config.getOption(ServiceConfigOption.BALANCE_SUB_ACCOUNT_REPORT_MODEL_PATH.getKey()); - return result; - } - - public void setBalanceSubAccountReportModelPath(String path) { - config.setOption(ServiceConfigOption.BALANCE_SUB_ACCOUNT_REPORT_MODEL_PATH.key, path); - config.saveForUser(); - } - - public String getEntryBookDocumentReportModelPath() { - String result = config.getOption(ServiceConfigOption.ENTRY_BOOK_DOCUMENT_REPORT_MODEL_PATH.getKey()); - return result; - } - - public void setEntryBookDocumentReportModelPath(String path) { - config.setOption(ServiceConfigOption.ENTRY_BOOK_DOCUMENT_REPORT_MODEL_PATH.key, path); - config.saveForUser(); - } - public String getEntryBookEntryBookReportModelPath() { - String result = config.getOption(ServiceConfigOption.ENTRY_BOOK_ENTRY_BOOK_REPORT_MODEL_PATH.getKey()); - return result; - } - - public void setEntryBookEntryBookReportModelPath(String path) { - config.setOption(ServiceConfigOption.ENTRY_BOOK_ENTRY_BOOK_REPORT_MODEL_PATH.key, path); - config.saveForUser(); - } - - public String getEntryBookFinancialPeriodReportModelPath() { - String result = config.getOption(ServiceConfigOption.ENTRY_BOOK_FINANCIAL_PERIOD_REPORT_MODEL_PATH.getKey()); - return result; - } - - public void setEntryBookFinancialPeriodReportModelPath(String path) { - config.setOption(ServiceConfigOption.ENTRY_BOOK_FINANCIAL_PERIOD_REPORT_MODEL_PATH.key, path); - config.saveForUser(); - } - - public String getEntryBookTransactionReportModelPath() { - String result = config.getOption(ServiceConfigOption.ENTRY_BOOK_TRANSACTION_REPORT_MODEL_PATH.getKey()); - return result; - } - - public void setEntryBookTransactionReportModelPath(String path) { - config.setOption(ServiceConfigOption.ENTRY_BOOK_TRANSACTION_REPORT_MODEL_PATH.key, path); - config.saveForUser(); - } - - public String getGeneralEntryBookDocumentReportModelPath() { - String result = config.getOption(ServiceConfigOption.GENERAL_ENTRY_BOOK_DOCUMENT_REPORT_MODEL_PATH.getKey()); - return result; - } - - public void setGeneralEntryBookDocumentReportModelPath(String path) { - config.setOption(ServiceConfigOption.GENERAL_ENTRY_BOOK_DOCUMENT_REPORT_MODEL_PATH.key, path); - config.saveForUser(); - } - - public String getGeneralEntryBookReportModelPath() { - String result = config.getOption(ServiceConfigOption.GENERAL_ENTRY_BOOK_REPORT_MODEL_PATH.getKey()); - return result; - } - - public void setGeneralEntryBookReportModelPath(String path) { - config.setOption(ServiceConfigOption.GENERAL_ENTRY_BOOK_REPORT_MODEL_PATH.key, path); - config.saveForUser(); - } - - public String getGeneralEntryBookEntryReportModelPath() { - String result = config.getOption(ServiceConfigOption.GENERAL_ENTRY_BOOK_ENTRY_REPORT_MODEL_PATH.getKey()); - return result; - } - - public void setGeneralEntryBookEntryReportModelPath(String path) { - config.setOption(ServiceConfigOption.GENERAL_ENTRY_BOOK_ENTRY_REPORT_MODEL_PATH.key, path); - config.saveForUser(); - } - - public String getGeneralLedgerDocumentReportModelPath() { - String result = config.getOption(ServiceConfigOption. - GENERAL_LEDGER_DOCUMENT_REPORT_MODEL_PATH.getKey()); - return result; - } - - public void setGeneralLedgerDocumentReportModelPath(String path) { - config.setOption(ServiceConfigOption. - GENERAL_LEDGER_DOCUMENT_REPORT_MODEL_PATH.key, path); - config.saveForUser(); - } - - public String getGeneralLedgerModelPath() { - String result = config.getOption(ServiceConfigOption. - GENERAL_LEDGER_MODEL_PATH.getKey()); - return result; - } - - public void setGeneralLedgerModelPath(String path) { - config.setOption(ServiceConfigOption. - GENERAL_LEDGER_MODEL_PATH.key, path); - config.saveForUser(); - } - - public String getGeneralLedgerEntryModelPath() { - String result = config.getOption(ServiceConfigOption. - GENERAL_LEDGER_ENTRY_MODEL_PATH.getKey()); - return result; - } - - public void setGeneralLedgerEntryModelPath(String path) { - config.setOption(ServiceConfigOption. - GENERAL_LEDGER_ENTRY_MODEL_PATH.key, path); - config.saveForUser(); - } - - public String getHostAddress() { - String result = config.getOption(ServiceConfigOption. - LIMA_HOST_ADDRESS.getKey()); - return result; - } - - /** * Lima option definition. * <p/> @@ -519,38 +285,11 @@ public class LimaBusinessConfig { APPLICATION_VERSION("application.version", n("application.version"), null, String.class, false, false), DATA_DIR("lima.data.dir", n("lima.config.data.dir.description"), "${user.home}/.lima", File.class, false, false), RULES_NATIONALTY("lima.rules", n("lima.config.rulesnationality.description"), FranceAccountingRules.class.getName(), String.class, false, false), - HTTP_PORT("lima.httpport", n("lima.config.httpport.description"), "5462", String.class, false, false), - SERVER_ADRESS("lima.serveraddress", n("lima.config.serveraddress.description"), "localhost", String.class, false, false), - VAT_PDF_URL("lima.report.vatpdfurl", n("lima.config.reportvatpdfurl.description"), "default", String.class, false, false), - - REPORTS_MODEL_DIR("lima.reports.dir",n("lima.config.reports.dir.description"),"${lima.data.dir}/reports", File.class, false, false), - - ACCOUNT_DOCUMENT_REPORT_MODEL_PATH("lima.config.documentReport.account.documentReportModelPath", n("lima.config.documentReport.account.documentReportModelPath.description"), "/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"), "/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"), "/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"), "/jasperreports/balance/BalanceSubAccountsReport.jrxml", String.class, false, false), - - GENERAL_ENTRY_BOOK_DOCUMENT_REPORT_MODEL_PATH("lima.config.documentReport.generalEntrybook.documentReportModelPath", n("lima.config.documentReport.generalEntrybook.documentReportModelPath.description"), "/jasperreports/generalEntryBook/DocumentReport.jrxml", String.class, false, false), - GENERAL_ENTRY_BOOK_REPORT_MODEL_PATH("lima.config.documentReport.generalEntrybook.generalEntryBookModelPath", n("lima.config.documentReport.generalEntrybook.generalEntryBookModelPath.description"), "/jasperreports/generalEntryBook/EntryBookPeriodReport.jrxml", String.class, false, false), - GENERAL_ENTRY_BOOK_ENTRY_REPORT_MODEL_PATH("lima.config.documentReport.generalEntrybook.generalEntryBookEntryModelPath", n("blima.config.documentReport.generalEntrybook.generalEntryBookEntryModelPath.description"), "/jasperreports/generalEntryBook/GeneralEntryBookEntryReport.jrxml", String.class, false, false), - - ENTRY_BOOK_DOCUMENT_REPORT_MODEL_PATH("lima.config.documentReport.entrybook.documentReportModelPath", n("lima.config.documentReport.entrybook.documentReportModelPath.description"), "/jasperreports/entryBook/DocumentReport.jrxml", String.class, false, false), - ENTRY_BOOK_ENTRY_BOOK_REPORT_MODEL_PATH("lima.config.documentReport.entrybook.entryBookModelPath", n("lima.config.documentReport.entrybook.entryBookModelPath.description"), "/jasperreports/entryBook/EntryBookReport.jrxml", String.class, false, false), - ENTRY_BOOK_FINANCIAL_PERIOD_REPORT_MODEL_PATH("lima.config.documentReport.entrybook.financialPeriodModelPath", n("lima.config.documentReport.entrybook.financialPeriodModelPath.description"), "/jasperreports/entryBook/FinancialPeriodReport.jrxml", String.class, false, false), - ENTRY_BOOK_TRANSACTION_REPORT_MODEL_PATH("lima.config.documentReport.entrybook.transactionReportModelPath", n("lima.config.documentReport.entrybook.transactionReportModelPath.description"), "/jasperreports/entryBook/TransactionReport.jrxml", String.class, false, false), - - GENERAL_LEDGER_DOCUMENT_REPORT_MODEL_PATH("lima.config.documentReport.generalLedger.documentReportModelPath", n("lima.config.documentReport.generalLedger.documentReportModelPath.description"), "/jasperreports/generalLedger/DocumentReport.jrxml", String.class, false, false), - GENERAL_LEDGER_MODEL_PATH("lima.config.documentReport.generalLedger.generalLedgerModelPath", n("lima.config.documentReport.generalLedger.generalLedgerModelPath.description"), "/jasperreports/generalLedger/GeneralLedgerReport.jrxml", String.class, false, false), - GENERAL_LEDGER_ENTRY_MODEL_PATH("lima.config.documentReport.generalLedger.generalLedgerEntryModelPath", n("lima.config.documentReport.generalLedger.generalLedgerEntryModelPath.description"), "/jasperreports/generalLedger/GeneralLedgerEntryReport.jrxml", String.class, false, false), SCALE("lima.scale", n("lima.config.scale.description"), "2", String.class, false, false), CURRENCY("lima.config.currency", "", "false", Boolean.class, false, false), DECIMAL_SEPARATOR("lima.data.bigDecimal.decimalSeparator", "", ",", Character.class, false, false), - THOUSAND_SEPARATOR("lima.thousandSeparator", "", " ", Character.class, false, false), - - LIMA_HOST_ADDRESS("lima.host.address",n("lima.config.host.address.description"),"localhost",String.class, false, false); - + THOUSAND_SEPARATOR("lima.thousandSeparator", "", " ", Character.class, false, false); private final String key; diff --git a/lima-business/src/main/java/org/chorem/lima/business/ejb/OptionsServiceImpl.java b/lima-business/src/main/java/org/chorem/lima/business/ejb/OptionsServiceImpl.java index 00e4204..2a5a893 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/ejb/OptionsServiceImpl.java +++ b/lima-business/src/main/java/org/chorem/lima/business/ejb/OptionsServiceImpl.java @@ -38,7 +38,6 @@ public class OptionsServiceImpl extends AbstractLimaService implements OptionsSe public OptionsServiceImpl() { scale = LimaBusinessConfig.getInstance().getScale(); - vatPDFUrl = LimaBusinessConfig.getInstance().getVatPDFUrl(); BigDecimalToString.generateDecimalFormat(); } @@ -70,73 +69,4 @@ public class OptionsServiceImpl extends AbstractLimaService implements OptionsSe LimaBusinessConfig.getInstance().setDecimalSeparator(decimalSeparator); BigDecimalToString.generateDecimalFormat(); } - - @Override - public void setReportsDir(String path) { - LimaBusinessConfig.getInstance().setReportsModelDir(path); - } - - @Override - public void setAccountReportPath(String path) { - LimaBusinessConfig.getInstance().setAccountReportModelPath(path); - } - - @Override - public void setBalanceReportPath(String path) { - LimaBusinessConfig.getInstance().setBalanceDocumentReportModelPath(path); - } - - @Override - public void setBalanceReportAccountReportPath(String path) { - LimaBusinessConfig.getInstance().setBalanceAccountReportModelPath(path); - } - - @Override - public void setBalanceSubAccountReportPath(String path) { - LimaBusinessConfig.getInstance().setBalanceSubAccountReportModelPath(path); - } - - @Override - public void setGeneralEntryBookEntryBookMainReportPath(String path) { - LimaBusinessConfig.getInstance().setGeneralEntryBookDocumentReportModelPath(path); - } - - @Override - public void setGeneralEntryBookPeriodReportPath(String path) { - LimaBusinessConfig.getInstance().setGeneralEntryBookReportModelPath(path); - } - - @Override - public void setGeneralEntryBookGeneralEntryBookReportPath(String path) { - LimaBusinessConfig.getInstance().setGeneralEntryBookEntryReportModelPath(path); - } - - @Override - public void setProvisionalEntryBookEntryBookMainReportPath(String path) { - LimaBusinessConfig.getInstance().setEntryBookDocumentReportModelPath(path); - } - - @Override - public void setProvisionalEntryBookEntryBookReportPath(String path) { - LimaBusinessConfig.getInstance().setEntryBookEntryBookReportModelPath(path); - } - - @Override - public void setProvisionalEntryBookFinancialPeriodReportPath(String path) { - LimaBusinessConfig.getInstance().setEntryBookFinancialPeriodReportModelPath(path); - } - - @Override - public void setProvisionalEntryBookTransactionReportPath(String path) { - LimaBusinessConfig.getInstance().setEntryBookTransactionReportModelPath(path); - } - - public String getVatPDFUrl() { - return vatPDFUrl; - } - - public void setVatPDFUrl(String url) { - LimaBusinessConfig.getInstance().setVatPDFUrl(url); - } - } diff --git a/lima-business/src/main/java/org/chorem/lima/service/LimaServiceFactory.java b/lima-business/src/main/java/org/chorem/lima/service/LimaServiceFactory.java index ff72208..ab24e0b 100644 --- a/lima-business/src/main/java/org/chorem/lima/service/LimaServiceFactory.java +++ b/lima-business/src/main/java/org/chorem/lima/service/LimaServiceFactory.java @@ -27,6 +27,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.openejb.client.RemoteInitialContextFactory; +import org.apache.openejb.core.LocalInitialContextFactory; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.ServiceMonitorable; import org.nuiton.config.ApplicationConfig; @@ -70,7 +71,6 @@ public class LimaServiceFactory { * @param config configuration */ public static void initFactory(ApplicationConfig config) { - // make a copy of options Properties props = new Properties(); @@ -79,7 +79,9 @@ public class LimaServiceFactory { // only copy necessary options props.putAll(config.getOptionStartsWith("java.naming")); props.putAll(config.getOptionStartsWith("openejb")); - if (StringUtils.isNotBlank(config.getOption(Context.PROVIDER_URL))) { + if (StringUtils.isBlank(config.getOption(Context.PROVIDER_URL)) || Boolean.valueOf(config.getOption("openejb.embedded.remotable"))) { + props.put(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); + } else { props.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName()); } diff --git a/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java b/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java index 32593b3..90a0a97 100644 --- a/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java +++ b/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java @@ -160,7 +160,7 @@ public abstract class AbstractLimaTest { Properties testProperties = new Properties(); // override somes String testDir = System.getProperty("java.io.tmpdir") + File.separator + "lima-business-" + UUID.randomUUID().toString(); - testProperties.setProperty(LimaBusinessConfig.ServiceConfigOption.DATA_DIR.getKey(), testDir); +// testProperties.setProperty(LimaBusinessConfig.ServiceConfigOption.DATA_DIR.getKey(), testDir); testProperties.setProperty(Environment.URL, "jdbc:h2:file:" + testDir + File.separator + "data"); testProperties.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread"); testProperties.setProperty("topia.persistence.classes", LimaCallaoEntityEnum.getImplementationClassesAsString()); diff --git a/lima-report/pom.xml b/lima-report/pom.xml index 839f8f4..7e9b7f2 100644 --- a/lima-report/pom.xml +++ b/lima-report/pom.xml @@ -37,14 +37,14 @@ <artifactId>junit</artifactId> </dependency> <dependency> - <groupId>org.nuiton</groupId> - <artifactId>nuiton-utils</artifactId> - </dependency> - <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-config</artifactId> + </dependency> + <dependency> <groupId>org.nuiton.i18n</groupId> <artifactId>nuiton-i18n</artifactId> </dependency> @@ -52,14 +52,7 @@ <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </dependency> - <dependency> - <groupId>org.eclipse.jetty</groupId> - <artifactId>jetty-servlet</artifactId> - </dependency> - <dependency> - <groupId>org.eclipse.jetty</groupId> - <artifactId>jetty-server</artifactId> - </dependency> + <dependency> <groupId>net.sf.jasperreports</groupId> <artifactId>jasperreports</artifactId> @@ -83,21 +76,11 @@ <scope>runtime</scope> </dependency> <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <scope>compile</scope> - </dependency> - <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <scope>compile</scope> </dependency> <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-core</artifactId> - <scope>compile</scope> - </dependency> - <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <scope>provided</scope> diff --git a/lima-report/src/main/java/org/chorem/lima/report/action/ReportBuilder.java b/lima-report/src/main/java/org/chorem/lima/report/action/ReportBuilder.java index 1644306..de306cb 100644 --- a/lima-report/src/main/java/org/chorem/lima/report/action/ReportBuilder.java +++ b/lima-report/src/main/java/org/chorem/lima/report/action/ReportBuilder.java @@ -34,9 +34,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaTechnicalException; import org.chorem.lima.beans.DocumentReport; -import org.chorem.lima.business.LimaBusinessConfig; import org.chorem.lima.business.utils.DocumentReportTypes; import org.chorem.lima.business.utils.DocumentsEnum; +import org.chorem.lima.report.service.LimaReportConfig; import java.io.IOException; import java.io.InputStream; @@ -80,7 +80,7 @@ public class ReportBuilder { */ public ReportBuilder() { - LimaBusinessConfig config = LimaBusinessConfig.getInstance(); + LimaReportConfig config = LimaReportConfig.getInstance(); // compile phase balanceDocumentReport = createReport(config.getReportModelUrl(DocumentReportTypes.BALANCE)); diff --git a/lima-report/src/main/java/org/chorem/lima/report/service/DocumentService.java b/lima-report/src/main/java/org/chorem/lima/report/service/DocumentService.java index 961904b..6041b80 100644 --- a/lima-report/src/main/java/org/chorem/lima/report/service/DocumentService.java +++ b/lima-report/src/main/java/org/chorem/lima/report/service/DocumentService.java @@ -31,7 +31,6 @@ import org.chorem.lima.LimaTechnicalException; import org.chorem.lima.beans.DocumentReport; import org.chorem.lima.beans.FinancialStatementAmounts; import org.chorem.lima.beans.ReportsDatas; -import org.chorem.lima.business.LimaBusinessConfig; import org.chorem.lima.business.api.AccountService; import org.chorem.lima.business.api.ClosedPeriodicEntryBookService; import org.chorem.lima.business.api.EntryService; @@ -39,7 +38,6 @@ import org.chorem.lima.business.api.FinancialPeriodService; import org.chorem.lima.business.api.FinancialStatementService; import org.chorem.lima.business.api.IdentityService; import org.chorem.lima.business.api.ReportService; -import org.chorem.lima.business.api.VatStatementService; import org.chorem.lima.business.api.report.BalanceReportService; import org.chorem.lima.business.api.report.GeneralEntryBookReportService; import org.chorem.lima.business.api.report.LedgerReportService; @@ -48,9 +46,9 @@ import org.chorem.lima.business.utils.BigDecimalToString; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.Identity; -import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.report.action.ReportBuilder; import org.chorem.lima.report.utils.DocumentsEnum; +import org.chorem.lima.service.LimaServiceFactory; import javax.swing.*; import java.io.File; @@ -73,8 +71,6 @@ public class DocumentService { private ReportService reportService; - private VatStatementService vatStatementService; - protected BalanceReportService balanceReportService; protected GeneralEntryBookReportService generalEntryBookReportService; @@ -93,7 +89,7 @@ public class DocumentService { protected AccountService accountService; - protected String path = LimaBusinessConfig.getInstance().getReportsModelDir().getAbsolutePath(); + protected String path = LimaReportConfig.getInstance().getReportsModelDir().getAbsolutePath(); protected final String BALANCE_FILE_PATH = path + File.separator + DocumentsEnum.BALANCE.getFileName() + ".pdf"; protected final String GENERAL_ENTRY_BOOK_REPORT_PDF_FILE_PATH = path + File.separator + DocumentsEnum.GENERAL_ENTRY_BOOK.getFileName() + ".pdf"; @@ -104,7 +100,6 @@ public class DocumentService { identityService = LimaServiceFactory.getService(IdentityService.class); financialStatementService = LimaServiceFactory.getService(FinancialStatementService.class); reportService = LimaServiceFactory.getService(ReportService.class); - vatStatementService = LimaServiceFactory.getService(VatStatementService.class); closedPeriodicEntryBookService = LimaServiceFactory.getService(ClosedPeriodicEntryBookService.class); financialPeriodService = LimaServiceFactory.getService(FinancialPeriodService.class); entryService = LimaServiceFactory.getService(EntryService.class); diff --git a/lima-business/src/main/java/org/chorem/lima/business/LimaBusinessConfig.java b/lima-report/src/main/java/org/chorem/lima/report/service/LimaReportConfig.java similarity index 65% copy from lima-business/src/main/java/org/chorem/lima/business/LimaBusinessConfig.java copy to lima-report/src/main/java/org/chorem/lima/report/service/LimaReportConfig.java index 02876e8..5c97e3e 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/LimaBusinessConfig.java +++ b/lima-report/src/main/java/org/chorem/lima/report/service/LimaReportConfig.java @@ -1,90 +1,48 @@ -/* - * #%L - * Lima :: business - * %% - * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.business; +package org.chorem.lima.report.service; -import com.google.common.collect.Maps; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaTechnicalException; -import org.chorem.lima.business.accountingrules.FranceAccountingRules; import org.chorem.lima.business.utils.DocumentReportTypes; -import org.chorem.lima.entity.LimaCallaoEntityEnum; -import org.chorem.lima.entity.LimaFlywayServiceImpl; import org.nuiton.config.ApplicationConfig; import org.nuiton.config.ArgumentsParserException; import org.nuiton.config.ConfigOptionDef; -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; import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; /** - * Configuration pour le business. - * <p/> - * A voir comment le lier avec celui de lima swing. - * - * @author chatellier - * @version $Revision$ - * <p/> - * Last update : $Date$ - * By : $Author$ + * Created by davidcosse on 13/03/15. */ -public class LimaBusinessConfig { +public class LimaReportConfig { - protected static final Log log = LogFactory.getLog(LimaBusinessConfig.class); - - protected static AccountingRules accountingRules; + protected static final Log log = LogFactory.getLog(LimaReportConfig.class); protected ApplicationConfig config; - protected Properties rootContextProperties; - - protected static volatile LimaBusinessConfig instance; + protected static LimaReportConfig instance; - private LimaBusinessConfig(String configFileName) { + private LimaReportConfig(ApplicationConfig config) { try { ApplicationConfig defaultConfig = new ApplicationConfig(ServiceConfigOption.CONFIG_FILE.getDefaultValue()); defaultConfig.loadDefaultOptions(ServiceConfigOption.values()); defaultConfig.parse(); - if (StringUtils.isNotBlank(configFileName)) { + if (config != null) { Properties flatOptions = defaultConfig.getFlatOptions(false); - - config = new ApplicationConfig(flatOptions, configFileName); - config.parse(); + flatOptions.putAll(config.getFlatOptions()); + this.config = new ApplicationConfig(flatOptions); + this.config.parse(); } else { if (log.isWarnEnabled()) { log.warn("No specific configuration provided, using the default one"); } - config = defaultConfig; + this.config = defaultConfig; } instance = this; } catch (ArgumentsParserException ex) { @@ -92,111 +50,25 @@ public class LimaBusinessConfig { } } - protected static Properties getRootContextProperties() { - if (getInstance().rootContextProperties == null) { - Properties result = instance.getFlatOptions(); - // add persistence classes from generated code - result.setProperty(TopiaConfigurationConstants.CONFIG_PERSISTENCE_CLASSES, LimaCallaoEntityEnum.getImplementationClassesAsString()); - - Map<String, String> toAddIfNotPresent = Maps.newLinkedHashMap(); - toAddIfNotPresent.put("topia.service.migration", LimaFlywayServiceImpl.class.getName()); - toAddIfNotPresent.put("topia.service.migration." + TopiaFlywayService.USE_MODEL_VERSION, "true"); - toAddIfNotPresent.put(TopiaConfigurationConstants.CONFIG_PERSISTENCE_INIT_SCHEMA, "true"); - - for (Map.Entry<String, String> entry : toAddIfNotPresent.entrySet()) { - if (!result.containsKey(entry.getKey())) { - result.setProperty(entry.getKey(), entry.getValue()); - } - } - getInstance().setRootContextProperties(result); - - } - Properties result = getInstance().rootContextProperties; - return result; - } - - public void setRootContextProperties(Properties rootContextProperties) { - this.rootContextProperties = rootContextProperties; - } - - public synchronized static LimaBusinessConfig getInstance(String configFileName) { + public synchronized static LimaReportConfig getInstance(ApplicationConfig config) { if (instance == null) { - instance= new LimaBusinessConfig(configFileName); + instance= new LimaReportConfig(config); } return instance; } - public static LimaBusinessConfig getInstance() { - if (instance == null) { - instance= new LimaBusinessConfig(null); - } - return instance; - } - - public void setConfig(ApplicationConfig config) { - this.config = config; + public synchronized static LimaReportConfig getInstance() { + return getInstance(null); } public ApplicationConfig getConfig() { return config; } - /** - * Instancie la bonne classe de nationalite en fonction du fichier de configuration. - * - * L'instance est conservée en cache. - * - * @return l'instance de rule - */ - public AccountingRules getAccountingRules() { - - if (accountingRules == null) { - loadAccountingRules(); - } - - return accountingRules; - } - - protected static void loadAccountingRules() { - Class<?> accountingRulesClass = getInstance().config.getOptionAsClass(ServiceConfigOption.RULES_NATIONALTY.key); - if (accountingRulesClass == null) { - if (log.isErrorEnabled()) { - log.error("No accounting rules defined for:" + ServiceConfigOption.RULES_NATIONALTY.key); - } - accountingRules = new FranceAccountingRules(); - } else { - try { - accountingRules = (AccountingRules) accountingRulesClass.newInstance(); - } catch (Exception ex) { - if (log.isErrorEnabled()) { - log.error("Can't instantiate accounting rules", ex); - } - - } - } - } - public Properties getFlatOptions() { return config.getFlatOptions(); } - public String getConfigFile() { - return config.getOption(ServiceConfigOption.CONFIG_FILE.key); - } - - public void setConfigFile(String configFile) { - LimaBusinessConfig.getInstance().config.setOption(ServiceConfigOption.CONFIG_FILE.key, configFile); - } - - public String getApplicationVersion() { - return config.getOption(ServiceConfigOption.APPLICATION_VERSION.key); - } - - public void setAccountingRule(String accountingRule) { - LimaBusinessConfig.getInstance().config.setOption(ServiceConfigOption.RULES_NATIONALTY.key, accountingRule); - // clear cache - loadAccountingRules(); - } public File getDataDir() { File datadir = config.getOptionAsFile(ServiceConfigOption.DATA_DIR.getKey()); @@ -204,7 +76,7 @@ public class LimaBusinessConfig { } public String getAddressServer() { - String serverAddress = config.getOption(ServiceConfigOption.SERVER_ADRESS.getKey()); + String serverAddress = config.getOption(ServiceConfigOption.SERVER_ADDRESS.getKey()); return serverAddress; } @@ -214,16 +86,6 @@ public class LimaBusinessConfig { return port; } - public String getVatPDFUrl() { - String vatPDFUrl = config.getOption(ServiceConfigOption.VAT_PDF_URL.getKey()); - return vatPDFUrl; - } - - public void setVatPDFUrl(String url) { - config.setOption(ServiceConfigOption.VAT_PDF_URL.key, url); - config.saveForUser(); - } - // ** REPORT PART ** public File getReportsModelDir() { @@ -242,53 +104,40 @@ public class LimaBusinessConfig { return vatPDFUrl; } - public int getScale() { - return config.getOptionAsInt(ServiceConfigOption.SCALE.key); - } - - public void setScale(String locale) { - config.setOption(ServiceConfigOption.SCALE.key, locale); + public void setAccountReportModelPath(String path) { + config.setOption(ServiceConfigOption.ACCOUNT_DOCUMENT_REPORT_MODEL_PATH.key, path); config.saveForUser(); } - public boolean getCurrency() { - return config.getOptionAsBoolean(ServiceConfigOption.CURRENCY.key); - } - - public void setCurrency(String locale) { - config.setOption(ServiceConfigOption.CURRENCY.key, locale); - config.saveForUser(); - } + protected URL getReportModelUrl(String documentReportKey) { - public char getDecimalSeparator() { - char decimalSeparator = config.getOption(ServiceConfigOption.DECIMAL_SEPARATOR.key).charAt(0); - return decimalSeparator; - } + String optionValue = config.getOption(documentReportKey); + File file = new File(optionValue); - public void setDecimalSeparator(String locale) { - config.setOption(ServiceConfigOption.DECIMAL_SEPARATOR.key, locale); - config.saveForUser(); - } + 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); + } - public char getThousandSeparator() { - return config.getOption(ServiceConfigOption.THOUSAND_SEPARATOR.key).charAt(0); - } + if (result == null) { + throw new LimaTechnicalException(String.format("Could not find option: %s", documentReportKey)); + } - public void setThousandSeparator(String locale) { - config.setOption(ServiceConfigOption.THOUSAND_SEPARATOR.key, locale); - config.saveForUser(); - } + return result; - public void setAccountReportModelPath(String path) { - config.setOption(ServiceConfigOption.ACCOUNT_DOCUMENT_REPORT_MODEL_PATH.key, path); - config.saveForUser(); } public URL getReportModelUrl(DocumentReportTypes documentType) { URL mainReportBuilderPath = null; switch (documentType) { case ACCOUNT: - mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.ACCOUNT_DOCUMENT_REPORT_MODEL_PATH.key); + mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.ACCOUNT_DOCUMENT_REPORT_MODEL_PATH.getKey()); break; case BALANCE: @@ -337,30 +186,6 @@ public class LimaBusinessConfig { return mainReportBuilderPath; } - protected URL getReportModelUrl(String documentReportKey) { - - String optionValue = config.getOption(documentReportKey); - 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(String.format("Could not find option: %s", documentReportKey)); - } - - return result; - - } - public void setBalanceDocumentReportModelPath(String path) { config.setOption(ServiceConfigOption.BALANCE_DOCUMENT_REPORT_MODEL_PATH.key, path); config.saveForUser(); @@ -491,37 +316,14 @@ public class LimaBusinessConfig { config.saveForUser(); } - public String getHostAddress() { - String result = config.getOption(ServiceConfigOption. - LIMA_HOST_ADDRESS.getKey()); - return result; - } - - /** - * Lima option definition. - * <p/> - * Contains all lima configuration key, with defaut value and - * information for jaxx configuration frame ({@code #type}, - * {@code #transientBoolean}, {@code #finalBoolean}...) - */ public enum ServiceConfigOption implements ConfigOptionDef { - CONFIG_FILE(ApplicationConfig.CONFIG_FILE_NAME, n("lima.configFileName.description"), "lima-business.config", String.class, true, true), + CONFIG_FILE(ApplicationConfig.CONFIG_FILE_NAME, n("lima.configFileName.description"), "lima-report.config", String.class, true, true), - DB_DIALECT("hibernate.dialect","", "org.hibernate.dialect.H2Dialect", String.class, false, false), - DB_USER_NAME("hibernate.connection.username","", "sa", String.class, false, false), - DB_PASSWORD("hibernate.connection.password","", "", String.class, false, false), - DB_DRIVER("hibernate.connection.driver_class","", "org.h2.Driver", String.class, false, false), - DB_URL("hibernate.connection.url","", "jdbc:h2:file:${lima.data.dir}/limadb", String.class, false, false), - DB_BATCH_SIZE("hibernate.jdbc.batch_size","", "50", String.class, false, false), - - APPLICATION_VERSION("application.version", n("application.version"), null, String.class, false, false), DATA_DIR("lima.data.dir", n("lima.config.data.dir.description"), "${user.home}/.lima", File.class, false, false), - RULES_NATIONALTY("lima.rules", n("lima.config.rulesnationality.description"), FranceAccountingRules.class.getName(), String.class, false, false), HTTP_PORT("lima.httpport", n("lima.config.httpport.description"), "5462", String.class, false, false), - SERVER_ADRESS("lima.serveraddress", n("lima.config.serveraddress.description"), "localhost", String.class, false, false), - VAT_PDF_URL("lima.report.vatpdfurl", n("lima.config.reportvatpdfurl.description"), "default", String.class, false, false), + SERVER_ADDRESS("lima.serveraddress", n("lima.config.serveraddress.description"), "localhost", String.class, false, false), REPORTS_MODEL_DIR("lima.reports.dir",n("lima.config.reports.dir.description"),"${lima.data.dir}/reports", File.class, false, false), @@ -542,15 +344,7 @@ public class LimaBusinessConfig { GENERAL_LEDGER_DOCUMENT_REPORT_MODEL_PATH("lima.config.documentReport.generalLedger.documentReportModelPath", n("lima.config.documentReport.generalLedger.documentReportModelPath.description"), "/jasperreports/generalLedger/DocumentReport.jrxml", String.class, false, false), GENERAL_LEDGER_MODEL_PATH("lima.config.documentReport.generalLedger.generalLedgerModelPath", n("lima.config.documentReport.generalLedger.generalLedgerModelPath.description"), "/jasperreports/generalLedger/GeneralLedgerReport.jrxml", String.class, false, false), - GENERAL_LEDGER_ENTRY_MODEL_PATH("lima.config.documentReport.generalLedger.generalLedgerEntryModelPath", n("lima.config.documentReport.generalLedger.generalLedgerEntryModelPath.description"), "/jasperreports/generalLedger/GeneralLedgerEntryReport.jrxml", String.class, false, false), - - SCALE("lima.scale", n("lima.config.scale.description"), "2", String.class, false, false), - CURRENCY("lima.config.currency", "", "false", Boolean.class, false, false), - DECIMAL_SEPARATOR("lima.data.bigDecimal.decimalSeparator", "", ",", Character.class, false, false), - THOUSAND_SEPARATOR("lima.thousandSeparator", "", " ", Character.class, false, false), - - LIMA_HOST_ADDRESS("lima.host.address",n("lima.config.host.address.description"),"localhost",String.class, false, false); - + GENERAL_LEDGER_ENTRY_MODEL_PATH("lima.config.documentReport.generalLedger.generalLedgerEntryModelPath", n("lima.config.documentReport.generalLedger.generalLedgerEntryModelPath.description"), "/jasperreports/generalLedger/GeneralLedgerEntryReport.jrxml", String.class, false, false); private final String key; @@ -619,5 +413,4 @@ public class LimaBusinessConfig { return type; } } - } diff --git a/lima-report/src/main/resources/i18n/lima-report_en_GB.properties b/lima-report/src/main/resources/i18n/lima-report_en_GB.properties index 0ebeb1c..ff86347 100644 --- a/lima-report/src/main/resources/i18n/lima-report_en_GB.properties +++ b/lima-report/src/main/resources/i18n/lima-report_en_GB.properties @@ -1,3 +1,4 @@ +blima.config.documentReport.generalEntrybook.generalEntryBookEntryModelPath.description= lima-business.document.account= lima-business.document.address= lima-business.document.addressMore= @@ -25,6 +26,24 @@ lima-business.document.society= lima-business.document.vat= lima-business.document.vatnumber= lima-business.document.zipcode= +lima.config.data.dir.description= +lima.config.documentReport.account.documentReportModelPath.description= +lima.config.documentReport.balance.balanceAccountReportModelPath.description= +lima.config.documentReport.balance.balanceSubAccountReportModelPath.description= +lima.config.documentReport.balance.documentReportModelPath.description= +lima.config.documentReport.entrybook.documentReportModelPath.description= +lima.config.documentReport.entrybook.entryBookModelPath.description= +lima.config.documentReport.entrybook.financialPeriodModelPath.description= +lima.config.documentReport.entrybook.transactionReportModelPath.description= +lima.config.documentReport.generalEntrybook.documentReportModelPath.description= +lima.config.documentReport.generalEntrybook.generalEntryBookModelPath.description= +lima.config.documentReport.generalLedger.documentReportModelPath.description= +lima.config.documentReport.generalLedger.generalLedgerEntryModelPath.description= +lima.config.documentReport.generalLedger.generalLedgerModelPath.description= +lima.config.httpport.description= +lima.config.reports.dir.description= +lima.config.serveraddress.description= +lima.configFileName.description= lima.financialtransaction.account= lima.fiscalperiod.fiscalperiod= lima.reports.account.noAccount= diff --git a/lima-report/src/main/resources/i18n/lima-report_fr_FR.properties b/lima-report/src/main/resources/i18n/lima-report_fr_FR.properties index 0ebeb1c..ff86347 100644 --- a/lima-report/src/main/resources/i18n/lima-report_fr_FR.properties +++ b/lima-report/src/main/resources/i18n/lima-report_fr_FR.properties @@ -1,3 +1,4 @@ +blima.config.documentReport.generalEntrybook.generalEntryBookEntryModelPath.description= lima-business.document.account= lima-business.document.address= lima-business.document.addressMore= @@ -25,6 +26,24 @@ lima-business.document.society= lima-business.document.vat= lima-business.document.vatnumber= lima-business.document.zipcode= +lima.config.data.dir.description= +lima.config.documentReport.account.documentReportModelPath.description= +lima.config.documentReport.balance.balanceAccountReportModelPath.description= +lima.config.documentReport.balance.balanceSubAccountReportModelPath.description= +lima.config.documentReport.balance.documentReportModelPath.description= +lima.config.documentReport.entrybook.documentReportModelPath.description= +lima.config.documentReport.entrybook.entryBookModelPath.description= +lima.config.documentReport.entrybook.financialPeriodModelPath.description= +lima.config.documentReport.entrybook.transactionReportModelPath.description= +lima.config.documentReport.generalEntrybook.documentReportModelPath.description= +lima.config.documentReport.generalEntrybook.generalEntryBookModelPath.description= +lima.config.documentReport.generalLedger.documentReportModelPath.description= +lima.config.documentReport.generalLedger.generalLedgerEntryModelPath.description= +lima.config.documentReport.generalLedger.generalLedgerModelPath.description= +lima.config.httpport.description= +lima.config.reports.dir.description= +lima.config.serveraddress.description= +lima.configFileName.description= lima.financialtransaction.account= lima.fiscalperiod.fiscalperiod= lima.reports.account.noAccount= diff --git a/lima-server/pom.xml b/lima-server/pom.xml index 27e8f7c..cbbab27 100644 --- a/lima-server/pom.xml +++ b/lima-server/pom.xml @@ -62,6 +62,15 @@ <version>${project.version}</version> <scope>compile</scope> </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-servlet</artifactId> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-server</artifactId> + </dependency> + <!-- for remote mode only --> <dependency> @@ -82,6 +91,53 @@ <scope>runtime</scope> </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-core</artifactId> + </dependency> + + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + </dependency> + + <dependency> + <groupId>org.nuiton.i18n</groupId> + <artifactId>nuiton-i18n</artifactId> + </dependency> + + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-utils</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.openejb</groupId> + <artifactId>openejb-core</artifactId> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-config</artifactId> + </dependency> + </dependencies> <build> diff --git a/lima-server/src/main/java/org.chorem.lima/LimaServer.java b/lima-server/src/main/java/org.chorem.lima/LimaServer.java index aa93b26..ed697cd 100644 --- a/lima-server/src/main/java/org.chorem.lima/LimaServer.java +++ b/lima-server/src/main/java/org.chorem.lima/LimaServer.java @@ -22,10 +22,13 @@ package org.chorem.lima; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.openejb.core.LocalInitialContextFactory; -import org.chorem.lima.report.service.HttpServerService; +import org.chorem.lima.business.LimaBusinessConfig; +import org.chorem.lima.report.service.LimaReportConfig; +import org.chorem.lima.server.HttpServerService; +import org.chorem.lima.server.LimaServerConfig; import org.chorem.lima.service.LimaServiceFactory; import org.nuiton.config.ApplicationConfig; @@ -59,21 +62,19 @@ public class LimaServer { */ public static void main(String... args) throws NamingException { - Properties properties = new Properties(); - properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName()); - properties.setProperty("openejb.embedded.remotable", "true"); - // Uncomment these properties to change the defaults - //properties.setProperty("ejbd.port", "4202"); - properties.setProperty("ejbd.bind", "0.0.0.0"); - //properties.setProperty("ejbd.threads", "200"); - //properties.setProperty("ejbd.disabled", "false"); - //properties.setProperty("ejbd.only_from", "127.0.0.1,192.168.1.1"); + String accountabilityName = null; + if (args!= null && args.length > 0 && StringUtils.isNotBlank(args[0])) { + accountabilityName = args[0]; + } + + LimaServerConfig serverConfig = LimaServerConfig.getInstance(accountabilityName); + + Properties properties = serverConfig.getFlatOptions(); + properties.put("openejb.embedded.remotable", "true"); - ApplicationConfig config = new ApplicationConfig(); - config.setOptions(properties); - LimaServiceFactory.initFactory(config); + launch(serverConfig.getConfig()); - getHttpServerService(); + LimaServerConfig.getInstance().getConfig().saveForUser(); // block main otherwize, main will end synchronized (properties) { @@ -89,10 +90,26 @@ public class LimaServer { } } - public static HttpServerService getHttpServerService() { - if (httpServerService == null) { + public static void launch(ApplicationConfig config) { + + // push all configs + LimaServerConfig.getInstance(config); + ApplicationConfig serverConfig = LimaServerConfig.getInstance().getConfig(); + LimaBusinessConfig.getInstance(serverConfig); + ApplicationConfig businessConfig = LimaBusinessConfig.getInstance().getConfig(); + LimaReportConfig.getInstance(businessConfig); + + // start EJB container + LimaServiceFactory.initFactory(businessConfig); + + // start web server only if it's on server mode + if (StringUtils.isBlank(businessConfig.getOption(Context.PROVIDER_URL)) || Boolean.valueOf(serverConfig.getOption("openejb.embedded.remotable"))) { httpServerService = new HttpServerService(); + httpServerService.start(); } + } + + public static HttpServerService getHttpServerService() { return httpServerService; } } diff --git a/lima-report/src/main/java/org/chorem/lima/report/service/HttpServerService.java b/lima-server/src/main/java/org.chorem.lima/server/HttpServerService.java similarity index 94% rename from lima-report/src/main/java/org/chorem/lima/report/service/HttpServerService.java rename to lima-server/src/main/java/org.chorem.lima/server/HttpServerService.java index a1e3486..f74c21f 100644 --- a/lima-report/src/main/java/org/chorem/lima/report/service/HttpServerService.java +++ b/lima-server/src/main/java/org.chorem.lima/server/HttpServerService.java @@ -1,4 +1,4 @@ -package org.chorem.lima.report.service; +package org.chorem.lima.server; /* * #%L @@ -28,13 +28,13 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.LimaBusinessConfig; import org.chorem.lima.business.api.AccountService; import org.chorem.lima.business.utils.DocumentsEnum; import org.chorem.lima.business.utils.FormatsEnum; import org.chorem.lima.entity.Account; -import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.report.action.ReportBuilder; +import org.chorem.lima.report.service.DocumentService; +import org.chorem.lima.service.LimaServiceFactory; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; @@ -79,9 +79,8 @@ public class HttpServerService { protected ReportBuilder reportBuilder; public HttpServerService() { - //File reportDir = (File) props.get("REPORTS_MODEL_DIR"); - //path = reportDir.getAbsolutePath(); - port = LimaBusinessConfig.getInstance().getHttpPort(); + + port = LimaServerConfig.getInstance().getHttpPort(); accountService = LimaServiceFactory.getService(AccountService.class); documentService = new DocumentService(); reportBuilder = new ReportBuilder(); @@ -91,8 +90,7 @@ public class HttpServerService { public void start() { if (server == null) { try { - LimaBusinessConfig config = LimaBusinessConfig.getInstance(); - File reportDir = config.getReportsModelDir(); + File reportDir = LimaServerConfig.getInstance().getReportsModelDir(); FileUtil.createDirectoryIfNecessary(reportDir); @@ -124,7 +122,7 @@ public class HttpServerService { public class MainServlet extends HttpServlet { private static final long serialVersionUID = 1L; - private String serverAddressConfig = LimaBusinessConfig.getInstance().getAddressServer(); + private String serverAddressConfig = LimaServerConfig.getInstance().getAddressServer(); @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { @@ -198,8 +196,7 @@ public class HttpServerService { } IOUtils.write(report, out, Charsets.UTF_8); } else { - LimaBusinessConfig config = LimaBusinessConfig.getInstance(); - File reportDir = config.getReportsModelDir(); + File reportDir = LimaServerConfig.getInstance().getReportsModelDir(); String path = reportDir.getAbsolutePath(); URL doc = new URL("file:" + path + File.separator + model + ".pdf"); if (log.isDebugEnabled()) { @@ -226,11 +223,9 @@ public class HttpServerService { /** create server Address : static config if exist or dynamical adress */ if (serverAddressConfig.equals("")) { - serverAddress += req.getServerName() - + ":" + req.getServerPort(); + serverAddress += req.getServerName() + ":" + req.getServerPort(); } else { - serverAddress += serverAddressConfig + ":" - + LimaBusinessConfig.getInstance().getHttpPort(); + serverAddress += serverAddressConfig + ":" + getHttpPort(); } Calendar calendar = Calendar.getInstance(); diff --git a/lima-business/src/main/java/org/chorem/lima/business/LimaBusinessConfig.java b/lima-server/src/main/java/org.chorem.lima/server/LimaServerConfig.java similarity index 75% copy from lima-business/src/main/java/org/chorem/lima/business/LimaBusinessConfig.java copy to lima-server/src/main/java/org.chorem.lima/server/LimaServerConfig.java index 02876e8..5c6dbb3 100644 --- a/lima-business/src/main/java/org/chorem/lima/business/LimaBusinessConfig.java +++ b/lima-server/src/main/java/org.chorem.lima/server/LimaServerConfig.java @@ -1,75 +1,37 @@ -/* - * #%L - * Lima :: business - * %% - * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.business; +package org.chorem.lima.server; -import com.google.common.collect.Maps; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.openejb.core.LocalInitialContextFactory; import org.chorem.lima.LimaTechnicalException; import org.chorem.lima.business.accountingrules.FranceAccountingRules; import org.chorem.lima.business.utils.DocumentReportTypes; -import org.chorem.lima.entity.LimaCallaoEntityEnum; -import org.chorem.lima.entity.LimaFlywayServiceImpl; import org.nuiton.config.ApplicationConfig; import org.nuiton.config.ArgumentsParserException; import org.nuiton.config.ConfigOptionDef; -import org.nuiton.topia.flyway.TopiaFlywayService; -import org.nuiton.topia.persistence.TopiaConfigurationConstants; +import javax.naming.Context; import java.io.File; import java.net.MalformedURLException; import java.net.URL; -import java.util.Map; import java.util.Properties; import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; /** - * Configuration pour le business. - * <p/> - * A voir comment le lier avec celui de lima swing. - * - * @author chatellier - * @version $Revision$ - * <p/> - * Last update : $Date$ - * By : $Author$ + * Created by davidcosse on 13/03/15. */ -public class LimaBusinessConfig { +public class LimaServerConfig { - protected static final Log log = LogFactory.getLog(LimaBusinessConfig.class); - - protected static AccountingRules accountingRules; + protected static final Log log = LogFactory.getLog(LimaServerConfig.class); protected ApplicationConfig config; - protected Properties rootContextProperties; - - protected static volatile LimaBusinessConfig instance; + protected static LimaServerConfig instance; - private LimaBusinessConfig(String configFileName) { + private LimaServerConfig(String configFileName) { try { ApplicationConfig defaultConfig = new ApplicationConfig(ServiceConfigOption.CONFIG_FILE.getDefaultValue()); defaultConfig.loadDefaultOptions(ServiceConfigOption.values()); @@ -85,6 +47,7 @@ public class LimaBusinessConfig { log.warn("No specific configuration provided, using the default one"); } config = defaultConfig; + } instance = this; } catch (ArgumentsParserException ex) { @@ -92,115 +55,59 @@ public class LimaBusinessConfig { } } - protected static Properties getRootContextProperties() { - if (getInstance().rootContextProperties == null) { - Properties result = instance.getFlatOptions(); - // add persistence classes from generated code - result.setProperty(TopiaConfigurationConstants.CONFIG_PERSISTENCE_CLASSES, LimaCallaoEntityEnum.getImplementationClassesAsString()); - - Map<String, String> toAddIfNotPresent = Maps.newLinkedHashMap(); - toAddIfNotPresent.put("topia.service.migration", LimaFlywayServiceImpl.class.getName()); - toAddIfNotPresent.put("topia.service.migration." + TopiaFlywayService.USE_MODEL_VERSION, "true"); - toAddIfNotPresent.put(TopiaConfigurationConstants.CONFIG_PERSISTENCE_INIT_SCHEMA, "true"); + private LimaServerConfig(final ApplicationConfig config) { + try { + ApplicationConfig defaultConfig = new ApplicationConfig(ServiceConfigOption.CONFIG_FILE.getDefaultValue()); + defaultConfig.loadDefaultOptions(ServiceConfigOption.values()); + defaultConfig.parse(); - for (Map.Entry<String, String> entry : toAddIfNotPresent.entrySet()) { - if (!result.containsKey(entry.getKey())) { - result.setProperty(entry.getKey(), entry.getValue()); + if (config != null) { + Properties flatOptions = defaultConfig.getFlatOptions(); + flatOptions.putAll(config.getFlatOptions(true)); + this.config = new ApplicationConfig(flatOptions, ServiceConfigOption.CONFIG_FILE.getDefaultValue()); + this.config.parse(); + } else { + if (log.isWarnEnabled()) { + log.warn("No specific configuration provided, using the default one"); } + this.config = defaultConfig; } - getInstance().setRootContextProperties(result); - + instance = this; + } catch (ArgumentsParserException ex) { + throw new LimaTechnicalException("Can't read configuration", ex); } - Properties result = getInstance().rootContextProperties; - return result; } - public void setRootContextProperties(Properties rootContextProperties) { - this.rootContextProperties = rootContextProperties; - } - - public synchronized static LimaBusinessConfig getInstance(String configFileName) { + public synchronized static LimaServerConfig getInstance(String configFileName) { if (instance == null) { - instance= new LimaBusinessConfig(configFileName); + instance= new LimaServerConfig(configFileName); } return instance; } - public static LimaBusinessConfig getInstance() { + public synchronized static LimaServerConfig getInstance(ApplicationConfig config) { if (instance == null) { - instance= new LimaBusinessConfig(null); + instance= new LimaServerConfig(config); } return instance; } - public void setConfig(ApplicationConfig config) { - this.config = config; + public synchronized static LimaServerConfig getInstance() { + return getInstance(""); } public ApplicationConfig getConfig() { return config; } - /** - * Instancie la bonne classe de nationalite en fonction du fichier de configuration. - * - * L'instance est conservée en cache. - * - * @return l'instance de rule - */ - public AccountingRules getAccountingRules() { - - if (accountingRules == null) { - loadAccountingRules(); - } - - return accountingRules; - } - - protected static void loadAccountingRules() { - Class<?> accountingRulesClass = getInstance().config.getOptionAsClass(ServiceConfigOption.RULES_NATIONALTY.key); - if (accountingRulesClass == null) { - if (log.isErrorEnabled()) { - log.error("No accounting rules defined for:" + ServiceConfigOption.RULES_NATIONALTY.key); - } - accountingRules = new FranceAccountingRules(); - } else { - try { - accountingRules = (AccountingRules) accountingRulesClass.newInstance(); - } catch (Exception ex) { - if (log.isErrorEnabled()) { - log.error("Can't instantiate accounting rules", ex); - } - - } - } - } - public Properties getFlatOptions() { return config.getFlatOptions(); } - public String getConfigFile() { - return config.getOption(ServiceConfigOption.CONFIG_FILE.key); - } - - public void setConfigFile(String configFile) { - LimaBusinessConfig.getInstance().config.setOption(ServiceConfigOption.CONFIG_FILE.key, configFile); - } - - public String getApplicationVersion() { - return config.getOption(ServiceConfigOption.APPLICATION_VERSION.key); - } - - public void setAccountingRule(String accountingRule) { - LimaBusinessConfig.getInstance().config.setOption(ServiceConfigOption.RULES_NATIONALTY.key, accountingRule); - // clear cache - loadAccountingRules(); - } public File getDataDir() { - File datadir = config.getOptionAsFile(ServiceConfigOption.DATA_DIR.getKey()); - return datadir; + File dataDir = config.getOptionAsFile(ServiceConfigOption.DATA_DIR.getKey()); + return dataDir; } public String getAddressServer() { @@ -208,12 +115,22 @@ public class LimaBusinessConfig { return serverAddress; } + public void setAddressServer(String serverAddress) { + config.setOption(ServiceConfigOption.SERVER_ADRESS.key, serverAddress); + config.saveForUser(); + } + public int getHttpPort() { String httpPort = config.getOption(ServiceConfigOption.HTTP_PORT.getKey()); Integer port = Integer.valueOf(httpPort); return port; } + public void setHttpPort(int port) { + config.setOption(ServiceConfigOption.HTTP_PORT.key, String.valueOf(port)); + config.saveForUser(); + } + public String getVatPDFUrl() { String vatPDFUrl = config.getOption(ServiceConfigOption.VAT_PDF_URL.getKey()); return vatPDFUrl; @@ -242,53 +159,40 @@ public class LimaBusinessConfig { return vatPDFUrl; } - public int getScale() { - return config.getOptionAsInt(ServiceConfigOption.SCALE.key); - } - - public void setScale(String locale) { - config.setOption(ServiceConfigOption.SCALE.key, locale); + public void setAccountReportModelPath(String path) { + config.setOption(ServiceConfigOption.ACCOUNT_DOCUMENT_REPORT_MODEL_PATH.key, path); config.saveForUser(); } - public boolean getCurrency() { - return config.getOptionAsBoolean(ServiceConfigOption.CURRENCY.key); - } - - public void setCurrency(String locale) { - config.setOption(ServiceConfigOption.CURRENCY.key, locale); - config.saveForUser(); - } + protected URL getReportModelUrl(String documentReportKey) { - public char getDecimalSeparator() { - char decimalSeparator = config.getOption(ServiceConfigOption.DECIMAL_SEPARATOR.key).charAt(0); - return decimalSeparator; - } + String optionValue = config.getOption(documentReportKey); + File file = new File(optionValue); - public void setDecimalSeparator(String locale) { - config.setOption(ServiceConfigOption.DECIMAL_SEPARATOR.key, locale); - config.saveForUser(); - } + 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); + } - public char getThousandSeparator() { - return config.getOption(ServiceConfigOption.THOUSAND_SEPARATOR.key).charAt(0); - } + if (result == null) { + throw new LimaTechnicalException(String.format("Could not find option: %s", documentReportKey)); + } - public void setThousandSeparator(String locale) { - config.setOption(ServiceConfigOption.THOUSAND_SEPARATOR.key, locale); - config.saveForUser(); - } + return result; - public void setAccountReportModelPath(String path) { - config.setOption(ServiceConfigOption.ACCOUNT_DOCUMENT_REPORT_MODEL_PATH.key, path); - config.saveForUser(); } public URL getReportModelUrl(DocumentReportTypes documentType) { URL mainReportBuilderPath = null; switch (documentType) { case ACCOUNT: - mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.ACCOUNT_DOCUMENT_REPORT_MODEL_PATH.key); + mainReportBuilderPath = getReportModelUrl(ServiceConfigOption.ACCOUNT_DOCUMENT_REPORT_MODEL_PATH.getKey()); break; case BALANCE: @@ -337,30 +241,6 @@ public class LimaBusinessConfig { return mainReportBuilderPath; } - protected URL getReportModelUrl(String documentReportKey) { - - String optionValue = config.getOption(documentReportKey); - 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(String.format("Could not find option: %s", documentReportKey)); - } - - return result; - - } - public void setBalanceDocumentReportModelPath(String path) { config.setOption(ServiceConfigOption.BALANCE_DOCUMENT_REPORT_MODEL_PATH.key, path); config.saveForUser(); @@ -497,17 +377,14 @@ public class LimaBusinessConfig { return result; } - - /** - * Lima option definition. - * <p/> - * Contains all lima configuration key, with defaut value and - * information for jaxx configuration frame ({@code #type}, - * {@code #transientBoolean}, {@code #finalBoolean}...) - */ public enum ServiceConfigOption implements ConfigOptionDef { - CONFIG_FILE(ApplicationConfig.CONFIG_FILE_NAME, n("lima.configFileName.description"), "lima-business.config", String.class, true, true), + EJB_INITIAL_CONTEXT_FACTORY(Context.INITIAL_CONTEXT_FACTORY, "", LocalInitialContextFactory.class.getName(), String.class, false, true), + EJB_REMOTABLE("openejb.embedded.remotable", "", "true", String.class, false, true), + EJB_PORT("ejbd.port", "", "4202", String.class, false, false), + EJB_BIND("ejbd.bind", "", "0.0.0.0", String.class, false, false), + + CONFIG_FILE(ApplicationConfig.CONFIG_FILE_NAME, n("lima.configFileName.description"), "lima-server.config", String.class, true, true), DB_DIALECT("hibernate.dialect","", "org.hibernate.dialect.H2Dialect", String.class, false, false), DB_USER_NAME("hibernate.connection.username","", "sa", String.class, false, false), @@ -619,5 +496,4 @@ public class LimaBusinessConfig { return type; } } - } diff --git a/lima-swing/pom.xml b/lima-swing/pom.xml index 1068052..d5e5412 100644 --- a/lima-swing/pom.xml +++ b/lima-swing/pom.xml @@ -46,25 +46,25 @@ <dependencies> <dependency> <groupId>${project.groupId}</groupId> - <artifactId>lima-business-api</artifactId> + <artifactId>lima-server</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>${project.groupId}</groupId> - <artifactId>lima-web</artifactId> + <artifactId>lima-business</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>${project.groupId}</groupId> - <artifactId>lima-callao</artifactId> + <artifactId>lima-business-api</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>${project.groupId}</groupId> - <artifactId>lima-report</artifactId> + <artifactId>lima-callao</artifactId> <version>${project.version}</version> <scope>compile</scope> </dependency> diff --git a/lima-swing/src/main/java/org/chorem/lima/LimaMain.java b/lima-swing/src/main/java/org/chorem/lima/LimaMain.java index 4d0a194..737acd3 100644 --- a/lima-swing/src/main/java/org/chorem/lima/LimaMain.java +++ b/lima-swing/src/main/java/org/chorem/lima/LimaMain.java @@ -25,9 +25,7 @@ package org.chorem.lima; import jaxx.runtime.SwingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.LimaBusinessConfig; import org.chorem.lima.business.api.AccountService; -import org.chorem.lima.report.service.HttpServerService; import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.ui.MainView; import org.chorem.lima.ui.MainViewHandler; @@ -56,9 +54,6 @@ public class LimaMain { /** splash */ protected static LimaSplash splash; - /** http serveur */ - protected static HttpServerService httpServerService; - /** * Lima main method. * @@ -134,7 +129,9 @@ public class LimaMain { splash.drawVersion(config.getVersion()); splash.updateProgression(0.1, t("lima.launch.services")); - LimaServiceFactory.initFactory(config); + + LimaServer.launch(config); + LimaSwingConfig.getInstance().saveForUser("topia.persistence.classes"); // load accounts and test if there is an account plan defined // if not, call #loadDefaultAccount() @@ -154,9 +151,6 @@ public class LimaMain { splash.updateProgression(0.7, t("lima.launch.webServer")); - //start http server - getHttpServerService().start(); - splash.updateProgression(1, t("lima.launch.finished")); // do init ui @@ -201,32 +195,4 @@ public class LimaMain { } } - public static HttpServerService getHttpServerService() { - if (httpServerService == null) { - LimaBusinessConfig serviceConfig = LimaBusinessConfig.getInstance(); - LimaSwingConfig swingConfig = LimaSwingConfig.getInstance(); - - // TODO DCossé 02/03/15 Ceci ne devrait pas être fait ainsi - // ici sont poussés côté service les chemins vers les fichiers source JASPER nécessaires à la compilation des rapports - // la configuration est pourssée dans les service afin de pouvoir être récupérée par la partie web ! - // dans la partie web ce fait la création (graphique) des rapports à partir des données remontées par la partie service. - serviceConfig.setBalanceDocumentReportModelPath(swingConfig.getBalanceDocumentReportModelPath()); - serviceConfig.setReportsModelDir(swingConfig.getReportsDir().getAbsolutePath()); - serviceConfig.setAccountReportModelPath(swingConfig.getAccountDocumentReportModelPath()); - serviceConfig.setBalanceDocumentReportModelPath(swingConfig.getBalanceDocumentReportModelPath()); - serviceConfig.setBalanceAccountReportModelPath(swingConfig.getBalanceAccountReportModelPath()); - serviceConfig.setBalanceSubAccountReportModelPath(swingConfig.getBalanceSubAccountReportModelPath()); - serviceConfig.setGeneralEntryBookDocumentReportModelPath(swingConfig.getGeneralEntryBookDocumentReportModelPath()); - serviceConfig.setGeneralEntryBookEntryReportModelPath(swingConfig.getGeneralEntryBookGeneralEntryBookEntryReportPath()); - serviceConfig.setEntryBookDocumentReportModelPath(swingConfig.getProvisionalEntryBookEntryBookMainReportPath()); - serviceConfig.setEntryBookEntryBookReportModelPath(swingConfig.getProvisionalEntryBookEntryBookReportPath()); - serviceConfig.setEntryBookFinancialPeriodReportModelPath(swingConfig.getProvisionalEntryBookFinancialPeriodReportPath()); - serviceConfig.setEntryBookTransactionReportModelPath(swingConfig.getProvisionalEntryBookTransactionReportPath()); - - - httpServerService = new HttpServerService(); - } - return httpServerService; - } - } diff --git a/lima-swing/src/main/java/org/chorem/lima/LimaSwingApplicationContext.java b/lima-swing/src/main/java/org/chorem/lima/LimaSwingApplicationContext.java index 54566a7..4e3cdb0 100644 --- a/lima-swing/src/main/java/org/chorem/lima/LimaSwingApplicationContext.java +++ b/lima-swing/src/main/java/org/chorem/lima/LimaSwingApplicationContext.java @@ -27,7 +27,6 @@ import jaxx.runtime.context.DefaultApplicationContext; import jaxx.runtime.context.JAXXContextEntryDef; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.LimaBusinessConfig; import org.chorem.lima.ui.LimaDecoratorProvider; import org.chorem.lima.ui.MainView; import org.chorem.lima.ui.MainViewHandler; @@ -82,14 +81,9 @@ public class LimaSwingApplicationContext extends DefaultApplicationContext { instance.setContextValue(new MainViewHandler()); CONFIG_DEF.setContextValue(instance, LimaSwingConfig.getInstance()); DECORATOR_PROVIDER_DEF.setContextValue(instance, new LimaDecoratorProvider()); - initApplicationContext(); return instance; } - protected static void initApplicationContext() { - LimaBusinessConfig.getInstance(LimaSwingConfig.Option.CONFIG_FILE.getDefaultValue()); - } - /** * Récupération du contexte applicatif. * 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 4a77292..e635bd5 100644 --- a/lima-swing/src/main/java/org/chorem/lima/LimaSwingConfig.java +++ b/lima-swing/src/main/java/org/chorem/lima/LimaSwingConfig.java @@ -305,10 +305,15 @@ public class LimaSwingConfig extends ApplicationConfig { * @return {@code true} if remote mode should be used */ public boolean isEJBRemoteMode() { - boolean result = getOptionAsBoolean(Option.OPENEJB_REMOTE_MODE.key); + boolean result = getOptionAsBoolean(Option.OPEN_EJB_REMOTE_MODE.key); return result; } + public void setEJBRemoteMode(boolean isRemotable) { + setOption(Option.OPEN_EJB_REMOTE_MODE.key, String.valueOf(isRemotable)); + saveForUser(); + } + public File getDataDirectory() { File result = getOptionAsFile(Option.DATA_DIR.key); return result; @@ -507,17 +512,12 @@ public class LimaSwingConfig extends ApplicationConfig { "support@codelutin.com", String.class, false, false), - OPENEJB_REMOTE_MODE("lima.openEjb.remote.mode", + OPEN_EJB_REMOTE_MODE("openejb.embedded.remotable", t("lima.openEjb.remote.mode.label"), n("lima.openEjb.remote.mode.description"), "false", String.class, false, false), - OPENEJB_EXCLUDE_INCLUDE("openejb.exclude-include.order", "open_EJB_include-exclude_order","open_EJB_include-exclude_order", "include-exclude", String.class, false, false), - OPENEJB_INCLUDE("openejb.deployments.classpath.include", "open_EJB_include","open_EJB_include", "", String.class, false, false), - OPENEJB_EXCLUDE("openejb.deployments.classpath.exclude", "open_EJB_exclude","open_EJB_exclude", ".*", String.class, false, false), - OPENEJB_DEPLOYMENTS_CLASSPATH_EAR("openejb.deployments.classpath.ear", "openejb.deployments.classpath.ear", "openejb.deployments.classpath.ear", "false", String.class, false, false), - LIMA_HOST_ADDRESS("lima.host.address", t("lima.config.host.address.label"), n("lima.config.host.address.description"), diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java b/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java index ff0a87a..5ac4ab1 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java @@ -27,11 +27,10 @@ import jaxx.runtime.swing.AboutPanel; import jaxx.runtime.swing.config.ConfigUIHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.LimaMain; import org.chorem.lima.LimaSwingApplicationContext; import org.chorem.lima.LimaSwingConfig; -import org.chorem.lima.business.LimaBusinessConfig; import org.chorem.lima.enums.ImportExportEnum; +import org.chorem.lima.server.LimaServerConfig; import org.chorem.lima.ui.account.AccountView; import org.chorem.lima.ui.celleditor.NumberSeparatorCellRenderer; import org.chorem.lima.ui.celleditor.NumberSeparatorTableCellRenderer; @@ -488,8 +487,8 @@ public class MainViewHandler { } public void loadURI(MainView ui) { - int port = LimaMain.getHttpServerService().getHttpPort(); - String address = LimaBusinessConfig.getInstance().getHostAddress(); + int port = LimaServerConfig.getInstance().getHttpPort(); + String address = LimaServerConfig.getInstance().getHostAddress(); String url = "http://" + address + ":" + port + "/"; if (log.isDebugEnabled()) { diff --git a/lima-swing/src/test/java/org/chorem/lima/ui/AbstractLimaTest.java b/lima-swing/src/test/java/org/chorem/lima/ui/AbstractLimaTest.java index 3bae008..4cf5ad1 100644 --- a/lima-swing/src/test/java/org/chorem/lima/ui/AbstractLimaTest.java +++ b/lima-swing/src/test/java/org/chorem/lima/ui/AbstractLimaTest.java @@ -43,6 +43,7 @@ import org.chorem.lima.entity.AccountTopiaDao; import org.chorem.lima.entity.LimaCallaoEntityEnum; import org.chorem.lima.entity.LimaCallaoTopiaApplicationContext; import org.chorem.lima.entity.LimaCallaoTopiaPersistenceContext; +import org.chorem.lima.server.LimaServerConfig; import org.chorem.lima.service.LimaServiceFactory; import org.hibernate.cfg.Environment; import org.junit.Before; @@ -149,7 +150,7 @@ public abstract class AbstractLimaTest { Properties testProperties = new Properties(); // override somes String testDir = System.getProperty("java.io.tmpdir") + File.separator + "lima-business-" + UUID.randomUUID().toString(); - testProperties.setProperty(LimaBusinessConfig.ServiceConfigOption.DATA_DIR.getKey(), testDir); + testProperties.setProperty(LimaServerConfig.ServiceConfigOption.DATA_DIR.getKey(), testDir); testProperties.setProperty(Environment.URL, "jdbc:h2:file:" + testDir + File.separator + "data"); testProperties.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread"); testProperties.setProperty("topia.persistence.classes", LimaCallaoEntityEnum.getImplementationClassesAsString()); diff --git a/pom.xml b/pom.xml index 5c2cfa0..179797c 100644 --- a/pom.xml +++ b/pom.xml @@ -141,7 +141,6 @@ <module>lima-report</module> <module>lima-server</module> <module>lima-swing</module> - </modules> <scm> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm