workflow::role::edit (public)workflow::role::edit [ -operation operation ] [ -role_id role_id ] \
[ -workflow_id workflow_id ] [ -array array ] [ -internal ] \
[ -no_complain ] [ -handlers handlers ]
Defined in packages/workflow/tcl/role-procs.tclEdit a workflow role.
Attributes of the array are:
short_name
pretty_name
sort_order
callbacks.
- Switches:
- -operation (defaults to
"update") (optional) - insert, update, delete
- -role_id (optional)
- For update/delete: The role to update or delete.
For insert: Optionally specify a pre-generated role_id for the role.
- -workflow_id (optional)
- For update/delete: Optionally specify the workflow_id. If not specified, we will execute a query to find it.
For insert: The workflow_id of the new role.
- -array (optional)
- For insert/update: Name of an array in the caller's namespace with attributes to insert/update.
- -internal (boolean) (optional)
- Set this flag if you're calling this proc from within the corresponding proc
for a particular workflow model. Will cause this proc to not flush the cache
or call workflow::definition_changed_handler, which the caller must then do.
- -no_complain (boolean) (optional)
- Silently ignore extra attributes that we don't know how to handle.
- -handlers (optional)
- Returns:
- role_id
- Authors:
- Peter Marklund
- Lars Pind <lars@collaboraid.biz>
See Also:
- Source code:
-
workflow::role::edit__arg_parser
switch $operation {
update - delete {
if { [empty_string_p $role_id] } {
error "You must specify the role_id of the role to $operation."
}
}
insert {}
default {
error "Illegal operation '$operation'"
}
}
switch $operation {
insert - update {
upvar 1 $array row
if { ![array exists row] } {
error "Array $array does not exist or is not an array"
}
foreach name [array names row] {
set missing_elm($name) 1
}
}
}
switch $operation {
insert {
if { [empty_string_p $workflow_id] } {
error "You must supply workflow_id"
}
# Default sort_order
if { ![exists_and_not_null row(sort_order)] } {
set row(sort_order) [workflow::default_sort_order -workflow_id $workflow_id -table_name "workflow_roles"]
}
# Default short_name on insert
if { ![info exists row(short_name)] } {
set row(short_name) {}
}
}
update {
if { [empty_string_p $workflow_id] } {
set workflow_id [workflow::role::get_element -role_id $role_id -element workflow_id]
}
}
}
# Parse column values
switch $operation {
insert - update {
set update_clauses [list]
set insert_names [list]
set insert_values [list]
# Handle columns in the workflow_roles table
foreach attr {
short_name pretty_name sort_order
} {
if { [info exists row($attr)] } {
set varname attr_$attr
# Convert the Tcl value to something we can use in the query
switch $attr {
short_name {
if { ![exists_and_not_null row(pretty_name)] } {
if { [empty_string_p $row(short_name)] } {
error "You cannot $operation with an empty short_name without also setting pretty_name"
} else {
set row(pretty_name) {}
}
}
set $varname [workflow::role::generate_short_name -workflow_id $workflow_id -pretty_name $row(pretty_name) -short_name $row(short_name) -role_id $role_id]
}
default {
set $varname $row($attr)
}
}
# Add the column to the insert/update statement
switch $attr {
default {
lappend update_clauses "$attr = :$varname"
lappend insert_names $attr
lappend insert_values :$varname
}
}
if { [info exists missing_elm($attr)] } {
unset missing_elm($attr)
}
}
}
}
}
db_transaction {
# Sort_order
switch $operation {
insert - update {
if { [info exists row(sort_order)] } {
workflow::role::update_sort_order -workflow_id $workflow_id -sort_order $row(sort_order)
}
}
}
# Do the insert/update/delete
switch $operation {
insert {
if { [empty_string_p $role_id] } {
set role_id [db_nextval "workflow_roles_seq"]
}
lappend insert_names role_id
lappend insert_values :role_id
lappend insert_names workflow_id
lappend insert_values :workflow_id
db_dml insert_role "
insert into workflow_roles
([join $insert_names ", "])
values
([join $insert_values ", "])
"
}
update {
if { [llength $update_clauses] > 0 } {
db_dml update_role "
update workflow_roles
set [join $update_clauses ", "]
where role_id = :role_id
"
}
}
delete {
db_dml delete_role {
delete from workflow_roles
where role_id = :role_id
}
}
}
switch $operation {
insert - update {
# Callbacks
if { [info exists row(callbacks)] } {
db_dml delete_callbacks {
delete from workflow_role_callbacks
where role_id = :role_id
}
foreach callback_name $row(callbacks) {
workflow::role::callback_insert -role_id $role_id -name $callback_name
}
unset missing_elm(callbacks)
}
# Check that there are no unknown attributes
if { [llength [array names missing_elm]] > 0 && !$no_complain } {
error "Trying to set illegal role attributes: [join [array names missing_elm] ", "]"
}
}
}
if { !$internal_p } {
workflow::definition_changed_handler -workflow_id $workflow_id
}
}
return $role_id
- Generic XQL file:
<?xml version="1.0"?>
<queryset>
<fullquery name="workflow::role::insert.do_insert">
<querytext>
insert into workflow_roles
(role_id, workflow_id, short_name, pretty_name, sort_order)
values
(:role_id, :workflow_id, :short_name, :pretty_name, :sort_order)
</querytext>
</fullquery>
<fullquery name="workflow::role::get_workflow_id_not_cached.select_workflow_id">
<querytext>
select workflow_id
from workflow_roles
where role_id = :role_id
</querytext>
</fullquery>
<fullquery name="workflow::role::get_all_info_not_cached.role_info">
<querytext>
select role_id,
workflow_id,
short_name,
pretty_name,
sort_order
from workflow_roles
where workflow_id = :workflow_id
order by sort_order
</querytext>
</fullquery>
<fullquery name="workflow::role::get_all_info_not_cached.role_callbacks">
<querytext>
select c.role_id,
impl.impl_id,
impl.impl_owner_name,
impl.impl_name,
ctr.contract_name,
c.sort_order
from workflow_roles r,
workflow_role_callbacks c,
acs_sc_impls impl,
acs_sc_bindings bind,
acs_sc_contracts ctr
where r.workflow_id = :workflow_id
and c.role_id = r.role_id
and impl.impl_id = c.acs_sc_impl_id
and bind.impl_id = impl.impl_id
and ctr.contract_id = bind.contract_id
order by r.role_id, c.sort_order
</querytext>
</fullquery>
<fullquery name="workflow::role::callback_insert.insert_callback">
<querytext>
insert into workflow_role_callbacks (role_id, acs_sc_impl_id, sort_order)
values (:role_id, :acs_sc_impl_id, :sort_order)
</querytext>
</fullquery>
<fullquery name="workflow::role::update_sort_order.select_sort_order_p">
<querytext>
select count(*)
from workflow_roles
where workflow_id = :workflow_id
and sort_order = :sort_order
</querytext>
</fullquery>
<fullquery name="workflow::role::update_sort_order.update_sort_order">
<querytext>
update workflow_roles
set sort_order = sort_order + 1
where workflow_id = :workflow_id
and sort_order >= :sort_order
</querytext>
</fullquery>
</queryset>
- Postgresql XQL file:
<?xml version="1.0"?>
<queryset>
<rdbms><type>postgresql</type><version>7.2</version></rdbms>
<fullquery name="workflow::role::callback_insert.select_sort_order">
<querytext>
select coalesce(max(sort_order),0) + 1
from workflow_role_callbacks
where role_id = :role_id
</querytext>
</fullquery>
</queryset>
- Oracle XQL file:
<?xml version="1.0"?>
<queryset>
<rdbms><type>oracle</type><version>8.1.6</version></rdbms>
<fullquery name="workflow::role::callback_insert.select_sort_order">
<querytext>
select nvl(max(sort_order),0) + 1
from workflow_role_callbacks
where role_id = :role_id
</querytext>
</fullquery>
</queryset>
|