Skip to content

Commit

Permalink
Fix simulated attribute override display when creating objects
Browse files Browse the repository at this point in the history
  • Loading branch information
rehoumir committed Sep 5, 2024
1 parent 56366bb commit c3c356c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
3 changes: 2 additions & 1 deletion project_rossum_deploy/commands/migrate/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from project_rossum_deploy.common.determine_path import determine_object_type_from_url
from project_rossum_deploy.utils.consts import (
MIGRATE_PLANNING_MODE_OBJECT_PLACEHOLDER,
display_warning,
settings,
MAPPING_SELECTED_ATTRIBUTE,
Expand Down Expand Up @@ -222,7 +223,7 @@ async def simulate_migrate_object(
return target_object
else:
print(
f'[red]CREATE[/red] [yellow]{object_type.value}[/yellow]: source "{source_object.get('id', None)} {source_object.get('name', '')}" -> target "{target_id} {target_object.get('name', 'no-name')}" {object_counter}.'
f'[red]CREATE[/red] [yellow]{object_type.value}[/yellow]: source "{source_object.get('id', None)} {source_object.get('name', '')}" -> target "{MIGRATE_PLANNING_MODE_OBJECT_PLACEHOLDER}" {object_counter}.'
)
return copy.deepcopy(source_object)

Expand Down
9 changes: 8 additions & 1 deletion project_rossum_deploy/commands/migrate/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ async def migrate_hooks(
errors: dict = {},
force: bool = False,
):
hook_paths = [hook_path async for hook_path in (source_path / "hooks").iterdir()]
if not await (source_path / "hooks").exists():
return

hook_paths = [
hook_path
async for hook_path in (source_path / "hooks").iterdir()
if await hook_path.is_file()
]

target_token_owner_id = ""
if not settings.IS_PROJECT_IN_SAME_ORG:
Expand Down
12 changes: 10 additions & 2 deletions project_rossum_deploy/commands/migrate/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ async def migrate_schemas(
errors: dict = {},
force: bool = False,
):
if not await (source_path / "schemas").exists():
return

schema_paths = [
schema_path async for schema_path in (source_path / "schemas").iterdir()
schema_path
async for schema_path in (source_path / "schemas").iterdir()
if await schema_path.is_file()
]

async def migrate_schema(schema_path: Path):
Expand Down Expand Up @@ -103,7 +108,7 @@ async def migrate_schema(schema_path: Path):
display_error(f"Error while migrating schema: {e}", e)

if plan_only:
print(Panel("Simulating workspaces."))
print(Panel("Simulating schemas."))

await asyncio.gather(
*[
Expand Down Expand Up @@ -146,6 +151,9 @@ async def update_formula_fields_code(schema_path: Path, schema: dict):
return

async for field_file_path in formula_directory.iterdir():
if not await field_file_path.is_file():
continue

formula_code = await read_formula_file(field_file_path)
formula_name = field_file_path.stem

Expand Down
4 changes: 4 additions & 0 deletions project_rossum_deploy/commands/migrate/workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ async def migrate_workspaces(
errors: dict = {},
force: bool = False,
):
if not (await (source_path / "workspaces").exists()):
return

workspace_paths = [
workspace_path
async for workspace_path in (source_path / "workspaces").iterdir()
if await workspace_path.is_dir()
]

async def migrate_workspace(ws_path: Path):
Expand Down
22 changes: 17 additions & 5 deletions project_rossum_deploy/common/attribute_override.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from project_rossum_deploy.utils.consts import (
ATTRIBUTE_OVERRIDE_SOURCE_REFERENCE_KEYWORD,
ATTRIBUTE_OVERRIDE_TARGET_REFERENCE_KEYWORD,
MIGRATE_PLANNING_MODE_OBJECT_PLACEHOLDER,
)
from project_rossum_deploy.utils.functions import (
flatten,
Expand Down Expand Up @@ -320,7 +321,7 @@ async def override_migrated_objects_attributes(
)
# Explicit override for settings and anything else
attribute_overrides = find_attribute_override_for_target(
targets_in_mapping, target_object["id"]
targets_in_mapping, target_object["id"], target_index
)
if not attribute_overrides:
continue
Expand Down Expand Up @@ -366,13 +367,24 @@ def print_simulation_message(
target_object: dict,
source_object_subset: dict,
):
return f'Simulated [green]{attribute_override_type}[/green] attribute override of [yellow]{object_type}[/yellow]: source "{source_object['id']} {source_object.get('name', 'no-name')}" to target "{target_object['id']} {target_object.get('name', 'no-name')}": {json.dumps(source_object_subset, indent=2)}'
target_name = (
f'{target_object['id']} {target_object.get('name', 'no-name')}'
if target_object["id"] != source_object["id"]
else MIGRATE_PLANNING_MODE_OBJECT_PLACEHOLDER
)
return f'Simulated [green]{attribute_override_type}[/green] attribute override of [yellow]{object_type}[/yellow]: source "{source_object['id']} {source_object.get('name', 'no-name')}" to target "{target_name}": {json.dumps(source_object_subset, indent=2)}'


def find_attribute_override_for_target(targets_in_mapping: dict, target_id: int):
for target in targets_in_mapping:
if target.get("target_id", None) == target_id:
def find_attribute_override_for_target(
targets_in_mapping: dict, target_id: int, target_index: int
):
for iterated_target_index, target in enumerate(targets_in_mapping):
iterated_target_id = target.get("target_id", None)
if iterated_target_id is None and target_index == iterated_target_index:
return target.get("attribute_override", {})
elif iterated_target_id == target_id:
return target.get("attribute_override", {})

return {}


Expand Down
2 changes: 2 additions & 0 deletions project_rossum_deploy/utils/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
ATTRIBUTE_OVERRIDE_TARGET_REFERENCE_KEYWORD = "$prd_ref"
ATTRIBUTE_OVERRIDE_SOURCE_REFERENCE_KEYWORD = "$source_value"

MIGRATE_PLANNING_MODE_OBJECT_PLACEHOLDER = "ID-WOULD-BE-CREATED"

MAPPING_SELECTED_ATTRIBUTE = "is_selected"


Expand Down

0 comments on commit c3c356c

Please sign in to comment.