This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

Create CSV files of JVx storages

Our AbstractStorage implementations have a writeCSV feature already implemented and you can call this method via action call mechanism. But sometimes you need different CSV exports or ZIP archives with different CSV files. You simply need control over the export.

There's a small project with the name AES Storage Export that could help you solving CSV export problems. It has one simple class that takes one or more storages and exports data as UTF-8 CSV files. All CSV files will be added to a zip archive (optionally AES encrypted)

Simple use the class in an server action and create your custom CSV exports.

Test case:

StorageExport export = new StorageExport();

ICondition condFilter = new GreaterEquals("ID", BigDecimal.valueOf(10)).and(new LessEquals("ID", BigDecimal.valueOf(20)));

StorageEntry entryColumns = new StorageEntry("columns.csv", createStorage(), condFilter);
entryColumns.setColumnNames("ID", "VALUE");

StorageEntry entryColumnsStorage = new StorageEntry("columns_storage.csv", createStorage(), condFilter);
entryColumnsStorage.setColumnNames(createColumnStorage(), "NAME");

export.add(new StorageEntry("first.csv", createStorage()));
export.add(new StorageEntry("filtered.csv", createStorage(), condFilter));
export.add(entryColumns);
export.add(entryColumnsStorage);
export.setPassword("testcase");
export.setSeparator(",");

File fiTemp = new File(System.getProperty("java.io.tmpdir"), "aesarchive.zip");

RemoteFileHandle rfh = new RemoteFileHandle();
export.export(rfh.getOutputStream());

FileUtil.save(fiTemp, rfh.getInputStream());

System.out.println(fiTemp);

Leave a Reply

Spam protection by WP Captcha-Free