Author: echatellier Date: 2012-05-11 17:23:45 +0200 (Fri, 11 May 2012) New Revision: 3411 Url: http://chorem.org/repositories/revision/lima/3411 Log: Fix hibernate exception : ids for this class must be manually assigned before calling save(): org.chorem.lima.entity.FinancialPeriodImpl Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialPeriodService.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/FinancialPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.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/FranceAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2012-05-11 10:26:46 UTC (rev 3410) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2012-05-11 15:23:45 UTC (rev 3411) @@ -36,6 +36,7 @@ import org.chorem.lima.entity.ClosedPeriodicEntryBookDAO; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FinancialPeriodDAO; import org.chorem.lima.entity.FinancialPeriodImpl; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.FiscalPeriodDAO; @@ -160,9 +161,8 @@ financialPeriod.setEndDate(loopDate); } //create it - fiscalPeriod.addFinancialPeriod(financialPeriod); financialPeriods.add(financialPeriod); - //financialPeriodService.createFinancialPeriodWithTransaction(financialPeriod, transaction); + //loop incremente loopDate = DateUtils.addMilliseconds(loopDate, 1); } 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-11 10:26:46 UTC (rev 3410) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2012-05-11 15:23:45 UTC (rev 3411) @@ -25,6 +25,15 @@ package org.chorem.lima.business.ejb; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.List; + +import javax.ejb.Remote; +import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; + import org.chorem.lima.business.AccountingRules; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; @@ -40,14 +49,7 @@ import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; -import javax.ejb.Remote; -import javax.ejb.Stateless; -import javax.ejb.TransactionAttribute; -import java.util.Date; -import java.util.List; - - /** * Gestion des périodes intermédiaires durant l'exercice. * Chaque timeSpan sera fixe, et devra correspondre à un mois complet. @@ -64,8 +66,10 @@ * peut être bloquée ou non */ @Override - public void createFinancialPeriods(List<FinancialPeriod> financialPeriods) throws LimaException { + public List<FinancialPeriod> createFinancialPeriods(Collection<FinancialPeriod> financialPeriods) throws LimaException { + List<FinancialPeriod> result = new ArrayList<FinancialPeriod>(); + try { FinancialPeriodDAO financialPeriodDAO = @@ -76,6 +80,10 @@ getDaoHelper().getEntryBookDAO(); //create all financial period for (FinancialPeriod financialPeriod : financialPeriods) { + + //create financial period + financialPeriod = financialPeriodDAO.create(financialPeriod); + //create ClosedPeriodicEntryBook for all entrybook for (EntryBook entryBook : entryBookDAO.findAll()) { //new closed periodic entrybook @@ -88,13 +96,15 @@ // create it closedPeriodicEntryBookDAO.create(closedPeriodicEntryBook); } - //create financial period - financialPeriodDAO.create(financialPeriod); + + result.add(financialPeriod); } } catch (TopiaException ex) { throw new LimaException("Can't create period", ex); } + + return result; } /** @return all financial period */ 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-11 10:26:46 UTC (rev 3410) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2012-05-11 15:23:45 UTC (rev 3411) @@ -67,6 +67,7 @@ import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.FiscalPeriodDAO; import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImpl; import org.nuiton.topia.framework.TopiaQuery; /** @@ -103,6 +104,8 @@ try { + FiscalPeriodDAO fiscalPeriodDAO = getDaoHelper().getFiscalPeriodDAO(); + Date beginDate = fiscalPeriod.getBeginDate(); beginDate = DateUtils.truncate(beginDate, Calendar.DATE); Date endDate = fiscalPeriod.getEndDate(); @@ -114,15 +117,21 @@ fiscalPeriod.setEndDate(endDate); //check rules before create the account - List<FinancialPeriod> financialPeriods = - accountingRules.createFiscalPeriodRules(fiscalPeriod); - financialPeriodService. - createFinancialPeriods(financialPeriods); + List<FinancialPeriod> financialPeriods = accountingRules.createFiscalPeriodRules(fiscalPeriod); - FiscalPeriodDAO fiscalPeriodDAO = getDaoHelper().getFiscalPeriodDAO(); + // FIXME echatellier 20120510 il y a un gros problème ici + // les periods sont instanciées par la rule + // mais crée ensuite par le service et la periodes + // est créée au final avec des entités qui n'ont pas les id affectés + financialPeriods = financialPeriodService.createFinancialPeriods(financialPeriods); - //create + // create result = fiscalPeriodDAO.create(fiscalPeriod); + result.addAllFinancialPeriod(financialPeriods); + + // udpate + result = fiscalPeriodDAO.update(result); + } catch (TopiaException ex) { throw new LimaException("Can't create period", 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-11 10:26:46 UTC (rev 3410) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/accountingrules/TestAccountingRules.java 2012-05-11 15:23:45 UTC (rev 3411) @@ -116,7 +116,6 @@ financialPeriod.setEndDate(loopDate); } //create it - fiscalPeriod.addFinancialPeriod(financialPeriod); financialPeriods.add(financialPeriod); //financialPeriodService.createFinancialPeriodWithTransaction(financialPeriod, transaction); //loop incremente Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialPeriodService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialPeriodService.java 2012-05-11 10:26:46 UTC (rev 3410) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialPeriodService.java 2012-05-11 15:23:45 UTC (rev 3411) @@ -25,14 +25,15 @@ package org.chorem.lima.business.api; +import java.util.Collection; +import java.util.Date; +import java.util.List; + import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.ClosedPeriodicEntryBook; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FinancialPeriod; -import java.util.Date; -import java.util.List; - /** * Financial period service. * @@ -47,7 +48,7 @@ List<FinancialPeriod> getUnblockedFinancialPeriods() throws LimaException; - void createFinancialPeriods(List<FinancialPeriod> financialPeriods) throws LimaException; + List<FinancialPeriod> createFinancialPeriods(Collection<FinancialPeriod> financialPeriods) throws LimaException; ClosedPeriodicEntryBook getClosedPeriodicEntryBook(EntryBook entryBook, FinancialPeriod financialPeriod) throws LimaException;