Search in sources :

Example 26 with AbstractOperation

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

the class DenormalizeCommand 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 = new DenormalizeOperation();
        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) AbstractOperation(com.google.refine.model.AbstractOperation) DenormalizeOperation(com.google.refine.operations.row.DenormalizeOperation) Process(com.google.refine.process.Process) Properties(java.util.Properties) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 27 with AbstractOperation

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

the class RowReorderOperationTests method testSortEmptyString.

@Test
public void testSortEmptyString() throws Exception {
    String sortingJson = "{\"criteria\":[{\"column\":\"key\",\"valueType\":\"number\",\"reverse\":false,\"blankPosition\":2,\"errorPosition\":1}]}";
    SortingConfig sortingConfig = SortingConfig.reconstruct(sortingJson);
    project.rows.get(1).cells.set(0, new Cell("", null));
    AbstractOperation op = new RowReorderOperation(Mode.RowBased, sortingConfig);
    Process process = op.createProcess(project, new Properties());
    process.performImmediate();
    Assert.assertEquals("h", project.rows.get(0).cells.get(1).value);
    Assert.assertEquals("f", project.rows.get(1).cells.get(1).value);
    Assert.assertEquals("b", project.rows.get(2).cells.get(1).value);
    Assert.assertEquals("d", project.rows.get(3).cells.get(1).value);
}
Also used : AbstractOperation(com.google.refine.model.AbstractOperation) Process(com.google.refine.process.Process) Properties(java.util.Properties) Cell(com.google.refine.model.Cell) SortingConfig(com.google.refine.sorting.SortingConfig) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test)

Example 28 with AbstractOperation

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

the class HistoryProcessTests method setUp.

@BeforeMethod
public void setUp() {
    project = new Project();
    projectMetadata = mock(ProjectMetadata.class);
    ProjectManager.singleton.registerProject(project, projectMetadata);
    AbstractOperation op = mock(AbstractOperation.class);
    Change ch = mock(Change.class);
    HistoryEntry entry = new HistoryEntry(1234L, project, "first operation", op, ch);
    project.history.addEntry(entry);
    entry = new HistoryEntry(5678L, project, "second operation", op, ch);
    project.history.addEntry(entry);
}
Also used : Project(com.google.refine.model.Project) AbstractOperation(com.google.refine.model.AbstractOperation) ProjectMetadata(com.google.refine.ProjectMetadata) HistoryEntry(com.google.refine.history.HistoryEntry) Change(com.google.refine.history.Change) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 29 with AbstractOperation

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

the class MoveColumnCommand 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");
        int index = Integer.parseInt(request.getParameter("index"));
        AbstractOperation op = new ColumnMoveOperation(columnName, index);
        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) AbstractOperation(com.google.refine.model.AbstractOperation) ColumnMoveOperation(com.google.refine.operations.column.ColumnMoveOperation) Process(com.google.refine.process.Process) Properties(java.util.Properties) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 30 with AbstractOperation

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

the class FillDownTests method testFillDownRecords.

// For issue #742
// https://github.com/OpenRefine/OpenRefine/issues/742
@Test
public void testFillDownRecords() throws Exception {
    AbstractOperation op = new FillDownOperation(EngineConfig.reconstruct("{\"mode\":\"record-based\",\"facets\":[]}"), "second");
    Process process = op.createProcess(project, new Properties());
    process.performImmediate();
    Assert.assertEquals("c", project.rows.get(0).cells.get(2).value);
    Assert.assertEquals("c", project.rows.get(1).cells.get(2).value);
    Assert.assertNull(project.rows.get(2).cells.get(2));
    Assert.assertEquals("h", project.rows.get(3).cells.get(2).value);
}
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)

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