Skip to content

Commit 54cd9de

Browse files
author
Jakub Amanowicz
committed
cherry picked mom10 from v2
Signed-off-by: Jakub Amanowicz <jakub.amanowicz@here.com>
1 parent 7ce37fe commit 54cd9de

File tree

19 files changed

+1081
-3
lines changed

19 files changed

+1081
-3
lines changed

here-naksha-lib-core/src/jvmMain/java/com/here/naksha/lib/core/models/geojson/implementation/namespaces/HereDeltaNs.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
@Deprecated
3434
public class HereDeltaNs extends JsonObject {
3535

36+
public static final String CHANGE_STATE_PROPERTY = "changeState";
37+
public static final String REVIEW_STATE_PROPERTY = "reviewState";
38+
3639
/**
3740
* Create a new default delta namespace for new features.
3841
*/
@@ -49,10 +52,10 @@ public HereDeltaNs() {
4952
*/
5053
@JsonCreator
5154
public HereDeltaNs(
52-
@JsonProperty("changeState") @Nullable MomChangeState changeState,
53-
@JsonProperty("reviewState") @Nullable MomReviewState reviewState) {
55+
@JsonProperty(CHANGE_STATE_PROPERTY) @Nullable MomChangeState changeState,
56+
@JsonProperty(REVIEW_STATE_PROPERTY) @Nullable MomReviewState reviewState) {
5457
if (changeState == null) {
55-
changeState = MomChangeState.CREATED;
58+
changeState = EChangeState.CREATED;
5659
}
5760
if (reviewState == null) {
5861
reviewState = MomReviewState.UNPUBLISHED;

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+
}
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 com.here.naksha.lib.core.models.geojson.implementation.XyzProperties;
22+
import java.util.Collections;
23+
import java.util.HashSet;
24+
import java.util.Set;
25+
26+
/**
27+
* Some of Meta-related properties from MOM 10
28+
*/
29+
public class MetaProperties {
30+
31+
private MetaProperties() {}
32+
33+
/**
34+
* Renamed in MOM 10 from {@link XyzProperties#HERE_META_NS}
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 XyzProperties#HERE_DELTA_NS} 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 com.here.naksha.lib.core.models.geojson.implementation.XyzFeature;
26+
import com.here.naksha.lib.core.models.geojson.implementation.XyzProperties;
27+
import com.here.naksha.lib.core.models.geojson.implementation.namespaces.EChangeState;
28+
import com.here.naksha.lib.core.models.geojson.implementation.namespaces.EReviewState;
29+
import com.here.naksha.lib.core.models.geojson.implementation.namespaces.HereDeltaNs;
30+
import com.here.naksha.lib.core.models.geojson.implementation.namespaces.HereMetaNs;
31+
import com.here.naksha.lib.core.util.json.JsonEnum;
32+
import java.util.Map;
33+
import org.jetbrains.annotations.NotNull;
34+
import org.jetbrains.annotations.Nullable;
35+
36+
public class Mom10Transformation {
37+
38+
private Mom10Transformation() {}
39+
40+
public static void populatePreMom10Namespaces(@Nullable XyzFeature feature) {
41+
if (feature == null) {
42+
return;
43+
}
44+
45+
XyzProperties properties = feature.getProperties();
46+
Map<String, Object> meta = (Map<String, Object>) properties.get(META);
47+
if (meta != null && !meta.isEmpty()) {
48+
HereDeltaNs deltaNs = deltaNs(meta);
49+
properties.setDeltaNamespace(deltaNs);
50+
HereMetaNs metaNs = metaNs(meta);
51+
properties.setMetaNamespace(metaNs);
52+
}
53+
}
54+
55+
private static @NotNull HereMetaNs metaNs(@NotNull Map<String, Object> meta) {
56+
HereMetaNs metaNs = new HereMetaNs();
57+
for (String metaKey : COMMON_META_PROPERTIES) {
58+
Object value = meta.get(metaKey);
59+
if (value != null) {
60+
metaNs.put(metaKey, value);
61+
}
62+
}
63+
return metaNs;
64+
}
65+
66+
private static @Nullable HereDeltaNs deltaNs(@NotNull Map<String, Object> meta) {
67+
Map<String, Object> moderationInfo = (Map<String, Object>) meta.get(MODERATION_INFO);
68+
if (moderationInfo == null) {
69+
return null;
70+
} else {
71+
HereDeltaNs deltaNs = new HereDeltaNs();
72+
String rawChangeState = (String) moderationInfo.get(DeltaProperties.CHANGE_STATE);
73+
if (rawChangeState != null) {
74+
deltaNs.setChangeState(JsonEnum.get(EChangeState.class, rawChangeState));
75+
}
76+
String rawReviewState = (String) moderationInfo.get(DeltaProperties.REVIEW_STATE);
77+
if (rawChangeState != null) {
78+
deltaNs.setReviewState(JsonEnum.get(EReviewState.class, rawReviewState));
79+
}
80+
String originId = (String) moderationInfo.get(DeltaProperties.ORIGIN_ID);
81+
if (originId != null) {
82+
deltaNs.setOriginId(originId);
83+
}
84+
String parentLink = (String) moderationInfo.get(DeltaProperties.PARENT_LINK);
85+
if (parentLink != null) {
86+
deltaNs.setParentLink(parentLink);
87+
}
88+
return deltaNs;
89+
}
90+
}
91+
92+
public static void dropPreMom10Namespaces(@Nullable XyzFeature feature) {
93+
XyzProperties properties = feature.getProperties();
94+
properties.remove(XyzProperties.HERE_META_NS);
95+
properties.remove(XyzProperties.HERE_DELTA_NS);
96+
}
97+
}

0 commit comments

Comments
 (0)