Skip to content

Commit

Permalink
ci(capella2polarion): Add full authority document rendering for Physi…
Browse files Browse the repository at this point in the history
…cal Interfaces
  • Loading branch information
ewuerger committed Sep 19, 2024
1 parent f13d895 commit 644fe98
Show file tree
Hide file tree
Showing 10 changed files with 310 additions and 3 deletions.
20 changes: 20 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ variables:
CAPELLA2POLARION_DEBUG: 1
CAPELLA2POLARION_FORCE_UPDATE: 0
CAPELLAMBSE_PUSH_MODEL_BADGE: 0
CAPELLA2POLARION_DOCUMENT_CONFIG: capella2polarion_document_config.yaml.j2
CAPELLA2POLARION_OVERWRITE_LAYOUTS: 1
CAPELLA2POLARION_OVERWRITE_NUMBERING: 1

capella2polarion_synchronise_elements:
needs:
Expand All @@ -47,3 +50,20 @@ capella2polarion_synchronise_elements:
$([[ $CAPELLA2POLARION_FORCE_UPDATE -eq 1 ]] && echo '--force-update') \
${CAPELLA2POLARION_TYPE_PREFIX:+--type-prefix="$CAPELLA2POLARION_TYPE_PREFIX"} \
${CAPELLA2POLARION_ROLE_PREFIX:+--role-prefix="$CAPELLA2POLARION_ROLE_PREFIX"}
capella2polarion_render_documents:
needs:
- job: capella2polarion_synchronise_elements

script:
- pip install git+https://github.com/DSD-DBS/[email protected]
- >
python \
-m capella2polarion \
$([[ $CAPELLA2POLARION_DEBUG -eq 1 ]] && echo '--debug') \
--polarion-project-id=${CAPELLA2POLARION_PROJECT_ID:?} \
--capella-model="${CAPELLA2POLARION_MODEL_JSON:?}" \
render-documents \
$([[ $CAPELLA2POLARION_OVERWRITE_LAYOUTS -eq 1 ]] && echo '--overwrite-layouts') \
$([[ $CAPELLA2POLARION_OVERWRITE_NUMBERING -eq 1 ]] && echo '--overwrite-numbering') \
--document-rendering-config="${CAPELLA2POLARION_DOCUMENT_CONFIG:?}"
82 changes: 82 additions & 0 deletions capella2polarion_document_config.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0

