-
Notifications
You must be signed in to change notification settings - Fork 0
/
close_task.sql
120 lines (110 loc) · 3.02 KB
/
close_task.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
-- FUNCTION: code_src.close_task(text, text, text, text)
-- DROP FUNCTION code_src.close_task(text, text, text, text);
CREATE OR REPLACE FUNCTION code_src.close_task(
uname text,
editversion text,
uapplication text,
ustatus text)
RETURNS text
LANGUAGE 'plpgsql'
COST 100
VOLATILE SECURITY DEFINER
AS $BODY$
DECLARE
/*
Summary:
Close a task
Testing:
select code_src.close_task('slee333', '3', 'uapp1', 'COMPLETED')
*/
userstatus text[] = '{"ABORTED","COMPLETED"}';
vfound boolean;
taskid ige_task.task_id%TYPE;
taskstatus ige_task.task_status%TYPE;
vversion ige_transaction.trans_name%TYPE;
o_status text;
o_message text;
o_json text;
astatus text;
retstatus text;
BEGIN
o_status = 'OK';
o_message = '';
taskid = -1;
vfound = false;
retstatus = '';
FOREACH astatus IN ARRAY userstatus LOOP
retstatus = TRIM(retstatus) || ' ' || astatus;
IF LOWER(astatus) = LOWER($4) THEN
vfound = true;
END IF;
END LOOP;
IF NOT vfound THEN
RAISE 'Status must be member of (%)', retstatus USING ERRCODE = '20001';
END IF;
vversion = $2;
SELECT get_task_id($2,$3) INTO taskid;
SELECT task_status INTO taskstatus
FROM ige_task t
WHERE t.task_id = taskid
AND t.task_type = $3
AND UPPER(t.assigned_to) = UPPER($1);
UPDATE ige_transaction
SET trans_status = $4,
date_end = NOW()
WHERE (trans_status = 'OPEN' OR trans_status IS NULL)
AND trans_name = vVersion;
UPDATE ige_task
SET task_status = $4
where task_id = taskid
and trans_id_expire = -1;
/*-- Beginning of updating Oracle
IF get_configuration_bool('anchorTO', 'ANCHORTO', 'sync_with_oracle') THEN
-- disable ige_transaction update for now
/*UPDATE imaint_anchor.ige_transaction
SET trans_status = $4,
date_end = NOW()
WHERE (trans_status = 'OPEN' OR trans_status IS NULL)
AND trans_name = vVersion;*/
UPDATE imaint_anchor.ige_task
SET task_status = $4
where task_id = taskid
and trans_id_expire = -1;
END IF;
-- End of updating Oracle */
SELECT row_to_json(c) INTO o_json
FROM
(
SELECT o_status status,
o_message message
) c;
RETURN o_json;
EXCEPTION
--WHEN SQLSTATE '20001' THEN
WHEN NO_DATA_FOUND THEN
o_status = SQLSTATE;
o_message = 'Transaction '||$2|| ' by user ('|| upper($1) || ') not found or Transaction status not equal to "OPEN"';
SELECT row_to_json(c) INTO o_json
FROM
(
SELECT o_status status,
o_message message
) c;
RETURN o_json;
WHEN OTHERS THEN
o_status = SQLSTATE;
o_message = SQLERRM;
SELECT row_to_json(c) INTO o_json
FROM
(
SELECT o_status status,
o_message message
) c;
RETURN o_json;
END;
$BODY$;
ALTER FUNCTION code_src.close_task(text, text, text, text)
OWNER TO network;
GRANT EXECUTE ON FUNCTION code_src.close_task(text, text, text, text) TO anchorto_run;
GRANT EXECUTE ON FUNCTION code_src.close_task(text, text, text, text) TO network;
REVOKE ALL ON FUNCTION code_src.close_task(text, text, text, text) FROM PUBLIC;