Search in sources :

Example 1 with Process

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

the class ApplyOperationsCommand method reconstructOperation.

protected void reconstructOperation(Project project, JSONObject obj) {
    AbstractOperation operation = OperationRegistry.reconstruct(project, obj);
    if (operation != null) {
        try {
            Process process = operation.createProcess(project, new Properties());
            project.processManager.queueProcess(process);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : AbstractOperation(com.google.refine.model.AbstractOperation) Process(com.google.refine.process.Process) Properties(java.util.Properties) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) JSONException(org.json.JSONException)

Example 2 with Process

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

the class SplitMultiValueCellsCommand 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");
        String keyColumnName = request.getParameter("keyColumnName");
        String separator = request.getParameter("separator");
        String mode = request.getParameter("mode");
        Boolean regex = Boolean.parseBoolean(request.getParameter("regex"));
        AbstractOperation op;
        if ("lengths".equals(mode)) {
            String s = request.getParameter("fieldLengths");
            int[] fieldLengths = ParsingUtilities.mapper.readValue(s, new TypeReference<int[]>() {
            });
            op = new MultiValuedCellSplitOperation(columnName, keyColumnName, fieldLengths);
        } else {
            op = new MultiValuedCellSplitOperation(columnName, keyColumnName, separator, regex);
        }
        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) MultiValuedCellSplitOperation(com.google.refine.operations.cell.MultiValuedCellSplitOperation) Process(com.google.refine.process.Process) Properties(java.util.Properties) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 3 with Process

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

the class RemoveColumnCommand 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");
        AbstractOperation op = new ColumnRemovalOperation(columnName);
        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) Process(com.google.refine.process.Process) ColumnRemovalOperation(com.google.refine.operations.column.ColumnRemovalOperation) Properties(java.util.Properties) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 4 with Process

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

the class ApplyOperationsCommand method reconstructOperation.

protected void reconstructOperation(Project project, ObjectNode obj) throws IOException {
    AbstractOperation operation = ParsingUtilities.mapper.convertValue(obj, AbstractOperation.class);
    if (operation != null && !(operation instanceof UnknownOperation)) {
        try {
            Process process = operation.createProcess(project, new Properties());
            project.processManager.queueProcess(process);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : AbstractOperation(com.google.refine.model.AbstractOperation) UnknownOperation(com.google.refine.operations.UnknownOperation) Process(com.google.refine.process.Process) Properties(java.util.Properties) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 5 with Process

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

the class TransposeRowsIntoColumnsCommand 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 rowCount = Integer.parseInt(request.getParameter("rowCount"));
        AbstractOperation op = new TransposeRowsIntoColumnsOperation(columnName, rowCount);
        Process process = op.createProcess(project, new Properties());
        performProcessAndRespond(request, response, project, process);
    } catch (Exception e) {
        respondException(response, e);
    }
}
Also used : TransposeRowsIntoColumnsOperation(com.google.refine.operations.cell.TransposeRowsIntoColumnsOperation) Project(com.google.refine.model.Project) 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