Index: openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/workflow-case-package.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/workflow-case-package.sql,v
diff -u -r1.3 -r1.4
--- openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/workflow-case-package.sql	11 Apr 2001 04:47:19 -0000	1.3
+++ openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/workflow-case-package.sql	13 Apr 2001 00:29:01 -0000	1.4
@@ -16,7 +16,7 @@
 -- is
 -- 
 --     function new (
---         case_id         in number default null,
+--         case_id         in integer default null,
 --         workflow_key    in varchar2,
 --         context_key     in varchar2 default null,
 --         object_id       in integer,
@@ -26,60 +26,60 @@
 --     ) return integer;
 -- 
 --     procedure add_manual_assignment (
---         case_id         in number,
+--         case_id         in integer,
 --         transition_key  in varchar2,
---         party_id        in number
+--         party_id        in integer
 --     );
 --   
 --     procedure remove_manual_assignment (
---         case_id         in number,
+--         case_id         in integer,
 --         transition_key  in varchar2,
---         party_id        in number
+--         party_id        in integer
 --     );
 --   
 --     procedure clear_manual_assignments (
---         case_id         in number,
+--         case_id         in integer,
 --         transition_key  in varchar2
 --     );
 --   
 --     procedure start_case (
---         case_id         in number,
+--         case_id         in integer,
 --         creation_user   in integer default null,
 --         creation_ip     in varchar2 default null,
 --         msg             in varchar2 default null
 --     );
 -- 
 --     procedure delete(
---         case_id         in number
+--         case_id         in integer
 --     );
 -- 
 --     procedure suspend(
---         case_id         in number,
---         user_id         in number default null,
+--         case_id         in integer,
+--         user_id         in integer default null,
 --         ip_address      in varchar2 default null,
 --         msg             in varchar2 default null
 --     );
 -- 
 --     procedure resume(
---         case_id         in number,
---         user_id         in number default null,
+--         case_id         in integer,
+--         user_id         in integer default null,
 --         ip_address      in varchar2 default null,
 --         msg             in varchar2 default null
 --     );
 -- 
 --     procedure cancel(
---         case_id         in number,
---         user_id         in number default null,
+--         case_id         in integer,
+--         user_id         in integer default null,
 --         ip_address      in varchar2 default null,
 --         msg             in varchar2 default null
 --     );
 -- 
 --     procedure fire_message_transition (
---         task_id         in number
+--         task_id         in integer
 --     );
 -- 
 --     /* To perform an action on the workflow: 
---      * (numbers in parenthesis is the number of times each function should get called)
+--      * (integers in parenthesis is the integer of times each function should get called)
 --      *
 --      * 1. begin_task_action (1)
 --      * 2. set_attribute_value (0..*)
@@ -88,51 +88,51 @@
 --      * 5. end_task_action (1)
 --      */
 --     function begin_task_action (
---         task_id         in number,
+--         task_id         in integer,
 --         action          in varchar2,
 --         action_ip       in varchar2,
---         user_id         in number,
+--         user_id         in integer,
 --         msg             in varchar2 default null
---     ) return number;
+--     ) return integer;
 -- 
 --     procedure set_attribute_value (
---         journal_id      in number,
+--         journal_id      in integer,
 --         attribute_name  in varchar2,
 --         value           in varchar2
 --     );
 -- 
 --     procedure end_task_action (
---         journal_id      in number,
+--         journal_id      in integer,
 --         action          in varchar2,
---         task_id         in number
+--         task_id         in integer
 --     );
 -- 
 --     /* Shortcut, that does both begin and end, when you have no attributes to set or assignments to make */
 --     function task_action (
---         task_id         in number,
+--         task_id         in integer,
 --         action          in varchar2,
 --         action_ip       in varchar2,
---         user_id         in number,
+--         user_id         in integer,
 --         msg             in varchar2 default null
---     ) return number;
+--     ) return integer;
 -- 
 --     function get_attribute_value (
---         case_id         in number,
+--         case_id         in integer,
 --         attribute_name  in varchar2
 --     ) return varchar2;
 -- 
 --     procedure add_task_assignment (
---         task_id         in number,
---         party_id        in number
+--         task_id         in integer,
+--         party_id        in integer
 --     );
 -- 
 --     procedure remove_task_assignment (
---         task_id         in number,
---         party_id        in number
+--         task_id         in integer,
+--         party_id        in integer
 --     );
 -- 
 --     procedure clear_task_assignments (
---         task_id         in number
+--         task_id         in integer
 --     );
 --   
 -- 
