1 Package Body ame_rul_upd as
2 /* $Header: amrulrhi.pkb 120.6 2006/02/14 01:23 vboggava noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' ame_rul_upd.'; -- Global package name
9 --
10 -- ----------------------------------------------------------------------------
11 -- |----------------------------< dt_update_dml >-----------------------------|
12 -- ----------------------------------------------------------------------------
13 -- {Start Of Comments}
14 --
15 -- Description:
16 -- This procedure controls the execution of dml from the datetrack mode
17 -- of CORRECTION only. It is important to note that the object version
18 -- number is only increment by 1 because the datetrack correction is
19 -- soley for one datetracked row.
20 -- This procedure controls the actual dml update logic. The functions of
21 -- this procedure are as follows:
22 -- 1) Get the next object_version_number.
23 -- 2) To set and unset the g_api_dml status as required (as we are about to
24 -- perform dml).
25 -- 3) To update the specified row in the schema using the primary key in
26 -- the predicates.
27 -- 4) To trap any constraint violations that may have occurred.
28 -- 5) To raise any other errors.
29 --
30 -- Prerequisites:
31 -- This is an internal private procedure which must be called from the
32 -- update_dml procedure.
33 --
34 -- In Parameters:
35 -- A Pl/Sql record structure.
36 --
37 -- Post Success:
38 -- The specified row will be updated in the schema.
39 --
40 -- Post Failure:
41 -- On the update dml failure it is important to note that we always reset the
42 -- g_api_dml status to false.
43 -- If a check or unique integrity constraint violation is raised the
44 -- constraint_error procedure will be called.
45 -- If any other error is reported, the error will be raised after the
46 -- g_api_dml status is reset.
47 --
48 -- Developer Implementation Notes:
49 -- The update 'set' arguments list should be modified if any of your
50 -- attributes are not updateable.
51 --
52 -- Access Status:
53 -- Internal Row Handler Use Only.
54 --
55 -- {End Of Comments}
56 -- ----------------------------------------------------------------------------
57 Procedure dt_update_dml
58 (p_rec in out nocopy ame_rul_shd.g_rec_type
59 ,p_effective_date in date
60 ,p_datetrack_mode in varchar2
61 ,p_validation_start_date in date
62 ,p_validation_end_date in date
63 ) is
64 --
65 l_proc varchar2(72) := g_package||'dt_update_dml';
66 --
67 Begin
68 hr_utility.set_location('Entering:'||l_proc, 5);
69 --
70 If (p_datetrack_mode = hr_api.g_correction) then
71 hr_utility.set_location(l_proc, 10);
72 --
73 -- Because we are updating a row we must get the next object
74 -- version number.
75 --
76 p_rec.object_version_number :=
77 ame_rul_shd.get_object_version_number
78 (p_rule_id => p_rec.rule_id
79 );
80 --
81 --
82 --
83 -- Update the ame_rules Row
84 --
85 update ame_rules
86 set
87 rule_id = p_rec.rule_id
88 ,rule_type = p_rec.rule_type
89 ,action_id = p_rec.action_id
90 ,description = p_rec.description
91 ,security_group_id = p_rec.security_group_id
92 ,rule_key = p_rec.rule_key
93 ,item_class_id = p_rec.item_class_id
94 ,object_version_number = p_rec.object_version_number
95 where rule_id = p_rec.rule_id
96 and start_date = p_validation_start_date
97 and ((p_validation_end_date is null and end_date is null) or
98 (end_date = p_validation_end_date));
99 --
100 --
101 --
102 -- Set the effective start and end dates
103 --
104 p_rec.start_date := p_validation_start_date;
105 p_rec.end_date := p_validation_end_date;
106 End If;
107 --
108 hr_utility.set_location(' Leaving:'||l_proc, 15);
109 Exception
110 When hr_api.check_integrity_violated Then
111 -- A check constraint has been violated
112 --
113 ame_rul_shd.constraint_error
114 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
115 When hr_api.unique_integrity_violated Then
116 -- Unique integrity has been violated
117 --
118 ame_rul_shd.constraint_error
119 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
120 When Others Then
121 --
122 Raise;
123 End dt_update_dml;
124 --
125 -- ----------------------------------------------------------------------------
126 -- |------------------------------< update_dml >------------------------------|
127 -- ----------------------------------------------------------------------------
128 -- {Start Of Comments}
129 --
130 -- Description:
131 -- This procedure calls the dt_update_dml control logic which handles
132 -- the actual datetrack dml.
133 --
134 -- Prerequisites:
135 -- This is an internal private procedure which must be called from the upd
136 -- procedure.
137 --
138 -- In Parameters:
139 -- A Pl/Sql record structre.
140 --
141 -- Post Success:
142 -- Processing contines.
143 --
144 -- Post Failure:
145 -- No specific error handling is required within this procedure.
146 --
147 -- Developer Implementation Notes:
148 -- The update 'set' arguments list should be modified if any of your
149 -- attributes are not updateable.
150 --
151 -- Access Status:
152 -- Internal Row Handler Use Only.
153 --
154 -- {End Of Comments}
155 -- ----------------------------------------------------------------------------
156 Procedure update_dml
157 (p_rec in out nocopy ame_rul_shd.g_rec_type
158 ,p_effective_date in date
159 ,p_datetrack_mode in varchar2
160 ,p_validation_start_date in date
161 ,p_validation_end_date in date
162 ) is
163 --
164 l_proc varchar2(72) := g_package||'update_dml';
165 --
166 Begin
167 hr_utility.set_location('Entering:'||l_proc, 5);
168 --
169 ame_rul_upd.dt_update_dml
170 (p_rec => p_rec
171 ,p_effective_date => p_effective_date
172 ,p_datetrack_mode => p_datetrack_mode
173 ,p_validation_start_date => p_validation_start_date
174 ,p_validation_end_date => p_validation_end_date
175 );
176 --
177 hr_utility.set_location(' Leaving:'||l_proc, 10);
178 End update_dml;
179 --
180 -- ----------------------------------------------------------------------------
181 -- |----------------------------< dt_pre_update >-----------------------------|
182 -- ----------------------------------------------------------------------------
183 -- {Start Of Comments}
184 --
185 -- Description:
186 -- The dt_pre_update procedure controls the execution
187 -- of dml for the datetrack modes of: UPDATE, UPDATE_OVERRIDE
188 -- and UPDATE_CHANGE_INSERT only. The execution required is as
189 -- follows:
190 --
191 -- 1) Providing the datetrack update mode is not 'CORRECTION'
192 -- then set the effective end date of the current row (this
193 -- will be the validation_start_date - 1).
194 -- 2) If the datetrack mode is 'UPDATE_OVERRIDE' then call the
195 -- corresponding delete_dml process to delete any future rows
196 -- where the effective_start_date is greater than or equal to
197 -- the validation_start_date.
198 -- 3) Call the insert_dml process to insert the new updated row
199 -- details.
200 --
201 -- Prerequisites:
202 -- This is an internal procedure which is called from the
203 -- pre_update procedure.
204 --
205 -- In Parameters:
206 --
207 -- Post Success:
208 -- Processing continues.
209 --
210 -- Post Failure:
211 -- If an error has occurred, an error message and exception will be raised
212 -- but not handled.
213 --
214 -- Developer Implementation Notes:
215 -- This is an internal procedure which is required by Datetrack. Don't
216 -- remove or modify.
217 --
218 -- Access Status:
219 -- Internal Row Handler Use Only.
220 --
221 -- {End Of Comments}
222 -- ----------------------------------------------------------------------------
223 Procedure dt_pre_update
224 (p_rec in out nocopy ame_rul_shd.g_rec_type
225 ,p_effective_date in date
226 ,p_datetrack_mode in varchar2
227 ,p_validation_start_date in date
228 ,p_validation_end_date in date
229 ) is
230 --
231 l_proc varchar2(72) := g_package||'dt_pre_update';
232 l_dummy_version_number number;
233 --
234 Begin
235 hr_utility.set_location('Entering:'||l_proc, 5);
236 If (p_datetrack_mode <> hr_api.g_correction) then
237 --
238 -- Update the current effective end date
239 --
240 ame_rul_shd.upd_end_date
241 (p_effective_date => p_effective_date
242 ,p_rule_id => p_rec.rule_id
243 ,p_new_end_date => p_validation_start_date
244 ,p_object_version_number => l_dummy_version_number
245 );
246 --
247 If (p_datetrack_mode = hr_api.g_update_override) then
248 --
249 -- As the datetrack mode is 'UPDATE_OVERRIDE' then we must
250 -- delete any future rows
251 --
252 ame_rul_del.delete_dml
253 (p_rec => p_rec
254 ,p_effective_date => p_effective_date
255 ,p_datetrack_mode => p_datetrack_mode
256 ,p_validation_start_date => p_validation_start_date
257 ,p_validation_end_date => p_validation_end_date
258 );
259 End If;
260 --
261 -- We must now insert the updated row
262 --
263 ame_rul_ins.insert_dml
264 (p_rec => p_rec
265 ,p_effective_date => p_effective_date
266 ,p_datetrack_mode => p_datetrack_mode
267 ,p_validation_start_date => p_validation_start_date
268 ,p_validation_end_date => p_validation_end_date
269 );
270 End If;
271 hr_utility.set_location(' Leaving:'||l_proc, 20);
272 End dt_pre_update;
273 --
274 -- ----------------------------------------------------------------------------
275 -- |------------------------------< pre_update >------------------------------|
276 -- ----------------------------------------------------------------------------
277 -- {Start Of Comments}
278 --
279 -- Description:
280 -- This private procedure contains any processing which is required before
281 -- the update dml.
282 --
283 -- Prerequisites:
284 -- This is an internal procedure which is called from the upd procedure.
285 --
286 -- In Parameters:
287 -- A Pl/Sql record structure.
288 --
289 -- Post Success:
290 -- Processing continues.
291 --
292 -- Post Failure:
293 -- If an error has occurred, an error message and exception will be raised
294 -- but not handled.
295 -- Developer Implementation Notes:
296 -- Any pre-processing required before the update dml is issued should be
297 -- coded within this procedure. It is important to note that any 3rd party
298 -- maintenance should be reviewed before placing in this procedure. The call
299 -- to the dt_update_dml procedure should NOT be removed.
300 --
301 -- Access Status:
302 -- Internal Row Handler Use Only.
303 --
304 -- {End Of Comments}
305 -- ----------------------------------------------------------------------------
306 Procedure pre_update
307 (p_rec in out nocopy ame_rul_shd.g_rec_type
308 ,p_effective_date in date
309 ,p_datetrack_mode in varchar2
310 ,p_validation_start_date in date
311 ,p_validation_end_date in date
312 ) is
313 --
314 l_proc varchar2(72) := g_package||'pre_update';
315 --
316 Begin
317 hr_utility.set_location('Entering:'||l_proc, 5);
318 --
319 --
320 --
321 dt_pre_update
322 (p_rec => p_rec
323 ,p_effective_date => p_effective_date
324 ,p_datetrack_mode => p_datetrack_mode
325 ,p_validation_start_date => p_validation_start_date
326 ,p_validation_end_date => p_validation_end_date
327 );
328 --
329 hr_utility.set_location(' Leaving:'||l_proc, 10);
330 End pre_update;
331 --
332 -- ----------------------------------------------------------------------------
333 -- |----------------------------< post_update >-------------------------------|
334 -- ----------------------------------------------------------------------------
335 -- {Start Of Comments}
336 --
337 -- Description:
338 -- This private procedure contains any processing which is required after
339 -- the update dml.
340 --
341 -- Prerequisites:
342 -- This is an internal procedure which is called from the upd procedure.
343 --
344 -- In Parameters:
345 -- A Pl/Sql record structure.
346 --
347 -- Post Success:
348 -- Processing continues.
349 --
350 -- Post Failure:
351 -- If an error has occurred, an error message and exception will be raised
352 -- but not handled.
353 --
354 -- Developer Implementation Notes:
355 -- Any post-processing required after the update dml is issued should be
356 -- coded within this procedure. It is important to note that any 3rd party
357 -- maintenance should be reviewed before placing in this procedure.
358 --
359 -- Access Status:
360 -- Internal Row Handler Use Only.
361 --
362 -- {End Of Comments}
363 -- ----------------------------------------------------------------------------
364 Procedure post_update
365 (p_rec in ame_rul_shd.g_rec_type
366 ,p_effective_date in date
367 ,p_datetrack_mode in varchar2
368 ,p_validation_start_date in date
369 ,p_validation_end_date in date
370 ) is
371 --
372 l_proc varchar2(72) := g_package||'post_update';
373 --
374 Begin
375 hr_utility.set_location('Entering:'||l_proc, 5);
376 begin
377 --
378 ame_rul_rku.after_update
379 (p_effective_date
380 => p_effective_date
381 ,p_datetrack_mode
382 => p_datetrack_mode
383 ,p_validation_start_date
384 => p_validation_start_date
385 ,p_validation_end_date
386 => p_validation_end_date
387 ,p_rule_id
388 => p_rec.rule_id
389 ,p_rule_type
390 => p_rec.rule_type
391 ,p_action_id
392 => p_rec.action_id
393 ,p_start_date
394 => p_rec.start_date
395 ,p_end_date
396 => p_rec.end_date
397 ,p_description
398 => p_rec.description
399 ,p_security_group_id
400 => p_rec.security_group_id
401 ,p_rule_key
402 => p_rec.rule_key
403 ,p_item_class_id
404 => p_rec.item_class_id
405 ,p_object_version_number
406 => p_rec.object_version_number
407 ,p_rule_type_o
408 => ame_rul_shd.g_old_rec.rule_type
409 ,p_action_id_o
410 => ame_rul_shd.g_old_rec.action_id
411 ,p_start_date_o
412 => ame_rul_shd.g_old_rec.start_date
413 ,p_end_date_o
414 => ame_rul_shd.g_old_rec.end_date
415 ,p_description_o
416 => ame_rul_shd.g_old_rec.description
417 ,p_security_group_id_o
418 => ame_rul_shd.g_old_rec.security_group_id
419 ,p_rule_key_o
420 => ame_rul_shd.g_old_rec.rule_key
421 ,p_item_class_id_o
422 => ame_rul_shd.g_old_rec.item_class_id
423 ,p_object_version_number_o
424 => ame_rul_shd.g_old_rec.object_version_number
425 );
426 --
427 exception
428 --
429 when hr_api.cannot_find_prog_unit then
430 --
431 hr_api.cannot_find_prog_unit_error
432 (p_module_name => 'AME_RULES'
433 ,p_hook_type => 'AU');
434 --
435 end;
436 --
437 hr_utility.set_location(' Leaving:'||l_proc, 10);
438 End post_update;
439 --
440 -- ----------------------------------------------------------------------------
441 -- |-----------------------------< convert_defs >-----------------------------|
442 -- ----------------------------------------------------------------------------
443 -- {Start Of Comments}
444 --
445 -- Description:
446 -- The Convert_Defs procedure has one very important function:
447 -- It must return the record structure for the row with all system defaulted
448 -- values converted into its corresponding parameter value for update. When
449 -- we attempt to update a row through the Upd process , certain
450 -- parameters can be defaulted which enables flexibility in the calling of
451 -- the upd process (e.g. only attributes which need to be updated need to be
452 -- specified). For the upd process to determine which attributes
453 -- have NOT been specified we need to check if the parameter has a reserved
454 -- system default value. Therefore, for all parameters which have a
455 -- corresponding reserved system default mechanism specified we need to
456 -- check if a system default is being used. If a system default is being
457 -- used then we convert the defaulted value into its corresponding attribute
458 -- value held in the g_old_rec data structure.
459 --
460 -- Prerequisites:
461 -- This private function can only be called from the upd process.
462 --
463 -- In Parameters:
464 -- A Pl/Sql record structure.
465 --
466 -- Post Success:
467 -- The record structure will be returned with all system defaulted parameter
468 -- values converted into its current row attribute value.
469 --
470 -- Post Failure:
471 -- No direct error handling is required within this function. Any possible
472 -- errors within this procedure will be a PL/SQL value error due to
473 -- conversion of datatypes or data lengths.
474 --
475 -- Developer Implementation Notes:
476 -- None.
477 --
478 -- Access Status:
479 -- Internal Row Handler Use Only.
480 --
481 -- {End Of Comments}
482 -- ----------------------------------------------------------------------------
483 Procedure convert_defs
484 (p_rec in out nocopy ame_rul_shd.g_rec_type
485 ) is
486 --
487 Begin
488 --
489 -- We must now examine each argument value in the
490 -- p_rec plsql record structure
491 -- to see if a system default is being used. If a system default
492 -- is being used then we must set to the 'current' argument value.
493 --
494 If (p_rec.rule_type = hr_api.g_number) then
495 p_rec.rule_type :=
496 ame_rul_shd.g_old_rec.rule_type;
497 End If;
498 If (p_rec.action_id = hr_api.g_number) then
499 p_rec.action_id :=
500 ame_rul_shd.g_old_rec.action_id;
501 End If;
502 If (p_rec.description = hr_api.g_varchar2) then
503 p_rec.description :=
504 ame_rul_shd.g_old_rec.description;
505 End If;
506 If (p_rec.security_group_id = hr_api.g_number) then
507 p_rec.security_group_id :=
508 ame_rul_shd.g_old_rec.security_group_id;
509 End If;
510 If (p_rec.rule_key = hr_api.g_varchar2) then
511 p_rec.rule_key :=
512 ame_rul_shd.g_old_rec.rule_key;
513 End If;
514 If (p_rec.item_class_id = hr_api.g_number) then
515 p_rec.item_class_id :=
516 ame_rul_shd.g_old_rec.item_class_id;
517 End If;
518 If (p_rec.start_date = hr_api.g_date) then
519 p_rec.start_date :=
520 ame_rul_shd.g_old_rec.start_date;
521 End If;
522 If (p_rec.end_date = hr_api.g_date) then
523 p_rec.end_date :=
524 ame_rul_shd.g_old_rec.end_date;
525 End If;
526
527 --
528 End convert_defs;
529 --
530 -- ----------------------------------------------------------------------------
531 -- |---------------------------------< upd >----------------------------------|
532 -- ----------------------------------------------------------------------------
533 Procedure upd
534 (p_effective_date in date
535 ,p_datetrack_mode in varchar2
536 ,p_rec in out nocopy ame_rul_shd.g_rec_type
537 ) is
538 --
539 l_proc varchar2(72) := g_package||'upd';
540 l_validation_start_date date;
541 l_validation_end_date date;
542 --
543 Begin
544 hr_utility.set_location('Entering:'||l_proc, 5);
545 --
546 -- Ensure that the DateTrack update mode is valid
547 --
548 dt_api.validate_dt_upd_mode(p_datetrack_mode => p_datetrack_mode);
549 -- set the start and end dates if not set
550 if p_rec.start_date is null then
551 p_rec.start_date := hr_api.g_date;
552 end if;
553 if p_rec.end_date is null then
554 p_rec.end_date := hr_api.g_date;
555 end if;
556 --
557 -- We must lock the row which we need to update.
558 --
559 ame_rul_shd.lck
560 (p_effective_date => p_effective_date
561 ,p_datetrack_mode => p_datetrack_mode
562 ,p_rule_id => p_rec.rule_id
563 ,p_object_version_number => p_rec.object_version_number
564 ,p_validation_start_date => l_validation_start_date
565 ,p_validation_end_date => l_validation_end_date
566 );
567 --
568 -- 1. During an update system defaults are used to determine if
569 -- arguments have been defaulted or not. We must therefore
570 -- derive the full record structure values to be updated.
571 --
572 -- 2. Call the supporting update validate operations.
573 --
574 ame_rul_upd.convert_defs(p_rec);
575 --
576 -- Make sure that the Rule start_date and end_date are correct
577 --
578 -- p_validation_start_date is sysdate, so if the start_date is greater
579 -- than sysdate then we should use the p_start_date else use sysdate.
580 --
581 if p_rec.start_date < l_validation_start_date then
582 p_rec.start_date := l_validation_start_date;
583 end if;
584 --
585 -- p_validation_end_date is ame_util.endOfTime, so if the end_date is less
586 -- than ame_util.endOfTime then we should use the p_end_date else use
587 -- p_validation_end_date.
588 --
589 /*if p_rec.end_date <> l_validation_end_date then
590 p_rec.end_date := l_validation_end_date;
591 end if;*/
592
593 --
594 ame_rul_bus.update_validate
595 (p_rec => p_rec
596 ,p_effective_date => p_effective_date
597 ,p_datetrack_mode => p_datetrack_mode
598 ,p_validation_start_date => l_validation_start_date
599 ,p_validation_end_date => l_validation_end_date
600 );
601 --
602 -- Call to raise any errors on multi-message list
603 hr_multi_message.end_validation_set;
604 --
605 -- Call the supporting pre-update operation
606 --
607 pre_update
608 (p_rec => p_rec
609 ,p_effective_date => p_effective_date
610 ,p_datetrack_mode => p_datetrack_mode
611 ,p_validation_start_date => l_validation_start_date
612 ,p_validation_end_date => l_validation_end_date
613 );
614 --
615 --
616 -- Update the row.
617 --
618 update_dml
619 (p_rec => p_rec
620 ,p_effective_date => p_effective_date
621 ,p_datetrack_mode => p_datetrack_mode
622 ,p_validation_start_date => l_validation_start_date
623 ,p_validation_end_date => l_validation_end_date
624 );
625 --
626 --
627 -- Call the supporting post-update operation
628 --
629 post_update
630 (p_rec => p_rec
631 ,p_effective_date => p_effective_date
632 ,p_datetrack_mode => p_datetrack_mode
633 ,p_validation_start_date => l_validation_start_date
634 ,p_validation_end_date => l_validation_end_date
635 );
636 --
637 --
638 -- Call to raise any errors on multi-message list
639 hr_multi_message.end_validation_set;
640 End upd;
641 --
642 -- ----------------------------------------------------------------------------
643 -- |------------------------------< upd >-------------------------------------|
644 -- ----------------------------------------------------------------------------
645 Procedure upd
646 (p_effective_date in date
647 ,p_datetrack_mode in varchar2
648 ,p_rule_id in number
649 ,p_object_version_number in out nocopy number
650 ,p_rule_type in number default hr_api.g_number
651 ,p_description in varchar2 default hr_api.g_varchar2
652 ,p_rule_key in varchar2 default hr_api.g_varchar2
653 ,p_action_id in number default hr_api.g_number
654 ,p_security_group_id in number default hr_api.g_number
655 ,p_item_class_id in number default hr_api.g_number
656 ,p_start_date in out nocopy date
657 ,p_end_date in out nocopy date
658 ) is
659 --
660 l_rec ame_rul_shd.g_rec_type;
661 l_proc varchar2(72) := g_package||'upd';
662 --
663 Begin
664 hr_utility.set_location('Entering:'||l_proc, 5);
665 --
666 -- Call conversion function to turn arguments into the
667 -- l_rec structure.
668 --
669 l_rec :=
670 ame_rul_shd.convert_args
671 (p_rule_id
672 ,p_rule_type
673 ,p_action_id
674 ,p_start_date
675 ,p_end_date
676 ,p_description
677 ,p_security_group_id
678 ,p_rule_key
679 ,p_item_class_id
680 ,p_object_version_number
681 );
682 --
683 -- Having converted the arguments into the
684 -- plsql record structure we call the corresponding record
685 -- business process.
686 --
687 ame_rul_upd.upd
688 (p_effective_date
689 ,p_datetrack_mode
690 ,l_rec
691 );
692 --
693 -- Set the out parameters
694 --
695 p_object_version_number := l_rec.object_version_number;
696 p_start_date := l_rec.start_date;
697 p_end_date := l_rec.end_date;
698 --
699 --
700 hr_utility.set_location(' Leaving:'||l_proc, 10);
701 End upd;
702 --
703 end ame_rul_upd;