DBA Data[Home] [Help]

PACKAGE BODY: APPS.PA_MOAC_UTILS

Source


1 PACKAGE BODY PA_MOAC_UTILS AS
2 -- $Header: PAXMOUTB.pls 120.5 2006/02/15 10:12:38 dlanka noship $
3 
4 -- **************************************************************** /
5 -- Function to check Projects implementations for an ORG_ID
6 -- Returns 'TURE' if PA is implemented or FALSE if not.
7 -- ---------------------------------------------------------------
8 Function pa_implemented (x_org_id number) return boolean is
9 	l_var varchar2 (1);
10 Begin
11 
12 select '1'
13 into l_var
14 from dual
15 where exists (select ORG_ID
16               from pa_implementations_all
17              where org_id = x_org_id);
18 
19 return TRUE;
20 Exception
21 when no_data_found then
22  return FALSE;
23 when others then
24  return FALSE ;
25 
26 end pa_implemented ;
27 
28 -- ****************************************************************/
29 FUNCTION GET_OU_COUNT RETURN NUMBER IS
30 
31 -- This function would return count of Operating Units a user has access to.
32 -- It would return 0 in case there is no access or initialization is not done.
33 --
34 BEGIN
35   RETURN MO_GLOBAL.GET_OU_COUNT;
36 END GET_OU_COUNT;
37 
38 -- ****************************************************************/
39 FUNCTION GET_VALID_OU
40 ( p_org_id  hr_operating_units.organization_id%TYPE DEFAULT NULL , p_product_code VARCHAR2  )
41 RETURN NUMBER
42 --
43 -- This function is used to determine and get valid operating unit where Projects is implmented.
44 -- Returns ORG_ID if valid and PA is implemneted or retruns NULL if invalid or PA is not implemented.
45 
46 -- This function uses  MO_GLOBAL.GET_VALID_ORG(p_org_id) to get valid org_id.
47 -- MO_GLOBAL.GET_VALID_ORG gets org_id in the following order if p_org_id IS NULL
48 --   1. get_current_org_id
49 --   2. get_default_org_id
50 
51 -- MO_GLOBAL.GET_VALID_ORG retruns p_org_id if Valid or returns NULL if invalid .
52 -- If p_org_id  does not exist in Global table, then it would throw up error.
53 -- Before calling this function, global temp table should be populated using MO initialization routine.
54 
55 IS
56  l_org_id NUMBER ;
57  l_status  VARCHAR2(1);
58 
59 BEGIN
60    l_org_id := p_org_id ;
61 
62  -- Replacing this call with mo_global.validate_orgid_pub_api
63  -- provided by MOAC team
64  --   l_org_id :=  MO_GLOBAL.GET_VALID_ORG(p_org_id);
65 
66  -- VALIDATE_ORGID_PUB_API will retrun either
67  -- Success ( 'S','O','C','D') or Failure ( 'F')
68 
69       mo_global.validate_orgid_pub_api( l_org_id, 'Y',l_status );
70 
71  -- Checking if Projects is implemented or not
72 
73   If l_org_id is not null and l_status IN ( 'S','O','C','D')  then
74        If p_product_code = 'PA' then
75           If  pa_implemented (l_org_id) then
76              RETURN l_org_id ;
77           else
78              RETURN NULL  ;
79           end if ;
80        elsif p_product_code = 'GMS' then
81           If gms_install.enabled(l_org_id) then
82              RETURN l_org_id ;
83           else
84              RETURN NULL  ;
85           end if;
86        End if ;
87   else
88    RETURN NULL  ;
89   End if ;
90 
91 END GET_VALID_OU;
92 
93 /*-- -------------------------------------------------------------------------------
94   Procedure Name: PROCEDURE mo_init_set_context
95 
96   DESCRIPTION   : New procedure added for MOAC. This procedure would be invoked by Public APIs
97                   to initialize proper multi-org context.
98 
99   CLIENT/SERVER : SERVER
100 
101   LIBRARY NAME  :
102 
103   PARAMETERS    : p_org_id     IN OUT NOCOPY NUMBER
104                 : p_product_code  IN  Default 'PA'
105                 : p_msg_count     OUT NOCOPY NUMBER,
106                 : p_msg_data      OUT NOCOPY VARCHAR2,
107                 : p_return_status OUT NOCOPY  ( 'S' -- Success , 'F' -- failure, 'U' -- unexpected )
108 
109   ALGORITHM     : This procedure would be invoked by Public/AMG APIs to initialize
110                   and set org context. This procedure checks if the P_ORG_ID
111  		  passed is valid or not using get_valid_ou function. If it is not
112 		  valid then error is thrown, else OU context is set to Single .
113   NOTES         :
114 
115 -- ****************************************************************/
116 
117 PROCEDURE MO_INIT_SET_CONTEXT(p_org_id           IN OUT NOCOPY  NUMBER
118                              , p_product_code    IN     VARCHAR2 DEFAULT 'PA'
119                              , p_msg_count       OUT NOCOPY NUMBER
120                              , p_msg_data        OUT NOCOPY VARCHAR2
121                              , p_return_status   OUT NOCOPY VARCHAR2 ) IS
122 
123 BEGIN
124    p_return_status := 'S' ;
125  -- Conditionally doing MO intialization
126   If NVL(mo_global.get_ou_count, 0)  = 0  then -- Fix for bug : 5037365
127     MO_GLOBAL.INIT(p_product_code);
128   end if ;
129 
130   If p_org_id = PA_INTERFACE_UTILS_PUB.G_PA_MISS_NUM then
131      p_org_id := FND_API.G_MISS_NUM ;
132   end if ;
133      p_org_id := GET_VALID_OU(p_org_id, p_product_code);
134 
135     IF p_org_id IS NULL THEN
136        FND_MSG_PUB.Initialize;
137 
138       p_return_status := FND_API.G_RET_STS_ERROR;
139 
140 	IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
141 
142 		FND_MESSAGE.SET_NAME('PA','PA_MOAC_PASS_VALID_ORG');
143 		FND_MSG_PUB.add;
144 		FND_MSG_PUB.Count_And_Get
145 				(   p_count  =>	p_msg_count 	,
146 				    p_data   =>	p_msg_data	);
147 	END IF;
148     else
149         MO_GLOBAL.SET_POLICY_CONTEXT('S',p_org_id);
150     END IF;
151 END MO_INIT_SET_CONTEXT;
152 
153 
154 -- **************************************************************** /
155 -- FUNCTION GET_CURRENT_ORG_ID : This function would return the ORG ID set
156 -- for the current session if the context is set to Single, for Multi-context
157 -- this function would return NULL. This function is a wrapper that makes
158 -- call to MO_GLOBAL.GET_CURRENT_ORG_ID.
159 
160 FUNCTION GET_CURRENT_ORG_ID
161 RETURN NUMBER
162 IS
163 BEGIN
164   RETURN MO_GLOBAL.GET_CURRENT_ORG_ID;
165 END GET_CURRENT_ORG_ID;
166 
167 -- ***********************************************************************
168 
169 FUNCTION GET_OU_NAME
170 (
171   p_ORG_ID                hr_all_organization_units_tl.organization_id%TYPE
172 )
173 RETURN VARCHAR2
174 IS
175 --
176 -- This function would return OU Name for the ORG_ID passed.
177 -- If the ORG_ID is NULL or invalid, it would return NULL
178 -- This function is a wrapper that makes call to MO_GLOBAL.GET_OU_NAME
179 --
180 BEGIN
181   RETURN MO_GLOBAL.GET_OU_NAME(p_org_id);
182 END GET_OU_NAME;
183 
184 -- ****************************************************************/
185 PROCEDURE GET_DEFAULT_OU
186 (
187   p_product_code            IN VARCHAR2  DEFAULT 'PA',
188   p_default_org_id     OUT NOCOPY hr_operating_units.organization_id%TYPE,
189   p_default_ou_name    OUT NOCOPY hr_operating_units.name%TYPE,
190   p_ou_count           OUT NOCOPY NUMBER
191 ) IS
192 --
193 -- This procedure should be used to get the default operating unit for a user
194 -- using MO_UTILS.GET_DEFAULT_OU.Also verifies whether Projects is implemented or not.
195 -- If Projects is not implemented returns NULL for default org_id and Name
196 --
197 --NOTE :
198 --=====
199 
200    --Here we need to check whether Projects is implemented for that OU
201 
202  l_default_org_id hr_operating_units.organization_id%TYPE  ;
203  l_default_ou_name hr_operating_units.name%TYPE  ;
204  l_ou_count NUMBER ;
205 BEGIN
206   MO_UTILS.GET_DEFAULT_OU( l_default_org_id,
207                            l_default_ou_name,
208 			   l_ou_count
209 			 );
210 
211    If l_default_org_id IS NOT NULL then
212         if p_product_code = 'PA' then
213           if  pa_implemented(l_default_org_id) then
214               p_default_org_id := l_default_org_id ;
215               p_default_ou_name := l_default_ou_name ;
216               p_ou_count := l_ou_count ;
217           else
218               p_default_org_id := NULL;
219               p_default_ou_name := NULL ;
220               p_ou_count := l_ou_count ;
221           end if ;
222         elsif p_product_code = 'GMS' then
223          if   gms_install.enabled(l_default_org_id) then
224               p_default_org_id := l_default_org_id ;
225               p_default_ou_name := l_default_ou_name ;
226               p_ou_count := l_ou_count ;
227           else
228               p_default_org_id := NULL;
229               p_default_ou_name := NULL ;
230               p_ou_count := l_ou_count ;
231           end if ;
232        end if;
233    else
234               p_default_org_id := NULL;
235               p_default_ou_name := NULL ;
236               p_ou_count := l_ou_count ;
237    end if;
238 
239 END GET_DEFAULT_OU;
240 
241 -- ****************************************************************/
242 PROCEDURE INITIALIZE(p_product_code  VARCHAR2 DEFAULT 'PA')
243 --
244 -- This procedure invokes MO Global initialization routine by passing PA as
245 -- product short code. This procedure would populate the global temporary table with the
246 -- operating units that a user has access to.
247 --
248 IS
249 BEGIN
250   MO_GLOBAL.INIT(p_product_code);
251 END INITIALIZE;
252 -- ****************************************************************/
253 PROCEDURE SET_POLICY_CONTEXT
254 (
255   p_access_mode      VARCHAR2,
256   p_org_id           hr_operating_units.organization_id%TYPE
257 )
258 IS
259 --
260 -- This procedure is used to initialize org context. If the access mode is S, the context
261 -- is set to Single and p_Org_id is set as current org_id, if the access mode is M, the context
262 -- is set to Multiple and then current org_id would be set to NULL.
263 --
264 BEGIN
265   IF p_access_mode ='S' THEN
266      MO_GLOBAL.SET_POLICY_CONTEXT('S',p_org_id);
267   ELSIF p_access_mode = 'M' THEN
268      MO_GLOBAL.SET_POLICY_CONTEXT('M',NULL);
269   END IF;
270 END SET_POLICY_CONTEXT;
271 
272 -- ****************************************************************/
273 
274 FUNCTION CHECK_ACCESS
275 (
276   p_org_id  hr_operating_units.organization_id%TYPE, p_product_code  varchar2 DEFAULT 'PA')
277 RETURN VARCHAR2
278 -- This function checks if the org_id exists in the
279 -- global temorary table or not, if it is present function returns 'Y', else returns 'N'.
280 -- Global temporary table gets populated if MOAC is initialized.
281 --
282 IS
283  l_access VARCHAR(1) ;
284 BEGIN
285     l_access :=  MO_GLOBAL.CHECK_ACCESS(p_org_id);
286     If l_access = 'N' then
287        RETURN l_access ;
288     else
289       if  p_product_code = 'PA' then
290           If pa_implemented( p_org_id) then
291             Return l_access ;
292           else Return 'N';
293           end if;
294       elsif  p_product_code = 'GMS' then
295           if gms_install.enabled(p_org_id) then
296           Return l_access ;
297           else Return 'N';
298           end if;
299       end if ;
300     end if ;
301 
302 END CHECK_ACCESS;
303 -- ****************************************************************/
304 END PA_MOAC_UTILS;