| @@ 5673-5734 (lines=62) @@ | ||
| 5670 | str(new_values['data']['point_id']) |
|
| 5671 | ||
| 5672 | ||
| 5673 | class EnergyStorageContainerSTSPointItem: |
|
| 5674 | def __init__(self): |
|
| 5675 | """Initializes EnergyStorageContainerSTSPointItem""" |
|
| 5676 | pass |
|
| 5677 | ||
| 5678 | @staticmethod |
|
| 5679 | def on_options(req, resp, id_, fid, pid): |
|
| 5680 | resp.status = falcon.HTTP_200 |
|
| 5681 | ||
| 5682 | @staticmethod |
|
| 5683 | @user_logger |
|
| 5684 | def on_delete(req, resp, id_, fid, pid): |
|
| 5685 | """Handles DELETE requests""" |
|
| 5686 | admin_control(req) |
|
| 5687 | if not id_.isdigit() or int(id_) <= 0: |
|
| 5688 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5689 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 5690 | if not fid.isdigit() or int(fid) <= 0: |
|
| 5691 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5692 | description='API.INVALID_STS_ID') |
|
| 5693 | if not pid.isdigit() or int(pid) <= 0: |
|
| 5694 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5695 | description='API.INVALID_POINT_ID') |
|
| 5696 | ||
| 5697 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 5698 | cursor = cnx.cursor() |
|
| 5699 | ||
| 5700 | cursor.execute(" SELECT name " |
|
| 5701 | " FROM tbl_energy_storage_containers_stses " |
|
| 5702 | " WHERE energy_storage_container_id = %s AND id = %s ", (id_, fid,)) |
|
| 5703 | if cursor.fetchone() is None: |
|
| 5704 | cursor.close() |
|
| 5705 | cnx.close() |
|
| 5706 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5707 | description='API.ENERGY_STORAGE_CONTAINER_STS_NOT_FOUND') |
|
| 5708 | ||
| 5709 | cursor.execute(" SELECT name " |
|
| 5710 | " FROM tbl_points " |
|
| 5711 | " WHERE id = %s ", (pid,)) |
|
| 5712 | if cursor.fetchone() is None: |
|
| 5713 | cursor.close() |
|
| 5714 | cnx.close() |
|
| 5715 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5716 | description='API.POINT_NOT_FOUND') |
|
| 5717 | ||
| 5718 | cursor.execute(" SELECT id " |
|
| 5719 | " FROM tbl_energy_storage_containers_stses_points " |
|
| 5720 | " WHERE sts_id = %s AND point_id = %s ", (fid, pid)) |
|
| 5721 | if cursor.fetchone() is None: |
|
| 5722 | cursor.close() |
|
| 5723 | cnx.close() |
|
| 5724 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5725 | description='API.STS_POINT_RELATION_NOT_FOUND') |
|
| 5726 | ||
| 5727 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_stses_points " |
|
| 5728 | " WHERE sts_id = %s AND point_id = %s ", (fid, pid)) |
|
| 5729 | cnx.commit() |
|
| 5730 | ||
| 5731 | cursor.close() |
|
| 5732 | cnx.close() |
|
| 5733 | ||
| 5734 | resp.status = falcon.HTTP_204 |
|
| 5735 | ||
| 5736 | ||
| 5737 | class EnergyStorageContainerClone: |
|
| @@ 4899-4960 (lines=62) @@ | ||
| 4896 | str(new_values['data']['point_id']) |
|
| 4897 | ||
| 4898 | ||
| 4899 | class EnergyStorageContainerPCSPointItem: |
|
| 4900 | def __init__(self): |
|
| 4901 | """Initializes EnergyStorageContainerPCSPointItem""" |
|
| 4902 | pass |
|
| 4903 | ||
| 4904 | @staticmethod |
|
| 4905 | def on_options(req, resp, id_, pcsid, pid): |
|
| 4906 | resp.status = falcon.HTTP_200 |
|
| 4907 | ||
| 4908 | @staticmethod |
|
| 4909 | @user_logger |
|
| 4910 | def on_delete(req, resp, id_, pcsid, pid): |
|
| 4911 | """Handles DELETE requests""" |
|
| 4912 | admin_control(req) |
|
| 4913 | if not id_.isdigit() or int(id_) <= 0: |
|
| 4914 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4915 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 4916 | if not pcsid.isdigit() or int(pcsid) <= 0: |
|
| 4917 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4918 | description='API.INVALID_PCS_ID') |
|
| 4919 | if not pid.isdigit() or int(pid) <= 0: |
|
| 4920 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4921 | description='API.INVALID_POINT_ID') |
|
| 4922 | ||
| 4923 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 4924 | cursor = cnx.cursor() |
|
| 4925 | ||
| 4926 | cursor.execute(" SELECT name " |
|
| 4927 | " FROM tbl_energy_storage_containers_power_conversion_systems " |
|
| 4928 | " WHERE energy_storage_container_id = %s AND id = %s ", (id_, pcsid,)) |
|
| 4929 | if cursor.fetchone() is None: |
|
| 4930 | cursor.close() |
|
| 4931 | cnx.close() |
|
| 4932 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4933 | description='API.ENERGY_STORAGE_CONTAINER_PCS_NOT_FOUND') |
|
| 4934 | ||
| 4935 | cursor.execute(" SELECT name " |
|
| 4936 | " FROM tbl_points " |
|
| 4937 | " WHERE id = %s ", (pid,)) |
|
| 4938 | if cursor.fetchone() is None: |
|
| 4939 | cursor.close() |
|
| 4940 | cnx.close() |
|
| 4941 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4942 | description='API.POINT_NOT_FOUND') |
|
| 4943 | ||
| 4944 | cursor.execute(" SELECT id " |
|
| 4945 | " FROM tbl_energy_storage_containers_pcses_points " |
|
| 4946 | " WHERE pcs_id = %s AND point_id = %s ", (pcsid, pid)) |
|
| 4947 | if cursor.fetchone() is None: |
|
| 4948 | cursor.close() |
|
| 4949 | cnx.close() |
|
| 4950 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4951 | description='API.PCS_POINT_RELATION_NOT_FOUND') |
|
| 4952 | ||
| 4953 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_pcses_points " |
|
| 4954 | " WHERE pcs_id = %s AND point_id = %s ", (pcsid, pid)) |
|
| 4955 | cnx.commit() |
|
| 4956 | ||
| 4957 | cursor.close() |
|
| 4958 | cnx.close() |
|
| 4959 | ||
| 4960 | resp.status = falcon.HTTP_204 |
|
| 4961 | ||
| 4962 | ||
| 4963 | class EnergyStorageContainerScheduleCollection: |
|
| @@ 4325-4386 (lines=62) @@ | ||
| 4322 | str(new_values['data']['point_id']) |
|
| 4323 | ||
| 4324 | ||
| 4325 | class EnergyStorageContainerLoadPointItem: |
|
| 4326 | def __init__(self): |
|
| 4327 | """Initializes EnergyStorageContainerLoadPointItem""" |
|
| 4328 | pass |
|
| 4329 | ||
| 4330 | @staticmethod |
|
| 4331 | def on_options(req, resp, id_, lid, pid): |
|
| 4332 | resp.status = falcon.HTTP_200 |
|
| 4333 | ||
| 4334 | @staticmethod |
|
| 4335 | @user_logger |
|
| 4336 | def on_delete(req, resp, id_, lid, pid): |
|
| 4337 | """Handles DELETE requests""" |
|
| 4338 | admin_control(req) |
|
| 4339 | if not id_.isdigit() or int(id_) <= 0: |
|
| 4340 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4341 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 4342 | if not lid.isdigit() or int(lid) <= 0: |
|
| 4343 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4344 | description='API.INVALID_LOAD_ID') |
|
| 4345 | if not pid.isdigit() or int(pid) <= 0: |
|
| 4346 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4347 | description='API.INVALID_POINT_ID') |
|
| 4348 | ||
| 4349 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 4350 | cursor = cnx.cursor() |
|
| 4351 | ||
| 4352 | cursor.execute(" SELECT name " |
|
| 4353 | " FROM tbl_energy_storage_containers_loads " |
|
| 4354 | " WHERE energy_storage_container_id = %s AND id = %s ", (id_, lid,)) |
|
| 4355 | if cursor.fetchone() is None: |
|
| 4356 | cursor.close() |
|
| 4357 | cnx.close() |
|
| 4358 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4359 | description='API.ENERGY_STORAGE_CONTAINER_LOAD_NOT_FOUND') |
|
| 4360 | ||
| 4361 | cursor.execute(" SELECT name " |
|
| 4362 | " FROM tbl_points " |
|
| 4363 | " WHERE id = %s ", (pid,)) |
|
| 4364 | if cursor.fetchone() is None: |
|
| 4365 | cursor.close() |
|
| 4366 | cnx.close() |
|
| 4367 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4368 | description='API.POINT_NOT_FOUND') |
|
| 4369 | ||
| 4370 | cursor.execute(" SELECT id " |
|
| 4371 | " FROM tbl_energy_storage_containers_loads_points " |
|
| 4372 | " WHERE load_id = %s AND point_id = %s ", (lid, pid)) |
|
| 4373 | if cursor.fetchone() is None: |
|
| 4374 | cursor.close() |
|
| 4375 | cnx.close() |
|
| 4376 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4377 | description='API.LOAD_POINT_RELATION_NOT_FOUND') |
|
| 4378 | ||
| 4379 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_loads_points " |
|
| 4380 | " WHERE load_id = %s AND point_id = %s ", (lid, pid)) |
|
| 4381 | cnx.commit() |
|
| 4382 | ||
| 4383 | cursor.close() |
|
| 4384 | cnx.close() |
|
| 4385 | ||
| 4386 | resp.status = falcon.HTTP_204 |
|
| 4387 | ||
| 4388 | ||
| 4389 | class EnergyStorageContainerPCSCollection: |
|
| @@ 3701-3762 (lines=62) @@ | ||
| 3698 | str(new_values['data']['point_id']) |
|
| 3699 | ||
| 3700 | ||
| 3701 | class EnergyStorageContainerHVACPointItem: |
|
| 3702 | def __init__(self): |
|
| 3703 | """Initializes EnergyStorageContainerHVACPointItem""" |
|
| 3704 | pass |
|
| 3705 | ||
| 3706 | @staticmethod |
|
| 3707 | def on_options(req, resp, id_, hid, pid): |
|
| 3708 | resp.status = falcon.HTTP_200 |
|
| 3709 | ||
| 3710 | @staticmethod |
|
| 3711 | @user_logger |
|
| 3712 | def on_delete(req, resp, id_, hid, pid): |
|
| 3713 | """Handles DELETE requests""" |
|
| 3714 | admin_control(req) |
|
| 3715 | if not id_.isdigit() or int(id_) <= 0: |
|
| 3716 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3717 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 3718 | if not hid.isdigit() or int(hid) <= 0: |
|
| 3719 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3720 | description='API.INVALID_HVAC_ID') |
|
| 3721 | if not pid.isdigit() or int(pid) <= 0: |
|
| 3722 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3723 | description='API.INVALID_POINT_ID') |
|
| 3724 | ||
| 3725 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 3726 | cursor = cnx.cursor() |
|
| 3727 | ||
| 3728 | cursor.execute(" SELECT name " |
|
| 3729 | " FROM tbl_energy_storage_containers_hvacs " |
|
| 3730 | " WHERE energy_storage_container_id = %s AND id = %s ", (id_, hid,)) |
|
| 3731 | if cursor.fetchone() is None: |
|
| 3732 | cursor.close() |
|
| 3733 | cnx.close() |
|
| 3734 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3735 | description='API.ENERGY_STORAGE_CONTAINER_HVAC_NOT_FOUND') |
|
| 3736 | ||
| 3737 | cursor.execute(" SELECT name " |
|
| 3738 | " FROM tbl_points " |
|
| 3739 | " WHERE id = %s ", (pid,)) |
|
| 3740 | if cursor.fetchone() is None: |
|
| 3741 | cursor.close() |
|
| 3742 | cnx.close() |
|
| 3743 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3744 | description='API.POINT_NOT_FOUND') |
|
| 3745 | ||
| 3746 | cursor.execute(" SELECT id " |
|
| 3747 | " FROM tbl_energy_storage_containers_hvacs_points " |
|
| 3748 | " WHERE hvac_id = %s AND point_id = %s ", (hid, pid)) |
|
| 3749 | if cursor.fetchone() is None: |
|
| 3750 | cursor.close() |
|
| 3751 | cnx.close() |
|
| 3752 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3753 | description='API.HVAC_POINT_RELATION_NOT_FOUND') |
|
| 3754 | ||
| 3755 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_hvacs_points " |
|
| 3756 | " WHERE hvac_id = %s AND point_id = %s ", (hid, pid)) |
|
| 3757 | cnx.commit() |
|
| 3758 | ||
| 3759 | cursor.close() |
|
| 3760 | cnx.close() |
|
| 3761 | ||
| 3762 | resp.status = falcon.HTTP_204 |
|
| 3763 | ||
| 3764 | ||
| 3765 | class EnergyStorageContainerLoadCollection: |
|
| @@ 3222-3283 (lines=62) @@ | ||
| 3219 | str(new_values['data']['point_id']) |
|
| 3220 | ||
| 3221 | ||
| 3222 | class EnergyStorageContainerGridPointItem: |
|
| 3223 | def __init__(self): |
|
| 3224 | """Initializes EnergyStorageContainerGridPointItem""" |
|
| 3225 | pass |
|
| 3226 | ||
| 3227 | @staticmethod |
|
| 3228 | def on_options(req, resp, id_, gid, pid): |
|
| 3229 | resp.status = falcon.HTTP_200 |
|
| 3230 | ||
| 3231 | @staticmethod |
|
| 3232 | @user_logger |
|
| 3233 | def on_delete(req, resp, id_, gid, pid): |
|
| 3234 | """Handles DELETE requests""" |
|
| 3235 | admin_control(req) |
|
| 3236 | if not id_.isdigit() or int(id_) <= 0: |
|
| 3237 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3238 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 3239 | if not gid.isdigit() or int(gid) <= 0: |
|
| 3240 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3241 | description='API.INVALID_GRID_ID') |
|
| 3242 | if not pid.isdigit() or int(pid) <= 0: |
|
| 3243 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3244 | description='API.INVALID_POINT_ID') |
|
| 3245 | ||
| 3246 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 3247 | cursor = cnx.cursor() |
|
| 3248 | ||
| 3249 | cursor.execute(" SELECT name " |
|
| 3250 | " FROM tbl_energy_storage_containers_grids " |
|
| 3251 | " WHERE energy_storage_container_id = %s AND id = %s ", (id_, gid,)) |
|
| 3252 | if cursor.fetchone() is None: |
|
| 3253 | cursor.close() |
|
| 3254 | cnx.close() |
|
| 3255 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3256 | description='API.ENERGY_STORAGE_CONTAINER_GRID_NOT_FOUND') |
|
| 3257 | ||
| 3258 | cursor.execute(" SELECT name " |
|
| 3259 | " FROM tbl_points " |
|
| 3260 | " WHERE id = %s ", (pid,)) |
|
| 3261 | if cursor.fetchone() is None: |
|
| 3262 | cursor.close() |
|
| 3263 | cnx.close() |
|
| 3264 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3265 | description='API.POINT_NOT_FOUND') |
|
| 3266 | ||
| 3267 | cursor.execute(" SELECT id " |
|
| 3268 | " FROM tbl_energy_storage_containers_grids_points " |
|
| 3269 | " WHERE grid_id = %s AND point_id = %s ", (gid, pid)) |
|
| 3270 | if cursor.fetchone() is None: |
|
| 3271 | cursor.close() |
|
| 3272 | cnx.close() |
|
| 3273 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3274 | description='API.GRID_POINT_RELATION_NOT_FOUND') |
|
| 3275 | ||
| 3276 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_grids_points " |
|
| 3277 | " WHERE grid_id = %s AND point_id = %s ", (gid, pid)) |
|
| 3278 | cnx.commit() |
|
| 3279 | ||
| 3280 | cursor.close() |
|
| 3281 | cnx.close() |
|
| 3282 | ||
| 3283 | resp.status = falcon.HTTP_204 |
|
| 3284 | ||
| 3285 | ||
| 3286 | class EnergyStorageContainerHVACCollection: |
|
| @@ 2558-2619 (lines=62) @@ | ||
| 2555 | str(new_values['data']['point_id']) |
|
| 2556 | ||
| 2557 | ||
| 2558 | class EnergyStorageContainerFirecontrolPointItem: |
|
| 2559 | def __init__(self): |
|
| 2560 | """Initializes EnergyStorageContainerFirecontrolPointItem""" |
|
| 2561 | pass |
|
| 2562 | ||
| 2563 | @staticmethod |
|
| 2564 | def on_options(req, resp, id_, fid, pid): |
|
| 2565 | resp.status = falcon.HTTP_200 |
|
| 2566 | ||
| 2567 | @staticmethod |
|
| 2568 | @user_logger |
|
| 2569 | def on_delete(req, resp, id_, fid, pid): |
|
| 2570 | """Handles DELETE requests""" |
|
| 2571 | admin_control(req) |
|
| 2572 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2573 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2574 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 2575 | if not fid.isdigit() or int(fid) <= 0: |
|
| 2576 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2577 | description='API.INVALID_FIRECONTROL_ID') |
|
| 2578 | if not pid.isdigit() or int(pid) <= 0: |
|
| 2579 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2580 | description='API.INVALID_POINT_ID') |
|
| 2581 | ||
| 2582 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2583 | cursor = cnx.cursor() |
|
| 2584 | ||
| 2585 | cursor.execute(" SELECT name " |
|
| 2586 | " FROM tbl_energy_storage_containers_firecontrols " |
|
| 2587 | " WHERE energy_storage_container_id = %s AND id = %s ", (id_, fid,)) |
|
| 2588 | if cursor.fetchone() is None: |
|
| 2589 | cursor.close() |
|
| 2590 | cnx.close() |
|
| 2591 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2592 | description='API.ENERGY_STORAGE_CONTAINER_FIRECONTROL_NOT_FOUND') |
|
| 2593 | ||
| 2594 | cursor.execute(" SELECT name " |
|
| 2595 | " FROM tbl_points " |
|
| 2596 | " WHERE id = %s ", (pid,)) |
|
| 2597 | if cursor.fetchone() is None: |
|
| 2598 | cursor.close() |
|
| 2599 | cnx.close() |
|
| 2600 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2601 | description='API.POINT_NOT_FOUND') |
|
| 2602 | ||
| 2603 | cursor.execute(" SELECT id " |
|
| 2604 | " FROM tbl_energy_storage_containers_firecontrols_points " |
|
| 2605 | " WHERE firecontrol_id = %s AND point_id = %s ", (fid, pid)) |
|
| 2606 | if cursor.fetchone() is None: |
|
| 2607 | cursor.close() |
|
| 2608 | cnx.close() |
|
| 2609 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2610 | description='API.FIRECONTROL_POINT_RELATION_NOT_FOUND') |
|
| 2611 | ||
| 2612 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_firecontrols_points " |
|
| 2613 | " WHERE firecontrol_id = %s AND point_id = %s ", (fid, pid)) |
|
| 2614 | cnx.commit() |
|
| 2615 | ||
| 2616 | cursor.close() |
|
| 2617 | cnx.close() |
|
| 2618 | ||
| 2619 | resp.status = falcon.HTTP_204 |
|
| 2620 | ||
| 2621 | ||
| 2622 | class EnergyStorageContainerGridCollection: |
|
| @@ 2079-2140 (lines=62) @@ | ||
| 2076 | str(new_values['data']['point_id']) |
|
| 2077 | ||
| 2078 | ||
| 2079 | class EnergyStorageContainerDCDCPointItem: |
|
| 2080 | def __init__(self): |
|
| 2081 | """Initializes MeterPointItem""" |
|
| 2082 | pass |
|
| 2083 | ||
| 2084 | @staticmethod |
|
| 2085 | def on_options(req, resp, id_, did, pid): |
|
| 2086 | resp.status = falcon.HTTP_200 |
|
| 2087 | ||
| 2088 | @staticmethod |
|
| 2089 | @user_logger |
|
| 2090 | def on_delete(req, resp, id_, did, pid): |
|
| 2091 | """Handles DELETE requests""" |
|
| 2092 | admin_control(req) |
|
| 2093 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2094 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2095 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 2096 | if not did.isdigit() or int(did) <= 0: |
|
| 2097 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2098 | description='API.INVALID_DCDC_ID') |
|
| 2099 | if not pid.isdigit() or int(pid) <= 0: |
|
| 2100 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2101 | description='API.INVALID_POINT_ID') |
|
| 2102 | ||
| 2103 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2104 | cursor = cnx.cursor() |
|
| 2105 | ||
| 2106 | cursor.execute(" SELECT name " |
|
| 2107 | " FROM tbl_energy_storage_containers_dcdcs " |
|
| 2108 | " WHERE energy_storage_container_id = %s AND id = %s ", (id_, did,)) |
|
| 2109 | if cursor.fetchone() is None: |
|
| 2110 | cursor.close() |
|
| 2111 | cnx.close() |
|
| 2112 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2113 | description='API.ENERGY_STORAGE_CONTAINER_DCDC_NOT_FOUND') |
|
| 2114 | ||
| 2115 | cursor.execute(" SELECT name " |
|
| 2116 | " FROM tbl_points " |
|
| 2117 | " WHERE id = %s ", (pid,)) |
|
| 2118 | if cursor.fetchone() is None: |
|
| 2119 | cursor.close() |
|
| 2120 | cnx.close() |
|
| 2121 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2122 | description='API.POINT_NOT_FOUND') |
|
| 2123 | ||
| 2124 | cursor.execute(" SELECT id " |
|
| 2125 | " FROM tbl_energy_storage_containers_dcdcs_points " |
|
| 2126 | " WHERE dcdc_id = %s AND point_id = %s ", (did, pid)) |
|
| 2127 | if cursor.fetchone() is None: |
|
| 2128 | cursor.close() |
|
| 2129 | cnx.close() |
|
| 2130 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2131 | description='API.DCDC_POINT_RELATION_NOT_FOUND') |
|
| 2132 | ||
| 2133 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_dcdcs_points " |
|
| 2134 | " WHERE dcdc_id = %s AND point_id = %s ", (did, pid)) |
|
| 2135 | cnx.commit() |
|
| 2136 | ||
| 2137 | cursor.close() |
|
| 2138 | cnx.close() |
|
| 2139 | ||
| 2140 | resp.status = falcon.HTTP_204 |
|
| 2141 | ||
| 2142 | ||
| 2143 | class EnergyStorageContainerFirecontrolCollection: |
|
| @@ 1424-1485 (lines=62) @@ | ||
| 1421 | str(new_values['data']['point_id']) |
|
| 1422 | ||
| 1423 | ||
| 1424 | class EnergyStorageContainerBatteryPointItem: |
|
| 1425 | def __init__(self): |
|
| 1426 | """Initializes MeterPointItem""" |
|
| 1427 | pass |
|
| 1428 | ||
| 1429 | @staticmethod |
|
| 1430 | def on_options(req, resp, id_, bid, pid): |
|
| 1431 | resp.status = falcon.HTTP_200 |
|
| 1432 | ||
| 1433 | @staticmethod |
|
| 1434 | @user_logger |
|
| 1435 | def on_delete(req, resp, id_, bid, pid): |
|
| 1436 | """Handles DELETE requests""" |
|
| 1437 | admin_control(req) |
|
| 1438 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1439 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1440 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 1441 | if not bid.isdigit() or int(bid) <= 0: |
|
| 1442 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1443 | description='API.INVALID_BMS_ID') |
|
| 1444 | if not pid.isdigit() or int(pid) <= 0: |
|
| 1445 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1446 | description='API.INVALID_POINT_ID') |
|
| 1447 | ||
| 1448 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1449 | cursor = cnx.cursor() |
|
| 1450 | ||
| 1451 | cursor.execute(" SELECT name " |
|
| 1452 | " FROM tbl_energy_storage_containers_batteries " |
|
| 1453 | " WHERE energy_storage_container_id = %s AND id = %s ", (id_, bid,)) |
|
| 1454 | if cursor.fetchone() is None: |
|
| 1455 | cursor.close() |
|
| 1456 | cnx.close() |
|
| 1457 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1458 | description='API.ENERGY_STORAGE_CONTAINER_BMS_NOT_FOUND') |
|
| 1459 | ||
| 1460 | cursor.execute(" SELECT name " |
|
| 1461 | " FROM tbl_points " |
|
| 1462 | " WHERE id = %s ", (pid,)) |
|
| 1463 | if cursor.fetchone() is None: |
|
| 1464 | cursor.close() |
|
| 1465 | cnx.close() |
|
| 1466 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1467 | description='API.POINT_NOT_FOUND') |
|
| 1468 | ||
| 1469 | cursor.execute(" SELECT id " |
|
| 1470 | " FROM tbl_energy_storage_containers_bmses_points " |
|
| 1471 | " WHERE bms_id = %s AND point_id = %s ", (bid, pid)) |
|
| 1472 | if cursor.fetchone() is None: |
|
| 1473 | cursor.close() |
|
| 1474 | cnx.close() |
|
| 1475 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1476 | description='API.BMS_POINT_RELATION_NOT_FOUND') |
|
| 1477 | ||
| 1478 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_bmses_points " |
|
| 1479 | " WHERE bms_id = %s AND point_id = %s ", (bid, pid)) |
|
| 1480 | cnx.commit() |
|
| 1481 | ||
| 1482 | cursor.close() |
|
| 1483 | cnx.close() |
|
| 1484 | ||
| 1485 | resp.status = falcon.HTTP_204 |
|
| 1486 | ||
| 1487 | ||
| 1488 | class EnergyStorageContainerCommandCollection: |
|
| @@ 4890-4951 (lines=62) @@ | ||
| 4887 | str(new_values['data']['point_id']) |
|
| 4888 | ||
| 4889 | ||
| 4890 | class HybridPowerStationPVPointItem: |
|
| 4891 | def __init__(self): |
|
| 4892 | """Initializes Class""" |
|
| 4893 | pass |
|
| 4894 | ||
| 4895 | @staticmethod |
|
| 4896 | def on_options(req, resp, id_, pvid, pid): |
|
| 4897 | resp.status = falcon.HTTP_200 |
|
| 4898 | ||
| 4899 | @staticmethod |
|
| 4900 | @user_logger |
|
| 4901 | def on_delete(req, resp, id_, pvid, pid): |
|
| 4902 | """Handles DELETE requests""" |
|
| 4903 | admin_control(req) |
|
| 4904 | if not id_.isdigit() or int(id_) <= 0: |
|
| 4905 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4906 | description='API.INVALID_HYBRID_POWER_STATION_ID') |
|
| 4907 | if not pvid.isdigit() or int(pvid) <= 0: |
|
| 4908 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4909 | description='API.INVALID_PV_ID') |
|
| 4910 | if not pid.isdigit() or int(pid) <= 0: |
|
| 4911 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4912 | description='API.INVALID_POINT_ID') |
|
| 4913 | ||
| 4914 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 4915 | cursor = cnx.cursor() |
|
| 4916 | ||
| 4917 | cursor.execute(" SELECT name " |
|
| 4918 | " FROM tbl_hybrid_power_stations_pvs " |
|
| 4919 | " WHERE hybrid_power_station_id = %s AND id = %s ", (id_, pvid,)) |
|
| 4920 | if cursor.fetchone() is None: |
|
| 4921 | cursor.close() |
|
| 4922 | cnx.close() |
|
| 4923 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4924 | description='API.HYBRID_POWER_STATION_PV_NOT_FOUND') |
|
| 4925 | ||
| 4926 | cursor.execute(" SELECT name " |
|
| 4927 | " FROM tbl_points " |
|
| 4928 | " WHERE id = %s ", (pid,)) |
|
| 4929 | if cursor.fetchone() is None: |
|
| 4930 | cursor.close() |
|
| 4931 | cnx.close() |
|
| 4932 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4933 | description='API.POINT_NOT_FOUND') |
|
| 4934 | ||
| 4935 | cursor.execute(" SELECT id " |
|
| 4936 | " FROM tbl_hybrid_power_stations_pvs_points " |
|
| 4937 | " WHERE pv_id = %s AND point_id = %s ", (pvid, pid)) |
|
| 4938 | if cursor.fetchone() is None: |
|
| 4939 | cursor.close() |
|
| 4940 | cnx.close() |
|
| 4941 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4942 | description='API.PV_POINT_RELATION_NOT_FOUND') |
|
| 4943 | ||
| 4944 | cursor.execute(" DELETE FROM tbl_hybrid_power_stations_pvs_points " |
|
| 4945 | " WHERE pv_id = %s AND point_id = %s ", (pvid, pid)) |
|
| 4946 | cnx.commit() |
|
| 4947 | ||
| 4948 | cursor.close() |
|
| 4949 | cnx.close() |
|
| 4950 | ||
| 4951 | resp.status = falcon.HTTP_204 |
|
| 4952 | ||
| 4953 | ||
| 4954 | class HybridPowerStationUserCollection: |
|
| @@ 4328-4389 (lines=62) @@ | ||
| 4325 | str(new_values['data']['point_id']) |
|
| 4326 | ||
| 4327 | ||
| 4328 | class HybridPowerStationPCSPointItem: |
|
| 4329 | def __init__(self): |
|
| 4330 | """Initializes Class""" |
|
| 4331 | pass |
|
| 4332 | ||
| 4333 | @staticmethod |
|
| 4334 | def on_options(req, resp, id_, pcsid, pid): |
|
| 4335 | resp.status = falcon.HTTP_200 |
|
| 4336 | ||
| 4337 | @staticmethod |
|
| 4338 | @user_logger |
|
| 4339 | def on_delete(req, resp, id_, pcsid, pid): |
|
| 4340 | """Handles DELETE requests""" |
|
| 4341 | admin_control(req) |
|
| 4342 | if not id_.isdigit() or int(id_) <= 0: |
|
| 4343 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4344 | description='API.INVALID_HYBRID_POWER_STATION_ID') |
|
| 4345 | if not pcsid.isdigit() or int(pcsid) <= 0: |
|
| 4346 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4347 | description='API.INVALID_PCS_ID') |
|
| 4348 | if not pid.isdigit() or int(pid) <= 0: |
|
| 4349 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4350 | description='API.INVALID_POINT_ID') |
|
| 4351 | ||
| 4352 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 4353 | cursor = cnx.cursor() |
|
| 4354 | ||
| 4355 | cursor.execute(" SELECT name " |
|
| 4356 | " FROM tbl_hybrid_power_stations_pcses " |
|
| 4357 | " WHERE hybrid_power_station_id = %s AND id = %s ", (id_, pcsid,)) |
|
| 4358 | if cursor.fetchone() is None: |
|
| 4359 | cursor.close() |
|
| 4360 | cnx.close() |
|
| 4361 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4362 | description='API.HYBRID_POWER_STATION_PCS_NOT_FOUND') |
|
| 4363 | ||
| 4364 | cursor.execute(" SELECT name " |
|
| 4365 | " FROM tbl_points " |
|
| 4366 | " WHERE id = %s ", (pid,)) |
|
| 4367 | if cursor.fetchone() is None: |
|
| 4368 | cursor.close() |
|
| 4369 | cnx.close() |
|
| 4370 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4371 | description='API.POINT_NOT_FOUND') |
|
| 4372 | ||
| 4373 | cursor.execute(" SELECT id " |
|
| 4374 | " FROM tbl_hybrid_power_stations_pcses_points " |
|
| 4375 | " WHERE pcs_id = %s AND point_id = %s ", (pcsid, pid)) |
|
| 4376 | if cursor.fetchone() is None: |
|
| 4377 | cursor.close() |
|
| 4378 | cnx.close() |
|
| 4379 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4380 | description='API.PCS_POINT_RELATION_NOT_FOUND') |
|
| 4381 | ||
| 4382 | cursor.execute(" DELETE FROM tbl_hybrid_power_stations_pcses_points " |
|
| 4383 | " WHERE pcs_id = %s AND point_id = %s ", (pcsid, pid)) |
|
| 4384 | cnx.commit() |
|
| 4385 | ||
| 4386 | cursor.close() |
|
| 4387 | cnx.close() |
|
| 4388 | ||
| 4389 | resp.status = falcon.HTTP_204 |
|
| 4390 | ||
| 4391 | ||
| 4392 | class HybridPowerStationPVCollection: |
|
| @@ 3746-3807 (lines=62) @@ | ||
| 3743 | str(new_values['data']['point_id']) |
|
| 3744 | ||
| 3745 | ||
| 3746 | class HybridPowerStationMCUPointItem: |
|
| 3747 | def __init__(self): |
|
| 3748 | """Initializes Class""" |
|
| 3749 | pass |
|
| 3750 | ||
| 3751 | @staticmethod |
|
| 3752 | def on_options(req, resp, id_, gid, pid): |
|
| 3753 | resp.status = falcon.HTTP_200 |
|
| 3754 | ||
| 3755 | @staticmethod |
|
| 3756 | @user_logger |
|
| 3757 | def on_delete(req, resp, id_, mid, pid): |
|
| 3758 | """Handles DELETE requests""" |
|
| 3759 | admin_control(req) |
|
| 3760 | if not id_.isdigit() or int(id_) <= 0: |
|
| 3761 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3762 | description='API.INVALID_HYBRID_POWER_STATION_ID') |
|
| 3763 | if not mid.isdigit() or int(mid) <= 0: |
|
| 3764 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3765 | description='API.INVALID_MCU_ID') |
|
| 3766 | if not pid.isdigit() or int(pid) <= 0: |
|
| 3767 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3768 | description='API.INVALID_POINT_ID') |
|
| 3769 | ||
| 3770 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 3771 | cursor = cnx.cursor() |
|
| 3772 | ||
| 3773 | cursor.execute(" SELECT name " |
|
| 3774 | " FROM tbl_hybrid_power_stations_mcus " |
|
| 3775 | " WHERE hybrid_power_station_id = %s AND id = %s ", (id_, mid,)) |
|
| 3776 | if cursor.fetchone() is None: |
|
| 3777 | cursor.close() |
|
| 3778 | cnx.close() |
|
| 3779 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3780 | description='API.HYBRID_POWER_STATION_MCU_NOT_FOUND') |
|
| 3781 | ||
| 3782 | cursor.execute(" SELECT name " |
|
| 3783 | " FROM tbl_points " |
|
| 3784 | " WHERE id = %s ", (pid,)) |
|
| 3785 | if cursor.fetchone() is None: |
|
| 3786 | cursor.close() |
|
| 3787 | cnx.close() |
|
| 3788 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3789 | description='API.POINT_NOT_FOUND') |
|
| 3790 | ||
| 3791 | cursor.execute(" SELECT id " |
|
| 3792 | " FROM tbl_hybrid_power_stations_mcus_points " |
|
| 3793 | " WHERE mcu_id = %s AND point_id = %s ", (mid, pid)) |
|
| 3794 | if cursor.fetchone() is None: |
|
| 3795 | cursor.close() |
|
| 3796 | cnx.close() |
|
| 3797 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3798 | description='API.MCU_POINT_RELATION_NOT_FOUND') |
|
| 3799 | ||
| 3800 | cursor.execute(" DELETE FROM tbl_hybrid_power_stations_mcus_points " |
|
| 3801 | " WHERE mcu_id = %s AND point_id = %s ", (mid, pid)) |
|
| 3802 | cnx.commit() |
|
| 3803 | ||
| 3804 | cursor.close() |
|
| 3805 | cnx.close() |
|
| 3806 | ||
| 3807 | resp.status = falcon.HTTP_204 |
|
| 3808 | ||
| 3809 | ||
| 3810 | class HybridPowerStationPCSCollection: |
|
| @@ 3178-3239 (lines=62) @@ | ||
| 3175 | str(new_values['data']['point_id']) |
|
| 3176 | ||
| 3177 | ||
| 3178 | class HybridPowerStationLoadPointItem: |
|
| 3179 | def __init__(self): |
|
| 3180 | """Initializes Class""" |
|
| 3181 | pass |
|
| 3182 | ||
| 3183 | @staticmethod |
|
| 3184 | def on_options(req, resp, id_, lid, pid): |
|
| 3185 | resp.status = falcon.HTTP_200 |
|
| 3186 | ||
| 3187 | @staticmethod |
|
| 3188 | @user_logger |
|
| 3189 | def on_delete(req, resp, id_, lid, pid): |
|
| 3190 | """Handles DELETE requests""" |
|
| 3191 | admin_control(req) |
|
| 3192 | if not id_.isdigit() or int(id_) <= 0: |
|
| 3193 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3194 | description='API.INVALID_HYBRID_POWER_STATION_ID') |
|
| 3195 | if not lid.isdigit() or int(lid) <= 0: |
|
| 3196 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3197 | description='API.INVALID_LOAD_ID') |
|
| 3198 | if not pid.isdigit() or int(pid) <= 0: |
|
| 3199 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3200 | description='API.INVALID_POINT_ID') |
|
| 3201 | ||
| 3202 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 3203 | cursor = cnx.cursor() |
|
| 3204 | ||
| 3205 | cursor.execute(" SELECT name " |
|
| 3206 | " FROM tbl_hybrid_power_stations_loads " |
|
| 3207 | " WHERE hybrid_power_station_id = %s AND id = %s ", (id_, lid,)) |
|
| 3208 | if cursor.fetchone() is None: |
|
| 3209 | cursor.close() |
|
| 3210 | cnx.close() |
|
| 3211 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3212 | description='API.HYBRID_POWER_STATION_LOAD_NOT_FOUND') |
|
| 3213 | ||
| 3214 | cursor.execute(" SELECT name " |
|
| 3215 | " FROM tbl_points " |
|
| 3216 | " WHERE id = %s ", (pid,)) |
|
| 3217 | if cursor.fetchone() is None: |
|
| 3218 | cursor.close() |
|
| 3219 | cnx.close() |
|
| 3220 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3221 | description='API.POINT_NOT_FOUND') |
|
| 3222 | ||
| 3223 | cursor.execute(" SELECT id " |
|
| 3224 | " FROM tbl_hybrid_power_stations_loads_points " |
|
| 3225 | " WHERE load_id = %s AND point_id = %s ", (lid, pid)) |
|
| 3226 | if cursor.fetchone() is None: |
|
| 3227 | cursor.close() |
|
| 3228 | cnx.close() |
|
| 3229 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3230 | description='API.LOAD_POINT_RELATION_NOT_FOUND') |
|
| 3231 | ||
| 3232 | cursor.execute(" DELETE FROM tbl_hybrid_power_stations_loads_points " |
|
| 3233 | " WHERE load_id = %s AND point_id = %s ", (lid, pid)) |
|
| 3234 | cnx.commit() |
|
| 3235 | ||
| 3236 | cursor.close() |
|
| 3237 | cnx.close() |
|
| 3238 | ||
| 3239 | resp.status = falcon.HTTP_204 |
|
| 3240 | ||
| 3241 | ||
| 3242 | class HybridPowerStationMCUCollection: |
|
| @@ 2582-2643 (lines=62) @@ | ||
| 2579 | str(new_values['data']['point_id']) |
|
| 2580 | ||
| 2581 | ||
| 2582 | class HybridPowerStationGeneratorPointItem: |
|
| 2583 | def __init__(self): |
|
| 2584 | """Initializes Class""" |
|
| 2585 | pass |
|
| 2586 | ||
| 2587 | @staticmethod |
|
| 2588 | def on_options(req, resp, id_, gid, pid): |
|
| 2589 | resp.status = falcon.HTTP_200 |
|
| 2590 | ||
| 2591 | @staticmethod |
|
| 2592 | @user_logger |
|
| 2593 | def on_delete(req, resp, id_, gid, pid): |
|
| 2594 | """Handles DELETE requests""" |
|
| 2595 | admin_control(req) |
|
| 2596 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2597 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2598 | description='API.INVALID_HYBRID_POWER_STATION_ID') |
|
| 2599 | if not gid.isdigit() or int(gid) <= 0: |
|
| 2600 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2601 | description='API.INVALID_GENERATOR_ID') |
|
| 2602 | if not pid.isdigit() or int(pid) <= 0: |
|
| 2603 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2604 | description='API.INVALID_POINT_ID') |
|
| 2605 | ||
| 2606 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2607 | cursor = cnx.cursor() |
|
| 2608 | ||
| 2609 | cursor.execute(" SELECT name " |
|
| 2610 | " FROM tbl_hybrid_power_stations_generators " |
|
| 2611 | " WHERE hybrid_power_station_id = %s AND id = %s ", (id_, gid,)) |
|
| 2612 | if cursor.fetchone() is None: |
|
| 2613 | cursor.close() |
|
| 2614 | cnx.close() |
|
| 2615 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2616 | description='API.HYBRID_POWER_STATION_GENERATOR_NOT_FOUND') |
|
| 2617 | ||
| 2618 | cursor.execute(" SELECT name " |
|
| 2619 | " FROM tbl_points " |
|
| 2620 | " WHERE id = %s ", (pid,)) |
|
| 2621 | if cursor.fetchone() is None: |
|
| 2622 | cursor.close() |
|
| 2623 | cnx.close() |
|
| 2624 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2625 | description='API.POINT_NOT_FOUND') |
|
| 2626 | ||
| 2627 | cursor.execute(" SELECT id " |
|
| 2628 | " FROM tbl_hybrid_power_stations_generators_points " |
|
| 2629 | " WHERE generator_id = %s AND point_id = %s ", (gid, pid)) |
|
| 2630 | if cursor.fetchone() is None: |
|
| 2631 | cursor.close() |
|
| 2632 | cnx.close() |
|
| 2633 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2634 | description='API.GENERATOR_POINT_RELATION_NOT_FOUND') |
|
| 2635 | ||
| 2636 | cursor.execute(" DELETE FROM tbl_hybrid_power_stations_generators_points " |
|
| 2637 | " WHERE generator_id = %s AND point_id = %s ", (gid, pid)) |
|
| 2638 | cnx.commit() |
|
| 2639 | ||
| 2640 | cursor.close() |
|
| 2641 | cnx.close() |
|
| 2642 | ||
| 2643 | resp.status = falcon.HTTP_204 |
|
| 2644 | ||
| 2645 | ||
| 2646 | class HybridPowerStationLoadCollection: |
|
| @@ 1998-2059 (lines=62) @@ | ||
| 1995 | str(new_values['data']['point_id']) |
|
| 1996 | ||
| 1997 | ||
| 1998 | class HybridPowerStationCMPointItem: |
|
| 1999 | def __init__(self): |
|
| 2000 | """Initializes Class""" |
|
| 2001 | pass |
|
| 2002 | ||
| 2003 | @staticmethod |
|
| 2004 | def on_options(req, resp, id_, cid, pid): |
|
| 2005 | resp.status = falcon.HTTP_200 |
|
| 2006 | ||
| 2007 | @staticmethod |
|
| 2008 | @user_logger |
|
| 2009 | def on_delete(req, resp, id_, cid, pid): |
|
| 2010 | """Handles DELETE requests""" |
|
| 2011 | admin_control(req) |
|
| 2012 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2013 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2014 | description='API.INVALID_HYBRID_POWER_STATION_ID') |
|
| 2015 | if not cid.isdigit() or int(cid) <= 0: |
|
| 2016 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2017 | description='API.INVALID_CM_ID') |
|
| 2018 | if not pid.isdigit() or int(pid) <= 0: |
|
| 2019 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2020 | description='API.INVALID_POINT_ID') |
|
| 2021 | ||
| 2022 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2023 | cursor = cnx.cursor() |
|
| 2024 | ||
| 2025 | cursor.execute(" SELECT name " |
|
| 2026 | " FROM tbl_hybrid_power_stations_cms " |
|
| 2027 | " WHERE hybrid_power_station_id = %s AND id = %s ", (id_, cid,)) |
|
| 2028 | if cursor.fetchone() is None: |
|
| 2029 | cursor.close() |
|
| 2030 | cnx.close() |
|
| 2031 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2032 | description='API.HYBRID_POWER_STATION_CM_NOT_FOUND') |
|
| 2033 | ||
| 2034 | cursor.execute(" SELECT name " |
|
| 2035 | " FROM tbl_points " |
|
| 2036 | " WHERE id = %s ", (pid,)) |
|
| 2037 | if cursor.fetchone() is None: |
|
| 2038 | cursor.close() |
|
| 2039 | cnx.close() |
|
| 2040 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2041 | description='API.POINT_NOT_FOUND') |
|
| 2042 | ||
| 2043 | cursor.execute(" SELECT id " |
|
| 2044 | " FROM tbl_hybrid_power_stations_cms_points " |
|
| 2045 | " WHERE cm_id = %s AND point_id = %s ", (cid, pid)) |
|
| 2046 | if cursor.fetchone() is None: |
|
| 2047 | cursor.close() |
|
| 2048 | cnx.close() |
|
| 2049 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2050 | description='API.CM_POINT_RELATION_NOT_FOUND') |
|
| 2051 | ||
| 2052 | cursor.execute(" DELETE FROM tbl_hybrid_power_stations_cms_points " |
|
| 2053 | " WHERE cm_id = %s AND point_id = %s ", (cid, pid)) |
|
| 2054 | cnx.commit() |
|
| 2055 | ||
| 2056 | cursor.close() |
|
| 2057 | cnx.close() |
|
| 2058 | ||
| 2059 | resp.status = falcon.HTTP_204 |
|
| 2060 | ||
| 2061 | ||
| 2062 | class HybridPowerStationGeneratorCollection: |
|
| @@ 1260-1321 (lines=62) @@ | ||
| 1257 | str(new_values['data']['point_id']) |
|
| 1258 | ||
| 1259 | ||
| 1260 | class HybridPowerStationBMSPointItem: |
|
| 1261 | def __init__(self): |
|
| 1262 | """Initializes Class""" |
|
| 1263 | pass |
|
| 1264 | ||
| 1265 | @staticmethod |
|
| 1266 | def on_options(req, resp, id_, bid, pid): |
|
| 1267 | resp.status = falcon.HTTP_200 |
|
| 1268 | ||
| 1269 | @staticmethod |
|
| 1270 | @user_logger |
|
| 1271 | def on_delete(req, resp, id_, bid, pid): |
|
| 1272 | """Handles DELETE requests""" |
|
| 1273 | admin_control(req) |
|
| 1274 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1275 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1276 | description='API.INVALID_HYBRID_POWER_STATION_ID') |
|
| 1277 | if not bid.isdigit() or int(bid) <= 0: |
|
| 1278 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1279 | description='API.INVALID_BMS_ID') |
|
| 1280 | if not pid.isdigit() or int(pid) <= 0: |
|
| 1281 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1282 | description='API.INVALID_POINT_ID') |
|
| 1283 | ||
| 1284 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1285 | cursor = cnx.cursor() |
|
| 1286 | ||
| 1287 | cursor.execute(" SELECT name " |
|
| 1288 | " FROM tbl_hybrid_power_stations_bmses " |
|
| 1289 | " WHERE hybrid_power_station_id = %s AND id = %s ", (id_, bid,)) |
|
| 1290 | if cursor.fetchone() is None: |
|
| 1291 | cursor.close() |
|
| 1292 | cnx.close() |
|
| 1293 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1294 | description='API.HYBRID_POWER_STATION_BMS_NOT_FOUND') |
|
| 1295 | ||
| 1296 | cursor.execute(" SELECT name " |
|
| 1297 | " FROM tbl_points " |
|
| 1298 | " WHERE id = %s ", (pid,)) |
|
| 1299 | if cursor.fetchone() is None: |
|
| 1300 | cursor.close() |
|
| 1301 | cnx.close() |
|
| 1302 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1303 | description='API.POINT_NOT_FOUND') |
|
| 1304 | ||
| 1305 | cursor.execute(" SELECT id " |
|
| 1306 | " FROM tbl_hybrid_power_stations_bmses_points " |
|
| 1307 | " WHERE bms_id = %s AND point_id = %s ", (bid, pid)) |
|
| 1308 | if cursor.fetchone() is None: |
|
| 1309 | cursor.close() |
|
| 1310 | cnx.close() |
|
| 1311 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1312 | description='API.BMS_POINT_RELATION_NOT_FOUND') |
|
| 1313 | ||
| 1314 | cursor.execute(" DELETE FROM tbl_hybrid_power_stations_bmses_points " |
|
| 1315 | " WHERE bms_id = %s AND point_id = %s ", (bid, pid)) |
|
| 1316 | cnx.commit() |
|
| 1317 | ||
| 1318 | cursor.close() |
|
| 1319 | cnx.close() |
|
| 1320 | ||
| 1321 | resp.status = falcon.HTTP_204 |
|
| 1322 | ||
| 1323 | ||
| 1324 | class HybridPowerStationCommandCollection: |
|