r2805 - in trunk: lima-business/src/main/java/org/chorem/lima/business lima-business/src/test/java/org/chorem/lima/business lima-swing/src/main/java/org/chorem/lima/util
Author: echatellier Date: 2010-03-16 16:53:11 +0100 (Tue, 16 Mar 2010) New Revision: 2805 Log: Add missing files during last refactoring Added: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java trunk/lima-business/src/main/java/org/chorem/lima/business/LimaException.java trunk/lima-business/src/test/java/org/chorem/lima/business/LimaConfigTest.java trunk/lima-swing/src/main/java/org/chorem/lima/util/ServiceHelper.java Added: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java 2010-03-16 15:53:11 UTC (rev 2805) @@ -0,0 +1,60 @@ +/* *##% + * Copyright (C) 2010 Code Lutin, 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package org.chorem.lima.business; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.ApplicationConfig; +import org.nuiton.util.ArgumentsParserException; + +/** + * TODO add comment here. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class LimaConfig extends ApplicationConfig { + + private static final Log log = LogFactory.getLog(LimaConfig.class); + + protected static LimaConfig instance; + + protected LimaConfig() { + + } + + public static LimaConfig getInstance() { + if (instance == null) { + instance = new LimaConfig(); + instance.setConfigFileName("lima.properties"); + try { + instance.parse(new String[0]); + } catch (ArgumentsParserException ex) { + if (log.isErrorEnabled()) { + log.error("Can't read configuration", ex); + } + } + } + + return instance; + } +} Property changes on: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaException.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaException.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaException.java 2010-03-16 15:53:11 UTC (rev 2805) @@ -0,0 +1,53 @@ +/* *##% Lima + * Copyright (C) 2010 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ + +package org.chorem.lima.business; + +/** + * Lima exception. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class LimaException extends Exception { + + /** serialVersionUID. */ + private static final long serialVersionUID = -6876236663940184462L; + + /** + * Constructs a new exception with the specified detail message. + * + * @param message message + */ + public LimaException(String message) { + super(message); + } + + /** + * Constructs a new exception with the specified detail message and cause. + * + * @param message message + * @param cause cause + */ + public LimaException(String message, Throwable cause) { + super(message, cause); + } +} Property changes on: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/lima-business/src/test/java/org/chorem/lima/business/LimaConfigTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/LimaConfigTest.java (rev 0) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/LimaConfigTest.java 2010-03-16 15:53:11 UTC (rev 2805) @@ -0,0 +1,55 @@ +/* *##% + * Copyright (C) 2010 Code Lutin, 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package org.chorem.lima.business; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Ignore; +import org.nuiton.util.ArgumentsParserException; + +/** + * TODO add comment here. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +@Ignore +public class LimaConfigTest extends LimaConfig { + + private static final Log log = LogFactory.getLog(LimaConfig.class); + + public static LimaConfig getInstance() { + if (instance == null) { + instance = new LimaConfig(); + instance.setConfigFileName("lima_test.properties"); + try { + instance.parse(new String[0]); + } catch (ArgumentsParserException ex) { + if (log.isErrorEnabled()) { + log.error("Can't read configuration", ex); + } + } + } + + return instance; + } +} Property changes on: trunk/lima-business/src/test/java/org/chorem/lima/business/LimaConfigTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/lima-swing/src/main/java/org/chorem/lima/util/ServiceHelper.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/util/ServiceHelper.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/util/ServiceHelper.java 2010-03-16 15:53:11 UTC (rev 2805) @@ -0,0 +1,354 @@ +/** + * *##% Lima service + * Copyright (C) 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ + +package org.chorem.lima.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import static org.nuiton.i18n.I18n._; + +import java.util.Calendar; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; + +/** + * @author chemit + * @author Rémi Chapelet + */ +public class ServiceHelper { + + /** + * log + */ + private static final Log log = LogFactory.getLog(ServiceHelper.class); + /** + * Transaction status type + */ + public static final String TR_FINALIZED = "TR_FINALIZED"; + public static final String TR_BALANCED = "TR_BALANCED"; + public static final String TR_WIP = "TR_WIP"; + /** + * Period status type + */ + public static final String PE_OPEN = "PE_OPEN"; + public static final String PE_CLOSETMP = "PE_CLOSETMP"; + public static final String PE_CLOSE = "PE_CLOSE"; + /** + * Responses + */ + public static final String RESPOND_SUCCESS = "success"; + public static final String RESPOND_ERROR = "error"; + + /** + * Account Error + */ + public static final String ACCOUNT_DOUBLE = "account_double"; + public static final String ACCOUNT_NOT_MASTER = "account_not_master"; + public static final String ACCOUNT_NOT_EXIST = "account_not_exist"; + public static final String ACCOUNT_WITH_ENTRIES = "account_with_entries"; + + /** + * Entries Error + */ + public static final String ENTRY_NOT_EXIST = "entry_not_exist"; + + /** + * Journal + */ + public static final String JOURNAL_DOUBLE = "journal_double"; + public static final String JOURNAL_NOT_EXIST = "journal_not_exist"; + public static final String JOURNAL_WITH_TRANSACTIONS = "journal_with_transactions"; + + /** + * Period + */ + public static final String PERIOD_CREATE_TIMESPANS = "period_create_timespan"; + public static final String PERIOD_TIMESPAN_NOT_BLOCK = "period_timespan_not_block"; + public static final String PERIOD_TIMESPAN_BLOCK = "period_timespan_block"; + public static final String PERIOD_ALL_TIMESPAN = "period_all_timespan"; + public static final String PERIOD_NOT_EXIST = "period_not_exist"; + + public static final String PERIOD_PREC_NOT_BLOCK = "period_prec_not_block"; + public static final String PERIOD_NEXT_NOT_BLOCK = "period_next_not_block"; + + /** + * Transaction + */ + public static final String TRANSACTION_NOT_JOURNAL = "transaction_not_journal"; + public static final String TRANSACTION_NOT_TIMESPAN = "transaction_not_timespan"; + public static final String TRANSACTION_TIMESPAN_BLOCKED = "transaction_timespan_blocked"; + public static final String TRANSACTION_NOT_EXIST = "transaction_not_exist"; + public static final String TRANSACTION_NOT_BALANCED = "transaction_not_balanced"; + + protected ServiceHelper() { + // no instance + } + + /** + * TODO + * + * @param accounts TODO + * @return TODO + */ + public static List<Account> getAllFlatAccount(Account accounts) { + List<Account> flatList = new LinkedList<Account>(); + concatListAccount(flatList, accounts.getChildren()); + return flatList; + } + + /** + * TODO + * + * @param res TODO + * @param add TODO + */ + private static void concatListAccount(List<Account> res, List<Account> add) { + res.addAll(add); + for (Account acc : add) { + if (acc.getChildren() != null) { + concatListAccount(res, acc.getChildren()); + } + } + } + + /** + * TODO + * + * @param periods TODO + * @return TODO + */ + public static List<PeriodDTO> getAllFlatPeriod(List<PeriodDTO> periods) { + List<PeriodDTO> flatList = new LinkedList<PeriodDTO>(); + for (PeriodDTO period : periods) { + flatList.add(period); + flatList.addAll(period.getChildren()); + } + return flatList; + } + + /** + * @param date + * @return + */ + public static String dateToMonth(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + switch (cal.get(Calendar.MONTH)) { + case Calendar.JANUARY: + return _("lima.date.january"); + case Calendar.FEBRUARY: + return _("lima.date.february"); + case Calendar.MARCH: + return _("lima.date.march"); + case Calendar.APRIL: + return _("lima.date.april"); + case Calendar.MAY: + return _("lima.date.may"); + case Calendar.JUNE: + return _("lima.date.june"); + case Calendar.JULY: + return _("lima.date.july"); + case Calendar.AUGUST: + return _("lima.date.august"); + case Calendar.SEPTEMBER: + return _("lima.date.september"); + case Calendar.OCTOBER: + return _("lima.date.october"); + case Calendar.NOVEMBER: + return _("lima.date.november"); + case Calendar.DECEMBER: + return _("lima.date.december"); + } + return null; + } + /** + * @param date the date to inspect + * @return the year of the given date + */ + public static String dateToYear(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + return "" + cal.get(Calendar.YEAR); + } + + /** + * @param trans + * @return + */ + public static boolean isEditable(TransactionDTO trans) { + String finalizedKey = ServiceHelper.PE_CLOSE; + return !trans.getPeriod().getStatus().getIdType().equals(finalizedKey); + } + + /** + * @param entry + * @return + */ + public static boolean isEditable(EntryDTO entry) { + return isEditable(entry.getTransaction()); + } + + public static StatusDTO findStatusByType(List<StatusDTO> list, String id) { + if (id == null || list == null) { + return null; + } + for (StatusDTO status : list) { + if (id.equals(status.getIdType())) { + return status; + } + } + log.warn("Status " + id + " couldn't be found."); + return null; + } + + public static JournalDTO findJournalById(List<JournalDTO> list, String id) { + if (id == null || list == null) { + return null; + } + for (JournalDTO journal : list) { + if (id.equalsIgnoreCase(journal.getIdName()) || id.equalsIgnoreCase(journal.getPrefix()) || id.equals(journal.getIdSeq())) { + return journal; + } + } + log.warn("Journal " + id + " couldn't be found."); + return null; + } + + public static StatusDTO findStatusById(List<StatusDTO> list, String id) { + if (id == null || list == null) { + return null; + } + for (StatusDTO Status : list) { + if (id.equals(Status.getIdName())) { + return Status; + } + } + log.warn("Status " + id + " couldn't be found."); + return null; + } + + public static AccountDTO findAccountById(List<AccountDTO> list, String id) { + if (id == null || list == null) { + return null; + } + for (AccountDTO account : list) { + if (id.equals(account.getIdNumber())) { + return account; + } + } + log.warn("Account " + id + " couldn't be found."); + return null; + } + + public static PeriodDTO findPeriodById(List<PeriodDTO> list, String id) { + if (id == null || list == null) { + return null; + } + for (PeriodDTO period : list) { + if (id.equals(period.getIdSeq())) { + return period; + } + } + log.warn("Period " + id + " couldn't be found."); + return null; + } + + public static PeriodDTO findPeriodByDate(List<PeriodDTO> list, Date d) { + if (d == null || list == null) { + return null; + } + PeriodDTO periodSearch = null; + for (PeriodDTO period : list) { + if ( betweenDate(d,period.getBegin(),period.getEnd()) ) { + periodSearch = period; + } + } + if ( periodSearch == null) + { + log.warn("Period with this date " + d + " couldn't be found."); + } + return periodSearch; + } + + /** + * Permet de rechercher toutes les transactions appartenant à une période + * donnée. + * @param period + * @param listTransactions + * @return + */ + public static List<TransactionDTO> findTransactionByPeriod(PeriodDTO period,List<TransactionDTO> listTransactions) + { + if (period == null || listTransactions == null) { + return null; + } + List<TransactionDTO> ListTransactionSearch = new LinkedList<TransactionDTO>(); + // Si période annuelle + if ( period.getParent() == null ) + { + for (TransactionDTO transaction : listTransactions) + { + if ( transaction.getPeriod().getParent().equals(period) ) + { + ListTransactionSearch.add(transaction); + } + } + } else { + // Si période mensuelle + for (TransactionDTO transaction : listTransactions) + { + if ( transaction.getPeriod().equals(period) ) + { + ListTransactionSearch.add(transaction); + } + } + } + return ListTransactionSearch; + } + + /** + * Permet de renvoyer vrai si une date d donnée est entre deux dates. + * @param d date se trouvant ou non dans la période + * @param dateBegin date de début de période + * @param dateEnd date de fin de période + * @return + */ + public static boolean betweenDate (Date d, Date dateBegin, Date dateEnd) + { + boolean result = false; + if ( ( (compareDate(d,dateBegin) == 0) || (compareDate(d,dateBegin) == 1) ) + && ( (compareDate(d,dateEnd) == 0) || (compareDate(d,dateEnd) == -1) ) ) + { + result = true; + } + return result; + } + + /** + * Implémentation de compareTO. Si il y a besoin, il est possible de la modifier. + * @param d1 + * @param d2 + * @return + */ + public static int compareDate(Date d1, Date d2) + { + return d1.compareTo(d2); + } +} Property changes on: trunk/lima-swing/src/main/java/org/chorem/lima/util/ServiceHelper.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL
participants (1)
-
echatellier@users.chorem.org