mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-02-20 21:48:07 +00:00
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
95 lines
3.5 KiB
Python
95 lines
3.5 KiB
Python
import glob
|
|
import os
|
|
|
|
from lxml import etree
|
|
|
|
from ...bpmn.parser.util import full_tag
|
|
from ...bpmn.parser.ValidationException import ValidationException
|
|
|
|
from ...bpmn.parser.BpmnParser import BpmnParser, BpmnValidator
|
|
from ...dmn.parser.DMNParser import DMNParser, get_dmn_ns
|
|
from ..engine.DMNEngine import DMNEngine
|
|
|
|
XSD_DIR = os.path.join(os.path.dirname(__file__), 'schema')
|
|
SCHEMAS = {
|
|
'http://www.omg.org/spec/DMN/20151101/dmn.xsd': os.path.join(XSD_DIR, 'DMN.xsd'),
|
|
'http://www.omg.org/spec/DMN/20180521/MODEL/': os.path.join(XSD_DIR, 'DMN12.xsd'),
|
|
'https://www.omg.org/spec/DMN/20191111/MODEL/': os.path.join(XSD_DIR, 'DMN13.xsd'),
|
|
}
|
|
|
|
|
|
class BpmnDmnParser(BpmnParser):
|
|
|
|
def __init__(self, namespaces=None, validator=None, dmn_schemas=None):
|
|
super().__init__(namespaces, validator)
|
|
self.dmn_schemas = dmn_schemas or SCHEMAS
|
|
self.dmn_parsers = {}
|
|
self.dmn_parsers_by_name = {}
|
|
self.dmn_dependencies = set()
|
|
|
|
def get_engine(self, decision_ref, node):
|
|
if decision_ref not in self.dmn_parsers:
|
|
options = ', '.join(list(self.dmn_parsers.keys()))
|
|
raise ValidationException(
|
|
'No DMN Diagram available with id "%s", Available DMN ids are: %s' %(decision_ref, options),
|
|
node=node, file_name='')
|
|
dmn_parser = self.dmn_parsers[decision_ref]
|
|
dmn_parser.parse()
|
|
decision = dmn_parser.decision
|
|
|
|
return DMNEngine(decision.decisionTables[0])
|
|
|
|
def add_dmn_xml(self, node, filename=None):
|
|
"""
|
|
Add the given lxml representation of the DMN file to the parser's set.
|
|
"""
|
|
nsmap = get_dmn_ns(node)
|
|
# We have to create a dmn validator on the fly, because we support multiple versions
|
|
# If we have a bpmn validator, assume DMN validation should be done as well.
|
|
# I don't like this, but I don't see a better solution.
|
|
schema = self.dmn_schemas.get(nsmap.get('dmn'))
|
|
if self.validator and schema is not None:
|
|
validator = BpmnValidator(schema)
|
|
validator.validate(node, filename)
|
|
|
|
dmn_parser = DMNParser(self, node, nsmap, filename=filename)
|
|
self.dmn_parsers[dmn_parser.get_id()] = dmn_parser
|
|
self.dmn_parsers_by_name[dmn_parser.get_name()] = dmn_parser
|
|
|
|
def add_dmn_file(self, filename):
|
|
"""
|
|
Add the given DMN filename to the parser's set.
|
|
"""
|
|
self.add_dmn_files([filename])
|
|
|
|
def add_dmn_files_by_glob(self, g):
|
|
"""
|
|
Add all filenames matching the provided pattern (e.g. *.bpmn) to the
|
|
parser's set.
|
|
"""
|
|
self.add_dmn_files(glob.glob(g))
|
|
|
|
def add_dmn_files(self, filenames):
|
|
"""
|
|
Add all filenames in the given list to the parser's set.
|
|
"""
|
|
for filename in filenames:
|
|
f = open(filename, 'r')
|
|
try:
|
|
self.add_dmn_xml(etree.parse(f).getroot(), filename=filename)
|
|
finally:
|
|
f.close()
|
|
|
|
def get_dependencies(self):
|
|
return self.process_dependencies.union(self.dmn_dependencies)
|
|
|
|
def get_dmn_dependencies(self):
|
|
return self.dmn_dependencies
|
|
|
|
def _find_dependencies(self, process):
|
|
super()._find_dependencies(process)
|
|
parser_cls, cls = self._get_parser_class(full_tag('businessRuleTask'))
|
|
for business_rule in process.xpath('.//bpmn:businessRuleTask',namespaces=self.namespaces):
|
|
self.dmn_dependencies.add(parser_cls.get_decision_ref(business_rule))
|
|
|