Search in sources :

Example 1 with SaveWikibaseSchemaOperation

use of org.openrefine.wikidata.operations.SaveWikibaseSchemaOperation in project OpenRefine by OpenRefine.

the class SaveWikibaseSchemaCommand 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 jsonString = request.getParameter("schema");
        if (jsonString == null) {
            respondError(response, "No Wikibase schema provided.");
            return;
        }
        WikibaseSchema schema = ParsingUtilities.mapper.readValue(jsonString, WikibaseSchema.class);
        AbstractOperation op = new SaveWikibaseSchemaOperation(schema);
        Process process = op.createProcess(project, new Properties());
        performProcessAndRespond(request, response, project, process);
    } catch (IOException e) {
        // We do not use respondException here because this is an expected
        // exception which happens every time a user tries to save an incomplete
        // schema - the exception should not be logged.
        respondError(response, String.format("Wikibase schema could not be parsed: ", e.getMessage()));
    } catch (Exception e) {
        // This is an unexpected exception, so we log it.
        respondException(response, e);
    }
}
Also used : Project(com.google.refine.model.Project) AbstractOperation(com.google.refine.model.AbstractOperation) SaveWikibaseSchemaOperation(org.openrefine.wikidata.operations.SaveWikibaseSchemaOperation) WikibaseSchema(org.openrefine.wikidata.schema.WikibaseSchema) Process(com.google.refine.process.Process) IOException(java.io.IOException) Properties(java.util.Properties) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

AbstractOperation (com.google.refine.model.AbstractOperation)1 Project (com.google.refine.model.Project)1 Process (com.google.refine.process.Process)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 ServletException (javax.servlet.ServletException)1 SaveWikibaseSchemaOperation (org.openrefine.wikidata.operations.SaveWikibaseSchemaOperation)1 WikibaseSchema (org.openrefine.wikidata.schema.WikibaseSchema)1