Code Duplication    Length = 62-63 lines in 8 locations

myems-api/core/energystoragecontainer.py 8 locations

@@ 2970-3032 (lines=63) @@
2967
                        str(new_values['data']['point_id'])
2968
2969
2970
class EnergyStorageContainerGridPointItem:
2971
    def __init__(self):
2972
        """Initializes EnergyStorageContainerGridPointItem"""
2973
        pass
2974
2975
    @staticmethod
2976
    def on_options(req, resp, id_, gid, pid):
2977
        _=req
2978
        resp.status = falcon.HTTP_200
2979
        _=id_
2980
    @staticmethod
2981
    @user_logger
2982
    def on_delete(req, resp, id_, gid, pid):
2983
        """Handles DELETE requests"""
2984
        admin_control(req)
2985
        if not id_.isdigit() or int(id_) <= 0:
2986
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2987
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
2988
        if not gid.isdigit() or int(gid) <= 0:
2989
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2990
                                   description='API.INVALID_GRID_ID')
2991
        if not pid.isdigit() or int(pid) <= 0:
2992
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2993
                                   description='API.INVALID_POINT_ID')
2994
2995
        cnx = mysql.connector.connect(**config.myems_system_db)
2996
        cursor = cnx.cursor()
2997
2998
        cursor.execute(" SELECT name "
2999
                       " FROM tbl_energy_storage_containers_grids "
3000
                       " WHERE energy_storage_container_id = %s AND id = %s ", (id_, gid,))
3001
        if cursor.fetchone() is None:
3002
            cursor.close()
3003
            cnx.close()
3004
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
3005
                                   description='API.ENERGY_STORAGE_CONTAINER_GRID_NOT_FOUND')
3006
3007
        cursor.execute(" SELECT name "
3008
                       " FROM tbl_points "
3009
                       " WHERE id = %s ", (pid,))
3010
        if cursor.fetchone() is None:
3011
            cursor.close()
3012
            cnx.close()
3013
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
3014
                                   description='API.POINT_NOT_FOUND')
3015
3016
        cursor.execute(" SELECT id "
3017
                       " FROM tbl_energy_storage_containers_grids_points "
3018
                       " WHERE grid_id = %s AND point_id = %s ", (gid, pid))
3019
        if cursor.fetchone() is None:
3020
            cursor.close()
3021
            cnx.close()
3022
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
3023
                                   description='API.GRID_POINT_RELATION_NOT_FOUND')
3024
3025
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_grids_points "
3026
                       " WHERE grid_id = %s AND point_id = %s ", (gid, pid))
3027
        cnx.commit()
3028
3029
        cursor.close()
3030
        cnx.close()
3031
3032
        resp.status = falcon.HTTP_204
3033
3034
3035
class EnergyStorageContainerHVACCollection:
@@ 2299-2361 (lines=63) @@
2296
                        str(new_values['data']['point_id'])
2297
2298
2299
class EnergyStorageContainerFirecontrolPointItem:
2300
    def __init__(self):
2301
        """Initializes EnergyStorageContainerFirecontrolPointItem"""
2302
        pass
2303
2304
    @staticmethod
2305
    def on_options(req, resp, id_, fid, pid):
2306
        _=req
2307
        resp.status = falcon.HTTP_200
2308
        _=id_
2309
    @staticmethod
2310
    @user_logger
2311
    def on_delete(req, resp, id_, fid, pid):
2312
        """Handles DELETE requests"""
2313
        admin_control(req)
2314
        if not id_.isdigit() or int(id_) <= 0:
2315
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2316
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
2317
        if not fid.isdigit() or int(fid) <= 0:
2318
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2319
                                   description='API.INVALID_FIRECONTROL_ID')
2320
        if not pid.isdigit() or int(pid) <= 0:
2321
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2322
                                   description='API.INVALID_POINT_ID')
2323
2324
        cnx = mysql.connector.connect(**config.myems_system_db)
2325
        cursor = cnx.cursor()
2326
2327
        cursor.execute(" SELECT name "
2328
                       " FROM tbl_energy_storage_containers_firecontrols "
2329
                       " WHERE energy_storage_container_id = %s AND id = %s ", (id_, fid,))
2330
        if cursor.fetchone() is None:
2331
            cursor.close()
2332
            cnx.close()
