r3829 - in trunk: . lima-business 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: dcosse Date: 2014-06-11 10:16:27 +0200 (Wed, 11 Jun 2014) New Revision: 3829 Url: http://forge.chorem.org/projects/lima/repository/revisions/3829 Log: #1032 utilisation de Base64 pour envoie du zip du server vers swing Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java trunk/lima-business/pom.xml trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java trunk/lima-business/src/test/java/org/chorem/lima/business/NewExportServiceTest.java trunk/pom.xml Modified: trunk/lima-business/pom.xml =================================================================== --- trunk/lima-business/pom.xml 2014-06-10 16:17:01 UTC (rev 3828) +++ trunk/lima-business/pom.xml 2014-06-11 08:16:27 UTC (rev 3829) @@ -122,6 +122,10 @@ <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-server</artifactId> </dependency> + <dependency> + <groupId>commons-codec</groupId> + <artifactId>commons-codec</artifactId> + </dependency> </dependencies> Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java 2014-06-10 16:17:01 UTC (rev 3828) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java 2014-06-11 08:16:27 UTC (rev 3829) @@ -49,18 +49,17 @@ import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.FiscalPeriodTopiaDao; import org.nuiton.csv.Export; +import org.apache.commons.codec.binary.Base64; import javax.ejb.EJB; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.nio.charset.Charset; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -93,8 +92,8 @@ @Override public String exportAllAsCSV(String path, String charset) throws LimaException { + ByteArrayOutputStream rstBao = new ByteArrayOutputStream(); ZipOutputStream export = null; - String filePath; try { List<File> files = Lists.newArrayList(); files.add(exportAccountsFile(charset)); @@ -103,12 +102,8 @@ files.add(exportFinancialTransactionsFile(charset)); files.add(exportEntriesFile(charset)); - SimpleDateFormat exportDate = new SimpleDateFormat(DATE_PATTERN); - filePath = path + "LIMA-BACKUP-"+ exportDate.format(new Date()) +".zip"; + export = new ZipOutputStream(rstBao); - FileOutputStream out = new FileOutputStream(filePath); - export = new ZipOutputStream(out); - for (File file : files) { ZipEntry ze= new ZipEntry(file.getName()); export.putNextEntry(ze); @@ -121,14 +116,15 @@ stream.close(); FileUtils.forceDelete(file); } + export.flush(); } catch (Exception e) { throw new LimaException("Can't export All",e); } finally { IOUtils.closeQuietly(export); } - - return filePath; + byte[] bytes = rstBao.toByteArray(); + return Base64.encodeBase64String(bytes); } protected File exportAccountsFile(String charset) throws Exception { Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java 2014-06-10 16:17:01 UTC (rev 3828) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewImportServiceImpl.java 2014-06-11 08:16:27 UTC (rev 3829) @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.IOUtils; import org.chorem.lima.business.LimaException; import org.chorem.lima.business.api.AccountService; @@ -32,6 +33,7 @@ import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; +import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; @@ -40,8 +42,6 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import static org.nuiton.i18n.I18n.t; - /** * Created by davidcosse on 03/06/14. */ @@ -165,14 +165,14 @@ } @Override - public void importAllAsCSV(String path) throws LimaException { - FileInputStream contentStream; + public void importAllAsCSV(String zippedBase64Str) throws LimaException { ZipInputStream zipInputStream = null; InputStream transactionsStream = null, entryBooksStream = null, fiscalPeriodsStream = null, entriesStream = null, accountsStream = null; try { - contentStream = new FileInputStream(path); - zipInputStream = new ZipInputStream(contentStream); + //contentStream = new FileInputStream(path); + byte[] bytes = Base64.decodeBase64(zippedBase64Str); + zipInputStream = new ZipInputStream(new ByteArrayInputStream(bytes)); // unzip ZipEntry entry; @@ -204,15 +204,15 @@ zipInputStream.closeEntry(); } + entryBooksStream = new FileInputStream(tmpDir + "entryBooks.csv"); + String entryBooksStreamString = IOUtils.toString(entryBooksStream); + importEntryBooksAsCSV(entryBooksStreamString); + // import transactionsStream = new FileInputStream(tmpDir + "financialTransactions.csv"); String transactionsStreamString = IOUtils.toString(transactionsStream); importFinancialTransactionsAsCSV(transactionsStreamString); - entryBooksStream = new FileInputStream(tmpDir + "entryBooks.csv"); - String entryBooksStreamString = IOUtils.toString(entryBooksStream); - importEntryBooksAsCSV(entryBooksStreamString); - fiscalPeriodsStream = new FileInputStream(tmpDir + "fiscalPeriods.csv"); String fiscalPeriodsStreamString = IOUtils.toString(fiscalPeriodsStream); importFiscalPeriodsAsCSV(fiscalPeriodsStreamString); Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/NewExportServiceTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/NewExportServiceTest.java 2014-06-10 16:17:01 UTC (rev 3828) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/NewExportServiceTest.java 2014-06-11 08:16:27 UTC (rev 3829) @@ -1,7 +1,6 @@ package org.chorem.lima.business; import com.google.common.collect.Lists; -import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; @@ -11,12 +10,10 @@ import org.junit.Assert; import org.junit.Test; -import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.nio.charset.Charset; -import java.util.Collection; import java.util.List; /** @@ -213,14 +210,10 @@ public void exportAllAsCSVTest() throws Exception { initTestWithFinancialTransaction(); String tmpDir = System.getProperty("java.io.tmpdir")+"/"; - String path = newExportService.exportAllAsCSV(tmpDir, "UTF-8"); - + String export = newExportService.exportAllAsCSV(tmpDir, "UTF-8"); initAbstractTest(); + newImportService.importAllAsCSV(export); + } - Collection<FinancialTransaction> financialTransactions = financialTransactionService.getAllFinancialTransactions(df.parse("January 1, 2012"),df.parse("December 31, 2012")); - Assert.assertTrue(financialTransactions.isEmpty()); - newImportService.importAllAsCSV(path); - FileUtils.deleteDirectory(new File(tmpDir)); - } } Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java 2014-06-10 16:17:01 UTC (rev 3828) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewImportService.java 2014-06-11 08:16:27 UTC (rev 3829) @@ -17,5 +17,5 @@ void importEntriesAsCSV(String contents) throws LimaException; - void importAllAsCSV(String contents) throws LimaException; + void importAllAsCSV(String zippedBase64Str) throws LimaException; } Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2014-06-10 16:17:01 UTC (rev 3828) +++ trunk/pom.xml 2014-06-11 08:16:27 UTC (rev 3829) @@ -183,12 +183,13 @@ <nuitonWidgetsVersion>1.1.1</nuitonWidgetsVersion> <launch4jPluginVersion>1.5.0.0</launch4jPluginVersion> - <jaxxVersion>2.8.5</jaxxVersion> + <jaxxVersion>2.8.7</jaxxVersion> <openEjbVersion>4.6.0.2</openEjbVersion> <slf4jVersion>1.7.7</slf4jVersion> <swingxVersion>1.6.5-1</swingxVersion> <pdfboxVersion>1.8.5</pdfboxVersion> <jbossTransactionVersion>1.0.0.Final</jbossTransactionVersion> + <commonsCodecVersion>1.9</commonsCodecVersion> <!-- license to use --> <license.licenseName>gpl_v3</license.licenseName> @@ -486,6 +487,13 @@ <version>${jettyPluginVersion}</version> </dependency> + <dependency> + <groupId>commons-codec</groupId> + <artifactId>commons-codec</artifactId> + <version>${commonsCodecVersion}</version> + </dependency> + + </dependencies> </dependencyManagement>
participants (1)
-
dcosse@users.chorem.org