1 Package Body irc_ido_ins as
2 /* $Header: iridorhi.pkb 120.5.12010000.2 2008/09/26 13:55:20 pvelugul ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' irc_ido_ins.'; -- Global package name
9 --
10 -- The following global variables are only to be used by
11 -- the set_base_key_value and pre_insert procedures.
12 --
13 g_document_id_i number default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19 (p_document_id in number) is
20 --
21 l_proc varchar2(72) := g_package||'set_base_key_value';
22 --
23 Begin
24 hr_utility.set_location('Entering:'||l_proc, 10);
25 --
26 irc_ido_ins.g_document_id_i := p_document_id;
27 --
28 hr_utility.set_location(' Leaving:'||l_proc, 20);
29 End set_base_key_value;
30 --
31 --
32 -- ----------------------------------------------------------------------------
33 -- |------------------------------< insert_dml >------------------------------|
34 -- ----------------------------------------------------------------------------
35 -- {Start Of Comments}
36 --
37 -- Description:
38 -- This procedure controls the actual dml insert logic. The processing of
39 -- this procedure are as follows:
40 -- 1) Initialise the object_version_number to 1 if the object_version_number
41 -- is defined as an attribute for this entity.
42 -- 2) To set and unset the g_api_dml status as required (as we are about to
43 -- perform dml).
44 -- 3) To insert the row into the schema.
45 -- 4) To trap any constraint violations that may have occurred.
46 -- 5) To raise any other errors.
47 --
48 -- Prerequisites:
49 -- This is an internal private procedure which must be called from the ins
50 -- procedure and must have all mandatory attributes set (except the
51 -- object_version_number which is initialised within this procedure).
52 --
53 -- In Parameters:
54 -- A Pl/Sql record structre.
55 --
56 -- Post Success:
57 -- The specified row will be inserted into the schema.
58 --
59 -- Post Failure:
60 -- On the insert dml failure it is important to note that we always reset the
61 -- g_api_dml status to false.
62 -- If a check, unique or parent integrity constraint violation is raised the
63 -- constraint_error procedure will be called.
64 -- If any other error is reported, the error will be raised after the
65 -- g_api_dml status is reset.
66 --
67 -- Developer Implementation Notes:
68 -- None.
69 --
70 -- Access Status:
71 -- Internal Row Handler Use Only.
72 --
73 -- {End Of Comments}
74 -- ----------------------------------------------------------------------------
75 Procedure insert_dml
76 (p_rec in out nocopy irc_ido_shd.g_rec_type
77 ) is
78 --
79 l_proc varchar2(72) := g_package||'insert_dml';
80 --
81 Begin
82 hr_utility.set_location('Entering:'||l_proc, 5);
83 p_rec.object_version_number := 1; -- Initialise the object version
84 --
85 irc_ido_shd.g_api_dml := true; -- Set the api dml status
86 --
87 --
88 -- Insert the row into: irc_documents
89 --
90 insert into irc_documents
91 (document_id
92 ,party_id
93 ,person_id
94 ,assignment_id
95 ,character_doc
96 ,binary_doc
97 ,file_name
98 ,file_format
99 ,mime_type
100 ,description
101 ,type
102 ,parsed_xml
103 ,object_version_number
104 ,end_date
105 )
106 Values
107 (p_rec.document_id
108 ,p_rec.party_id
109 ,p_rec.person_id
110 ,p_rec.assignment_id
111 ,empty_clob()
112 ,empty_blob()
113 ,p_rec.file_name
114 ,p_rec.file_format
115 ,p_rec.mime_type
116 ,p_rec.description
117 ,p_rec.type
118 ,empty_clob()
119 ,p_rec.object_version_number
120 ,p_rec.end_date
121 );
122 --
123 irc_ido_shd.g_api_dml := false; -- Unset the api dml status
124 --
125 --
126 hr_utility.set_location(' Leaving:'||l_proc, 10);
127 Exception
128 When hr_api.check_integrity_violated Then
129 -- A check constraint has been violated
130 irc_ido_shd.g_api_dml := false; -- Unset the api dml status
131 --
132 irc_ido_shd.constraint_error
133 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
134 When hr_api.parent_integrity_violated Then
135 -- Parent integrity has been violated
136 irc_ido_shd.g_api_dml := false; -- Unset the api dml status
137 --
138 irc_ido_shd.constraint_error
139 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
140 When hr_api.unique_integrity_violated Then
141 -- Unique integrity has been violated
142 irc_ido_shd.g_api_dml := false; -- Unset the api dml status
143 --
144 irc_ido_shd.constraint_error
145 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
146 When Others Then
147 --
148 irc_ido_shd.g_api_dml := false; -- Unset the api dml status
149 Raise;
150 End insert_dml;
151 --
152 -- ----------------------------------------------------------------------------
153 -- |------------------------------< pre_insert >------------------------------|
154 -- ----------------------------------------------------------------------------
155 -- {Start Of Comments}
156 --
157 -- Description:
158 -- This private procedure contains any processing which is required before
159 -- the insert dml. Presently, if the entity has a corresponding primary
160 -- key which is maintained by an associating sequence, the primary key for
161 -- the entity will be populated with the next sequence value in
162 -- preparation for the insert dml.
163 --
164 -- Prerequisites:
165 -- This is an internal procedure which is called from the ins procedure.
166 --
167 -- In Parameters:
168 -- A Pl/Sql record structure.
169 --
170 -- Post Success:
171 -- Processing continues.
172 --
173 -- Post Failure:
174 -- If an error has occurred, an error message and exception will be raised
175 -- but not handled.
176 --
177 -- Developer Implementation Notes:
178 -- Any pre-processing required before the insert dml is issued should be
179 -- coded within this procedure. As stated above, a good example is the
180 -- generation of a primary key number via a corresponding sequence.
181 -- It is important to note that any 3rd party maintenance should be reviewed
182 -- before placing in this procedure.
183 --
184 -- Access Status:
185 -- Internal Row Handler Use Only.
186 --
187 -- {End Of Comments}
188 -- ----------------------------------------------------------------------------
189 Procedure pre_insert
190 (p_rec in out nocopy irc_ido_shd.g_rec_type
191 ) is
192 --
193 Cursor C_Sel1 is select irc_documents_s.nextval from sys.dual;
194 --
195 Cursor C_Sel2 is
196 Select null
197 from irc_documents
198 where document_id =
199 irc_ido_ins.g_document_id_i;
200 --
201 l_proc varchar2(72) := g_package||'pre_insert';
202 l_exists varchar2(1);
203 --
204 Begin
205 hr_utility.set_location('Entering:'||l_proc, 5);
206 --
207 If (irc_ido_ins.g_document_id_i is not null) Then
208 --
209 -- Verify registered primary key values not already in use
210 --
211 Open C_Sel2;
212 Fetch C_Sel2 into l_exists;
213 If C_Sel2%found Then
214 Close C_Sel2;
215 --
216 -- The primary key values are already in use.
217 --
218 fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
219 fnd_message.set_token('TABLE_NAME','irc_documents');
220 fnd_message.raise_error;
221 End If;
222 Close C_Sel2;
223 --
224 -- Use registered key values and clear globals
225 --
226 p_rec.document_id :=
227 irc_ido_ins.g_document_id_i;
228 irc_ido_ins.g_document_id_i := null;
229 Else
230 --
231 -- No registerd key values, so select the next sequence number
232 --
233 --
234 -- Select the next sequence number
235 --
236 Open C_Sel1;
237 Fetch C_Sel1 Into p_rec.document_id;
238 Close C_Sel1;
239 End If;
240 --
241 -- Derive file_format from MIME type
242 --
243 if (p_rec.mime_type = 'text/html') OR
244 (p_rec.mime_type = 'text/xml') then
245 p_rec.file_format := 'TEXT';
246 else
247 p_rec.file_format := 'BINARY';
248 end if;
249 --
250 hr_utility.set_location(' Leaving:'||l_proc, 10);
251 End pre_insert;
252 --
253 -- ----------------------------------------------------------------------------
254 -- |-----------------------------< post_insert >------------------------------|
255 -- ----------------------------------------------------------------------------
256 -- {Start Of Comments}
257 --
258 -- Description:
259 -- This private procedure contains any processing which is required after
260 -- the insert dml.
261 --
262 -- Prerequisites:
263 -- This is an internal procedure which is called from the ins procedure.
264 --
265 -- In Parameters:
266 -- A Pl/Sql record structre.
267 --
268 -- Post Success:
269 -- Processing continues.
270 --
271 -- Post Failure:
272 -- If an error has occurred, an error message and exception will be raised
273 -- but not handled.
274 --
275 -- Developer Implementation Notes:
276 -- Any post-processing required after the insert dml is issued should be
277 -- coded within this procedure. It is important to note that any 3rd party
278 -- maintenance should be reviewed before placing in this procedure.
279 --
280 -- Access Status:
281 -- Internal Row Handler Use Only.
282 --
283 -- {End Of Comments}
284 -- ----------------------------------------------------------------------------
285 Procedure post_insert
286 (p_effective_date in date
287 ,p_rec in irc_ido_shd.g_rec_type
288 ) is
289 --
290 l_proc varchar2(72) := g_package||'post_insert';
291 --
292 Begin
293 hr_utility.set_location('Entering:'||l_proc, 5);
294 begin
295 --
296 irc_ido_rki.after_insert
297 (p_effective_date => p_effective_date
298 ,p_document_id
299 => p_rec.document_id
300 ,p_party_id
301 => p_rec.party_id
302 ,p_person_id => p_rec.person_id
303 ,p_assignment_id
304 => p_rec.assignment_id
305 ,p_file_name
306 => p_rec.file_name
307 ,p_file_format
308 => p_rec.file_format
309 ,p_mime_type
310 => p_rec.mime_type
311 ,p_description
312 => p_rec.description
313 ,p_type
314 => p_rec.type
315 ,p_object_version_number
316 => p_rec.object_version_number
317 ,p_end_date
318 => p_rec.end_date
319 );
320 --
321 exception
322 --
323 when hr_api.cannot_find_prog_unit then
324 --
325 hr_api.cannot_find_prog_unit_error
326 (p_module_name => 'IRC_DOCUMENTS'
327 ,p_hook_type => 'AI');
328 --
329 end;
330 --
331 hr_utility.set_location(' Leaving:'||l_proc, 10);
332 End post_insert;
333 --
334 -- ----------------------------------------------------------------------------
335 -- |---------------------------------< ins >----------------------------------|
336 -- ----------------------------------------------------------------------------
337 Procedure ins
338 (p_effective_date in date
339 ,p_rec in out nocopy irc_ido_shd.g_rec_type
340 ) is
341 --
342 l_proc varchar2(72) := g_package||'ins';
343 --
344 Begin
345 hr_utility.set_location('Entering:'||l_proc, 5);
346 --
347 -- Call the supporting insert validate operations
348 --
349 irc_ido_bus.insert_validate
350 (p_effective_date
351 ,p_rec
352 );
353 --
354 -- Call the supporting pre-insert operation
355 --
356 irc_ido_ins.pre_insert(p_rec);
357 --
358 -- Insert the row
359 --
360 irc_ido_ins.insert_dml(p_rec);
361 --
362 -- Call the supporting post-insert operation
363 --
364 irc_ido_ins.post_insert
365 (p_effective_date
366 ,p_rec
367 );
368 --
369 hr_utility.set_location('Leaving:'||l_proc, 20);
370 end ins;
371 --
372 -- ----------------------------------------------------------------------------
373 -- |---------------------------------< ins >----------------------------------|
374 -- ----------------------------------------------------------------------------
375 Procedure ins
376 (p_effective_date in date
377 ,p_person_id in number
378 ,p_mime_type in varchar2
379 ,p_type in varchar2
380 ,p_assignment_id in number default null
381 ,p_character_doc in clob default empty_clob()
382 ,p_file_name in varchar2 default null
383 ,p_description in varchar2 default null
384 ,p_parsed_xml in clob default empty_clob()
385 ,p_end_date in date default null
386 ,p_document_id out nocopy number
387 ,p_object_version_number out nocopy number
388 ) is
389 --
390 l_rec irc_ido_shd.g_rec_type;
391 l_proc varchar2(72) := g_package||'ins';
392 --
393 Begin
394 hr_utility.set_location('Entering:'||l_proc, 5);
395 --
396 -- Call conversion function to turn arguments into the
397 -- p_rec structure.
398 --
399 l_rec :=
400 irc_ido_shd.convert_args
401 (null
402 ,null
403 ,p_person_id
404 ,p_assignment_id
405 ,p_character_doc
406 ,p_file_name
407 ,p_mime_type
408 ,p_description
409 ,p_type
410 ,p_parsed_xml
411 ,null
412 ,p_end_date
413 );
414 --
415 -- Having converted the arguments into the irc_ido_rec
416 -- plsql record structure we call the corresponding record business process.
417 --
418 irc_ido_ins.ins
419 (p_effective_date
420 ,l_rec
421 );
422 --
423 -- As the primary key argument(s)
424 -- are specified as an OUT's we must set these values.
425 --
426 p_document_id := l_rec.document_id;
427 p_object_version_number := l_rec.object_version_number;
428 --
429 hr_utility.set_location(' Leaving:'||l_proc, 10);
430 End ins;
431 --
432 end irc_ido_ins;