@@ -148,7 +148,7 @@
 
 -- create or replace package body workflow_case
 -- function new
-create function workflow_case__new (number,varchar,varchar,integer,timestamp,integer,varchar)
+create function workflow_case__new (integer,varchar,varchar,integer,timestamp,integer,varchar)
 returns integer as '
 declare
   new__case_id                alias for $1;  
@@ -158,7 +158,7 @@
   new__creation_date          alias for $5;  
   new__creation_user          alias for $6;  
   new__creation_ip            alias for $7;  
-  v_case_id                   number;
+  v_case_id                   integer;
   v_workflow_case_table       varchar;
   v_context_key_for_query     varchar;
 begin
@@ -197,7 +197,7 @@
 
 
 -- procedure add_manual_assignment
-create function workflow_case__add_manual_assignment (number,varchar,number)
+create function workflow_case__add_manual_assignment (integer,varchar,integer)
 returns integer as '
 declare
   add_manual_assignment__case_id                alias for $1;  
@@ -221,7 +221,7 @@
 
 
 -- procedure remove_manual_assignment
-create function workflow_case__remove_manual_assignment (number,varchar,number)
+create function workflow_case__remove_manual_assignment (integer,varchar,integer)
 returns integer as '
 declare
   remove_manual_assignment__case_id                alias for $1;  
@@ -242,7 +242,7 @@
 
 
 -- procedure clear_manual_assignments
-create function workflow_case__clear_manual_assignments (number,varchar)
+create function workflow_case__clear_manual_assignments (integer,varchar)
 returns integer as '
 declare
   clear_manual_assignments__case_id                alias for $1;  
@@ -262,21 +262,22 @@
 
 
 -- procedure start_case
-create function workflow_case__start_case (number,integer,varchar,varchar)
+create function workflow_case__start_case (integer,integer,varchar,varchar)
 returns integer as '
 declare
   start_case__case_id                alias for $1;  
   start_case__creation_user          alias for $2;  
   start_case__creation_ip            alias for $3;  
   start_case__msg                    alias for $4;  
