Code Duplication    Length = 64-64 lines in 11 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:

myems-api/core/photovoltaicpowerstation.py 3 locations

@@ 5712-5775 (lines=64) @@
5709
                        str(new_values['data']['point_id'])
5710
5711
5712
class PhotovoltaicPowerStationLoadPointItem:
5713
    def __init__(self):
5714
        pass
5715
5716
    @staticmethod
5717
    def on_options(req, resp, id_, lid, pid):
5718
        _ = req
5719
        resp.status = falcon.HTTP_200
5720
        _ = id_
5721
        _ = lid
5722
        _ = pid
5723
5724
    @staticmethod
5725
    @user_logger
5726
    def on_delete(req, resp, id_, lid, pid):
5727
        admin_control(req)
5728
        if not id_.isdigit() or int(id_) <= 0:
5729
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5730
                                   description='API.INVALID_PHOTOVOLTAIC_POWER_STATION_ID')
5731
        if not lid.isdigit() or int(lid) <= 0:
5732
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5733
                                   description='API.INVALID_LOAD_ID')
5734
        if not pid.isdigit() or int(pid) <= 0:
5735
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5736
                                   description='API.INVALID_POINT_ID')
5737
5738
        cnx = mysql.connector.connect(**config.myems_system_db)
5739
        cursor = cnx.cursor()
5740
5741
        cursor.execute(" SELECT name "
5742
                       " FROM tbl_photovoltaic_power_stations_loads "
5743
                       " WHERE photovoltaic_power_station_id = %s AND id = %s ", (id_, lid,))
5744
        if cursor.fetchone() is None:
5745
            cursor.close()
5746
            cnx.close()
5747
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5748
                                   description='API.PHOTOVOLTAIC_LOAD_NOT_FOUND')
5749
5750
        cursor.execute(" SELECT name "
5751
                       " FROM tbl_points "
5752
                       " WHERE id = %s ", (pid,))
5753
        if cursor.fetchone() is None:
5754
            cursor.close()
5755
            cnx.close()
5756
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5757
                                   description='API.POINT_NOT_FOUND')
5758
5759
        cursor.execute(" SELECT id "
5760
                       " FROM tbl_photovoltaic_power_stations_loads_points "
5761
                       " WHERE load_id = %s AND point_id = %s ", (lid, pid))
5762
        if cursor.fetchone() is None:
5763
            cursor.close()
5764
            cnx.close()
5765
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5766
                                   description='API.LOAD_POINT_RELATION_NOT_FOUND')
5767
5768
        cursor.execute(" DELETE FROM tbl_photovoltaic_power_stations_loads_points "
5769
                       " WHERE load_id = %s AND point_id = %s ", (lid, pid))
5770
        cnx.commit()
5771
5772
        cursor.close()
5773
        cnx.close()
5774
5775
        resp.status = falcon.HTTP_204
5776
5777
5778
@@ 5525-5588 (lines=64) @@
5522
                        str(new_values['data']['point_id'])
5523
5524
5525
class PhotovoltaicPowerStationGridPointItem:
5526
    def __init__(self):
5527
        pass
5528
5529
    @staticmethod
5530
    def on_options(req, resp, id_, gid, pid):
5531
        _ = req
5532
        resp.status = falcon.HTTP_200
5533
        _ = id_
5534
        _ = gid
5535
        _ = pid
5536
5537
    @staticmethod
5538
    @user_logger
5539
    def on_delete(req, resp, id_, gid, pid):
5540
        admin_control(req)
5541
        if not id_.isdigit() or int(id_) <= 0:
5542
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5543
                                   description='API.INVALID_PHOTOVOLTAIC_POWER_STATION_ID')
5544
        if not gid.isdigit() or int(gid) <= 0:
5545
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5546
                                   description='API.INVALID_GRID_ID')
5547
        if not pid.isdigit() or int(pid) <= 0:
5548
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5549
                                   description='API.INVALID_POINT_ID')
5550
5551
        cnx = mysql.connector.connect(**config.myems_system_db)
5552
        cursor = cnx.cursor()
5553
5554
        cursor.execute(" SELECT name "
5555
                       " FROM tbl_photovoltaic_power_stations_grids "
5556
                       " WHERE photovoltaic_power_station_id = %s AND id = %s ", (id_, gid,))
