Skip to content

Commit c7a4c5c

Browse files
[BLAZ-2239] Import draw.io generated by lean.ix
1 parent 5448440 commit c7a4c5c

11 files changed

Lines changed: 128 additions & 12 deletions

File tree

slp_drawio/resources/schemas/drawio_schema.xsd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
33
<xs:element name="mxfile" type="mxfileType"/>
4+
<xs:element name="mxGraphModel" type="mxGraphModelType"/>
45
<xs:complexType name="mxCellType" mixed="true">
56
<xs:sequence>
67
<xs:element type="mxGeometryType" name="mxGeometry" minOccurs="0"/>
@@ -80,6 +81,7 @@
8081
<xs:element type="mxCellType" name="mxCell"/>
8182
<xs:element type="objectType" name="object"/>
8283
<xs:element type="objectType" name="UserObject"/>
84+
<xs:element name="lx-settings" type="lxSettingsType"/>
8385
</xs:choice>
8486
</xs:complexType>
8587
<xs:complexType name="mxGraphModelType">
@@ -128,4 +130,10 @@
128130
<xs:attribute type="xs:string" name="pages"/>
129131
<xs:anyAttribute processContents="lax"/>
130132
</xs:complexType>
133+
<xs:complexType name="lxSettingsType">
134+
<xs:sequence>
135+
<xs:any minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
136+
</xs:sequence>
137+
<xs:anyAttribute processContents="lax"/>
138+
</xs:complexType>
131139
</xs:schema>

slp_drawio/slp_drawio/load/drawio_dict_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def __is_mx_cell_component(mx_cell: dict):
2929

3030

3131
def __get_root_element(source) -> dict:
32-
return source.get("mxfile", {}).get("diagram", {}).get("mxGraphModel", {}).get("root", {})
32+
return source.get("mxfile", {}).get("diagram", {}).get("mxGraphModel",
33+
source.get("mxGraphModel", {})).get("root", {})
3334

3435

3536
def __process_object_elements(root: dict, element_keys: list[str]) -> list[dict]:
@@ -82,7 +83,7 @@ def get_dataflow_tags(dataflow_id: str, source) -> list[str]:
8283

8384

8485
def get_diagram_size(source) -> Optional[dict]:
85-
model = source.get("mxfile", {}).get("diagram", {}).get("mxGraphModel", {})
86+
model = source.get("mxfile", {}).get("diagram", {}).get("mxGraphModel", source.get("mxGraphModel", {}))
8687
if model:
8788
height = model.get('pageHeight', None)
8889
width = model.get('pageWidth', None)

slp_drawio/slp_drawio/load/drawio_to_dict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def __is_diagram_encoded(diagram_tags: List) -> bool:
1818
return len(diagram_tags) <= 1
1919

2020