-  v_journal_id                       number;        
+  v_journal_id                       integer;        
 begin
         /* Add an entry to the journal */
         v_journal_id := journal_entry__new(
             null, 
             start_case__case_id,
             ''case start'',
             ''Case started'',
+            now(),
             start_case__creation_user,
             start_case__creation_ip,
             start_case__msg
@@ -303,7 +304,7 @@
 
 
 -- procedure delete
-create function workflow_case__delete (number)
+create function workflow_case__delete (integer)
 returns integer as '
 declare
   delete__case_id                alias for $1;  
@@ -352,15 +353,15 @@
 
 
 -- procedure suspend
-create function workflow_case__suspend (number,number,varchar,varchar)
+create function workflow_case__suspend (integer,integer,varchar,varchar)
 returns integer as '
 declare
   suspend__case_id                alias for $1;  
   suspend__user_id                alias for $2;  
   suspend__ip_address             alias for $3;  
   suspend__msg                    alias for $4;  
   v_state                         varchar;   
-  v_journal_id                    number;        
+  v_journal_id                    integer;        
 begin
         select state into v_state
         from   wf_cases
@@ -391,15 +392,15 @@
 
 
 -- procedure resume
-create function workflow_case__resume (number,number,varchar,varchar)
+create function workflow_case__resume (integer,integer,varchar,varchar)
 returns integer as '
 declare
   resume__case_id                alias for $1;  
   resume__user_id                alias for $2;  
   resume__ip_address             alias for $3;  
   resume__msg                    alias for $4;  
   v_state                        varchar;   
-  v_journal_id                   number;        
+  v_journal_id                   integer;        
 begin
         select state into v_state
         from   wf_cases
@@ -430,15 +431,15 @@
 
 
 -- procedure cancel
-create function workflow_case__cancel (number,number,varchar,varchar)
+create function workflow_case__cancel (integer,integer,varchar,varchar)
 returns integer as '
 declare
   cancel__case_id                alias for $1;  
   cancel__user_id                alias for $2;  
   cancel__ip_address             alias for $3;  
   cancel__msg                    alias for $4;  
   v_state                        varchar;   
-  v_journal_id                   number;        
+  v_journal_id                   integer;        
 begin
         select state into v_state
         from   wf_cases
@@ -469,14 +470,14 @@
 
 
 -- procedure fire_message_transition
-create function workflow_case__fire_message_transition (number)
+create function workflow_case__fire_message_transition (integer)
 returns integer as '
 declare
   fire_message_transition__task_id               alias for $1;  
-  v_case_id                                      number;        
+  v_case_id                                      integer;        
   v_transition_name                              varchar;  
   v_trigger_type                                 varchar;   
-  v_journal_id                                   number;        
+  v_journal_id                                   integer;        
 begin
         select t.case_id, tr.transition_name, tr.trigger_type 
         into   v_case_id, v_transition_name, v_trigger_type
@@ -516,7 +517,7 @@
 
 
 -- function begin_task_action
-create function workflow_case__begin_task_action (number,varchar,varchar,number,varchar)
+create function workflow_case__begin_task_action (integer,varchar,varchar,integer,varchar)
 returns integer as '
 declare
   begin_task_action__task_id                alias for $1;  
@@ -525,10 +526,10 @@
   begin_task_action__user_id                alias for $4;  
   begin_task_action__msg                    alias for $5;  
   v_state                                   varchar;
-  v_journal_id                              number;
-  v_case_id                                 number;
+  v_journal_id                              integer;
+  v_case_id                                 integer;
   v_transition_name                         varchar;
-  v_num_rows                                number;
+  v_num_rows                                integer;
 begin
         select state into v_state
         from   wf_tasks
@@ -583,7 +584,7 @@
 
         else if begin_task_action__action = ''comment'' then
             -- We currently allow anyone to comment on a task
-            -- (need this line because PL/SQL doens''t like empty if blocks)
+            -- (need this line because PL/SQL does not like empty if blocks)
             v_num_rows := 0;
         end if; end if; end if;
 
@@ -613,13 +614,13 @@
 
 
 -- procedure end_task_action
-create function workflow_case__end_task_action (number,varchar,number)
+create function workflow_case__end_task_action (integer,varchar,integer)
 returns integer as '
 declare
-  journal_id             alias for $1;  
-  action                 alias for $2;  
-  task_id                alias for $3;  
-  v_user_id              number;
+  end_task_action__journal_id             alias for $1;  
+  end_task_action__action                 alias for $2;  
+  end_task_action__task_id                alias for $3;  
+  v_user_id                               integer;
 begin
         select creation_user into v_user_id
         from   acs_objects
@@ -649,8 +650,8 @@
 
 
 -- function task_action
-create function workflow_case__task_action (number,varchar,varchar,number,varchar)
-returns number as '
+create function workflow_case__task_action (integer,varchar,varchar,integer,varchar)
+returns integer as '
 declare
   task_action__task_id                alias for $1;  
   task_action__action                 alias for $2;  
@@ -679,15 +680,15 @@
 
 
 -- procedure set_attribute_value
-create function workflow_case__set_attribute_value (number,varchar,varchar)
+create function workflow_case__set_attribute_value (integer,varchar,varchar)
 returns integer as '
 declare
   set_attribute_value__journal_id             alias for $1;  
   set_attribute_value__attribute_name         alias for $2;  
   set_attribute_value__value                  alias for $3;  
   v_workflow_key                              varchar;
-  v_case_id                                   number;
-  v_attribute_id                              number;
+  v_case_id                                   integer;
+  v_attribute_id                              integer;
 begin
         select o.object_type, o.object_id into v_workflow_key, v_case_id
         from   journal_entries je, acs_objects o
@@ -716,7 +717,7 @@
 
 
 -- function get_attribute_value
-create function workflow_case__get_attribute_value (number,varchar)
+create function workflow_case__get_attribute_value (integer,varchar)
 returns integer as '
 declare
   get_attribute_value__case_id                alias for $1;  
@@ -731,22 +732,22 @@
 
 
 -- procedure add_task_assignment
-create function workflow_case__add_task_assignment (number,number)
+create function workflow_case__add_task_assignment (integer,integer)
 returns integer as '
 declare
-  add_task_assignment_task_id                alias for $1;  
-  add_task_assignment_party_id               alias for $2;  
+  add_task_assignment__task_id                alias for $1;  
+  add_task_assignment__party_id               alias for $2;  
   v_count                                    integer;       
-  v_workflow_key         wf_workflows.workflow_key%TYPE;
-  v_context_key          wf_contexts.context_key%TYPE;
-  v_case_id              wf_cases.case_id%TYPE;
-  v_transition_key       wf_transitions.transition_key%TYPE;
-  v_notification_callback   wf_context_transition_info.notification_callback%TYPE;
+  v_workflow_key                             wf_workflows.workflow_key%TYPE;
+  v_context_key                              wf_contexts.context_key%TYPE;
+  v_case_id                                  wf_cases.case_id%TYPE;
+  v_transition_key                           wf_transitions.transition_key%TYPE;
+  v_notification_callback     wf_context_transition_info.notification_callback%TYPE;
   v_notification_custom_arg   wf_context_transition_info.notification_custom_arg%TYPE;
-  callback_rec           c_callback%ROWTYPE;
-  v_assigned_user        record;
+  callback_rec                record;
+  v_assigned_user             record;
 begin
-        -- check that we don not hit the unique constraint
+        -- check that we do not hit the unique constraint
 
         select count(*) into v_count
         from   wf_task_assignments
@@ -788,7 +789,7 @@
         -- notify any new assignees
 
         for v_assigned_user in  
-        select distinct u.user_id
+            select distinct u.user_id
             from   users u
             where  u.user_id not in (
 	            select distinct u2.user_id
@@ -826,17 +827,17 @@
 
 
 -- procedure remove_task_assignment
-create function workflow_case__remove_task_assignment (number,number)
+create function workflow_case__remove_task_assignment (integer,integer)
 returns integer as '
 declare
   remove_task_assignment__task_id                alias for $1;  
   remove_task_assignment__party_id               alias for $2;  
-  v_num_assigned                                 number;        
-  v_case_id                                      number;        
+  v_num_assigned                                 integer;        
+  v_case_id                                      integer;        
   v_workflow_key                                 varchar;  
   v_transition_key                               varchar;  
   v_context_key                                  varchar;  
-  callback_rec                                   c_callback%ROWTYPE;
+  callback_rec                                   record;
 begin
         delete 
         from   wf_task_assignments
@@ -870,7 +871,7 @@
         if FOUND then
             PERFORM workflow_case__execute_unassigned_callback (
                 callback_rec.unassigned_callback,
-                task_id,
+                remove_task_assignment__task_id,
                 callback_rec.unassigned_custom_arg
             );
         end if;
@@ -880,11 +881,11 @@
 
 
 -- procedure clear_task_assignments
-create function workflow_case__clear_task_assignments (number)
+create function workflow_case__clear_task_assignments (integer)
 returns integer as '
 declare
   clear_task_assignments__task_id                alias for $1;  
-  v_case_id                                      number;        
+  v_case_id                                      integer;        
   v_transition_key                               varchar;  
   v_workflow_key                                 varchar;  
   v_context_key                                  varchar;  
@@ -914,7 +915,7 @@
 
         PERFORM workflow_case__execute_unassigned_callback (
             v_callback,
-            task_id,
+            clear_task_assignments__task_id,
             v_custom_arg
         );
 
@@ -923,7 +924,7 @@
 
 
 -- function evaluate_guard
-create function workflow_case__evaluate_guard (varchar,varchar,number,varchar,varchar,varchar,varchar)
+create function workflow_case__evaluate_guard (varchar,varchar,integer,varchar,varchar,varchar,varchar)
 returns boolean as '
 declare
   evaluate_guard__callback               alias for $1;  
@@ -951,7 +952,7 @@
                 evaluate_guard__transition_key || '','' || 
                 evaluate_guard__place_key || '','' || 
                 evaluate_guard__direction || '','' || 
-                evaluate_guard__custom_arg || '')''
+                evaluate_guard__custom_arg || '') as guard_happy_p''
                 LOOP
                     return v_rec.guard_happy_p;                        
                 end LOOP;
