workflow::parse_spec (private)

 workflow::parse_spec -short_name short_name \
    [ -package_key package_key ] [ -object_id object_id ] -spec spec \
    [ -workflow_handler workflow_handler ] [ -handlers handlers ]

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

Create workflow, roles, states, actions, etc., as appropriate

Switches:
-short_name (required)
-package_key (optional)
-object_id (optional)
-spec (required)
The roles spec
-workflow_handler (optional, defaults to "workflow")
-handlers (optional, defaults to " roles workflow::role actions workflow::action ")
Author:
Lars Pind <lars@collaboraid.biz>
See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 workflow::new_from_spec workflow::new_from_spec (public) workflow::parse_spec workflow::parse_spec workflow::new_from_spec->workflow::parse_spec db_transaction db_transaction (public) workflow::parse_spec->db_transaction workflow::flush_cache workflow::flush_cache (private) workflow::parse_spec->workflow::flush_cache

Testcases:
No testcase defined.
Source code:
    # Default values
    array set workflow {
        callbacks {}
        object_type {acs_object}
    }

    foreach { key value } $spec {
        set workflow($key) [string trim $value]
    }

    # Override stuff in the spec with stuff provided as an argument here
    foreach var { short_name package_key object_id } {
        if { [set $var] ne "" || (![info exists workflow($var)] || $workflow($var) eq "") } {
            set workflow($var) [set $var]
        }
    }

    # Pull out the extra types, roles/actions/states, so we don't try to create the workflow with them
    array set aux [list]
    array set counter [list]
    array set remain [list]
    foreach { key namespace } $handlers {
        if { [info exists workflow($key)] } {
            set aux($key$workflow($key)
            if { [info exists count($key)] } {
                incr remain($key)
            } else {
                set remain($key) 1
            }
            set counter($key) 0
            unset workflow($key)
        }
    }

    array set sub_id [list]

    db_transaction {
        # Create the workflow
        set workflow_id [${workflow_handler}::edit  -internal  -operation "insert"  -array workflow]

        # Create roles/actions/states
        foreach { type namespace } $handlers {
            # type is 'roles', 'actions', 'states', etc.
            if { [info exists aux($type)] } {
                incr remain($type) -1
                incr counter($type)
                foreach { subshort_name subspec } $aux($type) {
                    # subshort_name is the short_name of a single role/action/state
                    array unset row
                    array set row $subspec
                    set row(short_name) $subshort_name

                    # string trim everything
                    foreach key [array names row] {
                        set row($key) [string trim $row($key)]
                    }

                    set cmd [list ${namespace}::edit  -internal  -workflow_id $workflow_id  -handlers $handlers  -array row]

                    if { $counter($type) == 1 } {
                        lappend cmd -operation insert
                    } else {
                        lappend cmd -[string range $type 0 end-1]_id $sub_id(${type},${subshort_name})
                    }
                    if { $remain($type) == 0 } {
                        lappend cmd -no_complain
                    }

                    set sub_id(${type},${subshort_name}) [eval $cmd]

                    # Flush the cache after all creates
                    workflow::flush_cache -workflow_id $workflow_id
                }
            }
        }
    }

    return $workflow_id
Generic XQL file:
packages/workflow/tcl/workflow-procs.xql

PostgreSQL XQL file:
packages/workflow/tcl/workflow-procs-postgresql.xql

Oracle XQL file:
packages/workflow/tcl/workflow-procs-oracle.xql

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