workflow::action::get_all_info_not_cached (private)

 workflow::action::get_all_info_not_cached -workflow_id workflow_id

Defined in packages/workflow/tcl/action-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 actions 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::action::get_all_info workflow::action::get_all_info (private) workflow::action::get_all_info_not_cached workflow::action::get_all_info_not_cached workflow::action::get_all_info->workflow::action::get_all_info_not_cached db_foreach db_foreach (public) workflow::action::get_all_info_not_cached->db_foreach util_memoize_seed util_memoize_seed (public) workflow::action::get_all_info_not_cached->util_memoize_seed workflow::action::get_workflow_id_not_cached workflow::action::get_workflow_id_not_cached (private) workflow::action::get_all_info_not_cached->workflow::action::get_workflow_id_not_cached workflow::fsm::get_states workflow::fsm::get_states (public) workflow::action::get_all_info_not_cached->workflow::fsm::get_states workflow::state::fsm::get workflow::state::fsm::get (public) workflow::action::get_all_info_not_cached->workflow::state::fsm::get

Testcases:
No testcase defined.
Source code:
    # We avoid nested db queries in this proc to enhance performance

    # This is where we will ultimately deliver the results
    array set action_data {}

    # This will be a list of all action_id's
    set action_ids [list]

    # Get basic action info
    db_foreach action_info {} -column_array action_row {
        # Cache the mapping action_id -> workflow_id
        util_memoize_seed [list workflow::action::get_workflow_id_not_cached -action_id $action_row(action_id)]  $workflow_id

        set action_id $action_row(action_id)
        array set action_array_${action_id} {
            callbacks_array {}
            callbacks {}
            callback_ids {}
            allowed_roles {}
            allowed_role_ids {}
            allowed_roles_array {}
            privileges {}
            assigned_states {}
            assigned_state_ids {}
            enabled_states {}
            enabled_state_ids {}
            child_states {}
            child_state_ids {}
        }
        array set action_array_${action_id} [array get action_row]
        if { $action_row(parent_action_id) ne "" } {
            lappend action_array_$action_row(parent_action_id)(child_action_ids) $action_id
            lappend action_array_$action_row(parent_action_id)(child_actions) $action_row(short_name)
        }
        lappend action_ids $action_id
    }

    foreach action_id $action_ids {
        if { ![info exists action_array_${action_id}(child_action_ids)] } {
            set action_array_${action_id}(child_action_ids) [list]
            set action_array_${action_id}(child_actios) [list]
        }
    }

    # Get child states
    foreach state_id [workflow::fsm::get_states -all -workflow_id $workflow_id] {
        workflow::state::fsm::get -state_id $state_id -array state_array
        if { $state_array(parent_action_id) ne "" } {
            lappend action_array_$state_array(parent_action_id)(child_state_ids) $state_id
            lappend action_array_$state_array(parent_action_id)(child_states) $state_array(short_name)
        }
    }

    # Build a separate array for all action callbacks of the workflow

    # Columns: impl_id, impl_name, impl_owner_name, contract_name, action_id
    db_foreach action_callbacks {} -column_array callback_row {
        set action_id $callback_row(action_id)

        lappend action_array_${action_id}(callbacks)  "$callback_row(impl_owner_name).$callback_row(impl_name)"
        lappend action_array_${action_id}(callback_ids) $callback_row(impl_id)

        lappend action_array_${action_id}(callbacks_array) $callback_row(impl_id) [array get callback_row]
    }

    # Build an array for all allowed roles for all actions
    db_foreach action_allowed_roles {} -column_array allowed_role_row {
        set action_id $allowed_role_row(action_id)

        lappend action_array_${action_id}(allowed_roles) $allowed_role_row(short_name)
        lappend action_array_${action_id}(allowed_role_ids) $allowed_role_row(role_id)

        # The 'allowed_roles_array' entry is an array-list, keyed by role_id, with the value being
        # an array-list of the information returned by this call
        lappend action_array_${action_id}(allowed_roles_array)  [list $allowed_role_row(role_id) [array get allowed_role_row]]
    }

    # Build an array  of privileges for all actions
    db_foreach select_privileges {} {
        lappend action_array_${action_id}(privileges) $privilege
    }

    # Build arrays of enabled and assigned state short names for all actions
    db_foreach action_enabled_in_states {} {
        if {$assigned_p == "t"} {
            lappend action_array_${action_id}(assigned_states) $short_name
            lappend action_array_${action_id}(assigned_state_ids) $state_id
        } else {
            lappend action_array_${action_id}(enabled_states) $short_name
            lappend action_array_${action_id}(enabled_state_ids) $state_id
        }
    }

    # Move everything from the action_array_${action_id} arrays into the cacheo
    foreach action_id $action_ids {
        set action_data($action_id) [array get action_array_${action_id}]
    }

    set action_data(action_ids) $action_ids

    return [array get action_data]
