Skip to content

Commit

Permalink
WWI21/100-transformer-architecture-refactoring (#153)
Browse files Browse the repository at this point in the history
* remerge (#143)

* Add Swagger UI (#128)

* Wwi21/103 secure against xml vulnerabilities (#127)

* adds env var for XML security to CI and CD pipeline

* adds XML security env var to docker container

* raise exception if xml var does not exist

* Add secure xml package

* fixes linting errors

* Remove unnecessary tkinter import

* tries to fix env var setting for CI pipeline

* correctly sets FUNCTION_ENV_VARS in CD pipeline

---------

Co-authored-by: Kevin Stolz <[email protected]>

* Wwi21/33 building docker image for on prem deployment (#129)

* Integrate transformer

* implements matrix build

* fixes typo

* adds second function for integration

* fixes test setup for multiple functions

* fixes module issue for tests

* adds boilerplate tests for transform endpoint

* testing dependecy caching

* upes to build in caching functionality for pip

* extracts python version into env var

* reenables linting in pipeline

* fixes identation error

* adds timestamp to gcf deployment name

* makes definition of env variables the first step

* added basic Docker file for dhbw server

* makes source code linting conform

* testing transform endpoint as module for gcp deployment

* converts back to old imports

* updates docker file to allow for transformer module import

* fixes merge conflict within transform.py

* makes source code linter conform

* updaes CD-pipeline to build and push docker image to GCR

* now for reald cd and not ci

* fixes CD pipeline permissions

* pushes docker image to docker hub on deploy

---------

Co-authored-by: Kevin <[email protected]>

* Wwi21/33 building docker image for on prem deployment (#130)

* Integrate transformer

* implements matrix build

* fixes typo

* adds second function for integration

* fixes test setup for multiple functions

* fixes module issue for tests

* adds boilerplate tests for transform endpoint

* testing dependecy caching

* upes to build in caching functionality for pip

* extracts python version into env var

* reenables linting in pipeline

* fixes identation error

* adds timestamp to gcf deployment name

* makes definition of env variables the first step

* added basic Docker file for dhbw server

* makes source code linting conform

* testing transform endpoint as module for gcp deployment

* converts back to old imports

* updates docker file to allow for transformer module import

* fixes merge conflict within transform.py

* makes source code linter conform

* updaes CD-pipeline to build and push docker image to GCR

* now for reald cd and not ci

* fixes CD pipeline permissions

* pushes docker image to docker hub on deploy

* fixes typo

---------

Co-authored-by: Kevin <[email protected]>

* Wwi21/33 building docker image for on prem deployment (#131)

* Integrate transformer

* implements matrix build

* fixes typo

* adds second function for integration

* fixes test setup for multiple functions

* fixes module issue for tests

* adds boilerplate tests for transform endpoint

* testing dependecy caching

* upes to build in caching functionality for pip

* extracts python version into env var

* reenables linting in pipeline

* fixes identation error

* adds timestamp to gcf deployment name

* makes definition of env variables the first step

* added basic Docker file for dhbw server

* makes source code linting conform

* testing transform endpoint as module for gcp deployment

* converts back to old imports

* updates docker file to allow for transformer module import

* fixes merge conflict within transform.py

* makes source code linter conform

* updaes CD-pipeline to build and push docker image to GCR

* now for reald cd and not ci

* fixes CD pipeline permissions

* pushes docker image to docker hub on deploy

* fixes typo

* adds env vars for docker image push

---------

Co-authored-by: Kevin <[email protected]>

* Wwi21/33 building docker image for on prem deployment (#132)

* Integrate transformer

* implements matrix build

* fixes typo

* adds second function for integration

* fixes test setup for multiple functions

* fixes module issue for tests

* adds boilerplate tests for transform endpoint

* testing dependecy caching

* upes to build in caching functionality for pip

* extracts python version into env var

* reenables linting in pipeline

* fixes identation error

* adds timestamp to gcf deployment name

* makes definition of env variables the first step

* added basic Docker file for dhbw server

* makes source code linting conform

* testing transform endpoint as module for gcp deployment

* converts back to old imports

* updates docker file to allow for transformer module import

* fixes merge conflict within transform.py

* makes source code linter conform

* updaes CD-pipeline to build and push docker image to GCR

* now for reald cd and not ci

* fixes CD pipeline permissions

* pushes docker image to docker hub on deploy

* fixes typo

* adds env vars for docker image push

* makes cd jobs parallel

* tries to add github token to attestation step

---------

Co-authored-by: Kevin <[email protected]>

* Wwi21/33 building docker image for on prem deployment (#134)

* Integrate transformer

* implements matrix build

* fixes typo

* adds second function for integration

* fixes test setup for multiple functions

* fixes module issue for tests

* adds boilerplate tests for transform endpoint

* testing dependecy caching

* upes to build in caching functionality for pip

* extracts python version into env var

* reenables linting in pipeline

* fixes identation error

* adds timestamp to gcf deployment name

* makes definition of env variables the first step

* added basic Docker file for dhbw server

* makes source code linting conform

* testing transform endpoint as module for gcp deployment

* converts back to old imports

* updates docker file to allow for transformer module import

* fixes merge conflict within transform.py

* makes source code linter conform

* updaes CD-pipeline to build and push docker image to GCR

* now for reald cd and not ci

* fixes CD pipeline permissions

* pushes docker image to docker hub on deploy

* fixes typo

* adds env vars for docker image push

* makes cd jobs parallel

* tries to add github token to attestation step

* quick fix: remove attestation step

---------

Co-authored-by: Kevin <[email protected]>

* Update dependency pydantic to v2.7.3 (#108)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency certifi to v2024.6.2 (#115)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency packaging to v24.1 (#126)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency pytest to v8.2.2 (#123)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency requests to v2.32.3 (#111)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency ruff to v0.4.8 (#109)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Swagger docs modified configuration (#133)

* modified Swagger doc
* added openapi to test deployment of swagger doc

* Swagger docs (#136)

* changed folder name 'doc' to 'docs'

* Changed file directory names (#137)

* added function to clean string from whitespaces and "\n" (#138)

Co-authored-by: Frederick Engelns-Runte <[email protected]>

* Swagger docs (#139)

* relocated index.html

* Swagger docs - fixed error in index.html (#140)

* Update dependency ruff to v0.4.9 (#142)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency pydantic to v2.7.4 (#141)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

---------

Co-authored-by: nilsbgt <[email protected]>
Co-authored-by: Niyada <[email protected]>
Co-authored-by: Kevin Stolz <[email protected]>
Co-authored-by: Kevin <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Frederick Engelns-Bauer <[email protected]>
Co-authored-by: Frederick Engelns-Runte <[email protected]>

* Advance base model attributes

* Eliminate flow ref

* Cutting BPMNDIID, as ID is handled on BaseModel
level. BPMNDiagram and BPMNDIObject now inherit
from BPMNDINamespace directly

* Handle BPMNLabel on Object level, planes can now also have a label

* cuttoff/eliminate GenericIdNode, directly inherit BPMNNamespace to GenericBPMNNode,
Also eliminate hash function in GenericBPMNNode, as it is standard self+id hash in BaseModel

* Also inherit BPMNNamespace directl to flow... TODO Name inheritance

* Eliminate arc id, as it can be inherited, leave the hash individualised

* Inherit BaseModel directly in GenericNetNode

* Inherit BaseModel directly to NetElement and Page

* Eleminate standard hash in NetElement, as it is already implemented in BaseModel

* Eliminate id in Net and Operator, as they inherit
id from base model

* Ruff fix

* Cut GenericIdNode inheritance for message and time
event

* Fix GenericNode use, to BaseModel

---------

Co-authored-by: nilsbgt <[email protected]>
Co-authored-by: Niyada <[email protected]>
Co-authored-by: Kevin Stolz <[email protected]>
Co-authored-by: Kevin <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Frederick Engelns-Bauer <[email protected]>
Co-authored-by: Frederick Engelns-Runte <[email protected]>
Co-authored-by: Benjamin Bleidorn <[email protected]>
  • Loading branch information
9 people authored Jun 24, 2024
1 parent 126b9a2 commit a564217
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 84 deletions.
24 changes: 2 additions & 22 deletions src/transform/transformer/models/bpmn/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,13 @@ class BPMNNamespace(BaseBPMNModel, ns="bpmn", nsmap=ns_map):
"""Extension of BaseBPMNModel with namespace bpmn and namespace map."""


class GenericIdNode(BPMNNamespace):
"""Extension of BPMNNamespace with id attribute and hash method."""

id: str = attr()

def __hash__(self):
"""Returns a hash of this instance."""
return hash((type(self),) + (self.id,))


class FlowRef(BaseBPMNModel):
"""Extension of BaseBPMNModel."""

text: str


class GenericBPMNNode(GenericIdNode):
"""BPMN extension of GenericIdNode with name, incoming and outgoing attribute."""
class GenericBPMNNode(BPMNNamespace):
"""BPMN extension of BPMNNamespace with name, incoming and outgoing attribute."""

name: str | None = attr(default=None)
incoming: set[str] = element("incoming", default_factory=set)
outgoing: set[str] = element("outgoing", default_factory=set)

def __hash__(self):
"""Returns a hash of this instance."""
return hash((type(self),) + (self.id,))

def get_in_degree(self):
"""Returns incoming degree of this instance."""
return len(self.incoming)
Expand Down
11 changes: 5 additions & 6 deletions src/transform/transformer/models/bpmn/bpmn.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
BPMNNamespace,
Gateway,
GenericBPMNNode,
GenericIdNode,
)
from transformer.models.bpmn.bpmn_graphics import (
BPMNDiagram,
Expand Down Expand Up @@ -91,12 +90,12 @@ class EndEvent(GenericBPMNNode, tag="endEvent"):
"""EndEvent extension of GenericBPMNNode."""


class MessageEvent(GenericIdNode, tag="messageEventDefinition"):
"""MessageEvent extension of GenericIdNode."""
class MessageEvent(BPMNNamespace, tag="messageEventDefinition"):
"""MessageEvent extension of BPMNNamespace."""


class TimeEvent(GenericIdNode, tag="timerEventDefinition"):
"""TimeEvent extension of GenericIdNode."""
class TimeEvent(BPMNNamespace, tag="timerEventDefinition"):
"""TimeEvent extension of BPMNNamespace."""


class IntermediateCatchEvent(GenericBPMNNode, tag="intermediateCatchEvent"):
Expand Down Expand Up @@ -171,7 +170,7 @@ class ServiceTask(GenericTask, tag="serviceTask"):
# Flow


class Flow(GenericIdNode, tag="sequenceFlow"):
class Flow(BPMNNamespace, tag="sequenceFlow"):
"""Flow extension of GenericBPMNNode."""

name: str | None = attr(default=None)
Expand Down
41 changes: 18 additions & 23 deletions src/transform/transformer/models/bpmn/bpmn_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,32 @@
from transformer.utility.utility import BaseBPMNModel


class BPMNDINamespace(BaseBPMNModel, ns="bpmndi", nsmap=ns_map):
"""BPMNDINNamespace extension of BaseBPMNModel."""

pass
class DCBounds(BaseBPMNModel, tag="Bounds", ns="dc", nsmap=ns_map):
"""DCBounds extension of BaseBPMNModel with x,y, width and height xml attributes."""

x: float = attr(default=0)
y: float = attr(default=0)
width: float = attr()
height: float = attr()

class BPMNDIID(BPMNDINamespace):
"""BPMNDIID extension of BPMNDINamespace with string ID attribute."""

id: str | None = attr(default=None)
class BPMNDINamespace(BaseBPMNModel, ns="bpmndi", nsmap=ns_map):
"""BPMNDINNamespace extension of BaseBPMNModel."""

pass

class BPMNDIObject(BPMNDIID):
"""BPMNDIObject extension of BPMNDIID with element xml attribute."""
class BPMNLabel(BPMNDINamespace, tag="BPMNLabel"):
"""BPMNLabel extension of BPMNIDNamespace with DCBounds attribute."""

bpmnElement: str = attr()
bounds: DCBounds | None = element(default=None)

class BPMNDIObject(BPMNDINamespace):
"""BPMNDIObject extension of BPMNDINamespace with element xml attribute."""

class DCBounds(BaseBPMNModel, tag="Bounds", ns="dc", nsmap=ns_map):
"""DCBounds extension of BaseBPMNModel with x,y, width and height xml attributes."""
bpmnElement: str = attr()
label: BPMNLabel | None = element(default=None)

x: float = attr(default=0)
y: float = attr(default=0)
width: float = attr()
height: float = attr()


class DIWaypoint(BaseBPMNModel, tag="waypoint", ns="di", nsmap=ns_map):
Expand All @@ -40,25 +41,19 @@ class DIWaypoint(BaseBPMNModel, tag="waypoint", ns="di", nsmap=ns_map):
y: float = attr(default=0)


class BPMNLabel(BPMNDINamespace, tag="BPMNLabel"):
"""BPMNLabel extension of BPMNIDNamespace with DCBounds attribute."""

bounds: DCBounds | None = element(default=None)


class BPMNEdge(BPMNDIObject, tag="BPMNEdge"):
"""BPMNEdge extension of BPMNDIObject with waypoints and label."""

waypoints: list[DIWaypoint] = element(default_factory=list)
label: BPMNLabel | None = element(default=None)


class BPMNShape(BPMNDIObject, tag="BPMNShape"):
"""BPMNShape extension of BPMNDIObject with bounds, isExpanded and label attr.."""

bounds: DCBounds
isExpanded: bool | None = attr(default=None)
label: BPMNLabel | None = element(default=None)


class BPMNPlane(BPMNDIObject, tag="BPMNPlane"):
Expand All @@ -67,7 +62,7 @@ class BPMNPlane(BPMNDIObject, tag="BPMNPlane"):
eles: list[BPMNShape | BPMNEdge] = element(default_factory=list)


class BPMNDiagram(BPMNDIID, tag="BPMNDiagram"):
"""BPMNDiagram extension of BPMNDIID with plane as attribute."""
class BPMNDiagram(BPMNDINamespace, tag="BPMNDiagram"):
"""BPMNDiagram extension of BPMNDINamespace with plane as attribute."""

plane: BPMNPlane | None = element(default=None)
22 changes: 2 additions & 20 deletions src/transform/transformer/models/pnml/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@
from transformer.utility.utility import WOPED, BaseModel


class GenericNetIDNode(BaseModel):
"""Generic Petri net node extension of BaseModel (+ID)."""

id: str = attr()

def __hash__(self):
"""Return hash of this instance."""
return hash((type(self),) + (self.id,))


class Name(BaseModel, tag="name"):
"""Name extension of BaseModel (+graphics, title)."""

Expand Down Expand Up @@ -136,21 +126,13 @@ def is_workflow_event_trigger(self):
return self.is_workflow_message() or self.is_workflow_time()


class GenericNetNode(GenericNetIDNode):
"""Generic NetNode extension of net id node."""


class NetElement(GenericNetNode):
"""NetElement extension of GenericNetNode (+name, graphics, toolspecific)."""
class NetElement(BaseModel):
"""NetElement extension of BaseModel (+name, graphics, toolspecific)."""

name: Name | None = None
graphics: PositionGraphics | None = None
toolspecific: Toolspecific | None = None

def __hash__(self):
"""Return instance hashed by type and id."""
return hash((type(self),) + (self.id,))

def get_name(self):
"""Returns name of instance."""
if not self.name:
Expand Down
21 changes: 9 additions & 12 deletions src/transform/transformer/models/pnml/pnml.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pydantic_xml import attr, element

from transformer.models.pnml.base import (
GenericNetNode,
Inscription,
Name,
NetElement,
Expand Down Expand Up @@ -51,7 +50,6 @@ def create(id: str, name: str | None = None):
class Arc(BaseModel, tag="arc"):
"""Arc extension of BaseModel (+ID,source,target,inscription...)."""

id: str = attr()
source: str = attr()
target: str = attr()
inscription: Inscription | None = element(default=None)
Expand All @@ -63,8 +61,8 @@ def __hash__(self):
return hash((type(self),) + (self.id,) + (self.source,) + (self.target,))


class Page(GenericNetNode, tag="page"):
"""Page extension of GenericNetNode (+Net)."""
class Page(BaseModel, tag="page"):
"""Page extension of BaseModel (+Net)."""

net: "Net"

Expand All @@ -79,7 +77,6 @@ class Net(BaseModel, tag="net"):
toolspecific_global: ToolspecificGlobal | None = None

type_field: str | None = attr(default=None, alias="type")
id: str | None = attr(default=None)

places: set[Place] = element(default_factory=set)
transitions: set[Transition] = element(default_factory=set)
Expand All @@ -89,7 +86,7 @@ class Net(BaseModel, tag="net"):

# internal helper structures
_temp_elements: dict[str, NetElement] = PrivateAttr(default_factory=dict)
_type_map: dict[type[GenericNetNode], set[GenericNetNode]] = PrivateAttr(
_type_map: dict[type[BaseModel], set[BaseModel]] = PrivateAttr(
default_factory=dict
)
_temp_arcs: dict[int, Arc] = PrivateAttr(default_factory=dict)
Expand All @@ -116,7 +113,7 @@ def __init__(self, **data):
def _init_reference_structures(self):
"""Populate the helper structures."""
self._type_map = cast(
dict[type[GenericNetNode], set[GenericNetNode]],
dict[type[BaseModel], set[BaseModel]],
{
Place: self.places,
Transition: self.transitions,
Expand All @@ -140,7 +137,7 @@ def _init_reference_structures(self):

def _flatten_node_typ_map(self):
"""Return all nodes as a single list."""
all_nodes: list[GenericNetNode] = []
all_nodes: list[BaseModel] = []
for type_sets in self._type_map.values():
all_nodes.extend(type_sets)
return all_nodes
Expand All @@ -157,13 +154,13 @@ def _update_arc_incoming_outgoing(self, arc: Arc):
else:
self._temp_node_id_to_outgoing[arc.source].add(arc)

def get_in_degree(self, node: GenericNetNode):
def get_in_degree(self, node: BaseModel):
"""Return degree of incoming arcs."""
if node.id not in self._temp_node_id_to_incoming:
return 0
return len(self._temp_node_id_to_incoming[node.id])

def get_out_degree(self, node: GenericNetNode):
def get_out_degree(self, node: BaseModel):
"""Return degree of outgoing arcs."""
if node.id not in self._temp_node_id_to_outgoing:
return 0
Expand Down Expand Up @@ -271,7 +268,7 @@ def get_node_or_none(self, id: str):
return None
return self._temp_elements[id]

def remove_element(self, to_remove_node: GenericNetNode):
def remove_element(self, to_remove_node: BaseModel):
"""Remove element by instance."""
storage_set = self._type_map[type(to_remove_node)]
if storage_set is None:
Expand Down Expand Up @@ -301,7 +298,7 @@ def change_id(self, old_id: str, new_id: str):
self.connect_to_element(current_node, incoming)
self.connect_from_element(current_node, outgoing)

def remove_element_with_connecting_arcs(self, to_remove_node: GenericNetNode):
def remove_element_with_connecting_arcs(self, to_remove_node: BaseModel):
"""Remove element by instance and connecting arcs."""
for arc in [
*self.get_incoming(to_remove_node.id),
Expand Down
1 change: 0 additions & 1 deletion src/transform/transformer/models/pnml/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class WorkflowBranchingType(int, Enum):
class Operator(BaseModel, tag="operator"):
"""Operator extension of BaseModel (+id, type)."""

id: str = attr()
type: WorkflowBranchingType = attr()


Expand Down
7 changes: 7 additions & 0 deletions src/transform/transformer/utility/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from xml.etree.ElementTree import Element

from pydantic_xml import BaseXmlModel
from pydantic_xml import attr

WOPED = "WoPeD"

Expand Down Expand Up @@ -37,6 +38,12 @@ class BaseModel(
skip_empty=True,
):
"""BaseModel extension of BaseXmlModel."""
id: str | None = attr(default=None)
name: str | None = attr(default=None)

def __hash__(self):
"""Return hash of this instance."""
return hash((type(self),) + (self.id,))


class BaseBPMNModel(
Expand Down

0 comments on commit a564217

Please sign in to comment.