Search in sources :

Example 1 with OverlayModel

use of com.google.refine.model.OverlayModel 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);
    }
    try {
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Type", "application/json");
        response.setHeader("Cache-Control", "no-cache");
        Properties options = new Properties();
        JSONWriter writer = new JSONWriter(response.getWriter());
        writer.object();
        writer.key("columnModel");
        project.columnModel.write(writer, options);
        writer.key("recordModel");
        project.recordModel.write(writer, options);
        writer.key("overlayModels");
        writer.object();
        for (String modelName : project.overlayModels.keySet()) {
            OverlayModel overlayModel = project.overlayModels.get(modelName);
            if (overlayModel != null) {
                writer.key(modelName);
                project.overlayModels.get(modelName).write(writer, options);
            }
        }
        writer.endObject();
        writer.key("scripting");
        writer.object();
        for (String languagePrefix : MetaParser.getLanguagePrefixes()) {
            LanguageInfo info = MetaParser.getLanguageInfo(languagePrefix);
            writer.key(languagePrefix);
            writer.object();
            writer.key("name");
            writer.value(info.name);
            writer.key("defaultExpression");
            writer.value(info.defaultExpression);
            writer.endObject();
        }
        writer.endObject();
        writer.endObject();
    } catch (JSONException e) {
        HttpUtilities.respondException(response, e);
    }
}
Also used : JSONWriter(org.json.JSONWriter) Project(com.google.refine.model.Project) LanguageInfo(com.google.refine.expr.MetaParser.LanguageInfo) ImportingJob(com.google.refine.importing.ImportingJob) JSONException(org.json.JSONException) Properties(java.util.Properties) OverlayModel(com.google.refine.model.OverlayModel)

Aggregations

LanguageInfo (com.google.refine.expr.MetaParser.LanguageInfo)1 ImportingJob (com.google.refine.importing.ImportingJob)1 OverlayModel (com.google.refine.model.OverlayModel)1 Project (com.google.refine.model.Project)1 Properties (java.util.Properties)1 JSONException (org.json.JSONException)1 JSONWriter (org.json.JSONWriter)1