Code Duplication    Length = 64-64 lines in 8 locations

myems-api/core/energystoragecontainer.py 8 locations

@@ 5775-5838 (lines=64) @@
5772
                        str(new_values['data']['point_id'])
5773
5774
5775
class EnergyStorageContainerSTSPointItem:
5776
    def __init__(self):
5777
        """Initializes EnergyStorageContainerSTSPointItem"""
5778
        pass
5779
5780
    @staticmethod
5781
    def on_options(req, resp, id_, fid, pid):
5782
        _ = req
5783
        resp.status = falcon.HTTP_200
5784
        _ = id_
5785
5786
    @staticmethod
5787
    @user_logger
5788
    def on_delete(req, resp, id_, fid, pid):
5789
        """Handles DELETE requests"""
5790
        admin_control(req)
5791
        if not id_.isdigit() or int(id_) <= 0:
5792
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5793
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
5794
        if not fid.isdigit() or int(fid) <= 0:
5795
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5796
                                   description='API.INVALID_STS_ID')
5797
        if not pid.isdigit() or int(pid) <= 0:
5798
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5799
                                   description='API.INVALID_POINT_ID')
5800
5801
        cnx = mysql.connector.connect(**config.myems_system_db)
5802
        cursor = cnx.cursor()
5803
5804
        cursor.execute(" SELECT name "
5805
                       " FROM tbl_energy_storage_containers_stses "
5806
                       " WHERE energy_storage_container_id = %s AND id = %s ", (id_, fid,))
5807
        if cursor.fetchone() is None:
5808
            cursor.close()
5809
            cnx.close()
5810
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5811
                                   description='API.ENERGY_STORAGE_CONTAINER_STS_NOT_FOUND')
5812
5813
        cursor.execute(" SELECT name "
5814
                       " FROM tbl_points "
5815
                       " WHERE id = %s ", (pid,))
5816
        if cursor.fetchone() is None:
5817
            cursor.close()
5818
            cnx.close()
5819
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5820
                                   description='API.POINT_NOT_FOUND')
5821
5822
        cursor.execute(" SELECT id "
5823
                       " FROM tbl_energy_storage_containers_stses_points "
5824
                       " WHERE sts_id = %s AND point_id = %s ", (fid, pid))
5825
        if cursor.fetchone() is None:
5826
            cursor.close()
5827
            cnx.close()
5828
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5829
                                   description='API.STS_POINT_RELATION_NOT_FOUND')
5830
5831
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_stses_points "
5832
                       " WHERE sts_id = %s AND point_id = %s ", (fid, pid))
5833
        cnx.commit()
5834
5835
        cursor.close()
5836
        cnx.close()
5837
5838
        resp.status = falcon.HTTP_204
5839
5840
5841
class EnergyStorageContainerClone:
@@ 4984-5047 (lines=64) @@
4981
                        str(new_values['data']['point_id'])
4982
4983
4984
class EnergyStorageContainerPCSPointItem:
4985
    def __init__(self):
4986
        """Initializes EnergyStorageContainerPCSPointItem"""
4987
        pass
4988
4989
    @staticmethod
4990
    def on_options(req, resp, id_, pcsid, pid):
4991
        _ = req
4992
        resp.status = falcon.HTTP_200
4993
        _ = id_
4994
4995
    @staticmethod
4996
    @user_logger
4997
    def on_delete(req, resp, id_, pcsid, pid):
4998
        """Handles DELETE requests"""
4999
        admin_control(req)
5000
        if not id_.isdigit() or int(id_) <= 0:
5001
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5002
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
5003
        if not pcsid.isdigit() or int(pcsid) <= 0:
5004
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5005
                                   description='API.INVALID_PCS_ID')
5006
        if not pid.isdigit() or int(pid) <= 0:
5007
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5008
                                   description='API.INVALID_POINT_ID')
5009
5010
        cnx = mysql.connector.connect(**config.myems_system_db)
5011
        cursor = cnx.cursor()
5012
5013
        cursor.execute(" SELECT name "
5014
                       " FROM tbl_energy_storage_containers_power_conversion_systems "
5015
                       " WHERE energy_storage_container_id = %s AND id = %s ", (id_, pcsid,))
5016
        if cursor.fetchone() is None:
5017
            cursor.close()
5018
            cnx.close()
