r3185 - in trunk: lima-business/src/main/java/org/chorem/lima/business lima-business/src/main/java/org/chorem/lima/business/ejb lima-business/src/main/java/org/chorem/lima/business/ejbinterface lima-business/src/main/resources/i18n lima-swing/src/main/java/org/chorem/lima
Author: vsalaun Date: 2011-06-27 18:31:06 +0200 (Mon, 27 Jun 2011) New Revision: 3185 Url: http://chorem.org/repositories/revision/lima/3185 Log: add OptionsService in order to use some swing config on business config Added: trunk/lima-business/src/main/java/org/chorem/lima/business/OptionsServiceMonitorable.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/OptionsServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/OptionsService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/OptionsServiceLocal.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties trunk/lima-swing/src/main/java/org/chorem/lima/LimaConfig.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java 2011-06-17 15:32:15 UTC (rev 3184) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java 2011-06-27 16:31:06 UTC (rev 3185) @@ -119,6 +119,16 @@ Integer port = Integer.valueOf(httpPort); return port; } + + public String getScale() { + String scale = getOption(Option.SCALE.getKey()); + return scale; + } + + public void setScale(String locale) { + setOption(Option.SCALE.key, locale); + saveForUser(); + } /** * Load configuration with custom file name. @@ -150,7 +160,8 @@ RULES_NATIONALTY("lima.rules", _("lima.config.rulesnationality"), "default", String.class, false, false), REPORTS_DIR("lima.report.dir", _("lima.config.reportsdir"), "", String.class, false, false), HTTP_PORT("lima.httpport", _("lima.config.httpport"), "5462", String.class, false, false), - SERVER_ADRESS("lima.serveraddress", _("lima.config.serveraddress"), "", String.class, false, false); + SERVER_ADRESS("lima.serveraddress", _("lima.config.serveraddress"), "", String.class, false, false), + SCALE("lima.scale", _("lima.config.scale"), "2", String.class, false, false); private final String key; private final String description; Added: trunk/lima-business/src/main/java/org/chorem/lima/business/OptionsServiceMonitorable.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/OptionsServiceMonitorable.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/OptionsServiceMonitorable.java 2011-06-27 16:31:06 UTC (rev 3185) @@ -0,0 +1,7 @@ +package org.chorem.lima.business; + +import org.chorem.lima.business.ejbinterface.OptionsService; + +public interface OptionsServiceMonitorable extends OptionsService, ServiceMonitorable { + +} Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2011-06-17 15:32:15 UTC (rev 3184) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2011-06-27 16:31:06 UTC (rev 3185) @@ -52,6 +52,7 @@ import org.chorem.lima.business.ejbinterface.FinancialTransactionService; import org.chorem.lima.business.ejbinterface.FinancialTransactionServiceLocal; import org.chorem.lima.business.ejbinterface.ReportService; +import org.chorem.lima.business.ejbinterface.OptionsService; import org.chorem.lima.business.utils.FinancialPeriodComparator; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountDAO; @@ -104,6 +105,9 @@ @EJB protected EntryBookService entryBookService; + + @EJB + protected OptionsService optionsService; public FinancialTransactionServiceImpl() { LimaConfig config = LimaConfig.getInstance(); @@ -268,6 +272,7 @@ public List<FinancialTransaction> getAllInexactFinancialTransactions(FiscalPeriod fiscalPeriod) throws LimaException { TopiaContext topiaContext = null; List<FinancialTransaction> result = null; + List<FinancialTransaction> checkedResult = new ArrayList<FinancialTransaction>(); try { topiaContext = beginTransaction(); @@ -294,8 +299,18 @@ .addLoad(entryBookLabelProperty); result = financialTransactionDAO.findAllByQuery(query); + for (FinancialTransaction fTransaction : result) { + BigDecimal credit = fTransaction.getAmountCredit(); + BigDecimal debit = fTransaction.getAmountDebit(); + credit = credit.setScale(optionsService.getScale(), + BigDecimal.ROUND_HALF_UP); + debit = debit.setScale(optionsService.getScale(), + BigDecimal.ROUND_HALF_UP); + if (credit.equals(debit)) { + checkedResult.add(fTransaction); + } + } - } catch (TopiaException ex) { doCatch(topiaContext, ex, log); Added: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/OptionsServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/OptionsServiceImpl.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/OptionsServiceImpl.java 2011-06-27 16:31:06 UTC (rev 3185) @@ -0,0 +1,30 @@ +package org.chorem.lima.business.ejb; + +import javax.ejb.Stateless; + +import org.chorem.lima.business.LimaConfig; +import org.chorem.lima.business.ejbinterface.OptionsService; +import org.chorem.lima.business.ejbinterface.OptionsServiceLocal; + +@Stateless +public class OptionsServiceImpl extends AbstractLimaService implements OptionsService, OptionsServiceLocal { + + protected String scale; + + public OptionsServiceImpl() { + scale = LimaConfig.getInstance().getScale(); + } + + public int getScale() { + if (scale.isEmpty()) { + return 2; + } else { + return Integer.valueOf(scale); + } + } + + public void setScale(String scale) { + LimaConfig.getInstance().setScale(scale); + } + +} Added: trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/OptionsService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/OptionsService.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/OptionsService.java 2011-06-27 16:31:06 UTC (rev 3185) @@ -0,0 +1,32 @@ +package org.chorem.lima.business.ejbinterface; + +import javax.ejb.Remote; + +/** + * Service de report des certaines configurations du swing dans business + * + * Actuellement : + * <ul> + * <li>scale</li> + * </ul> + * + * @author salaun + * + */ + +@Remote +public interface OptionsService { + + /** + * Sets the swing scale to the business scale + * @param String: scale + */ + void setScale(String scale); + + /** + * Gets the business scale + * @return String: scale + */ + int getScale(); + +} Added: trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/OptionsServiceLocal.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/OptionsServiceLocal.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/OptionsServiceLocal.java 2011-06-27 16:31:06 UTC (rev 3185) @@ -0,0 +1,8 @@ +package org.chorem.lima.business.ejbinterface; + +import javax.ejb.Local; + +@Local +public interface OptionsServiceLocal extends OptionsService { + +} Modified: trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties =================================================================== --- trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties 2011-06-17 15:32:15 UTC (rev 3184) +++ trunk/lima-business/src/main/resources/i18n/lima-business_en_GB.properties 2011-06-27 16:31:06 UTC (rev 3185) @@ -65,4 +65,5 @@ lima.config.httpport=HTTP Port lima.config.reportsdir=Reports directories lima.config.rulesnationality=Rules Nationality +lima.config.scale=Scale lima.config.serveraddress=Server Address Modified: trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties =================================================================== --- trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties 2011-06-17 15:32:15 UTC (rev 3184) +++ trunk/lima-business/src/main/resources/i18n/lima-business_fr_FR.properties 2011-06-27 16:31:06 UTC (rev 3185) @@ -65,4 +65,5 @@ lima.config.httpport=Port HTTP lima.config.reportsdir=Dossier des rapports lima.config.rulesnationality=R\u00E8gles nationales +lima.config.scale=Pr\u00E9cision lima.config.serveraddress=Addresse serveur Modified: trunk/lima-swing/src/main/java/org/chorem/lima/LimaConfig.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/LimaConfig.java 2011-06-17 15:32:15 UTC (rev 3184) +++ trunk/lima-swing/src/main/java/org/chorem/lima/LimaConfig.java 2011-06-27 16:31:06 UTC (rev 3185) @@ -27,13 +27,23 @@ import static org.nuiton.i18n.I18n._; import java.beans.PropertyChangeListener; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; import java.util.Locale; +import java.util.Properties; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.actions.MiscAction; +import org.chorem.lima.business.OptionsServiceMonitorable; import org.chorem.lima.entity.LimaCallaoDAOHelper; +import org.chorem.lima.service.LimaServiceFactory; import org.nuiton.util.ApplicationConfig; import org.nuiton.util.ArgumentsParserException; +import org.nuiton.util.FileUtil; +import org.nuiton.util.SortedProperties; import org.nuiton.util.Version; import org.nuiton.util.VersionUtil; import org.nuiton.util.converter.ConverterUtil; @@ -58,6 +68,11 @@ private static final String configFile = "lima-config.properties"; + //used for services + protected static final String SERVICECONFIGFILE = "lima.properties"; + + protected OptionsServiceMonitorable optionsService; + /** * La version du logiciel. */ @@ -109,6 +124,7 @@ // TODO what is it for ? //FileUtil.setCurrentDirectory(getLimaUserDirectory()); //getLimaUserDirectory().mkdirs(); + } public static LimaConfig getInstance() { @@ -220,6 +236,8 @@ setOption(Option.SCALE.key, scale); saveForUser(); firePropertyChange("scale", null, scale); + System.out.println("new scale" + scale); + optionsService.setScale(scale); } /** @@ -455,4 +473,98 @@ this.aliases = aliases; } } + + /** + * Save configuration, in user home directory using the + * {@link #getConfigFileName}. Default, env and commande line note saved + * + * @param excludeKeys optional list of keys to exclude from + */ + public void saveForUser(String... excludeKeys) { + + File file = getUserConfigFile(); + if (log.isDebugEnabled()) { + log.debug("will save user configuration in " + file); + } + try { + save(file, false, excludeKeys); + } catch (IOException eee) { + if (log.isWarnEnabled()) { + log.warn(_("nuitonutil.error.applicationconfig.save", file), + eee); + } + } + } + + /** + * Save configuration, in specified file. + * + * @param file file where config will be writen + * @param forceAll if true save all config option + * (with defaults, classpath, env, command line) + * @param excludeKeys optional list of keys to exclude from + * @throws IOException if IO pb + */ + public void save(File file, + boolean forceAll, + String... excludeKeys) throws IOException { + + // + String[] serverProperties = {"scale"}; + + // store sorted in file + Properties prop = new SortedProperties(); + + // store server properties in file + Properties serverProp = new SortedProperties(); + + if (forceAll) { + prop.putAll(defaults); + prop.putAll(classpath); + } + prop.putAll(etcfile); + prop.putAll(homefile); + prop.putAll(curfile); + if (forceAll) { + prop.putAll(jvm); + prop.putAll(env); + prop.putAll(line); + } + prop.putAll(options); + + for (String excludeKey : excludeKeys) { + prop.remove(excludeKey); + } + + for (String serverPropertie : serverProperties) { + if (prop.containsKey(serverPropertie)) { + serverProp.put(serverPropertie, prop.get(serverPropertie)); + } + } + + // Ano #687 : create parentFile before using it in FileWriter + boolean dirCreated = FileUtil.createDirectoryIfNecessary(file.getParentFile()); + if (dirCreated && log.isDebugEnabled()) { + log.debug("Creation of config directory " + file.getParent()); + } + + OutputStream stream = new FileOutputStream(file); + try { + prop.store(stream, "Last saved " + new java.util.Date()); + } finally { + stream.close(); + } + + optionsService = + LimaServiceFactory.getInstance().getService( + OptionsServiceMonitorable.class); + + if (!serverProp.isEmpty()) { + if (serverProp.containsKey("scale")) { + if (!serverProp.getProperty("scale").isEmpty()) { + optionsService.setScale(serverProp.getProperty("scale")); + } + } + } + } }
participants (1)
-
vsalaun@users.chorem.org