DBA Data[Home] [Help]

PACKAGE BODY: APPS.ECX_OUT_WF_QH

Source


1 PACKAGE BODY ecx_out_wf_qh as
2 -- $Header: ECXOWFQB.pls 115.14 2004/06/01 21:19:23 mtai ship $
3 
4 
5 PROCEDURE Dequeue(p_agent_guid in RAW, p_event out NOCOPY WF_EVENT_T)
6 is
7   x_queue_name          varchar2(80);
8   x_agent_name          varchar2(30);
9   x_dequeue_options     dbms_aq.dequeue_options_t;
10   x_message_properties  dbms_aq.message_properties_t;
11   x_msgid               RAW(16);
12   x_clob                clob;
13   no_messages           exception;
14   pragma exception_init (no_messages, -25228);
15   x_ecxmsg              system.ecxmsg;
16   x_sys_guid            RAW(16);
17   x_sys_name            VARCHAR2(30);
18   x_from_agt            wf_agent_t := wf_agent_t(null,null);
19   x_to_agt              wf_agent_t := wf_agent_t(null,null);
20   l_module              varchar2(2000);
21 
22 begin
23   l_module := 'ecx.plsq.ecx_out_wf_qh.dequeue';
24   if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
25      wf_log_pkg.string(wf_log_pkg.level_procedure, l_module ||'.begin',
26         'getting queue details');
27   end if;
28 
29   select upper(queue_name), upper(name), system_guid
30   into   x_queue_name, x_agent_name, x_sys_guid
31   from   wf_agents
32   where  guid = p_agent_guid;
33 
34   if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
35      wf_log_pkg.string(wf_log_pkg.level_statement, l_module,
36         'getting system name');
37   end if;
38 
39   select upper(name)
40   into   x_sys_name
41   from   wf_systems
42   where  guid = x_sys_guid;
43 
44   x_from_agt := wf_agent_t(x_agent_name, x_sys_name);
45   x_to_agt := wf_agent_t(x_agent_name, x_sys_name);
46 
47   wf_event_t.initialize(p_event);
48 
49   x_dequeue_options.wait := dbms_aq.no_wait;
50   x_dequeue_options.navigation    := ecx_out_wf_qh.navigation;
51 
52   begin
53     dbms_aq.dequeue
54         (
55         queue_name              => x_queue_name,
56         dequeue_options         => x_dequeue_options,
57         message_properties      => x_message_properties,
58         payload                 => x_ecxmsg,
59         msgid                   => x_msgid
60         );
61 
62     ecx_out_wf_qh.navigation := dbms_aq.next_message;
63 
64     p_event.priority := 1;
65     p_event.event_name := 'oracle.apps.ecx.inbound.message.receive';
66     p_event.event_key := x_ecxmsg.document_number;
67     p_event.from_agent := x_from_agt ;
68     p_event.to_agent := x_to_agt ;
69     p_event.error_subscription := null;
70     p_event.error_message := null;
71     p_event.error_stack := null;
72 
73     if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
74        wf_log_pkg.string(wf_log_pkg.level_statement, l_module,
75           'setting message props');
76     end if;
77 
78   --p_event.AddParameterToList('ECX_MSGID', x_msgid);
79     p_event.AddParameterToList('TRANSACTION_TYPE', x_ecxmsg.transaction_type);
80     p_event.AddParameterToList('TRANSACTION_SUBTYPE', x_ecxmsg.transaction_subtype);
81     p_event.AddParameterToList('MESSAGE_STANDARD', x_ecxmsg.message_standard);
82     p_event.AddParameterToList('MESSAGE_TYPE', x_ecxmsg.message_type);
83     p_event.AddParameterToList('DOCUMENT_NUMBER', x_ecxmsg.document_number);
84     p_event.AddParameterToList('PARTYID', x_ecxmsg.partyid);
85     p_event.AddParameterToList('PARTY_SITE_ID', x_ecxmsg.party_site_id);
86     p_event.AddParameterToList('PROTOCOL_TYPE', x_ecxmsg.protocol_type);
87     p_event.AddParameterToList('PROTOCOL_ADDRESS', x_ecxmsg.protocol_ADDRESS);
88     p_event.AddParameterToList('USERNAME', x_ecxmsg.username);
89     p_event.AddParameterToList('PASSWORD', x_ecxmsg.password);
90     p_event.AddParameterToList('ATTRIBUTE1', x_ecxmsg.attribute1);
91     p_event.AddParameterToList('ATTRIBUTE2', x_ecxmsg.attribute2);
92     p_event.AddParameterToList('ATTRIBUTE3', x_ecxmsg.attribute3);
93     p_event.AddParameterToList('ATTRIBUTE4', x_ecxmsg.attribute4);
94     p_event.AddParameterToList('ATTRIBUTE5', x_ecxmsg.attribute5);
95 
96     if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
97        wf_log_pkg.string(wf_log_pkg.level_statement, l_module,
98           'setting payload');
99     end if;
100     p_event.setEventData(x_ecxmsg.payload);
101 
102   exception
103     when no_messages then
104       if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
105         wf_log_pkg.string(wf_log_pkg.level_statement, l_module,
106            'No more messages in dequeue.');
107       end if;
108       ecx_out_wf_qh.navigation := dbms_aq.first_message;
109       p_event := NULL;
110       return;
111   end;
112 
113 exception
114    when others then
115      Wf_Core.Context('ECX_OUT_WF_QH', 'Dequeue', x_queue_name);
116      raise;
117 end Dequeue;
118 
119 
120 /**
121   This procedure traverses through all the parameters in wf_event_t object, constructs the
122   system.ecxmsg object and returns these to the caller procedure
123 **/
124 procedure create_ecxmsg(p_event   in wf_event_t,
125                         x_ecxmsg  in out NOCOPY SYSTEM.ecxmsg
126                         )
127 is
128 
129   i_param_list          wf_parameter_list_t;
130   i_param_name          varchar2(2000);
131   i_param_value         varchar2(2000);
132   i_password            ecx_tp_details.password%TYPE;
133   m_password            ecx_tp_details.password%TYPE;
134   l_module              varchar2(2000);
135 
136 begin
137 
138   l_module := 'ecx.plsql.ecx_out_wf_qh.enqueue.create_ecxmsg';
139   -- loop through the parameter list and construct x_ecxmsg object
140   i_param_list := p_event.getParameterList();
141   if (i_param_list is null) then
142      if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
143         wf_log_pkg.string(wf_log_pkg.level_statement, l_module,
144                           'event object parameter list in empty');
145      end if;
146 
147      --MLS ecx_out_wf_qh.retmsg := 'Parameter List cannot be null';
148      ecx_out_wf_qh.retmsg :='ECX_PARAM_LIST_NOT_NULL';
149      ecx_out_wf_qh.retcode := 2;
150      raise queue_handler_exit;
151   else
152     x_ecxmsg  := SYSTEM.ecxmsg(null, null, null, null, null, null, null, null, null,
153                                null, null, null, null, null, null, null, null, null);
154     for i in i_param_list.first..i_param_list.last loop
155       i_param_name := i_param_list(i).GetName;
156       i_param_value := i_param_list(i).GetValue;
157 
158       if i_param_name = 'MESSAGE_TYPE' then
159         x_ecxmsg.message_type := i_param_value;
160 
161       elsif i_param_name = 'MESSAGE_STANDARD' then
162         x_ecxmsg.message_standard := i_param_value;
163 
164       elsif i_param_name = 'TRANSACTION_TYPE' then
165         x_ecxmsg.transaction_type := i_param_value;
166 
167       elsif i_param_name = 'TRANSACTION_SUBTYPE' then
168         x_ecxmsg.transaction_subtype := i_param_value;
169 
170       elsif i_param_name = 'DOCUMENT_NUMBER' then
171         x_ecxmsg.document_number := i_param_value;
172 
173       elsif i_param_name = 'PARTY_TYPE' then
174         x_ecxmsg.party_type := i_param_value;
175 
176       elsif i_param_name = 'PARTYID' then
177         x_ecxmsg.partyid := i_param_value;
178 
179       elsif i_param_name = 'PARTY_SITE_ID' then
180         x_ecxmsg.party_site_id := i_param_value;
181 
182       elsif i_param_name = 'PROTOCOL_TYPE' then
183         x_ecxmsg.protocol_type := i_param_value;
184 
185       elsif i_param_name = 'PROTOCOL_ADDRESS' then
186         x_ecxmsg.protocol_address := i_param_value;
187 
188       elsif i_param_name = 'USERNAME' then
189         x_ecxmsg.username := i_param_value;
190 
191       elsif i_param_name = 'PASSWORD' then
192         x_ecxmsg.password := i_param_value;
193 
194       elsif i_param_name = 'ATTRIBUTE1' then
195         x_ecxmsg.attribute1 := i_param_value;
196 
197       elsif i_param_name = 'ATTRIBUTE2' then
198         x_ecxmsg.attribute2 := i_param_value;
199 
200       elsif i_param_name = 'ATTRIBUTE3' then
201         x_ecxmsg.attribute3 := i_param_value;
202 
203       elsif i_param_name = 'ATTRIBUTE4' then
204         x_ecxmsg.attribute4 := i_param_value;
205 
206       elsif i_param_name = 'ATTRIBUTE5' then
207         x_ecxmsg.attribute5 := i_param_value;
208       end if;
209     end loop;
210   end if;
211 
212   if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
213      wf_log_pkg.string(wf_log_pkg.level_statement, l_module,
214         'setting payload');
215   end if;
216   x_ecxmsg.payload := p_event.getEventData();
217 
218 exception
219   when queue_handler_exit then
220     raise queue_handler_exit;
221   when others then
222     ecx_out_wf_qh.retmsg := SQLERRM;
223     ecx_out_wf_qh.retcode := 2;
224     raise queue_handler_exit;
225 end create_ecxmsg;
226 
227 
228 /**
229   This procedure enqueues the message on ecx_outqueue and returns the msgid of this message
230 **/
231 procedure enqueue_msg(
232                       x_out_queue		in varchar2,
233                       i_protocol_type 		in out NOCOPY varchar2,
234                       x_ecxmsg			in out NOCOPY SYSTEM.ecxmsg,
235                       x_msgid                   out NOCOPY raw
236 		      )
237 is
238   x_enqueue_options     dbms_aq.enqueue_options_t;
239   x_message_properties  dbms_aq.message_properties_t;
240   l_in_clob             clob;
241   l_out_clob            clob;
242   l_module              varchar2(2000);
243 
244 begin
245 
246   l_module := 'ecx.plsq.ecx_out_wf_qh.enqueue.enqueue_msg';
247   if ( (i_protocol_type = 'HTTP-WM') or (i_protocol_type = 'HTTPS-WM') ) then
248      x_message_properties.correlation := 'WEBMETHODS' ;
249   elsif ((i_protocol_type = 'HTTP') or (i_protocol_type = 'HTTP-OXTA') or
250          (i_protocol_type = 'HTTPS') or (i_protocol_type = 'HTTPS-OXTA') or
251          (i_protocol_type = 'HTTP-ATCH') or (i_protocol_type = 'HTTPS-ATCH') or
252          (i_protocol_type = 'OTAH-ATCH') or (i_protocol_type = 'OTAHS-ATCH') or
253          (i_protocol_type = 'SMTP')) then
254     x_message_properties.correlation := 'OXTA';
255   else
256     x_message_properties.correlation := i_protocol_type;
257   end if;
258 
259   if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
260      wf_log_pkg.string(wf_log_pkg.level_statement, l_module,
261         'Correlation id: '|| x_message_properties.correlation);
262   end if;
263 
264   l_in_clob := x_ecxmsg.payload;
265   ecx_eng_utils.convertEncryCodeClob(l_in_clob, l_out_clob);
266   x_ecxmsg.payload := l_out_clob;
267 
268   DBMS_AQ.ENQUEUE
269   (
270  	queue_name          => x_out_queue,
271         enqueue_options     => x_enqueue_options,
272    	message_properties  => x_message_properties,
273    	payload             => x_ecxmsg,
274    	msgid               => x_msgid
275   );
276 
277   -- assign the encrpyted clob back to x_ecxmsg so it will insert the
278   -- encrpyted clob to ecx_doclogs later.
279   x_ecxmsg.payload := l_in_clob;
280 
281   if dbms_lob.istemporary(l_out_clob) = 1 then
282      dbms_lob.freetemporary(l_out_clob);
283   end if;
284 
285   if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
286      wf_log_pkg.string(wf_log_pkg.level_statement, l_module,
287         'Enqueued Message: ' || x_msgid);
288   end if;
289 exception
290   when queue_handler_exit then
291     if dbms_lob.istemporary(l_out_clob) = 1 then
292        dbms_lob.freetemporary(l_out_clob);
293     end if;
294     raise queue_handler_exit;
295 
296   when others then
297     if dbms_lob.istemporary(l_out_clob) = 1 then
298        dbms_lob.freetemporary(l_out_clob);
299     end if;
300     ecx_out_wf_qh.retmsg := SQLERRM;
301     ecx_out_wf_qh.retcode := 2;
302     raise queue_handler_exit;
303 end enqueue_msg;
304 
305 
306 PROCEDURE Enqueue(p_event              in wf_event_t,
307                   p_out_agent_override in wf_agent_t )
308 is
309 
310   x_out_agent_name      varchar2(30);
311   x_out_system_name     varchar2(30);
312   x_to_agent_name       varchar2(30);
313   x_to_system_name      varchar2(30);
314   x_out_queue           varchar2(80);
315   x_to_queue            varchar2(80);
316   x_msgid               RAW(16);
317   x_ecxmsg		SYSTEM.ecxmsg;
318   l_module              varchar2(2000);
319 
320   cursor c1
321   is
322   select  ecx_trigger_id_s.NEXTVAL
323   from    dual;
324 
325 begin
326   l_module := 'ecx.plsql.ecx_out_wf_qh.enqueue';
327   if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
328      wf_log_pkg.string(wf_log_pkg.level_procedure, l_module ||'.begin',
329         'Enqueue Message');
330   end if;
331 
332   -- reset global variables
333   retmsg := null;
334   retcode := 0;
335   msgid := null;
336 
337   -- Determine the out queue
338   if (p_out_agent_override is not null) then
339     x_out_agent_name := p_out_agent_override.GetName();
340     x_out_system_name := p_out_agent_override.GetSystem();
341   else
342     x_out_agent_name := p_event.GetFromAgent().GetName();
343     x_out_system_name := p_event.GetFromAgent().GetSystem();
344   end if;
345 
346   select agt.queue_name into x_out_queue
347   from   wf_agents  agt,
348          wf_systems sys
349   where  agt.name = x_out_agent_name
350   and    sys.name = x_out_system_name
351   and    sys.guid = agt.system_guid;
352 
353   create_ecxmsg (p_event, x_ecxmsg);
354 
355   -- enqueue the message
356   ecx_out_wf_qh.enqueue_msg(
357                            x_out_queue		=> x_out_queue,
358                            i_protocol_type 	=> x_ecxmsg.protocol_type,
359                            x_ecxmsg		=> x_ecxmsg,
360                            x_msgid 		=> x_msgid
361                            );
362 
363   -- set msgid
364   ecx_out_wf_qh.msgid := x_msgid;
365   wf_event.g_msgid := x_msgid;
366 
367   if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
368      wf_log_pkg.string(wf_log_pkg.level_statement, l_module,
369         'Enqueue Message Successfully');
370   end if;
371 
372 /*
373     -- set the msgid in the item attribute if it is not a passthrough transaction.
374     if (not i_passthr) then
375       if (i_activity_id is not null)
376       then
377         begin
378           wf_engine.SetItemAttrText(i_item_type, i_item_key, 'ECX_MSGID_ATTR', x_msgid);
379         exception
380         when others then
381           -- If attr is not already defined, add a runtime attribute
382           -- with this name, then try the set again.
383           if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
384             wf_log_pkg.string(wf_log_pkg.level_statement, l_module,
385               'ECX_MSGID_ATTR is not defined!');
386           end if;
387           if (wf_core.error_name = 'WFENG_ITEM_ATTR') then
388             wf_core.clear;
389             wf_engine.AddItemAttr(itemtype => i_item_type,
390                         itemkey => i_item_key,
391                         aname => 'ECX_MSGID_ATTR',
392                         text_value => x_msgid);
393             if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
394               wf_log_pkg.string(wf_log_pkg.level_statement, l_module,
395                  'Created and set ECX_MSGID_ATTR ');
396             end if;
397             WF_CORE.Clear;
398           else
399             raise;
400           end if;
401         end;
402       end if;
403 */
404 exception
405   when queue_handler_exit then
406     wf_core.context('ECX_OUT_WF_QH', 'Enqueue', x_out_queue, ecx_debug.getMessage(ecx_out_wf_qh.retmsg,
407                      ecx_utils.i_errparams), ecx_out_wf_qh.retcode);
408     raise;
409 
410   when others then
411     ecx_out_wf_qh.retmsg := SQLERRM;
412     ecx_out_wf_qh.retcode := 2;
413     raise queue_handler_exit;
414 end Enqueue;
415 
416 end ECX_OUT_WF_QH;
417