full_authority:
- template_directory: jinja/document_templates
template: icd-interfaces-full_auth.html.j2
heading_numbering: True
work_item_layouts:
componentExchange:
fields_at_start:
- id
fields_at_end:
- context_diagram
physicalLink:
fields_at_start:
- id
fields_at_end:
- context_diagram
physicalActor:
fields_at_start:
- id
physicalComponentActor:
fields_at_start:
- id
physicalComponentNode:
fields_at_start:
- id
physicalComponentBehavior:
fields_at_start:
- id
class:
show_title: False
fields_at_end:
- tree_view
exchangeItem:
show_title: False
instances:
{%- for pl in model.search("PhysicalLink") %}
{%- if pl.ends %}
- polarion_space: Interface Documents
polarion_name: {{ pl.uuid }}
polarion_title: "{{ pl.name | safe }}"
params:
physical_link: {{ pl.uuid }}
{%- endif -%}
{% endfor %}
{# mixed_authority:
- template_directory: jinja/document_templates
heading_numbering: True
project_id: PROJECT_ID
work_item_layouts:
text:
show_title: False
physicalLink:
fields_at_start:
- id
physicalActor:
fields_at_start:
- id
physicalComponentActor:
fields_at_start:
- id
physicalComponentNode:
fields_at_start:
- id
physicalComponentBehavior:
fields_at_start:
- id
class:
show_title: False
fields_at_end:
- tree_view
exchangeItem:
show_title: False
sections:
IcdContent: icd-interfaces-mixed_authority.html.j2
instances:
- polarion_space: _default
polarion_name: NAME
polarion_title: TITLE
params:
physical_link: UUID #}
156 changes: 156 additions & 0 deletions jinja/document_templates/icd-interfaces-common.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{#
Copyright DB InfraGO AG and contributors
SPDX-License-Identifier: Apache-2.0
#}

{% set table_attributes='class="polarion-Document-table" style="margin: auto;margin-left: 0px;empty-cells: show;border-collapse: collapse;max-width: 1280px;border: 1px solid #CCCCCC;"' %}
{% set th_attributes='style="height: 12px;text-align: left;vertical-align: top;font-weight: bold;background-color: #F0F0F0;border: 1px solid #CCCCCC;padding: 5px;"' %}
{% set td_attributes='style="height: 12px;text-align: left;vertical-align: top;line-height: 18px;border: 1px solid #CCCCCC;padding: 5px;"' %}

{% macro add_class_dependencies(cls, classes) %}
{% if cls and cls.xtype == "org.polarsys.capella.core.data.information:Class" and not cls in classes %}
{% set _none = classes.append(cls) %}
{% if cls.super %}
{{ add_class_dependencies(cls.super, classes) }}
{% endif %}
{% for property in cls.properties %}
{% set type = None %}
{% if "type" in property.__dir__() %}
{% set type = property.type %}
{% elif "abstract_type" in property.__dir__() %}
{% set type = property.abstract_type %}
{% endif %}
{{ add_class_dependencies(type, classes) }}
{% endfor %}
{% endif %}
{% endmacro %}

{% macro render_content(physical_link, model, session) %}
{% set component_exchanges = physical_link.exchanges %}
{% set component_exchanges_components = (component_exchanges.map("source.owner") + component_exchanges.map("target.owner")) | reject("in", physical_link.ends.map("owner")) | unique(attribute="uuid") %}

{{ heading(2, "Interface Partners", session)}}
<workitem id="interface_partners">The scope of this interface document is the following link:</workitem>
{{ insert_work_item(physical_link, session) }}
{{ heading(3, "Partner A", session) }}
{{ insert_work_item(physical_link.source.owner, session) }}
{% for component in physical_link.source.owner.components | unique(attribute="uuid") %}
{% if component in component_exchanges_components %}
{{ insert_work_item(component, session, 1) }}
{% endif %}
{% endfor %}
{{ heading(3, "Partner B", session) }}
{{ insert_work_item(physical_link.target.owner, session) }}
{% for component in physical_link.source.owner.components | unique(attribute="uuid") %}
{% if component in component_exchanges_components %}
{{ insert_work_item(component, session, 1) }}
{% endif %}
{% endfor %}
{{ heading(3, "Exchange Item Allocation", session) }}
{% set exchange_items_by_direction = {} %}
{% set interfaces = {} %}
{% for component_exchange in component_exchanges %}
{% set provided_exchange_items_a = (component_exchange.source.provided_interfaces.map("exchange_item_allocations.item") + component_exchange.target.required_interfaces.map("exchange_item_allocations.item")) | list %}
{% set provided_exchange_items_b = (component_exchange.target.provided_interfaces.map("exchange_item_allocations.item") + component_exchange.source.required_interfaces.map("exchange_item_allocations.item")) | list %}
{% set component_a_b = (component_exchange.source.owner.uuid, component_exchange.target.owner.uuid) %}
{% set component_b_a = (component_exchange.target.owner.uuid, component_exchange.source.owner.uuid) %}
{% set _ = exchange_items_by_direction.update({component_a_b: exchange_items_by_direction.get(component_a_b, []) + provided_exchange_items_a}) %}
{% set _ = exchange_items_by_direction.update({component_b_a: exchange_items_by_direction.get(component_b_a, []) + provided_exchange_items_b}) %}
{% endfor %}
<workitem id="exchange_item_allocation">
<table {{table_attributes}}>
<tbody>
<tr>
<th {{th_attributes}}>Exchange Item</th>
<th {{th_attributes}}>Source</th>
<th {{th_attributes}}>Target</th>
<th {{th_attributes}}>Type</th>
<th {{th_attributes}}>Message Rate</th>
<th {{th_attributes}}>Safety Relevant</th>
</tr>
{% for direction, exchange_items in exchange_items_by_direction.items() %}
{% for ei in exchange_items | unique(attribute="uuid") %}
<tr>
<td {{td_attributes}}>{{ ei | link_work_item }}</td>
<td {{td_attributes}}>{{ model.by_uuid(direction[0]) | link_work_item }}</td>
<td {{td_attributes}}>{{ model.by_uuid(direction[1]) | link_work_item }}</td>
<td {{td_attributes}}>{{ ei.type }}</td>
<td {{td_attributes}}>
{% set message_rate = ei.property_value_groups.map("property_values") | selectattr("name", "equalto", "message rate") | first %}
{% if message_rate %}
{% set unit = message_rate.applied_property_values.map("property_values") | selectattr("name", "equalto", "__UNIT__") | first %}
{{ message_rate.value }}{% if unit %} {{unit.value}}{% endif %}
{% endif %}
</td>
<td {{td_attributes}}>
{% set message_rate = ei.property_value_groups.map("property_values") | selectattr("name", "equalto", "safety relevant") | first %}
{% if message_rate %}
{{ message_rate.value }}
{% endif %}
</td>
</tr>
{% endfor %}
{% endfor %}
</tbody>
</table>
</workitem>
{{ heading(2, "Interface Definition", session)}}
{{ heading(3, "Message Catalog", session)}}
<workitem id="message_catalog">This section identifies messages used within the interface.</workitem>
{%- set classes = {} -%}
{%- set inserted = [] -%}
{% for direction, eis in exchange_items_by_direction.items() %}
{% set _ = classes.setdefault(direction, []) %}
{{ heading(4, model.by_uuid(direction[0]).name + " → " + model.by_uuid(direction[1]).name, session) }}
{% for ei in eis | unique(attribute="uuid") %}
{{ heading(5, work_item_field(ei, "id") + " - " + ei.name, session) }}
{{ insert_work_item(ei, session) }}
{% for el in ei.elements %}
{{ add_class_dependencies(el.abstract_type, classes[direction]) }}
{% endfor %}
{% else %}
<workitem id="ei-{{ direction[0] }}>>>{{ direction[1] }}-empty">
There is no data defined for this direction.
</workitem>
{% endfor %}
{% endfor %}
{{ heading(3, "Message Description", session)}}
<workitem id="message_description">This section provides a detailed description of each message used within the interface.</workitem>
{% set object_count = {} %}

{% for direction, objects in classes.items() %}
{% for obj in objects | unique(attribute="uuid") %}
{% set _ = object_count.setdefault(obj.uuid, 0) %}
{% set _ = object_count.update({obj.uuid: object_count[obj.uuid] + 1}) %}
{% endfor %}
{% endfor %}

{% set multi_dir_clss = [] %}
{% for uuid, count in object_count.items() %}
{% if count > 1 %}
{% set _ = multi_dir_clss.append(uuid) %}
{% endif %}
{% endfor %}
{% if multi_dir_clss %}
{{ heading(4, "Generic Messages", session) }}
<workitem id="messages_generic">The following classes are used in multiple directions.</workitem>
{% for uuid in multi_dir_clss | unique %}
{% set cl = model.by_uuid(uuid) %}
{{ heading(5, work_item_field(cl, "id") + " - " + cl.name, session) }}
{{ insert_work_item(cl, session) }}
{% endfor %}
{%endif%}
{% for direction, clss in classes.items() %}
{{ heading(4, model.by_uuid(direction[0]).name + " → " + model.by_uuid(direction[1]).name, session) }}
{% for cl in clss | unique(attribute="uuid") %}
{% if cl.uuid not in multi_dir_clss %}
{{ heading(5, work_item_field(cl, "id") + " - " + cl.name, session) }}
{{ insert_work_item(cl, session) }}
{%endif%}
{% else %}
<workitem id="cls-{{ direction[0] }}>>>{{ direction[1] }}-empty">
There is no data defined for this direction.
</workitem>
{% endfor %}
{% endfor %}
{% endmacro %}
19 changes: 19 additions & 0 deletions jinja/document_templates/icd-interfaces-full_auth.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{#
Copyright DB InfraGO AG and contributors
SPDX-License-Identifier: Apache-2.0
#}

{% from 'icd-interfaces-common.html.j2' import render_content %}

{% set physical_link = model.by_uuid(physical_link) %}
{{ heading(1, "Interface " + physical_link.name, session)}}
{{ heading(2, "Table of Content", session)}}
<div id="polarion_wiki macro name=toc"></div>
<div id="polarion_wiki macro name=page_break" contentEditable="false" data-is-landscape="false"></div>
{{ heading(2, "Introduction", session)}}
<p>
This Interface Control Document only covers software message based communication (application layer) between ETCS compatible components.
At the moment physical interface definition is not in scope for this document.
The scope of the document covers Interface Requirements and Definition
</p>
{{ render_content(physical_link, model, session) }}
10 changes: 10 additions & 0 deletions jinja/document_templates/list-section.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{#
Copyright DB InfraGO AG and contributors
SPDX-License-Identifier: Apache-2.0
#}

<p>Test content</p>
{{ heading(3, "Several Items", session)}}
{% for item in items %}
{{ insert_work_item(model.by_uuid(item), session) }}
{% endfor %}
7 changes: 6 additions & 1 deletion jinja/element_templates/class_property.html.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{#
Copyright DB InfraGO AG and contributors
SPDX-License-Identifier: Apache-2.0
#}

{% from 'common_macros.html.j2' import show_other_attributes, linked_name, linked_name_with_icon, description, display_property %}
<p>Parent: {{ linked_name_with_icon(object.parent) | safe}}</p>
{{ display_property(object, object.parent) }}
{{ display_property(object, object.parent) }}
2 changes: 1 addition & 1 deletion jinja/element_templates/common_macros.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
{% endif %}
{% if type %}
{% if type.__class__.__name__ == "Enumeration" %}
{{ type.name | safe }}
{{ type.name | safe }}
{%- if type.domain_type -%}
<span> ({{type.domain_type.name | safe }})</span>
{%- else -%}
Expand Down
5 changes: 5 additions & 0 deletions jinja/element_templates/exchange_item.html.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{#
Copyright DB InfraGO AG and contributors
SPDX-License-Identifier: Apache-2.0
#}

{% from 'common_macros.html.j2' import show_other_attributes, description, typed_name, linked_name, linked_name_with_icon, display_property_label %}
{% from 'polarion_props.j2' import table_attributes, th_attributes, td_attributes %}

Expand Down
7 changes: 6 additions & 1 deletion jinja/element_templates/functional_exchange.html.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{#
Copyright DB InfraGO AG and contributors
SPDX-License-Identifier: Apache-2.0
#}

{% from 'common_macros.html.j2' import show_other_attributes, description, typed_name, linked_name, linked_name_with_icon, display_property_label %}

{%- set source_function = object.source.owner -%}
Expand All @@ -16,4 +21,4 @@ The {{ linked_name(source) | safe }} shall provide {{ linked_name_with_icon(obje
{% else %}
<p>This interaction is further specified via {{ linked_name_with_icon(object.exchange_items[0]) | safe}} Exchange Item</p>
{% endif %}
{% endif %}
{% endif %}
5 changes: 5 additions & 0 deletions jinja/element_templates/polarion_props.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{#
Copyright DB InfraGO AG and contributors
SPDX-License-Identifier: Apache-2.0
#}

{% set table_attributes='class="polarion-Document-table" style="margin: auto;margin-left: 0px;empty-cells: show;border-collapse: collapse;max-width: 1280px;border: 1px solid #CCCCCC;" id="polarion_wiki macro name=table"' %}
{% set th_attributes='style="height: 12px;text-align: left;vertical-align: top;font-weight: bold;background-color: #F0F0F0;border: 1px solid #CCCCCC;padding: 5px;"' %}
{% set td_attributes='style="height: 12px;text-align: left;vertical-align: top;line-height: 18px;border: 1px solid #CCCCCC;padding: 5px;"' %}

0 comments on commit 644fe98

Please sign in to comment.