def recover_step(self, message: dict): ''' given an execution id and a pointer from the persistent storage, return the asociated process node to continue its execution ''' try: pointer = Pointer.get_or_exception(message['pointer_id']) if pointer.status != 'ongoing': raise ModelNotFoundError( 'Specified pointer never existed, and never will', ) except ModelNotFoundError: raise InconsistentState('Queued dead pointer') user = User.get_by('identifier', message.get('user_identifier')) if user is None: if message.get('user_identifier') == '__system__': user = User(identifier='__system__', fullname='System').save() else: raise InconsistentState('sent identifier of unexisten user') return ( pointer, user, message['input'], )
def task_read(id): pointer = Pointer.get_or_exception(id) if pointer not in g.user.proxy.tasks: raise Forbidden([{ 'detail': 'Provided user does not have this task assigned', 'where': 'request.authorization', }]) execution = pointer.proxy.execution.get() collection = mongo.db[app.config['EXECUTION_COLLECTION']] state = collection.find_one({ 'id': execution.id, }) xml = Xml.load(app.config, execution.process_name, direct=True) xmliter = iter(xml) node = xmliter.find(lambda e: e.getAttribute('id') == pointer.node_id) xmliter.parser.expandNode(node) # Response body json_data = pointer.to_json(include=['*', 'execution']) # Append node info json_data['node_type'] = node.tagName # Append forms forms = [] for form in node.getElementsByTagName('form'): forms.append(form_to_dict(form)) json_data['form_array'] = forms # If any append previous work done node_state = state['state']['items'][pointer.node_id] node_actors = node_state['actors'] user_identifier = g.user.identifier if user_identifier in node_actors['items']: action = node_actors['items'][user_identifier] json_data['prev_work'] = action['forms'] # Append validation if node.tagName == 'validation': deps = list( map(lambda node: get_text(node), node.getElementsByTagName('dep'))) fields = [] for dep in deps: form_ref, input_name = dep.split('.') # TODO this could be done in O(log N + K) for node in state['state']['items'].values(): if node['state'] != 'valid': continue for identifier in node['actors']['items']: actor = node['actors']['items'][identifier] if actor['state'] != 'valid': continue for form_ix, form in enumerate(actor['forms']): if form['state'] != 'valid': continue if form['ref'] != form_ref: continue if input_name not in form['inputs']['items']: continue input = form['inputs']['items'][input_name] state_ref = [ node['id'], identifier, str(form_ix), ] state_ref = '.'.join(state_ref) state_ref = state_ref + ':' + dep field = { 'ref': state_ref, **input, } del field['state'] fields.append(field) json_data['fields'] = fields return jsonify({ 'data': json_data, })