5019
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5020
                                   description='API.ENERGY_STORAGE_CONTAINER_PCS_NOT_FOUND')
5021
5022
        cursor.execute(" SELECT name "
5023
                       " FROM tbl_points "
5024
                       " WHERE id = %s ", (pid,))
5025
        if cursor.fetchone() is None:
5026
            cursor.close()
5027
            cnx.close()
5028
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5029
                                   description='API.POINT_NOT_FOUND')
5030
5031
        cursor.execute(" SELECT id "
5032
                       " FROM tbl_energy_storage_containers_pcses_points "
5033
                       " WHERE pcs_id = %s AND point_id = %s ", (pcsid, pid))
5034
        if cursor.fetchone() is None:
5035
            cursor.close()
5036
            cnx.close()
5037
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5038
                                   description='API.PCS_POINT_RELATION_NOT_FOUND')
5039
5040
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_pcses_points "
5041
                       " WHERE pcs_id = %s AND point_id = %s ", (pcsid, pid))
5042
        cnx.commit()
5043
5044
        cursor.close()
5045
        cnx.close()
5046
5047
        resp.status = falcon.HTTP_204
5048
5049
5050
class EnergyStorageContainerScheduleCollection:
@@ 4399-4462 (lines=64) @@
4396
                        str(new_values['data']['point_id'])
4397
4398
4399
class EnergyStorageContainerLoadPointItem:
4400
    def __init__(self):
4401
        """Initializes EnergyStorageContainerLoadPointItem"""
4402
        pass
4403
4404
    @staticmethod
4405
    def on_options(req, resp, id_, lid, pid):
4406
        _ = req
4407
        resp.status = falcon.HTTP_200
4408
        _ = id_
4409
4410
    @staticmethod
4411
    @user_logger
4412
    def on_delete(req, resp, id_, lid, pid):
4413
        """Handles DELETE requests"""
4414
        admin_control(req)
4415
        if not id_.isdigit() or int(id_) <= 0:
4416
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
4417
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
4418
        if not lid.isdigit() or int(lid) <= 0:
4419
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
4420
                                   description='API.INVALID_LOAD_ID')
4421
        if not pid.isdigit() or int(pid) <= 0:
4422
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
4423
                                   description='API.INVALID_POINT_ID')
4424
4425
        cnx = mysql.connector.connect(**config.myems_system_db)
4426
        cursor = cnx.cursor()
4427
4428
        cursor.execute(" SELECT name "
4429
                       " FROM tbl_energy_storage_containers_loads "
4430
                       " WHERE energy_storage_container_id = %s AND id = %s ", (id_, lid,))
4431
        if cursor.fetchone() is None:
4432
            cursor.close()
4433
            cnx.close()
4434
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
4435
                                   description='API.ENERGY_STORAGE_CONTAINER_LOAD_NOT_FOUND')
4436
4437
        cursor.execute(" SELECT name "
4438
                       " FROM tbl_points "
4439
                       " WHERE id = %s ", (pid,))
4440
        if cursor.fetchone() is None:
4441
            cursor.close()
4442
            cnx.close()
4443
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
4444
                                   description='API.POINT_NOT_FOUND')
4445
4446
        cursor.execute(" SELECT id "
4447
                       " FROM tbl_energy_storage_containers_loads_points "
4448
                       " WHERE load_id = %s AND point_id = %s ", (lid, pid))
4449
        if cursor.fetchone() is None:
4450
            cursor.close()
4451
            cnx.close()
4452
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
4453
                                   description='API.LOAD_POINT_RELATION_NOT_FOUND')
4454
4455
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_loads_points "
4456
                       " WHERE load_id = %s AND point_id = %s ", (lid, pid))
4457
        cnx.commit()
4458
4459
        cursor.close()
4460
        cnx.close()
4461
4462
        resp.status = falcon.HTTP_204
4463
4464
4465
class EnergyStorageContainerPCSCollection:
@@ 3764-3827 (lines=64) @@
3761
                        str(new_values['data']['point_id'])
3762
3763
3764
class EnergyStorageContainerHVACPointItem:
3765
    def __init__(self):
3766
        """Initializes EnergyStorageContainerHVACPointItem"""
3767
        pass
3768
3769
    @staticmethod
3770
    def on_options(req, resp, id_, hid, pid):
3771
        _ = req
3772
        resp.status = falcon.HTTP_200
3773
        _ = id_