2333
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2334
                                   description='API.ENERGY_STORAGE_CONTAINER_FIRECONTROL_NOT_FOUND')
2335
2336
        cursor.execute(" SELECT name "
2337
                       " FROM tbl_points "
2338
                       " WHERE id = %s ", (pid,))
2339
        if cursor.fetchone() is None:
2340
            cursor.close()
2341
            cnx.close()
2342
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2343
                                   description='API.POINT_NOT_FOUND')
2344
2345
        cursor.execute(" SELECT id "
2346
                       " FROM tbl_energy_storage_containers_firecontrols_points "
2347
                       " WHERE firecontrol_id = %s AND point_id = %s ", (fid, pid))
2348
        if cursor.fetchone() is None:
2349
            cursor.close()
2350
            cnx.close()
2351
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2352
                                   description='API.FIRECONTROL_POINT_RELATION_NOT_FOUND')
2353
2354
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_firecontrols_points "
2355
                       " WHERE firecontrol_id = %s AND point_id = %s ", (fid, pid))
2356
        cnx.commit()
2357
2358
        cursor.close()
2359
        cnx.close()
2360
2361
        resp.status = falcon.HTTP_204
2362
2363
2364
class EnergyStorageContainerGridCollection:
@@ 1813-1875 (lines=63) @@
1810
                        str(new_values['data']['point_id'])
1811
1812
1813
class EnergyStorageContainerDCDCPointItem:
1814
    def __init__(self):
1815
        """Initializes MeterPointItem"""
1816
        pass
1817
1818
    @staticmethod
1819
    def on_options(req, resp, id_, did, pid):
1820
        _=req
1821
        resp.status = falcon.HTTP_200
1822
        _=id_
1823
    @staticmethod
1824
    @user_logger
1825
    def on_delete(req, resp, id_, did, pid):
1826
        """Handles DELETE requests"""
1827
        admin_control(req)
1828
        if not id_.isdigit() or int(id_) <= 0:
1829
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
1830
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
1831
        if not did.isdigit() or int(did) <= 0:
1832
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
1833
                                   description='API.INVALID_DCDC_ID')
1834
        if not pid.isdigit() or int(pid) <= 0:
1835
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
1836
                                   description='API.INVALID_POINT_ID')
1837
1838
        cnx = mysql.connector.connect(**config.myems_system_db)
1839
        cursor = cnx.cursor()
1840
1841
        cursor.execute(" SELECT name "
1842
                       " FROM tbl_energy_storage_containers_dcdcs "
1843
                       " WHERE energy_storage_container_id = %s AND id = %s ", (id_, did,))
1844
        if cursor.fetchone() is None:
1845
            cursor.close()
1846
            cnx.close()
1847
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
1848
                                   description='API.ENERGY_STORAGE_CONTAINER_DCDC_NOT_FOUND')
1849
1850
        cursor.execute(" SELECT name "
1851
                       " FROM tbl_points "
1852
                       " WHERE id = %s ", (pid,))
1853
        if cursor.fetchone() is None:
1854
            cursor.close()
1855
            cnx.close()
1856
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
1857
                                   description='API.POINT_NOT_FOUND')
1858
1859
        cursor.execute(" SELECT id "
1860
                       " FROM tbl_energy_storage_containers_dcdcs_points "
1861
                       " WHERE dcdc_id = %s AND point_id = %s ", (did, pid))
1862
        if cursor.fetchone() is None:
1863
            cursor.close()
1864
            cnx.close()
1865
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
1866
                                   description='API.DCDC_POINT_RELATION_NOT_FOUND')
1867
1868
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_dcdcs_points "
1869
                       " WHERE dcdc_id = %s AND point_id = %s ", (did, pid))
1870
        cnx.commit()
1871
1872
        cursor.close()
1873
        cnx.close()
1874
1875
        resp.status = falcon.HTTP_204
1876
1877
1878
class EnergyStorageContainerFirecontrolCollection:
@@ 5428-5489 (lines=62) @@
5425
                        str(new_values['data']['point_id'])
5426
5427
5428
class EnergyStorageContainerSTSPointItem:
5429
    def __init__(self):
5430
        """Initializes EnergyStorageContainerSTSPointItem"""
5431
        pass
5432
5433
    @staticmethod
5434
    def on_options(req, resp, id_, fid, pid):
