CsvExporter is linked to the UI, and should fully work. Unit Tests now assert that null cells can be handled by CsvExporter. CHANGES.txt is now updated to reflect Issue 59.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@845 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Iain Sproat 2010-05-24 12:36:35 +00:00
parent 53e20da8f4
commit 015b5a92ae
5 changed files with 57 additions and 28 deletions

View File

@ -18,6 +18,7 @@ Fixes:
Features:
- Row/record sorting (Issue 32)
- CSV exporting (Issue 59)
Changes:
- Moved unit tests from JUnit to TestNG

View File

@ -13,6 +13,7 @@ import javax.servlet.http.HttpServletResponse;
import com.metaweb.gridworks.ProjectManager;
import com.metaweb.gridworks.browsing.Engine;
import com.metaweb.gridworks.commands.Command;
import com.metaweb.gridworks.exporters.CsvExporter;
import com.metaweb.gridworks.exporters.Exporter;
import com.metaweb.gridworks.exporters.HtmlTableExporter;
import com.metaweb.gridworks.exporters.TripleloaderExporter;
@ -28,6 +29,7 @@ public class ExportRowsCommand extends Command {
s_formatToExporter.put("tripleloader", new TripleloaderExporter());
s_formatToExporter.put("html", new HtmlTableExporter());
s_formatToExporter.put("xls", new XlsExporter());
s_formatToExporter.put("csv", new CsvExporter());
}
public void doPost(HttpServletRequest request, HttpServletResponse response)

View File

@ -8,6 +8,7 @@ import java.util.Properties;
import com.metaweb.gridworks.browsing.Engine;
import com.metaweb.gridworks.browsing.FilteredRows;
import com.metaweb.gridworks.browsing.RowVisitor;
import com.metaweb.gridworks.model.Cell;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row;
@ -48,8 +49,11 @@ public class CsvExporter implements Exporter{
vals = new String[row.cells.size()];
for(int i = 0; i < vals.length; i++){
Cell cell = row.cells.get(i);
if(cell != null){
vals[i] = row.cells.get(i).value.toString();
}
}
csvWriter.writeNext(vals);
return false;

View File

@ -40,6 +40,10 @@ MenuBar.prototype._initializeUI = function() {
"label": "Tab-Separated Value",
"click": function() { self._doExportRows("tsv", "tsv"); }
},
{
"label": "Comma-Separated Value",
"click": function() { self._doExportRows("csv", "csv"); }
},
{
"label": "HTML Table",
"click": function() { self._doExportRows("html", "html"); }

View File

@ -97,6 +97,24 @@ public class CsvExporterTests {
"\"row2cell0\",\"row2cell1\",\"row2cell2\"\n");
}
@Test
public void exportCsvWithEmptyCells(){
CreateGrid(3,3);
project.rows.get(1).cells.set(1, null);
project.rows.get(2).cells.set(0, null);
try {
SUT.export(project, options, engine, writer);
} catch (IOException e) {
Assert.fail();
}
Assert.assertEquals(writer.toString(), "\"column0\",\"column1\",\"column2\"\n" +
"\"row0cell0\",\"row0cell1\",\"row0cell2\"\n" +
"\"row1cell0\",,\"row1cell2\"\n" +
",\"row2cell1\",\"row2cell2\"\n");
}
//helper methods
protected void CreateColumns(int noOfColumns){