jasquat 35ef5cbe54 Squashed 'SpiffWorkflow/' changes from 4195453a4..1f51db962
1f51db962 Merge pull request #283 from sartography/feature/better_errors
69fb4967e Patching up some bugs and logical disconnects as I test out the errors.
cf5be0096 * Making a few more things consistent in the error messages -- so there isn't filename for validation errors, and file_name for WorkflowExceptions.  Same for line_number vs sourceline. * Assure than an error_type is consistently set on exceptions. * ValidationExceptions should not bild up a detailed error message that replicates information available within it.
440ee16c8 Responding to some excellent suggestions from Elizabeth:
655e415e1 Merge pull request #282 from subhakarks/fix-workfowspec-dump
1f6d3cf4e Explain that the error happened in a pre-script or post script.
8119abd14 Added a top level SpiffWorklowException that all exceptions inherit from.  Aside from a message string you can append information to these exceptions with "add_note", which is a new method that all exceptions have starting in python 3.11 Switched arguments to the WorkflowException, WorkflowTaskException - which now always takes a string message as the first argument, and named arguments thereafter to be consistent with all other error messages in Python. Consistently raise ValidationExceptions whenever we encounter an error anywhere during parsing of xml. The BPMN/WorkflowTaskExecException is removed, in favor of just calling a WorkflowTaskException.  There is nothing BPMN Specific in the logic, so no need for this. Consolidated error message logic so that things like "Did you mean" just get added by default if possible.  So we don't have to separately deal with that logic each time. Better Error messages for DMN (include row number as a part of the error information)
13463b5c5 fix for workflowspec dump
be26100bc Merge pull request #280 from sartography/feature/remove-unused-bpmn-attributes-and-methods
23a5c1d70 remove 'entering_* methods
4e5875ec8 remove sequence flow
5eed83ab1 Merge pull request #278 from sartography/feature/remove-old-serializer
614f1c68a remove compact serializer and references
e7e410d4a remove old serializer and references

git-subtree-dir: SpiffWorkflow
git-subtree-split: 1f51db962ccaed5810f5d0f7d76a932f056430ab
2023-01-19 10:47:07 -05:00

110 lines
3.0 KiB
Python

from collections import OrderedDict
from enum import Enum
from ...util.deep_merge import DeepMerge
class HitPolicy(Enum):
UNIQUE = "UNIQUE"
COLLECT = "COLLECT"
# ANY = "ANY"
# PRIORITY = "PRIORITY"
# FIRST = "FIRST"
# OUTPUT_ORDER = "OUTPUT ORDER"
# RULE_ORDER = "RULE ORDER"
# class Aggregation(Enum):
# SUM = "SUM"
# COUNT = "COUNT"
# MIN = "MIN"
# MAX = "MAX"
class Decision:
def __init__(self, id, name):
self.id = id
self.name = name
self.decisionTables = []
class DecisionTable:
def __init__(self, id, name, hit_policy):
self.id = id
self.name = name
self.hit_policy = hit_policy
self.inputs = []
self.outputs = []
self.rules = []
class Input:
def __init__(self, id, label, name, expression, typeRef):
self.id = id
self.label = label
self.name = name
self.expression = expression
self.typeRef = typeRef
class InputEntry:
def __init__(self, id, input):
self.id = id
self.input = input
self.description = ''
self.lhs = []
class Output:
def __init__(self, id, label, name, typeRef):
self.id = id
self.label = label
self.name = name
self.typeRef = typeRef
class OutputEntry:
def __init__(self, id, output):
self.id = id
self.output = output
self.description = ''
self.text = ''
class Rule:
def __init__(self, id):
self.id = id
self.row_number = 0
self.description = ''
self.inputEntries = []
self.outputEntries = []
def output_as_dict(self, task):
script_engine = task.workflow.script_engine
out = OrderedDict()
for outputEntry in self.outputEntries:
# try to use the id, but fall back to label if no name is provided.
key = outputEntry.output.name or outputEntry.output.label
if hasattr(outputEntry, "text") and outputEntry.text:
outvalue = script_engine.evaluate(task, outputEntry.text)
else:
outvalue = ""
if '.' in key: # we need to allow for dot notation in the DMN -
# I would use box to do this, but they didn't have a feature to build
# a dict based on a dot notation withoug eval
# so we build up a dictionary structure based on the key, and let the parent
# do a deep merge
currentout = {}
subkeylist = list(reversed(key.split('.')))
for subkey in subkeylist[:-1]:
currentout[subkey] = outvalue
outvalue = currentout
currentout = {}
basekey = subkeylist[-1]
out[basekey] = DeepMerge.merge(out.get(basekey,{}),outvalue)
else:
out[key] = outvalue
return out