Add infrastructure to let scrutinizers report more details
This commit is contained in:
parent
c844742395
commit
abc51235c6
@ -1,5 +1,7 @@
|
|||||||
package org.openrefine.wikidata.qa;
|
package org.openrefine.wikidata.qa;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.openrefine.wikidata.utils.JacksonJsonizable;
|
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
|
// The number of times this issue was found
|
||||||
private int count;
|
private int count;
|
||||||
// Other details about the warning, that can be displayed to the user
|
// 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
|
@JsonCreator
|
||||||
public QAWarning(
|
public QAWarning(
|
||||||
@ -41,7 +51,7 @@ public class QAWarning extends JacksonJsonizable implements Comparable<QAWarning
|
|||||||
@JsonProperty("bucket_id") String bucketId,
|
@JsonProperty("bucket_id") String bucketId,
|
||||||
@JsonProperty("severity") Severity severity,
|
@JsonProperty("severity") Severity severity,
|
||||||
@JsonProperty("count") int count,
|
@JsonProperty("count") int count,
|
||||||
@JsonProperty("properties") Properties properties) {
|
@JsonProperty("properties") Map<String,Object> properties) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.bucketId = bucketId;
|
this.bucketId = bucketId;
|
||||||
this.severity = severity;
|
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")
|
@JsonProperty("type")
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type;
|
||||||
@ -94,7 +114,7 @@ public class QAWarning extends JacksonJsonizable implements Comparable<QAWarning
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty("properties")
|
@JsonProperty("properties")
|
||||||
public Properties getProperties() {
|
public Map<String,Object> getProperties() {
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package org.openrefine.wikidata.qa.scrutinizers;
|
package org.openrefine.wikidata.qa.scrutinizers;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.openrefine.wikidata.qa.ConstraintFetcher;
|
import org.openrefine.wikidata.qa.ConstraintFetcher;
|
||||||
import org.openrefine.wikidata.qa.QAWarning;
|
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.ItemUpdate;
|
import org.openrefine.wikidata.schema.ItemUpdate;
|
||||||
|
|
||||||
@ -31,36 +32,45 @@ public abstract class EditScrutinizer {
|
|||||||
* @param edit: the list of ItemUpdates to scrutinize
|
* @param edit: the list of ItemUpdates to scrutinize
|
||||||
*/
|
*/
|
||||||
public abstract void scrutinize(List<ItemUpdate> edit);
|
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
|
* @param warning
|
||||||
*/
|
*/
|
||||||
protected void info(String type) {
|
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
|
* @param warning
|
||||||
*/
|
*/
|
||||||
protected void warning(String type) {
|
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
|
* @param warning
|
||||||
*/
|
*/
|
||||||
protected void important(String type) {
|
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
|
* @param warning
|
||||||
*/
|
*/
|
||||||
protected void critical(String type) {
|
protected void critical(String type) {
|
||||||
_store.addWarning(new QAWarning(type, null, QAWarning.Severity.CRITICAL, 1, new Properties()));
|
addIssue(type, null, QAWarning.Severity.CRITICAL, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user