Generic XQL file:
<fullquery name="workflow::action::get_all_info_not_cached.select_privileges">
    <querytext>
      select p.privilege,
             p.action_id
      from   workflow_action_privileges p,
             workflow_actions a
      where  a.action_id = p.action_id
        and  a.workflow_id = :workflow_id
      order  by privilege
    </querytext>
</fullquery>

<fullquery name="workflow::action::get_all_info_not_cached.action_callbacks">
    <querytext>
      select impl.impl_id,
             impl.impl_name,
             impl.impl_owner_name,
             ctr.contract_name,
             a.action_id
      from   workflow_action_callbacks ac,
             workflow_actions a,
             acs_sc_impls impl,
             acs_sc_bindings bind,
             acs_sc_contracts ctr
      where  ac.action_id = a.action_id
      and    a.workflow_id = :workflow_id
      and    impl.impl_id = ac.acs_sc_impl_id
      and    impl.impl_id = bind.impl_id
      and    bind.contract_id = ctr.contract_id
      order  by a.action_id, ac.sort_order
    </querytext>
</fullquery>

<fullquery name="workflow::action::get_all_info_not_cached.action_allowed_roles">
    <querytext>
      select r.short_name,
             r.role_id,
             aar.action_id
      from   workflow_roles r,
             workflow_action_allowed_roles aar
      where  r.workflow_id = :workflow_id
      and    r.role_id = aar.role_id
      order  by r.sort_order
    </querytext>
</fullquery>

<fullquery name="workflow::action::get_all_info_not_cached.action_enabled_in_states">
    <querytext>
        select s.state_id,
               s.short_name,
               waeis.action_id,
               waeis.assigned_p
        from   workflow_fsm_action_en_in_st waeis,
               workflow_actions a,
               workflow_fsm_states s
        where  waeis.action_id = a.action_id
        and    a.workflow_id = :workflow_id
        and    s.state_id = waeis.state_id
        order  by s.sort_order
    </querytext>
</fullquery>
packages/workflow/tcl/action-procs.xql

PostgreSQL XQL file:
<fullquery name="workflow::action::get_all_info_not_cached.action_info">
    <querytext>
        select a.action_id,
               a.workflow_id,
               a.sort_order,
               a.short_name,
               a.pretty_name,
               a.pretty_past_tense,
               a.edit_fields,
               a.trigger_type,
               a.parent_action_id,
               (select short_name from workflow_actions where action_id = a.parent_action_id) as parent_action,
               a.assigned_role as assigned_role_id,
               (select short_name from workflow_roles where role_id = a.assigned_role) as assigned_role,
               a.always_enabled_p,
               fa.new_state as new_state_id,
               (select short_name from workflow_fsm_states where state_id = fa.new_state) as new_state,
               a.description,
               a.description_mime_type,
               extract (days from a.timeout) * 86400 + extract (hours from a.timeout) * 3600 + 
               extract (minutes from a.timeout) * 60 + extract (seconds from a.timeout) as timeout_seconds
        from   workflow_actions a left outer join 
               workflow_fsm_actions fa on (a.action_id = fa.action_id) 
        where  a.workflow_id = :workflow_id
        order by a.sort_order
    </querytext>
</fullquery>
packages/workflow/tcl/action-procs-postgresql.xql

Oracle XQL file:
<fullquery name="workflow::action::get_all_info_not_cached.action_info">
    <querytext>
        select a.action_id,
               a.workflow_id,
               a.sort_order,
               a.short_name,
               a.pretty_name,
               a.pretty_past_tense,
               a.edit_fields,
               a.trigger_type,
               a.parent_action_id,
               (select short_name from workflow_actions where action_id = a.parent_action_id) as parent_action,
               a.assigned_role as assigned_role_id,
               (select short_name from workflow_roles where role_id = a.assigned_role) as assigned_role,
               a.always_enabled_p,
               fa.new_state as new_state_id,
               (select short_name from workflow_fsm_states where state_id = fa.new_state) as new_state,
               a.description,
               a.description_mime_type,
               a.timeout_seconds
        from   workflow_actions a,
               workflow_fsm_actions fa
        where  a.workflow_id = :workflow_id
          and  a.action_id = fa.action_id (+)
        order by a.sort_order
    </querytext>
</fullquery>
packages/workflow/tcl/action-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: