-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backend API changes to support hierarchy descriptors
- Loading branch information
1 parent
43ca492
commit 01bccb8
Showing
35 changed files
with
1,119 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...java/edu/stanford/protege/webprotege/hierarchy/AnnotationPropertyHierarchyDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package edu.stanford.protege.webprotege.hierarchy; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import org.semanticweb.owlapi.model.OWLAnnotationProperty; | ||
import org.semanticweb.owlapi.vocab.OWLRDFVocabulary; | ||
import uk.ac.manchester.cs.owl.owlapi.OWLAnnotationPropertyImpl; | ||
import uk.ac.manchester.cs.owl.owlapi.OWLObjectPropertyImpl; | ||
|
||
import java.util.Set; | ||
|
||
@JsonTypeName("AnnotationPropertyHierarchyDescriptor") | ||
public record AnnotationPropertyHierarchyDescriptor(@JsonProperty("roots") Set<OWLAnnotationProperty> roots) implements HierarchyDescriptor { | ||
|
||
public AnnotationPropertyHierarchyDescriptor(@JsonProperty("roots") Set<OWLAnnotationProperty> roots) { | ||
this.roots = Set.copyOf(roots); | ||
} | ||
|
||
public static AnnotationPropertyHierarchyDescriptor create() { | ||
return new AnnotationPropertyHierarchyDescriptor(Set.of()); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/edu/stanford/protege/webprotege/hierarchy/ClassHierarchyDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package edu.stanford.protege.webprotege.hierarchy; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import org.semanticweb.owlapi.model.OWLClass; | ||
import org.semanticweb.owlapi.vocab.OWLRDFVocabulary; | ||
import uk.ac.manchester.cs.owl.owlapi.OWLClassImpl; | ||
|
||
import java.util.Set; | ||
|
||
@JsonTypeName("ClassHierarchyDescriptor") | ||
public record ClassHierarchyDescriptor(@JsonProperty("roots") Set<OWLClass> roots) implements HierarchyDescriptor { | ||
|
||
public ClassHierarchyDescriptor(Set<OWLClass> roots) { | ||
this.roots = Set.copyOf(roots); | ||
} | ||
|
||
@JsonCreator | ||
public static ClassHierarchyDescriptor create(@JsonProperty("roots") Set<OWLClass> roots) { | ||
return new ClassHierarchyDescriptor(roots); | ||
} | ||
|
||
public static ClassHierarchyDescriptor create() { | ||
return create(Set.of(new OWLClassImpl(OWLRDFVocabulary.OWL_THING.getIRI()))); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/edu/stanford/protege/webprotege/hierarchy/DataPropertyHierarchyDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package edu.stanford.protege.webprotege.hierarchy; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import org.semanticweb.owlapi.model.OWLDataProperty; | ||
import org.semanticweb.owlapi.vocab.OWLRDFVocabulary; | ||
import uk.ac.manchester.cs.owl.owlapi.OWLDataPropertyImpl; | ||
import uk.ac.manchester.cs.owl.owlapi.OWLObjectPropertyImpl; | ||
|
||
import java.util.Set; | ||
|
||
@JsonTypeName("DataPropertyHierarchyDescriptor") | ||
public record DataPropertyHierarchyDescriptor(@JsonProperty("roots") Set<OWLDataProperty> roots) implements HierarchyDescriptor { | ||
|
||
public DataPropertyHierarchyDescriptor(Set<OWLDataProperty> roots) { | ||
this.roots = Set.copyOf(roots); | ||
} | ||
|
||
public static DataPropertyHierarchyDescriptor create() { | ||
return new DataPropertyHierarchyDescriptor(Set.of(new OWLDataPropertyImpl(OWLRDFVocabulary.OWL_TOP_DATA_PROPERTY.getIRI()))); | ||
} | ||
} |
18 changes: 14 additions & 4 deletions
18
src/main/java/edu/stanford/protege/webprotege/hierarchy/EntityHierarchyChangedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/edu/stanford/protege/webprotege/hierarchy/HierarchyDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package edu.stanford.protege.webprotege.hierarchy; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(ClassHierarchyDescriptor.class), | ||
@JsonSubTypes.Type(ObjectPropertyHierarchyDescriptor.class), | ||
@JsonSubTypes.Type(DataPropertyHierarchyDescriptor.class), | ||
@JsonSubTypes.Type(AnnotationPropertyHierarchyDescriptor.class) | ||
}) | ||
public sealed interface HierarchyDescriptor permits ClassHierarchyDescriptor, ObjectPropertyHierarchyDescriptor, DataPropertyHierarchyDescriptor, AnnotationPropertyHierarchyDescriptor { | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...ain/java/edu/stanford/protege/webprotege/hierarchy/ObjectPropertyHierarchyDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package edu.stanford.protege.webprotege.hierarchy; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import org.semanticweb.owlapi.model.OWLObjectProperty; | ||
import org.semanticweb.owlapi.vocab.OWLRDFVocabulary; | ||
import uk.ac.manchester.cs.owl.owlapi.OWLObjectPropertyImpl; | ||
|
||
import java.util.Set; | ||
|
||
@JsonTypeName("ObjectPropertyHierarchyDescriptor") | ||
public record ObjectPropertyHierarchyDescriptor(@JsonProperty("roots") Set<OWLObjectProperty> roots) implements HierarchyDescriptor { | ||
|
||
public ObjectPropertyHierarchyDescriptor(Set<OWLObjectProperty> roots) { | ||
this.roots = Set.copyOf(roots); | ||
} | ||
|
||
public static ObjectPropertyHierarchyDescriptor create() { | ||
return new ObjectPropertyHierarchyDescriptor(Set.of(new OWLObjectPropertyImpl(OWLRDFVocabulary.OWL_TOP_OBJECT_PROPERTY.getIRI()))); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
.../stanford/protege/webprotege/hierarchy/AnnotationPropertyHierarchyDescriptorJsonTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package edu.stanford.protege.webprotege.hierarchy; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.semanticweb.owlapi.model.IRI; | ||
import org.semanticweb.owlapi.model.OWLDataFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.json.JsonTest; | ||
import org.springframework.boot.test.json.JacksonTester; | ||
|
||
import java.util.Set; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@JsonTest | ||
class AnnotationPropertyHierarchyDescriptorJsonTest { | ||
|
||
|
||
public static final String ROOT_IRI = "http://example.org/prop"; | ||
@Autowired | ||
private JacksonTester<AnnotationPropertyHierarchyDescriptor> jacksonTester; | ||
|
||
@Autowired | ||
private OWLDataFactory dataFactory; | ||
|
||
@Test | ||
void testSerializeClassHierarchyDescriptor() throws Exception { | ||
var prop = dataFactory.getOWLAnnotationProperty(IRI.create(ROOT_IRI)); | ||
var descriptor = new AnnotationPropertyHierarchyDescriptor(Set.of(prop)); | ||
var json = jacksonTester.write(descriptor); | ||
|
||
// Check for the correct JSON structure | ||
assertThat(json).hasJsonPathArrayValue("roots") | ||
.extractingJsonPathStringValue("roots[0].iri") | ||
.isEqualTo(ROOT_IRI); | ||
|
||
// Assert that the @type is correct | ||
assertThat(json).extractingJsonPathStringValue("['@type']") | ||
.isEqualTo("AnnotationPropertyHierarchyDescriptor"); | ||
} | ||
|
||
@Test | ||
void testDeserializeClassHierarchyDescriptor() throws Exception { | ||
var json = """ | ||
{ | ||
"@type": "AnnotationPropertyHierarchyDescriptor", | ||
"roots": [ | ||
{ | ||
"@type" : "AnnotationProperty", | ||
"iri": "http://example.org/prop" | ||
} | ||
] | ||
} | ||
"""; | ||
|
||
var objectContent = jacksonTester.parse(json); | ||
var descriptor = objectContent.getObject(); | ||
|
||
assertThat(descriptor).isNotNull(); | ||
assertThat(descriptor.roots()).hasSize(1); | ||
var rootClass = descriptor.roots().iterator().next(); | ||
assertThat(rootClass.getIRI().toString()).isEqualTo(ROOT_IRI); | ||
} | ||
} |
Oops, something went wrong.