Add infrastructure to let scrutinizers report more details

This commit is contained in:
Antonin Delpeuch 2018-01-10 12:13:28 +00:00
parent c844742395
commit abc51235c6
2 changed files with 43 additions and 13 deletions

View File

@ -1,5 +1,7 @@
package org.openrefine.wikidata.qa;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.openrefine.wikidata.utils.JacksonJsonizable;
@ -33,7 +35,15 @@ public class QAWarning extends JacksonJsonizable implements Comparable<QAWarning
// The number of times this issue was found
private int count;
// Other details about the warning, that can be displayed to the user
private Properties properties;
private Map<String,Object> properties;
public QAWarning(String type, String bucketId, Severity severity, int count) {
this.type = type;
this.bucketId = bucketId;
this.severity = severity;
this.count = count;
this.properties = new HashMap<String,Object>();
}
@JsonCreator
public QAWarning(
@ -41,7 +51,7 @@ public class QAWarning extends JacksonJsonizable implements Comparable<QAWarning
@JsonProperty("bucket_id") String bucketId,
@JsonProperty("severity") Severity severity,
@JsonProperty("count") int count,
@JsonProperty("properties") Properties properties) {
@JsonProperty("properties") Map<String,Object> properties) {
this.type = type;
this.bucketId = bucketId;
this.severity = severity;
@ -73,6 +83,16 @@ public class QAWarning extends JacksonJsonizable implements Comparable<QAWarning
}
}
/**
* Sets a property of the QA warning, to be used by the front-end
* for display.
* @param key: the name of the property
* @param value should be Jackson-serializable
*/
public void setProperty(String key, Object value) {
this.properties.put(key, value);
}
@JsonProperty("type")
public String getType() {
return type;
@ -94,7 +114,7 @@ public class QAWarning extends JacksonJsonizable implements Comparable<QAWarning
}
@JsonProperty("properties")
public Properties getProperties() {
public Map<String,Object> getProperties() {
return properties;
}

View File

@ -1,10 +1,11 @@
package org.openrefine.wikidata.qa.scrutinizers;
import java.util.List;
import java.util.Properties;
import java.util.Map;
import org.openrefine.wikidata.qa.ConstraintFetcher;
import org.openrefine.wikidata.qa.QAWarning;
import org.openrefine.wikidata.qa.QAWarning.Severity;
import org.openrefine.wikidata.qa.QAWarningStore;
import org.openrefine.wikidata.schema.ItemUpdate;
@ -31,36 +32,45 @@ public abstract class EditScrutinizer {
* @param edit: the list of ItemUpdates to scrutinize
*/
public abstract void scrutinize(List<ItemUpdate> edit);
protected void addIssue(QAWarning warning) {
_store.addWarning(warning);
}
protected void addIssue(String type, String aggregationId, Severity severity, int count) {
addIssue(new QAWarning(type, aggregationId, severity, count));
}
/**
* Helper to be used by subclasses to emit INFO warnings
* Helper to be used by subclasses to emit simple INFO warnings
* @param warning
*/
protected void info(String type) {
_store.addWarning(new QAWarning(type, null, QAWarning.Severity.INFO, 1, new Properties()));
addIssue(type, null, QAWarning.Severity.INFO, 1);
}
/**
* Helper to be used by subclasses to emit warnings
* Helper to be used by subclasses to emit simple warnings
* @param warning
*/
protected void warning(String type) {
_store.addWarning(new QAWarning(type, null, QAWarning.Severity.WARNING, 1, new Properties()));
addIssue(type, null, QAWarning.Severity.WARNING, 1);
}
/**
* Helper to be used by subclasses to emit important warnings
* Helper to be used by subclasses to emit simple important warnings
* @param warning
*/
protected void important(String type) {
_store.addWarning(new QAWarning(type, null, QAWarning.Severity.IMPORTANT, 1, new Properties()));
addIssue(type, null, QAWarning.Severity.IMPORTANT, 1);
}
/**
* Helper to be used by subclasses to emit critical warnings
* Helper to be used by subclasses to emit simple critical warnings
* @param warning
*/
protected void critical(String type) {
_store.addWarning(new QAWarning(type, null, QAWarning.Severity.CRITICAL, 1, new Properties()));
addIssue(type, null, QAWarning.Severity.CRITICAL, 1);
}
}