mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-02-23 15:08:10 +00:00
01a25fc3f Merge pull request #333 from sartography/feature/ruff 99c7bd0c7 ruff linting fixes 56d170ba1 Cleaning up badges in the readme. 51c13be93 tweaking action, adding button 96275ad7c Adding a github action to run tests c6c40976a minor fix to please sonarcloud. 03316babb Merge pull request #332 from sartography/updates-for-2.0-release ab70a34b5 Release Notes for 2.0.0_rc1 f0bf79bd9 copy edits a7c726951 Release Notes for 2.0.0_rc1 5f0468ba4 Merge pull request #330 from sartography/updates-for-2.0-release b9ad24406 Mostly minor edits e284dd8e2 corrections and tweaks to documentation 4b2e62600 add more examples 1ea258c6a update spiffworkflow concepts 851d7cdf6 fix a few bugs I found while testing the example repo 7a0a6bdf8 update bpmn docs 07c153f2d save/restore nested subprocess tests 340e9983b Merge branch 'main' of github.com:sartography/spiffworkflow into main 618afbc59 It is rare to submit an update that touches upon both religion and the origins of the universe. I think, for the sake of supporting all view points we must offer the possibility that there can be a thing that is not a child, but rather the beginning of all childen, that there is a chicken to the first egg, a single original big bank. a68dec77e use raw strings for regexes using escape sequences w/ burnettk 4644f2810 Merge pull request #329 from sartography/task/remove-deprecated-functions ca65602c0 correct typo in filename 39ab83f1f remove one deprecated and unused feature 23d54e524 Merge pull request #328 from sartography/improvement/task-spec-attributes 544614aa9 change dmn bpmn_id method to property 12ad185a4 update bpmnworkflow.waiting_events to use classname aec77097d fix some typos & add a few missing licenses 4b87c6d0c add some changes that didn't get included in the merge commit 965a5d4e1 Merge branch 'main' into improvement/task-spec-attributes a844b34f9 alternate bomnworkflow.cancel 0a455cdd2 Merge pull request #327 from sartography/feature/mark_tasks_in_sub_workflows_as_future_if_reseting_to_a_task_before_subworkflow 2bda992aa cancel tasks in subprocesses and return cancelled tasks 309937362 take account that we reset the parent when checking all sub-process executions. d4bcf1290 handle nested subprocesses when resetting tasks 032bedea6 reset subprocess task when resetting a task inside the subprocess 3a6abe157 change reset workflow to drop tasks and re-predict e9cd65757 move exceptions for bpmn into bpmn package e654f2ff1 add bpmn_id and bpmn_name attributes to task specs 74bb9cf1a Found that tasks within a sub-workflow were left in a state of "READY" after resetting to task before the sub-workflow. 957a8faec make all task specs in bpmn processes bpmn tasks b6070005c create actual mixin classes & improve package structure 666a9e4e5 Merge pull request #326 from sartography/feature/boundary_event_reset_fix 9fe5ae4ad Whenever a task is reset who's parent is a "_ParentBoundaryEvent" class, reset to that parent boundary event instead, and execute it, so that all the boundary events are reset to the correct point as well. fbc071af5 remove 'is_engine_step' and use existing 'manual' attribute instead 0d8e53a25 remove unused attributes, minor parser improvements 6ae98b585 Merge pull request #325 from sartography/bugfix/make-data-objects-available-to-gateways cefcd3733 make data objects available to gateways 6060fe778 Merge pull request #324 from sartography/task/update-license efa24bed2 update license 56271f7f7 Merge pull request #323 from sartography/bugfix/handle-dash-in-dmn 6de4e7e01 Merge pull request #322 from sartography/improvement/remove-celery 6ee0668cb remove unnecessary dependencies in test 7ceae68c2 change literal '-' in DMN input to None 4cffc7e7a remove celery task and dependency 580d6e516 Merge pull request #321 from sartography/improvement/allow-duplicate-subprocess-names e4440d4df remove legacy signavio parser 477a23184 remove absolute imports from tests failing in CI 15a812a92 use process ids only when storing process specs abaf1b9e9 move parallel gateway tests to their own package 29fd2d0d9 remove some redundant, unused, or unnecessary tests & consolidate others fda1480bc remove unused CORRELATE attribute from tests 21a2fdbee remove signavio files 299c2613c Merge pull request #320 from sartography/parser_funcs 01afc9f6e PR feedback 646737834 Cleanup dfd3f8214 Add same methods for dmn 764e33ccd Rename file, fix tests 9646abca4 Add bpmn in memory parser functions and tests 58f6bd317 Merge pull request #319 from sartography/feature/better_task_order_for_sub_processes fd7c9308f By swapping the order of these lines, we can assure that a call activity is returned BEFORE the tasks that it contains, rather than after it. 0a7ec19d6 Merge pull request #318 from sartography/feature/optionally-skip-call-activities-when-parsing 3430a2e9f add option to skip parsing call activities 1b1da1dd2 Merge pull request #317 from sartography/bugfix/non-bpmn-tutorial e82345d68 remove some bpmn-related stuff from core serializer 6f9bc279c use name for inputs/outputs in base serializer -- not sure why this was ever changed git-subtree-dir: SpiffWorkflow git-subtree-split: 01a25fc3f829786c4b65d19fd0fda408de37c79f
185 lines
7.8 KiB
Python
185 lines
7.8 KiB
Python
# 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.bpmn.specs.data_spec import TaskDataReference
|
|
from SpiffWorkflow.bpmn.parser.util import one
|
|
from SpiffWorkflow.bpmn.parser.ValidationException import ValidationException
|
|
from SpiffWorkflow.bpmn.parser.TaskParser import TaskParser
|
|
from SpiffWorkflow.bpmn.parser.task_parsers import SubprocessParser
|
|
|
|
from SpiffWorkflow.camunda.specs.business_rule_task import BusinessRuleTask
|
|
from SpiffWorkflow.camunda.specs.multiinstance_task import SequentialMultiInstanceTask, ParallelMultiInstanceTask
|
|
from SpiffWorkflow.camunda.specs.user_task import Form, FormField, EnumFormField
|
|
|
|
CAMUNDA_MODEL_NS = 'http://camunda.org/schema/1.0/bpmn'
|
|
|
|
|
|
class CamundaTaskParser(TaskParser):
|
|
|
|
def parse_extensions(self, node=None):
|
|
extensions = {}
|
|
extension_nodes = self.xpath('.//bpmn:extensionElements/camunda:properties/camunda:property')
|
|
for ex_node in extension_nodes:
|
|
extensions[ex_node.get('name')] = ex_node.get('value')
|
|
return extensions
|
|
|
|
def _add_multiinstance_task(self, loop_characteristics):
|
|
|
|
sequential = loop_characteristics.get('isSequential') == 'true'
|
|
prefix = 'bpmn:multiInstanceLoopCharacteristics'
|
|
|
|
cardinality = self.xpath(f'./{prefix}/bpmn:loopCardinality')
|
|
cardinality = cardinality[0].text if len(cardinality) > 0 else None
|
|
collection = self.attribute('collection', 'camunda', loop_characteristics)
|
|
if cardinality is None and collection is None:
|
|
self.raise_validation_exception('A multiinstance task must specify a cardinality or a collection')
|
|
|
|
element_var = self.attribute('elementVariable', 'camunda', loop_characteristics)
|
|
condition = self.xpath(f'./{prefix}/bpmn:completionCondition')
|
|
condition = condition[0].text if len(condition) > 0 else None
|
|
|
|
original = self.spec.task_specs.pop(self.task.name)
|
|
|
|
# We won't include the data input, because sometimes it is the collection, and other times it
|
|
# is the cardinality. The old MI task evaluated the cardinality at run time and treated it like
|
|
# a cardinality if it evaluated to an int, and as the data input if if evaluated to a collection
|
|
# I highly doubt that this is the way Camunda worked then, and I know that's not how it works
|
|
# now, and I think we should ultimately replace this with something that corresponds to how
|
|
# Camunda actually handles things; however, for the time being, I am just going to try to
|
|
# replicate the old behavior as closely as possible.
|
|
# In our subclassed MI task, we'll update the BPMN multiinstance attributes when the task starts.
|
|
params = {
|
|
'task_spec': '',
|
|
'cardinality': cardinality,
|
|
'data_output': TaskDataReference(collection) if collection is not None else None,
|
|
'output_item': TaskDataReference(element_var) if element_var is not None else None,
|
|
'condition': condition,
|
|
}
|
|
if sequential:
|
|
self.task = SequentialMultiInstanceTask(self.spec, original.name, **params)
|
|
else:
|
|
self.task = ParallelMultiInstanceTask(self.spec, original.name, **params)
|
|
self._copy_task_attrs(original)
|
|
|
|
|
|
class BusinessRuleTaskParser(CamundaTaskParser):
|
|
dmn_debug = None
|
|
|
|
def create_task(self):
|
|
decision_ref = self.get_decision_ref(self.node)
|
|
return BusinessRuleTask(self.spec, self.bpmn_id,
|
|
dmnEngine=self.process_parser.parser.get_engine(decision_ref, self.node),
|
|
**self.bpmn_attributes)
|
|
|
|
@staticmethod
|
|
def get_decision_ref(node):
|
|
return node.attrib['{' + CAMUNDA_MODEL_NS + '}decisionRef']
|
|
|
|
|
|
class UserTaskParser(CamundaTaskParser):
|
|
"""Base class for parsing User Tasks"""
|
|
|
|
def create_task(self):
|
|
form = self.get_form()
|
|
return self.spec_class(self.spec, self.bpmn_id, form=form, **self.bpmn_attributes)
|
|
|
|
def get_form(self):
|
|
"""Camunda provides a simple form builder, this will extract the
|
|
details from that form and construct a form model from it. """
|
|
form = Form()
|
|
try:
|
|
form.key = self.attribute('formKey', 'camunda')
|
|
except KeyError:
|
|
return form
|
|
for xml_field in self.xpath('.//camunda:formData/camunda:formField'):
|
|
if xml_field.get('type') == 'enum':
|
|
field = self.get_enum_field(xml_field)
|
|
else:
|
|
field = FormField()
|
|
|
|
field.id = xml_field.get('id')
|
|
field.type = xml_field.get('type')
|
|
field.label = xml_field.get('label')
|
|
field.default_value = xml_field.get('defaultValue')
|
|
|
|
prefix = '{' + self.nsmap.get('camunda') + '}'
|
|
for child in xml_field:
|
|
if child.tag == f'{prefix}properties':
|
|
for p in child:
|
|
field.add_property(p.get('id'), p.get('value'))
|
|
|
|
if child.tag == f'{prefix}validation':
|
|
for v in child:
|
|
field.add_validation(v.get('name'), v.get('config'))
|
|
|
|
form.add_field(field)
|
|
return form
|
|
|
|
def get_enum_field(self, xml_field):
|
|
field = EnumFormField()
|
|
|
|
for child in xml_field:
|
|
if child.tag == '{' + self.nsmap.get('camunda') + '}value':
|
|
field.add_option(child.get('id'), child.get('name'))
|
|
return field
|
|
|
|
|
|
# These classes need to be able to use the overriden _add_multiinstance_task method
|
|
# so they have to inherit from CamundaTaskParser. Therefore, the parsers have to just
|
|
# be copied, because both they and the CamundaTaskParser inherit from the base task
|
|
# parser. I am looking forward to the day when I can replaced all of this with
|
|
# something sane and sensible.
|
|
|
|
class SubWorkflowParser(CamundaTaskParser):
|
|
|
|
def create_task(self):
|
|
subworkflow_spec = SubprocessParser.get_subprocess_spec(self)
|
|
return self.spec_class(self.spec, self.bpmn_id, subworkflow_spec=subworkflow_spec, **self.bpmn_attributes)
|
|
|
|
|
|
class CallActivityParser(CamundaTaskParser):
|
|
"""Parses a CallActivity node."""
|
|
|
|
def create_task(self):
|
|
subworkflow_spec = SubprocessParser.get_call_activity_spec(self)
|
|
return self.spec_class(self.spec, self.bpmn_id, subworkflow_spec=subworkflow_spec, **self.bpmn_attributes)
|
|
|
|
|
|
class ScriptTaskParser(TaskParser):
|
|
"""
|
|
Parses a script task
|
|
"""
|
|
|
|
def create_task(self):
|
|
script = self.get_script()
|
|
return self.spec_class(self.spec, self.bpmn_id, script=script, **self.bpmn_attributes)
|
|
|
|
def get_script(self):
|
|
"""
|
|
Gets the script content from the node. A subclass can override this
|
|
method, if the script needs to be pre-parsed. The result of this call
|
|
will be passed to the Script Engine for execution.
|
|
"""
|
|
try:
|
|
return one(self.xpath('.//bpmn:script')).text
|
|
except AssertionError as ae:
|
|
raise ValidationException(
|
|
"Invalid Script Task. No Script Provided. " + str(ae),
|
|
node=self.node, file_name=self.filename)
|