Skip to content

Commit

Permalink
Merge pull request #357 from sartography/improvement/better-serializa…
Browse files Browse the repository at this point in the history
…tion

Improvement/better serialization
  • Loading branch information
essweine authored Oct 11, 2023
2 parents 92a7fdc + 6148025 commit c3a4943
Show file tree
Hide file tree
Showing 31 changed files with 1,107 additions and 1,229 deletions.
157 changes: 157 additions & 0 deletions SpiffWorkflow/bpmn/serializer/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Copyright (C) 2023 Sartography
#
# This file is part of SpiffWorkflow.
#
# SpiffWorkflow is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# SpiffWorkflow is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA

from SpiffWorkflow.task import Task
from SpiffWorkflow.bpmn.workflow import (
BpmnWorkflow,
BpmnSubWorkflow,
)
from SpiffWorkflow.bpmn.event import BpmnEvent
from SpiffWorkflow.bpmn.specs.data_spec import (
DataObject,
BpmnIoSpecification,
TaskDataReference,
)
from SpiffWorkflow.bpmn.specs.bpmn_process_spec import BpmnProcessSpec
from SpiffWorkflow.bpmn.specs.defaults import (
ManualTask,
NoneTask,
UserTask,
ExclusiveGateway,
InclusiveGateway,
ParallelGateway,
EventBasedGateway,
ScriptTask,
ServiceTask,
StandardLoopTask,
ParallelMultiInstanceTask,
SequentialMultiInstanceTask,
SubWorkflowTask,
CallActivity,
TransactionSubprocess,
StartEvent,
EndEvent,
IntermediateCatchEvent,
IntermediateThrowEvent,
BoundaryEvent,
SendTask,
ReceiveTask,
)
from SpiffWorkflow.bpmn.specs.control import (
BpmnStartTask,
SimpleBpmnTask,
BoundaryEventSplit,
BoundaryEventJoin,
_EndJoin,
)
from SpiffWorkflow.bpmn.specs.event_definitions.simple import (
NoneEventDefinition,
CancelEventDefinition,
TerminateEventDefinition,
)
from SpiffWorkflow.bpmn.specs.event_definitions.item_aware_event import (
SignalEventDefinition,
ErrorEventDefinition,
EscalationEventDefinition,
)
from SpiffWorkflow.bpmn.specs.event_definitions.timer import (
TimeDateEventDefinition,
DurationTimerEventDefinition,
CycleTimerEventDefinition,
)
from SpiffWorkflow.bpmn.specs.event_definitions.message import MessageEventDefinition
from SpiffWorkflow.bpmn.specs.event_definitions.multiple import MultipleEventDefinition

from .default.workflow import (
BpmnWorkflowConverter,
BpmnSubWorkflowConverter,
TaskConverter,
BpmnEventConverter,
)
from .helpers.spec import BpmnDataSpecificationConverter, EventDefinitionConverter
from .default.process_spec import BpmnProcessSpecConverter
from .default.task_spec import (
BpmnTaskSpecConverter,
ScriptTaskConverter,
StandardLoopTaskConverter,
MultiInstanceTaskConverter,
SubWorkflowConverter,
BoundaryEventJoinConverter,
ConditionalGatewayConverter,
ExclusiveGatewayConverter,
ParallelGatewayConverter,
EventConverter,
BoundaryEventConverter,
IOSpecificationConverter,
)
from .default.event_definition import (
TimerEventDefinitionConverter,
ErrorEscalationEventDefinitionConverter,
MessageEventDefinitionConverter,
MultipleEventDefinitionConverter,
)