5435
        resp.status = falcon.HTTP_200
5436
5437
    @staticmethod
5438
    @user_logger
5439
    def on_delete(req, resp, id_, fid, pid):
5440
        """Handles DELETE requests"""
5441
        admin_control(req)
5442
        if not id_.isdigit() or int(id_) <= 0:
5443
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5444
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
5445
        if not fid.isdigit() or int(fid) <= 0:
5446
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5447
                                   description='API.INVALID_STS_ID')
5448
        if not pid.isdigit() or int(pid) <= 0:
5449
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5450
                                   description='API.INVALID_POINT_ID')
5451
5452
        cnx = mysql.connector.connect(**config.myems_system_db)
5453
        cursor = cnx.cursor()
5454
5455
        cursor.execute(" SELECT name "
5456
                       " FROM tbl_energy_storage_containers_stses "
5457
                       " WHERE energy_storage_container_id = %s AND id = %s ", (id_, fid,))
5458
        if cursor.fetchone() is None:
5459
            cursor.close()
5460
            cnx.close()
5461
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5462
                                   description='API.ENERGY_STORAGE_CONTAINER_STS_NOT_FOUND')
5463
5464
        cursor.execute(" SELECT name "
5465
                       " FROM tbl_points "
5466
                       " WHERE id = %s ", (pid,))
5467
        if cursor.fetchone() is None:
5468
            cursor.close()
5469
            cnx.close()
5470
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5471
                                   description='API.POINT_NOT_FOUND')
5472
5473
        cursor.execute(" SELECT id "
5474
                       " FROM tbl_energy_storage_containers_stses_points "
5475
                       " WHERE sts_id = %s AND point_id = %s ", (fid, pid))
5476
        if cursor.fetchone() is None:
5477
            cursor.close()
5478
            cnx.close()
5479
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5480
                                   description='API.STS_POINT_RELATION_NOT_FOUND')
5481
5482
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_stses_points "
5483
                       " WHERE sts_id = %s AND point_id = %s ", (fid, pid))
5484
        cnx.commit()
5485
5486
        cursor.close()
5487
        cnx.close()
5488
5489
        resp.status = falcon.HTTP_204
5490
5491
5492
class EnergyStorageContainerClone:
@@ 4654-4715 (lines=62) @@
4651
                        str(new_values['data']['point_id'])
4652
4653
4654
class EnergyStorageContainerPCSPointItem:
4655
    def __init__(self):
4656
        """Initializes EnergyStorageContainerPCSPointItem"""
4657
        pass
4658
4659
    @staticmethod
4660
    def on_options(req, resp, id_, pcsid, pid):
4661
        resp.status = falcon.HTTP_200
4662
4663
    @staticmethod
4664
    @user_logger
4665
    def on_delete(req, resp, id_, pcsid, pid):
4666
        """Handles DELETE requests"""
4667
        admin_control(req)
4668
        if not id_.isdigit() or int(id_) <= 0:
4669
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
4670
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
4671
        if not pcsid.isdigit() or int(pcsid) <= 0:
4672
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
4673
                                   description='API.INVALID_PCS_ID')
4674
        if not pid.isdigit() or int(pid) <= 0:
4675
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
4676
                                   description='API.INVALID_POINT_ID')
4677
4678
        cnx = mysql.connector.connect(**config.myems_system_db)
4679
        cursor = cnx.cursor()
4680
4681
        cursor.execute(" SELECT name "
4682
                       " FROM tbl_energy_storage_containers_power_conversion_systems "
4683
                       " WHERE energy_storage_container_id = %s AND id = %s ", (id_, pcsid,))
4684
        if cursor.fetchone() is None:
4685
            cursor.close()
4686
            cnx.close()
4687
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
4688
                                   description='API.ENERGY_STORAGE_CONTAINER_PCS_NOT_FOUND')
4689
4690
        cursor.execute(" SELECT name "
4691
                       " FROM tbl_points "
4692
                       " WHERE id = %s ", (pid,))
4693
        if cursor.fetchone() is None:
4694
            cursor.close()
4695
            cnx.close()
4696
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
4697
                                   description='API.POINT_NOT_FOUND')
4698
4699
        cursor.execute(" SELECT id "
4700
                       " FROM tbl_energy_storage_containers_pcses_points "
4701
                       " WHERE pcs_id = %s AND point_id = %s ", (pcsid, pid))
