Skip to content

Commit

Permalink
Fix #69
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhorridge committed Sep 18, 2024
1 parent 0915cd3 commit 2dcf17f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,71 +20,34 @@
* 15 Mar 2017
*/
@JsonTypeName("webprotege.perspectives.ResetPerspectiveLayout")
public class ResetPerspectiveLayoutAction implements ProjectAction<ResetPerspectiveLayoutResult> {

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<ResetPerspectiveLayoutResult> {

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

Expand Down

0 comments on commit 2dcf17f

Please sign in to comment.