Model 1C modules as object parts
This commit is contained in:
@@ -962,6 +962,11 @@ class ModuleSourceResponse(BaseModel):
|
||||
name: str
|
||||
qualified_name: str
|
||||
module_role: str = "MODULE"
|
||||
owner_qualified_name: str | None = None
|
||||
owner_kind: str | None = None
|
||||
object_part: str | None = None
|
||||
form_name: str | None = None
|
||||
form_qualified_name: str | None = None
|
||||
source_path: str
|
||||
source_text: str
|
||||
routines_count: int = 0
|
||||
@@ -1167,6 +1172,7 @@ class NamedNode(BaseModel):
|
||||
kind: str
|
||||
name: str
|
||||
qualified_name: str
|
||||
attributes: dict = Field(default_factory=dict)
|
||||
|
||||
|
||||
class ImpactResponse(BaseModel):
|
||||
@@ -5041,7 +5047,7 @@ def _metadata_child_group_children(
|
||||
for edge in snapshot.edges
|
||||
if edge.source_lineage == owner_id
|
||||
and edge.kind in edge_kinds
|
||||
and (edge.kind != EdgeKind.CONTAINS or edge.attributes.get("link_type") == "METADATA_MODULE")
|
||||
and (edge.kind != EdgeKind.CONTAINS or edge.attributes.get("link_type") in {"METADATA_MODULE", "FORM_MODULE"})
|
||||
]
|
||||
nodes_by_id = {node.lineage_id: node for node in snapshot.nodes}
|
||||
child_nodes = sorted(
|
||||
@@ -5366,7 +5372,7 @@ def _flowchart_owner_index(snapshot: SirSnapshot, nodes_by_lineage: dict[str, ob
|
||||
target = nodes_by_lineage.get(edge.target_lineage)
|
||||
if source is None or target is None:
|
||||
continue
|
||||
if edge.kind == EdgeKind.CONTAINS and edge.attributes.get("link_type") == "METADATA_MODULE":
|
||||
if edge.kind == EdgeKind.CONTAINS and edge.attributes.get("link_type") in {"METADATA_MODULE", "FORM_MODULE"}:
|
||||
owner_by_lineage[target.lineage_id] = source
|
||||
elif edge.kind in {EdgeKind.HAS_COMMAND, EdgeKind.HAS_ROLE, EdgeKind.HAS_ATTRIBUTE, EdgeKind.HAS_TABULAR_SECTION, EdgeKind.HAS_FORM, EdgeKind.HAS_ELEMENT}:
|
||||
owner_by_lineage[target.lineage_id] = source
|
||||
@@ -5424,13 +5430,16 @@ def _metadata_tree_path_for_node(snapshot: SirSnapshot, node_id: str) -> list[st
|
||||
return ["main-configuration", "common", f"common.{common_branch}", node.lineage_id]
|
||||
return ["main-configuration", f"branch.{spec.code}", node.lineage_id]
|
||||
|
||||
parent_edge = next((edge for edge in snapshot.edges if edge.target_lineage == node.lineage_id), None)
|
||||
parent_edges = [edge for edge in snapshot.edges if edge.target_lineage == node.lineage_id]
|
||||
parent_edge = next((edge for edge in parent_edges if edge.attributes.get("link_type") == "FORM_MODULE"), None)
|
||||
if parent_edge is None:
|
||||
parent_edge = next(iter(parent_edges), None)
|
||||
if parent_edge is None:
|
||||
return [node.lineage_id]
|
||||
owner_node = _find_snapshot_node(snapshot, parent_edge.source_lineage)
|
||||
if owner_node is None:
|
||||
return [node.lineage_id]
|
||||
group_name = _metadata_group_name_for_edge(parent_edge.kind)
|
||||
group_name = _metadata_group_name_for_edge(parent_edge)
|
||||
return [*_metadata_tree_path_for_node(snapshot, owner_node.lineage_id), f"{owner_node.lineage_id}.{group_name}", node.lineage_id]
|
||||
|
||||
|
||||
@@ -5539,7 +5548,10 @@ def _common_branch_label_for_spec(spec_code: str) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
def _metadata_group_name_for_edge(edge_kind: EdgeKind) -> str:
|
||||
def _metadata_group_name_for_edge(edge) -> str:
|
||||
edge_kind = getattr(edge, "kind", edge)
|
||||
if edge_kind == EdgeKind.CONTAINS and getattr(edge, "attributes", {}).get("link_type") == "FORM_MODULE":
|
||||
return "Модуль формы"
|
||||
return {
|
||||
EdgeKind.HAS_ATTRIBUTE: "Реквизиты",
|
||||
EdgeKind.HAS_TABULAR_SECTION: "Табличные части",
|
||||
@@ -5591,7 +5603,7 @@ def _metadata_child_group_count(snapshot: SirSnapshot, owner_id: str, group_name
|
||||
for edge in snapshot.edges
|
||||
if edge.source_lineage == owner_id
|
||||
and edge.kind in edge_kinds
|
||||
and (edge.kind != EdgeKind.CONTAINS or edge.attributes.get("link_type") == "METADATA_MODULE")
|
||||
and (edge.kind != EdgeKind.CONTAINS or edge.attributes.get("link_type") in {"METADATA_MODULE", "FORM_MODULE"})
|
||||
)
|
||||
|
||||
|
||||
@@ -5614,7 +5626,7 @@ def _metadata_child_count_index(snapshot: SirSnapshot, owner_ids: list[str]) ->
|
||||
result: dict[str, Counter[EdgeKind]] = {owner_id: Counter() for owner_id in owner_set}
|
||||
for edge in snapshot.edges:
|
||||
if edge.source_lineage in owner_set and (
|
||||
edge.kind != EdgeKind.CONTAINS or edge.attributes.get("link_type") == "METADATA_MODULE"
|
||||
edge.kind != EdgeKind.CONTAINS or edge.attributes.get("link_type") in {"METADATA_MODULE", "FORM_MODULE"}
|
||||
):
|
||||
result[edge.source_lineage][edge.kind] += 1
|
||||
return result
|
||||
@@ -9017,10 +9029,16 @@ def _normalized_module_source_response(module, owner) -> ModuleSourceResponse:
|
||||
attributes = module.attributes or {}
|
||||
source_text = str(attributes.get("source_text", ""))
|
||||
routines = _normalized_module_routines(source_text)
|
||||
module_role = str(module.module_kind or attributes.get("module_role") or "MODULE")
|
||||
return ModuleSourceResponse(
|
||||
name=module.name,
|
||||
qualified_name=module.qualified_name or module.name,
|
||||
module_role=str(module.module_kind or attributes.get("module_role") or "MODULE"),
|
||||
module_role=module_role,
|
||||
owner_qualified_name=str(attributes.get("owner_qualified_name") or getattr(owner, "qualified_name", "") or "") or None,
|
||||
owner_kind=str(attributes.get("owner_kind") or getattr(owner, "object_kind", "") or "") or None,
|
||||
object_part=str(attributes.get("object_part") or _module_object_part_for_response(module_role, str(attributes.get("form_name") or ""))),
|
||||
form_name=str(attributes.get("form_name") or "") or None,
|
||||
form_qualified_name=str(attributes.get("form_qualified_name") or "") or None,
|
||||
source_path=module.source_path or "",
|
||||
source_text=source_text,
|
||||
routines_count=len(routines),
|
||||
@@ -9028,6 +9046,16 @@ def _normalized_module_source_response(module, owner) -> ModuleSourceResponse:
|
||||
)
|
||||
|
||||
|
||||
def _module_object_part_for_response(module_role: str, form_name: str = "") -> str:
|
||||
return {
|
||||
"OBJECT_MODULE": "object.module",
|
||||
"MANAGER_MODULE": "object.manager",
|
||||
"RECORD_SET_MODULE": "object.record_set",
|
||||
"FORM_MODULE": f"form.{form_name}.module" if form_name else "form.module",
|
||||
"MODULE": "module",
|
||||
}.get(module_role, "module")
|
||||
|
||||
|
||||
def _normalized_module_routines(source_text: str) -> list[ModuleRoutineResponse]:
|
||||
if not source_text:
|
||||
return []
|
||||
@@ -9150,11 +9178,17 @@ def _module_sources_for_object(snapshot: SirSnapshot, qualified_name: str) -> li
|
||||
if module is None or module.kind != NodeKind.MODULE:
|
||||
continue
|
||||
routines = _module_routines(snapshot, module.lineage_id, nodes_by_lineage)
|
||||
module_role = str(edge.attributes.get("module_role") or module.attributes.get("module_role") or "MODULE")
|
||||
modules.append(
|
||||
ModuleSourceResponse(
|
||||
name=module.name,
|
||||
qualified_name=module.qualified_name,
|
||||
module_role=str(edge.attributes.get("module_role", "MODULE")),
|
||||
module_role=module_role,
|
||||
owner_qualified_name=str(module.attributes.get("owner_qualified_name") or owner.qualified_name or "") or None,
|
||||
owner_kind=str(module.attributes.get("owner_kind") or owner.kind.value or "") or None,
|
||||
object_part=str(edge.attributes.get("object_part") or module.attributes.get("object_part") or _module_object_part_for_response(module_role, str(module.attributes.get("form_name") or ""))),
|
||||
form_name=str(edge.attributes.get("form_name") or module.attributes.get("form_name") or "") or None,
|
||||
form_qualified_name=str(module.attributes.get("form_qualified_name") or "") or None,
|
||||
source_path=module.source_ref.source_path,
|
||||
source_text=str(module.attributes.get("source_text", "")),
|
||||
routines_count=len(routines),
|
||||
@@ -9180,11 +9214,22 @@ def _module_source_response(
|
||||
None,
|
||||
)
|
||||
routines = _module_routines(snapshot, module.lineage_id, nodes_by_lineage)
|
||||
owner = nodes_by_lineage.get(owner_edge.source_lineage) if owner_edge else None
|
||||
module_role = str((owner_edge.attributes.get("module_role") if owner_edge else None) or module.attributes.get("module_role") or "MODULE")
|
||||
return [
|
||||
ModuleSourceResponse(
|
||||
name=module.name,
|
||||
qualified_name=module.qualified_name,
|
||||
module_role=str(owner_edge.attributes.get("module_role", "MODULE")) if owner_edge else "MODULE",
|
||||
module_role=module_role,
|
||||
owner_qualified_name=str(module.attributes.get("owner_qualified_name") or getattr(owner, "qualified_name", "") or "") or None,
|
||||
owner_kind=str(module.attributes.get("owner_kind") or getattr(getattr(owner, "kind", None), "value", "") or "") or None,
|
||||
object_part=str(
|
||||
(owner_edge.attributes.get("object_part") if owner_edge else None)
|
||||
or module.attributes.get("object_part")
|
||||
or _module_object_part_for_response(module_role, str(module.attributes.get("form_name") or ""))
|
||||
),
|
||||
form_name=str((owner_edge.attributes.get("form_name") if owner_edge else None) or module.attributes.get("form_name") or "") or None,
|
||||
form_qualified_name=str(module.attributes.get("form_qualified_name") or "") or None,
|
||||
source_path=module.source_ref.source_path,
|
||||
source_text=str(module.attributes.get("source_text", "")),
|
||||
routines_count=len(routines),
|
||||
@@ -10676,4 +10721,5 @@ def _named_node(node) -> NamedNode:
|
||||
kind=node.kind.value,
|
||||
name=node.name,
|
||||
qualified_name=node.qualified_name,
|
||||
attributes=getattr(node, "attributes", {}) or {},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user