@@ -964,27 +965,27 @@
 
 
 -- procedure execute_transition_callback
-create function workflow_case__execute_transition_callback (varchar,varchar,number,varchar)
+create function workflow_case__execute_transition_callback (varchar,varchar,integer,varchar)
 returns integer as '
 declare
   execute_transition_callback__callback               alias for $1;  
   execute_transition_callback__custom_arg             alias for $2;  
   execute_transition_callback__case_id                alias for $3;  
   execute_transition_callback__transition_key         alias for $4;  
 begin
-        if execute_transition_callback__callback is not null then 
+        if execute_transition_callback__callback != '''' then 
             execute ''select '' || execute_transition_callback__callback
             || ''('' || execute_transition_callback__case_id || '','' || 
             execute_transition_callback__transition_key || '','' || 
-            execute_transition_callback__custom_arg '')''
+            execute_transition_callback__custom_arg || '')'';
         end if;
 
         return 0; 
 end;' language 'plpgsql';
 
 
 -- function execute_time_callback
-create function workflow_case__execute_time_callback (varchar,varchar,number,varchar)
+create function workflow_case__execute_time_callback (varchar,varchar,integer,varchar)
 returns timestamp as '
 declare
   execute_time_callback__callback               alias for $1;  
@@ -1011,7 +1012,7 @@
 
 
 -- function get_task_deadline
-create function workflow_case__get_task_deadline (varchar,varchar,varchar,number,varchar)
+create function workflow_case__get_task_deadline (varchar,varchar,varchar,integer,varchar)
 returns integer as '
 declare
   get_task_deadline__callback               alias for $1;  
@@ -1021,9 +1022,11 @@
   get_task_deadline__transition_key         alias for $5;  
   v_deadline                                timestamp;
   v_rec                                     record;
+  v_str                                     varchar;
 begin
+        raise notice ''workflow_case__get_task_deadline'';
         /*
-         * 1. or if there''s a row in wf_case_deadlines, we use that
+         * 1. or if there is a row in wf_case_deadlines, we use that
          * 2. if there is a callback, we execute that
          * 3. otherwise, if there is an attribute, we use that
          */
@@ -1034,19 +1037,21 @@
             where case_id = get_task_deadline__case_id
             and   transition_key = get_task_deadline__transition_key;
 
+        raise notice ''get_task_deadline__callback = %'',get_task_deadline__callback;
         if NOT FOUND then
-            if get_task_deadline__callback is not null then
+            if get_task_deadline__callback != '''' then
                 /* callback */