4702
        if cursor.fetchone() is None:
4703
            cursor.close()
4704
            cnx.close()
4705
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
4706
                                   description='API.PCS_POINT_RELATION_NOT_FOUND')
4707
4708
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_pcses_points "
4709
                       " WHERE pcs_id = %s AND point_id = %s ", (pcsid, pid))
4710
        cnx.commit()
4711
4712
        cursor.close()
4713
        cnx.close()
4714
4715
        resp.status = falcon.HTTP_204
4716
4717
4718
class EnergyStorageContainerScheduleCollection:
@@ 4080-4141 (lines=62) @@
4077
                        str(new_values['data']['point_id'])
4078
4079
4080
class EnergyStorageContainerLoadPointItem:
4081
    def __init__(self):
4082
        """Initializes EnergyStorageContainerLoadPointItem"""
4083
        pass
4084
4085
    @staticmethod
4086
    def on_options(req, resp, id_, lid, pid):
4087
        resp.status = falcon.HTTP_200
4088
4089
    @staticmethod
4090
    @user_logger
4091
    def on_delete(req, resp, id_, lid, pid):
4092
        """Handles DELETE requests"""
4093
        admin_control(req)
4094
        if not id_.isdigit() or int(id_) <= 0:
4095
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
4096
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
4097
        if not lid.isdigit() or int(lid) <= 0:
4098
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
4099
                                   description='API.INVALID_LOAD_ID')
4100
        if not pid.isdigit() or int(pid) <= 0:
4101
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
4102
                                   description='API.INVALID_POINT_ID')
4103
4104
        cnx = mysql.connector.connect(**config.myems_system_db)
4105
        cursor = cnx.cursor()
4106
4107
        cursor.execute(" SELECT name "
4108
                       " FROM tbl_energy_storage_containers_loads "
4109
                       " WHERE energy_storage_container_id = %s AND id = %s ", (id_, lid,))
4110
        if cursor.fetchone() is None:
4111
            cursor.close()
4112
            cnx.close()
4113
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
4114
                                   description='API.ENERGY_STORAGE_CONTAINER_LOAD_NOT_FOUND')
4115
4116
        cursor.execute(" SELECT name "
4117
                       " FROM tbl_points "
4118
                       " WHERE id = %s ", (pid,))
4119
        if cursor.fetchone() is None:
4120
            cursor.close()
4121
            cnx.close()
4122
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
4123
                                   description='API.POINT_NOT_FOUND')
4124
4125
        cursor.execute(" SELECT id "
4126
                       " FROM tbl_energy_storage_containers_loads_points "
4127
                       " WHERE load_id = %s AND point_id = %s ", (lid, pid))
4128
        if cursor.fetchone() is None:
4129
            cursor.close()
4130
            cnx.close()
4131
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
4132
                                   description='API.LOAD_POINT_RELATION_NOT_FOUND')
4133
4134
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_loads_points "
4135
                       " WHERE load_id = %s AND point_id = %s ", (lid, pid))
4136
        cnx.commit()
4137
4138
        cursor.close()
4139
        cnx.close()
4140
4141
        resp.status = falcon.HTTP_204
4142
4143
4144
class EnergyStorageContainerPCSCollection:
@@ 3456-3517 (lines=62) @@
3453
                        str(new_values['data']['point_id'])
3454
3455
3456
class EnergyStorageContainerHVACPointItem:
3457
    def __init__(self):
3458
        """Initializes EnergyStorageContainerHVACPointItem"""
3459
        pass
3460
3461
    @staticmethod
3462
    def on_options(req, resp, id_, hid, pid):
3463
        resp.status = falcon.HTTP_200
3464
3465
    @staticmethod
3466
    @user_logger
3467
    def on_delete(req, resp, id_, hid, pid):
3468
        """Handles DELETE requests"""
3469
        admin_control(req)
3470
        if not id_.isdigit() or int(id_) <= 0:
3471
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
3472
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
3473
        if not hid.isdigit() or int(hid) <= 0:
3474
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
3475
                                   description='API.INVALID_HVAC_ID')
3476
        if not pid.isdigit() or int(pid) <= 0:
3477
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
3478
                                   description='API.INVALID_POINT_ID')
