Index: openacs-4/contrib/packages/simulation/tcl/action-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/action-procs.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/contrib/packages/simulation/tcl/action-procs.tcl 16 Dec 2003 18:34:00 -0000 1.6 +++ openacs-4/contrib/packages/simulation/tcl/action-procs.tcl 17 Dec 2003 14:03:49 -0000 1.7 @@ -169,14 +169,20 @@ ad_proc -public simulation::action::get { + {-local_only:boolean} {-action_id:required} {-array:required} } { - Get information about a simulation action + Get information about a simulation action. + + @param local_only Set this to only get the attributes from the simulation extension table, + not the ones derived from workflow::action::fsm. } { upvar 1 $array row - workflow::action::fsm::get -action_id $action_id -array row + if { !$local_only_p } { + workflow::action::fsm::get -action_id $action_id -array row + } db_1row select_action { select recipient, @@ -190,3 +196,91 @@ array set row [array get local_row] } + + +ad_proc -private simulation::action::generate_spec { + {-action_id {}} + {-one_id {}} +} { + Generate the spec for an individual simulation task definition. + + @param action_id The id of the action to generate spec for. + + @param one_id Same as action_id, just used for consistency across roles/actions/states. + + @return spec The actions spec + + @author Lars Pind (lars@collaboraid.biz) +} { + if { [empty_string_p $action_id] } { + if { [empty_string_p $one_id] } { + error "You must supply either action_id or one_id" + } + set action_id $one_id + } else { + if { ![empty_string_p $one_id] } { + error "You can only supply either action_id or one_id" + } + } + + set spec [workflow::action::fsm::generate_spec -action_id $action_id] + + get -action_id $action_id -array row -local_only + + array unset row recipient + + foreach name [lsort [array names row]] { + if { ![empty_string_p $row($name)] } { + lappend spec $name $row($name) + } + } + + return $spec +} + +ad_proc -public simulation::action::get_ids { + {-workflow_id:required} +} { + Get the action_id's of all the actions in the workflow. + + @param workflow_id The ID of the workflow + + @return list of action_id's. + + @author Lars Pind (lars@collaboraid.biz) +} { + return [workflow::action::fsm::get_ids -workflow_id $workflow_id] +} + +ad_proc -public simulation::action::get_element { + {-action_id {}} + {-one_id {}} + {-element:required} +} { + Return element from information about an action with a given id, including + simulation info. + + @param action_id The ID of the action + + @param one_id Same as action_id, just used for consistency across roles/actions/states. + + @param element The element you want + + @return The element you asked for + + @author Peter Marklund + @author Lars Pind (lars@collaboraid.biz) +} { + if { [empty_string_p $action_id] } { + if { [empty_string_p $one_id] } { + error "You must supply either action_id or one_id" + } + set action_id $one_id + } else { + if { ![empty_string_p $one_id] } { + error "You can only supply either action_id or one_id" + } + } + get -action_id $action_id -array row + return $row($element) +} Index: openacs-4/contrib/packages/simulation/tcl/role-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/role-procs.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/contrib/packages/simulation/tcl/role-procs.tcl 17 Dec 2003 09:34:22 -0000 1.9 +++ openacs-4/contrib/packages/simulation/tcl/role-procs.tcl 17 Dec 2003 14:03:49 -0000 1.10 @@ -152,14 +152,20 @@ } ad_proc -public simulation::role::get { + {-local_only:boolean} {-role_id:required} {-array:required} } { Get information about a simulation role + + @param local_only Set this to only get the attributes from the simulation extension table, + not the ones derived from workflow::role } { upvar 1 $array row - workflow::role::get -role_id $role_id -array row + if { !$local_only_p } { + workflow::role::get -role_id $role_id -array row + } db_1row select_sim_role { select role_id, @@ -171,3 +177,84 @@ array set row [array get local_row] } +ad_proc -public simulation::role::get_element { + {-role_id {}} + {-one_id {}} + {-element:required} +} { + Return a single element from the information about a role. + + @param role_id The id of the role to get an element for. + + @param one_id Same as role_id, just used for consistency across roles/actions/states. + + @return element The element you asked for + + @author Lars Pind (lars@collaboraid.biz) +} { + if { [empty_string_p $role_id] } { + if { [empty_string_p $one_id] } { + error "You must supply either role_id or one_id" + } + set role_id $one_id + } else { + if { ![empty_string_p $one_id] } { + error "You can only supply either role_id or one_id" + } + } + + get -role_id $role_id -array row + return $row($element) +} + +ad_proc -private simulation::role::get_ids { + {-workflow_id:required} +} { + Get the IDs of all the roles in the right order. + + @param workflow_id The id of the workflow to delete. + + @return A list of role IDs. + + @author Lars Pind (lars@collaboraid.biz) +} { + return [workflow::role::get_ids -workflow_id $workflow_id] +} + +ad_proc -private simulation::role::generate_spec { + {-role_id {}} + {-one_id {}} +} { + Generate the spec for an individual simulation task definition. + + @param role_id The id of the role to generate spec for. + + @param one_id Same as role_id, just used for consistency across roles/roles/states. + + @return spec The roles spec + + @author Lars Pind (lars@collaboraid.biz) +} { + if { [empty_string_p $role_id] } { + if { [empty_string_p $one_id] } { + error "You must supply either role_id or one_id" + } + set role_id $one_id + } else { + if { ![empty_string_p $one_id] } { + error "You can only supply either role_id or one_id" + } + } + + set spec [workflow::role::generate_spec -role_id $role_id] + + get -role_id $role_id -array row -local_only + + foreach name [lsort [array names row]] { + if { ![empty_string_p $row($name)] } { + lappend spec $name $row($name) + } + } + + return $spec +} Index: openacs-4/contrib/packages/simulation/tcl/template-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/template-procs.tcl,v diff -u -r1.19 -r1.20 --- openacs-4/contrib/packages/simulation/tcl/template-procs.tcl 17 Dec 2003 09:01:05 -0000 1.19 +++ openacs-4/contrib/packages/simulation/tcl/template-procs.tcl 17 Dec 2003 14:03:49 -0000 1.20 @@ -193,7 +193,7 @@ } # Map each party - foreach party_id $aux(enroll_groups) { + foreach party_id $aux($map_type) { db_dml map_party_to_template { insert into sim_party_sim_map (simulation_id, party_id, type) @@ -631,3 +631,27 @@ -replace } } + + +ad_proc -public simulation::template::generate_spec { + {-workflow_id:required} +} { + Generate a spec for a workflow in array list style. + + @param workflow_id The id of the workflow to generate a spec for. + @return The spec for the workflow. + + @author Lars Pind (lars@collaboraid.biz) + @see workflow::new +} { + set spec [workflow::generate_spec \ + -workflow_id $workflow_id \ + -handlers { + roles simulation::role + actions simulation::action + states workflow::state::fsm + }] + + return $spec +} + Index: openacs-4/packages/simulation/tcl/action-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/Attic/action-procs.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/packages/simulation/tcl/action-procs.tcl 16 Dec 2003 18:34:00 -0000 1.6 +++ openacs-4/packages/simulation/tcl/action-procs.tcl 17 Dec 2003 14:03:49 -0000 1.7 @@ -169,14 +169,20 @@ ad_proc -public simulation::action::get { + {-local_only:boolean} {-action_id:required} {-array:required} } { - Get information about a simulation action + Get information about a simulation action. + + @param local_only Set this to only get the attributes from the simulation extension table, + not the ones derived from workflow::action::fsm. } { upvar 1 $array row - workflow::action::fsm::get -action_id $action_id -array row + if { !$local_only_p } { + workflow::action::fsm::get -action_id $action_id -array row + } db_1row select_action { select recipient, @@ -190,3 +196,91 @@ array set row [array get local_row] } + + +ad_proc -private simulation::action::generate_spec { + {-action_id {}} + {-one_id {}} +} { + Generate the spec for an individual simulation task definition. + + @param action_id The id of the action to generate spec for. + + @param one_id Same as action_id, just used for consistency across roles/actions/states. + + @return spec The actions spec + + @author Lars Pind (lars@collaboraid.biz) +} { + if { [empty_string_p $action_id] } { + if { [empty_string_p $one_id] } { + error "You must supply either action_id or one_id" + } + set action_id $one_id + } else { + if { ![empty_string_p $one_id] } { + error "You can only supply either action_id or one_id" + } + } + + set spec [workflow::action::fsm::generate_spec -action_id $action_id] + + get -action_id $action_id -array row -local_only + + array unset row recipient + + foreach name [lsort [array names row]] { + if { ![empty_string_p $row($name)] } { + lappend spec $name $row($name) + } + } + + return $spec +} + +ad_proc -public simulation::action::get_ids { + {-workflow_id:required} +} { + Get the action_id's of all the actions in the workflow. + + @param workflow_id The ID of the workflow + + @return list of action_id's. + + @author Lars Pind (lars@collaboraid.biz) +} { + return [workflow::action::fsm::get_ids -workflow_id $workflow_id] +} + +ad_proc -public simulation::action::get_element { + {-action_id {}} + {-one_id {}} + {-element:required} +} { + Return element from information about an action with a given id, including + simulation info. + + @param action_id The ID of the action + + @param one_id Same as action_id, just used for consistency across roles/actions/states. + + @param element The element you want + + @return The element you asked for + + @author Peter Marklund + @author Lars Pind (lars@collaboraid.biz) +} { + if { [empty_string_p $action_id] } { + if { [empty_string_p $one_id] } { + error "You must supply either action_id or one_id" + } + set action_id $one_id + } else { + if { ![empty_string_p $one_id] } { + error "You can only supply either action_id or one_id" + } + } + get -action_id $action_id -array row + return $row($element) +} Index: openacs-4/packages/simulation/tcl/role-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/Attic/role-procs.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/packages/simulation/tcl/role-procs.tcl 17 Dec 2003 09:34:22 -0000 1.9 +++ openacs-4/packages/simulation/tcl/role-procs.tcl 17 Dec 2003 14:03:49 -0000 1.10 @@ -152,14 +152,20 @@ } ad_proc -public simulation::role::get { + {-local_only:boolean} {-role_id:required} {-array:required} } { Get information about a simulation role + + @param local_only Set this to only get the attributes from the simulation extension table, + not the ones derived from workflow::role } { upvar 1 $array row - workflow::role::get -role_id $role_id -array row + if { !$local_only_p } { + workflow::role::get -role_id $role_id -array row + } db_1row select_sim_role { select role_id, @@ -171,3 +177,84 @@ array set row [array get local_row] } +ad_proc -public simulation::role::get_element { + {-role_id {}} + {-one_id {}} + {-element:required} +} { + Return a single element from the information about a role. + + @param role_id The id of the role to get an element for. + + @param one_id Same as role_id, just used for consistency across roles/actions/states. + + @return element The element you asked for + + @author Lars Pind (lars@collaboraid.biz) +} { + if { [empty_string_p $role_id] } { + if { [empty_string_p $one_id] } { + error "You must supply either role_id or one_id" + } + set role_id $one_id + } else { + if { ![empty_string_p $one_id] } { + error "You can only supply either role_id or one_id" + } + } + + get -role_id $role_id -array row + return $row($element) +} + +ad_proc -private simulation::role::get_ids { + {-workflow_id:required} +} { + Get the IDs of all the roles in the right order. + + @param workflow_id The id of the workflow to delete. + + @return A list of role IDs. + + @author Lars Pind (lars@collaboraid.biz) +} { + return [workflow::role::get_ids -workflow_id $workflow_id] +} + +ad_proc -private simulation::role::generate_spec { + {-role_id {}} + {-one_id {}} +} { + Generate the spec for an individual simulation task definition. + + @param role_id The id of the role to generate spec for. + + @param one_id Same as role_id, just used for consistency across roles/roles/states. + + @return spec The roles spec + + @author Lars Pind (lars@collaboraid.biz) +} { + if { [empty_string_p $role_id] } { + if { [empty_string_p $one_id] } { + error "You must supply either role_id or one_id" + } + set role_id $one_id + } else { + if { ![empty_string_p $one_id] } { + error "You can only supply either role_id or one_id" + } + } + + set spec [workflow::role::generate_spec -role_id $role_id] + + get -role_id $role_id -array row -local_only + + foreach name [lsort [array names row]] { + if { ![empty_string_p $row($name)] } { + lappend spec $name $row($name) + } + } + + return $spec +} Index: openacs-4/packages/simulation/tcl/template-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/template-procs.tcl,v diff -u -r1.19 -r1.20 --- openacs-4/packages/simulation/tcl/template-procs.tcl 17 Dec 2003 09:01:05 -0000 1.19 +++ openacs-4/packages/simulation/tcl/template-procs.tcl 17 Dec 2003 14:03:49 -0000 1.20 @@ -193,7 +193,7 @@ } # Map each party - foreach party_id $aux(enroll_groups) { + foreach party_id $aux($map_type) { db_dml map_party_to_template { insert into sim_party_sim_map (simulation_id, party_id, type) @@ -631,3 +631,27 @@ -replace } } + + +ad_proc -public simulation::template::generate_spec { + {-workflow_id:required} +} { + Generate a spec for a workflow in array list style. + + @param workflow_id The id of the workflow to generate a spec for. + @return The spec for the workflow. + + @author Lars Pind (lars@collaboraid.biz) + @see workflow::new +} { + set spec [workflow::generate_spec \ + -workflow_id $workflow_id \ + -handlers { + roles simulation::role + actions simulation::action + states workflow::state::fsm + }] + + return $spec +} + Index: openacs-4/packages/workflow/tcl/action-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/action-procs.tcl,v diff -u -r1.17 -r1.18 --- openacs-4/packages/workflow/tcl/action-procs.tcl 16 Dec 2003 18:18:49 -0000 1.17 +++ openacs-4/packages/workflow/tcl/action-procs.tcl 17 Dec 2003 14:02:41 -0000 1.18 @@ -512,17 +512,32 @@ } ad_proc -public workflow::action::get_element { - {-action_id:required} + {-action_id {}} + {-one_id {}} {-element:required} } { Return a single element from the information about a action. @param action_id The ID of the action - @param element The element you want - @return The element you asked for + @param one_id Same as action_id, just used for consistency across roles/actions/states. + + @param element The element you want + + @return The element you asked for + @author Lars Pind (lars@collaboraid.biz) } { + if { [empty_string_p $action_id] } { + if { [empty_string_p $one_id] } { + error "You must supply either action_id or one_id" + } + set action_id $one_id + } else { + if { ![empty_string_p $one_id] } { + error "You can only supply either action_id or one_id" + } + } get -action_id $action_id -array row return $row($element) } @@ -659,9 +674,24 @@ return $short_name } +ad_proc -public workflow::action::get_ids { + {-workflow_id:required} +} { + Get the action_id's of all the actions in the workflow. + + @param workflow_id The ID of the workflow + @return list of action_id's. + @author Lars Pind (lars@collaboraid.biz) +} { + # Use cached data about actions + array set action_data [workflow::action::get_all_info -workflow_id $workflow_id] + return $action_data(action_ids) +} + + ###################################################################### # # workflow::action::fsm @@ -997,19 +1027,41 @@ } ad_proc -public workflow::action::fsm::get_element { - {-action_id:required} + {-action_id {}} + {-one_id {}} {-element:required} } { Return element from information about an action with a given id, including FSM-related info such as 'enabled_in_states', and 'new_state'. + Return a single element from the information about a action. + + @param action_id The ID of the action + + @param one_id Same as action_id, just used for consistency across roles/actions/states. + + @param element The element you want + + @return The element you asked for + @author Peter Marklund @author Lars Pind (lars@collaboraid.biz) } { + if { [empty_string_p $action_id] } { + if { [empty_string_p $one_id] } { + error "You must supply either action_id or one_id" + } + set action_id $one_id + } else { + if { ![empty_string_p $one_id] } { + error "You can only supply either action_id or one_id" + } + } workflow::action::fsm::get -action_id $action_id -array row return $row($element) } + ##### @@ -1089,15 +1141,30 @@ } ad_proc -private workflow::action::fsm::generate_spec { - {-action_id:required} + {-action_id {}} + {-one_id {}} } { Generate the spec for an individual action definition. @param action_id The id of the action to generate spec for. - @return spec The actions spec + @param one_id Same as action_id, just used for consistency across roles/actions/states. + + @return spec The actions spec + @author Lars Pind (lars@collaboraid.biz) } { + if { [empty_string_p $action_id] } { + if { [empty_string_p $one_id] } { + error "You must supply either action_id or one_id" + } + set action_id $one_id + } else { + if { ![empty_string_p $one_id] } { + error "You can only supply either action_id or one_id" + } + } + get -action_id $action_id -array row # Get rid of elements that shouldn't go into the spec @@ -1117,22 +1184,11 @@ # Get rid of a few defaults array set defaults { initial_action_p f always_enabled_p f } - foreach name [array names defaults] { - if { [string equal $row($name) $defaults($name)] } { - array unset row $name - } - } - - # Get rid of empty strings - foreach name [array names row] { - if { [empty_string_p $row($name)] } { - array unset row $name - } - } - set spec {} foreach name [lsort [array names row]] { - lappend spec $name $row($name) + if { ![empty_string_p $row($name)] && ![exists_and_equal defaults($name) $row($name)] } { + lappend spec $name $row($name) + } } return $spec @@ -1210,28 +1266,6 @@ } } -ad_proc -private workflow::action::fsm::generate_actions_spec { - {-workflow_id:required} -} { - Generate the spec for the block containing the definition of all - actions for the workflow. - - @param workflow_id The id of the workflow to delete. - @return The actions spec - - @author Lars Pind (lars@collaboraid.biz) -} { - # actions(short_name) { ... action-spec ... } - array set actions [list] - - foreach action_id [workflow::get_actions -workflow_id $workflow_id] { - lappend actions_list [get_element -action_id $action_id -element short_name] [generate_spec -action_id $action_id] - } - - return $actions_list - -} - ad_proc -private workflow::action::get_all_info { {-workflow_id:required} } { @@ -1364,3 +1398,18 @@ return [array get action_data] } + +ad_proc -public workflow::action::fsm::get_ids { + {-workflow_id:required} +} { + Get the action_id's of all the actions in the workflow. + + @param workflow_id The ID of the workflow + + @return list of action_id's. + + @author Lars Pind (lars@collaboraid.biz) +} { + return [workflow::action::get_ids -workflow_id $workflow_id] +} + Index: openacs-4/packages/workflow/tcl/role-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/role-procs.tcl,v diff -u -r1.14 -r1.15 --- openacs-4/packages/workflow/tcl/role-procs.tcl 16 Dec 2003 18:18:49 -0000 1.14 +++ openacs-4/packages/workflow/tcl/role-procs.tcl 17 Dec 2003 14:02:41 -0000 1.15 @@ -365,16 +365,30 @@ } ad_proc -public workflow::role::get_element { - {-role_id:required} + {-role_id {}} + {-one_id {}} {-element:required} } { Return a single element from the information about a role. - @param role_id The ID of the workflow + @param role_id The id of the role to get an element for. + + @param one_id Same as role_id, just used for consistency across roles/actions/states. + @return element The element you asked for @author Lars Pind (lars@collaboraid.biz) } { + if { [empty_string_p $role_id] } { + if { [empty_string_p $one_id] } { + error "You must supply either role_id or one_id" + } + set role_id $one_id + } else { + if { ![empty_string_p $one_id] } { + error "You can only supply either role_id or one_id" + } + } get -role_id $role_id -array row return $row($element) } @@ -450,15 +464,30 @@ } ad_proc -private workflow::role::generate_spec { - {-role_id:required} + {-role_id {}} + {-one_id {}} } { Generate the spec for an individual role definition. - @param role_id The id of the role to generate spec for. - @return spec The roles spec + @param role_id The id of the role to generate spec for. + @param one_id Same as role_id, just used for consistency across roles/actions/states. + + @return spec The roles spec + @author Lars Pind (lars@collaboraid.biz) } { + if { [empty_string_p $role_id] } { + if { [empty_string_p $one_id] } { + error "You must supply either role_id or one_id" + } + set role_id $one_id + } else { + if { ![empty_string_p $one_id] } { + error "You can only supply either role_id or one_id" + } + } + get -role_id $role_id -array row # Get rid of elements that shouldn't go into the spec @@ -471,40 +500,30 @@ array unset row callback_ids array unset row callback_impl_names - # Get rid of empty strings - foreach name [array names row] { - if { [empty_string_p $row($name)] } { - array unset row $name - } - } - set spec {} foreach name [lsort [array names row]] { - lappend spec $name $row($name) + if { ![empty_string_p $row($name)] } { + lappend spec $name $row($name) + } } return $spec } -ad_proc -private workflow::role::generate_roles_spec { +ad_proc -private workflow::role::get_ids { {-workflow_id:required} } { - Generate the spec for the block containing the definition of all - roles for the workflow. + Get the IDs of all the roles in the right order. - @param workflow_id The id of the workflow to delete. - @return The roles spec + @param workflow_id The id of the workflow to get roles for. + @return A list of role IDs. + @author Lars Pind (lars@collaboraid.biz) } { - # roles(short_name) { ... role-spec ... } - array set roles [list] - - foreach role_id [workflow::get_roles -workflow_id $workflow_id] { - lappend roles_list [get_element -role_id $role_id -element short_name] [generate_spec -role_id $role_id] - } - - return $roles_list + # Use cached data about roles + array set role_data [workflow::role::get_all_info -workflow_id $workflow_id] + return $role_data(role_ids) } ad_proc -public workflow::role::callback_insert { Index: openacs-4/packages/workflow/tcl/state-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/state-procs.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/packages/workflow/tcl/state-procs.tcl 16 Dec 2003 18:18:49 -0000 1.9 +++ openacs-4/packages/workflow/tcl/state-procs.tcl 17 Dec 2003 14:02:41 -0000 1.10 @@ -351,16 +351,30 @@ } ad_proc -public workflow::state::fsm::get_element { - {-state_id:required} + {-state_id {}} + {-one_id {}} {-element:required} } { Return a single element from the information about a state. @param state_id The ID of the workflow + @param one_id Same as state_id, just used for consistency across roles/actions/states. + @return The element you asked for @author Lars Pind (lars@collaboraid.biz) } { + if { [empty_string_p $state_id] } { + if { [empty_string_p $one_id] } { + error "You must supply either state_id or one_id" + } + set state_id $one_id + } else { + if { ![empty_string_p $one_id] } { + error "You can only supply either state_id or one_id" + } + } + get -state_id $state_id -array row return $row($element) } @@ -396,6 +410,22 @@ # Private procs ##### +ad_proc -private workflow::state::fsm::get_ids { + {-workflow_id:required} +} { + Get the state_id's of all the states in the workflow. + + @param workflow_id The ID of the workflow + @return list of state_id's. + + @author Lars Pind (lars@collaboraid.biz) +} { + # Use cached data + array set state_data [workflow::state::fsm::get_all_info -workflow_id $workflow_id] + + return $state_data(state_ids) +} + ad_proc -private workflow::state::fsm::get_workflow_id_not_cached { {-state_id:required} } { @@ -460,15 +490,30 @@ } ad_proc -private workflow::state::fsm::generate_spec { - {-state_id:required} + {-state_id {}} + {-one_id {}} } { Generate the spec for an individual state definition. @param state_id The id of the state to generate spec for. + + @param one_id Same as state_id, just used for consistency across roles/actions/states. + @return spec The states spec @author Lars Pind (lars@collaboraid.biz) } { + if { [empty_string_p $state_id] } { + if { [empty_string_p $one_id] } { + error "You must supply either state_id or one_id" + } + set state_id $one_id + } else { + if { ![empty_string_p $one_id] } { + error "You can only supply either state_id or one_id" + } + } + get -state_id $state_id -array row # Get rid of elements that shouldn't go into the spec @@ -477,16 +522,11 @@ array unset row workflow_id array unset row sort_order - # Get rid of empty strings - foreach name [array names row] { - if { [empty_string_p $row($name)] } { - array unset row $name - } - } - set spec {} foreach name [lsort [array names row]] { - lappend spec $name $row($name) + if { ![empty_string_p $row($name)] } { + lappend spec $name $row($name) + } } return $spec Index: openacs-4/packages/workflow/tcl/workflow-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/workflow-procs.tcl,v diff -u -r1.15 -r1.16 --- openacs-4/packages/workflow/tcl/workflow-procs.tcl 16 Dec 2003 18:18:49 -0000 1.15 +++ openacs-4/packages/workflow/tcl/workflow-procs.tcl 17 Dec 2003 14:02:41 -0000 1.16 @@ -423,10 +423,7 @@ @author Lars Pind (lars@collaboraid.biz) } { - # Use cached data about roles - array set role_data [workflow::role::get_all_info -workflow_id $workflow_id] - - return $role_data(role_ids) + return [workflow::role::get_ids -workflow_id $workflow_id] } ad_proc -public workflow::get_actions { @@ -439,10 +436,7 @@ @author Lars Pind (lars@collaboraid.biz) } { - # Use cached data about actions - array set action_data [workflow::action::get_all_info -workflow_id $workflow_id] - - return $action_data(action_ids) + return [workflow::action::get_ids -workflow_id $workflow_id] } ad_proc -public workflow::definition_changed_handler { @@ -529,6 +523,67 @@ return $short_name } +ad_proc -public workflow::generate_spec { + {-workflow_id:required} + {-handlers { + roles workflow::role + actions workflow::action + }} +} { + Generate a spec for a workflow in array list style. + Note that calling this directly with the default arguments will bomb, because workflow::action doesn't implement the required API. + + @param workflow_id The id of the workflow to generate a spec for. + + @param handlers An array-list with Tcl namespaces where handlers for various elements are defined. + The keys are identical to the keys in the spec, and the namespaces are where + the procs to handle them are defined. + + @return The spec for the workflow. + + @author Lars Pind (lars@collaboraid.biz) + @see workflow::new +} { + workflow::get -workflow_id $workflow_id -array row + + set short_name $row(short_name) + + array unset row object_id + array unset row workflow_id + array unset row short_name + array unset row callbacks_array + array unset row callback_ids + array unset row callback_impl_names + array unset row initial_action + array unset row initial_action_id + + set spec [list] + + # Output sorted, and with no empty elements + foreach name [lsort [array names row]] { + if { ![empty_string_p $row($name)] } { + lappend spec $name $row($name) + } + } + + foreach { key namespace } $handlers { + set subspec [list] + + foreach sub_id [${namespace}::get_ids -workflow_id $workflow_id] { + set sub_short_name [${namespace}::get_element \ + -one_id $sub_id \ + -element short_name] + lappend subspec $sub_short_name [${namespace}::generate_spec -one_id $sub_id] + } + + lappend spec $key $subspec + } + + return [list $short_name $spec] +} + + + #---------------------------------------------------------------------- # Private procs #---------------------------------------------------------------------- @@ -821,43 +876,21 @@ } { Generate a spec for a workflow in array list style. - @param workflow_id The id of the workflow to delete. + @param workflow_id The id of the workflow to generate a spec for. @return The spec for the workflow. @author Lars Pind (lars@collaboraid.biz) @see workflow::new } { - workflow::get -workflow_id $workflow_id -array row + set spec [workflow::generate_spec \ + -workflow_id $workflow_id \ + -handlers { + roles workflow::role + actions workflow::action::fsm + states workflow::state::fsm + }] - set short_name $row(short_name) - - array unset row object_id - array unset row workflow_id - array unset row short_name - array unset row callbacks_array - array unset row callback_ids - array unset row callback_impl_names - array unset row initial_action - array unset row initial_action_id - - set spec [list] - - # Get rid of empty strings - foreach name [array names row] { - if { [empty_string_p $row($name)] } { - array unset row $name - } - } - - foreach name [lsort [array names row]] { - lappend spec $name $row($name) - } - - lappend spec roles [workflow::role::generate_roles_spec -workflow_id $workflow_id] - lappend spec states [workflow::state::fsm::generate_states_spec -workflow_id $workflow_id] - lappend spec actions [workflow::action::fsm::generate_actions_spec -workflow_id $workflow_id] - - return [list $short_name $spec] + return $spec } ad_proc -public workflow::fsm::get_states { @@ -870,10 +903,7 @@ @author Lars Pind (lars@collaboraid.biz) } { - # Use cached data - array set state_data [workflow::state::fsm::get_all_info -workflow_id $workflow_id] - - return $state_data(state_ids) + return [workflow::state::fsm::get_ids -workflow_id $workflow_id] } ad_proc -public workflow::fsm::get_initial_state {