Author: dcosse Date: 2014-06-11 11:16:17 +0200 (Wed, 11 Jun 2014) New Revision: 3830 Url: http://forge.chorem.org/projects/lima/repository/revisions/3830 Log: #1032 creation du zip cot?\195?\169 swing Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewExportService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java trunk/lima-business/src/test/java/org/chorem/lima/business/NewExportServiceTest.java trunk/lima-swing/pom.xml trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 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-11 08:16:27 UTC (rev 3829) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/NewExportServiceImpl.java 2014-06-11 09:16:17 UTC (rev 3830) @@ -91,7 +91,7 @@ private FinancialTransactionService financialTransactionService; @Override - public String exportAllAsCSV(String path, String charset) throws LimaException { + public String exportAllAsCSV(String charset) throws LimaException { ByteArrayOutputStream rstBao = new ByteArrayOutputStream(); ZipOutputStream export = null; try { 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-11 08:16:27 UTC (rev 3829) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/NewExportServiceTest.java 2014-06-11 09:16:17 UTC (rev 3830) @@ -1,6 +1,7 @@ package org.chorem.lima.business; import com.google.common.collect.Lists; +import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.IOUtils; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; @@ -10,11 +11,16 @@ import org.junit.Assert; import org.junit.Test; +import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.util.List; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; /** * Created by davidcosse on 03/06/14. @@ -209,11 +215,18 @@ @Test public void exportAllAsCSVTest() throws Exception { initTestWithFinancialTransaction(); - String tmpDir = System.getProperty("java.io.tmpdir")+"/"; - String export = newExportService.exportAllAsCSV(tmpDir, "UTF-8"); + String export = newExportService.exportAllAsCSV("UTF-8"); initAbstractTest(); + String tmpDir = System.getProperty("java.io.tmpdir")+"/TMP_BACKUP.zip"; + createZipFile(tmpDir, export); newImportService.importAllAsCSV(export); } + protected void createZipFile(String path, String zippedBase64Str) throws Exception { + byte[] bytes = Base64.decodeBase64(zippedBase64Str); + ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); + IOUtils.copy(inputStream, new FileOutputStream(path)); + } + } Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewExportService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewExportService.java 2014-06-11 08:16:27 UTC (rev 3829) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/NewExportService.java 2014-06-11 09:16:17 UTC (rev 3830) @@ -42,7 +42,7 @@ */ public interface NewExportService { - String exportAllAsCSV(String path, String charset) throws LimaException; + String exportAllAsCSV(String charset) throws LimaException; String exportAccountsStream(String charset) throws LimaException; Modified: trunk/lima-swing/pom.xml =================================================================== --- trunk/lima-swing/pom.xml 2014-06-11 08:16:27 UTC (rev 3829) +++ trunk/lima-swing/pom.xml 2014-06-11 09:16:17 UTC (rev 3830) @@ -169,6 +169,11 @@ <artifactId>commons-lang</artifactId> </dependency> + <dependency> + <groupId>commons-codec</groupId> + <artifactId>commons-codec</artifactId> + </dependency> + </dependencies> <build> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-06-11 08:16:27 UTC (rev 3829) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2014-06-11 09:16:17 UTC (rev 3830) @@ -31,16 +31,15 @@ import java.awt.Color; import java.awt.Component; import java.awt.Container; -import java.io.BufferedReader; import java.io.BufferedWriter; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.OutputStreamWriter; -import java.io.StringWriter; import java.nio.charset.Charset; import java.util.concurrent.ExecutionException; @@ -53,10 +52,12 @@ import com.google.common.base.Charsets; import com.google.common.base.Strings; +import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.LimaException; import org.chorem.lima.business.api.ExportService; import org.chorem.lima.business.api.ImportService; import org.chorem.lima.business.api.NewExportService; @@ -135,7 +136,8 @@ String result = ""; switch (importExportMethodeF) { case CSV_ALL_EXPORT: - newExportService.exportAllAsCSV(filePath, charset.name()); + datas = newExportService.exportAllAsCSV(charset.name()); + createZipFile(filePath, datas); break; case CSV_ACCOUNTCHARTS_EXPORT: datas = exportService.exportAccountsChartAsCSV(); @@ -389,4 +391,14 @@ return result; } + + protected void createZipFile(String path, String zippedBase64Str) throws LimaException { + try { + byte[] bytes = Base64.decodeBase64(zippedBase64Str); + ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); + IOUtils.copy(inputStream, new FileOutputStream(path)); + } catch (IOException e) { + throw new LimaException("could not zip file", e); + } + } }