Skip to content

Commit a114c34

Browse files
author
Jakub Amanowicz
committed
CASL-1419 review fixes
Signed-off-by: Jakub Amanowicz <jakub.amanowicz@here.com>
1 parent 79705dd commit a114c34

14 files changed

+207
-675
lines changed

here-naksha-lib-mom10/README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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/main/java/com/here/naksha/mom10/Mom10Verification.java) is responsible for
22+
checking whether given feature **has MOM version equal or greater to `10.0.0`**.
23+
This information can be used to determine whether a further processing is required.
24+
25+
### Transforming from and to MOM 10
26+
27+
Transforming **from MOM 10** is assumed to happen only for writes - when a client comes with MOM 10
28+
feature:
29+
30+
- we create outdated namespaces basing on data that is mappable from MOM 10
31+
- we store the feature as it was given by the client with additional namespaces being stored next to
32+
the "new ones" (defined in MOM 10)
33+
- the result is feature in "hybrid state" - containing both new and old namespaces
34+
35+
Transforming **to MOM 10** is assumed to happen only for reads - when a client want to retrieve
36+
previously stored MOM 10 feature (described above):
37+
38+
- we fetch the whole "hybrid feature"
39+
- we drop everything that we added in `from MOM 10` transformation (basically we delete obsolete
40+
namespaces)
41+
- we return feature in the same shape as it was given to Naksha in the writing phase
42+
43+
The class responsible for these operations
44+
is [Mom10Transformation](../java/com/here/naksha/mom10/transform/Mom10Transformation.java).
45+
46+
#### Populating old delta
47+
48+
| `@ns:com:here:mom:delta` properties supported in Naksha V2 (pre MOM 10) | equivalents in `meta.moderationInfo` (MOM 10+) |
49+
|-------------------------------------------------------------------------|------------------------------------------------|
50+
| `originId` | `originId` |
51+
| `parentLink` | `parentLink` |
52+
| `changeState` | `changeState` |
53+
| `reviewState` | `reviewState` |
54+
| `streamId` | not applicable |
55+
| `potentialValue` | not applicable |
56+
| `priorityCategory` | not applicable |
57+
| `dueTS` | not applicable |
58+
| `changeCounter` | not applicable |
59+
60+
Only the properties supported in both old delta NS and new `moderationInfo` will be used for population of `@ns:com:here:mom:delta` namespace.
61+
62+
Pre MOM 10 delta NS
63+
model: https://docs.in.here.com/static/169823/1467398/html/#com/here/mom/internal/extension/branch/branch.html
64+
65+
MOM 10+ moderation
66+
info: https://here-dev.zoominsoftware.io/docs/bundle/map-object-model-data-specification-10/page/com/here/mom/internal/component/moderation/moderation-information.html
67+
68+
#### Populating old meta
69+
70+
Properties supported by both old `@ns:com:here:mom:meta` NS and MOM 10+ `meta` property
71+
- `sourceId` (!!)
72+
- `updatedByUser`
73+
- `lastUpdatedBy`
74+
- `modelVersion`
75+
- `protectionFlags`
76+
- `createdTS `
77+
- `layerId`
78+
- `updatedByApp`
79+
- `lastUpdatedTS`
80+
81+
Only the properties listed above will be populated when creating `@ns:com:here:mom:meta` namespace.
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+
}

here-naksha-lib-mom10/src/main/java/com/here/naksha/mom10/MetaProperties.java

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
package com.here.naksha.mom10;
2020

2121
import com.here.naksha.lib.core.models.geojson.implementation.XyzProperties;
22+
import java.util.Collections;
23+
import java.util.HashSet;
24+
import java.util.Set;
2225

