Author: echatellier Date: 2010-04-02 18:55:19 +0200 (Fri, 02 Apr 2010) New Revision: 2824 Log: Fin de la structure des ejb (interface/impl) mais sans contenu Added: trunk/lima-business/src/main/java/org/chorem/lima/business/EntryBookService.java trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialPeriodService.java trunk/lima-business/src/main/java/org/chorem/lima/business/FiscalPeriodService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ImportExportService.java trunk/lima-business/src/main/java/org/chorem/lima/business/RecordService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ReportService.java trunk/lima-business/src/main/java/org/chorem/lima/business/TransactionService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportExportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/CSVExport.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/CSVImport.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/CSVImportEBP.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/xml/ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/xml/XMLExport.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/xml/XMLImport.java trunk/lima-business/src/test/resources/log4j.properties Removed: trunk/lima-business/src/main/java/org/chorem/lima/business/dto/ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/ServiceHelper.java trunk/lima-business/src/main/resources/log4j.properties Modified: trunk/lima-business/pom.xml trunk/lima-business/src/main/java/org/chorem/lima/business/AccountService.java trunk/lima-business/src/main/java/org/chorem/lima/business/LimaBusinessException.java trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java trunk/lima-business/src/main/java/org/chorem/lima/business/LimaException.java trunk/lima-business/src/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/EntryBookServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FilesServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/RecordServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TransactionServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/UserServiceImpl.java trunk/lima-business/src/main/resources/lima.properties trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/RecordServiceImplTest.java Modified: trunk/lima-business/pom.xml =================================================================== --- trunk/lima-business/pom.xml 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/pom.xml 2010-04-02 16:55:19 UTC (rev 2824) @@ -33,10 +33,6 @@ <artifactId>nuiton-utils</artifactId> </dependency> <dependency> - <groupId>javax.time</groupId> - <artifactId>jsr-310-ri</artifactId> - </dependency> - <dependency> <groupId>org.apache.openejb</groupId> <artifactId>openejb-core</artifactId> </dependency> @@ -62,6 +58,12 @@ <!-- Temp disable --> <showDeprecation>false</showDeprecation> <showWarnings>true</showWarnings> + + <!-- XML/CSV import export don't compile for now --> + <excludes> + <exclude>**/*Import*.java</exclude> + <exclude>**/*Export*.java</exclude> + </excludes> </configuration> </plugin> </plugins> Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/AccountService.java 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/AccountService.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,5 +1,5 @@ -/* *##% - * Copyright (C) 2010 Code Lutin, Chatellier Eric +/* *##% Lima Business + * 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 @@ -14,7 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * ##%* + */ package org.chorem.lima.business; Added: trunk/lima-business/src/main/java/org/chorem/lima/business/EntryBookService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/EntryBookService.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/EntryBookService.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -0,0 +1,44 @@ +/* *##% Lima Business + * 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 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* + */ + +package org.chorem.lima.business; + +import java.util.List; + +import org.chorem.lima.entity.EntryBook; + +/** + * Entry book service. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public interface EntryBookService { + + List<EntryBook> getAllEntryBooks() throws LimaException; + + void createEntryBook(EntryBook entryBook) throws LimaException; + + void updateEntryBook(EntryBook entryBook) throws LimaException; + + void removeEntryBook(EntryBook entryBook) throws LimaException; +} Property changes on: trunk/lima-business/src/main/java/org/chorem/lima/business/EntryBookService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialPeriodService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialPeriodService.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialPeriodService.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -0,0 +1,46 @@ +/* *##% Lima Business + * 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 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* + */ + +package org.chorem.lima.business; + +import java.util.List; + +import org.chorem.lima.entity.FinancialPeriod; + +/** + * Financial period service. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public interface FinancialPeriodService { + + List<FinancialPeriod> getAllFinancialPeriods() throws LimaException; + + List<FinancialPeriod> getNonLockedFinancialPeriods() throws LimaException; + + void createFinancialPeriod(FinancialPeriod financialPeriod) throws LimaException; + + //void updateFiscalPeriod(FinancialPeriod financialPeriod) throws LimaException; + + //void removeFiscalPeriod(FinancialPeriod financialPeriod) throws LimaException; +} Property changes on: trunk/lima-business/src/main/java/org/chorem/lima/business/FinancialPeriodService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/lima-business/src/main/java/org/chorem/lima/business/FiscalPeriodService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/FiscalPeriodService.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/FiscalPeriodService.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -0,0 +1,44 @@ +/* *##% Lima Business + * 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 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* + */ + +package org.chorem.lima.business; + +import java.util.List; + +import org.chorem.lima.entity.FiscalPeriod; + +/** + * Fiscal period service. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public interface FiscalPeriodService { + + List<FiscalPeriod> getAllFiscalPeriods() throws LimaException; + + void createFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException; + + //void updateFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException; + + //void removeFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException; +} Property changes on: trunk/lima-business/src/main/java/org/chorem/lima/business/FiscalPeriodService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/lima-business/src/main/java/org/chorem/lima/business/ImportExportService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ImportExportService.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ImportExportService.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -0,0 +1,84 @@ +/* *##% Lima Business + * 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 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* + */ + +package org.chorem.lima.business; + +/** + * Import export service. + * + * Currently import and export as XML. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public interface ImportExportService { + + /** + * Get database export as xml. + * + * For now it's use byte[] to be {@link java.io.Serializable}. InputStream + * nor file is allowed. + * + * TODO find a better solution than byte[] + * + * @return export as byte array + * @throws LimaException + */ + byte[] exportAsXML() throws LimaException; + + /** + * Import xml data into database. + * + * For now it's use byte[] to be {@link java.io.Serializable}. InputStream + * nor file is allowed. + * + * TODO find a better solution than byte[] + * + * @param data xml data as byte array + * @throws LimaException + */ + void importAsXML(byte[] data) throws LimaException; + + /** + * Get database export as CSV; + * + * @return export as byte array + * @throws LimaException + */ + byte[] exportAsCSV() throws LimaException; + + /** + * Import data as CSV into database. + * + * @param data data to import (CSV) + * @throws LimaException + */ + void importAsCSV(byte[] data) throws LimaException; + + /** + * Import data as EBP CSV export. + * + * @param data + * @throws LimaException + */ + void importAsEbpCSV(byte[] data) throws LimaException; +} Property changes on: trunk/lima-business/src/main/java/org/chorem/lima/business/ImportExportService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaBusinessException.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaBusinessException.java 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaBusinessException.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,19 +1,20 @@ -/* *##% Lima - * Copyright (C) 2010 CodeLutin +/* *##% Lima Business + * Copyright (C) 2008 - 2010 CodeLutin * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* */ package org.chorem.lima.business; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,5 +1,5 @@ -/* *##% - * Copyright (C) 2010 Code Lutin, Chatellier Eric +/* *##% Lima Business + * 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 @@ -14,7 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * ##%* + */ package org.chorem.lima.business; @@ -25,8 +26,10 @@ import org.nuiton.util.ArgumentsParserException; /** - * TODO add comment here. + * Configuration pour le business. * + * A voir comment le lier avec celui de lima main. + * * @author chatellier * @version $Revision$ * Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaException.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaException.java 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaException.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,19 +1,20 @@ -/* *##% Lima - * Copyright (C) 2010 CodeLutin +/* *##% Lima Business + * Copyright (C) 2008 - 2010 CodeLutin * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* */ package org.chorem.lima.business; Added: trunk/lima-business/src/main/java/org/chorem/lima/business/RecordService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/RecordService.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/RecordService.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -0,0 +1,42 @@ +/* *##% Lima Business + * 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 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* + */ + +package org.chorem.lima.business; + +import java.util.List; + +/** + * Fiscal period service. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public interface RecordService { + + //List<FiscalPeriod> getAllFiscalPeriods() throws LimaException; + + //void createFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException; + + //void updateFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException; + + //void removeFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException; +} Property changes on: trunk/lima-business/src/main/java/org/chorem/lima/business/RecordService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/lima-business/src/main/java/org/chorem/lima/business/ReportService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ReportService.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ReportService.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -0,0 +1,50 @@ +/* *##% Lima Business + * 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 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* + */ + +package org.chorem.lima.business; + +/** + * Service de generation des rapports. + * + * Actuellement: + * <ul> + * <li>Balance</li> + * <li>Bilan</li> + * </ul> + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public interface ReportService { + + + /** + * Generation du bilan. + * + * @param period + * @return + * @throws LimaException + */ + String generateBalanceSheet(String period) throws LimaException; + + +} Property changes on: trunk/lima-business/src/main/java/org/chorem/lima/business/ReportService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/lima-business/src/main/java/org/chorem/lima/business/TransactionService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/TransactionService.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/TransactionService.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -0,0 +1,44 @@ +/* *##% Lima Business + * 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 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* + */ + +package org.chorem.lima.business; + +import java.util.List; + +import org.chorem.lima.entity.Transaction; + +/** + * Transaction service. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public interface TransactionService { + + //List<Transaction> getAllTransactions() throws LimaException; + + //void createTransaction(Transaction transaction) throws LimaException; + + //void updateTransaction(Transaction transaction) throws LimaException; + + //void removeTransaction(Transaction transaction) throws LimaException; +} Property changes on: trunk/lima-business/src/main/java/org/chorem/lima/business/TransactionService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL 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 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AbstractLimaService.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,5 +1,5 @@ -/* *##% - * Copyright (C) 2010 Code Lutin, Chatellier Eric +/* *##% Lima Business + * 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 @@ -14,7 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * ##%* + */ package org.chorem.lima.business.ejb; 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 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,20 +1,20 @@ -/* - * *##% Callao AccountServiceImpl - * Copyright (C) 2009 CodeLutin +/* *##% Lima Business + * Copyright (C) 2008 - 2010 CodeLutin * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* */ package org.chorem.lima.business.ejb; @@ -93,6 +93,9 @@ throw new LimaBusinessException("Invalid AccountNumber : " + account.getAccountNumber()); } + // TODO verifier que le numero de compte du fils commence par celui du pere + // (peut etre trop specific à la compta francaise) + TopiaContext transaction = null; try { // basic check done, make check in database 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 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,20 +1,20 @@ -/* - * *##% Callao EntryBookServiceImpl - * Copyright (C) 2009 CodeLutin +/* *##% Lima Business + * Copyright (C) 2008 - 2010 CodeLutin * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* */ package org.chorem.lima.business.ejb; @@ -24,8 +24,11 @@ import java.util.ArrayList; import java.util.List; +import javax.ejb.Stateless; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.EntryBookService; import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; @@ -33,7 +36,6 @@ import org.chorem.lima.entity.EntryBookDAO; import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.chorem.lima.entity.Transaction; -import org.chorem.lima.entity.TransactionDAO; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaException; @@ -45,12 +47,15 @@ * * @author Rémi Chapelet */ -public class EntryBookServiceImpl { +@Stateless +public class EntryBookServiceImpl extends AbstractLimaService implements EntryBookService { private static final Log log = LogFactory.getLog(EntryBookServiceImpl.class); private TopiaContext rootContext; + protected TransactionServiceImpl transactionService = new TransactionServiceImpl(); + //private ConvertEntryBook convertEntryBook = new ConvertEntryBook(); public EntryBookServiceImpl() { @@ -70,7 +75,7 @@ * @param EntryBook EntryBook * @throws LimaException */ - public void createEntryBook(EntryBook EntryBook) throws LimaException { + public void createEntryBook(EntryBook entryBook) throws LimaException { /*String result = ServiceHelper.RESPOND_ERROR; try { // Acces BDD @@ -113,60 +118,27 @@ transaction = rootContext.beginTransaction(); // test si un EntryBook de ce nom existe deja - EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(transaction); - EntryBook existingEntryBook = EntryBookDAO.findByLabel(EntryBook.getLabel()); + EntryBookDAO entryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(transaction); + EntryBook existingEntryBook = entryBookDAO.findByLabel(entryBook.getLabel()); if (existingEntryBook != null) { - throw new LimaBusinessException(_("An EntryBook already exists with this label : %s", EntryBook.getLabel())); + throw new LimaBusinessException(_("An EntryBook already exists with this label : %s", entryBook.getLabel())); } // creation du EntryBook - EntryBookDAO.create(EntryBook); + entryBookDAO.create(entryBook); // commit transaction.commitTransaction(); } catch (TopiaException ex) { - if (transaction != null) { - try { - transaction.rollbackTransaction(); - } catch (TopiaException e) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - } - } - if (log.isErrorEnabled()) { - log.error("Error during create account", ex); - } - throw new LimaException("Can't create EntryBook", ex); + doCatch(transaction, ex, log); } finally { - if (transaction != null) { - try { - transaction.closeContext(); - } catch (TopiaException ex) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - throw new LimaException("Can't create EntryBook", ex); - } - } + doFinally(transaction, log); } } - /* - * Création d'un EntryBook à partir de son DTO. - * @param EntryBookDTO EntryBook au format DTO. - * @return - * - public String createEntryBook(EntryBookDTO EntryBookDTO) { - String result; - result = createEntryBook(EntryBookDTO.getLabel(), EntryBookDTO.getPrefix(), - EntryBookDTO.getDescription()); - return result; - }*/ - - public List<EntryBook> getAllEntryBook() throws LimaException { + public List<EntryBook> getAllEntryBooks() throws LimaException { /*List<EntryBookDTO> listEntryBookDTO = new ArrayList<EntryBookDTO>(); try { @@ -208,31 +180,10 @@ transaction.commitTransaction(); } catch (TopiaException ex) { - if (transaction != null) { - try { - transaction.rollbackTransaction(); - } catch (TopiaException e) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - } - } - if (log.isErrorEnabled()) { - log.error("Error during create account", ex); - } - throw new LimaException("Can't create EntryBook", ex); + doCatch(transaction, ex, log); } finally { - if (transaction != null) { - try { - transaction.closeContext(); - } catch (TopiaException ex) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - throw new LimaException("Can't create EntryBook", ex); - } - } + doFinally(transaction, log); } return EntryBooksList; @@ -310,45 +261,39 @@ return EntryBookDTO; }*/ - /* - * Permet de modifier un EntryBook. - * @param label - * @param prefix - * @return - * - public String modifyEntryBook(String topiaId, String label, String prefix, - String description) { - String result = ServiceHelper.RESPOND_ERROR; - EntryBook EntryBookModify = searchEntryBookWithTopiaId(topiaId); - // Si le EntryBook n'existe pas - if (EntryBookModify == null) { - if (log.isWarnEnabled()) { - log.warn("Le EntryBook " + label + " n'existe pas !"); + /** + * Permet de modifier un journal. + * + * @param entryBook journal + * @throws LimaException + */ + public void updateEntryBook(EntryBook entryBook) throws LimaException { + TopiaContext transaction = null; + try { + // basic check done, make check in database + // TODO move it into JTA + transaction = rootContext.beginTransaction(); + + // test si un EntryBook de ce nom existe deja + EntryBookDAO entryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(transaction); + EntryBook existingEntryBook = entryBookDAO.findByLabel(entryBook.getLabel()); + if (existingEntryBook != null) { + throw new LimaBusinessException(_("An EntryBook already exists with this label : %s", entryBook.getLabel())); } - result = ServiceHelper.EntryBook_NOT_EXIST; - } else // Sinon on modifie le EntryBook - { - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper - .getEntryBookDAO(topiaContext); - // Modifie le EntryBook - EntryBookModify.setPrefix(prefix); - EntryBookModify.setDescription(description); - EntryBookDAO.update(EntryBookModify); - // Création BDD - topiaContext.commitTransaction(); - // Fermeture BDD - topiaContext.closeContext(); - result = ServiceHelper.RESPOND_SUCCESS; - } catch (TopiaException e) { - log.error(e); - } + + // creation du EntryBook + entryBookDAO.update(entryBook); + + // commit + transaction.commitTransaction(); } - return result; - }*/ + catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } + } /** * Permet d'effacer un EntryBook dans la base de données. @@ -360,7 +305,7 @@ * @return * @throws LimaException */ - public void removeEntryBook(EntryBook EntryBook) throws LimaException { + public void removeEntryBook(EntryBook entryBook) throws LimaException { /*String result = ServiceHelper.RESPOND_ERROR; EntryBook EntryBookDelete = searchEntryBookWithTopiaId(topiaId); // Si le EntryBook n'existe pas @@ -408,7 +353,7 @@ } } return result;*/ - + TopiaContext topiaTransaction = null; try { // basic check done, make check in database @@ -416,58 +361,23 @@ topiaTransaction = rootContext.beginTransaction(); // Vérifie si une transaction n'appartient pas à ce EntryBook. - TransactionDAO transactionDAO = LimaCallaoDAOHelper.getTransactionDAO(topiaTransaction); - Transaction transaction = transactionDAO.findByEntryBook(EntryBook); + Transaction transaction = transactionService.findByEntryBook(topiaTransaction, entryBook); if (transaction != null) { throw new LimaBusinessException("Can't delete EntryBook with transactions"); } // test si un EntryBook de ce nom existe deja EntryBookDAO EntryBookDAO = LimaCallaoDAOHelper.getEntryBookDAO(topiaTransaction); - EntryBookDAO.delete(EntryBook); + EntryBookDAO.delete(entryBook); // commit topiaTransaction.commitTransaction(); } catch (TopiaException ex) { - if (topiaTransaction != null) { - try { - topiaTransaction.rollbackTransaction(); - } catch (TopiaException e) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - } - } - if (log.isErrorEnabled()) { - log.error("Error during create account", ex); - } - throw new LimaException("Can't create EntryBook", ex); + doCatch(topiaTransaction, ex, log); } finally { - if (topiaTransaction != null) { - try { - topiaTransaction.closeContext(); - } catch (TopiaException ex) { - if (log.isErrorEnabled()) { - log.error("Error during rollback context", ex); - } - throw new LimaException("Can't create EntryBook", ex); - } - } + doFinally(topiaTransaction, log); } } - - /* - * Permet d'effacer un EntryBook dans la base de données. - * ATTENTION : si un EntryBook est associé avec des transactions, il est alors - * impossible de supprimer celui-ci. - * @param EntryBookDTO EntryBook au format DTO à supprimer - * @return - * - public String removeEntryBook(EntryBookDTO EntryBookDTO) { - String result = removeEntryBook(EntryBookDTO.getId()); - return result; - }*/ - } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryServiceImpl.java 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryServiceImpl.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,20 +1,20 @@ -/* - * *##% Callao EntryServiceImpl - * Copyright (C) 2009 CodeLutin +/* *##% Lima Business + * Copyright (C) 2008 - 2010 CodeLutin * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* */ package org.chorem.lima.business.ejb; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FilesServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FilesServiceImpl.java 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FilesServiceImpl.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,49 +1,32 @@ -/* - * *##% Callao FilesServiceImpl - * Copyright (C) 2009 CodeLutin +/* *##% Lima Business + * Copyright (C) 2008 - 2010 CodeLutin * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* */ package org.chorem.lima.business.ejb; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Date; -import java.util.Iterator; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.dto.AccountDTO; -import org.chorem.lima.business.dto.EntryDTO; -import org.chorem.lima.business.dto.JournalDTO; -import org.chorem.lima.business.dto.PeriodDTO; -import org.chorem.lima.business.dto.TimeSpanDTO; -import org.chorem.lima.business.dto.TransactionDTO; import org.chorem.lima.business.utils.DateUtil; -import org.chorem.lima.business.utils.ServiceHelper; -import org.jdom.Attribute; +import org.chorem.lima.entity.Account; import org.jdom.Document; import org.jdom.Element; -import org.jdom.JDOMException; -import org.jdom.input.SAXBuilder; -import org.jdom.output.Format; -import org.jdom.output.XMLOutputter; -import org.jdom.xpath.XPath; -import org.nuiton.topia.TopiaContext; /** * Cette classe permet d'importer et exporter des données comptables. Ces données @@ -318,7 +301,7 @@ * @param listAccountDTO * @param accounts */ - protected void accountXML(List<AccountDTO> listAccountDTO, Element accounts) { + protected void accountXML(List<Account> listAccount, Element accounts) { /*for (AccountDTO accountDTO : listAccountDTO) { Element account = new Element("account"); accounts.addContent(account); 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 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialPeriodServiceImpl.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,30 +1,39 @@ -/* - * *##% Callao TimeSpanServiceImpl - * Copyright (C) 2009 CodeLutin +/* *##% Lima Business + * Copyright (C) 2008 - 2010 CodeLutin * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* */ package org.chorem.lima.business.ejb; +import java.util.List; + +import javax.ejb.Stateless; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.FinancialPeriodService; import org.chorem.lima.business.LimaConfig; +import org.chorem.lima.business.LimaException; 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.TopiaContextFactory; +import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; /** @@ -33,7 +42,8 @@ * * @author Rémi Chapelet */ -public class FinancialPeriodServiceImpl { //implements TimeSpanService { +@Stateless +public class FinancialPeriodServiceImpl extends AbstractLimaService implements FinancialPeriodService { /** log */ private static final Log log = LogFactory.getLog(FinancialPeriodServiceImpl.class); @@ -61,8 +71,9 @@ * @param locked est à vrai si la période doit être bloquée. * @return */ - public void createTimeSpan(FinancialPeriod timeSpan /*Date beginTimeSpan, Date endTimeSpan, - Period period, boolean locked*/) { + @Override + public void createFinancialPeriod(FinancialPeriod financialPeriod /*Date beginTimeSpan, Date endTimeSpan, + Period period, boolean locked*/) throws LimaException { /* // timeSpan correspond à une période mensuelle. // La fonction va donc prendre seulement pour date de référence la @@ -101,8 +112,94 @@ log.error(e); return ServiceHelper.RESPOND_ERROR; }*/ + + TopiaContext transaction = null; + try { + // basic check done, make check in database + // TODO move it into JTA + transaction = rootContext.beginTransaction(); + + createFinancialPeriod(transaction, financialPeriod); + + // commit + transaction.commitTransaction(); + } + catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } } + /** + * Create a financial period with an opened transaction. + * + * @param transaction opened transaction + * @param financialPeriod financial period + * @throws TopiaException + */ + protected void createFinancialPeriod(TopiaContext transaction, FinancialPeriod financialPeriod) throws TopiaException { + + FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper.getFinancialPeriodDAO(transaction); + financialPeriodDAO.create(financialPeriod); + + } + + @Override + public List<FinancialPeriod> getAllFinancialPeriods() throws LimaException { + + List<FinancialPeriod> result = null; + + TopiaContext transaction = null; + try { + // basic check done, make check in database + // TODO move it into JTA + transaction = rootContext.beginTransaction(); + + FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper.getFinancialPeriodDAO(transaction); + result = financialPeriodDAO.findAll(); + + // commit + transaction.commitTransaction(); + } + catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } + + return result; + } + + @Override + public List<FinancialPeriod> getNonLockedFinancialPeriods() throws LimaException { + + List<FinancialPeriod> result = null; + + TopiaContext transaction = null; + try { + // basic check done, make check in database + // TODO move it into JTA + transaction = rootContext.beginTransaction(); + + FinancialPeriodDAO financialPeriodDAO = LimaCallaoDAOHelper.getFinancialPeriodDAO(transaction); + result = financialPeriodDAO.findAllByLocked(false); + + // commit + transaction.commitTransaction(); + } + catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } + + return result; + } + /* * Permet de trouver un timespan directement avec une date. La date peut * être quelconque. Exemple : d = 17 sept 2000, renvoie la période du 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 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FiscalPeriodServiceImpl.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,30 +1,43 @@ -/* - * *##% Callao PeriodServiceImpl - * Copyright (C) 2009 CodeLutin +/* *##% Lima Business + * Copyright (C) 2008 - 2010 CodeLutin * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* */ package org.chorem.lima.business.ejb; +import static org.nuiton.i18n.I18n._; + +import java.util.List; + +import javax.ejb.Stateless; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.FiscalPeriodService; +import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaConfig; +import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.FinancialPeriod; +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.TopiaContextFactory; +import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; /** @@ -34,13 +47,14 @@ * * @author Rémi Chapelet */ -public class FiscalPeriodServiceImpl { //implements PeriodService { +@Stateless +public class FiscalPeriodServiceImpl extends AbstractLimaService implements FiscalPeriodService { private static final Log log = LogFactory.getLog(FiscalPeriodServiceImpl.class); private TopiaContext rootContext; - private FinancialPeriodServiceImpl timeSpanServiceImpl = new FinancialPeriodServiceImpl(); + private FinancialPeriodServiceImpl financialPeriodService = new FinancialPeriodServiceImpl(); public FiscalPeriodServiceImpl() { LimaConfig config = LimaConfig.getInstance(); @@ -54,16 +68,23 @@ } /** - * Permet de créer une période principale. Elle a une durée de un an, - * composées de 12 périodes mensuelles. Elle correspond à l'exercice - * comptable. Pour créer une nouvelle période, la précédente doit être - * obligatoirement clôturée. + * Permet de créer un exercice. + * + * Elle a une durée de un an, composées de 12 périodes mensuelles. + * Elle peut aussi être plus courte ou plus longue si l'entreprise + * se constitu ou entre en liquidation ou que l'entreprise decide + * de changer + * + * Elle correspond à l'exercice comptable. + * Pour créer une nouvelle période, la précédente doit être obligatoirement clôturée. + * * @param beginTimeSpan date début de période * @param endTimeSpan date fin de période * @param lock Vrai si la période est bloquée * @return */ - public void createPeriod(FinancialPeriod period /*Date beginTimeSpan, Date endTimeSpan, boolean lock*/) { + @Override + public void createFiscalPeriod(FiscalPeriod fiscalPeriod /*Date beginTimeSpan, Date endTimeSpan, boolean lock*/) throws LimaException { /*// Par défaut lock est à false lock = false; String result = ServiceHelper.RESPOND_ERROR; @@ -127,8 +148,72 @@ log.error(e); } return result; */ + + // un exercice ne peut pas faire plus de 24 mois dans tous les cas + + // un exercice doit faire au moins une période + if ( fiscalPeriod.getFinancialPeriod() == null || + fiscalPeriod.getFinancialPeriod().isEmpty()) { + throw new LimaBusinessException(_("A fiscal period must have at least one financial period !")); + } + + // un exercice doit être collé au precedent + + // un exercice ne peut être crée que si l'anti precedent est fermé + // on peut creer un exercice si le precedent n'est pas fermé + + TopiaContext transaction = null; + try { + // basic check done, make check in database + // TODO move it into JTA + transaction = rootContext.beginTransaction(); + + // TODO maybe put this in antoher place + for (FinancialPeriod financialPeriod : fiscalPeriod.getFinancialPeriod()) { + financialPeriodService.createFinancialPeriod(transaction, financialPeriod); + } + + FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + fiscalPeriodDAO.create(fiscalPeriod); + + // commit + transaction.commitTransaction(); + } + catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } + } + public List<FiscalPeriod> getAllFiscalPeriods() throws LimaException { + + List<FiscalPeriod> result = null; + + TopiaContext transaction = null; + try { + // basic check done, make check in database + // TODO move it into JTA + transaction = rootContext.beginTransaction(); + + FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); + result = fiscalPeriodDAO.findAll(); + + // commit + transaction.commitTransaction(); + } + catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } + + return result; + } + /* * Permet de créer une période à partir d'une période DTO. * @param periodDTO période à créer au format DTO. Added: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportExportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportExportServiceImpl.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportExportServiceImpl.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -0,0 +1,120 @@ +/* *##% Lima Business + * 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 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* + */ + +package org.chorem.lima.business.ejb; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +import javax.ejb.Stateless; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.ImportExportService; +import org.chorem.lima.business.LimaException; + +/** + * XML and CSV import export service. + * + * TODO maybe split this impl into different XML and CSV impl. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +@Stateless +public class ImportExportServiceImpl implements ImportExportService { + + private static final Log log = LogFactory.getLog(ImportExportServiceImpl.class); + + /* + * @see org.chorem.lima.business.ImportExportService#exportAsXML() + */ + @Override + public byte[] exportAsXML() throws LimaException { + + byte[] data = null; + ByteArrayOutputStream byteArrayOutputStream = null; + try { + byteArrayOutputStream = new ByteArrayOutputStream(); + exportAsXML(byteArrayOutputStream); + } + catch (IOException eee) { + if (log.isErrorEnabled()) { + log.error("Can't export as xml", eee); + } + throw new LimaException("Can't export as xml", eee); + } + finally { + IOUtils.closeQuietly(byteArrayOutputStream); + } + + if (byteArrayOutputStream != null) { + data = byteArrayOutputStream.toByteArray(); + } + + return data; + } + + /** + * Do real output into a simple {@link OutputStream}. + * + * @param output + * @throws IOException + */ + protected void exportAsXML(OutputStream output) throws IOException { + + } + + /* + * @see org.chorem.lima.business.ImportExportService#importAsXML(byte[]) + */ + @Override + public void importAsXML(byte[] data) { + + } + + /* + * @see org.chorem.lima.business.ImportExportService#exportAsCSV() + */ + @Override + public byte[] exportAsCSV() throws LimaException { + return null; + } + + /* + * @see org.chorem.lima.business.ImportExportService#importAsCSV(byte[]) + */ + @Override + public void importAsCSV(byte[] data) throws LimaException { + + } + + /* + * @see org.chorem.lima.business.ImportExportService#importAsEBPCSV(byte[]) + */ + @Override + public void importAsEbpCSV(byte[] data) throws LimaException { + + } +} Property changes on: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportExportServiceImpl.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/RecordServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/RecordServiceImpl.java 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/RecordServiceImpl.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,20 +1,20 @@ -/* - * *##% Callao LogServiceImpl - * Copyright (C) 2009 CodeLutin +/* *##% Lima Business + * Copyright (C) 2008 - 2010 CodeLutin * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* */ package org.chorem.lima.business.ejb; @@ -22,12 +22,15 @@ import java.util.ArrayList; import java.util.List; +import javax.ejb.Stateless; + import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.RecordService; +import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.chorem.lima.entity.Record; import org.chorem.lima.entity.RecordDAO; -import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaException; @@ -40,7 +43,8 @@ * * @author Rémi Chapelet */ -public class RecordServiceImpl { //implements LogService { +@Stateless +public class RecordServiceImpl implements RecordService { /** log */ private static final org.apache.commons.logging.Log log = LogFactory 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 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,61 +1,57 @@ +/* *##% Lima Business + * 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 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* + */ + package org.chorem.lima.business.ejb; -import org.nuiton.topia.TopiaContext; +import javax.ejb.Stateless; -public class ReportServiceImpl { //implements ReportService { +import org.chorem.lima.business.ReportService; - //@Override +@Stateless +public class ReportServiceImpl implements ReportService { + public String generateAccount(String number, String amount, String label) { - // TODO Auto-generated method stub return null; } - //@Override + public String generateBalanceTrial(String period) { + return null; + } + public String generateBalanceSheet(String period) { - // TODO Auto-generated method stub return null; } - //@Override public String generateCashFlowStatement(String period) { - // TODO Auto-generated method stub return null; } - //@Override public String generateGeneralLedger(String period) { - // TODO Auto-generated method stub return null; } - //@Override public String generateIncomeStatement(String period) { - // TODO Auto-generated method stub return null; } - //@Override public String generateJournal(String type, String period) { - // TODO Auto-generated method stub return null; } - //@Override - public String[] getMethods() { - // TODO Auto-generated method stub - return null; - } - - //@Override - public void destroy() { - // TODO Auto-generated method stub - - } - - //@Override - public void init(TopiaContext arg0) { - // TODO Auto-generated method stub - - } - } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TransactionServiceImpl.java 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/TransactionServiceImpl.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,47 +1,39 @@ -/* - * *##% Callao TransactionServiceImpl - * Copyright (C) 2009 CodeLutin +/* *##% Lima Business + * Copyright (C) 2008 - 2010 CodeLutin * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* */ package org.chorem.lima.business.ejb; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import javax.ejb.Stateless; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.LimaConfig; -import org.chorem.lima.business.dto.EntryDTO; -import org.chorem.lima.business.dto.LogDTO; -import org.chorem.lima.business.dto.TransactionDTO; -import org.chorem.lima.business.utils.ServiceHelper; -import org.chorem.lima.entity.Account; -import org.chorem.lima.entity.Entry; -import org.chorem.lima.entity.EntryDAO; +import org.chorem.lima.business.TransactionService; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.LimaCallaoDAOHelper; -import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.Transaction; import org.chorem.lima.entity.TransactionDAO; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.framework.TopiaQuery; /** * Cette classe permet la création d'une transaction comptable dans l'application. @@ -52,18 +44,18 @@ * * @author Rémi Chapelet */ -public class TransactionServiceImpl { +@Stateless +public class TransactionServiceImpl implements TransactionService { - private static final Log log = LogFactory - .getLog(TransactionServiceImpl.class); + private static final Log log = LogFactory.getLog(TransactionServiceImpl.class); private TopiaContext rootContext; - private RecordServiceImpl logServiceImpl = new RecordServiceImpl(); + //private RecordServiceImpl logServiceImpl = new RecordServiceImpl(); - private EntryServiceImpl entryServiceImpl = new EntryServiceImpl(); + //private EntryServiceImpl entryServiceImpl = new EntryServiceImpl(); - private FinancialPeriodServiceImpl timeSpanServiceImpl = new FinancialPeriodServiceImpl(); + //private FinancialPeriodServiceImpl timeSpanServiceImpl = new FinancialPeriodServiceImpl(); public TransactionServiceImpl() { LimaConfig config = LimaConfig.getInstance(); @@ -742,5 +734,26 @@ boolean isTransactionBalanced = debit == credit; return isTransactionBalanced; }*/ + + /** + * Permet de retrouver la premiere transaction associée au journal. + * + * @param topiaTransaction context à utiliser + * @param entryBook journal + * @throws TopiaException + */ + protected Transaction findByEntryBook(TopiaContext topiaTransaction, EntryBook entryBook) throws TopiaException { + TransactionDAO transactionDAO = LimaCallaoDAOHelper.getTransactionDAO(topiaTransaction); + + TopiaQuery query = transactionDAO.createQuery(); + // entryBook is not visible, but column "entryBook" + // exist in transaction table + query.add("entryBook", entryBook); + + Transaction result = transactionDAO.findByQuery(query); + + return result; + } + } \ No newline at end of file Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/UserServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/UserServiceImpl.java 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/UserServiceImpl.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,20 +1,20 @@ -/* - * *##% Callao - * Copyright (C) 2010 CodeLutin +/* *##% Lima Business + * Copyright (C) 2008 - 2010 CodeLutin * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%* */ package org.chorem.lima.business.ejb; @@ -23,12 +23,9 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; -import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.chorem.lima.entity.User; -import org.chorem.lima.entity.UserDAO; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; /** Copied: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/CSVExport.java (from rev 2802, trunk/lima-swing/src/main/java/org/chorem/lima/export/CSVExport.java) =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/CSVExport.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/CSVExport.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -0,0 +1,199 @@ +/** + * *##% Lima-Callao CVSImport + * Copyright (C) 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ + +package org.chorem.lima.business.ejb.csv; + +import au.com.bytecode.opencsv.CSVWriter; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.LimaContext; +import org.chorem.lima.dto.AccountDTO; +import org.chorem.lima.dto.EntryDTO; +import org.chorem.lima.dto.JournalDTO; +import org.chorem.lima.dto.PeriodDTO; +import org.chorem.lima.dto.TransactionDTO; +import org.chorem.lima.util.Util; +import org.chorem.lima.service.util.ServiceHelper; + +import java.io.File; +import java.io.IOException; +import java.io.FileWriter; +import java.util.*; + +/** + * Cette méthode permet d'exporter toutes les données de Lima dans un fichier + * au format csv. + * + * @author Rémi Chapelet + */ +public class CSVExport { + + private static final Log log = LogFactory.getLog(CSVExport.class); + private CSVWriter csvWriter; + + /** + * Création de l'instance CSVWriter avec le fichier en paramètre. + * @param path + */ + public CSVExport(String path) { + try { + File f = new File(path); + // Le fichier a pour séparateur ';' + csvWriter = new CSVWriter(new FileWriter(f), ';'); + } catch (IOException e) { + log.debug(e); + } + } + + /** + * Permet de retourner l'instance csv du fichier. + * @return + * @throws java.io.IOException + */ + public CSVWriter getCSVWriter() throws IOException { + return csvWriter; + } + + /** + * Méthode principale qui appelle chaque méthode pour chaque type de données + * à enregistrer (journaux, comptes, etc). + * @return + */ + public String exportDatas() { + String result = ServiceHelper.RESPOND_SUCCESS; + /** + * Export des données + */ + String[] nextLine = new String[1]; + // Début période + // Sélection la période utilisée actuellement + PeriodDTO period = LimaContext.getContext().getDataManager() + .getCurrentPeriod(); + // Si la période courante est une période mensuelle, on récupère la période annuelle + if (period.getParent() != null) { + period = period.getParent(); + } + nextLine[0] = Util.DateToString(period.getBegin(), "dd/MM/yyyy"); + csvWriter.writeNext(nextLine); + // Fin périod + nextLine[0] = Util.DateToString(period.getEnd(), "dd/MM/yyyy"); + csvWriter.writeNext(nextLine); + // Export données + exportAccount(); + exportJournal(); + exportTransaction(); + // Ecriture dans le fichier les données dans le tampon + try { + csvWriter.flush(); + csvWriter.close(); + } catch (IOException e) { + log.debug(e); + result = ServiceHelper.RESPOND_ERROR; + } + return result; + } + + /** + * Export des comptes + */ + public void exportAccount() { + String[] nextLine = new String[5]; + // Récupère tous les comptes + List<AccountDTO> listAccount = ServiceHelper + .getAllFlatAccount(LimaContext.getContext().getDataManager() + .getAccountModel().getData()); + // Pour tous les comptes + for (AccountDTO account : listAccount) { + nextLine[0] = "C"; + nextLine[1] = account.getIdNumber(); + nextLine[2] = account.getDescription(); + nextLine[3] = account.getType(); + nextLine[4] = account.getIdSeq(); + // Ajoute la ligne au fichier + csvWriter.writeNext(nextLine); + } + } + + /** + * Export des journaux + */ + public void exportJournal() { + String[] nextLine = new String[5]; + // Récupère tous les journaux + List<JournalDTO> listJournal = LimaContext.getContext() + .getDataManager().getJournalModel().getData(); + // Pour tous les journaux + for (JournalDTO journal : listJournal) { + nextLine[0] = "J"; + nextLine[1] = journal.getIdName(); + nextLine[2] = journal.getPrefix(); + nextLine[3] = journal.getDescription(); + nextLine[4] = journal.getIdSeq(); + // Ajoute la ligne au fichier + csvWriter.writeNext(nextLine); + } + } + + /** + * Export des transactions et entrées comptables + */ + public void exportTransaction() { + String[] nextLineTrans = new String[8]; + String[] nextLineEntry = new String[7]; + // Récupère toutes les transactions + List<TransactionDTO> listTransaction = LimaContext.getContext() + .getDataManager().getTransactionModel().getData(); + // Pour toutes les transactions + for (TransactionDTO transaction : listTransaction) { + nextLineTrans[0] = "T"; + nextLineTrans[1] = transaction.getVoucherRef(); + nextLineTrans[2] = transaction.getDescription().trim(); + nextLineTrans[3] = transaction.getIdName().trim(); + nextLineTrans[4] = Util.DateToString(transaction.getEntryDate(), + "dd/MM/yyyy"); + nextLineTrans[5] = transaction.getJournal().getPrefix(); + nextLineTrans[6] = Util.DateToString(transaction.getPeriod() + .getBegin(), "dd/MM/yyyy"); + nextLineTrans[7] = transaction.getIdSeq(); + // Ajoute la ligne au fichier + csvWriter.writeNext(nextLineTrans); + /** + * Ajout des entrées + */ + List<EntryDTO> listEntry = transaction.getEntries(); + // Pour chaque entrée de la transaction + for (EntryDTO entry : listEntry) { + nextLineEntry[0] = "E"; + nextLineEntry[1] = entry.getAccount().getIdNumber(); + nextLineEntry[2] = entry.getDescription(); + nextLineEntry[3] = entry.getAmount(); + nextLineEntry[4] = entry.getLettrage(); + if (entry.getDebit()) { + nextLineEntry[5] = "D"; + } else { + nextLineEntry[5] = "C"; + } + nextLineEntry[6] = entry.getIdSeq(); + // Ajoute la ligne au fichier + csvWriter.writeNext(nextLineEntry); + } + } + } + +} \ No newline at end of file Copied: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/CSVImport.java (from rev 2802, trunk/lima-swing/src/main/java/org/chorem/lima/imports/CSVImport.java) =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/CSVImport.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/CSVImport.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -0,0 +1,361 @@ +/** + * *##% Lima-Callao CVSImport + * Copyright (C) 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ + +package org.chorem.lima.business.ejb.csv; + +import au.com.bytecode.opencsv.CSVReader; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.LimaContext; +import org.chorem.lima.dto.AccountDTO; +import org.chorem.lima.dto.EntryDTO; +import org.chorem.lima.dto.JournalDTO; +import org.chorem.lima.dto.PeriodDTO; +import org.chorem.lima.dto.TransactionDTO; +import org.chorem.lima.dto.util.DTOHelper; +import org.chorem.lima.util.Util; +import org.chorem.lima.service.*; +import org.chorem.lima.service.util.ServiceHelper; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.*; + + +/** + * Cette classe permet d'importer un fichier de données au format csv créé + * par l'application Lima + * + * @author Rémi Chapelet + */ +public class CSVImport { + + private static final Log log = LogFactory.getLog(CSVImport.class); + private CSVReader csvReader; + private LinkedList<TransactionDTO> listTransactions= new LinkedList<TransactionDTO>(); + private TransactionDTO transactionLast = null; + + protected final PeriodService periodService; + protected final EntryService entryService; + protected final TransactionService transactionService; + + /** + * Le constructeur avec en paramètre l'adresse du fichier de données. + * @param path + */ + public CSVImport(String path) { + try { + File f = new File(path); + // Le fichier a pour séparateur ';' + csvReader = new CSVReader(new FileReader(f), ';'); + } catch (FileNotFoundException e) { + log.debug(e); + } + // Déclaration des services + periodService = ServiceFactory.getServiceFactory().getPeriodService(); + entryService = ServiceFactory.getServiceFactory().getEntryService(); + transactionService = ServiceFactory.getServiceFactory().getTransactionService(); + } + + /** + * permet de retourner l'instance csv du fichier. + * @return + * @throws java.io.FileNotFoundException + */ + public CSVReader getCSVReader() throws FileNotFoundException { + return csvReader; + } + + + /** + * Fonction principale permettant de lire un fichier au format csv. + * Chaque ligne possède un identifiant : + * C : compte + * J : journal + * E : entrée comptable + * T : transaction + * @return + */ + public String importDatas () + { + // Message de retour de la méthode : success ou error + String result = ServiceHelper.RESPOND_ERROR; + try { + /** + * Déclaration des variables + */ + // Tableau de chaines correspondant à chaque ligne du fichier qui sera lue. + String[] nextLine; + // Création account Master + // Lima possède un compte principal, numéroté '0'. + AccountDTO accountRac = new AccountDTO("0", "0", "Plan comptable", null, new LinkedList<AccountDTO>(), null); + + /** + * Lecture des premières lignes du fichier + */ + nextLine = csvReader.readNext(); // Date début période + Date beginPeriod = Util.stringToDate(nextLine[0], "dd/MM/yyyy"); + nextLine = csvReader.readNext(); // Date fin période + Date endPeriod = Util.stringToDate(nextLine[0], "dd/MM/yyyy"); + + /** + * Création de la période : l'exercice comptable avec ses 12 mois. + */ + // Création de l'exercice + Date begin = Util.InitDateFirstDayMonth(beginPeriod); + Date end = Util.InitDateEndDayMonth(endPeriod); + PeriodDTO period = new PeriodDTO("",Integer.toString(begin.getYear()+1900),begin,end,null,null, + ServiceHelper.findStatusByType(LimaContext.getContext().getDataManager().getStatus(), "PE_OPEN")); + // Création des 12 mois + List<PeriodDTO> listPeriodChild = new LinkedList<PeriodDTO>(); + // Pour chaque mois + for (int i=0 ; i<12 ; i++) + { + Date beginTimeSpan = Util.InitDateFirstDayMonth(new Date(begin.getYear(),begin.getMonth()+i,begin.getDate())); + Date endTimeSpan = Util.InitDateEndDayMonth(new Date(begin.getYear(),begin.getMonth()+i,begin.getDate())); + // Création période + PeriodDTO periodChild = new PeriodDTO("",ServiceHelper.dateToMonth(beginTimeSpan)+" "+(beginTimeSpan.getYear()+1900),beginTimeSpan,endTimeSpan,null,period, + ServiceHelper.findStatusByType(LimaContext.getContext().getDataManager().getStatus(), "PE_OPEN")); + listPeriodChild.add(periodChild); + } + // On ajoute les 12 mois à l'exercice + period.setChildren(listPeriodChild); + // On ajoute la liste des exercices (ici un seul exercice) à Lima + LinkedList<PeriodDTO> listPeriod= new LinkedList<PeriodDTO>(); + listPeriod.add(period); + // Ajoute la période dans le service des Périodes + periodService.createPeriod(period, LimaContext.getContext().getDataManager().getStatus()); + // Réinitialise les périodes + LimaContext.getContext().getDataManager().resetPeriodes(listPeriod); + + /** + * Lecture de chaque ligne + * Ajout des comptes, journaux et entrées comptables + */ + boolean endReadAccount = false; // Vrai lorsque tous les comptes sont chargés + // Pour chaque ligne + while ((nextLine = csvReader.readNext()) != null) { + // Lecture de la 1ière cellule + String indice = nextLine[0]; + /** + * Compte + */ + if ( indice.equals("C") ) + { + log.debug("Ajout compte "+nextLine[1]); + result = importAccount(nextLine,accountRac); + } + /** + * Journal + */ + if ( indice.equals("J") ) + { + // Tous les comtes ont été chargés, on relance pour les charger + if (!endReadAccount) + { + LimaContext.getContext().getDataManager().resetAccountModel(accountRac); + endReadAccount = true; + } + log.debug("Ajout journal "+nextLine[1]); + result = importJournal(nextLine); + } + /** + * Transaction + */ + if ( indice.equals("T") ) + { + log.debug("Ajout transaction "+nextLine[1]); + result = importTransactions(nextLine); + } + /** + * Entry + */ + if ( indice.equals("E") ) + { + log.debug("Ajout entry "+nextLine[1]); + result = importEntries(nextLine); + } + } + }catch ( Exception e) { + log.debug(e); + } + + // Reset transactions + LimaContext.getContext().getDataManager().resetTransactionModel(listTransactions); + return result; + } + + /** + * Permet de découper une ligne du fichier csv pour charger les comptes. + * Pour chaque compte, il vérifie si il appartient à un compte père. + * Exemple : compte 164 - 'Emprunts auprès des établissements' + * On recherche dans tous les comptes, le compte numéro 16, si il existe, + * alors 16 sera le compte père, sinon on remonte d'un rang (recherche sur + * le compte 1, etc.). + * @param line + * @return + */ + public String importAccount(String[] line,AccountDTO accountRac) + { + // Numéro de compte (exemple : 512) + String numberAccount = line[1]; + // Label du compte (exemple : Banque) + String label = line[2]; + // Actif/Passif/Produit/Charge + String type = line[3]; + /** + * Détection des comptes pères + */ + AccountDTO accountMaster = null; + // si compte principal correspondant à une classe (1-2-3-4-5-6-7-8) + if ( numberAccount.length() == 1 ) // c-a-d taille du numéro de compte à 1 + { + accountMaster = accountRac; + } else { + // Sinon on recherche un compte père + int i=1; + // Liste des comptes existants + List<AccountDTO> listAccount = ServiceHelper.getAllFlatAccount(accountRac); + // Tant que le compte père n'a pas été trouvé + while (i<numberAccount.length() && accountMaster == null) + { + accountMaster = ServiceHelper.findAccountById(listAccount,numberAccount.substring(0, numberAccount.length()-i)); + i++; + } + } + // Création du compte + AccountDTO account = new AccountDTO("",numberAccount,label,type,new LinkedList<AccountDTO>(),accountMaster); + String result = LimaContext.getContext().getDataManager().getAccountModel().addAccount(account); + return result; + } + + /** + * Import des transactions. Il recherche le journal correspondant dans la + * base. C'est pourquoi le journal doit être chargé avant la lecture des + * transactions. Il fait de même avec les périodes. Lorsqu'il a chargé + * toutes les données de la transaction, il ajoute celle-ci dans lima. + * Il associe également la transaction lue dans la variable transactionLast. + * ainsi après avoir lu la transaction, il va lire les entrées de la transaction. + * Lors de l'ajout d'une entrée, il est nécessaire de connaître la transaction + * à laquelle elle est rattachée. + * @param line + * @return + */ + public String importTransactions (String[] line) + { + String result=""; + // document de référence + String voucherRef = line[1]; + // description + String description = line[2]; + // nom de la transaction + String name = line[3]; + // date de transaction + Date date = Util.stringToDate(line[4], "dd/MM/yyyy"); + // journal + String journal = line[5]; + JournalDTO journalDTO = ServiceHelper.findJournalById( + LimaContext.getContext().getDataManager().getJournalModel().getData(), + journal); + if (journalDTO == null) { + log.warn("Import : Journal " + journal + " does not exist."); + } + // periode + Date period = Util.stringToDate(line[6], "dd/MM/yyyy"); + // Recherche la période correspondante + PeriodDTO periodDTO = ServiceHelper.findPeriodByDate( + ServiceHelper.getAllFlatPeriod(LimaContext.getContext().getDataManager().getPeriodes()), period); + /** + * Création de la transaction + */ + TransactionDTO transaction = new TransactionDTO(null, name, date, + voucherRef, description, journalDTO, new LinkedList<EntryDTO>(), periodDTO, + ServiceHelper.findStatusByType(LimaContext.getContext().getDataManager().getStatus(), "TR_WIP")); + transactionLast = transaction; + // Ajoute la transaction dans le service + //result = Main.getContext().getDataManager().getTransactionModel().addTransaction(transaction); + result = transactionService.addTransaction(transaction, LimaContext.getContext().getDataManager().getStatus()); + // Ajoute la transaction dans la liste des transactions + listTransactions.add(transaction); + return result; + } + + /** + * Permet de rechercher toutes les entrées comptables dans le fichier. + * @param line + * @param nameTransacPrev + * @return + */ + public String importEntries (String[] line) + { + String result; + /** + * Account + */ + String accountId = line[1]; + AccountDTO accountDTO = ServiceHelper.findAccountById( + ServiceHelper.getAllFlatAccount(LimaContext.getContext().getDataManager().getAccountModel().getData()), + accountId); + if (accountDTO == null) { + log.warn("Import : Account " + accountId + " does not exist."); + } + /** + * Description + */ + String description = line[2]; + /** + * Amount + */ + String amount = line[3].trim(); + /** + * Lettrage + */ + String lettrage = line[4]; + /** + * Debit - Credit + */ + boolean debit = line[5].equals("D"); + // Création de l'entrée comptable + EntryDTO entry = new EntryDTO("",description,DTOHelper.format(amount),debit,lettrage,accountDTO,transactionLast,null); + // Ajout de l'entrée comptable dans le service + result = entryService.addEntry(LimaContext.getContext().getDataManager().getStatus(), entry); + // Ajout l'entrée à la transaction + transactionLast.addChild(entry); + return result; + } + + /** + * Cette méthode permet d'importer les journaux. + * @param line + * @return + */ + public String importJournal (String[] line) + { + String name = line[1]; + String prefixe = line[2]; + String description = line[3]; + // Création du journal + JournalDTO journalDTO = new JournalDTO("",name,description,prefixe); + // Ajout du journal dans le modèle de Lima + String result = LimaContext.getContext().getDataManager().getJournalModel().addJournal(journalDTO); + return result; + } + +} Copied: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/CSVImportEBP.java (from rev 2802, trunk/lima-swing/src/main/java/org/chorem/lima/imports/CSVImportEBP.java) =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/CSVImportEBP.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/csv/CSVImportEBP.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -0,0 +1,362 @@ +/** + * *##% Lima-Callao CVSImportEBP + * Copyright (C) 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ + +package org.chorem.lima.business.ejb.csv; + +import au.com.bytecode.opencsv.CSVReader; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.LimaContext; +import org.chorem.lima.balance.Category; +import org.chorem.lima.dto.AccountDTO; +import org.chorem.lima.dto.EntryDTO; +import org.chorem.lima.dto.JournalDTO; +import org.chorem.lima.dto.PeriodDTO; +import org.chorem.lima.dto.TransactionDTO; +import org.chorem.lima.dto.util.DTOHelper; +import org.chorem.lima.util.Util; +import org.chorem.lima.service.*; +import org.chorem.lima.service.util.ServiceHelper; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.*; + + +/** + * Cette classe permet d'importer un fichier de données au format csv. + * Il respecte la norme de l'application EBP. Toutefois, il est possible de modifier + * facilement et adapter le code pour un autre type de formatage de données. + * + * @author Rémi Chapelet + */ +public class CSVImportEBP { + + private static final Log log = LogFactory.getLog(CSVImportEBP.class); + private CSVReader csvReader; + private LinkedList<TransactionDTO> listTransactions= new LinkedList<TransactionDTO>(); + private TransactionDTO transactionWithSamePrefix = null; + + protected final PeriodService periodService; + protected final EntryService entryService; + protected final TransactionService transactionService; + + /** + * Le constructeur avec en paramètre l'adresse du fichier de données. + * @param path + */ + public CSVImportEBP(String path) { + //URL url = CSVImportEBP.class.getResource(path); + try { + File f = new File(path); + // Le fichier a pour séparateur ';' + csvReader = new CSVReader(new FileReader(f), ';'); + } catch (FileNotFoundException e) { + log.debug(e); + } + // Déclaration des services + periodService = ServiceFactory.getServiceFactory().getPeriodService(); + entryService = ServiceFactory.getServiceFactory().getEntryService(); + transactionService = ServiceFactory.getServiceFactory().getTransactionService(); + } + + /** + * permet de retourner l'instance csv du fichier. + * @return + * @throws java.io.FileNotFoundException + */ + public CSVReader getCSVReader() throws FileNotFoundException { + return csvReader; + } + + + /** + * Fonction principale permettant de lire un fichier au format csv. + * Ce dernier permet de lire les fichiers de l'application EBP. + * Chaque ligne possède un identifiant : + * C : compte + * J : journal + * E : entrée comptable + * Attention : EBP ne possède pas dans son fichier de sauvegarde de + * transactions, mais seulement des entrées. Or Lima utilise les transactions, + * reliées aux entrées. Il est donc important de créer une transaction pour + * chaque groupe d'entrées comptables. + * @return + */ + public String importDatas () + { + // Message de retour de la méthode : success ou error + String result = ServiceHelper.RESPOND_ERROR; + try { + /** + * Déclaration des variables + */ + // Tableau de chaines correspondant à chaque ligne du fichier qui sera lue. + String[] nextLine; + // Création account Master + // Lima possède un compte principal, numéroté '0'. + AccountDTO accountRac = new AccountDTO("0", "0", "Plan comptable", null, new LinkedList<AccountDTO>(), null); + + /** + * Lecture des 6 premières lignes du fichier + */ + csvReader.readNext(); // Nom application + csvReader.readNext(); // Codage des caractères + csvReader.readNext(); // Code 01 + csvReader.readNext(); // Nom de l'entreprise + nextLine = csvReader.readNext(); // Date début période + Date beginPeriod = Util.stringToDate(nextLine[0], "ddMMyyyy"); + nextLine = csvReader.readNext(); // Date fin période + Date endPeriod = Util.stringToDate(nextLine[0], "ddMMyyyy"); + + /** + * Création de la période : l'exercice comptable avec ses 12 mois. + */ + // Création de l'exercice + Date begin = Util.InitDateFirstDayMonth(beginPeriod); + Date end = Util.InitDateEndDayMonth(endPeriod); + PeriodDTO period = new PeriodDTO("",Integer.toString(begin.getYear()+1900),begin,end,null,null, + ServiceHelper.findStatusByType(LimaContext.getContext().getDataManager().getStatus(), "PE_OPEN")); + // Création des 12 mois + List<PeriodDTO> listPeriodChild = new LinkedList<PeriodDTO>(); + // Pour chaque mois + for (int i=0 ; i<12 ; i++) + { + Date beginTimeSpan = Util.InitDateFirstDayMonth(new Date(begin.getYear(),begin.getMonth()+i,begin.getDate())); + Date endTimeSpan = Util.InitDateEndDayMonth(new Date(begin.getYear(),begin.getMonth()+i,begin.getDate())); + // Création période + PeriodDTO periodChild = new PeriodDTO("",ServiceHelper.dateToMonth(beginTimeSpan)+" "+(beginTimeSpan.getYear()+1900),beginTimeSpan,endTimeSpan,null,period, + ServiceHelper.findStatusByType(LimaContext.getContext().getDataManager().getStatus(), "PE_OPEN")); + listPeriodChild.add(periodChild); + } + // On ajoute les 12 mois à l'exercice + period.setChildren(listPeriodChild); + // On ajoute la liste des exercices (ici un seul exercice) à Lima + LinkedList<PeriodDTO> listPeriod= new LinkedList<PeriodDTO>(); + listPeriod.add(period); + // Ajoute la période dans le service des Périodes + periodService.createPeriod(period, LimaContext.getContext().getDataManager().getStatus()); + // Réinitialise les périodes + LimaContext.getContext().getDataManager().resetPeriodes(listPeriod); + + /** + * Lecture de chaque ligne + * Ajout des comptes, journaux et entrées comptables + */ + boolean endReadAccount = false; // Vrai lorsque tous les comptes sont chargés + String nameTransacPrev = ""; // Valeur du nom de la transaction précédente + // Pour chaque ligne + while ((nextLine = csvReader.readNext()) != null) { + // Lecture de la 1ière cellule + String indice = nextLine[0]; + /** + * Compte + */ + if ( indice.equals("C") ) + { + log.debug("Ajout compte "+nextLine[1]); + result = importAccount(nextLine,accountRac); + } + /** + * Journal + */ + if ( indice.equals("J") ) + { + // Tous les comtes ont été chargés, on relance pour les charger + if (!endReadAccount) + { + LimaContext.getContext().getDataManager().resetAccountModel(accountRac); + endReadAccount = true; + } + log.debug("Ajout journal "+nextLine[1]); + result = importJournal(nextLine); + } + /** + * Entry + */ + if ( indice.equals("E") ) + { + log.debug("Ajout entry "+nextLine[1]); + result = importEntries(nextLine,nameTransacPrev); + nameTransacPrev = nextLine[4]; + } + } + }catch ( Exception e) { + log.debug(e); + } + + // Reset transactions + LimaContext.getContext().getDataManager().resetTransactionModel(listTransactions); + return result; + } + + /** + * Permet de découper une ligne du fichier csv pour charger les comptes. + * Pour chaque compte, il vérifie si il appartient à un compte père. + * Exemple : compte 164 - 'Emprunts auprès des établissements' + * On recherche dans tous les comptes, le compte numéro 16, si il existe, + * alors 16 sera le compte père, sinon on remonte d'un rang (recherche sur + * le compte 1, etc.). + * @param line + * @return + */ + public String importAccount(String[] line,AccountDTO accountRac) + { + // Numéro de compte (exemple : 512) + String numberAccount = line[1]; + // Label du compte (exemple : Banque) + String label = line[2]; + /** + * Détection des comptes pères + */ + AccountDTO accountMaster = null; + // si compte principal correspondant à une classe (1-2-3-4-5-6-7-8) + if ( numberAccount.length() == 1 ) // c-a-d taille du numéro de compte à 1 + { + accountMaster = accountRac; + } else { + // Sinon on recherche un compte père + int i=1; + // Liste des comptes existants + List<AccountDTO> listAccount = ServiceHelper.getAllFlatAccount(accountRac); + // Tant que le compte père n'a pas été trouvé + while (i<numberAccount.length() && accountMaster == null) + { + accountMaster = ServiceHelper.findAccountById(listAccount,numberAccount.substring(0, numberAccount.length()-i)); + i++; + } + } + // Recherche de la catégorie + String category = Category.findCategory(numberAccount); + // Création du compte + AccountDTO account = new AccountDTO("",numberAccount,label,category,new LinkedList<AccountDTO>(),accountMaster); + String result = LimaContext.getContext().getDataManager().getAccountModel().addAccount(account); + return result; + } + + /** + * Permet de rechercher toutes les transactions/entrées comptables dans le fichier. + * Néanmoins, le fichier ne possède pas de transactions, il est donc important + * d'identifier ces dernières. Il exsite dans le fichier des 'groupes" d'entrées + * comptables. Elles se suivent, et possèdent un numéro de document en + * commun (appelé dans l'algo ci-dessous 'numTransac'). + * On vérifie à chaque fois si l'entrée appartient au groupe lu précédent. Si + * oui, alors on l'a rattache à la même transaction 'transactionWithSamePrefix' ; + * si non, on créé dans ce cas une nouvelle transaction 'transactionWithSamePrefix'. + * Chaque transaction est ajoutée dans une liste, pour les ajouter au modèle + * dans Lima. + * @param line + * @param nameTransacPrev + * @return + */ + public String importEntries (String[] line, String nameTransacPrev) + { + String result; + /** + * Account + */ + String accountId = line[1]; + AccountDTO accountDTO = ServiceHelper.findAccountById( + ServiceHelper.getAllFlatAccount(LimaContext.getContext().getDataManager().getAccountModel().getData()), + accountId); + if (accountDTO == null) { + log.warn("Import : Account " + accountId + " does not exist."); + } + /** + * Date + */ + Date dateTransac = Util.stringToDate(line[2], "ddMMyyyy"); + /** + * Journal + */ + String journalId = line[3]; + JournalDTO journalDTO = ServiceHelper.findJournalById( + LimaContext.getContext().getDataManager().getJournalModel().getData(), + journalId); + if (journalDTO == null) { + log.warn("Import : Journal " + journalId + " does not exist."); + } + /** + * Transaction + */ + String numTransac = line[4]; + String descTransac = line[6]; + /** + * Debit - Credit + */ + boolean debit = line[7].equals("D"); + /** + * Amount + */ + String amount = line[8].trim(); + /** + * Lettrage + */ + String lettrage = line[10]; + /** + * Création transaction + */ + if ( !nameTransacPrev.equals(numTransac) ) + { + // Recherche la période correspondante + PeriodDTO period = ServiceHelper.findPeriodByDate( + ServiceHelper.getAllFlatPeriod(LimaContext.getContext().getDataManager().getPeriodes()), dateTransac); + // Création de la transaction + TransactionDTO transaction = new TransactionDTO(null, "", dateTransac, + numTransac, descTransac, journalDTO, new LinkedList<EntryDTO>(), period, + ServiceHelper.findStatusByType(LimaContext.getContext().getDataManager().getStatus(), "TR_WIP")); + transactionWithSamePrefix = transaction; + // Ajoute la transaction dans le service + result = transactionService.addTransaction(transaction, LimaContext.getContext().getDataManager().getStatus()); + // Ajoute la transaction dans la liste des transactions + listTransactions.add(transaction); + } + // Création de l'entrée comptable + EntryDTO entry = new EntryDTO("","",DTOHelper.format(amount),debit,lettrage,accountDTO,transactionWithSamePrefix,null); + // Ajout de l'entrée comptable dans le service + result = entryService.addEntry(LimaContext.getContext().getDataManager().getStatus(), entry); + // Ajout l'entrée à la transaction + transactionWithSamePrefix.addChild(entry); + return result; + } + + /** + * Cette méthode permet d'importer les journaux. + * Attention : dans le fichier de base de EBP, il ne possède pas de journaux, + * or il est important d'apporter des journaux dans le logiciel, sinon + * les transactions ne sont pas rattachés. + * Il suffit d'ajouter les journaux souhaités après les comptes avec la lettre + * J dans le fichier. + * Exemple : J;Journal des achats;AC + * @param line + * @return + */ + public String importJournal (String[] line) + { + String description = line[1]; + String prefixe = line[2]; + // Création du journal + JournalDTO journalDTO = new JournalDTO("",description,description,prefixe); + // Ajout du journal dans le modèle de Lima + String result = LimaContext.getContext().getDataManager().getJournalModel().addJournal(journalDTO); + return result; + } + +} Copied: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/xml/XMLExport.java (from rev 2802, trunk/lima-swing/src/main/java/org/chorem/lima/export/XMLExport.java) =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/xml/XMLExport.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/xml/XMLExport.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -0,0 +1,501 @@ +/** + * *##% Lima-Callao XMLExport + * Copyright (C) 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ + +package org.chorem.lima.business.ejb.xml; + +import static org.nuiton.i18n.I18n._; + +import java.io.FileOutputStream; +import java.util.Date; +import java.util.List; + +import javax.swing.SwingUtilities; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.LimaContext; +import org.chorem.lima.dto.AccountDTO; +import org.chorem.lima.dto.EntryDTO; +import org.chorem.lima.dto.JournalDTO; +import org.chorem.lima.dto.PeriodDTO; +import org.chorem.lima.dto.TransactionDTO; +import org.chorem.lima.ui.MainViewImpl; +import org.chorem.lima.ui.ProgressBarImpl; +import org.chorem.lima.util.ServiceHelper; +import org.chorem.lima.util.Util; +import org.jdom.Attribute; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.output.Format; +import org.jdom.output.XMLOutputter; + +/** + * Permet d'exporter les données dans un document xml. + * + * @author Rémi Chapelet + */ +public class XMLExport { + + /** + * log + */ + protected static final Log log = LogFactory.getLog(XMLExport.class); + + private static Element racine = new Element("Callao"); + + private static org.jdom.Document document = new Document(racine); + + private ProgressBarImpl progressBar; + + private String file; + + // Déclaration variables pour chargement des données + + private static List<PeriodDTO> listPeriodDTO = LimaContext.getContext().getDataManager().getPeriodes(); + private static List<JournalDTO> listJournalDTO = LimaContext.getContext().getDataManager().getJournalModel().getData(); + private static AccountDTO AccountMasterDTO = LimaContext.getContext().getDataManager().getAccountModel().getData(); + private static List<TransactionDTO> listTransactionDTO = LimaContext.getContext().getDataManager().getTransactionModel().getData(); + + /** + * Cete méthode permet d'exporter des données de Callao vers un fichier au + * format xml. + * + * @param pathFile + * @return + */ + public String exportFile(String pathFile) { + if (log.isDebugEnabled()) { + log.debug("Save file XML : "); + } + // Charge le nom du fichier + file = pathFile; + // Mise en place de la barre de progression + MainViewImpl context = LimaContext.get().getMainUI(); + progressBar = new ProgressBarImpl(context, context); + Runnable runnable = new Runnable() { + public void run() { + progressBar.setVisible(true); + } + }; + SwingUtilities.invokeLater(runnable); + new Thread() { + @Override + public void run() { + // MainViewImpl context = LimaContext.get().getMainUI(); + // progressBar = new ProgressBarImpl(context, context); + progressBar.setTitle(_("lima.progressBar.export.title")); + progressBar.getProgressBar().setString( + "0% : " + _("lima.progressBar.export.etape1")); + progressBar.getProgressBar().setValue(0); + + /** + * Partie Informations + */ + progressBar.getProgressBar().setString( + "10% : " + _("lima.progressBar.export.etape2")); + progressBar.getProgressBar().setValue(10); + Element info = new Element("informations"); + racine.addContent(info); + Attribute date = new Attribute("date", new Date().toString()); + info.setAttribute(date); + Attribute user = new Attribute("user", "Name user"); + info.setAttribute(user); + Attribute company = new Attribute("company", "Name company"); + info.setAttribute(company); + /** + * Partie Save + */ + // Création Element save + Element save = new Element("save"); + racine.addContent(save); + /** + * Period + */ + progressBar.getProgressBar().setString( + "25% : " + _("lima.progressBar.export.etape3")); + progressBar.getProgressBar().setValue(25); + Element periods = new Element("periods"); + Element timeSpans = new Element("timespans"); + save.addContent(periods); + save.addContent(timeSpans); + exportPeriod(periods, timeSpans); + /** + * Journal + */ + progressBar.getProgressBar().setString( + "35% : " + _("lima.progressBar.export.etape4")); + progressBar.getProgressBar().setValue(35); + Element journals = new Element("journals"); + save.addContent(journals); + exportJournal(journals); + /** + * Account + */ + progressBar.getProgressBar().setString( + "50% : " + _("lima.progressBar.export.etape5")); + progressBar.getProgressBar().setValue(50); + Element accounts = new Element("accounts"); + save.addContent(accounts); + // Appel une fonction récursive pour parcourir l'arborescence des comptes + accountXML(AccountMasterDTO.getChildren(), accounts); + /** + * Transaction + */ + progressBar.getProgressBar().setString( + "60% : " + _("lima.progressBar.export.etape6")); + progressBar.getProgressBar().setValue(60); + Element transactions = new Element("transactions"); + save.addContent(transactions); + Element entries = new Element("entries"); + save.addContent(entries); + exportTransaction(transactions, entries, progressBar); + /** + * Enregistre le fichier + */ + progressBar.getProgressBar().setString( + "100% : " + _("lima.progressBar.export.etape7")); + progressBar.getProgressBar().setValue(100); + enregistre(file); + progressBar.dispose(); + + } + }.start(); + + return ServiceHelper.RESPOND_SUCCESS; + } + + public String exportAccount(String pathFile) { + if (log.isDebugEnabled()) { + log.debug("Save Account XML : "); + } + // Charge le nom du fichier + file = pathFile; + + MainViewImpl context = LimaContext.get().getMainUI(); + progressBar = new ProgressBarImpl(context, context); + Runnable runnable = new Runnable() { + public void run() { + progressBar.setVisible(true); + } + }; + SwingUtilities.invokeLater(runnable); + + // Mise en place de la barre de progression + new Thread() { + @Override + public void run() { + // MainViewImpl context = LimaContext.get().getMainUI(); + // progressBar = new ProgressBarImpl(context, context); + progressBar.setTitle(_("lima.progressBar.export.title")); + progressBar.getProgressBar().setString( + "0% : " + _("lima.progressBar.export.etape1")); + progressBar.getProgressBar().setValue(0); + /** + * Partie Informations + */ + progressBar.getProgressBar().setString( + "10% : " + _("lima.progressBar.export.etape2")); + progressBar.getProgressBar().setValue(10); + Element info = new Element("informations"); + racine.addContent(info); + Attribute date = new Attribute("date", new Date().toString()); + info.setAttribute(date); + Attribute user = new Attribute("user", "Name user"); + info.setAttribute(user); + Attribute company = new Attribute("company", "Name company"); + info.setAttribute(company); + /** + * Partie Save + */ + // Création Element save + Element save = new Element("save"); + racine.addContent(save); + /** + * Account + */ + progressBar.getProgressBar().setString( + "50% : " + _("lima.progressBar.export.etape5")); + progressBar.getProgressBar().setValue(50); + Element accounts = new Element("accounts"); + save.addContent(accounts); + // Appel une fonction récursive pour parcourir l'arborescence des comptes + accountXML(AccountMasterDTO.getChildren(), accounts); + /** + * Enregistre le fichier + */ + progressBar.getProgressBar().setString( + "100% : " + _("lima.progressBar.export.etape7")); + progressBar.getProgressBar().setValue(100); + enregistre(file); + progressBar.dispose(); + } + }.start(); + return ServiceHelper.RESPOND_SUCCESS; + } + + /** + * @param periods + * @param timeSpans + */ + public void exportPeriod(Element periods, Element timeSpans) { + // Pour chaque période + for (PeriodDTO periodDTO : listPeriodDTO) { + // Création élément périod + Element period = new Element("period"); + periods.addContent(period); + // Identifiant période + Attribute id = new Attribute("id", periodDTO.getIdSeq()); + period.setAttribute(id); + // BeginPeriod + // Découpage date + String dateTab[] = Util.arrayDate(periodDTO.getBegin()); + Attribute beginYear = new Attribute("beginYear", dateTab[0]); + period.setAttribute(beginYear); + Attribute beginMonth = new Attribute("beginMonth", dateTab[1]); + period.setAttribute(beginMonth); + Attribute beginDay = new Attribute("beginDay", dateTab[2]); + period.setAttribute(beginDay); + // EndPeriod + dateTab = Util.arrayDate(periodDTO.getEnd()); + Attribute endYear = new Attribute("endYear", dateTab[0]); + period.setAttribute(endYear); + Attribute endMonth = new Attribute("endMonth", dateTab[1]); + period.setAttribute(endMonth); + Attribute endDay = new Attribute("endDay", dateTab[2]); + period.setAttribute(endDay); + // Locked Period + if (periodDTO.getStatus().getIdName() + .equals(ServiceHelper.PE_CLOSE)) { + Attribute locked = new Attribute("locked", "true"); + period.setAttribute(locked); + } else { + Attribute locked = new Attribute("locked", "false"); + period.setAttribute(locked); + } + /** + * TimeSpan + */ + // Recherche des timeSpans de la période + List<PeriodDTO> listTimeSpanDTO = periodDTO.getChildren(); + // Pour chaque timeSpan + for (PeriodDTO timeSpanDTO : listTimeSpanDTO) { + Element timeSpan = new Element("timespan"); + timeSpans.addContent(timeSpan); + // Identifiant timeSpan + Attribute idTimeSpan = new Attribute("id", timeSpanDTO + .getIdSeq()); + timeSpan.setAttribute(idTimeSpan); + Attribute idPeriod = new Attribute("idPeriod", periodDTO + .getIdSeq()); + timeSpan.setAttribute(idPeriod); + // Begin TimeSpan + // Découpage date + dateTab = Util.arrayDate(timeSpanDTO.getBegin()); + Attribute beginYearTimeSpan = new Attribute("beginYear", + dateTab[0]); + timeSpan.setAttribute(beginYearTimeSpan); + Attribute beginMonthTimeSpan = new Attribute("beginMonth", + dateTab[1]); + timeSpan.setAttribute(beginMonthTimeSpan); + Attribute beginDayTimeSpan = new Attribute("beginDay", + dateTab[2]); + timeSpan.setAttribute(beginDayTimeSpan); + // End TimeSpan + dateTab = Util.arrayDate(timeSpanDTO.getEnd()); + Attribute endYearTimeSpan = new Attribute("endYear", dateTab[0]); + timeSpan.setAttribute(endYearTimeSpan); + Attribute endMonthTimeSpan = new Attribute("endMonth", + dateTab[1]); + timeSpan.setAttribute(endMonthTimeSpan); + Attribute endDayTimeSpan = new Attribute("endDay", dateTab[2]); + timeSpan.setAttribute(endDayTimeSpan); + // Lock timeSpan + if (timeSpanDTO.getStatus().getIdName().equals( + ServiceHelper.PE_CLOSE)) { + Attribute locked = new Attribute("locked", "true"); + timeSpan.setAttribute(locked); + } else { + Attribute locked = new Attribute("locked", "false"); + timeSpan.setAttribute(locked); + } + } + } + } + + /** + * @param journals + */ + public void exportJournal(Element journals) { + for (JournalDTO journalDTO : listJournalDTO) { + Element journal = new Element("journal"); + journals.addContent(journal); + // Identification du journal + Attribute idJournal = new Attribute("id", journalDTO.getIdSeq()); + journal.setAttribute(idJournal); + // Label + Attribute label = new Attribute("label", journalDTO.getIdName()); + journal.setAttribute(label); + // Prefix + Attribute prefix = new Attribute("prefix", journalDTO.getPrefix()); + journal.setAttribute(prefix); + // Description + Attribute description = new Attribute("description", journalDTO + .getDescription()); + journal.setAttribute(description); + } + } + + /** + * Converti la liste des comptes pour être ajouté au document xml. + * + * @param listAccountDTO + * @param accounts + */ + public void accountXML(List<AccountDTO> listAccountDTO, Element accounts) { + for (AccountDTO accountDTO : listAccountDTO) { + Element account = new Element("account"); + accounts.addContent(account); + // Identification du account + Attribute idAccount = new Attribute("id", accountDTO.getIdSeq()); + account.setAttribute(idAccount); + // Label + Attribute label = new Attribute("label", accountDTO + .getDescription()); + account.setAttribute(label); + // Type + Attribute type = new Attribute("type", accountDTO.getType()); + account.setAttribute(type); + // AccountNumber + Attribute accountNumber = new Attribute("accountNumber", accountDTO + .getIdNumber()); + account.setAttribute(accountNumber); + // MasterAccountNumber + Attribute masterAccountNumber = new Attribute("masterAccount", + accountDTO.getParent().getIdNumber()); + account.setAttribute(masterAccountNumber); + // Ajoute les comptes enfants à la liste + accountXML(accountDTO.getChildren(), accounts); + } + } + + public void exportTransaction(Element transactions, Element entries, + ProgressBarImpl progressBar) { + // Nombre de transaction + float nbTransactions = listTransactionDTO.size(); + float incremente = 20 / nbTransactions; + float value = 80; + // Pour chaque transaction + for (TransactionDTO transactionDTO : listTransactionDTO) { + Element transaction = new Element("transaction"); + transactions.addContent(transaction); + // Identification de la transaction + Attribute idTransaction = new Attribute("id", transactionDTO + .getIdSeq()); + transaction.setAttribute(idTransaction); + // EntryDate + String dateTab[] = Util.arrayDate(transactionDTO.getEntryDate()); + Attribute entryDateYear = new Attribute("entryDateYear", dateTab[0]); + transaction.setAttribute(entryDateYear); + Attribute entryDateMonth = new Attribute("entryDateMonth", + dateTab[1]); + transaction.setAttribute(entryDateMonth); + Attribute entryDateDay = new Attribute("entryDateDay", dateTab[2]); + transaction.setAttribute(entryDateDay); + // VoucherRef + Attribute voucherRef = new Attribute("voucherRef", transactionDTO + .getVoucherRef()); + transaction.setAttribute(voucherRef); + // Description + Attribute description = new Attribute("description", transactionDTO + .getDescription()); + transaction.setAttribute(description); + // Id journal + Attribute IdJournal = new Attribute("idJournal", transactionDTO + .getJournal().getIdSeq()); + transaction.setAttribute(IdJournal); + // Id timeSpan + Attribute IdTimeSpan = new Attribute("idTimeSpan", transactionDTO + .getPeriod().getIdSeq()); + transaction.setAttribute(IdTimeSpan); + /** + * Entry + */ + List<EntryDTO> listEntryDTO = transactionDTO.getEntries(); + for (EntryDTO entryDTO : listEntryDTO) { + Element entry = new Element("entry"); + entries.addContent(entry); + // Identification du entry + Attribute idEntry = new Attribute("id", entryDTO.getIdSeq()); + entry.setAttribute(idEntry); + // Description + Attribute descriptionEntry = new Attribute("description", + entryDTO.getDescription()); + entry.setAttribute(descriptionEntry); + // Amount + Attribute amount = new Attribute("amount", entryDTO.getAmount()); + entry.setAttribute(amount); + // Lettering + Attribute lettering = new Attribute("lettering", entryDTO + .getLettrage()); + entry.setAttribute(lettering); + // Detail + Attribute detail = new Attribute("detail", entryDTO + .getDescription()); + entry.setAttribute(detail); + // Debit / crédit + if (entryDTO.getDebit()) { + Attribute debit = new Attribute("debit", "true"); + entry.setAttribute(debit); + } else { + Attribute debit = new Attribute("debit", "false"); + entry.setAttribute(debit); + } + // Transaction + Attribute idrefTransaction = new Attribute("idTransaction", + transactionDTO.getIdSeq()); + entry.setAttribute(idrefTransaction); + // Account + Attribute idAccount = new Attribute("idAccount", entryDTO + .getAccount().getIdSeq()); + entry.setAttribute(idAccount); + } + // Mise à jour de la barre de chargement + value = value + incremente; + progressBar.getProgressBar().setValue((int) value); + progressBar.getProgressBar().setString( + value + "% : " + _("lima.progressBar.export.etape6")); + + } + } + + /** + * Permet d'enregistrer le fichier xml. + * + * @param fichier + */ + static void enregistre(String fichier) { + try { + XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat()); + sortie.output(document, new FileOutputStream(fichier)); + } catch (java.io.IOException e) { + log.error(e); + } + } + +} Copied: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/xml/XMLImport.java (from rev 2802, trunk/lima-swing/src/main/java/org/chorem/lima/imports/XMLImport.java) =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/xml/XMLImport.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/xml/XMLImport.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -0,0 +1,234 @@ +/** + * *##% Lima-Callao XMLImport + * Copyright (C) 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ + +package org.chorem.lima.business.ejb.xml; + + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.LimaContext; +import org.jdom.*; +import org.chorem.lima.dto.AccountDTO; +import org.chorem.lima.dto.JournalDTO; +import org.chorem.lima.service.util.ServiceHelper; + +import org.jdom.input.SAXBuilder; +import java.io.*; +import org.jdom.xpath.XPath; +import java.util.List; +import java.util.LinkedList; +import java.util.Iterator; + +import org.chorem.lima.table.model.JournalTableModel; +import org.chorem.lima.ui.accounting.model.AccountTreeTableModel; + + +/** + * Permet de charger les données à partir d'un document xml. + * Il est possibble de charger les journaux, les comptes. + * + * @author Rémi Chapelet + */ +public class XMLImport { + + + /** log */ + protected static final Log log = LogFactory.getLog(XMLImport.class); + + static Element racine = new Element("Callao"); + + static org.jdom.Document document = new Document(racine); + + protected JournalTableModel journalServ; + protected AccountTreeTableModel accountServ; + + /** + * Import Journal + * @param file + * @return + */ + public String importJournal(String file) + { + if (log.isDebugEnabled()) { + log.debug("Load Journal XML "); + } + // Variables + journalServ = LimaContext.getContext().getDataManager().getJournalModel(); + String result = ServiceHelper.RESPOND_ERROR; + boolean existError = false; + // Chargement du fichier + loadFile(file); + try { + // Recherche de la racine + racine = document.getRootElement(); + // Chargement + XPath requeteXpath = XPath.newInstance("//journal"); + List results = requeteXpath.selectNodes(racine); + Iterator iter = results.iterator(); + // Pour tous les journaux + while (iter.hasNext()){ + Element noeudCourant = (Element) iter.next(); + // Recherche attributs + String label = noeudCourant.getAttribute("label").getValue(); + log.debug("Label "+label); + String prefix = noeudCourant.getAttribute("prefix").getValue(); + String description = noeudCourant.getAttribute("description").getValue(); + // Création du journal + JournalDTO journal = new JournalDTO("0", label, description, prefix); + // Ajout journal + result = journalServ.addJournal(journal); + // Control erreur + if ( result.equals(ServiceHelper.RESPOND_ERROR) ) + { + existError = true; + } + } + } catch (JDOMException e) { + log.error("Erreur JDOM " + e.getMessage() ); + e.printStackTrace(); + } + // Détection des erreurs + if ( !existError ) + { + result = ServiceHelper.RESPOND_SUCCESS; + } + return result; + } + + public String importAccount(InputStream stream) { + if (log.isDebugEnabled()) { + log.debug("Load Account XML "); + } + // Chargement du fichier + loadFile(stream, InputStream.class); + return importAccount(); + } + + /** + * Import Account + * @param file + * @return + */ + public String importAccount(String file) + { + if (log.isDebugEnabled()) { + log.debug("Load Account XML "); + } + loadFile(file); + return importAccount(); + } + + private String importAccount() { + // Variables + accountServ = LimaContext.getContext().getDataManager().getAccountModel(); + String result = ServiceHelper.RESPOND_ERROR; + boolean existError = false; + try { + // Recherche de la racine + racine = document.getRootElement(); + // Chargement + XPath requeteXpath = XPath.newInstance("//account"); + List results = requeteXpath.selectNodes(racine); + Iterator iter = results.iterator(); + // Création du compte principal pour Lima + AccountDTO accountMaster = new AccountDTO("0", "0", "Plan comptable", null, new LinkedList<AccountDTO>(), null); + // Pour tous les accounts + while (iter.hasNext()){ + Element noeudCourant = (Element) iter.next(); + // Recherche attributs + String label = noeudCourant.getAttribute("label").getValue(); + String accountNumber = noeudCourant.getAttribute("accountNumber").getValue(); + String masterAccount = noeudCourant.getAttribute("masterAccount").getValue(); + String type = noeudCourant.getAttribute("type").getValue(); + // Création bdd + // Si il n'a pas de compte père, alors on rattache le compte au compte '0' master. + if ( masterAccount.equals("0") ) + { + // Creation account sur le compte 0 + AccountDTO account = new AccountDTO("0", accountNumber, label, type, new LinkedList<AccountDTO>(), accountMaster); + // Ajout dans le service + result = accountServ.addAccount(account); + // Ajout dans Lima + account.getParent().addChild(account); + } else { + // Creation account sur le compte père donné dans le fichier + AccountDTO account = new AccountDTO("0",accountNumber,label,type, + new LinkedList<AccountDTO>(), + ServiceHelper.findAccountById(ServiceHelper.getAllFlatAccount(accountMaster),masterAccount)); + // Ajout dans le service + result = accountServ.addAccount(account); + // Ajout dans Lima + account.getParent().addChild(account); + } + // Control erreur + if ( result.equals(ServiceHelper.RESPOND_ERROR) ) + { + existError = true; + } + } + } catch (JDOMException e) { + log.error("Erreur JDOM " + e.getMessage() ); + e.printStackTrace(); + } + // Détection des erreurs + if ( !existError ) + { + result = ServiceHelper.RESPOND_SUCCESS; + } + // Reset pour le chargement des comptes + LimaContext.getContext().getDataManager().resetAccountModel(); + return result; + } + + private void loadFile(String file) { + loadFile(file, String.class); + } + /** + * + * @param file + */ + private <T> void loadFile(T file, Class<T> fileClass) + { + /** + * Chargement du fichier et construction du Dom + */ + if (log.isDebugEnabled()) { + log.debug("Load file : "+file); + } + try { + /* On crée une instance de SAXBuilder */ + SAXBuilder sxb = new SAXBuilder(); + if (fileClass.equals(String.class)) { + document = sxb.build((String)file); + } else if (fileClass.equals(InputStream.class)){ + document = sxb.build((InputStream)file); + } + } catch (IOException e) { + log.error("Erreur lors de la lecture du fichier " + + e.getMessage() ); + e.printStackTrace(); + } catch (JDOMException e){ + log.error("Erreur lors de la construction du fichier JDOM " + + e.getMessage() ); + e.printStackTrace(); + } + } + + +} \ No newline at end of file Deleted: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/ServiceHelper.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/utils/ServiceHelper.java 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/ServiceHelper.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,87 +0,0 @@ -/** - * *##% Callao ServiceHelper - * Copyright (C) 2009 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* - */ - -package org.chorem.lima.business.utils; - -/** - * Définition des messages acceptés par Callao - * @author Rémi Chapelet - * - * @deprecated since 0.4.0, with no replacement (Exception) - */ -public interface ServiceHelper { - - /** - * Réponses utilisées par la couche métier Callao - */ - public static final String RESPOND_SUCCESS = "success"; - public static final String RESPOND_ERROR = "error"; - - /** - * Account Error - */ - public static final String ACCOUNT_DOUBLE = "account_double"; - public static final String ACCOUNT_NOT_MASTER = "account_not_master"; - public static final String ACCOUNT_NOT_EXIST = "account_not_exist"; - public static final String ACCOUNT_WITH_ENTRIES = "account_with_entries"; - - /** - * Entries Error - */ - public static final String ENTRY_NOT_EXIST = "entry_not_exist"; - - /** - * Journal - */ - public static final String JOURNAL_DOUBLE = "journal_double"; - public static final String JOURNAL_NOT_EXIST = "journal_not_exist"; - public static final String JOURNAL_WITH_TRANSACTIONS = "journal_with_transactions"; - - /** - * Period - */ - public static final String PERIOD_CREATE_TIMESPANS = "period_create_timespan"; - public static final String PERIOD_TIMESPAN_NOT_BLOCK = "period_timespan_not_block"; - public static final String PERIOD_TIMESPAN_BLOCK = "period_timespan_block"; - public static final String PERIOD_ALL_TIMESPAN = "period_all_timespan"; - public static final String PERIOD_NOT_EXIST = "period_not_exist"; - - /** - * TimeSpan - */ - public static final String TIMESPAN_PREC_NOT_BLOCK = "timespan_prec_not_block"; - public static final String TIMESPAN_NEXT_NOT_BLOCK = "timespan_next_not_block"; - - /** - * Transaction - */ - public static final String TRANSACTION_NOT_JOURNAL = "transaction_not_journal"; - public static final String TRANSACTION_NOT_TIMESPAN = "transaction_not_timespan"; - public static final String TRANSACTION_TIMESPAN_BLOCKED = "transaction_timespan_blocked"; - public static final String TRANSACTION_NOT_EXIST = "transaction_not_exist"; - public static final String TRANSACTION_NOT_BALANCED = "transaction_not_balanced"; - - /** - * Définition des types de logs possibles - */ - public static final String LOG_ADD = "add"; - public static final String LOG_MODIFY = "modify"; - public static final String LOG_REMOVE = "remove"; - -} \ No newline at end of file Modified: trunk/lima-business/src/main/resources/lima.properties =================================================================== --- trunk/lima-business/src/main/resources/lima.properties 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/resources/lima.properties 2010-04-02 16:55:19 UTC (rev 2824) @@ -6,12 +6,4 @@ hibernate.connection.username=sa hibernate.connection.password= hibernate.connection.driver_class=org.h2.Driver -hibernate.connection.url=jdbc:h2:file:~/.lima/limadb - -# Permet de preciser les classes a utiliser -#topia.persistence.classes=org.chorem.callao.entity.AccountImpl, \ -#org.chorem.callao.entity.ClientImpl, \ -#org.chorem.callao.entity.EntryImpl, org.chorem.callao.entity.PeriodImpl, \ -#org.chorem.callao.entity.JournalImpl, org.chorem.callao.entity.ProjectImpl, \ -#org.chorem.callao.entity.TimeSpanImpl, org.chorem.callao.entity.TransactionImpl, \ -#org.chorem.callao.entity.UsersImpl, org.chorem.callao.entity.LogImpl +hibernate.connection.url=jdbc:h2:file:~/.lima/limadb \ No newline at end of file Deleted: trunk/lima-business/src/main/resources/log4j.properties =================================================================== --- trunk/lima-business/src/main/resources/log4j.properties 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/main/resources/log4j.properties 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,11 +0,0 @@ -# Global logging configuration -log4j.rootLogger=WARN, stdout - -# Console output... -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n - -# package level -log4j.logger.org.chorem.lima=DEBUG -log4j.logger.org.nuiton.util=DEBUG \ No newline at end of file Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -4,9 +4,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.dto.AccountDTO; import org.chorem.lima.business.ejb.AccountServiceImpl; -import org.chorem.lima.business.utils.ServiceHelper; import org.chorem.lima.entity.Account; import org.junit.AfterClass; import org.junit.Assert; Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,15 +1,9 @@ package org.chorem.lima.business; -import static org.junit.Assert.assertTrue; -import java.util.Date; - import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.ejb.FinancialPeriodServiceImpl; -import org.chorem.lima.business.utils.ServiceHelper; -import org.chorem.lima.entity.FinancialPeriod; import org.junit.AfterClass; -import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -1,19 +1,9 @@ package org.chorem.lima.business; -import static org.junit.Assert.assertTrue; - -import java.util.Date; -import java.util.List; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.dto.PeriodDTO; -import org.chorem.lima.business.dto.TimeSpanDTO; import org.chorem.lima.business.ejb.FiscalPeriodServiceImpl; -import org.chorem.lima.business.utils.ServiceHelper; -import org.chorem.lima.entity.FiscalPeriod; import org.junit.AfterClass; -import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/RecordServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/RecordServiceImplTest.java 2010-04-02 16:53:54 UTC (rev 2823) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/RecordServiceImplTest.java 2010-04-02 16:55:19 UTC (rev 2824) @@ -5,7 +5,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.dto.LogDTO; import org.chorem.lima.business.ejb.RecordServiceImpl; import org.chorem.lima.entity.Record; import org.junit.AfterClass; Copied: trunk/lima-business/src/test/resources/log4j.properties (from rev 2807, trunk/lima-business/src/main/resources/log4j.properties) =================================================================== --- trunk/lima-business/src/test/resources/log4j.properties (rev 0) +++ trunk/lima-business/src/test/resources/log4j.properties 2010-04-02 16:55:19 UTC (rev 2824) @@ -0,0 +1,11 @@ +# Global logging configuration +log4j.rootLogger=WARN, stdout + +# Console output... +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n + +# package level +log4j.logger.org.chorem.lima=DEBUG +log4j.logger.org.nuiton.util=DEBUG \ No newline at end of file