[Home] [Help]
PACKAGE BODY: APPS.EAM_METR_PROCESSOR
Source
1 PACKAGE BODY eam_metr_processor AS
2 /* $Header: EAMETRPB.pls 115.5 2003/11/20 01:12:56 lllin ship $ */
3
4 procedure start_processing(p_group_id in number,
5 p_retcode out NOCOPY varchar2);
6 procedure process_one_meter_data(p_group_id in number,
7 p_meter_id in number,
8 p_retcode out NOCOPY varchar2);
9 procedure insert_one_row(p_rowid rowid);
10 procedure end_processing(p_group_id in number);
11
12
13 procedure process_meter_reading_requests(
14 errbuf out NOCOPY varchar2,
15 retcode out NOCOPY varchar2,
16 p_group_id in number,
17 p_commit in boolean default true) is
18 cursor allmeters is
19 select distinct meter_id
20 from eam_meter_readings_interface
21 where group_id = p_group_id
22 and process_phase = WIP_CONSTANTS.ML_VALIDATION
23 and process_status = WIP_CONSTANTS.RUNNING;
24
25 x_meter_id number;
26 x_retcode varchar2(1);
27 x_has_error boolean := false;
28 x_all_error boolean := true;
29 begin
30 retcode := '0';
31 start_processing(p_group_id, retcode);
32 if ( retcode = '2' ) then
33 errbuf := 'The meter entity information provides are all incorrect. ' ||
34 'Please come back after correct them.';
35 return;
36 end if;
37
38 open allmeters;
39 LOOP
40 fetch allmeters into x_meter_id;
41 EXIT WHEN ( allmeters%NOTFOUND );
42 process_one_meter_data(p_group_id, x_meter_id, x_retcode);
43 if ( x_retcode = '2' ) then
44 x_has_error := true;
45 else
46 x_all_error := false;
47 end if;
48 END LOOP;
49 close allmeters;
50
51 end_processing(p_group_id);
52
53 if ( x_all_error AND retcode = '2') then
54 retcode := '2';
55 elsif ( x_has_error OR retcode = '1') then
56 retcode := '1';
57 else
58 retcode := '0';
59 end if;
60
61 if ( retcode <> '0' ) then
62 errbuf := 'Please go to meter reading interface form to check the problems.';
63 end if;
64
65 if ( p_commit ) then
66 commit;
67 end if;
68 end process_meter_reading_requests;
69
70
71 procedure start_processing(p_group_id in number,
72 p_retcode out NOCOPY varchar2) is
73 cursor allrows is
74 select rowid, interface_id
75 from eam_meter_readings_interface
76 where group_id = p_group_id
77 and process_phase = WIP_CONSTANTS.ML_VALIDATION
78 and process_status = WIP_CONSTANTS.RUNNING;
79
80 x_current_rowid rowid;
81 x_interface_id number;
82 x_retcode varchar2(1);
83 x_has_error boolean := false;
84 x_all_error boolean := true;
85 begin
86 p_retcode := '0';
87 -- generates the interface id and lock the rows
88 update eam_meter_readings_interface
89 set interface_id = wip_interface_s.nextval,
90 process_status = WIP_CONSTANTS.RUNNING
91 where group_id = p_group_id
92 and process_phase = WIP_CONSTANTS.ML_VALIDATION
93 and process_status = WIP_CONSTANTS.PENDING;
94
95 -- validate meter name and meter id field for all rows.
96 open allrows;
97 LOOP
98 fetch allrows into x_current_rowid, x_interface_id;
99 EXIT WHEN ( allrows%NOTFOUND );
100 eam_metr_validator.meter_name(x_current_rowid, x_interface_id, x_retcode);
101 if ( x_retcode = '2' ) then
102 x_has_error := true;
103 else
104 x_all_error := false;
105 end if;
106 eam_metr_validator.meter_id(x_current_rowid, x_interface_id, x_retcode);
107 if ( x_retcode = '2' ) then
108 x_has_error := true;
109 elsif ( x_retcode <> '#' ) then
110 x_all_error := false;
111 end if;
112
113 if ( x_all_error ) then
114 p_retcode := '2';
115 elsif ( x_has_error ) then
116 p_retcode := '1';
117 else
118 p_retcode := '0';
119 end if;
120 END LOOP;
121 close allrows;
122 end start_processing;
123
124
125 procedure process_one_meter_data(p_group_id in number,
126 p_meter_id in number,
127 p_retcode out NOCOPY varchar2) is
128 cursor meter is
129 select rowid, interface_id, disable_flag, meter_id, reading_date
130 from eam_meter_readings_interface
131 where group_id = p_group_id
132 and meter_id = p_meter_id
133 and process_phase = WIP_CONSTANTS.ML_VALIDATION
134 and process_status = WIP_CONSTANTS.RUNNING
135 order by reading_date;
136
137 x_rowid rowid;
138 x_interface_id number;
139 l_disable_flag varchar2(1);
140 l_msg_count number;
141 l_msg_data varchar2(5000);
142 l_return_status varchar2(1);
143 l_meter_id number;
144 l_reading_date date;
145 begin
146 p_retcode := '0';
147 open meter;
148 LOOP
149 fetch meter into x_rowid, x_interface_id, l_disable_flag, l_meter_id, l_reading_date;
150 EXIT WHEN ( meter%NOTFOUND );
151
152 savepoint eam_meter_reading_start;
153
154 eam_metr_validator.validate(x_rowid, x_interface_id);
155
156 -- check to see whether the current record errors out or not
157 -- due the validation
158 if ( eam_int_utils.has_errors ) then
159 -- rollback the default, etc.
160 rollback to savepoint eam_meter_reading_start;
161 -- set the error status for the current record
162 update eam_meter_readings_interface
163 set process_status = WIP_CONSTANTS.ERROR
164 where rowid = x_rowid;
165 -- set the return code
166 p_retcode := '2';
167 else
168 -- if the row passed validation, then we set the process phase
169 -- and then do the insertion
170 update eam_meter_readings_interface
171 set process_phase = WIP_CONSTANTS.ML_INSERTION
172 where rowid = x_rowid;
173
174 if (l_disable_flag is not null and l_disable_flag='Y') then
175 eam_meterreading_pub.disable_meter_reading
176 (p_api_version =>1.0,
177 x_msg_count => l_msg_count,
178 x_msg_data => l_msg_data,
179 x_return_status=> l_return_status,
180 p_meter_id=>l_meter_id,
181 p_meter_reading_date=> l_reading_date);
182
183
184 if (l_return_status <> 'S') then
185 fnd_message.set_name('EAM', 'EAM_METINT_DISABLE_ERROR'); eam_int_utils.record_error(x_interface_id,
186 fnd_message.get,
187 FALSE);
188 update eam_meter_readings_interface
189 set process_phase = WIP_CONSTANTS.ML_VALIDATION,
190 process_status = WIP_CONSTANTS.ERROR
191 where rowid = x_rowid;
192 else
193 update eam_meter_readings_interface
194 set process_phase = WIP_CONSTANTS.ML_COMPLETE,
195 process_status = WIP_CONSTANTS.COMPLETED
196 where rowid = x_rowid;
197 end if;
198 else
199 insert_one_row(x_rowid);
200
201 update eam_meter_readings_interface
202 set process_phase = WIP_CONSTANTS.ML_COMPLETE,
203 process_status = WIP_CONSTANTS.COMPLETED
204 where rowid = x_rowid;
205 end if;
206 end if;
207
208 eam_int_utils.load_errors('eam_meter_readings_interface');
209 END LOOP;
210 close meter;
211
212 end process_one_meter_data;
213
214
215 procedure insert_one_row(p_rowid rowid) is
216 begin
217 insert into eam_meter_readings(
218 meter_reading_id,
219 meter_id,
220 current_reading,
221 current_reading_date,
222 reset_flag,
223 life_to_date_reading,
224 wip_entity_id,
225 description,
226 source_line_id,
227 source_code,
228 created_by,
229 creation_date,
230 last_update_login,
231 last_update_date,
232 last_updated_by,
233 attribute_category,
234 attribute1,
235 attribute2,
236 attribute3,
237 attribute4,
238 attribute5,
239 attribute6,
240 attribute7,
241 attribute8,
242 attribute9,
243 attribute10,
244 attribute11,
245 attribute12,
246 attribute13,
247 attribute14,
248 attribute15,
249 disable_flag
250 )
251 select eam_meter_readings_s.nextval,
252 meter_id,
253 reading_value,
254 reading_date,
255 reset_flag,
256 life_to_date_reading,
257 wip_entity_id,
258 description,
259 source_line_id,
260 source_code,
261 created_by,
262 creation_date,
263 last_update_login,
264 last_update_date,
265 last_updated_by,
266 attribute_category,
267 attribute1,
268 attribute2,
269 attribute3,
270 attribute4,
271 attribute5,
272 attribute6,
273 attribute7,
274 attribute8,
275 attribute9,
276 attribute10,
277 attribute11,
278 attribute12,
279 attribute13,
280 attribute14,
281 attribute15,
282 disable_flag
283 from eam_meter_readings_interface
284 where rowid = p_rowid;
285
286 end insert_one_row;
287
288
289 procedure end_processing(p_group_id in number) is
290 begin
291 -- delete completed records
292 delete from wip_interface_errors
293 where interface_id in
294 (select interface_id
295 from eam_meter_readings_interface
296 where process_phase = WIP_CONSTANTS.ML_COMPLETE
297 and group_id = p_group_id
298 and process_status = WIP_CONSTANTS.COMPLETED);
299
300 delete from eam_meter_readings_interface
301 where process_phase = WIP_CONSTANTS.ML_COMPLETE
302 and group_id = p_group_id
303 and process_status = WIP_CONSTANTS.COMPLETED;
304
305 end end_processing;
306
307 END eam_metr_processor;