r3385 - in trunk: lima-business/src/main/java/org/chorem/lima/business/ejb lima-business/src/test/java/org/chorem/lima/business lima-business-api/src/main/java/org/chorem/lima/business/api
Author: echatellier Date: 2012-04-24 16:19:58 +0200 (Tue, 24 Apr 2012) New Revision: 3385 Url: http://chorem.org/repositories/revision/lima/3385 Log: Fix import entry book from ebp test Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2012-04-24 13:14:37 UTC (rev 3384) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportServiceImpl.java 2012-04-24 14:19:58 UTC (rev 3385) @@ -50,6 +50,7 @@ import javax.ejb.Remote; import javax.ejb.Stateless; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -117,6 +118,7 @@ import org.chorem.lima.entity.VatStatement; import org.chorem.lima.entity.VatStatementDAO; import org.chorem.lima.entity.VatStatementImpl; +import org.hsqldb.lib.ArrayUtil; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; @@ -372,6 +374,52 @@ return result.toString(); } + @Override + public String importEntryBookFromEbp(String datas) throws LimaException { + long before = System.currentTimeMillis(); + + StringBuilder result = new StringBuilder(); + TopiaContext topiaContext = beginTransaction(rootContext); + + try { + CSVReader csvReader = new CSVReader(new StringReader(datas)); + + // check if file have a good header + String[] headers = csvReader.readNext(); + if (!headers[0].equals("Code") || !headers[2].equals("Libelle")) { + throw new LimaBusinessException( + _("lima-business.import.noaccount")); + } + + // create entry book for each line + int count = 0; + String[] line = csvReader.readNext(); + while (line != null) { + EntryBook entryBook = new EntryBookImpl(); + entryBook.setCode(line[0]); + entryBook.setLabel(line[2]); + entryBookService.createEntryBook(entryBook); + result.append(_("lima-business.import.accountadded", entryBook.getCode(), entryBook.getLabel())); + count++; + + line = csvReader.readNext(); + } + + if (log.isInfoEnabled()) { + long after = System.currentTimeMillis(); + log.info("Imported form EBP : " + count + " accounts in " + (after-before) + " ms"); + } + + } catch (Exception ex) { + doCatch(topiaContext, ex); + } finally { + doFinally(topiaContext); + } + + return result.toString(); + } + + // ################ IMPORT ################ /** Remote methode to call all entities import from UI */ Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java 2012-04-24 13:14:37 UTC (rev 3384) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/ImportServiceImplTest.java 2012-04-24 14:19:58 UTC (rev 3385) @@ -80,7 +80,7 @@ entryBookStream = ImportServiceImplTest.class.getResourceAsStream("/ebp/journaux.txt"); String entryBookData = IOUtils.toString(entryBookStream, "ISO-8859-1"); - //importService.importAccountsChartFromEbp(entryBookData); + importService.importEntryBookFromEbp(entryBookData); entryBookStream.close(); entriesStream = ImportServiceImplTest.class.getResourceAsStream("/ebp/ecritures.txt"); @@ -137,7 +137,7 @@ public void testImportEntryBookEBP() throws Exception { importEBPData(); - Assert.assertNotNull(entryBookService.getEntryBookByCode("EV")); + Assert.assertNotNull(entryBookService.getEntryBookByCode("AN")); Assert.assertNotNull(entryBookService.getEntryBookByCode("BQ")); } Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java 2012-04-24 13:14:37 UTC (rev 3384) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/ImportService.java 2012-04-24 14:19:58 UTC (rev 3385) @@ -44,6 +44,15 @@ String importAccountsChartFromEbp(String data) throws LimaException; /** + * Import entry books as EBP import. + * + * @param datas + * @return + * @throws LimaException + */ + String importEntryBookFromEbp(String datas) throws LimaException; + + /** * Import entries as EBP import. * * @param data import file content as string (remote service can't take File) @@ -81,4 +90,6 @@ String importAsPDF(String data, ImportExportEntityEnum importExportEntityEnum, boolean saveMode) throws LimaException; + + }
participants (1)
-
echatellier@users.chorem.org