Search in sources :

Example 21 with Process

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

the class UrlFetchingTests method testUrlCaching.

/**
     * Test for caching
     */
@Test
public void testUrlCaching() throws Exception {
    for (int i = 0; i < 100; i++) {
        Row row = new Row(2);
        row.setCell(0, new Cell(i < 5 ? "apple" : "orange", null));
        project.rows.add(row);
    }
    EngineDependentOperation op = new ColumnAdditionByFetchingURLsOperation(engine_config, "fruits", "\"https://www.random.org/integers/?num=1&min=1&max=100&col=1&base=10&format=plain&rnd=new&city=\"+value", OnError.SetToBlank, "rand", 1, 500, true);
    ProcessManager pm = project.getProcessManager();
    Process process = op.createProcess(project, options);
    process.startPerforming(pm);
    Assert.assertTrue(process.isRunning());
    try {
        // We have 100 rows and 500 ms per row but only two distinct
        // values so we should not wait more than ~2000 ms to get the
        // results. Just to make sure the test passes with plenty of
        // net latency we sleep for longer (but still less than
        // 50,000ms).
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        Assert.fail("Test interrupted");
    }
    Assert.assertFalse(process.isRunning());
    // Inspect rows
    String ref_val = (String) project.rows.get(0).getCellValue(1);
    // just to make sure I picked the right column
    Assert.assertTrue(ref_val != "apple");
    for (int i = 1; i < 4; i++) {
        // all random values should be equal due to caching
        Assert.assertEquals(project.rows.get(i).getCellValue(1), ref_val);
    }
}
Also used : EngineDependentOperation(com.google.refine.operations.EngineDependentOperation) ColumnAdditionByFetchingURLsOperation(com.google.refine.operations.column.ColumnAdditionByFetchingURLsOperation) Process(com.google.refine.process.Process) Row(com.google.refine.model.Row) Cell(com.google.refine.model.Cell) ProcessManager(com.google.refine.process.ProcessManager) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) RefineTest(com.google.refine.tests.RefineTest)

Example 22 with Process

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

the class SaveWikibaseSchemaCommand 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 jsonString = request.getParameter("schema");
        if (jsonString == null) {
            respondError(response, "No Wikibase schema provided.");
            return;
        }
        WikibaseSchema schema = ParsingUtilities.mapper.readValue(jsonString, WikibaseSchema.class);
        AbstractOperation op = new SaveWikibaseSchemaOperation(schema);
        Process process = op.createProcess(project, new Properties());
        performProcessAndRespond(request, response, project, process);
    } catch (IOException e) {
        // We do not use respondException here because this is an expected
        // exception which happens every time a user tries to save an incomplete
        // schema - the exception should not be logged.
        respondError(response, String.format("Wikibase schema could not be parsed: ", e.getMessage()));
    } catch (Exception e) {
        // This is an unexpected exception, so we log it.
        respondException(response, e);
    }
}
Also used : Project(com.google.refine.model.Project) AbstractOperation(com.google.refine.model.AbstractOperation) SaveWikibaseSchemaOperation(org.openrefine.wikidata.operations.SaveWikibaseSchemaOperation) WikibaseSchema(org.openrefine.wikidata.schema.WikibaseSchema) Process(com.google.refine.process.Process) IOException(java.io.IOException) Properties(java.util.Properties) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 23 with Process

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

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

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

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