DBA Data[Home] [Help]

PACKAGE BODY: APPS.HXC_OTL_INFO_TYPE_HELPER

Source


1 PACKAGE body hxc_otl_info_type_helper AS
2 /* $Header: hxcinfotypehelp.pkb 120.2 2005/12/19 10:07:42 arundell noship $ */
3 
4   Type segment is record
5     (name fnd_descr_flex_column_usages.end_user_column_name%type,
6      column fnd_descr_flex_column_usages.application_column_name%type
7      );
8 
9   Type segment_list is table of segment index by binary_integer;
10 
11   Function form_otl_context
12      (p_context_prefix in varchar2,
13       p_context_code   in varchar2)
14    Return varchar2 is
15 
16   Begin
17      return substr(p_context_prefix||' - '||p_context_code,1,30);
18   End form_otl_context;
19 
20    Function form_long_otl_context
21       (p_context_prefix in varchar2,
22        p_context_code in varchar2)
23       Return varchar2 is
24 
25       cursor get_max_sequence is
26         select max(to_number(substrb(descriptive_flex_context_code,
27                                      instr(descriptive_flex_context_code,'-')+2)))
28           from fnd_descr_flex_contexts_vl
29          where descriptive_flexfield_name = 'OTC Information Types'
30            and application_id = 809
31            and  substrb(descriptive_flex_context_code,0,
32                         instr(descriptive_flex_context_code,'-')-2)
33                 =substrb(descriptive_flex_context_name,0,
34                          instr(descriptive_flex_context_name,'-')-2)||'C';
35 
36       l_max_sequence number;
37       l_long_context_code fnd_descr_flex_contexts.descriptive_flex_context_code%type;
38       l_test_long_context fnd_descr_flex_contexts_tl.descriptive_flex_context_name%type;
39 
40    Begin
41 
42       l_test_long_context := hxc_deposit_wrapper_utilities.get_dupdff_code
43                                (p_context_prefix||' - '||p_context_code);
44 
45       if(l_test_long_context <> p_context_prefix||' - '||p_context_code) then
46          l_long_context_code := l_test_long_context;
47       else
48          open get_max_sequence;
49          fetch get_max_sequence into l_max_sequence;
50          if(get_max_sequence%notfound) then
51             l_long_context_code := p_context_prefix||'C - 1';
52          else
53             l_long_context_code := p_context_prefix||'C - '||(l_max_sequence+1);
54          end if;
55          close get_max_sequence;
56 
57       end if;
58 
59       return l_long_context_code;
60 
61    End form_long_otl_context;
62 
63    function long_context_code
64       (p_otc_appl_short_name in fnd_application.application_short_name%type,
65        p_otc_flex_name in fnd_descriptive_flexs.descriptive_flexfield_name%type,
66        p_context_prefix in varchar2,
67        p_context_code in varchar2)
68       return boolean is
69 
70       l_long boolean;
71 
72    begin
73       l_long := false;
74 
75       if (fnd_flex_dsc_api.context_exists
76             (p_appl_short_name=> p_otc_appl_short_name,
77              p_flexfield_name=> p_otc_flex_name,
78              p_context_code=>form_otl_context(p_context_prefix, p_context_code))
79           )then
80          l_long := false;
81       else
82          l_long := true;
83       end if;
84 
85       if(
86           (length(p_context_code) >= (30-(length(p_context_prefix)+3)))
87         and
88           (l_long)
89         ) then
90          l_long := true;
91       else
92          l_long := false;
93       end if;
94 
95       return l_long;
96 
97    end long_context_code;
98 
99   function get_otl_flex
100      (p_appl_short_name fnd_application.application_short_name%type,
101       p_flexfield_name  fnd_descriptive_flexs.descriptive_flexfield_name%type
102       )
103      return fnd_dflex.dflex_r is
104 
105      l_flex      fnd_dflex.dflex_r;
106      l_flex_info fnd_dflex.dflex_dr;
107 
108   Begin
109 
110      fnd_dflex.get_flexfield
111         (appl_short_name => p_appl_short_name,
112          flexfield_name => p_flexfield_name,
113          flexfield => l_flex,
114          flexinfo => l_flex_info);
115 
116      return l_flex;
117 
118   End get_otl_flex;
119 
120   Function get_otl_context
121      (p_otl_flex in fnd_dflex.dflex_r,
122       p_context_code in fnd_descr_flex_contexts.descriptive_flex_context_code%type
123       )
124      Return fnd_dflex.context_r is
125 
126   Begin
127      return fnd_dflex.make_context
128         (flexfield => p_otl_flex,
129          context_code => p_context_code
130          );
131   End get_otl_context;
132 
133   Function otl_context_exists
134      (p_otc_appl_short_name in fnd_application.application_short_name%type,
135       p_otc_flex_name in fnd_descriptive_flexs.descriptive_flexfield_name%type,
136       p_context_code in fnd_descr_flex_contexts.descriptive_flex_context_code%type)
137    Return Boolean is
138      l_exists boolean;
139   Begin
140 
141      if FND_FLEX_DSC_API.context_exists
142         (P_APPL_SHORT_NAME => p_otc_appl_short_name,
143          P_FLEXFIELD_NAME => p_otc_flex_name,
144          P_CONTEXT_CODE => p_context_code
145          ) then
146         l_exists := true;
147      else
148         l_exists := false;
149      end if;
150 
151      return l_exists;
152   End otl_context_exists;
153 
154   Function segment_lists_differ
155      (p_list_a in segment_list,
156       p_list_b in segment_list)
157      Return Boolean is
158 
159      l_index   binary_integer;
160      l_differ  boolean;
161 
162   Begin
163      if(p_list_a.count <> p_list_b.count) then
164         l_differ := true;
165      else
166         l_differ := false;
167         l_index := p_list_a.first;
168         Loop
169            Exit when ((not p_list_a.exists(l_index)) or (l_differ));
170            if(
171               (p_list_a(l_index).name <> p_list_b(l_index).name)
172              OR
173               (p_list_a(l_index).column  <> p_list_b(l_index).column)
174              ) then
175               l_differ := true;
176            end if;
177            l_index := p_list_a.next(l_index);
178         End Loop;
179 
180      end if;
181 
182      return l_differ;
183 
184   End segment_lists_differ;
185 
186   Procedure populate_segment_list
187      (p_context in fnd_dflex.context_r,
188       p_segment_list in out nocopy segment_list) is
189 
190      l_segments FND_DFLEX.segments_dr;
191      l_segment_index NUMBER;
192      l_index         binary_integer;
193 
194   Begin
195 
196      FND_DFLEX.get_Segments
197         (context => p_context,
198          segments => l_segments,
199          enabled_only => FALSE);
200 
201      l_segment_index := l_segments.segment_name.first;
202      l_index := p_segment_list.count;
203 
204      Loop
205         exit when not l_segments.segment_name.exists(l_segment_index);
206         l_index := l_index + 1;
207 
208         p_segment_list(l_index).name := l_segments.segment_name(l_segment_index);
209         p_segment_list(l_index).column := l_segments.application_column_name(l_segment_index);
210 
211         l_segment_index := l_segments.segment_name.next(l_segment_index);
212 
213      End Loop;
214 
215   End populate_segment_list;
216 
217   Function build_otl_contexts
218      (p_otc_appl_short_name  in fnd_application.application_short_name%type,
219       p_otc_flex_name in fnd_descriptive_flexs.descriptive_flexfield_name%type,
220       p_context_prefix in varchar2,
221       p_flex in FND_DFLEX.dflex_r,
222       p_contexts in FND_DFLEX.contexts_dr,
223       p_context_index in number,
224       p_global_context in FND_DFLEX.context_r,
225       p_preserve in boolean)
226    Return Boolean is
227 
228      l_build boolean;
229      l_reference_segment_list segment_list;
230      l_otl_segment_list segment_list;
231      l_otl_context_code fnd_descr_flex_contexts.descriptive_flex_context_code%type;
232 
233   Begin
234 
235      if(long_context_code
236            (p_otc_appl_short_name,
237             p_otc_flex_name,
238             p_context_prefix,
239             p_contexts.context_code(p_context_index))
240         ) then
241         l_otl_context_code := form_long_otl_context(p_context_prefix,p_contexts.context_code(p_context_index));
242      else
243         l_otl_context_code := form_otl_context(p_context_prefix,p_contexts.context_code(p_context_index));
244      end if;
245 
246      if(p_preserve) then
247         l_build := true;
248         if(otl_context_exists
249              (p_otc_appl_short_name,
250               p_otc_flex_name,
251               l_otl_context_code)
252            ) then
253            --
254            -- First Add the global segments to the reference segment list
255            --
256            populate_segment_list
257               (p_global_context,
258                l_reference_segment_list
259                );
260            --
261            -- Next add the segments from this context to the reference list
262            --
263            populate_segment_list
264               (fnd_dflex.make_context(p_flex,p_contexts.context_code(p_context_index)),
265                l_reference_segment_list
266                );
267            --
268            -- Next add the segments from the OTL context to the otl list
269            --
270            populate_segment_list
271               (get_otl_context
272                  (get_otl_flex(p_otc_appl_short_name,p_otc_flex_name),
273                   l_otl_context_code),
274                l_otl_segment_list
275                );
276 
277            l_build := segment_lists_differ
278                          (l_reference_segment_list,
279                           l_otl_segment_list
280                           );
281 
282         else -- The OTL context does not exist, we must create it
283            l_build := true;
284         end if;
285      else -- Do we preserve the contexts
286         l_build := true;
287      end if;
288 
289      return l_build;
290 
291   End build_otl_contexts;
292 
293 END hxc_otl_info_type_helper;