Author: echatellier Date: 2012-05-11 12:19:53 +0200 (Fri, 11 May 2012) New Revision: 3409 Url: http://chorem.org/repositories/revision/lima/3409 Log: Removing all topiaContext use in services Removed: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/EntryBookServiceLocal.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/VatStatementServiceLocal.java Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialPeriodServiceLocal.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialStatementServiceLocal.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionServiceLocal.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodServiceLocal.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/IdentityServiceLocal.java trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ReportServiceLocal.java trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/LimaDaoHelper.java trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AbstractLimaService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.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/FinancialStatementServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.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/HttpServerServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/IdentityServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/VatStatementServiceImpl.java trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/TestAccountingRules.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -32,7 +32,6 @@ import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FiscalPeriod; -import org.nuiton.topia.TopiaContext; import java.util.List; @@ -62,7 +61,7 @@ * @param topiaTransaction * @throws LimaException */ - void removeEntryBookRules(EntryBook entryBook, TopiaContext topiaTransaction) throws LimaException; + void removeEntryBookRules(EntryBook entryBook) throws LimaException; /** * Fiscal Period rules @@ -71,9 +70,9 @@ * @param transaction * @throws LimaException */ - List<FinancialPeriod> createFiscalPeriodRules(FiscalPeriod fiscalPeriod, TopiaContext transaction) throws LimaException; + List<FinancialPeriod> createFiscalPeriodRules(FiscalPeriod fiscalPeriod) throws LimaException; - void blockFiscalPeriodRules(FiscalPeriod fiscalPeriod, TopiaContext transaction) throws LimaException; + void blockFiscalPeriodRules(FiscalPeriod fiscalPeriod) throws LimaException; /** * Entry rules @@ -82,7 +81,7 @@ * @param topiaTransaction * @throws LimaException */ - void updateEntryRules(Entry entry, Entry entryOld, TopiaContext topiaTransaction) throws LimaException; + void updateEntryRules(Entry entry, Entry entryOld) throws LimaException; void updateFinancialTransactionDateRules(FinancialTransaction financialTransaction, FinancialTransaction financialTransactionOld) throws LimaException; @@ -93,7 +92,7 @@ * @param topiaContext * @throws LimaException */ - void checkFinancialPeriodBlockedWithFinancialTransaction(FinancialTransaction financialTransaction, TopiaContext topiaContext) throws LimaException; + void checkFinancialPeriodBlockedWithFinancialTransaction(FinancialTransaction financialTransaction) throws LimaException; /** * Check if a financial period can be closed. @@ -102,5 +101,5 @@ * @param topiaContext * @throws LimaException */ - void blockClosedPeriodicEntryBookRules(ClosedPeriodicEntryBook closedPeriodicEntryBook, TopiaContext topiaContext) throws LimaException; + void blockClosedPeriodicEntryBookRules(ClosedPeriodicEntryBook closedPeriodicEntryBook) throws LimaException; } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaDaoHelper.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaDaoHelper.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaDaoHelper.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -30,6 +30,8 @@ import org.chorem.lima.entity.EntryBookDAO; import org.chorem.lima.entity.EntryDAO; import org.chorem.lima.entity.FinancialPeriodDAO; +import org.chorem.lima.entity.FinancialStatementDAO; +import org.chorem.lima.entity.FinancialTransactionDAO; import org.chorem.lima.entity.FiscalPeriodDAO; import org.chorem.lima.entity.IdentityDAO; import org.chorem.lima.entity.LimaCallaoDAOHelper; @@ -76,7 +78,15 @@ public FinancialPeriodDAO getFinancialPeriodDAO() throws TopiaException { return LimaCallaoDAOHelper.getFinancialPeriodDAO(context); } + + public FinancialTransactionDAO getFinancialTransactionDAO() throws TopiaException { + return LimaCallaoDAOHelper.getFinancialTransactionDAO(context); + } + public FinancialStatementDAO getFinancialStatementDAO() throws TopiaException { + return LimaCallaoDAOHelper.getFinancialStatementDAO(context); + } + public FiscalPeriodDAO getFiscalPeriodDAO() throws TopiaException { return LimaCallaoDAOHelper.getFiscalPeriodDAO(context); } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -52,8 +52,6 @@ import org.chorem.lima.entity.FinancialTransactionDAO; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.FiscalPeriodDAO; -import org.chorem.lima.entity.LimaCallaoDAOHelper; -import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; /** @@ -103,7 +101,7 @@ /** Rules to check before create fiscals periods */ @Override - public List<FinancialPeriod> createFiscalPeriodRules(FiscalPeriod fiscalPeriod, TopiaContext transaction) throws LimaException { + public List<FinancialPeriod> createFiscalPeriodRules(FiscalPeriod fiscalPeriod) throws LimaException { //check if the enddate period is after the begindate period if (fiscalPeriod.getEndDate().before(fiscalPeriod.getBeginDate())) { throw new LimaBusinessException(_("lima-business.defaultaccountingrules.enddateerror")); @@ -114,7 +112,7 @@ /** Rules to check before block fiscals periods */ @Override - public void blockFiscalPeriodRules(FiscalPeriod fiscalPeriod, TopiaContext transaction) throws LimaException { + public void blockFiscalPeriodRules(FiscalPeriod fiscalPeriod) throws LimaException { } @@ -138,16 +136,17 @@ /** Check if entrybook have financial transaction */ @Override - public void removeEntryBookRules(EntryBook entryBook, TopiaContext topiaTransaction) throws LimaException { + public void removeEntryBookRules(EntryBook entryBook) throws LimaException { try { - FinancialTransactionDAO financialTransactionDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaTransaction); + FinancialTransactionDAO financialTransactionDAO = getDaoHelper().getFinancialTransactionDAO(); + // Check if entrybook have entries long nbfinancialtransaction = financialTransactionDAO.getCountByEntryBook(entryBook); if (nbfinancialtransaction != 0) { throw new LimaBusinessException(_("lima-business.defaultaccountingrules.deleteentrybookerror")); } } catch (TopiaException ex) { - doCatch(topiaTransaction, ex, log); + throw new LimaException("Can't check rule", ex); } } @@ -157,7 +156,7 @@ * check if all entrybook of his financial period are blocked */ @Override - public void checkFinancialPeriodBlockedWithFinancialTransaction(FinancialTransaction financialTransaction, TopiaContext topiaContext) throws LimaException { + public void checkFinancialPeriodBlockedWithFinancialTransaction(FinancialTransaction financialTransaction) throws LimaException { try { //check financial period locked @@ -188,8 +187,8 @@ if (entryBooks.size() == closedEntryBooks.size()) { throw new LimaBusinessException(_("lima-business.defaultaccountingrules.allentrybookclosed")); } - } catch (TopiaException eee) { - doCatch(topiaContext, eee, log); + } catch (TopiaException ex) { + throw new LimaException("Can't check rule", ex); } } @@ -199,12 +198,11 @@ * Check if all financial transactions have EntryBooks */ @Override - public void blockClosedPeriodicEntryBookRules(ClosedPeriodicEntryBook closedPeriodicEntryBook, TopiaContext topiaContext) + public void blockClosedPeriodicEntryBookRules(ClosedPeriodicEntryBook closedPeriodicEntryBook) throws LimaException { try { - FinancialTransactionDAO financialTransactionDAO = - LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); + FinancialTransactionDAO financialTransactionDAO = getDaoHelper().getFinancialTransactionDAO(); // Check if all financial transactions of closedperiodicentrybook are equilibrate // FIMXE echatellier 20120504 unutile de recuperer une liste @@ -233,7 +231,7 @@ } } catch (TopiaException ex) { - doCatch(topiaContext, ex, log); + throw new LimaException("Can't check rule", ex); } } @@ -245,15 +243,14 @@ * - third, the new choice entrybook belong to a blocked closedPeriodicEntryBook */ @Override - public void updateEntryRules(Entry entry, Entry entryOld, TopiaContext topiaTransaction) throws LimaException { + public void updateEntryRules(Entry entry, Entry entryOld) throws LimaException { try { FinancialPeriodDAO financialPeriodDAO = getDaoHelper().getFinancialPeriodDAO(); FinancialPeriod financialPeriod = financialPeriodDAO.findByDate(entry.getFinancialTransaction().getTransactionDate()); - ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = - LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(topiaTransaction); + ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = getDaoHelper().getClosedPeriodicEntryBookDAO(); //second case ClosedPeriodicEntryBook closedPeriodicEntryBook = @@ -273,8 +270,8 @@ throw new LimaBusinessException(_("lima-Business.defaultaccountingrules.updateentryerror")); } - } catch (TopiaException eee) { - doCatch(topiaTransaction, eee, log); + } catch (TopiaException ex) { + throw new LimaException("Can't check rule", ex); } } @@ -398,28 +395,4 @@ throw new LimaException("Can't check financial transaction", ex); } } - - - /** - * Generic code used to rollback a transaction. - * <p/> - * TODO : replace this by JTA - * - * @throws LimaException - */ - protected void doCatch(TopiaContext transaction, Exception cause, Log log) throws LimaException { - if (transaction != null) { - try { - transaction.rollbackTransaction(); - } catch (TopiaException eee) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", eee); - } - } - } - if (log.isErrorEnabled()) { - log.error("Exception during query", cause); - } - throw new LimaException(_("lima-business.common.queryerror"), cause); - } } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -39,8 +39,6 @@ import org.chorem.lima.entity.FinancialPeriodImpl; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.FiscalPeriodDAO; -import org.chorem.lima.entity.LimaCallaoDAOHelper; -import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; import org.nuiton.topia.framework.TopiaQuery.Op; @@ -112,12 +110,11 @@ * Pas plus de deux exercices fiscaux ne peuvent-être ouvert en même temps */ @Override - public List<FinancialPeriod> createFiscalPeriodRules(FiscalPeriod fiscalPeriod, TopiaContext transaction) throws LimaException { - super.createFiscalPeriodRules(fiscalPeriod, transaction); + public List<FinancialPeriod> createFiscalPeriodRules(FiscalPeriod fiscalPeriod) throws LimaException { + super.createFiscalPeriodRules(fiscalPeriod); List<FinancialPeriod> financialPeriods = new ArrayList<FinancialPeriod>(); try { - FiscalPeriodDAO fiscalPeriodDAO = - LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + FiscalPeriodDAO fiscalPeriodDAO = getDaoHelper().getFiscalPeriodDAO(); //Checks if is not the first fiscalperiod to create if (fiscalPeriodDAO.findAll().size() != 0) { @@ -170,7 +167,7 @@ loopDate = DateUtils.addMilliseconds(loopDate, 1); } } catch (TopiaException ex) { - doCatch(transaction, ex, log); + throw new LimaException("Can't check rule", ex); } return financialPeriods; } @@ -179,10 +176,9 @@ * Règles de vérification de fermeture d'un exercice, appliquées à la comptabilité française. */ @Override - public void blockFiscalPeriodRules(FiscalPeriod fiscalPeriod, TopiaContext transaction) throws LimaException { + public void blockFiscalPeriodRules(FiscalPeriod fiscalPeriod) throws LimaException { try { - FiscalPeriodDAO fiscalPeriodDAO = - LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + FiscalPeriodDAO fiscalPeriodDAO = getDaoHelper().getFiscalPeriodDAO(); TopiaQuery query = fiscalPeriodDAO.createQuery(); fiscalPeriodDAO.findAllByQuery(query); @@ -197,7 +193,7 @@ throw new LimaBusinessException(_("lima-business.franceaccountingrules.antefiscalperiodnotblocked")); } } catch (TopiaException ex) { - doCatch(transaction, ex, log); + throw new LimaException("Can't check rule", ex); } } @@ -217,9 +213,8 @@ * qu'il reste des ClosedPeriodicEntryBook non clos ? */ @Override - public void blockClosedPeriodicEntryBookRules(ClosedPeriodicEntryBook closedPeriodicEntryBook, TopiaContext topiaTransaction) throws LimaException { - super.blockClosedPeriodicEntryBookRules( - closedPeriodicEntryBook, topiaTransaction); + public void blockClosedPeriodicEntryBookRules(ClosedPeriodicEntryBook closedPeriodicEntryBook) throws LimaException { + super.blockClosedPeriodicEntryBookRules(closedPeriodicEntryBook); FinancialPeriod financialPeriod = closedPeriodicEntryBook.getFinancialPeriod(); @@ -231,7 +226,7 @@ // un period peut ne pas durer un mois endDate = DateUtils.addMonths(endDate, -1); - FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(topiaTransaction); + FiscalPeriodDAO fiscalPeriodDAO = getDaoHelper().getFiscalPeriodDAO(); //search fiscalperiod have financialperiod FiscalPeriod fiscalPeriod = fiscalPeriodDAO.findByFinancialPeriod(financialPeriod); @@ -240,8 +235,7 @@ // et endDate ? il ne provienent pas du même endroit EntryBook entryBook = closedPeriodicEntryBook.getEntryBook(); - ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = - LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(topiaTransaction); + ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = getDaoHelper().getClosedPeriodicEntryBookDAO(); List<ClosedPeriodicEntryBook> closedPeriodicEntryBooks = closedPeriodicEntryBookDAO.findAllByEntryBookAndDates(entryBook, beginDate, endDate); @@ -260,28 +254,7 @@ } } catch (TopiaException ex) { - doCatch(topiaTransaction, ex, log); + throw new LimaException("Can't check rule", ex); } } - - /** - * Generic code used to rollback a transaction. - * - * @throws LimaException - */ - protected void doCatch(TopiaContext transaction, Exception cause, Log log) throws LimaException { - if (transaction != null) { - try { - transaction.rollbackTransaction(); - } catch (TopiaException eee) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", eee); - } - } - } - if (log.isErrorEnabled()) { - log.error("Exception during query", cause); - } - throw new LimaException(_("lima-business.common.queryerror"), cause); - } } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AbstractLimaService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AbstractLimaService.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AbstractLimaService.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -25,21 +25,10 @@ package org.chorem.lima.business.ejb; -import static org.nuiton.i18n.I18n._; - -import java.util.Properties; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaDaoHelper; -import org.chorem.lima.business.LimaException; import org.chorem.lima.business.LimaInterceptor; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaNotFoundException; -import org.nuiton.topia.TopiaRuntimeException; /** * Abstract code for all ejb services (get context, catch, finally...). @@ -61,93 +50,4 @@ protected LimaDaoHelper getDaoHelper() { return LimaInterceptor.DAO_HELPER.get(); } - - protected static TopiaContext acquireRootContext() { - try { - LimaConfig config = LimaConfig.getInstance(); - Properties options = config.getFlatOptions(); - - if (log.isDebugEnabled()) { - log.debug("Opening context to database : " + options.getProperty("hibernate.connection.url")); - } - return TopiaContextFactory.getContext(options); - } catch (TopiaNotFoundException ex) { - throw new TopiaRuntimeException("Could not acquire root context", ex); - } - } - - /** - * Generic code used to rollback a transaction. - * <p/> - * TODO : replace this by JTA - * - * @throws LimaException - */ - protected void doCatch(TopiaContext transaction, - Exception cause) throws LimaException { - if (cause instanceof LimaException) { - throw (LimaException) cause; - } - if (transaction != null) { - try { - transaction.rollbackTransaction(); - } catch (TopiaException eee) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", eee); - } - } - } - if (log.isErrorEnabled()) { - log.error("Exception during query", cause); - } - throw new LimaException(_("lima-business.common.queryerror", cause.getMessage()), cause); - } - - /** - * Generic code used too close a transaction. - * - * @param transaction transaction to close - * @throws LimaException - */ - protected void doFinally(TopiaContext transaction) throws LimaException { - if (transaction != null) { - try { - transaction.closeContext(); - } catch (TopiaException ex) { - if (log.isErrorEnabled()) { - log.error("Can't close transaction", ex); - } - throw new LimaException( - _("lima-business.common.close.transactionerror", ex)); - } - } - } - - protected TopiaContext beginTransaction(TopiaContext rootContext) throws LimaException { - if (rootContext == null) { - throw new NullPointerException("rootContext can not be null"); - } - // basic check done, make check in database - // TODO move it into JTA - try { - TopiaContext topiaContext = rootContext.beginTransaction(); - log.trace("beginTransaction" + topiaContext); - return topiaContext; - } catch (TopiaException e) { - throw new LimaException( - _("lima-business.common.open.transactionerror", e)); - } - } - - protected void commitTransaction(TopiaContext topiaContext) throws LimaException { - try { - topiaContext.commitTransaction(); - } catch (TopiaException eee) { - if (log.isErrorEnabled()) { - log.error("Error during commit context", eee); - } - throw new LimaException( - _("lima-business.common.commit.transactionerror", eee)); - } - } } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -38,7 +38,6 @@ import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; -import org.chorem.lima.business.LimaInterceptor; import org.chorem.lima.business.api.AccountService; import org.chorem.lima.business.utils.AccountComparator; import org.chorem.lima.entity.Account; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/DocumentServiceImpl.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -25,20 +25,27 @@ package org.chorem.lima.business.ejb; -import com.lowagie.text.BadElementException; -import com.lowagie.text.Cell; -import com.lowagie.text.Chapter; -import com.lowagie.text.Document; -import com.lowagie.text.DocumentException; -import com.lowagie.text.Element; -import com.lowagie.text.Font; -import com.lowagie.text.PageSize; -import com.lowagie.text.Paragraph; -import com.lowagie.text.Phrase; -import com.lowagie.text.Rectangle; -import com.lowagie.text.Table; -import com.lowagie.text.html.HtmlWriter; -import com.lowagie.text.pdf.PdfWriter; +import static org.nuiton.i18n.I18n._; + +import java.awt.Color; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; + +import javax.ejb.EJB; +import javax.ejb.Local; +import javax.ejb.Remote; +import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; + import org.apache.pdfbox.examples.fdf.SetField; import org.apache.pdfbox.pdmodel.PDDocument; import org.chorem.lima.beans.BalanceTrial; @@ -53,7 +60,7 @@ import org.chorem.lima.business.api.FinancialStatementServiceLocal; import org.chorem.lima.business.api.IdentityServiceLocal; import org.chorem.lima.business.api.ReportServiceLocal; -import org.chorem.lima.business.api.VatStatementServiceLocal; +import org.chorem.lima.business.api.VatStatementService; import org.chorem.lima.business.utils.DocumentsEnum; import org.chorem.lima.business.utils.EntryComparator; import org.chorem.lima.business.utils.FormatsEnum; @@ -65,40 +72,30 @@ import org.chorem.lima.entity.EntryDAO; import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialPeriodDAO; -import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.Identity; -import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.chorem.lima.entity.VatStatement; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.framework.TopiaQuery; -import org.nuiton.topia.framework.TopiaQuery.Op; -import javax.ejb.EJB; -import javax.ejb.Local; -import javax.ejb.Remote; -import javax.ejb.Stateless; -import java.awt.*; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.math.BigDecimal; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; +import com.lowagie.text.BadElementException; +import com.lowagie.text.Cell; +import com.lowagie.text.Chapter; +import com.lowagie.text.Document; +import com.lowagie.text.DocumentException; +import com.lowagie.text.Element; +import com.lowagie.text.Font; +import com.lowagie.text.PageSize; +import com.lowagie.text.Paragraph; +import com.lowagie.text.Phrase; +import com.lowagie.text.Rectangle; +import com.lowagie.text.Table; +import com.lowagie.text.html.HtmlWriter; +import com.lowagie.text.pdf.PdfWriter; -import static org.nuiton.i18n.I18n._; - @Stateless @Remote(DocumentService.class) @Local(DocumentServiceLocal.class) +@TransactionAttribute public class DocumentServiceImpl extends AbstractLimaService implements DocumentService, DocumentServiceLocal { - private TopiaContext rootContext; - //Services @EJB private IdentityServiceLocal identityService; @@ -110,7 +107,7 @@ private ReportServiceLocal reportService; @EJB - private VatStatementServiceLocal vatStatementService; + private VatStatementService vatStatementService; protected String path; @@ -142,7 +139,6 @@ public DocumentServiceImpl() { - rootContext = acquireRootContext(); path = LimaConfig.getInstance().getReportsDir().getAbsolutePath(); } @@ -743,9 +739,7 @@ Date endDate, FormatsEnum format) throws LimaException { Document document = new Document(PageSize.A4, 8, 8, 8, 8); - TopiaContext transaction = beginTransaction(rootContext); - try { Date newDate = new Date(); String dateS = dateFormat.format(newDate); @@ -767,8 +761,8 @@ Identity identity = identityService.getIdentity(); ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = - LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(transaction); - EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(transaction); + getDaoHelper().getClosedPeriodicEntryBookDAO(); + EntryDAO entryDAO = getDaoHelper().getEntryDAO(); //Split list by financialstatement type List<ClosedPeriodicEntryBook> closedPeriodicEntryBookList = closedPeriodicEntryBookDAO.findAllByDates(beginDate, endDate); @@ -851,12 +845,9 @@ document.close(); - } catch (Exception eee) { - doCatch(transaction, eee); - } finally { - doFinally(transaction); + } catch (Exception ex) { + throw new LimaException("Can't create document", ex); } - } public Table createEntryBooksHeaderTable() { @@ -1175,7 +1166,7 @@ public void createGeneralEntryBooksDocuments(Date beginDate, Date endDate, FormatsEnum format) throws LimaException { - TopiaContext transaction = beginTransaction(rootContext); + Document document = new Document(PageSize.A4, 8, 8, 8, 8); try { @@ -1200,10 +1191,10 @@ Identity identity = identityService.getIdentity(); FinancialPeriodDAO financialPeriodDAO = - LimaCallaoDAOHelper.getFinancialPeriodDAO(transaction); + getDaoHelper().getFinancialPeriodDAO(); ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = - LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(transaction); - EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(transaction); + getDaoHelper().getClosedPeriodicEntryBookDAO(); + EntryDAO entryDAO = getDaoHelper().getEntryDAO(); List<FinancialPeriod> financialPeriods = financialPeriodDAO.findByDates(beginDate, endDate); @@ -1315,12 +1306,9 @@ document.close(); - } catch (Exception eee) { - doCatch(transaction, eee); - } finally { - doFinally(transaction); + } catch (Exception ex) { + throw new LimaException("Can't generate document", ex); } - } public Table createGeneralEntryBooksHeaderTable() { @@ -1477,8 +1465,8 @@ doc.save(filePath); doc.close(); - } catch (Exception eee) { - doCatch(null, eee); + } catch (Exception ex) { + throw new LimaException("Can't create document", ex); } } } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -30,7 +30,6 @@ import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; import org.chorem.lima.business.api.EntryBookService; -import org.chorem.lima.business.api.EntryBookServiceLocal; import org.chorem.lima.entity.ClosedPeriodicEntryBook; import org.chorem.lima.entity.ClosedPeriodicEntryBookDAO; import org.chorem.lima.entity.ClosedPeriodicEntryBookImpl; @@ -38,14 +37,12 @@ import org.chorem.lima.entity.EntryBookDAO; import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialPeriodDAO; -import org.chorem.lima.entity.LimaCallaoDAOHelper; -import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; -import javax.ejb.Local; import javax.ejb.Remote; import javax.ejb.Stateless; -import java.util.ArrayList; +import javax.ejb.TransactionAttribute; + import java.util.List; import static org.nuiton.i18n.I18n._; @@ -58,26 +55,18 @@ */ @Stateless @Remote(EntryBookService.class) -@Local(EntryBookServiceLocal.class) -public class EntryBookServiceImpl extends AbstractLimaService implements EntryBookService, EntryBookServiceLocal { +@TransactionAttribute +public class EntryBookServiceImpl extends AbstractLimaService implements EntryBookService { - private TopiaContext rootContext; - - public EntryBookServiceImpl() { - rootContext = acquireRootContext(); - } - @Override - public EntryBook createEntryBookWithTransaction(EntryBook entryBook, - TopiaContext topiaContext) + public EntryBook createEntryBook(EntryBook entryBook) throws LimaException { EntryBook result = null; try { // check if entrybook with is name already exist - EntryBookDAO entryBookDAO = - LimaCallaoDAOHelper.getEntryBookDAO(topiaContext); + EntryBookDAO entryBookDAO = getDaoHelper().getEntryBookDAO(); EntryBook existingEntryBook = entryBookDAO.findByLabel(entryBook.getCode()); if (existingEntryBook != null) { @@ -91,9 +80,9 @@ //create ClosedPeriodicEntryBook for all unblocked financial period ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = - LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(topiaContext); + getDaoHelper().getClosedPeriodicEntryBookDAO(); FinancialPeriodDAO financialPeriodDAO = - LimaCallaoDAOHelper.getFinancialPeriodDAO(topiaContext); + getDaoHelper().getFinancialPeriodDAO(); // for all unblocked financialperiod for (FinancialPeriod financialPeriod : financialPeriodDAO.findAllByLocked(false)) { @@ -108,47 +97,23 @@ closedPeriodicEntryBookDAO.create(closedPeriodicEntryBook); } - commitTransaction(topiaContext); } catch (TopiaException ex) { - doCatch(topiaContext, ex); + throw new LimaException("Can't create entry book", ex); } return result; } @Override - public EntryBook createEntryBook(EntryBook entryBook) throws LimaException { - - TopiaContext transaction = beginTransaction(rootContext); - - EntryBook result = null; - try { - - result = createEntryBookWithTransaction(entryBook, transaction); - } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); - } - - return result; - } - - @Override public List<EntryBook> getAllEntryBooks() throws LimaException { - List<EntryBook> entryBooksList = new ArrayList<EntryBook>(); - TopiaContext transaction = beginTransaction(rootContext); - try { + List<EntryBook> entryBooksList = null; + try { // check if entrybook with is name already exist - EntryBookDAO entryBookDAO = - LimaCallaoDAOHelper.getEntryBookDAO(transaction); - List<EntryBook> entryBooks = entryBookDAO.findAll(); - entryBooksList.addAll(entryBooks); + EntryBookDAO entryBookDAO = getDaoHelper().getEntryBookDAO(); + entryBooksList = entryBookDAO.findAll(); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't get entry books", ex); } return entryBooksList; @@ -156,22 +121,17 @@ @Override public EntryBook updateEntryBook(EntryBook entryBook) throws LimaException { - TopiaContext transaction = beginTransaction(rootContext); EntryBook result = null; try { - EntryBookDAO entryBookDAO = - LimaCallaoDAOHelper.getEntryBookDAO(transaction); + EntryBookDAO entryBookDAO = getDaoHelper().getEntryBookDAO(); // creation du EntryBook result = entryBookDAO.update(entryBook); - commitTransaction(transaction); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't update entry book", ex); } return result; @@ -180,17 +140,16 @@ @Override public void removeEntryBook(EntryBook entryBook) throws LimaException { - TopiaContext topiaTransaction = beginTransaction(rootContext); AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); try { // check rule - accountingRules.removeEntryBookRules(entryBook, topiaTransaction); + accountingRules.removeEntryBookRules(entryBook); // delete all ClosedPeriodicEntryBook from this EntryBook ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = - LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(topiaTransaction); + getDaoHelper().getClosedPeriodicEntryBookDAO(); List<ClosedPeriodicEntryBook> closedPeriodicEntryBooks = closedPeriodicEntryBookDAO.findAllByEntryBook(entryBook); for (ClosedPeriodicEntryBook closedPeriodicEntryBook : closedPeriodicEntryBooks) { @@ -198,14 +157,11 @@ } // delete entry book - EntryBookDAO entryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(topiaTransaction); + EntryBookDAO entryBookDAO = getDaoHelper().getEntryBookDAO(); entryBookDAO.delete(entryBook); - commitTransaction(topiaTransaction); } catch (Exception ex) { - doCatch(topiaTransaction, ex); - } finally { - doFinally(topiaTransaction); + throw new LimaException("Can't remove entry book", ex); } } @@ -214,22 +170,17 @@ */ @Override public EntryBook getEntryBookByCode(String code) throws LimaException { - TopiaContext transaction = beginTransaction(rootContext); + EntryBook entryBook = null; try { + EntryBookDAO entryBookDAO = getDaoHelper().getEntryBookDAO(); - EntryBookDAO entryBookDAO = - LimaCallaoDAOHelper.getEntryBookDAO(transaction); - // creation du EntryBook entryBook = entryBookDAO.findByCode(code); - commitTransaction(transaction); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't get entry book", ex); } return entryBook; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ExportServiceImpl.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -47,16 +47,16 @@ import org.chorem.lima.entity.FiscalPeriodDAO; import org.chorem.lima.entity.Identity; import org.chorem.lima.entity.IdentityDAO; -import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.chorem.lima.entity.VatStatement; import org.chorem.lima.entity.VatStatementDAO; -import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; import javax.ejb.Local; import javax.ejb.Remote; import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; + import java.io.StringWriter; import java.text.SimpleDateFormat; import java.util.List; @@ -72,17 +72,12 @@ @Stateless @Remote(ExportService.class) @Local(ExportServiceLocal.class) +@TransactionAttribute public class ExportServiceImpl extends AbstractLimaService implements ExportService, ExportServiceLocal { - private TopiaContext rootContext; - private static final SimpleDateFormat SDATEFORMAT = new SimpleDateFormat("dd,MM,yyyy HH:mm:ss"); - public ExportServiceImpl() { - rootContext = acquireRootContext(); - } - //############## EXPORT EBP /** @@ -96,12 +91,11 @@ StringBuilder result = new StringBuilder(); int num = 0; - TopiaContext topiaContext = beginTransaction(rootContext); try { //export entries FinancialTransactionDAO financialTransactionDAO = - LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); + getDaoHelper().getFinancialTransactionDAO(); List<FinancialTransaction> listFinancialTransaction = financialTransactionDAO.findAll(); // For all financialTransaction @@ -155,10 +149,8 @@ } } } - } catch (Exception eeeTE) { - doCatch(topiaContext, eeeTE); - } finally { - doFinally(topiaContext); + } catch (Exception ex) { + throw new LimaException("Can't export", ex); } return result.toString(); } @@ -173,8 +165,6 @@ StringWriter out = new StringWriter(); CSVWriter csvWriter; - TopiaContext topiaContext = beginTransaction(rootContext); - try { csvWriter = new CSVWriter(out, CSVWriter.DEFAULT_SEPARATOR, @@ -182,8 +172,7 @@ //export accounts String[] nextLine = new String[10]; // Récupère tous les comptes - AccountDAO accountDAO = - LimaCallaoDAOHelper.getAccountDAO(topiaContext); + AccountDAO accountDAO = getDaoHelper().getAccountDAO(); List<Account> listAccount = accountDAO.findAll(); // Pour tous les comptes for (Account account : listAccount) { @@ -195,10 +184,8 @@ // Write cache in string csvWriter.flush(); csvWriter.close(); - } catch (Exception eeeTE) { - doCatch(topiaContext, eeeTE); - } finally { - doFinally(topiaContext); + } catch (Exception ex) { + throw new LimaException("Can't export", ex); } return out.getBuffer().toString(); } @@ -212,24 +199,20 @@ StringWriter out = new StringWriter(); CSVWriter csvWriter; - TopiaContext topiaContext = beginTransaction(rootContext); - try { csvWriter = new CSVWriter(out, ';'); - exportAccountsChartAsCSV(csvWriter, topiaContext); - exportEntryBookChartAsCSV(csvWriter, topiaContext); - exportFinancialStatementChartAsCSV(csvWriter, topiaContext); - exportFiscalPeriodAsCSV(csvWriter, topiaContext); - exportClosedPeriodicEntryBooksAsCSV(csvWriter, topiaContext); - exportFinancialTransactionsAndEntriesAsCSV(csvWriter, topiaContext); - exportIdentityAsCSV(csvWriter, topiaContext); + exportAccountsChartAsCSV(csvWriter); + exportEntryBookChartAsCSV(csvWriter); + exportFinancialStatementChartAsCSV(csvWriter); + exportFiscalPeriodAsCSV(csvWriter); + exportClosedPeriodicEntryBooksAsCSV(csvWriter); + exportFinancialTransactionsAndEntriesAsCSV(csvWriter); + exportIdentityAsCSV(csvWriter); // Write cache in string csvWriter.flush(); csvWriter.close(); - } catch (Exception eeeTE) { - doCatch(topiaContext, eeeTE); - } finally { - doFinally(topiaContext); + } catch (Exception ex) { + throw new LimaException("Can't export", ex); } return out.getBuffer().toString(); } @@ -242,17 +225,14 @@ StringWriter out = new StringWriter(); CSVWriter csvWriter; - TopiaContext topiaContext = beginTransaction(rootContext); try { csvWriter = new CSVWriter(out, ';'); - exportFinancialStatementChartAsCSV(csvWriter, topiaContext); + exportFinancialStatementChartAsCSV(csvWriter); // Write cache in file csvWriter.flush(); csvWriter.close(); - } catch (Exception eeeTE) { - doCatch(topiaContext, eeeTE); - } finally { - doFinally(topiaContext); + } catch (Exception ex) { + throw new LimaException("Can't export", ex); } return out.getBuffer().toString(); } @@ -268,13 +248,12 @@ * @param topiaContext * @throws LimaException */ - public void exportFinancialStatementChartAsCSV(CSVWriter csvWriter, - TopiaContext topiaContext) throws LimaException { + public void exportFinancialStatementChartAsCSV(CSVWriter csvWriter) throws LimaException { try { String[] nextLine = new String[12]; // Get all Financialstatements - FinancialStatementDAO financialStatementDAO = - LimaCallaoDAOHelper.getFinancialStatementDAO(topiaContext); + FinancialStatementDAO financialStatementDAO = + getDaoHelper().getFinancialStatementDAO(); TopiaQuery query = financialStatementDAO.createQuery(); query.addOrder(FinancialStatement.TOPIA_CREATE_DATE); @@ -313,8 +292,8 @@ // Add line in file csvWriter.writeNext(nextLine); } - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (TopiaException ex) { + throw new LimaException("Can't export", ex); } } @@ -325,18 +304,14 @@ StringWriter out = new StringWriter(); CSVWriter csvWriter; - TopiaContext topiaContext = beginTransaction(rootContext); - try { csvWriter = new CSVWriter(out, ';'); - exportVatStatementChartAsCSV(csvWriter, topiaContext); + exportVatStatementChartAsCSV(csvWriter); // Write cache in file csvWriter.flush(); csvWriter.close(); - } catch (Exception eeeTE) { - doCatch(topiaContext, eeeTE); - } finally { - doFinally(topiaContext); + } catch (Exception ex) { + throw new LimaException("Can't export", ex); } return out.getBuffer().toString(); @@ -351,13 +326,11 @@ * @param topiaContext * @throws LimaException */ - public void exportVatStatementChartAsCSV(CSVWriter csvWriter, - TopiaContext topiaContext) throws LimaException { + public void exportVatStatementChartAsCSV(CSVWriter csvWriter) throws LimaException { try { String[] nextLine = new String[6]; // Get all Vatstatements - VatStatementDAO vatStatementDAO = - LimaCallaoDAOHelper.getVatStatementDAO(topiaContext); + VatStatementDAO vatStatementDAO = getDaoHelper().getVatStatementDAO(); TopiaQuery query = vatStatementDAO.createQuery(); query.addOrder(VatStatement.TOPIA_CREATE_DATE); @@ -383,8 +356,8 @@ csvWriter.writeNext(nextLine); } - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (TopiaException ex) { + throw new LimaException("Can't export", ex); } } @@ -396,18 +369,14 @@ StringWriter out = new StringWriter(); CSVWriter csvWriter; - TopiaContext topiaContext = beginTransaction(rootContext); - try { csvWriter = new CSVWriter(out, ';'); - exportEntryBookChartAsCSV(csvWriter, topiaContext); + exportEntryBookChartAsCSV(csvWriter); // Write cache in file csvWriter.flush(); csvWriter.close(); - } catch (Exception eeeTE) { - doCatch(topiaContext, eeeTE); - } finally { - doFinally(topiaContext); + } catch (Exception ex) { + throw new LimaException("Can't export", ex); } return out.getBuffer().toString(); } @@ -421,13 +390,11 @@ * @param topiaContext * @throws LimaException */ - public void exportEntryBookChartAsCSV(CSVWriter csvWriter, - TopiaContext topiaContext) throws LimaException { + public void exportEntryBookChartAsCSV(CSVWriter csvWriter) throws LimaException { try { String[] nextLine = new String[3]; // Get all entrybook - EntryBookDAO entryBookDAO = - LimaCallaoDAOHelper.getEntryBookDAO(topiaContext); + EntryBookDAO entryBookDAO = getDaoHelper().getEntryBookDAO(); List<EntryBook> listEntryBook = entryBookDAO.findAll(); // For all EntryBook for (EntryBook entryBook : listEntryBook) { @@ -437,8 +404,8 @@ // Ajoute la ligne au fichier csvWriter.writeNext(nextLine); } - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (TopiaException ex) { + throw new LimaException("Can't export", ex); } } @@ -449,18 +416,14 @@ StringWriter out = new StringWriter(); CSVWriter csvWriter; - TopiaContext topiaContext = beginTransaction(rootContext); - try { csvWriter = new CSVWriter(out, ';'); - exportAccountsChartAsCSV(csvWriter, topiaContext); + exportAccountsChartAsCSV(csvWriter); // Write cache in file csvWriter.flush(); csvWriter.close(); - } catch (Exception eeeTE) { - doCatch(topiaContext, eeeTE); - } finally { - doFinally(topiaContext); + } catch (Exception ex) { + throw new LimaException("Can't export", ex); } return out.getBuffer().toString(); } @@ -474,13 +437,12 @@ * @param topiaContext * @throws LimaException */ - public void exportAccountsChartAsCSV(CSVWriter csvWriter, - TopiaContext topiaContext) throws LimaException { + public void exportAccountsChartAsCSV(CSVWriter csvWriter) throws LimaException { try { String[] nextLine = new String[6]; // Récupère tous les comptes AccountDAO accountDAO = - LimaCallaoDAOHelper.getAccountDAO(topiaContext); + getDaoHelper().getAccountDAO(); List<Account> listAccount = accountDAO.findAll(); // Pour tous les comptes for (Account account : listAccount) { @@ -492,8 +454,8 @@ // Ajoute la ligne au fichier csvWriter.writeNext(nextLine); } - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (TopiaException ex) { + throw new LimaException("Can't export", ex); } } @@ -507,13 +469,12 @@ * @param topiaContext * @throws LimaException */ - public void exportFinancialTransactionsAndEntriesAsCSV(CSVWriter csvWriter, - TopiaContext topiaContext) throws LimaException { + public void exportFinancialTransactionsAndEntriesAsCSV(CSVWriter csvWriter) throws LimaException { int numTransaction = 0; // Get all financialtransactions try { FinancialTransactionDAO financialTransactionDAO = - LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); + getDaoHelper().getFinancialTransactionDAO(); List<FinancialTransaction> listFinancialTransaction = financialTransactionDAO.findAll(); // For all financialTransaction @@ -548,8 +509,8 @@ } numTransaction++; } - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (TopiaException ex) { + throw new LimaException("Can't export", ex); } } @@ -562,13 +523,12 @@ * @param topiaContext * @throws LimaException */ - public void exportFiscalPeriodAsCSV(CSVWriter csvWriter, - TopiaContext topiaContext) throws LimaException { + public void exportFiscalPeriodAsCSV(CSVWriter csvWriter) throws LimaException { try { String[] nextLine = new String[4]; // Get all fiscalperiod FiscalPeriodDAO fiscalPeriodDAO = - LimaCallaoDAOHelper.getFiscalPeriodDAO(topiaContext); + getDaoHelper().getFiscalPeriodDAO(); List<FiscalPeriod> listFiscalPeriod = fiscalPeriodDAO.findAll(); // For all Entry @@ -580,8 +540,8 @@ // Ajoute la ligne au fichier csvWriter.writeNext(nextLine); } - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (TopiaException ex) { + throw new LimaException("Can't export", ex); } } @@ -593,13 +553,12 @@ * @param topiaContext * @throws LimaException */ - public void exportClosedPeriodicEntryBooksAsCSV(CSVWriter csvWriter, - TopiaContext topiaContext) throws LimaException { + public void exportClosedPeriodicEntryBooksAsCSV(CSVWriter csvWriter) throws LimaException { try { String[] nextLine = new String[5]; // Get all fiscalperiod ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = - LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(topiaContext); + getDaoHelper().getClosedPeriodicEntryBookDAO(); List<ClosedPeriodicEntryBook> listClosedPeriodicEntryBook = closedPeriodicEntryBookDAO.findAll(); // For all Entry @@ -617,17 +576,16 @@ // Ajoute la ligne au fichier csvWriter.writeNext(nextLine); } - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (TopiaException ex) { + throw new LimaException("Can't export", ex); } } - public void exportIdentityAsCSV(CSVWriter csvWriter, - TopiaContext topiaContext) throws LimaException { + public void exportIdentityAsCSV(CSVWriter csvWriter) throws LimaException { try { String[] nextLine = new String[12]; // Get identity - IdentityDAO identityDAO = LimaCallaoDAOHelper.getIdentityDAO(topiaContext); + IdentityDAO identityDAO = getDaoHelper().getIdentityDAO(); List<Identity> identities = identityDAO.findAll(); if (identities.size() != 0) { @@ -647,9 +605,8 @@ // Ajoute la ligne au fichier csvWriter.writeNext(nextLine); } - } catch (TopiaException eeeTE) { - doCatch(topiaContext, eeeTE); + } catch (TopiaException ex) { + throw new LimaException("Can't export", ex); } } - } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -39,13 +39,14 @@ import org.chorem.lima.entity.FinancialPeriodDAO; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.LimaCallaoDAOHelper; -import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; import javax.ejb.Local; import javax.ejb.Remote; import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; + import java.util.Date; import java.util.List; @@ -59,14 +60,9 @@ @Stateless @Remote(FinancialPeriodService.class) @Local(FinancialPeriodServiceLocal.class) +@TransactionAttribute public class FinancialPeriodServiceImpl extends AbstractLimaService implements FinancialPeriodService, FinancialPeriodServiceLocal { - private TopiaContext rootContext; - - public FinancialPeriodServiceImpl() { - rootContext = acquireRootContext(); - } - /** * 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 @@ -74,35 +70,14 @@ @Override public void createFinancialPeriods(List<FinancialPeriod> financialPeriods) throws LimaException { - TopiaContext topiaTransaction = beginTransaction(rootContext); try { - createFinancialPeriodsWithTransaction( - financialPeriods, topiaTransaction); - } catch (Exception ex) { - doCatch(topiaTransaction, ex); - } finally { - doFinally(topiaTransaction); - } - } - - - /** - * 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 - */ - @Override - public void createFinancialPeriodsWithTransaction(List<FinancialPeriod> financialPeriods, - TopiaContext topiaContext) throws LimaException { - - try { - FinancialPeriodDAO financialPeriodDAO = - LimaCallaoDAOHelper.getFinancialPeriodDAO(topiaContext); + getDaoHelper().getFinancialPeriodDAO(); ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = - LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(topiaContext); + getDaoHelper().getClosedPeriodicEntryBookDAO(); EntryBookDAO entryBookDAO = - LimaCallaoDAOHelper.getEntryBookDAO(topiaContext); + getDaoHelper().getEntryBookDAO(); //create all financial period for (FinancialPeriod financialPeriod : financialPeriods) { //create ClosedPeriodicEntryBook for all entrybook @@ -120,9 +95,9 @@ //create financial period financialPeriodDAO.create(financialPeriod); } - commitTransaction(topiaContext); + } catch (TopiaException ex) { - doCatch(topiaContext, ex); + throw new LimaException("Can't create period", ex); } } @@ -132,20 +107,16 @@ List<FinancialPeriod> result = null; - TopiaContext transaction = beginTransaction(rootContext); try { - FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper. - getFinancialPeriodDAO(transaction); + FinancialPeriodDAO financialPeriodDAO = getDaoHelper().getFinancialPeriodDAO(); TopiaQuery query = financialPeriodDAO.createQuery() .addOrder(FinancialPeriod.PROPERTY_BEGIN_DATE); result = financialPeriodDAO.findAllByQuery(query); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't get periods", ex); } return result; @@ -157,11 +128,9 @@ List<FinancialPeriod> result = null; - TopiaContext transaction = beginTransaction(rootContext); try { - FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper. - getFinancialPeriodDAO(transaction); + FinancialPeriodDAO financialPeriodDAO = getDaoHelper().getFinancialPeriodDAO(); TopiaQuery query = financialPeriodDAO.createQuery() .addEquals(FinancialPeriod.PROPERTY_LOCKED, Boolean.FALSE) @@ -169,9 +138,7 @@ result = financialPeriodDAO.findAllByQuery(query); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't create period", ex); } return result; @@ -183,10 +150,8 @@ List<FinancialPeriod> result = null; - TopiaContext transaction = beginTransaction(rootContext); try { - FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper. - getFinancialPeriodDAO(transaction); + FinancialPeriodDAO financialPeriodDAO = getDaoHelper().getFinancialPeriodDAO(); TopiaQuery query = financialPeriodDAO.createQuery() .addBetween(FinancialPeriod.PROPERTY_BEGIN_DATE, beginDate, endDate) @@ -194,28 +159,22 @@ result = financialPeriodDAO.findAllByQuery(query); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't get period", ex); } return result; } - @Override - public void blockClosedPeriodicEntryBookWithTransaction( - ClosedPeriodicEntryBook closedPeriodicEntryBook, - TopiaContext topiaContext) throws LimaException { + public void blockClosedPeriodicEntryBook(ClosedPeriodicEntryBook closedPeriodicEntryBook) throws LimaException { AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); try { // check rules before create the account - accountingRules.blockClosedPeriodicEntryBookRules( - closedPeriodicEntryBook, topiaContext); + accountingRules.blockClosedPeriodicEntryBookRules(closedPeriodicEntryBook); ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = - LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(topiaContext); + getDaoHelper().getClosedPeriodicEntryBookDAO(); //ClosedPeriodicEntryBook closedPeriodicEntryBook2 = // closedPeriodicEntryBookDAO.findByTopiaId( @@ -224,45 +183,23 @@ closedPeriodicEntryBook.setLocked(true); closedPeriodicEntryBookDAO.update(closedPeriodicEntryBook); - commitTransaction(topiaContext); } catch (TopiaException ex) { - doCatch(topiaContext, ex); + throw new LimaException("Can't block period", ex); } } @Override - public void blockClosedPeriodicEntryBook(ClosedPeriodicEntryBook closedPeriodicEntryBook) throws LimaException { - - TopiaContext topiaContext = beginTransaction(rootContext); - try { - - blockClosedPeriodicEntryBookWithTransaction(closedPeriodicEntryBook, topiaContext); - - commitTransaction(topiaContext); - } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); - } - - } - - @Override public ClosedPeriodicEntryBook getClosedPeriodicEntryBook(EntryBook entryBook, FinancialPeriod financialPeriod) throws LimaException { ClosedPeriodicEntryBook closedPeriodicEntryBook = null; - TopiaContext topiaContext = beginTransaction(rootContext); try { - ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = - LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(topiaContext); + ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = getDaoHelper().getClosedPeriodicEntryBookDAO(); closedPeriodicEntryBook = closedPeriodicEntryBookDAO.findByEntryBookAndFinancialPeriod(entryBook, financialPeriod); } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); + throw new LimaException("Can't get closed periodic", ex); } return closedPeriodicEntryBook; @@ -273,11 +210,10 @@ List<ClosedPeriodicEntryBook> result = null; - TopiaContext transaction = beginTransaction(rootContext); try { ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO - = LimaCallaoDAOHelper.getClosedPeriodicEntryBookDAO(transaction); + = getDaoHelper().getClosedPeriodicEntryBookDAO(); //Get closedperiodicentrybook from unlocked fiscalperiod TopiaQuery query = closedPeriodicEntryBookDAO.createQuery("E"); @@ -303,9 +239,7 @@ //call query result = closedPeriodicEntryBookDAO.findAllByQuery(query); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't get closed periodics", ex); } return result; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -43,7 +43,6 @@ import org.chorem.lima.entity.FinancialStatement; import org.chorem.lima.entity.FinancialStatementDAO; import org.chorem.lima.entity.LimaCallaoDAOHelper; -import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; import org.nuiton.topia.framework.TopiaQuery.Op; @@ -52,6 +51,8 @@ import javax.ejb.Local; import javax.ejb.Remote; import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; + import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; @@ -63,26 +64,19 @@ @Stateless @Remote(FinancialStatementService.class) @Local(FinancialStatementServiceLocal.class) +@TransactionAttribute public class FinancialStatementServiceImpl extends AbstractLimaService implements FinancialStatementService, FinancialStatementServiceLocal { - private TopiaContext rootContext; - @EJB private ReportServiceLocal reportServiceLocal; - public FinancialStatementServiceImpl() { - rootContext = acquireRootContext(); - } - @Override - public void createFinancialStatementWithTransaction(FinancialStatement masterFinancialStatement, - FinancialStatement financialStatement, - TopiaContext topiaContext) throws LimaException { + public void createFinancialStatement(FinancialStatement masterFinancialStatement, + FinancialStatement financialStatement) throws LimaException { try { - FinancialStatementDAO financialStatementDAO = - LimaCallaoDAOHelper.getFinancialStatementDAO(topiaContext); + FinancialStatementDAO financialStatementDAO = getDaoHelper().getFinancialStatementDAO(); financialStatementDAO.create(financialStatement); @@ -97,37 +91,18 @@ financialStatementDAO.update(masterfinancialStatementUpdate); } - commitTransaction(topiaContext); } catch (TopiaException ex) { - doCatch(topiaContext, ex); + throw new LimaException("Can't create financial statement", ex); } } @Override - public void createFinancialStatement(FinancialStatement masterFinancialStatement, - FinancialStatement financialStatement) throws LimaException { - - TopiaContext transaction = beginTransaction(rootContext); - try { - createFinancialStatementWithTransaction(masterFinancialStatement, financialStatement, transaction); - } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); - } - } - - - @Override public void removeFinancialStatement(FinancialStatement financialStatement) throws LimaException { - TopiaContext transaction = beginTransaction(rootContext); try { - FinancialStatementDAO financialStatementDAO = - LimaCallaoDAOHelper.getFinancialStatementDAO(transaction); + FinancialStatementDAO financialStatementDAO = getDaoHelper().getFinancialStatementDAO(); - // remove financialstatement FinancialStatement financialStatementToDelete = financialStatementDAO.findByTopiaId( @@ -149,17 +124,11 @@ } } - //commit - commitTransaction(transaction); - } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't remove financial statement", ex); } } - @Override public void removeAllFinancialStatement() throws LimaException { for (FinancialStatement financialStatement : getChildrenFinancialStatement(null)) { @@ -170,15 +139,12 @@ @Override public List<FinancialStatement> getAllFinancialStatements() throws LimaException { List<FinancialStatement> financialStatements = null; - TopiaContext transaction = beginTransaction(rootContext); + try { - FinancialStatementDAO financialStatementDAO = - LimaCallaoDAOHelper.getFinancialStatementDAO(transaction); + FinancialStatementDAO financialStatementDAO = getDaoHelper().getFinancialStatementDAO(); financialStatements = financialStatementDAO.findAll(); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't get financial statements", ex); } return financialStatements; } @@ -195,25 +161,20 @@ return result; } - @Override public List<FinancialStatement> getChildrenFinancialStatement(FinancialStatement masterFinancialStatement) throws LimaException { List<FinancialStatement> financialStatements = null; - TopiaContext transaction = beginTransaction(rootContext); try { - FinancialStatementDAO financialStatementDAO = - LimaCallaoDAOHelper.getFinancialStatementDAO(transaction); + FinancialStatementDAO financialStatementDAO = getDaoHelper().getFinancialStatementDAO(); TopiaQuery query = financialStatementDAO.createQuery(); query.addEquals(FinancialStatement.PROPERTY_MASTER_FINANCIAL_STATEMENT, masterFinancialStatement) .addOrder(FinancialStatement.TOPIA_CREATE_DATE); financialStatements = financialStatementDAO.findAllByQuery(query); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't get childreen statements", ex); } return financialStatements; } @@ -221,40 +182,34 @@ @Override public void updateFinancialStatement(FinancialStatement financialStatement) throws LimaException { - TopiaContext transaction = beginTransaction(rootContext); - try { + try { // DAO - FinancialStatementDAO financialStatementHeaderDAO = - LimaCallaoDAOHelper.getFinancialStatementDAO(transaction); + FinancialStatementDAO financialStatementHeaderDAO = getDaoHelper().getFinancialStatementDAO(); //update financialStatementHeaderDAO.update(financialStatement); - //commit - commitTransaction(transaction); + } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't update financial statement", ex); } } - /** remote methode to get list of financial statement */ + /** + * remote methode to get list of financial statement + */ @Override public List<FinancialStatementAmounts> financialStatementReport(Date selectedBeginDate, Date selectedEndDate) throws LimaException { List<FinancialStatementAmounts> result = null; - TopiaContext transaction = beginTransaction(rootContext); + try { //create list form tree result = financialStatementReport(null, selectedBeginDate, - selectedEndDate, new FinancialStatementDatasImpl(), - transaction).getListResult(); + selectedEndDate, new FinancialStatementDatasImpl()).getListResult(); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't generate report", ex); } return result; } @@ -270,107 +225,104 @@ * @return * @throws LimaException */ - public FinancialStatementDatas financialStatementReport(FinancialStatement financialStatement, + protected FinancialStatementDatas financialStatementReport(FinancialStatement financialStatement, Date selectedBeginDate, Date selectedEndDate, - FinancialStatementDatas result, - TopiaContext topiaContext) throws LimaException { + FinancialStatementDatas result) throws LimaException { List<FinancialStatement> financialStatements = getChildrenFinancialStatement(financialStatement); - try { - BigDecimal grossAmount = new BigDecimal(0), - provisionDeprecationAmount = new BigDecimal(0); - List<FinancialStatementAmounts> subResult = - new ArrayList<FinancialStatementAmounts>(); - for (FinancialStatement subFinancialStatement : financialStatements) { - FinancialStatementAmounts financialStatementAmounts = - financialStatementAmounts(subFinancialStatement, - selectedBeginDate, selectedEndDate, topiaContext); - if (!subFinancialStatement.getHeader()) { - //on calcul - grossAmount = - grossAmount.add(financialStatementAmounts.getGrossAmount()); - provisionDeprecationAmount = provisionDeprecationAmount.add( - financialStatementAmounts.getProvisionDeprecationAmount()); - subResult.add(financialStatementAmounts); - } else { - FinancialStatementDatas financialStatementDatas = - financialStatementReport(subFinancialStatement, - selectedBeginDate, selectedEndDate, result, topiaContext); - grossAmount = grossAmount.add(financialStatementDatas. - getFinancialStatementAmounts().getGrossAmount()); - provisionDeprecationAmount = provisionDeprecationAmount. - add(financialStatementDatas.getFinancialStatementAmounts(). - getProvisionDeprecationAmount()); + BigDecimal grossAmount = new BigDecimal(0), + provisionDeprecationAmount = new BigDecimal(0); + List<FinancialStatementAmounts> subResult = + new ArrayList<FinancialStatementAmounts>(); + for (FinancialStatement subFinancialStatement : financialStatements) { + FinancialStatementAmounts financialStatementAmounts = + financialStatementAmounts(subFinancialStatement, + selectedBeginDate, selectedEndDate); + if (!subFinancialStatement.getHeader()) { + //on calcul + grossAmount = + grossAmount.add(financialStatementAmounts.getGrossAmount()); + provisionDeprecationAmount = provisionDeprecationAmount.add( + financialStatementAmounts.getProvisionDeprecationAmount()); + subResult.add(financialStatementAmounts); + } else { + FinancialStatementDatas financialStatementDatas = + financialStatementReport(subFinancialStatement, + selectedBeginDate, selectedEndDate, result); + grossAmount = grossAmount.add(financialStatementDatas. + getFinancialStatementAmounts().getGrossAmount()); + provisionDeprecationAmount = provisionDeprecationAmount. + add(financialStatementDatas.getFinancialStatementAmounts(). + getProvisionDeprecationAmount()); - FinancialStatementAmounts headerfinancialStatementAmounts = - financialStatementDatas.getFinancialStatementAmounts(); - //Si sous-total - if (subFinancialStatement.getSubAmount()) { - FinancialStatementAmounts header = - new FinancialStatementAmountsImpl(); - header.setLabel(headerfinancialStatementAmounts.getLabel()); - header.setLevel(headerfinancialStatementAmounts.getLevel()); - header.setHeader(true); - //ajoute header - subResult.add(header); - //ajoute liste - if (financialStatementDatas.getListResult() != null) { - subResult.addAll(financialStatementDatas.getListResult()); - } - //ajoute sstotal - FinancialStatementAmounts subAmount = - new FinancialStatementAmountsImpl(); - subAmount.setLabel( - "TOTAL " + headerfinancialStatementAmounts.getLabel()); - subAmount.setLevel( - headerfinancialStatementAmounts.getLevel()); - subAmount.setGrossAmount( - headerfinancialStatementAmounts.getGrossAmount()); - subAmount.setProvisionDeprecationAmount( - headerfinancialStatementAmounts. - getProvisionDeprecationAmount()); - subAmount.setSubAmount(true); - subResult.add(subAmount); - //ajoute une ligne vide - subResult.add(new FinancialStatementAmountsImpl()); - }//sinon - else { - - if (subFinancialStatement.getHeaderAmount()) { - subResult.add(headerfinancialStatementAmounts); - } else { + FinancialStatementAmounts headerfinancialStatementAmounts = + financialStatementDatas.getFinancialStatementAmounts(); + //Si sous-total + if (subFinancialStatement.getSubAmount()) { + FinancialStatementAmounts header = + new FinancialStatementAmountsImpl(); + header.setLabel(headerfinancialStatementAmounts.getLabel()); + header.setLevel(headerfinancialStatementAmounts.getLevel()); + header.setHeader(true); + //ajoute header + subResult.add(header); + //ajoute liste + if (financialStatementDatas.getListResult() != null) { + subResult.addAll(financialStatementDatas.getListResult()); + } + //ajoute sstotal + FinancialStatementAmounts subAmount = + new FinancialStatementAmountsImpl(); + subAmount.setLabel( + "TOTAL " + headerfinancialStatementAmounts.getLabel()); + subAmount.setLevel( + headerfinancialStatementAmounts.getLevel()); + subAmount.setGrossAmount( + headerfinancialStatementAmounts.getGrossAmount()); + subAmount.setProvisionDeprecationAmount( headerfinancialStatementAmounts. - setGrossAmount(new BigDecimal(0)); - headerfinancialStatementAmounts. - setProvisionDeprecationAmount(new BigDecimal(0)); - subResult.add(headerfinancialStatementAmounts); - } - //ajoute liste - if (financialStatementDatas.getListResult() != null) { - subResult.addAll(financialStatementDatas.getListResult()); - } + getProvisionDeprecationAmount()); + subAmount.setSubAmount(true); + subResult.add(subAmount); + //ajoute une ligne vide + subResult.add(new FinancialStatementAmountsImpl()); + + }//sinon + else { + + if (subFinancialStatement.getHeaderAmount()) { + subResult.add(headerfinancialStatementAmounts); + } else { + headerfinancialStatementAmounts. + setGrossAmount(new BigDecimal(0)); + headerfinancialStatementAmounts. + setProvisionDeprecationAmount(new BigDecimal(0)); + subResult.add(headerfinancialStatementAmounts); } + //ajoute liste + if (financialStatementDatas.getListResult() != null) { + subResult.addAll(financialStatementDatas.getListResult()); + } } } - FinancialStatementAmounts financialStatementAmounts = - new FinancialStatementAmountsImpl(); - financialStatementAmounts.setGrossAmount(grossAmount); - financialStatementAmounts.setProvisionDeprecationAmount( - provisionDeprecationAmount); - if (financialStatement != null) { - financialStatementAmounts.setLabel(financialStatement.getLabel()); - financialStatementAmounts.setHeader(financialStatement.getHeader()); - financialStatementAmounts.setLevel(financialStatement.getLevel()); - } - result.setFinancialStatementAmounts(financialStatementAmounts); - result.setListResult(subResult); - } catch (LimaException eee) { - doCatch(topiaContext, eee); } + FinancialStatementAmounts financialStatementAmounts = + new FinancialStatementAmountsImpl(); + financialStatementAmounts.setGrossAmount(grossAmount); + financialStatementAmounts.setProvisionDeprecationAmount( + provisionDeprecationAmount); + if (financialStatement != null) { + financialStatementAmounts.setLabel(financialStatement.getLabel()); + financialStatementAmounts.setHeader(financialStatement.getHeader()); + financialStatementAmounts.setLevel(financialStatement.getLevel()); + } + result.setFinancialStatementAmounts(financialStatementAmounts); + result.setListResult(subResult); + return result; } @@ -385,10 +337,9 @@ * @return * @throws LimaException */ - public FinancialStatementAmounts financialStatementAmounts(FinancialStatement financialStatement, + protected FinancialStatementAmounts financialStatementAmounts(FinancialStatement financialStatement, Date selectedBeginDate, - Date selectedEndDate, - TopiaContext topiaContext) throws LimaException { + Date selectedEndDate) throws LimaException { FinancialStatementAmounts financialStatementAmounts = new FinancialStatementAmountsImpl(); BigDecimal amount = new BigDecimal(0); @@ -409,7 +360,7 @@ String accountsString = financialStatement.getAccounts(); if (accountsString != null && !accountsString.equals("")) { amounts = amountFromAccountList(accountsString, - selectedBeginDate, selectedEndDate, topiaContext); + selectedBeginDate, selectedEndDate); debitAmount = debitAmount.add(amounts.getDebit()); creditAmount = creditAmount.add(amounts.getCredit()); } @@ -417,14 +368,14 @@ String debitAccountsString = financialStatement.getDebitAccounts(); if (debitAccountsString != null && !debitAccountsString.equals("")) { amounts = amountFromAccountList(debitAccountsString, - selectedBeginDate, selectedEndDate, topiaContext); + selectedBeginDate, selectedEndDate); debitAmount = debitAmount.add(amounts.getDebit()); } //CREDIT ACCOUNTS LIST String creditAccountsString = financialStatement.getCreditAccounts(); if (creditAccountsString != null && !creditAccountsString.equals("")) { amounts = amountFromAccountList(creditAccountsString, - selectedBeginDate, selectedEndDate, topiaContext); + selectedBeginDate, selectedEndDate); creditAmount = creditAmount.add(amounts.getCredit()); } // PROVISION & DEPRECATION @@ -433,7 +384,7 @@ if (provisionDeprecationAccountsString != null && !provisionDeprecationAccountsString.equals("")) { amounts = amountFromAccountList( provisionDeprecationAccountsString, selectedBeginDate, - selectedEndDate, topiaContext); + selectedEndDate); provisionDeprecationAmount = provisionDeprecationAmount.add(amounts.getCredit()); provisionDeprecationAmount = @@ -464,17 +415,15 @@ return financialStatementAmounts; } - - public Amounts amountFromAccountList(String accountsNumberList, + protected Amounts amountFromAccountList(String accountsNumberList, Date selectedBeginDate, - Date selectedEndDate, - TopiaContext topiaContext) throws LimaException { + Date selectedEndDate) throws LimaException { Amounts amounts = new AmountsImpl(); BigDecimal debit = new BigDecimal(0); BigDecimal credit = new BigDecimal(0); Boolean substract = false; try { - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(topiaContext); + AccountDAO accountDAO = getDaoHelper().getAccountDAO(); //Remove Spaces String result = StringUtils.deleteWhitespace(accountsNumberList); StringTokenizer stQuote = new StringTokenizer(result, "-"); @@ -485,8 +434,8 @@ BigDecimal creditTemp = new BigDecimal(0); for (Account account : accountsList) { ReportsDatas reportsDatas = reportServiceLocal. - generateAccountReportsWithTransaction(account, true, - selectedBeginDate, selectedEndDate, topiaContext); + generateAccountsReports(account, true, + selectedBeginDate, selectedEndDate); if (reportsDatas.getSoldeDebit()) { debitTemp = debitTemp.add(reportsDatas.getAmountSolde()); } else { @@ -506,25 +455,22 @@ } amounts.setCredit(credit); amounts.setDebit(debit); - } catch (TopiaException e) { - doCatch(topiaContext, e); + } catch (TopiaException ex) { + throw new LimaException("Can't get accounts from list", ex); } return amounts; } - @Override public String checkFinancialStatementChart() throws LimaException { StringBuilder result = new StringBuilder(_("lima-business.financialstatement.check.warn")); - TopiaContext transaction = null; + try { - transaction = beginTransaction(rootContext); - AccountDAO accountDAO = - LimaCallaoDAOHelper.getAccountDAO(transaction); - FinancialStatementDAO financialStatementDAO = - LimaCallaoDAOHelper.getFinancialStatementDAO(transaction); + AccountDAO accountDAO = getDaoHelper().getAccountDAO(); + FinancialStatementDAO financialStatementDAO = getDaoHelper().getFinancialStatementDAO(); + List<Account> accountsList = accountDAO.findAllLeafAccounts(); List<FinancialStatement> financialStatementsList = @@ -557,18 +503,14 @@ } } catch (TopiaException ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't check financial statement", ex); } return result.toString(); } - public List<FinancialStatement> findFinancialStatementByAccountNumber(String accountNumber, - TopiaContext topiaContext) throws TopiaException { + protected List<FinancialStatement> findFinancialStatementByAccountNumber(String accountNumber) throws TopiaException { - FinancialStatementDAO financialStatementDAO = - LimaCallaoDAOHelper.getFinancialStatementDAO(topiaContext); + FinancialStatementDAO financialStatementDAO = getDaoHelper().getFinancialStatementDAO(); TopiaQuery query = financialStatementDAO.createQuery(); String accountProperty = Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -34,13 +34,14 @@ import javax.ejb.Local; import javax.ejb.Remote; import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; import org.chorem.lima.FinancialStatementWayEnum; import org.chorem.lima.beans.FinancialTransactionSearch; import org.chorem.lima.business.AccountingRules; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; -import org.chorem.lima.business.api.EntryBookServiceLocal; +import org.chorem.lima.business.api.EntryBookService; import org.chorem.lima.business.api.FinancialPeriodServiceLocal; import org.chorem.lima.business.api.FinancialTransactionService; import org.chorem.lima.business.api.FinancialTransactionServiceLocal; @@ -52,7 +53,6 @@ import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryDAO; import org.chorem.lima.entity.FinancialPeriod; -import org.chorem.lima.entity.FinancialPeriodDAO; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FinancialTransactionDAO; import org.chorem.lima.entity.FiscalPeriod; @@ -74,10 +74,9 @@ @Stateless @Remote(FinancialTransactionService.class) @Local(FinancialTransactionServiceLocal.class) +@TransactionAttribute public class FinancialTransactionServiceImpl extends AbstractLimaService implements FinancialTransactionService, FinancialTransactionServiceLocal { - private TopiaContext rootContext; - @EJB protected FinancialPeriodServiceLocal financialPeriodService; @@ -85,88 +84,67 @@ protected ReportServiceLocal reportService; @EJB - protected EntryBookServiceLocal entryBookService; + protected EntryBookService entryBookService; @EJB protected OptionsServiceLocal optionsService; - public FinancialTransactionServiceImpl() { - rootContext = acquireRootContext(); - } - @Override - public FinancialTransaction createFinancialTransactionWithTransaction( - FinancialTransaction financialtransaction, TopiaContext topiaContext) + public FinancialTransaction createFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException { FinancialTransaction fTransaction = null; AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); try { //check if the financial period is blocked - accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction( - financialtransaction, topiaContext); + accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction(financialtransaction); - FinancialTransactionDAO financialtransactionDAO = - LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); + FinancialTransactionDAO financialtransactionDAO = getDaoHelper().getFinancialTransactionDAO(); fTransaction = financialtransactionDAO.create(financialtransaction); - commitTransaction(topiaContext); - } catch (TopiaException ex) { - doCatch(topiaContext, ex); + throw new LimaException("Can't create financial transaction", ex); } return fTransaction; } - /** Permet de créer une transaction comptable contenant des entrées */ + /** + * Return the list of all financial transaction from two dates. + */ @Override - public FinancialTransaction createFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException { - - TopiaContext topiaContext = beginTransaction(rootContext); - try { - return createFinancialTransactionWithTransaction(financialtransaction, topiaContext); - } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); - } - return null; - } - - /** Return the list of all financial transaction from two dates */ - @Override public List<FinancialTransaction> getAllFinancialTransactions( Date beginDate, Date endDate) throws LimaException { List<FinancialTransaction> financialTransactions = null; - TopiaContext topiaTransaction = beginTransaction(rootContext); + try { - FinancialTransactionDAO transactionDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaTransaction); + FinancialTransactionDAO transactionDAO = getDaoHelper().getFinancialTransactionDAO(); financialTransactions = transactionDAO.findAllByDates(beginDate, endDate); } catch (Exception ex) { - doCatch(topiaTransaction, ex); - } finally { - doFinally(topiaTransaction); + throw new LimaException("Can't get financial transactions", ex); } return financialTransactions; } - /** Return the list of all financial transaction of a financial period */ + /** + * Return the list of all financial transaction of a financial period. + */ @Override public List<FinancialTransaction> getAllFinancialTransactions( FinancialPeriod period) throws LimaException { return getAllFinancialTransactions(period, null); } - /** Return the list of all financial transaction of a financial period and an entrybook */ + /** + * Return the list of all financial transaction of a financial period and an entrybook. + */ @Override public List<FinancialTransaction> getAllFinancialTransactions(FinancialPeriod financialPeriod, EntryBook entryBook) throws LimaException { List<FinancialTransaction> financialTransactions = null; - TopiaContext topiaTransaction = beginTransaction(rootContext); + try { - FinancialTransactionDAO transactionDAO = - LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaTransaction); + FinancialTransactionDAO transactionDAO = getDaoHelper().getFinancialTransactionDAO(); if (entryBook != null) { financialTransactions = transactionDAO.findAllByDates(financialPeriod.getBeginDate(), @@ -177,26 +155,22 @@ } } catch (Exception ex) { - doCatch(topiaTransaction, ex); - } finally { - doFinally(topiaTransaction); + throw new LimaException("Can't get financial transactions", ex); } return financialTransactions; } - /** * Get unbalanced financialtransaction from selected fiscalperiod. */ @Override public List<FinancialTransaction> getAllInexactFinancialTransactions(FiscalPeriod fiscalPeriod) throws LimaException { - TopiaContext topiaContext = beginTransaction(rootContext); + List<FinancialTransaction> result = null; List<FinancialTransaction> checkedResult = new ArrayList<FinancialTransaction>(); try { - FinancialTransactionDAO financialTransactionDAO = - LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); + FinancialTransactionDAO financialTransactionDAO = getDaoHelper().getFinancialTransactionDAO(); result = financialTransactionDAO.getAllIncorrectTransaction(fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate(), null); @@ -213,85 +187,43 @@ } } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); + throw new LimaException("Can't get financial transactions", ex); } return result; } - @Override - public List<FinancialTransaction> getAllFinancialTransactionsBalanced(FiscalPeriod fiscalPeriod) throws LimaException { - TopiaContext topiaContext = beginTransaction(rootContext); - List<FinancialTransaction> result = null; - try { - result = getAllFinancialTransactionsBalanced(fiscalPeriod, topiaContext); - } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); - } - return result; - } - - /** * Get balanced financialtransaction from selected fiscalperiod * * @param fiscalPeriod - * @param topiaContext * @return * @throws LimaException */ - public List<FinancialTransaction> getAllFinancialTransactionsBalanced(FiscalPeriod fiscalPeriod, - TopiaContext topiaContext) throws LimaException { + @Override + public List<FinancialTransaction> getAllFinancialTransactionsBalanced(FiscalPeriod fiscalPeriod) throws LimaException { List<FinancialTransaction> result = null; try { - FinancialTransactionDAO financialTransactionDAO = - LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); + FinancialTransactionDAO financialTransactionDAO = getDaoHelper().getFinancialTransactionDAO(); result = financialTransactionDAO.getAllBalancedTransaction(fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate(), null); } catch (TopiaException ex) { - doCatch(topiaContext, ex); + throw new LimaException("Can't get financial transactions", ex); } return result; } - /** - * update date and amount of a financial transaction - * call accounting rules - */ - @Override - public void updateFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException { - - TopiaContext topiaContext = beginTransaction(rootContext); - try { - updateFinancialTransactionWithTransaction( - financialtransaction, topiaContext); - commitTransaction(topiaContext); - } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); - } - - } - - /** * Method used by update entry and remove entry for update amounts. */ @Override - public void updateFinancialTransactionWithTransaction(FinancialTransaction financialtransaction, - TopiaContext topiaContext) throws LimaException { + public void updateFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException { AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); try { - FinancialTransactionDAO transactionDAO = - LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); + FinancialTransactionDAO transactionDAO = getDaoHelper().getFinancialTransactionDAO(); FinancialTransaction financialTransactionOld = transactionDAO.findByTopiaId(financialtransaction.getTopiaId()); @@ -305,7 +237,7 @@ financialtransaction.getEntryBook()); transactionDAO.update(financialTransactionOld); } catch (TopiaException ex) { - doCatch(topiaContext, ex); + throw new LimaException("Can't update financial transaction", ex); } } @@ -316,91 +248,59 @@ @Override public void removeFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException { - TopiaContext topiaTransaction = beginTransaction(rootContext); AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); try { //check if the financial period is blocked accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction( - financialtransaction, topiaTransaction); + financialtransaction); - FinancialTransactionDAO transactionDAO = - LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaTransaction); + FinancialTransactionDAO transactionDAO = getDaoHelper().getFinancialTransactionDAO(); FinancialTransaction financialTransaction2 = //patch : conflict object already instanciate transactionDAO.findByTopiaId(financialtransaction.getTopiaId()); - transactionDAO.delete(financialTransaction2); - commitTransaction(topiaTransaction); + } catch (Exception ex) { - doCatch(topiaTransaction, ex); - } finally { - doFinally(topiaTransaction); + throw new LimaException("Can't remove financial transaction", ex); } } @Override - public Entry createEntryWithTransaction(Entry entry, - TopiaContext topiaContext) throws LimaException { + public Entry createEntry(Entry entry) throws LimaException { AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); Entry newEntry = null; try { //check if the financial period is blocked accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction( - entry.getFinancialTransaction(), topiaContext); + entry.getFinancialTransaction()); - - EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); + EntryDAO entryDAO = getDaoHelper().getEntryDAO(); newEntry = entryDAO.create(entry); - } catch (TopiaException e) { - doCatch(topiaContext, e); + } catch (TopiaException ex) { + throw new LimaException("Can't create entry", ex); } return newEntry; } /** - * Create new entry - * the period must not be blocked, call accounting rules - * - * @return + * update entry, calculate amount of the financial transaction. */ @Override - public Entry createEntry(Entry entry) throws LimaException { - - TopiaContext topiaContext = beginTransaction(rootContext); - try { - - Entry newEntry = createEntryWithTransaction(entry, topiaContext); - - commitTransaction(topiaContext); - - return newEntry; - } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); - } - return null; - } - - - /** update entry, calculate amount of the financial transaction */ - @Override public void updateEntry(Entry entry) throws LimaException { - TopiaContext topiaContext = beginTransaction(rootContext); AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); try { - EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); + EntryDAO entryDAO = getDaoHelper().getEntryDAO(); Entry entryOld = entryDAO.findByTopiaId(entry.getTopiaId()); //check rules - accountingRules.updateEntryRules(entry, entryOld, topiaContext); + accountingRules.updateEntryRules(entry, entryOld); //get new entry amounts BigDecimal entryAmount = entry.getAmount(); @@ -419,36 +319,31 @@ //update entry entryDAO.update(entryOld); - commitTransaction(topiaContext); + } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); + throw new LimaException("Can't update entry", ex); } } - /** Remove entry, update amounts for the financial transaction */ + /** + * Remove entry, update amounts for the financial transaction. + */ @Override public void removeEntry(Entry entry) throws LimaException { AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); - TopiaContext topiaContext = beginTransaction(rootContext); try { - //check if the financial period is blocked accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction( - entry.getFinancialTransaction(), topiaContext); + entry.getFinancialTransaction()); - EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); + EntryDAO entryDAO = getDaoHelper().getEntryDAO(); //delete entryDAO.delete(entry); - //commit - commitTransaction(topiaContext); - } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); + + } catch (TopiaException ex) { + throw new LimaException("Can't remove entry", ex); } } @@ -456,10 +351,9 @@ public List<Object> searchFinancialTransaction(FinancialTransactionSearch financialTransactionSearch) throws LimaException { List<Object> result = new ArrayList<Object>(); List<FinancialTransaction> financialTransactions; - TopiaContext topiaContext = beginTransaction(rootContext); + try { - FinancialTransactionDAO financialTransactionDAO = - LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaContext); + FinancialTransactionDAO financialTransactionDAO = getDaoHelper().getFinancialTransactionDAO(); TopiaQuery query = financialTransactionDAO.createQuery("T"); String dateProperty = TopiaQuery.getProperty(FinancialTransaction.PROPERTY_TRANSACTION_DATE); @@ -495,7 +389,7 @@ if (account != null) { query.addEquals("E.account", account); } else if (accountsList != null) { - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(topiaContext); + AccountDAO accountDAO = getDaoHelper().getAccountDAO(); List<Account> accounts = accountDAO.stringToListAccounts(accountsList, false); StringBuffer accountNumbers = new StringBuffer("0,"); @@ -538,7 +432,7 @@ } financialTransactions = financialTransactionDAO.findAllByQuery(query); - EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); + EntryDAO entryDAO = getDaoHelper().getEntryDAO(); for (FinancialTransaction financialTransaction : financialTransactions) { result.add(financialTransaction); @@ -548,9 +442,7 @@ result.addAll(entries); } } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); + throw new LimaException("Can't search financial transaction", ex); } return result; } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -40,6 +40,7 @@ import javax.ejb.Local; import javax.ejb.Remote; import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; import org.apache.commons.lang3.time.DateUtils; import org.chorem.lima.beans.BalanceTrial; @@ -49,7 +50,7 @@ import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; import org.chorem.lima.business.api.AccountService; -import org.chorem.lima.business.api.EntryBookServiceLocal; +import org.chorem.lima.business.api.EntryBookService; import org.chorem.lima.business.api.FinancialPeriodServiceLocal; import org.chorem.lima.business.api.FinancialTransactionServiceLocal; import org.chorem.lima.business.api.FiscalPeriodService; @@ -67,8 +68,6 @@ import org.chorem.lima.entity.FinancialTransactionImpl; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.FiscalPeriodDAO; -import org.chorem.lima.entity.LimaCallaoDAOHelper; -import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; @@ -81,10 +80,9 @@ @Stateless @Remote(FiscalPeriodService.class) @Local(FiscalPeriodServiceLocal.class) +@TransactionAttribute public class FiscalPeriodServiceImpl extends AbstractLimaService implements FiscalPeriodService, FiscalPeriodServiceLocal { - private TopiaContext rootContext; - @EJB protected AccountService accountService; @@ -92,7 +90,7 @@ protected FinancialPeriodServiceLocal financialPeriodService; @EJB - protected EntryBookServiceLocal entryBookService; + protected EntryBookService entryBookService; @EJB protected ReportServiceLocal reportService; @@ -100,13 +98,8 @@ @EJB protected FinancialTransactionServiceLocal financialTransactionService; - public FiscalPeriodServiceImpl() { - rootContext = acquireRootContext(); - } - @Override - public FiscalPeriod createFiscalPeriodWithTransaction(FiscalPeriod fiscalPeriod, - TopiaContext topiaContext) throws LimaException { + public FiscalPeriod createFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException { AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); FiscalPeriod result = null; @@ -125,82 +118,54 @@ //check rules before create the account List<FinancialPeriod> financialPeriods = - accountingRules.createFiscalPeriodRules(fiscalPeriod, topiaContext); + accountingRules.createFiscalPeriodRules(fiscalPeriod); financialPeriodService. - createFinancialPeriodsWithTransaction(financialPeriods, topiaContext); + createFinancialPeriods(financialPeriods); - FiscalPeriodDAO fiscalPeriodDAO = - LimaCallaoDAOHelper.getFiscalPeriodDAO(topiaContext); + FiscalPeriodDAO fiscalPeriodDAO = getDaoHelper().getFiscalPeriodDAO(); //create result = fiscalPeriodDAO.create(fiscalPeriod); - - commitTransaction(topiaContext); } catch (TopiaException ex) { - doCatch(topiaContext, ex); + throw new LimaException("Can't create period", ex); } return result; } /** - * To create a fiscalperiod - * Check localized rules before create + * return all fiscal period. */ @Override - public FiscalPeriod createFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException { - - TopiaContext transaction = beginTransaction(rootContext); - FiscalPeriod result = null; - try { - result = createFiscalPeriodWithTransaction(fiscalPeriod, transaction); - } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); - } - - return result; - } - - /** return all fiscal period */ - @Override public List<FiscalPeriod> getAllFiscalPeriods() throws LimaException { List<FiscalPeriod> result = null; - TopiaContext transaction = beginTransaction(rootContext); try { - FiscalPeriodDAO fiscalPeriodDAO = - LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + FiscalPeriodDAO fiscalPeriodDAO = getDaoHelper().getFiscalPeriodDAO(); result = fiscalPeriodDAO.findAll(); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't get periods", ex); } return result; } - /** return all blocked fiscal periods */ + /** + * return all blocked fiscal periods. + */ @Override public List<FiscalPeriod> getAllBlockedFiscalPeriods() throws LimaException { List<FiscalPeriod> result = null; - TopiaContext transaction = beginTransaction(rootContext); try { - - FiscalPeriodDAO fiscalPeriodDAO = - LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + FiscalPeriodDAO fiscalPeriodDAO = getDaoHelper().getFiscalPeriodDAO(); result = fiscalPeriodDAO.findAllByLocked(true); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't create period", ex); } return result; @@ -213,16 +178,12 @@ List<FiscalPeriod> result = null; - TopiaContext transaction = beginTransaction(rootContext); try { - FiscalPeriodDAO fiscalPeriodDAO = - LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + FiscalPeriodDAO fiscalPeriodDAO = getDaoHelper().getFiscalPeriodDAO(); result = fiscalPeriodDAO.findAllByLocked(false); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't get periods", ex); } return result; @@ -231,11 +192,10 @@ @Override public FiscalPeriod getLastFiscalPeriod() throws LimaException { FiscalPeriod result = null; - TopiaContext transaction = beginTransaction(rootContext); + try { - FiscalPeriodDAO fiscalPeriodDAO = - LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + FiscalPeriodDAO fiscalPeriodDAO = getDaoHelper().getFiscalPeriodDAO(); TopiaQuery query = fiscalPeriodDAO.createQuery(); query.addOrderDesc(FiscalPeriod.PROPERTY_END_DATE); @@ -243,9 +203,7 @@ result = fiscalPeriodDAO.findByQuery(query); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't get period", ex); } return result; @@ -258,8 +216,6 @@ */ @Override public FiscalPeriod blockFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException { - //open transaction for update - TopiaContext transaction = beginTransaction(rootContext); AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); @@ -270,10 +226,9 @@ throw new LimaBusinessException(_("lima-business.fiscalperiod.fiscalperiodalreadyblocked")); } //check rules - accountingRules.blockFiscalPeriodRules(fiscalPeriod, transaction); + accountingRules.blockFiscalPeriodRules(fiscalPeriod); - FiscalPeriodDAO fiscalPeriodDAO = - LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + FiscalPeriodDAO fiscalPeriodDAO = getDaoHelper().getFiscalPeriodDAO(); // Get the old fiscal period instance for no object conflict FiscalPeriod oldFiscalPeriod = @@ -288,14 +243,10 @@ result = fiscalPeriodDAO.update(oldFiscalPeriod); - commitTransaction(transaction); - } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't block period", ex); } - + return result; } @@ -303,19 +254,28 @@ public void addRetainedEarnings(FiscalPeriod fiscalPeriod, boolean newyear, EntryBook entryBook) throws LimaException { - TopiaContext topiaContext = beginTransaction(rootContext); - try { - - //sets dates - // - endRetainedEarnings: last day of the closing year - // - beginRetainedEarnings: first open day of the following year + //sets dates + // - endRetainedEarnings: last day of the closing year + // - beginRetainedEarnings: first open day of the following year // Date endRetainedEarnings = fiscalPeriod.getBeginDate(); // Date beginRetainedEarnings = null; - //Sets entryBook - //search for the entryBook to use using param - boolean found = false; - List<EntryBook> entryBooksList = entryBookService.getAllEntryBooks(); + //Sets entryBook + //search for the entryBook to use using param + boolean found = false; + List<EntryBook> entryBooksList = entryBookService.getAllEntryBooks(); + for (EntryBook entry : entryBooksList) { + if (!found && entry.getCode().equals(entryBook.getCode()) + && entry.getLabel().equals(entryBook.getLabel())) { + entryBook = entry; + found = true; + } + } + //if entrybook isn't found + //then create it + if (!found) { + entryBookService.createEntryBook(entryBook); + entryBooksList = entryBookService.getAllEntryBooks(); for (EntryBook entry : entryBooksList) { if (!found && entry.getCode().equals(entryBook.getCode()) && entry.getLabel().equals(entryBook.getLabel())) { @@ -323,191 +283,167 @@ found = true; } } - //if entrybook isn't found - //then create it - if (!found) { - entryBookService.createEntryBook(entryBook); - entryBooksList = entryBookService.getAllEntryBooks(); - for (EntryBook entry : entryBooksList) { - if (!found && entry.getCode().equals(entryBook.getCode()) - && entry.getLabel().equals(entryBook.getLabel())) { - entryBook = entry; - found = true; - } - } - } + } - //Sets accounts, check if they exist, if not create them - //-> 8 COMPTES SPECIAUX - // -> 89 BILAN - // -> 890 Bilan d'ouverture - // -> 891 Bilan de cloture + //Sets accounts, check if they exist, if not create them + //-> 8 COMPTES SPECIAUX + // -> 89 BILAN + // -> 890 Bilan d'ouverture + // -> 891 Bilan de cloture - //89 BILAN - Account accountMaster = accountService.getAccountByNumber("89"); - if (accountMaster == null) { - accountMaster = new AccountImpl(); - accountMaster.setAccountNumber("89"); - accountMaster.setLabel("BILAN"); - accountService.createAccount(accountMaster); - accountMaster = accountService.getAccountByNumber("89"); - } + //89 BILAN + Account accountMaster = accountService.getAccountByNumber("89"); + if (accountMaster == null) { + accountMaster = new AccountImpl(); + accountMaster.setAccountNumber("89"); + accountMaster.setLabel("BILAN"); + accountService.createAccount(accountMaster); + accountMaster = accountService.getAccountByNumber("89"); + } - //890 Bilan d'ouverture - Account beginRetainedAccount = accountService.getAccountByNumber("890"); - if (beginRetainedAccount == null) { - beginRetainedAccount = new AccountImpl(); - beginRetainedAccount.setAccountNumber("890"); - beginRetainedAccount.setLabel("Bilan d'ouverture"); - accountService.createAccount(beginRetainedAccount); - beginRetainedAccount = accountService.getAccountByNumber("890"); - } + //890 Bilan d'ouverture + Account beginRetainedAccount = accountService.getAccountByNumber("890"); + if (beginRetainedAccount == null) { + beginRetainedAccount = new AccountImpl(); + beginRetainedAccount.setAccountNumber("890"); + beginRetainedAccount.setLabel("Bilan d'ouverture"); + accountService.createAccount(beginRetainedAccount); + beginRetainedAccount = accountService.getAccountByNumber("890"); + } - //891 Bilan de cloture - Account endRetainedAccount = accountService.getAccountByNumber("891"); - if (endRetainedAccount == null) { - endRetainedAccount = new AccountImpl(); - endRetainedAccount.setAccountNumber("891"); - endRetainedAccount.setLabel("Bilan de clôture"); - accountService.createAccount(endRetainedAccount); - endRetainedAccount = accountService.getAccountByNumber("891"); - } + //891 Bilan de cloture + Account endRetainedAccount = accountService.getAccountByNumber("891"); + if (endRetainedAccount == null) { + endRetainedAccount = new AccountImpl(); + endRetainedAccount.setAccountNumber("891"); + endRetainedAccount.setLabel("Bilan de clôture"); + accountService.createAccount(endRetainedAccount); + endRetainedAccount = accountService.getAccountByNumber("891"); + } - //look for the last financial period from the previous fiscal year - Collection<FinancialPeriod> fperiod = fiscalPeriod.getFinancialPeriod(); + //look for the last financial period from the previous fiscal year + Collection<FinancialPeriod> fperiod = fiscalPeriod.getFinancialPeriod(); - Iterator<FinancialPeriod> itr = fperiod.iterator(); - FinancialPeriod lastFPeriod = null; - while (itr.hasNext()) { - lastFPeriod = itr.next(); - } - //check if the last financial period isn't blocked - if (lastFPeriod.getLocked()) { - throw new LimaBusinessException(_("lima-business.fiscalperiod.previousfiscalperiodalreadyblocked")); - } + Iterator<FinancialPeriod> itr = fperiod.iterator(); + FinancialPeriod lastFPeriod = null; + while (itr.hasNext()) { + lastFPeriod = itr.next(); + } + //check if the last financial period isn't blocked + if (lastFPeriod.getLocked()) { + throw new LimaBusinessException(_("lima-business.fiscalperiod.previousfiscalperiodalreadyblocked")); + } - FinancialPeriod beginfinancialPeriod = null; - //settings to be done only if a new year exists - if (newyear) { - //look for the first financial period on the new fiscal year which is unlocked - found = false; - List<ClosedPeriodicEntryBook> resultsArray = - new ArrayList<ClosedPeriodicEntryBook>(); - List<ClosedPeriodicEntryBook> closedPeriodicEntryBook = - financialPeriodService.getAllClosedPeriodicEntryBooksFromUnblockedFiscalPeriod(); - Collections.sort(closedPeriodicEntryBook, new FinancialPeriodComparator()); - resultsArray.addAll(closedPeriodicEntryBook); - for (ClosedPeriodicEntryBook cPeriodicEntryBook : resultsArray) { - //check for - unlocked financial period - // - date after the closing fiscal year - // - unlocked entrybook - // - right code and label - if (!found && !cPeriodicEntryBook.getFinancialPeriod().getLocked() - && cPeriodicEntryBook.getFinancialPeriod().getBeginDate().after(fiscalPeriod.getEndDate()) - && !cPeriodicEntryBook.getLocked() - && cPeriodicEntryBook.getEntryBook().getCode().equals(entryBook.getCode()) - && cPeriodicEntryBook.getEntryBook().getLabel().equals(entryBook.getLabel())) { - found = true; - beginfinancialPeriod = cPeriodicEntryBook.getFinancialPeriod(); - } + FinancialPeriod beginfinancialPeriod = null; + //settings to be done only if a new year exists + if (newyear) { + //look for the first financial period on the new fiscal year which is unlocked + found = false; + List<ClosedPeriodicEntryBook> resultsArray = + new ArrayList<ClosedPeriodicEntryBook>(); + List<ClosedPeriodicEntryBook> closedPeriodicEntryBook = + financialPeriodService.getAllClosedPeriodicEntryBooksFromUnblockedFiscalPeriod(); + Collections.sort(closedPeriodicEntryBook, new FinancialPeriodComparator()); + resultsArray.addAll(closedPeriodicEntryBook); + for (ClosedPeriodicEntryBook cPeriodicEntryBook : resultsArray) { + //check for - unlocked financial period + // - date after the closing fiscal year + // - unlocked entrybook + // - right code and label + if (!found && !cPeriodicEntryBook.getFinancialPeriod().getLocked() + && cPeriodicEntryBook.getFinancialPeriod().getBeginDate().after(fiscalPeriod.getEndDate()) + && !cPeriodicEntryBook.getLocked() + && cPeriodicEntryBook.getEntryBook().getCode().equals(entryBook.getCode()) + && cPeriodicEntryBook.getEntryBook().getLabel().equals(entryBook.getLabel())) { + found = true; + beginfinancialPeriod = cPeriodicEntryBook.getFinancialPeriod(); } - if (!found) { - throw new LimaBusinessException(_("lima-business.fiscalperiod.newfinancialperioderror")); - } } + if (!found) { + throw new LimaBusinessException(_("lima-business.fiscalperiod.newfinancialperioderror")); + } + } - //holds entries of all closing transactions - FinancialTransaction endfinancialTransaction = new FinancialTransactionImpl(); - if (lastFPeriod != null) { + //holds entries of all closing transactions + FinancialTransaction endfinancialTransaction = new FinancialTransactionImpl(); + if (lastFPeriod != null) { + //Sets the endfinancialTransaction + endfinancialTransaction.setEntryBook(entryBook); + endfinancialTransaction.setTransactionDate(fiscalPeriod.getEndDate()); + financialTransactionService.createFinancialTransaction(endfinancialTransaction); + } + + //holds entries of all opening transactions + FinancialTransaction beginfinancialTransaction = new FinancialTransactionImpl(); + if (newyear) { + if (found) { //Sets the endfinancialTransaction - endfinancialTransaction.setEntryBook(entryBook); - endfinancialTransaction.setTransactionDate(fiscalPeriod.getEndDate()); - financialTransactionService.createFinancialTransaction(endfinancialTransaction); + beginfinancialTransaction.setEntryBook(entryBook); + beginfinancialTransaction.setTransactionDate(beginfinancialPeriod.getBeginDate()); + financialTransactionService.createFinancialTransaction(beginfinancialTransaction); } + } - //holds entries of all opening transactions - FinancialTransaction beginfinancialTransaction = new FinancialTransactionImpl(); - if (newyear) { - if (found) { - //Sets the endfinancialTransaction - beginfinancialTransaction.setEntryBook(entryBook); - beginfinancialTransaction.setTransactionDate(beginfinancialPeriod.getBeginDate()); - financialTransactionService.createFinancialTransaction(beginfinancialTransaction); - } - } + //Sets date for description, e.g: Report à nouveau (DATE) + Calendar calendar = Calendar.getInstance(); + calendar.setTime(fiscalPeriod.getEndDate()); - //Sets date for description, e.g: Report à nouveau (DATE) - Calendar calendar = Calendar.getInstance(); - calendar.setTime(fiscalPeriod.getEndDate()); + //Sets entries + Entry beginEntry; - //Sets entries - Entry beginEntry; + BalanceTrial results = reportService.generateBalanceTrial(fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate(), null, false, false); - BalanceTrial results = reportService.generateBalanceTrial(fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate(), null, false, false); + List<ReportsDatas> reportsDatasList = (List<ReportsDatas>) results.getReportsDatas(); - List<ReportsDatas> reportsDatasList = (List<ReportsDatas>) results.getReportsDatas(); + //check if at least one transaction has been reported + boolean transaction = false; - //check if at least one transaction has been reported - boolean transaction = false; - - for (ReportsDatas report : reportsDatasList) { - //Account class from 1 to 5 and only non zero amount - if (Integer.valueOf(report.getAccount().getAccountNumber().substring(0, 1)) < 6 - && !report.getAmountSolde().equals(BigDecimal.ZERO)) { - transaction = true; - //close accounts by removing amounts from all class 1 to 5 accounts + for (ReportsDatas report : reportsDatasList) { + //Account class from 1 to 5 and only non zero amount + if (Integer.valueOf(report.getAccount().getAccountNumber().substring(0, 1)) < 6 + && !report.getAmountSolde().equals(BigDecimal.ZERO)) { + transaction = true; + //close accounts by removing amounts from all class 1 to 5 accounts + beginEntry = new EntryImpl(); + beginEntry.setDescription(_("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); + beginEntry.setVoucher(_("lima-business.financialtransaction.retainedearnings.voucher")); + beginEntry.setFinancialTransaction(endfinancialTransaction); + beginEntry.setAccount(report.getAccount()); + beginEntry.setAmount(report.getAmountSolde().abs()); + beginEntry.setDebit(!report.getSoldeDebit()); + financialTransactionService.createEntry(beginEntry); + //save amounts inside account number 891 + beginEntry = new EntryImpl(); + beginEntry.setDescription(_("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); + beginEntry.setVoucher(_("lima-business.financialtransaction.retainedearnings.voucher")); + beginEntry.setFinancialTransaction(endfinancialTransaction); + beginEntry.setAccount(endRetainedAccount); + beginEntry.setAmount(report.getAmountSolde().abs()); + beginEntry.setDebit(report.getSoldeDebit()); + financialTransactionService.createEntry(beginEntry); + //open new year accounts if new year exists and a date has been found for the transaction + if (newyear && found) { + //give back amounts from class 1 to 5 accounts beginEntry = new EntryImpl(); beginEntry.setDescription(_("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); beginEntry.setVoucher(_("lima-business.financialtransaction.retainedearnings.voucher")); - beginEntry.setFinancialTransaction(endfinancialTransaction); + beginEntry.setFinancialTransaction(beginfinancialTransaction); beginEntry.setAccount(report.getAccount()); beginEntry.setAmount(report.getAmountSolde().abs()); - beginEntry.setDebit(!report.getSoldeDebit()); - financialTransactionService.createEntryWithTransaction(beginEntry, topiaContext); - //save amounts inside account number 891 + beginEntry.setDebit(report.getSoldeDebit()); + financialTransactionService.createEntry(beginEntry); + //close account by removing amount from account number 890 beginEntry = new EntryImpl(); beginEntry.setDescription(_("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); beginEntry.setVoucher(_("lima-business.financialtransaction.retainedearnings.voucher")); - beginEntry.setFinancialTransaction(endfinancialTransaction); + beginEntry.setFinancialTransaction(beginfinancialTransaction); beginEntry.setAccount(endRetainedAccount); beginEntry.setAmount(report.getAmountSolde().abs()); - beginEntry.setDebit(report.getSoldeDebit()); - financialTransactionService.createEntryWithTransaction(beginEntry, topiaContext); - //open new year accounts if new year exists and a date has been found for the transaction - if (newyear && found) { - //give back amounts from class 1 to 5 accounts - beginEntry = new EntryImpl(); - beginEntry.setDescription(_("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); - beginEntry.setVoucher(_("lima-business.financialtransaction.retainedearnings.voucher")); - beginEntry.setFinancialTransaction(beginfinancialTransaction); - beginEntry.setAccount(report.getAccount()); - beginEntry.setAmount(report.getAmountSolde().abs()); - beginEntry.setDebit(report.getSoldeDebit()); - financialTransactionService.createEntryWithTransaction(beginEntry, topiaContext); - //close account by removing amount from account number 890 - beginEntry = new EntryImpl(); - beginEntry.setDescription(_("lima-business.financialtransaction.retainedearnings.description") + " (" + calendar.get(Calendar.YEAR) + ")"); - beginEntry.setVoucher(_("lima-business.financialtransaction.retainedearnings.voucher")); - beginEntry.setFinancialTransaction(beginfinancialTransaction); - beginEntry.setAccount(endRetainedAccount); - beginEntry.setAmount(report.getAmountSolde().abs()); - beginEntry.setDebit(!report.getSoldeDebit()); - financialTransactionService.createEntryWithTransaction(beginEntry, topiaContext); - } + beginEntry.setDebit(!report.getSoldeDebit()); + financialTransactionService.createEntry(beginEntry); } } - //if no transaction has been reported - if (!transaction) { - topiaContext.rollbackTransaction(); - //if no problem appeared, commit - } else { - commitTransaction(topiaContext); - } - } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); } } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/HttpServerServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/HttpServerServiceImpl.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/HttpServerServiceImpl.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -45,6 +45,7 @@ import javax.ejb.Local; import javax.ejb.Remote; import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -64,6 +65,7 @@ @Stateless @Remote(HttpServerService.class) @Local(HttpServerServiceLocal.class) +@TransactionAttribute public class HttpServerServiceImpl extends AbstractLimaService implements HttpServerService, HttpServerServiceLocal { @EJB Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/IdentityServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/IdentityServiceImpl.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/IdentityServiceImpl.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -31,88 +31,51 @@ import org.chorem.lima.entity.Identity; import org.chorem.lima.entity.IdentityDAO; import org.chorem.lima.entity.LimaCallaoDAOHelper; -import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import javax.ejb.Local; import javax.ejb.Remote; import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; + import java.util.List; @Stateless @Remote(IdentityService.class) @Local(IdentityServiceLocal.class) +@TransactionAttribute public class IdentityServiceImpl extends AbstractLimaService implements IdentityService, IdentityServiceLocal { - private TopiaContext rootContext; - - public IdentityServiceImpl() { - rootContext = acquireRootContext(); - } - @Override - public Identity getIdentityWithTransaction(TopiaContext topiaContext) + public Identity getIdentity() throws LimaException { Identity identity = null; try { - IdentityDAO identityDAO = LimaCallaoDAOHelper.getIdentityDAO(topiaContext); + IdentityDAO identityDAO = getDaoHelper().getIdentityDAO(); List<Identity> identities = identityDAO.findAll(); if (identities.size() != 0) { identity = identities.get(0); } } catch (TopiaException ex) { - doCatch(topiaContext, ex); + throw new LimaException("Can't get identity", ex); } return identity; } @Override - public Identity getIdentity() throws LimaException { - TopiaContext topiaContext = beginTransaction(rootContext); - Identity identity = null; + public void updateIdentity(Identity identity) throws LimaException { try { - - identity = getIdentityWithTransaction(topiaContext); - } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); - } - return identity; - } - - - @Override - public void updateIdentityWithTransaction(Identity identity, - TopiaContext topiaContext) throws LimaException { - try { - IdentityDAO identityDAO = LimaCallaoDAOHelper.getIdentityDAO(topiaContext); + IdentityDAO identityDAO = getDaoHelper().getIdentityDAO(); List<Identity> identities = identityDAO.findAll(); if (identities.size() != 0) { identityDAO.delete(identities.get(0)); } identityDAO.create(identity); - commitTransaction(topiaContext); } catch (TopiaException ex) { - doCatch(topiaContext, ex); + throw new LimaException("Can't update identity", ex); } } - @Override - public void updateIdentity(Identity identity) throws LimaException { - TopiaContext topiaContext = beginTransaction(rootContext); - try { - - updateIdentityWithTransaction(identity, topiaContext); - - commitTransaction(topiaContext); - } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); - } - } - } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -49,9 +49,8 @@ import javax.ejb.Local; import javax.ejb.Remote; import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.pdfbox.exceptions.COSVisitorException; @@ -76,7 +75,7 @@ import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; import org.chorem.lima.business.api.AccountService; -import org.chorem.lima.business.api.EntryBookServiceLocal; +import org.chorem.lima.business.api.EntryBookService; import org.chorem.lima.business.api.FinancialPeriodServiceLocal; import org.chorem.lima.business.api.FinancialStatementServiceLocal; import org.chorem.lima.business.api.FinancialTransactionServiceLocal; @@ -84,7 +83,7 @@ import org.chorem.lima.business.api.IdentityServiceLocal; import org.chorem.lima.business.api.ImportService; import org.chorem.lima.business.api.ImportServiceLocal; -import org.chorem.lima.business.api.VatStatementServiceLocal; +import org.chorem.lima.business.api.VatStatementService; import org.chorem.lima.business.utils.AccountEBPComparator; import org.chorem.lima.business.utils.DocumentsEnum; import org.chorem.lima.business.utils.EntryEBPComparator; @@ -118,7 +117,6 @@ import org.chorem.lima.entity.VatStatement; import org.chorem.lima.entity.VatStatementDAO; import org.chorem.lima.entity.VatStatementImpl; -import org.hsqldb.lib.ArrayUtil; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; @@ -133,12 +131,11 @@ @Stateless @Remote(ImportService.class) @Local(ImportServiceLocal.class) +@TransactionAttribute public class ImportServiceImpl extends AbstractLimaService implements ImportService, ImportServiceLocal { private static final Log log = LogFactory.getLog(ImportServiceImpl.class); - private TopiaContext rootContext; - @EJB private AccountService accountService; @@ -155,10 +152,10 @@ private FinancialStatementServiceLocal financialStatementService; @EJB - private VatStatementServiceLocal vatStatementService; + private VatStatementService vatStatementService; @EJB - private EntryBookServiceLocal entryBookService; + private EntryBookService entryBookService; @EJB private IdentityServiceLocal identityService; @@ -166,10 +163,6 @@ private static final SimpleDateFormat SDATEFORMAT = new SimpleDateFormat( "dd,MM,yyyy HH:mm:ss"); - public ImportServiceImpl() { - rootContext = acquireRootContext(); - } - // ################ IMPORT THIRD PART ACCOUNTING SOFTWARE ################ @Override @@ -180,7 +173,6 @@ SimpleDateFormat epbDateFormat = new SimpleDateFormat("dd/MM/yyyy"); StringBuilder result = new StringBuilder(); - TopiaContext topiaContext = beginTransaction(rootContext); try { CSVReader csvReader = new CSVReader(new StringReader(datas)); ColumnPositionMappingStrategy<EntryEBPImpl> strat = new ColumnPositionMappingStrategy<EntryEBPImpl>(); @@ -209,15 +201,12 @@ Collections.sort(list, new EntryEBPComparator()); // DAOs - AccountDAO accountDAO = LimaCallaoDAOHelper - .getAccountDAO(topiaContext); - EntryBookDAO entryBookDAO = LimaCallaoDAOHelper - .getEntryBookDAO(topiaContext); + AccountDAO accountDAO = getDaoHelper().getAccountDAO(); + EntryBookDAO entryBookDAO = getDaoHelper().getEntryBookDAO(); List<FiscalPeriod> fiscalPeriods = fiscalPeriodService.getAllUnblockedFiscalPeriods(); Collections.sort(fiscalPeriods, new FiscalPeriodComparator()); int nbFiscalPeriods = fiscalPeriods.size(); - FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper - .getFinancialPeriodDAO(topiaContext); + FinancialPeriodDAO financialPeriodDAO = getDaoHelper().getFinancialPeriodDAO(); if (nbFiscalPeriods == 0) { throw new LimaBusinessException( @@ -283,14 +272,12 @@ financialTransaction.setEntryBook(entryBook); financialTransaction.setTransactionDate(date); financialTransactionService - .createFinancialTransactionWithTransaction( - financialTransaction, topiaContext); + .createFinancialTransaction(financialTransaction); result.append(_("lima-business.import.transactionadded", date, entryBook.getCode())); } financialTransaction.addEntry(entry); - financialTransactionService.createEntryWithTransaction( - entry, topiaContext); + financialTransactionService.createEntry(entry); result.append(_("lima-business.import.entryadded", entry.getDescription(), entry.getAmount())); } } @@ -300,12 +287,8 @@ log.info("Imported form EBP : " + list.size() + " entries in " + (after-before) + " ms"); } - // commit - commitTransaction(topiaContext); } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); + throw new LimaException("Can't import", ex); } return result.toString(); } @@ -315,7 +298,6 @@ long before = System.currentTimeMillis(); StringBuilder result = new StringBuilder(); - TopiaContext topiaContext = beginTransaction(rootContext); try { CSVReader csvReader = new CSVReader(new StringReader(datas)); @@ -340,8 +322,7 @@ List<AccountEBPImpl> list = csv.parse(strat, csvReader); Collections.sort(list, new AccountEBPComparator()); - AccountDAO accountDAO = LimaCallaoDAOHelper - .getAccountDAO(topiaContext); + AccountDAO accountDAO = getDaoHelper().getAccountDAO(); for (AccountEBP accountEBP : list) { String accountNumber = accountEBP.getNumero(); if (accountDAO.findByAccountNumber(accountNumber) != null) { @@ -362,9 +343,7 @@ } } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); + throw new LimaException("Can't import", ex); } return result.toString(); @@ -375,7 +354,6 @@ long before = System.currentTimeMillis(); StringBuilder result = new StringBuilder(); - TopiaContext topiaContext = beginTransaction(rootContext); try { CSVReader csvReader = new CSVReader(new StringReader(datas)); @@ -401,15 +379,15 @@ line = csvReader.readNext(); } + csvReader.close(); + if (log.isInfoEnabled()) { long after = System.currentTimeMillis(); log.info("Imported form EBP : " + count + " accounts in " + (after-before) + " ms"); } } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); + throw new LimaException("Can't import", ex); } return result.toString(); @@ -440,7 +418,6 @@ Map<Integer, List<EntryImport>> entries = new HashMap<Integer, List<EntryImport>>(); - TopiaContext topiaContext = beginTransaction(rootContext); try { String[] nextLine; @@ -452,65 +429,56 @@ if (importExportEntityEnum != null) { switch (importExportEntityEnum) { case ACCOUNT: - result.append(importAccountsChartsCSV(nextLine, - topiaContext)); + result.append(importAccountsChartsCSV(nextLine)); break; case ENTRYBOOK: - result.append(importEntryBooksChartCSV(nextLine, - topiaContext)); + result.append(importEntryBooksChartCSV(nextLine)); break; case FINANCIALSTATEMENT: result.append(importFinancialsStatementChartCSV(nextLine, - financialStatements, topiaContext)); + financialStatements)); break; case VATSTATEMENT: result.append(importVatStatementChartCSV(nextLine, - vatStatements, topiaContext)); + vatStatements)); break; case FISCALPERIOD: result.append(importFiscalPeriodCSV(nextLine, - fiscalPeriods, topiaContext)); + fiscalPeriods)); break; case CLOSEDPERIODICENTRYBOOK: importClosedPeriodicEntryBookCSV(nextLine, - closedPeriodicEntryBooks, topiaContext); + closedPeriodicEntryBooks); break; case FINANCIALTRANSACTION: importFinancialTransactionsCSV(nextLine, - financialTransactions, topiaContext); + financialTransactions); break; case ENTRY: - importEntriesCSV(nextLine, entries, topiaContext); + importEntriesCSV(nextLine, entries); break; case IDENTITY: - importIdentity(nextLine, topiaContext); + importIdentity(nextLine); break; } } } // create financialStatements - result.append(createFinancialStatements(financialStatements, - topiaContext)); + result.append(createFinancialStatements(financialStatements)); // create vatStatements - result.append(createVatStatements(vatStatements, - topiaContext)); + result.append(createVatStatements(vatStatements)); // create fiscalperiod Collections.sort(fiscalPeriods, new FiscalPeriodComparator()); - result.append(createFiscalPeriod(fiscalPeriods, topiaContext)); + result.append(createFiscalPeriod(fiscalPeriods)); // update closedperiodicentrybooks - result.append(updateClosedPeriodicEntryBooks(closedPeriodicEntryBooks, - topiaContext)); + result.append(updateClosedPeriodicEntryBooks(closedPeriodicEntryBooks)); // create financialtransaction and entries result.append(createFinancialTransactionsAndEntries( - financialTransactions, entries, topiaContext)); + financialTransactions, entries)); - commitTransaction(topiaContext); - } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); + throw new LimaException("Can't import", ex); } return result.toString(); } @@ -538,7 +506,6 @@ break; } - TopiaContext topiaContext = beginTransaction(rootContext); try { String[] nextLine; @@ -548,19 +515,18 @@ if (ImportExportEntityEnum.valueOfLabel(nextLine[0]) == importExportEntityEnum) { switch (importExportEntityEnum) { case ENTRYBOOK: - result.append(importEntryBooksChartCSV(nextLine, topiaContext)); + result.append(importEntryBooksChartCSV(nextLine)); break; case ACCOUNT: - result.append(importAccountsChartsCSV(nextLine, - topiaContext)); + result.append(importAccountsChartsCSV(nextLine)); break; case FINANCIALSTATEMENT: result.append(importFinancialsStatementChartCSV(nextLine, - financialStatements, topiaContext)); + financialStatements)); break; case VATSTATEMENT: result.append(importVatStatementChartCSV(nextLine, - vatStatements, topiaContext)); + vatStatements)); break; } } @@ -569,19 +535,15 @@ //create entity switch (importExportEntityEnum) { case FINANCIALSTATEMENT: - result.append(createFinancialStatements(financialStatements, - topiaContext)); + result.append(createFinancialStatements(financialStatements)); break; case VATSTATEMENT: - result.append(createVatStatements(vatStatements, - topiaContext)); + result.append(createVatStatements(vatStatements)); break; } } catch (Exception ex) { - doCatch(topiaContext, ex); - } finally { - doFinally(topiaContext); + throw new LimaException("Can't import", ex); } return result.toString(); } @@ -646,38 +608,34 @@ * @param topiaContext * @return * @throws LimaException + * @throws TopiaException */ - protected String importAccountsChartsCSV(String[] nextLine, - TopiaContext topiaContext) - throws LimaException { + protected String importAccountsChartsCSV(String[] nextLine) + throws LimaException, TopiaException { StringBuilder result = new StringBuilder(); String accountNumber = nextLine[1]; String label = nextLine[2]; String thirdParty = nextLine[3]; - try { - AccountDAO accountDAO = LimaCallaoDAOHelper - .getAccountDAO(topiaContext); + AccountDAO accountDAO = getDaoHelper().getAccountDAO(); - // if not exist, create it - if (accountDAO.findByAccountNumber(accountNumber) == null) { + // if not exist, create it + if (accountDAO.findByAccountNumber(accountNumber) == null) { - Account account = new AccountImpl(); - account.setAccountNumber(accountNumber); - account.setLabel(label); - account.setThirdParty(thirdParty); + Account account = new AccountImpl(); + account.setAccountNumber(accountNumber); + account.setLabel(label); + account.setThirdParty(thirdParty); - accountDAO.create(account); - result.append(_("lima-business.import.accountadded", - account.getAccountNumber(), - account.getLabel())); - } else { - result.append(_("lima-business.import.accountalreadyexist", accountNumber)); - } - } catch (TopiaException ex) { - doCatch(topiaContext, ex); + accountDAO.create(account); + result.append(_("lima-business.import.accountadded", + account.getAccountNumber(), + account.getLabel())); + } else { + result.append(_("lima-business.import.accountalreadyexist", accountNumber)); } + return result.toString(); } @@ -689,35 +647,30 @@ * @param fiscalPeriods * @param topiaContext * @return - * @throws LimaException + * @throws ParseException + * @throws TopiaException */ protected String importFiscalPeriodCSV(String[] nextLine, - List<FiscalPeriod> fiscalPeriods, - TopiaContext topiaContext) - throws LimaException { + List<FiscalPeriod> fiscalPeriods) + throws ParseException, TopiaException { StringBuilder result = new StringBuilder(); - try { - FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper - .getFiscalPeriodDAO(topiaContext); - FiscalPeriod fiscalPeriod = new FiscalPeriodImpl(); - Date beginDate = SDATEFORMAT.parse(nextLine[1]); - fiscalPeriod.setBeginDate(beginDate); - Date endDate = SDATEFORMAT.parse(nextLine[2]); - fiscalPeriod.setEndDate(endDate); - fiscalPeriod.setLocked(Boolean.parseBoolean(nextLine[3])); + FiscalPeriodDAO fiscalPeriodDAO = getDaoHelper().getFiscalPeriodDAO(); - // if not exist, skip - if (fiscalPeriodDAO.findByNaturalId(beginDate, endDate) == null) { - fiscalPeriods.add(fiscalPeriod); - } else { - result.append(_("lima-business.import.fiscalperiodalreadyexist", beginDate, endDate)); - } - } catch (ParseException ex) { - log.error("Can't parse date", ex); - } catch (TopiaException ex) { - doCatch(topiaContext, ex); + FiscalPeriod fiscalPeriod = new FiscalPeriodImpl(); + Date beginDate = SDATEFORMAT.parse(nextLine[1]); + fiscalPeriod.setBeginDate(beginDate); + Date endDate = SDATEFORMAT.parse(nextLine[2]); + fiscalPeriod.setEndDate(endDate); + fiscalPeriod.setLocked(Boolean.parseBoolean(nextLine[3])); + + // if not exist, skip + if (fiscalPeriodDAO.findByNaturalId(beginDate, endDate) == null) { + fiscalPeriods.add(fiscalPeriod); + } else { + result.append(_("lima-business.import.fiscalperiodalreadyexist", beginDate, endDate)); } + return result.toString(); } @@ -727,30 +680,27 @@ * @param nextLine * @param topiaContext * @return - * @throws LimaException + * @throws TopiaException + * @throws LimaException */ - protected String importEntryBooksChartCSV(String[] nextLine, TopiaContext topiaContext) throws LimaException { + protected String importEntryBooksChartCSV(String[] nextLine) throws TopiaException, LimaException { StringBuilder result = new StringBuilder(); - try { - EntryBookDAO entryBookDAO = LimaCallaoDAOHelper - .getEntryBookDAO(topiaContext); + EntryBookDAO entryBookDAO = getDaoHelper().getEntryBookDAO(); - EntryBook entryBook = new EntryBookImpl(); - entryBook.setCode(nextLine[1]); - entryBook.setLabel(nextLine[2]); + EntryBook entryBook = new EntryBookImpl(); + entryBook.setCode(nextLine[1]); + entryBook.setLabel(nextLine[2]); - // if exist, skip - if (entryBookDAO.findByCode(entryBook.getCode()) != null) { - result.append(_("lima-business.import.entrybookalreadyexist", entryBook.getLabel())); - } else { - // create it - entryBookService.createEntryBook(entryBook); - result.append(_("lima-business.import.financialstatementadded", entryBook.getLabel())); - } - } catch (TopiaException ex) { - doCatch(topiaContext, ex); + // if exist, skip + if (entryBookDAO.findByCode(entryBook.getCode()) != null) { + result.append(_("lima-business.import.entrybookalreadyexist", entryBook.getLabel())); + } else { + // create it + entryBookService.createEntryBook(entryBook); + result.append(_("lima-business.import.financialstatementadded", entryBook.getLabel())); } + return result.toString(); } @@ -764,8 +714,7 @@ * @throws LimaException */ protected void importClosedPeriodicEntryBookCSV(String[] nextLine, - List<ClosedPeriodicEntryBookImport> closedPeriodicEntryBooks, - TopiaContext topiaContext) throws LimaException { + List<ClosedPeriodicEntryBookImport> closedPeriodicEntryBooks) throws LimaException { String locked = nextLine[1]; String beginDate = nextLine[2]; String endDate = nextLine[3]; @@ -794,10 +743,10 @@ * @param topiaContext * @return * @throws LimaException + * @throws TopiaException */ protected String importFinancialsStatementChartCSV(String[] nextLine, - LinkedHashMap<String, ArrayList<FinancialStatementImport>> financialStatements, - TopiaContext topiaContext) throws LimaException { + LinkedHashMap<String, ArrayList<FinancialStatementImport>> financialStatements) throws LimaException, TopiaException { StringBuilder result = new StringBuilder(); String label = nextLine[1]; @@ -811,41 +760,37 @@ String masterFinancialStatement = nextLine[9]; String financialStatementWay = nextLine[10]; - try { - FinancialStatementDAO financialStatementDAO = LimaCallaoDAOHelper - .getFinancialStatementDAO(topiaContext); + FinancialStatementDAO financialStatementDAO = getDaoHelper().getFinancialStatementDAO(); - // if exist, skip - if (financialStatementDAO.findByLabel(label) == null) { - // create it - FinancialStatementImport financialStatementImport = new FinancialStatementImportImpl(); - financialStatementImport.setLabel(label); - financialStatementImport.setHeader(header); - financialStatementImport.setAccounts(accounts); - financialStatementImport.setCreditAccounts(creditAccounts); - financialStatementImport.setDebitAccounts(debitAccounts); - financialStatementImport.setHeaderAmount(headerAmount); - financialStatementImport - .setProvisionDeprecationAccounts(provisionDeprecationAccounts); - financialStatementImport.setSubAmount(subAmount); - financialStatementImport - .setMasterFinancialStatement(masterFinancialStatement); - financialStatementImport.setWay(financialStatementWay); + // if exist, skip + if (financialStatementDAO.findByLabel(label) == null) { + // create it + FinancialStatementImport financialStatementImport = new FinancialStatementImportImpl(); + financialStatementImport.setLabel(label); + financialStatementImport.setHeader(header); + financialStatementImport.setAccounts(accounts); + financialStatementImport.setCreditAccounts(creditAccounts); + financialStatementImport.setDebitAccounts(debitAccounts); + financialStatementImport.setHeaderAmount(headerAmount); + financialStatementImport + .setProvisionDeprecationAccounts(provisionDeprecationAccounts); + financialStatementImport.setSubAmount(subAmount); + financialStatementImport + .setMasterFinancialStatement(masterFinancialStatement); + financialStatementImport.setWay(financialStatementWay); - // put it in hashlinkedlist - if (financialStatements.containsKey(label)) { - financialStatements.get(label).add(financialStatementImport); - } else { - List<FinancialStatementImport> list = new ArrayList<FinancialStatementImport>(); - list.add(financialStatementImport); - financialStatements.put(label, (ArrayList<FinancialStatementImport>) list); - } + // put it in hashlinkedlist + if (financialStatements.containsKey(label)) { + financialStatements.get(label).add(financialStatementImport); } else { - result.append(_("lima-business.import.financialstatementalreadyexist", label)); + List<FinancialStatementImport> list = new ArrayList<FinancialStatementImport>(); + list.add(financialStatementImport); + financialStatements.put(label, (ArrayList<FinancialStatementImport>) list); } - } catch (TopiaException ex) { - doCatch(topiaContext, ex); + } else { + result.append(_("lima-business.import.financialstatementalreadyexist", label)); } + return result.toString(); } @@ -859,10 +804,10 @@ * @param topiaContext * @return * @throws LimaException + * @throws TopiaException */ protected String importVatStatementChartCSV(String[] nextLine, - Map<String, ArrayList<VatStatementImport>> vatStatements, - TopiaContext topiaContext) throws LimaException { + Map<String, ArrayList<VatStatementImport>> vatStatements) throws LimaException, TopiaException { StringBuilder result = new StringBuilder(); @@ -872,35 +817,30 @@ String accounts = nextLine[4]; String masterVatStatement = nextLine[5]; + VatStatementDAO vatStatementDAO = getDaoHelper().getVatStatementDAO(); - try { - VatStatementDAO vatStatementDAO = LimaCallaoDAOHelper - .getVatStatementDAO(topiaContext); + // if exist, skip + if (vatStatementDAO.findByLabel(label) == null) { + // create it + VatStatementImport vatStatementImport = new VatStatementImportImpl(); + vatStatementImport.setLabel(label); + vatStatementImport.setBoxName(boxName); + vatStatementImport.setHeader(header); + vatStatementImport.setAccounts(accounts); + vatStatementImport.setMasterVatStatement(masterVatStatement); - // if exist, skip - if (vatStatementDAO.findByLabel(label) == null) { - // create it - VatStatementImport vatStatementImport = new VatStatementImportImpl(); - vatStatementImport.setLabel(label); - vatStatementImport.setBoxName(boxName); - vatStatementImport.setHeader(header); - vatStatementImport.setAccounts(accounts); - vatStatementImport.setMasterVatStatement(masterVatStatement); - - // put it in hashlinkedlist - if (vatStatements.containsKey(label)) { - vatStatements.get(label).add(vatStatementImport); - } else { - List<VatStatementImport> list = new ArrayList<VatStatementImport>(); - list.add(vatStatementImport); - vatStatements.put(label, (ArrayList<VatStatementImport>) list); - } + // put it in hashlinkedlist + if (vatStatements.containsKey(label)) { + vatStatements.get(label).add(vatStatementImport); } else { - result.append(_("lima-business.import.vatstatementalreadyexist", label)); + List<VatStatementImport> list = new ArrayList<VatStatementImport>(); + list.add(vatStatementImport); + vatStatements.put(label, (ArrayList<VatStatementImport>) list); } - } catch (TopiaException ex) { - doCatch(topiaContext, ex); + } else { + result.append(_("lima-business.import.vatstatementalreadyexist", label)); } + return result.toString(); } @@ -916,8 +856,7 @@ * @throws LimaException */ protected void importFinancialTransactionsCSV(String[] nextLine, - Map<Integer, FinancialTransactionImport> financialTransactions, - TopiaContext topiaContext) throws LimaException { + Map<Integer, FinancialTransactionImport> financialTransactions) throws LimaException { int num = new Integer(nextLine[1]); FinancialTransactionImport financialTransactionImport = new FinancialTransactionImportImpl(); financialTransactionImport.setDate(nextLine[2]); @@ -940,8 +879,7 @@ * @throws LimaException */ protected void importEntriesCSV(String[] nextLine, - Map<Integer, List<EntryImport>> entries, - TopiaContext topiaContext) throws LimaException { + Map<Integer, List<EntryImport>> entries) throws LimaException { int num = new Integer(nextLine[1]); EntryImport entryImport = new EntryImportImpl(); @@ -967,170 +905,159 @@ // ################ CREATE ENTITY IN DB FOR IMPORT ################ /** + * @throws TopiaException * @deprecated do only one method import without bean use (and remove beans) */ @Deprecated - protected String createFinancialStatements(Map<String, ArrayList<FinancialStatementImport>> financialStatements, - TopiaContext topiaContext) throws LimaException { + protected String createFinancialStatements(Map<String, ArrayList<FinancialStatementImport>> financialStatements) throws LimaException, TopiaException { StringBuilder result = new StringBuilder(); - try { - FinancialStatementDAO financialStatementDAO = LimaCallaoDAOHelper - .getFinancialStatementDAO(topiaContext); + FinancialStatementDAO financialStatementDAO = getDaoHelper().getFinancialStatementDAO(); - while (financialStatements.size() > 0) { - for (Iterator<ArrayList<FinancialStatementImport>> itr = financialStatements - .values().iterator(); itr.hasNext(); ) { - List<FinancialStatementImport> financialStatementImports = - itr.next(); + while (financialStatements.size() > 0) { + for (Iterator<ArrayList<FinancialStatementImport>> itr = financialStatements + .values().iterator(); itr.hasNext(); ) { + List<FinancialStatementImport> financialStatementImports = + itr.next(); - for (Iterator<FinancialStatementImport> itr2 = financialStatementImports.iterator(); itr2.hasNext(); ) { - FinancialStatementImport financialStatementImport = - itr2.next(); - String masterFinancialStatementLabel = financialStatementImport - .getMasterFinancialStatement(); - FinancialStatement masterFinancialStatement = financialStatementDAO - .findByLabel(masterFinancialStatementLabel); + for (Iterator<FinancialStatementImport> itr2 = financialStatementImports.iterator(); itr2.hasNext(); ) { + FinancialStatementImport financialStatementImport = + itr2.next(); + String masterFinancialStatementLabel = financialStatementImport + .getMasterFinancialStatement(); + FinancialStatement masterFinancialStatement = financialStatementDAO + .findByLabel(masterFinancialStatementLabel); - if (masterFinancialStatementLabel.equals("") - || masterFinancialStatement != null) { - // create it - FinancialStatement financialStatement = new FinancialStatementImpl(); - financialStatement.setLabel(financialStatementImport - .getLabel()); - financialStatement.setHeader(Boolean - .parseBoolean(financialStatementImport - .getHeader())); - financialStatement.setAccounts(financialStatementImport - .getAccounts()); - financialStatement - .setDebitAccounts(financialStatementImport - .getDebitAccounts()); - financialStatement - .setCreditAccounts(financialStatementImport - .getCreditAccounts()); - financialStatement - .setProvisionDeprecationAccounts(financialStatementImport - .getProvisionDeprecationAccounts()); - financialStatement.setSubAmount(Boolean - .parseBoolean(financialStatementImport - .getSubAmount())); - financialStatement.setHeaderAmount(Boolean - .parseBoolean(financialStatementImport - .getHeaderAmount())); - String financialStatementWay = financialStatementImport.getWay(); - if (!financialStatementWay.equals("")) { - FinancialStatementWayEnum financialStatementWayEnum = - FinancialStatementWayEnum.valueOf(financialStatementWay); - financialStatement.setWay(financialStatementWayEnum); - } + if (masterFinancialStatementLabel.equals("") + || masterFinancialStatement != null) { + // create it + FinancialStatement financialStatement = new FinancialStatementImpl(); + financialStatement.setLabel(financialStatementImport + .getLabel()); + financialStatement.setHeader(Boolean + .parseBoolean(financialStatementImport + .getHeader())); + financialStatement.setAccounts(financialStatementImport + .getAccounts()); + financialStatement + .setDebitAccounts(financialStatementImport + .getDebitAccounts()); + financialStatement + .setCreditAccounts(financialStatementImport + .getCreditAccounts()); + financialStatement + .setProvisionDeprecationAccounts(financialStatementImport + .getProvisionDeprecationAccounts()); + financialStatement.setSubAmount(Boolean + .parseBoolean(financialStatementImport + .getSubAmount())); + financialStatement.setHeaderAmount(Boolean + .parseBoolean(financialStatementImport + .getHeaderAmount())); + String financialStatementWay = financialStatementImport.getWay(); + if (!financialStatementWay.equals("")) { + FinancialStatementWayEnum financialStatementWayEnum = + FinancialStatementWayEnum.valueOf(financialStatementWay); + financialStatement.setWay(financialStatementWayEnum); + } - financialStatementService - .createFinancialStatementWithTransaction( - masterFinancialStatement, - financialStatement, topiaContext); + financialStatementService + .createFinancialStatement( + masterFinancialStatement, + financialStatement); - result.append(_("lima-business.import.financialstatementadded", - financialStatementImport.getLabel())); + result.append(_("lima-business.import.financialstatementadded", + financialStatementImport.getLabel())); - itr2.remove(); - } else if (!financialStatements - .containsKey(masterFinancialStatementLabel)) { - result.append(_("lima-business.import.financialstatementalnomaster", - financialStatementImport.getLabel(), - masterFinancialStatementLabel)); - itr2.remove(); - } + itr2.remove(); + } else if (!financialStatements + .containsKey(masterFinancialStatementLabel)) { + result.append(_("lima-business.import.financialstatementalnomaster", + financialStatementImport.getLabel(), + masterFinancialStatementLabel)); + itr2.remove(); } - if (financialStatementImports.isEmpty()) { - itr.remove(); - } } + if (financialStatementImports.isEmpty()) { + itr.remove(); + } } - } catch (TopiaException ex) { - doCatch(topiaContext, ex); } return result.toString(); } /** + * @throws TopiaException * @deprecated do only one method import without bean use (and remove beans) */ @Deprecated - protected String createVatStatements(Map<String, ArrayList<VatStatementImport>> vatStatements, - TopiaContext topiaContext) throws LimaException { + protected String createVatStatements(Map<String, ArrayList<VatStatementImport>> vatStatements) throws LimaException, TopiaException { StringBuilder result = new StringBuilder(); - try { - VatStatementDAO vatStatementDAO = LimaCallaoDAOHelper - .getVatStatementDAO(topiaContext); + VatStatementDAO vatStatementDAO = getDaoHelper().getVatStatementDAO(); - while (vatStatements.size() > 0) { - for (Iterator<ArrayList<VatStatementImport>> itr = vatStatements - .values().iterator(); itr.hasNext(); ) { - List<VatStatementImport> vatStatementImports = - itr.next(); + while (vatStatements.size() > 0) { + for (Iterator<ArrayList<VatStatementImport>> itr = vatStatements + .values().iterator(); itr.hasNext(); ) { + List<VatStatementImport> vatStatementImports = + itr.next(); - for (Iterator<VatStatementImport> itr2 = vatStatementImports.iterator(); itr2.hasNext(); ) { - VatStatementImport vatStatementImport = - itr2.next(); - String masterVatStatementLabel = vatStatementImport - .getMasterVatStatement(); - VatStatement masterVatStatement = vatStatementDAO - .findByLabel(masterVatStatementLabel); + for (Iterator<VatStatementImport> itr2 = vatStatementImports.iterator(); itr2.hasNext(); ) { + VatStatementImport vatStatementImport = + itr2.next(); + String masterVatStatementLabel = vatStatementImport + .getMasterVatStatement(); + VatStatement masterVatStatement = vatStatementDAO + .findByLabel(masterVatStatementLabel); - if (masterVatStatementLabel.equals("") - || masterVatStatement != null) { - // create it - VatStatement vatStatement = new VatStatementImpl(); - vatStatement.setBoxName(vatStatementImport - .getBoxName()); - vatStatement.setLabel(vatStatementImport - .getLabel()); - vatStatement.setAccounts(vatStatementImport - .getAccounts()); - vatStatement.setHeader(Boolean - .parseBoolean(vatStatementImport - .getHeader())); + if (masterVatStatementLabel.equals("") + || masterVatStatement != null) { + // create it + VatStatement vatStatement = new VatStatementImpl(); + vatStatement.setBoxName(vatStatementImport + .getBoxName()); + vatStatement.setLabel(vatStatementImport + .getLabel()); + vatStatement.setAccounts(vatStatementImport + .getAccounts()); + vatStatement.setHeader(Boolean + .parseBoolean(vatStatementImport + .getHeader())); - vatStatementService - .createVatStatementWithTransaction( - masterVatStatement, - vatStatement, topiaContext); + vatStatementService + .createVatStatement( + masterVatStatement, + vatStatement); - result.append(_("lima-business.import.vatstatementadded", - vatStatementImport.getLabel())); + result.append(_("lima-business.import.vatstatementadded", + vatStatementImport.getLabel())); - itr2.remove(); - } else if (!vatStatements - .containsKey(masterVatStatementLabel)) { - result.append(_("lima-business.import.vatstatementalnomaster", - vatStatementImport.getLabel(), - masterVatStatementLabel)); - itr2.remove(); - } + itr2.remove(); + } else if (!vatStatements + .containsKey(masterVatStatementLabel)) { + result.append(_("lima-business.import.vatstatementalnomaster", + vatStatementImport.getLabel(), + masterVatStatementLabel)); + itr2.remove(); } - if (vatStatementImports.isEmpty()) { - itr.remove(); - } } + if (vatStatementImports.isEmpty()) { + itr.remove(); + } } - } catch (TopiaException ex) { - doCatch(topiaContext, ex); } + return result.toString(); } - protected String createFiscalPeriod(List<FiscalPeriod> fiscalPeriods, - TopiaContext topiaContext) { + protected String createFiscalPeriod(List<FiscalPeriod> fiscalPeriods) { StringBuilder result = new StringBuilder(); for (FiscalPeriod fiscalPeriod : fiscalPeriods) { // create fiscalPeriod try { - fiscalPeriodService.createFiscalPeriodWithTransaction( - fiscalPeriod, topiaContext); + fiscalPeriodService.createFiscalPeriod(fiscalPeriod); result.append(_("lima-business.import.fiscalperiodadded", fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate())); @@ -1142,122 +1069,108 @@ } /** + * @throws ParseException + * @throws TopiaException * @deprecated do only one method import without bean use (and remove beans) */ @Deprecated protected String updateClosedPeriodicEntryBooks( - List<ClosedPeriodicEntryBookImport> closedPeriodicEntryBooks, - TopiaContext topiaContext) throws LimaException { + List<ClosedPeriodicEntryBookImport> closedPeriodicEntryBooks) throws LimaException, ParseException, TopiaException { StringBuilder result = new StringBuilder(); - try { - FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper - .getFinancialPeriodDAO(topiaContext); - EntryBookDAO entryBookDAO = LimaCallaoDAOHelper - .getEntryBookDAO(topiaContext); - ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = LimaCallaoDAOHelper - .getClosedPeriodicEntryBookDAO(topiaContext); - for (ClosedPeriodicEntryBookImport closedPeriodicEntryBookImport : closedPeriodicEntryBooks) { - // update closedPeriodicEntryBook - Date beginDateFinancialPeriod = SDATEFORMAT - .parse(closedPeriodicEntryBookImport - .getBeginDateFinancialPeriod()); - Date endDateFinancialPeriod = SDATEFORMAT - .parse(closedPeriodicEntryBookImport - .getEndDateFinancialPeriod()); - FinancialPeriod financialPeriod = financialPeriodDAO - .findByNaturalId(beginDateFinancialPeriod, - endDateFinancialPeriod); - String codeEntryBook = closedPeriodicEntryBookImport - .getCodeEntryBook(); - EntryBook entryBook = entryBookDAO.findByCode(codeEntryBook); - ClosedPeriodicEntryBook closedPeriodicEntryBook = closedPeriodicEntryBookDAO - .findByEntryBookAndFinancialPeriod(entryBook, - financialPeriod); - try { - financialPeriodService - .blockClosedPeriodicEntryBookWithTransaction( - closedPeriodicEntryBook, topiaContext); - result.append(_("lima-business.import.closedperiodicentrybookupdated", - beginDateFinancialPeriod, endDateFinancialPeriod, codeEntryBook)); - } catch (LimaException eee) { - result.append(_("lima-business.common.failed", eee)); - } + FinancialPeriodDAO financialPeriodDAO = getDaoHelper().getFinancialPeriodDAO(); + EntryBookDAO entryBookDAO = getDaoHelper().getEntryBookDAO(); + ClosedPeriodicEntryBookDAO closedPeriodicEntryBookDAO = getDaoHelper().getClosedPeriodicEntryBookDAO(); + for (ClosedPeriodicEntryBookImport closedPeriodicEntryBookImport : closedPeriodicEntryBooks) { + // update closedPeriodicEntryBook + Date beginDateFinancialPeriod = SDATEFORMAT + .parse(closedPeriodicEntryBookImport + .getBeginDateFinancialPeriod()); + Date endDateFinancialPeriod = SDATEFORMAT + .parse(closedPeriodicEntryBookImport + .getEndDateFinancialPeriod()); + FinancialPeriod financialPeriod = financialPeriodDAO + .findByNaturalId(beginDateFinancialPeriod, + endDateFinancialPeriod); + String codeEntryBook = closedPeriodicEntryBookImport + .getCodeEntryBook(); + EntryBook entryBook = entryBookDAO.findByCode(codeEntryBook); + ClosedPeriodicEntryBook closedPeriodicEntryBook = closedPeriodicEntryBookDAO + .findByEntryBookAndFinancialPeriod(entryBook, + financialPeriod); + try { + financialPeriodService + .blockClosedPeriodicEntryBook( + closedPeriodicEntryBook); + result.append(_("lima-business.import.closedperiodicentrybookupdated", + beginDateFinancialPeriod, endDateFinancialPeriod, codeEntryBook)); + } catch (LimaException eee) { + result.append(_("lima-business.common.failed", eee)); } - } catch (TopiaException ex) { - doCatch(topiaContext, ex); - } catch (ParseException ex) { - log.error("Can't parse date", ex); } + return result.toString(); } /** + * @throws ParseException + * @throws TopiaException * @deprecated do only one method import without bean use (and remove beans) */ @Deprecated protected String createFinancialTransactionsAndEntries( Map<Integer, FinancialTransactionImport> financialTransactions, - Map<Integer, List<EntryImport>> entries, TopiaContext topiaContext) - throws LimaException { + Map<Integer, List<EntryImport>> entries) + throws LimaException, ParseException, TopiaException { StringBuilder result = new StringBuilder(); - try { - EntryBookDAO entryBookDAO = LimaCallaoDAOHelper - .getEntryBookDAO(topiaContext); - EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); - FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper - .getFinancialPeriodDAO(topiaContext); - FinancialTransactionDAO financialTransactionDAO = LimaCallaoDAOHelper - .getFinancialTransactionDAO(topiaContext); - AccountDAO accountDAO = LimaCallaoDAOHelper - .getAccountDAO(topiaContext); - for (Map.Entry<Integer, FinancialTransactionImport> map : financialTransactions - .entrySet()) { - FinancialTransactionImport financialTransactionImport = map - .getValue(); - FinancialTransaction financialTransaction = new FinancialTransactionImpl(); - Date dateFinancialTransaction = SDATEFORMAT - .parse(financialTransactionImport.getDate()); - financialTransaction - .setTransactionDate(dateFinancialTransaction); + EntryBookDAO entryBookDAO = getDaoHelper().getEntryBookDAO(); + EntryDAO entryDAO = getDaoHelper().getEntryDAO(); + FinancialPeriodDAO financialPeriodDAO = getDaoHelper().getFinancialPeriodDAO(); + FinancialTransactionDAO financialTransactionDAO = getDaoHelper().getFinancialTransactionDAO(); + AccountDAO accountDAO = getDaoHelper().getAccountDAO(); - EntryBook entryBook = entryBookDAO - .findByCode(financialTransactionImport - .getCodeEntryBook()); - financialTransaction.setEntryBook(entryBook); + for (Map.Entry<Integer, FinancialTransactionImport> map : financialTransactions + .entrySet()) { + FinancialTransactionImport financialTransactionImport = map + .getValue(); + FinancialTransaction financialTransaction = new FinancialTransactionImpl(); + Date dateFinancialTransaction = SDATEFORMAT + .parse(financialTransactionImport.getDate()); + financialTransaction + .setTransactionDate(dateFinancialTransaction); - financialTransactionDAO.create(financialTransaction); + EntryBook entryBook = entryBookDAO + .findByCode(financialTransactionImport + .getCodeEntryBook()); + financialTransaction.setEntryBook(entryBook); - List<EntryImport> entryImports = entries.get(map.getKey()); - for (EntryImport entryImport : entryImports) { - Entry entry = new EntryImpl(); - Account account = accountDAO - .findByAccountNumber(entryImport.getAccount()); - entry.setAccount(account); - entry.setDescription(entryImport.getDescription()); - entry.setAmount(new BigDecimal(entryImport.getAmount())); - entry.setDebit(Boolean.parseBoolean(entryImport.getDebit())); + financialTransactionDAO.create(financialTransaction); - entry.setLettering(entryImport.getLettering()); + List<EntryImport> entryImports = entries.get(map.getKey()); + for (EntryImport entryImport : entryImports) { + Entry entry = new EntryImpl(); + Account account = accountDAO + .findByAccountNumber(entryImport.getAccount()); + entry.setAccount(account); + entry.setDescription(entryImport.getDescription()); + entry.setAmount(new BigDecimal(entryImport.getAmount())); + entry.setDebit(Boolean.parseBoolean(entryImport.getDebit())); - entry.setDetail(entryImport.getDetail()); - entry.setVoucher(entryImport.getVoucher()); - entry.setPosition(entryImport.getPosition()); - entryDAO.create(entry); - financialTransaction.addEntry(entry); - } + entry.setLettering(entryImport.getLettering()); + + entry.setDetail(entryImport.getDetail()); + entry.setVoucher(entryImport.getVoucher()); + entry.setPosition(entryImport.getPosition()); + entryDAO.create(entry); + financialTransaction.addEntry(entry); } - } catch (TopiaException ex) { - doCatch(topiaContext, ex); - } catch (ParseException ex) { - log.error("Can't parse date", ex); } + return result.toString(); } - protected String importIdentity(String[] nextLine, - TopiaContext topiaContext) throws LimaException { + protected String importIdentity(String[] nextLine) throws LimaException { StringBuilder result = new StringBuilder(); Identity identity = new IdentityImpl(); @@ -1274,7 +1187,7 @@ identity.setClassificationCode(nextLine[10]); identity.setBusinessNumber(nextLine[11]); - identityService.updateIdentityWithTransaction(identity, topiaContext); + identityService.updateIdentity(identity); // create it result.append(_("lima-business.import.identityadded", identity.getName())); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -34,6 +34,7 @@ import javax.ejb.Local; import javax.ejb.Remote; import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; import org.apache.commons.lang3.StringUtils; import org.chorem.lima.beans.BalanceTrial; @@ -51,51 +52,21 @@ import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryDAO; import org.chorem.lima.entity.FinancialPeriod; -import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FiscalPeriod; -import org.chorem.lima.entity.LimaCallaoDAOHelper; -import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaQuery; @Stateless @Remote(ReportService.class) @Local(ReportServiceLocal.class) +@TransactionAttribute public class ReportServiceImpl extends AbstractLimaService implements ReportService, ReportServiceLocal { - private TopiaContext rootContext; - @EJB protected FinancialPeriodServiceLocal financialPeriodService; @EJB protected AccountService accountService; - public ReportServiceImpl() { - rootContext = acquireRootContext(); - } - - @Override - public ReportsDatas generateAccountsReports(Account account, - Boolean thirdPartAccountsMode, - Date beginDate, - Date endDate) throws LimaException { - ReportsDatas reportsDatas = null; - - TopiaContext topiaTransaction = beginTransaction(rootContext); - try { - reportsDatas = - generateAccountReportsWithTransaction(account, thirdPartAccountsMode, beginDate, - endDate, topiaTransaction); - } catch (Exception ex) { - doCatch(topiaTransaction, ex); - } finally { - doFinally(topiaTransaction); - } - - return reportsDatas; - } - /** * Recursiv * List entries for a period and an account @@ -104,56 +75,54 @@ * - for subaccount * - for a foldaccounts, contains many accounts * - for a foldthirdparts accounts - * @throws TopiaException */ @Override - public ReportsDatas generateAccountReportsWithTransaction(Account account, - Boolean thirdPartAccountsMode, - Date beginDate, - Date endDate, - TopiaContext topiaContext) throws LimaException, TopiaException { + public ReportsDatas generateAccountsReports(Account account, Boolean thirdPartAccountsMode, + Date beginDate, Date endDate) throws LimaException { ReportsDatas reportsDatas = new ReportsDatasImpl(); - - BigDecimal credit = new BigDecimal(0); - BigDecimal debit = new BigDecimal(0); - BigDecimal solde = new BigDecimal(0); - List<Entry> entries = new ArrayList<Entry>(); - //Get allsubaccounts and thirdParts accounts - List<Account> accounts = accountService.getAllSubAccounts(account); - - // is already subaccount - // TODO echatellier 20120502 c'est vraiment voulu ? - // il ne peut pas y avoir de transaction sur des comptes non feuilles ? - // a verifier, sinon, supprimer la récursion - if (accounts.size() == 0) { - reportsDatas = generateSubAccountReportsWithTransaction(account, - beginDate, endDate, topiaContext); - } - // else is folder accounts contains many subs and thirds accounts - else { - for (Account subAccount : accounts) { - ReportsDatas subReportsDatas = - generateAccountReportsWithTransaction(subAccount, true, - beginDate, endDate, topiaContext); - debit = debit.add(subReportsDatas.getAmountDebit()); - credit = credit.add(subReportsDatas.getAmountCredit()); - entries.addAll(subReportsDatas.getListEntry()); + try { + BigDecimal credit = new BigDecimal(0); + BigDecimal debit = new BigDecimal(0); + BigDecimal solde = new BigDecimal(0); + List<Entry> entries = new ArrayList<Entry>(); + + //Get allsubaccounts and thirdParts accounts + List<Account> accounts = accountService.getAllSubAccounts(account); + + // is already subaccount + // TODO echatellier 20120502 c'est vraiment voulu ? + // il ne peut pas y avoir de transaction sur des comptes non feuilles ? + // a verifier, sinon, supprimer la récursion + if (accounts.size() == 0) { + reportsDatas = generateSubAccountReports(account, + beginDate, endDate); } - //solde = debit - credit - solde = solde.add(debit); - solde = solde.subtract(credit); - - if (solde.compareTo(BigDecimal.ZERO) == 1) { - reportsDatas.setSoldeDebit(true); + // else is folder accounts contains many subs and thirds accounts + else { + for (Account subAccount : accounts) { + ReportsDatas subReportsDatas = + generateAccountsReports(subAccount, true, beginDate, endDate); + debit = debit.add(subReportsDatas.getAmountDebit()); + credit = credit.add(subReportsDatas.getAmountCredit()); + entries.addAll(subReportsDatas.getListEntry()); + } + //solde = debit - credit + solde = solde.add(debit); + solde = solde.subtract(credit); + + if (solde.compareTo(BigDecimal.ZERO) == 1) { + reportsDatas.setSoldeDebit(true); + } + solde = solde.abs(); + reportsDatas.setAmountCredit(credit); + reportsDatas.setAmountDebit(debit); + reportsDatas.setAmountSolde(solde); + reportsDatas.setListEntry(entries); } - solde = solde.abs(); - reportsDatas.setAmountCredit(credit); - reportsDatas.setAmountDebit(debit); - reportsDatas.setAmountSolde(solde); - reportsDatas.setListEntry(entries); + } catch (TopiaException ex) { + throw new LimaException("Can't generate report", ex); } - return reportsDatas; } @@ -169,14 +138,14 @@ * @throws LimaException * @throws TopiaException */ - protected ReportsDatas generateSubAccountReportsWithTransaction(Account account, - Date beginDate, Date endDate, TopiaContext topiaContext) throws TopiaException { + protected ReportsDatas generateSubAccountReports(Account account, + Date beginDate, Date endDate) throws TopiaException { ReportsDatas reportsDatas = new ReportsDatasImpl(); BigDecimal credit = new BigDecimal(0); BigDecimal debit = new BigDecimal(0); BigDecimal solde = new BigDecimal(0); - EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); + EntryDAO entryDAO = getDaoHelper().getEntryDAO(); // trouve les entrees associées à ca compte entre les date données List<Entry> listEntries = entryDAO.findAllEntryOfBalancedTransaction(account, beginDate, endDate); @@ -220,14 +189,14 @@ * Get all entries if true * @throws TopiaException */ - public ReportsDatas generateSubAccountBalanceWithTransaction(Account account, - Date beginDate, Date endDate, Boolean getEntries, TopiaContext topiaContext) throws LimaException, TopiaException { + public ReportsDatas generateSubAccountBalance(Account account, + Date beginDate, Date endDate, Boolean getEntries) throws LimaException, TopiaException { ReportsDatas reportsDatas = new ReportsDatasImpl(); BigDecimal credit = new BigDecimal(0); BigDecimal debit = new BigDecimal(0); BigDecimal solde = new BigDecimal(0); - EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaContext); + EntryDAO entryDAO = getDaoHelper().getEntryDAO(); if (getEntries) { List<Entry> listEntries = entryDAO.findAllEntryOfBalancedTransaction(account, beginDate, endDate); @@ -282,9 +251,8 @@ BigDecimal solde = new BigDecimal(0); // Get all entries with a topia query - TopiaContext topiaTransaction = beginTransaction(rootContext); try { - EntryDAO entryDAO = LimaCallaoDAOHelper.getEntryDAO(topiaTransaction); + EntryDAO entryDAO = getDaoHelper().getEntryDAO(); List<Entry> entries = entryDAO.findAllEntryOfBalancedTransaction(entryBook, beginDate, endDate); reportsDatas.setListEntry(entries); @@ -314,10 +282,8 @@ reportsDatas.setAmountCredit(credit); reportsDatas.setAmountDebit(debit); reportsDatas.setAmountSolde(solde); - } catch (Exception ex) { - doCatch(topiaTransaction, ex); - } finally { - doFinally(topiaTransaction); + } catch (TopiaException ex) { + throw new LimaException("Can't generate report", ex); } return reportsDatas; @@ -345,11 +311,10 @@ BigDecimal credit = new BigDecimal(0); BigDecimal debit = new BigDecimal(0); BigDecimal solde = new BigDecimal(0); - TopiaContext topiaTransaction = beginTransaction(rootContext); + try { - AccountDAO accountDAO = - LimaCallaoDAOHelper.getAccountDAO(topiaTransaction); + AccountDAO accountDAO = getDaoHelper().getAccountDAO(); //for each account create a balance sheet with a ReportsDatas List<Account> accounts; @@ -366,8 +331,8 @@ } for (Account account : accounts) { ReportsDatas reportsDatas = - generateSubAccountBalanceWithTransaction(account, beginDate, - endDate, getEntries, topiaTransaction); + generateSubAccountBalance(account, beginDate, + endDate, getEntries); reportsDatas.setAccount(account); BigDecimal amount = reportsDatas.getAmountSolde(); if (amount == null) { @@ -402,9 +367,7 @@ balanceTrial.setAmountDebit(debit); balanceTrial.setAmountSolde(solde); } catch (Exception ex) { - doCatch(topiaTransaction, ex); - } finally { - doFinally(topiaTransaction); + throw new LimaException("Can't generate report", ex); } return balanceTrial; @@ -426,11 +389,9 @@ endDate, selectedAccounts, true, - movementedFilter - ); + movementedFilter); } - /** * Generate VAT * @@ -440,36 +401,30 @@ @Override public List<Object> generateVat(FiscalPeriod fiscalPeriod) throws LimaException { List<Object> list = new ArrayList<Object>(); - if (fiscalPeriod != null) { - TopiaContext topiaTransaction = beginTransaction(rootContext); - try { + try { - //lists all accounts - AccountDAO accountDAO = - LimaCallaoDAOHelper.getAccountDAO(topiaTransaction); - List<Account> accountsList; - //gets all financial periods from the fiscal period - List<FinancialPeriod> financialPeriod = financialPeriodService.getFinancialPeriods( - fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate()); - for (FinancialPeriod fp : financialPeriod) { - list.add(fp); - accountsList = accountDAO.findAll(); - for (Account account : accountsList) { - //VAT accounts start only with number 44 - //FIXME echatellier 44 is hardcoded and depends on - //french rule ? - if (account.getAccountNumber().startsWith("44")) { - list.add(generateBalanceTrial(fp.getBeginDate(), - fp.getEndDate(), account.getAccountNumber(), - true, false)); - } + //lists all accounts + AccountDAO accountDAO = getDaoHelper().getAccountDAO(); + List<Account> accountsList; + //gets all financial periods from the fiscal period + List<FinancialPeriod> financialPeriod = financialPeriodService.getFinancialPeriods( + fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate()); + for (FinancialPeriod fp : financialPeriod) { + list.add(fp); + accountsList = accountDAO.findAll(); + for (Account account : accountsList) { + //VAT accounts start only with number 44 + //FIXME echatellier 44 is hardcoded and depends on + //french rule ? + if (account.getAccountNumber().startsWith("44")) { + list.add(generateBalanceTrial(fp.getBeginDate(), + fp.getEndDate(), account.getAccountNumber(), + true, false)); } } - } catch (Exception eee) { - doCatch(topiaTransaction, eee); - } finally { - doFinally(topiaTransaction); } + } catch (TopiaException ex) { + throw new LimaException("Can't generate report", ex); } return list; } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/VatStatementServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/VatStatementServiceImpl.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/VatStatementServiceImpl.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -35,7 +35,6 @@ import org.chorem.lima.business.LimaException; import org.chorem.lima.business.api.ReportServiceLocal; import org.chorem.lima.business.api.VatStatementService; -import org.chorem.lima.business.api.VatStatementServiceLocal; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountDAO; import org.chorem.lima.entity.LimaCallaoDAOHelper; @@ -51,6 +50,8 @@ import javax.ejb.Local; import javax.ejb.Remote; import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; + import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; @@ -64,27 +65,18 @@ */ @Stateless @Remote(VatStatementService.class) -@Local(VatStatementServiceLocal.class) -public class VatStatementServiceImpl extends AbstractLimaService implements VatStatementService, VatStatementServiceLocal { +@TransactionAttribute +public class VatStatementServiceImpl extends AbstractLimaService implements VatStatementService { - private TopiaContext rootContext; - @EJB private ReportServiceLocal reportServiceLocal; - public VatStatementServiceImpl() { - rootContext = acquireRootContext(); - } - - @Override - public void createVatStatementWithTransaction(VatStatement masterVatStatement, - VatStatement vatStatement, - TopiaContext topiaContext) throws LimaException { + public void createVatStatement(VatStatement masterVatStatement, + VatStatement vatStatement) throws LimaException { try { - VatStatementDAO vatStatementDAO = - LimaCallaoDAOHelper.getVatStatementDAO(topiaContext); + VatStatementDAO vatStatementDAO = getDaoHelper().getVatStatementDAO(); vatStatementDAO.create(vatStatement); @@ -99,53 +91,26 @@ vatStatementDAO.update(mastervatStatementUpdate); } - commitTransaction(topiaContext); - } catch (TopiaException ex) { - doCatch(topiaContext, ex); + throw new LimaException("Can't create vat statement", ex); } } - @Override - public void createVatStatement(VatStatement masterVatStatement, - VatStatement vatStatement) throws LimaException { - - TopiaContext transaction = beginTransaction(rootContext); - try { - - createVatStatementWithTransaction(masterVatStatement, - vatStatement, - transaction); - } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); - } - - } - - - @Override public List<VatStatement> getAllVatStatements() throws LimaException { - TopiaContext transaction = beginTransaction(rootContext); List<VatStatement> vatStatements = null; try { - VatStatementDAO vatStatementDAO = - LimaCallaoDAOHelper.getVatStatementDAO(transaction); + VatStatementDAO vatStatementDAO = getDaoHelper().getVatStatementDAO(); vatStatements = vatStatementDAO.findAll(); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't get vat statements", ex); } return vatStatements; } - @Override public List<VatStatement> getAllChildrenVatStatement( VatStatement vatStatement, List<VatStatement> result) throws LimaException { @@ -160,25 +125,20 @@ } - @Override public List<VatStatement> getChildrenVatStatement(VatStatement masterVatStatement) throws LimaException { List<VatStatement> vatStatements = null; - TopiaContext transaction = beginTransaction(rootContext); try { - VatStatementDAO vatStatementDAO = - LimaCallaoDAOHelper.getVatStatementDAO(transaction); + VatStatementDAO vatStatementDAO = getDaoHelper().getVatStatementDAO(); TopiaQuery query = vatStatementDAO.createQuery(); query.addEquals("masterVatStatement", masterVatStatement) .addOrder(VatStatement.TOPIA_CREATE_DATE); vatStatements = vatStatementDAO.findAllByQuery(query); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't get vat statements", ex); } return vatStatements; @@ -187,22 +147,17 @@ @Override public void updateVatStatement(VatStatement vatStatement) throws LimaException { - TopiaContext transaction = beginTransaction(rootContext); try { // DAO - VatStatementDAO vatStatementHeaderDAO = - LimaCallaoDAOHelper.getVatStatementDAO(transaction); + VatStatementDAO vatStatementHeaderDAO = getDaoHelper().getVatStatementDAO(); //update vatStatementHeaderDAO.update(vatStatement); - //commit - commitTransaction(transaction); } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + throw new LimaException("Can't update vat statement", ex); } } + /* TODO echatellier 20120510 unused function public Amounts amountFromAccountList(String accountsNumberList, Date selectedBeginDate, Date selectedEndDate, @@ -248,24 +203,22 @@ doCatch(topiaContext, e); } return amounts; - } + }*/ /** - * Gives the list of account numbers from a VatStatement + * Gives the list of account numbers from a VatStatement. * * @param vatStatement * @param topiaContext * @return accountNumbersList * @throws LimaException */ - public String findAccountNumberByVatStatement(VatStatement vatStatement, - TopiaContext topiaContext) throws LimaException { + protected String findAccountNumberByVatStatement(VatStatement vatStatement) throws LimaException { String accountNumbersList = null; try { - VatStatementDAO vatStatementDAO = - LimaCallaoDAOHelper.getVatStatementDAO(topiaContext); + VatStatementDAO vatStatementDAO = getDaoHelper().getVatStatementDAO(); TopiaQuery query = vatStatementDAO.createQuery(); String labelProperty = @@ -285,8 +238,8 @@ if (vatStatementsList.size() > 0) { accountNumbersList = vatStatementsList.get(0).getAccounts(); } - } catch (TopiaException e) { - doCatch(topiaContext, e); + } catch (TopiaException ex) { + throw new LimaException("Can't find accountNumber by vatStatement", ex); } return accountNumbersList; } @@ -295,51 +248,30 @@ public VatStatementAmounts vatStatementAmounts(VatStatement vatStatement, Date selectedBeginDate, Date selectedEndDate) throws LimaException { - TopiaContext transaction = beginTransaction(rootContext); - VatStatementAmounts vatStatementAmount = new VatStatementAmountsImpl(); - try { - vatStatementAmount = vatStatementAmounts(vatStatement, - selectedBeginDate, - selectedEndDate, - transaction); - } catch (Exception e) { - doCatch(transaction, e); - } finally { - doFinally(transaction); - } - return vatStatementAmount; - } + VatStatementAmounts vatStatementAmounts = new VatStatementAmountsImpl(); - @Override - public VatStatementAmounts vatStatementAmounts(VatStatement vatStatement, - Date selectedBeginDate, - Date selectedEndDate, - TopiaContext topiacontext) throws LimaException { - VatStatementAmounts vatStatementAmounts = - new VatStatementAmountsImpl(); - BigDecimal debitTemp = new BigDecimal(0); BigDecimal creditTemp = new BigDecimal(0); try { - String accountNumbersList = findAccountNumberByVatStatement(vatStatement, topiacontext); + String accountNumbersList = findAccountNumberByVatStatement(vatStatement); - AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(topiacontext); + AccountDAO accountDAO = getDaoHelper().getAccountDAO(); List<Account> accountsList = accountDAO.stringToListAccounts(accountNumbersList, false); for (Account account : accountsList) { ReportsDatas reportsDatas = reportServiceLocal. - generateAccountReportsWithTransaction(account, true, - selectedBeginDate, selectedEndDate, topiacontext); + generateAccountsReports(account, true, + selectedBeginDate, selectedEndDate); if (reportsDatas.getSoldeDebit()) { debitTemp = debitTemp.add(reportsDatas.getAmountSolde()); } else { creditTemp = creditTemp.add(reportsDatas.getAmountSolde()); } } - } catch (TopiaException e) { - doCatch(topiacontext, e); + } catch (TopiaException ex) { + throw new LimaException("Error in vatStatementAmounts", ex); } //return debitTemp.subtract(creditTemp).abs(); vatStatementAmounts.setAmount(debitTemp.subtract(creditTemp).abs()); @@ -351,12 +283,10 @@ public VatStatement findVatStatementByString(String label) throws LimaException { VatStatement vatStatement = new VatStatementImpl(); - TopiaContext transaction = beginTransaction(rootContext); try { - VatStatementDAO vatStatementDAO = - LimaCallaoDAOHelper.getVatStatementDAO(transaction); + VatStatementDAO vatStatementDAO = getDaoHelper().getVatStatementDAO(); TopiaQuery query = vatStatementDAO.createQuery(); String labelProperty = @@ -378,29 +308,20 @@ vatStatement = vatStatementsList.get(0); } - } catch (Exception e) { - doCatch(transaction, e); - } finally { - doFinally(transaction); + } catch (TopiaException ex) { + throw new LimaException("Can't find vatstatement", ex); } return vatStatement; } /** remote methode to get list of financial statement */ public List<VatStatementAmounts> vatStatementReport(Date beginDate, Date endDate) throws LimaException { - List<VatStatementAmounts> result = null; - TopiaContext transaction = beginTransaction(rootContext); - try { - //create list form tree - VatStatementDatas vatStatementDatas = vatStatementReport(null, beginDate, endDate, - new VatStatementDatasImpl(), - transaction); - result = vatStatementDatas.getListResult(); - } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); - } + + //create list form tree + VatStatementDatas vatStatementDatas = vatStatementReport(null, beginDate, endDate, + new VatStatementDatasImpl()); + List<VatStatementAmounts> result = vatStatementDatas.getListResult(); + return result; } @@ -412,78 +333,72 @@ public VatStatementDatas vatStatementReport(VatStatement vatStatement, Date selectedBeginDate, Date selectedEndDate, - VatStatementDatas result, - TopiaContext topiaContext) throws LimaException { + VatStatementDatas result) throws LimaException { List<VatStatement> vatStatements = getChildrenVatStatement(vatStatement); - try { - BigDecimal amount = new BigDecimal(0); - List<VatStatementAmounts> subResult = - new ArrayList<VatStatementAmounts>(); - for (VatStatement subVatStatement : vatStatements) { - VatStatementAmounts vatStatementAmounts = - vatStatementAmounts(subVatStatement, - selectedBeginDate, selectedEndDate, topiaContext); - vatStatementAmounts.setLabel(subVatStatement.getLabel()); - if (!subVatStatement.getHeader()) { - //on calcul - amount = - amount.add(vatStatementAmounts.getAmount()); - subResult.add(vatStatementAmounts); - } else { - VatStatementDatas vatStatementDatas = - vatStatementReport(subVatStatement, - selectedBeginDate, selectedEndDate, result, topiaContext); - amount = amount.add(vatStatementDatas. - getVatStatementAmounts().getAmount()); + BigDecimal amount = new BigDecimal(0); + List<VatStatementAmounts> subResult = + new ArrayList<VatStatementAmounts>(); + for (VatStatement subVatStatement : vatStatements) { + VatStatementAmounts vatStatementAmounts = + vatStatementAmounts(subVatStatement, + selectedBeginDate, selectedEndDate); + vatStatementAmounts.setLabel(subVatStatement.getLabel()); + if (!subVatStatement.getHeader()) { + //on calcul + amount = + amount.add(vatStatementAmounts.getAmount()); + subResult.add(vatStatementAmounts); + } else { + VatStatementDatas vatStatementDatas = + vatStatementReport(subVatStatement, + selectedBeginDate, selectedEndDate, result); + amount = amount.add(vatStatementDatas. + getVatStatementAmounts().getAmount()); - VatStatementAmounts headerVatStatementAmounts = - vatStatementDatas.getVatStatementAmounts(); - //Si sous-total - if (subVatStatement.getHeader()) { - VatStatementAmounts header = - new VatStatementAmountsImpl(); - header.setLabel(headerVatStatementAmounts.getLabel()); - header.setLevel(headerVatStatementAmounts.getLevel()); - header.setHeader(true); - //ajoute header - subResult.add(header); - //ajoute liste - if (vatStatementDatas.getListResult() != null) { - subResult.addAll(vatStatementDatas.getListResult()); - } - //ajoute une ligne vide - subResult.add(new VatStatementAmountsImpl()); + VatStatementAmounts headerVatStatementAmounts = + vatStatementDatas.getVatStatementAmounts(); + //Si sous-total + if (subVatStatement.getHeader()) { + VatStatementAmounts header = + new VatStatementAmountsImpl(); + header.setLabel(headerVatStatementAmounts.getLabel()); + header.setLevel(headerVatStatementAmounts.getLevel()); + header.setHeader(true); + //ajoute header + subResult.add(header); + //ajoute liste + if (vatStatementDatas.getListResult() != null) { + subResult.addAll(vatStatementDatas.getListResult()); } + //ajoute une ligne vide + subResult.add(new VatStatementAmountsImpl()); + } } - VatStatementAmounts vatStatementAmounts = - new VatStatementAmountsImpl(); - vatStatementAmounts.setAmount(amount); - if (vatStatement != null) { - vatStatementAmounts.setLabel(vatStatement.getLabel()); - vatStatementAmounts.setHeader(vatStatement.getHeader()); - vatStatementAmounts.setLevel(vatStatement.getLevel()); - } - result.setVatStatementAmounts(vatStatementAmounts); - result.setListResult(subResult); - } catch (LimaException eee) { - doCatch(topiaContext, eee); } + VatStatementAmounts vatStatementAmounts = + new VatStatementAmountsImpl(); + vatStatementAmounts.setAmount(amount); + if (vatStatement != null) { + vatStatementAmounts.setLabel(vatStatement.getLabel()); + vatStatementAmounts.setHeader(vatStatement.getHeader()); + vatStatementAmounts.setLevel(vatStatement.getLevel()); + } + result.setVatStatementAmounts(vatStatementAmounts); + result.setListResult(subResult); + return result; } @Override public void removeVatStatement(VatStatement vatStatement) throws LimaException { - TopiaContext transaction = beginTransaction(rootContext); try { - VatStatementDAO vatStatementDAO = - LimaCallaoDAOHelper.getVatStatementDAO(transaction); + VatStatementDAO vatStatementDAO = getDaoHelper().getVatStatementDAO(); - // remove vatstatement VatStatement vatStatementToDelete = vatStatementDAO.findByTopiaId( @@ -505,13 +420,8 @@ } } - //commit - commitTransaction(transaction); - - } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); + } catch (TopiaException ex) { + throw new LimaException("Can't remove vatstatement", ex); } } Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/TestAccountingRules.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/TestAccountingRules.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/TestAccountingRules.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -66,12 +66,11 @@ * Copier/coller de la methode france. * Le probleme ici est que le default n'en creer aucune. */ - public List<FinancialPeriod> createFiscalPeriodRules(FiscalPeriod fiscalPeriod, TopiaContext transaction) throws LimaException { - super.createFiscalPeriodRules(fiscalPeriod, transaction); + public List<FinancialPeriod> createFiscalPeriodRules(FiscalPeriod fiscalPeriod) throws LimaException { + super.createFiscalPeriodRules(fiscalPeriod); List<FinancialPeriod> financialPeriods = new ArrayList<FinancialPeriod>(); try { - FiscalPeriodDAO fiscalPeriodDAO = - LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + FiscalPeriodDAO fiscalPeriodDAO = getDaoHelper().getFiscalPeriodDAO(); //Checks if is not the first fiscalperiod to create if (fiscalPeriodDAO.findAll().size() != 0) { @@ -124,7 +123,7 @@ loopDate = DateUtils.addMilliseconds(loopDate, 1); } } catch (TopiaException ex) { - doCatch(transaction, ex, log); + throw new LimaException("Can't check rule", ex); } return financialPeriods; } Deleted: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/EntryBookServiceLocal.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/EntryBookServiceLocal.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/EntryBookServiceLocal.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -1,47 +0,0 @@ -/* - * #%L - * Lima business - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.business.api; - -import org.chorem.lima.business.LimaException; -import org.chorem.lima.entity.EntryBook; -import org.nuiton.topia.TopiaContext; - - -/** - * Entry book service. - * - * @author chatellier - * @version $Revision$ - * <p/> - * Last update : $Date$ - * By : $Author$ - */ - -public interface EntryBookServiceLocal extends EntryBookService { - - EntryBook createEntryBookWithTransaction(EntryBook entryBook, TopiaContext topiaContext) throws LimaException; - -} Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialPeriodServiceLocal.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialPeriodServiceLocal.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialPeriodServiceLocal.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -45,11 +45,5 @@ public interface FinancialPeriodServiceLocal extends FinancialPeriodService { - void createFinancialPeriodsWithTransaction(List<FinancialPeriod> financialPeriods, - TopiaContext topiaContext) throws LimaException; - void blockClosedPeriodicEntryBookWithTransaction(ClosedPeriodicEntryBook closedPeriodicEntryBook, - TopiaContext topiaContext) throws LimaException; - - } Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialStatementServiceLocal.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialStatementServiceLocal.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialStatementServiceLocal.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -31,9 +31,5 @@ public interface FinancialStatementServiceLocal extends FinancialStatementService { - void createFinancialStatementWithTransaction(FinancialStatement masterFinancialStatement, - FinancialStatement financialStatement, - TopiaContext topiaContext) throws LimaException; - } Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionServiceLocal.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionServiceLocal.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionServiceLocal.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -42,13 +42,5 @@ public interface FinancialTransactionServiceLocal extends FinancialTransactionService { - FinancialTransaction createFinancialTransactionWithTransaction(FinancialTransaction financialtransaction, - TopiaContext topiaContext) throws LimaException; - void updateFinancialTransactionWithTransaction(FinancialTransaction financialtransaction, - TopiaContext topiaContext) throws LimaException; - - Entry createEntryWithTransaction(Entry entry, TopiaContext topiaContext) throws LimaException; - - } Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodServiceLocal.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodServiceLocal.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FiscalPeriodServiceLocal.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -40,8 +40,5 @@ */ public interface FiscalPeriodServiceLocal extends FiscalPeriodService { - FiscalPeriod createFiscalPeriodWithTransaction(FiscalPeriod fiscalPeriod, - TopiaContext topiaContext) throws LimaException; - } Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/IdentityServiceLocal.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/IdentityServiceLocal.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/IdentityServiceLocal.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -31,9 +31,5 @@ public interface IdentityServiceLocal extends IdentityService { - void updateIdentityWithTransaction(Identity identity, - TopiaContext topiaContext) throws LimaException; - Identity getIdentityWithTransaction(TopiaContext topiaContext) throws LimaException; - } Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ReportServiceLocal.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ReportServiceLocal.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ReportServiceLocal.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -52,28 +52,4 @@ public interface ReportServiceLocal extends ReportService { - ReportsDatas generateAccountReportsWithTransaction(Account account, - Boolean thirdPartAccountsMode, - Date beginDate, - Date endDate, - TopiaContext topiaContext) throws LimaException, TopiaException; - - /** - * Calculate all credit, debit and solde amounts for the balance. - * <p/> - * Get all entries if true - * - * @param account - * @param beginDate - * @param endDate - * @param getEntries - * @param topiaContext - * @return - * @throws LimaException - */ - ReportsDatas generateSubAccountBalanceWithTransaction(Account account, - Date beginDate, - Date endDate, - Boolean getEntries, - TopiaContext topiaContext) throws LimaException, TopiaException; } Deleted: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/VatStatementServiceLocal.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/VatStatementServiceLocal.java 2012-05-09 15:37:59 UTC (rev 3408) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/VatStatementServiceLocal.java 2012-05-11 10:19:53 UTC (rev 3409) @@ -1,52 +0,0 @@ -/* - * #%L - * Lima :: business - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2011 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package org.chorem.lima.business.api; - -import org.chorem.lima.beans.VatStatementAmounts; -import org.chorem.lima.beans.VatStatementDatas; -import org.chorem.lima.business.LimaException; -import org.chorem.lima.entity.VatStatement; -import org.nuiton.topia.TopiaContext; - -import java.util.Date; - -public interface VatStatementServiceLocal extends VatStatementService { - - void createVatStatementWithTransaction( - VatStatement masterVatStatement, VatStatement vatStatement, - TopiaContext transaction) throws LimaException; - - VatStatementAmounts vatStatementAmounts(VatStatement vatStatement, - Date selectedBeginDate, - Date selectedEndDate, - TopiaContext topiacontext) throws LimaException; - - VatStatementDatas vatStatementReport(VatStatement vatStatement, - Date selectedBeginDate, - Date selectedEndDate, - VatStatementDatas result, - TopiaContext topiaContext) throws LimaException; - -}