2326
/**
2427
* Some of Meta-related properties from MOM 10
@@ -33,19 +36,58 @@ private MetaProperties() {}
3336
public static final String META = "meta";
3437

3538
/**
36-
* Renamed from {@link XyzProperties#HERE_DELTA_NS} and moved under {@link MetaProperties#META}
39+
* Source of truth about model version - required since MOM 10.0.0, optional before
3740
*/
38-
public static final String MODERATION_INFO = "moderationInfo";
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");
3962

4063
/**
41-
* Moved from {@link XyzProperties#HERE_DELTA_NS} to {@link MetaProperties#META}
64+
* Renamed from {@link XyzProperties#HERE_DELTA_NS} and moved under {@link MetaProperties#META}
4265
*/
43-
public static final String CONFIDENCE = "confidence";
66+
public static final String MODERATION_INFO = "moderationInfo";
4467

45-
public static final String SOURCE_INFO = "sourceInfo";
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");
4685

47-
/**
48-
* Source of truth about model version - required since MOM 10.0.0
49-
*/
50-
public static final String MODEL_VERSION = "modelVersion";
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+
}
5193
}

here-naksha-lib-mom10/src/main/java/com/here/naksha/mom10/Mom10Transformation.java

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,23 @@
1818
*/
1919
package com.here.naksha.mom10;
2020

21-
import static com.here.naksha.mom10.MetaProperties.CONFIDENCE;
21+
import static com.here.naksha.mom10.MetaProperties.COMMON_META_PROPERTIES;
2222
import static com.here.naksha.mom10.MetaProperties.META;
2323
import static com.here.naksha.mom10.MetaProperties.MODERATION_INFO;
24-
import static com.here.naksha.mom10.MetaProperties.SOURCE_INFO;
2524

2625
import com.here.naksha.lib.core.models.geojson.implementation.XyzFeature;
2726
import com.here.naksha.lib.core.models.geojson.implementation.XyzProperties;
2827
import com.here.naksha.lib.core.models.geojson.implementation.namespaces.EChangeState;
2928
import com.here.naksha.lib.core.models.geojson.implementation.namespaces.EReviewState;
3029
import com.here.naksha.lib.core.models.geojson.implementation.namespaces.HereDeltaNs;
3130
import com.here.naksha.lib.core.models.geojson.implementation.namespaces.HereMetaNs;
31+
import com.here.naksha.lib.core.util.json.JsonEnum;
3232
import java.util.Map;
3333
import org.jetbrains.annotations.NotNull;
3434
import org.jetbrains.annotations.Nullable;
3535

