1 Package Body per_seu_bus as
2 /* $Header: peseurhi.pkb 120.4 2005/11/09 13:59:48 vbanner noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := 'per_seu_bus.'; -- Global package name
9 g_debug boolean := hr_utility.debug_enabled;
10 --
11 -- The following two global variables are only to be
12 -- used by the return_legislation_code function.
13 --
14 g_legislation_code varchar2(150) default null;
15 g_security_user_id number default null;
16 --
17 -- ---------------------------------------------------------------------------
18 -- |----------------------< set_security_group_id >--------------------------|
19 -- ---------------------------------------------------------------------------
20 --
21 Procedure set_security_group_id
22 (p_security_user_id in number
23 ,p_associated_column1 in varchar2 default null
24 ) is
25 --
26 -- Fetch the security group and legislation code for the business group
27 -- context.
28 -- WARNING: the business group context is taken from the security profile
29 -- but the business_group_id will be null for Global security profiles.
30 -- In this case, the cursor will not return a row and a primary key
31 -- error will be raised. For this reason, this procedure is not called
32 -- from anywhere else in the row-handler and it is recommended that
33 -- this remains the case; lookup validation should use hr_standard_lookups
34 -- not hr_lookups.
35 --
36 cursor csr_sec_grp is
37 select pbg.security_group_id,
38 pbg.legislation_code
39 from per_business_groups_perf pbg
40 , per_security_users seu
41 , per_security_profiles psp
42 where seu.security_user_id = p_security_user_id
43 and seu.security_profile_id = psp.security_profile_id
44 and psp.business_group_id is not null
45 and pbg.business_group_id = psp.business_group_id;
46 --
47 -- Declare local variables
48 --
49 l_security_group_id number;
50 l_proc varchar2(72) := g_package||'set_security_group_id';
51 l_legislation_code varchar2(150);
52 --
53 begin
54 --
55 hr_utility.set_location('Entering:'|| l_proc, 10);
56 --
57 -- Ensure that all the mandatory parameter are not null
58 --
59 hr_api.mandatory_arg_error
60 (p_api_name => l_proc
61 ,p_argument => 'security_user_id'
62 ,p_argument_value => p_security_user_id
63 );
64 --
65 -- A row will not be returned for global security profiles.
66 --
67 open csr_sec_grp;
68 fetch csr_sec_grp into l_security_group_id
69 , l_legislation_code;
70 --
71 if csr_sec_grp%notfound then
72 --
73 -- Occurs for global security profiles.
74 --
75 close csr_sec_grp;
76 --
77 -- The primary key is invalid therefore we must error
78 --
79 fnd_message.set_name('PAY','HR_7220_INVALID_PRIMARY_KEY');
80 hr_multi_message.add
81 (p_associated_column1
82 => nvl(p_associated_column1,'SECURITY_USER_ID')
83 );
84 --
85 else
86 close csr_sec_grp;
87 --
88 -- Set the security_group_id in CLIENT_INFO
89 --
90 hr_api.set_security_group_id
91 (p_security_group_id => l_security_group_id
92 );
93 --
94 -- Set the sessions legislation context in HR_SESSION_DATA
95 --
96 hr_api.set_legislation_context(l_legislation_code);
97 end if;
98 --
99 hr_utility.set_location(' Leaving:'|| l_proc, 20);
100 --
101 end set_security_group_id;
102 --
103 -- ---------------------------------------------------------------------------
104 -- |---------------------< return_legislation_code >-------------------------|
105 -- ---------------------------------------------------------------------------
106 --
107 Function return_legislation_code
108 (p_security_user_id in number
109 )
110 Return Varchar2 Is
111 --
112 -- Fetch the legislation code from the business group.
113 -- WARNING: the business group context is taken from the security profile
114 -- but the business_group_id will be null for Global security profiles.
115 -- In this case, the cursor will not return a row and a primary key
116 -- error will be raised. For this reason, this procedure is not called
117 -- from anywhere else in the row-handler and it is recommended that
118 -- this remains the case; lookup validation should use hr_standard_lookups
119 -- not hr_lookups.
120
121 cursor csr_leg_code is
122 select pbg.legislation_code
123 from per_business_groups_perf pbg
124 , per_security_users seu
125 , per_security_profiles psp
126 where seu.security_user_id = p_security_user_id
127 and seu.security_profile_id = psp.security_profile_id
128 and psp.business_group_id is not null
129 and pbg.business_group_id = psp.business_group_id;
130 --
131 -- Declare local variables
132 --
133 l_legislation_code varchar2(150);
134 l_proc varchar2(72) := g_package||'return_legislation_code';
135 --
136 Begin
137 --
138 hr_utility.set_location('Entering:'|| l_proc, 10);
139 --
140 -- Ensure that all the mandatory parameter are not null
141 --
142 hr_api.mandatory_arg_error
143 (p_api_name => l_proc
144 ,p_argument => 'security_user_id'
145 ,p_argument_value => p_security_user_id
146 );
147 --
148 if ( nvl(per_seu_bus.g_security_user_id, hr_api.g_number)
149 = p_security_user_id) then
150 --
151 -- The legislation code has already been found with a previous
152 -- call to this function. Just return the value in the global
153 -- variable.
154 --
155 l_legislation_code := per_seu_bus.g_legislation_code;
156 hr_utility.set_location(l_proc, 20);
157 else
158 --
159 -- The ID is different to the last call to this function
160 -- or this is the first call to this function.
161 --
162 --
163 -- A row will not be returned for global security profiles.
164 --
165 open csr_leg_code;
166 fetch csr_leg_code into l_legislation_code;
167 --
168 if csr_leg_code%notfound then
169 --
170 -- The primary key is invalid therefore we must error;
171 -- occurs for global security profiles.
172 --
173 close csr_leg_code;
174 fnd_message.set_name('PAY','HR_7220_INVALID_PRIMARY_KEY');
175 fnd_message.raise_error;
176 end if;
177 hr_utility.set_location(l_proc,30);
178 --
179 -- Set the global variables so the values are
180 -- available for the next call to this function.
181 --
182 close csr_leg_code;
183 per_seu_bus.g_security_user_id := p_security_user_id;
184 per_seu_bus.g_legislation_code := l_legislation_code;
185 end if;
186 hr_utility.set_location(' Leaving:'|| l_proc, 40);
187 return l_legislation_code;
188 end return_legislation_code;
189 --
190 -- ----------------------------------------------------------------------------
191 -- |-----------------------< chk_non_updateable_args >------------------------|
192 -- ----------------------------------------------------------------------------
193 -- {Start Of Comments}
194 --
195 -- Description:
196 -- This procedure is used to ensure that non updateable attributes have
197 -- not been updated. If an attribute has been updated an error is generated.
198 --
199 -- Pre Conditions:
200 -- g_old_rec has been populated with details of the values currently in
201 -- the database.
202 --
203 -- In Arguments:
204 -- p_rec has been populated with the updated values the user would like the
205 -- record set to.
206 --
207 -- Post Success:
208 -- Processing continues if all the non updateable attributes have not
209 -- changed.
210 --
211 -- Post Failure:
215 -- {End Of Comments}
212 -- An application error is raised if any of the non updatable attributes
213 -- have been altered.
214 --
216 -- ----------------------------------------------------------------------------
217 --
218 Procedure chk_non_updateable_args
219 (p_effective_date in date
220 ,p_rec in per_seu_shd.g_rec_type
221 ) IS
222 --
223 l_proc varchar2(72) := g_package || 'chk_non_updateable_args';
224 --
225 Begin
226 --
227 -- Only proceed with the validation if a row exists for the current
228 -- record in the HR Schema.
229 --
230 IF NOT per_seu_shd.api_updating
231 (p_security_user_id => p_rec.security_user_id
232 ,p_object_version_number => p_rec.object_version_number
233 ) THEN
234 fnd_message.set_name('PER', 'HR_6153_ALL_PROCEDURE_FAIL');
235 fnd_message.set_token('PROCEDURE ', l_proc);
236 fnd_message.set_token('STEP ', '5');
237 fnd_message.raise_error;
238 END IF;
239 --
240 -- All values (besides the primary key) can be updated so there is
241 -- no additional non-updateable argument checking.
242 --
243 End chk_non_updateable_args;
244 --
245 -- ----------------------------------------------------------------------------
246 -- |-----------------------< chk_user_id >------------------------------------|
247 -- ----------------------------------------------------------------------------
248 --
249 Procedure chk_user_id
250 (p_security_user_id in number
251 ,p_user_id in number
252 ,p_object_version_number in number
253 ,p_effective_date in date
254 ) IS
255
256 --
257 -- Local variables.
258 --
259 l_proc varchar2(72) := g_package || 'chk_user_id';
260 l_api_updating boolean;
261 l_user_id number;
262
263 --
264 -- Verifies the user exists and is effective.
265 --
266 CURSOR csr_chk_user IS
267 SELECT fndu.user_id
268 FROM fnd_user_view fndu
269 WHERE fndu.user_id = p_user_id
270 AND p_effective_date BETWEEN
271 fndu.start_date and NVL(fndu.end_date, hr_api.g_eot);
272 --
273 Begin
274
275 IF g_debug THEN
276 hr_utility.set_location('Entering: '||l_proc, 10);
277 END IF;
278
279 --
280 -- Only proceed with validation if:
281 -- a) inserting or
282 -- b) updating and the parameters used within this chk procedure
283 -- have not changed.
284 --
285 l_api_updating := per_seu_shd.api_updating
286 (p_security_user_id => p_security_user_id
287 ,p_object_version_number => p_object_version_number);
288
289 IF (l_api_updating
290 AND NVL(per_seu_shd.g_old_rec.user_id, hr_api.g_number)
291 = NVL(p_user_id, hr_api.g_number)) THEN
292 RETURN;
293 END IF;
294
295 hr_api.mandatory_arg_error(p_api_name => l_proc,
296 p_argument => 'p_user_id',
297 p_argument_value => p_user_id);
298
299
300 OPEN csr_chk_user;
301 FETCH csr_chk_user INTO l_user_id;
302 CLOSE csr_chk_user;
303
304 IF l_user_id IS NULL THEN
305 --
306 -- If the user_id is null, the user either does not exist, or
307 -- is not effective as of the effective date passed in.
308 --
309 IF g_debug THEN
310 hr_utility.set_location(l_proc, 20);
311 END IF;
312
313 hr_utility.set_message(800, 'HR_50128_INVALID_USER');
314 hr_multi_message.add
315 (p_associated_column1 => 'PER_SECURITY_USERS.USER_ID');
316
317 END IF;
318
319 IF g_debug THEN
320 hr_utility.set_location(' Leaving:'|| l_proc, 999);
321 END IF;
322
323 End chk_user_id;
324 --
325 -- ----------------------------------------------------------------------------
326 -- |-----------------------< chk_security_profile_id >------------------------|
327 -- ----------------------------------------------------------------------------
328 --
329 Procedure chk_security_profile_id
330 (p_security_user_id in number
331 ,p_security_profile_id in number
332 ,p_object_version_number in number
333 ) IS
334
335 --
336 -- Local variables.
337 --
338 l_proc varchar2(72) := g_package || 'chk_security_profile_id';
339 l_api_updating boolean;
340 l_security_profile_id number;
341
342 --
343 -- Verifies the security profile exists.
344 --
345 CURSOR csr_chk_sec_prof IS
346 SELECT psp.security_profile_id
347 FROM per_security_profiles psp
348 WHERE psp.security_profile_id = p_security_profile_id;
349
350 --
351 Begin
352
353 IF g_debug THEN
354 hr_utility.set_location('Entering: '||l_proc, 10);
355 END IF;
356
357 --
358 -- Only proceed with validation if:
359 -- a) inserting or
360 -- b) updating and the parameters used within this chk procedure
361 -- have not changed.
362 --
363 l_api_updating := per_seu_shd.api_updating
364 (p_security_user_id => p_security_user_id
365 ,p_object_version_number => p_object_version_number);
366
367 IF (l_api_updating
371 END IF;
368 AND NVL(per_seu_shd.g_old_rec.security_profile_id, hr_api.g_number)
369 = NVL(p_security_profile_id, hr_api.g_number)) THEN
370 RETURN;
372
373 hr_api.mandatory_arg_error(p_api_name => l_proc,
374 p_argument => 'p_security_profile_id',
375 p_argument_value => p_security_profile_id);
376
377
378 OPEN csr_chk_sec_prof;
379 FETCH csr_chk_sec_prof INTO l_security_profile_id;
380 CLOSE csr_chk_sec_prof;
381
382 IF l_security_profile_id IS NULL THEN
383 --
384 -- If the security_profile_id is null, then the security profile
385 -- does not exist.
386 --
387 IF g_debug THEN
388 hr_utility.set_location(l_proc, 20);
389 END IF;
390
391 hr_utility.set_message(800, 'HR_50143_INVALID_SEC_PROF');
392 hr_multi_message.add
393 (p_associated_column1 => 'PER_SECURITY_USERS.SECURITY_PROFILE_ID');
394
395 END IF;
396
397 IF g_debug THEN
398 hr_utility.set_location(' Leaving:'|| l_proc, 999);
399 END IF;
400
401 END chk_security_profile_id;
402 --
403 -- ----------------------------------------------------------------------------
404 -- |-----------------------< chk_association_unique >-------------------------|
405 -- ----------------------------------------------------------------------------
406 --
407 Procedure chk_association_unique
408 (p_security_user_id in number
409 ,p_user_id in number
410 ,p_security_profile_id in number
411 ,p_object_version_number in number
412 ) IS
413
414 --
415 -- Local variables.
416 --
417 l_proc varchar2(72) := g_package || 'chk_association_unique';
418 l_api_updating boolean;
419 l_user_id number;
420
421 --
422 -- Verifies that a row does not already exist for this user in this
423 -- security profile.
424 --
425 CURSOR csr_chk_unique IS
426 SELECT seu.user_id
427 FROM per_security_users seu
428 WHERE seu.user_id = p_user_id
429 AND seu.security_profile_id = p_security_profile_id
430 AND seu.security_user_id <> NVL(p_security_profile_id, hr_api.g_number);
431
432 --
433 Begin
434
435 IF g_debug THEN
436 hr_utility.set_location('Entering: '||l_proc, 10);
437 END IF;
438
439 --
440 -- Only proceed with validation if:
441 -- a) inserting or
442 -- b) updating and the parameters used within this chk procedure
443 -- have not changed.
444 --
445 l_api_updating := per_seu_shd.api_updating
446 (p_security_user_id => p_security_user_id
447 ,p_object_version_number => p_object_version_number);
448
449 IF (l_api_updating
450 AND NVL(per_seu_shd.g_old_rec.user_id, hr_api.g_number)
451 = NVL(p_user_id, hr_api.g_number)
452 AND NVL(per_seu_shd.g_old_rec.security_profile_id, hr_api.g_number)
453 = NVL(p_security_profile_id, hr_api.g_number)) THEN
454 RETURN;
455 END IF;
456
457 IF hr_multi_message.no_exclusive_error
458 (p_check_column1 => 'PER_SECURITY_USERS.USER_ID'
459 ,p_check_column2 => 'PER_SECURITY_USERS.SECURITY_PROFILE_ID')
460 THEN
461 --
462 -- Only proceed if the dependent validation has not errored.
463 --
464 IF g_debug THEN
465 hr_utility.set_location(l_proc, 20);
466 END IF;
467
468 OPEN csr_chk_unique;
469 FETCH csr_chk_unique INTO l_user_id;
470 CLOSE csr_chk_unique;
471
472 IF l_user_id IS NOT NULL THEN
473 --
474 -- If the user_id is set then this user / security profile association
475 -- is not unique; raise an error.
476 --
477 IF g_debug THEN
478 hr_utility.set_location(l_proc, 30);
479 END IF;
480
481 hr_utility.set_message(800, 'HR_50145_SEU_NOT_UNIQUE');
482 hr_multi_message.add
483 (p_associated_column1 => 'PER_SECURITY_USERS.USER_ID'
484 ,p_associated_column2 => 'PER_SECURITY_USERS.SECURITY_PROFILE_ID');
485
486 END IF;
487
488 END IF;
489
490 IF g_debug THEN
491 hr_utility.set_location(' Leaving:'|| l_proc, 999);
492 END IF;
493
494 END chk_association_unique;
495 --
496 -- ----------------------------------------------------------------------------
497 -- |--------------------< chk_process_in_next_run_flag >-----------------------|
498 -- ----------------------------------------------------------------------------
499 --
500 -- bug 4338667
501 Procedure chk_process_in_next_run_flag
502 (p_security_user_id in number
503 ,p_process_in_next_run_flag in varchar2
504 ,p_object_version_number in number
505 ) IS
506
507 --
508 -- Local variables.
509 --
510 l_proc varchar2(72) := g_package || 'chk_process_in_next_run_flag';
511 l_api_updating boolean;
512
513 --
514 Begin
515
516 IF g_debug THEN
517 hr_utility.set_location('Entering: '||l_proc, 10);
518 END IF;
519 --
520 -- Only proceed with validation if:
521 -- a) inserting or
522 -- b) updating and the parameters used within this chk procedure
523 -- have not changed.
524 --
525 l_api_updating := per_seu_shd.api_updating
526 (p_security_user_id => p_security_user_id
527 ,p_object_version_number => p_object_version_number);
528
529 IF (l_api_updating
530 AND NVL(per_seu_shd.g_old_rec.process_in_next_run_flag, hr_api.g_varchar2)
531 = NVL(p_process_in_next_run_flag, hr_api.g_varchar2)) THEN
532 RETURN;
533 END IF;
534
535 IF p_process_in_next_run_flag NOT IN (NULL,'Y','N')
536 THEN
537 --
538 -- If the process_in_next_run_flag is not null, Y or N
539 -- raise an error message informing the user of this fact.
540 --
541 hr_utility.set_message(800, 'HR_50292_INVALID_PINR_FLAG');
542 hr_multi_message.add
543 (p_associated_column1 => 'PER_SECURITY_USERS.PROCESS_IN_NEXT_RUN_FLAG');
544
545 IF g_debug THEN
546 hr_utility.set_location(l_proc, 69);
547 hr_utility.set_location('process_in_next_run_flag is not null Y or N',69);
548 END IF;
549 END IF;
550
551 IF g_debug THEN
552 hr_utility.set_location(' Leaving:'|| l_proc, 999);
553 END IF;
554
555 END chk_process_in_next_run_flag;
556 --
557 -- ----------------------------------------------------------------------------
558 -- |---------------------------< insert_validate >----------------------------|
559 -- ----------------------------------------------------------------------------
560 Procedure insert_validate
561 (p_effective_date in date
562 ,p_rec in per_seu_shd.g_rec_type
563 ) is
564 --
565 l_proc varchar2(72) := g_package||'insert_validate';
566 --
567 Begin
568
569 IF g_debug THEN
570 hr_utility.set_location('Entering:'||l_proc, 5);
571 END IF;
572
573 --
574 -- Call all supporting business operations
575 --
576 --
577 -- This table does not have a mandatory business_group_id
578 -- column, so client_info is not populated by calling the
579 -- per_seu_bus.set_security_group_id procedure.
580 -- Here, validation is performed without a business group context,
581 -- so any lookup code validation should use HR_STANDARD_LOOKUPS and not
582 -- HR_LOOKUPs.
583 --
584
585 --
586 -- Exclusive validation.
587 --
588 -- Validate the security profile.
589 --
593 ,p_object_version_number => p_rec.object_version_number);
590 per_seu_bus.chk_security_profile_id
591 (p_security_user_id => p_rec.security_user_id
592 ,p_security_profile_id => p_rec.security_profile_id
594
595 IF g_debug THEN
596 hr_utility.set_location(l_proc, 10);
597 END IF;
598
599 --
600 -- Validate the user.
601 --
602 per_seu_bus.chk_user_id
603 (p_security_user_id => p_rec.security_user_id
604 ,p_user_id => p_rec.user_id
605 ,p_object_version_number => p_rec.object_version_number
606 ,p_effective_date => p_effective_date);
607
608 --
609 -- Validate the process_in_next_run_flag
610 --
611 per_seu_bus.chk_process_in_next_run_flag
612 (p_security_user_id => p_rec.security_user_id
613 ,p_process_in_next_run_flag => p_rec.process_in_next_run_flag
614 ,p_object_version_number => p_rec.object_version_number);
615
616 --
617 -- End exclusive validation.
618 --
619 hr_multi_message.end_validation_set;
620
621 IF g_debug THEN
622 hr_utility.set_location(l_proc, 20);
623 END IF;
624
625 --
626 -- Dependent validation.
627 --
628 -- Association uniqueness check.
629 --
630 per_seu_bus.chk_association_unique
631 (p_security_user_id => p_rec.security_user_id
632 ,p_user_id => p_rec.user_id
633 ,p_security_profile_id => p_rec.security_profile_id
634 ,p_object_version_number => p_rec.object_version_number);
635
636 IF g_debug THEN
637 hr_utility.set_location(' Leaving:'||l_proc, 999);
638 END IF;
639
640 End insert_validate;
641 --
642 -- ----------------------------------------------------------------------------
643 -- |---------------------------< update_validate >----------------------------|
644 -- ----------------------------------------------------------------------------
645 Procedure update_validate
646 (p_effective_date in date
647 ,p_rec in per_seu_shd.g_rec_type
648 ) is
649 --
650 l_proc varchar2(72) := g_package||'update_validate';
651 --
652 Begin
653
654 IF g_debug THEN
655 hr_utility.set_location('Entering:'||l_proc, 5);
656 END IF;
657
658 --
659 -- Call all supporting business operations
660 --
661 --
662 -- This table does not have a mandatory business_group_id
663 -- column, so client_info is not populated by calling the
664 -- per_seu_bus.set_security_group_id procedure.
665 -- Here, validation is performed without a business group context,
666 -- so any lookup code validation should use HR_STANDARD_LOOKUPS and not
667 -- HR_LOOKUPS.
668 --
669 -- Validate Dependent Attributes
670 --
671 chk_non_updateable_args
672 (p_effective_date => p_effective_date
673 ,p_rec => p_rec
674 );
675
676 --
677 -- Validate the security profile.
678 --
679 per_seu_bus.chk_security_profile_id
680 (p_security_user_id => p_rec.security_user_id
681 ,p_security_profile_id => p_rec.security_profile_id
682 ,p_object_version_number => p_rec.object_version_number);
683
684 IF g_debug THEN
685 hr_utility.set_location(l_proc, 10);
686 END IF;
687
688 --
689 -- Validate the user.
690 --
691 per_seu_bus.chk_user_id
692 (p_security_user_id => p_rec.security_user_id
693 ,p_user_id => p_rec.user_id
694 ,p_object_version_number => p_rec.object_version_number
695 ,p_effective_date => p_effective_date);
696
697 --
698 -- Validate the process_in_next_run_flag
699 --
700 per_seu_bus.chk_process_in_next_run_flag
701 (p_security_user_id => p_rec.security_user_id
702 ,p_process_in_next_run_flag => p_rec.process_in_next_run_flag
703 ,p_object_version_number => p_rec.object_version_number);
704
705 --
706 -- End exclusive validation.
707 --
708 hr_multi_message.end_validation_set;
709
710 IF g_debug THEN
711 hr_utility.set_location(l_proc, 20);
712 END IF;
713
714 --
715 -- Dependent validation.
716 --
717 -- Association uniqueness check.
718 --
719 per_seu_bus.chk_association_unique
720 (p_security_user_id => p_rec.security_user_id
721 ,p_user_id => p_rec.user_id
722 ,p_security_profile_id => p_rec.security_profile_id
723 ,p_object_version_number => p_rec.object_version_number);
724
725 IF g_debug THEN
726 hr_utility.set_location(' Leaving:'||l_proc, 999);
727 END IF;
728
729 End update_validate;
730 --
731 -- ----------------------------------------------------------------------------
732 -- |---------------------------< delete_validate >----------------------------|
733 -- ----------------------------------------------------------------------------
734 Procedure delete_validate
735 (p_rec in per_seu_shd.g_rec_type
736 ) is
737 --
738 l_proc varchar2(72) := g_package||'delete_validate';
739 --
740 Begin
741 hr_utility.set_location('Entering:'||l_proc, 5);
742 --
743 -- Call all supporting business operations
744 --
745 hr_utility.set_location(' Leaving:'||l_proc, 10);
746 End delete_validate;
747 --
748 end per_seu_bus;