use of com.google.refine.process.Process in project OpenRefine by OpenRefine.
the class JoinMultiValuedCellsTests method testJoinMultiValuedCells.
/*
* Test to demonstrate the intended behaviour of the function
*/
@Test
public void testJoinMultiValuedCells() throws Exception {
AbstractOperation op = new MultiValuedCellJoinOperation("Value", "Key", ",");
Process process = op.createProcess(project, new Properties());
process.performImmediate();
int keyCol = project.columnModel.getColumnByName("Key").getCellIndex();
int valueCol = project.columnModel.getColumnByName("Value").getCellIndex();
Assert.assertEquals(project.rows.get(0).getCellValue(keyCol), "Record_1");
Assert.assertEquals(project.rows.get(0).getCellValue(valueCol), "one,two,three,four");
}
use of com.google.refine.process.Process in project OpenRefine by OpenRefine.
the class JoinMultiValueCellsCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (!hasValidCSRFToken(request)) {
respondCSRFError(response);
return;
}
try {
Project project = getProject(request);
String columnName = request.getParameter("columnName");
String keyColumnName = request.getParameter("keyColumnName");
String separator = request.getParameter("separator");
AbstractOperation op = new MultiValuedCellJoinOperation(columnName, keyColumnName, separator);
Process process = op.createProcess(project, new Properties());
performProcessAndRespond(request, response, project, process);
} catch (Exception e) {
respondException(response, e);
}
}
use of com.google.refine.process.Process in project OpenRefine by OpenRefine.
the class KeyValueColumnizeCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (!hasValidCSRFToken(request)) {
respondCSRFError(response);
return;
}
try {
Project project = getProject(request);
String keyColumnName = request.getParameter("keyColumnName");
String valueColumnName = request.getParameter("valueColumnName");
String noteColumnName = request.getParameter("noteColumnName");
AbstractOperation op = new KeyValueColumnizeOperation(keyColumnName, valueColumnName, noteColumnName);
Process process = op.createProcess(project, new Properties());
performProcessAndRespond(request, response, project, process);
} catch (Exception e) {
respondException(response, e);
}
}
use of com.google.refine.process.Process in project OpenRefine by OpenRefine.
the class EngineDependentCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (!hasValidCSRFToken(request)) {
respondCSRFError(response);
return;
}
try {
Project project = getProject(request);
AbstractOperation op = createOperation(project, request, getEngineConfig(request));
Process process = op.createProcess(project, new Properties());
performProcessAndRespond(request, response, project, process);
} catch (Exception e) {
respondException(response, e);
}
}
use of com.google.refine.process.Process in project OpenRefine by OpenRefine.
the class TransposeTests method keyValueComumnize.
@Test
public void keyValueComumnize() throws Exception {
String input = "ID;Cat;Val\n" + "1;a;1\n" + "1;b;3\n" + "2;b;4\n" + "2;c;5\n" + "3;a;2\n" + "3;b;5\n" + "3;d;3\n";
prepareOptions(";", -1, 0, 0, 1, false, false);
List<Exception> exceptions = new ArrayList<Exception>();
importer.parseOneFile(project, metadata, job, "filesource", new StringReader(input), -1, options, exceptions);
project.update();
ProjectManager.singleton.registerProject(project, metadata);
AbstractOperation op = new KeyValueColumnizeOperation("Cat", "Val", null);
Process process = op.createProcess(project, new Properties());
HistoryEntry historyEntry = process.performImmediate();
// Expected output from the GUI.
// ID;a;b;c;d
// 1;1;3;;
// 2;;4;5;
// 3;2;5;;3
Assert.assertEquals(project.columnModel.columns.size(), 5);
Assert.assertEquals(project.columnModel.columns.get(0).getName(), "ID");
Assert.assertEquals(project.columnModel.columns.get(1).getName(), "a");
Assert.assertEquals(project.columnModel.columns.get(2).getName(), "b");
Assert.assertEquals(project.columnModel.columns.get(3).getName(), "c");
Assert.assertEquals(project.columnModel.columns.get(4).getName(), "d");
Assert.assertEquals(project.rows.size(), 3);
// The actual row data structure has to leave the columns model untouched for redo/undo purpose.
// So we have 2 empty columns(column 1,2) on the row level.
// 1;1;3;;
Assert.assertEquals(project.rows.get(0).cells.get(0).value, "1");
Assert.assertEquals(project.rows.get(0).cells.get(3).value, "1");
Assert.assertEquals(project.rows.get(0).cells.get(4).value, "3");
// 2;;4;5;
Assert.assertEquals(project.rows.get(1).cells.get(0).value, "2");
Assert.assertEquals(project.rows.get(1).cells.get(4).value, "4");
Assert.assertEquals(project.rows.get(1).cells.get(5).value, "5");
// 3;2;5;;3
Assert.assertEquals(project.rows.get(2).cells.get(0).value, "3");
Assert.assertEquals(project.rows.get(2).cells.get(3).value, "2");
Assert.assertEquals(project.rows.get(2).cells.get(4).value, "5");
Assert.assertEquals(project.rows.get(2).cells.get(6).value, "3");
}
Aggregations