Skip to content

Commit caeafc7

Browse files
author
Jakub Amanowicz
authored
V3 casl 1466 v3 mom 10 (#538)
* cherry picked mom10 from v2 Signed-off-by: Jakub Amanowicz <jakub.amanowicz@here.com> * CASL-1466 migrated mom10 module to v3 Signed-off-by: Jakub Amanowicz <jakub.amanowicz@here.com> * CASL-1466 review fixes Signed-off-by: Jakub Amanowicz <jakub.amanowicz@here.com> --------- Signed-off-by: Jakub Amanowicz <jakub.amanowicz@here.com>
1 parent 7ce37fe commit caeafc7

File tree

22 files changed

+1116
-1
lines changed

22 files changed

+1116
-1
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ val allModules = mapOf(
9494
Pair("here-naksha-lib-view", Pair(CleanAndTest.KOTLIN, PublishModule.NO)),
9595
Pair("here-naksha-storage-http", Pair(CleanAndTest.KOTLIN, PublishModule.NO)),
9696
Pair("here-naksha-cli", Pair(CleanAndTest.KOTLIN, PublishModule.NO)),
97+
Pair("here-naksha-lib-mom10", Pair(CleanAndTest.KOTLIN, PublishModule.YES)),
9798
)
9899

99100
fun Project.configureVanniktechMavenPublish() {

buildSrc/src/main/kotlin/Descriptions.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ private val Descriptions = mapOf(
2525
"here-naksha-lib-view" to "Naksha library, adding capabilities to combine multiple storages, maps, collections into a single virtual view.",
2626
"here-naksha-storage-http" to "TBD",
2727
"here-naksha-cli" to "The Naksha CLI tool allows users to interact with Naksha storage.",
28+
"here-naksha-lib-mom10" to "Naksha library offering support for MOM 10"
2829
)
2930

3031
fun Project.gatherDescription(): String

here-naksha-lib-mom10/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
## lib-mom10 module
2+
3+
The job of this module is to provide Naksha ecosystem with tools needed for correct MOM 10 handling.
4+
5+
Naksha itself relies heavily on `@ns:com:here:mom:meta` and `@ns:com:here:mom:delta` namespaces that
6+
were changed in MOM 10.
7+
There were renamed and slightly reshaped, there are also some properties that are no longer valid in
8+
MOM 10.
9+
10+
Because of the above, Naksha has to:
11+
12+
- **do nothing** if the handled (written or read) feature has version below `10.0.0` - we know that
13+
for "pre-MOM 10" features all of necessary namespaces are in place
14+
- when writing `MOM 10` feature: create and shape missing namespace so that all logic that depends
15+
on them will work as expected
16+
- when reading `MOM 10` feature: return them in the same shape as they were written (== don't
17+
include obsolete namespaces needed by Naksha)
18+
19+
### Checking `modelVersion`
20+
21+
[Mom10Verification](src/jvmMain/java/com/here/naksha/mom10/Mom10Verification.java) is responsible
22+
for
23+
checking whether given feature **has MOM version equal or greater to `10.0.0`**.
24+
This information can be used to determine whether a further processing is required.
25+
26+
### Transforming from and to MOM 10
27+
28+
Transforming **from MOM 10** is assumed to happen only for writes - when a client comes with MOM 10
29+
feature:
30+
31+
- we create outdated namespaces basing on data that is mappable from MOM 10
32+
- we store the feature as it was given by the client with additional namespaces being stored next to
33+
the "new ones" (defined in MOM 10)
34+
- the result is feature in "hybrid state" - containing both new and old namespaces
35+
36+
Transforming **to MOM 10** is assumed to happen only for reads - when a client want to retrieve
37+
previously stored MOM 10 feature (described above):
38+
39+
- we fetch the whole "hybrid feature"
40+
- we drop everything that we added in `from MOM 10` transformation (basically we delete obsolete
41+
namespaces)
42+
- we return feature in the same shape as it was given to Naksha in the writing phase
43+
44+
The class responsible for these operations
45+
is [Mom10Transformation](src/jvmMain/java/com/here/naksha/mom10/Mom10Transformation.java).
46+
47+
#### Populating old delta
48+
49+
| `@ns:com:here:mom:delta` properties supported in Naksha (pre MOM 10) | equivalents in `meta.moderationInfo` (MOM 10+) |
50+
|----------------------------------------------------------------------|------------------------------------------------|
51+
| `originId` | `originId` |
52+
| `parentLink` | `parentLink` |
53+
| `changeState` | `changeState` |
54+
| `reviewState` | `reviewState` |
55+
| `streamId` | not applicable |
56+
| `potentialValue` | not applicable |
57+
| `priorityCategory` | not applicable |
58+
| `dueTS` | not applicable |
59+
| `changeCounter` | not applicable |
60+
61+
Only the properties supported in both old delta NS and new `moderationInfo` will be used for
62+
population of `@ns:com:here:mom:delta` namespace.
63+
64+
Pre MOM 10 delta NS
65+
model: https://docs.in.here.com/static/169823/1467398/html/#com/here/mom/internal/extension/branch/branch.html
66+
67+
MOM 10+ moderation
68+
info: https://here-dev.zoominsoftware.io/docs/bundle/map-object-model-data-specification-10/page/com/here/mom/internal/component/moderation/moderation-information.html
69+
70+
#### Populating old meta
71+
72+
Properties supported by both old `@ns:com:here:mom:meta` NS and MOM 10+ `meta` property
73+
74+
- `sourceId`
75+
- `updatedByUser`
76+
- `lastUpdatedBy`
77+
- `modelVersion`
78+
- `protectionFlags`
79+
- `createdTS `
80+
- `layerId`
81+
- `updatedByApp`
82+
- `lastUpdatedTS`
83+
84+
Only the properties listed above will be populated when creating `@ns:com:here:mom:meta` namespace.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
plugins {
2+
alias(libs.plugins.kotlin.multiplatform)
3+
}
4+
5+
description = gatherDescription()
6+
7+
kotlin {
8+
jvm {}
9+
sourceSets {
10+
jvmMain {
11+
jvmToolchain(23)
12+
dependencies {
13+
implementation(project(":here-naksha-lib-model"))
14+
implementation(project(":here-naksha-lib-handlers"))
15+
}
16+
}
17+
jvmTest {
18+
dependencies {
19+
implementation(libs.bundles.testing)
20+
}
21+
}
22+
}
23+
}
24+
25+
tasks {
26+
getByName<Jar>("jvmJar") { dependsOn("jvmProcessResources") }
27+
getByName<ProcessResources>("jvmTestProcessResources") { dependsOn("jvmProcessResources") }
28+
getByName<Test>("jvmTest") {
29+
useJUnitPlatform()
30+
maxHeapSize = "6g"
31+
}
32+
}
33+
34+
setOverallCoverage(0.0) // only increasing allowed!
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2017-2024 HERE Europe B.V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
package com.here.naksha.mom10;
20+
21+
class DeltaProperties {
22+
private DeltaProperties() {}
23+
24+
/*
25+
Properties that are part of both pre-MOM 10 delta NS and MOM 10+ moderationInfo
26+
pre MOM 10: https://docs.in.here.com/static/169823/1467398/html/#com/here/mom/internal/extension/branch/branch.html
27+
MOM 10+: https://here-dev.zoominsoftware.io/docs/bundle/map-object-model-data-specification-10/page/com/here/mom/internal/component/moderation/moderation-information.html
28+
*/
29+
public static final String ORIGIN_ID = "originId";
30+
public static final String PARENT_LINK = "parentLink";
31+
public static final String CHANGE_STATE = "changeState";
32+
public static final String REVIEW_STATE = "reviewState";
33+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (C) 2017-2024 HERE Europe B.V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
package com.here.naksha.mom10;
20+
21+
import java.util.Collections;
22+
import java.util.HashSet;
23+
import java.util.Set;
24+
25+
/**
26+
* Some of Meta-related properties from MOM 10
27+
*/
28+
public class MetaProperties {
29+
30+
private MetaProperties() {
31+
}
32+
33+
/**
34+
* Renamed in MOM 10 from {@link naksha.model.objects.NakshaProperties#META_KEY}
35+
*/
36+
public static final String META = "meta";
37+
38+
/**
39+
* Source of truth about model version - required since MOM 10.0.0, optional before
40+
*/
41+
public static final String MODEL_VERSION = "modelVersion";
42+
43+
/*
44+
https://docs.in.here.com/static/169823/1467398/html/#com/here/mom/internal/component/meta/metadata.html
45+
*/
46+
private static final Set<String> META_NAMESPACE_PROPERTIES = Set.of(
47+
"createdTS",
48+
"hashPayload",
49+
"lastObservedTS",
50+
"lastReviewedTS",
51+
"lastUpdatedBy",
52+
"lastUpdatedTS",
53+
"layerId",
54+
MODEL_VERSION,
55+
"operation",
56+
"owner",
57+
"protectionFlags",
58+
"sourceId",
59+
"tid",
60+
"updatedByApp",
61+
"updatedByUser");
62+
63+
/**
64+
* Renamed from {@link naksha.model.objects.NakshaProperties#DELTA_KEY} and moved under {@link MetaProperties#META}
65+
*/
66+
public static final String MODERATION_INFO = "moderationInfo";
67+
68+
// https://here-dev.zoominsoftware.io/docs/bundle/map-object-model-data-specification-10/page/com/here/mom/internal/component/meta/metadata.html
69+
private static final Set<String> MOM_10_META_PROPERTIES = Set.of(
70+
"confidence",
71+
"createdTS",
72+
"externalIds",
73+
"keyValues",
74+
"lastUpdatedBy",
75+
"lastUpdatedTS",
76+
"layerId",
77+
MODEL_VERSION, // "modelVersion"
78+
MODERATION_INFO, // "moderationInfo"
79+
"protectionFlags",
80+
"sourceId",
81+
"sourceInfo",
82+
"tags",
83+
"updatedByApp",
84+
"updatedByUser");
85+
86+
static final Set<String> COMMON_META_PROPERTIES;
87+
88+
static {
89+
HashSet<String> metaProperties = new HashSet<>(META_NAMESPACE_PROPERTIES);
90+
metaProperties.retainAll(MOM_10_META_PROPERTIES);
91+
COMMON_META_PROPERTIES = Collections.unmodifiableSet(metaProperties);
92+
}
93+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (C) 2017-2024 HERE Europe B.V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
package com.here.naksha.mom10;
20+
21+
import static com.here.naksha.mom10.MetaProperties.COMMON_META_PROPERTIES;
22+
import static com.here.naksha.mom10.MetaProperties.META;
23+
import static com.here.naksha.mom10.MetaProperties.MODERATION_INFO;
24+
25+
import java.util.Map;
26+
import naksha.model.mom.MomDeltaNs;
27+
import naksha.model.mom.MomMetaNs;
28+
import naksha.model.objects.NakshaFeature;
29+
import naksha.model.objects.NakshaProperties;
30+
import org.jetbrains.annotations.NotNull;
31+
import org.jetbrains.annotations.Nullable;
32+
33+
public class Mom10Transformation {
34+
35+
private Mom10Transformation() {
36+
}
37+
38+
public static void populatePreMom10Namespaces(@Nullable NakshaFeature feature) {
39+
if (feature == null) {
40+
return;
41+
}
42+
43+
NakshaProperties properties = feature.getProperties();
44+
Map<String, Object> meta = (Map<String, Object>) properties.get(META);
45+
if (meta != null && !meta.isEmpty()) {
46+
MomDeltaNs deltaNs = deltaNs(meta);
47+
properties.setDelta(deltaNs);
48+
MomMetaNs metaNs = metaNs(meta);
49+
properties.setMeta(metaNs);
50+
}
51+
}
52+
53+
private static @NotNull MomMetaNs metaNs(@NotNull Map<String, Object> meta) {
54+
MomMetaNs metaNs = new MomMetaNs();
55+
for (String metaKey : COMMON_META_PROPERTIES) {
56+
Object value = meta.get(metaKey);
57+
if (value != null) {
58+
metaNs.put(metaKey, value);
59+
}
60+
}
61+
return metaNs;
62+
}
63+
64+
private static @Nullable MomDeltaNs deltaNs(@NotNull Map<String, Object> meta) {
65+
Map<String, Object> moderationInfo = (Map<String, Object>) meta.get(MODERATION_INFO);
66+
if (moderationInfo == null) {
67+
return null;
68+
} else {
69+
MomDeltaNs deltaNs = new MomDeltaNs();
70+
String changeState = (String) moderationInfo.get(DeltaProperties.CHANGE_STATE);
71+
if (changeState != null) {
72+
deltaNs.setChangeState(changeState);
73+
}
74+
String reviewState = (String) moderationInfo.get(DeltaProperties.REVIEW_STATE);
75+
if (reviewState != null) {
76+
deltaNs.setReviewState(reviewState);
77+
}
78+
String originId = (String) moderationInfo.get(DeltaProperties.ORIGIN_ID);
79+
if (originId != null) {
80+
deltaNs.setOriginId(originId);
81+
}
82+
String parentLink = (String) moderationInfo.get(DeltaProperties.PARENT_LINK);
83+
if (parentLink != null) {
84+
deltaNs.setParentLink(parentLink);
85+
}
86+
return deltaNs;
87+
}
88+
}
89+
90+
public static void dropPreMom10Namespaces(@Nullable NakshaFeature feature) {
91+
if(feature != null) {
92+
NakshaProperties properties = feature.getProperties();
93+
properties.remove(NakshaProperties.META_KEY);
94+
properties.remove(NakshaProperties.DELTA_KEY);
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)