[Home] [Help]
PACKAGE BODY: APPS.OKE_PRINT_CONTRACT_WF
Source
1 PACKAGE BODY OKE_PRINT_CONTRACT_WF AS
2 /* $Header: OKEWCPPB.pls 120.2.12020000.2 2012/07/25 17:36:00 vgujarat ship $ */
3
4 --
5 -- Global Variables
6 --
7 EventName VARCHAR2(240) := NULL;
8 l_Item_Key VARCHAR2(1000) := 'DEFAULT';
9 --
10 -- Private Procedures and Functions
11 --
12 PROCEDURE GetEventName
13 ( ItemType IN VARCHAR2
14 , ItemKey IN VARCHAR2
15 ) IS
16
17 BEGIN
18
19 EventName := WF_ENGINE.GetItemAttrText
20 ( ItemType => ItemType
21 , ItemKey => ItemKey
22 , AName => 'ECX_EVENT_NAME' );
23
24 END GetEventName;
25
26 PROCEDURE Raise_Business_Event
27 ( P_Header_ID IN VARCHAR2
28 , P_Major_Version IN NUMBER
29 , X_Item_Key OUT NOCOPY VARCHAR2
30 ) IS
31
32 l_xmldocument varchar2(30000);
33 l_eventdata clob;
34 --l_message varchar2(10);
35 MapCode VARCHAR2(30);
36 TxnType VARCHAR2(30) := 'ECX';
37 EventName VARCHAR2(80) := 'oracle.apps.oke.documents.contract.print';
38 ParamList wf_parameter_list_t := wf_parameter_list_t();
39
40 l_latest_version NUMBER; -- The latest version number of the contract
41 l_org_id NUMBER; -- for MOAC
42
43
44 cursor c_version is
45 select max(major_version)
46 from oke_k_headers_hv
47 where k_header_id =P_Header_id;
48
49 cursor c_org is
50 select authoring_org_id
51 from oke_k_headers_v
52 where k_header_id =P_Header_id;
53
54
55 BEGIN
56
57 OPEN c_version;
58 FETCH c_version INTO l_latest_version;
59 CLOSE c_version;
60
61 OPEN c_org;
62 FETCH c_org INTO l_org_id;
63 CLOSE c_org;
64
65 IF P_Major_Version<=l_latest_version THEN
66 MapCode :='OKE_K_PRINT_H_OUT';
67 ELSE
68 MapCode :='OKE_K_PRINT_OUT';
69 END IF;
70
71
72 --
73 -- Building Parameter List
74 --
75 wf_event.AddParameterToList( p_name => 'ECX_MAP_CODE'
76 , p_value => MapCode
77 , p_parameterList => ParamList );
78
79 wf_event.AddParameterToList( p_name => 'ECX_TRANSACTION_TYPE'
80 , p_value => TxnType
81 , p_parameterList => ParamList );
82
83 wf_event.AddParameterToList( p_name => 'ECX_DOCUMENT_ID'
84 , p_value => P_Header_id
85 , p_parameterList => ParamList );
86
87 wf_event.AddParameterToList( p_name => 'ECX_PARAMETER1'
88 , p_value => P_Header_ID
89 , p_parameterList => ParamList );
90
91 wf_event.AddParameterToList( p_name => 'ECX_PARAMETER2'
92 , p_value => P_Major_Version
93 , p_parameterList => ParamList );
94
95 wf_event.AddParameterToList( p_name => 'ORG_ID'
96 , p_value => l_org_id
97 , p_parameterList => ParamList );
98
99
100 IF ( OKE_UTILS.Debug_Mode = 'Y' ) THEN
101 wf_event.AddParameterToList( p_name => 'ECX_DEBUG_LEVEL'
102 , p_value => '0'
103 , p_parameterList => ParamList );
104 END IF;
105
106 --
107 -- Raise Event
108 --
109
110 wf_event.Raise( p_event_name => EventName
111 , p_event_key => to_char(sysdate , 'YYYYMMDD HH24MISS')
112 , p_parameters => ParamList );
113
114 ParamList.DELETE;
115
116 X_Item_Key := l_Item_Key;
117
118
119 commit;
120
121 exception
122 when others then
123 null;
124
125 END;
126
127 --
128 -- Public Procedures
129 --
130 PROCEDURE Initialize
131 ( ItemType IN VARCHAR2
132 , ItemKey IN VARCHAR2
133 , ActID IN NUMBER
134 , FuncMode IN VARCHAR2
135 , ResultOut OUT NOCOPY VARCHAR2
136 ) IS
137
138
139 BEGIN
140
141 IF ( FuncMode = 'RUN' ) THEN
142 --
143 -- Getting the event name from the Workflow attribute
144 --
145 GetEventName( ItemType , ItemKey );
146
147 --
148 -- The URL should be generic for all types of documents.
149 -- Perform this action before form specific initializations
150 -- so it is possible to override the result on a form-by-form
151 -- basis.
152 --
153 WF_ENGINE.SetItemAttrText
154 ( ItemType => ItemType
155 , ItemKey => ItemKey
156 , AName => 'DOCUMENT_URL'
157 , AValue => wfa_html.base_url ||
158 '/Wf_Event_Html.EventDataContents?' ||
159 'P_EventAttribute=ECX_EVENT_MESSAGE&' ||
160 'P_ItemType=' || ItemType || '&' ||
161 'P_ItemKey=' || replace(ItemKey , ' ' , '+')
162 );
163
164
165 l_Item_Key := 'P_ItemKey=' || replace(ItemKey , ' ' , '+');
166
167
168
169 ResultOut := 'COMPLETE:';
170 RETURN;
171
172 END IF;
173
174 IF ( FuncMode = 'CANCEL' ) THEN
175 ResultOut := '';
176 RETURN;
177 END IF;
178
179 IF ( FuncMode = 'TIMEOUT' ) THEN
180 ResultOut := '';
181 RETURN;
182 END IF;
183
184 EXCEPTION
185 WHEN OTHERS THEN
186 ResultOut := 'ERROR:';
187 WF_Core.Context
188 ( 'OKE_PRINT_CONTRACT_WF'
189 , 'INITIALIZE'
190 , ItemType
191 , ItemKey
192 , to_char(ActID)
193 , FuncMode
194 , ResultOut );
195 RAISE;
196
197 END Initialize;
198
199 FUNCTION getEventData
200 ( p_itemType IN VARCHAR2
201 , p_itemKey IN VARCHAR2
202 )RETURN CLOB IS
203
204 l_event_t wf_event_t;
205 l_eventdata clob;
206 l_eventdata_utf clob;
207
208 l_temp_art_text VARCHAR2(10000);
209 l_max_read_amount BINARY_INTEGER := 3333;
210 l_read_start_position INTEGER:= 1;
211 l_tag_end_position NUMBER := -99;
212 l_amount_left_to_read Number := 0;
213 l_eventData_length INTEGER;
214
215 buf VARCHAR2(10000);
216
217 BEGIN
218
219 -- Get Data from WF
220 wf_event_t.Initialize(l_event_t);
221 l_event_t :=wf_engine.GetItemAttrEvent(
222 itemType => p_itemType,
223 itemKey => p_itemKey,
224 name =>'ECX_EVENT_MESSAGE');
225 l_eventData :=l_event_t.GetEventData();
226
227
228 -- Init the clob and add utf 8 encoding
229 -- The clob content will get converted to UTF-8 in okePrintContract.jsp
230 l_eventdata_utf := to_clob('<?xml version=''1.0'' encoding=''utf-8''?>');
231
232 -- Find the xml declaration ending point.
233 l_max_read_amount := 3333;
234 dbms_lob.read (l_eventData, l_max_read_amount, 1, l_temp_art_text);-- dbms_lob returns in chars
235 l_tag_end_position := InStr(l_temp_art_text,'?>',1);
236 l_read_start_position := l_tag_end_position+2;
237
238
239 -- Read 3333 bytes from the l_tag_end_position+1 at a stretch and write to the utf clob.
240 l_eventData_length := DBMS_LOB.GETLENGTH(l_eventData);
241 l_amount_left_to_read := l_eventData_length-l_tag_end_position;
242
243 while (l_amount_left_to_read > 0 ) LOOP
244
245 IF l_amount_left_to_read > 3333 THEN
246 dbms_lob.read (l_eventData, l_max_read_amount, l_read_start_position, buf);-- dbms_lob returns in chars
247 l_amount_left_to_read := l_amount_left_to_read-l_max_read_amount;
248 l_read_start_position := l_read_start_position+l_max_read_amount;
249 ELSE
250 dbms_lob.read (l_eventData, l_amount_left_to_read, l_read_start_position, buf);-- dbms_lob returns in chars
251 l_amount_left_to_read := 0;
252 END IF;
253 dbms_lob.writeappend(l_eventData_utf,Length(buf), buf);
254 END LOOP;
255
256 return l_eventData_utf;
257 EXCEPTION
258 WHEN OTHERS THEN
259 RAISE;
260 END getEventData;
261
262 END OKE_PRINT_CONTRACT_WF;