Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
WARN if any subjects are missing 'rdf:type', DM2E/dm2e-mappings#87
Browse files Browse the repository at this point in the history
  • Loading branch information
kba committed Apr 7, 2014
1 parent 5a6e467 commit de50b43
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public enum ValidationProblemCategory {
MISSING_CONDITIONALLY_REQUIRED_PROPERTY(" is missing required property <%s> (Condition: %s)"),
MISSING_REQUIRED_ONE_OF(" is missing one of %s"),
MISSING_CONDITIONALLY_REQUIRED_ONE_OF(" is missing required property <%s> (Condition: %s)"),

UNTYPED_RESOURCE(" has no rdf:type."),

INVALID_LITERAL(" Invalid literal value for <%s>: '%s' (%s)"),
BAD_MIMETYPE(" has unsupported MIME type '%s'."),
Expand Down
41 changes: 38 additions & 3 deletions src/main/java/eu/dm2e/validation/validator/BaseValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,27 +344,54 @@ protected void checkStatement(final Statement stmt, Dm2eValidationReport report)

}

/*
* (non-Javadoc)
*
* reg-name = *( unreserved / pct-encoded / sub-delims )
*
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" <---This seems like a
* practical shortcut, most closely resembling original answer
*
* reserved = gen-delims / sub-delims
*
* gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
*
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" /
* "="
*
* pct-encoded = "%" HEXDIG HEXDIG
*/
@Override
public Set<String> build_illegal_Uri_Strings() {
Set<String> ret = new HashSet<>();
ret.add("\r");
ret.add("\n");
ret.add("\t");
ret.add(":");
ret.add("[");
ret.add("]");
ret.add("!");
ret.add("$");
ret.add("'");
ret.add("(");
ret.add(")");
ret.add("*");
ret.add(",");
ret.add(";");
ret.add("{");
ret.add("}");
ret.add("<");
ret.add(">");
ret.add("+");
ret.add(" ");
ret.add("^");
// ret.add("?");
// ret.add("&");
ret.add("%2F"); // == '/'
ret.add("%0D"); // == '\r'
ret.add("%0A"); // == '\n'
ret.add("%09"); // == '\t'
// ret.add("%3A"); // == ':'
ret.add("%3C"); // == '<'
ret.add("%3E"); // == '>'
// ret.add("%3F"); // == '?'
return ret;
}

Expand Down Expand Up @@ -732,6 +759,14 @@ public Dm2eValidationReport validateWithDm2e(Model m) {

Dm2eValidationReport report = new Dm2eValidationReport(getVersion());

// Check that every subject has a rdf:type
ResIterator iter = m.listSubjects();
while (iter.hasNext()) {
Resource subj = iter.next();
if (! m.contains(subj, prop(m, NS.RDF.PROP_TYPE), (Resource)null)) {
report.add(ValidationLevel.WARNING, ValidationProblemCategory.UNTYPED_RESOURCE, subj);
}
}
// * check unknown elements
validateByStatement(m, report);

Expand Down
12 changes: 12 additions & 0 deletions src/test/java/eu/dm2e/validation/validator/BaseValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ public class BaseValidatorTest extends ValidationTest {
// Tests
//

@Test
public void testIssue85() throws Exception {
Model m = ModelFactory.createDefaultModel();
final Resource testAgg = res(m, "http://agg1");
final Resource testCho = res(m, "http://cho1");
testAgg.addProperty(prop(m, NS.EDM.PROP_AGGREGATED_CHO), testCho);
Dm2eValidationReport report = v1_1_rev1_2.validateWithDm2e(m);
ValidationProblemCategory expected = ValidationProblemCategory.UNTYPED_RESOURCE;
log.debug(report.toString());
containsCategory(report, expected);
}

@Test
@Ignore
public void testPropertyWhiteList() {
Expand Down

0 comments on commit de50b43

Please sign in to comment.