3636
public class Mom10Transformation {
37+
3738
private Mom10Transformation() {}
3839

3940
public static void populatePreMom10Namespaces(@Nullable XyzFeature feature) {
@@ -43,42 +44,53 @@ public static void populatePreMom10Namespaces(@Nullable XyzFeature feature) {
4344

4445
XyzProperties properties = feature.getProperties();
4546
Map<String, Object> meta = (Map<String, Object>) properties.get(META);
46-
if (meta != null) {
47-
Map<String, Object> moderationInfo = (Map<String, Object>) meta.get(MODERATION_INFO);
48-
if (moderationInfo != null) {
49-
HereDeltaNs deltaNs = deltaNsFromModerationInfo(moderationInfo);
47+
if (meta != null && !meta.isEmpty()) {
48+
HereDeltaNs deltaNs = deltaNs(meta);
49+
if (deltaNs != null) {
5050
properties.setDeltaNamespace(deltaNs);
5151
}
52-
53-
if (!meta.isEmpty()) {
54-
HereMetaNs metaNs = new HereMetaNs();
55-
metaNs.putAll(meta);
56-
// remove properties that before MOM 10 lived in root properties
57-
metaNs.remove(CONFIDENCE);
58-
metaNs.remove(MODERATION_INFO);
59-
metaNs.remove(SOURCE_INFO);
52+
HereMetaNs metaNs = metaNs(meta);
53+
if (metaNs != null) {
6054
properties.setMetaNamespace(metaNs);
6155
}
6256
}
6357
}
6458

65-
private static HereDeltaNs deltaNsFromModerationInfo(@NotNull Map<String, Object> moderationInfo) {
66-
HereDeltaNs deltaNs = new HereDeltaNs();
67-
String rawChangeState = (String) moderationInfo.get(HereDeltaNs.CHANGE_STATE_PROPERTY);
68-
if (rawChangeState != null) {
69-
deltaNs.setChangeState(EChangeState.get(EChangeState.class, rawChangeState));
70-
}
71-
String rawReviewState = (String) moderationInfo.get(HereDeltaNs.REVIEW_STATE_PROPERTY);
72-
if (rawChangeState != null) {
73-
deltaNs.setReviewState(EReviewState.get(EReviewState.class, rawReviewState));
59+
private static @NotNull HereMetaNs metaNs(@NotNull Map<String, Object> meta) {
60+
HereMetaNs metaNs = new HereMetaNs();
61+
for (String metaKey : COMMON_META_PROPERTIES) {
62+
Object value = meta.get(metaKey);
63+
if (value != null) {
64+
metaNs.put(metaKey, value);
65+
}
7466
}
75-
for (Map.Entry<String, Object> entry : moderationInfo.entrySet()) {
76-
if (!entry.getKey().equals(HereDeltaNs.CHANGE_STATE_PROPERTY)
77-
&& !entry.getKey().equals(HereDeltaNs.REVIEW_STATE_PROPERTY)) {
78-
deltaNs.put(entry.getKey(), entry.getValue());
67+
return metaNs;
68+
}
69+
70+
private static @Nullable HereDeltaNs deltaNs(@NotNull Map<String, Object> meta) {
71+
Map<String, Object> moderationInfo = (Map<String, Object>) meta.get(MODERATION_INFO);
72+
if (moderationInfo == null) {
73+
return null;
74+
} else {
75+
HereDeltaNs deltaNs = new HereDeltaNs();
76+
String rawChangeState = (String) moderationInfo.get(DeltaProperties.CHANGE_STATE);
77+
if (rawChangeState != null) {
78+
deltaNs.setChangeState(JsonEnum.get(EChangeState.class, rawChangeState));
79+
}
80+
String rawReviewState = (String) moderationInfo.get(DeltaProperties.REVIEW_STATE);
81+
if (rawChangeState != null) {
82+
deltaNs.setReviewState(JsonEnum.get(EReviewState.class, rawReviewState));
83+
}
84+
String originId = (String) moderationInfo.get(DeltaProperties.ORIGIN_ID);
85+
if (originId != null) {
86+
deltaNs.setOriginId(originId);
87+
}
88+
String parentLink = (String) moderationInfo.get(DeltaProperties.PARENT_LINK);
89+
if (parentLink != null) {
90+
deltaNs.setParentLink(parentLink);
7991
}
92+
return deltaNs;
8093
}
81-
return deltaNs;
8294
}
8395

8496
public static void dropPreMom10Namespaces(@Nullable XyzFeature feature) {

here-naksha-lib-mom10/src/main/java/com/here/naksha/mom10/Mom10Verification.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828

2929
public class Mom10Verification {
3030

31-
private static final Pattern SEM_VER_PATTERN = Pattern.compile(
32-
"^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$");
31+
private static final Pattern SHORT_SEM_VER = Pattern.compile("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\..+$");
3332

3433
private Mom10Verification() {}
3534

@@ -50,7 +49,7 @@ private static boolean specifiesAtLeastMom10(@NotNull String modelVersion) {
5049
}
5150

5251
private static @Nullable Integer getMajorFrom(@NotNull String modelVersion) {
53-
Matcher matcher = SEM_VER_PATTERN.matcher(modelVersion);
52+
Matcher matcher = SHORT_SEM_VER.matcher(modelVersion);
5453
if (matcher.find()) {
5554
try {
5655
return Integer.parseInt(matcher.group(1));

0 commit comments

Comments
 (0)