-
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.
Merge branch 'Support_hierarchy_change_operations_#8'
- Loading branch information
Showing
5 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/main/java/edu/stanford/protege/webprotege/bulkop/ChangeEntityParentsAction.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,34 @@ | ||
package edu.stanford.protege.webprotege.bulkop; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import com.google.common.collect.ImmutableSet; | ||
import edu.stanford.protege.webprotege.common.ChangeRequestId; | ||
import edu.stanford.protege.webprotege.common.ContentChangeRequest; | ||
import edu.stanford.protege.webprotege.common.ProjectId; | ||
import edu.stanford.protege.webprotege.dispatch.ProjectAction; | ||
import org.semanticweb.owlapi.model.OWLClass; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Matthew Horridge | ||
* Stanford Center for Biomedical Informatics Research | ||
* 25 Sep 2018 | ||
*/ | ||
|
||
|
||
@JsonTypeName("webprotege.entities.ChangeEntityParents") | ||
public record ChangeEntityParentsAction(@JsonProperty("changeRequestId") ChangeRequestId changeRequestId, | ||
@JsonProperty("projectId") @Nonnull ProjectId projectId, | ||
@JsonProperty("parents") @Nonnull ImmutableSet<OWLClass> parents, | ||
@JsonProperty("entity") @Nonnull OWLClass entity, | ||
@JsonProperty("commitMessage") @Nonnull String commitMessage) implements ProjectAction<ChangeEntityParentsResult>, HasCommitMessage, ContentChangeRequest { | ||
|
||
public static final String CHANNEL = "webprotege.entities.ChangeEntityParents"; | ||
|
||
@Override | ||
public String getChannel() { | ||
return CHANNEL; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/edu/stanford/protege/webprotege/bulkop/ChangeEntityParentsResult.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.bulkop; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import edu.stanford.protege.webprotege.dispatch.Result; | ||
import edu.stanford.protege.webprotege.entity.OWLEntityData; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.Set; | ||
|
||
/** | ||
* Matthew Horridge | ||
* Stanford Center for Biomedical Informatics Research | ||
* 25 Sep 2018 | ||
*/ | ||
|
||
|
||
@JsonTypeName("webprotege.entities.ChangeEntityParents") | ||
public record ChangeEntityParentsResult(@JsonProperty("classesWithCycle") @Nonnull Set<OWLEntityData> classesWithCycle) implements Result { | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyParentsAction.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,37 @@ | ||
package edu.stanford.protege.webprotege.hierarchy; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import edu.stanford.protege.webprotege.common.ProjectId; | ||
import edu.stanford.protege.webprotege.dispatch.ProjectAction; | ||
import org.semanticweb.owlapi.model.OWLEntity; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* Matthew Horridge Stanford Center for Biomedical Informatics Research 28 Nov 2017 | ||
*/ | ||
|
||
|
||
@JsonTypeName("webprotege.hierarchies.GetHierarchyParents") | ||
public record GetHierarchyParentsAction(@JsonProperty("projectId") @Nonnull ProjectId projectId, | ||
@JsonProperty("entity") @Nonnull OWLEntity entity, | ||
@JsonProperty("hierarchyId") @Nonnull HierarchyId hierarchyId) implements ProjectAction<GetHierarchyParentsResult> { | ||
|
||
public static final String CHANNEL = "webprotege.hierarchies.GetHierarchyParents"; | ||
|
||
@Override | ||
public String getChannel() { | ||
return CHANNEL; | ||
} | ||
|
||
public GetHierarchyParentsAction(@JsonProperty("projectId") @Nonnull ProjectId projectId, | ||
@JsonProperty("entity") @Nonnull OWLEntity entity, | ||
@JsonProperty("hierarchyId") @Nonnull HierarchyId hierarchyId) { | ||
this.projectId = checkNotNull(projectId); | ||
this.entity = checkNotNull(entity); | ||
this.hierarchyId = checkNotNull(hierarchyId); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyParentsResult.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 edu.stanford.protege.webprotege.dispatch.Result; | ||
import edu.stanford.protege.webprotege.entity.OWLEntityData; | ||
import org.semanticweb.owlapi.model.OWLEntity; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import java.util.List; | ||
|
||
|
||
/** | ||
* Matthew Horridge Stanford Center for Biomedical Informatics Research 28 Nov 2017 | ||
*/ | ||
|
||
@JsonTypeName("webprotege.hierarchies.GetHierarchyParents") | ||
public record GetHierarchyParentsResult(@JsonProperty("entity") @Nullable OWLEntity entity, | ||
@JsonProperty("parents") @Nonnull List<OWLEntityData> parents) implements Result { | ||
} |
100 changes: 100 additions & 0 deletions
100
src/test/java/edu/stanford/protege/webprotege/hierarchy/GetHierarchyParentsActionTest.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,100 @@ | ||
package edu.stanford.protege.webprotege.hierarchy; | ||
|
||
import edu.stanford.protege.webprotege.common.ProjectId; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.semanticweb.owlapi.model.OWLEntity; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.startsWith; | ||
import static org.mockito.Mockito.mock; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
class GetHierarchyParentsActionTest { | ||
|
||
|
||
private GetHierarchyParentsAction action; | ||
|
||
private final ProjectId projectId = ProjectId.generate(); | ||
|
||
@Mock | ||
private OWLEntity entity; | ||
|
||
@Mock | ||
private HierarchyId hierarchyId; | ||
|
||
@Before | ||
public void setUp() { | ||
action = new GetHierarchyParentsAction(projectId, entity, hierarchyId); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
} | ||
|
||
@SuppressWarnings("ConstantConditions") | ||
@Test(expected = NullPointerException.class) | ||
public void shouldThrowNullPointerExceptionIf_projectId_IsNull() { | ||
new GetHierarchyParentsAction(null, entity, hierarchyId); | ||
} | ||
|
||
@Test | ||
public void shouldReturnSupplied_projectId() { | ||
assertThat(action.projectId(), is(this.projectId)); | ||
} | ||
|
||
@SuppressWarnings("ConstantConditions") | ||
@Test(expected = NullPointerException.class) | ||
public void shouldThrowNullPointerExceptionIf_entity_IsNull() { | ||
new GetHierarchyParentsAction(projectId, null, hierarchyId); | ||
} | ||
|
||
|
||
@Test | ||
public void shouldReturnSupplied_entity() { | ||
assertThat(action.entity(), is(this.entity)); | ||
} | ||
|
||
|
||
@SuppressWarnings("ConstantConditions") | ||
@Test(expected = NullPointerException.class) | ||
public void shouldThrowNullPointerExceptionIf_hierarchyId_IsNull() { | ||
new GetHierarchyParentsAction(projectId, entity, null); | ||
} | ||
|
||
@Test | ||
public void shouldBeEqualToOther() { | ||
assertThat(action, is(new GetHierarchyParentsAction(projectId, entity, hierarchyId))); | ||
} | ||
|
||
@Test | ||
public void shouldNotBeEqualToOtherThatHasDifferent_projectId() { | ||
assertThat(action, is(not(new GetHierarchyParentsAction(ProjectId.generate(), entity, hierarchyId)))); | ||
} | ||
|
||
@Test | ||
public void shouldNotBeEqualToOtherThatHasDifferent_entity() { | ||
assertThat(action, is(not(new GetHierarchyParentsAction(projectId, mock(OWLEntity.class), hierarchyId)))); | ||
} | ||
|
||
@Test | ||
public void shouldNotBeEqualToOtherThatHasDifferent_hierarchyId() { | ||
assertThat(action, is(not(new GetHierarchyParentsAction(projectId, entity, mock(HierarchyId.class))))); | ||
} | ||
|
||
@Test | ||
public void shouldBeEqualToOtherHashCode() { | ||
assertThat(action.hashCode(), is(new GetHierarchyParentsAction(projectId, entity, hierarchyId).hashCode())); | ||
} | ||
|
||
@Test | ||
public void shouldImplementToString() { | ||
assertThat(action.toString(), startsWith("GetHierarchyParentsAction")); | ||
} | ||
} |