diff --git a/dm_cli/__init__.py b/dm_cli/__init__.py index 89bec30..0ae9338 100644 --- a/dm_cli/__init__.py +++ b/dm_cli/__init__.py @@ -1 +1 @@ -VERSION = "1.0.6" +VERSION = "1.0.7" diff --git a/dm_cli/domain.py b/dm_cli/domain.py index 707eadf..baa97ca 100644 --- a/dm_cli/domain.py +++ b/dm_cli/domain.py @@ -92,26 +92,28 @@ def _content_to_ref_dict(self): if isinstance(child, Package): result.append( { - "ref": str(child.uid), - "targetName": child.name, - "targetType": SIMOS.PACKAGE.value, - "type": "dmss://system/SIMOS/Link", + "address": str(child.uid), + "type": "dmss://system/SIMOS/Reference", + "referenceType": "link", } ) else: # Assume the child is a dict if "name" in child: result.append( { - "ref": child["_id"], - "targetName": child["name"], - "targetType": child["type"], - "type": "dmss://system/SIMOS/Link", + "address": child["_id"], + "type": "dmss://system/SIMOS/Reference", + "referenceType": "link", } ) else: result.append( - {"ref": child["_id"], "targetType": child["type"], "type": "dmss://system/SIMOS/Link"} + { + "address": child["_id"], + "type": "dmss://system/SIMOS/Reference", + "referenceType": "link", + } ) return result @@ -130,6 +132,7 @@ class Dependency: protocol: TDependencyProtocol address: str version: str = "" + type: str = "" def __eq__(self, other): return ( diff --git a/dm_cli/import_entity.py b/dm_cli/import_entity.py index ca99302..2f5259c 100644 --- a/dm_cli/import_entity.py +++ b/dm_cli/import_entity.py @@ -70,7 +70,6 @@ def import_folder_entity(source_path: Path, destination: str) -> None: print(f"Importing PACKAGE '{source_path.name}' --> '{destination}/'") destination_path = Path(destination) data_source = destination_path.parts[0] - try: # Check if target already exists on remote. Then delete or raise exception dmss_api.document_get_by_path(f"dmss://{destination}/{source_path.name}") if not state.force: diff --git a/dm_cli/package_tree_from_zip.py b/dm_cli/package_tree_from_zip.py index d1be9e4..dd352bc 100644 --- a/dm_cli/package_tree_from_zip.py +++ b/dm_cli/package_tree_from_zip.py @@ -88,4 +88,9 @@ def package_tree_from_zip( update=True, ) + # Make sure to replace relative references in _meta_ + root_package.meta = replace_relative_references( + "_meta_", root_package.meta, dependencies, data_source_id, file_path=root_package.path() + ) + return root_package diff --git a/dm_cli/utils/reference.py b/dm_cli/utils/reference.py index 585cbe0..fd27d98 100644 --- a/dm_cli/utils/reference.py +++ b/dm_cli/utils/reference.py @@ -70,6 +70,7 @@ def replace_relative_references( When importing packages, the following additional parameter is required: @param zip_file: """ + KEYS_TO_CHECK = ("type", "attributeType", "extends", "_blueprintPath_") # These keys may contain a reference if key in KEYS_TO_CHECK: @@ -94,8 +95,8 @@ def replace_relative_references( file_path, ) - # If the value is a complex type, dig down recursively. Ignore the _meta_ key - if key != "_meta_" and isinstance(value, dict) and value != {}: + # If the value is a complex type, dig down recursively. + if isinstance(value, dict) and value != {}: # First check if the type is a blob type if ( replace_relative_references( diff --git a/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/instances/package.json b/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/instances/package.json index 53fb7b7..15a7376 100644 --- a/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/instances/package.json +++ b/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/instances/package.json @@ -6,12 +6,14 @@ "version": "0.0.1", "dependencies": [ { + "type": "CORE:Dependency", "alias": "CORE", "address": "system/SIMOS", "version": "0.0.1", "protocol": "dmss" }, { + "type": "CORE:Dependency", "alias": "TEST-MODELS", "address": "DemoApplicationDataSource/models", "version": "0.0.1", diff --git a/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/models/CarPackage/Car.json b/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/models/CarPackage/Car.json index 09e1630..c00999f 100644 --- a/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/models/CarPackage/Car.json +++ b/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/models/CarPackage/Car.json @@ -8,6 +8,7 @@ "version": "0.0.1", "dependencies": [ { + "type": "CORE:Dependency", "alias": "CORE", "address": "system/SIMOS", "version": "0.0.1", diff --git a/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/models/CarPackage/EnginePackage/package.json b/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/models/CarPackage/EnginePackage/package.json index 0c038cc..a712103 100644 --- a/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/models/CarPackage/EnginePackage/package.json +++ b/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/models/CarPackage/EnginePackage/package.json @@ -6,6 +6,7 @@ "version": "0.0.1", "dependencies": [ { + "type": "CORE:Dependency", "alias": "TEST-ENGINE", "address": "system/SIMOS", "version": "0.0.1", diff --git a/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/models/CarPackage/package.json b/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/models/CarPackage/package.json index 5bd7999..a7723a9 100644 --- a/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/models/CarPackage/package.json +++ b/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/models/CarPackage/package.json @@ -6,6 +6,7 @@ "version": "0.0.1", "dependencies": [ { + "type": "CORE:Dependency", "alias": "TEST", "address": "system/SIMOS", "version": "0.0.1", diff --git a/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/models/package.json b/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/models/package.json index 676819e..8861155 100644 --- a/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/models/package.json +++ b/tests/test_data/test_app_dir_struct/data/DemoApplicationDataSource/models/package.json @@ -6,6 +6,7 @@ "version": "0.0.1", "dependencies": [ { + "type": "CORE:Dependency", "alias": "CORE", "address": "system/SIMOS", "version": "0.0.1", diff --git a/tests/unit/test_import_entity.py b/tests/unit/test_import_entity.py index 5e291e5..bffde88 100644 --- a/tests/unit/test_import_entity.py +++ b/tests/unit/test_import_entity.py @@ -36,6 +36,7 @@ "version": "0.0.1", "dependencies": [ { + "type": "CORE:Dependency", "alias": "CORE", "address": "system/SIMOS", "version": "0.0.1", @@ -62,6 +63,7 @@ "version": "0.0.1", "dependencies": [ { + "type": "CORE:Dependency", "alias": "CORE", "address": "system/SIMOS", "version": "0.0.1", @@ -123,9 +125,7 @@ def test_replace_relative_references(self): assert prepared_document["attributes"][0]["type"] == f"{REFERENCE_PREFIX}/BlueprintAttribute" # Ensure the attribute's attributeType is not replaced, as it's a primitive assert prepared_document["attributes"][0]["attributeType"] == "integer" - - # _meta_ references should not be replaced - assert prepared_document["_meta_"]["type"] == document["_meta_"]["type"] + assert prepared_document["_meta_"]["type"] == "dmss://system/SIMOS/Meta" def test_replace_relative_references_no_meta(self): src_path = Path("MyRootPackage/Moorings/Mooring_no_meta.json") diff --git a/tests/unit/test_import_package.py b/tests/unit/test_import_package.py index f5f2b4a..923d840 100644 --- a/tests/unit/test_import_package.py +++ b/tests/unit/test_import_package.py @@ -39,6 +39,7 @@ "version": "0.0.1", "dependencies": [ { + "type": "CORE:Dependency", "alias": "CORE", "address": "system/SIMOS", "version": "0.0.1", @@ -56,6 +57,7 @@ "version": "0.0.1", "dependencies": [ { + "type": "CORE:Dependency", "alias": "SINTEF", "address": "marine-models.sintef.com/Signals", "version": "1.2.3", @@ -194,12 +196,14 @@ "version": "0.0.1", "dependencies": [ { + "type": "CORE:Dependency", "alias": "CORE", "address": "system/SIMOS", "version": "0.0.1", "protocol": "dmss", }, { + "type": "CORE:Dependency", "alias": "SINTEF", "address": "marine-models.sintef.com/Signals", "version": "1.2.3", @@ -217,6 +221,7 @@ "version": "0.0.1", "dependencies": [ { + "type": "CORE:Dependency", "alias": "SINTEF", "address": "marine-models.sintef.com/Signals/SpecialSignals", "version": "3.2.1",