1 Package body OKC_CONTEXT AS
2 /*$Header: OKCPCTXB.pls 120.7.12010000.2 2010/02/10 08:41:17 spingali ship $*/
3 l_debug VARCHAR2(1) := NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N');
4
5 g_okc_organization_id NUMBER;
6 g_okc_business_group_id NUMBER;
7 g_moac_access_mode VARCHAR2(3);
8 g_moac_current_org_id NUMBER;
9
10 -- Procedure set_okc_org_context(p_org_id IN NUMBER DEFAULT NULL,p_organization_id IN NUMBER DEFAULT NULL)
11 -- Procedure sets the okc context values for Multi Org. If the parameters are not passed procedure reads
12 -- the calue from user profile options.
13
14 PROCEDURE set_okc_org_context(p_org_id IN NUMBER ,
15 p_organization_id IN NUMBER ) IS
16
17 -- Bug Fix 5014701- Performance Re-Fix
18
19 CURSOR c_bus_grp(p_id IN NUMBER) IS
20 SELECT business_group_id
21 FROM HR_ALL_ORGANIZATION_UNITS OU,
22 HR_ORGANIZATION_INFORMATION OI1,
23 HR_ORGANIZATION_INFORMATION OI2
24 WHERE OU.ORGANIZATION_ID = p_id
25 AND OI1.ORG_INFORMATION1 = 'OPERATING_UNIT'
26 AND OI2.ORG_INFORMATION_CONTEXT = 'Operating Unit Information'
27 AND OI1.ORGANIZATION_ID = OU.ORGANIZATION_ID
28 AND OI2.ORGANIZATION_ID = OU.ORGANIZATION_ID;
29
30 /**
31 CURSOR c_bus_grp(p_id IN NUMBER) IS
32 SELECT business_group_id
33 FROM okx_organization_defs_v
34 WHERE id1= p_id
35 AND ORGANIZATION_TYPE = 'OPERATING_UNIT' AND INFORMATION_TYPE = 'Operating Unit Information';
36
37 **/
38
39
40 l_business_group_id NUMBER;
41 l_default_org_id hr_operating_units.organization_id%TYPE;
42 l_default_ou_name hr_operating_units.name%TYPE;
43 l_ou_count NUMBER;
44 l_org_id hr_operating_units.organization_id%TYPE;
45
46
47 BEGIN
51 /*
48 -- Sets the org_id to a context namespace attribute.
49 IF p_org_id IS NULL OR p_org_id = -99 THEN
50 --mmadhavi changes for MOAC project
52 DBMS_SESSION.SET_CONTEXT('OKC_CONTEXT','ORG_ID',NVL(FND_PROFILE.VALUE('ORG_ID'),-99));
53 ELSE
54 DBMS_SESSION.SET_CONTEXT('OKC_CONTEXT','ORG_ID',p_org_id);
55 END IF;
56 */
57
58 mo_utils.get_default_ou(l_default_org_id, l_default_ou_name, l_ou_count);
59 If l_default_org_id is NOT NULL AND l_default_org_id <> -99 THEN
60 mo_global.set_policy_context('S', l_default_org_id);
61 l_org_id := l_default_org_id;
62 Else
63 mo_global.set_policy_context('M', NULL);
64 l_org_id := NULL;
65
66 End If;
67
68 ELSE
69 mo_global.set_policy_context('S', p_org_id);
70 l_org_id := p_org_id;
71 END IF;
72
73 -- Sets the Inventory org_id to a context namespace attribute.
74 -- If Organization_ID is null, then use the Org_ID set in the context
75 -- tsaifee 07/24/2000.
76
77 IF p_organization_id IS NULL THEN
78 -- Added By Jvorugan for Bug:4729941
79 IF l_org_id IS NOT NULL THEN
80 DBMS_SESSION.SET_CONTEXT('OKC_CONTEXT','ORGANIZATION_ID',
81 NVL(OE_PROFILE.VALUE('OE_ORGANIZATION_ID',l_org_id),-99)); --Mmadhavi replaced get_okc_org_id with l_org_id
82 ELSE
83 DBMS_SESSION.SET_CONTEXT('OKC_CONTEXT','ORGANIZATION_ID',-99);
84 END IF;
85 -- End of changes for Bug:4729941
86 ELSE
87 DBMS_SESSION.SET_CONTEXT('OKC_CONTEXT','ORGANIZATION_ID',p_organization_id);
88 END IF;
89
90 -- Sets the Inventory business_group_id to a context namespace attribute.
91
92 --OPEN c_bus_grp(sys_context('OKC_CONTEXT','ORG_ID'));
93 OPEN c_bus_grp(l_org_id); --Mmadhavi replaced get_okc_org_id with l_org_id
94 FETCH c_bus_grp INTO l_business_group_id;
95 CLOSE c_bus_grp;
96
97 l_business_group_id := NVL(l_business_group_id,-99);
98
99 DBMS_SESSION.SET_CONTEXT('OKC_CONTEXT','BUSINESS_GROUP_ID',l_business_group_id);
100
101 END set_okc_org_context;
102
103 -- Procedure set_okc_org_context(p_chr_id IN NUMBER)
104 -- Procedure sets the okc context values for Multi Org. These org values are obtained from the okc_k_headers_v
105 -- for the chr_id passed in.
106
107 PROCEDURE set_okc_org_context(p_chr_id IN NUMBER) IS
108 CURSOR c_chr IS
109 SELECT authoring_org_id,
110 inv_organization_id
111 FROM okc_k_headers_all_b --changed to _all for MOAC
112 WHERE id = p_chr_id;
113
114 -- Bug Fix 5014701- Performance Fix
115
116 CURSOR c_bus_grp(p_id IN NUMBER) IS
117 SELECT business_group_id
118 FROM HR_ALL_ORGANIZATION_UNITS OU
119 WHERE OU.ORGANIZATION_ID = p_id;
120
121 /**
122 CURSOR c_bus_grp(p_id IN NUMBER) IS
123 SELECT business_group_id
124 FROM okx_organization_defs_v
125 WHERE id1= p_id
126 AND ORGANIZATION_TYPE = 'OPERATING_UNIT' AND INFORMATION_TYPE = 'Operating Unit Information';
127
128 **/
129
130 l_business_group_id NUMBER;
131 l_org_id hr_operating_units.organization_id%TYPE;
132
133 BEGIN
134 DBMS_SESSION.SET_CONTEXT('OKC_CONTEXT','CHR_ID',p_chr_id); -- bug#2155926
135
136 FOR l_c_chr IN c_chr
137 LOOP
138 --DBMS_SESSION.SET_CONTEXT('OKC_CONTEXT','ORG_ID',l_c_chr.authoring_org_id);
139 --mmadhavi for MOAC project
140 mo_global.set_policy_context('S', l_c_chr.authoring_org_id);
141 DBMS_SESSION.SET_CONTEXT('OKC_CONTEXT','ORGANIZATION_ID',l_c_chr.inv_organization_id);
142 l_org_id := l_c_chr.authoring_org_id ;
143 END LOOP;
144
145 -- Sets the Inventory business_group_id to a context namespace attribute.
146
147 OPEN c_bus_grp(l_org_id); --Mmadhavi replaced get_okc_org_id with l_org_id
148 FETCH c_bus_grp INTO l_business_group_id;
149 CLOSE c_bus_grp;
150
151 l_business_group_id := NVL(l_business_group_id,-99);
152
153 DBMS_SESSION.SET_CONTEXT('OKC_CONTEXT','BUSINESS_GROUP_ID',l_business_group_id);
154 END set_okc_org_context;
155
156 -- Function get_okc_organization_id RETURN NUMBER
157 -- Returns the Inventory organization id.
158
159 FUNCTION get_okc_organization_id RETURN NUMBER IS
160 BEGIN
161 RETURN(sys_context('OKC_CONTEXT','ORGANIZATION_ID'));
162 END get_okc_organization_id;
163
164 -- Function get_okc_org_id RETURN NUMBER
165 -- Returns the org_id.
166
167 FUNCTION get_okc_org_id RETURN NUMBER IS
168 BEGIN
169 --RETURN(sys_context('OKC_CONTEXT','ORG_ID'));
170 --mmadhavi for MOAC
171 RETURN nvl(mo_global.get_current_org_id,-99);
172 END get_okc_org_id;
173
174
175 --new procedure added to save the current OKC and MOAC contexts
176 --the following contexts are saved
177 -- OKC_CONTEXT : ORGANIZATION_ID
178 -- OKC_CONTEXT : BUSINESS_GROUP_ID
179 -- MOAC (via MO_GLOBAL.set_policy_context)
180 -- MO_GLOBAL.g_access_mode (MULTI_ORG : ACCESS_MODE)
181 -- MO_GLOBAL.g_current_org_id (MULTI_ORG2 : CURRENT_ORG_ID)
182 PROCEDURE save_current_contexts
183 IS
184 BEGIN
185 g_moac_access_mode := MO_GLOBAL.get_access_mode;
186 g_moac_current_org_id := MO_GLOBAL.get_current_org_id;
187 g_okc_organization_id := sys_context('OKC_CONTEXT', 'ORGANIZATION_ID');
188 g_okc_business_group_id := sys_context('OKC_CONTEXT','BUSINESS_GROUP_ID');
189 END save_current_contexts;
190
191
192
193 --new procedure added to restore the OKC and MOAC contexts saved by
194 --call to save_current_contexts
195 /*PROCEDURE restore_contexts
196 IS
197 BEGIN
198 MO_GLOBAL.set_policy_context(g_moac_access_mode, g_moac_current_org_id);
199 DBMS_SESSION.SET_CONTEXT('OKC_CONTEXT','ORGANIZATION_ID',g_okc_organization_id);
200 DBMS_SESSION.SET_CONTEXT('OKC_CONTEXT','ORGANIZATION_ID',g_okc_business_group_id);
201 END restore_contexts;*/
202
203 ---modified for bug8936332
204
205 PROCEDURE restore_contexts IS
206 BEGIN
207 MO_GLOBAL.set_policy_context(g_moac_access_mode, g_moac_current_org_id);
208 DBMS_SESSION.SET_CONTEXT('OKC_CONTEXT','ORGANIZATION_ID',g_okc_organization_id);
209 DBMS_SESSION.SET_CONTEXT('OKC_CONTEXT','BUSINESS_GROUP_ID',g_okc_business_group_id);
210 END restore_contexts;
211
212 ---modified for bug8936332
213
214 END okc_context;