-                for v_rec in 
-                execute ''select '' || get_task_deadline__callback || ''('' || 
+                v_str := ''select '' || get_task_deadline__callback || ''('' || 
                 get_task_deadline__case_id || '','' || 
                 get_task_deadline__transition_key || '','' || 
-                get_task_deadline__custom_arg ||  '') as deadline''
+                get_task_deadline__custom_arg || '') as deadline'';
+                raise notice ''v_str = %'', v_str;
+                for v_rec in execute v_str
                 LOOP
                     v_deadline := v_rec.deadline;
                     exit;
                 end LOOP;
-            else if get_task_deadline__attribute_name is not null then
+            else if get_task_deadline__attribute_name != '''' then
                 /* attribute */
                 v_deadline := acs_object__get_attribute(
                     get_task_deadline__case_id,
@@ -1063,7 +1068,7 @@
 
 
 -- function execute_hold_timeout_callback
-create function workflow_case__execute_hold_timeout_callback (varchar,varchar,number,varchar)
+create function workflow_case__execute_hold_timeout_callback (varchar,varchar,integer,varchar)
 returns integer as '
 declare
   execute_hold_timeout_callback__callback               alias for $1;  
@@ -1082,7 +1087,7 @@
         || ''('' ||
         execute_hold_timeout_callback__case_id || '','' ||
         execute_hold_timeout_callback__transition_key || '','' ||
-        execute_hold_timeout_callback__custom_arg || '') into hold_timeout''
+        execute_hold_timeout_callback__custom_arg || '') as hold_timeout''
         LOOP
            return v_rec.hold_timeout;
         end LOOP;
@@ -1093,14 +1098,14 @@
 
 
 -- procedure execute_unassigned_callback
-create function workflow_case__execute_unassigned_callback (varchar,number,varchar)
+create function workflow_case__execute_unassigned_callback (varchar,integer,varchar)
 returns integer as '
 declare
   callback               alias for $1;  
   task_id                alias for $2;  
   custom_arg             alias for $3;  
 begin
-        if callback is not null then
+        if callback != '''' then
             execute ''select '' || callback
             || ''('' || task_id || '','' || custom_arg || '')'';
         end if;
@@ -1110,14 +1115,15 @@
 
 
 -- procedure set_task_assignments
-create function workflow_case__set_task_assignments (number,varchar,varchar)
+create function workflow_case__set_task_assignments (integer,varchar,varchar)
 returns integer as '
 declare
   set_task_assignments__task_id                alias for $1;  
   set_task_assignments__callback               alias for $2;  
   set_task_assignments__custom_arg             alias for $3;  
   v_done_p                                     boolean;
   case_assignment_rec                          record;
