mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-02-05 22:53:57 +00:00
35ef5cbe54
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
87 lines
3.6 KiB
Python
87 lines
3.6 KiB
Python
from SpiffWorkflow.bpmn.parser.ValidationException import ValidationException
|
|
from .util import first
|
|
|
|
DEFAULT_NSMAP = {
|
|
'bpmn': 'http://www.omg.org/spec/BPMN/20100524/MODEL',
|
|
'bpmndi': 'http://www.omg.org/spec/BPMN/20100524/DI',
|
|
'dc': 'http://www.omg.org/spec/DD/20100524/DC',
|
|
|
|
}
|
|
|
|
CAMUNDA_MODEL_NS = 'http://camunda.org/schema/1.0/bpmn'
|
|
|
|
class NodeParser:
|
|
|
|
def __init__(self, node, nsmap=None, filename=None, lane=None):
|
|
|
|
self.node = node
|
|
self.nsmap = nsmap or DEFAULT_NSMAP
|
|
self.filename = filename
|
|
self.lane = self._get_lane() or lane
|
|
self.position = self._get_position() or {'x': 0.0, 'y': 0.0}
|
|
|
|
def get_id(self):
|
|
return self.node.get('id')
|
|
|
|
def xpath(self, xpath, extra_ns=None):
|
|
return self._xpath(self.node, xpath, extra_ns)
|
|
|
|
def doc_xpath(self, xpath, extra_ns=None):
|
|
root = self.node.getroottree().getroot()
|
|
return self._xpath(root, xpath, extra_ns)
|
|
|
|
def parse_condition(self, sequence_flow):
|
|
expression = first(self._xpath(sequence_flow, './/bpmn:conditionExpression'))
|
|
return expression.text if expression is not None else None
|
|
|
|
def parse_documentation(self, sequence_flow=None):
|
|
node = sequence_flow if sequence_flow is not None else self.node
|
|
documentation_node = first(self._xpath(node, './/bpmn:documentation'))
|
|
return None if documentation_node is None else documentation_node.text
|
|
|
|
def parse_incoming_data_references(self):
|
|
specs = []
|
|
for name in self.xpath('.//bpmn:dataInputAssociation/bpmn:sourceRef'):
|
|
ref = first(self.doc_xpath(f".//bpmn:dataObjectReference[@id='{name.text}']"))
|
|
if ref is not None and ref.get('dataObjectRef') in self.process_parser.spec.data_objects:
|
|
specs.append(self.process_parser.spec.data_objects[ref.get('dataObjectRef')])
|
|
else:
|
|
raise ValidationException(f'Cannot resolve dataInputAssociation {name}', self.node, self.file_name)
|
|
return specs
|
|
|
|
def parse_outgoing_data_references(self):
|
|
specs = []
|
|
for name in self.xpath('.//bpmn:dataOutputAssociation/bpmn:targetRef'):
|
|
ref = first(self.doc_xpath(f".//bpmn:dataObjectReference[@id='{name.text}']"))
|
|
if ref is not None and ref.get('dataObjectRef') in self.process_parser.spec.data_objects:
|
|
specs.append(self.process_parser.spec.data_objects[ref.get('dataObjectRef')])
|
|
else:
|
|
raise ValidationException(f'Cannot resolve dataOutputAssociation {name}', self.node, self.file_name)
|
|
return specs
|
|
|
|
def parse_extensions(self, node=None):
|
|
extensions = {}
|
|
extra_ns = {'camunda': CAMUNDA_MODEL_NS}
|
|
extension_nodes = self.xpath('.//bpmn:extensionElements/camunda:properties/camunda:property', extra_ns)
|
|
for ex_node in extension_nodes:
|
|
extensions[ex_node.get('name')] = ex_node.get('value')
|
|
return extensions
|
|
|
|
def _get_lane(self):
|
|
noderef = first(self.doc_xpath(f".//bpmn:flowNodeRef[text()='{self.get_id()}']"))
|
|
if noderef is not None:
|
|
return noderef.getparent().get('name')
|
|
|
|
def _get_position(self):
|
|
bounds = first(self.doc_xpath(f".//bpmndi:BPMNShape[@bpmnElement='{self.get_id()}']//dc:Bounds"))
|
|
if bounds is not None:
|
|
return {'x': float(bounds.get('x', 0)), 'y': float(bounds.get('y', 0))}
|
|
|
|
def _xpath(self, node, xpath, extra_ns=None):
|
|
if extra_ns is not None:
|
|
nsmap = self.nsmap.copy()
|
|
nsmap.update(extra_ns)
|
|
else:
|
|
nsmap = self.nsmap
|
|
return node.xpath(xpath, namespaces=nsmap)
|