DEFAULT_CONFIG = {
BpmnWorkflow: BpmnWorkflowConverter,
BpmnSubWorkflow: BpmnSubWorkflowConverter,
Task: TaskConverter,
BpmnEvent: BpmnEventConverter,
DataObject: BpmnDataSpecificationConverter,
TaskDataReference: BpmnDataSpecificationConverter,
BpmnIoSpecification: IOSpecificationConverter,
BpmnProcessSpec: BpmnProcessSpecConverter,
SimpleBpmnTask: BpmnTaskSpecConverter,
BpmnStartTask: BpmnTaskSpecConverter,
_EndJoin: BpmnTaskSpecConverter,
NoneTask: BpmnTaskSpecConverter,
ManualTask: BpmnTaskSpecConverter,
UserTask: BpmnTaskSpecConverter,
ScriptTask: ScriptTaskConverter,
StandardLoopTask: StandardLoopTaskConverter,
ParallelMultiInstanceTask: MultiInstanceTaskConverter,
SequentialMultiInstanceTask: MultiInstanceTaskConverter,
SubWorkflowTask: SubWorkflowConverter,
CallActivity: SubWorkflowConverter,
TransactionSubprocess: SubWorkflowConverter,
BoundaryEventSplit: BpmnTaskSpecConverter,
BoundaryEventJoin: BoundaryEventJoinConverter,
ExclusiveGateway: ExclusiveGatewayConverter,
InclusiveGateway: ConditionalGatewayConverter,
ParallelGateway: ParallelGatewayConverter,
StartEvent: EventConverter,
EndEvent: EventConverter,
IntermediateCatchEvent: EventConverter,
IntermediateThrowEvent: EventConverter,
BoundaryEvent: BoundaryEventConverter,
SendTask: EventConverter,
ReceiveTask: EventConverter,
EventBasedGateway: EventConverter,
CancelEventDefinition: EventDefinitionConverter,
ErrorEventDefinition: ErrorEscalationEventDefinitionConverter,
EscalationEventDefinition: ErrorEscalationEventDefinitionConverter,
MessageEventDefinition: MessageEventDefinitionConverter,
NoneEventDefinition: EventDefinitionConverter,
SignalEventDefinition: EventDefinitionConverter,
TerminateEventDefinition: EventDefinitionConverter,
TimeDateEventDefinition: TimerEventDefinitionConverter,
DurationTimerEventDefinition: TimerEventDefinitionConverter,
CycleTimerEventDefinition: TimerEventDefinitionConverter,
MultipleEventDefinition: MultipleEventDefinitionConverter,
}
48 changes: 0 additions & 48 deletions SpiffWorkflow/bpmn/serializer/data_spec.py

This file was deleted.

Empty file.
64 changes: 64 additions & 0 deletions SpiffWorkflow/bpmn/serializer/default/event_definition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright (C) 2023 Sartography
#
# This file is part of SpiffWorkflow.
#
# SpiffWorkflow is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# SpiffWorkflow is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA

from ..helpers.spec import EventDefinitionConverter


class ErrorEscalationEventDefinitionConverter(EventDefinitionConverter):

def to_dict(self, event_definition):
dct = super().to_dict(event_definition)
dct['code'] = event_definition.code
return dct


class MessageEventDefinitionConverter(EventDefinitionConverter):

def to_dict(self, event_definition):
dct = super().to_dict(event_definition)
dct['correlation_properties'] = self.correlation_properties_to_dict(event_definition.correlation_properties)
return dct

def from_dict(self, dct):
dct['correlation_properties'] = self.correlation_properties_from_dict(dct['correlation_properties'])
event_definition = super().from_dict(dct)
return event_definition


class TimerEventDefinitionConverter(EventDefinitionConverter):

def to_dict(self, event_definition):
dct = super().to_dict(event_definition)
dct['expression'] = event_definition.expression
return dct


class MultipleEventDefinitionConverter(EventDefinitionConverter):

def to_dict(self, event_definition):
dct = super().to_dict(event_definition)
dct['parallel'] = event_definition.parallel
dct['event_definitions'] = [self.registry.convert(e) for e in event_definition.event_definitions]
return dct

def from_dict(self, dct):
events = dct.pop('event_definitions')
event_definition = super().from_dict(dct)
event_definition.event_definitions = [self.registry.restore(d) for d in events]
return event_definition
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA

from SpiffWorkflow.bpmn.specs.bpmn_process_spec import BpmnProcessSpec
from ..helpers.registry import BpmnConverter

from .helpers.spec import WorkflowSpecConverter

class BpmnProcessSpecConverter(WorkflowSpecConverter):

def __init__(self, registry):
super().__init__(BpmnProcessSpec, registry)
class BpmnProcessSpecConverter(BpmnConverter):

def convert_task_spec_extensions(self, task_spec, dct):
# Extensions will be moved out of the base parser, but since we currently add them to some
Expand Down Expand Up @@ -56,7 +52,7 @@ def to_dict(self, spec):

def from_dict(self, dct):

spec = self.spec_class(name=dct['name'], description=dct['description'], filename=dct['file'])
spec = self.target_class(name=dct['name'], description=dct['description'], filename=dct['file'])
# These are automatically created with a workflow and should be replaced
del spec.task_specs['Start']
spec.start = None
Expand Down
Loading

0 comments on commit c3a4943

Please sign in to comment.