+  context_assignment_rec                       record;
 begin
 
         /* Find out who to assign the given task to.
@@ -1139,29 +1145,29 @@
         LOOP
             v_done_p := ''t'';
             PERFORM workflow_case__add_task_assignment (
-                task_id,
+                set_task_assignments__task_id,
                 case_assignment_rec.party_id
             );
         end loop;
 
         if v_done_p != ''t'' then
 
-            if set_task_assignments__callback is not null then
+            if set_task_assignments__callback != '''' then
                 execute ''select ''|| set_task_assignments__callback || ''('' || 
                 set_task_assignments__task_id || '','' || 
                 set_task_assignments__custom_arg || '')'';
             else
                 for context_assignment_rec in  
-                select party_id
-                from   wf_context_assignments ca, wf_cases c, wf_tasks t
-                where  t.task_id = set_task_assignments__task_id
-                and    c.case_id = t.case_id
-                and    ca.context_key = c.context_key
-                and    ca.workflow_key = t.workflow_key
-                and    ca.transition_key = t.transition_key
+                    select party_id
+                    from   wf_context_assignments ca, wf_cases c, wf_tasks t
+                    where  t.task_id = set_task_assignments__task_id
+                    and    c.case_id = t.case_id
+                    and    ca.context_key = c.context_key
+                    and    ca.workflow_key = t.workflow_key
+                    and    ca.transition_key = t.transition_key
                 LOOP
                     PERFORM workflow_case__add_task_assignment (
-                        task_id,
+                        set_task_assignments__task_id,
                         context_assignment_rec.party_id
                     );
                 end LOOP;
@@ -1173,13 +1179,13 @@
 
 
 -- procedure add_token
-create function workflow_case__add_token (number,varchar,number)
+create function workflow_case__add_token (integer,varchar,integer)
 returns integer as '
 declare
   add_token__case_id                alias for $1;  
   add_token__place_key              alias for $2;  
   add_token__journal_id             alias for $3;  
-  v_token_id                        number;
+  v_token_id                        integer;
   v_workflow_key                    varchar;
 begin
         select wf_token_id_seq.nextval into v_token_id from dual;
@@ -1199,7 +1205,7 @@
 
 
 -- procedure lock_token
-create function workflow_case__lock_token (number,varchar,number,number)
+create function workflow_case__lock_token (integer,varchar,integer,integer)
 returns integer as '
 declare
   lock_token__case_id                alias for $1;  
@@ -1223,16 +1229,18 @@
                locked_task_id = lock_token__task_id,
                locked_date = now(),
                locked_journal_id = lock_token__journal_id
-        where  case_id = lock_token__case_id
-        and    place_key = lock_token__place_key
-        and    state = ''free'';
+        where  token_id = (select token_id 
+                             from wf_tokens 
+                            where case_id = lock_token__case_id
+                              and place_key = lock_token__place_key
+                              and state = ''free'');
 
         return 0; 
 end;' language 'plpgsql';
 
 
 -- procedure release_token
-create function workflow_case__release_token (number,number)
+create function workflow_case__release_token (integer,integer)
 returns integer as '
 declare
   release_token__task_id                alias for $1;  
@@ -1268,15 +1276,15 @@
 
 
 -- procedure consume_token
-create function workflow_case__consume_token (number,varchar,number,number)
+create function workflow_case__consume_token (integer,varchar,integer,integer)
 returns integer as '
 declare
   consume_token__case_id                alias for $1;  
   consume_token__place_key              alias for $2;  
   consume_token__journal_id             alias for $3;  
   consume_token__task_id                alias for $4;  
 begin
-        if task_id is null then
+        if consume_token__task_id is null then
             update wf_tokens
             set    state = ''consumed'',
                    consumed_date = now(),
@@ -1301,7 +1309,7 @@
 
 
 -- procedure sweep_automatic_transitions
-create function workflow_case__sweep_automatic_transitions (number,number)
+create function workflow_case__sweep_automatic_transitions (integer,integer)
 returns integer as '
 declare
   sweep_automatic_transitions__case_id                alias for $1;  
@@ -1320,7 +1328,15 @@
                 sweep_automatic_transitions__journal_id);
 
             if v_finished_p = ''f'' then
-                for task_rec in enabled_automatic_transitions loop
+                for task_rec in 
+                    select task_id
+                    from   wf_tasks ta, wf_transitions tr
+                    where  tr.workflow_key = ta.workflow_key
+                    and    tr.transition_key = ta.transition_key
+                    and    tr.trigger_type = ''automatic''
+                    and    ta.state = ''enabled''
+                    and    ta.case_id = sweep_automatic_transitions__case_id
+                LOOP
                     PERFORM workflow_case__fire_transition_internal(
                         task_rec.task_id,
                         sweep_automatic_transitions__journal_id
@@ -1338,15 +1354,15 @@
 
 
 -- function finished_p
-create function workflow_case__finished_p (number,number)
+create function workflow_case__finished_p (integer,integer)
 returns booleanr as '
 declare
   finished_p__case_id                alias for $1;  
   finished_p__journal_id             alias for $2;  
   v_case_state                       varchar;
-  v_token_id                         number;
-  v_num_rows                         number;
-  v_journal_id                       number;
+  v_token_id                         integer;
+  v_num_rows                         integer;
+  v_journal_id                       integer;
 begin
         select state into v_case_state 
         from   wf_cases 
@@ -1355,7 +1371,7 @@
         if v_case_state = ''finished'' then
             return ''t'';
         else
-            /* Let''s see if the case is actually finished, but just not marked so */
+            /* Let us see if the case is actually finished, but just not marked so */
             select case when count(*) = 0 then 0 else 1 end into v_num_rows
             from   wf_tokens
             where  case_id = finished_p__case_id
