Skip to content

Commit

Permalink
fix: replace references in meta
Browse files Browse the repository at this point in the history
  • Loading branch information
eoaksnes authored and soofstad committed Apr 27, 2023
1 parent aec4f46 commit cfb6ea6
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dm_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "1.0.6"
VERSION = "1.0.7"
21 changes: 12 additions & 9 deletions dm_cli/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -130,6 +132,7 @@ class Dependency:
protocol: TDependencyProtocol
address: str
version: str = ""
type: str = ""

def __eq__(self, other):
return (
Expand Down
1 change: 0 additions & 1 deletion dm_cli/import_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions dm_cli/package_tree_from_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions dm_cli/utils/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"version": "0.0.1",
"dependencies": [
{
"type": "CORE:Dependency",
"alias": "CORE",
"address": "system/SIMOS",
"version": "0.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"version": "0.0.1",
"dependencies": [
{
"type": "CORE:Dependency",
"alias": "TEST-ENGINE",
"address": "system/SIMOS",
"version": "0.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"version": "0.0.1",
"dependencies": [
{
"type": "CORE:Dependency",
"alias": "TEST",
"address": "system/SIMOS",
"version": "0.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"version": "0.0.1",
"dependencies": [
{
"type": "CORE:Dependency",
"alias": "CORE",
"address": "system/SIMOS",
"version": "0.0.1",
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_import_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"version": "0.0.1",
"dependencies": [
{
"type": "CORE:Dependency",
"alias": "CORE",
"address": "system/SIMOS",
"version": "0.0.1",
Expand All @@ -62,6 +63,7 @@
"version": "0.0.1",
"dependencies": [
{
"type": "CORE:Dependency",
"alias": "CORE",
"address": "system/SIMOS",
"version": "0.0.1",
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_import_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"version": "0.0.1",
"dependencies": [
{
"type": "CORE:Dependency",
"alias": "CORE",
"address": "system/SIMOS",
"version": "0.0.1",
Expand All @@ -56,6 +57,7 @@
"version": "0.0.1",
"dependencies": [
{
"type": "CORE:Dependency",
"alias": "SINTEF",
"address": "marine-models.sintef.com/Signals",
"version": "1.2.3",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit cfb6ea6

Please sign in to comment.