3774
3775
    @staticmethod
3776
    @user_logger
3777
    def on_delete(req, resp, id_, hid, pid):
3778
        """Handles DELETE requests"""
3779
        admin_control(req)
3780
        if not id_.isdigit() or int(id_) <= 0:
3781
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
3782
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
3783
        if not hid.isdigit() or int(hid) <= 0:
3784
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
3785
                                   description='API.INVALID_HVAC_ID')
3786
        if not pid.isdigit() or int(pid) <= 0:
3787
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
3788
                                   description='API.INVALID_POINT_ID')
3789
3790
        cnx = mysql.connector.connect(**config.myems_system_db)
3791
        cursor = cnx.cursor()
3792
3793
        cursor.execute(" SELECT name "
3794
                       " FROM tbl_energy_storage_containers_hvacs "
3795
                       " WHERE energy_storage_container_id = %s AND id = %s ", (id_, hid,))
3796
        if cursor.fetchone() is None:
3797
            cursor.close()
3798
            cnx.close()
3799
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
3800
                                   description='API.ENERGY_STORAGE_CONTAINER_HVAC_NOT_FOUND')
3801
3802
        cursor.execute(" SELECT name "
3803
                       " FROM tbl_points "
3804
                       " WHERE id = %s ", (pid,))
3805
        if cursor.fetchone() is None:
3806
            cursor.close()
3807
            cnx.close()
3808
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
3809
                                   description='API.POINT_NOT_FOUND')
3810
3811
        cursor.execute(" SELECT id "
3812
                       " FROM tbl_energy_storage_containers_hvacs_points "
3813
                       " WHERE hvac_id = %s AND point_id = %s ", (hid, pid))
3814
        if cursor.fetchone() is None:
3815
            cursor.close()
3816
            cnx.close()
3817
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
3818
                                   description='API.HVAC_POINT_RELATION_NOT_FOUND')
3819
3820
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_hvacs_points "
3821
                       " WHERE hvac_id = %s AND point_id = %s ", (hid, pid))
3822
        cnx.commit()
3823
3824
        cursor.close()
3825
        cnx.close()
3826
3827
        resp.status = falcon.HTTP_204
3828
3829
3830
class EnergyStorageContainerLoadCollection:
@@ 3274-3337 (lines=64) @@
3271
                        str(new_values['data']['point_id'])
3272
3273
3274
class EnergyStorageContainerGridPointItem:
3275
    def __init__(self):
3276
        """Initializes EnergyStorageContainerGridPointItem"""
3277
        pass
3278
3279
    @staticmethod
3280
    def on_options(req, resp, id_, gid, pid):
3281
        _ = req
3282
        resp.status = falcon.HTTP_200
3283
        _ = id_
3284
3285
    @staticmethod
3286
    @user_logger
3287
    def on_delete(req, resp, id_, gid, pid):
3288
        """Handles DELETE requests"""
3289
        admin_control(req)
3290
        if not id_.isdigit() or int(id_) <= 0:
3291
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
3292
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
3293
        if not gid.isdigit() or int(gid) <= 0:
3294
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
3295
                                   description='API.INVALID_GRID_ID')
3296
        if not pid.isdigit() or int(pid) <= 0:
3297
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
3298
                                   description='API.INVALID_POINT_ID')
3299
3300
        cnx = mysql.connector.connect(**config.myems_system_db)
3301
        cursor = cnx.cursor()
3302
3303
        cursor.execute(" SELECT name "
3304
                       " FROM tbl_energy_storage_containers_grids "
3305
                       " WHERE energy_storage_container_id = %s AND id = %s ", (id_, gid,))
3306
        if cursor.fetchone() is None:
3307
            cursor.close()
3308
            cnx.close()
3309
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
3310
                                   description='API.ENERGY_STORAGE_CONTAINER_GRID_NOT_FOUND')
3311
3312
        cursor.execute(" SELECT name "
3313
                       " FROM tbl_points "
3314
                       " WHERE id = %s ", (pid,))
3315
        if cursor.fetchone() is None:
3316
            cursor.close()
3317
            cnx.close()
3318
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
3319
                                   description='API.POINT_NOT_FOUND')
3320
3321
        cursor.execute(" SELECT id "
3322
                       " FROM tbl_energy_storage_containers_grids_points "
3323
                       " WHERE grid_id = %s AND point_id = %s ", (gid, pid))
