r2814 - in trunk/lima-business/src: main/java/org/chorem/lima/business main/java/org/chorem/lima/business/ejb test/java/org/chorem/lima/business
Author: echatellier Date: 2010-03-25 14:40:03 +0100 (Thu, 25 Mar 2010) New Revision: 2814 Log: Refactor some entities name Added: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/RecordServiceImpl.java trunk/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/RecordServiceImplTest.java Removed: trunk/lima-business/src/main/java/org/chorem/lima/business/convertObject/ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/JournalServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/LogServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/PeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TimeSpanServiceImpl.java trunk/lima-business/src/test/java/org/chorem/lima/business/JournalServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/LogServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/PeriodServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/TimeSpanServiceImplTest.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FilesServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TransactionServiceImpl.java trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/EntryServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/FilesServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/UserServiceImplTest.java Copied: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java (from rev 2811, trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/JournalServiceImpl.java) =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -0,0 +1,473 @@ +/* + * *##% Callao EntryBookServiceImpl + * Copyright (C) 2009 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.ejb; + +import static org.nuiton.i18n.I18n._; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.LimaBusinessException; +import org.chorem.lima.business.LimaConfig; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.EntryBookDAO; +import org.chorem.lima.entity.LimaCallaoDAOHelper; +import org.chorem.lima.entity.Transaction; +import org.chorem.lima.entity.TransactionDAO; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaNotFoundException; + +/** + * Implémente la fonction multi-EntryBook. Il est possible de créer ici le + * EntryBook des ventes, le EntryBook des achats, etc. + * + * @author Rémi Chapelet + */ +public class EntryBookServiceImpl { + + private static final Log log = LogFactory.getLog(EntryBookServiceImpl.class); + + private TopiaContext rootContext; + + //private ConvertEntryBook convertEntryBook = new ConvertEntryBook(); + + public EntryBookServiceImpl() { + LimaConfig config = LimaConfig.getInstance(); + try { + rootContext = TopiaContextFactory.getContext(config.getOptions()); + } catch (TopiaNotFoundException ex) { + if (log.isErrorEnabled()) { + log.error("Can't init topia context", ex); + } + } + } + + /** + * Création d'un EntryBook. Il peut être unique sur son label (au choix). + * + * @param EntryBook EntryBook + * @throws LimaException + */ + public void createEntryBook(EntryBook EntryBook) throws LimaException { + /*String result = ServiceHelper.RESPOND_ERROR; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper + .getEntryBookDAO(topiaContext); + + // Si on souhaite avoir un EntryBook unique avec son label + + EntryBook EntryBook = searchEntryBookWithLabel(label); + // Si un EntryBook existe déjà avec ce label + if (EntryBook != null) { + if (log.isWarnEnabled()) { + log.warn("Un EntryBook avec le label " + label + + " existe déjà !"); + } + result = ServiceHelper.EntryBook_DOUBLE; + } else { + // Creation du EntryBook + EntryBook newEntryBook = EntryBookDAO.create(); + newEntryBook.setLabel(label); + newEntryBook.setPrefix(prefix); + newEntryBook.setDescription(description); + // Création BDD + topiaContext.commitTransaction(); + result = ServiceHelper.RESPOND_SUCCESS; + } + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return result;*/ + + TopiaContext transaction = null; + try { + // basic check done, make check in database + // TODO move it into JTA + transaction = rootContext.beginTransaction(); + + // test si un EntryBook de ce nom existe deja + EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(transaction); + EntryBook existingEntryBook = EntryBookDAO.findByLabel(EntryBook.getLabel()); + if (existingEntryBook != null) { + throw new LimaBusinessException(_("An EntryBook already exists with this label : %s", EntryBook.getLabel())); + } + + // creation du EntryBook + EntryBookDAO.create(EntryBook); + + // commit + transaction.commitTransaction(); + } + catch (TopiaException ex) { + if (transaction != null) { + try { + transaction.rollbackTransaction(); + } catch (TopiaException e) { + if (log.isErrorEnabled()) { + log.error("Error during rollback context", ex); + } + } + } + if (log.isErrorEnabled()) { + log.error("Error during create account", ex); + } + throw new LimaException("Can't create EntryBook", ex); + } + finally { + if (transaction != null) { + try { + transaction.closeContext(); + } catch (TopiaException ex) { + if (log.isErrorEnabled()) { + log.error("Error during rollback context", ex); + } + throw new LimaException("Can't create EntryBook", ex); + } + } + } + } + + /* + * Création d'un EntryBook à partir de son DTO. + * @param EntryBookDTO EntryBook au format DTO. + * @return + * + public String createEntryBook(EntryBookDTO EntryBookDTO) { + String result; + result = createEntryBook(EntryBookDTO.getLabel(), EntryBookDTO.getPrefix(), + EntryBookDTO.getDescription()); + return result; + }*/ + + public List<EntryBook> getAllEntryBook() throws LimaException { + /*List<EntryBookDTO> listEntryBookDTO = new ArrayList<EntryBookDTO>(); + + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper + .getEntryBookDAO(topiaContext); + // Creation du EntryBook + List<EntryBook> listEntryBook = EntryBookDAO.findAll(); + // Pour chaque EntryBook, on le transforme en DTO + for (EntryBook EntryBook : listEntryBook) { + // Converti en DTO + EntryBookDTO EntryBookDTO = convertEntryBook + .EntryBookEntityToDto(EntryBook); + // Ajoute à la liste + listEntryBookDTO.add(EntryBookDTO); + } + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return listEntryBookDTO;*/ + + List<EntryBook> EntryBooksList = new ArrayList<EntryBook>(); + TopiaContext transaction = null; + try { + // basic check done, make check in database + // TODO move it into JTA + transaction = rootContext.beginTransaction(); + + // test si un EntryBook de ce nom existe deja + EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(transaction); + List<EntryBook> EntryBooks = EntryBookDAO.findAll(); + EntryBooksList.addAll(EntryBooks); + + // commit + transaction.commitTransaction(); + } + catch (TopiaException ex) { + if (transaction != null) { + try { + transaction.rollbackTransaction(); + } catch (TopiaException e) { + if (log.isErrorEnabled()) { + log.error("Error during rollback context", ex); + } + } + } + if (log.isErrorEnabled()) { + log.error("Error during create account", ex); + } + throw new LimaException("Can't create EntryBook", ex); + } + finally { + if (transaction != null) { + try { + transaction.closeContext(); + } catch (TopiaException ex) { + if (log.isErrorEnabled()) { + log.error("Error during rollback context", ex); + } + throw new LimaException("Can't create EntryBook", ex); + } + } + } + + return EntryBooksList; + } + + /* + * Permet de rechercher un EntryBook existant à partir de son label. + * ATTENTION : il est possible que plusieurs journaux existent avec ce + * même label. La méthode renvoie le premier trouvé. + * @param prefix préfixe du EntryBook recherché + * @return + * + public EntryBook searchEntryBookWithLabel(String label) { + EntryBook EntryBookResult = null; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper + .getEntryBookDAO(topiaContext); + // Creation du EntryBook + EntryBookResult = EntryBookDAO.findByLabel(label); + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return EntryBookResult; + }*/ + + /* + * Permet de rechercher un EntryBook existant à partir du label. + * Le EntryBook recherché est converti automatiquement en format DTO. + * @param prefix préfixe du EntryBook recherché + * @return + * + public EntryBookDTO searchEntryBookDTOWithLabel(String label) { + EntryBook EntryBook = searchEntryBookWithLabel(label); + EntryBookDTO EntryBookDTO = convertEntryBook.EntryBookEntityToDto(EntryBook); + return EntryBookDTO; + }*/ + + /* + * Permet de rechercher un EntryBook unique identifé par son topiaId. + * @param topiaId identifiant du EntryBook recherché + * @return + * + public EntryBook searchEntryBookWithTopiaId(String topiaId) { + EntryBook EntryBookResult = null; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper + .getEntryBookDAO(topiaContext); + // Creation du EntryBook + EntryBookResult = EntryBookDAO.findByTopiaId(topiaId); + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return EntryBookResult; + }*/ + + /* + * Permet de rechercher un EntryBook existant à partir du topiaId. + * Le EntryBook recherché est converti automatiquement en format DTO. + * @param prefix préfixe du EntryBook recherché + * @return + * + public EntryBookDTO searchEntryBookDTOWithTopiaId(String topiaId) { + EntryBook EntryBook = searchEntryBookWithTopiaId(topiaId); + EntryBookDTO EntryBookDTO = convertEntryBook.EntryBookEntityToDto(EntryBook); + return EntryBookDTO; + }*/ + + /* + * Permet de modifier un EntryBook. + * @param label + * @param prefix + * @return + * + public String modifyEntryBook(String topiaId, String label, String prefix, + String description) { + String result = ServiceHelper.RESPOND_ERROR; + EntryBook EntryBookModify = searchEntryBookWithTopiaId(topiaId); + // Si le EntryBook n'existe pas + if (EntryBookModify == null) { + if (log.isWarnEnabled()) { + log.warn("Le EntryBook " + label + " n'existe pas !"); + } + result = ServiceHelper.EntryBook_NOT_EXIST; + } else // Sinon on modifie le EntryBook + { + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper + .getEntryBookDAO(topiaContext); + // Modifie le EntryBook + EntryBookModify.setPrefix(prefix); + EntryBookModify.setDescription(description); + EntryBookDAO.update(EntryBookModify); + // Création BDD + topiaContext.commitTransaction(); + // Fermeture BDD + topiaContext.closeContext(); + result = ServiceHelper.RESPOND_SUCCESS; + } catch (TopiaException e) { + log.error(e); + } + } + return result; + }*/ + + /** + * Permet d'effacer un EntryBook dans la base de données. + * + * ATTENTION : si un EntryBook est associé avec des transactions, il est alors + * impossible de supprimer celui-ci. + * + * @param prefix préfixe du EntryBook à supprimer + * @return + * @throws LimaException + */ + public void removeEntryBook(EntryBook EntryBook) throws LimaException { + /*String result = ServiceHelper.RESPOND_ERROR; + EntryBook EntryBookDelete = searchEntryBookWithTopiaId(topiaId); + // Si le EntryBook n'existe pas + if (EntryBookDelete == null) { + if (log.isWarnEnabled()) { + log.warn("Le EntryBook " + topiaId + " n'existe pas !"); + } + result = ServiceHelper.EntryBook_NOT_EXIST; + } else // Sinon on efface le EntryBook + { + + // Vérifie si une transaction n'appartient pas à ce EntryBook. + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + TransactionDAO transactionDAO = LimaCallaoDAOHelper + .getTransactionDAO(topiaContext); + // Recherche au moins une transaction avec ce EntryBook. + Transaction transaction = transactionDAO + .findByEntryBook(EntryBookDelete); + // Il existe au moins une transaction + if (transaction != null) { + if (log.isWarnEnabled()) { + log.warn("Le EntryBook " + topiaId + + " possède des transactions comptables !"); + } + result = ServiceHelper.EntryBook_WITH_TRANSACTIONS; + } else { + + // Efface le EntryBook + // Chargement du DAO + EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper + .getEntryBookDAO(topiaContext); + // Supprime le EntryBook + EntryBookDAO.delete(EntryBookDelete); + // Création BDD + topiaContext.commitTransaction(); + // Fermeture BDD + topiaContext.closeContext(); + result = ServiceHelper.RESPOND_SUCCESS; + } + } catch (TopiaException e) { + log.error(e); + } + } + return result;*/ + + TopiaContext topiaTransaction = null; + try { + // basic check done, make check in database + // TODO move it into JTA + topiaTransaction = rootContext.beginTransaction(); + + // Vérifie si une transaction n'appartient pas à ce EntryBook. + TransactionDAO transactionDAO = LimaCallaoDAOHelper.getTransactionDAO(topiaTransaction); + Transaction transaction = transactionDAO.findByEntryBook(EntryBook); + if (transaction != null) { + throw new LimaBusinessException("Can't delete EntryBook with transactions"); + } + + // test si un EntryBook de ce nom existe deja + EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(topiaTransaction); + EntryBookDAO.delete(EntryBook); + + // commit + topiaTransaction.commitTransaction(); + } + catch (TopiaException ex) { + if (topiaTransaction != null) { + try { + topiaTransaction.rollbackTransaction(); + } catch (TopiaException e) { + if (log.isErrorEnabled()) { + log.error("Error during rollback context", ex); + } + } + } + if (log.isErrorEnabled()) { + log.error("Error during create account", ex); + } + throw new LimaException("Can't create EntryBook", ex); + } + finally { + if (topiaTransaction != null) { + try { + topiaTransaction.closeContext(); + } catch (TopiaException ex) { + if (log.isErrorEnabled()) { + log.error("Error during rollback context", ex); + } + throw new LimaException("Can't create EntryBook", ex); + } + } + } + } + + /* + * Permet d'effacer un EntryBook dans la base de données. + * ATTENTION : si un EntryBook est associé avec des transactions, il est alors + * impossible de supprimer celui-ci. + * @param EntryBookDTO EntryBook au format DTO à supprimer + * @return + * + public String removeEntryBook(EntryBookDTO EntryBookDTO) { + String result = removeEntryBook(EntryBookDTO.getId()); + return result; + }*/ + +} Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryServiceImpl.java 2010-03-25 13:03:22 UTC (rev 2813) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryServiceImpl.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -43,7 +43,7 @@ private TopiaContext rootContext; - private LogServiceImpl logServiceImpl = new LogServiceImpl(); + private RecordServiceImpl logServiceImpl = new RecordServiceImpl(); // TODO A revoir car transaction a besoin de entry et vice versa private static TransactionServiceImpl transactionServiceImpl = new TransactionServiceImpl(); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FilesServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FilesServiceImpl.java 2010-03-25 13:03:22 UTC (rev 2813) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FilesServiceImpl.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -68,11 +68,11 @@ private EntryServiceImpl entryServiceImpl = new EntryServiceImpl(); - private JournalServiceImpl journalServiceImpl = new JournalServiceImpl(); + private EntryBookServiceImpl journalServiceImpl = new EntryBookServiceImpl(); - private PeriodServiceImpl periodServiceImpl = new PeriodServiceImpl(); + private FiscalPeriodServiceImpl periodServiceImpl = new FiscalPeriodServiceImpl(); - private TimeSpanServiceImpl timeSpanServiceImpl = new TimeSpanServiceImpl(); + private FinancialPeriodServiceImpl timeSpanServiceImpl = new FinancialPeriodServiceImpl(); private TransactionServiceImpl transactionServiceImpl = new TransactionServiceImpl(); Copied: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java (from rev 2811, trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TimeSpanServiceImpl.java) =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -0,0 +1,534 @@ +/* + * *##% Callao TimeSpanServiceImpl + * Copyright (C) 2009 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.ejb; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.LimaConfig; +import org.chorem.lima.entity.FinancialPeriod; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaNotFoundException; + +/** + * Gestion des périodes intermédiaires durant l'exercice. + * Chaque timeSpan sera fixe, et devra correspondre à un mois complet. + * + * @author Rémi Chapelet + */ +public class FinancialPeriodServiceImpl { //implements TimeSpanService { + + /** log */ + private static final Log log = LogFactory.getLog(FinancialPeriodServiceImpl.class); + + private TopiaContext rootContext; + + private static TransactionServiceImpl transactionServiceImpl = new TransactionServiceImpl(); + + public FinancialPeriodServiceImpl() { + LimaConfig config = LimaConfig.getInstance(); + try { + rootContext = TopiaContextFactory.getContext(config.getOptions()); + } catch (TopiaNotFoundException ex) { + if (log.isErrorEnabled()) { + log.error("Can't init topia context", ex); + } + } + } + + /** + * Création d'une période timeSpan mensuelle avec une date de début et de fin. Une période + * peut être bloquée ou non. + * @param beginTimeSpan date de début de période + * @param endTimeSpan date de fin de période + * @param locked est à vrai si la période doit être bloquée. + * @return + */ + public void createTimeSpan(FinancialPeriod timeSpan /*Date beginTimeSpan, Date endTimeSpan, + Period period, boolean locked*/) { +/* + // timeSpan correspond à une période mensuelle. + // La fonction va donc prendre seulement pour date de référence la + // date beginTimeSpan. Elle calcule automatiquement la date de fin + // suivant le mois. + DateUtil dateutil = new DateUtil(); + // Initialise la date de début au premier du mois + beginTimeSpan = dateutil.InitDateFirstDayMonth(beginTimeSpan); + // Initialise la date de fin au dernier du mois + endTimeSpan = dateutil.InitDateEndDayMonth(beginTimeSpan); + if (log.isInfoEnabled()) { + log.info("Nouveau timeSpan du " + beginTimeSpan.toString() + " au " + + endTimeSpan.toString()); + } + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper + .getTimeSpanDAO(topiaContext); + // Creation du timespan + TimeSpan newtimeSpan = timeSpanDAO.create(); + newtimeSpan.setBeginTimeSpan(beginTimeSpan); + newtimeSpan.setEndTimeSpan(endTimeSpan); + newtimeSpan.setLocked(locked); + newtimeSpan.setPeriod(period); + // Création BDD + topiaContext.commitTransaction(); + // Fermeture BDD + topiaContext.closeContext(); + if (log.isInfoEnabled()) { + log.info("Ajout avec succes du timeSpan"); + } + return ServiceHelper.RESPOND_SUCCESS; + } catch (TopiaException e) { + log.error(e); + return ServiceHelper.RESPOND_ERROR; + }*/ + } + + /* + * Permet de trouver un timespan directement avec une date. La date peut + * être quelconque. Exemple : d = 17 sept 2000, renvoie la période du + * 1 sept au 30 sept 2000. + * @param d + * @return + * + public TimeSpan searchTimeSpanByDate(Date d) { + TimeSpan timeSpan = null; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper + .getTimeSpanDAO(topiaContext); + // Par précaution, on initialise la date au debut du mois + DateUtil dateutil = new DateUtil(); + // Recherche du timeSpan + Date searchDate = dateutil.InitDateFirstDayMonth(d); + timeSpan = timeSpanDAO.findByBeginTimeSpan(searchDate); + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return timeSpan; + }*/ + + /* + * Recherche un timeSpan précis, avec sa date de création. + * @param timeSpanDTO timeSpan au format DTO qu'on recherche + * @return + * + public TimeSpan searchTimeSpanByDate(TimeSpanDTO timeSpanDTO) { + TimeSpan timeSpan = searchTimeSpanByDate(timeSpanDTO.getBeginTimeSpan()); + return timeSpan; + }*/ + + /* + * Recherche un timeSpan UNIQUE. Celui est identifié par son topiaId. + * @param topiaId Identifiant du timeSpan recherché + * @return + * + public TimeSpan searchTimeSpanWithTopiaId(String topiaId) { + TimeSpan timeSpan = null; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper + .getTimeSpanDAO(topiaContext); + // Recherche du timeSpan + timeSpan = timeSpanDAO.findByTopiaId(topiaId); + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return timeSpan; + }*/ + + /* + * Permet de rechercher un timeSpan à l'aide d'une date. Il fait appel + * à la méthode searchTimeSpanByDate. + * La méthode renvoie un objet DTO. + * @param d + * @return + * + public TimeSpanDTO searchTimeSpanDTOByDate(Date d) { + TimeSpan timeSpan = searchTimeSpanByDate(d); + TimeSpanDTO timeSpanDTO = convertTimeSpan.timeSpanEntityToDto(timeSpan); + return timeSpanDTO; + }*/ + + /* + * Permet de faire une recherche de tous les timeSpans d'une période. + * @param period + * @return + * + public List<TimeSpan> searchListTimeSpan(Period period) { + List<TimeSpan> listTimeSpan = null; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper + .getTimeSpanDAO(topiaContext); + // Recherche les timeSpans avec cette période + listTimeSpan = timeSpanDAO.findAllByPeriod(period); + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return listTimeSpan; + }*/ + + /* + * Permet de rechercher tous les timeSpans suivant une période donnée. + * Chaque timeSpan est converti ensuite en DTO. + * @param period + * @return + * + public List<TimeSpanDTO> searchListTimeSpanDTO(Period period) { + List<TimeSpanDTO> listTimeSpanDTO = new ArrayList<TimeSpanDTO>(); + List<TimeSpan> listTimeSpan = searchListTimeSpan(period); + for (TimeSpan timeSpan : listTimeSpan) { + TimeSpanDTO timeSpanDTO = convertTimeSpan + .timeSpanEntityToDto(timeSpan); + listTimeSpanDTO.add(timeSpanDTO); + } + return listTimeSpanDTO; + }*/ + + /* + * Permet de bloquer un timespan, celle-ci ne doit pas être bloquée. + * La fonction doit s'assurer que les timeSpans précédents doivent être + * bloqués. + * Les transactions doivent être équilibrées + * @param timespan période qui doit être fermée + * @param period période (12 smois) + * + public String blockTimeSpan(TimeSpan timespan) { + String result = ServiceHelper.RESPOND_ERROR; + // Si la période n'est pas déjà fermée. + if (timespan.getLocked()) { + if (log.isInfoEnabled()) { + log.info("Timespan deja bloqué !"); + } + } else { + Period period = getPeriodWithTimeSpan(timespan); + if (period.getLocked()) { + if (log.isErrorEnabled()) { + log.error("La période du timespan est bloquée !"); + } + } else { + // Vérifie si tous les timeSpans précédents sont bloqués + boolean AllTimeSpanBlock = alltimeSpanBlocked(timespan, period); + if (AllTimeSpanBlock) { + // Enregistrement dans la base de données + try { + // Acces BDD + TopiaContext topiaContext = rootContext + .beginTransaction(); + // Chargement du DAO + TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper + .getTimeSpanDAO(topiaContext); + + // Vérifie si les transactons sont équilibrées + List<Transaction> listTransaction = transactionServiceImpl + .searchListTransactionWithTimeSpan(timespan); + boolean isTransactionBalanced = true; + boolean existTransactionNotBalanced = false; + for (Transaction transaction : listTransaction) { + isTransactionBalanced = transactionServiceImpl + .isTransactionBalanced(transaction); + if (!isTransactionBalanced) { + if (log.isInfoEnabled()) { + log.info("La transaction n'est pas bloquée."); + } + existTransactionNotBalanced = true; + } + } + if (!existTransactionNotBalanced) { + // Bloque la période + timespan.setLocked(true); + // Mise à jour de timespan dans la BDD + timeSpanDAO.update(timespan); + // Création BDD + topiaContext.commitTransaction(); + if (log.isInfoEnabled()) { + log.info("Timespan bloqué avec succès"); + } + result = ServiceHelper.RESPOND_SUCCESS; + } else { + result = ServiceHelper.TRANSACTION_NOT_BALANCED; + } + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + } else { + if (log.isErrorEnabled()) { + log.error("Il existe un ou plusieurs timespans précédents" + + " non bloqués."); + } + result = ServiceHelper.TIMESPAN_PREC_NOT_BLOCK; + } + } + } + return result; + }*/ + + /* + * Permet de bloquer une période au format DTO. + * + * @param timespanDTO + * @return + * + public String blockTimeSpan(TimeSpanDTO timespanDTO) { + return blockTimeSpan(searchTimeSpanByDate(timespanDTO)); + }*/ + + /* + * Permet de débloquer un timespan, à condition que les timespans suivants + * celui-ci soient bien débloqués. + * @param timespan + * @param period + * @return + * + public String unblockTimeSpan(TimeSpan timespan) { + String result = ServiceHelper.RESPOND_ERROR; + // Si le timspan n'est pas bloqué + if (!timespan.getLocked()) { + if (log.isWarnEnabled()) { + log.warn("Timespan non bloqué !"); + } + } else { + Period period = getPeriodWithTimeSpan(timespan); + if (period.getLocked()) { + if (log.isErrorEnabled()) { + log.error("La période du timespan est bloquée !"); + } + } else { + boolean NextTimeSpanUnblock = nextTimeSpanUnblock(timespan, + period); + // Si aucun timespan suivant bloqué + if (NextTimeSpanUnblock) { + try { + // Acces BDD + TopiaContext topiaContext = rootContext + .beginTransaction(); + // Chargement du DAO + TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper + .getTimeSpanDAO(topiaContext); + // débloque la période + timespan.setLocked(false); + // Mise à jour de timespan dans la BDD + timeSpanDAO.update(timespan); + // Création BDD + topiaContext.commitTransaction(); + if (log.isInfoEnabled()) { + log.info("Timespan débloqué avec succès"); + } + result = ServiceHelper.RESPOND_SUCCESS; + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + } else { + result = ServiceHelper.TIMESPAN_NEXT_NOT_BLOCK; + } + } + } + return result; + }*/ + + /* + * Permet de bloquer une période au format DTO. + * + * @param timespanDTO + * @return + * + public String unblockTimeSpan(TimeSpanDTO timespanDTO) { + return unblockTimeSpan(searchTimeSpanByDate(timespanDTO)); + }*/ + + /* + * Cette méthode va rechercher tous les timeSpans non bloqués après + * le timeSpan renseigné en paramètre. + * Si elle trouve au moins un timeSpan NON bloqué, elle renvoie alors faux. + * Cette méthode permet essentiellement de définir si il est possible + * ou non de bloquer un timeSpan. A savoir, un timeSpan ne peut être bloqué, + * si il existe des timeSpans suivant (dans le calendrier) qui sont non + * bloqués. + * @param timespan + * @param period + * @return + * + private boolean nextTimeSpanUnblock(TimeSpan timespan, Period period) { + boolean NextTimeSpanUnblock = false; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper + .getTimeSpanDAO(topiaContext); + // Recherche des TimeSpans avec la même période. + // (on doit récupérer normalement 12 timeSpans) + List<TimeSpan> listeTimeSpanOfPeriod = timeSpanDAO + .findAllByPeriod(period); + NextTimeSpanUnblock = true; + for (TimeSpan timeSpanNext : listeTimeSpanOfPeriod) { + // Si le timespan est après celui qu'on souhaite bloquer ET est non bloqué + if (timeSpanNext.getBeginTimeSpan().compareTo( + timespan.getBeginTimeSpan()) == 1 + && timeSpanNext.getLocked()) { + NextTimeSpanUnblock = false; + if (log.isInfoEnabled()) { + log.info("Timespan " + timeSpanNext.toString() + + " est bloqué"); + } + } + } + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return NextTimeSpanUnblock; + }*/ + + /* + * Permet de renvoyer une période dont appartient le timeSpan. + * @param timeSpan timeSpan dont on souhaite retourner la période + * @return + * + private Period getPeriodWithTimeSpan(TimeSpan timeSpan) { + PeriodServiceImpl periodServiceImpl = new PeriodServiceImpl(); + Date beginTimeSpan = timeSpan.getBeginTimeSpan(); + Period period = periodServiceImpl.searchPeriodWithDate(beginTimeSpan); + return period; + }*/ + + /* + * Cette méthode renvoie vrai lorsque tous les timespans de la période + * précédent au timespan en paramètre sont bloqués. + * @param timespan + * @param period le paramètre period est important, en effet un timespan ne + * peut être indépendant. + * @return + * + private boolean alltimeSpanBlocked(TimeSpan timespan, Period period) { + boolean AllTimeSpanBlock = false; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper + .getTimeSpanDAO(topiaContext); + // Recherche des TimeSpans avec la même période. + // (on doit récupérer normalement 12 timeSpans) + List<TimeSpan> listeTimeSpanOfPeriod = timeSpanDAO + .findAllByPeriod(period); + // Fermeture BDD + topiaContext.closeContext(); + // On contrôle que les timeSpans précédents sont bloqués. + AllTimeSpanBlock = true; + for (TimeSpan timeSpanPrev : listeTimeSpanOfPeriod) { + // Si la période est avant celle qu'on souhaite bloquer ET est non bloquée + if (timeSpanPrev.getBeginTimeSpan().compareTo( + timespan.getBeginTimeSpan()) == -1 + && !timeSpanPrev.getLocked()) { + AllTimeSpanBlock = false; + if (log.isInfoEnabled()) { + log.info("Timespan " + timeSpanPrev.toString() + + " non bloqué"); + } + } + } + } catch (TopiaException e) { + log.error(e); + } + return AllTimeSpanBlock; + }*/ + + /* + * Permet d'effacer un timeSpan. Ce dernier ne doit pas être bloqué. + * @param timeSpan + * @return + * + public String removeTimeSpan(TimeSpan timeSpan) { + String result = ServiceHelper.RESPOND_ERROR; + // Si le timspan est bloqué + if (timeSpan.getLocked()) { + if (log.isWarnEnabled()) { + log.warn("Timespan bloqué !"); + } + } else { + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper + .getTimeSpanDAO(topiaContext); + // Mise à jour de timespan dans la BDD + timeSpanDAO.delete(timeSpan); + // Création BDD + topiaContext.commitTransaction(); + if (log.isInfoEnabled()) { + log.info("Timespan supprimé avec succès"); + } + result = ServiceHelper.RESPOND_SUCCESS; + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + } + return result; + }*/ + + /* + * Vérifie si le timeSpan donné en paramètre est bloqué ou non. + * @param timeSpan + * @return + * + public boolean isTimeSpanBlocked(TimeSpan timeSpan) { + boolean isTimeSpanBlocked = true; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper + .getTimeSpanDAO(topiaContext); + // Mise à jour de timespan dans la BDD + TimeSpan timeSpanSearch = timeSpanDAO.findByTopiaId(timeSpan + .getTopiaId()); + isTimeSpanBlocked = timeSpanSearch.getLocked(); + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return isTimeSpanBlocked; + }*/ +} Copied: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java (from rev 2811, trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/PeriodServiceImpl.java) =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -0,0 +1,505 @@ +/* + * *##% Callao PeriodServiceImpl + * Copyright (C) 2009 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.ejb; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.LimaConfig; +import org.chorem.lima.entity.FinancialPeriod; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaNotFoundException; + +/** + * Gestion des périodes. + * Chaque période doit posséder 12 timespans mensuels. + * Une période ne peut être supprimée et débloquée. + * + * @author Rémi Chapelet + */ +public class FiscalPeriodServiceImpl { //implements PeriodService { + + private static final Log log = LogFactory.getLog(FiscalPeriodServiceImpl.class); + + private TopiaContext rootContext; + + private FinancialPeriodServiceImpl timeSpanServiceImpl = new FinancialPeriodServiceImpl(); + + public FiscalPeriodServiceImpl() { + LimaConfig config = LimaConfig.getInstance(); + try { + rootContext = TopiaContextFactory.getContext(config.getOptions()); + } catch (TopiaNotFoundException ex) { + if (log.isErrorEnabled()) { + log.error("Can't init topia context", ex); + } + } + } + + /** + * Permet de créer une période principale. Elle a une durée de un an, + * composées de 12 périodes mensuelles. Elle correspond à l'exercice + * comptable. Pour créer une nouvelle période, la précédente doit être + * obligatoirement clôturée. + * @param beginTimeSpan date début de période + * @param endTimeSpan date fin de période + * @param lock Vrai si la période est bloquée + * @return + */ + public void createPeriod(FinancialPeriod period /*Date beginTimeSpan, Date endTimeSpan, boolean lock*/) { + /*// Par défaut lock est à false + lock = false; + String result = ServiceHelper.RESPOND_ERROR; + + try { + boolean correctPeriod = false; + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + PeriodDAO periodDAO = LimaCallaoDAOHelper + .getPeriodDAO(topiaContext); + // Creation de la periodDate + PeriodDates newPeriod = new PeriodDates(beginTimeSpan, endTimeSpan); + + // Creation de la période + Period period = periodDAO.create(); + period.setBeginPeriod(newPeriod.getFromDate()); + period.setEndPeriod(newPeriod.getThruDate()); + period.setLocked(lock); + // Vérification si la période est correcte + correctPeriod = isCorrectPeriod(period); + if (correctPeriod) { + // Si elle est correcte : Création BDD + topiaContext.commitTransaction(); + if (log.isInfoEnabled()) { + log.info("Ajout exercice du " + beginTimeSpan.toString() + + " au " + endTimeSpan.toString()); + } + + //Ajout des timeSpans mensuels + //Par défaut, il prend seulement la date beginTimeSpan, et calcule + //la date de fin, c'est pourquoi il est laissé deux fois "beginTimeSpan" + TimeSpanServiceImpl timeSpanImpl = new TimeSpanServiceImpl(); + boolean stop = false; // En cas d'erreur lors de la création d'un timeSpan. + + List<Date> monthList = newPeriod.getMonths(); + + int max = monthList.size(); + log.debug("la periode fait:" + max); + for (int i = 0; i < max; i++) { + // Création timeSpan + result = timeSpanImpl.createTimeSpan(monthList.get(i), + monthList.get(i), period, false); + if (result.equals(ServiceHelper.RESPOND_ERROR)) { + stop = true; + if (log.isErrorEnabled()) { + log.error("Erreur lors de la création des " + max + + " timeSpans"); + } + result = ServiceHelper.PERIOD_CREATE_TIMESPANS; + } + // Supprimer la periode si stop = true + } + if (stop == false) { + result = ServiceHelper.RESPOND_SUCCESS; + } + } + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return result; */ + } + + /* + * Permet de créer une période à partir d'une période DTO. + * @param periodDTO période à créer au format DTO. + * @return + * + public String createPeriod(PeriodDTO periodDTO) { + String result = createPeriod(periodDTO.getBeginPeriod(), periodDTO + .getEndPeriod(), false); + // Tous les timeSpans sont automatiquement créés avec la méthode createPeriod + return result; + }*/ + + /* + * Permet de vérifier si la période est correcte (aucun chevauchement avec + * les autres périodes, période(s) précédente(s) bloquée(s), formée de 1 à 24 + * mois). + * @param period période à tester si elle est correcte + * @return + * + private boolean isCorrectPeriod(Period period) { + // Calcul du nombre de mois pour que la période soit valide (12 mois) + int number_months = dateUtil.numberOfMonths(period.getBeginPeriod(), + period.getEndPeriod()); + boolean result = true; + + if (number_months == 0 && number_months >= 24) // Periode de 1mois a 24 mois + { + if (log.isErrorEnabled()) { + log.error("Période du " + + period.getBeginPeriod() + + " au " + + period.getEndPeriod() + + " : L'exercice doit faire au minimum 1 mois et au maximum 24 mois"); + } + result = false; + } else { + // Période(s) précédente(s) bloquée(s). + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + PeriodDAO periodDAO = LimaCallaoDAOHelper + .getPeriodDAO(topiaContext); + // Recherche les périodes qui ne sont pas bloquées. + List<Period> listePeriod = periodDAO.findAllByLocked(false); + // Recherche la dernière période, les dates doivent se suivre + Date date_search = period.getBeginPeriod(); + Period previousPeriod = periodDAO.findByEndPeriod(dateUtil + .previousDay(date_search)); + // Nombre de périodes dans la base + int number_period = periodDAO.findAll().size(); + // Fermeture BDD + topiaContext.closeContext(); + // Si il y a au moins une période trouvée + if (!(listePeriod.isEmpty())) { + if (log.isErrorEnabled()) { + log.error("Il existe au moins une période précédente non bloquée !"); + } + result = false; + } + // Si la période précédente correspond au jour précédent + // et vérifie si ce n'est pas la première période + if (previousPeriod == null && number_period != 0) { + if (log.isErrorEnabled()) { + log.error("Votre période doit être collée " + + "aux autres périodes !" + + date_search.toString() + " PPP " + + dateUtil.previousDay(date_search).toString()); + } + result = false; + } + } catch (TopiaException e) { + log.error(e); + } + } + return result; + }*/ + + /* + * Cette méthode permet de bloquer une période. Elle doit vérifier que + * tous les timeSpans mensuels sont bloqués. + * @param + * @return + * + public String blockPeriod(Period period) { + String result = ServiceHelper.RESPOND_ERROR; + // La période ne doit pas être nulle + if (period != null) { + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper + .getTimeSpanDAO(topiaContext); + // Recherche tous les timeSpans de la période non bloquées + List<TimeSpan> listeTimeSpan = timeSpanDAO + .findAllByPeriod(period); + boolean existTimeSpanNotBlock = false; + for (TimeSpan timeSpan : listeTimeSpan) { + // Si timeSpan non bloqué + if (!timeSpan.getLocked()) { + existTimeSpanNotBlock = true; + if (log.isErrorEnabled()) { + log.error("Le timeSpan du " + + timeSpan.getBeginTimeSpan().toString() + + " au " + + timeSpan.getEndTimeSpan().toString() + + " non bloqué !"); + } + result = ServiceHelper.PERIOD_TIMESPAN_NOT_BLOCK; + } + } + // Si il n'existe pas de timeSpan non bloqué + if (!(existTimeSpanNotBlock)) { + // Bloque la période + period.setLocked(true); + // Chargement du DAO + PeriodDAO periodDAO = LimaCallaoDAOHelper + .getPeriodDAO(topiaContext); + periodDAO.update(period); + // Création BDD + topiaContext.commitTransaction(); + result = ServiceHelper.RESPOND_SUCCESS; + if (log.isInfoEnabled()) { + log.info("Période " + + period.getBeginPeriod().toString() + " au " + + period.getEndPeriod().toString() + + " bloquée avec succès."); + } + } + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + } + return result; + }*/ + + /* + * Permet de bloquer une période. Avec la périodeDTO passée en paramètre, on + * effectue une recherche avec la date de début pour récupérer la période + * dans la base de données. Il est possible de l'identifier avec son topiaId, + * mais il y a plus de risque que cette mentien ne soit pas renseignée dans + * l'objet periodDTO. + * @param periodDTO + * @return + * + public String blockPeriod(PeriodDTO periodDTO) { + // Recherche de la période + Period period = searchPeriodWithDate(periodDTO.getBeginPeriod()); + String result = blockPeriod(period); + return result; + }*/ + + /* + * Permet de bloquer TOUS les timeSpans de la période + * @param period + * @return + * + public String blockAllTimeSpanOfPeriod(Period period) { + String result = ServiceHelper.RESPOND_ERROR; + if (period == null) { + if (log.isErrorEnabled()) { + log.error("La période ne peut bloquer ses périodes mensuelles, " + + "il faut une période en entrée."); + } + } else { + // On bloque chaque timeSpan + boolean ErrorBlockTimeSpan = false; + List<TimeSpanDTO> listTimeSpanDTO = timeSpanServiceImpl + .searchListTimeSpanDTO(period); + // tri la liste des timeSpans dans l'ordre croissant des dates + Collections.sort(listTimeSpanDTO); + for (TimeSpanDTO timeSpanDTO : listTimeSpanDTO) { + result = timeSpanServiceImpl.blockTimeSpan(timeSpanDTO); + if (result.equals(ServiceHelper.RESPOND_ERROR)) { + ErrorBlockTimeSpan = true; + } + } + // Si il n'y a pas eu d'erreurs pour bloquer les timespans + if (!ErrorBlockTimeSpan) { + result = ServiceHelper.RESPOND_SUCCESS; + } else { + if (log.isErrorEnabled()) { + log.error("Impossible de bloquer tous les timeSpans."); + } + result = ServiceHelper.PERIOD_ALL_TIMESPAN; + } + } + return result; + }*/ + + /* + * Cette méthode est semblable à searchPeriodWithDateFirst. Elle permet + * de rechercher une période sans forcément connaître la date de départ. On + * donne une date quelconque, et elle retourne la période correspondante. + * @param d + * @return + * + public Period searchPeriodWithDate(Date d) { + Period period = null; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + PeriodDAO periodDAO = LimaCallaoDAOHelper + .getPeriodDAO(topiaContext); + // Recherche de toutes les périodes + List<Period> listePeriod = periodDAO.findAll(); + // Fermeture BDD + topiaContext.closeContext(); + // Recherche de la période + for (Period periodSearch : listePeriod) { + // Recherche si la date d est entre la date de début et fin de la période + boolean periodBetweenDate = dateUtil.betweenDate(d, + periodSearch.getBeginPeriod(), periodSearch + .getEndPeriod()); + // Si la date est comprise dans les limites de la période + if (periodBetweenDate) { + period = periodSearch; + } + } + } catch (TopiaException e) { + log.error(e); + } + return period; + }*/ + + /* + * Permet de rechercher une période au format DTO avec une date. Cette date + * peut être quelconque (pas obligatoire d'être le premier jour de la période + * par exemple). + * @param d date comprise dans la période qu'on souhaite rechercher + * @return + * + public PeriodDTO searchPeriodDTOWithDate(Date d) { + Period period = searchPeriodWithDate(d); + // Converti la période en PeriodDTO + PeriodDTO periodDTO = convertPeriod.periodEntityToDto(period); + return periodDTO; + }*/ + + /* + * Permet de renvoyer tous les périodes en format DTO, avec tous les timeSpans + * en format DTO également. + * @return + * + public List<PeriodDTO> getAllPeriod() { + ArrayList<PeriodDTO> listAllPeriodDTO = new ArrayList<PeriodDTO>(); + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + PeriodDAO periodDAO = LimaCallaoDAOHelper + .getPeriodDAO(topiaContext); + // Recherche de toutes les périodes + List<Period> listePeriod = periodDAO.findAll(); + // Transforme les périodes en DTO + for (Period period : listePeriod) { + PeriodDTO periodDTO = convertPeriod.periodEntityToDto(period); + listAllPeriodDTO.add(periodDTO); + } + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return listAllPeriodDTO; + }*/ + + /* + * Recherche une période précise, avec son identifiant topiaId. + * @param topiaId identifiant de la période + * @return + * + public Period searchPeriodWithTopiaId(String topiaId) { + Period periodSearch = null; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + PeriodDAO periodDAO = LimaCallaoDAOHelper + .getPeriodDAO(topiaContext); + // Creation du journal + periodSearch = periodDAO.findByTopiaId(topiaId); + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return periodSearch; + }*/ + + + /* + * Efface une période dans la base de données. Tous les timeSpans sont + * également effacés. Cette méthode est uniquement utilisée pour les tests + * unitaires. + * @param period + * @return + * + public String removePeriod(String topiaId) { + String result = ServiceHelper.RESPOND_ERROR; + Period periodDelete = searchPeriodWithTopiaId(topiaId); + // Si la période n'existe pas + if (periodDelete == null) { + if (log.isWarnEnabled()) { + log.warn("La période " + topiaId + " n'existe pas !"); + } + result = ServiceHelper.PERIOD_NOT_EXIST; + } else // Sinon on efface la période + { + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + PeriodDAO periodDAO = LimaCallaoDAOHelper + .getPeriodDAO(topiaContext); + // Débloque la période + periodDelete.setLocked(false); + // Mise à jour dans la bdd + periodDAO.update(periodDelete); + // Création BDD + topiaContext.commitTransaction(); + + // Supprime les timeSpans de la période + List<TimeSpanDTO> listTimeSpanDTO = timeSpanServiceImpl + .searchListTimeSpanDTO(periodDelete); + // tri la liste des timeSpans dans l'ordre décroissant des dates + Collections.sort(listTimeSpanDTO, Collections.reverseOrder()); + // Débloque les timeSpans + for (TimeSpanDTO timeSpanDTO : listTimeSpanDTO) { + TimeSpan timeSpan = timeSpanServiceImpl + .searchTimeSpanByDate(timeSpanDTO); + // Si le timeSpan est bloqué + if (timeSpanDTO.isLocked()) { + // débloque le timeSpan + timeSpanServiceImpl.unblockTimeSpan(timeSpan); + } + } + // Efface les timeSpans + for (TimeSpanDTO timeSpanDTO : listTimeSpanDTO) { + TimeSpan timeSpan = timeSpanServiceImpl + .searchTimeSpanByDate(timeSpanDTO); + // efface le timeSpan + timeSpanServiceImpl.removeTimeSpan(timeSpan); + } + + + //Supprime la période + periodDAO.delete(periodDelete); + // Création BDD + topiaContext.commitTransaction(); + // Fermeture BDD + topiaContext.closeContext(); + result = ServiceHelper.RESPOND_SUCCESS; + } catch (TopiaException e) { + log.error(e); + } + } + return result; + }*/ + + /* + * Permet d'effacer une période au format DTO. + * @param periodDTO la période à supprimer + * @return + * + public String removePeriod(PeriodDTO periodDTO) { + String result = removePeriod(periodDTO.getId()); + return result; + }*/ +} Deleted: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/JournalServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/JournalServiceImpl.java 2010-03-25 13:03:22 UTC (rev 2813) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/JournalServiceImpl.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -1,473 +0,0 @@ -/* - * *##% Callao JournalServiceImpl - * Copyright (C) 2009 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.ejb; - -import static org.nuiton.i18n.I18n._; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.LimaBusinessException; -import org.chorem.lima.business.LimaConfig; -import org.chorem.lima.business.LimaException; -import org.chorem.lima.entity.Journal; -import org.chorem.lima.entity.JournalDAO; -import org.chorem.lima.entity.LimaCallaoDAOHelper; -import org.chorem.lima.entity.Transaction; -import org.chorem.lima.entity.TransactionDAO; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaNotFoundException; - -/** - * Implémente la fonction multi-journal. Il est possible de créer ici le - * journal des ventes, le journal des achats, etc. - * - * @author Rémi Chapelet - */ -public class JournalServiceImpl { - - private static final Log log = LogFactory.getLog(JournalServiceImpl.class); - - private TopiaContext rootContext; - - //private ConvertJournal convertJournal = new ConvertJournal(); - - public JournalServiceImpl() { - LimaConfig config = LimaConfig.getInstance(); - try { - rootContext = TopiaContextFactory.getContext(config.getOptions()); - } catch (TopiaNotFoundException ex) { - if (log.isErrorEnabled()) { - log.error("Can't init topia context", ex); - } - } - } - - /** - * Création d'un journal. Il peut être unique sur son label (au choix). - * - * @param journal journal - * @throws LimaException - */ - public void createJournal(Journal journal) throws LimaException { - /*String result = ServiceHelper.RESPOND_ERROR; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - JournalDAO journalDAO = LimaCallaoDAOHelper - .getJournalDAO(topiaContext); - - // Si on souhaite avoir un journal unique avec son label - - Journal journal = searchJournalWithLabel(label); - // Si un journal existe déjà avec ce label - if (journal != null) { - if (log.isWarnEnabled()) { - log.warn("Un journal avec le label " + label - + " existe déjà !"); - } - result = ServiceHelper.JOURNAL_DOUBLE; - } else { - // Creation du journal - Journal newJournal = journalDAO.create(); - newJournal.setLabel(label); - newJournal.setPrefix(prefix); - newJournal.setDescription(description); - // Création BDD - topiaContext.commitTransaction(); - result = ServiceHelper.RESPOND_SUCCESS; - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return result;*/ - - TopiaContext transaction = null; - try { - // basic check done, make check in database - // TODO move it into JTA - transaction = rootContext.beginTransaction(); - - // test si un journal de ce nom existe deja - JournalDAO journalDAO = LimaCallaoDAOHelper.getJournalDAO(transaction); - Journal existingJournal = journalDAO.findByLabel(journal.getLabel()); - if (existingJournal != null) { - throw new LimaBusinessException(_("An journal already exists with this label : %s", journal.getLabel())); - } - - // creation du journal - journalDAO.create(journal); - - // commit - transaction.commitTransaction(); - } - catch (TopiaException ex) { - if (transaction != null) { - try { - transaction.rollbackTransaction(); - } catch (TopiaException e) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - } - } - if (log.isErrorEnabled()) { - log.error("Error during create account", ex); - } - throw new LimaException("Can't create journal", ex); - } - finally { - if (transaction != null) { - try { - transaction.closeContext(); - } catch (TopiaException ex) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - throw new LimaException("Can't create journal", ex); - } - } - } - } - - /* - * Création d'un journal à partir de son DTO. - * @param journalDTO Journal au format DTO. - * @return - * - public String createJournal(JournalDTO journalDTO) { - String result; - result = createJournal(journalDTO.getLabel(), journalDTO.getPrefix(), - journalDTO.getDescription()); - return result; - }*/ - - public List<Journal> getAllJournal() throws LimaException { - /*List<JournalDTO> listJournalDTO = new ArrayList<JournalDTO>(); - - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - JournalDAO journalDAO = LimaCallaoDAOHelper - .getJournalDAO(topiaContext); - // Creation du journal - List<Journal> listJournal = journalDAO.findAll(); - // Pour chaque journal, on le transforme en DTO - for (Journal journal : listJournal) { - // Converti en DTO - JournalDTO journalDTO = convertJournal - .journalEntityToDto(journal); - // Ajoute à la liste - listJournalDTO.add(journalDTO); - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return listJournalDTO;*/ - - List<Journal> journalsList = new ArrayList<Journal>(); - TopiaContext transaction = null; - try { - // basic check done, make check in database - // TODO move it into JTA - transaction = rootContext.beginTransaction(); - - // test si un journal de ce nom existe deja - JournalDAO journalDAO = LimaCallaoDAOHelper.getJournalDAO(transaction); - List<Journal> journals = journalDAO.findAll(); - journalsList.addAll(journals); - - // commit - transaction.commitTransaction(); - } - catch (TopiaException ex) { - if (transaction != null) { - try { - transaction.rollbackTransaction(); - } catch (TopiaException e) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - } - } - if (log.isErrorEnabled()) { - log.error("Error during create account", ex); - } - throw new LimaException("Can't create journal", ex); - } - finally { - if (transaction != null) { - try { - transaction.closeContext(); - } catch (TopiaException ex) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - throw new LimaException("Can't create journal", ex); - } - } - } - - return journalsList; - } - - /* - * Permet de rechercher un journal existant à partir de son label. - * ATTENTION : il est possible que plusieurs journaux existent avec ce - * même label. La méthode renvoie le premier trouvé. - * @param prefix préfixe du journal recherché - * @return - * - public Journal searchJournalWithLabel(String label) { - Journal journalResult = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - JournalDAO journalDAO = LimaCallaoDAOHelper - .getJournalDAO(topiaContext); - // Creation du journal - journalResult = journalDAO.findByLabel(label); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return journalResult; - }*/ - - /* - * Permet de rechercher un journal existant à partir du label. - * Le journal recherché est converti automatiquement en format DTO. - * @param prefix préfixe du journal recherché - * @return - * - public JournalDTO searchJournalDTOWithLabel(String label) { - Journal journal = searchJournalWithLabel(label); - JournalDTO journalDTO = convertJournal.journalEntityToDto(journal); - return journalDTO; - }*/ - - /* - * Permet de rechercher un journal unique identifé par son topiaId. - * @param topiaId identifiant du journal recherché - * @return - * - public Journal searchJournalWithTopiaId(String topiaId) { - Journal journalResult = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - JournalDAO journalDAO = LimaCallaoDAOHelper - .getJournalDAO(topiaContext); - // Creation du journal - journalResult = journalDAO.findByTopiaId(topiaId); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return journalResult; - }*/ - - /* - * Permet de rechercher un journal existant à partir du topiaId. - * Le journal recherché est converti automatiquement en format DTO. - * @param prefix préfixe du journal recherché - * @return - * - public JournalDTO searchJournalDTOWithTopiaId(String topiaId) { - Journal journal = searchJournalWithTopiaId(topiaId); - JournalDTO journalDTO = convertJournal.journalEntityToDto(journal); - return journalDTO; - }*/ - - /* - * Permet de modifier un journal. - * @param label - * @param prefix - * @return - * - public String modifyJournal(String topiaId, String label, String prefix, - String description) { - String result = ServiceHelper.RESPOND_ERROR; - Journal journalModify = searchJournalWithTopiaId(topiaId); - // Si le journal n'existe pas - if (journalModify == null) { - if (log.isWarnEnabled()) { - log.warn("Le journal " + label + " n'existe pas !"); - } - result = ServiceHelper.JOURNAL_NOT_EXIST; - } else // Sinon on modifie le journal - { - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - JournalDAO journalDAO = LimaCallaoDAOHelper - .getJournalDAO(topiaContext); - // Modifie le journal - journalModify.setPrefix(prefix); - journalModify.setDescription(description); - journalDAO.update(journalModify); - // Création BDD - topiaContext.commitTransaction(); - // Fermeture BDD - topiaContext.closeContext(); - result = ServiceHelper.RESPOND_SUCCESS; - } catch (TopiaException e) { - log.error(e); - } - } - return result; - }*/ - - /** - * Permet d'effacer un journal dans la base de données. - * - * ATTENTION : si un journal est associé avec des transactions, il est alors - * impossible de supprimer celui-ci. - * - * @param prefix préfixe du journal à supprimer - * @return - * @throws LimaException - */ - public void removeJournal(Journal journal) throws LimaException { - /*String result = ServiceHelper.RESPOND_ERROR; - Journal journalDelete = searchJournalWithTopiaId(topiaId); - // Si le journal n'existe pas - if (journalDelete == null) { - if (log.isWarnEnabled()) { - log.warn("Le journal " + topiaId + " n'existe pas !"); - } - result = ServiceHelper.JOURNAL_NOT_EXIST; - } else // Sinon on efface le journal - { - - // Vérifie si une transaction n'appartient pas à ce journal. - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TransactionDAO transactionDAO = LimaCallaoDAOHelper - .getTransactionDAO(topiaContext); - // Recherche au moins une transaction avec ce journal. - Transaction transaction = transactionDAO - .findByJournal(journalDelete); - // Il existe au moins une transaction - if (transaction != null) { - if (log.isWarnEnabled()) { - log.warn("Le journal " + topiaId - + " possède des transactions comptables !"); - } - result = ServiceHelper.JOURNAL_WITH_TRANSACTIONS; - } else { - - // Efface le journal - // Chargement du DAO - JournalDAO journalDAO = LimaCallaoDAOHelper - .getJournalDAO(topiaContext); - // Supprime le journal - journalDAO.delete(journalDelete); - // Création BDD - topiaContext.commitTransaction(); - // Fermeture BDD - topiaContext.closeContext(); - result = ServiceHelper.RESPOND_SUCCESS; - } - } catch (TopiaException e) { - log.error(e); - } - } - return result;*/ - - TopiaContext topiaTransaction = null; - try { - // basic check done, make check in database - // TODO move it into JTA - topiaTransaction = rootContext.beginTransaction(); - - // Vérifie si une transaction n'appartient pas à ce journal. - TransactionDAO transactionDAO = LimaCallaoDAOHelper.getTransactionDAO(topiaTransaction); - Transaction transaction = transactionDAO.findByJournal(journal); - if (transaction != null) { - throw new LimaBusinessException("Can't delete journal with transactions"); - } - - // test si un journal de ce nom existe deja - JournalDAO journalDAO = LimaCallaoDAOHelper.getJournalDAO(topiaTransaction); - journalDAO.delete(journal); - - // commit - topiaTransaction.commitTransaction(); - } - catch (TopiaException ex) { - if (topiaTransaction != null) { - try { - topiaTransaction.rollbackTransaction(); - } catch (TopiaException e) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - } - } - if (log.isErrorEnabled()) { - log.error("Error during create account", ex); - } - throw new LimaException("Can't create journal", ex); - } - finally { - if (topiaTransaction != null) { - try { - topiaTransaction.closeContext(); - } catch (TopiaException ex) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - throw new LimaException("Can't create journal", ex); - } - } - } - } - - /* - * Permet d'effacer un journal dans la base de données. - * ATTENTION : si un journal est associé avec des transactions, il est alors - * impossible de supprimer celui-ci. - * @param journalDTO journal au format DTO à supprimer - * @return - * - public String removeJournal(JournalDTO journalDTO) { - String result = removeJournal(journalDTO.getId()); - return result; - }*/ - -} Deleted: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/LogServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/LogServiceImpl.java 2010-03-25 13:03:22 UTC (rev 2813) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/LogServiceImpl.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -1,366 +0,0 @@ -/* - * *##% Callao LogServiceImpl - * Copyright (C) 2009 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.ejb; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.LimaConfig; -import org.chorem.lima.business.LimaException; -import org.chorem.lima.entity.EntryLog; -import org.chorem.lima.entity.EntryLogDAO; -import org.chorem.lima.entity.LimaCallaoDAOHelper; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaNotFoundException; - -/** - * Permet d'ajouter des logs au systeme. - * - * ATTENTION on ne peut supprimer un log. - * - * @author Rémi Chapelet - */ -public class LogServiceImpl { //implements LogService { - - /** log */ - private static final org.apache.commons.logging.Log log = LogFactory - .getLog(LogServiceImpl.class); - - private TopiaContext rootContext; - - - public LogServiceImpl() { - LimaConfig config = LimaConfig.getInstance(); - try { - rootContext = TopiaContextFactory.getContext(config.getOptions()); - } catch (TopiaNotFoundException ex) { - if (log.isErrorEnabled()) { - log.error("Can't init topia context", ex); - } - } - } - - /** - * Création d'un log dans le systeme. - * - * @param entryLog date de creation du log - * @throws LimaException - */ - public void addLog(EntryLog entryLog) throws LimaException { - /*String result = ServiceHelper.RESPOND_ERROR; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - EntryLogDAO logDAO = LimaCallaoDAOHelper.getEntryLogDAO(topiaContext); - // Creation du log - EntryLog newlog = logDAO.create(); - newlog.setLogDate(logDate); - newlog.setTransDate(transDate); - newlog.setVoucherRef(voucherRef); - newlog.setType(type); - newlog.setTransDesc(transDesc); - newlog.setEntryDesc(entryDesc); - newlog.setAmount(amount); - newlog.setDebit(debit); - newlog.setLettering(lettering); - // Création BDD - topiaContext.commitTransaction(); - // Fermeture BDD - topiaContext.closeContext(); - // Affichage pour les logs - String topiaId = newlog.getTopiaId(); - if (log.isInfoEnabled()) { - log.info("Log created: "+ topiaId); - } - result = ServiceHelper.RESPOND_SUCCESS; - }catch (TopiaException e) { - log.error(e); - } - return result;*/ - - TopiaContext transaction = null; - try { - // basic check done, make check in database - // TODO move it into JTA - transaction = rootContext.beginTransaction(); - - // creation - EntryLogDAO entryLogDAO = LimaCallaoDAOHelper - .getEntryLogDAO(transaction); - entryLogDAO.create(entryLog); - - // commit - transaction.commitTransaction(); - } catch (TopiaException ex) { - if (transaction != null) { - try { - transaction.rollbackTransaction(); - } catch (TopiaException e) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - } - } - if (log.isErrorEnabled()) { - log.error("Error during create account", ex); - } - throw new LimaException("Can't create entry log", ex); - } finally { - if (transaction != null) { - try { - transaction.closeContext(); - } catch (TopiaException ex) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - throw new LimaException("Can't create entry log", ex); - } - } - } - } - - /* - * Création d'un log à partir d'un log DTO. - * @param logDTO log en format DTO qu'on souhaite créer - * @return - * - public String addLog (LogDTO logDTO) { - String result = ServiceHelper.RESPOND_ERROR; - // Vérifie si logDTO existe - if (logDTO != null) - { - result = addLog(logDTO.getLogDate(),logDTO.getTransDate(),logDTO.getType(), - logDTO.getVoucherRef(),logDTO.getTransDesc(),logDTO.getEntryDesc(), - logDTO.getAmount(),logDTO.isDebit(),logDTO.getLettering()); - } - return result; - }*/ - - /** - * Recherche tous les logs dans la base de donnees. - * - * @return la liste des logs - * @throws LimaException - */ - public List<EntryLog> listeAllLog() throws LimaException { - /*List<EntryLog> listelog = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - EntryLogDAO logDAO = LimaCallaoDAOHelper - .getEntryLogDAO(topiaContext); - // recherche des log - listelog = logDAO.findAll(); - // Fermeture BDD - topiaContext.closeContext(); - if (log.isInfoEnabled()) { - log.info("Search all logs"); - } - } catch (TopiaException e) { - log.error(e); - } - return listelog;*/ - - List<EntryLog> entryLogsList = new ArrayList<EntryLog>(); - TopiaContext transaction = null; - try { - // basic check done, make check in database - // TODO move it into JTA - transaction = rootContext.beginTransaction(); - - // creation - EntryLogDAO entryLogDAO = LimaCallaoDAOHelper - .getEntryLogDAO(transaction); - List<EntryLog> entryLogs = entryLogDAO.findAll(); - entryLogsList.addAll(entryLogs); - - // commit - transaction.commitTransaction(); - } catch (TopiaException ex) { - if (transaction != null) { - try { - transaction.rollbackTransaction(); - } catch (TopiaException e) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - } - } - if (log.isErrorEnabled()) { - log.error("Error during create account", ex); - } - throw new LimaException("Can't create entry log", ex); - } finally { - if (transaction != null) { - try { - transaction.closeContext(); - } catch (TopiaException ex) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - throw new LimaException("Can't create entry log", ex); - } - } - } - - return entryLogsList; - } - - /* - * Permet de renvoyer tous les logs au format DTO. - * @return - * - public List<LogDTO> listeAllLogDTO() { - List<LogDTO> listLogDTO = new ArrayList<LogDTO>(); - // On recherche tous les logs. - List<EntryLog> listLog = listeAllLog(); - // Pour chaque log, on le converti en logDTO et on l'ajoute à la nouvelle liste de DTO - for (EntryLog log : listLog) { - // conerti de l'entity en DTO - LogDTO logDTO = convertLog.logEntityToDto(log); - // Ajoute à la liste des logs DTO - listLogDTO.add(logDTO); - } - return listLogDTO; - }*/ - - /* - * Renvoie une liste de tous les logs suivant la date de creation - * @param datecreate date de creation des logs recherchés - * @return une liste des logs trouves - * - public List<EntryLog> searchLogWithDateCreate(Date dateCreate) { - List<EntryLog> listelog = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - EntryLogDAO logDAO = LimaCallaoDAOHelper - .getEntryLogDAO(topiaContext); - // recherche des log - listelog = logDAO.findAllByLogDate(dateCreate); - // Fermeture BDD - topiaContext.closeContext(); - if (log.isInfoEnabled()) { - log.info("Log(s) find : " + listelog.size() + "log(s)"); - } - } catch (TopiaException e) { - log.error(e); - } - return listelog; - }*/ - - /* - * Permet de rechercher tous les logs suivant la date de création, c'est à - * dire de l'opération effectuée sur une entry à un jour précis, et qui a - * déclenchée automatiquement une création de log. - * La méthode renvoie sous forme de liste, en convertissant les objets - * entitys en DTO. - * @param dateCreate date de création des logs recherchés - * @return - * - public List<LogDTO> searchLogDTOWithDateCreate(Date dateCreate) { - List<LogDTO> listLogDTO = new ArrayList<LogDTO>(); - // On recherche tous les logs suivant la date de création. - List<EntryLog> listLog = searchLogWithDateCreate(dateCreate); - // Pour chaque log, on le converti en logDTO et on l'ajoute à la nouvelle liste de DTO - for (EntryLog log : listLog) { - // conerti de l'entity en DTO - LogDTO logDTO = convertLog.logEntityToDto(log); - // Ajoute à la liste des logs DTO - listLogDTO.add(logDTO); - } - return listLogDTO; - }*/ - - /* - * Recherche un log avec son identifiant topiaId. - * @param topiaId identifiant d'un log - * @return - * - public EntryLog searchLogWithTopiaId(String topiaId) { - EntryLog logSearch = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - EntryLogDAO logDAO = LimaCallaoDAOHelper - .getEntryLogDAO(topiaContext); - // Creation du journal - logSearch = logDAO.findByTopiaId(topiaId); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return logSearch; - }*/ - - /* - * Efface un log : uniquement utilisé pour supprimer les logs dans les tests - * unitaires. - * @param topiaId identifiant du log à supprimer - * @return - * - public String removeLog(String topiaId) { - String result = ServiceHelper.RESPOND_ERROR; - EntryLog logDelete = searchLogWithTopiaId(topiaId); - // Si le log n'existe pas - if (logDelete == null) { - if (log.isWarnEnabled()) { - log.warn("Le log " + topiaId + " n'existe pas !"); - } - } else // Sinon on efface le log - { - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - EntryLogDAO logDAO = LimaCallaoDAOHelper - .getEntryLogDAO(topiaContext); - // Supprime le log - logDAO.delete(logDelete); - // Création BDD - topiaContext.commitTransaction(); - // Fermeture BDD - topiaContext.closeContext(); - result = ServiceHelper.RESPOND_SUCCESS; - } catch (TopiaException e) { - log.error(e); - } - } - return result; - }*/ - - /* - * Permet de supprimer un log à partir de son DTO. - * @param logDTO log à supprimer - * @return - * - public String removeLog(LogDTO logDTO) { - String result = removeLog(logDTO.getId()); - return result; - }*/ -} Deleted: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/PeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/PeriodServiceImpl.java 2010-03-25 13:03:22 UTC (rev 2813) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/PeriodServiceImpl.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -1,505 +0,0 @@ -/* - * *##% Callao PeriodServiceImpl - * Copyright (C) 2009 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.ejb; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.LimaConfig; -import org.chorem.lima.entity.Period; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.TopiaNotFoundException; - -/** - * Gestion des périodes. - * Chaque période doit posséder 12 timespans mensuels. - * Une période ne peut être supprimée et débloquée. - * - * @author Rémi Chapelet - */ -public class PeriodServiceImpl { //implements PeriodService { - - private static final Log log = LogFactory.getLog(PeriodServiceImpl.class); - - private TopiaContext rootContext; - - private TimeSpanServiceImpl timeSpanServiceImpl = new TimeSpanServiceImpl(); - - public PeriodServiceImpl() { - LimaConfig config = LimaConfig.getInstance(); - try { - rootContext = TopiaContextFactory.getContext(config.getOptions()); - } catch (TopiaNotFoundException ex) { - if (log.isErrorEnabled()) { - log.error("Can't init topia context", ex); - } - } - } - - /** - * Permet de créer une période principale. Elle a une durée de un an, - * composées de 12 périodes mensuelles. Elle correspond à l'exercice - * comptable. Pour créer une nouvelle période, la précédente doit être - * obligatoirement clôturée. - * @param beginTimeSpan date début de période - * @param endTimeSpan date fin de période - * @param lock Vrai si la période est bloquée - * @return - */ - public void createPeriod(Period period /*Date beginTimeSpan, Date endTimeSpan, boolean lock*/) { - /*// Par défaut lock est à false - lock = false; - String result = ServiceHelper.RESPOND_ERROR; - - try { - boolean correctPeriod = false; - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - PeriodDAO periodDAO = LimaCallaoDAOHelper - .getPeriodDAO(topiaContext); - // Creation de la periodDate - PeriodDates newPeriod = new PeriodDates(beginTimeSpan, endTimeSpan); - - // Creation de la période - Period period = periodDAO.create(); - period.setBeginPeriod(newPeriod.getFromDate()); - period.setEndPeriod(newPeriod.getThruDate()); - period.setLocked(lock); - // Vérification si la période est correcte - correctPeriod = isCorrectPeriod(period); - if (correctPeriod) { - // Si elle est correcte : Création BDD - topiaContext.commitTransaction(); - if (log.isInfoEnabled()) { - log.info("Ajout exercice du " + beginTimeSpan.toString() - + " au " + endTimeSpan.toString()); - } - - //Ajout des timeSpans mensuels - //Par défaut, il prend seulement la date beginTimeSpan, et calcule - //la date de fin, c'est pourquoi il est laissé deux fois "beginTimeSpan" - TimeSpanServiceImpl timeSpanImpl = new TimeSpanServiceImpl(); - boolean stop = false; // En cas d'erreur lors de la création d'un timeSpan. - - List<Date> monthList = newPeriod.getMonths(); - - int max = monthList.size(); - log.debug("la periode fait:" + max); - for (int i = 0; i < max; i++) { - // Création timeSpan - result = timeSpanImpl.createTimeSpan(monthList.get(i), - monthList.get(i), period, false); - if (result.equals(ServiceHelper.RESPOND_ERROR)) { - stop = true; - if (log.isErrorEnabled()) { - log.error("Erreur lors de la création des " + max - + " timeSpans"); - } - result = ServiceHelper.PERIOD_CREATE_TIMESPANS; - } - // Supprimer la periode si stop = true - } - if (stop == false) { - result = ServiceHelper.RESPOND_SUCCESS; - } - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return result; */ - } - - /* - * Permet de créer une période à partir d'une période DTO. - * @param periodDTO période à créer au format DTO. - * @return - * - public String createPeriod(PeriodDTO periodDTO) { - String result = createPeriod(periodDTO.getBeginPeriod(), periodDTO - .getEndPeriod(), false); - // Tous les timeSpans sont automatiquement créés avec la méthode createPeriod - return result; - }*/ - - /* - * Permet de vérifier si la période est correcte (aucun chevauchement avec - * les autres périodes, période(s) précédente(s) bloquée(s), formée de 1 à 24 - * mois). - * @param period période à tester si elle est correcte - * @return - * - private boolean isCorrectPeriod(Period period) { - // Calcul du nombre de mois pour que la période soit valide (12 mois) - int number_months = dateUtil.numberOfMonths(period.getBeginPeriod(), - period.getEndPeriod()); - boolean result = true; - - if (number_months == 0 && number_months >= 24) // Periode de 1mois a 24 mois - { - if (log.isErrorEnabled()) { - log.error("Période du " - + period.getBeginPeriod() - + " au " - + period.getEndPeriod() - + " : L'exercice doit faire au minimum 1 mois et au maximum 24 mois"); - } - result = false; - } else { - // Période(s) précédente(s) bloquée(s). - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - PeriodDAO periodDAO = LimaCallaoDAOHelper - .getPeriodDAO(topiaContext); - // Recherche les périodes qui ne sont pas bloquées. - List<Period> listePeriod = periodDAO.findAllByLocked(false); - // Recherche la dernière période, les dates doivent se suivre - Date date_search = period.getBeginPeriod(); - Period previousPeriod = periodDAO.findByEndPeriod(dateUtil - .previousDay(date_search)); - // Nombre de périodes dans la base - int number_period = periodDAO.findAll().size(); - // Fermeture BDD - topiaContext.closeContext(); - // Si il y a au moins une période trouvée - if (!(listePeriod.isEmpty())) { - if (log.isErrorEnabled()) { - log.error("Il existe au moins une période précédente non bloquée !"); - } - result = false; - } - // Si la période précédente correspond au jour précédent - // et vérifie si ce n'est pas la première période - if (previousPeriod == null && number_period != 0) { - if (log.isErrorEnabled()) { - log.error("Votre période doit être collée " - + "aux autres périodes !" - + date_search.toString() + " PPP " - + dateUtil.previousDay(date_search).toString()); - } - result = false; - } - } catch (TopiaException e) { - log.error(e); - } - } - return result; - }*/ - - /* - * Cette méthode permet de bloquer une période. Elle doit vérifier que - * tous les timeSpans mensuels sont bloqués. - * @param - * @return - * - public String blockPeriod(Period period) { - String result = ServiceHelper.RESPOND_ERROR; - // La période ne doit pas être nulle - if (period != null) { - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Recherche tous les timeSpans de la période non bloquées - List<TimeSpan> listeTimeSpan = timeSpanDAO - .findAllByPeriod(period); - boolean existTimeSpanNotBlock = false; - for (TimeSpan timeSpan : listeTimeSpan) { - // Si timeSpan non bloqué - if (!timeSpan.getLocked()) { - existTimeSpanNotBlock = true; - if (log.isErrorEnabled()) { - log.error("Le timeSpan du " - + timeSpan.getBeginTimeSpan().toString() - + " au " - + timeSpan.getEndTimeSpan().toString() - + " non bloqué !"); - } - result = ServiceHelper.PERIOD_TIMESPAN_NOT_BLOCK; - } - } - // Si il n'existe pas de timeSpan non bloqué - if (!(existTimeSpanNotBlock)) { - // Bloque la période - period.setLocked(true); - // Chargement du DAO - PeriodDAO periodDAO = LimaCallaoDAOHelper - .getPeriodDAO(topiaContext); - periodDAO.update(period); - // Création BDD - topiaContext.commitTransaction(); - result = ServiceHelper.RESPOND_SUCCESS; - if (log.isInfoEnabled()) { - log.info("Période " - + period.getBeginPeriod().toString() + " au " - + period.getEndPeriod().toString() - + " bloquée avec succès."); - } - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - } - return result; - }*/ - - /* - * Permet de bloquer une période. Avec la périodeDTO passée en paramètre, on - * effectue une recherche avec la date de début pour récupérer la période - * dans la base de données. Il est possible de l'identifier avec son topiaId, - * mais il y a plus de risque que cette mentien ne soit pas renseignée dans - * l'objet periodDTO. - * @param periodDTO - * @return - * - public String blockPeriod(PeriodDTO periodDTO) { - // Recherche de la période - Period period = searchPeriodWithDate(periodDTO.getBeginPeriod()); - String result = blockPeriod(period); - return result; - }*/ - - /* - * Permet de bloquer TOUS les timeSpans de la période - * @param period - * @return - * - public String blockAllTimeSpanOfPeriod(Period period) { - String result = ServiceHelper.RESPOND_ERROR; - if (period == null) { - if (log.isErrorEnabled()) { - log.error("La période ne peut bloquer ses périodes mensuelles, " - + "il faut une période en entrée."); - } - } else { - // On bloque chaque timeSpan - boolean ErrorBlockTimeSpan = false; - List<TimeSpanDTO> listTimeSpanDTO = timeSpanServiceImpl - .searchListTimeSpanDTO(period); - // tri la liste des timeSpans dans l'ordre croissant des dates - Collections.sort(listTimeSpanDTO); - for (TimeSpanDTO timeSpanDTO : listTimeSpanDTO) { - result = timeSpanServiceImpl.blockTimeSpan(timeSpanDTO); - if (result.equals(ServiceHelper.RESPOND_ERROR)) { - ErrorBlockTimeSpan = true; - } - } - // Si il n'y a pas eu d'erreurs pour bloquer les timespans - if (!ErrorBlockTimeSpan) { - result = ServiceHelper.RESPOND_SUCCESS; - } else { - if (log.isErrorEnabled()) { - log.error("Impossible de bloquer tous les timeSpans."); - } - result = ServiceHelper.PERIOD_ALL_TIMESPAN; - } - } - return result; - }*/ - - /* - * Cette méthode est semblable à searchPeriodWithDateFirst. Elle permet - * de rechercher une période sans forcément connaître la date de départ. On - * donne une date quelconque, et elle retourne la période correspondante. - * @param d - * @return - * - public Period searchPeriodWithDate(Date d) { - Period period = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - PeriodDAO periodDAO = LimaCallaoDAOHelper - .getPeriodDAO(topiaContext); - // Recherche de toutes les périodes - List<Period> listePeriod = periodDAO.findAll(); - // Fermeture BDD - topiaContext.closeContext(); - // Recherche de la période - for (Period periodSearch : listePeriod) { - // Recherche si la date d est entre la date de début et fin de la période - boolean periodBetweenDate = dateUtil.betweenDate(d, - periodSearch.getBeginPeriod(), periodSearch - .getEndPeriod()); - // Si la date est comprise dans les limites de la période - if (periodBetweenDate) { - period = periodSearch; - } - } - } catch (TopiaException e) { - log.error(e); - } - return period; - }*/ - - /* - * Permet de rechercher une période au format DTO avec une date. Cette date - * peut être quelconque (pas obligatoire d'être le premier jour de la période - * par exemple). - * @param d date comprise dans la période qu'on souhaite rechercher - * @return - * - public PeriodDTO searchPeriodDTOWithDate(Date d) { - Period period = searchPeriodWithDate(d); - // Converti la période en PeriodDTO - PeriodDTO periodDTO = convertPeriod.periodEntityToDto(period); - return periodDTO; - }*/ - - /* - * Permet de renvoyer tous les périodes en format DTO, avec tous les timeSpans - * en format DTO également. - * @return - * - public List<PeriodDTO> getAllPeriod() { - ArrayList<PeriodDTO> listAllPeriodDTO = new ArrayList<PeriodDTO>(); - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - PeriodDAO periodDAO = LimaCallaoDAOHelper - .getPeriodDAO(topiaContext); - // Recherche de toutes les périodes - List<Period> listePeriod = periodDAO.findAll(); - // Transforme les périodes en DTO - for (Period period : listePeriod) { - PeriodDTO periodDTO = convertPeriod.periodEntityToDto(period); - listAllPeriodDTO.add(periodDTO); - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return listAllPeriodDTO; - }*/ - - /* - * Recherche une période précise, avec son identifiant topiaId. - * @param topiaId identifiant de la période - * @return - * - public Period searchPeriodWithTopiaId(String topiaId) { - Period periodSearch = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - PeriodDAO periodDAO = LimaCallaoDAOHelper - .getPeriodDAO(topiaContext); - // Creation du journal - periodSearch = periodDAO.findByTopiaId(topiaId); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return periodSearch; - }*/ - - - /* - * Efface une période dans la base de données. Tous les timeSpans sont - * également effacés. Cette méthode est uniquement utilisée pour les tests - * unitaires. - * @param period - * @return - * - public String removePeriod(String topiaId) { - String result = ServiceHelper.RESPOND_ERROR; - Period periodDelete = searchPeriodWithTopiaId(topiaId); - // Si la période n'existe pas - if (periodDelete == null) { - if (log.isWarnEnabled()) { - log.warn("La période " + topiaId + " n'existe pas !"); - } - result = ServiceHelper.PERIOD_NOT_EXIST; - } else // Sinon on efface la période - { - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - PeriodDAO periodDAO = LimaCallaoDAOHelper - .getPeriodDAO(topiaContext); - // Débloque la période - periodDelete.setLocked(false); - // Mise à jour dans la bdd - periodDAO.update(periodDelete); - // Création BDD - topiaContext.commitTransaction(); - - // Supprime les timeSpans de la période - List<TimeSpanDTO> listTimeSpanDTO = timeSpanServiceImpl - .searchListTimeSpanDTO(periodDelete); - // tri la liste des timeSpans dans l'ordre décroissant des dates - Collections.sort(listTimeSpanDTO, Collections.reverseOrder()); - // Débloque les timeSpans - for (TimeSpanDTO timeSpanDTO : listTimeSpanDTO) { - TimeSpan timeSpan = timeSpanServiceImpl - .searchTimeSpanByDate(timeSpanDTO); - // Si le timeSpan est bloqué - if (timeSpanDTO.isLocked()) { - // débloque le timeSpan - timeSpanServiceImpl.unblockTimeSpan(timeSpan); - } - } - // Efface les timeSpans - for (TimeSpanDTO timeSpanDTO : listTimeSpanDTO) { - TimeSpan timeSpan = timeSpanServiceImpl - .searchTimeSpanByDate(timeSpanDTO); - // efface le timeSpan - timeSpanServiceImpl.removeTimeSpan(timeSpan); - } - - - //Supprime la période - periodDAO.delete(periodDelete); - // Création BDD - topiaContext.commitTransaction(); - // Fermeture BDD - topiaContext.closeContext(); - result = ServiceHelper.RESPOND_SUCCESS; - } catch (TopiaException e) { - log.error(e); - } - } - return result; - }*/ - - /* - * Permet d'effacer une période au format DTO. - * @param periodDTO la période à supprimer - * @return - * - public String removePeriod(PeriodDTO periodDTO) { - String result = removePeriod(periodDTO.getId()); - return result; - }*/ -} Copied: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/RecordServiceImpl.java (from rev 2811, trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/LogServiceImpl.java) =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/RecordServiceImpl.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/RecordServiceImpl.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -0,0 +1,366 @@ +/* + * *##% Callao LogServiceImpl + * Copyright (C) 2009 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.ejb; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.LimaConfig; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.entity.Record; +import org.chorem.lima.entity.RecordDAO; +import org.chorem.lima.entity.LimaCallaoDAOHelper; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaNotFoundException; + +/** + * Permet d'ajouter des logs au systeme. + * + * ATTENTION on ne peut supprimer un log. + * + * @author Rémi Chapelet + */ +public class RecordServiceImpl { //implements LogService { + + /** log */ + private static final org.apache.commons.logging.Log log = LogFactory + .getLog(RecordServiceImpl.class); + + private TopiaContext rootContext; + + + public RecordServiceImpl() { + LimaConfig config = LimaConfig.getInstance(); + try { + rootContext = TopiaContextFactory.getContext(config.getOptions()); + } catch (TopiaNotFoundException ex) { + if (log.isErrorEnabled()) { + log.error("Can't init topia context", ex); + } + } + } + + /** + * Création d'un log dans le systeme. + * + * @param entryLog date de creation du log + * @throws LimaException + */ + public void addLog(Record entryLog) throws LimaException { + /*String result = ServiceHelper.RESPOND_ERROR; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + EntryLogDAO logDAO = LimaCallaoDAOHelper.getEntryLogDAO(topiaContext); + // Creation du log + EntryLog newlog = logDAO.create(); + newlog.setLogDate(logDate); + newlog.setTransDate(transDate); + newlog.setVoucherRef(voucherRef); + newlog.setType(type); + newlog.setTransDesc(transDesc); + newlog.setEntryDesc(entryDesc); + newlog.setAmount(amount); + newlog.setDebit(debit); + newlog.setLettering(lettering); + // Création BDD + topiaContext.commitTransaction(); + // Fermeture BDD + topiaContext.closeContext(); + // Affichage pour les logs + String topiaId = newlog.getTopiaId(); + if (log.isInfoEnabled()) { + log.info("Log created: "+ topiaId); + } + result = ServiceHelper.RESPOND_SUCCESS; + }catch (TopiaException e) { + log.error(e); + } + return result;*/ + + TopiaContext transaction = null; + try { + // basic check done, make check in database + // TODO move it into JTA + transaction = rootContext.beginTransaction(); + + // creation + RecordDAO recordDAO = LimaCallaoDAOHelper + .getRecordDAO(transaction); + recordDAO.create(entryLog); + + // commit + transaction.commitTransaction(); + } catch (TopiaException ex) { + if (transaction != null) { + try { + transaction.rollbackTransaction(); + } catch (TopiaException e) { + if (log.isErrorEnabled()) { + log.error("Error during rollback context", ex); + } + } + } + if (log.isErrorEnabled()) { + log.error("Error during create account", ex); + } + throw new LimaException("Can't create entry log", ex); + } finally { + if (transaction != null) { + try { + transaction.closeContext(); + } catch (TopiaException ex) { + if (log.isErrorEnabled()) { + log.error("Error during rollback context", ex); + } + throw new LimaException("Can't create entry log", ex); + } + } + } + } + + /* + * Création d'un log à partir d'un log DTO. + * @param logDTO log en format DTO qu'on souhaite créer + * @return + * + public String addLog (LogDTO logDTO) { + String result = ServiceHelper.RESPOND_ERROR; + // Vérifie si logDTO existe + if (logDTO != null) + { + result = addLog(logDTO.getLogDate(),logDTO.getTransDate(),logDTO.getType(), + logDTO.getVoucherRef(),logDTO.getTransDesc(),logDTO.getEntryDesc(), + logDTO.getAmount(),logDTO.isDebit(),logDTO.getLettering()); + } + return result; + }*/ + + /** + * Recherche tous les logs dans la base de donnees. + * + * @return la liste des logs + * @throws LimaException + */ + public List<Record> listeAllLog() throws LimaException { + /*List<EntryLog> listelog = null; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + EntryLogDAO logDAO = LimaCallaoDAOHelper + .getEntryLogDAO(topiaContext); + // recherche des log + listelog = logDAO.findAll(); + // Fermeture BDD + topiaContext.closeContext(); + if (log.isInfoEnabled()) { + log.info("Search all logs"); + } + } catch (TopiaException e) { + log.error(e); + } + return listelog;*/ + + List<Record> entryLogsList = new ArrayList<Record>(); + TopiaContext transaction = null; + try { + // basic check done, make check in database + // TODO move it into JTA + transaction = rootContext.beginTransaction(); + + // creation + RecordDAO recordDAO = LimaCallaoDAOHelper + .getRecordDAO(transaction); + List<Record> entryLogs = recordDAO.findAll(); + entryLogsList.addAll(entryLogs); + + // commit + transaction.commitTransaction(); + } catch (TopiaException ex) { + if (transaction != null) { + try { + transaction.rollbackTransaction(); + } catch (TopiaException e) { + if (log.isErrorEnabled()) { + log.error("Error during rollback context", ex); + } + } + } + if (log.isErrorEnabled()) { + log.error("Error during create account", ex); + } + throw new LimaException("Can't create entry log", ex); + } finally { + if (transaction != null) { + try { + transaction.closeContext(); + } catch (TopiaException ex) { + if (log.isErrorEnabled()) { + log.error("Error during rollback context", ex); + } + throw new LimaException("Can't create entry log", ex); + } + } + } + + return entryLogsList; + } + + /* + * Permet de renvoyer tous les logs au format DTO. + * @return + * + public List<LogDTO> listeAllLogDTO() { + List<LogDTO> listLogDTO = new ArrayList<LogDTO>(); + // On recherche tous les logs. + List<EntryLog> listLog = listeAllLog(); + // Pour chaque log, on le converti en logDTO et on l'ajoute à la nouvelle liste de DTO + for (EntryLog log : listLog) { + // conerti de l'entity en DTO + LogDTO logDTO = convertLog.logEntityToDto(log); + // Ajoute à la liste des logs DTO + listLogDTO.add(logDTO); + } + return listLogDTO; + }*/ + + /* + * Renvoie une liste de tous les logs suivant la date de creation + * @param datecreate date de creation des logs recherchés + * @return une liste des logs trouves + * + public List<EntryLog> searchLogWithDateCreate(Date dateCreate) { + List<EntryLog> listelog = null; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + EntryLogDAO logDAO = LimaCallaoDAOHelper + .getEntryLogDAO(topiaContext); + // recherche des log + listelog = logDAO.findAllByLogDate(dateCreate); + // Fermeture BDD + topiaContext.closeContext(); + if (log.isInfoEnabled()) { + log.info("Log(s) find : " + listelog.size() + "log(s)"); + } + } catch (TopiaException e) { + log.error(e); + } + return listelog; + }*/ + + /* + * Permet de rechercher tous les logs suivant la date de création, c'est à + * dire de l'opération effectuée sur une entry à un jour précis, et qui a + * déclenchée automatiquement une création de log. + * La méthode renvoie sous forme de liste, en convertissant les objets + * entitys en DTO. + * @param dateCreate date de création des logs recherchés + * @return + * + public List<LogDTO> searchLogDTOWithDateCreate(Date dateCreate) { + List<LogDTO> listLogDTO = new ArrayList<LogDTO>(); + // On recherche tous les logs suivant la date de création. + List<EntryLog> listLog = searchLogWithDateCreate(dateCreate); + // Pour chaque log, on le converti en logDTO et on l'ajoute à la nouvelle liste de DTO + for (EntryLog log : listLog) { + // conerti de l'entity en DTO + LogDTO logDTO = convertLog.logEntityToDto(log); + // Ajoute à la liste des logs DTO + listLogDTO.add(logDTO); + } + return listLogDTO; + }*/ + + /* + * Recherche un log avec son identifiant topiaId. + * @param topiaId identifiant d'un log + * @return + * + public EntryLog searchLogWithTopiaId(String topiaId) { + EntryLog logSearch = null; + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + EntryLogDAO logDAO = LimaCallaoDAOHelper + .getEntryLogDAO(topiaContext); + // Creation du journal + logSearch = logDAO.findByTopiaId(topiaId); + // Fermeture BDD + topiaContext.closeContext(); + } catch (TopiaException e) { + log.error(e); + } + return logSearch; + }*/ + + /* + * Efface un log : uniquement utilisé pour supprimer les logs dans les tests + * unitaires. + * @param topiaId identifiant du log à supprimer + * @return + * + public String removeLog(String topiaId) { + String result = ServiceHelper.RESPOND_ERROR; + EntryLog logDelete = searchLogWithTopiaId(topiaId); + // Si le log n'existe pas + if (logDelete == null) { + if (log.isWarnEnabled()) { + log.warn("Le log " + topiaId + " n'existe pas !"); + } + } else // Sinon on efface le log + { + try { + // Acces BDD + TopiaContext topiaContext = rootContext.beginTransaction(); + // Chargement du DAO + EntryLogDAO logDAO = LimaCallaoDAOHelper + .getEntryLogDAO(topiaContext); + // Supprime le log + logDAO.delete(logDelete); + // Création BDD + topiaContext.commitTransaction(); + // Fermeture BDD + topiaContext.closeContext(); + result = ServiceHelper.RESPOND_SUCCESS; + } catch (TopiaException e) { + log.error(e); + } + } + return result; + }*/ + + /* + * Permet de supprimer un log à partir de son DTO. + * @param logDTO log à supprimer + * @return + * + public String removeLog(LogDTO logDTO) { + String result = removeLog(logDTO.getId()); + return result; + }*/ +} Deleted: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TimeSpanServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TimeSpanServiceImpl.java 2010-03-25 13:03:22 UTC (rev 2813) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TimeSpanServiceImpl.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -1,534 +0,0 @@ -/* - * *##% Callao TimeSpanServiceImpl - * Copyright (C) 2009 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.ejb; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.LimaConfig; -import org.chorem.lima.entity.TimeSpan; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.TopiaNotFoundException; - -/** - * Gestion des périodes intermédiaires durant l'exercice. - * Chaque timeSpan sera fixe, et devra correspondre à un mois complet. - * - * @author Rémi Chapelet - */ -public class TimeSpanServiceImpl { //implements TimeSpanService { - - /** log */ - private static final Log log = LogFactory.getLog(TimeSpanServiceImpl.class); - - private TopiaContext rootContext; - - private static TransactionServiceImpl transactionServiceImpl = new TransactionServiceImpl(); - - public TimeSpanServiceImpl() { - LimaConfig config = LimaConfig.getInstance(); - try { - rootContext = TopiaContextFactory.getContext(config.getOptions()); - } catch (TopiaNotFoundException ex) { - if (log.isErrorEnabled()) { - log.error("Can't init topia context", ex); - } - } - } - - /** - * Création d'une période timeSpan mensuelle avec une date de début et de fin. Une période - * peut être bloquée ou non. - * @param beginTimeSpan date de début de période - * @param endTimeSpan date de fin de période - * @param locked est à vrai si la période doit être bloquée. - * @return - */ - public void createTimeSpan(TimeSpan timeSpan /*Date beginTimeSpan, Date endTimeSpan, - Period period, boolean locked*/) { -/* - // timeSpan correspond à une période mensuelle. - // La fonction va donc prendre seulement pour date de référence la - // date beginTimeSpan. Elle calcule automatiquement la date de fin - // suivant le mois. - DateUtil dateutil = new DateUtil(); - // Initialise la date de début au premier du mois - beginTimeSpan = dateutil.InitDateFirstDayMonth(beginTimeSpan); - // Initialise la date de fin au dernier du mois - endTimeSpan = dateutil.InitDateEndDayMonth(beginTimeSpan); - if (log.isInfoEnabled()) { - log.info("Nouveau timeSpan du " + beginTimeSpan.toString() + " au " - + endTimeSpan.toString()); - } - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Creation du timespan - TimeSpan newtimeSpan = timeSpanDAO.create(); - newtimeSpan.setBeginTimeSpan(beginTimeSpan); - newtimeSpan.setEndTimeSpan(endTimeSpan); - newtimeSpan.setLocked(locked); - newtimeSpan.setPeriod(period); - // Création BDD - topiaContext.commitTransaction(); - // Fermeture BDD - topiaContext.closeContext(); - if (log.isInfoEnabled()) { - log.info("Ajout avec succes du timeSpan"); - } - return ServiceHelper.RESPOND_SUCCESS; - } catch (TopiaException e) { - log.error(e); - return ServiceHelper.RESPOND_ERROR; - }*/ - } - - /* - * Permet de trouver un timespan directement avec une date. La date peut - * être quelconque. Exemple : d = 17 sept 2000, renvoie la période du - * 1 sept au 30 sept 2000. - * @param d - * @return - * - public TimeSpan searchTimeSpanByDate(Date d) { - TimeSpan timeSpan = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Par précaution, on initialise la date au debut du mois - DateUtil dateutil = new DateUtil(); - // Recherche du timeSpan - Date searchDate = dateutil.InitDateFirstDayMonth(d); - timeSpan = timeSpanDAO.findByBeginTimeSpan(searchDate); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return timeSpan; - }*/ - - /* - * Recherche un timeSpan précis, avec sa date de création. - * @param timeSpanDTO timeSpan au format DTO qu'on recherche - * @return - * - public TimeSpan searchTimeSpanByDate(TimeSpanDTO timeSpanDTO) { - TimeSpan timeSpan = searchTimeSpanByDate(timeSpanDTO.getBeginTimeSpan()); - return timeSpan; - }*/ - - /* - * Recherche un timeSpan UNIQUE. Celui est identifié par son topiaId. - * @param topiaId Identifiant du timeSpan recherché - * @return - * - public TimeSpan searchTimeSpanWithTopiaId(String topiaId) { - TimeSpan timeSpan = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Recherche du timeSpan - timeSpan = timeSpanDAO.findByTopiaId(topiaId); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return timeSpan; - }*/ - - /* - * Permet de rechercher un timeSpan à l'aide d'une date. Il fait appel - * à la méthode searchTimeSpanByDate. - * La méthode renvoie un objet DTO. - * @param d - * @return - * - public TimeSpanDTO searchTimeSpanDTOByDate(Date d) { - TimeSpan timeSpan = searchTimeSpanByDate(d); - TimeSpanDTO timeSpanDTO = convertTimeSpan.timeSpanEntityToDto(timeSpan); - return timeSpanDTO; - }*/ - - /* - * Permet de faire une recherche de tous les timeSpans d'une période. - * @param period - * @return - * - public List<TimeSpan> searchListTimeSpan(Period period) { - List<TimeSpan> listTimeSpan = null; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Recherche les timeSpans avec cette période - listTimeSpan = timeSpanDAO.findAllByPeriod(period); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return listTimeSpan; - }*/ - - /* - * Permet de rechercher tous les timeSpans suivant une période donnée. - * Chaque timeSpan est converti ensuite en DTO. - * @param period - * @return - * - public List<TimeSpanDTO> searchListTimeSpanDTO(Period period) { - List<TimeSpanDTO> listTimeSpanDTO = new ArrayList<TimeSpanDTO>(); - List<TimeSpan> listTimeSpan = searchListTimeSpan(period); - for (TimeSpan timeSpan : listTimeSpan) { - TimeSpanDTO timeSpanDTO = convertTimeSpan - .timeSpanEntityToDto(timeSpan); - listTimeSpanDTO.add(timeSpanDTO); - } - return listTimeSpanDTO; - }*/ - - /* - * Permet de bloquer un timespan, celle-ci ne doit pas être bloquée. - * La fonction doit s'assurer que les timeSpans précédents doivent être - * bloqués. - * Les transactions doivent être équilibrées - * @param timespan période qui doit être fermée - * @param period période (12 smois) - * - public String blockTimeSpan(TimeSpan timespan) { - String result = ServiceHelper.RESPOND_ERROR; - // Si la période n'est pas déjà fermée. - if (timespan.getLocked()) { - if (log.isInfoEnabled()) { - log.info("Timespan deja bloqué !"); - } - } else { - Period period = getPeriodWithTimeSpan(timespan); - if (period.getLocked()) { - if (log.isErrorEnabled()) { - log.error("La période du timespan est bloquée !"); - } - } else { - // Vérifie si tous les timeSpans précédents sont bloqués - boolean AllTimeSpanBlock = alltimeSpanBlocked(timespan, period); - if (AllTimeSpanBlock) { - // Enregistrement dans la base de données - try { - // Acces BDD - TopiaContext topiaContext = rootContext - .beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - - // Vérifie si les transactons sont équilibrées - List<Transaction> listTransaction = transactionServiceImpl - .searchListTransactionWithTimeSpan(timespan); - boolean isTransactionBalanced = true; - boolean existTransactionNotBalanced = false; - for (Transaction transaction : listTransaction) { - isTransactionBalanced = transactionServiceImpl - .isTransactionBalanced(transaction); - if (!isTransactionBalanced) { - if (log.isInfoEnabled()) { - log.info("La transaction n'est pas bloquée."); - } - existTransactionNotBalanced = true; - } - } - if (!existTransactionNotBalanced) { - // Bloque la période - timespan.setLocked(true); - // Mise à jour de timespan dans la BDD - timeSpanDAO.update(timespan); - // Création BDD - topiaContext.commitTransaction(); - if (log.isInfoEnabled()) { - log.info("Timespan bloqué avec succès"); - } - result = ServiceHelper.RESPOND_SUCCESS; - } else { - result = ServiceHelper.TRANSACTION_NOT_BALANCED; - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - } else { - if (log.isErrorEnabled()) { - log.error("Il existe un ou plusieurs timespans précédents" - + " non bloqués."); - } - result = ServiceHelper.TIMESPAN_PREC_NOT_BLOCK; - } - } - } - return result; - }*/ - - /* - * Permet de bloquer une période au format DTO. - * - * @param timespanDTO - * @return - * - public String blockTimeSpan(TimeSpanDTO timespanDTO) { - return blockTimeSpan(searchTimeSpanByDate(timespanDTO)); - }*/ - - /* - * Permet de débloquer un timespan, à condition que les timespans suivants - * celui-ci soient bien débloqués. - * @param timespan - * @param period - * @return - * - public String unblockTimeSpan(TimeSpan timespan) { - String result = ServiceHelper.RESPOND_ERROR; - // Si le timspan n'est pas bloqué - if (!timespan.getLocked()) { - if (log.isWarnEnabled()) { - log.warn("Timespan non bloqué !"); - } - } else { - Period period = getPeriodWithTimeSpan(timespan); - if (period.getLocked()) { - if (log.isErrorEnabled()) { - log.error("La période du timespan est bloquée !"); - } - } else { - boolean NextTimeSpanUnblock = nextTimeSpanUnblock(timespan, - period); - // Si aucun timespan suivant bloqué - if (NextTimeSpanUnblock) { - try { - // Acces BDD - TopiaContext topiaContext = rootContext - .beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // débloque la période - timespan.setLocked(false); - // Mise à jour de timespan dans la BDD - timeSpanDAO.update(timespan); - // Création BDD - topiaContext.commitTransaction(); - if (log.isInfoEnabled()) { - log.info("Timespan débloqué avec succès"); - } - result = ServiceHelper.RESPOND_SUCCESS; - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - } else { - result = ServiceHelper.TIMESPAN_NEXT_NOT_BLOCK; - } - } - } - return result; - }*/ - - /* - * Permet de bloquer une période au format DTO. - * - * @param timespanDTO - * @return - * - public String unblockTimeSpan(TimeSpanDTO timespanDTO) { - return unblockTimeSpan(searchTimeSpanByDate(timespanDTO)); - }*/ - - /* - * Cette méthode va rechercher tous les timeSpans non bloqués après - * le timeSpan renseigné en paramètre. - * Si elle trouve au moins un timeSpan NON bloqué, elle renvoie alors faux. - * Cette méthode permet essentiellement de définir si il est possible - * ou non de bloquer un timeSpan. A savoir, un timeSpan ne peut être bloqué, - * si il existe des timeSpans suivant (dans le calendrier) qui sont non - * bloqués. - * @param timespan - * @param period - * @return - * - private boolean nextTimeSpanUnblock(TimeSpan timespan, Period period) { - boolean NextTimeSpanUnblock = false; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Recherche des TimeSpans avec la même période. - // (on doit récupérer normalement 12 timeSpans) - List<TimeSpan> listeTimeSpanOfPeriod = timeSpanDAO - .findAllByPeriod(period); - NextTimeSpanUnblock = true; - for (TimeSpan timeSpanNext : listeTimeSpanOfPeriod) { - // Si le timespan est après celui qu'on souhaite bloquer ET est non bloqué - if (timeSpanNext.getBeginTimeSpan().compareTo( - timespan.getBeginTimeSpan()) == 1 - && timeSpanNext.getLocked()) { - NextTimeSpanUnblock = false; - if (log.isInfoEnabled()) { - log.info("Timespan " + timeSpanNext.toString() - + " est bloqué"); - } - } - } - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return NextTimeSpanUnblock; - }*/ - - /* - * Permet de renvoyer une période dont appartient le timeSpan. - * @param timeSpan timeSpan dont on souhaite retourner la période - * @return - * - private Period getPeriodWithTimeSpan(TimeSpan timeSpan) { - PeriodServiceImpl periodServiceImpl = new PeriodServiceImpl(); - Date beginTimeSpan = timeSpan.getBeginTimeSpan(); - Period period = periodServiceImpl.searchPeriodWithDate(beginTimeSpan); - return period; - }*/ - - /* - * Cette méthode renvoie vrai lorsque tous les timespans de la période - * précédent au timespan en paramètre sont bloqués. - * @param timespan - * @param period le paramètre period est important, en effet un timespan ne - * peut être indépendant. - * @return - * - private boolean alltimeSpanBlocked(TimeSpan timespan, Period period) { - boolean AllTimeSpanBlock = false; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Recherche des TimeSpans avec la même période. - // (on doit récupérer normalement 12 timeSpans) - List<TimeSpan> listeTimeSpanOfPeriod = timeSpanDAO - .findAllByPeriod(period); - // Fermeture BDD - topiaContext.closeContext(); - // On contrôle que les timeSpans précédents sont bloqués. - AllTimeSpanBlock = true; - for (TimeSpan timeSpanPrev : listeTimeSpanOfPeriod) { - // Si la période est avant celle qu'on souhaite bloquer ET est non bloquée - if (timeSpanPrev.getBeginTimeSpan().compareTo( - timespan.getBeginTimeSpan()) == -1 - && !timeSpanPrev.getLocked()) { - AllTimeSpanBlock = false; - if (log.isInfoEnabled()) { - log.info("Timespan " + timeSpanPrev.toString() - + " non bloqué"); - } - } - } - } catch (TopiaException e) { - log.error(e); - } - return AllTimeSpanBlock; - }*/ - - /* - * Permet d'effacer un timeSpan. Ce dernier ne doit pas être bloqué. - * @param timeSpan - * @return - * - public String removeTimeSpan(TimeSpan timeSpan) { - String result = ServiceHelper.RESPOND_ERROR; - // Si le timspan est bloqué - if (timeSpan.getLocked()) { - if (log.isWarnEnabled()) { - log.warn("Timespan bloqué !"); - } - } else { - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Mise à jour de timespan dans la BDD - timeSpanDAO.delete(timeSpan); - // Création BDD - topiaContext.commitTransaction(); - if (log.isInfoEnabled()) { - log.info("Timespan supprimé avec succès"); - } - result = ServiceHelper.RESPOND_SUCCESS; - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - } - return result; - }*/ - - /* - * Vérifie si le timeSpan donné en paramètre est bloqué ou non. - * @param timeSpan - * @return - * - public boolean isTimeSpanBlocked(TimeSpan timeSpan) { - boolean isTimeSpanBlocked = true; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - TimeSpanDAO timeSpanDAO = LimaCallaoDAOHelper - .getTimeSpanDAO(topiaContext); - // Mise à jour de timespan dans la BDD - TimeSpan timeSpanSearch = timeSpanDAO.findByTopiaId(timeSpan - .getTopiaId()); - isTimeSpanBlocked = timeSpanSearch.getLocked(); - // Fermeture BDD - topiaContext.closeContext(); - } catch (TopiaException e) { - log.error(e); - } - return isTimeSpanBlocked; - }*/ -} Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TransactionServiceImpl.java 2010-03-25 13:03:22 UTC (rev 2813) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TransactionServiceImpl.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -33,9 +33,9 @@ import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryDAO; -import org.chorem.lima.entity.Journal; +import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.LimaCallaoDAOHelper; -import org.chorem.lima.entity.TimeSpan; +import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.Transaction; import org.chorem.lima.entity.TransactionDAO; import org.nuiton.topia.TopiaContext; @@ -59,11 +59,11 @@ private TopiaContext rootContext; - private LogServiceImpl logServiceImpl = new LogServiceImpl(); + private RecordServiceImpl logServiceImpl = new RecordServiceImpl(); private EntryServiceImpl entryServiceImpl = new EntryServiceImpl(); - private TimeSpanServiceImpl timeSpanServiceImpl = new TimeSpanServiceImpl(); + private FinancialPeriodServiceImpl timeSpanServiceImpl = new FinancialPeriodServiceImpl(); public TransactionServiceImpl() { LimaConfig config = LimaConfig.getInstance(); Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java 2010-03-25 13:03:22 UTC (rev 2813) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -5,6 +5,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.dto.AccountDTO; +import org.chorem.lima.business.ejb.AccountServiceImpl; import org.chorem.lima.business.utils.ServiceHelper; import org.chorem.lima.entity.Account; import org.junit.AfterClass; Copied: trunk/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java (from rev 2802, trunk/lima-business/src/test/java/org/chorem/lima/business/JournalServiceImplTest.java) =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java (rev 0) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -0,0 +1,99 @@ +package org.chorem.lima.business; + +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.ejb.EntryBookServiceImpl; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Tests pour la gestion des journaux + * + * L'application peut gérer plusieurs journaux pour la gestion des transactions. + * Il est tester ici l'ajout, la recherche. + * + * @author Rémi Chapelet + */ +public class EntryBookServiceImplTest { + + /** log. */ + private static final org.apache.commons.logging.Log log = LogFactory + .getLog(EntryBookServiceImplTest.class); + + private static EntryBookServiceImpl instance; + + @BeforeClass + public static void setUpClass() throws Exception { + LimaConfigTest.getInstance(); + } + + /** + * On nettoie la base de données + * @throws java.lang.Exception + */ + @AfterClass + public static void tearDownClass() throws Exception { + /*List<JournalDTO> list = instance.getAllJournal(); + // On supprime chaque journal + for (JournalDTO journalDTO : list) { + instance.removeJournal(journalDTO); + }*/ + } + + @Before + public void setUp() { + instance = new EntryBookServiceImpl(); + } + + public EntryBookServiceImplTest() { + } + + /** + * Permet de tester l'ajout d'un journal dans la base de données. + */ + @Test + public void createJournalTest() { + /*String result = instance.createJournal("Journal des ventes", "jdv", + "description"); + Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS, result);*/ + } + + /** + * Permet de tester l'ajout d'un journal sous format DTO. + */ + @Test + public void createJournalDTOTest() { + /*JournalDTO journalDTO = new JournalDTO("", "Journal des achats", "jda", + "description"); + String result = instance.createJournal(journalDTO); + Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS, result);*/ + } + + /** + * Permet de tester la recherche d'un journal suivant son préfixe. + */ + @Test + public void searchJournalWithLabelTest() { + /*Journal result = instance.searchJournalWithLabel("Journal des ventes"); + Assert.assertEquals("Journal des ventes", result.getLabel()); + result = instance.searchJournalWithLabel("Journal des achats"); + Assert.assertEquals("Journal des achats", result.getLabel());*/ + } + + /** + * Permet de tester la modification d'un journal suivant son préfixe. + */ + @Test + public void modifyJournalTest() { + /*Journal journal = instance.searchJournalWithLabel("Journal des ventes"); + Assert.assertEquals("Journal des ventes", journal.getLabel()); + String result = instance.modifyJournal(journal.getTopiaId(), + "Journal des ventes", "new_prefix", "new_description"); + // Recherche du journal dans la bdd + JournalDTO journalDTO = instance + .searchJournalDTOWithLabel("Journal des ventes"); + Assert.assertEquals("new_prefix", journalDTO.getPrefix());*/ + } + +} \ No newline at end of file Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/EntryServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/EntryServiceImplTest.java 2010-03-25 13:03:22 UTC (rev 2813) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/EntryServiceImplTest.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -1,6 +1,7 @@ package org.chorem.lima.business; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.ejb.EntryServiceImpl; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/FilesServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/FilesServiceImplTest.java 2010-03-25 13:03:22 UTC (rev 2813) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/FilesServiceImplTest.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -1,6 +1,7 @@ package org.chorem.lima.business; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.ejb.FilesServiceImpl; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; Copied: trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java (from rev 2802, trunk/lima-business/src/test/java/org/chorem/lima/business/TimeSpanServiceImplTest.java) =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java (rev 0) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -0,0 +1,98 @@ +package org.chorem.lima.business; + +import static org.junit.Assert.assertTrue; + +import java.util.Date; + +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.ejb.FinancialPeriodServiceImpl; +import org.chorem.lima.business.utils.ServiceHelper; +import org.chorem.lima.entity.FinancialPeriod; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Tests pour la gestion des timespans + * + * Fonctions : + * _ création d'un timespan + * _ bloquer un timespan + * _ débloquer un timespan + * _ rechercher un timespan + * _ rechercher une période à partir d'un timespan + * + * @author Rémi Chapelet + */ +public class FinancialPeriodServiceImplTest { + + /** log. */ + private static final org.apache.commons.logging.Log log = LogFactory + .getLog(FinancialPeriodServiceImplTest.class); + + private static FinancialPeriodServiceImpl instance; + + @BeforeClass + public static void setUpClass() throws Exception { + LimaConfigTest.getInstance(); + } + + /** + * On nettoie la base de données + * @throws java.lang.Exception + */ + @AfterClass + public static void tearDownClass() throws Exception { + /*Date beginTimeSpan = new Date(111,0,1); + TimeSpan timeSpan = instance.searchTimeSpanByDate(beginTimeSpan); + instance.removeTimeSpan(timeSpan);*/ + } + + @Before + public void setUp() { + instance = new FinancialPeriodServiceImpl(); + } + + public FinancialPeriodServiceImplTest() { + } + + /** + * Permet de tester l'ajout d'un timspan + */ + @Test + public void createTimeSpanTest() { + /*// debut 1 janvier 2011 + Date beginTimeSpan = new Date(111, 0, 1); + // fin 15 janvier 2011 + Date endTimeSpan = new Date(111, 0, 15); + String result; + + // Création du timespan du 1 janvier au 31 janvier. + // Malgre la date de fin du 15 janvier, elle ne prend en compte que la + // date de début. La période a pour valeur nulle, et le timepsan est + // non bloqué. + result = instance.createTimeSpan(beginTimeSpan, endTimeSpan, null, + false); + Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS, result);*/ + } + + /** + * Permet de tester la fonction rechercher pour un timespan. Si ce dernier + * n'est pas trouvé, l'objet de retour est nul. + */ + @Test + public void findTimeSpanByMonthYearTest() { + /*// Il existe déja une période du 1 jan 2011 au 31 jan 2011 (createTimeSpanTest) + // debut 1 janvier 2011 + Date dateSearch = new Date(111, 0, 1); + TimeSpan timespan = instance.searchTimeSpanByDate(dateSearch); + assertTrue(timespan != null); // Trouve bien le timespan + // debut 1 mai 2011 + dateSearch = new Date(111, 4, 1); + timespan = instance.searchTimeSpanByDate(dateSearch); + assertTrue(timespan == null); // Ne le trouve pas */ + } + +} Copied: trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java (from rev 2802, trunk/lima-business/src/test/java/org/chorem/lima/business/PeriodServiceImplTest.java) =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java (rev 0) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -0,0 +1,198 @@ +package org.chorem.lima.business; + +import static org.junit.Assert.assertTrue; + +import java.util.Date; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.dto.PeriodDTO; +import org.chorem.lima.business.dto.TimeSpanDTO; +import org.chorem.lima.business.ejb.FiscalPeriodServiceImpl; +import org.chorem.lima.business.utils.ServiceHelper; +import org.chorem.lima.entity.FiscalPeriod; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Tests pour la gestion des périodes + * + * Fonctions : + * _ création d'une période + * _ valider une période (si elle est correcte) + * _ bloquer une période (ATTENTION : on ne peut débloquer une période !) + * _ rechercher une période + * + * @author Rémi Chapelet + */ +public class FiscalPeriodServiceImplTest { + + /** log. */ + private static final Log log = LogFactory + .getLog(FiscalPeriodServiceImplTest.class); + + private static FiscalPeriodServiceImpl instance; + + @BeforeClass + public static void setUpClass() throws Exception { + LimaConfigTest.getInstance(); + } + + /** + * On nettoie la base de données + * @throws java.lang.Exception + */ + @AfterClass + public static void tearDownClass() throws Exception { + /*Date d = new Date(110,0,1); + PeriodDTO periodDTO = instance.searchPeriodDTOWithDate(d); + instance.removePeriod(periodDTO); + d = new Date(109,0,1); + periodDTO = instance.searchPeriodDTOWithDate(d); + instance.removePeriod(periodDTO);*/ + } + + /** + * Permet de tester l'ajout d'une période. + */ + @Test + public void createPeriodTest() { + /*String result; + // debut 1 janvier 2009 + Date beginPeriod = new Date(109, 0, 1); + // fin 31 décembre 2009 + Date endPeriod = new Date(109, 11, 31); + // Création période avec son découpage sur 12 mois + result = instance.createPeriod(beginPeriod, endPeriod, false); + Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS, result);*/ + } + + /** + * Permet de tester si différentes périodes sont correctes ou non + * La création d'une nouvelle période doit remplir ce contrat. + * On définit plusieurs périodes pour les créer dans Callao. Pour chaque + * création, la période est testée si elle est correcte ou non. + */ + @Test + public void isCorrectPeriodTest() { + /*// Période déja créée Jan 2009 - Déc 2009 (et non bloquée) (createPeriodTest) + // debut 1 janvier 2010 + Date beginPeriod = new Date(110, 0, 1); + // fin 1 février 2010 + Date endPeriod = new Date(110, 1, 1); + String result; + // Cette période est non correcte, car il n'y a pas 12 mois complets + // Et la période précédente est non bloquée. + result = instance.createPeriod(beginPeriod, endPeriod, false); + Assert.assertEquals(ServiceHelper.RESPOND_ERROR, result); + // Création période sur 12 mois, MAIS période précédente non bloquée ! + // fin 31 décembre 2010 pour avoir 12 mois complets + endPeriod = new Date(110, 11, 31); + result = instance.createPeriod(beginPeriod, endPeriod, false); + Assert.assertEquals(ServiceHelper.RESPOND_ERROR, result); + // Période précédente non bloquée et non collée au niveau des dates + // de début et fin + // debut 1 avril 2009 + beginPeriod = new Date(109, 3, 1); + // fin 31 mars 2010 + endPeriod = new Date(110, 2, 31); + result = instance.createPeriod(beginPeriod, endPeriod, false); + Assert.assertEquals(ServiceHelper.RESPOND_ERROR, result); + // Création période qui chevauche la période 2009. + // debut 1 fevrier 2008 + beginPeriod = new Date(108, 1, 1); + // fin 1 janvier 2009 + endPeriod = new Date(109, 0, 1); + result = instance.createPeriod(beginPeriod, endPeriod, false); + Assert.assertEquals(ServiceHelper.RESPOND_ERROR, result);*/ + } + + /** + * Permet de tester la recherche sur les périodes. Il suffit de donner une + * date quelconque, il est renvoyé alors la période dont l'intervalle de + * temps comprend cette date. + */ + @Test + public void searchPeriodWithDateTest() { + /*// Période créée Jan 2009 - Déc 2009 (et non bloquée) (createPeriodTest) + // Date recherchée 17 avril 2009 + Date dateSearch = new Date(109, 3, 17); + Period period = instance.searchPeriodWithDate(dateSearch); + assertTrue(period != null); // Période trouvée + // Date recherchée 17 septembre 2000 + dateSearch = new Date(100, 8, 17); + period = instance.searchPeriodWithDate(dateSearch); + assertTrue(period == null); // Période non trouvée + // Recherche la période sur la date de debut de période. + // Date recherchée 1 janvier 2009 + dateSearch = new Date(109, 0, 1); + period = instance.searchPeriodWithDate(dateSearch); + assertTrue(period != null); // Période trouvée + // Recherche la période sur la date de fin de période. + // Date recherchée 31 décembre 2009 + dateSearch = new Date(109, 11, 31); + period = instance.searchPeriodWithDate(dateSearch); + assertTrue(period != null); // Période trouvée*/ + } + + /** + * Permet de tester si les périodes peuvent être bloquées ou non + * Test également la fonction permettant de bloquer tous les timespans + * d'une période. + */ + @Test + public void blockPeriodTest() { + /*// Période créée Jan 2009 - Déc 2009 (et non bloquée) (createPeriodTest) + // debut 1 janvier 2009 + Date beginTimeSpan = new Date(109, 0, 1); + String result; + // On souhaite bloquer la période, MAIS les timeSpans ne le sont pas + // On recherche la période Jan 2009 - Déc 2009 + Period period = instance.searchPeriodWithDate(beginTimeSpan); + result = instance.blockPeriod(period); + Assert.assertEquals(ServiceHelper.PERIOD_TIMESPAN_NOT_BLOCK, result); + // On bloque tous les timeSpans et la période ensuite + result = instance.blockAllTimeSpanOfPeriod(period); + Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS, result); + // On bloque de nouveau la période + result = instance.blockPeriod(period); + Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS, result);*/ + } + + /** + * Permet de tester les objets DTO pour la période. + * Création d'une période 2015 avec la création des 12 timeSpans + */ + @Test + public void PeriodDTOTest() { + /*// Création période DTO + Date dateBegin = new Date(110, 0, 1); + Date dateEnd = new Date(110, 11, 31); + PeriodDTO periodDTO = new PeriodDTO(); + periodDTO.setBeginPeriod(dateBegin); + periodDTO.setEndPeriod(dateEnd); + // Création BDD + String result = instance.createPeriod(periodDTO); + Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS, result);*/ + } + + /** + * Permet de tester la transformation d'une période en DTO avec ses timeSpans + * associés. + */ + @Test + public void searchPeriodDTOTest() { + /*// Cherche la période 2009 + Date dateBegin = new Date(109, 0, 1); + PeriodDTO periodDTO = instance.searchPeriodDTOWithDate(dateBegin); + Assert.assertEquals(dateBegin, periodDTO.getBeginPeriod()); + // Recherche des timeSpanDTO + List<TimeSpanDTO> listTimeSpanDTO = periodDTO.getListTimeSpan(); + // Nombre 12 timeSpans mensuels + Assert.assertEquals(12, listTimeSpanDTO.size());*/ + } + +} \ No newline at end of file Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java 2010-03-25 13:03:22 UTC (rev 2813) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -1,6 +1,11 @@ package org.chorem.lima.business; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.ejb.AccountServiceImpl; +import org.chorem.lima.business.ejb.EntryBookServiceImpl; +import org.chorem.lima.business.ejb.FiscalPeriodServiceImpl; +import org.chorem.lima.business.ejb.FinancialPeriodServiceImpl; +import org.chorem.lima.business.ejb.TransactionServiceImpl; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -15,9 +20,9 @@ private static final org.apache.commons.logging.Log log = LogFactory.getLog(TransactionServiceImplTest.class); private static TransactionServiceImpl instanceTransaction; - private static PeriodServiceImpl instancePeriod; - private static TimeSpanServiceImpl instanceTimespan; - private static JournalServiceImpl instanceJournal; + private static FiscalPeriodServiceImpl instancePeriod; + private static FinancialPeriodServiceImpl instanceTimespan; + private static EntryBookServiceImpl instanceJournal; private static AccountServiceImpl instanceAccount; private static String topiaIDTransaction; @@ -30,9 +35,9 @@ @Before public void setUp() { instanceTransaction = new TransactionServiceImpl(); - instancePeriod = new PeriodServiceImpl(); - instanceTimespan = new TimeSpanServiceImpl(); - instanceJournal = new JournalServiceImpl(); + instancePeriod = new FiscalPeriodServiceImpl(); + instanceTimespan = new FinancialPeriodServiceImpl(); + instanceJournal = new EntryBookServiceImpl(); instanceAccount = new AccountServiceImpl(); } Deleted: trunk/lima-business/src/test/java/org/chorem/lima/business/JournalServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/JournalServiceImplTest.java 2010-03-25 13:03:22 UTC (rev 2813) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/JournalServiceImplTest.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -1,98 +0,0 @@ -package org.chorem.lima.business; - -import org.apache.commons.logging.LogFactory; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * Tests pour la gestion des journaux - * - * L'application peut gérer plusieurs journaux pour la gestion des transactions. - * Il est tester ici l'ajout, la recherche. - * - * @author Rémi Chapelet - */ -public class JournalServiceImplTest { - - /** log. */ - private static final org.apache.commons.logging.Log log = LogFactory - .getLog(JournalServiceImplTest.class); - - private static JournalServiceImpl instance; - - @BeforeClass - public static void setUpClass() throws Exception { - LimaConfigTest.getInstance(); - } - - /** - * On nettoie la base de données - * @throws java.lang.Exception - */ - @AfterClass - public static void tearDownClass() throws Exception { - /*List<JournalDTO> list = instance.getAllJournal(); - // On supprime chaque journal - for (JournalDTO journalDTO : list) { - instance.removeJournal(journalDTO); - }*/ - } - - @Before - public void setUp() { - instance = new JournalServiceImpl(); - } - - public JournalServiceImplTest() { - } - - /** - * Permet de tester l'ajout d'un journal dans la base de données. - */ - @Test - public void createJournalTest() { - /*String result = instance.createJournal("Journal des ventes", "jdv", - "description"); - Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS, result);*/ - } - - /** - * Permet de tester l'ajout d'un journal sous format DTO. - */ - @Test - public void createJournalDTOTest() { - /*JournalDTO journalDTO = new JournalDTO("", "Journal des achats", "jda", - "description"); - String result = instance.createJournal(journalDTO); - Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS, result);*/ - } - - /** - * Permet de tester la recherche d'un journal suivant son préfixe. - */ - @Test - public void searchJournalWithLabelTest() { - /*Journal result = instance.searchJournalWithLabel("Journal des ventes"); - Assert.assertEquals("Journal des ventes", result.getLabel()); - result = instance.searchJournalWithLabel("Journal des achats"); - Assert.assertEquals("Journal des achats", result.getLabel());*/ - } - - /** - * Permet de tester la modification d'un journal suivant son préfixe. - */ - @Test - public void modifyJournalTest() { - /*Journal journal = instance.searchJournalWithLabel("Journal des ventes"); - Assert.assertEquals("Journal des ventes", journal.getLabel()); - String result = instance.modifyJournal(journal.getTopiaId(), - "Journal des ventes", "new_prefix", "new_description"); - // Recherche du journal dans la bdd - JournalDTO journalDTO = instance - .searchJournalDTOWithLabel("Journal des ventes"); - Assert.assertEquals("new_prefix", journalDTO.getPrefix());*/ - } - -} \ No newline at end of file Deleted: trunk/lima-business/src/test/java/org/chorem/lima/business/LogServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/LogServiceImplTest.java 2010-03-25 13:03:22 UTC (rev 2813) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/LogServiceImplTest.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -1,109 +0,0 @@ -package org.chorem.lima.business; - -import java.util.Date; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.dto.LogDTO; -import org.chorem.lima.entity.EntryLog; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * Tests pour la gestion des timespans - * @author Rémi Chapelet - */ -public class LogServiceImplTest { - - /** log. */ - private static final org.apache.commons.logging.Log log = LogFactory - .getLog(UserServiceImplTest.class); - - private static LogServiceImpl instance; - - @BeforeClass - public static void setUpClass() throws Exception { - LimaConfigTest.getInstance(); - } - - @Before - public void setUp() { - instance = new LogServiceImpl(); - } - - @AfterClass - public static void tearDownClass() throws Exception { - /*List<LogDTO> list = instance.listeAllLogDTO(); - for (LogDTO logDTO : list) - { - instance.removeLog(logDTO); - }*/ - } - - /** - * Permet de tester la recherche de tous les logs - */ - @Test - public void listeAllLogTest() { - /*// Ajout d'un log - Date logDate = new Date(2008,1,1); - Date transDate = new Date(); - instance.addLog(logDate, transDate, "test", "test", "test", - "test", "test", true, "test"); - // Recherche des logs - List<EntryLog> result = instance.listeAllLog(); - if (log.isDebugEnabled()) { - log.debug("Nombre de log : " + result.size()); - } - // trouve un log - Assert.assertEquals(1,result.size());*/ - } - - /** - * Test de la fonction de recherche de tous les logs suivant la date - * de création - */ - @Test - public void searchDateCreateTest() { - /*// Ajout d'un log avec comme date de creation 01/01/2009 - Date logDate = new Date(2009,1,1); - Date transDate = new Date(); - instance.addLog(logDate, transDate, "test", "test", "test", - "test", "test", true, "test"); - // Recherche des logs suivant la date - List<EntryLog> result = instance.searchLogWithDateCreate(logDate); - if (log.isDebugEnabled()) { - log.debug("Nombre de log recherche pour la date de creation : " - + result.size()); - } - // Apres avoir inséré un log a la date, il doit obligatoirement - // avoir au moins un log. - Assert.assertEquals(1,result.size());*/ - } - - /** - * Permet de tester la recherche de logs en format DTO. - */ - @Test - public void searchLogDTOWithDateCreate() { - - // Création de trois logs DTO - /*Date logDate = new Date(2000,1,1); - Date transDate = new Date(); - // Création logDTO - LogDTO logDTO = new LogDTO("",logDate, "test", transDate, "test", "test", - "test", "test", true, "test"); - // Ajout de trois logs - instance.addLog(logDTO); - instance.addLog(logDTO); - instance.addLog(logDTO); - // Recherche de ses trois logs sous forme de list de DTO - List<LogDTO> listLogDTO = instance.searchLogDTOWithDateCreate(logDate); - Assert.assertEquals(3,listLogDTO.size());*/ - } - -} Deleted: trunk/lima-business/src/test/java/org/chorem/lima/business/PeriodServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/PeriodServiceImplTest.java 2010-03-25 13:03:22 UTC (rev 2813) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/PeriodServiceImplTest.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -1,197 +0,0 @@ -package org.chorem.lima.business; - -import static org.junit.Assert.assertTrue; - -import java.util.Date; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.dto.PeriodDTO; -import org.chorem.lima.business.dto.TimeSpanDTO; -import org.chorem.lima.business.utils.ServiceHelper; -import org.chorem.lima.entity.Period; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * Tests pour la gestion des périodes - * - * Fonctions : - * _ création d'une période - * _ valider une période (si elle est correcte) - * _ bloquer une période (ATTENTION : on ne peut débloquer une période !) - * _ rechercher une période - * - * @author Rémi Chapelet - */ -public class PeriodServiceImplTest { - - /** log. */ - private static final Log log = LogFactory - .getLog(PeriodServiceImplTest.class); - - private static PeriodServiceImpl instance; - - @BeforeClass - public static void setUpClass() throws Exception { - LimaConfigTest.getInstance(); - } - - /** - * On nettoie la base de données - * @throws java.lang.Exception - */ - @AfterClass - public static void tearDownClass() throws Exception { - /*Date d = new Date(110,0,1); - PeriodDTO periodDTO = instance.searchPeriodDTOWithDate(d); - instance.removePeriod(periodDTO); - d = new Date(109,0,1); - periodDTO = instance.searchPeriodDTOWithDate(d); - instance.removePeriod(periodDTO);*/ - } - - /** - * Permet de tester l'ajout d'une période. - */ - @Test - public void createPeriodTest() { - /*String result; - // debut 1 janvier 2009 - Date beginPeriod = new Date(109, 0, 1); - // fin 31 décembre 2009 - Date endPeriod = new Date(109, 11, 31); - // Création période avec son découpage sur 12 mois - result = instance.createPeriod(beginPeriod, endPeriod, false); - Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS, result);*/ - } - - /** - * Permet de tester si différentes périodes sont correctes ou non - * La création d'une nouvelle période doit remplir ce contrat. - * On définit plusieurs périodes pour les créer dans Callao. Pour chaque - * création, la période est testée si elle est correcte ou non. - */ - @Test - public void isCorrectPeriodTest() { - /*// Période déja créée Jan 2009 - Déc 2009 (et non bloquée) (createPeriodTest) - // debut 1 janvier 2010 - Date beginPeriod = new Date(110, 0, 1); - // fin 1 février 2010 - Date endPeriod = new Date(110, 1, 1); - String result; - // Cette période est non correcte, car il n'y a pas 12 mois complets - // Et la période précédente est non bloquée. - result = instance.createPeriod(beginPeriod, endPeriod, false); - Assert.assertEquals(ServiceHelper.RESPOND_ERROR, result); - // Création période sur 12 mois, MAIS période précédente non bloquée ! - // fin 31 décembre 2010 pour avoir 12 mois complets - endPeriod = new Date(110, 11, 31); - result = instance.createPeriod(beginPeriod, endPeriod, false); - Assert.assertEquals(ServiceHelper.RESPOND_ERROR, result); - // Période précédente non bloquée et non collée au niveau des dates - // de début et fin - // debut 1 avril 2009 - beginPeriod = new Date(109, 3, 1); - // fin 31 mars 2010 - endPeriod = new Date(110, 2, 31); - result = instance.createPeriod(beginPeriod, endPeriod, false); - Assert.assertEquals(ServiceHelper.RESPOND_ERROR, result); - // Création période qui chevauche la période 2009. - // debut 1 fevrier 2008 - beginPeriod = new Date(108, 1, 1); - // fin 1 janvier 2009 - endPeriod = new Date(109, 0, 1); - result = instance.createPeriod(beginPeriod, endPeriod, false); - Assert.assertEquals(ServiceHelper.RESPOND_ERROR, result);*/ - } - - /** - * Permet de tester la recherche sur les périodes. Il suffit de donner une - * date quelconque, il est renvoyé alors la période dont l'intervalle de - * temps comprend cette date. - */ - @Test - public void searchPeriodWithDateTest() { - /*// Période créée Jan 2009 - Déc 2009 (et non bloquée) (createPeriodTest) - // Date recherchée 17 avril 2009 - Date dateSearch = new Date(109, 3, 17); - Period period = instance.searchPeriodWithDate(dateSearch); - assertTrue(period != null); // Période trouvée - // Date recherchée 17 septembre 2000 - dateSearch = new Date(100, 8, 17); - period = instance.searchPeriodWithDate(dateSearch); - assertTrue(period == null); // Période non trouvée - // Recherche la période sur la date de debut de période. - // Date recherchée 1 janvier 2009 - dateSearch = new Date(109, 0, 1); - period = instance.searchPeriodWithDate(dateSearch); - assertTrue(period != null); // Période trouvée - // Recherche la période sur la date de fin de période. - // Date recherchée 31 décembre 2009 - dateSearch = new Date(109, 11, 31); - period = instance.searchPeriodWithDate(dateSearch); - assertTrue(period != null); // Période trouvée*/ - } - - /** - * Permet de tester si les périodes peuvent être bloquées ou non - * Test également la fonction permettant de bloquer tous les timespans - * d'une période. - */ - @Test - public void blockPeriodTest() { - /*// Période créée Jan 2009 - Déc 2009 (et non bloquée) (createPeriodTest) - // debut 1 janvier 2009 - Date beginTimeSpan = new Date(109, 0, 1); - String result; - // On souhaite bloquer la période, MAIS les timeSpans ne le sont pas - // On recherche la période Jan 2009 - Déc 2009 - Period period = instance.searchPeriodWithDate(beginTimeSpan); - result = instance.blockPeriod(period); - Assert.assertEquals(ServiceHelper.PERIOD_TIMESPAN_NOT_BLOCK, result); - // On bloque tous les timeSpans et la période ensuite - result = instance.blockAllTimeSpanOfPeriod(period); - Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS, result); - // On bloque de nouveau la période - result = instance.blockPeriod(period); - Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS, result);*/ - } - - /** - * Permet de tester les objets DTO pour la période. - * Création d'une période 2015 avec la création des 12 timeSpans - */ - @Test - public void PeriodDTOTest() { - /*// Création période DTO - Date dateBegin = new Date(110, 0, 1); - Date dateEnd = new Date(110, 11, 31); - PeriodDTO periodDTO = new PeriodDTO(); - periodDTO.setBeginPeriod(dateBegin); - periodDTO.setEndPeriod(dateEnd); - // Création BDD - String result = instance.createPeriod(periodDTO); - Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS, result);*/ - } - - /** - * Permet de tester la transformation d'une période en DTO avec ses timeSpans - * associés. - */ - @Test - public void searchPeriodDTOTest() { - /*// Cherche la période 2009 - Date dateBegin = new Date(109, 0, 1); - PeriodDTO periodDTO = instance.searchPeriodDTOWithDate(dateBegin); - Assert.assertEquals(dateBegin, periodDTO.getBeginPeriod()); - // Recherche des timeSpanDTO - List<TimeSpanDTO> listTimeSpanDTO = periodDTO.getListTimeSpan(); - // Nombre 12 timeSpans mensuels - Assert.assertEquals(12, listTimeSpanDTO.size());*/ - } - -} \ No newline at end of file Copied: trunk/lima-business/src/test/java/org/chorem/lima/business/RecordServiceImplTest.java (from rev 2802, trunk/lima-business/src/test/java/org/chorem/lima/business/LogServiceImplTest.java) =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/RecordServiceImplTest.java (rev 0) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/RecordServiceImplTest.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -0,0 +1,110 @@ +package org.chorem.lima.business; + +import java.util.Date; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.dto.LogDTO; +import org.chorem.lima.business.ejb.RecordServiceImpl; +import org.chorem.lima.entity.Record; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Tests pour la gestion des timespans + * @author Rémi Chapelet + */ +public class RecordServiceImplTest { + + /** log. */ + private static final org.apache.commons.logging.Log log = LogFactory + .getLog(UserServiceImplTest.class); + + private static RecordServiceImpl instance; + + @BeforeClass + public static void setUpClass() throws Exception { + LimaConfigTest.getInstance(); + } + + @Before + public void setUp() { + instance = new RecordServiceImpl(); + } + + @AfterClass + public static void tearDownClass() throws Exception { + /*List<LogDTO> list = instance.listeAllLogDTO(); + for (LogDTO logDTO : list) + { + instance.removeLog(logDTO); + }*/ + } + + /** + * Permet de tester la recherche de tous les logs + */ + @Test + public void listeAllLogTest() { + /*// Ajout d'un log + Date logDate = new Date(2008,1,1); + Date transDate = new Date(); + instance.addLog(logDate, transDate, "test", "test", "test", + "test", "test", true, "test"); + // Recherche des logs + List<EntryLog> result = instance.listeAllLog(); + if (log.isDebugEnabled()) { + log.debug("Nombre de log : " + result.size()); + } + // trouve un log + Assert.assertEquals(1,result.size());*/ + } + + /** + * Test de la fonction de recherche de tous les logs suivant la date + * de création + */ + @Test + public void searchDateCreateTest() { + /*// Ajout d'un log avec comme date de creation 01/01/2009 + Date logDate = new Date(2009,1,1); + Date transDate = new Date(); + instance.addLog(logDate, transDate, "test", "test", "test", + "test", "test", true, "test"); + // Recherche des logs suivant la date + List<EntryLog> result = instance.searchLogWithDateCreate(logDate); + if (log.isDebugEnabled()) { + log.debug("Nombre de log recherche pour la date de creation : " + + result.size()); + } + // Apres avoir inséré un log a la date, il doit obligatoirement + // avoir au moins un log. + Assert.assertEquals(1,result.size());*/ + } + + /** + * Permet de tester la recherche de logs en format DTO. + */ + @Test + public void searchLogDTOWithDateCreate() { + + // Création de trois logs DTO + /*Date logDate = new Date(2000,1,1); + Date transDate = new Date(); + // Création logDTO + LogDTO logDTO = new LogDTO("",logDate, "test", transDate, "test", "test", + "test", "test", true, "test"); + // Ajout de trois logs + instance.addLog(logDTO); + instance.addLog(logDTO); + instance.addLog(logDTO); + // Recherche de ses trois logs sous forme de list de DTO + List<LogDTO> listLogDTO = instance.searchLogDTOWithDateCreate(logDate); + Assert.assertEquals(3,listLogDTO.size());*/ + } + +} Deleted: trunk/lima-business/src/test/java/org/chorem/lima/business/TimeSpanServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/TimeSpanServiceImplTest.java 2010-03-25 13:03:22 UTC (rev 2813) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/TimeSpanServiceImplTest.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -1,97 +0,0 @@ -package org.chorem.lima.business; - -import static org.junit.Assert.assertTrue; - -import java.util.Date; - -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.utils.ServiceHelper; -import org.chorem.lima.entity.TimeSpan; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * Tests pour la gestion des timespans - * - * Fonctions : - * _ création d'un timespan - * _ bloquer un timespan - * _ débloquer un timespan - * _ rechercher un timespan - * _ rechercher une période à partir d'un timespan - * - * @author Rémi Chapelet - */ -public class TimeSpanServiceImplTest { - - /** log. */ - private static final org.apache.commons.logging.Log log = LogFactory - .getLog(TimeSpanServiceImplTest.class); - - private static TimeSpanServiceImpl instance; - - @BeforeClass - public static void setUpClass() throws Exception { - LimaConfigTest.getInstance(); - } - - /** - * On nettoie la base de données - * @throws java.lang.Exception - */ - @AfterClass - public static void tearDownClass() throws Exception { - /*Date beginTimeSpan = new Date(111,0,1); - TimeSpan timeSpan = instance.searchTimeSpanByDate(beginTimeSpan); - instance.removeTimeSpan(timeSpan);*/ - } - - @Before - public void setUp() { - instance = new TimeSpanServiceImpl(); - } - - public TimeSpanServiceImplTest() { - } - - /** - * Permet de tester l'ajout d'un timspan - */ - @Test - public void createTimeSpanTest() { - /*// debut 1 janvier 2011 - Date beginTimeSpan = new Date(111, 0, 1); - // fin 15 janvier 2011 - Date endTimeSpan = new Date(111, 0, 15); - String result; - - // Création du timespan du 1 janvier au 31 janvier. - // Malgre la date de fin du 15 janvier, elle ne prend en compte que la - // date de début. La période a pour valeur nulle, et le timepsan est - // non bloqué. - result = instance.createTimeSpan(beginTimeSpan, endTimeSpan, null, - false); - Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS, result);*/ - } - - /** - * Permet de tester la fonction rechercher pour un timespan. Si ce dernier - * n'est pas trouvé, l'objet de retour est nul. - */ - @Test - public void findTimeSpanByMonthYearTest() { - /*// Il existe déja une période du 1 jan 2011 au 31 jan 2011 (createTimeSpanTest) - // debut 1 janvier 2011 - Date dateSearch = new Date(111, 0, 1); - TimeSpan timespan = instance.searchTimeSpanByDate(dateSearch); - assertTrue(timespan != null); // Trouve bien le timespan - // debut 1 mai 2011 - dateSearch = new Date(111, 4, 1); - timespan = instance.searchTimeSpanByDate(dateSearch); - assertTrue(timespan == null); // Ne le trouve pas */ - } - -} Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/UserServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/UserServiceImplTest.java 2010-03-25 13:03:22 UTC (rev 2813) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/UserServiceImplTest.java 2010-03-25 13:40:03 UTC (rev 2814) @@ -2,6 +2,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.ejb.UserServiceImpl; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass;
participants (1)
-
echatellier@users.chorem.org