OWLSchemaPersistingManager extends SchemaPersistingManager { public void persistSchema(Reflections types) throws InconsistentAnnotationException, RepositoryException { Collection<AccessibleObject> iriAnnotatedObjects = new HashSet<>(); for(AccessibleObject object : types.getMethodsAnnotatedWith(Iri.class)) { if(!isFromLoadedBehaviour(object)) { iriAnnotatedObjects.add(object); } } for (AccessibleObject object : types.getFieldsAnnotatedWith(Iri.class)) { if(!isFromLoadedBehaviour(object)) { iriAnnotatedObjects.add(object); } } checkSchemaAnnotationConsistency(iriAnnotatedObjects); validateAgainstExistingSchema(iriAnnotatedObjects); persistInheritance(types.getTypesAnnotatedWith(Iri.class)); persistPropertyCharacteristics(iriAnnotatedObjects); persistPropertyRestrictions(iriAnnotatedObjects); } OWLSchemaPersistingManager(ObjectConnection connection); void persistSchema(Reflections types);  }
@Test public void testAnnotationPersisting() throws Exception { Anno4j anno4j = new Anno4j(); Reflections types = new Reflections( new ConfigurationBuilder() .setUrls( ClasspathHelper.forClass(Person.class, ClasspathHelper.staticClassLoader()), ClasspathHelper.forClass(PersonSupport.class, ClasspathHelper.staticClassLoader()) ) .setScanners(new MethodAnnotationsScanner(), new FieldAnnotationsScanner(), new TypeAnnotationsScanner(), new SubTypesScanner()) ); Transaction transaction = anno4j.createTransaction(); transaction.begin(); SchemaPersistingManager persistingManager = new OWLSchemaPersistingManager(transaction.getConnection()); persistingManager.persistSchema(types); String q = QUERY_PREFIX + "ASK { " + " <http: " <http: " <http: " <http: " <http: " <http: " <http: "}"; BooleanQuery characteristicsQuery = transaction.getConnection().prepareBooleanQuery(QueryLanguage.SPARQL, q); assertTrue(characteristicsQuery.evaluate()); q = QUERY_PREFIX + "ASK { " + " ?r1 a owl:Restriction . " + " <http: " ?r1 owl:onProperty <http: " ?r1 owl:minCardinality ?v1 . " + " FILTER ( ?v1 = 1 )" + " ?r2 a owl:Restriction . " + " <http: " ?r2 owl:onProperty <http: " ?r2 owl:maxCardinality ?v2 . " + " FILTER ( ?v2 = 1 )" + " ?r3 a owl:Restriction . " + " <http: " ?r3 owl:onProperty <http: " ?r3 owl:onClass <http: " ?r3 owl:minQualifiedCardinality ?v3 . " + " FILTER ( ?v3 = 0 )" + " ?r4 a owl:Restriction . " + " <http: " ?r4 owl:onProperty <http: " ?r4 owl:allValuesFrom <http: " ?r5 a owl:Restriction . " + " <http: " ?r5 owl:onProperty <http: " ?r5 owl:minCardinality ?v5 . " + " FILTER( ?v5 = 2 )" + " ?r6 a owl:Restriction . " + " <http: " ?r6 owl:onProperty <http: " ?r6 owl:minQualifiedCardinality ?v6 . " + " ?r6 owl:onClass <http: " FILTER( ?v6 = 1 )" + "}"; BooleanQuery restrictionQuery = transaction.getConnection().prepareBooleanQuery(QueryLanguage.SPARQL, q); assertTrue(restrictionQuery.evaluate()); }
@Test public void testContradictoryExistingSchema() throws Exception { Anno4j anno4j = new Anno4j(); Transaction setupTransaction = anno4j.createTransaction(); setupTransaction.begin(); setupTransaction.getConnection().prepareUpdate("INSERT DATA {" + " <http: " _:restr a owl:Restriction . " + " _:restr owl:onProperty <http: " _:restr owl:minCardinality '42'^^xsd:nonNegativeInteger . " + "}").execute(); setupTransaction.commit(); Transaction transaction = anno4j.createTransaction(); transaction.begin(); SchemaPersistingManager persistingManager = new OWLSchemaPersistingManager(transaction.getConnection()); Reflections types = new Reflections( new ConfigurationBuilder() .setUrls( ClasspathHelper.forClass(Person.class, ClasspathHelper.staticClassLoader()), ClasspathHelper.forClass(PersonSupport.class, ClasspathHelper.staticClassLoader()) ) .setScanners(new MethodAnnotationsScanner(), new FieldAnnotationsScanner(), new TypeAnnotationsScanner(), new SubTypesScanner()) ); boolean exceptionThrown = false; try { persistingManager.persistSchema(types); } catch (SchemaPersistingManager.ContradictorySchemaException e) { exceptionThrown = true; } assertTrue(exceptionThrown); }