3324
        if cursor.fetchone() is None:
3325
            cursor.close()
3326
            cnx.close()
3327
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
3328
                                   description='API.GRID_POINT_RELATION_NOT_FOUND')
3329
3330
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_grids_points "
3331
                       " WHERE grid_id = %s AND point_id = %s ", (gid, pid))
3332
        cnx.commit()
3333
3334
        cursor.close()
3335
        cnx.close()
3336
3337
        resp.status = falcon.HTTP_204
3338
3339
3340
class EnergyStorageContainerHVACCollection:
@@ 2599-2662 (lines=64) @@
2596
                        str(new_values['data']['point_id'])
2597
2598
2599
class EnergyStorageContainerFirecontrolPointItem:
2600
    def __init__(self):
2601
        """Initializes EnergyStorageContainerFirecontrolPointItem"""
2602
        pass
2603
2604
    @staticmethod
2605
    def on_options(req, resp, id_, fid, pid):
2606
        _ = req
2607
        resp.status = falcon.HTTP_200
2608
        _ = id_
2609
2610
    @staticmethod
2611
    @user_logger
2612
    def on_delete(req, resp, id_, fid, pid):
2613
        """Handles DELETE requests"""
2614
        admin_control(req)
2615
        if not id_.isdigit() or int(id_) <= 0:
2616
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2617
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
2618
        if not fid.isdigit() or int(fid) <= 0:
2619
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2620
                                   description='API.INVALID_FIRECONTROL_ID')
2621
        if not pid.isdigit() or int(pid) <= 0:
2622
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2623
                                   description='API.INVALID_POINT_ID')
2624
2625
        cnx = mysql.connector.connect(**config.myems_system_db)
2626
        cursor = cnx.cursor()
2627
2628
        cursor.execute(" SELECT name "
2629
                       " FROM tbl_energy_storage_containers_firecontrols "
2630
                       " WHERE energy_storage_container_id = %s AND id = %s ", (id_, fid,))
2631
        if cursor.fetchone() is None:
2632
            cursor.close()
2633
            cnx.close()
2634
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2635
                                   description='API.ENERGY_STORAGE_CONTAINER_FIRECONTROL_NOT_FOUND')
2636
2637
        cursor.execute(" SELECT name "
2638
                       " FROM tbl_points "
2639
                       " WHERE id = %s ", (pid,))
2640
        if cursor.fetchone() is None:
2641
            cursor.close()
2642
            cnx.close()
2643
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2644
                                   description='API.POINT_NOT_FOUND')
2645
2646
        cursor.execute(" SELECT id "
2647
                       " FROM tbl_energy_storage_containers_firecontrols_points "
2648
                       " WHERE firecontrol_id = %s AND point_id = %s ", (fid, pid))
2649
        if cursor.fetchone() is None:
2650
            cursor.close()
2651
            cnx.close()
2652
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2653
                                   description='API.FIRECONTROL_POINT_RELATION_NOT_FOUND')
2654
2655
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_firecontrols_points "
2656
                       " WHERE firecontrol_id = %s AND point_id = %s ", (fid, pid))
2657
        cnx.commit()
2658
2659
        cursor.close()
2660
        cnx.close()
2661
2662
        resp.status = falcon.HTTP_204
2663
2664
2665
class EnergyStorageContainerGridCollection:
@@ 2109-2172 (lines=64) @@
2106
                        str(new_values['data']['point_id'])
2107
2108
2109
class EnergyStorageContainerDCDCPointItem:
2110
    def __init__(self):
2111
        """Initializes MeterPointItem"""
2112
        pass
2113
2114
    @staticmethod
2115
    def on_options(req, resp, id_, did, pid):
2116
        _ = req
2117
        resp.status = falcon.HTTP_200
2118
        _ = id_
2119
2120
    @staticmethod
2121
    @user_logger
2122
    def on_delete(req, resp, id_, did, pid):
2123
        """Handles DELETE requests"""
2124
        admin_control(req)
2125
        if not id_.isdigit() or int(id_) <= 0:
2126
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2127
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
2128
        if not did.isdigit() or int(did) <= 0:
2129
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2130
                                   description='API.INVALID_DCDC_ID')
2131
        if not pid.isdigit() or int(pid) <= 0:
2132
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2133
                                   description='API.INVALID_POINT_ID')
