Search in sources :

Example 41 with Process

use of com.google.refine.process.Process in project OpenRefine by OpenRefine.

the class ReconOperationTests method serializeReconProcess.

@Test
public void serializeReconProcess() throws Exception {
    ReconOperation op = ParsingUtilities.mapper.readValue(json, ReconOperation.class);
    Project project = mock(Project.class);
    Process process = op.createProcess(project, new Properties());
    TestUtils.isSerializedTo(process, String.format(processJson, process.hashCode()));
}
Also used : Project(com.google.refine.model.Project) 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 Process

use of com.google.refine.process.Process in project OpenRefine by OpenRefine.

the class ReconOperationTests method testFailingRecon.

@Test
public void testFailingRecon() throws Exception {
    Project project = createCSVProject("my recon test project", "column\n" + "valueA\n" + "valueB\n" + "valueC");
    StandardReconConfig reconConfig = mock(StandardReconConfig.class);
    List<Recon> reconList = Arrays.asList((Recon) null, (Recon) null, (Recon) null);
    ReconJob reconJob = mock(ReconJob.class);
    when(reconConfig.batchRecon(Mockito.any(), Mockito.anyLong())).thenReturn(reconList);
    when(reconConfig.getBatchSize()).thenReturn(10);
    when(reconConfig.createJob(Mockito.eq(project), Mockito.anyInt(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(reconJob);
    ReconOperation op = new ReconOperation(EngineConfig.reconstruct("{}"), "column", reconConfig);
    Process process = op.createProcess(project, new Properties());
    runAndWait(project.getProcessManager(), process, 1000);
    Column column = project.columnModel.columns.get(0);
    Assert.assertNotNull(column.getReconStats());
    Assert.assertEquals(column.getReconStats().matchedTopics, 0);
    Assert.assertNull(project.rows.get(0).getCell(0).recon);
    Assert.assertNull(project.rows.get(1).getCell(0).recon);
    Assert.assertNull(project.rows.get(2).getCell(0).recon);
}
Also used : Project(com.google.refine.model.Project) StandardReconConfig(com.google.refine.model.recon.StandardReconConfig) Column(com.google.refine.model.Column) ReconJob(com.google.refine.model.recon.ReconJob) Process(com.google.refine.process.Process) Properties(java.util.Properties) Recon(com.google.refine.model.Recon) RefineTest(com.google.refine.RefineTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 43 with Process

use of com.google.refine.process.Process 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

Process (com.google.refine.process.Process)43 Properties (java.util.Properties)41 AbstractOperation (com.google.refine.model.AbstractOperation)36 Test (org.testng.annotations.Test)29 RefineTest (com.google.refine.RefineTest)27 BeforeTest (org.testng.annotations.BeforeTest)20 Project (com.google.refine.model.Project)17 IOException (java.io.IOException)14 ServletException (javax.servlet.ServletException)13 Cell (com.google.refine.model.Cell)5 Row (com.google.refine.model.Row)5 Column (com.google.refine.model.Column)4 ProcessManager (com.google.refine.process.ProcessManager)4 ArrayList (java.util.ArrayList)4 StandardReconConfig (com.google.refine.model.recon.StandardReconConfig)2 ReconOperation (com.google.refine.operations.recon.ReconOperation)2 RefineTest (com.google.refine.tests.RefineTest)2 StringReader (java.io.StringReader)2 HttpUrl (okhttp3.HttpUrl)2 MockResponse (okhttp3.mockwebserver.MockResponse)2