21-
def _decode_diagram(content: str) -> str:
21+
def _decode_diagram(content: str) -> str | None:
2222
tree = ElementTree.XML(content)
23-
tree_tag = tree.find('diagram')
23+
tree_tag = tree if tree.tag == 'mxGraphModel' else tree.find('diagram')
2424
if __is_diagram_encoded(list(tree_tag.iter())):
2525
data = base64.b64decode(tree_tag.text, validate=True)
2626
xml = zlib.decompress(data, wbits=-15).decode()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<mxGraphModel dx="1421" dy="904" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
2+
<root>
3+
<lx-settings id="0">
4+
<lx-fact-sheet-type-labels fact-sheet-type="BusinessCapability">
5+
<lx-label value="fullName" />
6+
</lx-fact-sheet-type-labels>
7+
</lx-settings>
8+
<mxCell id="0" />
9+
<mxCell id="1" parent="0" />
10+
<mxCell id="5i7VU8sxTlh_DojUgWXD-1" value="AWS Cloud" style="points=[[0,0],[0.25,0],[0.5,0],[0.75,0],[1,0],[1,0.25],[1,0.5],[1,0.75],[1,1],[0.75,1],[0.5,1],[0.25,1],[0,1],[0,0.75],[0,0.5],[0,0.25]];outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;container=1;pointerEvents=0;collapsible=0;recursiveResize=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_aws_cloud_alt;strokeColor=#232F3E;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#232F3E;dashed=0;" parent="1" vertex="1">
11+
<mxGeometry x="210" y="230" width="130" height="130" as="geometry" />
12+
</mxCell>
13+
<mxCell id="xUHJV5QXkyTOu5aMK-rF-2" value="" style="image;html=1;image=img/lib/clip_art/computers/Database_128x128.png" parent="5i7VU8sxTlh_DojUgWXD-1" vertex="1">
14+
<mxGeometry x="25" y="40" width="80" height="80" as="geometry" />
15+
</mxCell>
16+
<mxCell id="5i7VU8sxTlh_DojUgWXD-2" value="Region" style="points=[[0,0],[0.25,0],[0.5,0],[0.75,0],[1,0],[1,0.25],[1,0.5],[1,0.75],[1,1],[0.75,1],[0.5,1],[0.25,1],[0,1],[0,0.75],[0,0.5],[0,0.25]];outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;container=1;pointerEvents=0;collapsible=0;recursiveResize=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_region;strokeColor=#147EBA;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#147EBA;dashed=1;" parent="1" vertex="1">
17+
<mxGeometry x="440" y="230" width="130" height="130" as="geometry" />
18+
</mxCell>
19+
<mxCell id="xUHJV5QXkyTOu5aMK-rF-3" value="" style="outlineConnect=0;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;shape=mxgraph.aws3.ec2;fillColor=#F58534;gradientColor=none;" parent="5i7VU8sxTlh_DojUgWXD-2" vertex="1">
20+
<mxGeometry x="26.75" y="27" width="76.5" height="93" as="geometry" />
21+
</mxCell>
22+
</root>
23+
</mxGraphModel>

slp_drawio/tests/resources/test_resource_paths.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
wrong_mxgraphmodel_drawio = f'{drawio}/wrong_mxgraphmodel.drawio'
1616
wrong_root_drawio = f'{drawio}/wrong_root.drawio'
1717
not_xml = f'{drawio}/not_xml.drawio'
18+
lean_ix_drawio = f'{drawio}/lean_ix.drawio.xml'

slp_drawio/tests/unit/load/test_drawio_dict_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ def test_is_multiple_pages(source, expected):
5050
pytest.param({'mxfile': {'diagram': {'mxGraphModel': {'pageHeight': 123, 'pageWidth': 456}}}},
5151
{'height': 123, 'width': 456},
5252
id='exists size'),
53+
pytest.param({'mxGraphModel': {'pageHeight': 123, 'pageWidth': 456}},
54+
{'height': 123, 'width': 456},
55+
id='exists size only mxGraphModel'),
5356
pytest.param({'mxfile': {'diagram': {'mxGraphModel': {}}}}, None, id='not dimensions'),
57+
pytest.param({'mxGraphModel': {}}, None, id='not dimensions only mxGraphModel'),
5458
pytest.param({}, None, id='not model')
5559
])
5660
def test_get_diagram_size(source, expected):

slp_drawio/tests/validate/test_drawio_validator.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from slp_base import DiagramFileNotValidError, CommonError
88
from slp_drawio.slp_drawio.validate.drawio_validator import DrawioValidator
99
from slp_drawio.tests.resources.test_resource_paths import wrong_mxgraphmodel_drawio, wrong_mxfile_drawio, \
10-
wrong_mxcell_drawio, wrong_root_drawio, aws_minimal_drawio, aws_minimal_xml, not_xml
10+
wrong_mxcell_drawio, wrong_root_drawio, aws_minimal_drawio, aws_minimal_xml, not_xml, lean_ix_drawio
1111

1212
filename_pattern = re.compile('^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}\\.[drawio|xml]')
1313

@@ -79,12 +79,13 @@ def test_invalid_schema(self, filepath: str):
7979
assert error_info.typename == 'DiagramFileNotValidError'
8080
assert error_info.value.message == 'Provided diag_file is not valid. It does not comply with schema'
8181

