Skip to content

Commit 49c7955

Browse files
jens-kuertenJens Kürten
andauthored
Implement release check events and abort action (#13)
* fix base action * typo * new release events * common dialog data * adapt schema * fix dependency * remove general release events * add release check events for documents, parts and ecs * update schema * remove unneeded constructors * cdb_obsolete can be None * Functions can return Actions or list of Actions directly * make doc * add documentation for new actions and events * make schema * unused import * remove mentioning workloadresponse * clarify check events * change order * remove some unused code * make object linking independent of field names * rename fields to attached_<object> * adjust documentation to include the attached_<object> fields --------- Co-authored-by: Jens Kürten <[email protected]>
1 parent c1aac00 commit 49c7955

27 files changed

+553
-116
lines changed

csfunctions/actions/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from pydantic import Field
44

55
from .abort_and_show_error import AbortAndShowErrorAction
6+
from .base import ActionNames
67
from .dummy import DummyAction
78

8-
Action = Annotated[Union[AbortAndShowErrorAction, DummyAction], Field(discriminator="name")]
9+
ActionUnion = Union[AbortAndShowErrorAction, DummyAction]
10+
Action = Annotated[ActionUnion, Field(discriminator="name")]
Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
11
from typing import Literal
22

3-
from pydantic import BaseModel, Field
3+
from pydantic import Field
44

55
from .base import ActionNames, BaseAction
66

77

8-
class AbortAndShowErrorData(BaseModel):
9-
def __init__(self, message: str, **kwargs):
10-
super().__init__(message=message, **kwargs)
11-
12-
message: str = Field("unknown error", description="error message to be shown to the user")
13-
14-
158
class AbortAndShowErrorAction(BaseAction):
16-
def __init__(self, id: str, message: str | None = None, **kwargs): # pylint: disable=redefined-builtin
17-
if message:
18-
super().__init__(name=ActionNames.ABORT_AND_SHOW_ERROR, id=id, data=AbortAndShowErrorData(message=message))
19-
else:
20-
super().__init__(name=ActionNames.ABORT_AND_SHOW_ERROR, id=id, data=kwargs["data"])
21-
22-
name: Literal[ActionNames.ABORT_AND_SHOW_ERROR]
23-
data: AbortAndShowErrorData
9+
name: Literal[ActionNames.ABORT_AND_SHOW_ERROR] = ActionNames.ABORT_AND_SHOW_ERROR
10+
message: str = Field("unknown error", description="error message to be shown to the user")

csfunctions/actions/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from enum import Enum
22

3-
from pydantic import BaseModel, Field
3+
from pydantic import BaseModel
44

55

66
class ActionNames(str, Enum):
@@ -10,5 +10,4 @@ class ActionNames(str, Enum):
1010

1111
class BaseAction(BaseModel):
1212
name: str
13-
id: str = Field(..., description="unique identifier")
14-
data: dict | None = None
13+
id: str | None = None

csfunctions/events/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,39 @@
22

33
from pydantic import Field
44

5-
from .document_release import DocumentReleaseData, DocumentReleaseDialogData, DocumentReleaseEvent
5+
from .dialog_data import DocumentReleaseDialogData, PartReleaseDialogData
6+
from .document_release import DocumentReleaseData, DocumentReleaseEvent
7+
from .document_release_check import DocumentReleaseCheckData, DocumentReleaseCheckEvent
68
from .dummy import DummyEvent, DummyEventData
79
from .engineering_change_release import EngineeringChangeRelease, EngineeringChangeReleaseData
10+
from .engineering_change_release_check import EngineeringChangeReleaseCheck, EngineeringChangeReleaseCheckData
811
from .field_value_calculation import FieldValueCalculationData, FieldValueCalculationEvent
9-
from .part_release import PartReleaseData, PartReleaseDialogData, PartReleaseEvent
12+
from .part_release import PartReleaseData, PartReleaseEvent
13+
from .part_release_check import PartReleaseCheckData, PartReleaseCheckEvent
1014
from .workflow_task_trigger import WorkflowTaskTriggerEvent, WorkflowTaskTriggerEventData
1115

1216
Event = Annotated[
1317
Union[
1418
DocumentReleaseEvent,
19+
DocumentReleaseCheckEvent,
1520
PartReleaseEvent,
21+
PartReleaseCheckEvent,
1622
FieldValueCalculationEvent,
1723
DummyEvent,
1824
EngineeringChangeRelease,
25+
EngineeringChangeReleaseCheck,
1926
WorkflowTaskTriggerEvent,
2027
],
2128
Field(discriminator="name"),
2229
]
2330
EventData = Union[
2431
DocumentReleaseData,
32+
DocumentReleaseCheckData,
2533
PartReleaseData,
34+
PartReleaseCheckData,
2635
FieldValueCalculationData,
2736
DummyEventData,
2837
EngineeringChangeReleaseData,
38+
EngineeringChangeReleaseCheckData,
2939
WorkflowTaskTriggerEventData,
3040
]

csfunctions/events/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
class EventNames(str, Enum):
77
DUMMY = "dummy"
88
DOCUMENT_RELEASE = "document_release"
9+
DOCUMENT_RELEASE_CHECK = "document_release_check"
910
PART_RELEASE = "part_release"
11+
PART_RELEASE_CHECK = "part_release_check"
1012
ENGINEERING_CHANGE_RELEASE = "engineering_change_release"
13+
ENGINEERING_CHANGE_RELEASE_CHECK = "engineering_change_release_check"
1114
FIELD_VALUE_CALCULATION = "field_value_calculation"
1215
WORKFLOW_TASK_TRIGGER = "workflow_task_trigger"
1316

1417

1518
class BaseEvent(BaseModel):
1619
name: str
1720
event_id: str = Field(..., description="unique identifier")
18-
data: dict | None = None

csfunctions/events/dialog_data.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import Literal
2+
3+
from pydantic import BaseModel, Field
4+
5+
6+
class DocumentReleaseDialogData(BaseModel):
7+
dialog_type: Literal["document_release"] = "document_release"
8+
cdbprot_remark: str | None = Field(None, description="remark")
9+
cdb_ec_id: str | None = Field(None, description="Engineering Change ID")
10+
11+
12+
class PartReleaseDialogData(BaseModel):
13+
dialog_type: Literal["part_release"] = "part_release"
14+
cdbprot_remark: str | None = Field("", description="remark")
15+
cdb_ec_id: str | None = Field("", description="Engineering Change ID")

csfunctions/events/document_release.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,15 @@
55
from csfunctions.objects import Document, Part
66

77
from .base import BaseEvent, EventNames
8-
9-
10-
class DocumentReleaseDialogData(BaseModel):
11-
cdbprot_remark: str | None = Field(None, description="remark")
12-
cdb_ec_id: str | None = Field(None, description="Engineering Change ID")
8+
from .dialog_data import DocumentReleaseDialogData
139

1410

1511
class DocumentReleaseData(BaseModel):
16-
def __init__(self, documents: list[Document], parts: list[Part], dialog_data: dict, **kwargs):
17-
super().__init__(documents=documents, parts=parts, dialog_data=dialog_data, **kwargs)
18-
19-
documents: list[Document] = Field(..., description="List if documents that were released.")
12+
documents: list[Document] = Field(..., description="List of documents that were released.")
2013
parts: list[Part] = Field(..., description="List of parts that belong to the released documents")
2114
dialog_data: DocumentReleaseDialogData
2215

2316

2417
class DocumentReleaseEvent(BaseEvent):
25-
def __init__(self, event_id: str, data: DocumentReleaseData, **_):
26-
super().__init__(name=EventNames.DOCUMENT_RELEASE, event_id=event_id, data=data)
27-
28-
name: Literal[EventNames.DOCUMENT_RELEASE]
18+
name: Literal[EventNames.DOCUMENT_RELEASE] = EventNames.DOCUMENT_RELEASE
2919
data: DocumentReleaseData
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from typing import Literal
2+
3+
from pydantic import BaseModel, Field
4+
5+
from csfunctions.objects import Document, Part
6+
7+
from .base import BaseEvent, EventNames
8+
from .dialog_data import DocumentReleaseDialogData
9+
10+
11+
class DocumentReleaseCheckData(BaseModel):
12+
documents: list[Document] = Field(..., description="List of documents that will be released.")
13+
attached_parts: list[Part] = Field(..., description="List of parts that belong to the documents")
14+
dialog_data: DocumentReleaseDialogData
15+
16+
17+
class DocumentReleaseCheckEvent(BaseEvent):
18+
name: Literal[EventNames.DOCUMENT_RELEASE_CHECK] = EventNames.DOCUMENT_RELEASE_CHECK
19+
data: DocumentReleaseCheckData

csfunctions/events/engineering_change_release.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,5 @@ class EngineeringChangeReleaseData(BaseModel):
1616

1717

1818
class EngineeringChangeRelease(BaseEvent):
19-
def __init__(self, event_id: str, data: EngineeringChangeReleaseData, **_):
20-
super().__init__(name=EventNames.ENGINEERING_CHANGE_RELEASE, event_id=event_id, data=data)
21-
22-
name: Literal[EventNames.ENGINEERING_CHANGE_RELEASE]
19+
name: Literal[EventNames.ENGINEERING_CHANGE_RELEASE] = EventNames.ENGINEERING_CHANGE_RELEASE
2320
data: EngineeringChangeReleaseData
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import Literal
2+
3+
from pydantic import BaseModel, Field
4+
5+
from csfunctions.objects import Document, EngineeringChange, Part
6+
7+
from .base import BaseEvent, EventNames
8+
9+
10+
class EngineeringChangeReleaseCheckData(BaseModel):
11+
attached_documents: list[Document] = Field(..., description="List of included documents.")
12+
attached_parts: list[Part] = Field(..., description="List of included parts.")
13+
engineering_changes: list[EngineeringChange] = Field(
14+
..., description="List of engineering changes that will be released."
15+
)
16+
17+
18+
class EngineeringChangeReleaseCheck(BaseEvent):
19+
name: Literal[EventNames.ENGINEERING_CHANGE_RELEASE_CHECK] = EventNames.ENGINEERING_CHANGE_RELEASE_CHECK
20+
data: EngineeringChangeReleaseCheckData

0 commit comments

Comments
 (0)