Index: openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/load-workflow.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/load-workflow.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/load-workflow.sql 12 Apr 2001 00:12:06 -0000 1.1 @@ -0,0 +1,210 @@ + +create function my_random() +returns integer ' +begin + return random(); +end;' language 'plpgsql'; + + + +-- show errors + +create function push_task_ahead(integer,varchar,integer,varchar,varchar) +returns integer as ' +declare + push_task_ahead__task_id alias for $1; + push_task_ahead__state alias for $2; + push_task_ahead__user_id alias for $3; + push_task_ahead__workflow_key alias for $4; + push_task_ahead__transition_key alias for $5; + v_journal_id integer; + v_value char(1); + attr_rec record; +begin + if state = ''enabled'' then + v_journal_id := workflow_case__task_action ( + push_task_ahead__task_id, + ''start'', + ''1.1.1.1'', + push_task_ahead__user_id, + null + ); + else + /* State must be started */ + if my_random() < 0.02 then + v_journal_id := workflow_case__task_action ( + push_task_ahead__task_id, + ''cancel'', + ''1.1.1.1'', + push_task_ahead__user_id, + null + ); + else + v_journal_id := workflow_case__begin_task_action ( + push_task_ahead__task_id, + ''finish'', + ''1.1.1.1'', + push_task_ahead__user_id, + null + ); + + for attr_rec in select a.attribute_name, datatype + from wf_transition_attribute_map m, acs_attributes a + where workflow_key = push_task_ahead.workflow_key + and transition_key = push_task_ahead.transition_key + and a.attribute_id = m.attribute_id + loop + /* We only know how to handle boolean attributes ... + but that''s the only thing we have right now, so ... */ + + if attr_rec.datatype = ''boolean'' then + if my_random() < 0.5 then + v_value := ''t''; + else + v_value := ''f''; + end if; + + select workflow_case__set_attribute_value ( + v_journal_id, + attr_rec.attribute_name, + v_value + ); + end if; + end loop; + + select workflow_case__end_task_action ( + v_journal_id, + ''finish'', + push_task_ahead__task_id + ); + end if; + end if; + + return 0; +end;' language 'plpgsql'; + +select inline_1 (); + +drop function inline_1 (); + + +-- show errors + + +create function inline_2 () +returns integer as ' +declare + v_object_id integer; + v_workflow_key varchar(100); + v_count integer; + v_num_cases integer; + v_party_id integer; + v_case_id integer; + v_task_id integer; + v_user_id integer; + v_num_tasks integer; + v_state varchar(100); + v_transition_key varchar(100); + trans_rec record; + party_rec record; + case_rec record; +begin + v_num_cases := 100; + + --select dbms_random__initialize (943820482); + -- ); + + for trans_rec in select transition_key + from wf_transitions + where workflow_key = v_workflow_key + LOOP + for party_rec in select party_id + from parties sample(50) + LOOP + select workflow_case__add_manual_assignment ( + v_case_id, + trans_rec.transition_key, + party_rec.party_id + ); + end loop; + end loop; + + select workflow_case__start_case ( + v_case_id, + null, + null, + null + ); + + end loop; + + /* Move 85% of the cases all the way to finished */ + + for case_rec in select case_id from wf_cases sample (85) + loop + loop + select case when count(*) = 0 then 0 else 1 end into v_num_tasks + from wf_user_tasks; + + exit when v_num_tasks = 0; + + if my_random() < 0.005 then + select workflow_case__cancel ( + case_rec.case_id, + null, + null, + null + ); + end if; + + select task_id, state, user_id, workflow_key, transition_key + into v_task_id, v_state, v_user_id, v_workflow_key, v_transition_key + from wf_user_tasks + where case_id = case_rec.case_id + and rownum = 1; + + PERFORM push_task_ahead( + v_task_id, + v_state, + v_user_id, + v_workflow_key, + v_transition_key + ); + end loop; + end loop; + + + /* Fire transitions at random */ + + for v_count in 1 .. round(v_num_cases * 0.15 * 3) + loop + select case when count(*) = 0 then 0 else 1 end into v_num_tasks + from wf_user_tasks; + + exit when v_num_tasks = 0; + + select task_id, state, user_id, workflow_key, transition_key + into v_task_id, v_state, v_user_id, v_workflow_key, v_transition_key + from wf_user_tasks + limit 1; + + PERFORM push_task_ahead( + v_task_id, + v_state, + v_user_id, + v_workflow_key, + v_transition_key + ); + end loop; + + return 0; +end;' language 'plpgsql'; + +select inline_2 (); + +drop function inline_2 (); + + +-- show errors + + Index: openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/sample-article-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/sample-article-create.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/sample-article-create.sql 12 Apr 2001 00:12:06 -0000 1.1 @@ -0,0 +1,230 @@ +-- +-- acs-workflow/sql/sample-article-create.sql +-- +-- Creates a sample article-authoring workflow to play with +-- +-- @author Kevin Scaldeferri (kevin@theory.caltech.edu) +-- +-- @creation-date 2000-05-18 +-- +-- @cvs-id $Id: sample-article-create.sql,v 1.1 2001/04/12 00:12:06 danw Exp $ +-- + +/* This table will hold one row for each case using this workflow. */ +create table wf_article_cases ( + case_id integer primary key + constraint wf_article_cases_case_fk + references wf_cases on delete cascade +); + + +create function inline_0 () returns integer as ' +declare + v_workflow_key varchar(40); +begin + v_workflow_key := workflow__create_workflow( + ''article_wf'', + ''Article Publication'', + ''Article Publications'', + ''Workflow for managing the publication of an article'', + ''wf_article_cases'', + ''case_id'' + ); + + return null; +end;' language 'plpgsql'; + +select inline_0 (); + +drop function inline_0 (); + +insert into wf_places(place_key, workflow_key, place_name, sort_order) + values ('start', 'article_wf', 'Initial state', 1); +insert into wf_places(place_key, workflow_key, place_name, sort_order) + values ('to_be_written', 'article_wf', 'Needs to be written', 2); +insert into wf_places(place_key, workflow_key, place_name, sort_order) + values ('to_be_reviewed', 'article_wf', 'Needs review', 3); +insert into wf_places(place_key, workflow_key, place_name, sort_order) + values ('to_go_to_press', 'article_wf', 'Ready to go to press', 4); +insert into wf_places(place_key, workflow_key, place_name, sort_order) + values ('end', 'article_wf', 'End state', 5); + + +insert into wf_transitions(transition_key, transition_name, workflow_key, sort_order, trigger_type) + values ('specification', 'Description and assignment by editor', 'article_wf', 1, 'user'); +insert into wf_transitions(transition_key, transition_name, workflow_key, sort_order, trigger_type) + values ('writing', 'Writing by author', 'article_wf', 2, 'user'); +insert into wf_transitions(transition_key, transition_name, workflow_key, sort_order, trigger_type) + values ('review', 'Approval by reviewer', 'article_wf', 3, 'user'); +insert into wf_transitions(transition_key, transition_name, workflow_key, sort_order, trigger_type) + values ('press', 'Publication of article', 'article_wf', 4, 'automatic'); + + +-- specification -- +-- in +insert into wf_arcs(workflow_key, transition_key, place_key, direction) + values ('article_wf', 'specification', 'start', 'in'); +-- out +insert into wf_arcs(workflow_key, transition_key, place_key, direction) + values ('article_wf', 'specification', 'to_be_written', 'out'); + + +-- writing +-- in +insert into wf_arcs(workflow_key, transition_key, place_key, direction) + values ('article_wf', 'writing', 'to_be_written', 'in'); +-- out +insert into wf_arcs(workflow_key, transition_key, place_key, direction) + values ('article_wf', 'writing', 'to_be_reviewed', 'out'); + + +-- review (or-split) +-- in +insert into wf_arcs(workflow_key, transition_key, place_key, direction) + values ('article_wf', 'review', 'to_be_reviewed', 'in'); +-- out +insert into wf_arcs(workflow_key, transition_key, place_key, direction, guard_callback, guard_custom_arg, guard_description) + values ('article_wf', 'review', 'to_go_to_press', 'out', 'wf_callback.guard_attribute_true', 'reviewer_ok', 'Reviewer approved article'); +insert into wf_arcs(workflow_key, transition_key, place_key, direction, guard_callback, guard_description) + values ('article_wf', 'review', 'to_be_written', 'out', '#', 'Reviewer disapproved article'); + + +-- press +-- in +insert into wf_arcs(workflow_key, transition_key, place_key, direction) + values ('article_wf', 'press', 'to_go_to_press', 'in'); +-- out +insert into wf_arcs(workflow_key, transition_key, place_key, direction) + values ('article_wf', 'press', 'end', 'out'); + + +create function inline_1 () returns integer as ' +declare + v_attribute_id acs_attributes.attribute_id%TYPE; +begin + v_attribute_id := workflow__create_attribute( + ''article_wf'', + ''reviewer_ok'', + ''boolean'', + ''Reviewer Approval'', + null, + null, + null, + ''f'', + 1, + 1, + null, + ''generic'', + ''none'' + ); + + insert into wf_transition_attribute_map + (workflow_key, transition_key, attribute_id, sort_order) + values + (''article_wf'', ''review'', v_attribute_id, 1); + + return null; + +end;' language 'plpgsql'; + +select inline_1 (); +drop function inline_1 (); + +-- assignment as part of workflow +insert into wf_transition_assignment_map + (workflow_key, transition_key, assign_transition_key) +values + ('article_wf', 'specification', 'writing'); + +insert into wf_transition_assignment_map + (workflow_key, transition_key, assign_transition_key) +values + ('article_wf', 'specification', 'review'); + + +/* Context stuff */ + + +insert into wf_context_transition_info ( + context_key, workflow_key, transition_key, hold_timeout_callback, hold_timeout_custom_arg +) values ( + 'default', 'article_wf', 'specification', 'wf_callback.time_sysdate_plus_x', 1/24 +); + +commit; + + +-- create or replace package wf_article_callback +-- is +-- procedure notification( +-- task_id in number, +-- custom_arg in varchar2, +-- party_to in integer, +-- party_from in out integer, +-- subject in out varchar2, +-- body in out varchar2 +-- ); +-- +-- end wf_article_callback; +-- / +-- show errors + + +-- create or replace package body wf_article_callback + +-- FIXME: last three variables are in/out variables. + +create function notification(number,varchar,integer,integer,varchar,varchar) +returns integer as ' +declare + notification__task_id alias for $1; + notification__custom_arg alias for $2; + notification__party_to alias for $3; + notification__party_from alias for $4; + notification__subject alias for $5; + notification__body alias for $6; + v_deadline_pretty varchar(400); + v_object_name text; + v_transition_name wf_transitions.transition_name%TYPE; + v_name varchar(1000); +begin + select to_char(ta.deadline,'Mon fmDDfm, YYYY HH24:MI:SS'), + acs_object.name(c.object_id), + tr.transition_name + into v_deadline_pretty, + v_object_name, + v_transition_name + from wf_tasks ta, wf_transitions tr, wf_cases c + where ta.task_id = notification__task_id + and c.case_id = ta.case_id + and tr.workflow_key = c.workflow_key + and tr.transition_key = ta.transition_key; + + notification__subject := ''Assignment: '' || v_transition_name || '' '' || + v_object_name; + + notification__body := ''Dear '' || acs_object__name(notification__party_to) || '' +'' || '' +Today, you have been assigned to a task. +'' || '' +Task : '' || v_transition_name || '' +Object : '' || v_object_name || '' +''; + + if v_deadline_pretty != '''' then + notification__ body := notification__body || ''Deadline: '' || v_deadline_pretty || '' +''; + end if; + + return null; +end;' language 'plpgsql'; + + + + +update wf_context_transition_info +set notification_callback = 'wf_article_callback.notification' +where workflow_key = 'article_wf' +and context_key = 'default' +and transition_key = 'specification'; + Index: openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/sample-article-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/sample-article-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/sample-article-drop.sql 12 Apr 2001 00:12:06 -0000 1.1 @@ -0,0 +1,20 @@ +-- +-- acs-workflow/sql/sample-article-drop.sql +-- +-- Drops the article-authoring workflow. +-- +-- @author Kevin Scaldeferri (kevin@theory.caltech.edu) +-- +-- @creation-date 2000-05-18 +-- +-- @cvs-id $Id: sample-article-drop.sql,v 1.1 2001/04/12 00:12:06 danw Exp $ +-- + + +select workflow__delete_cases('article_wf'); + +drop table wf_article_cases; + +select workflow__drop_workflow('article_wf'); + + Index: openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/sample-expenses-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/sample-expenses-drop.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/sample-expenses-drop.sql 12 Apr 2001 00:12:06 -0000 1.1 @@ -0,0 +1,20 @@ +-- +-- acs-workflow/sql/sample-expenses-drop.sql +-- +-- Drops the expenses workflow. +-- +-- @author Lars Pind (lars@pinds.com) +-- +-- @creation-date 2000-05-18 +-- +-- @cvs-id $Id: sample-expenses-drop.sql,v 1.1 2001/04/12 00:12:06 danw Exp $ +-- + + +select workflow__delete_cases('expenses_wf'); + +drop table wf_expenses_cases; + +select workflow__drop_workflow('expenses_wf'); + +