DBA Data[Home] [Help]

PACKAGE BODY: APPS.PV_USER_RESP_PVT

Source


1 PACKAGE BODY Pv_User_Resp_Pvt AS
2  /* $Header: pvxvpurb.pls 120.9 2006/05/05 13:32:50 dgottlie ship $ */
3 
4 -- ===============================================================
5 -- Start of Comments
6 -- Package name
7 --          PV_USER_RESP_PUB
8 -- Purpose
9 --
10 -- History
11 --         24-OCT-2002    Jessica.Lee         Created
12 --         02-OCT-2003    Karen.Tsao          Modified for 11.5.10
13 --         28-OCT-2003    Karen.Tsao          Made changes in assign_resp, get_default_resp, and get_default_org_resp
14 --         04-NOV-2003    Karen.Tsao          Change i := 0 to i := 1 in get_store_prgm_resp.
15 --         11-NOV-2003    Karen.Tsao          Change the cursors c_get_user_resp_groups (in assign cases) to query
16 --                                            fnd_responsibility_vl to get the application_id.
17 --         12-NOV-2003    Karen.Tsao          Added procedure manage_resp_on_address_change() and
18 --                                            function manage_resp_on_address_change() for business event subscription.
19 --         14-NOV-2003    Karen.Tsao          1. Changed cursor name from c_get_user_resp_groups to c_get_application_id (in assign cases).
20 --                                            2. Modified the way to handle store responsibility.
21 --                                            3. Changed the method name from get_default_and_assign to get_default_assign_addrow.
22 --         19-NOV-2003    Karen.Tsao          Took out l_cnt delaration and := 1 for the FOR-LOOP.
23 --         10-DEC-2003    Karen.Tsao          Modified.
24 --         11-FEB-2004    Karen.Tsao          Fixed for bug 3428985. Added get_partner_users_2(). Modified manage_ter_exp_memb_resp()
25 --                                            and revoke_default_resp(), make a call to get_partner_users_2() instead of get_partner_users().
26 --         19-FEB-2004    Karen.Tsao          Fixed for bug 3436285. Added adjust_user_resps() API.
27 --         12-MAR-2003    pukken              TO fix bug 3492311. modified manage_resp_on_address_change subscription
28 --         05-APR-2004    Karen.Tsao          Fixed for bug 3533631.
29 --         30-APR-2004    Karen.Tsao          Fixed for bug 3586212. Added pvpp.partner_id = p_partner_id in API assign_default_resp().
30 --         24-MAY-2004    Karen.Tsao          Fixed for sql repository. Took out the c_get_application_id and hard code the iStore application to 671.
31 --         22-JUL-2004    Karen.Tsao          Fixed for sql repository. Bug #3766776.
32 --         10-AUG-2004    Karen.Tsao          Fixed for bug 3824526. Updated create_resp_mapping() API.
33 --         13-AUG-2004    Karen.Tsao          Fixed for bug 3830319. Created manage_merged_party_memb_resp() API for party merge routine.
34 --         18-AUG-2004    Karen.Tsao          Updated the logic in manage_merged_party_memb_resp() API based on contact merge happening after resp merge.
35 --         14-APR-2004    Karen.Tsao          Make update_resp_mapping into concurrent program call exec_cre_upd_del_resp_mapping (same as
36 --                                            create and delete). Therefore, change API name exec_cre_or_del_resp_mapping to exec_cre_upd_del_resp_mapping.
37 --         07-OCT-2005    Karen.Tsao          Fixed for bug 4644887 - took out the reference to fnd_user_resp_groups in get_partner_users_2().
38 --
39 --
40 -- NOTE
41 --
42 -- End of Comments
43 -- ===============================================================
44 
45 G_PKG_NAME   CONSTANT VARCHAR2(30) := 'PV_USER_RESP_PVT';
46 G_FILE_NAME  CONSTANT VARCHAR2(12) := 'pvxvpurb.pls';
47 
48 G_APP_ID CONSTANT NUMBER := 691;
49 
50 PV_DEBUG_HIGH_ON CONSTANT BOOLEAN := Fnd_Msg_Pub.CHECK_MSG_LEVEL(Fnd_Msg_Pub.G_MSG_LVL_DEBUG_HIGH);
51 PV_DEBUG_LOW_ON CONSTANT BOOLEAN := Fnd_Msg_Pub.CHECK_MSG_LEVEL(Fnd_Msg_Pub.G_MSG_LVL_DEBUG_LOW);
52 PV_DEBUG_MEDIUM_ON CONSTANT BOOLEAN := Fnd_Msg_Pub.CHECK_MSG_LEVEL(Fnd_Msg_Pub.G_MSG_LVL_DEBUG_MEDIUM);
53 g_log_level     CONSTANT NUMBER := FND_LOG.LEVEL_ERROR;
54 g_log_to_file            VARCHAR2(5)  := 'N';
55 
56 bad_action                     EXCEPTION;
57 NO_SOURCE_RESP_MAP_RULE_ID     EXCEPTION;
58 EXC_ERROR                      EXCEPTION;
59 no_user_name                   EXCEPTION;
60 
61 /*
62 * private Debug_Log
63 * input: p_msg_string, p_msg_type
64 * Write the message into log
65 *
66 */
67 PROCEDURE Debug_Log(
68    p_msg_string    IN VARCHAR2,
69    p_msg_type      IN VARCHAR2 := 'PV_DEBUG_MESSAGE'
70 )
71 IS
72 BEGIN
73    IF (PV_DEBUG_HIGH_ON) THEN
74      Pvx_Utility_Pvt.debug_message('g_log_to_file = ' || g_log_to_file);
75    END IF;
76    IF (g_log_to_file = 'N') THEN
77         Pvx_Utility_Pvt.debug_message(p_msg_string);
78    ELSIF (g_log_to_file = 'Y') THEN
79       FND_MESSAGE.Set_Name('PV', p_msg_type);
80       FND_MESSAGE.Set_Token('TEXT', p_msg_string);
81       FND_FILE.PUT_LINE( FND_FILE.LOG,  fnd_message.get );
82    END IF;
83 END Debug_Log;
84 
85 /*****************************
86  * debug_message
87  *****************************/
88 PROCEDURE debug_message
89 (
90     p_log_level IN NUMBER
91    ,p_module_name    IN VARCHAR2
92    ,p_text   IN VARCHAR2
93 )
94 IS
95 BEGIN
96 
97   IF  (p_log_level>= FND_LOG.G_CURRENT_RUNTIME_LEVEL) THEN
98       FND_LOG.STRING(p_log_level, p_module_name, p_text);
99   END IF;
100 
101 
102 END debug_message;
103 
104 /*****************************
105  * WRITE_LOG
106  *****************************/
107 PROCEDURE WRITE_LOG
108 (
109    p_api_name      IN VARCHAR2
110    , p_log_message   IN VARCHAR2
111 )
112 IS
113 
114 BEGIN
115   debug_message (
116       p_log_level     => g_log_level
117      ,p_module_name   => 'plsql.pv'||'.'|| g_pkg_name||'.'||p_api_name||'.'||p_log_message
118      ,p_text          => p_log_message
119   );
120 END WRITE_LOG;
121 
122 /*
123 * get_partner_users
124 * get the list of partner users based on the partner id and partner type
125 *
126 */
127 FUNCTION get_partner_users (
128      p_partner_id		       IN NUMBER,
129      p_user_role_code       IN VARCHAR2
130 )
131 RETURN JTF_NUMBER_TABLE
132 IS
133    l_user_ids_tbl JTF_NUMBER_TABLE  := JTF_NUMBER_TABLE();
134    l_user_id      NUMBER;
135    i              NUMBER := 1;
136 
137    CURSOR c_primary_user_ids IS
138       SELECT user_id
139       FROM pv_partner_primary_users_v
140       WHERE partner_id = p_partner_id;
141 
142    CURSOR c_business_user_ids IS
143       SELECT user_id
144       FROM pv_partner_business_users_v
145       WHERE partner_id = p_partner_id;
146 
147 BEGIN
148    IF (PV_DEBUG_HIGH_ON) THEN
149       Debug_Log('get_partner_users: - START');
150       Debug_Log('get_partner_users: p_user_role_code = ' || p_user_role_code);
151    END IF;
152    IF (p_user_role_code = G_ALL)  THEN
153       IF (PV_DEBUG_HIGH_ON) THEN
154          Debug_Log('get_partner_users: p_user_role_code = G_ALL');
155       END IF;
156       -- Primary users
157       FOR x IN c_primary_user_ids LOOP
158          IF (PV_DEBUG_HIGH_ON) THEN
159             Debug_Log('get_partner_users: i = ' || i);
160             Debug_Log('get_partner_users: x.user_id = ' || x.user_id);
161          END IF;
162          l_user_ids_tbl.extend;
163      		l_user_ids_tbl(i) := x.user_id;
164      		i := i+1;
165   		END LOOP;
166       -- Business users
167       FOR x IN c_business_user_ids LOOP
168          IF (PV_DEBUG_HIGH_ON) THEN
169             Debug_Log('get_partner_users: i = ' || i);
170             Debug_Log('get_partner_users: x.user_id = ' || x.user_id);
171          END IF;
172          l_user_ids_tbl.extend;
173      		l_user_ids_tbl(i) := x.user_id;
174      		i := i+1;
175   		END LOOP;
176    ELSIF (p_user_role_code = G_PRIMARY)  THEN
177       IF (PV_DEBUG_HIGH_ON) THEN
178          Debug_Log('get_partner_users: p_user_role_code = G_PRIMARY');
179       END IF;
180       FOR x IN c_primary_user_ids LOOP
181          IF (PV_DEBUG_HIGH_ON) THEN
182             Debug_Log('get_partner_users: i = ' || i);
183             Debug_Log('get_partner_users: x.user_id = ' || x.user_id);
184          END IF;
185          l_user_ids_tbl.extend;
186      		l_user_ids_tbl(i) := x.user_id;
187      		i := i+1;
188   		END LOOP;
189    ELSIF (p_user_role_code = G_BUSINESS)  THEN
190       IF (PV_DEBUG_HIGH_ON) THEN
191          Debug_Log('get_partner_users: p_user_role_code = G_BUSINESS');
192       END IF;
193       FOR x IN c_business_user_ids LOOP
194          IF (PV_DEBUG_HIGH_ON) THEN
195             Debug_Log('get_partner_users: i = ' || i);
196             Debug_Log('get_partner_users: x.user_id = ' || x.user_id);
197          END IF;
198          l_user_ids_tbl.extend;
199      		l_user_ids_tbl(i) := x.user_id;
200      		i := i+1;
201   		END LOOP;
202   END IF;
203    IF (PV_DEBUG_HIGH_ON) THEN
204       Debug_Log('get_partner_users: - END');
205    END IF;
206 
207   RETURN l_user_ids_tbl;
208   EXCEPTION WHEN OTHERS THEN
209  	RETURN NULL;
210 END; -- Endo of get_partner_users_
211 
212 /*
213 * get_partner_users_2
214 * get the list of partner users based on the partner id and partner type
215 * differencies between get_partner_users and get_partner_users_2 is:
216 * instead of using views pv_partner_primary_users_v and pv_partner_business_users_v
217 * hardcoded the query of the views but took out the where status = 'A'
218 */
219 FUNCTION get_partner_users_2 (
220      p_partner_id		       IN NUMBER,
221      p_user_role_code       IN VARCHAR2
222 )
223 RETURN JTF_NUMBER_TABLE
224 IS
225    l_user_ids_tbl JTF_NUMBER_TABLE  := JTF_NUMBER_TABLE();
226    l_user_id      NUMBER;
227    i              NUMBER := 1;
228 
229    CURSOR c_primary_user_ids IS
230       SELECT user_id
231       FROM   (
232              SELECT jtfre.user_id user_id, pvpp.partner_id partner_id
233              FROM   pv_partner_profiles pvpp, hz_relationships hzr, jtf_rs_resource_extns jtfre, fnd_user fndu
234              WHERE  pvpp.partner_party_id = hzr.object_id
235                     AND hzr.relationship_code = 'EMPLOYEE_OF'
236                     AND HZR.subject_table_name ='HZ_PARTIES'
237                     AND HZR.object_table_name ='HZ_PARTIES'
238                     AND HZR.directional_flag = 'F'
239                     AND hzr.start_date <= SYSDATE
240 		    AND (hzr.end_date is null or  hzr.end_date > sysdate)
241 		    AND HZR.status = 'A'
242                     AND hzr.party_id = jtfre.source_id
243                     AND jtfre.category = 'PARTY'
244                     AND fndu.user_id = jtfre.user_id
245                     AND fndu.start_date <= sysdate
246                     AND (fndu.end_date is null or fndu.end_date > sysdate)
247                     AND exists (
248                                            SELECT jtfp1.principal_name username
249                                            FROM jtf_auth_principal_maps jtfpm, jtf_auth_principals_b jtfp1, jtf_auth_domains_b jtfd, jtf_auth_principals_b jtfp2, jtf_auth_role_perms jtfrp, jtf_auth_permissions_b jtfperm
250                                            WHERE jtfp1.is_user_flag=1
251                                            AND jtfp1.jtf_auth_principal_id=jtfpm.jtf_auth_principal_id
252                                            AND jtfp2.jtf_auth_principal_id=jtfpm.jtf_auth_parent_principal_id
253                                            AND jtfp2.is_user_flag=0
254                                            AND jtfp2.jtf_auth_principal_id=jtfrp.jtf_auth_principal_id
255                                            AND jtfrp.positive_flag = 1
256                                            AND jtfrp.jtf_auth_permission_id = jtfperm.jtf_auth_permission_id
257                                            AND jtfperm.permission_name in ('PV_PARTNER_USER', 'IBE_INT_PRIMARY_USER')
258                                            AND jtfd.jtf_auth_domain_id = jtfpm.jtf_auth_domain_id
259                                            AND jtfd.domain_name = 'CRM_DOMAIN'
260 					   and jtfp1.principal_name = jtfre.user_name
261                                            GROUP BY jtfp1.principal_name
262                                            HAVING count (distinct decode(jtfperm.permission_name, 'IBE_INT_PRIMARY_USER', null, jtfperm.permission_name) ) = 1
263                                            AND count(distinct decode(jtfperm.permission_name, 'IBE_INT_PRIMARY_USER', jtfperm.permission_name, null )) =1
264                                            )
265              )
266       WHERE  partner_id = p_partner_id;
267 
268    CURSOR c_business_user_ids IS
269       SELECT user_id
270       FROM   (
271              SELECT jtfre.user_id user_id, pvpp.partner_id partner_id
272              FROM pv_partner_profiles pvpp, hz_relationships hzr, jtf_rs_resource_extns jtfre, fnd_user fndu
273              WHERE pvpp.partner_party_id = hzr.object_id
274              AND hzr.relationship_code = 'EMPLOYEE_OF'
275              AND HZR.subject_table_name ='HZ_PARTIES'
276              AND HZR.object_table_name ='HZ_PARTIES'
277              AND HZR.directional_flag = 'F'
278              AND hzr.start_date <= SYSDATE
279 	     AND (hzr.end_date is null or  hzr.end_date > sysdate)
280 	     AND HZR.status = 'A'
281              AND hzr.party_id = jtfre.source_id
282              AND jtfre.category = 'PARTY'
283              AND fndu.user_id = jtfre.user_id
284              AND fndu.start_date <= sysdate
285              AND (fndu.end_date is null or fndu.end_date > sysdate)
286              AND exists (
287                                                SELECT jtfp1.principal_name username
288                                                FROM jtf_auth_principal_maps jtfpm, jtf_auth_principals_b jtfp1, jtf_auth_domains_b jtfd, jtf_auth_principals_b jtfp2, jtf_auth_role_perms jtfrp, jtf_auth_permissions_b jtfperm
289                                                WHERE jtfp1.is_user_flag = 1
290                                                AND jtfp1.jtf_auth_principal_id = jtfpm.jtf_auth_principal_id
291                                                AND jtfpm.jtf_auth_parent_principal_id = jtfp2.jtf_auth_principal_id
292                                                AND jtfp2.is_user_flag = 0
293                                                AND jtfp2.jtf_auth_principal_id = jtfrp.jtf_auth_principal_id
294                                                AND jtfrp.positive_flag = 1
295                                                AND jtfrp.jtf_auth_permission_id = jtfperm.jtf_auth_permission_id
296                                                AND jtfperm.permission_name in ('PV_PARTNER_USER', 'IBE_INT_PRIMARY_USER')
297                                                AND jtfd.jtf_auth_domain_id = jtfpm.jtf_auth_domain_id
298                                                AND jtfd.domain_name = 'CRM_DOMAIN'
299 					       and jtfp1.principal_name = jtfre.user_name
300                                                GROUP BY jtfp1.principal_name
301                                                HAVING count( distinct decode(jtfperm.permission_name, 'IBE_INT_PRIMARY_USER', null, jtfperm.permission_name ) ) = 1
302                                                AND count (distinct decode(jtfperm.permission_name, 'IBE_INT_PRIMARY_USER' , jtfperm.permission_name, null ) ) = 0 )
303              )
304       WHERE  partner_id = p_partner_id;
305 
306 BEGIN
307    IF (PV_DEBUG_HIGH_ON) THEN
308       Debug_Log('get_partner_users_2: - START');
309       Debug_Log('get_partner_users_2: p_user_role_code = ' || p_user_role_code);
310    END IF;
311    IF (p_user_role_code = G_ALL)  THEN
312       IF (PV_DEBUG_HIGH_ON) THEN
313          Debug_Log('get_partner_users_2: p_user_role_code = G_ALL');
314       END IF;
315       -- Primary users
316       FOR x IN c_primary_user_ids LOOP
317          IF (PV_DEBUG_HIGH_ON) THEN
318             Debug_Log('get_partner_users_2: i = ' || i);
319             Debug_Log('get_partner_users_2: x.user_id = ' || x.user_id);
320          END IF;
321          l_user_ids_tbl.extend;
322      		l_user_ids_tbl(i) := x.user_id;
323      		i := i+1;
324   		END LOOP;
325       -- Business users
326       FOR x IN c_business_user_ids LOOP
327          IF (PV_DEBUG_HIGH_ON) THEN
328             Debug_Log('get_partner_users_2: i = ' || i);
329             Debug_Log('get_partner_users_2: x.user_id = ' || x.user_id);
330          END IF;
331          l_user_ids_tbl.extend;
332      		l_user_ids_tbl(i) := x.user_id;
333      		i := i+1;
334   		END LOOP;
335    ELSIF (p_user_role_code = G_PRIMARY)  THEN
336       IF (PV_DEBUG_HIGH_ON) THEN
337          Debug_Log('get_partner_users_2: p_user_role_code = G_PRIMARY');
338       END IF;
339       FOR x IN c_primary_user_ids LOOP
340          IF (PV_DEBUG_HIGH_ON) THEN
341             Debug_Log('get_partner_users_2: i = ' || i);
342             Debug_Log('get_partner_users_2: x.user_id = ' || x.user_id);
343          END IF;
344          l_user_ids_tbl.extend;
345      		l_user_ids_tbl(i) := x.user_id;
346      		i := i+1;
347   		END LOOP;
348    ELSIF (p_user_role_code = G_BUSINESS)  THEN
349       IF (PV_DEBUG_HIGH_ON) THEN
350          Debug_Log('get_partner_users_2: p_user_role_code = G_BUSINESS');
351       END IF;
352       FOR x IN c_business_user_ids LOOP
353          IF (PV_DEBUG_HIGH_ON) THEN
354             Debug_Log('get_partner_users_2: i = ' || i);
355             Debug_Log('get_partner_users_2: x.user_id = ' || x.user_id);
356          END IF;
357          l_user_ids_tbl.extend;
358      		l_user_ids_tbl(i) := x.user_id;
359      		i := i+1;
360   		END LOOP;
361   END IF;
362    IF (PV_DEBUG_HIGH_ON) THEN
363       Debug_Log('get_partner_users_2: - END');
364    END IF;
365 
366   RETURN l_user_ids_tbl;
367   EXCEPTION WHEN OTHERS THEN
368  	RETURN NULL;
369 END; -- Endo of get_partner_users_2
370 
371 /*
372 * get_partners
373 * get the list of partner ids based on the user id
374 *
375 */
376 FUNCTION get_partners (
377     p_user_id		     IN  NUMBER
378 )
379 RETURN JTF_NUMBER_TABLE
380 IS
381    l_partner_ids_tbl   JTF_NUMBER_TABLE  := JTF_NUMBER_TABLE();
382    l_user_id           NUMBER;
383    l_index             NUMBER := 1;
384 
385    CURSOR c_get_partner_id IS
386       select pvpp.partner_id partner_id
387       from   jtf_rs_resource_extns RES, hz_relationships hzr, pv_partner_profiles pvpp
388       where  RES.user_id = p_user_id
389       and    RES.category = 'PARTY'
390       and    RES.start_date_active <= SYSDATE and nvl(RES.end_date_active , sysdate) >= SYSDATE
391       and    RES.source_id = hzr.party_id and hzr.directional_flag = 'F'
392       and    hzr.relationship_code = 'EMPLOYEE_OF' and HZR.subject_table_name ='HZ_PARTIES'
393       and    HZR.object_table_name ='HZ_PARTIES' and hzr.start_date <= SYSDATE
394       and    (hzr.end_date is null or hzr.end_date > SYSDATE)
395       and    hzr.object_id = pvpp.partner_party_id
396       and    pvpp.status = 'A';
397 BEGIN
398    FOR x in c_get_partner_id
399    LOOP
400       IF (PV_DEBUG_HIGH_ON) THEN
401          Debug_Log('x.partner_id: ' || x.partner_id);
402       END IF;
403 
404       l_partner_ids_tbl.extend;
405       l_partner_ids_tbl(l_index) := x.partner_id;
406       l_index := l_index + 1;
407    END LOOP;
408   RETURN l_partner_ids_tbl;
409 EXCEPTION
410    WHEN OTHERS THEN
411  	   RETURN NULL;
412 END;
413 
414 /*
415 * assign_resp
416 * input: p_user_id, p_resp_id, p_app_id
417 * assigning the user p_user_id with resp p_resp_id for application p_app_id
418 *
419 */
420 
421 PROCEDURE assign_resp
422 (
423     p_api_version_number         IN   NUMBER,
424     p_init_msg_list              IN   VARCHAR2  := Fnd_Api.g_false,
425     p_commit                     IN   VARCHAR2  := Fnd_Api.g_false,
426     p_user_id			 		 IN   NUMBER,
427     p_resp_id		 			 IN   NUMBER,
428     p_app_id				 	 IN   NUMBER,
429     X_Return_Status		 		 OUT NOCOPY  VARCHAR2,
430     X_Msg_Count			 		 OUT NOCOPY  NUMBER,
431     X_Msg_Data			 		 OUT NOCOPY  VARCHAR2
432 )
433 IS
434 l_api_name                  CONSTANT  VARCHAR2(30) := 'assign_resp';
435 l_api_version_number        CONSTANT  NUMBER       := 1.0;
436 l_object_version_number     NUMBER;
437 BEGIN
438      ---- Initialize----------------
439 
440       -- Standard Start of API savepoint
441       SAVEPOINT assign_resp;
442 
443       -- Standard call to check for call compatibility.
444       IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
445                                          ,p_api_version_number
446                                          ,l_api_name
447                                          ,G_PKG_NAME
448                                          )
449       THEN
450           RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
451       END IF;
452 
453       -- Initialize message list if p_init_msg_list is set to TRUE.
454       IF Fnd_Api.to_Boolean( p_init_msg_list )
455       THEN
456          Fnd_Msg_Pub.initialize;
457       END IF;
458 
459       -- Debug Message
460       IF (PV_DEBUG_HIGH_ON) THEN
461          Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
462       END IF;
463 
464       -- Initialize API return status to SUCCESS
465       x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
466 
467       IF (p_user_id is null) THEN
468          FND_MESSAGE.SET_NAME  ('PV', 'PV_USER_ID_NULL');
469          FND_MSG_PUB.ADD;
470          raise FND_API.G_EXC_ERROR;
471       END IF;
472 
473       IF (p_resp_id is null) THEN
474          FND_MESSAGE.SET_NAME  ('PV', 'PV_RESP_ID_NULL');
475          FND_MSG_PUB.ADD;
476          raise FND_API.G_EXC_ERROR;
477       END IF;
478 
479       IF (p_app_id is null) THEN
480          FND_MESSAGE.SET_NAME  ('PV', 'PV_APPL_ID_NULL');
481          FND_MSG_PUB.ADD;
482          raise FND_API.G_EXC_ERROR;
483       END IF;
484 
485       Fnd_User_Resp_Groups_Api.UPLOAD_ASSIGNMENT(
486 	  		user_id => p_user_id,
487 	  		responsibility_id => p_resp_id,
488 	  		responsibility_application_id => p_app_id,
489 	  		start_date => SYSDATE,
490 	  		end_date => NULL,
491 	  		description => NULL );
492 
493      -- Check for commit : no commit at private procedure
494      --IF Fnd_Api.to_boolean(p_commit) THEN
495      --   COMMIT;
496      --END IF;
497 
498     Fnd_Msg_Pub.count_and_get(
499        p_encoded => Fnd_Api.g_false
500       ,p_count   => x_msg_count
501       ,p_data    => x_msg_data
502       );
503 
504       -- Debug Message
505       IF (PV_DEBUG_HIGH_ON) THEN
506 
507       Debug_Log('PRIVATE API: ' || l_api_name || ' - END');
508       END IF;
509 
510 EXCEPTION
511    WHEN Fnd_Api.G_EXC_ERROR THEN
512      ROLLBACK TO assign_resp;
513      x_return_status := Fnd_Api.G_RET_STS_ERROR;
514      -- Standard call to get message count and if count=1, get the message
515      Fnd_Msg_Pub.Count_And_Get (
516              p_encoded => Fnd_Api.G_FALSE
517             ,p_count   => x_msg_count
518             ,p_data    => x_msg_data
519             );
520 
521    WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
522      ROLLBACK TO assign_resp;
523      x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
524      -- Standard call to get message count and if count=1, get the message
525      Fnd_Msg_Pub.Count_And_Get (
526              p_encoded => Fnd_Api.G_FALSE
527             ,p_count   => x_msg_count
528             ,p_data    => x_msg_data
529             );
530 
531    WHEN OTHERS THEN
532      ROLLBACK TO assign_resp;
533      x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
534      IF Fnd_Msg_Pub.Check_Msg_Level ( Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
535      THEN
536         Fnd_Msg_Pub.Add_Exc_Msg( G_PKG_NAME,l_api_name);
537      END IF;
538      -- Standard call to get message count and if count=1, get the message
539      Fnd_Msg_Pub.Count_And_Get (
540              p_encoded => Fnd_Api.G_FALSE
541             ,p_count   => x_msg_count
542             ,p_data    => x_msg_data
543             );
544 
545 END assign_resp;
546 
547 /*
548 * revoke resp
549 * input: p_user_id, p_resp_id, p_app_id
550 * revoking user resp when the status code is upgraded, terminated or expired
551 * based on a p_user_id, we will revoke p_resp_id for the application p_app_id
552 */
553 PROCEDURE revoke_resp(
554     p_api_version_number         IN   NUMBER,
555     p_init_msg_list          	   IN   VARCHAR2  := Fnd_Api.g_false,
556     p_commit                 	   IN   VARCHAR2  := Fnd_Api.g_false,
557     p_user_id			 			   IN   NUMBER,
558     p_resp_id		 				   IN   NUMBER,
559     p_app_id				 		   IN   NUMBER,
560     p_security_group_id			   IN   NUMBER,
561     p_start_date			 		   IN   DATE,
562     p_description 				   IN   VARCHAR2,
563     x_return_status		 	      OUT NOCOPY  VARCHAR2,
564     x_msg_count			 		   OUT NOCOPY  NUMBER,
565     x_msg_data			 			   OUT NOCOPY  VARCHAR2
566 )
567 
568 IS
569    l_api_name                  CONSTANT  VARCHAR2(30) := 'revoke_resp';
570    l_api_version_number        CONSTANT  NUMBER       := 1.0;
571    l_object_version_number     NUMBER;
572 
573 BEGIN
574      ---- Initialize----------------
575 
576       -- Standard Start of API savepoint
577       SAVEPOINT revoke_resp;
578 
579       -- Standard call to check for call compatibility.
580       IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
581                                          ,p_api_version_number
582                                          ,l_api_name
583                                          ,G_PKG_NAME
584                                          )
585       THEN
586           RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
587       END IF;
588 
589       -- Initialize message list if p_init_msg_list is set to TRUE.
590       IF Fnd_Api.to_Boolean( p_init_msg_list )
591       THEN
592          Fnd_Msg_Pub.initialize;
593       END IF;
594 
595       -- Debug Message
596       IF (PV_DEBUG_HIGH_ON) THEN
597          Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
598       END IF;
599 
600       -- Initialize API return status to SUCCESS
601       x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
602 
603       Fnd_User_Resp_Groups_Api.UPLOAD_ASSIGNMENT(
604          user_id                        => p_user_id,
605          responsibility_id              => p_resp_id,
606          responsibility_application_id  => p_app_id,
607          security_group_id              => p_security_group_id,
608          start_date                     => p_start_date,
609          end_date                       => SYSDATE,
610          description                    => p_description
611       );
612 
613       Fnd_Msg_Pub.count_and_get(
614           p_encoded => Fnd_Api.g_false
615          ,p_count   => x_msg_count
616          ,p_data    => x_msg_data
617       );
618 
619       -- Debug Message
620       IF (PV_DEBUG_HIGH_ON) THEN
621 
622       Debug_Log('PRIVATE API: ' || l_api_name || ' - END');
623       END IF;
624 
625 EXCEPTION
626    WHEN Fnd_Api.G_EXC_ERROR THEN
627      ROLLBACK TO revoke_resp;
628      x_return_status := Fnd_Api.G_RET_STS_ERROR;
629      -- Standard call to get message count and if count=1, get the message
630      Fnd_Msg_Pub.Count_And_Get (
631              p_encoded => Fnd_Api.G_FALSE
632             ,p_count   => x_msg_count
633             ,p_data    => x_msg_data
634             );
635 
636    WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
637      ROLLBACK TO revoke_resp;
638      x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
639      -- Standard call to get message count and if count=1, get the message
640      Fnd_Msg_Pub.Count_And_Get (
641              p_encoded => Fnd_Api.G_FALSE
642             ,p_count   => x_msg_count
643             ,p_data    => x_msg_data
644             );
645 
646    WHEN OTHERS THEN
647      ROLLBACK TO revoke_resp;
648      x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
649      IF Fnd_Msg_Pub.Check_Msg_Level ( Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
650      THEN
651         Fnd_Msg_Pub.Add_Exc_Msg( G_PKG_NAME,l_api_name);
652      END IF;
653      -- Standard call to get message count and if count=1, get the message
654      Fnd_Msg_Pub.Count_And_Get (
655              p_encoded => Fnd_Api.G_FALSE
656             ,p_count   => x_msg_count
657             ,p_data    => x_msg_data
658             );
659 
660 
661 END revoke_resp;
662 
663 
664 /*
665 * revoke resp
666 * input: p_user_id, p_resp_id, p_app_id
667 * revoking user resp when the status code is upgraded, terminated or expired
668 * based on a p_user_id, we will revoke p_resp_id for the application p_app_id
669 */
670 PROCEDURE revoke_resp(
671     p_api_version_number         IN   NUMBER,
672     p_init_msg_list          	   IN   VARCHAR2  := Fnd_Api.g_false,
673     p_commit                 	   IN   VARCHAR2  := Fnd_Api.g_false,
674     p_user_id			 			   IN   JTF_NUMBER_TABLE,
675     p_resp_id		 				   IN   NUMBER,
676     x_return_status		 	      OUT NOCOPY  VARCHAR2,
677     x_msg_count			 		   OUT NOCOPY  NUMBER,
678     x_msg_data			 			   OUT NOCOPY  VARCHAR2
679 )
680 
681 IS
682    CURSOR c_get_user_resp_groups IS
683       SELECT  user_id, responsibility_id, responsibility_application_id, security_group_id, start_date, description
684       FROM    fnd_user_resp_groups
685       WHERE   user_id in (
686                SELECT * FROM TABLE (CAST(p_user_id AS JTF_NUMBER_TABLE))
687               )
688       AND     responsibility_id = p_resp_id;
689 
690    l_api_name                  CONSTANT  VARCHAR2(30) := 'revoke_resp';
691    l_api_version_number        CONSTANT  NUMBER       := 1.0;
692    l_object_version_number     NUMBER;
693 
694 BEGIN
695      ---- Initialize----------------
696 
697       -- Standard Start of API savepoint
698       SAVEPOINT revoke_resp;
699 
700 
701       -- Standard call to check for call compatibility.
702       IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
703                                          ,p_api_version_number
704                                          ,l_api_name
705                                          ,G_PKG_NAME
706                                          )
707       THEN
708           RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
709       END IF;
710 
711       -- Initialize message list if p_init_msg_list is set to TRUE.
712       IF Fnd_Api.to_Boolean( p_init_msg_list )
713       THEN
714          Fnd_Msg_Pub.initialize;
715       END IF;
716 
717       -- Initialize API return status to SUCCESS
718       x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
719 
720       IF (PV_DEBUG_HIGH_ON) THEN
721          Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
722       END IF;
723 
724        -- Debug Message
725       IF (PV_DEBUG_HIGH_ON) THEN
726          IF (p_user_id IS NULL) THEN
727             Debug_Log('PRIVATE API: p_user_id is null');
728          ELSE
729             FOR l_cnt IN 1..p_user_id.count LOOP
730                Debug_Log('PRIVATE API: p_user_id(' || l_cnt || ') = ' || p_user_id(l_cnt));
731             END LOOP;
732          END IF;
733          Debug_Log('PRIVATE API: p_resp_id = ' || p_resp_id);
734       END IF;
735 
736       FOR x IN c_get_user_resp_groups LOOP
737          -- Debug Message
738          IF (PV_DEBUG_HIGH_ON) THEN
739             Debug_Log('revoke_resp: x.responsibility_id = ' || x.responsibility_id);
740             Debug_Log('revoke_resp: x.user_id = ' || x.user_id);
741             Debug_Log('revoke_resp: x.responsibility_application_id = ' || x.responsibility_application_id);
742             Debug_Log('revoke_resp: x.security_group_id = ' || x.security_group_id);
743             Debug_Log('revoke_resp: x.start_date = ' || x.start_date);
744             Debug_Log('revoke_resp: x.description = ' || x.description);
745          END IF;
746 
747          revoke_resp(
748              p_api_version_number         => p_api_version_number
749             ,p_init_msg_list              => FND_API.G_FALSE
750             ,p_commit                     => FND_API.G_FALSE
751             ,p_user_id                    => x.user_id
752             ,p_resp_id                    => x.responsibility_id
753             ,p_app_id                     => x.responsibility_application_id
754             ,p_security_group_id          => x.security_group_id
755             ,p_start_date                 => x.start_date
756             ,p_description                => x.description
757             ,x_return_status              => x_return_status
758             ,x_msg_count                  => x_msg_count
759             ,x_msg_data                   => x_msg_data
760          );
761          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
762             RAISE FND_API.G_EXC_ERROR;
763          END IF;
764       END LOOP;
765 
766       Fnd_Msg_Pub.count_and_get(
767           p_encoded => Fnd_Api.g_false
768          ,p_count   => x_msg_count
769          ,p_data    => x_msg_data
770       );
771 
772       -- Debug Message
773       IF (PV_DEBUG_HIGH_ON) THEN
774 
775       Debug_Log('PRIVATE API: ' || l_api_name || ' - END');
776       END IF;
777 
778 EXCEPTION
779    WHEN Fnd_Api.G_EXC_ERROR THEN
780      ROLLBACK TO revoke_resp;
781      x_return_status := Fnd_Api.G_RET_STS_ERROR;
782      -- Standard call to get message count and if count=1, get the message
783      Fnd_Msg_Pub.Count_And_Get (
784              p_encoded => Fnd_Api.G_FALSE
785             ,p_count   => x_msg_count
786             ,p_data    => x_msg_data
787             );
788 
789    WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
790      ROLLBACK TO revoke_resp;
791      x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
792      -- Standard call to get message count and if count=1, get the message
793      Fnd_Msg_Pub.Count_And_Get (
794              p_encoded => Fnd_Api.G_FALSE
795             ,p_count   => x_msg_count
796             ,p_data    => x_msg_data
797             );
798 
799    WHEN OTHERS THEN
800      ROLLBACK TO revoke_resp;
801      x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
802      IF Fnd_Msg_Pub.Check_Msg_Level ( Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
803      THEN
804         Fnd_Msg_Pub.Add_Exc_Msg( G_PKG_NAME,l_api_name);
805      END IF;
806      -- Standard call to get message count and if count=1, get the message
807      Fnd_Msg_Pub.Count_And_Get (
808              p_encoded => Fnd_Api.G_FALSE
809             ,p_count   => x_msg_count
810             ,p_data    => x_msg_data
811             );
812 
813 
814 END revoke_resp;
815 
816 /*
817 * get_user_role_code
818 * This is to get the default responsibility using partner_id and user_rold
819 */
820 PROCEDURE get_user_role_code(
821     p_user_id            IN  NUMBER
822    ,x_user_role_code     OUT NOCOPY VARCHAR2
823 )
824 IS
825     CURSOR get_user_role IS
826       SELECT   jtfperm.permission_name
827       FROM     jtf_auth_principal_maps jtfpm,
828                jtf_auth_principals_b jtfp1, jtf_auth_domains_b jtfd,
829                jtf_auth_principals_b jtfp2,
830                jtf_auth_role_perms jtfrp,
831                jtf_auth_permissions_b jtfperm,
832                fnd_user fndu
833       WHERE    fndu.user_id = p_user_id
834       AND      jtfp1.principal_name = fndu.user_name
835       AND      jtfp1.is_user_flag=1
836       AND      jtfp1.jtf_auth_principal_id=jtfpm.jtf_auth_principal_id
837       AND      jtfpm.jtf_auth_parent_principal_id = jtfp2.jtf_auth_principal_id
838       AND      jtfp2.is_user_flag=0
839       AND      jtfp2.jtf_auth_principal_id = jtfrp.jtf_auth_principal_id
840       AND      jtfrp.positive_flag = 1
841       AND      jtfrp.jtf_auth_permission_id = jtfperm.jtf_auth_permission_id
842       AND      jtfperm.permission_name in ('IBE_INT_PRIMARY_USER', 'PV_PARTNER_USER')
843       AND      jtfd.jtf_auth_domain_id=jtfpm.jtf_auth_domain_id
844       AND      jtfd.domain_name='CRM_DOMAIN'
845       GROUP BY jtfperm.permission_name;
846 
847     is_partner_user boolean := false;
848     is_primary_user boolean := false;
849 
850 BEGIN
851    FOR x IN get_user_role LOOP
852       IF (x.permission_name = 'IBE_INT_PRIMARY_USER') THEN
853         is_primary_user     := true;
854       ELSIF (x.permission_name = 'PV_PARTNER_USER') THEN
855         is_partner_user  := true;
856       END IF;
857    END LOOP;
858 
859    IF((not is_partner_user) and (not is_primary_user)) THEN
860       FND_MESSAGE.SET_NAME  ('PV', 'PV_NOT_VALID_PARTNER_USER');
861       FND_MSG_PUB.ADD;
862       raise FND_API.G_EXC_ERROR;
863    ELSIF (is_primary_user) THEN
864       x_user_role_code := G_PRIMARY;
865    ELSE
866       x_user_role_code := G_BUSINESS;
867    END IF;
868 END get_user_role_code;
869 
870 /*
871 * get_default_resp
872 * This is to get the default responsibility using partner_id and user_rold
873 */
874 PROCEDURE get_default_resp(
875     p_api_version_number         IN   NUMBER
876    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
877    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
878    ,x_return_status              OUT  NOCOPY  VARCHAR2
879    ,x_msg_count                  OUT  NOCOPY  NUMBER
880    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
881    ,p_partner_id                 IN   NUMBER
882    ,p_user_role_code             IN   VARCHAR2
883    ,x_responsibility_id          OUT  NOCOPY NUMBER
884    ,x_resp_map_rule_id           OUT  NOCOPY NUMBER
885 )
886 IS
887    CURSOR c_get_resp_map_rule_info (cv_user_role_code VARCHAR2) IS
888       SELECT resp_map_rule_id, geo_hierarchy_id, responsibility_id
889       FROM   pv_ge_resp_map_rules
890       WHERE  user_role_code = p_user_role_code
891       AND    program_id is null
892       AND    delete_flag = 'N';
893 
894    CURSOR c_get_area1_resp (cv_user_role_code VARCHAR2) IS
895       SELECT rmr.resp_map_rule_id, rmr.responsibility_id
896       FROM   pv_ge_resp_map_rules rmr, jtf_loc_hierarchies_vl lh
897       WHERE  rmr.user_role_code = p_user_role_code
898       AND    rmr.program_id is null
899       AND    rmr.geo_hierarchy_id = lh.location_hierarchy_id
900       AND    lh.location_type_code = 'AREA1'
901       AND    rmr.delete_flag = 'N';
902 
903    l_api_name                  CONSTANT  VARCHAR2(30) := 'get_default_resp';
904    l_api_version_number        CONSTANT NUMBER   := 1.0;
905    l_geo_hierarchy_id_tbl      JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
906    l_responsibility_id_tbl     JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
907    l_resp_map_rule_id_tbl      JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
908    l_index                     NUMBER;
909    l_matched_geo_hierarchy_id  NUMBER;
910    l_responsibility_id         NUMBER;
911 
912 
913 BEGIN
914   ---- Initialize----------------
915 
916    -- Standard Start of API savepoint
917    SAVEPOINT get_default_resp;
918 
919    -- Standard call to check for call compatibility.
920    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
921                                       ,p_api_version_number
922                                       ,l_api_name
923                                       ,G_PKG_NAME
924                                       )
925    THEN
926        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
927    END IF;
928 
929    -- Initialize message list if p_init_msg_list is set to TRUE.
930    IF Fnd_Api.to_Boolean( p_init_msg_list )
931    THEN
932       Fnd_Msg_Pub.initialize;
933    END IF;
934 
935    -- Debug Message
936    IF (PV_DEBUG_HIGH_ON) THEN
937       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
938    END IF;
939 
940    -- Initialize API return status to SUCCESS
941    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
942 
943    l_index := 1;
944    FOR x IN c_get_resp_map_rule_info(p_user_role_code)
945    LOOP
946       l_geo_hierarchy_id_tbl.extend;
947       l_geo_hierarchy_id_tbl(l_index) := x.geo_hierarchy_id;
948       l_responsibility_id_tbl.extend;
949       l_responsibility_id_tbl(l_index) := x.responsibility_id;
950       l_resp_map_rule_id_tbl.extend;
951       l_resp_map_rule_id_tbl(l_index) := x.resp_map_rule_id;
952       IF (PV_DEBUG_HIGH_ON) THEN
953          Debug_Log('get_default_resp: l_index = ' || l_index);
954          Debug_Log('get_default_resp: l_geo_hierarchy_id_tbl(l_index) = ' || l_geo_hierarchy_id_tbl(l_index));
955          Debug_Log('get_default_resp: l_responsibility_id_tbl(l_index) = ' || l_responsibility_id_tbl(l_index));
956          Debug_Log('get_default_resp: l_resp_map_rule_id_tbl(l_index) = ' || l_resp_map_rule_id_tbl(l_index));
957       END IF;
958       l_index := l_index + 1;
959    END LOOP;
960 
961    PV_PARTNER_GEO_MATCH_PVT.Get_Ptnr_Matched_Geo_Id (
962       p_api_version_number         => p_api_version_number
963      ,p_init_msg_list              => FND_API.G_FALSE
964      ,x_return_status              => x_return_status
965      ,x_msg_count                  => x_msg_count
966      ,x_msg_data                   => x_msg_data
967      ,p_partner_id                 => p_partner_id
968      ,p_geo_hierarchy_id           => l_geo_hierarchy_id_tbl
969      ,x_geo_hierarchy_id           => l_matched_geo_hierarchy_id
970    );
971 
972    IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
973        RAISE FND_API.G_EXC_ERROR;
974     END IF;
975 
976    -- if l_matched_geo_hierarchy_id is null
977    -- most likely the partner doesn't have address in database
978    IF l_matched_geo_hierarchy_id is null THEN
979       IF (PV_DEBUG_HIGH_ON) THEN
980          Debug_Log('get_default_resp: l_matched_geo_hierarchy_id is null');
981       END IF;
982       FOR x IN c_get_area1_resp(p_user_role_code)
983       LOOP
984          x_responsibility_id := x.responsibility_id;
985          x_resp_map_rule_id := x.resp_map_rule_id;
986       END LOOP;
987       IF ((x_responsibility_id is null) or (x_resp_map_rule_id is null)) THEN
988         FND_MESSAGE.set_name('PV', 'PV_NO_DEFLT_RESP');
989         FND_MSG_PUB.add;
990         RAISE FND_API.G_EXC_ERROR;
991       END IF;
992    ELSE
993       IF (PV_DEBUG_HIGH_ON) THEN
994          Debug_Log('get_default_resp: l_matched_geo_hierarchy_id =' || l_matched_geo_hierarchy_id);
995       END IF;
996       FOR i IN 1..l_geo_hierarchy_id_tbl.COUNT
997       LOOP
998           IF l_geo_hierarchy_id_tbl(i) = l_matched_geo_hierarchy_id THEN
999             x_responsibility_id := l_responsibility_id_tbl(i);
1000             x_resp_map_rule_id := l_resp_map_rule_id_tbl(i);
1001             EXIT;
1002           END IF;
1003       END LOOP;
1004    END IF;
1005 
1006    IF (PV_DEBUG_HIGH_ON) THEN
1007       Debug_Log('get_default_resp: x_responsibility_id =' || x_responsibility_id);
1008       Debug_Log('get_default_resp: x_resp_map_rule_id =' || x_resp_map_rule_id);
1009    END IF;
1010 
1011    -- Check for commit
1012    IF FND_API.to_boolean(p_commit) THEN
1013       COMMIT;
1014    END IF;
1015 
1016    FND_MSG_PUB.count_and_get(
1017       p_encoded => FND_API.g_false
1018      ,p_count   => x_msg_count
1019      ,p_data    => x_msg_data
1020    );
1021 
1022 EXCEPTION
1023 
1024    WHEN PVX_Utility_PVT.resource_locked THEN
1025      x_return_status := FND_API.g_ret_sts_error;
1026          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
1027 
1028    WHEN FND_API.G_EXC_ERROR THEN
1029      ROLLBACK TO get_default_resp;
1030      x_return_status := FND_API.G_RET_STS_ERROR;
1031      -- Standard call to get message count and if count=1, get the message
1032      FND_MSG_PUB.Count_And_Get (
1033             p_encoded => FND_API.G_FALSE,
1034             p_count   => x_msg_count,
1035             p_data    => x_msg_data
1036      );
1037 
1038    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1039      ROLLBACK TO get_default_resp;
1040      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1041      -- Standard call to get message count and if count=1, get the message
1042      FND_MSG_PUB.Count_And_Get (
1043             p_encoded => FND_API.G_FALSE,
1044             p_count => x_msg_count,
1045             p_data  => x_msg_data
1046      );
1047 
1048    WHEN OTHERS THEN
1049      ROLLBACK TO get_default_resp;
1050      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1051      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1052      THEN
1053         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
1054      END IF;
1055      -- Standard call to get message count and if count=1, get the message
1056      FND_MSG_PUB.Count_And_Get (
1057             p_encoded => FND_API.G_FALSE,
1058             p_count => x_msg_count,
1059             p_data  => x_msg_data
1060      );
1061 
1062 END get_default_resp;
1063 
1064 /*
1065 * get_default_org_resp
1066 * This is to get the default responsibility using partner_org_id and user_rold
1067 * This will be used only during partner self_service flow as partner_id does
1068 * not exist before calling this API.
1069 */
1070 PROCEDURE get_default_org_resp(
1071     p_api_version_number         IN   NUMBER
1072    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
1073    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
1074    ,x_return_status              OUT  NOCOPY  VARCHAR2
1075    ,x_msg_count                  OUT  NOCOPY  NUMBER
1076    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
1077    ,p_partner_org_id             IN   NUMBER
1078    ,p_user_role_code             IN   VARCHAR2
1079    ,x_responsibility_id          OUT  NOCOPY NUMBER
1080    ,x_resp_map_rule_id           OUT  NOCOPY NUMBER
1081 )
1082 IS
1083    CURSOR c_get_resp_map_rule_info (cv_user_role_code VARCHAR2) IS
1084       SELECT resp_map_rule_id, geo_hierarchy_id, responsibility_id
1085       FROM   pv_ge_resp_map_rules
1086       WHERE  user_role_code = cv_user_role_code
1087       AND    program_id is null
1088       AND    delete_flag = 'N';
1089 
1090    CURSOR c_get_area1_resp (cv_user_role_code VARCHAR2) IS
1091       SELECT rmr.resp_map_rule_id, rmr.responsibility_id
1092       FROM   pv_ge_resp_map_rules rmr, jtf_loc_hierarchies_vl lh
1093       WHERE  rmr.user_role_code = p_user_role_code
1094       AND    rmr.program_id is null
1095       AND    rmr.geo_hierarchy_id = lh.location_hierarchy_id
1096       AND    lh.location_type_code = 'AREA1'
1097       AND    rmr.delete_flag = 'N';
1098 
1099    l_api_name                  CONSTANT  VARCHAR2(30) := 'get_default_org_resp';
1100    l_api_version_number        CONSTANT NUMBER   := 1.0;
1101    l_geo_hierarchy_id_tbl      JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
1102    l_responsibility_id_tbl     JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
1103    l_resp_map_rule_id_tbl      JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
1104    l_index                     NUMBER;
1105    l_matched_geo_hierarchy_id  NUMBER;
1106    l_responsibility_id                   NUMBER;
1107 
1108 
1109 BEGIN
1110   ---- Initialize----------------
1111 
1112    -- Standard Start of API savepoint
1113    SAVEPOINT get_default_org_resp;
1114 
1115    -- Standard call to check for call compatibility.
1116    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
1117                                       ,p_api_version_number
1118                                       ,l_api_name
1119                                       ,G_PKG_NAME
1120                                       )
1121    THEN
1122        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
1123    END IF;
1124 
1125    -- Initialize message list if p_init_msg_list is set to TRUE.
1126    IF Fnd_Api.to_Boolean( p_init_msg_list )
1127    THEN
1128       Fnd_Msg_Pub.initialize;
1129    END IF;
1130 
1131    -- Debug Message
1132    IF (PV_DEBUG_HIGH_ON) THEN
1133       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
1134    END IF;
1135 
1136    -- Initialize API return status to SUCCESS
1137    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
1138 
1139    l_index := 1;
1140    FOR x IN c_get_resp_map_rule_info(p_user_role_code)
1141    LOOP
1142       l_geo_hierarchy_id_tbl.extend;
1143       l_geo_hierarchy_id_tbl(l_index) := x.geo_hierarchy_id;
1144       l_responsibility_id_tbl.extend;
1145       l_responsibility_id_tbl(l_index) := x.responsibility_id;
1146       l_resp_map_rule_id_tbl.extend;
1147       l_resp_map_rule_id_tbl(l_index) := x.resp_map_rule_id;
1148       IF (PV_DEBUG_HIGH_ON) THEN
1149          Debug_Log('get_default_org_resp: l_index = ' || l_index);
1150          Debug_Log('get_default_org_resp: l_geo_hierarchy_id_tbl(l_index) = ' || l_geo_hierarchy_id_tbl(l_index));
1151          Debug_Log('get_default_org_resp: l_responsibility_id_tbl(l_index) = ' || l_responsibility_id_tbl(l_index));
1152          Debug_Log('get_default_org_resp: l_resp_map_rule_id_tbl(l_index) = ' || l_resp_map_rule_id_tbl(l_index));
1153       END IF;
1154       l_index := l_index + 1;
1155    END LOOP;
1156 
1157    PV_PARTNER_GEO_MATCH_PVT.Get_Ptnr_Org_Matched_Geo_Id (
1158       p_api_version_number         => p_api_version_number
1159      ,p_init_msg_list              => FND_API.G_FALSE
1160      ,x_return_status              => x_return_status
1161      ,x_msg_count                  => x_msg_count
1162      ,x_msg_data                   => x_msg_data
1163      ,p_party_id                   => p_partner_org_id
1164      ,p_geo_hierarchy_id           => l_geo_hierarchy_id_tbl
1165      ,x_geo_hierarchy_id           => l_matched_geo_hierarchy_id
1166    );
1167 
1168    IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
1169        RAISE FND_API.G_EXC_ERROR;
1170     END IF;
1171 
1172    -- if l_matched_geo_hierarchy_id is null
1173    -- most likely the partner doesn't have address in database
1174    IF l_matched_geo_hierarchy_id is null THEN
1175       IF (PV_DEBUG_HIGH_ON) THEN
1176          Debug_Log('get_default_org_resp: l_matched_geo_hierarchy_id is null');
1177       END IF;
1178       FOR x IN c_get_area1_resp(p_user_role_code)
1179       LOOP
1180          x_responsibility_id := x.responsibility_id;
1181          x_resp_map_rule_id := x.resp_map_rule_id;
1182       END LOOP;
1183       IF ((x_responsibility_id is null) or (x_resp_map_rule_id is null)) THEN
1184         FND_MESSAGE.set_name('PV', 'PV_NO_DEFLT_RESP');
1185         FND_MSG_PUB.add;
1186         RAISE FND_API.G_EXC_ERROR;
1187       END IF;
1188    ELSE
1189       IF (PV_DEBUG_HIGH_ON) THEN
1190          Debug_Log('get_default_org_resp: l_matched_geo_hierarchy_id =' || l_matched_geo_hierarchy_id);
1191       END IF;
1192       FOR i IN 1..l_geo_hierarchy_id_tbl.COUNT
1193       LOOP
1194           IF l_geo_hierarchy_id_tbl(i) = l_matched_geo_hierarchy_id THEN
1195             x_responsibility_id := l_responsibility_id_tbl(i);
1196             x_resp_map_rule_id := l_resp_map_rule_id_tbl(i);
1197             EXIT;
1198           END IF;
1199       END LOOP;
1200    END IF;
1201 
1202    IF (PV_DEBUG_HIGH_ON) THEN
1203       Debug_Log('get_default_org_resp: x_responsibility_id =' || x_responsibility_id);
1204       Debug_Log('get_default_org_resp: x_resp_map_rule_id =' || x_resp_map_rule_id);
1205    END IF;
1206 
1207    -- Check for commit
1208    IF FND_API.to_boolean(p_commit) THEN
1209       COMMIT;
1210    END IF;
1211 
1212    FND_MSG_PUB.count_and_get(
1213       p_encoded => FND_API.g_false
1214      ,p_count   => x_msg_count
1215      ,p_data    => x_msg_data
1216    );
1217 
1218 EXCEPTION
1219 
1220    WHEN PVX_Utility_PVT.resource_locked THEN
1221      x_return_status := FND_API.g_ret_sts_error;
1222          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
1223 
1224    WHEN FND_API.G_EXC_ERROR THEN
1225      ROLLBACK TO get_default_org_resp;
1226      x_return_status := FND_API.G_RET_STS_ERROR;
1227      -- Standard call to get message count and if count=1, get the message
1228      FND_MSG_PUB.Count_And_Get (
1229             p_encoded => FND_API.G_FALSE,
1230             p_count   => x_msg_count,
1231             p_data    => x_msg_data
1232      );
1233 
1234    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1235      ROLLBACK TO get_default_org_resp;
1236      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1237      -- Standard call to get message count and if count=1, get the message
1238      FND_MSG_PUB.Count_And_Get (
1239             p_encoded => FND_API.G_FALSE,
1240             p_count => x_msg_count,
1241             p_data  => x_msg_data
1242      );
1243 
1244    WHEN OTHERS THEN
1245      ROLLBACK TO get_default_org_resp;
1246      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1247      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1248      THEN
1249         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
1250      END IF;
1251      -- Standard call to get message count and if count=1, get the message
1252      FND_MSG_PUB.Count_And_Get (
1253             p_encoded => FND_API.G_FALSE,
1254             p_count => x_msg_count,
1255             p_data  => x_msg_data
1256      );
1257 
1258 END get_default_org_resp;
1259 
1260 /*
1261 * get_program_resp
1262 * This is to get the program responsibility using partner_id, user_rold, and program_id
1263 */
1264 PROCEDURE get_program_resp(
1265     p_api_version_number         IN   NUMBER
1266    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
1267    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
1268    ,x_return_status              OUT  NOCOPY  VARCHAR2
1269    ,x_msg_count                  OUT  NOCOPY  NUMBER
1270    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
1271    ,p_partner_id                 IN   NUMBER
1272    ,p_user_role_code             IN   VARCHAR2
1273    ,p_program_id                 IN   NUMBER
1274    ,x_responsibility_id          OUT  NOCOPY NUMBER
1275    ,x_resp_map_rule_id           OUT  NOCOPY NUMBER
1276 )
1277 IS
1278    CURSOR c_get_resp_map_rule_info (cv_user_role_code VARCHAR2, cv_program_id NUMBER) IS
1279       SELECT resp_map_rule_id, geo_hierarchy_id, responsibility_id
1280       FROM   pv_ge_resp_map_rules
1281       WHERE  user_role_code = cv_user_role_code
1282       AND    program_id = cv_program_id
1283       AND    delete_flag = 'N';
1284 
1285    CURSOR c_get_area1_resp (cv_user_role_code VARCHAR2, cv_program_id NUMBER) IS
1286       SELECT rmr.resp_map_rule_id, rmr.responsibility_id
1287       FROM   pv_ge_resp_map_rules rmr, jtf_loc_hierarchies_vl lh
1288       WHERE  rmr.user_role_code = p_user_role_code
1289       AND    rmr.program_id = cv_program_id
1290       AND    rmr.geo_hierarchy_id = lh.location_hierarchy_id
1291       AND    lh.location_type_code = 'AREA1'
1292       AND    rmr.delete_flag = 'N';
1293 
1294    l_api_name                  CONSTANT  VARCHAR2(30) := 'get_program_resp';
1295    l_api_version_number        CONSTANT NUMBER   := 1.0;
1296    l_geo_hierarchy_id_tbl      JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
1297    l_responsibility_id_tbl     JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
1298    l_resp_map_rule_id_tbl      JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
1299    l_index                     NUMBER;
1300    l_matched_geo_hierarchy_id  NUMBER;
1301    l_responsibility_id                   NUMBER;
1302 
1303 BEGIN
1304   ---- Initialize----------------
1305 
1306    -- Standard Start of API savepoint
1307    SAVEPOINT get_program_resp;
1308 
1309    -- Standard call to check for call compatibility.
1310    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
1311                                       ,p_api_version_number
1312                                       ,l_api_name
1313                                       ,G_PKG_NAME
1314                                       )
1315    THEN
1316        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
1317    END IF;
1318 
1319    -- Initialize message list if p_init_msg_list is set to TRUE.
1320    IF Fnd_Api.to_Boolean( p_init_msg_list )
1321    THEN
1322       Fnd_Msg_Pub.initialize;
1323    END IF;
1324 
1325    -- Debug Message
1326    IF (PV_DEBUG_HIGH_ON) THEN
1327       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
1328    END IF;
1329 
1330    -- Initialize API return status to SUCCESS
1331    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
1332 
1333    l_index := 1;
1334    FOR x IN c_get_resp_map_rule_info(p_user_role_code, p_program_id)
1335    LOOP
1336       l_geo_hierarchy_id_tbl.extend;
1337       l_geo_hierarchy_id_tbl(l_index) := x.geo_hierarchy_id;
1338       l_responsibility_id_tbl.extend;
1339       l_responsibility_id_tbl(l_index) := x.responsibility_id;
1340       l_resp_map_rule_id_tbl.extend;
1341       l_resp_map_rule_id_tbl(l_index) := x.resp_map_rule_id;
1342 
1343       IF (PV_DEBUG_HIGH_ON) THEN
1344          Debug_Log('get_program_resp: l_geo_hierarchy_id_tbl('||l_index||')='||l_geo_hierarchy_id_tbl(l_index));
1345          Debug_Log('get_program_resp: l_responsibility_id_tbl('||l_index||')='||l_responsibility_id_tbl(l_index));
1346          Debug_Log('get_program_resp: l_resp_map_rule_id_tbl('||l_index||')='||l_resp_map_rule_id_tbl(l_index));
1347       END IF;
1348       l_index := l_index + 1;
1349    END LOOP;
1350 
1351    PV_PARTNER_GEO_MATCH_PVT.Get_Ptnr_Matched_Geo_Id (
1352       p_api_version_number         => p_api_version_number
1353      ,p_init_msg_list              => FND_API.G_FALSE
1354      ,x_return_status              => x_return_status
1355      ,x_msg_count                  => x_msg_count
1356      ,x_msg_data                   => x_msg_data
1357      ,p_partner_id                 => p_partner_id
1358      ,p_geo_hierarchy_id           => l_geo_hierarchy_id_tbl
1359      ,x_geo_hierarchy_id           => l_matched_geo_hierarchy_id
1360    );
1361 
1362    IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
1363        RAISE FND_API.G_EXC_ERROR;
1364     END IF;
1365 
1366    -- if l_matched_geo_hierarchy_id is null
1367    -- most likely the partner doesn't have address in database
1368    IF l_matched_geo_hierarchy_id is null THEN
1369       IF (PV_DEBUG_HIGH_ON) THEN
1370          Debug_Log('get_program_resp: l_matched_geo_hierarchy_id is null - get resp of AREA1');
1371       END IF;
1372       FOR x IN c_get_area1_resp(p_user_role_code, p_program_id)
1373       LOOP
1374          x_responsibility_id := x.responsibility_id;
1375          x_resp_map_rule_id := x.resp_map_rule_id;
1376          IF (PV_DEBUG_HIGH_ON) THEN
1377             Debug_Log('get_program_resp: x_responsibility_id = ' || x_responsibility_id);
1378             Debug_Log('get_program_resp: x_resp_map_rule_id = ' || x_resp_map_rule_id);
1379          END IF;
1380       END LOOP;
1381    ELSE
1382       FOR i IN 1..l_geo_hierarchy_id_tbl.COUNT
1383       LOOP
1384           IF l_geo_hierarchy_id_tbl(i) = l_matched_geo_hierarchy_id THEN
1385             x_responsibility_id := l_responsibility_id_tbl(i);
1386             x_resp_map_rule_id := l_resp_map_rule_id_tbl(i);
1387             IF (PV_DEBUG_HIGH_ON) THEN
1388                Debug_Log('get_program_resp: x_responsibility_id = ' || x_responsibility_id);
1389                Debug_Log('get_program_resp: x_resp_map_rule_id = ' || x_resp_map_rule_id);
1390             END IF;
1391             EXIT;
1392           END IF;
1393       END LOOP;
1394    END IF;
1395    -- Check for commit
1396    IF FND_API.to_boolean(p_commit) THEN
1397       COMMIT;
1398    END IF;
1399 
1400    FND_MSG_PUB.count_and_get(
1401       p_encoded => FND_API.g_false
1402      ,p_count   => x_msg_count
1403      ,p_data    => x_msg_data
1404    );
1405 
1406 EXCEPTION
1407 
1408    WHEN PVX_Utility_PVT.resource_locked THEN
1409      x_return_status := FND_API.g_ret_sts_error;
1410          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
1411 
1412    WHEN FND_API.G_EXC_ERROR THEN
1413      ROLLBACK TO get_program_resp;
1414      x_return_status := FND_API.G_RET_STS_ERROR;
1415      -- Standard call to get message count and if count=1, get the message
1416      FND_MSG_PUB.Count_And_Get (
1417             p_encoded => FND_API.G_FALSE,
1418             p_count   => x_msg_count,
1419             p_data    => x_msg_data
1420      );
1421 
1422    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1423      ROLLBACK TO get_program_resp;
1424      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1425      -- Standard call to get message count and if count=1, get the message
1426      FND_MSG_PUB.Count_And_Get (
1427             p_encoded => FND_API.G_FALSE,
1428             p_count => x_msg_count,
1429             p_data  => x_msg_data
1430      );
1431 
1432    WHEN OTHERS THEN
1433      ROLLBACK TO get_program_resp;
1434      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1435      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1436      THEN
1437         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
1438      END IF;
1439      -- Standard call to get message count and if count=1, get the message
1440      FND_MSG_PUB.Count_And_Get (
1441             p_encoded => FND_API.G_FALSE,
1442             p_count => x_msg_count,
1443             p_data  => x_msg_data
1444      );
1445 
1446 END get_program_resp;
1447 
1448 /*
1449 * get_store_prgm_resps
1450 * This is to get the all store responsibilities of a given partner
1451 */
1452 
1453 PROCEDURE get_store_prgm_resps(
1454     p_api_version_number         IN   NUMBER
1455    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
1456    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
1457    ,x_return_status              OUT  NOCOPY  VARCHAR2
1458    ,x_msg_count                  OUT  NOCOPY  NUMBER
1459    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
1460    ,p_partner_id                 IN   JTF_NUMBER_TABLE
1461    ,x_responsibility_id          OUT  NOCOPY JTF_NUMBER_TABLE
1462    ,x_resp_map_rule_id           OUT  NOCOPY JTF_NUMBER_TABLE
1463 )
1464 IS
1465    CURSOR get_resp_id IS
1466 	SELECT ben.benefit_id, ben.program_benefits_id
1467 	FROM  pv_program_benefits ben
1468 	WHERE
1469 	ben.benefit_type_code = 'STORES'
1470 	AND ben.delete_flag = 'N'
1471 	AND ben.program_id in
1472 	(
1473 	SELECT program_id
1474 	FROM pv_partner_program_b
1475             START WITH program_id in
1476             (
1477              SELECT /*+ leading(T) USE_NL(T MEM)*/ mem.program_id
1478              FROM  pv_pg_memberships mem, (SELECT column_value FROM TABLE (CAST(p_partner_id AS JTF_NUMBER_TABLE))) t
1479              WHERE mem.partner_id = t.column_value
1480                    AND    mem.membership_status_code = 'ACTIVE'
1481             )
1482             CONNECT BY PRIOR program_parent_id = program_id
1483 	);
1484 
1485    l_api_name                  CONSTANT  VARCHAR2(30) := 'get_store_prgm_resps';
1486    l_api_version_number        CONSTANT NUMBER   := 1.0;
1487    l_responsibility_id         JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
1488    l_resp_map_rule_id          JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
1489    i                           NUMBER;
1490 
1491 BEGIN
1492   ---- Initialize----------------
1493 
1494    -- Standard Start of API savepoint
1495    SAVEPOINT get_store_prgm_resps;
1496 
1497    -- Standard call to check for call compatibility.
1498    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
1499                                       ,p_api_version_number
1500                                       ,l_api_name
1501                                       ,G_PKG_NAME
1502                                       )
1503    THEN
1504        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
1505    END IF;
1506 
1507    -- Initialize message list if p_init_msg_list is set to TRUE.
1508    IF Fnd_Api.to_Boolean( p_init_msg_list )
1509    THEN
1510       Fnd_Msg_Pub.initialize;
1511    END IF;
1512 
1513    -- Debug Message
1514    IF (PV_DEBUG_HIGH_ON) THEN
1515       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
1516    END IF;
1517 
1518    -- Initialize API return status to SUCCESS
1519    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
1520 
1521    i := 1;
1522    FOR x in get_resp_id LOOP
1523       IF (PV_DEBUG_HIGH_ON) THEN
1524         Debug_Log('get_store_prgm_resps: x.benefit_id = ' || x.benefit_id);
1525         Debug_Log('get_program_resp: x_resp_map_rule_id = ' || x.program_benefits_id);
1526       END IF;
1527       l_responsibility_id.extend;
1528       l_resp_map_rule_id.extend;
1529       l_responsibility_id(i) := x.benefit_id;
1530       l_resp_map_rule_id(i) := x.program_benefits_id;
1531       i := i + 1;
1532    END LOOP;
1533 
1534    x_responsibility_id := l_responsibility_id;
1535    x_resp_map_rule_id := l_resp_map_rule_id;
1536 
1537    -- Check for commit
1538    IF FND_API.to_boolean(p_commit) THEN
1539       COMMIT;
1540    END IF;
1541 
1542    FND_MSG_PUB.count_and_get(
1543       p_encoded => FND_API.g_false
1544      ,p_count   => x_msg_count
1545      ,p_data    => x_msg_data
1546    );
1547 
1548 EXCEPTION
1549 
1550    WHEN PVX_Utility_PVT.resource_locked THEN
1551      x_return_status := FND_API.g_ret_sts_error;
1552          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
1553 
1554    WHEN FND_API.G_EXC_ERROR THEN
1555      ROLLBACK TO get_store_prgm_resps;
1556      x_return_status := FND_API.G_RET_STS_ERROR;
1557      -- Standard call to get message count and if count=1, get the message
1558      FND_MSG_PUB.Count_And_Get (
1559             p_encoded => FND_API.G_FALSE,
1560             p_count   => x_msg_count,
1561             p_data    => x_msg_data
1562      );
1563 
1564    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1565      ROLLBACK TO get_store_prgm_resps;
1566      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1567      -- Standard call to get message count and if count=1, get the message
1568      FND_MSG_PUB.Count_And_Get (
1569             p_encoded => FND_API.G_FALSE,
1570             p_count => x_msg_count,
1571             p_data  => x_msg_data
1572      );
1573 
1574    WHEN OTHERS THEN
1575      ROLLBACK TO get_store_prgm_resps;
1576      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1577      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1578      THEN
1579         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
1580      END IF;
1581      -- Standard call to get message count and if count=1, get the message
1582      FND_MSG_PUB.Count_And_Get (
1583             p_encoded => FND_API.G_FALSE,
1584             p_count => x_msg_count,
1585             p_data  => x_msg_data
1586      );
1587 
1588 END get_store_prgm_resps;
1589 
1590 
1591 /*
1592 * get_store_prgm_resps
1593 * This is to get the all store responsibilities of a given program_id
1594 */
1595 
1596 PROCEDURE get_store_prgm_resps(
1597     p_api_version_number         IN   NUMBER
1598    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
1599    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
1600    ,x_return_status              OUT  NOCOPY  VARCHAR2
1601    ,x_msg_count                  OUT  NOCOPY  NUMBER
1602    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
1603    ,p_program_id                 IN   NUMBER
1604    ,x_responsibility_id          OUT  NOCOPY JTF_NUMBER_TABLE
1605    ,x_resp_map_rule_id           OUT  NOCOPY JTF_NUMBER_TABLE
1606 )
1607 IS
1608    CURSOR get_resp_id IS
1609       SELECT ben.benefit_id, ben.program_benefits_id
1610       FROM   pv_program_benefits ben
1611       WHERE  ben.program_id IN (
1612                 SELECT program_id
1613                 FROM pv_partner_program_b
1614                 START WITH program_id = p_program_id
1615                 CONNECT BY PRIOR program_parent_id = program_id
1616              )
1617       AND    ben.benefit_type_code = 'STORES'
1618       AND    ben.delete_flag = 'N';
1619 
1620    l_api_name                  CONSTANT  VARCHAR2(30) := 'get_store_prgm_resps';
1621    l_api_version_number        CONSTANT NUMBER   := 1.0;
1622    l_responsibility_id         JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
1623    l_resp_map_rule_id          JTF_NUMBER_TABLE := JTF_NUMBER_TABLE();
1624    i                           NUMBER;
1625 
1626 BEGIN
1627   ---- Initialize----------------
1628 
1629    -- Standard Start of API savepoint
1630    SAVEPOINT get_store_prgm_resps;
1631 
1632    -- Standard call to check for call compatibility.
1633    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
1634                                       ,p_api_version_number
1635                                       ,l_api_name
1636                                       ,G_PKG_NAME
1637                                       )
1638    THEN
1639        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
1640    END IF;
1641 
1642    -- Initialize message list if p_init_msg_list is set to TRUE.
1643    IF Fnd_Api.to_Boolean( p_init_msg_list )
1644    THEN
1645       Fnd_Msg_Pub.initialize;
1646    END IF;
1647 
1648    -- Debug Message
1649    IF (PV_DEBUG_HIGH_ON) THEN
1650       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
1651    END IF;
1652 
1653    -- Initialize API return status to SUCCESS
1654    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
1655 
1656    i := 1;
1657    FOR x in get_resp_id LOOP
1658       IF (PV_DEBUG_HIGH_ON) THEN
1659         Debug_Log('get_store_prgm_resps: x.benefit_id = ' || x.benefit_id);
1660         Debug_Log('get_program_resp: x_resp_map_rule_id = ' || x.program_benefits_id);
1661       END IF;
1662       l_responsibility_id.extend;
1663       l_resp_map_rule_id.extend;
1664       l_responsibility_id(i) := x.benefit_id;
1665       l_resp_map_rule_id(i) := x.program_benefits_id;
1666       i := i + 1;
1667    END LOOP;
1668 
1669    x_responsibility_id := l_responsibility_id;
1670    x_resp_map_rule_id := l_resp_map_rule_id;
1671 
1672    IF (PV_DEBUG_HIGH_ON) THEN
1673       Debug_Log('PRIVATE API: ' || l_api_name || ' - END');
1674    END IF;
1675 
1676    -- Check for commit
1677    IF FND_API.to_boolean(p_commit) THEN
1678       COMMIT;
1679    END IF;
1680 
1681    FND_MSG_PUB.count_and_get(
1682       p_encoded => FND_API.g_false
1683      ,p_count   => x_msg_count
1684      ,p_data    => x_msg_data
1685    );
1686 
1687 EXCEPTION
1688 
1689    WHEN PVX_Utility_PVT.resource_locked THEN
1690      x_return_status := FND_API.g_ret_sts_error;
1691          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
1692 
1693    WHEN FND_API.G_EXC_ERROR THEN
1694      ROLLBACK TO get_store_prgm_resps;
1695      x_return_status := FND_API.G_RET_STS_ERROR;
1696      -- Standard call to get message count and if count=1, get the message
1697      FND_MSG_PUB.Count_And_Get (
1698             p_encoded => FND_API.G_FALSE,
1699             p_count   => x_msg_count,
1700             p_data    => x_msg_data
1701      );
1702 
1703    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1704      ROLLBACK TO get_store_prgm_resps;
1705      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1706      -- Standard call to get message count and if count=1, get the message
1707      FND_MSG_PUB.Count_And_Get (
1708             p_encoded => FND_API.G_FALSE,
1709             p_count => x_msg_count,
1710             p_data  => x_msg_data
1711      );
1712 
1713    WHEN OTHERS THEN
1714      ROLLBACK TO get_store_prgm_resps;
1715      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1716      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1717      THEN
1718         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
1719      END IF;
1720      -- Standard call to get message count and if count=1, get the message
1721      FND_MSG_PUB.Count_And_Get (
1722             p_encoded => FND_API.G_FALSE,
1723             p_count => x_msg_count,
1724             p_data  => x_msg_data
1725      );
1726 
1727 END get_store_prgm_resps;
1728 
1729 /************
1730  * This API will do the following three things:
1731  * 1. Get the default responsibility.
1732  * 2. Assign that to all the users passed in.
1733  * 3. Add a new row to the pv_ge_ptnr_resps table.
1734  ************/
1735 PROCEDURE get_default_assign_addrow(
1736     p_api_version_number         IN   NUMBER
1737    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
1738    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
1739    ,x_return_status              OUT  NOCOPY  VARCHAR2
1740    ,x_msg_count                  OUT  NOCOPY  NUMBER
1741    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
1742    ,p_user_role_code             IN   VARCHAR2
1743    ,p_user_ids_tbl               IN   JTF_NUMBER_TABLE
1744    ,p_partner_id                 IN   NUMBER
1745 )
1746 IS
1747    l_api_name              CONSTANT  VARCHAR2(30) := 'get_default_assign_addrow';
1748    l_exist                 NUMBER;
1749    l_responsibility_id     NUMBER;
1750    l_resp_map_rule_id      NUMBER;
1751    l_ge_ptnr_resps_rec     PV_Ge_Ptnr_Resps_PVT.ge_ptnr_resps_rec_type;
1752    l_ptnr_resp_id          NUMBER;
1753    l_user_ids_tbl          JTF_NUMBER_TABLE;
1754 
1755 BEGIN
1756   ---- Initialize----------------
1757 
1758    -- Initialize message list if p_init_msg_list is set to TRUE.
1759    IF Fnd_Api.to_Boolean( p_init_msg_list )
1760    THEN
1761       Fnd_Msg_Pub.initialize;
1762    END IF;
1763 
1764    -- Debug Message
1765    IF (PV_DEBUG_HIGH_ON) THEN
1766       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
1767    END IF;
1768 
1769    -- Initialize API return status to SUCCESS
1770    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
1771    get_default_resp(
1772        p_api_version_number         => p_api_version_number
1773       ,p_init_msg_list              => FND_API.G_FALSE
1774       ,p_commit                     => FND_API.G_FALSE
1775       ,x_return_status              => x_return_status
1776       ,x_msg_count                  => x_msg_count
1777       ,x_msg_data                   => x_msg_data
1778       ,p_partner_id                 => p_partner_id
1779       ,p_user_role_code             => p_user_role_code
1780       ,x_responsibility_id          => l_responsibility_id
1781       ,x_resp_map_rule_id           => l_resp_map_rule_id
1782    );
1783    IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
1784       RAISE FND_API.G_EXC_ERROR;
1785    END IF;
1786 
1787    IF (PV_DEBUG_HIGH_ON) THEN
1788       Debug_Log('get_default_assign_addrow: l_responsibility_id = ' || l_responsibility_id);
1789       Debug_Log('get_default_assign_addrow: l_resp_map_rule_id = ' || l_resp_map_rule_id);
1790    END IF;
1791 
1792    -- Fixed for bug 3533631.
1793    IF (p_user_ids_tbl is null) THEN
1794       Debug_Log('get_default_assign_addrow: p_user_ids_tbl is null');
1795       l_user_ids_tbl := get_partner_users(p_partner_id, p_user_role_code);
1796    ELSE
1797       l_user_ids_tbl := p_user_ids_tbl;
1798    END IF;
1799 
1800    IF (l_responsibility_id is not null) and (l_resp_map_rule_id is not null) THEN
1801       FOR l_cnt IN 1..l_user_ids_tbl.count LOOP
1802          assign_resp(
1803              p_api_version_number         => p_api_version_number
1804             ,p_init_msg_list              => FND_API.G_FALSE
1805             ,p_commit                     => FND_API.G_FALSE
1806             ,p_user_id                    => l_user_ids_tbl(l_cnt)
1807             ,p_resp_id                    => l_responsibility_id
1808             ,p_app_id                     => 691
1809             ,x_return_status              => x_return_status
1810             ,x_msg_count                  => x_msg_count
1811             ,x_msg_data                   => x_msg_data
1812          );
1813          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
1814             RAISE FND_API.G_EXC_ERROR;
1815          END IF;
1816       END LOOP;
1817 
1818       /****
1819        * API to add a row to pv_ge_ptnr_resps
1820        ****/
1821       l_ge_ptnr_resps_rec.partner_id := p_partner_id;
1822       l_ge_ptnr_resps_rec.user_role_code := p_user_role_code;
1823       l_ge_ptnr_resps_rec.responsibility_id := l_responsibility_id;
1824       l_ge_ptnr_resps_rec.source_resp_map_rule_id := l_resp_map_rule_id;
1825       l_ge_ptnr_resps_rec.resp_type_code := G_PROGRAM;
1826 
1827       IF (PV_DEBUG_HIGH_ON) THEN
1828          Debug_Log('get_default_assign_addrow: l_ge_ptnr_resps_rec.partner_id = ' || l_ge_ptnr_resps_rec.partner_id);
1829          Debug_Log('get_default_assign_addrow: l_ge_ptnr_resps_rec.user_role_code = ' || l_ge_ptnr_resps_rec.user_role_code);
1830          Debug_Log('get_default_assign_addrow: l_ge_ptnr_resps_rec.responsibility_id = ' || l_ge_ptnr_resps_rec.responsibility_id);
1831          Debug_Log('get_default_assign_addrow: l_ge_ptnr_resps_rec.source_resp_map_rule_id = ' || l_ge_ptnr_resps_rec.source_resp_map_rule_id);
1832          Debug_Log('get_default_assign_addrow: l_ge_ptnr_resps_rec.resp_type_code = ' || l_ge_ptnr_resps_rec.resp_type_code);
1833       END IF;
1834 
1835       PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps(
1836           p_api_version_number         => p_api_version_number
1837          ,p_init_msg_list              => FND_API.G_FALSE
1838          ,p_commit                     => FND_API.G_FALSE
1839          ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
1840 
1841          ,x_return_status              => x_return_status
1842          ,x_msg_count                  => x_msg_count
1843          ,x_msg_data                   => x_msg_data
1844          ,p_ge_ptnr_resps_rec          => l_ge_ptnr_resps_rec
1845          ,x_ptnr_resp_id               => l_ptnr_resp_id
1846       );
1847 
1848       IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
1849          RAISE FND_API.G_EXC_ERROR;
1850       END IF;
1851    ELSE
1852       FND_MESSAGE.set_name('PV', 'PV_NO_DEFAULT_RESP');
1853       FND_MSG_PUB.add;
1854       RAISE FND_API.G_EXC_ERROR;
1855    END IF;
1856 
1857    -- Check for commit
1858    IF FND_API.to_boolean(p_commit) THEN
1859       COMMIT;
1860    END IF;
1861 
1862    FND_MSG_PUB.count_and_get(
1863       p_encoded => FND_API.g_false
1864      ,p_count   => x_msg_count
1865      ,p_data    => x_msg_data
1866    );
1867 
1868 EXCEPTION
1869 
1870    WHEN PVX_Utility_PVT.resource_locked THEN
1871      x_return_status := FND_API.g_ret_sts_error;
1872          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
1873 
1874    WHEN FND_API.G_EXC_ERROR THEN
1875      x_return_status := FND_API.G_RET_STS_ERROR;
1876      -- Standard call to get message count and if count=1, get the message
1877      FND_MSG_PUB.Count_And_Get (
1878             p_encoded => FND_API.G_FALSE,
1879             p_count   => x_msg_count,
1880             p_data    => x_msg_data
1881      );
1882 
1883    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1884      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1885      -- Standard call to get message count and if count=1, get the message
1886      FND_MSG_PUB.Count_And_Get (
1887             p_encoded => FND_API.G_FALSE,
1888             p_count => x_msg_count,
1889             p_data  => x_msg_data
1890      );
1891 
1892    WHEN OTHERS THEN
1893      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1894      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1895      THEN
1896         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
1897      END IF;
1898      -- Standard call to get message count and if count=1, get the message
1899      FND_MSG_PUB.Count_And_Get (
1900             p_encoded => FND_API.G_FALSE,
1901             p_count => x_msg_count,
1902             p_data  => x_msg_data
1903      );
1904 
1905 END get_default_assign_addrow;
1906 
1907 /*
1908 * assign_first_user_resp
1909 * This public API will be called during partner self service registration.
1910 */
1911 PROCEDURE assign_first_user_resp(
1912     p_api_version_number         IN   NUMBER
1913    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
1914    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
1915    ,x_return_status              OUT  NOCOPY  VARCHAR2
1916    ,x_msg_count                  OUT  NOCOPY  NUMBER
1917    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
1918    ,p_resp_map_rule_id           IN   NUMBER
1919    ,p_responsibility_id          IN   NUMBER
1920    ,p_partner_id                 IN   NUMBER
1921    ,p_user_id                    IN   NUMBER
1922 )
1923 IS
1924    l_api_name                  CONSTANT  VARCHAR2(30) := 'assign_first_user_resp';
1925    l_api_version_number        CONSTANT NUMBER   := 1.0;
1926    l_ptnr_resp_id              NUMBER;
1927    l_ge_ptnr_resps_rec         PV_Ge_Ptnr_Resps_PVT.ge_ptnr_resps_rec_type;
1928 
1929 BEGIN
1930   ---- Initialize----------------
1931 
1932    -- Standard Start of API savepoint
1933    SAVEPOINT assign_first_user_resp;
1934 
1935    -- Standard call to check for call compatibility.
1936    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
1937                                       ,p_api_version_number
1938                                       ,l_api_name
1939                                       ,G_PKG_NAME
1940                                       )
1941    THEN
1942        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
1943    END IF;
1944 
1945    -- Initialize message list if p_init_msg_list is set to TRUE.
1946    IF Fnd_Api.to_Boolean( p_init_msg_list )
1947    THEN
1948       Fnd_Msg_Pub.initialize;
1949    END IF;
1950 
1951    -- Debug Message
1952    IF (PV_DEBUG_HIGH_ON) THEN
1953       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
1954    END IF;
1955 
1956    -- Initialize API return status to SUCCESS
1957    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
1958 
1959    IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
1960        RAISE FND_API.G_EXC_ERROR;
1961     END IF;
1962 
1963    assign_resp (
1964        p_api_version_number         => p_api_version_number
1965       ,p_init_msg_list              => FND_API.G_FALSE
1966       ,p_commit                     => FND_API.G_FALSE
1967       ,p_user_id                    => p_user_id
1968       ,p_resp_id                    => p_responsibility_id
1969       ,p_app_id                     => 691
1970       ,x_return_status              => x_return_status
1971       ,x_msg_count                  => x_msg_count
1972       ,x_msg_data                   => x_msg_data
1973    );
1974 
1975    IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
1976        RAISE FND_API.G_EXC_ERROR;
1977     END IF;
1978 
1979    /****
1980     * API to add a row to pv_ge_ptnr_resps
1981     ****/
1982    l_ge_ptnr_resps_rec.partner_id := p_partner_id;
1983    l_ge_ptnr_resps_rec.user_role_code := G_PRIMARY;
1984    l_ge_ptnr_resps_rec.responsibility_id := p_responsibility_id;
1985    l_ge_ptnr_resps_rec.source_resp_map_rule_id := p_resp_map_rule_id;
1986    l_ge_ptnr_resps_rec.resp_type_code := G_PROGRAM;
1987 
1988    IF (PV_DEBUG_HIGH_ON) THEN
1989       Debug_Log('assign_first_user_resp: l_ge_ptnr_resps_rec.partner_id = ' || l_ge_ptnr_resps_rec.partner_id);
1990       Debug_Log('assign_first_user_resp: l_ge_ptnr_resps_rec.user_role_code = ' || l_ge_ptnr_resps_rec.user_role_code);
1991       Debug_Log('assign_first_user_resp: l_ge_ptnr_resps_rec.responsibility_id = ' || l_ge_ptnr_resps_rec.responsibility_id);
1992       Debug_Log('assign_first_user_resp: l_ge_ptnr_resps_rec.source_resp_map_rule_id = ' || l_ge_ptnr_resps_rec.source_resp_map_rule_id);
1993       Debug_Log('assign_first_user_resp: l_ge_ptnr_resps_rec.resp_type_code = ' || l_ge_ptnr_resps_rec.resp_type_code);
1994    END IF;
1995 
1996    PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps(
1997        p_api_version_number         => p_api_version_number
1998       ,p_init_msg_list              => FND_API.G_FALSE
1999       ,p_commit                     => FND_API.G_FALSE
2000       ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
2001 
2002       ,x_return_status              => x_return_status
2003       ,x_msg_count                  => x_msg_count
2004       ,x_msg_data                   => x_msg_data
2005       ,p_ge_ptnr_resps_rec          => l_ge_ptnr_resps_rec
2006       ,x_ptnr_resp_id               => l_ptnr_resp_id
2007    );
2008 
2009    IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
2010       RAISE FND_API.G_EXC_ERROR;
2011    END IF;
2012 
2013    -- Check for commit
2014    IF FND_API.to_boolean(p_commit) THEN
2015       COMMIT;
2016    END IF;
2017 
2018    FND_MSG_PUB.count_and_get(
2019       p_encoded => FND_API.g_false
2020      ,p_count   => x_msg_count
2021      ,p_data    => x_msg_data
2022    );
2023 
2024 EXCEPTION
2025 
2026    WHEN PVX_Utility_PVT.resource_locked THEN
2027      x_return_status := FND_API.g_ret_sts_error;
2028          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
2029 
2030    WHEN FND_API.G_EXC_ERROR THEN
2031      ROLLBACK TO assign_first_user_resp;
2032      x_return_status := FND_API.G_RET_STS_ERROR;
2033      -- Standard call to get message count and if count=1, get the message
2034      FND_MSG_PUB.Count_And_Get (
2035             p_encoded => FND_API.G_FALSE,
2036             p_count   => x_msg_count,
2037             p_data    => x_msg_data
2038      );
2039 
2040    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2041      ROLLBACK TO assign_first_user_resp;
2042      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2043      -- Standard call to get message count and if count=1, get the message
2044      FND_MSG_PUB.Count_And_Get (
2045             p_encoded => FND_API.G_FALSE,
2046             p_count => x_msg_count,
2047             p_data  => x_msg_data
2048      );
2049 
2050    WHEN OTHERS THEN
2051      ROLLBACK TO assign_first_user_resp;
2052      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2053      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2054      THEN
2055         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
2056      END IF;
2057      -- Standard call to get message count and if count=1, get the message
2058      FND_MSG_PUB.Count_And_Get (
2059             p_encoded => FND_API.G_FALSE,
2060             p_count => x_msg_count,
2061             p_data  => x_msg_data
2062      );
2063 
2064 END assign_first_user_resp;
2065 
2066 /*
2067 * assign_user_resps
2068 * This public API will be called during additional user registration of
2069 * an existing partner, when an existing user becomes a partner user,
2070 * and when partner contact resource is actived.
2071 */
2072 PROCEDURE assign_user_resps(
2073     p_api_version_number         IN   NUMBER
2074    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
2075    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
2076    ,x_return_status              OUT  NOCOPY  VARCHAR2
2077    ,x_msg_count                  OUT  NOCOPY  NUMBER
2078    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
2079    ,p_user_id                    IN   NUMBER
2080    ,p_user_role_code             IN   VARCHAR2
2081 )
2082 IS
2083    CURSOR c_get_resp_id (cv_partner_id JTF_NUMBER_TABLE, cv_user_role_code VARCHAR2, cv_resp_type_code VARCHAR2) IS
2084       SELECT /*+ CARDINALITY(t 10) */ responsibility_id
2085       FROM   pv_ge_ptnr_resps,
2086 	     (SELECT * FROM TABLE (CAST(cv_partner_id AS JTF_NUMBER_TABLE))) t
2087       WHERE  partner_id = t.column_value
2088       AND    user_role_code = cv_user_role_code
2089       AND    resp_type_code = cv_resp_type_code;
2090 
2091    CURSOR c_get_program_id (cv_partner_id JTF_NUMBER_TABLE) IS
2092       SELECT /*+ CARDINALITY(t 10) */ program_id, partner_id
2093       FROM   pv_pg_memberships,
2094 	     (SELECT * FROM TABLE (CAST(cv_partner_id AS JTF_NUMBER_TABLE))) t
2095       WHERE  partner_id = t.column_value
2096       AND    membership_status_code = 'ACTIVE';
2097 
2098    l_api_name                  CONSTANT  VARCHAR2(30) := 'assign_user_resps';
2099    l_api_version_number        CONSTANT NUMBER   := 1.0;
2100    l_responsibility_id_tbl         JTF_NUMBER_TABLE;
2101    l_responsibility_id         NUMBER;
2102    l_resp_map_rule_id          NUMBER;
2103    l_partner_ids_tbl           JTF_NUMBER_TABLE;
2104    l_resp_exist                VARCHAR(1) := 'N';
2105    l_ge_ptnr_resps_rec         PV_Ge_Ptnr_Resps_PVT.ge_ptnr_resps_rec_type;
2106    l_ptnr_resp_id              NUMBER;
2107    l_user_ids_tbl              JTF_NUMBER_TABLE;
2108 BEGIN
2109   ---- Initialize----------------
2110 
2111    -- Standard Start of API savepoint
2112    SAVEPOINT assign_user_resps;
2113 
2114    -- Standard call to check for call compatibility.
2115    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
2116                                       ,p_api_version_number
2117                                       ,l_api_name
2118                                       ,G_PKG_NAME
2119                                       )
2120    THEN
2121        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
2122    END IF;
2123 
2124    -- Initialize message list if p_init_msg_list is set to TRUE.
2125    IF Fnd_Api.to_Boolean( p_init_msg_list )
2126    THEN
2127       Fnd_Msg_Pub.initialize;
2128    END IF;
2129 
2130    -- Debug Message
2131    IF (PV_DEBUG_HIGH_ON) THEN
2132       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
2133    END IF;
2134 
2135    -- Initialize API return status to SUCCESS
2136    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
2137 
2138    l_partner_ids_tbl := get_partners(p_user_id);
2139 
2140    IF (l_partner_ids_tbl.count = 0) THEN
2141        FND_MESSAGE.set_name('PV', 'PV_INVALID_PTNR_USER');
2142        FND_MSG_PUB.add;
2143        RAISE FND_API.G_EXC_ERROR;
2144    END IF;
2145 
2146    IF (PV_DEBUG_HIGH_ON) THEN
2147       Debug_Log('assign_user_resps: l_partner_ids_tbl.count: ' || l_partner_ids_tbl.count);
2148    END IF;
2149 
2150    FOR x IN c_get_resp_id (l_partner_ids_tbl, p_user_role_code, G_PROGRAM) LOOP
2151       l_resp_exist := 'Y';
2152       IF (PV_DEBUG_HIGH_ON) THEN
2153          Debug_Log('assign_user_resps: x.responsibility_id: ' || x.responsibility_id);
2154       END IF;
2155       assign_resp (
2156           p_api_version_number         => p_api_version_number
2157          ,p_init_msg_list              => FND_API.G_FALSE
2158          ,p_commit                     => FND_API.G_FALSE
2159          ,p_user_id                    => p_user_id
2160          ,p_resp_id                    => x.responsibility_id
2161          ,p_app_id                     => 691
2162          ,x_return_status              => x_return_status
2163          ,x_msg_count                  => x_msg_count
2164          ,x_msg_data                   => x_msg_data
2165       );
2166       IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
2167          RAISE FND_API.G_EXC_ERROR;
2168       END IF;
2169    END LOOP;
2170 
2171    IF (l_resp_exist = 'N') THEN
2172       FOR x IN c_get_program_id (l_partner_ids_tbl) LOOP
2173          l_responsibility_id := null;
2174          l_resp_map_rule_id := null;
2175          get_program_resp(
2176              p_api_version_number         => p_api_version_number
2177             ,p_init_msg_list              => FND_API.G_FALSE
2178             ,p_commit                     => FND_API.G_FALSE
2179             ,x_return_status              => x_return_status
2180             ,x_msg_count                  => x_msg_count
2181             ,x_msg_data                   => x_msg_data
2182             ,p_partner_id                 => x.partner_id
2183             ,p_user_role_code             => p_user_role_code
2184             ,p_program_id                 => x.program_id
2185             ,x_responsibility_id          => l_responsibility_id
2186             ,x_resp_map_rule_id           => l_resp_map_rule_id
2187          );
2188 
2189          IF (PV_DEBUG_HIGH_ON) THEN
2190             Debug_Log('assign_user_resps: l_responsibility_id = ' || l_responsibility_id);
2191             Debug_Log('assign_user_resps: l_resp_map_rule_id = ' || l_resp_map_rule_id);
2192          END IF;
2193 
2194          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
2195             RAISE FND_API.G_EXC_ERROR;
2196          END IF;
2197          IF (l_responsibility_id is not null) and (l_resp_map_rule_id is not null) THEN
2198             l_resp_exist := 'Y';
2199             assign_resp (
2200                 p_api_version_number         => p_api_version_number
2201                ,p_init_msg_list              => FND_API.G_FALSE
2202                ,p_commit                     => FND_API.G_FALSE
2203                ,p_user_id                    => p_user_id
2204                ,p_resp_id                    => l_responsibility_id
2205                ,p_app_id                     => 691
2206                ,x_return_status              => x_return_status
2207                ,x_msg_count                  => x_msg_count
2208                ,x_msg_data                   => x_msg_data
2209             );
2210             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
2211                RAISE FND_API.G_EXC_ERROR;
2212             END IF;
2213 
2214             /****
2215              * API to add a row to pv_ge_ptnr_resps
2216              ****/
2217             l_ge_ptnr_resps_rec.partner_id := x.partner_id;
2218             l_ge_ptnr_resps_rec.user_role_code := p_user_role_code;
2219             l_ge_ptnr_resps_rec.program_id := x.program_id;
2220             l_ge_ptnr_resps_rec.responsibility_id := l_responsibility_id;
2221             l_ge_ptnr_resps_rec.source_resp_map_rule_id := l_resp_map_rule_id;
2222             l_ge_ptnr_resps_rec.resp_type_code := G_PROGRAM;
2223 
2224             IF (PV_DEBUG_HIGH_ON) THEN
2225                Debug_Log('assign_user_resps: l_ge_ptnr_resps_rec.partner_id = ' || l_ge_ptnr_resps_rec.partner_id);
2226                Debug_Log('assign_user_resps: l_ge_ptnr_resps_rec.user_role_code = ' || l_ge_ptnr_resps_rec.user_role_code);
2227                Debug_Log('assign_user_resps: l_ge_ptnr_resps_rec.program_id = ' || l_ge_ptnr_resps_rec.program_id);
2228                Debug_Log('assign_user_resps: l_ge_ptnr_resps_rec.responsibility_id = ' || l_ge_ptnr_resps_rec.responsibility_id);
2229                Debug_Log('assign_user_resps: l_ge_ptnr_resps_rec.source_resp_map_rule_id = ' || l_ge_ptnr_resps_rec.source_resp_map_rule_id);
2230                Debug_Log('assign_user_resps: l_ge_ptnr_resps_rec.resp_type_code = ' || l_ge_ptnr_resps_rec.resp_type_code);
2231             END IF;
2232 
2233             PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps(
2234                 p_api_version_number         => p_api_version_number
2235                ,p_init_msg_list              => FND_API.G_FALSE
2236                ,p_commit                     => FND_API.G_FALSE
2237                ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
2238 
2239                ,x_return_status              => x_return_status
2240                ,x_msg_count                  => x_msg_count
2241                ,x_msg_data                   => x_msg_data
2242                ,p_ge_ptnr_resps_rec          => l_ge_ptnr_resps_rec
2243                ,x_ptnr_resp_id               => l_ptnr_resp_id
2244             );
2245             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
2246                RAISE FND_API.G_EXC_ERROR;
2247             END IF;
2248          END IF;
2249       END LOOP;
2250    END IF;
2251    -- If there is no program responsibility (l_resp_exist still equals to 'N'),
2252    -- get the default responsibility and assign it to the user
2253    IF (l_resp_exist = 'N') THEN
2254       l_user_ids_tbl := JTF_NUMBER_TABLE();
2255       l_user_ids_tbl.extend;
2256       l_user_ids_tbl(1) := p_user_id;
2257       FOR l_cnt IN 1..l_partner_ids_tbl.count LOOP
2258          get_default_assign_addrow(
2259              p_api_version_number         => p_api_version_number
2260             ,p_init_msg_list              => FND_API.G_FALSE
2261             ,p_commit                     => FND_API.G_FALSE
2262             ,x_return_status              => x_return_status
2263             ,x_msg_count                  => x_msg_count
2264             ,x_msg_data                   => x_msg_data
2265             ,p_user_role_code             => p_user_role_code
2266             ,p_user_ids_tbl               => l_user_ids_tbl
2267             ,p_partner_id                 => l_partner_ids_tbl(l_cnt)
2268          );
2269 
2270          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
2271             RAISE FND_API.G_EXC_ERROR;
2272          END IF;
2273       END LOOP;
2274    END IF;
2275 
2276    -- Store responsibility
2277    FOR x IN c_get_resp_id (l_partner_ids_tbl, G_ALL, G_STORE) LOOP
2278       l_resp_exist := 'Y';
2279       IF (PV_DEBUG_HIGH_ON) THEN
2280          Debug_Log('assign_user_resps: Store x.responsibility_id: ' || x.responsibility_id);
2281       END IF;
2282       assign_resp (
2283          p_api_version_number         => p_api_version_number
2284         ,p_init_msg_list              => FND_API.G_FALSE
2285         ,p_commit                     => FND_API.G_FALSE
2286         ,p_user_id                    => p_user_id
2287         ,p_resp_id                    => x.responsibility_id
2288         ,p_app_id                     => 671
2289         ,x_return_status              => x_return_status
2290         ,x_msg_count                  => x_msg_count
2291         ,x_msg_data                   => x_msg_data
2292       );
2293       IF (PV_DEBUG_HIGH_ON) THEN
2294         Debug_Log('assign_user_resps: after assign_resp');
2295       END IF;
2296 
2297       IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
2298         RAISE FND_API.G_EXC_ERROR;
2299       END IF;
2300    END LOOP; -- End of FOR x IN c_get_resp_id (l_partner_ids_tbl, p_user_role_code, G_STORE)
2301 
2302    -- Check for commit
2303    IF FND_API.to_boolean(p_commit) THEN
2304       COMMIT;
2305    END IF;
2306 
2307    FND_MSG_PUB.count_and_get(
2308       p_encoded => FND_API.g_false
2309      ,p_count   => x_msg_count
2310      ,p_data    => x_msg_data
2311    );
2312 
2313 EXCEPTION
2314 
2315    WHEN PVX_Utility_PVT.resource_locked THEN
2316      x_return_status := FND_API.g_ret_sts_error;
2317      PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
2318 
2319    WHEN FND_API.G_EXC_ERROR THEN
2320      ROLLBACK TO assign_user_resps;
2321      x_return_status := FND_API.G_RET_STS_ERROR;
2322      -- Standard call to get message count and if count=1, get the message
2323      FND_MSG_PUB.Count_And_Get (
2324             p_encoded => FND_API.G_FALSE,
2325             p_count   => x_msg_count,
2326             p_data    => x_msg_data
2327      );
2328 
2329    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2330      ROLLBACK TO assign_user_resps;
2331      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2332      -- Standard call to get message count and if count=1, get the message
2333      FND_MSG_PUB.Count_And_Get (
2334             p_encoded => FND_API.G_FALSE,
2335             p_count => x_msg_count,
2336             p_data  => x_msg_data
2337      );
2338 
2339    WHEN OTHERS THEN
2340      ROLLBACK TO assign_user_resps;
2341      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2342      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2343      THEN
2344         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
2345      END IF;
2346      -- Standard call to get message count and if count=1, get the message
2347      FND_MSG_PUB.Count_And_Get (
2348             p_encoded => FND_API.G_FALSE,
2349             p_count => x_msg_count,
2350             p_data  => x_msg_data
2351      );
2352 
2353 END assign_user_resps;
2354 
2355 /*
2356 * assign_user_resps
2357 * This public API will be called during additional user registration of
2358 * an existing partner, when an existing user becomes a partner user,
2359 * and when partner contact resource is actived.
2360 */
2361 PROCEDURE assign_user_resps(
2362     p_api_version_number         IN   NUMBER
2363    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
2364    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
2365    ,x_return_status              OUT  NOCOPY  VARCHAR2
2366    ,x_msg_count                  OUT  NOCOPY  NUMBER
2367    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
2368    ,p_user_name                  IN   VARCHAR2
2369 )
2370 IS
2371    CURSOR c_get_user_id IS
2372       select usr.user_id
2373       from   jtf_rs_resource_extns extn, fnd_user usr
2374       where  extn.user_id     = usr.user_id
2375       and    usr.user_name	   = p_user_name;
2376 
2377    l_api_name                  CONSTANT  VARCHAR2(30) := 'assign_user_resps';
2378    l_api_version_number        CONSTANT NUMBER   := 1.0;
2379    l_user_role_code            VARCHAR2(30);
2380 
2381 BEGIN
2382   ---- Initialize----------------
2383 
2384    -- Standard Start of API savepoint
2385    SAVEPOINT assign_user_resps_2;
2386 
2387    -- Standard call to check for call compatibility.
2388    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
2389                                       ,p_api_version_number
2390                                       ,l_api_name
2391                                       ,G_PKG_NAME
2392                                       )
2393    THEN
2394        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
2395    END IF;
2396 
2397    -- Initialize message list if p_init_msg_list is set to TRUE.
2398    IF Fnd_Api.to_Boolean( p_init_msg_list )
2399    THEN
2400       Fnd_Msg_Pub.initialize;
2401    END IF;
2402 
2403    -- Debug Message
2404    IF (PV_DEBUG_HIGH_ON) THEN
2405       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
2406    END IF;
2407 
2408    -- Initialize API return status to SUCCESS
2409    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
2410 
2411    FOR x IN c_get_user_id LOOP
2412       get_user_role_code (
2413           p_user_id        => x.user_id
2414          ,x_user_role_code => l_user_role_code
2415       );
2416 
2417       IF (PV_DEBUG_HIGH_ON) THEN
2418          Debug_Log('assign_user_resps_2: l_user_role_code = ' || l_user_role_code);
2419       END IF;
2420       assign_user_resps(
2421           p_api_version_number         => p_api_version_number
2422          ,p_init_msg_list              => FND_API.G_FALSE
2423          ,p_commit                     => FND_API.G_FALSE
2424          ,x_return_status              => x_return_status
2425          ,x_msg_count                  => x_msg_count
2426          ,x_msg_data                   => x_msg_data
2427          ,p_user_id                    => x.user_id
2428          ,p_user_role_code             => l_user_role_code
2429       );
2430       IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
2431          RAISE FND_API.G_EXC_ERROR;
2432       END IF;
2433    END LOOP;
2434 
2435    -- Debug Message
2436    IF (PV_DEBUG_HIGH_ON) THEN
2437       Debug_Log('PRIVATE API: ' || l_api_name || ' - END');
2438    END IF;
2439 
2440    -- Check for commit
2441    IF FND_API.to_boolean(p_commit) THEN
2442       COMMIT;
2443    END IF;
2444 
2445    FND_MSG_PUB.count_and_get(
2446       p_encoded => FND_API.g_false
2447      ,p_count   => x_msg_count
2448      ,p_data    => x_msg_data
2449    );
2450 
2451 EXCEPTION
2452 
2453    WHEN PVX_Utility_PVT.resource_locked THEN
2454      x_return_status := FND_API.g_ret_sts_error;
2455          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
2456 
2457    WHEN FND_API.G_EXC_ERROR THEN
2458      ROLLBACK TO assign_user_resps_2;
2459      x_return_status := FND_API.G_RET_STS_ERROR;
2460      -- Standard call to get message count and if count=1, get the message
2461      FND_MSG_PUB.Count_And_Get (
2462             p_encoded => FND_API.G_FALSE,
2463             p_count   => x_msg_count,
2464             p_data    => x_msg_data
2465      );
2466 
2467    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2468      ROLLBACK TO assign_user_resps_2;
2469      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2470      -- Standard call to get message count and if count=1, get the message
2471      FND_MSG_PUB.Count_And_Get (
2472             p_encoded => FND_API.G_FALSE,
2473             p_count => x_msg_count,
2474             p_data  => x_msg_data
2475      );
2476 
2477    WHEN OTHERS THEN
2478      ROLLBACK TO assign_user_resps_2;
2479      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2480      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2481      THEN
2482         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
2483      END IF;
2484      -- Standard call to get message count and if count=1, get the message
2485      FND_MSG_PUB.Count_And_Get (
2486             p_encoded => FND_API.G_FALSE,
2487             p_count => x_msg_count,
2488             p_data  => x_msg_data
2489      );
2490 END assign_user_resps;
2491 
2492 
2493 /*
2494  * switch_user_resp
2495  * This public API will be called when user role is switched from primary to
2496  * non-primary or viceversa.
2497  */
2498 PROCEDURE switch_user_resp(
2499     p_api_version_number         IN   NUMBER
2500    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
2501    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
2502    ,x_return_status              OUT  NOCOPY  VARCHAR2
2503    ,x_msg_count                  OUT  NOCOPY  NUMBER
2504    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
2505    ,p_user_id                    IN   NUMBER
2506    ,p_from_user_role_code        IN   VARCHAR2
2507    ,p_to_user_role_code          IN   VARCHAR2
2508 )
2509 IS
2510    CURSOR c_get_respid_and_action (cv_partner_id JTF_NUMBER_TABLE, cv_user_id NUMBER, cv_from_user_role_code VARCHAR2, cv_to_user_role_code VARCHAR2) IS
2511       (SELECT /*+LEADING(T) USE_NL(t p f)*/ p.responsibility_id, 'REVOKE' action, f.responsibility_application_id, f.security_group_id, f.start_date, f.description
2512        FROM   pv_ge_ptnr_resps p, fnd_user_resp_groups f
2513        WHERE  partner_id in (
2514                  SELECT  * FROM TABLE (CAST(cv_partner_id AS JTF_NUMBER_TABLE))
2515               )
2516        AND    p.user_role_code = cv_from_user_role_code
2517        AND    p.responsibility_id = f.responsibility_id
2518        AND    f.user_id = cv_user_id
2519        AND    p.resp_type_code = G_PROGRAM
2520        MINUS
2521        SELECT /*+LEADING(T) USE_NL(t p f)*/ p.responsibility_id, 'REVOKE' action, f.responsibility_application_id, f.security_group_id, f.start_date, f.description
2522        FROM   pv_ge_ptnr_resps p, fnd_user_resp_groups f
2523        WHERE  partner_id in (
2524                  SELECT  * FROM TABLE (CAST(cv_partner_id AS JTF_NUMBER_TABLE))
2525               )
2526        AND    p.user_role_code = cv_to_user_role_code
2527        AND    p.responsibility_id = f.responsibility_id
2528        AND    f.user_id = cv_user_id
2529        AND    p.resp_type_code = G_PROGRAM
2530       )
2531       UNION
2532       (SELECT /*+LEADING(T) USE_NL(t p f)*/ p.responsibility_id, 'ASSIGN' action, f.responsibility_application_id, f.security_group_id, f.start_date, f.description
2533        FROM   pv_ge_ptnr_resps p, fnd_user_resp_groups f
2534        WHERE  partner_id in (
2535                  SELECT  * FROM TABLE (CAST(cv_partner_id AS JTF_NUMBER_TABLE))
2536               )
2537        AND    p.user_role_code = cv_to_user_role_code
2538        AND    p.responsibility_id = f.responsibility_id
2539        AND    f.user_id = cv_user_id
2540        AND    p.resp_type_code = G_PROGRAM
2541        MINUS
2542        SELECT /*+LEADING(T) USE_NL(t p f)*/ p.responsibility_id, 'ASSIGN' action, f.responsibility_application_id, f.security_group_id, f.start_date, f.description
2543        FROM   pv_ge_ptnr_resps p, fnd_user_resp_groups f
2544        WHERE  partner_id in (
2545                  SELECT  * FROM TABLE (CAST(cv_partner_id AS JTF_NUMBER_TABLE))
2546               )
2547        AND    p.user_role_code = cv_from_user_role_code
2548        AND    p.responsibility_id = f.responsibility_id
2549        AND    f.user_id = cv_user_id
2550        AND    p.resp_type_code = G_PROGRAM
2551       );
2552 
2553    l_api_name                  CONSTANT  VARCHAR2(30) := 'switch_user_resp';
2554    l_api_version_number        CONSTANT NUMBER   := 1.0;
2555    l_partner_ids_tbl           JTF_NUMBER_TABLE;
2556     l_is_resp_assigned   boolean := false;
2557 
2558 BEGIN
2559   ---- Initialize----------------
2560 
2561    -- Standard Start of API savepoint
2562    SAVEPOINT switch_user_resp;
2563 
2564    -- Standard call to check for call compatibility.
2565    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
2566                                       ,p_api_version_number
2567                                       ,l_api_name
2568                                       ,G_PKG_NAME
2569                                       )
2570    THEN
2571        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
2572    END IF;
2573 
2574    -- Initialize message list if p_init_msg_list is set to TRUE.
2575    IF Fnd_Api.to_Boolean( p_init_msg_list )
2576    THEN
2577       Fnd_Msg_Pub.initialize;
2578    END IF;
2579 
2580    -- Debug Message
2581    IF (PV_DEBUG_HIGH_ON) THEN
2582       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
2583    END IF;
2584 
2585    -- Initialize API return status to SUCCESS
2586    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
2587 
2588    l_partner_ids_tbl := get_partners(p_user_id);
2589 
2590    IF (l_partner_ids_tbl.count = 0) THEN
2591        FND_MESSAGE.set_name('PV', 'PV_INVALID_PTNR_USER');
2592        FND_MSG_PUB.add;
2593        RAISE FND_API.G_EXC_ERROR;
2594    END IF;
2595 
2596    FOR x in c_get_respid_and_action (l_partner_ids_tbl, p_user_id, p_from_user_role_code, p_to_user_role_code)
2597    LOOP
2598       -- Debug Message
2599       IF (PV_DEBUG_HIGH_ON) THEN
2600          Debug_Log('switch_user_resp: In c_get_respid_and_action');
2601       END IF;
2602       IF x.action = 'ASSIGN' THEN
2603          -- Debug Message
2604          IF (PV_DEBUG_HIGH_ON) THEN
2605             Debug_Log('switch_user_resp: ASSIGN');
2606          END IF;
2607          assign_resp (
2608              p_api_version_number         => p_api_version_number
2609             ,p_init_msg_list              => FND_API.G_FALSE
2610             ,p_commit                     => FND_API.G_FALSE
2611             ,p_user_id                    => p_user_id
2612             ,p_resp_id                    => x.responsibility_id
2613             ,p_app_id                     => 691
2614             ,x_return_status              => x_return_status
2615             ,x_msg_count                  => x_msg_count
2616             ,x_msg_data                   => x_msg_data
2617          );
2618 
2619 	 l_is_resp_assigned := true;
2620       ELSIF x.action = 'REVOKE' THEN
2621          -- Debug Message
2622          IF (PV_DEBUG_HIGH_ON) THEN
2623             Debug_Log('switch_user_resp: REVOKE');
2624             Debug_Log('switch_user_resp: x.responsibility_id = ' || x.responsibility_id);
2625             Debug_Log('switch_user_resp: x.responsibility_application_id = ' || x.responsibility_application_id);
2626             Debug_Log('switch_user_resp: x.security_group_id = ' || x.security_group_id);
2627             Debug_Log('switch_user_resp: x.start_date = ' || x.start_date);
2628             Debug_Log('switch_user_resp: x.description = ' || x.description);
2629          END IF;
2630          revoke_resp(
2631              p_api_version_number         => p_api_version_number
2632             ,p_init_msg_list              => FND_API.G_FALSE
2633             ,p_commit                     => FND_API.G_FALSE
2634             ,p_user_id                    => p_user_id
2635             ,p_resp_id                    => x.responsibility_id
2636             ,p_app_id                     => x.responsibility_application_id
2637             ,p_security_group_id          => x.security_group_id
2638             ,p_start_date                 => x.start_date
2639             ,p_description                => x.description
2640             ,x_return_status              => x_return_status
2641             ,x_msg_count                  => x_msg_count
2642             ,x_msg_data                   => x_msg_data
2643          );
2644       END IF;
2645 
2646       IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
2647          RAISE FND_API.G_EXC_ERROR;
2648       END IF;
2649    END LOOP;
2650 
2651 
2652      IF (not l_is_resp_assigned) THEN
2653       pv_user_Resp_pvt.assign_user_resps(
2654       p_api_version_number         => p_api_version_number
2655      ,p_init_msg_list              => FND_API.g_false
2656      ,p_commit                     => FND_API.G_FALSE
2657      ,x_return_status              => x_return_status
2658      ,x_msg_count                  => x_msg_count
2659      ,x_msg_data                   => x_msg_data
2660      ,p_user_id                    => p_user_id
2661      ,p_user_role_code             => p_to_user_role_code
2662      );
2663 
2664        IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
2665          RAISE FND_API.G_EXC_ERROR;
2666       END IF;
2667 
2668    END IF;
2669 
2670    -- Check for commit
2671    IF FND_API.to_boolean(p_commit) THEN
2672       COMMIT;
2673    END IF;
2674 
2675    FND_MSG_PUB.count_and_get(
2676       p_encoded => FND_API.g_false
2677      ,p_count   => x_msg_count
2678      ,p_data    => x_msg_data
2679    );
2680 
2681 EXCEPTION
2682 
2683    WHEN PVX_Utility_PVT.resource_locked THEN
2684      x_return_status := FND_API.g_ret_sts_error;
2685          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
2686 
2687    WHEN FND_API.G_EXC_ERROR THEN
2688      ROLLBACK TO switch_user_resp;
2689      x_return_status := FND_API.G_RET_STS_ERROR;
2690      -- Standard call to get message count and if count=1, get the message
2691      FND_MSG_PUB.Count_And_Get (
2692             p_encoded => FND_API.G_FALSE,
2693             p_count   => x_msg_count,
2694             p_data    => x_msg_data
2695      );
2696 
2697    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2698      ROLLBACK TO switch_user_resp;
2699      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2700      -- Standard call to get message count and if count=1, get the message
2701      FND_MSG_PUB.Count_And_Get (
2702             p_encoded => FND_API.G_FALSE,
2703             p_count => x_msg_count,
2704             p_data  => x_msg_data
2705      );
2706 
2707    WHEN OTHERS THEN
2708      ROLLBACK TO switch_user_resp;
2709      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2710      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2711      THEN
2712         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
2713      END IF;
2714      -- Standard call to get message count and if count=1, get the message
2715      FND_MSG_PUB.Count_And_Get (
2716             p_encoded => FND_API.G_FALSE,
2717             p_count => x_msg_count,
2718             p_data  => x_msg_data
2719      );
2720 
2721 END switch_user_resp;
2722 
2723 /************
2724  * This API will do the following three things:
2725  * 1. Revoke the old responsibility_id that passed in.
2726  * 2. Update the corresponding row (using p_ptnr_resp_id) in pv_ge_ptnr_resps.
2727  * 3. Assign the new responsibility_id that passed in.
2728 ************/
2729 PROCEDURE revoke_update_assign(
2730     p_api_version_number         IN   NUMBER
2731    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
2732    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
2733    ,x_return_status              OUT  NOCOPY  VARCHAR2
2734    ,x_msg_count                  OUT  NOCOPY  NUMBER
2735    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
2736    ,p_user_ids_tbl               IN   JTF_NUMBER_TABLE
2737    ,p_ptnr_resp_id               IN   NUMBER
2738    ,p_old_responsibility_id      IN   NUMBER
2739    ,p_new_responsibility_id      IN   NUMBER
2740    ,p_program_id                 IN   NUMBER       := null
2741    ,p_resp_map_rule_id           IN   NUMBER       := null
2742    ,p_object_version_number      IN   NUMBER
2743    ,p_is_revoke                  IN   VARCHAR2
2744 )
2745 IS
2746    l_api_name              CONSTANT  VARCHAR2(30) := 'revoke_update_assign';
2747    l_exist                 NUMBER;
2748    l_responsibility_id     NUMBER;
2749    l_resp_map_rule_id      NUMBER;
2750    l_ge_ptnr_resps_rec     PV_Ge_Ptnr_Resps_PVT.ge_ptnr_resps_rec_type;
2751    l_ptnr_resp_id          NUMBER;
2752 
2753 BEGIN
2754   ---- Initialize----------------
2755 
2756    -- Initialize message list if p_init_msg_list is set to TRUE.
2757    IF Fnd_Api.to_Boolean( p_init_msg_list )
2758    THEN
2759       Fnd_Msg_Pub.initialize;
2760    END IF;
2761 
2762    -- Debug Message
2763    IF (PV_DEBUG_HIGH_ON) THEN
2764       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
2765    END IF;
2766 
2767    -- Initialize API return status to SUCCESS
2768    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
2769 
2770    IF p_is_revoke = 'Y' THEN
2771       IF (PV_DEBUG_HIGH_ON) THEN
2772          Debug_Log('revoke_update_assign: p_old_responsibility_id' || p_old_responsibility_id);
2773       END IF;
2774       revoke_resp(
2775           p_api_version_number         => p_api_version_number
2776          ,p_init_msg_list              => FND_API.G_FALSE
2777          ,p_commit                     => FND_API.G_FALSE
2778          ,p_user_id                    => p_user_ids_tbl
2779          ,p_resp_id                    => p_old_responsibility_id
2780          ,x_return_status              => x_return_status
2781          ,x_msg_count                  => x_msg_count
2782          ,x_msg_data                   => x_msg_data
2783       );
2784       IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
2785          RAISE FND_API.G_EXC_ERROR;
2786       END IF;
2787    END IF;
2788 
2789    /****
2790     * API to update the resp in pv_partner_memberships
2791     ****/
2792    l_ge_ptnr_resps_rec.ptnr_resp_id := p_ptnr_resp_id;
2793    l_ge_ptnr_resps_rec.responsibility_id := p_new_responsibility_id;
2794    IF p_resp_map_rule_id IS NOT NULL THEN
2795       l_ge_ptnr_resps_rec.source_resp_map_rule_id := p_resp_map_rule_id;
2796       Debug_Log('revoke_update_assign: l_ge_ptnr_resps_rec.source_resp_map_rule_id = ' || l_ge_ptnr_resps_rec.source_resp_map_rule_id);
2797    END IF;
2798    IF p_program_id IS NOT NULL THEN
2799       l_ge_ptnr_resps_rec.program_id := p_program_id;
2800       Debug_Log('revoke_update_assign: l_ge_ptnr_resps_rec.program_id = ' || l_ge_ptnr_resps_rec.program_id);
2801    END IF;
2802    l_ge_ptnr_resps_rec.object_version_number := p_object_version_number;
2803 
2804    IF (PV_DEBUG_HIGH_ON) THEN
2805       Debug_Log('revoke_update_assign: l_ge_ptnr_resps_rec.ptnr_resp_id = ' || l_ge_ptnr_resps_rec.ptnr_resp_id);
2806       Debug_Log('revoke_update_assign: l_ge_ptnr_resps_rec.responsibility_id = ' || l_ge_ptnr_resps_rec.responsibility_id);
2807       Debug_Log('revoke_update_assign: l_ge_ptnr_resps_rec.object_version_number = ' || l_ge_ptnr_resps_rec.object_version_number);
2808   END IF;
2809 
2810   PV_Ge_Ptnr_Resps_PVT.Update_Ge_Ptnr_Resps(
2811        p_api_version_number         => p_api_version_number
2812       ,p_init_msg_list              => FND_API.G_FALSE
2813       ,p_commit                     => FND_API.G_FALSE
2814       ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
2815 
2816       ,x_return_status              => x_return_status
2817       ,x_msg_count                  => x_msg_count
2818       ,x_msg_data                   => x_msg_data
2819       ,p_ge_ptnr_resps_rec          => l_ge_ptnr_resps_rec
2820    );
2821    IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
2822       RAISE FND_API.G_EXC_ERROR;
2823       x_return_status := FND_API.G_RET_STS_ERROR;
2824    END IF;
2825 
2826    FOR l_cnt IN 1..p_user_ids_tbl.count LOOP
2827       -- Debug Message
2828       IF (PV_DEBUG_HIGH_ON) THEN
2829          Debug_Log('revoke_update_assign: p_new_responsibility_id' || p_new_responsibility_id);
2830       END IF;
2831 
2832       assign_resp(
2833           p_api_version_number         => p_api_version_number
2834          ,p_init_msg_list              => FND_API.G_FALSE
2835          ,p_commit                     => FND_API.G_FALSE
2836          ,p_user_id                    => p_user_ids_tbl(l_cnt)
2837          ,p_resp_id                    => p_new_responsibility_id
2838          ,p_app_id                     => 691
2839          ,x_return_status              => x_return_status
2840          ,x_msg_count                  => x_msg_count
2841          ,x_msg_data                   => x_msg_data
2842       );
2843       IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
2844          RAISE FND_API.G_EXC_ERROR;
2845       END IF;
2846    END LOOP;
2847 
2848    -- Check for commit
2849    IF FND_API.to_boolean(p_commit) THEN
2850       COMMIT;
2851    END IF;
2852 
2853    FND_MSG_PUB.count_and_get(
2854       p_encoded => FND_API.g_false
2855      ,p_count   => x_msg_count
2856      ,p_data    => x_msg_data
2857    );
2858 
2859 EXCEPTION
2860 
2861    WHEN PVX_Utility_PVT.resource_locked THEN
2862      x_return_status := FND_API.g_ret_sts_error;
2863          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
2864 
2865    WHEN FND_API.G_EXC_ERROR THEN
2866      RAISE FND_API.G_EXC_ERROR;
2867      x_return_status := FND_API.G_RET_STS_ERROR;
2868      -- Standard call to get message count and if count=1, get the message
2869      FND_MSG_PUB.Count_And_Get (
2870             p_encoded => FND_API.G_FALSE,
2871             p_count   => x_msg_count,
2872             p_data    => x_msg_data
2873      );
2874 
2875    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2876      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2877      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2878      -- Standard call to get message count and if count=1, get the message
2879      FND_MSG_PUB.Count_And_Get (
2880             p_encoded => FND_API.G_FALSE,
2881             p_count => x_msg_count,
2882             p_data  => x_msg_data
2883      );
2884 
2885    WHEN OTHERS THEN
2886      RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2887      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2888      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2889      THEN
2890         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
2891      END IF;
2892      -- Standard call to get message count and if count=1, get the message
2893      FND_MSG_PUB.Count_And_Get (
2894             p_encoded => FND_API.G_FALSE,
2895             p_count => x_msg_count,
2896             p_data  => x_msg_data
2897      );
2898 END revoke_update_assign;
2899 
2900 /*
2901  * manage_ter_exp_memb_resp
2902  * This private API gets called when membership is terminated or expired
2903  */
2904 PROCEDURE manage_ter_exp_memb_resp(
2905     p_api_version_number         IN   NUMBER
2906    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
2907    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
2908    ,x_return_status              OUT  NOCOPY  VARCHAR2
2909    ,x_msg_count                  OUT  NOCOPY  NUMBER
2910    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
2911    ,p_partner_id                 IN   NUMBER
2912    ,p_program_id                 IN   NUMBER
2913 )
2914 IS
2915 
2916    CURSOR c_get_partner_resp_info(cv_resp_type_code VARCHAR2) IS
2917       SELECT ptnr_resp_id, user_role_code, responsibility_id, object_version_number
2918       FROM   pv_ge_ptnr_resps
2919       WHERE  partner_id = p_partner_id
2920       AND    program_id = p_program_id
2921       AND    resp_type_code = cv_resp_type_code;
2922 
2923    -- Get the resp id of all other partners which have the same
2924    -- partner_party_id of the pass in partner
2925    CURSOR c_get_other_resp_id(cv_user_role_code VARCHAR2, cv_resp_type_code VARCHAR2) IS
2926       SELECT responsibility_id
2927       FROM   pv_ge_ptnr_resps
2928       WHERE  partner_id in (
2929                 SELECT partner_id
2930                 FROM   pv_partner_profiles
2931                 WHERE  partner_party_id in (
2932                           SELECT partner_party_id
2933                           FROM pv_partner_profiles
2934                           WHERE partner_id = p_partner_id
2935                        )
2936                 AND    partner_id <> p_partner_id
2937              )
2938        AND   user_role_code = cv_user_role_code
2939        AND   resp_type_code = cv_resp_type_code;
2940 
2941    CURSOR c_get_count (cv_partner_id NUMBER, cv_user_role_code VARCHAR2, cv_responsibility_id NUMBER, cv_resp_type_code VARCHAR2) IS
2942       SELECT count(*)
2943       FROM   pv_ge_ptnr_resps
2944       WHERE  partner_id = cv_partner_id
2945          AND user_role_code = cv_user_role_code
2946          AND responsibility_id = cv_responsibility_id
2947          AND resp_type_code = cv_resp_type_code;
2948 
2949    CURSOR c_check_prgm_resp_exist (cv_partner_id NUMBER, cv_user_role_code VARCHAR2) IS
2950       SELECT 1
2951       FROM   pv_ge_ptnr_resps
2952       WHERE  partner_id = cv_partner_id
2953       AND    user_role_code = cv_user_role_code
2954       AND    resp_type_code = G_PROGRAM;
2955 
2956    l_api_name                 CONSTANT  VARCHAR2(30) := 'manage_ter_exp_memb_resp';
2957    l_api_version_number       CONSTANT NUMBER   := 1.0;
2958    l_user_ids_tbl             JTF_NUMBER_TABLE;
2959    l_related_partner_id_tbl   JTF_NUMBER_TABLE;
2960    l_exist                    NUMBER;
2961    l_count                    NUMBER;
2962    l_responsibility_id        JTF_NUMBER_TABLE;
2963    l_no_revoke                BOOLEAN;
2964 BEGIN
2965   ---- Initialize----------------
2966 
2967    -- Standard Start of API savepoint
2968    SAVEPOINT manage_ter_exp_memb_resp;
2969 
2970    -- Standard call to check for call compatibility.
2971    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
2972                                       ,p_api_version_number
2973                                       ,l_api_name
2974                                       ,G_PKG_NAME
2975                                       )
2976    THEN
2977        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
2978    END IF;
2979 
2980    -- Initialize message list if p_init_msg_list is set to TRUE.
2981    IF Fnd_Api.to_Boolean( p_init_msg_list )
2982    THEN
2983       Fnd_Msg_Pub.initialize;
2984    END IF;
2985 
2986    -- Debug Message
2987    IF (PV_DEBUG_HIGH_ON) THEN
2988       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
2989    END IF;
2990 
2991    -- Initialize API return status to SUCCESS
2992    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
2993 
2994    -- Get the ptnr_resp_id, responsibility_id, and user_role_code for
2995    -- the passed in partner_id, program_id, and resp_type_code is G_PROGRAM
2996    FOR x IN c_get_partner_resp_info(G_PROGRAM) LOOP
2997       OPEN c_get_count(p_partner_id, x.user_role_code, x.responsibility_id, G_PROGRAM);
2998       FETCH c_get_count into l_count;
2999       CLOSE c_get_count;
3000       IF (PV_DEBUG_HIGH_ON) THEN
3001          Debug_Log('manage_ter_exp_memb_resp: l_count = ' || l_count);
3002       END IF;
3003       -- If there is only this (partner_id, user_role_code, responsibility_id, resp_type_code) combo,
3004       -- do the following steps.
3005       IF (l_count = 1) THEN
3006          IF (PV_DEBUG_HIGH_ON) THEN
3007             Debug_Log('manage_ter_exp_memb_resp: l_count is 1');
3008          END IF;
3009 
3010          IF (PV_DEBUG_HIGH_ON) THEN
3011             Debug_Log('manage_ter_exp_memb_resp: x.responsibility_id = ' || x.responsibility_id);
3012          END IF;
3013 
3014          l_no_revoke := false;
3015          FOR y IN c_get_other_resp_id(x.user_role_code, G_PROGRAM) LOOP
3016             -- To check if there is same resp_id assigned to the users
3017             -- The users in two partner_id which have the same partner_party_id
3018             -- We set l_no_revoke to true, that means, we will not revoke this resp
3019             IF (x.responsibility_id = y.responsibility_id) THEN
3020                l_no_revoke := true;
3021                exit;
3022             END IF;
3023          END LOOP;
3024          IF (not l_no_revoke) THEN
3025             revoke_resp(
3026                 p_api_version_number         => p_api_version_number
3027                ,p_init_msg_list              => FND_API.G_FALSE
3028                ,p_commit                     => p_commit
3029                ,p_user_id                    => get_partner_users_2(p_partner_id, x.user_role_code)
3030                ,p_resp_id                    => x.responsibility_id
3031                ,x_return_status              => x_return_status
3032                ,x_msg_count                  => x_msg_count
3033                ,x_msg_data                   => x_msg_data
3034             );
3035             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3036                RAISE FND_API.G_EXC_ERROR;
3037             END IF;
3038          END IF;
3039 
3040          /****
3041           * API to delete the row with ptnr_resp_id = x.ptnr_resp_id from pv_partner_memberships
3042           ****/
3043          IF (PV_DEBUG_HIGH_ON) THEN
3044             Debug_Log('manage_ter_exp_memb_resp: before calling PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps');
3045             Debug_Log('manage_ter_exp_memb_resp: x.ptnr_resp_id = ' || x.ptnr_resp_id);
3046          END IF;
3047 
3048          PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps(
3049              p_api_version_number         => p_api_version_number
3050             ,p_init_msg_list              => FND_API.G_FALSE
3051             ,p_commit                     => FND_API.G_FALSE
3052             ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
3053 
3054             ,x_return_status              => x_return_status
3055             ,x_msg_count                  => x_msg_count
3056             ,x_msg_data                   => x_msg_data
3057             ,p_ptnr_resp_id               => x.ptnr_resp_id
3058             ,p_object_version_number      => x.object_version_number
3059          );
3060          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3061             RAISE FND_API.G_EXC_ERROR;
3062          END IF;
3063 
3064          OPEN c_check_prgm_resp_exist(p_partner_id, x.user_role_code);
3065          FETCH c_check_prgm_resp_exist INTO l_exist  ;
3066 
3067          IF (c_check_prgm_resp_exist%NOTFOUND) THEN
3068             -- Get the new default resp, assign it to the users, and add a new
3069             -- row into pv_ge_ptnr_resps
3070             IF (PV_DEBUG_HIGH_ON) THEN
3071                Debug_Log('manage_ter_exp_memb_resp: c_check_prgm_resp_exist%NOTFOUND');
3072             END IF;
3073             get_default_assign_addrow(
3074                 p_api_version_number         => p_api_version_number
3075                ,p_init_msg_list              => FND_API.G_FALSE
3076                ,p_commit                     => FND_API.G_FALSE
3077                ,x_return_status              => x_return_status
3078                ,x_msg_count                  => x_msg_count
3079                ,x_msg_data                   => x_msg_data
3080                ,p_user_role_code             => x.user_role_code
3081                ,p_user_ids_tbl               => get_partner_users(p_partner_id, x.user_role_code)
3082                ,p_partner_id                 => p_partner_id
3083             );
3084             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3085                CLOSE c_check_prgm_resp_exist;
3086                RAISE FND_API.G_EXC_ERROR;
3087             END IF;
3088          END IF;
3089          CLOSE c_check_prgm_resp_exist;
3090       ELSIF l_count > 1 THEN
3091          /****
3092           * API to delete the row with ptnr_resp_id = x.ptnr_resp_id from pv_partner_memberships
3093           ****/
3094          IF (PV_DEBUG_HIGH_ON) THEN
3095             Debug_Log('manage_ter_exp_memb_resp: before calling PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps');
3096             Debug_Log('manage_ter_exp_memb_resp: x.ptnr_resp_id = ' || x.ptnr_resp_id);
3097          END IF;
3098 
3099          PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps(
3100              p_api_version_number         => p_api_version_number
3101             ,p_init_msg_list              => FND_API.G_FALSE
3102             ,p_commit                     => p_commit
3103             ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
3104 
3105             ,x_return_status              => x_return_status
3106             ,x_msg_count                  => x_msg_count
3107             ,x_msg_data                   => x_msg_data
3108             ,p_ptnr_resp_id               => x.ptnr_resp_id
3109             ,p_object_version_number      => x.object_version_number
3110          );
3111          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3112             RAISE FND_API.G_EXC_ERROR;
3113          END IF;
3114       END IF; -- End of IF l_count = 1
3115     END LOOP; -- End of FOR x IN c_get_partner_resp_info
3116 
3117    -- Get the store program responsibility_id
3118    -- Get the ptnr_resp_id, responsibility_id, and user_role_code for
3119    -- the passed in partner_id, program_id, and resp_type_code is G_PROGRAM
3120    FOR x IN c_get_partner_resp_info(G_STORE) LOOP
3121       OPEN c_get_count(p_partner_id, x.user_role_code, x.responsibility_id, G_STORE);
3122       FETCH c_get_count into l_count;
3123       CLOSE c_get_count;
3124       IF (PV_DEBUG_HIGH_ON) THEN
3125          Debug_Log('manage_ter_exp_memb_resp: l_count = ' || l_count);
3126       END IF;
3127       -- If there is only this (partner_id, user_role_code, responsibility_id, resp_type_code) combo,
3128       -- do the following steps.
3129       IF (l_count = 1) THEN
3130          IF (PV_DEBUG_HIGH_ON) THEN
3131             Debug_Log('manage_ter_exp_memb_resp: l_count is 1');
3132          END IF;
3133 
3134          IF (PV_DEBUG_HIGH_ON) THEN
3135             Debug_Log('manage_ter_exp_memb_resp: x.responsibility_id = ' || x.responsibility_id);
3136          END IF;
3137 
3138          l_no_revoke := false;
3139          FOR y IN c_get_other_resp_id(x.user_role_code, G_STORE) LOOP
3140             -- To check if there is same resp_id assigned to the users
3141             -- The users in two partner_id which have the same partner_party_id
3142             -- We set l_no_revoke to true, that means, we will not revoke this resp
3143             IF (x.responsibility_id = y.responsibility_id) THEN
3144                l_no_revoke := true;
3145                exit;
3146             END IF;
3147          END LOOP;
3148          IF (not l_no_revoke) THEN
3149             -- Revoke for all users
3150             revoke_resp(
3151                 p_api_version_number         => p_api_version_number
3152                ,p_init_msg_list              => FND_API.G_FALSE
3153                ,p_commit                     => p_commit
3154                ,p_user_id                    => get_partner_users_2(p_partner_id, G_ALL)
3155                ,p_resp_id                    => x.responsibility_id
3156                ,x_return_status              => x_return_status
3157                ,x_msg_count                  => x_msg_count
3158                ,x_msg_data                   => x_msg_data
3159             );
3160             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3161                RAISE FND_API.G_EXC_ERROR;
3162             END IF;
3163          END IF; -- End of IF (not l_no_revoke)
3164       END IF; -- End of IF (l_count = 1)
3165       /****
3166        * API to delete the row with ptnr_resp_id = x.ptnr_resp_id from pv_partner_memberships
3167        ****/
3168       IF (PV_DEBUG_HIGH_ON) THEN
3169          Debug_Log('manage_ter_exp_memb_resp: before calling PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps');
3170          Debug_Log('manage_ter_exp_memb_resp: x.ptnr_resp_id = ' || x.ptnr_resp_id);
3171       END IF;
3172 
3173       PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps(
3174           p_api_version_number         => p_api_version_number
3175          ,p_init_msg_list              => FND_API.G_FALSE
3176          ,p_commit                     => FND_API.G_FALSE
3177          ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
3178 
3179          ,x_return_status              => x_return_status
3180          ,x_msg_count                  => x_msg_count
3181          ,x_msg_data                   => x_msg_data
3182          ,p_ptnr_resp_id               => x.ptnr_resp_id
3183          ,p_object_version_number      => x.object_version_number
3184       );
3185       IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3186          RAISE FND_API.G_EXC_ERROR;
3187       END IF;
3188    END LOOP; -- End of FOR x IN c_get_partner_resp_info(G_STORE) LOOP
3189 
3190    FND_MSG_PUB.count_and_get(
3191       p_encoded => FND_API.g_false
3192      ,p_count   => x_msg_count
3193      ,p_data    => x_msg_data
3194    );
3195 
3196    -- Check for commit
3197    IF FND_API.to_boolean(p_commit) THEN
3198       COMMIT;
3199    END IF;
3200 
3201 EXCEPTION
3202 
3203    WHEN PVX_Utility_PVT.resource_locked THEN
3204      x_return_status := FND_API.g_ret_sts_error;
3205          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
3206 
3207    WHEN FND_API.G_EXC_ERROR THEN
3208      ROLLBACK TO manage_ter_exp_memb_resp;
3209      x_return_status := FND_API.G_RET_STS_ERROR;
3210      -- Standard call to get message count and if count=1, get the message
3211      FND_MSG_PUB.Count_And_Get (
3212             p_encoded => FND_API.G_FALSE,
3213             p_count   => x_msg_count,
3214             p_data    => x_msg_data
3215      );
3216 
3217    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3218      ROLLBACK TO manage_ter_exp_memb_resp;
3219      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3220      -- Standard call to get message count and if count=1, get the message
3221      FND_MSG_PUB.Count_And_Get (
3222             p_encoded => FND_API.G_FALSE,
3223             p_count => x_msg_count,
3224             p_data  => x_msg_data
3225      );
3226 
3227    WHEN OTHERS THEN
3228      ROLLBACK TO manage_ter_exp_memb_resp;
3229      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3230      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3231      THEN
3232         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
3233      END IF;
3234      -- Standard call to get message count and if count=1, get the message
3235      FND_MSG_PUB.Count_And_Get (
3236             p_encoded => FND_API.G_FALSE,
3237             p_count => x_msg_count,
3238             p_data  => x_msg_data
3239      );
3240 
3241 END manage_ter_exp_memb_resp;
3242 
3243 
3244 /*
3245  * manage_active_memb_resp
3246  * This private API gets called when new 'ACTIVE' membership row is created in
3247  * pv_pg_memberships table.
3248  */
3249 PROCEDURE manage_active_memb_resp(
3250     p_api_version_number         IN   NUMBER
3251    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
3252    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
3253    ,x_return_status              OUT  NOCOPY  VARCHAR2
3254    ,x_msg_count                  OUT  NOCOPY  NUMBER
3255    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
3256    ,p_partner_id                 IN   NUMBER
3257    ,p_program_id                 IN   NUMBER
3258    ,p_membership_id              IN   NUMBER
3259 )
3260 IS
3261    CURSOR c_get_default_resp_id (cv_partner_id NUMBER, cv_user_role_code VARCHAR2) IS
3262       SELECT ptnr_resp_id, responsibility_id, object_version_number
3263       FROM   pv_ge_ptnr_resps
3264       WHERE  partner_id = cv_partner_id
3265       AND    program_id is null
3266       AND    user_role_code = cv_user_role_code
3267       AND    resp_type_code = G_PROGRAM;
3268 
3269    CURSOR c_get_prev_memberships (cv_membership_id NUMBER) IS
3270       SELECT prev.program_id
3271       FROM   pv_pg_mmbr_transitions tran, pv_pg_memberships prev
3272       WHERE  tran.to_membership_id = cv_membership_id
3273       AND    prev.membership_id = tran.from_membership_id;
3274 
3275    l_api_name                 CONSTANT  VARCHAR2(30) := 'manage_active_memb_resp';
3276    l_api_version_number       CONSTANT NUMBER   := 1.0;
3277    l_responsibility_id        NUMBER;
3278    l_store_responsibility_id  JTF_NUMBER_TABLE;
3279    l_store_resp_map_rule_id   JTF_NUMBER_TABLE;
3280    l_resp_map_rule_id         NUMBER;
3281    l_ptnr_resp_id             NUMBER;
3282    l_ge_ptnr_resps_rec        PV_Ge_Ptnr_Resps_PVT.ge_ptnr_resps_rec_type;
3283    l_user_ids_tbl             JTF_NUMBER_TABLE;
3284 
3285 BEGIN
3286   ---- Initialize----------------
3287 
3288    -- Standard Start of API savepoint
3289    SAVEPOINT manage_active_memb_resp;
3290 
3291    -- Standard call to check for call compatibility.
3292    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
3293                                       ,p_api_version_number
3294                                       ,l_api_name
3295                                       ,G_PKG_NAME
3296                                       )
3297    THEN
3298        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
3299    END IF;
3300 
3301    -- Initialize message list if p_init_msg_list is set to TRUE.
3302    IF Fnd_Api.to_Boolean( p_init_msg_list )
3303    THEN
3304       Fnd_Msg_Pub.initialize;
3305    END IF;
3306 
3307    -- Debug Message
3308    IF (PV_DEBUG_HIGH_ON) THEN
3309       Debug_Log('PRIVATE API: ' || l_api_name || ' - START...');
3310       Debug_Log('manage_active_memb_resp: p_partner_id = ' || p_partner_id);
3311       Debug_Log('manage_active_memb_resp: p_program_id = ' || p_program_id);
3312       Debug_Log('manage_active_memb_resp: p_membership_id = ' || p_membership_id);
3313    END IF;
3314 
3315    -- Initialize API return status to SUCCESS
3316    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
3317 
3318    -- Get all users of the partner_id and the user_role_code.
3319    --primary_user_ids_tbl := get_partner_users(p_partner_id, G_PRIMARY);
3320    --business_user_ids_tbl := get_partner_users(p_partner_id, G_BUSINESS);
3321 
3322    -- Get the program responsibility for primary users
3323    IF (PV_DEBUG_HIGH_ON) THEN
3324       Debug_Log('manage_active_memb_resp: primary users');
3325    END IF;
3326    get_program_resp(
3327        p_api_version_number         => p_api_version_number
3328       ,p_init_msg_list              => FND_API.G_FALSE
3329       ,p_commit                     => FND_API.G_FALSE
3330       ,x_return_status              => x_return_status
3331       ,x_msg_count                  => x_msg_count
3332       ,x_msg_data                   => x_msg_data
3333       ,p_partner_id                 => p_partner_id
3334       ,p_user_role_code             => G_PRIMARY
3335       ,p_program_id                 => p_program_id
3336       ,x_responsibility_id          => l_responsibility_id
3337       ,x_resp_map_rule_id           => l_resp_map_rule_id
3338    );
3339    IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3340       RAISE FND_API.G_EXC_ERROR;
3341    END IF;
3342 
3343    IF (PV_DEBUG_HIGH_ON) THEN
3344       Debug_Log('manage_active_memb_resp: l_responsibility_id = ' || l_responsibility_id);
3345       Debug_Log('manage_active_memb_resp: l_resp_map_rule_id = ' || l_resp_map_rule_id);
3346    END IF;
3347 
3348    -- If there is any program responsibility, get the partner primary users and assign
3349    -- that responsibility to all of them
3350    IF (l_responsibility_id is not null) and (l_resp_map_rule_id is not null) THEN
3351       l_user_ids_tbl := get_partner_users(p_partner_id, G_PRIMARY);
3352       -- Check if default responsibility is still assigned to partner
3353       -- If yes, revoke for all partner primary users
3354       FOR x in c_get_default_resp_id(p_partner_id, G_PRIMARY)
3355       LOOP
3356          IF (PV_DEBUG_HIGH_ON) THEN
3357             Debug_Log('manage_active_memb_resp: x.responsibility_id = ' || x.responsibility_id);
3358          END IF;
3359          revoke_resp(
3360              p_api_version_number         => p_api_version_number
3361             ,p_init_msg_list              => FND_API.G_FALSE
3362             ,p_commit                     => FND_API.G_FALSE
3363             ,p_user_id                    => l_user_ids_tbl
3364             ,p_resp_id                    => x.responsibility_id
3365             ,x_return_status              => x_return_status
3366             ,x_msg_count                  => x_msg_count
3367             ,x_msg_data                   => x_msg_data
3368          );
3369          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3370             RAISE FND_API.G_EXC_ERROR;
3371          END IF;
3372 
3373          /****
3374           * API to delete the row with ptnr_resp_id = x.ptnr_resp_id from pv_partner_memberships
3375           ****/
3376          IF (PV_DEBUG_HIGH_ON) THEN
3377             Debug_Log('manage_active_memb_resp: before calling PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps');
3378             Debug_Log('manage_active_memb_resp: x.ptnr_resp_id = ' || x.ptnr_resp_id);
3379          END IF;
3380 
3381          PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps(
3382              p_api_version_number         => p_api_version_number
3383             ,p_init_msg_list              => FND_API.G_FALSE
3384             ,p_commit                     => FND_API.G_FALSE
3385             ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
3386             ,x_return_status              => x_return_status
3387             ,x_msg_count                  => x_msg_count
3388             ,x_msg_data                   => x_msg_data
3389             ,p_ptnr_resp_id               => x.ptnr_resp_id
3390             ,p_object_version_number      => x.object_version_number
3391          );
3392          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3393             RAISE FND_API.G_EXC_ERROR;
3394          END IF;
3395       END LOOP; -- End of loop c_get_default_resp_id()
3396 
3397       FOR l_cnt IN 1..l_user_ids_tbl.count LOOP
3398          IF (PV_DEBUG_HIGH_ON) THEN
3399             Debug_Log('manage_active_memb_resp: assign: l_user_ids_tbl('||l_cnt||')='||l_user_ids_tbl(l_cnt));
3400          END IF;
3401 
3402          assign_resp(
3403              p_api_version_number         => p_api_version_number
3404             ,p_init_msg_list              => FND_API.G_FALSE
3405             ,p_commit                     => FND_API.G_FALSE
3406             ,p_user_id                    => l_user_ids_tbl(l_cnt)
3407             ,p_resp_id                    => l_responsibility_id
3408             ,p_app_id                     => 691
3409             ,x_return_status              => x_return_status
3410             ,x_msg_count                  => x_msg_count
3411             ,x_msg_data                   => x_msg_data
3412          );
3413          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3414             RAISE FND_API.G_EXC_ERROR;
3415          END IF;
3416       END LOOP;
3417 
3418       /****
3419        * API to add a row to pv_ge_ptnr_resps
3420        ****/
3421       IF (PV_DEBUG_HIGH_ON) THEN
3422          Debug_Log('manage_active_memb_resp: before calling PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps');
3423       END IF;
3424 
3425       l_ge_ptnr_resps_rec.partner_id := p_partner_id;
3426       l_ge_ptnr_resps_rec.user_role_code := G_PRIMARY;
3427       l_ge_ptnr_resps_rec.responsibility_id := l_responsibility_id;
3428       l_ge_ptnr_resps_rec.program_id := p_program_id;
3429       l_ge_ptnr_resps_rec.source_resp_map_rule_id := l_resp_map_rule_id;
3430       l_ge_ptnr_resps_rec.resp_type_code := G_PROGRAM;
3431 
3432       IF (PV_DEBUG_HIGH_ON) THEN
3433          Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.partner_id = ' || l_ge_ptnr_resps_rec.partner_id);
3434          Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.user_role_code = ' || l_ge_ptnr_resps_rec.user_role_code);
3435          Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.responsibility_id = ' || l_ge_ptnr_resps_rec.responsibility_id);
3436          Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.program_id = ' || l_ge_ptnr_resps_rec.program_id);
3437          Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.source_resp_map_rule_id = ' || l_ge_ptnr_resps_rec.source_resp_map_rule_id);
3438          Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.resp_type_code = ' || l_ge_ptnr_resps_rec.resp_type_code);
3439       END IF;
3440 
3441       PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps(
3442           p_api_version_number         => p_api_version_number
3443          ,p_init_msg_list              => FND_API.G_FALSE
3444          ,p_commit                     => FND_API.G_FALSE
3445          ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
3446 
3447          ,x_return_status              => x_return_status
3448          ,x_msg_count                  => x_msg_count
3449          ,x_msg_data                   => x_msg_data
3450          ,p_ge_ptnr_resps_rec          => l_ge_ptnr_resps_rec
3451          ,x_ptnr_resp_id               => l_ptnr_resp_id
3452       );
3453       IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3454          RAISE FND_API.G_EXC_ERROR;
3455       END IF;
3456    END IF; -- End of IF (l_responsibility_id is not null) and (l_resp_map_rule_id is not null)
3457 
3458    -- Get the program responsibility for business users
3459    IF (PV_DEBUG_HIGH_ON) THEN
3460       Debug_Log('manage_active_memb_resp: business users');
3461    END IF;
3462    get_program_resp(
3463        p_api_version_number         => p_api_version_number
3464       ,p_init_msg_list              => FND_API.G_FALSE
3465       ,p_commit                     => FND_API.G_FALSE
3466       ,x_return_status              => x_return_status
3467       ,x_msg_count                  => x_msg_count
3468       ,x_msg_data                   => x_msg_data
3469       ,p_partner_id                 => p_partner_id
3470       ,p_user_role_code             => G_BUSINESS
3471       ,p_program_id                 => p_program_id
3472       ,x_responsibility_id          => l_responsibility_id
3473       ,x_resp_map_rule_id           => l_resp_map_rule_id
3474    );
3475    IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3476       RAISE FND_API.G_EXC_ERROR;
3477    END IF;
3478 
3479    IF (PV_DEBUG_HIGH_ON) THEN
3480       Debug_Log('manage_active_memb_resp: l_responsibility_id = ' || l_responsibility_id);
3481       Debug_Log('manage_active_memb_resp: l_resp_map_rule_id = ' || l_resp_map_rule_id);
3482    END IF;
3483    -- If there is any program responsibility, get the partner business users and assign
3484    -- that responsibility to all of them
3485    IF (l_responsibility_id is not null) and (l_resp_map_rule_id is not null) THEN
3486       l_user_ids_tbl := get_partner_users(p_partner_id, G_BUSINESS);
3487       -- Check if default responsibility is still assigned to partner
3488       -- If yes, revoke for all partner primary users
3489       FOR x in c_get_default_resp_id(p_partner_id, G_BUSINESS)
3490       LOOP
3491          IF (PV_DEBUG_HIGH_ON) THEN
3492             Debug_Log('manage_active_memb_resp: x.responsibility_id = ' || x.responsibility_id);
3493          END IF;
3494 
3495          revoke_resp(
3496              p_api_version_number         => p_api_version_number
3497             ,p_init_msg_list              => FND_API.G_FALSE
3498             ,p_commit                     => FND_API.G_FALSE
3499             ,p_user_id                    => l_user_ids_tbl
3500             ,p_resp_id                    => x.responsibility_id
3501             ,x_return_status              => x_return_status
3502             ,x_msg_count                  => x_msg_count
3503             ,x_msg_data                   => x_msg_data
3504          );
3505          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3506             RAISE FND_API.G_EXC_ERROR;
3507          END IF;
3508          /****
3509           * API to delete the row with ptnr_resp_id = x.ptnr_resp_id from pv_partner_memberships
3510           ****/
3511          IF (PV_DEBUG_HIGH_ON) THEN
3512             Debug_Log('manage_active_memb_resp: before calling PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps');
3513             Debug_Log('manage_active_memb_resp: x.ptnr_resp_id = ' || x.ptnr_resp_id);
3514          END IF;
3515 
3516          PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps(
3517              p_api_version_number         => p_api_version_number
3518             ,p_init_msg_list              => FND_API.G_FALSE
3519             ,p_commit                     => p_commit
3520             ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
3521             ,x_return_status              => x_return_status
3522             ,x_msg_count                  => x_msg_count
3523             ,x_msg_data                   => x_msg_data
3524             ,p_ptnr_resp_id               => x.ptnr_resp_id
3525             ,p_object_version_number      => x.object_version_number
3526          );
3527 
3528          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3529             RAISE FND_API.G_EXC_ERROR;
3530          END IF;
3531       END LOOP;
3532 
3533       FOR l_cnt IN 1..l_user_ids_tbl.count LOOP
3534          IF (PV_DEBUG_HIGH_ON) THEN
3535             Debug_Log('manage_active_memb_resp: assign: l_user_ids_tbl('||l_cnt||')='||l_user_ids_tbl(l_cnt));
3536          END IF;
3537 
3538          assign_resp(
3539              p_api_version_number         => p_api_version_number
3540             ,p_init_msg_list              => FND_API.G_FALSE
3541             ,p_commit                     => FND_API.G_FALSE
3542             ,p_user_id                    => l_user_ids_tbl(l_cnt)
3543             ,p_resp_id                    => l_responsibility_id
3544             ,p_app_id                     => 691
3545             ,x_return_status              => x_return_status
3546             ,x_msg_count                  => x_msg_count
3547             ,x_msg_data                   => x_msg_data
3548          );
3549          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3550             RAISE FND_API.G_EXC_ERROR;
3551          END IF;
3552       END LOOP;
3553 
3554       /****
3555        * API to add a row to pv_ptnr_resps
3556        ****/
3557       IF (PV_DEBUG_HIGH_ON) THEN
3558          Debug_Log('manage_active_memb_resp: before calling PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps');
3559       END IF;
3560 
3561       l_ge_ptnr_resps_rec.partner_id := p_partner_id;
3562       l_ge_ptnr_resps_rec.user_role_code := G_BUSINESS;
3563       l_ge_ptnr_resps_rec.responsibility_id := l_responsibility_id;
3564       l_ge_ptnr_resps_rec.program_id := p_program_id;
3565       l_ge_ptnr_resps_rec.source_resp_map_rule_id := l_resp_map_rule_id;
3566       l_ge_ptnr_resps_rec.resp_type_code := G_PROGRAM;
3567 
3568       IF (PV_DEBUG_HIGH_ON) THEN
3569          Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.partner_id = ' || l_ge_ptnr_resps_rec.partner_id);
3570          Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.user_role_code = ' || l_ge_ptnr_resps_rec.user_role_code);
3571          Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.responsibility_id = ' || l_ge_ptnr_resps_rec.responsibility_id);
3572          Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.program_id = ' || l_ge_ptnr_resps_rec.program_id);
3573          Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.source_resp_map_rule_id = ' || l_ge_ptnr_resps_rec.source_resp_map_rule_id);
3574          Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.resp_type_code = ' || l_ge_ptnr_resps_rec.resp_type_code);
3575       END IF;
3576 
3577       PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps(
3578           p_api_version_number         => p_api_version_number
3579          ,p_init_msg_list              => FND_API.G_FALSE
3580          ,p_commit                     => FND_API.G_FALSE
3581          ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
3582          ,x_return_status              => x_return_status
3583          ,x_msg_count                  => x_msg_count
3584          ,x_msg_data                   => x_msg_data
3585          ,p_ge_ptnr_resps_rec          => l_ge_ptnr_resps_rec
3586          ,x_ptnr_resp_id               => l_ptnr_resp_id
3587       );
3588       IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3589          RAISE FND_API.G_EXC_ERROR;
3590       END IF;
3591    END IF; -- End of IF (l_responsibility_id is not null) and (l_resp_map_rule_id is not null)
3592 
3593    -- Get the store program responsibility_id
3594    get_store_prgm_resps(
3595        p_api_version_number         => p_api_version_number
3596       ,p_init_msg_list              => FND_API.G_FALSE
3597       ,p_commit                     => FND_API.G_FALSE
3598       ,x_return_status              => x_return_status
3599       ,x_msg_count                  => x_msg_count
3600       ,x_msg_data                   => x_msg_data
3601       ,p_program_id                 => p_program_id
3602       ,x_responsibility_id          => l_store_responsibility_id
3603       ,x_resp_map_rule_id           => l_store_resp_map_rule_id
3604    );
3605 
3606    IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3607        RAISE FND_API.G_EXC_ERROR;
3608    END IF;
3609 
3610    IF l_store_responsibility_id IS NULL THEN
3611       IF (PV_DEBUG_HIGH_ON) THEN
3612          Debug_Log('manage_active_memb_resp: l_store_responsibility_id is null');
3613       END IF;
3614    END IF;
3615 
3616    IF l_store_responsibility_id IS NOT NULL THEN
3617       IF (PV_DEBUG_HIGH_ON) THEN
3618          Debug_Log('manage_active_memb_resp: l_store_responsibility_id is not null');
3619       END IF;
3620       l_user_ids_tbl := get_partner_users(p_partner_id, G_ALL);
3621       -- assign the above responsibility_id to all primary users
3622       FOR l_r_cnt IN 1..l_store_responsibility_id.count LOOP
3623          IF (PV_DEBUG_HIGH_ON) THEN
3624             Debug_Log('manage_active_memb_resp: primary: l_store_responsibility_id('||l_r_cnt||')='||l_store_responsibility_id(l_r_cnt));
3625          END IF;
3626          FOR l_u_cnt IN 1..l_user_ids_tbl.count LOOP
3627             assign_resp (
3628                 p_api_version_number         => p_api_version_number
3629                ,p_init_msg_list              => FND_API.G_FALSE
3630                ,p_commit                     => FND_API.G_FALSE
3631                ,p_user_id                    => l_user_ids_tbl(l_u_cnt)
3632                ,p_resp_id                    => l_store_responsibility_id(l_r_cnt)
3633                ,p_app_id                     => 671
3634                ,x_return_status              => x_return_status
3635                ,x_msg_count                  => x_msg_count
3636                ,x_msg_data                   => x_msg_data
3637             );
3638             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3639                RAISE FND_API.G_EXC_ERROR;
3640             END IF;
3641          END LOOP; -- End of l_user_ids_tbl
3642 
3643          IF (PV_DEBUG_HIGH_ON) THEN
3644             Debug_Log('manage_active_memb_resp: before calling PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps');
3645          END IF;
3646 
3647          /****
3648           * API to add a row to pv_ptnr_resps
3649           ****/
3650          l_ge_ptnr_resps_rec.partner_id := p_partner_id;
3651          l_ge_ptnr_resps_rec.user_role_code := G_ALL;
3652          l_ge_ptnr_resps_rec.responsibility_id := l_store_responsibility_id(l_r_cnt);
3653          l_ge_ptnr_resps_rec.program_id := p_program_id;
3654          l_ge_ptnr_resps_rec.source_resp_map_rule_id := l_store_resp_map_rule_id(l_r_cnt);
3655          l_ge_ptnr_resps_rec.resp_type_code := G_STORE;
3656 
3657          IF (PV_DEBUG_HIGH_ON) THEN
3658             Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.partner_id = ' || l_ge_ptnr_resps_rec.partner_id);
3659             Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.user_role_code = ' || l_ge_ptnr_resps_rec.user_role_code);
3660             Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.responsibility_id = ' || l_ge_ptnr_resps_rec.responsibility_id);
3661             Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.program_id = ' || l_ge_ptnr_resps_rec.program_id);
3662             Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.source_resp_map_rule_id = ' || l_ge_ptnr_resps_rec.source_resp_map_rule_id);
3663             Debug_Log('manage_active_memb_resp: l_ge_ptnr_resps_rec.resp_type_code = ' || l_ge_ptnr_resps_rec.resp_type_code);
3664          END IF;
3665 
3666          PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps(
3667              p_api_version_number         => p_api_version_number
3668             ,p_init_msg_list              => FND_API.G_FALSE
3669             ,p_commit                     => FND_API.G_FALSE
3670             ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
3671             ,x_return_status              => x_return_status
3672             ,x_msg_count                  => x_msg_count
3673             ,x_msg_data                   => x_msg_data
3674             ,p_ge_ptnr_resps_rec          => l_ge_ptnr_resps_rec
3675             ,x_ptnr_resp_id               => l_ptnr_resp_id
3676          );
3677          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3678             RAISE FND_API.G_EXC_ERROR;
3679          END IF;
3680       END LOOP; -- End of FOR l_r_cnt IN 1..l_store_responsibility_id.count
3681    END IF; -- End of IF (l_responsibility_id is not null) and (l_resp_map_rule_id is not null)
3682 
3683    -- Get if there are any previous memberships that are associated with the current membership.
3684    FOR x IN c_get_prev_memberships(p_membership_id)
3685    LOOP
3686       IF (PV_DEBUG_HIGH_ON) THEN
3687          Debug_Log('manage_active_memb_resp: before calling manage_ter_exp_memb_resp');
3688       END IF;
3689       -- Call c_get_prev_memberships for all the programs retrieved in the above step
3690       manage_ter_exp_memb_resp(
3691           p_api_version_number         => p_api_version_number
3692          ,p_init_msg_list              => FND_API.G_FALSE
3693          ,p_commit                     => FND_API.G_FALSE
3694          ,x_return_status              => x_return_status
3695          ,x_msg_count                  => x_msg_count
3696          ,x_msg_data                   => x_msg_data
3697          ,p_partner_id                 => p_partner_id
3698          ,p_program_id                 => x.program_id
3699       );
3700       IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3701          RAISE FND_API.G_EXC_ERROR;
3702       END IF;
3703    END LOOP;
3704 
3705    -- Check for commit
3706    IF FND_API.to_boolean(p_commit) THEN
3707       COMMIT;
3708    END IF;
3709 
3710    FND_MSG_PUB.count_and_get(
3711       p_encoded => FND_API.g_false
3712      ,p_count   => x_msg_count
3713      ,p_data    => x_msg_data
3714    );
3715 
3716 EXCEPTION
3717 
3718    WHEN PVX_Utility_PVT.resource_locked THEN
3719      x_return_status := FND_API.g_ret_sts_error;
3720          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
3721 
3722    WHEN FND_API.G_EXC_ERROR THEN
3723      ROLLBACK TO manage_active_memb_resp;
3724      x_return_status := FND_API.G_RET_STS_ERROR;
3725      -- Standard call to get message count and if count=1, get the message
3726      FND_MSG_PUB.Count_And_Get (
3727             p_encoded => FND_API.G_FALSE,
3728             p_count   => x_msg_count,
3729             p_data    => x_msg_data
3730      );
3731 
3732    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3733      ROLLBACK TO manage_active_memb_resp;
3734      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3735      -- Standard call to get message count and if count=1, get the message
3736      FND_MSG_PUB.Count_And_Get (
3737             p_encoded => FND_API.G_FALSE,
3738             p_count => x_msg_count,
3739             p_data  => x_msg_data
3740      );
3741 
3742    WHEN OTHERS THEN
3743      ROLLBACK TO manage_active_memb_resp;
3744      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3745      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3746      THEN
3747         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
3748      END IF;
3749      -- Standard call to get message count and if count=1, get the message
3750      FND_MSG_PUB.Count_And_Get (
3751             p_encoded => FND_API.G_FALSE,
3752             p_count => x_msg_count,
3753             p_data  => x_msg_data
3754      );
3755 
3756 END manage_active_memb_resp;
3757 
3758 /*
3759  * manage_memb_resp
3760  * This public API will take care of managing user responsibilities when
3761  * membership is terminated, exprired, created, upgraded, and downgraded.
3762  * This should be called when a new row is created in pv_pg_memberships
3763  * table with the membership_id of the row that just got created, membership_id
3764  * of program that is being terminated or expireing.
3765  */
3766 PROCEDURE manage_memb_resp(
3767     p_api_version_number         IN   NUMBER
3768    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
3769    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
3770    ,x_return_status              OUT  NOCOPY  VARCHAR2
3771    ,x_msg_count                  OUT  NOCOPY  NUMBER
3772    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
3773    ,p_membership_id              IN   NUMBER
3774 )
3775 IS
3776    CURSOR c_get_membership_status (cv_membership_id NUMBER) IS
3777       SELECT membership_status_code, partner_id, program_id
3778       FROM   pv_pg_memberships
3779       WHERE  membership_id = cv_membership_id;
3780 
3781    l_api_name              CONSTANT  VARCHAR2(30) := 'manage_memb_resp';
3782    l_api_version_number        CONSTANT NUMBER   := 1.0;
3783    l_user_ids_tbl            JTF_NUMBER_TABLE;
3784    l_responsibility_id               NUMBER;
3785    l_resp_map_rule_id      NUMBER;
3786 
3787 BEGIN
3788   ---- Initialize----------------
3789 
3790    -- Standard Start of API savepoint
3791    SAVEPOINT manage_memb_resp;
3792 
3793    -- Standard call to check for call compatibility.
3794    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
3795                                       ,p_api_version_number
3796                                       ,l_api_name
3797                                       ,G_PKG_NAME
3798                                       )
3799    THEN
3800        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
3801    END IF;
3802 
3803    -- Initialize message list if p_init_msg_list is set to TRUE.
3804    IF Fnd_Api.to_Boolean( p_init_msg_list )
3805    THEN
3806       Fnd_Msg_Pub.initialize;
3807    END IF;
3808 
3809    -- Debug Message
3810    IF (PV_DEBUG_HIGH_ON) THEN
3811       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
3812    END IF;
3813 
3814    -- Initialize API return status to SUCCESS
3815    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
3816 
3817    -- Get the membership status
3818    FOR x IN c_get_membership_status (p_membership_id)
3819    LOOP
3820       IF x.membership_status_code = 'TERMINATED' THEN
3821          IF (PV_DEBUG_HIGH_ON) THEN
3822             Debug_Log('manage_memb_resp: TERMINATED');
3823          END IF;
3824          manage_ter_exp_memb_resp(
3825              p_api_version_number         => p_api_version_number
3826             ,p_init_msg_list              => FND_API.G_FALSE
3827             ,p_commit                     => FND_API.G_FALSE
3828             ,x_return_status              => x_return_status
3829             ,x_msg_count                  => x_msg_count
3830             ,x_msg_data                   => x_msg_data
3831             ,p_partner_id                 => x.partner_id
3832             ,p_program_id                 => x.program_id
3833          );
3834          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3835             RAISE FND_API.G_EXC_ERROR;
3836          END IF;
3837       ELSIF x.membership_status_code = 'ACTIVE' THEN
3838          IF (PV_DEBUG_HIGH_ON) THEN
3839             Debug_Log('manage_memb_resp: ACTIVE');
3840          END IF;
3841          manage_active_memb_resp(
3842              p_api_version_number         => p_api_version_number
3843             ,p_init_msg_list              => FND_API.G_FALSE
3844             ,p_commit                     => FND_API.G_FALSE
3845             ,x_return_status              => x_return_status
3846             ,x_msg_count                  => x_msg_count
3847             ,x_msg_data                   => x_msg_data
3848             ,p_partner_id                 => x.partner_id
3849             ,p_program_id                 => x.program_id
3850             ,p_membership_id              => p_membership_id
3851          );
3852          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
3853             RAISE FND_API.G_EXC_ERROR;
3854          END IF;
3855       END IF;
3856    END LOOP;
3857 
3858    -- Check for commit
3859    IF FND_API.to_boolean(p_commit) THEN
3860       COMMIT;
3861    END IF;
3862 
3863    FND_MSG_PUB.count_and_get(
3864       p_encoded => FND_API.g_false
3865      ,p_count   => x_msg_count
3866      ,p_data    => x_msg_data
3867    );
3868 
3869 EXCEPTION
3870 
3871    WHEN PVX_Utility_PVT.resource_locked THEN
3872      x_return_status := FND_API.g_ret_sts_error;
3873          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
3874 
3875    WHEN FND_API.G_EXC_ERROR THEN
3876      ROLLBACK TO manage_memb_resp;
3877      x_return_status := FND_API.G_RET_STS_ERROR;
3878      -- Standard call to get message count and if count=1, get the message
3879      FND_MSG_PUB.Count_And_Get (
3880             p_encoded => FND_API.G_FALSE,
3881             p_count   => x_msg_count,
3882             p_data    => x_msg_data
3883      );
3884 
3885    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3886      ROLLBACK TO manage_memb_resp;
3887      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3888      -- Standard call to get message count and if count=1, get the message
3889      FND_MSG_PUB.Count_And_Get (
3890             p_encoded => FND_API.G_FALSE,
3891             p_count => x_msg_count,
3892             p_data  => x_msg_data
3893      );
3894 
3895    WHEN OTHERS THEN
3896      ROLLBACK TO manage_memb_resp;
3897      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3898      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
3899      THEN
3900         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
3901      END IF;
3902      -- Standard call to get message count and if count=1, get the message
3903      FND_MSG_PUB.Count_And_Get (
3904             p_encoded => FND_API.G_FALSE,
3905             p_count => x_msg_count,
3906             p_data  => x_msg_data
3907      );
3908 
3909 END manage_memb_resp;
3910 
3911 /*
3912  * delete_resp_mapping
3913  * This public API will take care of managing partner user responsibilities when
3914  * responsibility mapping is soft deleted.
3915  */
3916 PROCEDURE delete_resp_mapping(
3917     p_api_version_number         IN   NUMBER
3918    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
3919    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
3920    ,x_return_status              OUT  NOCOPY  VARCHAR2
3921    ,x_msg_count                  OUT  NOCOPY  NUMBER
3922    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
3923    ,p_source_resp_map_rule_id    IN   NUMBER
3924 )
3925 IS
3926    CURSOR c_get_ptnr_resps (cv_source_resp_map_rule_id NUMBER) IS
3927       SELECT ptnr_resp_id, responsibility_id, partner_id, user_role_code, program_id, object_version_number
3928       FROM   pv_ge_ptnr_resps
3929       WHERE  source_resp_map_rule_id = cv_source_resp_map_rule_id
3930       AND    resp_type_code = G_PROGRAM
3931       ORDER BY partner_id, user_role_code;
3932 
3933    CURSOR c_get_count (cv_partner_id NUMBER, cv_user_role_code VARCHAR2, cv_responsibility_id NUMBER) IS
3934       SELECT count(*)
3935       FROM   pv_ge_ptnr_resps
3936       WHERE  partner_id = cv_partner_id
3937       AND    user_role_code = cv_user_role_code
3938       AND    responsibility_id = cv_responsibility_id
3939       AND    resp_type_code = G_PROGRAM;
3940 
3941    CURSOR c_check_if_resp_exist (cv_partner_id NUMBER, cv_user_role_code VARCHAR2) IS
3942       SELECT 1
3943       FROM   pv_ge_ptnr_resps
3944       WHERE  partner_id = cv_partner_id
3945       AND    user_role_code = cv_user_role_code
3946       AND    resp_type_code = G_PROGRAM;
3947 
3948    l_api_name              CONSTANT  VARCHAR2(30) := 'delete_resp_mapping';
3949    l_api_version_number    CONSTANT NUMBER   := 1.0;
3950    l_user_ids_tbl          JTF_NUMBER_TABLE;
3951    l_exist                 NUMBER;
3952    l_count                 NUMBER;
3953    l_responsibility_id     NUMBER;
3954    l_resp_map_rule_id      NUMBER;
3955    l_ptnr_resp_id          NUMBER;
3956    l_ge_ptnr_resps_rec     PV_Ge_Ptnr_Resps_PVT.ge_ptnr_resps_rec_type;
3957 
3958 BEGIN
3959   ---- Initialize----------------
3960 
3961    -- Standard Start of API savepoint
3962    SAVEPOINT delete_resp_mapping;
3963 
3964    -- Standard call to check for call compatibility.
3965    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
3966                                       ,p_api_version_number
3967                                       ,l_api_name
3968                                       ,G_PKG_NAME
3969                                       )
3970    THEN
3971        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
3972    END IF;
3973 
3974    -- Initialize message list if p_init_msg_list is set to TRUE.
3975    IF Fnd_Api.to_Boolean( p_init_msg_list )
3976    THEN
3977       Fnd_Msg_Pub.initialize;
3978    END IF;
3979 
3980    -- Debug Message
3981    IF (PV_DEBUG_HIGH_ON) THEN
3982       Debug_Log('PRIVATE API: ' || l_api_name || ' - START...');
3983    END IF;
3984    -- Initialize API return status to SUCCESS
3985    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
3986    -- Get the membership status
3987    FOR x IN c_get_ptnr_resps (p_source_resp_map_rule_id)
3988    LOOP
3989       l_user_ids_tbl := get_partner_users(x.partner_id, x.user_role_code);
3990 
3991       IF (PV_DEBUG_HIGH_ON) THEN
3992          Debug_Log('delete_resp_mapping: x.program_id = ' || x.program_id);
3993       END IF;
3994 
3995       IF x.program_id IS NOT NULL THEN
3996          OPEN c_get_count(x.partner_id, x.user_role_code, x.responsibility_id);
3997          FETCH c_get_count into l_count;
3998          CLOSE c_get_count;
3999          -- If there is only this (partner_id, user_role_code, responsibility_id) combo,
4000          -- do the following steps. Otherwise, continue.
4001          IF l_count = 1 THEN
4002             -- Get all users of the partner_id and the user_role_code.
4003             -- Rovoke the responsibility for all of them.
4004             IF (PV_DEBUG_HIGH_ON) THEN
4005                Debug_Log('delete_resp_mapping: x.responsibility_id = ' || x.responsibility_id);
4006             END IF;
4007             revoke_resp(
4008                 p_api_version_number         => p_api_version_number
4009                ,p_init_msg_list              => FND_API.G_FALSE
4010                ,p_commit                     => FND_API.G_FALSE
4011                ,p_user_id                    => l_user_ids_tbl
4012                ,p_resp_id                    => x.responsibility_id
4013                ,x_return_status              => x_return_status
4014                ,x_msg_count                  => x_msg_count
4015                ,x_msg_data                   => x_msg_data
4016             );
4017             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4018                RAISE FND_API.G_EXC_ERROR;
4019             END IF;
4020          END IF;
4021 
4022          /****
4023           * API to delete the row with ptnr_resp_id = x.ptnr_resp_id from pv_partner_memberships
4024           ****/
4025          IF (PV_DEBUG_HIGH_ON) THEN
4026             Debug_Log('delete_resp_mapping: before calling PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps');
4027             Debug_Log('delete_resp_mapping: x.ptnr_resp_id = ' || x.ptnr_resp_id);
4028          END IF;
4029 
4030          PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps(
4031              p_api_version_number         => p_api_version_number
4032             ,p_init_msg_list              => FND_API.G_FALSE
4033             ,p_commit                     => FND_API.G_FALSE
4034             ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
4035 
4036             ,x_return_status              => x_return_status
4037             ,x_msg_count                  => x_msg_count
4038             ,x_msg_data                   => x_msg_data
4039             ,p_ptnr_resp_id               => x.ptnr_resp_id
4040             ,p_object_version_number      => x.object_version_number
4041          );
4042 
4043          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4044             RAISE FND_API.G_EXC_ERROR;
4045          END IF;
4046 
4047          IF (PV_DEBUG_HIGH_ON) THEN
4048             Debug_Log('delete_resp_mapping: before calling get_program_resp');
4049          END IF;
4050          -- Get the program responsibility for primary users
4051          get_program_resp(
4052              p_api_version_number         => p_api_version_number
4053             ,p_init_msg_list              => FND_API.G_FALSE
4054             ,p_commit                     => FND_API.G_FALSE
4055             ,x_return_status              => x_return_status
4056             ,x_msg_count                  => x_msg_count
4057             ,x_msg_data                   => x_msg_data
4058             ,p_partner_id                 => x.partner_id
4059             ,p_user_role_code             => x.user_role_code
4060             ,p_program_id                 => x.program_id
4061             ,x_responsibility_id          => l_responsibility_id
4062             ,x_resp_map_rule_id           => l_resp_map_rule_id
4063          );
4064          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4065             RAISE FND_API.G_EXC_ERROR;
4066          END IF;
4067 
4068          --
4069          -- If no program resp is returned and there is no other same resps,
4070          -- check if partner has at least one resp
4071          IF ((l_responsibility_id is null) or (l_resp_map_rule_id is null)) THEN
4072             IF (PV_DEBUG_HIGH_ON) THEN
4073                Debug_Log('delete_resp_mapping: (l_responsibility_id is null or l_resp_map_rule_id is null) 1');
4074             END IF;
4075             OPEN c_check_if_resp_exist(x.partner_id, x.user_role_code);
4076             FETCH c_check_if_resp_exist into l_exist;
4077             --CLOSE c_check_if_resp_exist;
4078             -- If there is none, do the following steps. Otherwise, do nothing.
4079             IF (c_check_if_resp_exist%NOTFOUND) THEN
4080                get_default_assign_addrow(
4081                    p_api_version_number         => p_api_version_number
4082                   ,p_init_msg_list              => FND_API.G_FALSE
4083                   ,p_commit                     => FND_API.G_FALSE
4084                   ,x_return_status              => x_return_status
4085                   ,x_msg_count                  => x_msg_count
4086                   ,x_msg_data                   => x_msg_data
4087                   ,p_user_role_code             => x.user_role_code
4088                   ,p_user_ids_tbl               => l_user_ids_tbl
4089                   ,p_partner_id                 => x.partner_id
4090                );
4091                IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4092                   CLOSE c_check_if_resp_exist;
4093                   RAISE FND_API.G_EXC_ERROR;
4094                END IF;
4095             END IF; -- End of IF (c_check_if_resp_exist%NOTFOUND)
4096             CLOSE c_check_if_resp_exist;
4097 
4098          -- If some program resp is returned, assign it to the users
4099          ELSE
4100             IF (PV_DEBUG_HIGH_ON) THEN
4101                Debug_Log('delete_resp_mapping: !!!(l_responsibility_id is null or l_resp_map_rule_id is null) and l_count = 1');
4102             END IF;
4103 
4104             FOR l_cnt IN 1..l_user_ids_tbl.count
4105             LOOP
4106                assign_resp(
4107                    p_api_version_number         => p_api_version_number
4108                   ,p_init_msg_list              => FND_API.G_FALSE
4109                   ,p_commit                     => FND_API.G_FALSE
4110                   ,p_user_id                    => l_user_ids_tbl(l_cnt)
4111                   ,p_resp_id                    => l_responsibility_id
4112                   ,p_app_id                     => 691
4113                   ,x_return_status              => x_return_status
4114                   ,x_msg_count                  => x_msg_count
4115                   ,x_msg_data                   => x_msg_data
4116                );
4117             END LOOP;
4118 
4119             /****
4120              * API to add a row to Create_Ge_Ptnr_Resps
4121              ****/
4122             IF (PV_DEBUG_HIGH_ON) THEN
4123                Debug_Log('delete_resp_mapping: before calling PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps');
4124             END IF;
4125             l_ge_ptnr_resps_rec.partner_id := x.partner_id;
4126             l_ge_ptnr_resps_rec.user_role_code := x.user_role_code;
4127             l_ge_ptnr_resps_rec.responsibility_id := l_responsibility_id;
4128             l_ge_ptnr_resps_rec.program_id := x.program_id;
4129             l_ge_ptnr_resps_rec.source_resp_map_rule_id := l_resp_map_rule_id;
4130             l_ge_ptnr_resps_rec.resp_type_code := G_PROGRAM;
4131 
4132             IF (PV_DEBUG_HIGH_ON) THEN
4133                Debug_Log('delete_resp_mapping: l_ge_ptnr_resps_rec.partner_id = ' || l_ge_ptnr_resps_rec.partner_id);
4134                Debug_Log('delete_resp_mapping: l_ge_ptnr_resps_rec.user_role_code = ' || l_ge_ptnr_resps_rec.user_role_code);
4135                Debug_Log('delete_resp_mapping: l_ge_ptnr_resps_rec.responsibility_id = ' || l_ge_ptnr_resps_rec.responsibility_id);
4136                Debug_Log('delete_resp_mapping: l_ge_ptnr_resps_rec.program_id = ' || l_ge_ptnr_resps_rec.program_id);
4137                Debug_Log('delete_resp_mapping: l_ge_ptnr_resps_rec.source_resp_map_rule_id = ' || l_ge_ptnr_resps_rec.source_resp_map_rule_id);
4138                Debug_Log('delete_resp_mapping: l_ge_ptnr_resps_rec.resp_type_code = ' || l_ge_ptnr_resps_rec.resp_type_code);
4139             END IF;
4140 
4141             PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps(
4142                 p_api_version_number         => p_api_version_number
4143                ,p_init_msg_list              => FND_API.G_FALSE
4144                ,p_commit                     => FND_API.G_FALSE
4145                ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
4146 
4147                ,x_return_status              => x_return_status
4148                ,x_msg_count                  => x_msg_count
4149                ,x_msg_data                   => x_msg_data
4150                ,p_ge_ptnr_resps_rec          => l_ge_ptnr_resps_rec
4151                ,x_ptnr_resp_id               => l_ptnr_resp_id
4152             );
4153 
4154             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4155                RAISE FND_API.G_EXC_ERROR;
4156             END IF;
4157          END IF; -- End of IF (l_responsibility_id is null) or (l_resp_map_rule_id is null)
4158 
4159       ELSIF x.program_id IS NULL THEN
4160          IF (PV_DEBUG_HIGH_ON) THEN
4161             Debug_Log('delete_resp_mapping: x.program_id is null');
4162             Debug_Log('delete_resp_mapping: x.responsibility_id = ' || x.responsibility_id);
4163          END IF;
4164          revoke_resp(
4165              p_api_version_number         => p_api_version_number
4166             ,p_init_msg_list              => FND_API.G_FALSE
4167             ,p_commit                     => FND_API.G_FALSE
4168             ,p_user_id                    => l_user_ids_tbl
4169             ,p_resp_id                    => x.responsibility_id
4170             ,x_return_status              => x_return_status
4171             ,x_msg_count                  => x_msg_count
4172             ,x_msg_data                   => x_msg_data
4173          );
4174          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4175             RAISE FND_API.G_EXC_ERROR;
4176          END IF;
4177          /****
4178           * API to delete the row with ptnr_resp_id = x.ptnr_resp_id from pv_partner_memberships
4179           ****/
4180          IF (PV_DEBUG_HIGH_ON) THEN
4181             Debug_Log('delete_resp_mapping: before calling PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps');
4182             Debug_Log('delete_resp_mapping: x.ptnr_resp_id = ' || x.ptnr_resp_id);
4183          END IF;
4184 
4185          PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps(
4186              p_api_version_number         => p_api_version_number
4187             ,p_init_msg_list              => FND_API.G_FALSE
4188             ,p_commit                     => p_commit
4189             ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
4190 
4191             ,x_return_status              => x_return_status
4192             ,x_msg_count                  => x_msg_count
4193             ,x_msg_data                   => x_msg_data
4194             ,p_ptnr_resp_id               => x.ptnr_resp_id
4195             ,p_object_version_number      => x.object_version_number
4196          );
4197 
4198          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4199             RAISE FND_API.G_EXC_ERROR;
4200          END IF;
4201 
4202          IF (PV_DEBUG_HIGH_ON) THEN
4203             Debug_Log('delete_resp_mapping: before calling get_default_assign_addrow');
4204          END IF;
4205          -- Get the new default resp, assign it to the users, and add a new
4206          -- row into pv_ge_ptnr_resps
4207          get_default_assign_addrow(
4208              p_api_version_number         => p_api_version_number
4209             ,p_init_msg_list              => FND_API.G_FALSE
4210             ,p_commit                     => FND_API.G_FALSE
4211             ,x_return_status              => x_return_status
4212             ,x_msg_count                  => x_msg_count
4213             ,x_msg_data                   => x_msg_data
4214             ,p_user_role_code             => x.user_role_code
4215             ,p_user_ids_tbl               => l_user_ids_tbl
4216             ,p_partner_id                 => x.partner_id
4217          );
4218          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4219             RAISE FND_API.G_EXC_ERROR;
4220          END IF;
4221       END IF; -- End of IF program_id IS NOT NULL
4222    END LOOP;
4223    -- Check for commit
4224    IF FND_API.to_boolean(p_commit) THEN
4225       COMMIT;
4226    END IF;
4227 
4228    FND_MSG_PUB.count_and_get(
4229       p_encoded => FND_API.g_false
4230      ,p_count   => x_msg_count
4231      ,p_data    => x_msg_data
4232    );
4233 
4234 EXCEPTION
4235 
4236    WHEN PVX_Utility_PVT.resource_locked THEN
4237      x_return_status := FND_API.g_ret_sts_error;
4238          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
4239 
4240    WHEN FND_API.G_EXC_ERROR THEN
4241      ROLLBACK TO delete_resp_mapping;
4242      x_return_status := FND_API.G_RET_STS_ERROR;
4243      -- Standard call to get message count and if count=1, get the message
4244      FND_MSG_PUB.Count_And_Get (
4245             p_encoded => FND_API.G_FALSE,
4246             p_count   => x_msg_count,
4247             p_data    => x_msg_data
4248      );
4249 
4250    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4251      ROLLBACK TO delete_resp_mapping;
4252      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4253      -- Standard call to get message count and if count=1, get the message
4254      FND_MSG_PUB.Count_And_Get (
4255             p_encoded => FND_API.G_FALSE,
4256             p_count => x_msg_count,
4257             p_data  => x_msg_data
4258      );
4259 
4260    WHEN OTHERS THEN
4261      ROLLBACK TO delete_resp_mapping;
4262      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4263      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4264      THEN
4265         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
4266      END IF;
4267      -- Standard call to get message count and if count=1, get the message
4268      FND_MSG_PUB.Count_And_Get (
4269             p_encoded => FND_API.G_FALSE,
4270             p_count => x_msg_count,
4271             p_data  => x_msg_data
4272      );
4273 
4274 END delete_resp_mapping;
4275 
4276 /*
4277  * update_resp_mapping
4278  * This public API will take care of managing partner user responsibilities when
4279  * responsibility mapping is updated with a new responsibility.
4280  */
4281 PROCEDURE update_resp_mapping(
4282     p_api_version_number         IN   NUMBER
4283    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
4284    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
4285    ,x_return_status              OUT  NOCOPY  VARCHAR2
4286    ,x_msg_count                  OUT  NOCOPY  NUMBER
4287    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
4288    ,p_source_resp_map_rule_id    IN   NUMBER
4289 )
4290 IS
4291    CURSOR c_get_ptnr_resps (cv_source_resp_map_rule_id NUMBER) IS
4292       SELECT ptnr_resp_id, responsibility_id, partner_id, user_role_code, program_id, object_version_number
4293       FROM   pv_ge_ptnr_resps
4294       WHERE  source_resp_map_rule_id = cv_source_resp_map_rule_id
4295       AND    resp_type_code = G_PROGRAM
4296       ORDER BY partner_id, user_role_code;
4297 
4298    CURSOR c_get_new_resp (cv_source_resp_map_rule_id NUMBER) IS
4299       SELECT responsibility_id
4300       FROM   pv_ge_resp_map_rules
4301       WHERE  resp_map_rule_id = cv_source_resp_map_rule_id;
4302 
4303    CURSOR c_get_count (cv_partner_id NUMBER, cv_user_role_code VARCHAR2, cv_responsibility_id NUMBER) IS
4304       SELECT count(*)
4305       FROM   pv_ge_ptnr_resps
4306       WHERE  partner_id = cv_partner_id
4307       AND    user_role_code = cv_user_role_code
4308       AND    responsibility_id = cv_responsibility_id
4309       AND    resp_type_code = G_PROGRAM;
4310 
4311    l_api_name              CONSTANT  VARCHAR2(30) := 'update_resp_mapping';
4312    l_api_version_number    CONSTANT NUMBER   := 1.0;
4313    l_user_ids_tbl          JTF_NUMBER_TABLE;
4314    l_first_time_flag       VARCHAR2(1);
4315    l_count                 NUMBER;
4316    l_new_responsibility_id NUMBER;
4317    l_resp_map_rule_id      NUMBER;
4318 
4319 BEGIN
4320   ---- Initialize----------------
4321 
4322    -- Standard Start of API savepoint
4323    SAVEPOINT update_resp_mapping;
4324 
4325    -- Standard call to check for call compatibility.
4326    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
4327                                       ,p_api_version_number
4328                                       ,l_api_name
4329                                       ,G_PKG_NAME
4330                                       )
4331    THEN
4332        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
4333    END IF;
4334 
4335    -- Initialize message list if p_init_msg_list is set to TRUE.
4336    IF Fnd_Api.to_Boolean( p_init_msg_list )
4337    THEN
4338       Fnd_Msg_Pub.initialize;
4339    END IF;
4340 
4341    -- Debug Message
4342    IF (PV_DEBUG_HIGH_ON) THEN
4343       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
4344    END IF;
4345 
4346    -- Initialize API return status to SUCCESS
4347    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4348 
4349    FOR x IN c_get_new_resp(p_source_resp_map_rule_id) LOOP
4350       IF (PV_DEBUG_HIGH_ON) THEN
4351          Debug_Log('update_resp_mapping: new x.responsibility_id = ' || x.responsibility_id);
4352       END IF;
4353       l_new_responsibility_id := x.responsibility_id;
4354    END LOOP;
4355 
4356    FOR x IN c_get_ptnr_resps (p_source_resp_map_rule_id) LOOP
4357       IF (PV_DEBUG_HIGH_ON) THEN
4358          Debug_Log('update_resp_mapping: x.responsibility_id = ' || x.responsibility_id);
4359          Debug_Log('update_resp_mapping: x.program_id = ' || x.program_id);
4360       END IF;
4361 
4362       l_user_ids_tbl := get_partner_users(x.partner_id, x.user_role_code);
4363 
4364       IF x.program_id IS NOT NULL THEN
4365          IF (PV_DEBUG_HIGH_ON) THEN
4366             Debug_Log('update_resp_mapping: x.program_id is not null');
4367          END IF;
4368          OPEN c_get_count(x.partner_id, x.user_role_code, x.responsibility_id);
4369          FETCH c_get_count into l_count;
4370          CLOSE c_get_count;
4371          -- If there is only this (partner_id, user_role_code, responsibility_id) combo,
4372          -- call revoke_update_assign with p_is_revoke = 'Y'
4373          -- Otherwise, call revoke_update_assign with p_is_revoke = 'N'
4374          IF l_count = 1 THEN
4375             -- Rovoke the responsibility for all partner users.
4376             -- Update the corresponding row in pv_ge_ptnr_resps.
4377             -- Assign the new responsibility for all partner users.
4378             IF (PV_DEBUG_HIGH_ON) THEN
4379                Debug_Log('update_resp_mapping: before calling revoke_update_assign');
4380             END IF;
4381             revoke_update_assign(
4382                 p_api_version_number         => p_api_version_number
4383                ,p_init_msg_list              => FND_API.G_FALSE
4384                ,p_commit                     => FND_API.G_FALSE
4385                ,x_return_status              => x_return_status
4386                ,x_msg_count                  => x_msg_count
4387                ,x_msg_data                   => x_msg_data
4388                ,p_user_ids_tbl               => l_user_ids_tbl
4389                ,p_ptnr_resp_id               => x.ptnr_resp_id
4390                ,p_old_responsibility_id      => x.responsibility_id
4391                ,p_new_responsibility_id      => l_new_responsibility_id
4392                ,p_object_version_number      => x.object_version_number
4393                ,p_is_revoke                  => 'Y'
4394             );
4395             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4396                RAISE FND_API.G_EXC_ERROR;
4397             END IF;
4398             IF (PV_DEBUG_HIGH_ON) THEN
4399                Debug_Log('update_resp_mapping: after calling revoke_update_assign');
4400             END IF;
4401 
4402          ELSE
4403             -- Update the corresponding row in pv_ge_ptnr_resps.
4404             -- Assign the new responsibility for all partner users.
4405             IF (PV_DEBUG_HIGH_ON) THEN
4406                Debug_Log('update_resp_mapping: before calling revoke_update_assign');
4407             END IF;
4408            revoke_update_assign(
4409                 p_api_version_number         => p_api_version_number
4410                ,p_init_msg_list              => FND_API.G_FALSE
4411                ,p_commit                     => FND_API.G_FALSE
4412                ,x_return_status              => x_return_status
4413                ,x_msg_count                  => x_msg_count
4414                ,x_msg_data                   => x_msg_data
4415                ,p_user_ids_tbl               => l_user_ids_tbl
4416                ,p_ptnr_resp_id               => x.ptnr_resp_id
4417                ,p_old_responsibility_id      => x.responsibility_id
4418                ,p_new_responsibility_id      => l_new_responsibility_id
4419                ,p_object_version_number      => x.object_version_number
4420                ,p_is_revoke                  => 'N'
4421             );
4422             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4423                RAISE FND_API.G_EXC_ERROR;
4424             END IF;
4425 
4426             IF (PV_DEBUG_HIGH_ON) THEN
4427                Debug_Log('update_resp_mapping: after calling revoke_update_assign');
4428             END IF;
4429          END IF;
4430       ELSE  -- IF program_id IS NULL
4431          -- Rovoke the responsibility for all partner users.
4432          -- Update the corresponding row in pv_ge_ptnr_resps.
4433          -- Assign the new responsibility for all partner users.
4434          IF (PV_DEBUG_HIGH_ON) THEN
4435             Debug_Log('update_resp_mapping: before calling revoke_update_assign');
4436          END IF;
4437          revoke_update_assign(
4438              p_api_version_number         => p_api_version_number
4439             ,p_init_msg_list              => FND_API.G_FALSE
4440             ,p_commit                     => FND_API.G_FALSE
4441             ,x_return_status              => x_return_status
4442             ,x_msg_count                  => x_msg_count
4443             ,x_msg_data                   => x_msg_data
4444             ,p_user_ids_tbl               => l_user_ids_tbl
4445             ,p_ptnr_resp_id               => x.ptnr_resp_id
4446             ,p_old_responsibility_id      => x.responsibility_id
4447             ,p_new_responsibility_id      => l_new_responsibility_id
4448             ,p_object_version_number      => x.object_version_number
4449             ,p_is_revoke                  => 'Y'
4450          );
4451          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4452             RAISE FND_API.G_EXC_ERROR;
4453          END IF;
4454          IF (PV_DEBUG_HIGH_ON) THEN
4455             Debug_Log('update_resp_mapping: before calling revoke_update_assign');
4456          END IF;
4457       END IF; -- End of IF program_id IS NOT NULL
4458    END LOOP;
4459 
4460    -- Check for commit
4461    IF FND_API.to_boolean(p_commit) THEN
4462       COMMIT;
4463    END IF;
4464 
4465    FND_MSG_PUB.count_and_get(
4466       p_encoded => FND_API.g_false
4467      ,p_count   => x_msg_count
4468      ,p_data    => x_msg_data
4469    );
4470 
4471 EXCEPTION
4472 
4473    WHEN PVX_Utility_PVT.resource_locked THEN
4474      x_return_status := FND_API.g_ret_sts_error;
4475          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
4476 
4477    WHEN FND_API.G_EXC_ERROR THEN
4478      ROLLBACK TO update_resp_mapping;
4479      x_return_status := FND_API.G_RET_STS_ERROR;
4480      -- Standard call to get message count and if count=1, get the message
4481      FND_MSG_PUB.Count_And_Get (
4482             p_encoded => FND_API.G_FALSE,
4483             p_count   => x_msg_count,
4484             p_data    => x_msg_data
4485      );
4486 
4487    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4488      ROLLBACK TO update_resp_mapping;
4489      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4490      -- Standard call to get message count and if count=1, get the message
4491      FND_MSG_PUB.Count_And_Get (
4492             p_encoded => FND_API.G_FALSE,
4493             p_count => x_msg_count,
4494             p_data  => x_msg_data
4495      );
4496 
4497    WHEN OTHERS THEN
4498      ROLLBACK TO update_resp_mapping;
4499      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4500      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4501      THEN
4502         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
4503      END IF;
4504      -- Standard call to get message count and if count=1, get the message
4505      FND_MSG_PUB.Count_And_Get (
4506             p_encoded => FND_API.G_FALSE,
4507             p_count => x_msg_count,
4508             p_data  => x_msg_data
4509      );
4510 
4511 END update_resp_mapping;
4512 
4513 /*
4514  * create_resp_mapping
4515  * This public API will take care of managing partner user responsibilities when
4516  * responsibility mapping is created.
4517  */
4518 PROCEDURE create_resp_mapping(
4519     p_api_version_number         IN   NUMBER
4520    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
4521    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
4522    ,x_return_status              OUT  NOCOPY  VARCHAR2
4523    ,x_msg_count                  OUT  NOCOPY  NUMBER
4524    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
4525    ,p_source_resp_map_rule_id    IN   NUMBER
4526 )
4527 IS
4528    CURSOR c_get_resp_info_1 (cv_source_resp_map_rule_id NUMBER) IS
4529       SELECT m.partner_id, mr.user_role_code, mr.program_id
4530       FROM   pv_pg_memberships m, pv_ge_resp_map_rules mr
4531       WHERE  mr.program_id = m.program_id
4532       AND    m.membership_status_code = 'ACTIVE'
4533       AND    mr.resp_map_rule_id = cv_source_resp_map_rule_id;
4534 
4535    CURSOR c_get_resp_info_2 (cv_source_resp_map_rule_id NUMBER) IS
4536       SELECT user_role_code
4537       FROM   pv_ge_resp_map_rules mr
4538       WHERE  program_id is null
4539       AND    resp_map_rule_id = cv_source_resp_map_rule_id;
4540 
4541    CURSOR c_get_ptnr_resps_1 (cv_partner_id NUMBER, cv_user_role_code VARCHAR2, cv_program_id NUMBER) IS
4542       SELECT ptnr_resp_id, program_id, responsibility_id, source_resp_map_rule_id, object_version_number
4543       FROM   pv_ge_ptnr_resps
4544       WHERE  partner_id = cv_partner_id
4545       AND    user_role_code = cv_user_role_code
4546       AND    program_id = cv_program_id
4547       AND    resp_type_code = G_PROGRAM;
4548 
4549    CURSOR c_get_defalut_resp (cv_partner_id NUMBER, cv_user_role_code VARCHAR2, cv_program_id NUMBER) IS
4550       SELECT ptnr_resp_id, responsibility_id, object_version_number
4551       FROM   pv_ge_ptnr_resps
4552       WHERE  partner_id = cv_partner_id
4553       AND    user_role_code = cv_user_role_code
4554       AND    program_id is null
4555       AND    resp_type_code = G_PROGRAM;
4556 
4557    CURSOR c_get_ptnr_resps_2 (cv_user_role_code VARCHAR2) IS
4558       SELECT ptnr_resp_id, responsibility_id, source_resp_map_rule_id, object_version_number, partner_id
4559       FROM   pv_ge_ptnr_resps
4560       WHERE  user_role_code = cv_user_role_code
4561       AND    program_id is null
4562       AND    resp_type_code = G_PROGRAM;
4563 
4564    CURSOR c_get_count (cv_partner_id NUMBER, cv_user_role_code VARCHAR2, cv_responsibility_id NUMBER) IS
4565       SELECT count(*)
4566       FROM   pv_ge_ptnr_resps
4567       WHERE  partner_id = cv_partner_id
4568       AND    user_role_code = cv_user_role_code
4569       AND    responsibility_id = cv_responsibility_id
4570       AND    resp_type_code = G_PROGRAM;
4571 
4572    l_api_name              CONSTANT  VARCHAR2(30) := 'create_resp_mapping';
4573    l_api_version_number    CONSTANT NUMBER   := 1.0;
4574    l_user_ids_tbl          JTF_NUMBER_TABLE;
4575    l_first_time_flag       VARCHAR2(1);
4576    l_count                 NUMBER;
4577    l_new_responsibility_id NUMBER;
4578    l_resp_map_rule_id      NUMBER;
4579    l_same_comb             boolean;
4580    l_exist                 NUMBER;
4581    l_ge_ptnr_resps_rec     PV_Ge_Ptnr_Resps_PVT.ge_ptnr_resps_rec_type;
4582    l_ptnr_resp_id          NUMBER;
4583 BEGIN
4584   ---- Initialize----------------
4585 
4586    -- Standard Start of API savepoint
4587    SAVEPOINT create_resp_mapping;
4588 
4589    -- Standard call to check for call compatibility.
4590    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
4591                                       ,p_api_version_number
4592                                       ,l_api_name
4593                                       ,G_PKG_NAME
4594                                       )
4595    THEN
4596        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
4597    END IF;
4598 
4599    -- Initialize message list if p_init_msg_list is set to TRUE.
4600    IF Fnd_Api.to_Boolean( p_init_msg_list )
4601    THEN
4602       Fnd_Msg_Pub.initialize;
4603    END IF;
4604 
4605    -- Debug Message
4606    IF (PV_DEBUG_HIGH_ON) THEN
4607       Debug_Log('PRIVATE API: ' || l_api_name || ' - START...');
4608    END IF;
4609 
4610    -- Initialize API return status to SUCCESS
4611    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4612 
4613    FOR x IN c_get_resp_info_1 (p_source_resp_map_rule_id) LOOP
4614       IF (PV_DEBUG_HIGH_ON) THEN
4615          Debug_Log('create_resp_mapping: x.partner_id = ' || x.partner_id);
4616          Debug_Log('create_resp_mapping: x.user_role_code = ' ||x.user_role_code);
4617       END IF;
4618 
4619       l_user_ids_tbl := get_partner_users(x.partner_id, x.user_role_code);
4620 
4621       --IF x.program_id IS NOT NULL THEN
4622       IF (PV_DEBUG_HIGH_ON) THEN
4623          Debug_Log('create_resp_mapping: x.program_id is not null');
4624          Debug_Log('create_resp_mapping: before calling get_program_resp');
4625       END IF;
4626       get_program_resp(
4627           p_api_version_number         => p_api_version_number
4628          ,p_init_msg_list              => FND_API.G_FALSE
4629          ,p_commit                     => FND_API.G_FALSE
4630          ,x_return_status              => x_return_status
4631          ,x_msg_count                  => x_msg_count
4632          ,x_msg_data                   => x_msg_data
4633          ,p_partner_id                 => x.partner_id
4634          ,p_user_role_code             => x.user_role_code
4635          ,p_program_id                 => x.program_id
4636          ,x_responsibility_id          => l_new_responsibility_id
4637          ,x_resp_map_rule_id           => l_resp_map_rule_id
4638       );
4639       IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4640          RAISE FND_API.G_EXC_ERROR;
4641       END IF;
4642       IF (PV_DEBUG_HIGH_ON) THEN
4643          Debug_Log('create_resp_mapping: after calling get_program_resp');
4644          Debug_Log('create_resp_mapping: l_new_responsibility_id = ' || l_new_responsibility_id);
4645          Debug_Log('create_resp_mapping: l_resp_map_rule_id = ' || l_resp_map_rule_id);
4646       END IF;
4647       l_same_comb := false;
4648       FOR y in c_get_ptnr_resps_1(x.partner_id, x.user_role_code, x.program_id) LOOP
4649          l_same_comb :=  true;
4650          IF (PV_DEBUG_HIGH_ON) THEN
4651             Debug_Log('create_resp_mapping: y.ptnr_resp_id = ' || y.ptnr_resp_id);
4652             Debug_Log('create_resp_mapping: y.responsibility_id = ' || y.responsibility_id);
4653          END IF;
4654          IF (y.responsibility_id <> l_new_responsibility_id) THEN
4655             OPEN c_get_count(x.partner_id, x.user_role_code, y.responsibility_id);
4656             FETCH c_get_count into l_count;
4657             CLOSE c_get_count;
4658             -- If there is only this (partner_id, user_role_code, responsibility_id) combo,
4659             -- call revoke_update_assign with p_is_revoke = 'Y'
4660             -- Otherwise, call revoke_update_assign with p_is_revoke = 'N'
4661             IF l_count = 1 THEN
4662                IF (PV_DEBUG_HIGH_ON) THEN
4663                   Debug_Log('create_resp_mapping: l_count = 1');
4664                   Debug_Log('create_resp_mapping: before calling revoke_update_assign');
4665                END IF;
4666                -- Rovoke the responsibility for all partner users.
4667                -- Update the corresponding row in pv_ge_ptnr_resps.
4668                -- Assign the new responsibility for all partner users.
4669                revoke_update_assign(
4670                    p_api_version_number         => p_api_version_number
4671                   ,p_init_msg_list              => FND_API.G_FALSE
4672                   ,p_commit                     => FND_API.G_FALSE
4673                   ,x_return_status              => x_return_status
4674                   ,x_msg_count                  => x_msg_count
4675                   ,x_msg_data                   => x_msg_data
4676                   ,p_user_ids_tbl               => l_user_ids_tbl
4677                   ,p_ptnr_resp_id               => y.ptnr_resp_id
4678                   ,p_old_responsibility_id      => y.responsibility_id
4679                   ,p_new_responsibility_id      => l_new_responsibility_id
4680                   ,p_resp_map_rule_id           => l_resp_map_rule_id
4681                   ,p_object_version_number      => y.object_version_number
4682                   ,p_is_revoke                  => 'Y'
4683                );
4684                IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4685                   RAISE FND_API.G_EXC_ERROR;
4686                END IF;
4687             ELSE
4688                IF (PV_DEBUG_HIGH_ON) THEN
4689                   Debug_Log('create_resp_mapping: else');
4690                   Debug_Log('create_resp_mapping: before calling revoke_update_assign');
4691                END IF;
4692 
4693                -- Update the corresponding row in pv_ge_ptnr_resps.
4694                -- Assign the new responsibility for all partner users.
4695                revoke_update_assign(
4696                    p_api_version_number         => p_api_version_number
4697                   ,p_init_msg_list              => FND_API.G_FALSE
4698                   ,p_commit                     => FND_API.G_FALSE
4699                   ,x_return_status              => x_return_status
4700                   ,x_msg_count                  => x_msg_count
4701                   ,x_msg_data                   => x_msg_data
4702                   ,p_user_ids_tbl               => l_user_ids_tbl
4703                   ,p_ptnr_resp_id               => y.ptnr_resp_id
4704                   ,p_old_responsibility_id      => y.responsibility_id
4705                   ,p_new_responsibility_id      => l_new_responsibility_id
4706                   ,p_object_version_number      => y.object_version_number
4707                   ,p_is_revoke                  => 'N'
4708                );
4709                IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4710                   RAISE FND_API.G_EXC_ERROR;
4711                END IF;
4712             END IF; -- End of IF l_count = 1
4713          END IF; -- End of IF (y.responsibility <> l_new_responsibility_id)
4714       END LOOP; -- End of FOR y in c_get_ptnr_resps_1(x.partner_id, x.user_role_code, x.program_id)
4715 
4716       IF (not l_same_comb) THEN
4717          IF (PV_DEBUG_HIGH_ON) THEN
4718             Debug_Log('create_resp_mapping: not l_same_comb');
4719          END IF;
4720          FOR y IN c_get_defalut_resp (x.partner_id, x.user_role_code, x.program_id) LOOP
4721             revoke_resp(
4722                 p_api_version_number         => p_api_version_number
4723                ,p_init_msg_list              => FND_API.G_FALSE
4724                ,p_commit                     => FND_API.G_FALSE
4725                ,p_user_id                    => l_user_ids_tbl
4726                ,p_resp_id                    => y.responsibility_id
4727                ,x_return_status              => x_return_status
4728                ,x_msg_count                  => x_msg_count
4729                ,x_msg_data                   => x_msg_data
4730             );
4731             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4732                RAISE FND_API.G_EXC_ERROR;
4733             END IF;
4734            /****
4735              * API to delete the row with ptnr_resp_id = x.ptnr_resp_id from pv_partner_memberships
4736              ****/
4737             IF (PV_DEBUG_HIGH_ON) THEN
4738                Debug_Log('create_resp_mapping: before calling PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps');
4739                Debug_Log('create_resp_mapping: y.ptnr_resp_id = ' || y.ptnr_resp_id);
4740                Debug_Log('create_resp_mapping: y.object_version_number = ' || y.object_version_number);
4741            END IF;
4742 
4743            PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps(
4744                 p_api_version_number         => p_api_version_number
4745                ,p_init_msg_list              => FND_API.G_FALSE
4746                ,p_commit                     => FND_API.G_FALSE
4747                ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
4748 
4749                ,x_return_status              => x_return_status
4750                ,x_msg_count                  => x_msg_count
4751                ,x_msg_data                   => x_msg_data
4752                ,p_ptnr_resp_id               => y.ptnr_resp_id
4753                ,p_object_version_number      => y.object_version_number
4754             );
4755             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4756                RAISE FND_API.G_EXC_ERROR;
4757             END IF;
4758          END LOOP; -- End of FOR y IN c_get_defalut_resp (x.partner_id, x.user_role_code, x.program_id)
4759 
4760          FOR l_u_cnt IN 1..l_user_ids_tbl.count LOOP
4761             assign_resp (
4762                 p_api_version_number         => p_api_version_number
4763                ,p_init_msg_list              => FND_API.G_FALSE
4764                ,p_commit                     => FND_API.G_FALSE
4765                ,p_user_id                    => l_user_ids_tbl(l_u_cnt)
4766                ,p_resp_id                    => l_new_responsibility_id
4767                ,p_app_id                     => 691
4768                ,x_return_status              => x_return_status
4769                ,x_msg_count                  => x_msg_count
4770                ,x_msg_data                   => x_msg_data
4771             );
4772             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4773                RAISE FND_API.G_EXC_ERROR;
4774             END IF;
4775          END LOOP; -- End of l_l_user_ids_tbl
4776 
4777          /****
4778           * API to add a row to pv_ge_ptnr_resps
4779           ****/
4780          l_ge_ptnr_resps_rec.partner_id := x.partner_id;
4781          l_ge_ptnr_resps_rec.user_role_code := x.user_role_code;
4782          l_ge_ptnr_resps_rec.program_id := x.program_id;
4783          l_ge_ptnr_resps_rec.responsibility_id := l_new_responsibility_id;
4784          l_ge_ptnr_resps_rec.source_resp_map_rule_id := l_resp_map_rule_id;
4785          l_ge_ptnr_resps_rec.resp_type_code := G_PROGRAM;
4786 
4787          IF (PV_DEBUG_HIGH_ON) THEN
4788             Debug_Log('create_resp_mapping: l_ge_ptnr_resps_rec.partner_id = ' || l_ge_ptnr_resps_rec.partner_id);
4789             Debug_Log('create_resp_mapping: l_ge_ptnr_resps_rec.user_role_code = ' || l_ge_ptnr_resps_rec.user_role_code);
4790             Debug_Log('create_resp_mapping: l_ge_ptnr_resps_rec.program_id = ' || l_ge_ptnr_resps_rec.program_id);
4791             Debug_Log('create_resp_mapping: l_ge_ptnr_resps_rec.responsibility_id = ' || l_ge_ptnr_resps_rec.responsibility_id);
4792             Debug_Log('create_resp_mapping: l_ge_ptnr_resps_rec.source_resp_map_rule_id = ' || l_ge_ptnr_resps_rec.source_resp_map_rule_id);
4793             Debug_Log('create_resp_mapping: l_ge_ptnr_resps_rec.resp_type_code = ' || l_ge_ptnr_resps_rec.resp_type_code);
4794          END IF;
4795 
4796          PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps(
4797              p_api_version_number         => p_api_version_number
4798             ,p_init_msg_list              => FND_API.G_FALSE
4799             ,p_commit                     => FND_API.G_FALSE
4800             ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
4801 
4802             ,x_return_status              => x_return_status
4803             ,x_msg_count                  => x_msg_count
4804             ,x_msg_data                   => x_msg_data
4805             ,p_ge_ptnr_resps_rec          => l_ge_ptnr_resps_rec
4806             ,x_ptnr_resp_id               => l_ptnr_resp_id
4807          );
4808 
4809          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4810             RAISE FND_API.G_EXC_ERROR;
4811          END IF;
4812       END IF; -- End of IF (not l_same_comb)
4813    END LOOP; -- End of FOR x IN c_get_resp_info_1 (p_source_resp_map_rule_id)
4814          Debug_Log('create_resp_mapping: program_id is null');
4815 
4816    FOR x IN c_get_resp_info_2 (p_source_resp_map_rule_id) LOOP
4817       IF (PV_DEBUG_HIGH_ON) THEN
4818          Debug_Log('create_resp_mapping: program_id is null');
4819       END IF;
4820 
4821       FOR y IN c_get_ptnr_resps_2 (x.user_role_code) LOOP
4822          IF (PV_DEBUG_HIGH_ON) THEN
4823             Debug_Log('create_resp_mapping: before calling get_default_resp');
4824          END IF;
4825          get_default_resp(
4826              p_api_version_number         => p_api_version_number
4827             ,p_init_msg_list              => FND_API.G_FALSE
4828             ,p_commit                     => FND_API.G_FALSE
4829             ,x_return_status              => x_return_status
4830             ,x_msg_count                  => x_msg_count
4831             ,x_msg_data                   => x_msg_data
4832             ,p_partner_id                 => y.partner_id
4833             ,p_user_role_code             => x.user_role_code
4834             ,x_responsibility_id          => l_new_responsibility_id
4835             ,x_resp_map_rule_id           => l_resp_map_rule_id
4836          );
4837          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4838             RAISE FND_API.G_EXC_ERROR;
4839          END IF;
4840 
4841          IF l_resp_map_rule_id <> y.source_resp_map_rule_id THEN
4842             -- Rovoke the responsibility for all partner users.
4843             -- Update the corresponding row in pv_ge_ptnr_resps.
4844             -- Assign the new responsibility for all partner users.
4845             IF (PV_DEBUG_HIGH_ON) THEN
4846                Debug_Log('create_resp_mapping: l_resp_map_rule_id <> y.source_resp_map_rule_id');
4847                Debug_Log('create_resp_mapping: before calling revoke_update_assign');
4848             END IF;
4849 
4850             -- Call get_partner_users for each partner_id
4851             l_user_ids_tbl := get_partner_users(y.partner_id, x.user_role_code);
4852             revoke_update_assign(
4853                 p_api_version_number         => p_api_version_number
4854                ,p_init_msg_list              => FND_API.G_FALSE
4855                ,p_commit                     => FND_API.G_FALSE
4856                ,x_return_status              => x_return_status
4857                ,x_msg_count                  => x_msg_count
4858                ,x_msg_data                   => x_msg_data
4859                ,p_user_ids_tbl               => l_user_ids_tbl
4860                ,p_ptnr_resp_id               => y.ptnr_resp_id
4861                ,p_old_responsibility_id      => y.responsibility_id
4862                ,p_new_responsibility_id      => l_new_responsibility_id
4863                ,p_resp_map_rule_id           => l_resp_map_rule_id
4864                ,p_object_version_number      => y.object_version_number
4865                ,p_is_revoke                  => 'Y'
4866             );
4867             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
4868                RAISE FND_API.G_EXC_ERROR;
4869             END IF;
4870          END IF; -- End of IF l_resp_map_rule_id <> y.source_resp_map_rule_id
4871       END LOOP; -- End of FOR y IN c_get_ptnr_resps_2
4872    END LOOP; -- End of FOR x IN c_get_resp_info_2 (p_source_resp_map_rule_id)
4873 
4874    -- Check for commit
4875    IF FND_API.to_boolean(p_commit) THEN
4876       COMMIT;
4877    END IF;
4878 
4879    FND_MSG_PUB.count_and_get(
4880       p_encoded => FND_API.g_false
4881      ,p_count   => x_msg_count
4882      ,p_data    => x_msg_data
4883    );
4884 
4885 EXCEPTION
4886 
4887    WHEN PVX_Utility_PVT.resource_locked THEN
4888      x_return_status := FND_API.g_ret_sts_error;
4889          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
4890 
4891    WHEN FND_API.G_EXC_ERROR THEN
4892      ROLLBACK TO create_resp_mapping;
4893      x_return_status := FND_API.G_RET_STS_ERROR;
4894      -- Standard call to get message count and if count=1, get the message
4895      FND_MSG_PUB.Count_And_Get (
4896             p_encoded => FND_API.G_FALSE,
4897             p_count   => x_msg_count,
4898             p_data    => x_msg_data
4899      );
4900 
4901    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4902      ROLLBACK TO create_resp_mapping;
4903      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4904      -- Standard call to get message count and if count=1, get the message
4905      FND_MSG_PUB.Count_And_Get (
4906             p_encoded => FND_API.G_FALSE,
4907             p_count => x_msg_count,
4908             p_data  => x_msg_data
4909      );
4910 
4911    WHEN OTHERS THEN
4912      ROLLBACK TO create_resp_mapping;
4913      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4914      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
4915      THEN
4916         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
4917      END IF;
4918      -- Standard call to get message count and if count=1, get the message
4919      FND_MSG_PUB.Count_And_Get (
4920             p_encoded => FND_API.G_FALSE,
4921             p_count => x_msg_count,
4922             p_data  => x_msg_data
4923      );
4924 
4925 END create_resp_mapping;
4926 
4927 /*
4928  * revoke_uer_resps
4929  * This public API will take care of revoking all PRM responsibilities and store
4930  * responsibilities that are assigned upon partner enrollment into a program
4931  */
4932 PROCEDURE revoke_user_resps(
4933     p_api_version_number         IN   NUMBER
4934    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
4935    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
4936    ,x_return_status              OUT  NOCOPY  VARCHAR2
4937    ,x_msg_count                  OUT  NOCOPY  NUMBER
4938    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
4939    ,p_user_id                    IN   NUMBER
4940    ,p_user_role_code             IN   VARCHAR2
4941 )
4942 IS
4943    -- Fixed for bug 3766776
4944    CURSOR c_get_resp_info (cv_partner_id JTF_NUMBER_TABLE)  IS
4945       SELECT /*+ LEADING(T) USE_NL (T P F) */
4946              p.responsibility_id, f.responsibility_application_id, f.security_group_id,
4947              f.start_date, f.description, f.user_id
4948       FROM   pv_ge_ptnr_resps p,
4949              (SELECT column_value FROM TABLE (CAST(cv_partner_id AS JTF_NUMBER_TABLE))) t ,
4950              fnd_user_resp_groups f
4951       WHERE  p.partner_id = t.column_value
4952       AND    nvl(end_date, sysdate) >= sysdate
4953       AND    f.user_id = p_user_id
4954       AND    f.responsibility_id = p.responsibility_id
4955       AND    user_role_code in (p_user_role_code, G_ALL);
4956 
4957    -- Fixed for bug 3766776
4958    CURSOR c_get_user_resp_groups (cv_responsibility_id_tbl JTF_NUMBER_TABLE) IS
4959       SELECT
4960              user_id, responsibility_id, responsibility_application_id, security_group_id,
4961              start_date, description
4962       FROM   fnd_user_resp_groups,
4963              (SELECT column_value FROM TABLE (CAST(cv_responsibility_id_tbl AS JTF_NUMBER_TABLE))) t
4964       WHERE  responsibility_id = t.column_value
4965       AND    user_id = p_user_id;
4966 
4967    l_api_name              CONSTANT  VARCHAR2(30) := 'revoke_user_resps';
4968    l_api_version_number    CONSTANT NUMBER   := 1.0;
4969    primary_user_ids_tbl    JTF_NUMBER_TABLE;
4970    business_user_ids_tbl   JTF_NUMBER_TABLE;
4971    l_responsibility_id_tbl JTF_NUMBER_TABLE;
4972    l_partner_ids_tbl       JTF_NUMBER_TABLE;
4973 
4974 BEGIN
4975   ---- Initialize----------------
4976 
4977    -- Standard Start of API savepoint
4978    SAVEPOINT revoke_user_resps;
4979 
4980    -- Standard call to check for call compatibility.
4981    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
4982                                       ,p_api_version_number
4983                                       ,l_api_name
4984                                       ,G_PKG_NAME
4985                                       )
4986    THEN
4987        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
4988    END IF;
4989 
4990    -- Initialize message list if p_init_msg_list is set to TRUE.
4991    IF Fnd_Api.to_Boolean( p_init_msg_list )
4992    THEN
4993       Fnd_Msg_Pub.initialize;
4994    END IF;
4995 
4996    -- Debug Message
4997    IF (PV_DEBUG_HIGH_ON) THEN
4998       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
4999    END IF;
5000 
5001    -- Initialize API return status to SUCCESS
5002    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
5003 
5004    l_partner_ids_tbl := get_partners(p_user_id);
5005 
5006    IF (l_partner_ids_tbl.count = 0) THEN
5007        FND_MESSAGE.set_name('PV', 'PV_INVALID_PTNR_USER');
5008        FND_MSG_PUB.add;
5009        RAISE FND_API.G_EXC_ERROR;
5010    END IF;
5011 
5012    -- Get the program and store responsibility_id
5013    FOR x IN c_get_resp_info (l_partner_ids_tbl)  LOOP
5014       IF (PV_DEBUG_HIGH_ON) THEN
5015          Debug_Log('revoke_user_resps: x.responsibility_id = ' || x.responsibility_id);
5016          Debug_Log('revoke_user_resps: x.user_id = ' || x.user_id);
5017          Debug_Log('revoke_user_resps: x.responsibility_application_id = ' || x.responsibility_application_id);
5018          Debug_Log('revoke_user_resps: x.security_group_id = ' || x.security_group_id);
5019          Debug_Log('revoke_user_resps: x.start_date = ' || x.start_date);
5020          Debug_Log('revoke_user_resps: x.description = ' || x.description);
5021       END IF;
5022 
5023       revoke_resp(
5024           p_api_version_number         => p_api_version_number
5025          ,p_init_msg_list              => FND_API.G_FALSE
5026          ,p_commit                     => FND_API.G_FALSE
5027          ,p_user_id                    => x.user_id
5028          ,p_resp_id                    => x.responsibility_id
5029          ,p_app_id                     => x.responsibility_application_id
5030          ,p_security_group_id          => x.security_group_id
5031          ,p_start_date                 => x.start_date
5032          ,p_description                => x.description
5033          ,x_return_status              => x_return_status
5034          ,x_msg_count                  => x_msg_count
5035          ,x_msg_data                   => x_msg_data
5036       );
5037       IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
5038          RAISE FND_API.G_EXC_ERROR;
5039       END IF;
5040    END LOOP;
5041 
5042    -- Check for commit
5043    IF FND_API.to_boolean(p_commit) THEN
5044       COMMIT;
5045    END IF;
5046 
5047    FND_MSG_PUB.count_and_get(
5048       p_encoded => FND_API.g_false
5049      ,p_count   => x_msg_count
5050      ,p_data    => x_msg_data
5051    );
5052 
5053 EXCEPTION
5054 
5055    WHEN PVX_Utility_PVT.resource_locked THEN
5056      x_return_status := FND_API.g_ret_sts_error;
5057          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
5058 
5059    WHEN FND_API.G_EXC_ERROR THEN
5060      ROLLBACK TO revoke_user_resps;
5061      x_return_status := FND_API.G_RET_STS_ERROR;
5062      -- Standard call to get message count and if count=1, get the message
5063      FND_MSG_PUB.Count_And_Get (
5064             p_encoded => FND_API.G_FALSE,
5065             p_count   => x_msg_count,
5066             p_data    => x_msg_data
5067      );
5068 
5069    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5070      ROLLBACK TO revoke_user_resps;
5071      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5072      -- Standard call to get message count and if count=1, get the message
5073      FND_MSG_PUB.Count_And_Get (
5074             p_encoded => FND_API.G_FALSE,
5075             p_count => x_msg_count,
5076             p_data  => x_msg_data
5077      );
5078 
5079    WHEN OTHERS THEN
5080      ROLLBACK TO revoke_user_resps;
5081      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5082      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5083      THEN
5084         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
5085      END IF;
5086      -- Standard call to get message count and if count=1, get the message
5087      FND_MSG_PUB.Count_And_Get (
5088             p_encoded => FND_API.G_FALSE,
5089             p_count => x_msg_count,
5090             p_data  => x_msg_data
5091      );
5092 END revoke_user_resps;
5093 
5094 
5095 /*
5096  * revoke_uer_resps
5097  * This public API will take care of revoking all PRM responsibilities and store
5098  * responsibilities that are assigned upon partner enrollment into a program
5099  */
5100 PROCEDURE revoke_user_resps(
5101     p_api_version_number         IN   NUMBER
5102    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
5103    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
5104    ,x_return_status              OUT  NOCOPY  VARCHAR2
5105    ,x_msg_count                  OUT  NOCOPY  NUMBER
5106    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
5107    ,p_user_name                  IN   VARCHAR2
5108 )
5109 IS
5110 
5111    CURSOR c_get_user_id IS
5112       select usr.user_id
5113       from   jtf_rs_resource_extns extn, fnd_user usr
5114       where  extn.user_id     = usr.user_id
5115       and    usr.user_name	   = p_user_name;
5116 
5117    l_api_name              CONSTANT  VARCHAR2(30) := 'revoke_user_resps';
5118    l_api_version_number    CONSTANT NUMBER   := 1.0;
5119    l_user_role_code        VARCHAR2(30);
5120 
5121 BEGIN
5122   ---- Initialize----------------
5123 
5124    -- Standard Start of API savepoint
5125    SAVEPOINT revoke_user_resps;
5126 
5127    -- Standard call to check for call compatibility.
5128    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
5129                                       ,p_api_version_number
5130                                       ,l_api_name
5131                                       ,G_PKG_NAME
5132                                       )
5133    THEN
5134        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
5135    END IF;
5136 
5137    -- Initialize message list if p_init_msg_list is set to TRUE.
5138    IF Fnd_Api.to_Boolean( p_init_msg_list )
5139    THEN
5140       Fnd_Msg_Pub.initialize;
5141    END IF;
5142 
5143    -- Debug Message
5144    IF (PV_DEBUG_HIGH_ON) THEN
5145       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
5146    END IF;
5147 
5148    -- Initialize API return status to SUCCESS
5149    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
5150 
5151    FOR x IN c_get_user_id LOOP
5152       get_user_role_code (
5153           p_user_id        => x.user_id
5154          ,x_user_role_code => l_user_role_code
5155       );
5156       IF (PV_DEBUG_HIGH_ON) THEN
5157          Debug_Log('revoke_user_resps: l_user_role_code = ' || l_user_role_code);
5158       END IF;
5159 
5160       revoke_user_resps(
5161          p_api_version_number         => l_api_version_number
5162         ,p_init_msg_list              => FND_API.G_FALSE
5163         ,x_return_status              => x_return_status
5164         ,x_msg_count                  => x_msg_count
5165         ,x_msg_data                   => x_msg_data
5166         ,p_user_id                    => x.user_id
5167         ,p_user_role_code             => l_user_role_code
5168       );
5169       IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
5170          RAISE FND_API.G_EXC_ERROR;
5171       END IF;
5172    END LOOP;
5173    -- Check for commit
5174    IF FND_API.to_boolean(p_commit) THEN
5175       COMMIT;
5176    END IF;
5177 
5178    FND_MSG_PUB.count_and_get(
5179       p_encoded => FND_API.g_false
5180      ,p_count   => x_msg_count
5181      ,p_data    => x_msg_data
5182    );
5183 
5184 EXCEPTION
5185 
5186    WHEN PVX_Utility_PVT.resource_locked THEN
5187      x_return_status := FND_API.g_ret_sts_error;
5188          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
5189 
5190    WHEN FND_API.G_EXC_ERROR THEN
5191      ROLLBACK TO revoke_user_resps;
5192      x_return_status := FND_API.G_RET_STS_ERROR;
5193      -- Standard call to get message count and if count=1, get the message
5194      FND_MSG_PUB.Count_And_Get (
5195             p_encoded => FND_API.G_FALSE,
5196             p_count   => x_msg_count,
5197             p_data    => x_msg_data
5198      );
5199 
5200    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5201      ROLLBACK TO revoke_user_resps;
5202      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5203      -- Standard call to get message count and if count=1, get the message
5204      FND_MSG_PUB.Count_And_Get (
5205             p_encoded => FND_API.G_FALSE,
5206             p_count => x_msg_count,
5207             p_data  => x_msg_data
5208      );
5209 
5210    WHEN OTHERS THEN
5211      ROLLBACK TO revoke_user_resps;
5212      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5213      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5214      THEN
5215         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
5216      END IF;
5217      -- Standard call to get message count and if count=1, get the message
5218      FND_MSG_PUB.Count_And_Get (
5219             p_encoded => FND_API.G_FALSE,
5220             p_count => x_msg_count,
5221             p_data  => x_msg_data
5222      );
5223 END revoke_user_resps;
5224 
5225 /*
5226  * manage_store_resp_on_create
5227  * This public API will take care of creating store responsibility of partner that
5228  * have active membership in the program. This should be called when a new store
5229  * responsibility is added to a program.
5230  */
5231 PROCEDURE manage_store_resp_on_create(
5232     p_api_version_number         IN   NUMBER
5233    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
5234    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
5235    ,x_return_status              OUT  NOCOPY  VARCHAR2
5236    ,x_msg_count                  OUT  NOCOPY  NUMBER
5237    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
5238    ,p_resp_map_rule_id           IN   NUMBER
5239    ,p_resp_id                    IN   NUMBER
5240    ,p_program_id                 IN   NUMBER
5241 )
5242 IS
5243    CURSOR c_get_partner_and_program IS
5244       SELECT partner_id, program_id
5245       FROM   pv_pg_memberships
5246       WHERE  program_id in (
5247             SELECT           program_id
5248             FROM             pv_partner_program_b
5249             WHERE            program_level_code = 'MEMBERSHIP'
5250             START WITH       program_id = p_program_id
5251             CONNECT BY PRIOR program_id = program_parent_id
5252       )
5253       AND    membership_status_code = 'ACTIVE';
5254 
5255    l_api_name              CONSTANT  VARCHAR2(30) := 'manage_store_resp_on_create';
5256    l_api_version_number    CONSTANT NUMBER        := 1.0;
5257    l_user_ids_tbl          JTF_NUMBER_TABLE;
5258    l_ge_ptnr_resps_rec     PV_Ge_Ptnr_Resps_PVT.ge_ptnr_resps_rec_type;
5259    l_ptnr_resp_id          NUMBER;
5260    l_exist                 NUMBER;
5261 BEGIN
5262   ---- Initialize----------------
5263 
5264    -- Standard Start of API savepoint
5265    SAVEPOINT manage_store_resp_on_create;
5266 
5267    -- Standard call to check for call compatibility.
5268    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
5269                                       ,p_api_version_number
5270                                       ,l_api_name
5271                                       ,G_PKG_NAME
5272                                       )
5273    THEN
5274        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
5275    END IF;
5276 
5277    -- Initialize message list if p_init_msg_list is set to TRUE.
5278    IF Fnd_Api.to_Boolean( p_init_msg_list )
5279    THEN
5280       Fnd_Msg_Pub.initialize;
5281    END IF;
5282 
5283    -- Initialize API return status to SUCCESS
5284    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
5285 
5286    IF (p_resp_map_rule_id is null) THEN
5287      x_return_status := FND_API.G_RET_STS_ERROR;
5288     FND_MESSAGE.set_name('PV', 'PV_NO_RESP_MAP_RULE_ID');
5289     FND_MSG_PUB.add;
5290      RAISE FND_API.G_EXC_ERROR;
5291    END IF;
5292 
5293    IF (p_resp_id is null) THEN
5294      x_return_status := FND_API.G_RET_STS_ERROR;
5295     FND_MESSAGE.set_name('PV', 'PV_NO_RESP_ID');
5296     FND_MSG_PUB.add;
5297      RAISE FND_API.G_EXC_ERROR;
5298    END IF;
5299 
5300    IF (p_program_id is null) THEN
5301      x_return_status := FND_API.G_RET_STS_ERROR;
5302     FND_MESSAGE.set_name('PV', 'PV_NO_PROGRAM_ID');
5303     FND_MSG_PUB.add;
5304      RAISE FND_API.G_EXC_ERROR;
5305    END IF;
5306 
5307    FOR x IN c_get_partner_and_program LOOP
5308       IF (PV_DEBUG_HIGH_ON) THEN
5309          Debug_Log('manage_store_resp_on_create: x.partner_id = ' || x.partner_id);
5310          Debug_Log('manage_store_resp_on_create = x.program_id' || x.program_id);
5311       END IF;
5312       l_user_ids_tbl := get_partner_users(x.partner_id, G_ALL);
5313       FOR l_u_cnt IN 1..l_user_ids_tbl.count LOOP
5314          assign_resp (
5315              p_api_version_number         => p_api_version_number
5316             ,p_init_msg_list              => FND_API.G_FALSE
5317             ,p_commit                     => FND_API.G_FALSE
5318             ,p_user_id                    => l_user_ids_tbl(l_u_cnt)
5319             ,p_resp_id                    => p_resp_id
5320             ,p_app_id                     => 671
5321             ,x_return_status              => x_return_status
5322             ,x_msg_count                  => x_msg_count
5323             ,x_msg_data                   => x_msg_data
5324          );
5325          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
5326             RAISE FND_API.G_EXC_ERROR;
5327          END IF;
5328       END LOOP; -- End of l_l_user_ids_tbl
5329 
5330       /****
5331        * API to add a row to pv_ge_ptnr_resps
5332        ****/
5333       l_ge_ptnr_resps_rec.partner_id := x.partner_id;
5334       l_ge_ptnr_resps_rec.user_role_code := G_ALL;
5335       l_ge_ptnr_resps_rec.program_id := x.program_id;
5336       l_ge_ptnr_resps_rec.responsibility_id := p_resp_id;
5337       l_ge_ptnr_resps_rec.source_resp_map_rule_id := p_resp_map_rule_id;
5338       l_ge_ptnr_resps_rec.resp_type_code := G_STORE;
5339 
5340       IF (PV_DEBUG_HIGH_ON) THEN
5341          Debug_Log('manage_store_resp_on_create: l_ge_ptnr_resps_rec.partner_id = ' || l_ge_ptnr_resps_rec.partner_id);
5342          Debug_Log('manage_store_resp_on_create: l_ge_ptnr_resps_rec.user_role_code = ' || l_ge_ptnr_resps_rec.user_role_code);
5343          Debug_Log('manage_store_resp_on_create: l_ge_ptnr_resps_rec.program_id = ' || l_ge_ptnr_resps_rec.program_id);
5344          Debug_Log('manage_store_resp_on_create: l_ge_ptnr_resps_rec.responsibility_id = ' || l_ge_ptnr_resps_rec.responsibility_id);
5345          Debug_Log('manage_store_resp_on_create: l_ge_ptnr_resps_rec.source_resp_map_rule_id = ' || l_ge_ptnr_resps_rec.source_resp_map_rule_id);
5346          Debug_Log('manage_store_resp_on_create: l_ge_ptnr_resps_rec.resp_type_code = ' || l_ge_ptnr_resps_rec.resp_type_code);
5347       END IF;
5348 
5349       PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps(
5350           p_api_version_number         => p_api_version_number
5351          ,p_init_msg_list              => FND_API.G_FALSE
5352          ,p_commit                     => FND_API.G_FALSE
5353          ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
5354 
5355          ,x_return_status              => x_return_status
5356          ,x_msg_count                  => x_msg_count
5357          ,x_msg_data                   => x_msg_data
5358          ,p_ge_ptnr_resps_rec          => l_ge_ptnr_resps_rec
5359          ,x_ptnr_resp_id               => l_ptnr_resp_id
5360       );
5361 
5362       IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
5363          RAISE FND_API.G_EXC_ERROR;
5364       END IF;
5365    END LOOP; -- End of FOR x IN c_get_partner_and_program
5366 
5367    -- Check for commit
5368    IF FND_API.to_boolean(p_commit) THEN
5369       COMMIT;
5370    END IF;
5371 
5372    FND_MSG_PUB.count_and_get(
5373       p_encoded => FND_API.g_false
5374      ,p_count   => x_msg_count
5375      ,p_data    => x_msg_data
5376    );
5377 
5378 EXCEPTION
5379 
5380    WHEN PVX_Utility_PVT.resource_locked THEN
5381      x_return_status := FND_API.g_ret_sts_error;
5382          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
5383 
5384    WHEN FND_API.G_EXC_ERROR THEN
5385      ROLLBACK TO manage_store_resp_on_create;
5386      x_return_status := FND_API.G_RET_STS_ERROR;
5387      -- Standard call to get message count and if count=1, get the message
5388      FND_MSG_PUB.Count_And_Get (
5389             p_encoded => FND_API.G_FALSE,
5390             p_count   => x_msg_count,
5391             p_data    => x_msg_data
5392      );
5393 
5394    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5395      ROLLBACK TO manage_store_resp_on_create;
5396      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5397      -- Standard call to get message count and if count=1, get the message
5398      FND_MSG_PUB.Count_And_Get (
5399             p_encoded => FND_API.G_FALSE,
5400             p_count => x_msg_count,
5401             p_data  => x_msg_data
5402      );
5403 
5404    WHEN OTHERS THEN
5405      ROLLBACK TO manage_store_resp_on_create;
5406      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5407      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5408      THEN
5409         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
5410      END IF;
5411      -- Standard call to get message count and if count=1, get the message
5412      FND_MSG_PUB.Count_And_Get (
5413             p_encoded => FND_API.G_FALSE,
5414             p_count => x_msg_count,
5415             p_data  => x_msg_data
5416      );
5417 END manage_store_resp_on_create;
5418 
5419 /*
5420  * manage_store_resp_on_delete
5421  * This public API will take care of deleting store responsibility of partner that
5422  * have active membership in the program. This should be called when a store
5423  * responsibility is deleted.
5424  */
5425 PROCEDURE manage_store_resp_on_delete(
5426     p_api_version_number         IN   NUMBER
5427    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
5428    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
5429    ,x_return_status              OUT  NOCOPY  VARCHAR2
5430    ,x_msg_count                  OUT  NOCOPY  NUMBER
5431    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
5432    ,p_resp_map_rule_id           IN   NUMBER
5433 )
5434 IS
5435    CURSOR c_get_partner_id (cv_program_id NUMBER) IS
5436       SELECT partner_id
5437       FROM   pv_pg_memberships
5438       WHERE  program_id = cv_program_id
5439       AND    membership_status_code = 'ACTIVE';
5440 
5441    CURSOR c_get_ptnr_resps_info IS
5442       SELECT ptnr_resp_id, program_id, responsibility_id, object_version_number
5443       FROM   pv_ge_ptnr_resps
5444       WHERE  source_resp_map_rule_id = p_resp_map_rule_id
5445       AND    resp_type_code = G_STORE;
5446 
5447   CURSOR c_get_count (cv_partner_id NUMBER, cv_responsibility_id NUMBER) IS
5448       SELECT count(*)
5449       FROM   pv_ge_ptnr_resps
5450       WHERE  partner_id = cv_partner_id
5451          AND user_role_code = G_ALL
5452          AND responsibility_id = cv_responsibility_id
5453          AND resp_type_code = G_STORE;
5454 
5455    -- Get the resp id of all other partners which have the same
5456    -- partner_party_id of the pass in partner
5457    CURSOR c_get_other_resp_id (cv_partner_id NUMBER) IS
5458       SELECT responsibility_id
5459       FROM   pv_ge_ptnr_resps
5460       WHERE  partner_id in (
5461                 SELECT partner_id
5462                 FROM   pv_partner_profiles
5463                 WHERE  partner_party_id in (
5464                           SELECT partner_party_id
5465                           FROM pv_partner_profiles
5466                           WHERE partner_id = cv_partner_id
5467                        )
5468                 AND    partner_id <> cv_partner_id
5469              )
5470        AND   user_role_code = G_ALL
5471        AND   resp_type_code = G_STORE;
5472 
5473    l_api_name              CONSTANT  VARCHAR2(30) := 'manage_store_resp_on_delete';
5474    l_api_version_number    CONSTANT NUMBER   := 1.0;
5475    l_count                 NUMBER;
5476    l_no_revoke             BOOLEAN;
5477    l_ge_ptnr_resps_rec     PV_Ge_Ptnr_Resps_PVT.ge_ptnr_resps_rec_type;
5478 
5479 BEGIN
5480   ---- Initialize----------------
5481 
5482    -- Standard Start of API savepoint
5483    SAVEPOINT manage_store_resp_on_delete;
5484 
5485    -- Standard call to check for call compatibility.
5486    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
5487                                       ,p_api_version_number
5488                                       ,l_api_name
5489                                       ,G_PKG_NAME
5490                                       )
5491    THEN
5492        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
5493    END IF;
5494 
5495    -- Initialize message list if p_init_msg_list is set to TRUE.
5496    IF Fnd_Api.to_Boolean( p_init_msg_list )
5497    THEN
5498       Fnd_Msg_Pub.initialize;
5499    END IF;
5500 
5501    --Debug_Log('priflie: ' || fnd_profile.VALUE('FND_AS_MSG_LEVEL_THRESHOLD'));
5502    -- Debug Message
5503    IF (PV_DEBUG_HIGH_ON) THEN
5504       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
5505    END IF;
5506 
5507    -- Initialize API return status to SUCCESS
5508    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
5509 
5510    IF (p_resp_map_rule_id is null) THEN
5511      x_return_status := FND_API.G_RET_STS_ERROR;
5512     FND_MESSAGE.set_name('PV', 'PV_NO_RESP_MAP_RULE_ID');
5513     FND_MSG_PUB.add;
5514      RAISE FND_API.G_EXC_ERROR;
5515    END IF;
5516 
5517    FOR x IN c_get_ptnr_resps_info LOOP
5518       IF (PV_DEBUG_HIGH_ON) THEN
5519          Debug_Log('manage_store_resp_on_delete: x.ptnr_resp_id = ' || x.ptnr_resp_id);
5520          Debug_Log('manage_store_resp_on_delete: x.program_id = ' || x.program_id);
5521          Debug_Log('manage_store_resp_on_delete: x.responsibility_id = ' || x.responsibility_id);
5522          Debug_Log('manage_store_resp_on_delete: x.object_version_number = ' || x.object_version_number);
5523       END IF;
5524       FOR y IN c_get_partner_id(x.program_id) LOOP
5525          OPEN c_get_count(y.partner_id, x.responsibility_id);
5526          FETCH c_get_count into l_count;
5527          CLOSE c_get_count;
5528          IF (PV_DEBUG_HIGH_ON) THEN
5529             Debug_Log('manage_store_resp_on_delete: l_count = ' || l_count);
5530          END IF;
5531          -- If there is only this (partner_id, responsibility_id) for store responsibility combo,
5532          -- do the following steps.
5533          IF (l_count = 1) THEN
5534             IF (PV_DEBUG_HIGH_ON) THEN
5535                Debug_Log('manage_store_resp_on_delete: l_count is 1');
5536             END IF;
5537 
5538             l_no_revoke := false;
5539             FOR z IN c_get_other_resp_id (y.partner_id) LOOP
5540                -- To check if there is same resp_id assigned to the users
5541                -- The users in two partner_id which have the same partner_party_id
5542                -- We set l_no_revoke to true, that means, we will not revoke this resp
5543                IF (x.responsibility_id = z.responsibility_id) THEN
5544                   l_no_revoke := true;
5545                   exit;
5546                END IF;
5547             END LOOP;
5548             IF (not l_no_revoke) THEN
5549                revoke_resp(
5550                    p_api_version_number         => p_api_version_number
5551                   ,p_init_msg_list              => FND_API.G_FALSE
5552                   ,p_commit                     => p_commit
5553                   ,p_user_id                    => get_partner_users(y.partner_id, G_ALL)
5554                   ,p_resp_id                    => x.responsibility_id
5555                   ,x_return_status              => x_return_status
5556                   ,x_msg_count                  => x_msg_count
5557                   ,x_msg_data                   => x_msg_data
5558                );
5559                IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
5560                   RAISE FND_API.G_EXC_ERROR;
5561                END IF;
5562             END IF; -- End of IF (not l_no_revoke)
5563          END IF; -- End of IF (l_count = 1)
5564 
5565          /****
5566           * API to delete the row with ptnr_resp_id = x.ptnr_resp_id from pv_partner_memberships
5567           ****/
5568          IF (PV_DEBUG_HIGH_ON) THEN
5569             Debug_Log('manage_store_resp_on_delete: before calling PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps');
5570             Debug_Log('manage_store_resp_on_delete: x.ptnr_resp_id = ' || x.ptnr_resp_id);
5571             Debug_Log('manage_store_resp_on_delete: x.object_version_number = ' || x.object_version_number);
5572          END IF;
5573 
5574          PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps(
5575              p_api_version_number         => p_api_version_number
5576             ,p_init_msg_list              => FND_API.G_FALSE
5577             ,p_commit                     => FND_API.G_FALSE
5578             ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
5579 
5580             ,x_return_status              => x_return_status
5581             ,x_msg_count                  => x_msg_count
5582             ,x_msg_data                   => x_msg_data
5583             ,p_ptnr_resp_id               => x.ptnr_resp_id
5584             ,p_object_version_number      => x.object_version_number
5585          );
5586          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
5587             RAISE FND_API.G_EXC_ERROR;
5588          END IF;
5589       END LOOP; -- End of FOR y IN c_get_partner_id(x.program_id)
5590    END LOOP; -- End of FOR x IN c_get_ptnr_resps_info
5591 
5592    -- Check for commit
5593    IF FND_API.to_boolean(p_commit) THEN
5594       COMMIT;
5595    END IF;
5596 
5597    FND_MSG_PUB.count_and_get(
5598       p_encoded => FND_API.g_false
5599      ,p_count   => x_msg_count
5600      ,p_data    => x_msg_data
5601    );
5602 
5603 EXCEPTION
5604 
5605    WHEN PVX_Utility_PVT.resource_locked THEN
5606      x_return_status := FND_API.g_ret_sts_error;
5607          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
5608 
5609    WHEN FND_API.G_EXC_ERROR THEN
5610      ROLLBACK TO manage_store_resp_on_delete;
5611      x_return_status := FND_API.G_RET_STS_ERROR;
5612      -- Standard call to get message count and if count=1, get the message
5613      FND_MSG_PUB.Count_And_Get (
5614             p_encoded => FND_API.G_FALSE,
5615             p_count   => x_msg_count,
5616             p_data    => x_msg_data
5617      );
5618 
5619    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5620      ROLLBACK TO manage_store_resp_on_delete;
5621      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5622      -- Standard call to get message count and if count=1, get the message
5623      FND_MSG_PUB.Count_And_Get (
5624             p_encoded => FND_API.G_FALSE,
5625             p_count => x_msg_count,
5626             p_data  => x_msg_data
5627      );
5628 
5629    WHEN OTHERS THEN
5630      ROLLBACK TO manage_store_resp_on_delete;
5631      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5632      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5633      THEN
5634         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
5635      END IF;
5636      -- Standard call to get message count and if count=1, get the message
5637      FND_MSG_PUB.Count_And_Get (
5638             p_encoded => FND_API.G_FALSE,
5639             p_count => x_msg_count,
5640             p_data  => x_msg_data
5641      );
5642 END manage_store_resp_on_delete;
5643 
5644 /*
5645  * assign_default_resp
5646  * This public API will be called when partner status changes from I to A.
5647  * It will assign the default responsibility to all the users of the
5648  * pass in partner.
5649  */
5650 PROCEDURE assign_default_resp (
5651     p_api_version_number         IN   NUMBER
5652    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
5653    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
5654    ,x_return_status              OUT  NOCOPY  VARCHAR2
5655    ,x_msg_count                  OUT  NOCOPY  NUMBER
5656    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
5657    ,p_partner_id                 IN   NUMBER
5658 )
5659 IS
5660    CURSOR c_get_primary_users IS
5661       SELECT jtfre.user_id user_id
5662       FROM   hz_relationships hzr, jtf_rs_resource_extns jtfre, pv_partner_profiles pvpp, fnd_user fndu
5663       WHERE  pvpp.partner_id = p_partner_id
5664       AND    pvpp.status = 'A'
5665       AND    pvpp.partner_party_id = hzr.object_id
5666       AND    hzr.directional_flag = 'F'
5667       AND    hzr.relationship_code = 'EMPLOYEE_OF'
5668       AND    HZR.subject_table_name ='HZ_PARTIES'
5669       AND    HZR.object_table_name ='HZ_PARTIES'
5670       AND    hzr.start_date <= SYSDATE
5671       AND    (hzr.end_date is null or  hzr.end_date > sysdate)
5672       AND    HZR.status = 'A'
5673       AND    hzr.party_id = jtfre.source_id
5674       AND    jtfre.category = 'PARTY'
5675       AND    fndu.user_id = jtfre.user_id
5676       AND    fndu.start_date <= sysdate
5677       AND    (fndu.end_date is null or fndu.end_date > sysdate)
5678       AND    exists (
5679                 SELECT    jtfp1.principal_name username
5680                 FROM      jtf_auth_principal_maps jtfpm,
5681                           jtf_auth_principals_b jtfp1,
5682                           jtf_auth_domains_b jtfd,
5683                           jtf_auth_principals_b jtfp2,
5684                           jtf_auth_role_perms jtfrp,
5685                           jtf_auth_permissions_b jtfperm
5686                 WHERE     jtfp1.is_user_flag=1
5687                 AND       jtfp1.jtf_auth_principal_id=jtfpm.jtf_auth_principal_id
5688                 AND       jtfpm.jtf_auth_parent_principal_id = jtfp2.jtf_auth_principal_id
5689                 AND       jtfp2.is_user_flag=0
5690                 AND       jtfp2.jtf_auth_principal_id = jtfrp.jtf_auth_principal_id
5691                 AND       jtfrp.positive_flag = 1
5692                 AND       jtfrp.jtf_auth_permission_id = jtfperm.jtf_auth_permission_id
5693                 AND       jtfperm.permission_name in ('PV_PARTNER_USER', 'IBE_INT_PRIMARY_USER')
5694                 AND       jtfd.jtf_auth_domain_id=jtfpm.jtf_auth_domain_id
5695                 AND       jtfd.domain_name='CRM_DOMAIN'
5696 		AND       jtfp1.principal_name = jtfre.user_name
5697                 GROUP BY  jtfp1.principal_name
5698                 HAVING    count( distinct decode(jtfperm.permission_name,  'IBE_INT_PRIMARY_USER', null, jtfperm.permission_name ) ) = 1
5699                 AND       count(  distinct decode(jtfperm.permission_name,  'IBE_INT_PRIMARY_USER', jtfperm.permission_name, null ) ) = 1
5700              );
5701 
5702    CURSOR c_get_business_users IS
5703       SELECT jtfre.user_id user_id
5704       FROM   hz_relationships hzr,
5705              jtf_rs_resource_extns jtfre,
5706              pv_partner_profiles pvpp, fnd_user fndu
5707       WHERE  pvpp.partner_id = p_partner_id
5708       AND    pvpp.status = 'A'
5709       AND    pvpp.partner_party_id = hzr.object_id
5710       AND    hzr.directional_flag = 'F'
5711       AND    hzr.relationship_code = 'EMPLOYEE_OF'
5712       AND    HZR.subject_table_name ='HZ_PARTIES'
5713       AND    HZR.object_table_name ='HZ_PARTIES'
5714       AND    hzr.start_date <= SYSDATE
5715       AND    (hzr.end_date is null or  hzr.end_date > sysdate)
5716       AND    HZR.status = 'A'
5717       AND    hzr.party_id = jtfre.source_id
5718       AND    jtfre.category = 'PARTY'
5719       AND    fndu.user_id = jtfre.user_id
5720       AND    fndu.start_date <= sysdate
5721       AND    (fndu.end_date is null or fndu.end_date > sysdate)
5722       AND    exists  (
5723                 SELECT    jtfp1.principal_name username
5724                 FROM      jtf_auth_principal_maps jtfpm,
5725                           jtf_auth_principals_b jtfp1,
5726                           jtf_auth_domains_b jtfd,
5727                           jtf_auth_principals_b jtfp2,
5728                           jtf_auth_role_perms jtfrp,
5729                           jtf_auth_permissions_b jtfperm
5730                 WHERE     jtfp1.is_user_flag=1
5731                 AND       jtfp1.jtf_auth_principal_id=jtfpm.jtf_auth_principal_id
5732                 AND       jtfpm.jtf_auth_parent_principal_id = jtfp2.jtf_auth_principal_id
5733                 AND       jtfp2.is_user_flag=0
5734                 AND       jtfp2.jtf_auth_principal_id = jtfrp.jtf_auth_principal_id
5735                 AND       jtfrp.positive_flag = 1
5736                 AND       jtfrp.jtf_auth_permission_id = jtfperm.jtf_auth_permission_id
5737                 AND       jtfperm.permission_name in ('PV_PARTNER_USER', 'IBE_INT_PRIMARY_USER')
5738                 AND       jtfd.jtf_auth_domain_id=jtfpm.jtf_auth_domain_id
5739                 AND       jtfd.domain_name='CRM_DOMAIN'
5740 		AND       jtfp1.principal_name = jtfre.user_name
5741                 GROUP BY  jtfp1.principal_name
5742                 HAVING    count( distinct decode(jtfperm.permission_name,  'IBE_INT_PRIMARY_USER', null, jtfperm.permission_name ) ) = 1
5743                 AND       count(  distinct decode(jtfperm.permission_name,  'IBE_INT_PRIMARY_USER', jtfperm.permission_name, null ) ) = 0
5744       );
5745 
5746    l_api_name                  CONSTANT  VARCHAR2(30) := 'assign_default_resp';
5747    l_api_version_number        CONSTANT NUMBER   := 1.0;
5748    l_responsibility_id         NUMBER;
5749    l_resp_map_rule_id          NUMBER;
5750    l_partner_ids_tbl           JTF_NUMBER_TABLE;
5751    l_ge_ptnr_resps_rec         PV_Ge_Ptnr_Resps_PVT.ge_ptnr_resps_rec_type;
5752    l_ptnr_resp_id              NUMBER;
5753 
5754 BEGIN
5755    ---- Initialize----------------
5756 
5757    -- Standard Start of API savepoint
5758    SAVEPOINT assign_default_resp;
5759 
5760    -- Standard call to check for call compatibility.
5761    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
5762                                       ,p_api_version_number
5763                                       ,l_api_name
5764                                       ,G_PKG_NAME
5765                                       )
5766    THEN
5767        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
5768    END IF;
5769 
5770    -- Initialize message list if p_init_msg_list is set to TRUE.
5771    IF Fnd_Api.to_Boolean( p_init_msg_list )
5772    THEN
5773       Fnd_Msg_Pub.initialize;
5774    END IF;
5775 
5776    -- Debug Message
5777    IF (PV_DEBUG_HIGH_ON) THEN
5778       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
5779       WRITE_LOG(l_api_name, 'PRIVATE API: ' || l_api_name || ' - START');
5780    END IF;
5781 
5782    -- Initialize API return status to SUCCESS
5783    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
5784 
5785    -- Get the default resp for primary users
5786    get_default_resp(
5787        p_api_version_number         => p_api_version_number
5788       ,p_init_msg_list              => FND_API.G_FALSE
5789       ,p_commit                     => FND_API.G_FALSE
5790       ,x_return_status              => x_return_status
5791       ,x_msg_count                  => x_msg_count
5792       ,x_msg_data                   => x_msg_data
5793       ,p_partner_id                 => p_partner_id
5794       ,p_user_role_code             => G_PRIMARY
5795       ,x_responsibility_id          => l_responsibility_id
5796       ,x_resp_map_rule_id           => l_resp_map_rule_id
5797    );
5798    IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
5799       RAISE FND_API.G_EXC_ERROR;
5800    END IF;
5801 
5802    IF (l_responsibility_id is not null) and (l_resp_map_rule_id is not null) THEN
5803       FOR x in c_get_primary_users LOOP
5804          assign_resp(
5805              p_api_version_number         => p_api_version_number
5806             ,p_init_msg_list              => FND_API.G_FALSE
5807             ,p_commit                     => FND_API.G_FALSE
5808             ,p_user_id                    => x.user_id
5809             ,p_resp_id                    => l_responsibility_id
5810             ,p_app_id                     => 691
5811             ,x_return_status              => x_return_status
5812             ,x_msg_count                  => x_msg_count
5813             ,x_msg_data                   => x_msg_data
5814          );
5815          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
5816             RAISE FND_API.G_EXC_ERROR;
5817          END IF;
5818       END LOOP;
5819 
5820       /****
5821        * API to add a row to pv_ge_ptnr_resps
5822        ****/
5823       l_ge_ptnr_resps_rec.partner_id := p_partner_id;
5824       l_ge_ptnr_resps_rec.user_role_code := G_PRIMARY;
5825       l_ge_ptnr_resps_rec.responsibility_id := l_responsibility_id;
5826       l_ge_ptnr_resps_rec.source_resp_map_rule_id := l_resp_map_rule_id;
5827       l_ge_ptnr_resps_rec.resp_type_code := G_PROGRAM;
5828 
5829       IF (PV_DEBUG_HIGH_ON) THEN
5830          Debug_Log('assign_default_resp: l_ge_ptnr_resps_rec.partner_id = ' || l_ge_ptnr_resps_rec.partner_id);
5831          Debug_Log('assign_default_resp: l_ge_ptnr_resps_rec.user_role_code = ' || l_ge_ptnr_resps_rec.user_role_code);
5832          Debug_Log('assign_default_resp: l_ge_ptnr_resps_rec.responsibility_id = ' || l_ge_ptnr_resps_rec.responsibility_id);
5833          Debug_Log('assign_default_resp: l_ge_ptnr_resps_rec.source_resp_map_rule_id = ' || l_ge_ptnr_resps_rec.source_resp_map_rule_id);
5834          Debug_Log('assign_default_resp: l_ge_ptnr_resps_rec.resp_type_code = ' || l_ge_ptnr_resps_rec.resp_type_code);
5835          WRITE_LOG(l_api_name, 'assign_default_resp: l_ge_ptnr_resps_rec.partner_id = ' || l_ge_ptnr_resps_rec.partner_id);
5836          WRITE_LOG(l_api_name, 'assign_default_resp: l_ge_ptnr_resps_rec.user_role_code = ' || l_ge_ptnr_resps_rec.user_role_code);
5837          WRITE_LOG(l_api_name, 'assign_default_resp: l_ge_ptnr_resps_rec.responsibility_id = ' || l_ge_ptnr_resps_rec.responsibility_id);
5838          WRITE_LOG(l_api_name, 'assign_default_resp: l_ge_ptnr_resps_rec.source_resp_map_rule_id = ' || l_ge_ptnr_resps_rec.source_resp_map_rule_id);
5839          WRITE_LOG(l_api_name, 'assign_default_resp: l_ge_ptnr_resps_rec.resp_type_code = ' || l_ge_ptnr_resps_rec.resp_type_code);
5840       END IF;
5841 
5842       PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps(
5843           p_api_version_number         => p_api_version_number
5844          ,p_init_msg_list              => FND_API.G_FALSE
5845          ,p_commit                     => FND_API.G_FALSE
5846          ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
5847 
5848          ,x_return_status              => x_return_status
5849          ,x_msg_count                  => x_msg_count
5850          ,x_msg_data                   => x_msg_data
5851          ,p_ge_ptnr_resps_rec          => l_ge_ptnr_resps_rec
5852          ,x_ptnr_resp_id               => l_ptnr_resp_id
5853       );
5854    ELSE
5855       FND_MESSAGE.set_name('PV', 'PV_NO_DEFAULT_RESP');
5856       FND_MSG_PUB.add;
5857       RAISE FND_API.G_EXC_ERROR;
5858    END IF;
5859 
5860    -- Get the default resp for business users
5861    get_default_resp(
5862        p_api_version_number         => p_api_version_number
5863       ,p_init_msg_list              => FND_API.G_FALSE
5864       ,p_commit                     => FND_API.G_FALSE
5865       ,x_return_status              => x_return_status
5866       ,x_msg_count                  => x_msg_count
5867       ,x_msg_data                   => x_msg_data
5868       ,p_partner_id                 => p_partner_id
5869       ,p_user_role_code             => G_BUSINESS
5870       ,x_responsibility_id          => l_responsibility_id
5871       ,x_resp_map_rule_id           => l_resp_map_rule_id
5872    );
5873    IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
5874       RAISE FND_API.G_EXC_ERROR;
5875    END IF;
5876 
5877    IF (l_responsibility_id is not null) and (l_resp_map_rule_id is not null) THEN
5878       FOR x IN c_get_business_users LOOP
5879          assign_resp(
5880              p_api_version_number         => p_api_version_number
5881             ,p_init_msg_list              => FND_API.G_FALSE
5882             ,p_commit                     => FND_API.G_FALSE
5883             ,p_user_id                    => x.user_id
5884             ,p_resp_id                    => l_responsibility_id
5885             ,p_app_id                     => 691
5886             ,x_return_status              => x_return_status
5887             ,x_msg_count                  => x_msg_count
5888             ,x_msg_data                   => x_msg_data
5889          );
5890          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
5891             RAISE FND_API.G_EXC_ERROR;
5892          END IF;
5893       END LOOP;
5894 
5895       /****
5896        * API to add a row to pv_ge_ptnr_resps
5897        ****/
5898       l_ge_ptnr_resps_rec.partner_id := p_partner_id;
5899       l_ge_ptnr_resps_rec.user_role_code := G_BUSINESS;
5900       l_ge_ptnr_resps_rec.responsibility_id := l_responsibility_id;
5901       l_ge_ptnr_resps_rec.source_resp_map_rule_id := l_resp_map_rule_id;
5902       l_ge_ptnr_resps_rec.resp_type_code := G_PROGRAM;
5903 
5904       IF (PV_DEBUG_HIGH_ON) THEN
5905          Debug_Log('assign_default_resp: l_ge_ptnr_resps_rec.partner_id = ' || l_ge_ptnr_resps_rec.partner_id);
5906          Debug_Log('assign_default_resp: l_ge_ptnr_resps_rec.user_role_code = ' || l_ge_ptnr_resps_rec.user_role_code);
5907          Debug_Log('assign_default_resp: l_ge_ptnr_resps_rec.responsibility_id = ' || l_ge_ptnr_resps_rec.responsibility_id);
5908          Debug_Log('assign_default_resp: l_ge_ptnr_resps_rec.source_resp_map_rule_id = ' || l_ge_ptnr_resps_rec.source_resp_map_rule_id);
5909          Debug_Log('assign_default_resp: l_ge_ptnr_resps_rec.resp_type_code = ' || l_ge_ptnr_resps_rec.resp_type_code);
5910          WRITE_LOG(l_api_name, 'assign_default_resp: l_ge_ptnr_resps_rec.partner_id = ' || l_ge_ptnr_resps_rec.partner_id);
5911          WRITE_LOG(l_api_name, 'assign_default_resp: l_ge_ptnr_resps_rec.user_role_code = ' || l_ge_ptnr_resps_rec.user_role_code);
5912          WRITE_LOG(l_api_name, 'assign_default_resp: l_ge_ptnr_resps_rec.responsibility_id = ' || l_ge_ptnr_resps_rec.responsibility_id);
5913          WRITE_LOG(l_api_name, 'assign_default_resp: l_ge_ptnr_resps_rec.source_resp_map_rule_id = ' || l_ge_ptnr_resps_rec.source_resp_map_rule_id);
5914          WRITE_LOG(l_api_name, 'assign_default_resp: l_ge_ptnr_resps_rec.resp_type_code = ' || l_ge_ptnr_resps_rec.resp_type_code);
5915       END IF;
5916 
5917       PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps(
5918           p_api_version_number         => p_api_version_number
5919          ,p_init_msg_list              => FND_API.G_FALSE
5920          ,p_commit                     => FND_API.G_FALSE
5921          ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
5922 
5923          ,x_return_status              => x_return_status
5924          ,x_msg_count                  => x_msg_count
5925          ,x_msg_data                   => x_msg_data
5926          ,p_ge_ptnr_resps_rec          => l_ge_ptnr_resps_rec
5927          ,x_ptnr_resp_id               => l_ptnr_resp_id
5928       );
5929    ELSE
5930       FND_MESSAGE.set_name('PV', 'PV_NO_DEFAULT_RESP');
5931       FND_MSG_PUB.add;
5932       RAISE FND_API.G_EXC_ERROR;
5933    END IF;
5934 
5935 EXCEPTION
5936 
5937    WHEN PVX_Utility_PVT.resource_locked THEN
5938      x_return_status := FND_API.g_ret_sts_error;
5939      PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
5940 
5941    WHEN FND_API.G_EXC_ERROR THEN
5942      ROLLBACK TO assign_default_resp;
5943      x_return_status := FND_API.G_RET_STS_ERROR;
5944      -- Standard call to get message count and if count=1, get the message
5945      FND_MSG_PUB.Count_And_Get (
5946             p_encoded => FND_API.G_FALSE,
5947             p_count   => x_msg_count,
5948             p_data    => x_msg_data
5949      );
5950 
5951    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5952      ROLLBACK TO assign_default_resp;
5953      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5954      -- Standard call to get message count and if count=1, get the message
5955      FND_MSG_PUB.Count_And_Get (
5956             p_encoded => FND_API.G_FALSE,
5957             p_count => x_msg_count,
5958             p_data  => x_msg_data
5959      );
5960 
5961    WHEN OTHERS THEN
5962      ROLLBACK TO assign_default_resp;
5963      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5964      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5965      THEN
5966         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
5967      END IF;
5968      -- Standard call to get message count and if count=1, get the message
5969      FND_MSG_PUB.Count_And_Get (
5970             p_encoded => FND_API.G_FALSE,
5971             p_count => x_msg_count,
5972             p_data  => x_msg_data
5973      );
5974 END assign_default_resp;
5975 
5976 /*
5977  * manage_resp_on_address_change
5978  * This public procedure will take care of managing partner responsibilities
5979  * when partner organization address changes.
5980  */
5981 PROCEDURE manage_resp_on_address_change(
5982     p_api_version_number         IN   NUMBER
5983    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
5984    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
5985    ,x_return_status              OUT  NOCOPY  VARCHAR2
5986    ,x_msg_count                  OUT  NOCOPY  NUMBER
5987    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
5988    ,p_org_party_id               IN   NUMBER
5989 )
5990 IS
5991    CURSOR c_get_partner_id IS
5992       SELECT    partner_id
5993       FROM      pv_partner_profiles
5994       WHERE     partner_party_id = p_org_party_id;
5995 
5996    CURSOR c_get_resp_info (cv_partner_id NUMBER) IS
5997       SELECT   ptnr_resp_id, responsibility_id, partner_id, program_id,
5998                user_role_code, object_version_number
5999       FROM     pv_ge_ptnr_resps
6000       WHERE    partner_id = cv_partner_id
6001       AND      resp_type_code = G_PROGRAM
6002       ORDER BY user_role_code;
6003 
6004    CURSOR c_check_prgm_resp_exist (cv_partner_id NUMBER, cv_user_role_code VARCHAR2) IS
6005       SELECT 1
6006       FROM   pv_ge_ptnr_resps
6007       WHERE  partner_id = cv_partner_id
6008       AND    user_role_code = cv_user_role_code
6009       AND    resp_type_code = G_PROGRAM;
6010 
6011    l_api_name                  CONSTANT  VARCHAR2(30) := 'manage_resp_on_address_change';
6012    l_api_version_number        CONSTANT NUMBER   := 1.0;
6013    primary_user_ids_tbl        JTF_NUMBER_TABLE;
6014    business_user_ids_tbl       JTF_NUMBER_TABLE;
6015    l_responsibility_id         NUMBER;
6016    l_resp_map_rule_id          NUMBER;
6017    l_ge_ptnr_resps_rec         PV_Ge_Ptnr_Resps_PVT.ge_ptnr_resps_rec_type;
6018    l_ptnr_resp_id              NUMBER;
6019    l_exist                     NUMBER;
6020 BEGIN
6021    ---- Initialize----------------
6022 
6023    -- Standard Start of API savepoint
6024    SAVEPOINT manage_resp_on_address_change;
6025 
6026    -- Standard call to check for call compatibility.
6027    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
6028                                       ,p_api_version_number
6029                                       ,l_api_name
6030                                       ,G_PKG_NAME
6031                                       )
6032    THEN
6033        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
6034    END IF;
6035 
6036    -- Initialize message list if p_init_msg_list is set to TRUE.
6037    IF Fnd_Api.to_Boolean( p_init_msg_list )
6038    THEN
6039       Fnd_Msg_Pub.initialize;
6040    END IF;
6041 
6042    -- Debug Message
6043    IF (PV_DEBUG_HIGH_ON) THEN
6044       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
6045    END IF;
6046 
6047    -- Initialize API return status to SUCCESS
6048    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
6049 
6050    FOR x IN c_get_partner_id LOOP
6051       IF (PV_DEBUG_HIGH_ON) THEN
6052          Debug_Log('manage_resp_on_address_change: x.partner_id = ' || x.partner_id);
6053       END IF;
6054       primary_user_ids_tbl := null;
6055       business_user_ids_tbl := null;
6056       FOR y IN c_get_resp_info(x.partner_id) LOOP
6057          IF (y.user_role_code = G_PRIMARY) THEN
6058             -- Get all users of the partner_id and the user_role_code by calling get_partner_users().
6059             -- Only do this once for each partner
6060             IF (primary_user_ids_tbl is null) THEN
6061                IF (PV_DEBUG_HIGH_ON) THEN
6062                   Debug_Log('manage_resp_on_address_change: primary_user_ids_tbl is null');
6063                END IF;
6064                primary_user_ids_tbl := get_partner_users(x.partner_id, y.user_role_code);
6065             END IF;
6066 
6067             IF (PV_DEBUG_HIGH_ON) THEN
6068                Debug_Log('manage_resp_on_address_change: y.responsibility_id = ' || y.responsibility_id);
6069             END IF;
6070             revoke_resp(
6071                 p_api_version_number         => p_api_version_number
6072                ,p_init_msg_list              => FND_API.G_FALSE
6073                ,p_commit                     => p_commit
6074                ,p_user_id                    => primary_user_ids_tbl
6075                ,p_resp_id                    => y.responsibility_id
6076                ,x_return_status              => x_return_status
6077                ,x_msg_count                  => x_msg_count
6078                ,x_msg_data                   => x_msg_data
6079             );
6080             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
6081                RAISE FND_API.G_EXC_ERROR;
6082             END IF;
6083          END IF;
6084          IF (y.user_role_code = G_BUSINESS) THEN
6085             -- Get all users of the partner_id and the user_role_code by calling get_partner_users().
6086             -- Only do this once for each partner
6087             IF (business_user_ids_tbl is null) THEN
6088                IF (PV_DEBUG_HIGH_ON) THEN
6089                   Debug_Log('manage_resp_on_address_change: primary_user_ids_tbl is null');
6090                END IF;
6091                business_user_ids_tbl := get_partner_users(x.partner_id, y.user_role_code);
6092             END IF;
6093 
6094             IF (PV_DEBUG_HIGH_ON) THEN
6095                Debug_Log('manage_resp_on_address_change: y.responsibility_id = ' || y.responsibility_id);
6096             END IF;
6097             revoke_resp(
6098                 p_api_version_number         => p_api_version_number
6099                ,p_init_msg_list              => FND_API.G_FALSE
6100                ,p_commit                     => p_commit
6101                ,p_user_id                    => business_user_ids_tbl
6102                ,p_resp_id                    => y.responsibility_id
6103                ,x_return_status              => x_return_status
6104                ,x_msg_count                  => x_msg_count
6105                ,x_msg_data                   => x_msg_data
6106             );
6107             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
6108                RAISE FND_API.G_EXC_ERROR;
6109             END IF;
6110          END IF;
6111 
6112          /****
6113           * API to delete the row with ptnr_resp_id = x.ptnr_resp_id
6114           ****/
6115          IF (PV_DEBUG_HIGH_ON) THEN
6116             Debug_Log('manage_resp_on_address_change: before calling PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps');
6117             Debug_Log('manage_resp_on_address_change: y.ptnr_resp_id = ' || y.ptnr_resp_id);
6118             Debug_Log('manage_resp_on_address_change: y.object_version_number = ' || y.object_version_number);
6119          END IF;
6120 
6121          PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps(
6122              p_api_version_number         => p_api_version_number
6123             ,p_init_msg_list              => FND_API.G_FALSE
6124             ,p_commit                     => FND_API.G_FALSE
6125             ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
6126 
6127             ,x_return_status              => x_return_status
6128             ,x_msg_count                  => x_msg_count
6129             ,x_msg_data                   => x_msg_data
6130             ,p_ptnr_resp_id               => y.ptnr_resp_id
6131             ,p_object_version_number      => y.object_version_number
6132          );
6133          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
6134             RAISE FND_API.G_EXC_ERROR;
6135          END IF;
6136 
6137          IF (y.program_id IS NOT NULL) THEN
6138             get_program_resp(
6139                 p_api_version_number         => p_api_version_number
6140                ,p_init_msg_list              => FND_API.G_FALSE
6141                ,p_commit                     => FND_API.G_FALSE
6142                ,x_return_status              => x_return_status
6143                ,x_msg_count                  => x_msg_count
6144                ,x_msg_data                   => x_msg_data
6145                ,p_partner_id                 => x.partner_id
6146                ,p_user_role_code             => y.user_role_code
6147                ,p_program_id                 => y.program_id
6148                ,x_responsibility_id          => l_responsibility_id
6149                ,x_resp_map_rule_id           => l_resp_map_rule_id
6150             );
6151             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
6152                RAISE FND_API.G_EXC_ERROR;
6153             END IF;
6154          ELSE
6155 
6156             get_default_resp(
6157                 p_api_version_number         => p_api_version_number
6158                ,p_init_msg_list              => FND_API.G_FALSE
6159                ,p_commit                     => FND_API.G_FALSE
6160                ,x_return_status              => x_return_status
6161                ,x_msg_count                  => x_msg_count
6162                ,x_msg_data                   => x_msg_data
6163                ,p_partner_id                 => x.partner_id
6164                ,p_user_role_code             => y.user_role_code
6165                ,x_responsibility_id          => l_responsibility_id
6166                ,x_resp_map_rule_id           => l_resp_map_rule_id
6167             );
6168             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
6169                RAISE FND_API.G_EXC_ERROR;
6170             END IF;
6171          END IF;
6172          IF (l_responsibility_id is not null) and (l_resp_map_rule_id is not null) THEN
6173             IF (y.user_role_code = G_PRIMARY) THEN
6174                FOR l_cnt IN 1..primary_user_ids_tbl.count LOOP
6175                   IF (PV_DEBUG_HIGH_ON) THEN
6176                      Debug_Log('manage_resp_on_address_change: assign: primary_user_ids_tbl('||l_cnt||')='||primary_user_ids_tbl(l_cnt));
6177                   END IF;
6178                   assign_resp(
6179                       p_api_version_number         => p_api_version_number
6180                      ,p_init_msg_list              => FND_API.G_FALSE
6181                      ,p_commit                     => FND_API.G_FALSE
6182                      ,p_user_id                    => primary_user_ids_tbl(l_cnt)
6183                      ,p_resp_id                    => l_responsibility_id
6184                      ,p_app_id                     => 691
6185                      ,x_return_status              => x_return_status
6186                      ,x_msg_count                  => x_msg_count
6187                      ,x_msg_data                   => x_msg_data
6188                   );
6189                   IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
6190                      RAISE FND_API.G_EXC_ERROR;
6191                   END IF;
6192                END LOOP;
6193             ELSIF (y.user_role_code = G_BUSINESS) THEN
6194                FOR l_cnt IN 1..business_user_ids_tbl.count LOOP
6195                   IF (PV_DEBUG_HIGH_ON) THEN
6196                      Debug_Log('manage_resp_on_address_change: assign: business_user_ids_tbl('||l_cnt||')='||business_user_ids_tbl(l_cnt));
6197                   END IF;
6198                   assign_resp(
6199                       p_api_version_number         => p_api_version_number
6200                      ,p_init_msg_list              => FND_API.G_FALSE
6201                      ,p_commit                     => FND_API.G_FALSE
6202                      ,p_user_id                    => business_user_ids_tbl(l_cnt)
6203                      ,p_resp_id                    => l_responsibility_id
6204                      ,p_app_id                     => 691
6205                      ,x_return_status              => x_return_status
6206                      ,x_msg_count                  => x_msg_count
6207                      ,x_msg_data                   => x_msg_data
6208                   );
6209                   IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
6210                      RAISE FND_API.G_EXC_ERROR;
6211                   END IF;
6212                END LOOP;
6213             END IF;
6214 
6215             /****
6216              * API to add a row to pv_ge_ptnr_resps
6217              ****/
6218             l_ge_ptnr_resps_rec.partner_id := x.partner_id;
6219             l_ge_ptnr_resps_rec.user_role_code := y.user_role_code;
6220             l_ge_ptnr_resps_rec.responsibility_id := l_responsibility_id;
6221             l_ge_ptnr_resps_rec.source_resp_map_rule_id := l_resp_map_rule_id;
6222             l_ge_ptnr_resps_rec.resp_type_code := G_PROGRAM;
6223             IF (y.program_id IS NOT NULL) THEN
6224                l_ge_ptnr_resps_rec.program_id := y.program_id;
6225             END IF;
6226 
6227             IF (PV_DEBUG_HIGH_ON) THEN
6228                Debug_Log('manage_resp_on_address_change: l_ge_ptnr_resps_rec.partner_id = ' || l_ge_ptnr_resps_rec.partner_id);
6229                Debug_Log('manage_resp_on_address_change: l_ge_ptnr_resps_rec.user_role_code = ' || l_ge_ptnr_resps_rec.user_role_code);
6230                Debug_Log('manage_resp_on_address_change: l_ge_ptnr_resps_rec.program_id = ' || l_ge_ptnr_resps_rec.program_id);
6231                Debug_Log('manage_resp_on_address_change: l_ge_ptnr_resps_rec.responsibility_id = ' || l_ge_ptnr_resps_rec.responsibility_id);
6232                Debug_Log('manage_resp_on_address_change: l_ge_ptnr_resps_rec.source_resp_map_rule_id = ' || l_ge_ptnr_resps_rec.source_resp_map_rule_id);
6233                Debug_Log('manage_resp_on_address_change: l_ge_ptnr_resps_rec.resp_type_code = ' || l_ge_ptnr_resps_rec.resp_type_code);
6234             END IF;
6235 
6236             PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps(
6237                 p_api_version_number         => p_api_version_number
6238                ,p_init_msg_list              => FND_API.G_FALSE
6239                ,p_commit                     => FND_API.G_FALSE
6240                ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
6241 
6242                ,x_return_status              => x_return_status
6243                ,x_msg_count                  => x_msg_count
6244                ,x_msg_data                   => x_msg_data
6245                ,p_ge_ptnr_resps_rec          => l_ge_ptnr_resps_rec
6246                ,x_ptnr_resp_id               => l_ptnr_resp_id
6247             );
6248             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
6249                RAISE FND_API.G_EXC_ERROR;
6250             END IF;
6251          END IF; -- End of IF (l_responsibility_id is not null) and (l_resp_map_rule_id is not null)
6252       END LOOP; -- End of FOR y IN c_get_resp_info(x.partner_id)
6253 
6254       -- Check if at least one partner responsibility exists in
6255       -- PV_GE_PTNR_RESPS for G_PRIMARY and G_BUSINESS
6256       -- check for G_PRIMARY first
6257       OPEN c_check_prgm_resp_exist(x.partner_id, G_PRIMARY);
6258       FETCH c_check_prgm_resp_exist INTO l_exist;
6259       IF (c_check_prgm_resp_exist%NOTFOUND) THEN
6260          -- Get the new default resp, assign it to the users, and add a new
6261          -- row into pv_ge_ptnr_resps
6262          IF (PV_DEBUG_HIGH_ON) THEN
6263             Debug_Log('manage_resp_on_address_change: c_check_prgm_resp_exist%NOTFOUND - G_PRIMARY');
6264          END IF;
6265          get_default_assign_addrow(
6266              p_api_version_number         => p_api_version_number
6267             ,p_init_msg_list              => FND_API.G_FALSE
6268             ,p_commit                     => FND_API.G_FALSE
6269             ,x_return_status              => x_return_status
6270             ,x_msg_count                  => x_msg_count
6271             ,x_msg_data                   => x_msg_data
6272             ,p_user_role_code             => G_PRIMARY
6273             ,p_user_ids_tbl               => primary_user_ids_tbl
6274             ,p_partner_id                 => x.partner_id
6275          );
6276          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
6277             CLOSE c_check_prgm_resp_exist;
6278             RAISE FND_API.G_EXC_ERROR;
6279          END IF;
6280       END IF;
6281       CLOSE c_check_prgm_resp_exist;
6282 
6283       -- check for G_BUSINESS
6284       OPEN c_check_prgm_resp_exist(x.partner_id, G_BUSINESS);
6285       FETCH c_check_prgm_resp_exist INTO l_exist;
6286       IF (c_check_prgm_resp_exist%NOTFOUND) THEN
6287          -- Get the new default resp, assign it to the users, and add a new
6288          -- row into pv_ge_ptnr_resps
6289          IF (PV_DEBUG_HIGH_ON) THEN
6290             Debug_Log('manage_resp_on_address_change: c_check_prgm_resp_exist%NOTFOUND - G_BUSINESS');
6291          END IF;
6292          get_default_assign_addrow(
6293              p_api_version_number         => p_api_version_number
6294             ,p_init_msg_list              => FND_API.G_FALSE
6295             ,p_commit                     => FND_API.G_FALSE
6296             ,x_return_status              => x_return_status
6297             ,x_msg_count                  => x_msg_count
6298             ,x_msg_data                   => x_msg_data
6299             ,p_user_role_code             => G_BUSINESS
6300             ,p_user_ids_tbl               => business_user_ids_tbl
6301             ,p_partner_id                 => x.partner_id
6302          );
6303          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
6304             CLOSE c_check_prgm_resp_exist;
6305             RAISE FND_API.G_EXC_ERROR;
6306          END IF;
6307       END IF; -- End of IF (c_check_prgm_resp_exist%NOTFOUND)
6308       CLOSE c_check_prgm_resp_exist;
6309    END LOOP; -- End of FOR x IN c_get_partner_id
6310 
6311    -- Check for commit
6312    IF FND_API.to_boolean(p_commit) THEN
6313       COMMIT;
6314    END IF;
6315 
6316    FND_MSG_PUB.count_and_get(
6317       p_encoded => FND_API.g_false
6318      ,p_count   => x_msg_count
6319      ,p_data    => x_msg_data
6320    );
6321 
6322 EXCEPTION
6323    WHEN PVX_Utility_PVT.resource_locked THEN
6324      x_return_status := FND_API.g_ret_sts_error;
6325      PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
6326 
6327    WHEN FND_API.G_EXC_ERROR THEN
6328      ROLLBACK TO manage_resp_on_address_change;
6329      x_return_status := FND_API.G_RET_STS_ERROR;
6330      -- Standard call to get message count and if count=1, get the message
6331      FND_MSG_PUB.Count_And_Get (
6332             p_encoded => FND_API.G_FALSE,
6333             p_count   => x_msg_count,
6334             p_data    => x_msg_data
6335      );
6336 
6337    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6338      ROLLBACK TO manage_resp_on_address_change;
6339      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6340      -- Standard call to get message count and if count=1, get the message
6341      FND_MSG_PUB.Count_And_Get (
6342             p_encoded => FND_API.G_FALSE,
6343             p_count => x_msg_count,
6344             p_data  => x_msg_data
6345      );
6346 
6347    WHEN OTHERS THEN
6348      ROLLBACK TO manage_resp_on_address_change;
6349      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6350      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6351      THEN
6352         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
6353      END IF;
6354      -- Standard call to get message count and if count=1, get the message
6355      FND_MSG_PUB.Count_And_Get (
6356             p_encoded => FND_API.G_FALSE,
6357             p_count => x_msg_count,
6358             p_data  => x_msg_data
6359      );
6360 END manage_resp_on_address_change;
6361 
6362 /*
6363  * revoke_default_resp
6364  * This public API will be called when partner status changes from A to I
6365  * after the call to PV_Pg_Memberships_PVT.Terminate_ptr_memberships
6366  * Because after the the call PV_Pg_Memberships_PVT.Terminate_ptr_memberships
6367  * at least one responsibility will be assigned to the users, if the
6368  * partner is inactivated, we want to revoke all the responsibilities.
6369  */
6370 PROCEDURE revoke_default_resp (
6371     p_api_version_number         IN   NUMBER
6372    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
6373    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
6374    ,x_return_status              OUT  NOCOPY  VARCHAR2
6375    ,x_msg_count                  OUT  NOCOPY  NUMBER
6376    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
6377    ,p_partner_id                 IN   NUMBER
6378 )
6379 IS
6380    CURSOR c_get_default_resp IS
6381       SELECT ptnr_resp_id, user_role_code, responsibility_id, object_version_number
6382       FROM   pv_ge_ptnr_resps
6383       WHERE  partner_id = p_partner_id
6384       AND    program_id is null
6385       AND    resp_type_code = G_PROGRAM;
6386 
6387    l_api_name                  CONSTANT  VARCHAR2(30) := 'revoke_default_resp';
6388    l_api_version_number        CONSTANT NUMBER   := 1.0;
6389    primary_user_ids_tbl        JTF_NUMBER_TABLE;
6390    business_user_ids_tbl       JTF_NUMBER_TABLE;
6391 
6392 BEGIN
6393    ---- Initialize----------------
6394 
6395    -- Standard Start of API savepoint
6396    SAVEPOINT revoke_default_resp;
6397 
6398    -- Standard call to check for call compatibility.
6399    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
6400                                       ,p_api_version_number
6401                                       ,l_api_name
6402                                       ,G_PKG_NAME
6403                                       )
6404    THEN
6405        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
6406    END IF;
6407 
6408    -- Initialize message list if p_init_msg_list is set to TRUE.
6409    IF Fnd_Api.to_Boolean( p_init_msg_list )
6410    THEN
6411       Fnd_Msg_Pub.initialize;
6412    END IF;
6413    /*
6414    Pvx_Utility_Pvt.debug_message('g_log_to_file... = ' || g_log_to_file);
6415 
6416    FND_MESSAGE.set_name('PV', 'PV_DEBUG_MESSAGE');
6417    FND_MESSAGE.set_token('TEXT', g_log_to_file);
6418    FND_MSG_PUB.add;
6419    */
6420    -- Debug Message
6421    IF (PV_DEBUG_HIGH_ON) THEN
6422       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
6423       WRITE_LOG(l_api_name, 'PRIVATE API: ' || l_api_name || ' - START');
6424    END IF;
6425 
6426    -- Initialize API return status to SUCCESS
6427    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
6428 
6429    -- Get all users of the partner_id and the user_role_code.
6430    primary_user_ids_tbl := get_partner_users_2(p_partner_id, G_PRIMARY);
6431    business_user_ids_tbl := get_partner_users_2(p_partner_id, G_BUSINESS);
6432 
6433    FOR x IN c_get_default_resp LOOP
6434       IF (x.user_role_code = G_PRIMARY) THEN
6435          IF (PV_DEBUG_HIGH_ON) THEN
6436             Debug_Log('revoke_default_resp: x.responsibility_id = ' || x.responsibility_id);
6437             WRITE_LOG(l_api_name, 'revoke_default_resp: x.responsibility_id = ' || x.responsibility_id);
6438          END IF;
6439          revoke_resp(
6440              p_api_version_number         => p_api_version_number
6441             ,p_init_msg_list              => FND_API.G_FALSE
6442             ,p_commit                     => p_commit
6443             ,p_user_id                    => primary_user_ids_tbl
6444             ,p_resp_id                    => x.responsibility_id
6445             ,x_return_status              => x_return_status
6446             ,x_msg_count                  => x_msg_count
6447             ,x_msg_data                   => x_msg_data
6448          );
6449          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
6450             RAISE FND_API.G_EXC_ERROR;
6451          END IF;
6452       ELSIF (x.user_role_code = G_BUSINESS) THEN
6453          IF (PV_DEBUG_HIGH_ON) THEN
6454             Debug_Log('revoke_default_resp: x.responsibility_id = ' || x.responsibility_id);
6455             WRITE_LOG(l_api_name, 'revoke_default_resp: x.responsibility_id = ' || x.responsibility_id);
6456          END IF;
6457          revoke_resp(
6458              p_api_version_number         => p_api_version_number
6459             ,p_init_msg_list              => FND_API.G_FALSE
6460             ,p_commit                     => p_commit
6461             ,p_user_id                    => business_user_ids_tbl
6462             ,p_resp_id                    => x.responsibility_id
6463             ,x_return_status              => x_return_status
6464             ,x_msg_count                  => x_msg_count
6465             ,x_msg_data                   => x_msg_data
6466          );
6467          IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
6468             RAISE FND_API.G_EXC_ERROR;
6469          END IF;
6470       END IF;
6471 
6472       /****
6473        * API to delete the row with ptnr_resp_id = x.ptnr_resp_id from pv_partner_memberships
6474        ****/
6475       IF (PV_DEBUG_HIGH_ON) THEN
6476          Debug_Log('revoke_default_resp: before calling PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps');
6477          Debug_Log('revoke_default_resp: x.ptnr_resp_id = ' || x.ptnr_resp_id);
6478          WRITE_LOG(l_api_name, 'revoke_default_resp: before calling PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps');
6479          WRITE_LOG(l_api_name, 'revoke_default_resp: x.ptnr_resp_id = ' || x.ptnr_resp_id);
6480       END IF;
6481 
6482       PV_Ge_Ptnr_Resps_PVT.Delete_Ge_Ptnr_Resps(
6483           p_api_version_number         => p_api_version_number
6484          ,p_init_msg_list              => FND_API.G_FALSE
6485          ,p_commit                     => FND_API.G_FALSE
6486          ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
6487 
6488          ,x_return_status              => x_return_status
6489          ,x_msg_count                  => x_msg_count
6490          ,x_msg_data                   => x_msg_data
6491          ,p_ptnr_resp_id               => x.ptnr_resp_id
6492          ,p_object_version_number      => x.object_version_number
6493       );
6494       IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
6495          RAISE FND_API.G_EXC_ERROR;
6496       END IF;
6497    END LOOP;
6498       -- Check for commit
6499    IF FND_API.to_boolean(p_commit) THEN
6500       COMMIT;
6501    END IF;
6502 
6503    FND_MSG_PUB.count_and_get(
6504       p_encoded => FND_API.g_false
6505      ,p_count   => x_msg_count
6506      ,p_data    => x_msg_data
6507    );
6508 
6509 EXCEPTION
6510 
6511    WHEN PVX_Utility_PVT.resource_locked THEN
6512      x_return_status := FND_API.g_ret_sts_error;
6513      PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
6514 
6515    WHEN FND_API.G_EXC_ERROR THEN
6516      ROLLBACK TO revoke_default_resp;
6517      x_return_status := FND_API.G_RET_STS_ERROR;
6518      -- Standard call to get message count and if count=1, get the message
6519      FND_MSG_PUB.Count_And_Get (
6520             p_encoded => FND_API.G_FALSE,
6521             p_count   => x_msg_count,
6522             p_data    => x_msg_data
6523      );
6524 
6525    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6526      ROLLBACK TO revoke_default_resp;
6527      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6528      -- Standard call to get message count and if count=1, get the message
6529      FND_MSG_PUB.Count_And_Get (
6530             p_encoded => FND_API.G_FALSE,
6531             p_count => x_msg_count,
6532             p_data  => x_msg_data
6533      );
6534 
6535    WHEN OTHERS THEN
6536      ROLLBACK TO revoke_default_resp;
6537      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6538      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6539      THEN
6540         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
6541      END IF;
6542      -- Standard call to get message count and if count=1, get the message
6543      FND_MSG_PUB.Count_And_Get (
6544             p_encoded => FND_API.G_FALSE,
6545             p_count => x_msg_count,
6546             p_data  => x_msg_data
6547      );
6548 END revoke_default_resp;
6549 
6550 /*
6551 * adjust_user_resps
6552 * input: p_user_id, p_resp_id, p_app_id
6553 * assigning the user p_user_id with resp p_resp_id for application p_app_id
6554 *
6555 */
6556 
6557 PROCEDURE adjust_user_resps
6558 (
6559     p_api_version_number         IN   NUMBER
6560    ,p_init_msg_list              IN   VARCHAR2  := Fnd_Api.g_false
6561    ,p_commit                     IN   VARCHAR2  := Fnd_Api.g_false
6562    ,x_return_status              OUT  NOCOPY  VARCHAR2
6563    ,x_msg_count                  OUT  NOCOPY  NUMBER
6564    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
6565    ,p_user_id			 	         IN   NUMBER
6566    ,p_def_resp_id		 			   IN   NUMBER
6567    ,p_user_role_code             IN   VARCHAR2
6568    ,p_partner_id				 	   IN   NUMBER
6569 )
6570 IS
6571    CURSOR c_get_resp_id IS
6572       SELECT responsibility_id
6573       FROM   pv_ge_ptnr_resps
6574       WHERE  partner_id = p_partner_id
6575       AND    user_role_code = p_user_role_code
6576       AND    resp_type_code = G_PROGRAM;
6577 
6578    CURSOR c_get_user_resp_groups IS
6579       SELECT  user_id, responsibility_id, responsibility_application_id, security_group_id, start_date, description
6580       FROM    fnd_user_resp_groups
6581       WHERE   user_id = p_user_id
6582       AND     responsibility_id = p_def_resp_id;
6583 
6584    l_api_name                  CONSTANT  VARCHAR2(30) := 'adjust_user_resps';
6585    l_api_version_number        CONSTANT NUMBER   := 1.0;
6586    l_exist                    NUMBER;
6587 
6588 BEGIN
6589   ---- Initialize----------------
6590 
6591    -- Standard Start of API savepoint
6592    SAVEPOINT assign_user_resps;
6593 
6594    -- Standard call to check for call compatibility.
6595    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
6596                                       ,p_api_version_number
6597                                       ,l_api_name
6598                                       ,G_PKG_NAME
6599                                       )
6600    THEN
6601        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
6602    END IF;
6603 
6604    -- Initialize message list if p_init_msg_list is set to TRUE.
6605    IF Fnd_Api.to_Boolean( p_init_msg_list )
6606    THEN
6607       Fnd_Msg_Pub.initialize;
6608    END IF;
6609 
6610    -- Debug Message
6611    IF (PV_DEBUG_HIGH_ON) THEN
6612       Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
6613    END IF;
6614 
6615    -- Initialize API return status to SUCCESS
6616    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
6617 
6618    FOR x IN c_get_resp_id LOOP
6619       IF (PV_DEBUG_HIGH_ON) THEN
6620          Debug_Log('adjust_user_resps: x.responsibility_id: ' || x.responsibility_id);
6621       END IF;
6622       IF (x.responsibility_id = p_def_resp_id) THEN
6623          -- The p_def_resp_id is the default resp in pv_ge_ptnr_resps
6624          -- Do nothing
6625          IF (PV_DEBUG_HIGH_ON) THEN
6626             Debug_Log('adjust_user_resps: c_same_resp_exists%NOTFOUND');
6627          END IF;
6628       ELSE
6629          -- The p_def_resp_id is not the default resp in pv_ge_ptnr_resps
6630          -- Revoke the original default resp in pv_ge_ptnr_resps.
6631          -- Assign p_def_resp_id to the user.
6632          IF (PV_DEBUG_HIGH_ON) THEN
6633             Debug_Log('adjust_user_resps: !c_same_resp_exists%NOTFOUND');
6634          END IF;
6635 
6636          FOR y IN c_get_user_resp_groups LOOP
6637             -- Debug Message
6638             IF (PV_DEBUG_HIGH_ON) THEN
6639                Debug_Log('adjust_user_resps: y.responsibility_id = ' || y.responsibility_id);
6640                Debug_Log('adjust_user_resps: y.user_id = ' || y.user_id);
6641                Debug_Log('adjust_user_resps: y.responsibility_application_id = ' || y.responsibility_application_id);
6642                Debug_Log('adjust_user_resps: y.security_group_id = ' || y.security_group_id);
6643                Debug_Log('adjust_user_resps: y.start_date = ' || y.start_date);
6644                Debug_Log('adjust_user_resps: y.description = ' || y.description);
6645             END IF;
6646 
6647             revoke_resp(
6648                 p_api_version_number         => p_api_version_number
6649                ,p_init_msg_list              => FND_API.G_FALSE
6650                ,p_commit                     => FND_API.G_FALSE
6651                ,p_user_id                    => y.user_id
6652                ,p_resp_id                    => y.responsibility_id
6653                ,p_app_id                     => y.responsibility_application_id
6654                ,p_security_group_id          => y.security_group_id
6655                ,p_start_date                 => y.start_date
6656                ,p_description                => y.description
6657                ,x_return_status              => x_return_status
6658                ,x_msg_count                  => x_msg_count
6659                ,x_msg_data                   => x_msg_data
6660             );
6661             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
6662                RAISE FND_API.G_EXC_ERROR;
6663             END IF;
6664 
6665             assign_resp (
6666                 p_api_version_number         => p_api_version_number
6667                ,p_init_msg_list              => FND_API.G_FALSE
6668                ,p_commit                     => FND_API.G_FALSE
6669                ,p_user_id                    => p_user_id
6670                ,p_resp_id                    => x.responsibility_id
6671                ,p_app_id                     => 691
6672                ,x_return_status              => x_return_status
6673                ,x_msg_count                  => x_msg_count
6674                ,x_msg_data                   => x_msg_data
6675             );
6676             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
6677                RAISE FND_API.G_EXC_ERROR;
6678             END IF;
6679          END LOOP;
6680       END IF;
6681    END LOOP;
6682 
6683    -- Check for commit
6684    IF FND_API.to_boolean(p_commit) THEN
6685       COMMIT;
6686    END IF;
6687 
6688    FND_MSG_PUB.count_and_get(
6689       p_encoded => FND_API.g_false
6690      ,p_count   => x_msg_count
6691      ,p_data    => x_msg_data
6692    );
6693 
6694 EXCEPTION
6695 
6696    WHEN PVX_Utility_PVT.resource_locked THEN
6697      x_return_status := FND_API.g_ret_sts_error;
6698      PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
6699 
6700    WHEN FND_API.G_EXC_ERROR THEN
6701      ROLLBACK TO assign_user_resps;
6702      x_return_status := FND_API.G_RET_STS_ERROR;
6703      -- Standard call to get message count and if count=1, get the message
6704      FND_MSG_PUB.Count_And_Get (
6705             p_encoded => FND_API.G_FALSE,
6706             p_count   => x_msg_count,
6707             p_data    => x_msg_data
6708      );
6709 
6710    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6711      ROLLBACK TO assign_user_resps;
6712      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6713      -- Standard call to get message count and if count=1, get the message
6714      FND_MSG_PUB.Count_And_Get (
6715             p_encoded => FND_API.G_FALSE,
6716             p_count => x_msg_count,
6717             p_data  => x_msg_data
6718      );
6719 
6720    WHEN OTHERS THEN
6721      ROLLBACK TO assign_user_resps;
6722      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6723      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6724      THEN
6725         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
6726      END IF;
6727      -- Standard call to get message count and if count=1, get the message
6728      FND_MSG_PUB.Count_And_Get (
6729             p_encoded => FND_API.G_FALSE,
6730             p_count => x_msg_count,
6731             p_data  => x_msg_data
6732      );
6733 
6734 END adjust_user_resps;
6735 
6736 procedure exec_cre_upd_del_resp_mapping (
6737     ERRBUF                       OUT  NOCOPY VARCHAR2
6738    ,RETCODE                      OUT  NOCOPY VARCHAR2
6739    ,p_action                     IN   VARCHAR2
6740    ,p_source_resp_map_rule_id    IN   NUMBER
6741 )
6742 IS
6743    l_api_version_number       NUMBER;
6744    l_init_msg_list            VARCHAR2(1);
6745    l_return_status            VARCHAR2(1);
6746    l_msg_count                NUMBER;
6747    l_msg_data                 VARCHAR2(32767);
6748 
6749 BEGIN
6750    g_log_to_file := 'Y';
6751    Debug_Log('exec_cre_upd_del_resp_mapping: BEGIN');
6752    Debug_Log('exec_cre_upd_del_resp_mapping: p_action = ' || p_action);
6753    Debug_Log('exec_cre_upd_del_resp_mapping: p_source_resp_map_rule_id = ' || p_source_resp_map_rule_id);
6754 
6755    IF (p_action IS NULL or (p_action <> 'CRE' and p_action <> 'DEL' and p_action <> 'UPD')) THEN
6756       RAISE bad_action;
6757    ELSIF (p_source_resp_map_rule_id IS NULL) THEN
6758       RAISE no_source_resp_map_rule_id;
6759    END IF;
6760 
6761    l_api_version_number := 1.0;
6762    l_init_msg_list := FND_API.g_true;
6763 
6764    IF (p_action = 'CRE') THEN
6765      Debug_Log('exec_cre_upd_del_resp_mapping: execute create_resp_mapping');
6766      create_resp_mapping(
6767          p_api_version_number         => l_api_version_number
6768         ,p_init_msg_list              => FND_API.G_FALSE
6769         ,x_return_status              => l_return_status
6770         ,x_msg_count                  => l_msg_count
6771         ,x_msg_data                   => l_msg_data
6772         ,p_source_resp_map_rule_id    => p_source_resp_map_rule_id
6773       );
6774    ELSIF (p_action = 'DEL') THEN
6775     Debug_Log('exec_cre_upd_del_resp_mapping: execute delete_resp_mapping');
6776       delete_resp_mapping(
6777          p_api_version_number         => l_api_version_number
6778         ,p_init_msg_list              => FND_API.G_FALSE
6779         ,x_return_status              => l_return_status
6780         ,x_msg_count                  => l_msg_count
6781         ,x_msg_data                   => l_msg_data
6782         ,p_source_resp_map_rule_id    => p_source_resp_map_rule_id
6783       );
6784    ELSIF (p_action = 'UPD') THEN
6785      Debug_Log('exec_cre_upd_del_resp_mapping: execute update_resp_mapping');
6786      update_resp_mapping(
6787          p_api_version_number         => l_api_version_number
6788         ,p_init_msg_list              => FND_API.G_FALSE
6789         ,x_return_status              => l_return_status
6790         ,x_msg_count                  => l_msg_count
6791         ,x_msg_data                   => l_msg_data
6792         ,p_source_resp_map_rule_id    => p_source_resp_map_rule_id
6793       );
6794    END IF;
6795 
6796    IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
6797       Debug_Log('exec_cre_upd_del_resp_mapping: l_return_status <> FND_API.G_RET_STS_SUCCESS');
6798       RAISE exc_error;
6799    END IF;
6800 
6801    Debug_Log('exec_cre_upd_del_resp_mapping: END');
6802    RETCODE := '0';
6803    COMMIT;
6804 
6805 EXCEPTION
6806 WHEN bad_action THEN
6807    Debug_Log('------------bad_action-----------------');
6808    RETCODE := '2';
6809    ROLLBACK;
6810 
6811 WHEN no_source_resp_map_rule_id THEN
6812    Debug_Log('------------no_source_resp_map_rule_id-----------------');
6813    RETCODE := '2';
6814    ROLLBACK;
6815 
6816 WHEN exc_error THEN
6817    Debug_Log('------------exc_error-----------------');
6818    IF l_msg_count > 1 THEN
6819       fnd_msg_pub.reset;
6820       FOR i IN 1..l_msg_count LOOP
6821          Debug_Log(fnd_msg_pub.get(p_encoded => fnd_api.g_false));
6822       END LOOP;
6823    ELSE
6824       Debug_Log(l_msg_data);
6825    END IF;
6826    RETCODE := '2';
6827    ROLLBACK;
6828 
6829 WHEN OTHERS THEN
6830    Debug_Log(sqlerrm);
6831    RETCODE := sqlcode;
6832    ERRBUF := sqlerrm;
6833    ROLLBACK;
6834 
6835 END exec_cre_upd_del_resp_mapping;
6836 
6837 procedure exec_asgn_or_rvok_user_resps (
6838     ERRBUF                       OUT  NOCOPY VARCHAR2
6839    ,RETCODE                      OUT  NOCOPY VARCHAR2
6840    ,p_action                     IN   VARCHAR2
6841    ,p_user_name                  IN   VARCHAR2
6842 )
6843 IS
6844    l_api_version_number       NUMBER;
6845    l_init_msg_list            VARCHAR2(1);
6846    l_return_status            VARCHAR2(1);
6847    l_msg_count                NUMBER;
6848    l_msg_data                 VARCHAR2(32767);
6849 
6850 BEGIN
6851    g_log_to_file := 'Y';
6852 
6853    Debug_Log('exec_asgn_or_rvok_user_resps: BEGIN');
6854    Debug_Log('exec_asgn_or_rvok_user_resps: p_action = ' || p_action);
6855    Debug_Log('exec_asgn_or_rvok_user_resps: p_user_name = ' || p_user_name);
6856 
6857    IF (p_action IS NULL or (p_action <> 'A' and p_action <> 'R')) THEN
6858       RAISE bad_action;
6859    ELSIF (p_user_name IS NULL) THEN
6860       RAISE no_user_name;
6861    END IF;
6862 
6863    l_api_version_number := 1.0;
6864    l_init_msg_list := FND_API.g_true;
6865 
6866    IF (p_action = 'A') THEN
6867     Debug_Log('exec_asgn_or_rvok_user_resps: execute assign_user_resps');
6868      assign_user_resps(
6869          p_api_version_number         => l_api_version_number
6870         ,p_init_msg_list              => FND_API.G_FALSE
6871         ,x_return_status              => l_return_status
6872         ,x_msg_count                  => l_msg_count
6873         ,x_msg_data                   => l_msg_data
6874         ,p_user_name                  => p_user_name
6875       );
6876    ELSE
6877     Debug_Log('exec_asgn_or_rvok_user_resps: execute revoke_user_resps');
6878       revoke_user_resps(
6879          p_api_version_number         => l_api_version_number
6880         ,p_init_msg_list              => FND_API.G_FALSE
6881         ,x_return_status              => l_return_status
6882         ,x_msg_count                  => l_msg_count
6883         ,x_msg_data                   => l_msg_data
6884         ,p_user_name                  => p_user_name
6885       );
6886    END IF;
6887 
6888    IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
6889       Debug_Log('exec_asgn_or_rvok_user_resps: l_return_status <> FND_API.G_RET_STS_SUCCESS');
6890       RAISE exc_error;
6891    END IF;
6892 
6893    Debug_Log('exec_asgn_or_rvok_user_resps: END');
6894    RETCODE := '0';
6895    COMMIT;
6896 
6897 EXCEPTION
6898 WHEN bad_action THEN
6899    Debug_Log('------------bad_action-----------------');
6900    RETCODE := '2';
6901    ROLLBACK;
6902 
6903 WHEN no_user_name THEN
6904    Debug_Log('------------no_user_name-----------------');
6905    RETCODE := '2';
6906    ROLLBACK;
6907 
6908 WHEN exc_error THEN
6909    Debug_Log('------------exc_error-----------------');
6910    IF l_msg_count > 1 THEN
6911       fnd_msg_pub.reset;
6912       FOR i IN 1..l_msg_count LOOP
6913          Debug_Log(fnd_msg_pub.get(p_encoded => fnd_api.g_false));
6914       END LOOP;
6915    ELSE
6916       Debug_Log(l_msg_data);
6917    END IF;
6918    RETCODE := '2';
6919    ROLLBACK;
6920 
6921 WHEN OTHERS THEN
6922    Debug_Log(sqlerrm);
6923    RETCODE := sqlcode;
6924    ERRBUF := sqlerrm;
6925    ROLLBACK;
6926 
6927 END exec_asgn_or_rvok_user_resps;
6928 
6929 /*****************************
6930  * manage_resp_on_address_change
6931  *****************************/
6932 FUNCTION manage_resp_on_address_change
6933 ( p_subscription_guid  in raw,
6934   p_event              in out NOCOPY wf_event_t
6935 )
6936 RETURN VARCHAR2
6937 IS
6938    l_api_name          CONSTANT VARCHAR2(30) := 'manage_resp_on_address_change';
6939    l_org_id            NUMBER;
6940    l_location_id       NUMBER;
6941    l_partner_id        NUMBER;
6942    l_party_site_id     NUMBER;
6943    l_party_id          NUMBER;
6944    x_return_status     VARCHAR2(10);
6945    x_msg_count         NUMBER;
6946    x_msg_data          VARCHAR2(2000);
6947    l_key         VARCHAR2(240) := p_event.GetEventKey();
6948    CURSOR get_party_id_csr ( p_location_id  IN NUMBER ) IS
6949    SELECT partner_party_id
6950    FROM   pv_partner_profiles prof
6951           , hz_party_sites st
6952           , hz_locations   loc
6953    WHERE  prof.partner_party_id = st.party_id
6954    AND    prof.status = 'A'
6955    AND    st.location_id=loc.location_id
6956    AND    st.identifying_address_flag = 'Y'
6957    AND    st.status='A'
6958    AND    st.location_id= p_location_id;
6959 
6960   CURSOR is_partner_csr (cv_party_site_id NUMBER) IS
6961     SELECT partner_id
6962     FROM   hz_party_sites hzps,
6963            pv_partner_profiles ppp
6964     WHERE  hzps.party_site_id = cv_party_site_id
6965     AND    hzps.status = 'A'
6966     AND    hzps.identifying_address_flag = 'Y'
6967     AND    ppp.partner_party_id = hzps.party_id
6968     AND	   ppp.status = 'A';
6969 
6970  BEGIN
6971    FND_MSG_PUB.initialize;
6972 
6973    IF (PV_DEBUG_HIGH_ON) THEN
6974      WRITE_LOG(l_api_name, 'Start manage_resp_on_address_change');
6975    END IF;
6976    l_location_id         := p_event.GetValueForParameter('LOCATION_ID');
6977    IF (PV_DEBUG_HIGH_ON) THEN
6978      WRITE_LOG(l_api_name, 'l_location_id = ' ||to_char( l_location_id));
6979    END IF;
6980 
6981    x_return_status := FND_API.G_RET_STS_SUCCESS;
6982 
6983    -- modified by pukken to get the partner_party_id from the location_id.
6984    IF ( l_key like 'oracle.apps.ar.hz.Location.update%'  ) THEN
6985       FOR x in get_party_id_csr ( l_location_id ) LOOP
6986          IF (PV_DEBUG_HIGH_ON) THEN
6987            WRITE_LOG(l_api_name, 'partner party_id = ' || to_char(x.partner_party_id) );
6988 	 END IF;
6989          Pv_User_Resp_Pvt.manage_resp_on_address_change (
6990              p_api_version_number      => 1.0
6991             ,p_init_msg_list           => FND_API.G_FALSE
6992             ,p_commit                  => FND_API.G_FALSE
6993             ,x_return_status           => x_return_status
6994             ,x_msg_count               => x_msg_count
6995             ,x_msg_data                => x_msg_data
6996             ,p_org_party_id            => x.partner_party_id
6997          );
6998 	 IF (PV_DEBUG_HIGH_ON) THEN
6999            WRITE_LOG(l_api_name, 'x_return_status = ' || x_return_status || 'x_msg_data is ' || x_msg_data);
7000 	 END IF;
7001       END LOOP;
7002    END IF;
7003    IF (PV_DEBUG_HIGH_ON) THEN
7004      WRITE_LOG(l_api_name, 'After loop call to  manage_resp_on_address_change API');
7005    END IF;
7006 
7007    --jkylee added changes
7008    l_party_site_id := p_event.GetValueForParameter('PARTY_SITE_ID');
7009    IF (PV_DEBUG_HIGH_ON) THEN
7010         WRITE_LOG(l_api_name, ' l_party_site_id   = ' ||  to_char(l_party_site_id)  );
7011    END IF;
7012 
7013    IF ( l_key like 'oracle.apps.ar.hz.PartySite.update%'  ) THEN
7014       IF (PV_DEBUG_HIGH_ON) THEN
7015         WRITE_LOG(l_api_name, 'oracle.apps.ar.hz.PartySite.update event fired');
7016       END IF;
7017 
7018       /* check if the party_id exists in pv_partner_profiles table and
7019          also make sure that the address change is for the location of primary address..
7020          if yes..call resp mapping api
7021       */
7022       OPEN is_partner_csr( l_party_site_id );
7023       FETCH is_partner_csr INTO l_partner_id;
7024       IF is_partner_csr%FOUND THEN
7025       	 CLOSE is_partner_csr;
7026 	 IF (PV_DEBUG_HIGH_ON) THEN
7027       	   WRITE_LOG(l_api_name, 'in party site update evnt before manage update address api call');
7028 	 END IF;
7029       	 Pv_User_Resp_Pvt.manage_resp_on_address_change (
7030              p_api_version_number      => 1.0
7031             ,p_init_msg_list           => FND_API.G_FALSE
7032             ,p_commit                  => FND_API.G_FALSE
7033             ,x_return_status           => x_return_status
7034             ,x_msg_count               => x_msg_count
7035             ,x_msg_data                => x_msg_data
7036             ,p_org_party_id            => l_party_id
7037          );
7038 	 IF (PV_DEBUG_HIGH_ON) THEN
7039            WRITE_LOG(l_api_name, 'party site update subscription x_return_status = ' || x_return_status || 'x_msg_data is ' || x_msg_data);
7040 	 END IF;
7041       END IF;-- end of if , if the party is an active partner
7042    END IF; -- end of if , if the event is PartySite.update
7043 
7044    IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
7045       RAISE FND_API.G_EXC_ERROR;
7046    END IF;
7047    RETURN 'SUCCESS';
7048 EXCEPTION
7049  WHEN FND_API.G_EXC_ERROR THEN
7050     IF (PV_DEBUG_HIGH_ON) THEN
7051       WRITE_LOG(l_api_name, 'G_EXC_ERROR');
7052     END IF;
7053     WF_CORE.CONTEXT('Pv_User_Resp_Pvt', 'manage_resp_on_address_change', p_event.getEventName(), p_subscription_guid);
7054     WF_EVENT.setErrorInfo(p_event, 'Error from manage_resp_on_address_change');
7055     RETURN 'ERROR';
7056  WHEN OTHERS THEN
7057     IF (PV_DEBUG_HIGH_ON) THEN
7058       WRITE_LOG(l_api_name, 'OTHER');
7059     END IF;
7060     WF_CORE.CONTEXT('Pv_User_Resp_Pvt', 'manage_resp_on_address_change', p_event.getEventName(), p_subscription_guid);
7061     WF_EVENT.setErrorInfo(p_event, 'ERROR');
7062     RETURN 'ERROR';
7063 END;
7064 
7065 /*
7066  * manage_merged_party_memb_resp
7067  * This public API will take care of managing user responsibilities when
7068  * two parties are merged.
7069  */
7070 PROCEDURE manage_merged_party_memb_resp(
7071     p_api_version_number         IN   NUMBER
7072    ,p_init_msg_list              IN   VARCHAR2     := FND_API.G_FALSE
7073    ,p_commit                     IN   VARCHAR2     := FND_API.G_FALSE
7074    ,x_return_status              OUT  NOCOPY  VARCHAR2
7075    ,x_msg_count                  OUT  NOCOPY  NUMBER
7076    ,x_msg_data                   OUT  NOCOPY  VARCHAR2
7077    ,p_from_partner_id            IN   NUMBER
7078    ,p_to_partner_id              IN   NUMBER
7079 )
7080 IS
7081    -- Check if there is no row for business user in pv_ge_ptnr_resps but there are business users
7082    CURSOR c_is_business_user_exist IS
7083       SELECT 1
7084       FROM   dual
7085       WHERE  EXISTS (
7086              SELECT 1
7087              FROM   pv_partner_business_users_v
7088              WHERE  partner_id = p_from_partner_id);
7089 
7090    CURSOR c_is_business_resp_exist IS
7091       SELECT  1
7092       FROM    pv_ge_ptnr_resps
7093       WHERE   partner_id = p_to_partner_id
7094       and     user_role_code = 'BUSINESS';
7095 
7096    CURSOR c_get_program_id IS
7097       SELECT program_id, partner_id
7098       FROM   pv_pg_memberships
7099       WHERE  partner_id = p_to_partner_id
7100       AND    membership_status_code = 'ACTIVE';
7101 
7102    CURSOR c_get_to_resp_info IS
7103       SELECT     responsibility_id, user_role_code
7104       FROM       pv_ge_ptnr_resps
7105       WHERE      partner_id = p_to_partner_id;
7106 
7107    l_api_name                  CONSTANT  VARCHAR2(30) := 'manage_merged_party_memb_resp';
7108    l_api_version_number        CONSTANT NUMBER   := 1.0;
7109    l_exist                     NUMBER;
7110    l_last_program_id           NUMBER := 0;
7111    l_user_ids_tbl              JTF_NUMBER_TABLE;
7112    l_resp_exist                VARCHAR(1) := 'N';
7113    l_responsibility_id         NUMBER;
7114    l_resp_map_rule_id          NUMBER;
7115    l_ge_ptnr_resps_rec         PV_Ge_Ptnr_Resps_PVT.ge_ptnr_resps_rec_type;
7116    l_ptnr_resp_id              NUMBER;
7117 
7118 BEGIN
7119   ---- Initialize----------------
7120 
7121    -- Standard Start of API savepoint
7122    SAVEPOINT manage_merged_party_memb_resp;
7123 
7124    -- Standard call to check for call compatibility.
7125    IF NOT Fnd_Api.Compatible_API_Call (l_api_version_number
7126                                       ,p_api_version_number
7127                                       ,l_api_name
7128                                       ,G_PKG_NAME
7129                                       )
7130    THEN
7131        RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
7132    END IF;
7133 
7134    -- Initialize message list if p_init_msg_list is set to TRUE.
7135    IF Fnd_Api.to_Boolean( p_init_msg_list )
7136    THEN
7137       Fnd_Msg_Pub.initialize;
7138    END IF;
7139 
7140    -- Debug Message
7141    Debug_Log('PRIVATE API: ' || l_api_name || ' - START');
7142 
7143    -- Initialize API return status to SUCCESS
7144    x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
7145 
7146    g_log_to_file := 'Y';
7147 
7148    revoke_default_resp (
7149        p_api_version_number      => 1.0
7150       ,p_init_msg_list           => FND_API.G_FALSE
7151       ,p_commit                  => FND_API.G_FALSE
7152       ,x_return_status           => x_return_status
7153       ,x_msg_count               => x_msg_count
7154       ,x_msg_data                => x_msg_data
7155       ,p_partner_id              => p_from_partner_id
7156    );
7157    IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
7158       RAISE FND_API.G_EXC_ERROR;
7159    END IF;
7160 
7161    FOR a IN c_is_business_user_exist LOOP
7162       Debug_Log('manage_merged_party_memb_resp: start to create resp for business users');
7163 
7164       OPEN c_is_business_resp_exist;
7165       FETCH c_is_business_resp_exist INTO l_exist;
7166       -- If there is no row for business user responsibility,
7167       -- get the correct resp and insert into pv_ge_ptnr_resps
7168       IF (c_is_business_resp_exist%NOTFOUND) THEN
7169          Debug_Log('manage_ter_exp_memb_resp: c_is_business_resp_exist%NOTFOUND');
7170 
7171          FOR x IN c_get_program_id LOOP
7172             l_responsibility_id := null;
7173             l_resp_map_rule_id := null;
7174             get_program_resp(
7175                 p_api_version_number         => p_api_version_number
7176                ,p_init_msg_list              => FND_API.G_FALSE
7177                ,p_commit                     => FND_API.G_FALSE
7178                ,x_return_status              => x_return_status
7179                ,x_msg_count                  => x_msg_count
7180                ,x_msg_data                   => x_msg_data
7181                ,p_partner_id                 => x.partner_id
7182                ,p_user_role_code             => 'BUSINESS'
7183                ,p_program_id                 => x.program_id
7184                ,x_responsibility_id          => l_responsibility_id
7185                ,x_resp_map_rule_id           => l_resp_map_rule_id
7186             );
7187 
7188             Debug_Log('manage_merged_party_memb_resp: l_responsibility_id = ' || l_responsibility_id);
7189             Debug_Log('manage_merged_party_memb_resp: l_resp_map_rule_id = ' || l_resp_map_rule_id);
7190 
7191             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
7192                RAISE FND_API.G_EXC_ERROR;
7193             END IF;
7194 
7195             IF (l_responsibility_id is not null) and (l_resp_map_rule_id is not null) THEN
7196                l_resp_exist := 'Y';
7197                /****
7198                 * API to add a row to pv_ge_ptnr_resps
7199                 ****/
7200                l_ge_ptnr_resps_rec.partner_id := x.partner_id;
7201                l_ge_ptnr_resps_rec.user_role_code := 'BUSINESS';
7202                l_ge_ptnr_resps_rec.program_id := x.program_id;
7203                l_ge_ptnr_resps_rec.responsibility_id := l_responsibility_id;
7204                l_ge_ptnr_resps_rec.source_resp_map_rule_id := l_resp_map_rule_id;
7205                l_ge_ptnr_resps_rec.resp_type_code := G_PROGRAM;
7206 
7207                Debug_Log('manage_merged_party_memb_resp: l_ge_ptnr_resps_rec.partner_id = ' || l_ge_ptnr_resps_rec.partner_id);
7208                Debug_Log('manage_merged_party_memb_resp: l_ge_ptnr_resps_rec.user_role_code = ' || l_ge_ptnr_resps_rec.user_role_code);
7209                Debug_Log('manage_merged_party_memb_resp: l_ge_ptnr_resps_rec.program_id = ' || l_ge_ptnr_resps_rec.program_id);
7210                Debug_Log('manage_merged_party_memb_resp: l_ge_ptnr_resps_rec.responsibility_id = ' || l_ge_ptnr_resps_rec.responsibility_id);
7211                Debug_Log('manage_merged_party_memb_resp: l_ge_ptnr_resps_rec.source_resp_map_rule_id = ' || l_ge_ptnr_resps_rec.source_resp_map_rule_id);
7212                Debug_Log('manage_merged_party_memb_resp: l_ge_ptnr_resps_rec.resp_type_code = ' || l_ge_ptnr_resps_rec.resp_type_code);
7213 
7214                PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps(
7215                    p_api_version_number         => p_api_version_number
7216                   ,p_init_msg_list              => FND_API.G_FALSE
7217                   ,p_commit                     => FND_API.G_FALSE
7218                   ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
7219 
7220                   ,x_return_status              => x_return_status
7221                   ,x_msg_count                  => x_msg_count
7222                   ,x_msg_data                   => x_msg_data
7223                   ,p_ge_ptnr_resps_rec          => l_ge_ptnr_resps_rec
7224                   ,x_ptnr_resp_id               => l_ptnr_resp_id
7225                );
7226                IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
7227                   RAISE FND_API.G_EXC_ERROR;
7228                END IF;
7229             END IF; -- End of IF (l_responsibility_id is not null) and (l_resp_map_rule_id is not null)
7230          END LOOP; -- End of FOR c_get_program_id LOOP
7231 
7232          IF (l_resp_exist = 'N') THEN
7233             get_default_resp(
7234                 p_api_version_number         => p_api_version_number
7235                ,p_init_msg_list              => FND_API.G_FALSE
7236                ,p_commit                     => FND_API.G_FALSE
7237                ,x_return_status              => x_return_status
7238                ,x_msg_count                  => x_msg_count
7239                ,x_msg_data                   => x_msg_data
7240                ,p_partner_id                 => p_to_partner_id
7241                ,p_user_role_code             => 'BUSINESS'
7242                ,x_responsibility_id          => l_responsibility_id
7243                ,x_resp_map_rule_id           => l_resp_map_rule_id
7244             );
7245             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
7246                RAISE FND_API.G_EXC_ERROR;
7247             END IF;
7248             IF (l_responsibility_id is not null) and (l_resp_map_rule_id is not null) THEN
7249                /****
7250                 * API to add a row to pv_ge_ptnr_resps
7251                 ****/
7252                l_ge_ptnr_resps_rec.partner_id := p_to_partner_id;
7253                l_ge_ptnr_resps_rec.user_role_code := 'BUSINESS';
7254                l_ge_ptnr_resps_rec.responsibility_id := l_responsibility_id;
7255                l_ge_ptnr_resps_rec.source_resp_map_rule_id := l_resp_map_rule_id;
7256                l_ge_ptnr_resps_rec.resp_type_code := G_PROGRAM;
7257 
7258                Debug_Log('manage_merged_party_memb_resp: l_ge_ptnr_resps_rec.partner_id = ' || l_ge_ptnr_resps_rec.partner_id);
7259                Debug_Log('manage_merged_party_memb_resp: l_ge_ptnr_resps_rec.user_role_code = ' || l_ge_ptnr_resps_rec.user_role_code);
7260                Debug_Log('manage_merged_party_memb_resp: l_ge_ptnr_resps_rec.responsibility_id = ' || l_ge_ptnr_resps_rec.responsibility_id);
7261                Debug_Log('manage_merged_party_memb_resp: l_ge_ptnr_resps_rec.source_resp_map_rule_id = ' || l_ge_ptnr_resps_rec.source_resp_map_rule_id);
7262                Debug_Log('manage_merged_party_memb_resp: l_ge_ptnr_resps_rec.resp_type_code = ' || l_ge_ptnr_resps_rec.resp_type_code);
7263 
7264                PV_Ge_Ptnr_Resps_PVT.Create_Ge_Ptnr_Resps(
7265                    p_api_version_number         => p_api_version_number
7266                   ,p_init_msg_list              => FND_API.G_FALSE
7267                   ,p_commit                     => FND_API.G_FALSE
7268                   ,p_validation_level           => FND_API.G_VALID_LEVEL_FULL
7269 
7270                   ,x_return_status              => x_return_status
7271                   ,x_msg_count                  => x_msg_count
7272                   ,x_msg_data                   => x_msg_data
7273                   ,p_ge_ptnr_resps_rec          => l_ge_ptnr_resps_rec
7274                   ,x_ptnr_resp_id               => l_ptnr_resp_id
7275                );
7276                IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
7277                   RAISE FND_API.G_EXC_ERROR;
7278                END IF;
7279             ELSE
7280                FND_MESSAGE.set_name('PV', 'PV_NO_DEFAULT_RESP');
7281                FND_MSG_PUB.add;
7282                RAISE FND_API.G_EXC_ERROR;
7283             END IF; -- End of IF (l_responsibility_id is not null) and (l_resp_map_rule_id is not null)
7284          END IF; -- End of IF (l_resp_exist = 'N')
7285       END IF; -- End of IF (c_is_business_user_exist%NOTFOUND)
7286       CLOSE c_is_business_resp_exist;
7287    END LOOP; -- End of c_is_business_user_exist
7288 
7289    FOR x IN c_get_to_resp_info LOOP
7290       Debug_Log('manage_merged_party_memb_resp: x.responsibility_id: ' || x.responsibility_id);
7291       -- PRIMARY users
7292       IF (x.user_role_code = 'PRIMARY') THEN
7293          Debug_Log('manage_merged_party_memb_resp: PRIMARY');
7294 
7295          l_user_ids_tbl := get_partner_users(p_from_partner_id, x.user_role_code);
7296          FOR l_u_cnt IN 1..l_user_ids_tbl.count LOOP
7297             assign_resp (
7298                 p_api_version_number         => p_api_version_number
7299                ,p_init_msg_list              => FND_API.G_FALSE
7300                ,p_commit                     => FND_API.G_FALSE
7301                ,p_user_id                    => l_user_ids_tbl(l_u_cnt)
7302                ,p_resp_id                    => x.responsibility_id
7303                ,p_app_id                     => 691
7304                ,x_return_status              => x_return_status
7305                ,x_msg_count                  => x_msg_count
7306                ,x_msg_data                   => x_msg_data
7307             );
7308             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
7309                RAISE FND_API.G_EXC_ERROR;
7310             END IF;
7311          END LOOP;
7312       ELSIF (x.user_role_code = 'BUSINESS') THEN
7313          Debug_Log('manage_merged_party_memb_resp: BUSINESS');
7314 
7315          l_user_ids_tbl := get_partner_users(p_from_partner_id, x.user_role_code);
7316          FOR l_u_cnt IN 1..l_user_ids_tbl.count LOOP
7317             assign_resp (
7318                 p_api_version_number         => p_api_version_number
7319                ,p_init_msg_list              => FND_API.G_FALSE
7320                ,p_commit                     => FND_API.G_FALSE
7321                ,p_user_id                    => l_user_ids_tbl(l_u_cnt)
7322                ,p_resp_id                    => x.responsibility_id
7323                ,p_app_id                     => 691
7324                ,x_return_status              => x_return_status
7325                ,x_msg_count                  => x_msg_count
7326                ,x_msg_data                   => x_msg_data
7327             );
7328             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
7329                RAISE FND_API.G_EXC_ERROR;
7330             END IF;
7331          END LOOP;
7332       ELSIF (x.user_role_code = 'ALL') THEN
7333          Debug_Log('manage_merged_party_memb_resp: ALL');
7334          l_user_ids_tbl := get_partner_users(p_from_partner_id, x.user_role_code);
7335          FOR l_u_cnt IN 1..l_user_ids_tbl.count LOOP
7336             assign_resp (
7337                 p_api_version_number         => p_api_version_number
7338                ,p_init_msg_list              => FND_API.G_FALSE
7339                ,p_commit                     => FND_API.G_FALSE
7340                ,p_user_id                    => l_user_ids_tbl(l_u_cnt)
7341                ,p_resp_id                    => x.responsibility_id
7342                ,p_app_id                     => 671
7343                ,x_return_status              => x_return_status
7344                ,x_msg_count                  => x_msg_count
7345                ,x_msg_data                   => x_msg_data
7346             );
7347             IF x_return_status<>FND_API.G_RET_STS_SUCCESS THEN
7348                RAISE FND_API.G_EXC_ERROR;
7349             END IF;
7350          END LOOP;
7351       END IF;
7352    END LOOP;
7353 
7354    -- Check for commit
7355    IF FND_API.to_boolean(p_commit) THEN
7356       COMMIT;
7357    END IF;
7358 
7359    FND_MSG_PUB.count_and_get(
7360       p_encoded => FND_API.g_false
7361      ,p_count   => x_msg_count
7362      ,p_data    => x_msg_data
7363    );
7364 
7365 EXCEPTION
7366 
7367    WHEN PVX_Utility_PVT.resource_locked THEN
7368      x_return_status := FND_API.g_ret_sts_error;
7369          PVX_Utility_PVT.Error_Message(p_message_name => 'PV_API_RESOURCE_LOCKED');
7370 
7371    WHEN FND_API.G_EXC_ERROR THEN
7372      ROLLBACK TO manage_merged_party_memb_resp;
7373      x_return_status := FND_API.G_RET_STS_ERROR;
7374      -- Standard call to get message count and if count=1, get the message
7375      FND_MSG_PUB.Count_And_Get (
7376             p_encoded => FND_API.G_FALSE,
7377             p_count   => x_msg_count,
7378             p_data    => x_msg_data
7379      );
7380 
7381    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7382      ROLLBACK TO manage_merged_party_memb_resp;
7383      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7384      -- Standard call to get message count and if count=1, get the message
7385      FND_MSG_PUB.Count_And_Get (
7386             p_encoded => FND_API.G_FALSE,
7387             p_count => x_msg_count,
7388             p_data  => x_msg_data
7389      );
7390 
7391    WHEN OTHERS THEN
7392      ROLLBACK TO manage_merged_party_memb_resp;
7393      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7394      IF FND_MSG_PUB.Check_Msg_Level ( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
7395      THEN
7396         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME,l_api_name);
7397      END IF;
7398      -- Standard call to get message count and if count=1, get the message
7399      FND_MSG_PUB.Count_And_Get (
7400             p_encoded => FND_API.G_FALSE,
7401             p_count => x_msg_count,
7402             p_data  => x_msg_data
7403      );
7404 
7405 END manage_merged_party_memb_resp;
7406 
7407 END Pv_User_Resp_Pvt;