DBA Data[Home] [Help]

PACKAGE BODY: APPS.ZPB_PUBLISH

Source


1 PACKAGE BODY ZPB_PUBLISH AS
2 /* $Header: ZPBPUBB.pls 120.0.12010.2 2005/12/23 06:02:52 appldev noship $ */
3 
4 
5 /*+=========================================================================+
6   | startPublishTaskCP
7   |
8   | Starts the Publish WorkFlow process which runs independent of BP Tasks.
9   |
10   | Notes:
11   |  1. Manages context for WF.
12   |  2. Starts the WF process.
13   |
14   +========================================================================+
15 */
16 
17     PROCEDURE startPublishTaskCP(
18         itemtype    IN VARCHAR2,
19         itemkey     IN VARCHAR2,
20         actid       IN NUMBER,
21         funcmode    IN VARCHAR2,
22         resultout   OUT nocopy VARCHAR2
23  )
24    IS
25         -- Enter the procedure variables here. As shown below
26         CurrtaskSeq         NUMBER;
27         ACID                NUMBER;
28         ownerID             NUMBER;
29         respID              NUMBER;
30         respAppID           NUMBER;
31         InstanceID          NUMBER;
32         TaskID              NUMBER;
33         REQID               NUMBER;
34 
35         owner               VARCHAR2(30);
36         ACNAME              VARCHAR2(300);
37         charDate            VARCHAR2(30);
38         newItemKey          VARCHAR2(240);
39         workflowprocess     VARCHAR2(30);
40         TaskName            VARCHAR2(256);
41 
42     	issue_msg           fnd_new_messages.message_text%TYPE;
43         textVarNameArray    Wf_Engine.NameTabTyp; -- Array of Text Attribute Names
44         textVarValArray     Wf_Engine.TextTabTyp; -- Text Array of Item Attribute Values
45         numVarNameArray     Wf_Engine.NameTabTyp;  -- Array of Numeric Attribute Names
46         numVarValArray      Wf_Engine.NumTabTyp;   -- Number Array of Item Attribute Values
47 
48 
49         CURSOR c_tasks is
50             select *
51             from zpb_analysis_cycle_tasks
52             where ANALYSIS_CYCLE_ID = InstanceID
53             and Sequence = CurrtaskSeq;
54         v_tasks c_Tasks%ROWTYPE;
55 
56    BEGIN
57   	    resultout :='COMPLETE:N';
58         -- Get current global attributes to run next WF task!
59         CurrtaskSeq := wf_engine.GetItemAttrNumber(Itemtype => ItemType,
60                        Itemkey => ItemKey,
61                        aname => 'TASKSEQ');
62         ACID := wf_engine.GetItemAttrNumber(Itemtype => ItemType,
63                        Itemkey => ItemKey,
64                        aname => 'ACID');
65         ACNAME := wf_engine.GetItemAttrText(Itemtype => ItemType,
66                        Itemkey => ItemKey,
67                        aname => 'ACNAME');
68         ownerID := wf_engine.GetItemAttrNumber(Itemtype => ItemType,
69                        Itemkey => ItemKey,
70                        aname => 'OWNERID');
71         respID := wf_engine.GetItemAttrNumber(Itemtype => ItemType,
72                        Itemkey => ItemKey,
73                        aname => 'RESPID');
74         respAppID := wf_engine.GetItemAttrNumber(Itemtype => ItemType,
75                        Itemkey => ItemKey,
76                        aname => 'RESPAPPID');
77         owner := wf_engine.GetItemAttrText(Itemtype => ItemType,
78                        Itemkey => ItemKey,
79                        aname => 'FNDUSERNAM');
80         InstanceID := wf_engine.GetItemAttrNumber(Itemtype => ItemType,
81                        Itemkey => ItemKey,
82                        aname => 'INSTANCEID');
83         TaskID := wf_engine.GetItemAttrNumber(Itemtype => ItemType,
84                        Itemkey => ItemKey,
85                        aname => 'TASKID');
86 
87         WorkflowProcess := 'PUBLISH_WORKFLOW';
88         -- Set item key and date
89         charDate := to_char(sysdate, 'MM/DD/YYYY-HH24-MI-SS');
90         newItemKey := rtrim(substr(ACName, 1, 50), ' ') || '-' || to_char(ACID) || '-' || to_char(CurrtaskSeq+1) || '-' || workflowprocess || '-' || charDate;
91 -- +============================================================+
92         -- Create WF start process instance
93         wf_engine.CreateProcess(ItemType => ItemType,
94                         itemKey => newItemKey,
95                         process => WorkflowProcess);
96 
97 	   -- Get the short text from fnd messages
98         FND_MESSAGE.SET_NAME('ZPB', 'ZPB_PUBLISH_TASK_ISSUE_MSG');
99         issue_msg := FND_MESSAGE.GET;
100 
101         textVarNameArray(1) := 'EPBPERFORMER';
102         textVarValArray(1) := owner;
103 
104         textVarNameArray(2) := 'ACNAME';
105         textVarValArray(2) := ACNAME;
106 
107         textVarNameArray(3) := 'ISSUEMSG';
108         textVarValArray(3) := issue_msg;
109 
110         textVarNameArray(4) := 'FNDUSERNAM';
111         textVarValArray(4) := owner;
112 
113         Wf_Engine.SetItemAttrTextArray(Itemtype => ItemType,
114                         Itemkey => newItemKey,
115                         aname => textVarNameArray,
116                         avalue => textVarValArray);
117 
118         numVarNameArray(1) := 'OWNERID';
119         numVarValArray(1) := ownerID;
120 
121         numVarNameArray(2) := 'RESPID';
122         numVarValArray(2) := respID;
123 
124         numVarNameArray(3) := 'RESPAPPID';
125         numVarValArray(3) := respAppID;
126 
127         numVarNameArray(4) := 'INSTANCEID';
128         numVarValArray(4) := InstanceID;
129 
130         numVarNameArray(5) := 'TASKID';
131         numVarValArray(5) := TaskID;
132 
133         Wf_Engine.SetItemAttrNumberArray(Itemtype => ItemType,
134                   Itemkey => newItemKey,
135                   aname => numVarNameArray,
136                   avalue => numVarValArray);
137 
138         --If the session has been interrupted, reset the Context.
139 
140 -- +============================================================+
141         -- Now that all is created and set START the PROCESS!
142         wf_engine.StartProcess(ItemType => ItemType,
143                         ItemKey => newItemKey);
144 
145         resultout := 'COMPLETE:Y';
146         EXCEPTION
147             WHEN others THEN
148               raise;
149     END startPublishTaskCP;
150 
151 /*+=========================================================================+
152   | getApprovalFlag
153   |
154   | 1. Checks whether "Approval Flag" is set by the User or not.
155   | 2. Also checks whether the "Send Status Report" flag is set or not.
156   |
157   +========================================================================+
158 */
159 
160     PROCEDURE getApprovalFlag(
161         itemtype    IN VARCHAR2,
162         itemkey     IN VARCHAR2,
163         actid       IN NUMBER,
164         funcmode    IN VARCHAR2,
165         resultout   OUT nocopy VARCHAR2
166  )
167    IS
168         call_status         BOOLEAN;
169 
170     	l_respapp_id        NUMBER;
171         l_user_id           NUMBER;
172     	l_resp_id           NUMBER;
173         l_start_pos         NUMBER;
174         l_pre_PathLoc       NUMBER;
175         l_post_PathLoc      NUMBER;
176         l_pre_RepNameLoc    NUMBER;
177         l_post_RepNameLoc   NUMBER;
178         request_id          NUMBER;
179         InstanceID          NUMBER;
180         TaskID              NUMBER;
181 
182         l_owner             VARCHAR2(30);
183         l_ACNAME            VARCHAR2(300);
184         rphase              VARCHAR2(30);
185         rstatus             VARCHAR2(30);
186         dphase              VARCHAR2(30);
187         dstatus             VARCHAR2(30);
188         message             VARCHAR2(240);
189         appr_flag           VARCHAR2(1);
190         send_status_flag    VARCHAR2(1);
191         template_name       VARCHAR2(4000);
192         read_access         VARCHAR2(4000);
193         recipients_list     VARCHAR2(4000);
194         datasources_list    VARCHAR2(4000);
195         l_char_delim        VARCHAR2(8);
196 
197 
198     	issue_msg       fnd_new_messages.message_text%TYPE;
199     	no_issue_msg    fnd_new_messages.message_text%TYPE;
200 
201         textVarNameArray Wf_Engine.NameTabTyp; -- Array of Text Attribute Names
202         textVarValArray  Wf_Engine.TextTabTyp; -- Text Array of Item Attribute Values
203 
204         CURSOR c_recipient is
205           select NAME, value
206           from ZPB_TASK_PARAMETERS
207           where TASK_ID = TaskID and name = 'SPECIFIED_NOTIFICATION_RECIPIENT';
208 
209         v_recipient c_recipient%ROWTYPE;
210 
211         CURSOR c_datasources is
212           select NAME, value
213           from ZPB_TASK_PARAMETERS
214           where TASK_ID = TaskID and name = 'TEMPLATE_DATASOURCE';
215 
216         v_datasources c_datasources%ROWTYPE;
217 
218    BEGIN
219         l_owner := wf_engine.GetItemAttrText(Itemtype => ItemType,
220                        Itemkey => ItemKey,
221                        aname => 'FNDUSERNAM');
222  	    l_resp_id := wf_engine.GetItemAttrNumber(Itemtype => ItemType,
223         		       Itemkey => ItemKey,
224  	  	               aname => 'RESPID');
225         l_user_id := wf_engine.GetItemAttrNumber(Itemtype => ItemType,
226         		       Itemkey => ItemKey,
227 	  	               aname => 'OWNERID');
228         l_respapp_id := wf_engine.GetItemAttrNumber(Itemtype => ItemType,
229         		       Itemkey => ItemKey,
230  	  	               aname => 'RESPAPPID');
231         l_ACNAME := wf_engine.GetItemAttrText(Itemtype => ItemType,
232                        Itemkey => ItemKey,
233                        aname => 'ACNAME');
234         InstanceID := wf_engine.GetItemAttrNumber(Itemtype => ItemType,
235                        Itemkey => ItemKey,
236                        aname => 'INSTANCEID');
237         TaskID := wf_engine.GetItemAttrNumber(Itemtype => ItemType,
238                          Itemkey => ItemKey,
239                          aname => 'TASKID');
240 
241         l_start_pos          := 1;
242         l_pre_PathLoc        := 3;
243         l_post_PathLoc       := 4;
244         l_pre_RepNameLoc     := 2;
245         l_post_RepNameLoc    := 3;
246         l_char_delim         := fnd_global.newline;
247 
248         --Getting the List of Document Recipients
249         for  v_recipient in c_recipient loop
250            recipients_list := recipients_list || v_recipient.value || l_char_delim;
251         end loop;
252         recipients_list := SUBSTR(
253                             recipients_list,
254                             l_start_pos,
255                             length(recipients_list) - length(l_char_delim));
256 
257         --Getting the Lits of Datasources used to create the Document
258         for  v_datasources in c_datasources loop
259            datasources_list := datasources_list ||
260            SUBSTR(
261              v_datasources.value,
262              INSTR(v_datasources.value, l_char_delim, l_start_pos, l_pre_PathLoc)+1,
263              INSTR(v_datasources.value, l_char_delim, l_start_pos, l_post_PathLoc)-
264                  INSTR(v_datasources.value, l_char_delim, l_start_pos, l_pre_PathLoc)-1
265                   ) || '/' ||
266            SUBSTR(
267              v_datasources.value,
268              INSTR(v_datasources.value, l_char_delim, l_start_pos, l_pre_RepNameLoc)+1,
269              INSTR(v_datasources.value, l_char_delim, l_start_pos, l_post_RepNameLoc)-
270                  INSTR(v_datasources.value, l_char_delim, l_start_pos, l_pre_RepNameLoc)-1
271                   )
272            || l_char_delim;
273         end loop;
274 
275         datasources_list := SUBSTR(
276                             datasources_list,
277                             l_start_pos,
278                             length(datasources_list) - length(l_char_delim));
279 
280         --Getting the Template Name used to create the Document
281         SELECT value INTO template_name
282         FROM zpb_task_parameters
283         WHERE task_ID = taskID and NAME = 'DOCUMENT_TEMPLATE_NAME';
284 
285         --Getting the Document Security used
286         SELECT value INTO read_access
287         FROM zpb_task_parameters
288         WHERE task_ID = taskID and NAME = 'DOCUMENT_SECURITY';
289         IF read_access = 'USER_READSCOPE' THEN
290             read_access := fnd_message.get_string('ZPB', 'ZPB_RECIPIENT_READ_SCOPE');
291         ELSE
292             read_access := fnd_message.get_string('ZPB', 'ZPB_BPO_READ_SCOPE');
293         END IF;
294 
295         --To find whether the Approval required CheckBox is selected
296         SELECT value INTO appr_flag
297         FROM zpb_task_parameters
298         WHERE task_ID = taskID and NAME = 'DOCUMENT_WAIT_FOR_APPROVAL';
299 
300         --To find whether Send Status Report CheckBox is selected
301         SELECT value INTO send_status_flag
302         FROM zpb_task_parameters
303         WHERE task_ID = taskID and NAME = 'DOCUMENT_SEND_STATUS_BPO';
304 
305 	    -- Get the short text from fnd messages
306         FND_MESSAGE.SET_NAME('ZPB', 'ZPB_CAL_JAVA_XML_GEN_ISSUE_MSG');
307         issue_msg := FND_MESSAGE.GET;
308         FND_MESSAGE.SET_NAME('ZPB', 'ZPB_NO_ISSUE_MSG');
309         no_issue_msg := FND_MESSAGE.GET;
310 
311         textVarNameArray(1) := 'ISSUEMSG';
312         textVarValArray(1) := issue_msg;
313 
314         textVarNameArray(2) := 'NOISSUEMSG';
315         textVarValArray(2) := no_issue_msg;
316 
317         textVarNameArray(3) := 'ACNAME';
318         textVarValArray(3) := l_ACNAME;
319 
320         textVarNameArray(4) := 'TEMPLATE_NAME';
321         textVarValArray(4) := template_name;
322 
323         textVarNameArray(5) := 'READ_ACCESS';
324         textVarValArray(5) := read_access;
325 
326         textVarNameArray(6) := 'DOC_RECEP_LIST';
327         textVarValArray(6) := recipients_list;
328 
329         textVarNameArray(7) := 'DATASOURCE_LIST';
330         textVarValArray(7) := datasources_list;
331 
332         IF (send_status_flag = 'Y') THEN
333             textVarNameArray(8) := 'EPBPERFORMER';
334             textVarValArray(8) := l_owner;
335             call_status := FND_REQUEST.add_notification(l_owner);
336         END IF;
337 
338         Wf_Engine.SetItemAttrTextArray(Itemtype => ItemType,
339                         Itemkey => ItemKey,
340                         aname => textVarNameArray,
341                         avalue => textVarValArray);
342 
343         --If the session has been interrupted due to notification, reset the Context.
344      	fnd_global.apps_initialize(l_user_id,l_resp_id,l_respapp_id);
345 
346         -- WF BACKGROUND ENGINE TO RUN deferred activities like WAIT.
347         call_status := FND_CONCURRENT.GET_REQUEST_STATUS(request_id, 'ZPB', 'ZPB_WF_START', rphase,rstatus,dphase,dstatus, message);
348 
349         IF (appr_flag = 'Y') THEN
350             resultout := 'COMPLETE:Y';
351         ELSE
352             resultout := 'COMPLETE:N';
353         END IF;
354 
355    EXCEPTION
356 
357         WHEN NO_DATA_FOUND then
358             resultout := 'COMPLETE:N';
359         WHEN others THEN
360             raise;
361    END getApprovalFlag;
362 END ZPB_PUBLISH;