DBA Data[Home] [Help]

PACKAGE BODY: APPS.HR_STARTUP_DATA_API_SUPPORT

Source


1 PACKAGE BODY hr_startup_data_api_support AS
2 /* $Header: hrsdasup.pkb 120.0 2005/05/31 02:37:18 appldev noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |-----------------------< enable_startup_mode >----------------------------|
6 -- ----------------------------------------------------------------------------
7 PROCEDURE enable_startup_mode
8                  (p_mode IN varchar2
9                  ,p_startup_session_id IN number default null) IS
10 --
11 BEGIN
12   --
13   hr_startup_data_api_support.g_startup_mode := p_mode;
14   hr_startup_data_api_support.g_startup_session_id := p_startup_session_id;
15   hr_utility.trace('enable_startup_mode');
16   hr_utility.trace('mode is: ' || hr_startup_data_api_support.g_startup_mode);
17   hr_utility.trace('sessionid is: '||to_char(hr_startup_data_api_support.g_startup_session_id));
18   --
19 END enable_startup_mode;
20 --
21 -- ----------------------------------------------------------------------------
22 -- |-----------------------< return_startup_mode >----------------------------|
23 -- ----------------------------------------------------------------------------
24 FUNCTION return_startup_mode RETURN varchar2 IS
25 --
26 BEGIN
27   hr_utility.trace('entering return_startup_mode');
28   hr_utility.trace('return val : ' || hr_startup_data_api_support.g_startup_mode);
29   RETURN (hr_startup_data_api_support.g_startup_mode);
30 END return_startup_mode;
31 --
32 -- ----------------------------------------------------------------------------
33 -- |----------------------< create_owner_definition >-------------------------|
34 -- ----------------------------------------------------------------------------
35 PROCEDURE create_owner_definition(p_product_shortname IN varchar2
36                                  ,p_validate IN boolean) IS
37 --
38 -- Cursor to determine session_id.
39 CURSOR csr_get_session_id IS
40   SELECT userenv('sessionid') from dual;
41 --
42 BEGIN
43   --
44   -- Issue savepoint
45   SAVEPOINT ins_owner_def;
46   --
47   -- Fetch session_id
48   IF hr_startup_data_api_support.g_session_id IS NULL THEN
49     if hr_startup_data_api_support.g_startup_session_id is null then
50       OPEN csr_get_session_id;
51       FETCH csr_get_session_id INTO hr_startup_data_api_support.g_session_id;
52       CLOSE csr_get_session_id;
53     else
54       hr_startup_data_api_support.g_session_id :=
55                           hr_startup_data_api_support.g_startup_session_id;
56     end if;
57   END IF;
58   --
59   hr_utility.trace('create_owner_definition');
60   hr_utility.trace('session id: ' || to_char(hr_startup_data_api_support.g_session_id));
61   hr_utility.trace('product_short_name: ' || p_product_shortname);
62   INSERT INTO hr_owner_definitions
63     (session_id
64     ,product_short_name)
65   VALUES
66     (hr_startup_data_api_support.g_session_id
67     ,p_product_shortname);
68   --
69   -- When in validation mode, raise validation enabled exception
70   IF p_validate THEN
71      hr_utility.trace('p_validate is TRUE');
72      raise hr_api.validate_enabled;
73   END IF;
74   --
75 EXCEPTION
76   WHEN hr_api.validate_enabled THEN
77      -- As validate_enabled exception raised, roll back to savepoint
78      hr_utility.trace('raising hr_api.validate_enabled');
79      ROLLBACK TO ins_owner_def;
80   WHEN others THEN
81      -- Unexpected error
82      hr_utility.trace('raising unknown error');
83      ROLLBACK TO ins_owner_def;
84      raise;
85 END create_owner_definition;
86 --
87 -- ----------------------------------------------------------------------------
88 -- |----------------------< delete_owner_definitions >------------------------|
89 -- ----------------------------------------------------------------------------
90 PROCEDURE delete_owner_definitions(p_validate IN boolean) IS
91 --
92 CURSOR csr_get_sessionid IS
93   SELECT userenv('sessionid')
94     FROM dual;
95 --
96 BEGIN
97   --
98   hr_utility.trace('delete_owner_definitions');
99   -- Issue savepoint
100   SAVEPOINT del_owner_defs;
101   --
102   -- Delete rows for current session
103   DELETE FROM hr_owner_definitions
104   WHERE session_id = userenv('sessionid');
105   --
106   -- When in validation mode, raise validation enabled exception
107   IF p_validate THEN
108      hr_utility.trace('p_validate is TRUE');
109      RAISE hr_api.validate_enabled;
110   END IF;
111   --
112 EXCEPTION
113   WHEN hr_api.validate_enabled THEN
114     --
115     -- Rollback to savepoint, as validate_enabled trigger has been raised
116     hr_utility.trace('raising hr_api.validate_enabled');
117     ROLLBACK TO del_owner_defs;
118     --
119   WHEN OTHERS THEN
120     -- Unexpected error
121     hr_utility.trace('raising unknown error');
122     ROLLBACK TO del_owner_defs;
123     RAISE;
124 END delete_owner_definitions;
125 --
126 -- ----------------------------------------------------------------------------
127 -- |--------------------------< mode_allowed >--------------------------------|
128 -- ----------------------------------------------------------------------------
129 PROCEDURE mode_allowed(p_generic IN boolean
130                       ,p_startup IN boolean
131                       ,p_user    IN boolean) IS
132 --
133 BEGIN
134   hr_startup_data_api_support.g_generic_allowed := p_generic;
135   hr_startup_data_api_support.g_startup_allowed := p_startup;
136   hr_startup_data_api_support.g_user_allowed    := p_user;
137   hr_utility.trace('mode_allowed');
138   if p_generic then hr_utility.trace('p_generic : TRUE'); else hr_utility.trace('p_generic : FALSE'); end if;
139   if p_startup then hr_utility.trace('p_startup : TRUE'); else hr_utility.trace('p_startup : FALSE'); end if;
140   if p_user then hr_utility.trace('p_user : TRUE'); else hr_utility.trace('p_user : FALSE'); end if;
141 END mode_allowed;
142 --
143 -- ----------------------------------------------------------------------------
144 -- |-----------------------< chk_startup_action >-----------------------------|
145 -- ----------------------------------------------------------------------------
146 --
147 -- Description:
148 --  This procedure will check that the current action is allowed according to
149 --  the current startup mode.
150 --
151 -- ----------------------------------------------------------------------------
152 PROCEDURE chk_startup_action
153   (p_generic_allowed   IN boolean
154   ,p_startup_allowed   IN boolean
155   ,p_user_allowed      IN boolean
156   ,p_business_group_id    IN number
157   ,p_legislation_code     IN varchar2
158   ,p_legislation_subgroup IN varchar2
159   ) IS
160 --
161 CURSOR csr_check_exists (p_session_id number) IS
162   SELECT 'Y'
163     FROM hr_owner_definitions def
164    WHERE def.session_id = p_session_id;
165 --
166 l_exists  varchar2(1);
167 l_mode    varchar2(10);
168 l_proc    varchar2(72) := 'chk_startup_action';
169 l_session_id number;
170 --
171 BEGIN
172   -- fetch startup mode
173   l_mode := hr_startup_data_api_support.return_startup_mode;
174   l_session_id := nvl(hr_startup_data_api_support.g_startup_session_id
175                      , userenv('sessionid'));
176   --
177   hr_utility.trace('chk_startup_action');
178   hr_utility.trace('l_session_id : ' || to_char(l_session_id));
179   hr_utility.trace('hr_startup_data_api_support.g_startup_session_id : ' || to_char(hr_startup_data_api_support.g_startup_session_id));
180   hr_utility.trace('l_mode : ' || l_mode);
181   hr_utility.trace('p_business_group_id : ' || nvl(to_char(p_business_group_id), 'NULL'));
182   hr_utility.trace('p_legislation_code : ' || nvl(p_legislation_code, 'NULL'));
183   hr_utility.trace('p_legislation_subgroup : ' || nvl(p_legislation_subgroup, 'NULL'));
184 
185   -- Only perform checks is API is not being called by SDM
186   IF (l_mode <> 'DELIVERY') THEN
187      IF ((p_business_group_id IS NULL) AND
188          (p_legislation_code IS NULL) AND
189          (p_legislation_subgroup IS NULL)) THEN
190         IF ((l_mode <> 'GENERIC') OR (NOT p_generic_allowed)) THEN
191            -- Generic rows being inserted, yet shouldnt be
192            fnd_message.set_name('PER', 'PER_289140_STARTUP_GEN_MOD_ERR');
193            fnd_message.raise_error;
194         ELSE
195            hr_utility.trace('Entering PER_289141_STARTUP_OWN_DEF_ERR else stmt');
196            hr_utility.trace('l_session_id : ' || to_char(l_session_id));
197            OPEN csr_check_exists(l_session_id);
198            FETCH csr_check_exists INTO l_exists;
199            IF csr_check_exists%NOTFOUND THEN
200               hr_utility.trace('didnt find the id');
201               CLOSE csr_check_exists;
202               fnd_message.set_name('PER', 'PER_289141_STARTUP_OWN_DEF_ERR');
203               fnd_message.raise_error;
204            END IF;
205            CLOSE csr_check_exists;
206         END IF;
207      ELSIF ((p_business_group_id IS NULL) AND
208             (p_legislation_code IS NOT NULL)) THEN
209         IF ((l_mode <> 'STARTUP') OR (NOT p_startup_allowed)) THEN
210            -- Startup row being inserted, but shouldnt be
211            fnd_message.set_name('PER', 'PER_289142_STARTUP_ST_MODE_ERR');
212            fnd_message.raise_error;
213         ELSE
214            OPEN csr_check_exists(l_session_id);
215            FETCH csr_check_exists INTO l_exists;
216            IF csr_check_exists%NOTFOUND THEN
217               CLOSE csr_check_exists;
218               fnd_message.set_name('PER', 'PER_289141_STARTUP_OWN_DEF_ERR');
219               fnd_message.raise_error;
220            END IF;
221            CLOSE csr_check_exists;
222         END IF;
223      ELSE
224         IF ((l_mode <> 'USER') OR (NOT p_user_allowed)) THEN
225            fnd_message.set_name('PER', 'PER_289143_STARTUP_USR_MOD_ERR');
226            fnd_message.raise_error;
227         END IF;
228      END IF;
229   END IF;
230 END chk_startup_action;
231 --
232 -- ----------------------------------------------------------------------------
233 -- |--------------------< chk_upd_del_startup_action >------------------------|
234 -- ----------------------------------------------------------------------------
235 PROCEDURE chk_upd_del_startup_action
236   (p_generic_allowed   IN boolean
237   ,p_startup_allowed   IN boolean
238   ,p_user_allowed      IN boolean
239   ,p_business_group_id    IN number
240   ,p_legislation_code     IN varchar2
241   ,p_legislation_subgroup IN varchar2
242   ) IS
243 --
244 l_mode    varchar2(10);
245 l_proc    varchar2(72) := 'chk_startup_action';
246 --
247 BEGIN
248   -- fetch startup mode
249   l_mode := hr_startup_data_api_support.return_startup_mode;
250   -- Only perform checks if API is not being called by SDM
251   IF (l_mode <> 'DELIVERY') THEN
252      IF ((p_business_group_id IS NULL) AND
253          (p_legislation_code IS NULL) AND
254          (p_legislation_subgroup IS NULL)) THEN
255         IF ((l_mode <> 'GENERIC') OR (NOT p_generic_allowed)) THEN
256            -- Generic rows being inserted, yet shouldnt be
257            fnd_message.set_name('PER', 'PER_289140_STARTUP_GEN_MOD_ERR');
258            fnd_message.raise_error;
259         END IF;
260      ELSIF ((p_business_group_id IS NULL) AND
261             (p_legislation_code IS NOT NULL)) THEN
262         IF ((l_mode <> 'STARTUP') OR (NOT p_startup_allowed)) THEN
263            -- Startup row being inserted, but shouldnt be
264            fnd_message.set_name('PER', 'PER_289142_STARTUP_ST_MODE_ERR');
265            fnd_message.raise_error;
266         END IF;
267      ELSE
268         IF ((l_mode <> 'USER') OR (NOT p_user_allowed)) THEN
269            fnd_message.set_name('PER', 'PER_289143_STARTUP_USR_MOD_ERR');
270            fnd_message.raise_error;
271         END IF;
272      END IF;
273   END IF;
274 END chk_upd_del_startup_action;
275 --
276 END hr_startup_data_api_support;