Search in sources :

Example 31 with Project

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

the class GetOperationsCommand method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Project project = getProject(request);
    HistoryEntries entries = new HistoryEntries(project.history.getLastPastEntries(-1));
    respondJSON(response, entries);
}
Also used : Project(com.google.refine.model.Project)

Example 32 with Project

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

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

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

the class ExportProjectCommand method doPost.

/**
 * This command uses POST but is left CSRF-unprotected as it does not incur a state change.
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        Project project = getProject(request);
        ProjectManager.singleton.ensureProjectSaved(project.id);
        response.setHeader("Content-Type", "application/x-gzip");
        OutputStream os = response.getOutputStream();
        try {
            FileProjectManager.gzipTarToOutputStream(project, os);
        } finally {
            os.close();
        }
    } catch (Exception e) {
        respondException(response, e);
    }
}
Also used : Project(com.google.refine.model.Project) OutputStream(java.io.OutputStream) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 35 with Project

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

the class GetModelsCommand method internalRespond.

protected void internalRespond(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Project project = null;
    // This command also supports retrieving rows for an importing job.
    String importingJobID = request.getParameter("importingJobID");
    if (importingJobID != null) {
        long jobID = Long.parseLong(importingJobID);
        ImportingJob job = ImportingManager.getJob(jobID);
        if (job != null) {
            project = job.project;
        }
    }
    if (project == null) {
        project = getProject(request);
    }
    response.setHeader("Cache-Control", "no-cache");
    Map<String, LanguageInfo> prefixesMap = new HashMap<>();
    for (String languagePrefix : MetaParser.getLanguagePrefixes()) {
        LanguageInfo info = MetaParser.getLanguageInfo(languagePrefix);
        prefixesMap.put(languagePrefix, info);
    }
    Map<String, HttpHeaderInfo> headersMap = new HashMap<>();
    for (String headerLabel : HttpHeadersSupport.getHttpHeaderLabels()) {
        HttpHeaderInfo info = HttpHeadersSupport.getHttpHeaderInfo(headerLabel);
        headersMap.put(headerLabel, info);
    }
    respondJSON(response, new ModelsResponse(project.columnModel, project.recordModel, project.overlayModels, prefixesMap, headersMap));
}
Also used : Project(com.google.refine.model.Project) LanguageInfo(com.google.refine.expr.MetaParser.LanguageInfo) HashMap(java.util.HashMap) ImportingJob(com.google.refine.importing.ImportingJob) HttpHeaderInfo(com.google.refine.commands.HttpHeadersSupport.HttpHeaderInfo)

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