@@ -1364,8 +1380,8 @@
             if v_num_rows = 0 then 
                 return ''f'';
             else
-                /* There''s a token in the end place.
-                 * Count the total number of tokens to make sure the wf is well-constructed.
+                /* There is a token in the end place.
+                 * Count the total integer of tokens to make sure the wf is well-constructed.
                  */
     
                 select case when count(*) = 0 then 0
@@ -1416,8 +1432,10 @@
 end;' language 'plpgsql';
 
 
+
+
 -- procedure notify_assignee
-create function workflow_case__notify_assignee (integer,integer,<=>,varchar)
+create function workflow_case__notify_assignee (integer,integer,varchar,varchar)
 returns integer as '
 declare
   notify_assignee__task_id                alias for $1;  
@@ -1435,7 +1453,7 @@
   v_request_id                            integer;       
 begin
         select to_char(ta.deadline,''Mon fmDDfm, YYYY HH24:MI:SS''),
-               acs_object.name(c.object_id),
+               acs_object__name(c.object_id),
                tr.transition_key,
                tr.transition_name
         into   v_deadline_pretty,
@@ -1449,25 +1467,26 @@
         and    tr.transition_key = ta.transition_key;
 
         /* Default values */
-        v_party_from := -1;   /* This default value should probably be pulled from somewhere */
-        v_subject := ''Assignment: ''|| v_transition_name || '' '' || v_object_name;
+        /* This default value should probably be pulled from somewhere */
+        v_party_from := -1;   
+        v_subject := ''Assignment: '' || v_transition_name || '' '' || v_object_name;
         v_body := ''You have been assigned to a task.
-''||''
-Task    : ''||v_transition_name||''
-Object  : ''||v_object_name||''
+'' || ''
+Task    : '' || v_transition_name || ''
+Object  : '' || v_object_name || ''
 '';
 
         if v_deadline_pretty != '''' then
-            v_body := v_body ||''Deadline: ''||v_deadline_pretty||''
+            v_body := v_body || ''Deadline: '' || v_deadline_pretty || ''
 '';
         end if;
 
-        /* We''d like to add a URL to go visit, but how do we get that URL? */
+        /* We would like to add a URL to go visit, but how do we get that URL? */
         /* The notifications should really be sent from the application server layer, not from the database */
     
         -- FIXME: last three args are also out varibles.
 
-        if notify_assignee__callback is not null then
+        if notify_assignee__callback != '''' then
             execute ''select '' || notify_assignee__callback || ''('' || 
             notify_assignee__task_id || '','' ||
             notify_assignee__custom_arg || '','' ||
@@ -1478,34 +1497,34 @@
         end if;
             
         -- FIXME: notifications package not ported yet.
-
+/*
         v_request_id := nt__post_request (       
             v_party_from,
             notify_assignee__user_id,
-            ''f'' ,
+            ''f'',
             v_subject,
             v_body,
             3
         );
-
+*/
     return 0; 
 end;' language 'plpgsql';
 
 
 -- procedure enable_transitions
-create function workflow_case__enable_transitions (number)
+create function workflow_case__enable_transitions (integer)
 returns integer as '
 declare
   enable_transitions__case_id                alias for $1;  
-  v_task_id                                  number;        
+  v_task_id                                  integer;        
   v_workflow_key                             varchar;  
   v_trigger_time                             timestamp;     
   v_deadline_date                            timestamp;     
   v_party_from                               integer;       
   v_subject                                  varchar;  
   v_body                                     text; 
-  v_num_assigned                             number;        
-  request_id                                 nt_requests.request_id%TYPE;
+  v_num_assigned                             integer;        
+--  request_id                                 nt_requests.request_id%TYPE;
   trans_rec                                  record;
 begin
         select workflow_key into v_workflow_key 
@@ -1571,7 +1590,7 @@
                                         trans_rec.transition_key);
             end if; end if;
 
