Skip to content

Commit 1703f3e

Browse files
gunplarJakub Amanowicz
andauthored
V3 casl 658 activitylog migration (#403)
* WIP Signed-off-by: phmai <phuc.mai@here.com> * WIP Signed-off-by: phmai <phuc.mai@here.com> * WIP Signed-off-by: phmai <phuc.mai@here.com> * WIP Signed-off-by: phmai <phuc.mai@here.com> * WIP Signed-off-by: phmai <phuc.mai@here.com> * WIP Signed-off-by: phmai <phuc.mai@here.com> * WIP Signed-off-by: phmai <phuc.mai@here.com> * WIP Signed-off-by: phmai <phuc.mai@here.com> * WIP Signed-off-by: phmai <phuc.mai@here.com> * WIP Signed-off-by: phmai <phuc.mai@here.com> * fix compiler errors after merging Signed-off-by: phmai <phuc.mai@here.com> * WIP Signed-off-by: phmai <phuc.mai@here.com> * refactor Action enum values Signed-off-by: phmai <phuc.mai@here.com> * Revert "refactor Action enum values" This reverts commit e98e748. * fix test data temporarily until CASL-791 Signed-off-by: phmai <phuc.mai@here.com> * gradle Signed-off-by: phmai <phuc.mai@here.com> * WIP new kotlin classes for activity log Signed-off-by: phmai <phuc.mai@here.com> * WIP new kotlin classes for activity log Signed-off-by: phmai <phuc.mai@here.com> * WIP Signed-off-by: phmai <phuc.mai@here.com> * disable old patcher in lib-core Signed-off-by: phmai <phuc.mai@here.com> * fix bug Signed-off-by: phmai <phuc.mai@here.com> * remove old diff package Signed-off-by: phmai <phuc.mai@here.com> * fix test Signed-off-by: phmai <phuc.mai@here.com> * add module to github cicd Signed-off-by: phmai <phuc.mai@here.com> * remove old patcher Signed-off-by: phmai <phuc.mai@here.com> * move gradle settings Signed-off-by: phmai <phuc.mai@here.com> * fix assertion Signed-off-by: phmai <phuc.mai@here.com> --------- Signed-off-by: phmai <phuc.mai@here.com> Co-authored-by: Jakub Amanowicz <jakub.amanowicz@here.com>
1 parent 419fe2e commit 1703f3e

File tree

52 files changed

+677
-1877
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+677
-1877
lines changed

.github/workflows/reusable-build-and-publish-v3s.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
# run: gradle shadowJar jacocoTestReport jacocoTestCoverageVerification
5656
shell: bash
5757
run: |
58-
array=( here-naksha-lib-model here-naksha-lib-base here-naksha-lib-core here-naksha-lib-psql here-naksha-lib-view here-naksha-storage-http here-naksha-lib-diff here-naksha-lib-handlers here-naksha-lib-hub )
58+
array=( here-naksha-lib-model here-naksha-lib-base here-naksha-lib-core here-naksha-lib-psql here-naksha-lib-view here-naksha-storage-http here-naksha-lib-diff here-naksha-lib-handlers here-naksha-lib-hub here-naksha-handler-activitylog)
5959
for item in ${array[@]}; do
6060
gradle -x jsNodeTest :$item:build :$item:jacocoTestReport :$item:jacocoTestCoverageVerification
6161
done

buildSrc/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ dependencies {
1616
implementation("com.diffplug.spotless:spotless-plugin-gradle:6.22.0")
1717
implementation("org.jetbrains.kotlin.multiplatform:org.jetbrains.kotlin.multiplatform.gradle.plugin:2.0.20")
1818
implementation("org.jetbrains.kotlin.plugin.js-plain-objects:org.jetbrains.kotlin.plugin.js-plain-objects.gradle.plugin:2.0.20")
19+
implementation("org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:2.1.0")
1920
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
plugins {
22
id("naksha.java")
33
id("naksha.publish")
4+
kotlin("jvm")
45
}
56
description = "Naksha Activity Log Handler"
67
dependencies {
78
implementation(project(":here-naksha-lib-core"))
89
implementation(project(":here-naksha-lib-psql"))
910
implementation(project(":here-naksha-lib-handlers"))
11+
implementation(project(":here-naksha-lib-diff"))
1012

1113
implementation(Lib.flipkart_zjsonpatch)
1214
testImplementation(Lib.jayway_jsonpath)
1315
testImplementation(Lib.mockito)
1416
testImplementation(Lib.json_assert)
1517
testImplementation(testFixtures(project(":here-naksha-lib-core")))
1618
}
17-
setOverallCoverage(0.4) // only increasing allowed!
19+
setOverallCoverage(0.4) // only increasing allowed!
20+
kotlin {
21+
jvmToolchain(17)
22+
}

here-naksha-handler-activitylog/src/main/java/com/here/naksha/handler/activitylog/ActivityLogComparator.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,30 @@
1818
*/
1919
package com.here.naksha.handler.activitylog;
2020

21-
import naksha.model.XyzFeature;
22-
import com.here.naksha.lib.core.models.geojson.implementation.namespaces.XyzNamespace;
2321
import java.util.Comparator;
22+
import naksha.model.XyzNs;
23+
import naksha.model.objects.NakshaFeature;
2424

25-
public class ActivityLogComparator implements Comparator<XyzFeature> {
25+
public class ActivityLogComparator implements Comparator<NakshaFeature> {
2626

2727
@Override
28-
public int compare(XyzFeature featureA, XyzFeature featureB) {
28+
public int compare(NakshaFeature featureA, NakshaFeature featureB) {
2929
int updatedAtComparison = Long.compare(updatedAt(featureA), updatedAt(featureB));
3030
if (updatedAtComparison == 0) {
3131
return uuid(featureA).compareTo(uuid(featureB)) * -1;
3232
}
3333
return updatedAtComparison * -1;
3434
}
3535

36-
private static String uuid(XyzFeature feature) {
36+
private static String uuid(NakshaFeature feature) {
3737
return xyzNamespace(feature).getUuid();
3838
}
3939

40-
private static long updatedAt(XyzFeature feature) {
41-
return xyzNamespace(feature).getUpdatedAt();
40+
private static long updatedAt(NakshaFeature feature) {
41+
return xyzNamespace(feature).getUpdatedAt().toLong();
4242
}
4343

44-
private static XyzNamespace xyzNamespace(XyzFeature feature) {
45-
return feature.getProperties().getXyzNamespace();
44+
private static XyzNs xyzNamespace(NakshaFeature feature) {
45+
return feature.getProperties().getXyz();
4646
}
4747
}

here-naksha-handler-activitylog/src/main/java/com/here/naksha/handler/activitylog/ActivityLogEnhancer.java

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
import static com.here.naksha.handler.activitylog.ReversePatchUtil.toJsonNode;
2323

2424
import com.fasterxml.jackson.databind.JsonNode;
25-
import naksha.model.EXyzAction;
26-
import naksha.model.XyzFeature;
27-
import com.here.naksha.lib.core.models.geojson.implementation.namespaces.Original;
28-
import com.here.naksha.lib.core.models.geojson.implementation.namespaces.XyzActivityLog;
29-
import com.here.naksha.lib.core.models.geojson.implementation.namespaces.XyzNamespace;
25+
import naksha.model.Action;
26+
import naksha.model.XyzNs;
27+
import naksha.model.objects.NakshaFeature;
28+
import naksha.model.objects.NakshaProperties;
3029
import org.jetbrains.annotations.NotNull;
3130
import org.jetbrains.annotations.Nullable;
3231
import org.slf4j.Logger;
@@ -38,34 +37,32 @@ public class ActivityLogEnhancer {
3837

3938
private ActivityLogEnhancer() {}
4039

41-
static XyzFeature enhanceWithActivityLog(
42-
@NotNull XyzFeature newFeature, @Nullable XyzFeature oldFeature, @NotNull String spaceId) {
43-
XyzActivityLog activityLog = activityLog(newFeature, oldFeature, spaceId);
44-
newFeature.getProperties().setXyzActivityLog(activityLog);
40+
static NakshaFeature enhanceWithActivityLog(
41+
@NotNull NakshaFeature newFeature, @Nullable NakshaFeature oldFeature, @NotNull String spaceId) {
42+
NakshaActivityLog activityLog = activityLog(newFeature, oldFeature, spaceId);
43+
newFeature.getProperties().put(NakshaProperties.XYZ_ACTIVITY_LOG_NS, activityLog);
4544
newFeature.setId(uuid(newFeature));
4645
return newFeature;
4746
}
4847

49-
private static XyzActivityLog activityLog(
50-
@NotNull XyzFeature newFeature, @Nullable XyzFeature oldFeature, @NotNull String spaceId) {
51-
final XyzNamespace xyzNamespace = xyzNamespace(newFeature);
52-
final XyzActivityLog xyzActivityLog = new XyzActivityLog();
53-
xyzActivityLog.setId(newFeature.getId());
54-
xyzActivityLog.setOriginal(original(xyzNamespace, spaceId));
55-
EXyzAction action = xyzNamespace.getAction();
56-
if (action != null) {
57-
xyzActivityLog.setAction(action);
58-
}
59-
xyzActivityLog.setDiff(calculateDiff(action, newFeature, oldFeature));
60-
return xyzActivityLog;
48+
private static NakshaActivityLog activityLog(
49+
@NotNull NakshaFeature newFeature, @Nullable NakshaFeature oldFeature, @NotNull String spaceId) {
50+
final XyzNs xyzNamespace = xyzNamespace(newFeature);
51+
final NakshaActivityLog activityLog = new NakshaActivityLog();
52+
activityLog.setId(newFeature.getId());
53+
activityLog.setOriginal(original(xyzNamespace, spaceId));
54+
Action action = xyzNamespace.getAction();
55+
activityLog.setAction(action.toString());
56+
activityLog.setDiff(calculateDiff(action, newFeature, oldFeature));
57+
return activityLog;
6158
}
6259

63-
private static Original original(@Nullable XyzNamespace xyzNamespace, @Nullable String spaceId) {
60+
private static Original original(@Nullable XyzNs xyzNamespace, @Nullable String spaceId) {
6461
Original original = new Original();
6562
if (xyzNamespace != null) {
6663
original.setPuuid(xyzNamespace.getPuuid());
67-
original.setUpdatedAt(xyzNamespace.getUpdatedAt());
68-
original.setCreatedAt(xyzNamespace.getCreatedAt());
64+
original.setUpdatedAt(xyzNamespace.getUpdatedAt().toLong());
65+
original.setCreatedAt(xyzNamespace.getCreatedAt().toLong());
6966
}
7067
if (spaceId != null) {
7168
original.setSpace(spaceId);
@@ -74,10 +71,10 @@ private static Original original(@Nullable XyzNamespace xyzNamespace, @Nullable
7471
}
7572

7673
private static @Nullable JsonNode calculateDiff(
77-
@Nullable EXyzAction action, @NotNull XyzFeature newFeature, @Nullable XyzFeature oldFeature) {
78-
if (action == null || EXyzAction.CREATE.equals(action) || EXyzAction.DELETE.equals(action)) {
74+
@Nullable Action action, @NotNull NakshaFeature newFeature, @Nullable NakshaFeature oldFeature) {
75+
if (action == null || Action.CREATED.equals(action) || Action.DELETED.equals(action)) {
7976
return null;
80-
} else if (EXyzAction.UPDATE.equals(action)) {
77+
} else if (Action.UPDATED.equals(action)) {
8178
if (oldFeature == null) {
8279
logger.warn(
8380
"Unable to calculate reversePatch for, missing predecessor for feature with uuid: {}, returning null",
@@ -91,11 +88,11 @@ private static Original original(@Nullable XyzNamespace xyzNamespace, @Nullable
9188
}
9289
}
9390

94-
private static String uuid(XyzFeature feature) {
91+
private static String uuid(NakshaFeature feature) {
9592
return xyzNamespace(feature).getUuid();
9693
}
9794

98-
private static XyzNamespace xyzNamespace(XyzFeature feature) {
99-
return feature.getProperties().getXyzNamespace();
95+
private static XyzNs xyzNamespace(NakshaFeature feature) {
96+
return feature.getProperties().getXyz();
10097
}
10198
}

0 commit comments

Comments
 (0)