2134
2135
        cnx = mysql.connector.connect(**config.myems_system_db)
2136
        cursor = cnx.cursor()
2137
2138
        cursor.execute(" SELECT name "
2139
                       " FROM tbl_energy_storage_containers_dcdcs "
2140
                       " WHERE energy_storage_container_id = %s AND id = %s ", (id_, did,))
2141
        if cursor.fetchone() is None:
2142
            cursor.close()
2143
            cnx.close()
2144
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2145
                                   description='API.ENERGY_STORAGE_CONTAINER_DCDC_NOT_FOUND')
2146
2147
        cursor.execute(" SELECT name "
2148
                       " FROM tbl_points "
2149
                       " WHERE id = %s ", (pid,))
2150
        if cursor.fetchone() is None:
2151
            cursor.close()
2152
            cnx.close()
2153
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2154
                                   description='API.POINT_NOT_FOUND')
2155
2156
        cursor.execute(" SELECT id "
2157
                       " FROM tbl_energy_storage_containers_dcdcs_points "
2158
                       " WHERE dcdc_id = %s AND point_id = %s ", (did, pid))
2159
        if cursor.fetchone() is None:
2160
            cursor.close()
2161
            cnx.close()
2162
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2163
                                   description='API.DCDC_POINT_RELATION_NOT_FOUND')
2164
2165
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_dcdcs_points "
2166
                       " WHERE dcdc_id = %s AND point_id = %s ", (did, pid))
2167
        cnx.commit()
2168
2169
        cursor.close()
2170
        cnx.close()
2171
2172
        resp.status = falcon.HTTP_204
2173
2174
2175
class EnergyStorageContainerFirecontrolCollection:
@@ 1211-1274 (lines=64) @@
1208
                        str(new_values['data']['point_id'])
1209
1210
1211
class EnergyStorageContainerBatteryPointItem:
1212
    def __init__(self):
1213
        """Initializes MeterPointItem"""
1214
        pass
1215
1216
    @staticmethod
1217
    def on_options(req, resp, id_, bid, pid):
1218
        _ = req
1219
        resp.status = falcon.HTTP_200
1220
        _ = id_
1221
1222
    @staticmethod
1223
    @user_logger
1224
    def on_delete(req, resp, id_, bid, pid):
1225
        """Handles DELETE requests"""
1226
        admin_control(req)
1227
        if not id_.isdigit() or int(id_) <= 0:
1228
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
1229
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
1230
        if not bid.isdigit() or int(bid) <= 0:
1231
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
1232
                                   description='API.INVALID_BMS_ID')
1233
        if not pid.isdigit() or int(pid) <= 0:
1234
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
1235
                                   description='API.INVALID_POINT_ID')
1236
1237
        cnx = mysql.connector.connect(**config.myems_system_db)
1238
        cursor = cnx.cursor()
1239
1240
        cursor.execute(" SELECT name "
1241
                       " FROM tbl_energy_storage_containers_batteries "
1242
                       " WHERE energy_storage_container_id = %s AND id = %s ", (id_, bid,))
1243
        if cursor.fetchone() is None:
1244
            cursor.close()
1245
            cnx.close()
1246
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
1247
                                   description='API.ENERGY_STORAGE_CONTAINER_BMS_NOT_FOUND')
1248
1249
        cursor.execute(" SELECT name "
1250
                       " FROM tbl_points "
1251
                       " WHERE id = %s ", (pid,))
1252
        if cursor.fetchone() is None:
1253
            cursor.close()
1254
            cnx.close()
1255
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
1256
                                   description='API.POINT_NOT_FOUND')
1257
1258
        cursor.execute(" SELECT id "
1259
                       " FROM tbl_energy_storage_containers_bmses_points "
1260
                       " WHERE bms_id = %s AND point_id = %s ", (bid, pid))
1261
        if cursor.fetchone() is None:
1262
            cursor.close()
1263
            cnx.close()
1264
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
1265
                                   description='API.BMS_POINT_RELATION_NOT_FOUND')
1266
1267
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_bmses_points "
1268
                       " WHERE bms_id = %s AND point_id = %s ", (bid, pid))
1269
        cnx.commit()
1270
1271
        cursor.close()
1272
        cnx.close()
1273
1274
        resp.status = falcon.HTTP_204
1275
1276
1277
class EnergyStorageContainerCommandCollection: