Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cognite_toolkit/_cdf_tk/apps/_migrate_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ConnectionCreator,
InFieldAssetMapping,
InFieldConditionMapping,
InFieldCreatableViews,
InFieldUserMapping,
)
from cognite_toolkit._cdf_tk.commands._migrate.creators import (
Expand Down Expand Up @@ -1625,7 +1626,11 @@ def infield_data(
client,
infield_mappings,
connection_creator=connection_creator,
custom_properties_mappings=[InFieldConditionMapping(infield_mappings), InFieldUserMapping()],
custom_properties_mappings=[
InFieldConditionMapping(infield_mappings),
InFieldUserMapping(),
InFieldCreatableViews(),
],
custom_instance_mappings={
InFieldLegacyToCDMScheduleMapper.SCHEDULE_VIEW: InFieldLegacyToCDMScheduleMapper(
client, connection_creator, schedule_mapping
Expand Down
38 changes: 38 additions & 0 deletions cognite_toolkit/_cdf_tk/commands/_migrate/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,44 @@ def _map_user(source_prop: str, target_prop: str) -> None:
return ConversionResult(container_properties=created_properties, errors=issues)


class InFieldCreatableViews(CustomContainerPropertiesMapping):
"""Custom mapping for all views that implements the creatable interface in the InField data migration.

In the Creatable in InFieldOnCDM the properties 'visibility' and 'isArchived' are typically null
in the Legacy model, but should be set explicitly to `PUBLIC` and `false` if they are null.

"""

VIEW_IDS: ClassVar[Set[ViewId]] = frozenset(
{
ViewId(space="cdf_apm", external_id="Action", version="v1"),
ViewId(space="cdf_apm", external_id="Checklist", version="v7"),
ViewId(space="cdf_apm", external_id="ChecklistItem", version="v7"),
ViewId(space="cdf_apm", external_id="Condition", version="v1"),
ViewId(space="cdf_apm", external_id="ConditionalAction", version="v1"),
ViewId(space="cdf_apm", external_id="MeasurementReading", version="v4"),
ViewId(space="cdf_apm", external_id="Schedule", version="v4"),
ViewId(space="cdf_apm", external_id="Template", version="v9"),
ViewId(space="cdf_apm", external_id="TemplateItem", version="v7"),
}
)

def convert(
self, source_properties: dict[str, JsonValue | NodeId | list[NodeId]], context: ConversionContext
) -> ConversionResult:
created_properties: dict[str, JsonValue | NodeId | list[NodeId]] = {}
issues: list[str] = []

is_archived = source_properties.get("isArchived", None)
if is_archived is None:
created_properties["isArchived"] = False
visibility = source_properties.get("visibility", None)
if visibility is None:
created_properties["visibility"] = "PUBLIC"

return ConversionResult(container_properties=created_properties, errors=issues)


class InFieldAssetMapping(CustomConnectionMapping[NodeId]):
"""Custom cases in the InField data migration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ instances:
createdBy:
externalId: VJZrRM_kByZe-moErWilvg
space: cognite_app_data
isArchived: false
item:
externalId: 0083e7c3-946f-4d5d-958b-133963108ad9
space: smoke_infield_migration_target_space
order: 2
sourceCreatedUser: VJZrRM_kByZe-moErWilvg
title: any comments ?
type: message
visibility: PUBLIC
space: smoke_infield_migration_target_space
- createdTime: 1772711569310
externalId: 2A7QpAmrd9eYbbY_zHH_Ag
Expand All @@ -25,6 +27,7 @@ instances:
createdBy:
externalId: VJZrRM_kByZe-moErWilvg
space: cognite_app_data
isArchived: false
item:
externalId: -3Z4iakG1YSFRAfVlazYMA
space: smoke_infield_migration_target_space
Expand All @@ -40,6 +43,7 @@ instances:
updatedBy:
externalId: VJZrRM_kByZe-moErWilvg
space: cognite_app_data
visibility: PUBLIC
space: smoke_infield_migration_target_space
- createdTime: 1772711570095
externalId: 431db206-55d6-4f37-9eff-6e7fd4bb37c7
Expand Down Expand Up @@ -100,6 +104,7 @@ instances:
test description character limitation test description character limitation
test description character limitation test description character limitation
test 111111111111111111111111111111111111
isArchived: false
labels:
- group:one Task group
order: 141
Expand All @@ -111,6 +116,7 @@ instances:
updatedBy:
externalId: VJZrRM_kByZe-moErWilvg
space: cognite_app_data
visibility: PUBLIC
space: smoke_infield_migration_target_space
- createdTime: 1772711568422
externalId: RhIUePwMQI0WDEQQv-xkig
Expand All @@ -137,6 +143,7 @@ instances:
updatedBy:
externalId: VJZrRM_kByZe-moErWilvg
space: cognite_app_data
visibility: PUBLIC
space: smoke_infield_migration_target_space
- createdTime: 1772711572850
externalId: -3Z4iakG1YSFRAfVlazYMA
Expand Down Expand Up @@ -170,6 +177,7 @@ instances:
updatedBy:
externalId: VJZrRM_kByZe-moErWilvg
space: cognite_app_data
visibility: PUBLIC
space: smoke_infield_migration_target_space
- createdTime: 1772715784353
externalId: -iExvo-uJ5JqMTPL2OYN-g
Expand All @@ -184,24 +192,28 @@ instances:
createdBy:
externalId: VJZrRM_kByZe-moErWilvg
space: cognite_app_data
isArchived: false
parameters:
message: 'item is not okay '
sourceCreatedUser: VJZrRM_kByZe-moErWilvg
sourceUpdatedUser: VJZrRM_kByZe-moErWilvg
updatedBy:
externalId: VJZrRM_kByZe-moErWilvg
space: cognite_app_data
visibility: PUBLIC
space: smoke_infield_migration_target_space
- createdTime: 1772715777591
externalId: 1DC026YVbKG3QYAOMzJoXw
instanceType: node
properties:
cdf_infield:
ConditionalAction/v1:
isArchived: false
logic: or
parentObject:
externalId: RhIUePwMQI0WDEQQv-xkig
space: smoke_infield_migration_target_space
visibility: PUBLIC
space: smoke_infield_migration_target_space
- createdTime: 1772715785819
externalId: dSq9c2wTh6geOGOIdh11yHhHXKEPWPfX1A8I317N9Sc_IrDfZSISoOzW9PPS3OpYnTAGShkwDS3bB4A49NONUyA_5_J63kPbDgRGDH0bCu8X2s5uLi8iQUm3uXdb6LArzAM_CzTrvN_VceSKRS45WPcooFlsmSgfL5l2aoWsLZmHdKo
Expand All @@ -213,12 +225,14 @@ instances:
externalId: 1DC026YVbKG3QYAOMzJoXw
space: smoke_infield_migration_target_space
field: status
isArchived: false
operator: equals
source:
externalId: -3Z4iakG1YSFRAfVlazYMA
space: smoke_infield_migration_target_space
sourceView: cdf_infield/ChecklistItem/v1
value: Not applicable
visibility: PUBLIC
space: smoke_infield_migration_target_space
- createdTime: 1776149020700
externalId: ae818e1b-82e7-446d-a645-05f0752d2c45
Expand Down
Loading