Skip to content

Commit

Permalink
Merge branch 'Support_hierarchy_change_operations_#8'
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhorridge committed Jun 5, 2024
2 parents a122e08 + a2b8a2c commit 7c7c721
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 0 deletions.
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;
}
}
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 {

}
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);
}
}
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 {
}
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"));
}
}

0 comments on commit 7c7c721

Please sign in to comment.