-            /* we''re ready to insert the row */
+            /* we are ready to insert the row */
             select wf_task_id_seq.nextval into v_task_id from dual;
 
             insert into wf_tasks (
@@ -1616,12 +1635,12 @@
 
 
 -- procedure fire_transition_internal
-create function workflow_case__fire_transition_internal (number,number)
+create function workflow_case__fire_transition_internal (integer,integer)
 returns integer as '
 declare
   fire_transition_internal__task_id                alias for $1;  
   fire_transition_internal__journal_id             alias for $2;  
-  v_case_id                                        number;        
+  v_case_id                                        integer;        
   v_state                                          varchar;   
   v_transition_key                                 varchar;  
   v_workflow_key                                   varchar;  
@@ -1631,7 +1650,7 @@
   v_fire_callback                                  varchar;  
   v_fire_custom_arg                                text; 
   v_found_happy_guard                              boolean;       
-  v_locked_task_id                                 number;   
+  v_locked_task_id                                 integer;   
   place_rec                                        record;     
 begin
         select t.case_id, t.state, t.workflow_key, t.transition_key, ti.fire_callback, ti.fire_custom_arg
@@ -1711,7 +1730,7 @@
         end loop;
 
 
-        /* If we didn''t find any happy guards, look for arcs with the special hash (#) guard */
+        /* If we did not find any happy guards, look for arcs with the special hash (#) guard */
 
         if v_found_happy_guard = ''f'' then
             for place_rec in 
@@ -1745,12 +1764,12 @@
 
 
 -- procedure ensure_task_in_state
-create function workflow_case__ensure_task_in_state (number,varchar)
+create function workflow_case__ensure_task_in_state (integer,varchar)
 returns integer as '
 declare
   ensure_task_in_state__task_id         alias for $1;  
   ensure_task_in_state__state           alias for $2;  
-  v_count                               number;        
+  v_count                               integer;        
 begin
         select case when count(*) 0 then 0 else 1 end into v_count
         from   wf_tasks 
@@ -1766,13 +1785,13 @@
 
 
 -- procedure start_task
-create function workflow_case__start_task (number,number,number)
+create function workflow_case__start_task (integer,integer,integer)
 returns integer as '
 declare
   start_task__task_id                alias for $1;  
   start_task__user_id                alias for $2;  
   start_task__journal_id             alias for $3;  
-  v_case_id                          number;        
+  v_case_id                          integer;        
   v_workflow_key                     wf_workflows.workflow_key%TYPE;
   v_transition_key                   varchar(100);  
   v_hold_timeout_callback            varchar(100);  
@@ -1828,7 +1847,7 @@
 
 
 -- procedure cancel_task
-create function workflow_case__cancel_task (number,number)
+create function workflow_case__cancel_task (integer,integer)
 returns integer as '
 declare
   cancel_task__task_id                alias for $1;  
@@ -1867,7 +1886,7 @@
 
 
 -- procedure finish_task
-create function workflow_case__finish_task (number,number)
+create function workflow_case__finish_task (integer,integer)
 returns integer as '
 declare
   finish_task__task_id                alias for $1;  
@@ -1902,12 +1921,12 @@
 create function inline_0 ()
 returns integer as '
 begin
-    PERFORM  nt__schedule_process (1,'localhost',25);
+    PERFORM  nt__schedule_process (1,''localhost'',25);
 
     return 0;
 end;' language 'plpgsql';
 
-select inline_0 ();
+-- select inline_0 ();
 
 drop function inline_0 ();
 
