diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/perspective/PerspectivePresenter.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/perspective/PerspectivePresenter.java index 4eedcdb76..e36926ba4 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/perspective/PerspectivePresenter.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/perspective/PerspectivePresenter.java @@ -116,7 +116,7 @@ private void handleResetPerspective(ResetPerspectiveEvent event) { private void executeResetPerspective(PerspectiveId perspectiveId) { GWT.log("[PerspectivePresenter] Reset Perspective: " + perspectiveId); - dispatchServiceManager.execute(resetPerspective(projectId, perspectiveId), + dispatchServiceManager.execute(resetPerspective(projectId, perspectiveId, ChangeRequestId.get(UuidV4.uuidv4())), result -> { removePerspective(perspectiveId); installPerspective(result.getResetLayout()); diff --git a/webprotege-gwt-ui-server-core/src/test/java/edu/stanford/bmir/protege/web/shared/perspective/ResetPerspectiveLayout_Serialization_TestCase.java b/webprotege-gwt-ui-server-core/src/test/java/edu/stanford/bmir/protege/web/shared/perspective/ResetPerspectiveLayout_Serialization_TestCase.java index 35ce7d69b..c69c81f1d 100644 --- a/webprotege-gwt-ui-server-core/src/test/java/edu/stanford/bmir/protege/web/shared/perspective/ResetPerspectiveLayout_Serialization_TestCase.java +++ b/webprotege-gwt-ui-server-core/src/test/java/edu/stanford/bmir/protege/web/shared/perspective/ResetPerspectiveLayout_Serialization_TestCase.java @@ -20,7 +20,8 @@ public class ResetPerspectiveLayout_Serialization_TestCase { @Test public void shouldSerializeAction() throws IOException { var action = ResetPerspectiveLayoutAction.create(mockProjectId(), - PerspectiveId.generate()); + PerspectiveId.generate(), + ChangeRequestId.get("12345678-1234-1234-1234-123456789abc")); JsonSerializationTestUtil.testSerialization(action, Action.class); } diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/perspective/ResetPerspectiveLayoutAction.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/perspective/ResetPerspectiveLayoutAction.java index 204984b06..5b789054e 100644 --- a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/perspective/ResetPerspectiveLayoutAction.java +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/perspective/ResetPerspectiveLayoutAction.java @@ -1,6 +1,10 @@ package edu.stanford.bmir.protege.web.shared.perspective; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; +import com.google.auto.value.AutoValue; +import com.google.common.annotations.GwtCompatible; import edu.stanford.bmir.protege.web.shared.annotations.GwtSerializationConstructor; import edu.stanford.bmir.protege.web.shared.dispatch.ProjectAction; import edu.stanford.bmir.protege.web.shared.project.ProjectId; @@ -16,71 +20,34 @@ * 15 Mar 2017 */ @JsonTypeName("webprotege.perspectives.ResetPerspectiveLayout") -public class ResetPerspectiveLayoutAction implements ProjectAction { - - private ProjectId projectId; - - private PerspectiveId perspectiveId; - - @GwtSerializationConstructor - private ResetPerspectiveLayoutAction() { - } - - /** - * Requests that the perspective identified by the specified id in the specified project is reset to - * the default for the current user. - * @param projectId The project id. - * @param perspectiveId The perspective id. - */ - private ResetPerspectiveLayoutAction(@Nonnull ProjectId projectId, @Nonnull PerspectiveId perspectiveId) { - this.projectId = checkNotNull(projectId); - this.perspectiveId = checkNotNull(perspectiveId); - } +@GwtCompatible(serializable = true) +@AutoValue +public abstract class ResetPerspectiveLayoutAction implements ProjectAction { public static ResetPerspectiveLayoutAction resetPerspective(@Nonnull ProjectId projectId, - @Nonnull PerspectiveId perspectiveId) { - return create(projectId, perspectiveId); + @Nonnull PerspectiveId perspectiveId, + @Nonnull ChangeRequestId changeRequestId) { + return create(projectId, perspectiveId, changeRequestId); } - public static ResetPerspectiveLayoutAction create(@Nonnull ProjectId projectId, - @Nonnull PerspectiveId perspectiveId) { - return new ResetPerspectiveLayoutAction(projectId, perspectiveId); + @JsonCreator + public static ResetPerspectiveLayoutAction create(@JsonProperty("projectId") @Nonnull ProjectId projectId, + @JsonProperty("perspectiveId") @Nonnull PerspectiveId perspectiveId, + @JsonProperty("changeRequestId") @Nonnull ChangeRequestId changeRequestId) { + return new AutoValue_ResetPerspectiveLayoutAction(projectId, perspectiveId, changeRequestId); } @Nonnull @Override - public ProjectId getProjectId() { - return projectId; - } + @JsonProperty("projectId") + public abstract ProjectId getProjectId(); - @Nonnull - public PerspectiveId getPerspectiveId() { - return perspectiveId; - } - - @Override - public int hashCode() { - return projectId.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof ResetPerspectiveLayoutAction)) { - return false; - } - ResetPerspectiveLayoutAction other = (ResetPerspectiveLayoutAction) obj; - return this.projectId.equals(other.projectId) - && this.perspectiveId.equals(other.perspectiveId); - } + @Nonnull + @JsonProperty("perspectiveId") + public abstract PerspectiveId getPerspectiveId(); - @Override - public String toString() { - return toStringHelper("ResetPerspectiveLayoutAction" ) - .addValue(projectId) - .toString(); - } + @Nonnull + @JsonProperty("changeRequestId") + public abstract ChangeRequestId getChangeRequestId(); } diff --git a/webprotege-gwt-ui-shared/src/test/java/edu/stanford/bmir/protege/web/shared/perspective/ResetPerspectiveLayoutAction_TestCase.java b/webprotege-gwt-ui-shared/src/test/java/edu/stanford/bmir/protege/web/shared/perspective/ResetPerspectiveLayoutAction_TestCase.java index e197707b9..78cd60069 100644 --- a/webprotege-gwt-ui-shared/src/test/java/edu/stanford/bmir/protege/web/shared/perspective/ResetPerspectiveLayoutAction_TestCase.java +++ b/webprotege-gwt-ui-shared/src/test/java/edu/stanford/bmir/protege/web/shared/perspective/ResetPerspectiveLayoutAction_TestCase.java @@ -23,17 +23,20 @@ public class ResetPerspectiveLayoutAction_TestCase { @Mock private PerspectiveId perspectiveId; + @Mock + ChangeRequestId changeRequestId; + @Before public void setUp() throws Exception { - resetPerspectiveLayoutAction = ResetPerspectiveLayoutAction.create(projectId, perspectiveId); + resetPerspectiveLayoutAction = ResetPerspectiveLayoutAction.create(projectId, perspectiveId, changeRequestId); } @SuppressWarnings("ConstantConditions") @Test(expected = NullPointerException.class) public void shouldThrowNullPointerExceptionIf_projectId_IsNull() { - ResetPerspectiveLayoutAction.create(null, perspectiveId); + ResetPerspectiveLayoutAction.create(null, perspectiveId, changeRequestId); } @Test @@ -44,7 +47,7 @@ public void shouldReturnSupplied_projectId() { @SuppressWarnings("ConstantConditions") @Test(expected = NullPointerException.class) public void shouldThrowNullPointerExceptionIf_perspectiveId_IsNull() { - ResetPerspectiveLayoutAction.create(projectId, null); + ResetPerspectiveLayoutAction.create(projectId, null, changeRequestId); } @Test @@ -65,22 +68,22 @@ public void shouldNotBeEqualToNull() { @Test public void shouldBeEqualToOther() { - assertThat(resetPerspectiveLayoutAction, is(ResetPerspectiveLayoutAction.create(projectId, perspectiveId))); + assertThat(resetPerspectiveLayoutAction, is(ResetPerspectiveLayoutAction.create(projectId, perspectiveId, changeRequestId))); } @Test public void shouldNotBeEqualToOtherThatHasDifferent_projectId() { - assertThat(resetPerspectiveLayoutAction, is(not(ResetPerspectiveLayoutAction.create(mock(ProjectId.class), perspectiveId)))); + assertThat(resetPerspectiveLayoutAction, is(not(ResetPerspectiveLayoutAction.create(mock(ProjectId.class), perspectiveId, changeRequestId)))); } @Test public void shouldNotBeEqualToOtherThatHasDifferent_perspectiveId() { - assertThat(resetPerspectiveLayoutAction, is(not(ResetPerspectiveLayoutAction.create(projectId, mock(PerspectiveId.class))))); + assertThat(resetPerspectiveLayoutAction, is(not(ResetPerspectiveLayoutAction.create(projectId, mock(PerspectiveId.class), changeRequestId)))); } @Test public void shouldBeEqualToOtherHashCode() { - assertThat(resetPerspectiveLayoutAction.hashCode(), is(ResetPerspectiveLayoutAction.create(projectId, perspectiveId) + assertThat(resetPerspectiveLayoutAction.hashCode(), is(ResetPerspectiveLayoutAction.create(projectId, perspectiveId, changeRequestId) .hashCode())); }