Move exceptions to own package

This commit is contained in:
Antonin Delpeuch 2018-01-11 10:15:48 +00:00
parent 5d9aa9cae5
commit bf7000e601
25 changed files with 61 additions and 37 deletions

View File

@ -1,6 +0,0 @@
package org.openrefine.wikidata.schema;
public class SkipStatementException extends Exception {
static final long serialVersionUID = 738592057L;
}

View File

@ -7,6 +7,7 @@ import java.util.Map.Entry;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
import org.wikidata.wdtk.datamodel.interfaces.TimeValue;
@ -38,9 +39,9 @@ public class WbDateConstant extends WbDateExpr {
@Override
public TimeValue evaluate(ExpressionContext ctxt)
throws SkipStatementException {
throws SkipSchemaExpressionException {
if (parsed == null) {
throw new SkipStatementException();
throw new SkipSchemaExpressionException();
}
return parsed;
}

View File

@ -1,10 +1,11 @@
package org.openrefine.wikidata.schema;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.wikidata.wdtk.datamodel.interfaces.TimeValue;
public abstract class WbDateExpr extends WbValueExpr {
@Override
public abstract TimeValue evaluate(ExpressionContext ctxt)
throws SkipStatementException;
throws SkipSchemaExpressionException;
}

View File

@ -2,6 +2,7 @@ package org.openrefine.wikidata.schema;
import java.text.ParseException;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.wikidata.wdtk.datamodel.interfaces.TimeValue;
import com.fasterxml.jackson.annotation.JsonCreator;
@ -22,7 +23,7 @@ public class WbDateVariable extends WbDateExpr {
@Override
public TimeValue evaluate(ExpressionContext ctxt)
throws SkipStatementException {
throws SkipSchemaExpressionException {
Cell cell = ctxt.getCellByName(columnName);
if (cell != null) {
try {
@ -31,7 +32,7 @@ public class WbDateVariable extends WbDateExpr {
} catch (ParseException e) {
}
}
throw new SkipStatementException();
throw new SkipSchemaExpressionException();
}
public String getColumnName() {

View File

@ -2,6 +2,7 @@ package org.openrefine.wikidata.schema;
import java.util.List;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.openrefine.wikidata.utils.JacksonJsonizable;
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
import org.wikidata.wdtk.datamodel.interfaces.Statement;
@ -26,7 +27,7 @@ public class WbItemDocumentExpr extends JacksonJsonizable {
this.statementGroups = statementGroupExprs;
}
public ItemUpdate evaluate(ExpressionContext ctxt) throws SkipStatementException {
public ItemUpdate evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException {
ItemIdValue subjectId = getSubject().evaluate(ctxt);
ItemUpdate update = new ItemUpdate(subjectId);
for(WbStatementGroupExpr expr : getStatementGroups()) {

View File

@ -2,9 +2,10 @@ package org.openrefine.wikidata.schema;
import org.openrefine.wikidata.schema.ExpressionContext;
import org.openrefine.wikidata.schema.WbValueExpr;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
public abstract class WbItemExpr extends WbValueExpr {
public abstract ItemIdValue evaluate(ExpressionContext ctxt) throws SkipStatementException;
public abstract ItemIdValue evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException;
}

View File

@ -3,6 +3,7 @@ package org.openrefine.wikidata.schema;
import org.openrefine.wikidata.schema.entityvalues.NewEntityIdValue;
import org.openrefine.wikidata.schema.entityvalues.TermedItemIdValue;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
@ -25,7 +26,7 @@ public class WbItemVariable extends WbItemExpr {
}
@Override
public ItemIdValue evaluate(ExpressionContext ctxt) throws SkipStatementException {
public ItemIdValue evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException {
Cell cell = ctxt.getCellByName(getColumnName());
if (cell != null && cell.recon != null) {
Recon recon = cell.recon;
@ -48,7 +49,7 @@ public class WbItemVariable extends WbItemExpr {
rowId, columnId, siteIRI, label);
}
}
throw new SkipStatementException();
throw new SkipSchemaExpressionException();
}
public String getColumnName() {

View File

@ -1,5 +1,7 @@
package org.openrefine.wikidata.schema;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -18,7 +20,7 @@ public class WbLanguageConstant extends WbLanguageExpr {
_langLabel = langLabel;
}
public String evaluate(ExpressionContext ctxt) throws SkipStatementException {
public String evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException {
return _langId;
}

View File

@ -1,5 +1,6 @@
package org.openrefine.wikidata.schema;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.openrefine.wikidata.utils.JacksonJsonizable;
import com.fasterxml.jackson.annotation.JsonSubTypes;
@ -19,7 +20,7 @@ public abstract class WbLanguageExpr extends JacksonJsonizable {
*
* @param ctxt the evaluation context
* @return a Wikimedia language code
* @throws SkipStatementException when the code is invalid
* @throws SkipSchemaExpressionException when the code is invalid
*/
public abstract String evaluate(ExpressionContext ctxt) throws SkipStatementException;
public abstract String evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException;
}

View File

@ -1,5 +1,7 @@
package org.openrefine.wikidata.schema;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -18,13 +20,13 @@ public class WbLanguageVariable extends WbLanguageExpr {
@Override
public String evaluate(ExpressionContext ctxt)
throws SkipStatementException {
throws SkipSchemaExpressionException {
Cell cell = ctxt.getCellByName(getColumnName());
if (cell != null) {
// TODO some validation here?
return cell.value.toString();
}
throw new SkipStatementException();
throw new SkipSchemaExpressionException();
}
public String getColumnName() {

View File

@ -2,6 +2,7 @@ package org.openrefine.wikidata.schema;
import java.text.ParseException;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
import org.wikidata.wdtk.datamodel.interfaces.GlobeCoordinatesValue;
@ -48,9 +49,9 @@ public class WbLocationConstant extends WbLocationExpr {
@Override
public GlobeCoordinatesValue evaluate(ExpressionContext ctxt)
throws SkipStatementException {
throws SkipSchemaExpressionException {
if (parsed == null)
throw new SkipStatementException();
throw new SkipSchemaExpressionException();
return parsed;
}

View File

@ -1,9 +1,10 @@
package org.openrefine.wikidata.schema;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.wikidata.wdtk.datamodel.interfaces.GlobeCoordinatesValue;
public abstract class WbLocationExpr extends WbValueExpr {
@Override
public abstract GlobeCoordinatesValue evaluate(ExpressionContext ctxt)
throws SkipStatementException;
throws SkipSchemaExpressionException;
}

View File

@ -2,6 +2,7 @@ package org.openrefine.wikidata.schema;
import java.text.ParseException;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.wikidata.wdtk.datamodel.interfaces.GlobeCoordinatesValue;
import com.fasterxml.jackson.annotation.JsonCreator;
@ -22,7 +23,7 @@ public class WbLocationVariable extends WbLocationExpr {
@Override
public GlobeCoordinatesValue evaluate(ExpressionContext ctxt)
throws SkipStatementException {
throws SkipSchemaExpressionException {
Cell cell = ctxt.getCellByName(getColumnName());
if (cell != null) {
String expr = cell.value.toString();
@ -31,7 +32,7 @@ public class WbLocationVariable extends WbLocationExpr {
} catch (ParseException e) {
}
}
throw new SkipStatementException();
throw new SkipSchemaExpressionException();
}
public String getColumnName() {

View File

@ -1,5 +1,6 @@
package org.openrefine.wikidata.schema;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue;
@ -22,7 +23,7 @@ public class WbMonolingualExpr extends WbValueExpr {
@Override
public MonolingualTextValue evaluate(ExpressionContext ctxt)
throws SkipStatementException {
throws SkipSchemaExpressionException {
return Datamodel.makeMonolingualTextValue(
getValueExpr().evaluate(ctxt).getString(),
getLanguageExpr().evaluate(ctxt));

View File

@ -1,5 +1,6 @@
package org.openrefine.wikidata.schema;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.openrefine.wikidata.utils.JacksonJsonizable;
import org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue;
@ -40,7 +41,7 @@ public class WbNameDescExpr extends JacksonJsonizable {
item.addAlias(val);
break;
}
} catch (SkipStatementException e) {
} catch (SkipSchemaExpressionException e) {
return;
}
}

View File

@ -3,6 +3,7 @@ package org.openrefine.wikidata.schema;
import java.util.ArrayList;
import java.util.List;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.openrefine.wikidata.utils.JacksonJsonizable;
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
import org.wikidata.wdtk.datamodel.interfaces.Reference;
@ -22,7 +23,7 @@ public class WbReferenceExpr extends JacksonJsonizable {
this.snakExprs = snakExprs;
}
public Reference evaluate(ExpressionContext ctxt) throws SkipStatementException {
public Reference evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException {
List<SnakGroup> snakGroups = new ArrayList<SnakGroup>();
for (WbSnakExpr expr : getSnaks()) {
List<Snak> snakList = new ArrayList<Snak>(1);

View File

@ -1,5 +1,6 @@
package org.openrefine.wikidata.schema;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.openrefine.wikidata.utils.JacksonJsonizable;
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
@ -23,7 +24,7 @@ public class WbSnakExpr extends JacksonJsonizable {
this.value = valueExpr;
}
public Snak evaluate(ExpressionContext ctxt) throws SkipStatementException {
public Snak evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException {
PropertyIdValue propertyId = getProp().evaluate(ctxt);
Value evaluatedValue = value.evaluate(ctxt);
return Datamodel.makeValueSnak(propertyId, evaluatedValue);

View File

@ -10,6 +10,7 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.openrefine.wikidata.utils.JacksonJsonizable;
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
import org.wikidata.wdtk.datamodel.interfaces.Claim;
@ -52,7 +53,7 @@ public class WbStatementExpr extends JacksonJsonizable {
return snakGroups;
}
public Statement evaluate(ExpressionContext ctxt, ItemIdValue subject, PropertyIdValue propertyId) throws SkipStatementException {
public Statement evaluate(ExpressionContext ctxt, ItemIdValue subject, PropertyIdValue propertyId) throws SkipSchemaExpressionException {
Value mainSnakValue = getMainsnak().evaluate(ctxt);
Snak mainSnak = Datamodel.makeValueSnak(propertyId, mainSnakValue);

View File

@ -3,6 +3,7 @@ package org.openrefine.wikidata.schema;
import java.util.ArrayList;
import java.util.List;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.openrefine.wikidata.utils.JacksonJsonizable;
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
@ -27,7 +28,7 @@ public class WbStatementGroupExpr extends JacksonJsonizable {
this.statementExprs = claimExprs;
}
public StatementGroup evaluate(ExpressionContext ctxt, ItemIdValue subject) throws SkipStatementException {
public StatementGroup evaluate(ExpressionContext ctxt, ItemIdValue subject) throws SkipSchemaExpressionException {
PropertyIdValue propertyId = propertyExpr.evaluate(ctxt);
List<Statement> statements = new ArrayList<Statement>(statementExprs.size());
for(WbStatementExpr expr : statementExprs) {

View File

@ -1,7 +1,8 @@
package org.openrefine.wikidata.schema;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.wikidata.wdtk.datamodel.interfaces.StringValue;
public abstract class WbStringExpr extends WbValueExpr {
public abstract StringValue evaluate(ExpressionContext ctxt) throws SkipStatementException;
public abstract StringValue evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException;
}

View File

@ -1,5 +1,6 @@
package org.openrefine.wikidata.schema;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.wikidata.wdtk.datamodel.helpers.Datamodel;
import org.wikidata.wdtk.datamodel.interfaces.StringValue;
@ -21,12 +22,12 @@ public class WbStringVariable extends WbStringExpr {
@Override
public StringValue evaluate(ExpressionContext ctxt)
throws SkipStatementException {
throws SkipSchemaExpressionException {
Cell cell = ctxt.getCellByName(columnName);
if (cell != null) {
return Datamodel.makeStringValue(cell.value.toString());
}
throw new SkipStatementException();
throw new SkipSchemaExpressionException();
}
public String getColumnName() {

View File

@ -3,6 +3,7 @@ package org.openrefine.wikidata.schema;
import org.json.JSONException;
import org.json.JSONObject;
import org.wikidata.wdtk.datamodel.interfaces.Value;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.openrefine.wikidata.utils.JacksonJsonizable;
import com.fasterxml.jackson.annotation.JsonSubTypes;
@ -36,7 +37,7 @@ public abstract class WbValueExpr extends JacksonJsonizable {
* Evaluates the value expression in a given context,
* returns a wikibase value suitable to be the target of a claim.
*/
public abstract Value evaluate(ExpressionContext ctxt) throws SkipStatementException;
public abstract Value evaluate(ExpressionContext ctxt) throws SkipSchemaExpressionException;
public static WbValueExpr fromJSON(JSONObject obj) throws JSONException {
return fromJSONClass(obj, WbValueExpr.class);

View File

@ -25,6 +25,7 @@ import com.google.refine.model.OverlayModel;
import com.google.refine.model.Project;
import com.google.refine.model.Row;
import org.openrefine.wikidata.schema.WbItemDocumentExpr;
import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException;
import org.openrefine.wikidata.schema.ExpressionContext;
import org.openrefine.wikidata.utils.JacksonJsonizable;
@ -81,7 +82,7 @@ public class WikibaseSchema implements OverlayModel {
try {
result.add(expr.evaluate(ctxt));
} catch (SkipStatementException e) {
} catch (SkipSchemaExpressionException e) {
continue;
}
}

View File

@ -1,4 +1,4 @@
package org.openrefine.wikidata.schema;
package org.openrefine.wikidata.schema.exceptions;
public class InvalidSchemaException extends Exception {

View File

@ -0,0 +1,6 @@
package org.openrefine.wikidata.schema.exceptions;
public class SkipSchemaExpressionException extends Exception {
static final long serialVersionUID = 738592057L;
}