@@ 241-257 (lines=17) @@ | ||
238 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.BAD_REQUEST', |
|
239 | description='API.ENERGY_ITEM_DOES_NOT_BELONG_TO_ENERGY_CATEGORY') |
|
240 | ||
241 | if master_meter_id is not None: |
|
242 | cursor.execute(" SELECT name, energy_category_id " |
|
243 | " FROM tbl_meters " |
|
244 | " WHERE id = %s ", |
|
245 | (new_values['data']['master_meter_id'],)) |
|
246 | row = cursor.fetchone() |
|
247 | if row is None: |
|
248 | cursor.close() |
|
249 | cnx.close() |
|
250 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
251 | description='API.MASTER_METER_NOT_FOUND') |
|
252 | else: |
|
253 | if row[1] != energy_category_id: |
|
254 | cursor.close() |
|
255 | cnx.close() |
|
256 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.BAD_REQUEST', |
|
257 | description='API.MASTER_METER_DOES_NOT_BELONG_TO_SAME_ENERGY_CATEGORY') |
|
258 | ||
259 | add_values = (" INSERT INTO tbl_meters " |
|
260 | " (name, uuid, energy_category_id, is_counted, hourly_low_limit, hourly_high_limit," |
|
@@ 223-239 (lines=17) @@ | ||
220 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
221 | description='API.COST_CENTER_NOT_FOUND') |
|
222 | ||
223 | if energy_item_id is not None: |
|
224 | cursor.execute(" SELECT name, energy_category_id " |
|
225 | " FROM tbl_energy_items " |
|
226 | " WHERE id = %s ", |
|
227 | (new_values['data']['energy_item_id'],)) |
|
228 | row = cursor.fetchone() |
|
229 | if row is None: |
|
230 | cursor.close() |
|
231 | cnx.close() |
|
232 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
233 | description='API.ENERGY_ITEM_NOT_FOUND') |
|
234 | else: |
|
235 | if row[1] != energy_category_id: |
|
236 | cursor.close() |
|
237 | cnx.close() |
|
238 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.BAD_REQUEST', |
|
239 | description='API.ENERGY_ITEM_DOES_NOT_BELONG_TO_ENERGY_CATEGORY') |
|
240 | ||
241 | if master_meter_id is not None: |
|
242 | cursor.execute(" SELECT name, energy_category_id " |
|
@@ 1705-1721 (lines=17) @@ | ||
1702 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.BAD_REQUEST', |
|
1703 | description='API.ENERGY_ITEM_DOES_NOT_BELONG_TO_ENERGY_CATEGORY') |
|
1704 | ||
1705 | if master_meter_id is not None: |
|
1706 | cursor.execute(" SELECT name, energy_category_id " |
|
1707 | " FROM tbl_meters " |
|
1708 | " WHERE id = %s ", |
|
1709 | (master_meter_id,)) |
|
1710 | row = cursor.fetchone() |
|
1711 | if row is None: |
|
1712 | cursor.close() |
|
1713 | cnx.close() |
|
1714 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1715 | description='API.MASTER_METER_NOT_FOUND') |
|
1716 | else: |
|
1717 | if row[1] != energy_category_id: |
|
1718 | cursor.close() |
|
1719 | cnx.close() |
|
1720 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.BAD_REQUEST', |
|
1721 | description='API.MASTER_METER_DOES_NOT_BELONG_TO_SAME_ENERGY_CATEGORY') |
|
1722 | ||
1723 | add_values = (" INSERT INTO tbl_meters " |
|
1724 | " (name, uuid, energy_category_id, is_counted, hourly_low_limit, hourly_high_limit," |
|
@@ 907-923 (lines=17) @@ | ||
904 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.BAD_REQUEST', |
|
905 | description='API.ENERGY_ITEM_DOES_NOT_BELONG_TO_ENERGY_CATEGORY') |
|
906 | ||
907 | if master_meter_id is not None: |
|
908 | cursor.execute(" SELECT name, energy_category_id " |
|
909 | " FROM tbl_meters " |
|
910 | " WHERE id = %s ", |
|
911 | (new_values['data']['master_meter_id'],)) |
|
912 | row = cursor.fetchone() |
|
913 | if row is None: |
|
914 | cursor.close() |
|
915 | cnx.close() |
|
916 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
917 | description='API.MASTER_METER_NOT_FOUND') |
|
918 | else: |
|
919 | if row[1] != energy_category_id: |
|
920 | cursor.close() |
|
921 | cnx.close() |
|
922 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.BAD_REQUEST', |
|
923 | description='API.MASTER_METER_DOES_NOT_BELONG_TO_SAME_ENERGY_CATEGORY') |
|
924 | ||
925 | # todo: check all descendants against new_values['data']['master_meter_id'] |
|
926 | if master_meter_id is not None: |
|
@@ 889-905 (lines=17) @@ | ||
886 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
887 | description='API.COST_CENTER_NOT_FOUND') |
|
888 | ||
889 | if energy_item_id is not None: |
|
890 | cursor.execute(" SELECT name, energy_category_id " |
|
891 | " FROM tbl_energy_items " |
|
892 | " WHERE id = %s ", |
|
893 | (new_values['data']['energy_item_id'],)) |
|
894 | row = cursor.fetchone() |
|
895 | if row is None: |
|
896 | cursor.close() |
|
897 | cnx.close() |
|
898 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
899 | description='API.ENERGY_ITEM_NOT_FOUND') |
|
900 | else: |
|
901 | if row[1] != energy_category_id: |
|
902 | cursor.close() |
|
903 | cnx.close() |
|
904 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.BAD_REQUEST', |
|
905 | description='API.ENERGY_ITEM_DOES_NOT_BELONG_TO_ENERGY_CATEGORY') |
|
906 | ||
907 | if master_meter_id is not None: |
|
908 | cursor.execute(" SELECT name, energy_category_id " |
@@ 605-621 (lines=17) @@ | ||
602 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
603 | description='API.COST_CENTER_NOT_FOUND') |
|
604 | ||
605 | if energy_item_id is not None: |
|
606 | cursor.execute(" SELECT name, energy_category_id " |
|
607 | " FROM tbl_energy_items " |
|
608 | " WHERE id = %s ", |
|
609 | (new_values['data']['energy_item_id'],)) |
|
610 | row = cursor.fetchone() |
|
611 | if row is None: |
|
612 | cursor.close() |
|
613 | cnx.close() |
|
614 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
615 | description='API.ENERGY_ITEM_NOT_FOUND') |
|
616 | else: |
|
617 | if row[1] != energy_category_id: |
|
618 | cursor.close() |
|
619 | cnx.close() |
|
620 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.BAD_REQUEST', |
|
621 | description='API.ENERGY_ITEM_IS_NOT_BELONG_TO_ENERGY_CATEGORY') |
|
622 | ||
623 | update_row = (" UPDATE tbl_offline_meters " |
|
624 | " SET name = %s, energy_category_id = %s," |
|
@@ 189-205 (lines=17) @@ | ||
186 | cnx.close() |
|
187 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
188 | description='API.ENERGY_CATEGORY_NOT_FOUND') |
|
189 | if energy_item_id is not None: |
|
190 | cursor.execute(" SELECT name, energy_category_id " |
|
191 | " FROM tbl_energy_items " |
|
192 | " WHERE id = %s ", |
|
193 | (new_values['data']['energy_item_id'],)) |
|
194 | row = cursor.fetchone() |
|
195 | if row is None: |
|
196 | cursor.close() |
|
197 | cnx.close() |
|
198 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
199 | description='API.ENERGY_ITEM_NOT_FOUND') |
|
200 | else: |
|
201 | if row[1] != energy_category_id: |
|
202 | cursor.close() |
|
203 | cnx.close() |
|
204 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.BAD_REQUEST', |
|
205 | description='API.ENERGY_ITEM_IS_NOT_BELONG_TO_ENERGY_CATEGORY') |
|
206 | ||
207 | cursor.execute(" SELECT name " |
|
208 | " FROM tbl_cost_centers " |
|
@@ 845-861 (lines=17) @@ | ||
842 | cnx.close() |
|
843 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
844 | description='API.ENERGY_CATEGORY_NOT_FOUND') |
|
845 | if energy_item_id is not None: |
|
846 | cursor.execute(" SELECT name, energy_category_id " |
|
847 | " FROM tbl_energy_items " |
|
848 | " WHERE id = %s ", |
|
849 | (new_values['energy_item']['id'],)) |
|
850 | row = cursor.fetchone() |
|
851 | if row is None: |
|
852 | cursor.close() |
|
853 | cnx.close() |
|
854 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
855 | description='API.ENERGY_ITEM_NOT_FOUND') |
|
856 | else: |
|
857 | if row[1] != energy_category_id: |
|
858 | cursor.close() |
|
859 | cnx.close() |
|
860 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.BAD_REQUEST', |
|
861 | description='API.ENERGY_ITEM_IS_NOT_BELONG_TO_ENERGY_CATEGORY') |
|
862 | ||
863 | cursor.execute(" SELECT name " |
|
864 | " FROM tbl_cost_centers " |
@@ 265-281 (lines=17) @@ | ||
262 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
263 | description='API.COST_CENTER_NOT_FOUND') |
|
264 | ||
265 | if energy_item_id is not None: |
|
266 | cursor.execute(" SELECT name, energy_category_id " |
|
267 | " FROM tbl_energy_items " |
|
268 | " WHERE id = %s ", |
|
269 | (new_values['data']['energy_item_id'],)) |
|
270 | row = cursor.fetchone() |
|
271 | if row is None: |
|
272 | cursor.close() |
|
273 | cnx.close() |
|
274 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
275 | description='API.ENERGY_ITEM_NOT_FOUND') |
|
276 | else: |
|
277 | if row[1] != energy_category_id: |
|
278 | cursor.close() |
|
279 | cnx.close() |
|
280 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.BAD_REQUEST', |
|
281 | description='API.ENERGY_ITEM_IS_NOT_BELONG_TO_ENERGY_CATEGORY') |
|
282 | ||
283 | for variable in new_values['data']['expression']['variables']: |
|
284 | if variable['meter_type'].lower() == 'meter': |
|
@@ 1158-1174 (lines=17) @@ | ||
1155 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1156 | description='API.COST_CENTER_NOT_FOUND') |
|
1157 | ||
1158 | if energy_item_id is not None: |
|
1159 | cursor.execute(" SELECT name, energy_category_id " |
|
1160 | " FROM tbl_energy_items " |
|
1161 | " WHERE id = %s ", |
|
1162 | (new_values['energy_item']['id'],)) |
|
1163 | row = cursor.fetchone() |
|
1164 | if row is None: |
|
1165 | cursor.close() |
|
1166 | cnx.close() |
|
1167 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1168 | description='API.ENERGY_ITEM_NOT_FOUND') |
|
1169 | else: |
|
1170 | if row[1] != energy_category_id: |
|
1171 | cursor.close() |
|
1172 | cnx.close() |
|
1173 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.BAD_REQUEST', |
|
1174 | description='API.ENERGY_ITEM_IS_NOT_BELONG_TO_ENERGY_CATEGORY') |
|
1175 | ||
1176 | for variable in new_values['expression']['variables']: |
|
1177 | if variable['meter_type'].lower() == 'meter': |