-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add add_attributes
serializer
#139
base: main
Are you sure you want to change the base?
Changes from all commits
64d0692
ee26a4f
fac3949
f9a300b
d0a3155
20da2f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
"""Objects for serialization of capella objects to workitems.""" | ||
|
||
from __future__ import annotations | ||
|
||
import collections | ||
import enum | ||
import hashlib | ||
import logging | ||
import mimetypes | ||
|
@@ -33,6 +35,14 @@ | |
logger = logging.getLogger(__name__) | ||
C2P_IMAGE_PREFIX = "__C2P__" | ||
JINJA_RENDERED_IMG_CLS = "jinja-rendered-image" | ||
ARCHITECTURE_LAYERS: dict[str, str] = { | ||
"common": "Common", | ||
"oa": "Operational Analysis", | ||
"sa": "System Analysis", | ||
"la": "Logical Architecture", | ||
"pa": "Physical Architecture", | ||
"epbs": "EPBS", | ||
} | ||
|
||
|
||
def resolve_element_type(type_: str) -> str: | ||
|
@@ -57,6 +67,16 @@ def _format(texts: list[str]) -> dict[str, str]: | |
return requirement_types | ||
|
||
|
||
def _resolve_capella_attribute( | ||
element: m.ModelElement | m.Diagram, attribute: str | ||
) -> polarion_api.TextContent: | ||
value = getattr(element, attribute) | ||
if isinstance(value, enum.Enum): | ||
return polarion_api.TextContent(type="string", value=value.name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we return |
||
|
||
raise ValueError(f"Unsupported attribute type: {value!r}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should be more generic here. We could add an HTML-Flag to the config of an attribute. If this flag is set, we export the value of the attribute as |
||
|
||
|
||
class CapellaWorkItemSerializer(polarion_html_helper.JinjaRendererMixin): | ||
"""The general serializer class for CapellaWorkItems.""" | ||
|
||
|
@@ -424,6 +444,10 @@ def __generic_work_item( | |
obj, raw_description or markupsafe.Markup("") | ||
) | ||
converter_data.description_references = uuids | ||
layer = polarion_api.TextContent( | ||
type="string", | ||
value=ARCHITECTURE_LAYERS.get(converter_data.layer, "UNKNOWN"), | ||
) | ||
requirement_types = self._get_requirement_types_text(obj) | ||
|
||
converter_data.work_item = data_model.CapellaWorkItem( | ||
|
@@ -433,6 +457,7 @@ def __generic_work_item( | |
uuid_capella=obj.uuid, | ||
description=polarion_api.HtmlContent(value), | ||
status="open", | ||
layer=layer, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought we would add the layer optional via the |
||
**requirement_types, # type:ignore[arg-type] | ||
) | ||
assert converter_data.work_item is not None | ||
|
@@ -441,6 +466,32 @@ def __generic_work_item( | |
|
||
return converter_data.work_item | ||
|
||
def _add_attributes( | ||
self, | ||
converter_data: data_session.ConverterData, | ||
attributes: list[dict[str, t.Any]], | ||
): | ||
assert converter_data.work_item is not None | ||
for attribute in attributes: | ||
try: | ||
value = _resolve_capella_attribute( | ||
converter_data.capella_element, attribute["capella_attr"] | ||
) | ||
setattr( | ||
converter_data.work_item, attribute["polarion_id"], value | ||
) | ||
except AttributeError: | ||
logger.error( | ||
"Attribute %r not found on %r", | ||
attribute["capella_attr"], | ||
converter_data.type_config.p_type, | ||
) | ||
continue | ||
except ValueError as error: | ||
logger.error(error.args[0]) | ||
|
||
return converter_data.work_item | ||
|
||
def _diagram( | ||
self, | ||
converter_data: data_session.ConverterData, | ||
|
@@ -451,6 +502,10 @@ def _diagram( | |
assert converter_data.work_item is not None | ||
assert isinstance(diagram, m.Diagram) | ||
work_item_id = converter_data.work_item.id | ||
layer = polarion_api.TextContent( | ||
type="string", | ||
value=ARCHITECTURE_LAYERS.get(converter_data.layer, "UNKNOWN"), | ||
) | ||
|
||
diagram_html, attachment = self._draw_diagram_svg( | ||
diagram, | ||
|
@@ -473,6 +528,7 @@ def _diagram( | |
uuid_capella=diagram.uuid, | ||
description=polarion_api.HtmlContent(diagram_html), | ||
status="open", | ||
layer=layer, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the layer will in the future always be part of a diagram workitem and this is not configurable. I think this is fine, but needs to be communicated as a change in the release notes |
||
) | ||
if attachment: | ||
self._add_attachment(converter_data.work_item, attachment) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to have this as enum defined in Polarion, wouldn't it? This way we could just post the actual values like
oa
to Polarion and there it can be handled including localization.