Search in sources :

Example 36 with Project

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

the class ApplyOperationsCommand method doPost.

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (!hasValidCSRFToken(request)) {
        respondCSRFError(response);
        return;
    }
    Project project = getProject(request);
    String jsonString = request.getParameter("operations");
    try {
        ArrayNode a = ParsingUtilities.evaluateJsonStringToArrayNode(jsonString);
        int count = a.size();
        for (int i = 0; i < count; i++) {
            if (a.get(i) instanceof ObjectNode) {
                ObjectNode obj = (ObjectNode) a.get(i);
                reconstructOperation(project, obj);
            }
        }
        if (project.processManager.hasPending()) {
            respond(response, "{ \"code\" : \"pending\" }");
        } else {
            respond(response, "{ \"code\" : \"ok\" }");
        }
    } catch (IOException e) {
        respondException(response, e);
    }
}
Also used : Project(com.google.refine.model.Project) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOException(java.io.IOException)

Example 37 with Project

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

the class UndoRedoCommand method doPost.

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (!hasValidCSRFToken(request)) {
        respondCSRFError(response);
        return;
    }
    Project project = getProject(request);
    long lastDoneID = -1;
    String lastDoneIDString = request.getParameter("lastDoneID");
    if (lastDoneIDString != null) {
        lastDoneID = Long.parseLong(lastDoneIDString);
    } else {
        String undoIDString = request.getParameter("undoID");
        if (undoIDString != null) {
            long undoID = Long.parseLong(undoIDString);
            lastDoneID = project.history.getPrecedingEntryID(undoID);
        }
    }
    try {
        boolean done = lastDoneID == -1 || project.processManager.queueProcess(new HistoryProcess(project, lastDoneID));
        respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }");
    } catch (Exception e) {
        respondException(response, e);
    }
}
Also used : Project(com.google.refine.model.Project) HistoryProcess(com.google.refine.history.HistoryProcess) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 38 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 39 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)

Example 40 with Project

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

the class SetProjectTagsCommand method doPost.

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (!hasValidCSRFToken(request)) {
        respondCSRFError(response);
        return;
    }
    response.setHeader("Content-Type", "application/json");
    Project project;
    try {
        project = getProject(request);
    } catch (ServletException e) {
        respond(response, "error", e.getLocalizedMessage());
        return;
    }
    ProjectMetadata metadata = project.getMetadata();
    String oldT = request.getParameter("old");
    String newT = request.getParameter("new");
    Map<String, Integer> allProjectTags = ProjectManager.singleton.getAllProjectTags();
    // Lets remove the old tags from the general map
    String[] oldTags = oldT.split(",");
    for (String tag : oldTags) {
        if (allProjectTags != null && allProjectTags.containsKey(tag)) {
            int occurrence = allProjectTags.get(tag);
            if (occurrence == 1) {
                allProjectTags.remove(tag);
            } else {
                allProjectTags.put(tag, occurrence - 1);
            }
        }
    }
    // Lets add the new tags to the general map
    String[] newTags = newT.split(" |\\,");
    List<String> polishedTags = new ArrayList<String>(newTags.length);
    for (String tag : newTags) {
        tag = tag.trim();
        if (!tag.isEmpty()) {
            if (allProjectTags != null) {
                if (allProjectTags.containsKey(tag)) {
                    allProjectTags.put(tag, allProjectTags.get(tag) + 1);
                } else {
                    allProjectTags.put(tag, 1);
                }
            }
            polishedTags.add(tag);
        }
    }
    // Lets update the project tags
    metadata.setTags(polishedTags.toArray(new String[polishedTags.size()]));
    metadata.updateModified();
    respond(response, "{ \"code\" : \"ok\" }");
}
Also used : ServletException(javax.servlet.ServletException) Project(com.google.refine.model.Project) ProjectMetadata(com.google.refine.ProjectMetadata) ArrayList(java.util.ArrayList)

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