Search in sources :

Example 91 with Project

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

the class GetProcessesCommand method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Project project = getProject(request);
    respondJSON(response, project.processManager);
}
Also used : Project(com.google.refine.model.Project)

Example 92 with Project

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

the class AnnotateOneRowCommand method doPost.

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (!hasValidCSRFToken(request)) {
        respondCSRFError(response);
        return;
    }
    response.setCharacterEncoding("UTF-8");
    response.setHeader("Content-Type", "application/json");
    try {
        Project project = getProject(request);
        int rowIndex = Integer.parseInt(request.getParameter("row"));
        String starredString = request.getParameter("starred");
        if (starredString != null) {
            boolean starred = "true".endsWith(starredString);
            String description = (starred ? "Star row " : "Unstar row ") + (rowIndex + 1);
            StarOneRowProcess process = new StarOneRowProcess(project, description, rowIndex, starred);
            performProcessAndRespond(request, response, project, process);
            return;
        }
        String flaggedString = request.getParameter("flagged");
        if (flaggedString != null) {
            boolean flagged = "true".endsWith(flaggedString);
            String description = (flagged ? "Flag row " : "Unflag row ") + (rowIndex + 1);
            FlagOneRowProcess process = new FlagOneRowProcess(project, description, rowIndex, flagged);
            performProcessAndRespond(request, response, project, process);
            return;
        }
        respond(response, "{ \"code\" : \"error\", \"message\" : \"invalid command parameters\" }");
    } catch (Exception e) {
        respondException(response, e);
    }
}
Also used : Project(com.google.refine.model.Project) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 93 with Project

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

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

the class GetProjectMetadataCommand method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Project project;
    try {
        project = getProject(request);
    } catch (ServletException e) {
        respond(response, "error", e.getLocalizedMessage());
        return;
    }
    respondJSON(response, ProjectManager.singleton.getProjectMetadata(project.id));
}
Also used : ServletException(javax.servlet.ServletException) Project(com.google.refine.model.Project)

Example 95 with Project

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

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