workflow::state::fsm::get_all_info_not_cached (private)

 workflow::state::fsm::get_all_info_not_cached -workflow_id workflow_id

Defined in packages/workflow/tcl/state-procs.tcl

This proc is for internal use in the workflow API only and should not be invoked directly from application code. Returns all information related to states for a certain workflow instance. Goes to the database on every invocation and should be used together with util_memoize.

Switches:
-workflow_id
(required)
Author:
Peter Marklund

Partial Call Graph (max 5 caller/called nodes):
%3 workflow::state::fsm::get_all_info workflow::state::fsm::get_all_info (private) workflow::state::fsm::get_all_info_not_cached workflow::state::fsm::get_all_info_not_cached workflow::state::fsm::get_all_info->workflow::state::fsm::get_all_info_not_cached db_foreach db_foreach (public) workflow::state::fsm::get_all_info_not_cached->db_foreach util_memoize_seed util_memoize_seed (public) workflow::state::fsm::get_all_info_not_cached->util_memoize_seed workflow::state::fsm::get_workflow_id_not_cached workflow::state::fsm::get_workflow_id_not_cached (private) workflow::state::fsm::get_all_info_not_cached->workflow::state::fsm::get_workflow_id_not_cached

Testcases:
No testcase defined.
Source code:
    # state_data will be an array keyed by state_id
    # state_data(123) = array-list with: hide_fields, pretty_name, short_name, state_id, sort_order, workflow_id,
    #                                    enabled_actions, enabled_action_ids, assigned_actions, assigned_action_ids
    # In addition:
    # state_data(state_ids) = [list of state_ids in sort order]
    array set state_data [list]

    # state_array_$state_id is an internal datastructure. It's the array for each state_id entry
    # but as a separate array making it easier to lappend to individual entries

    #----------------------------------------------------------------------
    # Get core state information from DB
    #----------------------------------------------------------------------

    # Use a list to be able to retrieve states in sort order
    set state_ids [list]
    db_foreach select_states {} -column_array state_row {
        # Cache the state_id -> workflow_id lookup
        util_memoize_seed [list workflow::state::fsm::get_workflow_id_not_cached -state_id $state_row(state_id)]  $workflow_id

        set state_id $state_row(state_id)

        array set state_array_$state_id [array get state_row]

        lappend state_ids $state_id
    }
    set state_data(state_ids) $state_ids

    array set action_short_name [list]

    #----------------------------------------------------------------------
    # Build state-action map
    #----------------------------------------------------------------------

    # Will be stored like this:
    # assigned_p_${state_id}($action_id) = 1 if assigned, 0 if enabled, non-existent if neither

    # In addition, we have a supporting structure of action information
    #   action_info(${action_id},short_name)
    #   action_info(${action_id},trigger_type)
    #   action_info(${action_id},always_enabled_p)
    #   action_info(${action_id},parent_action_id)
    #   action_info(${action_id},child_action_ids)

    # 1. Get action data: trigger_type, always_enabled, hierarchy
    db_foreach always_enabled_actions {
        select action_id,
               short_name,
               trigger_type,
               always_enabled_p,
               parent_action_id
        from   workflow_actions
        where  workflow_id = :workflow_id
    } {
        set action_info(${action_id},short_name) $short_name
        set action_info(${action_id},trigger_type) [string trim $trigger_type]
        set action_info(${action_id},parent_action_id) $parent_action_id
        if { [string is true -strict $always_enabled_p] && [lsearch { user auto message } $trigger_type] != -1 } {
            set action_info(${action_id},always_enabled_p) 1
        } else {
            set action_info(${action_id},always_enabled_p) 0
        }

        # Store as a child of parent NOTE: Not needed any longer
        if { $parent_action_id ne "" } {
            lappend action_info(${parent_action_id},child_action_ids) $action_id
        }

        # Mark enabled in all states that have the same parent as the action
        if { $action_info(${action_id},always_enabled_p) } {
            foreach state_id $state_ids {
                if {$parent_action_id eq [set state_array_${state_id}(parent_action_id)]} {
                    set assigned_p_${state_id}($action_id) 0
                }
            }
        }
    }

    # 2. Get action-state map
    db_foreach always_enabled_actions {
        select e.action_id,
               e.state_id,
               e.assigned_p
        from   workflow_actions a,
               workflow_fsm_action_en_in_st e
        where  a.workflow_id = :workflow_id
        and    a.action_id = e.action_id
    } {
        set assigned_p_${state_id}($action_id) [string is true -strict $assigned_p]
    }

    # 3. Put stuff back into the output array
    foreach state_id $state_ids {
        set state_array_${state_id}(enabled_action_ids) [list]
        set state_array_${state_id}(enabled_actions) [list]
        set state_array_${state_id}(assigned_action_ids) [list]
        set state_array_${state_id}(assigned_actions) [list]

        if { [info exists assigned_p_${state_id}] } {
            foreach action_id [array names assigned_p_${state_id}] {
                # Enabled
                lappend state_array_${state_id}(enabled_action_ids) $action_id
                lappend state_array_${state_id}(enabled_actions) $action_info(${action_id},short_name)

                # Assigned
                if { [set assigned_p_${state_id}($action_id)] } {
                    lappend state_array_${state_id}(assigned_action_ids) $action_id
                    lappend state_array_${state_id}(assigned_actions) $action_info(${action_id},short_name)
                }
            }
        }
    }

    #----------------------------------------------------------------------
    # Final output
    #----------------------------------------------------------------------

    # Move over to normal array
    foreach state_id $state_ids {
        set state_data($state_id) [array get state_array_$state_id]
    }

    return [array get state_data]
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
<fullquery name="workflow::state::fsm::get_all_info_not_cached.select_states">
    <querytext>
      select s.workflow_id,
             s.state_id,
             s.sort_order,
             s.short_name,
             s.pretty_name,
             s.hide_fields,
             s.parent_action_id,
             (select short_name from workflow_actions where action_id = s.parent_action_id) as parent_action
      from   workflow_fsm_states s
      where  s.workflow_id = :workflow_id
      order by s.sort_order
    </querytext>
</fullquery>
packages/workflow/tcl/state-procs.xql

[ hide source ]
Show another procedure: