Index: openacs-4/packages/workflow/workflow.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/workflow.info,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/workflow/workflow.info 10 Jan 2003 13:37:46 -0000 1.1 @@ -0,0 +1,46 @@ + + + + + Workflow Service + Workflow Services + f + t + + + + oracle + postgresql + + Peter Marklund + Lars Pind + A Tcl API for creating workflows that support the Bug Tracker, CMS publication, and simple approval. + 2003-01-10 + Collaboraid + Currently this package uses a Finite State Machine (FSM) implementation of workflows but it is designed to allow for addition of other workflow implementations (i.e. Petri Nets or dependency graphs). For more information, see: <a href="http://www.collaboraid.biz/developer/workflow-spec">the workflow specification</a>. + + + + + + + + + + + + + + + + + + + + + + + + + + Index: openacs-4/packages/workflow/sql/postgresql/workflow-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/sql/postgresql/workflow-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/workflow/sql/postgresql/workflow-create.sql 10 Jan 2003 13:38:15 -0000 1.1 @@ -0,0 +1,12 @@ +-- Data model for the workflow package, part of the OpenACS system. +-- +-- @author Lars Pind (lars@collaboraid.biz) +-- @author Peter Marklund (peter@collaboraid.biz) +-- @creation-date 8 Januar 2003 +-- +-- This is free software distributed under the terms of the GNU Public +-- License. Full text of the license is available from the GNU Project: +-- http://www.fsf.org/copyleft/gpl.html + +\i workflow-tables-create.sql +\i workflow-procedural-create.sql Index: openacs-4/packages/workflow/sql/postgresql/workflow-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/sql/postgresql/workflow-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/workflow/sql/postgresql/workflow-drop.sql 10 Jan 2003 13:38:15 -0000 1.1 @@ -0,0 +1,12 @@ +-- Drop data model for the workflow package, part of the OpenACS system. +-- +-- @author Lars Pind (lars@collaboraid.biz) +-- @author Peter Marklund (peter@collaboraid.biz) +-- @creation-date 9 Januar 2003 +-- +-- This is free software distributed under the terms of the GNU Public +-- License. Full text of the license is available from the GNU Project: +-- http://www.fsf.org/copyleft/gpl.html + +\i workflow-tables-drop.sql +\i workflow-procedural-drop.sql Index: openacs-4/packages/workflow/sql/postgresql/workflow-procedural-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/sql/postgresql/workflow-procedural-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/workflow/sql/postgresql/workflow-procedural-create.sql 10 Jan 2003 13:38:15 -0000 1.1 @@ -0,0 +1,51 @@ +-- Procedural database code for the workflow package, a package in the OpenACS system. +-- +-- @author Lars Pind (lars@collaboraid.biz) +-- @author Peter Marklund (peter@collaboraid.biz) +-- +-- This is free software distributed under the terms of the GNU Public +-- License. Full text of the license is available from the GNU Project: +-- http://www.fsf.org/copyleft/gpl.html + +--------------------------------- +-- Workflow level, Generic Model +--------------------------------- + +-- Function for creating a workflow +create function workflow__new (varchar, -- short_name + varchar, -- pretty_name + integer, -- object_id + varchar, -- object_type + integer, -- creation_user + integer, -- creation_ip + integer -- context_id + ) +returns integer as ' +declare + p_short_name alias for $1; + p_pretty_name alias for $2; + p_object_id alias for $3; + p_object_type alias for $4; + p_creation_user alias for $5; + p_creation_ip alias for $6; + p_context_id alias for $7; + + v_workflow_id integer; +begin + -- Instantiate the ACS Object super type with auditing info + v_workflow_id := acs_object__new(null, + ''workflow_new'', + now(), + p_creation_user, + p_creation_ip, + p_context_id, + ''t''); + + -- Insert workflow specific info into the workflows table + insert into workflows + (workflow_id, short_name, pretty_name, object_id, object_type) + values + (v_workflow_id, p_short_name, p_pretty_name, p_object_id, p_object_type) + +end; +' language 'plpgsql'; Index: openacs-4/packages/workflow/sql/postgresql/workflow-procedural-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/sql/postgresql/workflow-procedural-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/workflow/sql/postgresql/workflow-procedural-drop.sql 10 Jan 2003 13:38:15 -0000 1.1 @@ -0,0 +1,22 @@ +-- Drop procedural database code for the workflow package, a package in the OpenACS system. +-- +-- @author Lars Pind (lars@collaboraid.biz) +-- @author Peter Marklund (peter@collaboraid.biz) +-- +-- This is free software distributed under the terms of the GNU Public +-- License. Full text of the license is available from the GNU Project: +-- http://www.fsf.org/copyleft/gpl.html + +--------------------------------- +-- Workflow level, Generic Model +--------------------------------- + +-- Drop all functions +drop function workflow__new (varchar, -- short_name + varchar, -- pretty_name + integer, -- object_id + varchar, -- object_type + integer, -- creation_user + integer, -- creation_ip + integer -- context_id + ); Index: openacs-4/packages/workflow/sql/postgresql/workflow-tables-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/sql/postgresql/workflow-tables-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/workflow/sql/postgresql/workflow-tables-create.sql 10 Jan 2003 13:38:15 -0000 1.1 @@ -0,0 +1,443 @@ +-- Data model for the workflow package, part of the OpenACS system. +-- +-- @author Lars Pind (lars@collaboraid.biz) +-- @author Peter Marklund (peter@collaboraid.biz) +-- +-- @creation-date 9 January 2003 +-- +-- This is free software distributed under the terms of the GNU Public +-- License. Full text of the license is available from the GNU Project: +-- http://www.fsf.org/copyleft/gpl.html + +--------------------------------- +-- Workflow level, Generic Model +--------------------------------- + +-- Create the workflow object type +-- We use workflow_new rather than just workflow +-- to avoid a clash with the old workflow package acs-workflow +create function inline_0 () +returns integer as ' +begin + PERFORM acs_object_type__create_type ( + ''workflow_new'', + ''New Workflow'', + ''New Workflows'', + ''acs_object'', + ''workflows'', + ''workflow_id'', + null, + ''f'', + null, + null + ); + + return 0; +end;' language 'plpgsql'; +select inline_0 (); +drop function inline_0 (); + +create table workflows ( + workflow_id integer + constraint workflows_pk + primary key + constraint workflows_workflow_id_fk + references acs_objects(object_id) + on delete cascade, + short_name varchar(100) + constraint workflows_short_name_nn + not null, + pretty_name varchar(200) + constraint workflows_pretty_name_nn + not null, + object_id integer + constraint workflows_object_id_nn + not null + constraint workflows_object_id_fk + references acs_objects(object_id) + on delete cascade, + -- object_id points to either a package type, package instance, or single workflow case + -- For Bug Tracker, every package instance will get its own workflow instance that is a copy + -- of the workflow instance for the Bug Tracker package type + object_type varchar(1000) + constraint workflows_object_type_nn + not null + constraint workflows_object_type_fk + references acs_object_types(object_type) + on delete cascade, + -- the object type (and its subtypes) this workflow is designed for. Use acs_object + -- if you don't want to restrict the types of objects this workflow can be applied to. + constraint workflows_oid_sn_un + unique (object_id, short_name) +); + +-- For callback procedures that execute when any action in the workflow is taken +create table workflow_side_effects ( + workflow_id integer + constraint workflow_side_effects_wid_nn + not null + constraint workflow_side_effects_wid_fk + references workflows(workflow_id) + on delete cascade, + acs_sc_impl_id integer + constraint workflow_side_effects_sci_nn + not null + constraint workflow_side_effects_sci_fk + references acs_sc_impls(impl_id) + on delete cascade, + sort_order integer + constraint workflow_side_effects_so_nn + not null, + constraint workflow_side_effects_pk + primary key (workflow_id, acs_sc_impl_id) +); + +create table workflow_roles ( + role_id integer + constraint workflow_roles_pk + primary key, + workflow_id integer + constraint workflow_roles_workflow_id_fk + references workflows(workflow_id) + on delete cascade, + short_name varchar(100) + constraint workflow_roles_short_name_nn + not null, + pretty_name varchar(200) + constraint workflow_roles_pretty_name_nn + not null +); + +create sequence t_wf_workflow_roles_seq; +create view wf_workflow_roles_seq as +select nextval('t_wf_workflow_roles_seq') as nextval; + +-- Static role-party map +create table workflow_role_default_parties ( + role_id integer + constraint workflow_role_default_parties_rid_nn + not null + constraint workflow_role_default_parties_rid_fk + references workflow_roles(role_id) + on delete cascade, + party_id integer + constraint workflow_role_default_parties_pid_nn + not null + constraint workflow_role_default_parties_pid_fk + references parties(party_id) + on delete cascade, + constraint workflow_role_default_parties_pk + primary key (role_id, party_id) +); + +-- Static map between roles and parties allowed to be in those roles +create table workflow_role_allowed_parties ( + role_id integer + constraint workflow_role_allowed_parties_rid_nn + not null + constraint workflow_role_allowed_parties_rid_fk + references workflow_roles(role_id) + on delete cascade, + party_id integer + constraint workflow_role_allowed_parties_pid_nn + not null + constraint workflow_role_allowed_parties_pid_fk + references parties(party_id) + on delete cascade, + constraint workflow_role_allowed_parties_pk + primary key (role_id, party_id) +); + +-- Application specific callback procedures for dynamically mapping parties to roles +create table workflow_role_assignment_rules ( + role_id integer + constraint workflow_role_assignment_rules_role_id_nn + not null + constraint workflow_role_assignment_rules_role_id_fk + references workflow_roles(role_id) + on delete cascade, + acs_sc_impl_id integer + constraint workflow_role_assignment_rules_contract_id_nn + not null + constraint workflow_role_assignment_rules_contract_id_fk + references acs_sc_impls(impl_id) + on delete cascade, + -- this can be an implementation of any of the three assignment + -- service contracts: DefaultAssignee, AssigneePickList, or + -- AssigneeSubQuery + sort_order integer + constraint workflow_role_assignment_rules_sort_order_nn + not null, + constraint workflow_role_assignment_rules_pk + primary key (role_id, acs_sc_impl_id) +); + +create table workflow_actions ( + action_id integer + constraint workflow_actions_pk + primary key, + workflow_id integer + constraint workflow_actions_workflow_id_nn + not null + constraint workflow_actions_workflow_id_fk + references workflows(workflow_id) + on delete cascade, + sort_order integer + constraint workflow_actions_sort_order_nn + not null, + short_name varchar(100) + constraint workflow_actions_short_name_nn + not null, + pretty_name varchar(200) + constraint workflow_actions_pretty_name_nn + not null, + pretty_past_tense varchar(200), + assigned_role integer + constraint workflow_actions_assigned_role_fk + references workflow_roles(role_id) + on delete set null +); + +create sequence t_wf_workflow_actions_seq; +create view wf_workflow_actions_seq as +select nextval('t_wf_workflow_actions_seq') as nextval; + +-- Determines which roles are allowed to take certain actions +create table workflow_action_allowed_roles ( + action_id integer + constraint workflow_action_allowed_roles_action_id_nn + not null + constraint workflow_action_allowed_roles_action_id_fk + references workflow_actions(action_id) + on delete cascade, + role_id integer + constraint workflow_action_allowed_roles_role_id_nn + not null + constraint workflow_action_allowed_roles_role_id_fk + references workflow_roles(role_id) + on delete cascade, + constraint workflow_action_allowed_roles_pk + primary key (action_id, role_id) +); + +-- Determines which privileges (on the object treated by a workflow case) will allow +-- users to take certain actions +create table workflow_action_privileges ( + action_id integer + constraint workflow_action_privileges_action_id_nn + not null + constraint workflow_action_privileges_action_id_fk + references workflow_actions(action_id) + on delete cascade, + privilege varchar(100) + constraint workflow_action_privileges_privilege_nn + not null + constraint workflow_action_privileges_privilege_fk + references acs_privileges(privilege) + on delete cascade, + constraint workflow_action_privileges_pk + primary key (action_id, privilege) +); + +-- For application specific callback procedures that execute when +-- certain actions are taken +create table workflow_action_side_effects ( + action_id integer + constraint workflow_action_side_effects_action_id_nn + not null + constraint workflow_action_side_effects_action_id_fk + references workflow_actions(action_id) + on delete cascade, + acs_sc_impl_id integer + constraint workflow_action_side_effects_sci_nn + not null + constraint workflow_action_side_effects_sci_fk + references acs_sc_impls(impl_id) + on delete cascade, + sort_order integer + constraint workflow_action_side_effects_sort_order_nn + not null, + constraint workflow_action_side_effects_pk + primary key (action_id, acs_sc_impl_id) +); + +--------------------------------- +-- Workflow level, Finite State Machine Model +--------------------------------- + +create table workflow_fsm_states ( + state_id integer + constraint workflow_fsm_states_pk + primary key, + workflow_id integer + constraint workflow_fsm_states_workflow_id_nn + not null + constraint workflow_fsm_states_workflow_id_fk + references workflows(workflow_id) + on delete cascade, + sort_order integer + constraint workflow_fsm_states_sort_order_nn + not null, + short_name varchar(100) + constraint workflow_fsm_states_short_name_nn + not null, + pretty_name varchar(200) + constraint workflow_fsm_states_pretty_name_nn + not null +); + +create sequence t_wf_workflow_fsm_states_seq; +create view wf_workflow_fsm_states_seq as +select nextval('t_wf_workflow_fsm_states_seq') as nextval; + +create table workflow_fsm_actions ( + action_id integer + constraint workflow_fsm_actions_pk + primary key + constraint workflow_fsm_actions_action_id_fk + references workflow_actions(action_id) + on delete cascade, + new_state integer + constraint workflow_fsm_actions_new_state_fk + references workflow_fsm_states(state_id) + on delete set null + -- can be null +); + +create table workflow_fsm_action_enabled_in_states ( + action_id integer + constraint workflow_fsm_action_enabled_in_states_action_id_nn + not null + constraint workflow_fsm_action_enabled_in_states_action_id_fk + references workflow_fsm_actions(action_id) + on delete cascade, + state_id integer + constraint workflow_fsm_action_enabled_in_states_state_id_nn + not null + constraint workflow_fsm_action_enabled_in_states_state_id_fk + references workflow_fsm_states + on delete cascade +); + +create table workflow_fsm ( + workflow_id integer + constraint workflow_fsm_pk + primary key + constraint workflow_fsm_workflow_id_fk + references workflows(workflow_id) + on delete cascade, + initial_state integer + constraint workflow_fsm_initial_state_nn + not null + constraint workflow_fsm_initial_state_fk + references workflow_fsm_states(state_id) +); + +--------------------------------- +-- Case level, Generic Model +--------------------------------- + +create table workflow_cases ( + case_id integer + constraint workflow_cases_pk + primary key + constraint workflow_cases_case_id_fk + references acs_objects(object_id) + on delete cascade, + workflow_id integer + constraint workflow_cases_workflow_id_nn + not null + constraint workflow_cases_workflow_id_fk + references workflows(workflow_id) + on delete cascade, + object_id integer + constraint workflow_cases_object_id_nn + not null + constraint workflow_cases_object_id_fk + references acs_objects(object_id) + on delete cascade + constraint workflow_cases_object_id_un + unique + -- the object which this case is about, e.g. the acs-object for a bug-tracker bug +); + +create table workflow_case_log ( + entry_id integer + constraint workflow_case_log_pk + primary key, + case_id integer + constraint workflow_case_log_case_id_fk + references workflow_cases(case_id) + on delete cascade, + action_id integer + constraint workflow_case_log_action_id_fk + references workflow_actions(action_id) + on delete cascade, + user_id integer + constraint workflow_case_log_user_id_fk + references users(user_id) + on delete cascade, + action_date timestamp + constraint workflow_case_log_action_date_nn + not null + default now(), + comment text, + comment_format varchar(30) default 'plain' not null + constraint bt_bug_actions_comment_format_ck + check (comment_format in ('html', 'plain', 'pre')) +); + +create table workflow_case_log_data ( + entry_id integer + constraint workflow_case_log_data_eid_nn + not null + constraint workflow_case_log_data_eid_fk + references workflow_case_log(entry_id) + on delete cascade, + key varchar(50), + value varchar(4000), + constraint workflow_case_log_data_pk + primary key (entry_id, key) +); + +create table workflow_case_role_party_map ( + case_id integer + constraint workflow_case_role_party_map_case_id_nn + not null + constraint workflow_case_role_party_map_case_id_fk + references workflow_cases(case_id) + on delete cascade, + role_id integer + constraint workflow_case_role_party_map_case_id_nn + not null + constraint workflow_case_role_party_map_case_id_fk + references workflow_roles(role_id) + on delete cascade, + party_id integer + constraint workflow_case_role_party_map_party_id_nn + not null + constraint workflow_case_role_party_map_party_id_fk + references parties(party_id) + on delete cascade, + constraint workflow_case_role_party_map_pk + primary key (case_id, role_id, party_id) +); + +--------------------------------- +-- Case level, Finite State Machine Model +--------------------------------- + +create table workflow_case_fsm ( + case_id integer + constraint workflow_case_fsm_case_id_nn + not null + constraint workflow_case_fsm_case_id_fk + references workflow_cases(case_id) + on delete cascade, + current_state integer + constraint workflow_case_fsm_state_id_nn + not null + constraint workflow_case_fsm_state_id_fk + references workflow_fsm_states(state_id) + on delete cascade +); Index: openacs-4/packages/workflow/sql/postgresql/workflow-tables-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/sql/postgresql/workflow-tables-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/workflow/sql/postgresql/workflow-tables-drop.sql 10 Jan 2003 13:38:15 -0000 1.1 @@ -0,0 +1,68 @@ +-- Drop table data for the workflow package, part of the OpenACS system. +-- +-- @author Lars Pind (lars@collaboraid.biz) +-- @author Peter Marklund (peter@collaboraid.biz) +-- @creation-date 9 Januar 2003 +-- +-- This is free software distributed under the terms of the GNU Public +-- License. Full text of the license is available from the GNU Project: +-- http://www.fsf.org/copyleft/gpl.html + +-- Drop all data in workflow tables by dropping the acs objects of all workflows in the system. +-- This is sufficient since all workflow data ultimately +-- hangs on workflow instances and will be dropped on cascade +create function inline_0 () +returns integer as ' +declare + row record; +begin + for row in select object_id from acs_objects + where object_type = ''workflow_new'' + loop + perform acs_object__delete(row.object_id); + end loop; + + return 1; +end;' language 'plpgsql'; +select inline_0 (); +drop function inline_0(); + +-- Drop the workflow object type +create function inline_0 () +returns integer as ' +begin + perform acs_object_type__drop_type(''workflow_new'', ''t''); + + return 1; +end;' language 'plpgsql'; +select inline_0 (); +drop function inline_0(); + +-- Drop all tables +drop table workflow_case_fsm; +drop table workflow_case_role_party_map; +drop table workflow_case_log_data; +drop table workflow_case_log; +drop table workflow_cases; +drop table workflow_fsm; +drop table workflow_fsm_action_enabled_in_states; +drop table workflow_fsm_actions; +drop table workflow_fsm_states; +drop table workflow_action_side_effects; +drop table workflow_action_privileges; +drop table workflow_action_allowed_roles; +drop table workflow_actions; +drop table workflow_role_assignment_rules; +drop table workflow_role_allowed_parties; +drop table workflow_role_default_parties; +drop table workflow_roles; +drop table workflow_side_effects; +drop table workflows; + +-- Drop all sequences and their views +drop sequence t_wf_workflow_roles_seq; +drop view wf_workflow_roles_seq; +drop sequence t_wf_workflow_actions_seq; +drop view wf_workflow_actions_seq; +drop sequence t_wf_workflow_fsm_states_seq; +drop view wf_workflow_fsm_states_seq; 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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/workflow/tcl/action-procs.tcl 10 Jan 2003 13:38:37 -0000 1.1 @@ -0,0 +1,61 @@ +ad_library { + Procedures in the workflow::action namespace. + + @creation-date 9 January 2003 + @author Lars Pind (lars@collaboraid.biz) + @author Peter Marklund (peter@collaboraid.biz) + @cvs-id $Id: action-procs.tcl,v 1.1 2003/01/10 13:38:37 peterm Exp $ +} + +namespace eval ::workflow::action {} + +ad_proc -public ::workflow::action::add { + {-workflow_id:required} + {-short_name:required} + {-pretty_name:required} + {-pretty_past_tense {}} + {-assigned_role {}} + {-allowed_roles {}} + {-privileges {}} +} { + This procedure should never be invoked from application code. Instead use + a procedure for a certain workflow implementation, such as for example + workflow::fsm::action::add for Finite State Machine workflows. + + @param workflow_id The id of the FSM workflow to add the action to + @param short_name Short name of the action for use in source code. + Should be on Tcl variable syntax. + @param pretty_name Human readable name of the action for use in UI. + @param pretty_past_tense Past tense of pretty name + @param assigned_role Users in this role are expected (obliged) to take + the action. + @param allowed_roles Users in these roles are allowed to take the action. + @param privileges Users with these privileges on the object + treated by the workflow (i.e. a bug in the + Bug Tracker) will be allowed to take this + action. + + @return The id of the created action + + @see workflow::fsm::action::add + + @author Peter Marklund +} { + db_transaction { + # Insert basic action info + set action_id [db_nextval "wf_workflow_fsm_actions_seq"] + db_dml insert_action {} + + # Record which roles are allowed to take action + foreach allowed_role $allowed_roles { + db_dml insert_allowed_role {} + } + + # Record which privileges enable the action + foreach privilege $privileges { + db_dml insert_privilege {} + } + } + + return $action_id +} Index: openacs-4/packages/workflow/tcl/action-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/action-procs.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/workflow/tcl/action-procs.xql 10 Jan 2003 13:38:37 -0000 1.1 @@ -0,0 +1,30 @@ + + + + + + insert into workflow_actions + (action_id, workflow_id, sort_order, short_name, + pretty_name, pretty_past_tense, assigned_role) + values (:action_id, :workflow_id, :sort_order, :short_name, + :pretty_name, :pretty_past_tense, :assigned_role) + + + + + + insert into workflow_action_allowed_roles + (action_id, role_id) + values (:action_id, :allowed_role) + + + + + + insert into workflow_action_privileges + (action_id, privilege) + values (:action_id, :privilege) + + + + Index: openacs-4/packages/workflow/tcl/fsm-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/Attic/fsm-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/workflow/tcl/fsm-procs.tcl 10 Jan 2003 13:38:37 -0000 1.1 @@ -0,0 +1,110 @@ +ad_library { + Procedures in the workflow::fsm namespace and + in its child namespaces. + + @creation-date 8 January 2003 + @author Lars Pind (lars@collaboraid.biz) + @author Peter Marklund (peter@collaboraid.biz) + @cvs-id $Id: fsm-procs.tcl,v 1.1 2003/01/10 13:38:37 peterm Exp $ +} + +namespace eval ::workflow::fsm {} + +ad_proc -public ::workflow::fsm::set_initial_state { + {-workflow_id:required} + {-initial_state:required} +} { + Set the initial state of an FSM (Finite State Machine) workflow. + + @param workflow_id The id of the workflow to set initial state for. + @param initial_state The id of the initial state of the workflow + + @author Peter Marklund +} { + db_dml do_insert {} +} + + +namespace eval ::workflow::fsm::state {} + +ad_proc -public ::workflow::fsm::state::add { + {-workflow_id:required} + {-short_name:required} + {-pretty_name:required} + {-sort_order ""} +} { + Creates a new state for a certain FSM (Finite State Machine) workflow. + + @param workflow_id The id of the FSM workflow to add the state to + @param short_name + @param pretty_name + + @author Peter Marklund +} { + set state_id [db_nextval "wf_workflow_fsm_states_seq"] + + db_dml do_insert {} +} + +ad_proc -public ::workflow::fsm::state::id_from_short_name { + short_name +} { + Return the id of the state with given short name + + @param short_name The name of the state to return the id for. + + @author Peter Marklund +} { + return [db_string id_from_name {}] +} + +namespace eval ::workflow::fsm::action {} + +ad_proc -public ::workflow::fsm::action::add { + {-workflow_id:required} + {-short_name:required} + {-pretty_name:required} + {-pretty_past_tense {}} + {-allowed_roles {}} + {-assigned_role {}} + {-privileges {}} + {-enabled_states {}} + {-new_state {}} +} { + Add an action to a certain FSM (Finite State Machine) workflow. This procedure + invokes the generic workflow::action::add procedures and does additional inserts + for FSM specific information. See the parameter + documentation for the proc workflow::action::add. + + @param enabled_states The short names of states in which the + action is enabled. + @param new_state The state that a workflow case moves to + when the action is taken. Optional. + + @see workflow::action::add + + @author Peter Marklund +} { + + db_transaction { + # Generic workflow data: + set action_id [workflow::action::add -workflow_id $workflow_id + -short_name $short_name + -pretty_name $pretty_name + -pretty_past_tense $pretty_past_tense + -allowed_roles $allowed_roles + -assigned_role $assigned_role + -privileges $privileges] + + # FSM specific data: + + # Record whether the action changes state + db_dml insert_fsm_action {} + + # Record in which states the action is enabled + foreach state_short_name $enabled_states { + set enabled_state_id [workflow::fsm::state::id_from_short_name $state_short_name] + db_dml insert_enabled_state {} + } + } +} Index: openacs-4/packages/workflow/tcl/fsm-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/Attic/fsm-procs.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/workflow/tcl/fsm-procs.xql 10 Jan 2003 13:38:37 -0000 1.1 @@ -0,0 +1,45 @@ + + + + + + insert into workflow_fsm + (workflow_id, initial_state) + values (:workflow_id, :initial_state) + + + + + + insert into workflow_fsm_states + (state_id, workflow_id, sort_order, short_name, pretty_name) + values (:state_id, :workflow_id, :sort_order, :short_name, :pretty_name) + + + + + + select state_id + from workflow workflow_fsm_states + where short_name = :short_name + + + + + + insert info workflow_fsm_actions + (action_id, new_state) + values + (:action_id, :new_state) + + + + + + insert into workflow_fsm_action_enabled_in_states + (action_id, state_id) + values (:action_id, :enabled_state_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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/workflow/tcl/role-procs.tcl 10 Jan 2003 13:38:37 -0000 1.1 @@ -0,0 +1,29 @@ +ad_library { + Procedures in the workflow::role namespace. + + @creation-date 8 January 2003 + @author Lars Pind (lars@collaboraid.biz) + @author Peter Marklund (peter@collaboraid.biz) + @cvs-id $Id: role-procs.tcl,v 1.1 2003/01/10 13:38:37 peterm Exp $ +} + +namespace eval workflow::role { + + ad_proc -public add { + {-workflow_id:required} + {-short_name:required} + {-pretty_name:required} + } { + Creates a new role for a certain workflow. + + @param workflow_id + @param short_name + @param pretty_name + + @author Peter Marklund + } { + set role_id [db_nextval "wf_workflow_roles_seq"] + + db_dml do_insert {} + } +} Index: openacs-4/packages/workflow/tcl/role-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/role-procs.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/workflow/tcl/role-procs.xql 10 Jan 2003 13:38:37 -0000 1.1 @@ -0,0 +1,13 @@ + + + + + + insert into workflow_roles + (role_id, workflow_id, short_name, pretty_name) + values + (:role_id, :workflow_id, :short_name, :pretty_name) + + + + Index: openacs-4/packages/workflow/tcl/workflow-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/workflow-procs-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/workflow/tcl/workflow-procs-postgresql.xql 10 Jan 2003 13:38:37 -0000 1.1 @@ -0,0 +1,19 @@ + + + postgresql7.2 + + + + select workflow__new (:short_name, + :pretty_name, + :object_id, + :object_type, + :creation_user, + :creation_ip, + :context_id + ); + + + + + 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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/workflow/tcl/workflow-procs.tcl 10 Jan 2003 13:38:37 -0000 1.1 @@ -0,0 +1,46 @@ +ad_library { + Procedures in the workflow namespace. + + @creation-date 8 January 2003 + @author Lars Pind (lars@collaboraid.biz) + @author Peter Marklund (peter@collaboraid.biz) + @cvs-id $Id: workflow-procs.tcl,v 1.1 2003/01/10 13:38:37 peterm Exp $ +} + +namespace eval ::workflow {} + +ad_proc -public ::workflow::add { + {-short_name:required} + {-pretty_name:required} + {-object_id:required} + {-object_type "acs_object"} +} { + Creates a new workflow. + + @param short_name For referring to the workflow from Tcl code. Use Tcl variable syntax. + @param pretty_name A human readable name for the workflow for use in the UI. + @param object_id The id of an ACS Object indicating the scope the workflow. + Typically this will be the id of a package type or a package instance + but it could also be some other type of ACS object within a package, for example + the id of a bug in the Bug Tracker application. + @param object_type The type of objects that the workflow will be applied to. Valid values are in the + acs_object_types table. The parameter is optional and defaults to acs_object. + + @author Peter Marklund +} { + # Auditing information for the acs_objects table + if { [ad_conn isconnected] } { + set creation_user [ad_conn user_id] + set creation_ip [ad_conn peeraddr] + } else { + # No HTTP request so we have don't have IP and user info + set creation_user "" + set creation_ip "" + } + + # It makes sense that the workflow inherits permissions from the object (typically package type or package instance) + # that sets the scope of the workflow + set context_id $object_id + + db_dml do_insert {} +}