Skip to content

Commit

Permalink
Merge pull request #11 from protegeproject/Create_a_mechanism_to_read…
Browse files Browse the repository at this point in the history
…_the_released_classes_#17

Create a mechanism to read the released classes #17
  • Loading branch information
soimugeoWB authored Jun 17, 2024
2 parents 8247fc9 + 57a4b87 commit 9cebe61
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,7 +19,7 @@
*/
@AutoValue

public abstract class EntityNode implements Serializable, Comparable<EntityNode> {
public abstract class EntityNode implements Serializable, Comparable<EntityNode> {

private static final boolean NOT_DEPRECATED = false;

Expand All @@ -34,21 +29,26 @@ public abstract class EntityNode implements Serializable, Comparable<EntityNode

private static final ImmutableSet<Tag> NO_ENTITY_TAGS = ImmutableSet.of();

private static final ImmutableSet<EntityStatus> NO_STATUSES = ImmutableSet.of();


@Nonnull
public static EntityNode get(@Nonnull OWLEntity entity,
@Nonnull String browserText,
@Nonnull ImmutableMap<DictionaryLanguage, String> shortForms,
boolean deprecated,
@Nonnull Set<Watch> watches,
int openCommentCount,
Collection<Tag> tags) {
Collection<Tag> tags,
Set<EntityStatus> 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
Expand All @@ -59,18 +59,20 @@ public static EntityNode get(@JsonProperty("entity") @Nonnull OWLEntity entity,
@JsonProperty("deprecated") boolean deprecated,
@JsonProperty("watches") @Nonnull Set<Watch> watches,
@JsonProperty("openCommentCount") int openCommentCount,
@JsonProperty("tags") Collection<Tag> tags) {
@JsonProperty("tags") Collection<Tag> tags,
@JsonProperty("statuses") Set<EntityStatus> statuses) {
ImmutableMap<DictionaryLanguage, String> 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));
}

/**
Expand All @@ -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
Expand All @@ -110,10 +113,10 @@ public String getText(@Nonnull DictionaryLanguageData prefLang) {

public String getText(@Nonnull List<DictionaryLanguage> 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<Tag> getTags();
Expand All @@ -128,12 +131,15 @@ public String getText(@Nonnull List<DictionaryLanguage> prefLang, String default
@Nonnull
public abstract ImmutableMap<DictionaryLanguage, String> getShortForms();

@JsonProperty("statuses")
public abstract ImmutableSet<EntityStatus> getStatuses();

@JsonProperty("shortForms")
public ImmutableList<ShortForm> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<EntityStatus> {

@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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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":"<http://stuff.com/I0>","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[]},"sink":false},"successor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I1"},"browserText":"<http://stuff.com/I1>","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[]},"sink":false}}}
{"type":"AddEdge","edge":{"predecessor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I0"},"browserText":"<http://stuff.com/I0>","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[], "statuses":[]},"sink":false},"successor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I1"},"browserText":"<http://stuff.com/I1>","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[], "statuses":[]},"sink":false}}}
""";
var read = tester.readObject(new StringReader(json));
assertThat(read).isInstanceOf(AddEdge.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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":"<http://stuff.com/I0>","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[]},"sink":false},"successor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I1"},"browserText":"<http://stuff.com/I1>","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[]},"sink":false}}}
{"type":"RemoveEdge","edge":{"predecessor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I0"},"browserText":"<http://stuff.com/I0>","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[], "statuses":[]},"sink":false},"successor":{"userObject":{"entity":{"@type":"Class","iri":"http://stuff.com/I1"},"browserText":"<http://stuff.com/I1>","tags":[],"deprecated":false,"watches":[],"openCommentCount":0,"shortForms":[], "statuses":[]},"sink":false}}}
""";
var read = tester.readObject(new StringReader(json));
assertThat(read).isInstanceOf(RemoveEdge.class);
Expand Down

0 comments on commit 9cebe61

Please sign in to comment.