diff --git a/SpiffWorkflow/bpmn/script_engine/feel_engine.py b/SpiffWorkflow/bpmn/script_engine/feel_engine.py index 2d5492fe..3bb0b589 100644 --- a/SpiffWorkflow/bpmn/script_engine/feel_engine.py +++ b/SpiffWorkflow/bpmn/script_engine/feel_engine.py @@ -32,11 +32,6 @@ def feelConvertTime(datestr,parsestr): class FeelInterval(): def __init__(self, begin, end, leftOpen=False, rightOpen=False): - warnings.warn( - 'The FEEL script engine is deprecated and will be removed in the next release', - DeprecationWarning, - stacklevel=2, - ) # pesky thing with python floats and Decimal comparison if isinstance(begin,float): begin = Decimal("%0.5f"%begin) @@ -274,6 +269,11 @@ class FeelLikeScriptEngine(PythonScriptEngine): expressions in a mini-language of your own. """ def __init__(self, environment=None): + warnings.warn( + 'The FEEL script engine is deprecated and will be removed in the next release', + DeprecationWarning, + stacklevel=2, + ) super().__init__(environment=environment) def validate(self, expression): @@ -294,17 +294,10 @@ def patch_expression(self, invalid_python, lhs=''): proposed_python = lhs + proposed_python return proposed_python - def _evaluate(self, expression, context, task=None, external_context=None): - """ - Evaluate the given expression, within the context of the given task and - return the result. - """ + def evaluate(self, task, expression, external_context=None): if external_context is None: external_context = {} - - revised = self.patch_expression(expression) - external_context.update(externalFuncs) - return super()._evaluate(revised, context, external_context=external_context) + return self._evaluate(expression, task.data, external_context=external_context) def execute(self, task, script, data, external_context=None): """ @@ -313,8 +306,15 @@ def execute(self, task, script, data, external_context=None): if external_context is None: external_context = {} external_context.update(externalFuncs) - super().execute(task, script, external_context) - - - + return super().execute(task, script, external_context) + def _evaluate(self, expression, context, task=None, external_context=None): + """ + Evaluate the given expression, within the context of the given task and + return the result. + """ + if external_context is None: + external_context = {} + external_context.update(externalFuncs) + revised = self.patch_expression(expression) + return self.environment.evaluate(revised, context, external_context=external_context) diff --git a/SpiffWorkflow/bpmn/script_engine/python_engine.py b/SpiffWorkflow/bpmn/script_engine/python_engine.py index a32004ab..cb5b58d4 100644 --- a/SpiffWorkflow/bpmn/script_engine/python_engine.py +++ b/SpiffWorkflow/bpmn/script_engine/python_engine.py @@ -20,6 +20,7 @@ import ast import sys import traceback +import warnings from SpiffWorkflow.exceptions import SpiffWorkflowException from SpiffWorkflow.bpmn.exceptions import WorkflowTaskException @@ -49,7 +50,7 @@ def evaluate(self, task, expression, external_context=None): return the result. """ try: - return self._evaluate(expression, task.data, external_context) + return self.environment.evaluate(expression, task.data, external_context) except SpiffWorkflowException as se: se.add_note(f"Error evaluating expression '{expression}'") raise se @@ -59,15 +60,20 @@ def evaluate(self, task, expression, external_context=None): def execute(self, task, script, external_context=None): """Execute the script, within the context of the specified task.""" try: - return self._execute(script, task.data, external_context or {}) + return self.environment.execute(script, task.data, external_context or {}) except Exception as err: wte = self.create_task_exec_exception(task, script, err) raise wte def call_service(self, operation_name, operation_params, task_data): - """Override to control how external services are called from service - tasks.""" - raise NotImplementedError("To call external services override the script engine and implement `call_service`.") + """Override to control how external services are called from service tasks.""" + warnings.warn( + 'In the next release, implementation of this method will be moved to the scripting environment', + DeprecationWarning, + stacklevel=2, + ) + # Ideally, this method would look like call_service(self, task, operation_name, operation_params) + return self.environment.call_service(operation_name, operation_params, task_data) def create_task_exec_exception(self, task, script, err): line_number, error_line = self.get_error_line_number_and_content(script, err) @@ -97,9 +103,3 @@ def get_error_line_number_and_content(self, script, err): if line_number > 0: error_line = script.splitlines()[line_number - 1] return line_number, error_line - - def _evaluate(self, expression, context, external_context=None): - return self.environment.evaluate(expression, context, external_context) - - def _execute(self, script, context, external_context=None): - return self.environment.execute(script, context, external_context) diff --git a/SpiffWorkflow/bpmn/script_engine/python_environment.py b/SpiffWorkflow/bpmn/script_engine/python_environment.py index ff97c4f2..bd4b4a4d 100644 --- a/SpiffWorkflow/bpmn/script_engine/python_environment.py +++ b/SpiffWorkflow/bpmn/script_engine/python_environment.py @@ -30,6 +30,9 @@ def evaluate(self, expression, context, external_context=None): def execute(self, script, context, external_context=None): raise NotImplementedError("Subclass must implement this method") + def call_service(self, operation_name, operation_params, task_data): + raise NotImplementedError("To call external services override the script engine and implement `call_service`.") + class TaskDataEnvironment(BasePythonScriptEngineEnvironment): diff --git a/SpiffWorkflow/bpmn/specs/event_definitions/message.py b/SpiffWorkflow/bpmn/specs/event_definitions/message.py index e9245b45..e9f27a65 100644 --- a/SpiffWorkflow/bpmn/specs/event_definitions/message.py +++ b/SpiffWorkflow/bpmn/specs/event_definitions/message.py @@ -59,7 +59,7 @@ def get_correlations(self, task, payload): if key not in correlations: correlations[key] = {} try: - correlations[key][property.name] = task.workflow.script_engine._evaluate(property.retrieval_expression, payload) + correlations[key][property.name] = task.workflow.script_engine.environment.evaluate(property.retrieval_expression, payload) except WorkflowException: # Just ignore missing keys. The dictionaries have to match exactly pass diff --git a/SpiffWorkflow/dmn/engine/DMNEngine.py b/SpiffWorkflow/dmn/engine/DMNEngine.py index 96e35cd3..fc9b60a4 100644 --- a/SpiffWorkflow/dmn/engine/DMNEngine.py +++ b/SpiffWorkflow/dmn/engine/DMNEngine.py @@ -122,8 +122,7 @@ def evaluate(self, input_expr, match_expr, task): external_context = { 'dmninputexpr': script_engine.evaluate(task, input_expr) } - return script_engine.evaluate(task, match_expr, - external_context=external_context) + return script_engine.evaluate(task, match_expr, external_context=external_context) # The input expression just has to be something that can be parsed as is by the engine. script_engine.validate(input_expr) diff --git a/tests/SpiffWorkflow/dmn/feel_engine/FeelBoolDecisionTest.py b/tests/SpiffWorkflow/dmn/feel_engine/FeelBoolDecisionTest.py index 3addab0e..c9dc3fab 100644 --- a/tests/SpiffWorkflow/dmn/feel_engine/FeelBoolDecisionTest.py +++ b/tests/SpiffWorkflow/dmn/feel_engine/FeelBoolDecisionTest.py @@ -23,9 +23,3 @@ def test_bool_decision_string_output2(self): def test_bool_decision_string_output3(self): res = self.runner.decide(None) self.assertEqual(res.description, 'ELSE Row Annotation') - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FeelBoolDecisionTestClass) - -if __name__ == '__main__': - unittest.TextTestRunner(verbosity=2).run(suite())