diff --git a/capella2polarion/elements/__init__.py b/capella2polarion/elements/__init__.py index 9dc0696b..5c7c8b48 100644 --- a/capella2polarion/elements/__init__.py +++ b/capella2polarion/elements/__init__.py @@ -33,7 +33,9 @@ } PHYSICAL_COMPONENT_TYPES = { "PhysicalComponentNode": "PhysicalComponent", + "PhysicalActorNode": "PhysicalComponent", "PhysicalComponentBehavior": "PhysicalComponent", + "PhysicalActorBehavior": "PhysicalComponent", } POL2CAPELLA_TYPES: dict[str, str] = ( { @@ -232,25 +234,22 @@ def _fix_components( elements[typ] = actors elements[xtype] = components - nodes: list[common.GenericElement] = [] - behaviors: list[common.GenericElement] = [] - components = [] + nature_mapping: dict[str, tuple[list[common.GenericElement], str]] = { + "None": ([], "PhysicalComponentNode"), + "NODE": ([], "PhysicalComponentNode"), + "BEHAVIOR": ([], "PhysicalComponentBehavior"), + "NODE_actor": ([], "PhysicalActorNode"), + "BEHAVIOR_actor": ([], "PhysicalActorBehavior"), + } for obj in elements.get("PhysicalComponent", []): - if obj.nature is not None and obj.nature.name == "NODE": - nodes.append(obj) - type_map[obj.uuid] = "PhysicalComponentNode" - elif obj.nature is not None and obj.nature.name == "BEHAVIOR": - behaviors.append(obj) - type_map[obj.uuid] = "PhysicalComponentBehavior" - else: - components.append(obj) - - if nodes: - elements["PhysicalComponentNode"] = nodes - if behaviors: - elements["PhysicalComponentBehavior"] = behaviors - if components: - elements["PhysicalComponent"] = components + is_actor = "_actor" if obj.is_actor else "" + container, xtype = nature_mapping[f"{str(obj.nature)}{is_actor}"] + container.append(obj) + type_map[obj.uuid] = xtype + + for container, xtype in nature_mapping.values(): + if container: + elements[xtype] = container def make_model_elements_index(ctx: dict[str, t.Any]) -> None: diff --git a/capella2polarion/elements/serialize.py b/capella2polarion/elements/serialize.py index 856cf84a..50954dab 100644 --- a/capella2polarion/elements/serialize.py +++ b/capella2polarion/elements/serialize.py @@ -291,42 +291,13 @@ def _condition(html: bool, value: str) -> CapellaWorkItem.Condition: return {"type": _type, "value": value} -def component_or_actor( - obj: cs.Component, ctx: dict[str, t.Any] -) -> CapellaWorkItem: - """Return attributes for a ``Component``.""" - work_item = _generic_work_item(obj, ctx) - if obj.is_actor: - xtype = RE_CAMEL_CASE_2ND_WORD_PATTERN.sub( - r"\1Actor", type(obj).__name__ - ) - # pylint: disable-next=attribute-defined-outside-init - work_item.type = helpers.resolve_element_type(xtype) - return work_item - - -def physical_component( - obj: pa.PhysicalComponent, ctx: dict[str, t.Any] -) -> CapellaWorkItem: - """Return attributes for a ``PhysicalComponent``.""" - work_item = component_or_actor(obj, ctx) - xtype = work_item.type - if obj.nature is not None: - # pylint: disable-next=attribute-defined-outside-init - work_item.type = f"{xtype}{obj.nature.name.capitalize()}" - return work_item - - Serializer = cabc.Callable[ [common.GenericElement, dict[str, t.Any]], CapellaWorkItem ] SERIALIZERS: dict[str, Serializer] = { "CapabilityRealization": include_pre_and_post_condition, - "LogicalComponent": component_or_actor, "OperationalCapability": include_pre_and_post_condition, - "PhysicalComponent": physical_component, "SystemCapability": include_pre_and_post_condition, - "SystemComponent": component_or_actor, "Scenario": include_pre_and_post_condition, "Constraint": constraint, }