|
| 1 | +# coding=utf-8 |
| 2 | +from typing import List |
| 3 | + |
| 4 | +from application.flow.i_step_node import NodeResult |
| 5 | +from application.flow.step_node.variable_assign.i_variable_assign_node import IVariableAssignNode |
| 6 | + |
| 7 | + |
| 8 | +class BaseVariableAssignNode(IVariableAssignNode): |
| 9 | + def save_context(self, details, workflow_manage): |
| 10 | + self.context['variable_list'] = details.get('variable_list') |
| 11 | + |
| 12 | + def execute(self, variable_list, stream, **kwargs) -> NodeResult: |
| 13 | + # |
| 14 | + for variable in variable_list: |
| 15 | + if 'fields' not in variable: |
| 16 | + continue |
| 17 | + if 'global' == variable['fields'][0]: |
| 18 | + if variable['source'] == 'custom': |
| 19 | + self.workflow_manage.context[variable['fields'][1]] = variable['value'] |
| 20 | + else: |
| 21 | + reference = self.get_reference_content(variable['reference']) |
| 22 | + self.workflow_manage.context[variable['fields'][1]] = reference |
| 23 | + # print('variable_list:', variable_list) |
| 24 | + |
| 25 | + return NodeResult({'variable_list': variable_list}, {}) |
| 26 | + |
| 27 | + def get_reference_content(self, fields: List[str]): |
| 28 | + return str(self.workflow_manage.get_reference_field( |
| 29 | + fields[0], |
| 30 | + fields[1:])) |
| 31 | + |
| 32 | + def get_details(self, index: int, **kwargs): |
| 33 | + return { |
| 34 | + 'name': self.node.properties.get('stepName'), |
| 35 | + "index": index, |
| 36 | + 'run_time': self.context.get('run_time'), |
| 37 | + 'type': self.node.type, |
| 38 | + 'variable_list': self.context.get('variable_list'), |
| 39 | + 'status': self.status, |
| 40 | + 'err_message': self.err_message |
| 41 | + } |
0 commit comments