[Home] [Help]
PACKAGE BODY: APPS.FND_CONCURRENT_BUSINESS_EVENT
Source
1 package body fnd_concurrent_business_event as
2 /* $Header: AFCPBIAB.pls 120.0 2007/12/17 20:37:07 tkamiya noship $ */
3
4 ------------------------------------------------------------------------
5 -- constants
6 ------------------------------------------------------------------------
7 NTRUE constant number :=1;
8 NFALSE constant number :=0;
9
10
11 -----------------------------------------------------------------
12 -- parse_event_name_from_number --
13 -- returns event name when called with event_number --
14 -----------------------------------------------------------------
15 function parse_event_name_from_number(
16 p_event_code in number)
17 return varchar2
18 is
19 v_event_name varchar2(100);
20 begin
21
22 select decode(p_event_code, 1, 'oracle.apps.fnd.concurrent.request.submitted',
23 2, 'oracle.apps.fnd.concurrent.request.on_hold',
24 3, 'oracle.apps.fnd.concurrent.request.resumed',
25 4, 'oracle.apps.fnd.concurrent.request.running',
26 5, 'oracle.apps.fnd.concurrent.program.completed',
27 6, 'oracle.apps.fnd.concurrent.request.postprocessing_started',
28 7, 'oracle.apps.fnd.concurrent.request.postprocessing_ended',
29 8, 'oracle.apps.fnd.concurrent.request.completed',
30 'NOT_FOUND')
31 into v_event_name
32 from dual;
33
34 return v_event_name;
35
36 end parse_event_name_from_number;
37
38
39 -------------------------------------------------------------------------
40 -- raise_wf_bi_event_1
41 -- Internal function called from raise_cp_bi_event only
42 -- Sets up parameter list and raises business event
43 -------------------------------------------------------------------------
44 procedure raise_wf_bi_event_1(
45 p_event_number in number,
46 p_event_name in varchar2,
47 p_request_id in number,
48 p_requested_by in number,
49 p_program_application_id in number,
50 p_concurrent_program_id in number,
51 p_status in varchar2,
52 p_completion_text in varchar2,
53 p_time_stamp in date)
54 is
55 v_params WF_PARAMETER_LIST_T;
56 v_event_key varchar2(100);
57 v_request_id varchar2(17);
58
59 begin
60 v_request_id:=to_char(p_request_id,'FM999999999999999');
61 ------------------------------------------------
62 -- log an addparameter message --
63 ------------------------------------------------
64 if (fnd_log.level_statement >= fnd_log.g_current_runtime_level) then
65 fnd_log.string(fnd_log.level_statement,'fnd.plsql.fnd_concurrent_business_event.raise_cp_bi_event',
66 'Concurrent Manager/Request for request id '||
67 v_request_id||
68 ' is PREPARING PARAMETERS for Business Event '||
69 p_event_name);
70 end if;
71
72 ------------------------------------------------
73 -- Prepare a parameter list --
74 ------------------------------------------------
75 WF_EVENT.AddParameterToList('REQUEST_ID', to_char(p_request_id,'FM999999999999999'), v_params);
76 WF_EVENT.AddParameterToList('REQUESTED_BY', to_char(p_requested_by,'FM999999999999999'), v_params);
77 WF_EVENT.AddParameterToList('PROGRAM_APPLICATION_ID', to_char(p_program_application_id,'FM999999999999999'), v_params);
78 WF_EVENT.AddParameterToList('CONCURRENT_PROGRAM_ID', to_char(p_concurrent_program_id,'FM999999999999999'), v_params);
79 WF_EVENT.AddParameterToList('STATUS', p_status, v_params);
80 WF_EVENT.AddParameterToList('COMPLETION_TEXT', p_completion_text, v_params);
81 WF_EVENT.AddparameterToList('TIME_STAMP', to_char(p_time_stamp, 'MMDDYY HH24MISS'), v_params);
82
83 --------------------------------------------------------------------------------------
84 -- create a unique key by tailing request_id with Julian date and event number --
85 --------------------------------------------------------------------------------------
86 v_event_key := v_request_id||':'||
87 to_char(sysdate, 'YYYYMMDDHH24MISS')||':'||
88 to_char(p_event_number, 'FM09');
89
90 ------------------------------------------------
91 -- log a pre-fire message --
92 ------------------------------------------------
93 if (fnd_log.level_event >= fnd_log.g_current_runtime_level) then
94 fnd_message.set_name('FND', 'BUSINESS_EVENT_ACTION');
95 fnd_message.set_token('ACTION', 'PRE-FIRE');
96 fnd_message.set_token('REQID', v_request_id);
97 fnd_message.set_token('EVENT_NAME', p_event_name);
98 fnd_log.message(fnd_log.level_event, 'fnd.plsql.fnd_concurrent_business_event.raise_cp_bi_event', TRUE);
99 end if;
100
101 ------------------------------------------------
102 -- Raise an evnet FIRE! --
103 ------------------------------------------------
104 if (fnd_log.level_statement >= fnd_log.g_current_runtime_level) then
105 fnd_log.string(fnd_log.level_statement,'fnd.plsql.fnd_concurrent_business_event.raise_cp_bi_event',
106 'called WF_EVENT.raise with '||
107 p_event_name||' '||v_event_key||' '||'v_params');
108 end if;
109
110 WF_EVENT.raise(p_event_name,
111 v_event_key,
112 NULL,
113 v_params,
114 NULL);
115
116 ------------------------------------------------
117 -- log a post-fire message --
118 ------------------------------------------------
119 if (fnd_log.level_event >= fnd_log.g_current_runtime_level) then
120 fnd_message.set_name('FND', 'BUSINESS_EVENT_ACTION');
121 fnd_message.set_token('ACTION', 'POST-FIRE');
122 fnd_message.set_token('REQID', v_request_id);
123 fnd_message.set_token('EVENT_NAME', p_event_name);
124 fnd_log.message(fnd_log.level_event, 'fnd.plsql.fnd_concurrent_business_event.raise_cp_bi_event', TRUE);
125 end if;
126
127 end raise_wf_bi_event_1;
128
129
130 -------------------------------------------------------------------------
131 -- raise a business event
132 -------------------------------------------------------------------------
133 function raise_cp_bi_event(
134 p_request_id in number,
135 p_event_number in number,
136 p_time_stamp in date default null,
137 p_status_code in varchar2 default null)
138 return number
139 is
140 v_profile_bi_enable varchar2(2) := null;
141 v_event_enabled varchar2(1) := null;
142 v_event_map_info varchar2(50) := null;
143 v_tempcount number := 0;
144 v_tempstr varchar2(1) := null;
145 v_event_name varchar2(100) := null;
146 v_requested_by number(15);
147 v_program_application_id number(15);
148 v_concurrent_program_id number(15);
149 v_status_code varchar2(30);
150 v_time_stamp date;
151 v_completion_text varchar2(240);
152
153
154 begin
155 ---------------------------------------------------------
156 -- if business event is not enabled, get out quickly --
157 -- Retrieve CONCURRENT: Business event enable profile --
158 -- if anything other than uppercase 'Y' then get out! --
159 ---------------------------------------------------------
160 v_profile_bi_enable := fnd_profile.value('conc_bi_enable');
161 if (v_profile_bi_enable <> 'Y') then
162 return NFALSE;
163 end if;
164
165 ---------------------------------------------------------
166 -- log a debug message to indicate parameters passed --
167 ---------------------------------------------------------
168 if (fnd_log.level_statement >= fnd_log.g_current_runtime_level) then
169 fnd_log.string(fnd_log.level_statement,'fnd.plsql.fnd_concurrent_business_event.raise_cp_bi_event',
170 '--------DEBUG MESSAGE: '||
171 to_char(p_request_id,'FM999999999999999')||
172 ' for '||
173 to_char(p_event_number,'FM99'));
174 end if;
175
176 ---------------------------------------------------------
177 -- Check for obvious errors --
178 -- Exit false if necessary --
179 ---------------------------------------------------------
180 if (p_request_id IS null) then
181 return NFALSE;
182 end if;
183
184 select count(*) into v_tempcount
185 from fnd_concurrent_requests
186 where request_id = p_request_id;
187
188 if (v_tempcount <> 1) then
189 return NFALSE;
190 end if;
191
192 if ((p_event_number < request_submitted) and
193 (p_event_number > request_completed)) then
194 return NFALSE;
195 end if;
196
197 ----------------------------------------------------------
198 -- Find out if this event is enabled --
199 ----------------------------------------------------------
200 select program_application_id, concurrent_program_id
201 into v_program_application_id, v_concurrent_program_id
202 from fnd_concurrent_requests
203 where request_id = p_request_id;
204
205 select business_event_map into v_event_map_info
206 from fnd_conc_prog_onsite_info
207 where program_application_id = v_program_application_id
208 and concurrent_program_id = v_concurrent_program_id;
209
210 -- is 'Y' there at the right place for me?
211 v_tempstr:=substr(v_event_map_info, p_event_number, 1);
212
213 -----------------------------------------------------------------
214 -- if profile is enabled (and it IS if you are here...) --
215 -- and the event is set to Y then --
216 -- prep rest of the parameters and Fire! --
217 -----------------------------------------------------------------
218 if (v_tempstr='Y') then
219
220 v_event_name := parse_event_name_from_number(p_event_number);
221
222 select requested_by, program_application_id, concurrent_program_id, status_code, completion_text
223 into v_requested_by, v_program_application_id, v_concurrent_program_id, v_status_code, v_completion_text
224 from fnd_concurrent_requests
225 where request_id = p_request_id;
226
227 ---------------------------------------------------
228 -- take care of nullable parameters --
229 ---------------------------------------------------
230 if (p_time_stamp IS NULL) then -- if time stamp was not passed in parameter,
231 v_time_stamp := sysdate; -- use current sysdate
232 else
233 v_time_stamp := p_time_stamp;
234 end if;
235
236 if (p_status_code is NOT NULL) then -- passing status in parameter causes
237 v_status_code := p_status_code; -- completion status from table to be overridden
238 end if;
239
240 raise_wf_bi_event_1(p_event_number,
241 v_event_name,
242 p_request_id,
243 v_requested_by,
244 v_program_application_id,
245 v_concurrent_program_id,
246 v_status_code,
247 v_completion_text,
248 v_time_stamp);
249 else
250 return NFALSE;
251 end if;
252 return NTRUE;
253
254 ---------------------------------------------------------------
255 -- exceptions handling --
256 -- if any errors are encountered, simply return false and --
257 -- don't propagage exceptions to the caller routine --
258 ---------------------------------------------------------------
259 EXCEPTION
260 WHEN OTHERS THEN
261 return NFALSE;
262
263 end raise_cp_bi_event;
264
265
266 --------------------------------------------------------------------
267 -- change_event --
268 -- update particular event for a particular program --
269 -- this function performs COMMIT! --
270 -- for p_new_status see constants --
271 --------------------------------------------------------------------
272 function change_event(
273 p_application_id in number,
274 p_concurrent_program_id in number,
275 p_event_number in number,
276 p_new_status in varchar2)
277 return number
278 is
279 v_temp_count number;
280 v_current_state varchar2(51);
281 v_left_char varchar2(51);
282 v_right_char varchar2(51);
283 v_new_char varchar2(51);
284
285 begin
286
287 -- check for obvious errors
288 select count(*)
289 into v_temp_count
290 from fnd_conc_prog_onsite_info
291 where program_application_id = p_application_id
292 and concurrent_program_id = p_concurrent_program_id;
293
294 if (v_temp_count <> 1) then
295 return(1); -- error!
296 end if;
297
298 if ((p_event_number < 1) OR (p_event_number > 51)) then
299 return(1); -- error!
300 end if;
301
302 -- read the current state of the events padded with Ns to make up 50 positions
303 select RPAD(business_event_map, 50, 'N')
304 into v_current_state
305 from fnd_conc_prog_onsite_info
306 where program_application_id = p_application_id
307 and concurrent_program_id = p_concurrent_program_id;
308
309 -- rpad doesn't work if data was null to begin with...
310 if (v_current_state IS NULL) then
311 v_current_state:='NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN';
312 end if;
313
314 -- splice in new stautus for a given position
315 v_left_char := substr(v_current_state, 1, p_event_number - 1);
316 v_right_char := substr(v_current_state, p_event_number + 1);
317
318 v_new_char := concat(v_left_char, p_new_status);
319 v_new_char := concat(v_new_char, v_right_char);
320
321 -- update table with new status
322 update fnd_conc_prog_onsite_info
323 set business_event_map = v_new_char
324 where program_application_id = p_application_id
325 and concurrent_program_id = p_concurrent_program_id;
326
327 commit;
328
329 return(0); -- success!
330
331 end change_event;
332
333
334 --------------------------------------------------------------
335 -- enable event --
336 -- call change event to enable event --
337 -- this function performs COMMIT! --
338 --------------------------------------------------------------
339
340 function enable_event(
341 p_application_id in number,
342 p_concurrent_program_id in number,
343 p_event_number in number)
344 return number
345 is
346 v_new_status varchar2(1):='Y';
347 v_result number;
348
349 begin
350 v_result:=change_event(p_application_id, p_concurrent_program_id, p_event_number, v_new_status);
351 return v_result;
352
353 end enable_event;
354
355
356 --------------------------------------------------------------
357 -- disable event --
358 -- call change event to enable event --
359 -- this function performs COMMIT! --
360 --------------------------------------------------------------
361
362 function disable_event(
363 p_application_id in number,
364 p_concurrent_program_id in number,
365 p_event_number in number)
366 return number
367 is
368 v_new_status varchar2(1):='N';
369 v_result number;
370
371 begin
372 v_result:=change_event(p_application_id, p_concurrent_program_id, p_event_number, v_new_status);
373 return v_result;
374
375 end disable_event;
376
377
378 end fnd_concurrent_business_event;