Skip to content

Commit

Permalink
fix!: Remove width and height from ELK input data
Browse files Browse the repository at this point in the history
  • Loading branch information
ewuerger committed Dec 9, 2024
1 parent a8b2b40 commit 494fa84
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
34 changes: 31 additions & 3 deletions capella2polarion/data_model/work_item_attachments.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0
"""Module providing the CapellaWorkItemAttachment classes."""

from __future__ import annotations

import base64
import copy
import dataclasses
import hashlib
import logging
Expand All @@ -12,7 +14,7 @@
import cairosvg
import polarion_rest_api_client as polarion_api
from capellambse import model
from capellambse_context_diagrams import context
from capellambse_context_diagrams import _elkjs, context

SVG_MIME_TYPE = "image/svg+xml"
PNG_MIME_TYPE = "image/png"
Expand Down Expand Up @@ -116,9 +118,15 @@ def content_checksum(self) -> str:
try:
elk_input = self.diagram.elk_input_data(self.render_params)
if isinstance(elk_input, tuple):
input_str = ";".join(eit.json() for eit in elk_input)
input_str = ";".join(
remove_width_and_height(eit).model_dump_json()
for eit in elk_input
)
else:
input_str = elk_input.json()
input_str = remove_width_and_height(
elk_input
).model_dump_json()

self._checksum = hashlib.sha256(
input_str.encode("utf-8")
).hexdigest()
Expand All @@ -134,6 +142,26 @@ def content_checksum(self) -> str:
return self._checksum


def remove_width_and_height(
elk_input: _elkjs.ELKInputData,
) -> _elkjs.ELKInputData:
"""Remove width and height from all elements in elk input."""

def process_item(item):
if hasattr(item, "width"):
del item.width
if hasattr(item, "height"):
del item.height

for attr in ("children", "edges", "ports", "labels"):
for element in getattr(item, attr, []):
process_item(element)

elk_input_copy = copy.deepcopy(elk_input)
process_item(elk_input_copy)
return elk_input_copy


class PngConvertedSvgAttachment(Capella2PolarionAttachment):
"""A special attachment type for PNGs which shall be created from SVGs.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_workitem_attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"0ed1417e8e4717524bc91162dcf8633afca686e93f8b036d0bc48d81f0444f56"
)
CONTEXT_DIAGRAM_CHECKSUM = (
"572cb7ba53bcde56638a119fafc1304af294467d8c851f4b2cc35ce2f5d231eb"
"a26f4fc31c6c1c3b96d5725fa727cfd5f8651bec68faf04c8113359855bf5461"
)

TEST_DIAG_UUID = "_APOQ0QPhEeynfbzU12yy7w"
Expand Down

0 comments on commit 494fa84

Please sign in to comment.