Search in sources :

Example 46 with Project

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

the class ReconJudgeOneCellCommand method doPost.

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (!hasValidCSRFToken(request)) {
        respondCSRFError(response);
        return;
    }
    try {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        Project project = getProject(request);
        int rowIndex = Integer.parseInt(request.getParameter("row"));
        int cellIndex = Integer.parseInt(request.getParameter("cell"));
        Judgment judgment = Recon.stringToJudgment(request.getParameter("judgment"));
        ReconCandidate match = null;
        String id = request.getParameter("id");
        if (id != null) {
            String scoreString = request.getParameter("score");
            match = new ReconCandidate(id, request.getParameter("name"), request.getParameter("types").split(","), scoreString != null ? Double.parseDouble(scoreString) : 100);
        }
        JudgeOneCellProcess process = new JudgeOneCellProcess(project, "Judge one cell's recon result", judgment, rowIndex, cellIndex, match, request.getParameter("identifierSpace"), request.getParameter("schemaSpace"));
        HistoryEntry historyEntry = project.processManager.queueProcess(process);
        if (historyEntry != null) {
            /*
                 * If the process is done, write back the cell's data so that the
                 * client side can update its UI right away.
                 */
            Pool pool = new Pool();
            if (process.newCell != null && process.newCell.recon != null) {
                pool.pool(process.newCell.recon);
            }
            respondJSON(response, new ReconClearOneCellCommand.CellResponse(historyEntry, process.newCell, pool));
        } else {
            respond(response, "{ \"code\" : \"pending\" }");
        }
    } catch (Exception e) {
        respondException(response, e);
    }
}
Also used : Project(com.google.refine.model.Project) HistoryEntry(com.google.refine.history.HistoryEntry) Pool(com.google.refine.util.Pool) ReconCandidate(com.google.refine.model.ReconCandidate) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Judgment(com.google.refine.model.Recon.Judgment)

Example 47 with Project

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

the class JoinMultiValueCellsCommand 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");
        AbstractOperation op = new MultiValuedCellJoinOperation(columnName, keyColumnName, separator);
        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) MultiValuedCellJoinOperation(com.google.refine.operations.cell.MultiValuedCellJoinOperation) AbstractOperation(com.google.refine.model.AbstractOperation) Process(com.google.refine.process.Process) Properties(java.util.Properties) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 48 with Project

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

the class KeyValueColumnizeCommand 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 keyColumnName = request.getParameter("keyColumnName");
        String valueColumnName = request.getParameter("valueColumnName");
        String noteColumnName = request.getParameter("noteColumnName");
        AbstractOperation op = new KeyValueColumnizeOperation(keyColumnName, valueColumnName, noteColumnName);
        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) Properties(java.util.Properties) KeyValueColumnizeOperation(com.google.refine.operations.cell.KeyValueColumnizeOperation) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 49 with Project

use of com.google.refine.model.Project 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)

Example 50 with Project

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

the class RenameColumnCommand 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 oldColumnName = request.getParameter("oldColumnName");
        String newColumnName = request.getParameter("newColumnName");
        AbstractOperation op = new ColumnRenameOperation(oldColumnName, newColumnName);
        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) Properties(java.util.Properties) ColumnRenameOperation(com.google.refine.operations.column.ColumnRenameOperation) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

Project (com.google.refine.model.Project)146 Properties (java.util.Properties)46 IOException (java.io.IOException)40 Engine (com.google.refine.browsing.Engine)37 Test (org.testng.annotations.Test)37 ServletException (javax.servlet.ServletException)35 ProjectMetadata (com.google.refine.ProjectMetadata)33 BeforeMethod (org.testng.annotations.BeforeMethod)31 Cell (com.google.refine.model.Cell)29 Row (com.google.refine.model.Row)29 RefineTest (com.google.refine.RefineTest)25 Column (com.google.refine.model.Column)25 BeforeTest (org.testng.annotations.BeforeTest)18 Process (com.google.refine.process.Process)17 AbstractOperation (com.google.refine.model.AbstractOperation)14 StringWriter (java.io.StringWriter)13 RowVisitor (com.google.refine.browsing.RowVisitor)11 ArrayList (java.util.ArrayList)11 File (java.io.File)10 WrappedCell (com.google.refine.expr.WrappedCell)9