From b1267012fea94a90625ca51ed7886da92f040710 Mon Sep 17 00:00:00 2001 From: soimugeo Date: Mon, 11 Nov 2024 10:04:16 +0200 Subject: [PATCH 1/3] added ChangeType to ProjectChangeForEntity --- .../uiHistoryConcern/changes/ChangeType.java | 7 +++++++ .../changes/ProjectChangeForEntity.java | 20 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/main/java/edu/stanford/protege/webprotege/linearizationservice/uiHistoryConcern/changes/ChangeType.java diff --git a/src/main/java/edu/stanford/protege/webprotege/linearizationservice/uiHistoryConcern/changes/ChangeType.java b/src/main/java/edu/stanford/protege/webprotege/linearizationservice/uiHistoryConcern/changes/ChangeType.java new file mode 100644 index 0000000..65a2ff6 --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/linearizationservice/uiHistoryConcern/changes/ChangeType.java @@ -0,0 +1,7 @@ +package edu.stanford.protege.webprotege.linearizationservice.uiHistoryConcern.changes; + +public enum ChangeType { + CREATE_ENTITY, + DELETE_ENTITY, + UPDATE_ENTITY +} diff --git a/src/main/java/edu/stanford/protege/webprotege/linearizationservice/uiHistoryConcern/changes/ProjectChangeForEntity.java b/src/main/java/edu/stanford/protege/webprotege/linearizationservice/uiHistoryConcern/changes/ProjectChangeForEntity.java index 5dd91bd..9afaf15 100644 --- a/src/main/java/edu/stanford/protege/webprotege/linearizationservice/uiHistoryConcern/changes/ProjectChangeForEntity.java +++ b/src/main/java/edu/stanford/protege/webprotege/linearizationservice/uiHistoryConcern/changes/ProjectChangeForEntity.java @@ -1,12 +1,28 @@ package edu.stanford.protege.webprotege.linearizationservice.uiHistoryConcern.changes; import edu.stanford.protege.webprotege.change.ProjectChange; +import org.jetbrains.annotations.NotNull; public record ProjectChangeForEntity(String whoficEntityIri, - ProjectChange projectChange) { + ChangeType changeType, + ProjectChange projectChange) implements Comparable { public static ProjectChangeForEntity create(String whoficEntityIri, + ChangeType changeType, ProjectChange projectChange) { - return new ProjectChangeForEntity(whoficEntityIri, projectChange); + return new ProjectChangeForEntity(whoficEntityIri, changeType, projectChange); + } + + //All linearization/postcoordination changes are updates made on the whoficEntityIri. + // From this microservice we don't create or delete entities. that is the responsibility of the backend-service. + public static ProjectChangeForEntity create(String whoficEntityIri, + ProjectChange projectChange) { + return new ProjectChangeForEntity(whoficEntityIri, ChangeType.UPDATE_ENTITY, projectChange); + } + + @Override + public int compareTo(@NotNull ProjectChangeForEntity other) { + return Long.compare(this.projectChange.getTimestamp(), other.projectChange.getTimestamp()); + } } From 812ae969eb4b1137e3ab27feb0dce2e238667e7c Mon Sep 17 00:00:00 2001 From: soimugeo Date: Mon, 11 Nov 2024 10:20:16 +0200 Subject: [PATCH 2/3] updated ProjectChangesManagerTest --- .../changes/ProjectChangesManagerTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/test/java/edu/stanford/protege/webprotege/linearizationservice/uiHistoryConcern/changes/ProjectChangesManagerTest.java b/src/test/java/edu/stanford/protege/webprotege/linearizationservice/uiHistoryConcern/changes/ProjectChangesManagerTest.java index a77e1b3..0500911 100644 --- a/src/test/java/edu/stanford/protege/webprotege/linearizationservice/uiHistoryConcern/changes/ProjectChangesManagerTest.java +++ b/src/test/java/edu/stanford/protege/webprotege/linearizationservice/uiHistoryConcern/changes/ProjectChangesManagerTest.java @@ -8,7 +8,7 @@ import edu.stanford.protege.webprotege.linearizationservice.repositories.definitions.LinearizationDefinitionRepository; import edu.stanford.protege.webprotege.linearizationservice.uiHistoryConcern.diff.Revision2DiffElementsTranslator; import edu.stanford.protege.webprotege.linearizationservice.uiHistoryConcern.nodeRendering.EntityRendererManager; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.*; import org.mockito.junit.jupiter.MockitoExtension; @@ -64,7 +64,11 @@ public void GIVEN_validHistories_WHEN_getProjectChangesForHistoriesCalled_THEN_r assertEquals(1, result.size()); Iterator iterator = result.iterator(); - ProjectChange projectChange = iterator.next().projectChange(); + ProjectChangeForEntity projectChangeForEntity = iterator.next(); + ChangeType projectChangeType = projectChangeForEntity.changeType(); + assertEquals(ChangeType.UPDATE_ENTITY, projectChangeType); + + ProjectChange projectChange = projectChangeForEntity.projectChange(); assertNotNull(projectChange); assertEquals(12345L, projectChange.getTimestamp()); assertEquals("user1", projectChange.getAuthor().id()); @@ -117,6 +121,7 @@ public void GIVEN_validProjectIdAndRevision_WHEN_getProjectChangesForRevisionCal assertNotNull(result); assertEquals(entityIri, result.whoficEntityIri()); + assertEquals(ChangeType.UPDATE_ENTITY, result.changeType()); ProjectChange projectChange = result.projectChange(); assertNotNull(projectChange); From 4b40a7e8ed1af2c5a02aa56e7018685973efc7f2 Mon Sep 17 00:00:00 2001 From: soimugeo Date: Tue, 12 Nov 2024 14:37:18 +0200 Subject: [PATCH 3/3] updated compareTo in ProjectChangeForEntity --- .../uiHistoryConcern/changes/ProjectChangeForEntity.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/stanford/protege/webprotege/linearizationservice/uiHistoryConcern/changes/ProjectChangeForEntity.java b/src/main/java/edu/stanford/protege/webprotege/linearizationservice/uiHistoryConcern/changes/ProjectChangeForEntity.java index 9afaf15..bd51116 100644 --- a/src/main/java/edu/stanford/protege/webprotege/linearizationservice/uiHistoryConcern/changes/ProjectChangeForEntity.java +++ b/src/main/java/edu/stanford/protege/webprotege/linearizationservice/uiHistoryConcern/changes/ProjectChangeForEntity.java @@ -22,7 +22,10 @@ public static ProjectChangeForEntity create(String whoficEntityIri, @Override public int compareTo(@NotNull ProjectChangeForEntity other) { - return Long.compare(this.projectChange.getTimestamp(), other.projectChange.getTimestamp()); - + int timestampComparison = Long.compare(this.projectChange.getTimestamp(), other.projectChange.getTimestamp()); + if (timestampComparison != 0) { + return timestampComparison; + } + return this.whoficEntityIri.compareTo(other.whoficEntityIri); } }