Search in sources :

Example 41 with AbstractOperation

use of com.google.refine.model.AbstractOperation in project OpenRefine by OpenRefine.

the class JoinMultiValuedCellsTests method testJoinMultiValuedCellsMultipleSpaces.

@Test
public void testJoinMultiValuedCellsMultipleSpaces() 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");
}
Also used : AbstractOperation(com.google.refine.model.AbstractOperation) Process(com.google.refine.process.Process) Properties(java.util.Properties) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 42 with AbstractOperation

use of com.google.refine.model.AbstractOperation in project OpenRefine by OpenRefine.

the class TransposeColumnsIntoRowsCommand 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;
        String startColumnName = request.getParameter("startColumnName");
        int columnCount = Integer.parseInt(request.getParameter("columnCount"));
        boolean ignoreBlankCells = Boolean.parseBoolean(request.getParameter("ignoreBlankCells"));
        boolean fillDown = Boolean.parseBoolean(request.getParameter("fillDown"));
        String combinedColumnName = request.getParameter("combinedColumnName");
        if (combinedColumnName != null) {
            boolean prependColumnName = Boolean.parseBoolean(request.getParameter("prependColumnName"));
            String separator = request.getParameter("separator");
            op = new TransposeColumnsIntoRowsOperation(startColumnName, columnCount, ignoreBlankCells, fillDown, combinedColumnName, prependColumnName, separator);
        } else {
            String keyColumnName = request.getParameter("keyColumnName");
            String valueColumnName = request.getParameter("valueColumnName");
            op = new TransposeColumnsIntoRowsOperation(startColumnName, columnCount, ignoreBlankCells, fillDown, keyColumnName, valueColumnName);
        }
        Process process = op.createProcess(project, new Properties());
        performProcessAndRespond(request, response, project, process);
    } catch (Exception e) {
        respondException(response, e);
    }
}
Also used : Project(com.google.refine.model.Project) TransposeColumnsIntoRowsOperation(com.google.refine.operations.cell.TransposeColumnsIntoRowsOperation) AbstractOperation(com.google.refine.model.AbstractOperation) Process(com.google.refine.process.Process) Properties(java.util.Properties) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

AbstractOperation (com.google.refine.model.AbstractOperation)42 Process (com.google.refine.process.Process)36 Properties (java.util.Properties)36 Test (org.testng.annotations.Test)27 RefineTest (com.google.refine.RefineTest)25 Project (com.google.refine.model.Project)14 IOException (java.io.IOException)14 BeforeTest (org.testng.annotations.BeforeTest)14 ServletException (javax.servlet.ServletException)13 ArrayList (java.util.ArrayList)4 Column (com.google.refine.model.Column)3 HistoryEntry (com.google.refine.history.HistoryEntry)2 Cell (com.google.refine.model.Cell)2 Row (com.google.refine.model.Row)2 StringReader (java.io.StringReader)2 ProjectMetadata (com.google.refine.ProjectMetadata)1 Change (com.google.refine.history.Change)1 ModelException (com.google.refine.model.ModelException)1 ReconConfig (com.google.refine.model.recon.ReconConfig)1 StandardReconConfig (com.google.refine.model.recon.StandardReconConfig)1