5557
        if cursor.fetchone() is None:
5558
            cursor.close()
5559
            cnx.close()
5560
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5561
                                   description='API.PHOTOVOLTAIC_GRID_NOT_FOUND')
5562
5563
        cursor.execute(" SELECT name "
5564
                       " FROM tbl_points "
5565
                       " WHERE id = %s ", (pid,))
5566
        if cursor.fetchone() is None:
5567
            cursor.close()
5568
            cnx.close()
5569
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5570
                                   description='API.POINT_NOT_FOUND')
5571
5572
        cursor.execute(" SELECT id "
5573
                       " FROM tbl_photovoltaic_power_stations_grids_points "
5574
                       " WHERE grid_id = %s AND point_id = %s ", (gid, pid))
5575
        if cursor.fetchone() is None:
5576
            cursor.close()
5577
            cnx.close()
5578
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5579
                                   description='API.GRID_POINT_RELATION_NOT_FOUND')
5580
5581
        cursor.execute(" DELETE FROM tbl_photovoltaic_power_stations_grids_points "
5582
                       " WHERE grid_id = %s AND point_id = %s ", (gid, pid))
5583
        cnx.commit()
5584
5585
        cursor.close()
5586
        cnx.close()
5587
5588
        resp.status = falcon.HTTP_204
5589
5590
5591
class PhotovoltaicPowerStationLoadPointCollection:
@@ 5338-5401 (lines=64) @@
5335
                        str(new_values['data']['point_id'])
5336
5337
5338
class PhotovoltaicPowerStationInvertorPointItem:
5339
    def __init__(self):
5340
        pass
5341
5342
    @staticmethod
5343
    def on_options(req, resp, id_, iid, pid):
5344
        _ = req
5345
        resp.status = falcon.HTTP_200
5346
        _ = id_
5347
        _ = iid
5348
        _ = pid
5349
5350
    @staticmethod
5351
    @user_logger
5352
    def on_delete(req, resp, id_, iid, pid):
5353
        admin_control(req)
5354
        if not id_.isdigit() or int(id_) <= 0:
5355
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5356
                                   description='API.INVALID_PHOTOVOLTAIC_POWER_STATION_ID')
5357
        if not iid.isdigit() or int(iid) <= 0:
5358
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5359
                                   description='API.INVALID_INVERTOR_ID')
5360
        if not pid.isdigit() or int(pid) <= 0:
5361
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
5362
                                   description='API.INVALID_POINT_ID')
5363
5364
        cnx = mysql.connector.connect(**config.myems_system_db)
5365
        cursor = cnx.cursor()
5366
5367
        cursor.execute(" SELECT name "
5368
                       " FROM tbl_photovoltaic_power_stations_invertors "
5369
                       " WHERE photovoltaic_power_station_id = %s AND id = %s ", (id_, iid,))
5370
        if cursor.fetchone() is None:
5371
            cursor.close()
5372
            cnx.close()
5373
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5374
                                   description='API.PHOTOVOLTAIC_INVERTOR_NOT_FOUND')
5375
5376
        cursor.execute(" SELECT name "
5377
                       " FROM tbl_points "
5378
                       " WHERE id = %s ", (pid,))
5379
        if cursor.fetchone() is None:
5380
            cursor.close()
5381
            cnx.close()
5382
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5383
                                   description='API.POINT_NOT_FOUND')
5384
5385
        cursor.execute(" SELECT id "
5386
                       " FROM tbl_photovoltaic_power_stations_invertors_points "
5387
                       " WHERE invertor_id = %s AND point_id = %s ", (iid, pid))
5388
        if cursor.fetchone() is None:
5389
            cursor.close()
5390
            cnx.close()
5391
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
5392
                                   description='API.INVERTOR_POINT_RELATION_NOT_FOUND')
5393
5394
        cursor.execute(" DELETE FROM tbl_photovoltaic_power_stations_invertors_points "
5395
                       " WHERE invertor_id = %s AND point_id = %s ", (iid, pid))
5396
        cnx.commit()
5397
5398
        cursor.close()
5399
        cnx.close()
5400
5401
        resp.status = falcon.HTTP_204
5402
5403
5404
class PhotovoltaicPowerStationGridPointCollection: