Search in sources :

Example 6 with WikibaseSchema

use of org.openrefine.wikidata.schema.WikibaseSchema 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

WikibaseSchema (org.openrefine.wikidata.schema.WikibaseSchema)6 Project (com.google.refine.model.Project)3 Test (org.testng.annotations.Test)3 Engine (com.google.refine.browsing.Engine)2 IOException (java.io.IOException)2 Properties (java.util.Properties)2 ServletException (javax.servlet.ServletException)2 Command (com.google.refine.commands.Command)1 Change (com.google.refine.history.Change)1 AbstractOperation (com.google.refine.model.AbstractOperation)1 Process (com.google.refine.process.Process)1 LineNumberReader (java.io.LineNumberReader)1 StringWriter (java.io.StringWriter)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 CommandTest (org.openrefine.wikidata.commands.CommandTest)1 CommandUtilities.respondError (org.openrefine.wikidata.commands.CommandUtilities.respondError)1 Manifest (org.openrefine.wikidata.manifests.Manifest)1