82-
@pytest.mark.parametrize('mime, size, filepath', [
83-
pytest.param('application/octet-stream', 10, aws_minimal_drawio, id='encoded-tiny-binary'),
84-
pytest.param('application/xml', 10 * 1024 * 1024, aws_minimal_xml, id='xml-big-xml'),
85-
pytest.param('text/plain', 10 * 1024 * 1024, aws_minimal_drawio, id='encoded-big-text')
82+
@pytest.mark.parametrize('mime, filepath', [
83+
pytest.param('application/octet-stream', aws_minimal_drawio, id='encoded-tiny-binary'),
84+
pytest.param('application/xml', aws_minimal_xml, id='xml-big-xml'),
85+
pytest.param('text/plain', aws_minimal_drawio, id='encoded-big-text'),
86+
pytest.param('application/xml', lean_ix_drawio, id='lean-ix-drawio-xml')
8687
])
87-
def test_valid_file(self, mime: str, size: int, filepath: str):
88+
def test_valid_file(self, mime: str, filepath: str):
8889
# GIVEN the valid file
8990
file = get_byte_data(filepath)
9091

tests/integration/api/controllers/diagram/drawio/test_otm_controller_diagram_drawio.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import json
22

3+
import pytest
34
import responses
45
from fastapi.testclient import TestClient
6+
from tests.resources import test_resource_paths
57

68
from sl_util.sl_util.file_utils import get_byte_data
79
from startleft.startleft.api import fastapi_server
810
from startleft.startleft.api.controllers.diagram import diag_create_otm_controller
9-
from tests.resources import test_resource_paths
1011

1112
webapp = fastapi_server.webapp
1213

@@ -47,4 +48,33 @@ def test_create_otm_multi_page_error(self):
4748
assert body_response['title'] == 'Diagram file is not valid'
4849
assert body_response['detail'] == 'DrawIO processor does not accept diagrams with multiple pages'
4950
assert len(body_response['errors']) == 1
50-
assert body_response['errors'][0]['errorMessage'] == 'Diagram File is not compatible'
51+
assert body_response['errors'][0]['errorMessage'] == 'Diagram File is not compatible'
52+
53+
@pytest.mark.parametrize('diagram_file_path', [
54+
test_resource_paths.drawio_minimal,
55+
test_resource_paths.lean_ix_drawio
56+
])
57+
@responses.activate
58+
def test_create_otm_ok(self, diagram_file_path):
59+
# Given a project_id
60+
project_id: str = 'test_ok'
61+
project_name: str = 'test_ok_name'
62+
63+
# And the source file
64+
diag_file = get_byte_data(diagram_file_path)
65+
66+
# And the mapping file
67+
mapping_file = get_byte_data(test_resource_paths.default_drawio_mapping)
68+
69+
# When I do post on diagram endpoint
70+
files = {'diag_file': (diagram_file_path, diag_file),
71+
'default_mapping_file': ('default_mapping_file.yaml', mapping_file)}
72+
body = {'diag_type': 'DRAWIO', 'id': project_id, 'name': project_name}
73+
response = client.post(get_url(), files=files, data=body)
74+
75+
# Then
76+
assert response.status_code == 201
77+
assert response.headers.get('content-type') == json_mime
78+
otm = json.loads(response.text)
79+
assert len(otm['trustZones']) > 0
80+
assert len(otm['components']) > 0
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<mxfile host="Electron" modified="2023-10-10T12:38:11.657Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/19.0.3 Chrome/102.0.5005.63 Electron/19.0.3 Safari/537.36" etag="IaZ6VWqQhPlsWStpV9DA" version="19.0.3" type="device">
3+
<diagram id="pOeIjdqQ_qid1hbLa7JX" name="Page-1">
4+
<mxGraphModel dx="1421" dy="904" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
5+
<root>
6+
<mxCell id="0" />
7+
<mxCell id="1" parent="0" />
8+
<mxCell id="5i7VU8sxTlh_DojUgWXD-1" value="AWS Cloud" style="points=[[0,0],[0.25,0],[0.5,0],[0.75,0],[1,0],[1,0.25],[1,0.5],[1,0.75],[1,1],[0.75,1],[0.5,1],[0.25,1],[0,1],[0,0.75],[0,0.5],[0,0.25]];outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;container=1;pointerEvents=0;collapsible=0;recursiveResize=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_aws_cloud_alt;strokeColor=#232F3E;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#232F3E;dashed=0;" parent="1" vertex="1">
9+
<mxGeometry x="210" y="230" width="130" height="130" as="geometry" />
10+
</mxCell>
11+
<mxCell id="xUHJV5QXkyTOu5aMK-rF-2" value="" style="image;html=1;image=img/lib/clip_art/computers/Database_128x128.png" parent="5i7VU8sxTlh_DojUgWXD-1" vertex="1">
12+
<mxGeometry x="25" y="40" width="80" height="80" as="geometry" />
13+
</mxCell>
14+
<mxCell id="5i7VU8sxTlh_DojUgWXD-2" value="Region" style="points=[[0,0],[0.25,0],[0.5,0],[0.75,0],[1,0],[1,0.25],[1,0.5],[1,0.75],[1,1],[0.75,1],[0.5,1],[0.25,1],[0,1],[0,0.75],[0,0.5],[0,0.25]];outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;container=1;pointerEvents=0;collapsible=0;recursiveResize=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_region;strokeColor=#147EBA;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#147EBA;dashed=1;" parent="1" vertex="1">
15+
<mxGeometry x="440" y="230" width="130" height="130" as="geometry" />
16+
</mxCell>
17+
<mxCell id="xUHJV5QXkyTOu5aMK-rF-3" value="" style="outlineConnect=0;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;shape=mxgraph.aws3.ec2;fillColor=#F58534;gradientColor=none;" parent="5i7VU8sxTlh_DojUgWXD-2" vertex="1">
18+
<mxGeometry x="26.75" y="27" width="76.5" height="93" as="geometry" />
19+
</mxCell>
20+
</root>
21+
</mxGraphModel>
22+
</diagram>
23+
</mxfile>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<mxGraphModel dx="1421" dy="904" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
2+
<root>
3+
<lx-settings id="0">
4+
<lx-fact-sheet-type-labels fact-sheet-type="BusinessCapability">
5+
<lx-label value="fullName" />
6+
</lx-fact-sheet-type-labels>
7+
</lx-settings>
8+
<mxCell id="0" />
9+
<mxCell id="1" parent="0" />
10+
<mxCell id="5i7VU8sxTlh_DojUgWXD-1" value="AWS Cloud" style="points=[[0,0],[0.25,0],[0.5,0],[0.75,0],[1,0],[1,0.25],[1,0.5],[1,0.75],[1,1],[0.75,1],[0.5,1],[0.25,1],[0,1],[0,0.75],[0,0.5],[0,0.25]];outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;container=1;pointerEvents=0;collapsible=0;recursiveResize=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_aws_cloud_alt;strokeColor=#232F3E;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#232F3E;dashed=0;" parent="1" vertex="1">
11+
<mxGeometry x="210" y="230" width="130" height="130" as="geometry" />
12+
</mxCell>
13+
<mxCell id="xUHJV5QXkyTOu5aMK-rF-2" value="" style="image;html=1;image=img/lib/clip_art/computers/Database_128x128.png" parent="5i7VU8sxTlh_DojUgWXD-1" vertex="1">
14+
<mxGeometry x="25" y="40" width="80" height="80" as="geometry" />
15+
</mxCell>
16+
<mxCell id="5i7VU8sxTlh_DojUgWXD-2" value="Region" style="points=[[0,0],[0.25,0],[0.5,0],[0.75,0],[1,0],[1,0.25],[1,0.5],[1,0.75],[1,1],[0.75,1],[0.5,1],[0.25,1],[0,1],[0,0.75],[0,0.5],[0,0.25]];outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;container=1;pointerEvents=0;collapsible=0;recursiveResize=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_region;strokeColor=#147EBA;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#147EBA;dashed=1;" parent="1" vertex="1">
17+
<mxGeometry x="440" y="230" width="130" height="130" as="geometry" />
18+
</mxCell>
19+
<mxCell id="xUHJV5QXkyTOu5aMK-rF-3" value="" style="outlineConnect=0;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;shape=mxgraph.aws3.ec2;fillColor=#F58534;gradientColor=none;" parent="5i7VU8sxTlh_DojUgWXD-2" vertex="1">
20+
<mxGeometry x="26.75" y="27" width="76.5" height="93" as="geometry" />
21+
</mxCell>
22+
</root>
23+
</mxGraphModel>

0 commit comments

Comments
 (0)