3479
3480
        cnx = mysql.connector.connect(**config.myems_system_db)
3481
        cursor = cnx.cursor()
3482
3483
        cursor.execute(" SELECT name "
3484
                       " FROM tbl_energy_storage_containers_hvacs "
3485
                       " WHERE energy_storage_container_id = %s AND id = %s ", (id_, hid,))
3486
        if cursor.fetchone() is None:
3487
            cursor.close()
3488
            cnx.close()
3489
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
3490
                                   description='API.ENERGY_STORAGE_CONTAINER_HVAC_NOT_FOUND')
3491
3492
        cursor.execute(" SELECT name "
3493
                       " FROM tbl_points "
3494
                       " WHERE id = %s ", (pid,))
3495
        if cursor.fetchone() is None:
3496
            cursor.close()
3497
            cnx.close()
3498
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
3499
                                   description='API.POINT_NOT_FOUND')
3500
3501
        cursor.execute(" SELECT id "
3502
                       " FROM tbl_energy_storage_containers_hvacs_points "
3503
                       " WHERE hvac_id = %s AND point_id = %s ", (hid, pid))
3504
        if cursor.fetchone() is None:
3505
            cursor.close()
3506
            cnx.close()
3507
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
3508
                                   description='API.HVAC_POINT_RELATION_NOT_FOUND')
3509
3510
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_hvacs_points "
3511
                       " WHERE hvac_id = %s AND point_id = %s ", (hid, pid))
3512
        cnx.commit()
3513
3514
        cursor.close()
3515
        cnx.close()
3516
3517
        resp.status = falcon.HTTP_204
3518
3519
3520
class EnergyStorageContainerLoadCollection:
@@ 1157-1218 (lines=62) @@
1154
                        str(new_values['data']['point_id'])
1155
1156
1157
class EnergyStorageContainerBatteryPointItem:
1158
    def __init__(self):
1159
        """Initializes MeterPointItem"""
1160
        pass
1161
1162
    @staticmethod
1163
    def on_options(req, resp, id_, bid, pid):
1164
        resp.status = falcon.HTTP_200
1165
1166
    @staticmethod
1167
    @user_logger
1168
    def on_delete(req, resp, id_, bid, pid):
1169
        """Handles DELETE requests"""
1170
        admin_control(req)
1171
        if not id_.isdigit() or int(id_) <= 0:
1172
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
1173
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
1174
        if not bid.isdigit() or int(bid) <= 0:
1175
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
1176
                                   description='API.INVALID_BMS_ID')
1177
        if not pid.isdigit() or int(pid) <= 0:
1178
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
1179
                                   description='API.INVALID_POINT_ID')
1180
1181
        cnx = mysql.connector.connect(**config.myems_system_db)
1182
        cursor = cnx.cursor()
1183
1184
        cursor.execute(" SELECT name "
1185
                       " FROM tbl_energy_storage_containers_batteries "
1186
                       " WHERE energy_storage_container_id = %s AND id = %s ", (id_, bid,))
1187
        if cursor.fetchone() is None:
1188
            cursor.close()
1189
            cnx.close()
1190
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
1191
                                   description='API.ENERGY_STORAGE_CONTAINER_BMS_NOT_FOUND')
1192
1193
        cursor.execute(" SELECT name "
1194
                       " FROM tbl_points "
1195
                       " WHERE id = %s ", (pid,))
1196
        if cursor.fetchone() is None:
1197
            cursor.close()
1198
            cnx.close()
1199
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
1200
                                   description='API.POINT_NOT_FOUND')
1201
1202
        cursor.execute(" SELECT id "
1203
                       " FROM tbl_energy_storage_containers_bmses_points "
1204
                       " WHERE bms_id = %s AND point_id = %s ", (bid, pid))
1205
        if cursor.fetchone() is None:
1206
            cursor.close()
1207
            cnx.close()
1208
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
1209
                                   description='API.BMS_POINT_RELATION_NOT_FOUND')
1210
1211
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_bmses_points "
1212
                       " WHERE bms_id = %s AND point_id = %s ", (bid, pid))
1213
        cnx.commit()
1214
1215
        cursor.close()
1216
        cnx.close()
1217
1218
        resp.status = falcon.HTTP_204
1219
1220
1221
class EnergyStorageContainerCommandCollection: