def _split_test(cr, workitem, split_mode, ident, signal=None, stack=None): cr.execute('select * from wkf_transition where act_from=%s', (workitem['act_id'],)) test = False transitions = [] alltrans = cr.dictfetchall() if split_mode=='XOR' or split_mode=='OR': for transition in alltrans: if wkf_expr.check(cr, workitem, ident, transition,signal): test = True transitions.append((transition['id'], workitem['inst_id'])) if split_mode=='XOR': break else: test = True for transition in alltrans: if not wkf_expr.check(cr, workitem, ident, transition,signal): test = False break cr.execute('select count(*) from wkf_witm_trans where trans_id=%s and inst_id=%s', (transition['id'], workitem['inst_id'])) if not cr.fetchone()[0]: transitions.append((transition['id'], workitem['inst_id'])) if test and len(transitions): cr.executemany('insert into wkf_witm_trans (trans_id,inst_id) values (%s,%s)', transitions) cr.execute('delete from wkf_workitem where id=%s', (workitem['id'],)) for t in transitions: _join_test(cr, t[0], t[1], ident, stack) return True return False
def _split_test(cr, workitem, split_mode, ident, signal=None, stack=None): if stack is None: raise 'Error !!!' cr.execute('select * from wkf_transition where act_from=%s', (workitem['act_id'],)) test = False transitions = [] alltrans = cr.dictfetchall() if split_mode=='XOR' or split_mode=='OR': for transition in alltrans: if wkf_expr.check(cr, workitem, ident, transition,signal): test = True transitions.append((transition['id'], workitem['inst_id'])) if split_mode=='XOR': break else: test = True for transition in alltrans: if not wkf_expr.check(cr, workitem, ident, transition,signal): test = False break cr.execute('select count(*) from wkf_witm_trans where trans_id=%s and inst_id=%s', (transition['id'], workitem['inst_id'])) if not cr.fetchone()[0]: transitions.append((transition['id'], workitem['inst_id'])) if test and len(transitions): cr.executemany('insert into wkf_witm_trans (trans_id,inst_id) values (%s,%s)', transitions) cr.execute('delete from wkf_workitem where id=%s', (workitem['id'],)) for t in transitions: _join_test(cr, t[0], t[1], ident, stack) return True return False
def _split_test(cr, workitem, split_mode, ident, signal=None, stack=None): """ Attempt to move the workitem to a target state denoted by signal @param cr: database handle @param workitem: dict of the workitem to process @param split_mode: Can be 'xor', 'or', or 'and' controls how the next workitems get generated? #FIXME @param ident: tuple of (uid, dotted model name, resource id ) @param signal: desired signal (or transition name) to follow this will filter the list of possible transitions to only that signal noted. @param stack: ??? """ if stack is None: raise 'Error !!!' # Find all transitions out of the current activity node. Depending on the # splitting style of the current activity node, create a list of possible # allowed transitions this record can follow. cr.execute('select * from wkf_transition where act_from=%s', (workitem['act_id'], )) test = False transitions = [] alltrans = cr.dictfetchall() if split_mode == 'XOR' or split_mode == 'OR': for transition in alltrans: if wkf_expr.check(cr, workitem, ident, transition, signal): if config['debug_workflow']: _logger.debug(" {m} split {i[1]},{i[2]} workitem,{w[id]} "\ "transition {t[id]},{t[signal]} OK".format( w=workitem,i=ident,s=signal,t=transition,m=split_mode) ) test = True transitions.append((transition['id'], workitem['inst_id'])) # XOR only allows one transition so break after finding the first one if split_mode == 'XOR': break else: if config['debug_workflow']: _logger.debug(" {m} split {i[1]},{i[2]} workitem,{w[id]} "\ "transition {t[id]},{t[signal]} NOK".format( w=workitem,i=ident,s=signal,t=transition,m=split_mode) ) # If the split mode is 'AND', we only progress when ALL transitions can be # followed else: test = True for transition in alltrans: if not wkf_expr.check(cr, workitem, ident, transition, signal): test = False if config['debug_workflow']: _logger.debug( " {m} split {i[1]},{i[2]} workitem,{w[id]} transition {t[id]},{t[signal]} NOK" .format(w=workitem, i=ident, s=signal, t=transition, m=split_mode)) break else: if config['debug_workflow']: _logger.debug( " {m} split {i[1]},{i[2]} workitem,{w[id]} transition {t[id]},{t[signal]} OK" .format(w=workitem, i=ident, s=signal, t=transition, m=split_mode)) cr.execute( 'select count(*) from wkf_witm_trans where trans_id=%s and inst_id=%s', (transition['id'], workitem['inst_id'])) if not cr.fetchone()[0]: transitions.append((transition['id'], workitem['inst_id'])) # If we now have some transitions, let's move the instance into the new states # via wkf_workitems. Note that this sytem create a list of entries in # wkf_witm_trans then turns them into new wkf_workitems. I guess we do things # this way to take advantage of the create method's processing of associated actions if test and len(transitions): cr.executemany( 'insert into wkf_witm_trans (trans_id,inst_id) values (%s,%s)', transitions) cr.execute('delete from wkf_workitem where id=%s', (workitem['id'], )) for t in transitions: _join_test(cr, t[0], t[1], ident, stack) return True return False