diff --git a/src/main/java/edu/stanford/protege/webprotege/entity/EntityNode.java b/src/main/java/edu/stanford/protege/webprotege/entity/EntityNode.java index f402e96..89b7c77 100644 --- a/src/main/java/edu/stanford/protege/webprotege/entity/EntityNode.java +++ b/src/main/java/edu/stanford/protege/webprotege/entity/EntityNode.java @@ -1,14 +1,9 @@ package edu.stanford.protege.webprotege.entity; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; + +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import edu.stanford.protege.webprotege.common.DictionaryLanguage; -import edu.stanford.protege.webprotege.common.DictionaryLanguageData; -import edu.stanford.protege.webprotege.common.ShortForm; +import com.google.common.collect.*; +import edu.stanford.protege.webprotege.common.*; import edu.stanford.protege.webprotege.tag.Tag; import edu.stanford.protege.webprotege.watches.Watch; import org.semanticweb.owlapi.model.OWLEntity; @@ -24,7 +19,7 @@ */ @AutoValue -public abstract class EntityNode implements Serializable, Comparable { +public abstract class EntityNode implements Serializable, Comparable { private static final boolean NOT_DEPRECATED = false; @@ -34,6 +29,9 @@ public abstract class EntityNode implements Serializable, Comparable NO_ENTITY_TAGS = ImmutableSet.of(); + private static final ImmutableSet NO_STATUSES = ImmutableSet.of(); + + @Nonnull public static EntityNode get(@Nonnull OWLEntity entity, @Nonnull String browserText, @@ -41,14 +39,16 @@ public static EntityNode get(@Nonnull OWLEntity entity, boolean deprecated, @Nonnull Set watches, int openCommentCount, - Collection tags) { + Collection tags, + Set statuses) { return new AutoValue_EntityNode(entity, - browserText, - ImmutableSet.copyOf(tags), - deprecated, - ImmutableSet.copyOf(watches), - openCommentCount, - shortForms); + browserText, + ImmutableSet.copyOf(tags), + deprecated, + ImmutableSet.copyOf(watches), + openCommentCount, + shortForms, + ImmutableSet.copyOf(statuses)); } @JsonCreator @@ -59,18 +59,20 @@ public static EntityNode get(@JsonProperty("entity") @Nonnull OWLEntity entity, @JsonProperty("deprecated") boolean deprecated, @JsonProperty("watches") @Nonnull Set watches, @JsonProperty("openCommentCount") int openCommentCount, - @JsonProperty("tags") Collection tags) { + @JsonProperty("tags") Collection tags, + @JsonProperty("statuses") Set statuses) { ImmutableMap map = shortForms.stream() - .collect(toImmutableMap(ShortForm::getDictionaryLanguage, - ShortForm::getShortForm)); + .collect(toImmutableMap(ShortForm::getDictionaryLanguage, + ShortForm::getShortForm)); return get(entity, - browserText, - map, - deprecated, - ImmutableSet.copyOf(watches), - openCommentCount, - ImmutableSet.copyOf(tags)); + browserText, + map, + deprecated, + ImmutableSet.copyOf(watches), + openCommentCount, + ImmutableSet.copyOf(tags), + ImmutableSet.copyOf(statuses)); } /** @@ -84,12 +86,13 @@ public static EntityNode get(@JsonProperty("entity") @Nonnull OWLEntity entity, @Nonnull public static EntityNode getFromEntityData(@Nonnull OWLEntityData entityData) { return get(entityData.getEntity(), - entityData.getBrowserText(), - entityData.getShortForms(), - NOT_DEPRECATED, - NO_WATCHES, - NO_OPEN_COMMENTS, - NO_ENTITY_TAGS); + entityData.getBrowserText(), + entityData.getShortForms(), + NOT_DEPRECATED, + NO_WATCHES, + NO_OPEN_COMMENTS, + NO_ENTITY_TAGS, + NO_STATUSES); } @Nonnull @@ -110,10 +113,10 @@ public String getText(@Nonnull DictionaryLanguageData prefLang) { public String getText(@Nonnull List prefLang, String defaultText) { return prefLang.stream() - .map(language -> getShortForms().get(language)) - .filter(Objects::nonNull) - .findFirst() - .orElse(defaultText); + .map(language -> getShortForms().get(language)) + .filter(Objects::nonNull) + .findFirst() + .orElse(defaultText); } public abstract ImmutableSet getTags(); @@ -128,12 +131,15 @@ public String getText(@Nonnull List prefLang, String default @Nonnull public abstract ImmutableMap getShortForms(); + @JsonProperty("statuses") + public abstract ImmutableSet getStatuses(); + @JsonProperty("shortForms") public ImmutableList getShortFormsList() { return getShortForms().entrySet() - .stream() - .map(entry -> ShortForm.get(entry.getKey(), entry.getValue())) - .collect(ImmutableList.toImmutableList()); + .stream() + .map(entry -> ShortForm.get(entry.getKey(), entry.getValue())) + .collect(ImmutableList.toImmutableList()); } @Override diff --git a/src/main/java/edu/stanford/protege/webprotege/entity/EntityStatus.java b/src/main/java/edu/stanford/protege/webprotege/entity/EntityStatus.java new file mode 100644 index 0000000..46f3ff7 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/entity/EntityStatus.java @@ -0,0 +1,27 @@ +package edu.stanford.protege.webprotege.entity; + +import com.fasterxml.jackson.annotation.*; +import com.google.auto.value.AutoValue; + +import javax.annotation.Nonnull; +import java.io.Serializable; + +@AutoValue +public abstract class EntityStatus implements Serializable, Comparable { + + @JsonCreator + public static EntityStatus get(@Nonnull @JsonProperty("status") String status) { + return new AutoValue_EntityStatus(status); + } + + + @JsonProperty("status") + @Nonnull + public abstract String getStatus(); + + + @Override + public int compareTo(EntityStatus o) { + return this.getStatus().compareToIgnoreCase(o.getStatus()); + } +} diff --git a/src/test/java/edu/stanford/protege/webprotege/entity/EntityNode_Serialization_TestCase.java b/src/test/java/edu/stanford/protege/webprotege/entity/EntityNode_Serialization_TestCase.java index d291db6..33fd951 100644 --- a/src/test/java/edu/stanford/protege/webprotege/entity/EntityNode_Serialization_TestCase.java +++ b/src/test/java/edu/stanford/protege/webprotege/entity/EntityNode_Serialization_TestCase.java @@ -25,17 +25,18 @@ public class EntityNode_Serialization_TestCase { @Test public void shouldSerializeNode() throws IOException { var entityNode = EntityNode.get(mockOWLClass(), - "The browser text", - ImmutableMap.of(DictionaryLanguage.localName(), "Hello"), - true, - ImmutableSet.of(Watch.create(mockUserId(), mockOWLClass(), WatchType.ENTITY)), - 33, - ImmutableSet.of(Tag.get(TagId.createTagId(), - mockProjectId(), - "The Tag Label", - "The tag description", - Color.getWhite(), - Color.getWhite(), ImmutableList.of()))); + "The browser text", + ImmutableMap.of(DictionaryLanguage.localName(), "Hello"), + true, + ImmutableSet.of(Watch.create(mockUserId(), mockOWLClass(), WatchType.ENTITY)), + 33, + ImmutableSet.of(Tag.get(TagId.createTagId(), + mockProjectId(), + "The Tag Label", + "The tag description", + Color.getWhite(), + Color.getWhite(), ImmutableList.of())), + ImmutableSet.of()); } } diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/AddEdge_Serialization_Test.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/AddEdge_Serialization_Test.java index d399c07..292db04 100644 --- a/src/test/java/edu/stanford/protege/webprotege/hierarchy/AddEdge_Serialization_Test.java +++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/AddEdge_Serialization_Test.java @@ -47,7 +47,7 @@ void shouldSerializeAsJson() throws IOException { @Test void shouldDeserializeFromJson() throws IOException { var json = """ - {"type":"AddEdge","edge":{"predecessor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I0"},"browserText":"","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[]},"sink":false},"successor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I1"},"browserText":"","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[]},"sink":false}}} + {"type":"AddEdge","edge":{"predecessor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I0"},"browserText":"","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[], "statuses":[]},"sink":false},"successor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I1"},"browserText":"","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[], "statuses":[]},"sink":false}}} """; var read = tester.readObject(new StringReader(json)); assertThat(read).isInstanceOf(AddEdge.class); diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GraphNode_TestCase.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GraphNode_TestCase.java index c9bb0f7..e44eac7 100644 --- a/src/test/java/edu/stanford/protege/webprotege/hierarchy/GraphNode_TestCase.java +++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/GraphNode_TestCase.java @@ -7,7 +7,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.io.IOException; import java.io.Serializable; @@ -71,11 +71,12 @@ public void isSinkShouldReturnSuppliedSinkFlag() { @Test public void shouldSerializeAsJson() throws IOException { var graphNode = new GraphNode<>(EntityNode.get(MockingUtils.mockOWLClass(), - "Hello", - ImmutableList.of(), - true, ImmutableSet.of(), - 3, - ImmutableSet.of())); - + "Hello", + ImmutableList.of(), + true, ImmutableSet.of(), + 3, + ImmutableSet.of(), + ImmutableSet.of())); + } } diff --git a/src/test/java/edu/stanford/protege/webprotege/hierarchy/RemoveEdge_Serialization_Test.java b/src/test/java/edu/stanford/protege/webprotege/hierarchy/RemoveEdge_Serialization_Test.java index 246130c..5892179 100644 --- a/src/test/java/edu/stanford/protege/webprotege/hierarchy/RemoveEdge_Serialization_Test.java +++ b/src/test/java/edu/stanford/protege/webprotege/hierarchy/RemoveEdge_Serialization_Test.java @@ -52,7 +52,7 @@ void shouldSerializeAsJson() throws IOException { @Test void shouldDeserializeFromJson() throws IOException { var json = """ - {"type":"RemoveEdge","edge":{"predecessor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I0"},"browserText":"","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[]},"sink":false},"successor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I1"},"browserText":"","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[]},"sink":false}}} + {"type":"RemoveEdge","edge":{"predecessor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I0"},"browserText":"","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[], "statuses":[]},"sink":false},"successor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I1"},"browserText":"","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[], "statuses":[]},"sink":false}}} """; var read = tester.readObject(new StringReader(json)); assertThat(read).isInstanceOf(RemoveEdge.class);