Separate out PreviewResults from Wikidata extension
This commit is contained in:
parent
292700c6f4
commit
49a89c301b
@ -0,0 +1,68 @@
|
|||||||
|
package org.openrefine.wikidata.commands;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.openrefine.wikidata.qa.QAWarning;
|
||||||
|
import org.openrefine.wikidata.qa.QAWarning.Severity;
|
||||||
|
import org.openrefine.wikidata.updates.ItemUpdate;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
public class PreviewResults {
|
||||||
|
|
||||||
|
protected List<QAWarning> warnings;
|
||||||
|
protected Severity maxSeverity;
|
||||||
|
protected int nbWarnings;
|
||||||
|
protected int editCount;
|
||||||
|
protected List<ItemUpdate> editsPreview;
|
||||||
|
|
||||||
|
@JsonProperty("warnings")
|
||||||
|
public List<QAWarning> getWarnings() {
|
||||||
|
return warnings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("max_severity")
|
||||||
|
public Severity getMaxSeverity() {
|
||||||
|
return maxSeverity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("nb_warnings")
|
||||||
|
public int getNbWarnings() {
|
||||||
|
return nbWarnings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("edit_count")
|
||||||
|
public int getEditCount() {
|
||||||
|
return editCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("edits_preview")
|
||||||
|
public List<ItemUpdate> getEditsPreview() {
|
||||||
|
return editsPreview;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PreviewResults(
|
||||||
|
List<QAWarning> warnings,
|
||||||
|
Severity maxSeverity,
|
||||||
|
int nbWarnings,
|
||||||
|
int editCount,
|
||||||
|
List<ItemUpdate> editsPreview) {
|
||||||
|
this.warnings = warnings;
|
||||||
|
this.maxSeverity = maxSeverity;
|
||||||
|
this.nbWarnings = nbWarnings;
|
||||||
|
this.editCount = editCount;
|
||||||
|
this.editsPreview = editsPreview;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
try {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
return mapper.writeValueAsString(this);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
return super.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -35,50 +35,18 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.openrefine.wikidata.qa.EditInspector;
|
import org.openrefine.wikidata.qa.EditInspector;
|
||||||
import org.openrefine.wikidata.qa.QAWarning;
|
|
||||||
import org.openrefine.wikidata.qa.QAWarning.Severity;
|
|
||||||
import org.openrefine.wikidata.qa.QAWarningStore;
|
import org.openrefine.wikidata.qa.QAWarningStore;
|
||||||
import org.openrefine.wikidata.schema.WikibaseSchema;
|
import org.openrefine.wikidata.schema.WikibaseSchema;
|
||||||
import org.openrefine.wikidata.updates.ItemUpdate;
|
import org.openrefine.wikidata.updates.ItemUpdate;
|
||||||
import org.openrefine.wikidata.updates.scheduler.WikibaseAPIUpdateScheduler;
|
import org.openrefine.wikidata.updates.scheduler.WikibaseAPIUpdateScheduler;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import static org.openrefine.wikidata.commands.CommandUtilities.respondError;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
|
|
||||||
import com.google.refine.browsing.Engine;
|
import com.google.refine.browsing.Engine;
|
||||||
import com.google.refine.commands.Command;
|
import com.google.refine.commands.Command;
|
||||||
import com.google.refine.model.Project;
|
import com.google.refine.model.Project;
|
||||||
|
import com.google.refine.util.ParsingUtilities;
|
||||||
|
|
||||||
public class PreviewWikibaseSchemaCommand extends Command {
|
public class PreviewWikibaseSchemaCommand extends Command {
|
||||||
|
|
||||||
protected static class PreviewResults {
|
|
||||||
@JsonProperty("warnings")
|
|
||||||
List<QAWarning> warnings;
|
|
||||||
@JsonProperty("max_severity")
|
|
||||||
Severity maxSeverity;
|
|
||||||
@JsonProperty("nb_warnings")
|
|
||||||
int nbWarnings;
|
|
||||||
@JsonProperty("edit_count")
|
|
||||||
int editCount;
|
|
||||||
@JsonProperty("edits_preview")
|
|
||||||
List<ItemUpdate> editsPreview;
|
|
||||||
|
|
||||||
protected PreviewResults(
|
|
||||||
List<QAWarning> warnings,
|
|
||||||
Severity maxSeverity,
|
|
||||||
int nbWarnings,
|
|
||||||
int editCount,
|
|
||||||
List<ItemUpdate> editsPreview) {
|
|
||||||
this.warnings = warnings;
|
|
||||||
this.maxSeverity = maxSeverity;
|
|
||||||
this.nbWarnings = nbWarnings;
|
|
||||||
this.editCount = editCount;
|
|
||||||
this.editsPreview = editsPreview;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
@ -126,11 +94,12 @@ public class PreviewWikibaseSchemaCommand extends Command {
|
|||||||
.limit(10)
|
.limit(10)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
respondJSON(response, new PreviewResults(
|
PreviewResults previewResults = new PreviewResults(
|
||||||
warningStore.getWarnings(),
|
warningStore.getWarnings(),
|
||||||
warningStore.getMaxSeverity(),
|
warningStore.getMaxSeverity(),
|
||||||
warningStore.getNbWarnings(),
|
warningStore.getNbWarnings(),
|
||||||
nonNullEdits.size(), firstEdits));
|
nonNullEdits.size(), firstEdits);
|
||||||
|
respondJSON(response, previewResults);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
respondException(response, e);
|
respondException(response, e);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user