DBA Data[Home] [Help]

PACKAGE BODY: APPS.HR_OPT_INS

Source


1 Package Body hr_opt_ins as
2 /* $Header: hroptrhi.pkb 120.1 2005/09/29 07:03 santosin noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  hr_opt_ins.';  -- Global package name
9 --
10 -- The following global variables are only to be used by
11 -- the set_base_key_value and pre_insert procedures.
12 --
13 g_option_id_i  number   default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19   (p_option_id  in  number) is
20 --
21   l_proc       varchar2(72) := g_package||'set_base_key_value';
22 --
23 Begin
24   hr_utility.set_location('Entering:'||l_proc, 10);
25   --
26   hr_opt_ins.g_option_id_i := p_option_id;
27   --
28   hr_utility.set_location(' Leaving:'||l_proc, 20);
29 End set_base_key_value;
30 --
31 --
32 -- ----------------------------------------------------------------------------
33 -- |------------------------------< insert_dml >------------------------------|
34 -- ----------------------------------------------------------------------------
35 -- {Start Of Comments}
36 --
37 -- Description:
38 --   This procedure controls the actual dml insert logic. The processing of
39 --   this procedure are as follows:
40 --   1) Initialise the object_version_number to 1 if the object_version_number
41 --      is defined as an attribute for this entity.
42 --   2) To set and unset the g_api_dml status as required (as we are about to
43 --      perform dml).
44 --   3) To insert the row into the schema.
45 --   4) To trap any constraint violations that may have occurred.
46 --   5) To raise any other errors.
47 --
48 -- Prerequisites:
49 --   This is an internal private procedure which must be called from the ins
50 --   procedure and must have all mandatory attributes set (except the
51 --   object_version_number which is initialised within this procedure).
52 --
53 -- In Parameters:
54 --   A Pl/Sql record structre.
55 --
56 -- Post Success:
57 --   The specified row will be inserted into the schema.
58 --
59 -- Post Failure:
60 --   On the insert dml failure it is important to note that we always reset the
61 --   g_api_dml status to false.
62 --   If a check, unique or parent integrity constraint violation is raised the
63 --   constraint_error procedure will be called.
64 --   If any other error is reported, the error will be raised after the
65 --   g_api_dml status is reset.
66 --
67 -- Developer Implementation Notes:
68 --   None.
69 --
70 -- Access Status:
71 --   Internal Row Handler Use Only.
72 --
73 -- {End Of Comments}
74 -- ----------------------------------------------------------------------------
75 Procedure insert_dml
76   (p_rec in out nocopy hr_opt_shd.g_rec_type
77   ) is
78 --
79   l_proc  varchar2(72) := g_package||'insert_dml';
80 --
81 Begin
82   hr_utility.set_location('Entering:'||l_proc, 5);
83   p_rec.object_version_number := 1;  -- Initialise the object version
84   --
85   --
86   --
87   -- Insert the row into: hr_ki_options
88   --
89   insert into hr_ki_options
90       (option_id
91       ,option_type_id
92       ,option_level
93       ,option_level_id
94       ,value
95       ,encrypted
96       ,integration_id
97       ,object_version_number
98       )
99   Values
100     (p_rec.option_id
101     ,p_rec.option_type_id
102     ,p_rec.option_level
103     ,p_rec.option_level_id
104     ,p_rec.value
105     ,p_rec.encrypted
106     ,p_rec.integration_id
107     ,p_rec.object_version_number
108     );
109   --
110   --
111   --
112   hr_utility.set_location(' Leaving:'||l_proc, 10);
113 Exception
114   When hr_api.check_integrity_violated Then
115     -- A check constraint has been violated
116     --
117     hr_opt_shd.constraint_error
118       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
119   When hr_api.parent_integrity_violated Then
120     -- Parent integrity has been violated
121     --
122     hr_opt_shd.constraint_error
123       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
124   When hr_api.unique_integrity_violated Then
125     -- Unique integrity has been violated
126     --
127     hr_opt_shd.constraint_error
128       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
129   When Others Then
130     --
131     Raise;
132 End insert_dml;
133 --
134 -- ----------------------------------------------------------------------------
135 -- |------------------------------< pre_insert >------------------------------|
136 -- ----------------------------------------------------------------------------
137 -- {Start Of Comments}
138 --
139 -- Description:
140 --   This private procedure contains any processing which is required before
141 --   the insert dml. Presently, if the entity has a corresponding primary
142 --   key which is maintained by an associating sequence, the primary key for
143 --   the entity will be populated with the next sequence value in
144 --   preparation for the insert dml.
145 --
146 -- Prerequisites:
147 --   This is an internal procedure which is called from the ins procedure.
148 --
149 -- In Parameters:
150 --   A Pl/Sql record structure.
151 --
152 -- Post Success:
153 --   Processing continues.
154 --
155 -- Post Failure:
156 --   If an error has occurred, an error message and exception will be raised
157 --   but not handled.
158 --
159 -- Developer Implementation Notes:
160 --   Any pre-processing required before the insert dml is issued should be
161 --   coded within this procedure. As stated above, a good example is the
162 --   generation of a primary key number via a corresponding sequence.
163 --   It is important to note that any 3rd party maintenance should be reviewed
164 --   before placing in this procedure.
165 --
166 -- Access Status:
167 --   Internal Row Handler Use Only.
168 --
169 -- {End Of Comments}
170 -- ----------------------------------------------------------------------------
171 Procedure pre_insert
172   (p_rec  in out nocopy hr_opt_shd.g_rec_type
173   ) is
174 --
175   Cursor C_Sel1 is select hr_ki_options_s.nextval from sys.dual;
176 --
177   Cursor C_Sel2 is
178     Select null
179       from hr_ki_options
180      where option_id =
181              hr_opt_ins.g_option_id_i;
182 --
183   l_proc   varchar2(72) := g_package||'pre_insert';
184   l_exists varchar2(1);
185   l_option_type_id number;
186 --
187 Begin
188   hr_utility.set_location('Entering:'||l_proc, 5);
189    select option_type_id
190      into l_option_type_id
191        from hr_ki_option_types
192      where option_type_key = 'PASSWORD';
193   --
194   If (hr_opt_ins.g_option_id_i is not null) Then
195     --
196     -- Verify registered primary key values not already in use
197     --
198     Open C_Sel2;
199     Fetch C_Sel2 into l_exists;
200     If C_Sel2%found Then
201        Close C_Sel2;
202        --
203        -- The primary key values are already in use.
204        --
205        fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
206        fnd_message.set_token('TABLE_NAME','hr_ki_options');
207        fnd_message.raise_error;
208     End If;
209     Close C_Sel2;
210     --
211     -- Use registered key values and clear globals
212     --
213     p_rec.option_id :=
214       hr_opt_ins.g_option_id_i;
215     hr_opt_ins.g_option_id_i := null;
216   Else
217     --
218     -- No registerd key values, so select the next sequence number
219     --
220     --
221     -- Select the next sequence number
222     --
223     Open C_Sel1;
224     Fetch C_Sel1 Into p_rec.option_id;
225     Close C_Sel1;
226   End If;
227   if p_rec.option_type_id = l_option_type_id then
228        FND_VAULT.put('KI',p_rec.integration_id ||'#' || p_rec.option_type_id || '#' || p_rec.option_level_id || '#' || p_rec.option_id,p_rec.value);
229        p_rec.value := p_rec.integration_id ||'#' || p_rec.option_type_id || '#' || p_rec.option_level_id || '#' || p_rec.option_id;
230   elsif upper(p_rec.encrypted) ='Y' then
231         --p_rec.value :=icx_call.encrypt(p_rec.value);
232           FND_VAULT.put('KI',p_rec.integration_id ||'#' || p_rec.option_type_id || '#' || p_rec.option_level_id || '#' || p_rec.option_id,p_rec.value);
233           p_rec.value := p_rec.integration_id ||'#' || p_rec.option_type_id || '#' || p_rec.option_level_id || '#' || p_rec.option_id;
234   end if;
235   --
236   hr_utility.set_location(' Leaving:'||l_proc, 10);
237 End pre_insert;
238 --
239 -- ----------------------------------------------------------------------------
240 -- |-----------------------------< post_insert >------------------------------|
241 -- ----------------------------------------------------------------------------
242 -- {Start Of Comments}
243 --
244 -- Description:
245 --   This private procedure contains any processing which is required after
246 --   the insert dml.
247 --
248 -- Prerequisites:
249 --   This is an internal procedure which is called from the ins procedure.
250 --
251 -- In Parameters:
252 --   A Pl/Sql record structre.
253 --
254 -- Post Success:
255 --   Processing continues.
256 --
257 -- Post Failure:
258 --   If an error has occurred, an error message and exception will be raised
259 --   but not handled.
260 --
261 -- Developer Implementation Notes:
262 --   Any post-processing required after the insert dml is issued should be
263 --   coded within this procedure. It is important to note that any 3rd party
264 --   maintenance should be reviewed before placing in this procedure.
265 --
266 -- Access Status:
267 --   Internal Row Handler Use Only.
268 --
269 -- {End Of Comments}
270 -- ----------------------------------------------------------------------------
271 Procedure post_insert
272   (p_effective_date               in date
273   ,p_rec                          in hr_opt_shd.g_rec_type
274   ) is
275 --
276   l_proc  varchar2(72) := g_package||'post_insert';
277 --
278 Begin
279   hr_utility.set_location('Entering:'||l_proc, 5);
280   begin
281     --
282     hr_opt_rki.after_insert
283       (p_effective_date              => p_effective_date
284       ,p_option_id
285       => p_rec.option_id
286       ,p_option_type_id
287       => p_rec.option_type_id
288       ,p_option_level
289       => p_rec.option_level
290       ,p_option_level_id
291       => p_rec.option_level_id
292       ,p_value
293       => p_rec.value
294       ,p_encrypted
295       => p_rec.encrypted
296       ,p_integration_id
297       => p_rec.integration_id
298       ,p_object_version_number
299       => p_rec.object_version_number
300       );
301     --
302   exception
303     --
304     when hr_api.cannot_find_prog_unit then
305       --
306       hr_api.cannot_find_prog_unit_error
307         (p_module_name => 'HR_KI_OPTIONS'
308         ,p_hook_type   => 'AI');
309       --
310   end;
311   --
312   hr_utility.set_location(' Leaving:'||l_proc, 10);
313 End post_insert;
314 --
315 -- ----------------------------------------------------------------------------
316 -- |---------------------------------< ins >----------------------------------|
317 -- ----------------------------------------------------------------------------
318 Procedure ins
319   (p_effective_date               in date
320   ,p_rec                          in out nocopy hr_opt_shd.g_rec_type
321   ) is
322 --
323   l_proc  varchar2(72) := g_package||'ins';
324 --
325 Begin
326   hr_utility.set_location('Entering:'||l_proc, 5);
327   --
328   -- Call the supporting insert validate operations
329   --
330   hr_opt_bus.insert_validate
331      (p_effective_date
332      ,p_rec
333      );
334   --
335   -- Call to raise any errors on multi-message list
336   hr_multi_message.end_validation_set;
337   --
338   -- Call the supporting pre-insert operation
339   --
340   hr_opt_ins.pre_insert(p_rec);
341   --
342   -- Insert the row
343   --
344   hr_opt_ins.insert_dml(p_rec);
345   --
346   -- Call the supporting post-insert operation
347   --
348   hr_opt_ins.post_insert
349      (p_effective_date
350      ,p_rec
351      );
352   --
353   -- Call to raise any errors on multi-message list
354   hr_multi_message.end_validation_set;
355   --
356   hr_utility.set_location('Leaving:'||l_proc, 20);
357 end ins;
358 --
359 -- ----------------------------------------------------------------------------
360 -- |---------------------------------< ins >----------------------------------|
361 -- ----------------------------------------------------------------------------
362 Procedure ins
363   (p_effective_date               in     date
364   ,p_option_type_id                 in     number
365   ,p_option_level                   in     number
366   ,p_encrypted                      in     varchar2
367   ,p_integration_id                 in     number
368   ,p_option_level_id                in     varchar2   default null
369   ,p_value                          in     varchar2 default null
370   ,p_option_id                         out nocopy number
371   ,p_object_version_number             out nocopy number
372   ) is
373 --
374   l_rec   hr_opt_shd.g_rec_type;
375   l_proc  varchar2(72) := g_package||'ins';
376 --
377 Begin
378   hr_utility.set_location('Entering:'||l_proc, 5);
379   --
380   -- Call conversion function to turn arguments into the
381   -- p_rec structure.
382   --
383   l_rec :=
384   hr_opt_shd.convert_args
385     (null
386     ,p_option_type_id
387     ,p_option_level
388     ,p_option_level_id
389     ,p_value
390     ,p_encrypted
391     ,p_integration_id
392     ,null
393     );
394   --
395   -- Having converted the arguments into the hr_opt_rec
396   -- plsql record structure we call the corresponding record business process.
397   --
398   hr_opt_ins.ins
399      (p_effective_date
400      ,l_rec
401      );
402   --
403   -- As the primary key argument(s)
404   -- are specified as an OUT's we must set these values.
405   --
406   p_option_id := l_rec.option_id;
407   p_object_version_number := l_rec.object_version_number;
408   --
409   hr_utility.set_location(' Leaving:'||l_proc, 10);
410 End ins;
411 --
412 end hr_opt_ins;