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);
}
}
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);
}
}
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);
}
}
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);
}
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);
}
}
Aggregations