| @@ 5791-5854 (lines=64) @@ | ||
| 5788 | str(new_values['data']['point_id']) |
|
| 5789 | ||
| 5790 | ||
| 5791 | class EnergyStorageContainerSTSPointItem: |
|
| 5792 | def __init__(self): |
|
| 5793 | pass |
|
| 5794 | ||
| 5795 | @staticmethod |
|
| 5796 | def on_options(req, resp, id_, fid, pid): |
|
| 5797 | _ = req |
|
| 5798 | resp.status = falcon.HTTP_200 |
|
| 5799 | _ = id_ |
|
| 5800 | ||
| 5801 | @staticmethod |
|
| 5802 | @user_logger |
|
| 5803 | def on_delete(req, resp, id_, fid, pid): |
|
| 5804 | """Handles DELETE requests""" |
|
| 5805 | admin_control(req) |
|
| 5806 | if not id_.isdigit() or int(id_) <= 0: |
|
| 5807 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5808 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 5809 | if not fid.isdigit() or int(fid) <= 0: |
|
| 5810 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5811 | description='API.INVALID_STS_ID') |
|
| 5812 | if not pid.isdigit() or int(pid) <= 0: |
|
| 5813 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5814 | description='API.INVALID_POINT_ID') |
|
| 5815 | ||
| 5816 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 5817 | cursor = cnx.cursor() |
|
| 5818 | ||
| 5819 | cursor.execute(" SELECT name " |
|
| 5820 | " FROM tbl_energy_storage_containers_stses " |
|
| 5821 | " WHERE energy_storage_container_id = %s AND id = %s ", (id_, fid,)) |
|
| 5822 | if cursor.fetchone() is None: |
|
| 5823 | cursor.close() |
|
| 5824 | cnx.close() |
|
| 5825 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5826 | description='API.ENERGY_STORAGE_CONTAINER_STS_NOT_FOUND') |
|
| 5827 | ||
| 5828 | cursor.execute(" SELECT name " |
|
| 5829 | " FROM tbl_points " |
|
| 5830 | " WHERE id = %s ", (pid,)) |
|
| 5831 | if cursor.fetchone() is None: |
|
| 5832 | cursor.close() |
|
| 5833 | cnx.close() |
|
| 5834 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5835 | description='API.POINT_NOT_FOUND') |
|
| 5836 | ||
| 5837 | cursor.execute(" SELECT id " |
|
| 5838 | " FROM tbl_energy_storage_containers_stses_points " |
|
| 5839 | " WHERE sts_id = %s AND point_id = %s ", (fid, pid)) |
|
| 5840 | if cursor.fetchone() is None: |
|
| 5841 | cursor.close() |
|
| 5842 | cnx.close() |
|
| 5843 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5844 | description='API.STS_POINT_RELATION_NOT_FOUND') |
|
| 5845 | ||
| 5846 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_stses_points " |
|
| 5847 | " WHERE sts_id = %s AND point_id = %s ", (fid, pid)) |
|
| 5848 | cnx.commit() |
|
| 5849 | ||
| 5850 | cursor.close() |
|
| 5851 | cnx.close() |
|
| 5852 | ||
| 5853 | resp.status = falcon.HTTP_204 |
|
| 5854 | ||
| 5855 | ||
| 5856 | class EnergyStorageContainerClone: |
|
| 5857 | def __init__(self): |
|
| @@ 5006-5069 (lines=64) @@ | ||
| 5003 | str(new_values['data']['point_id']) |
|
| 5004 | ||
| 5005 | ||
| 5006 | class EnergyStorageContainerPCSPointItem: |
|
| 5007 | def __init__(self): |
|
| 5008 | pass |
|
| 5009 | ||
| 5010 | @staticmethod |
|
| 5011 | def on_options(req, resp, id_, pcsid, pid): |
|
| 5012 | _ = req |
|
| 5013 | resp.status = falcon.HTTP_200 |
|
| 5014 | _ = id_ |
|
| 5015 | ||
| 5016 | @staticmethod |
|
| 5017 | @user_logger |
|
| 5018 | def on_delete(req, resp, id_, pcsid, pid): |
|
| 5019 | """Handles DELETE requests""" |
|
| 5020 | admin_control(req) |
|
| 5021 | if not id_.isdigit() or int(id_) <= 0: |
|
| 5022 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5023 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 5024 | if not pcsid.isdigit() or int(pcsid) <= 0: |
|
| 5025 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5026 | description='API.INVALID_PCS_ID') |
|
| 5027 | if not pid.isdigit() or int(pid) <= 0: |
|
| 5028 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5029 | description='API.INVALID_POINT_ID') |
|
| 5030 | ||
| 5031 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 5032 | cursor = cnx.cursor() |
|
| 5033 | ||
| 5034 | cursor.execute(" SELECT name " |
|
| 5035 | " FROM tbl_energy_storage_containers_power_conversion_systems " |
|
| 5036 | " WHERE energy_storage_container_id = %s AND id = %s ", (id_, pcsid,)) |
|
| 5037 | if cursor.fetchone() is None: |
|
| 5038 | cursor.close() |
|
| 5039 | cnx.close() |
|
| 5040 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5041 | description='API.ENERGY_STORAGE_CONTAINER_PCS_NOT_FOUND') |
|
| 5042 | ||
| 5043 | cursor.execute(" SELECT name " |
|
| 5044 | " FROM tbl_points " |
|
| 5045 | " WHERE id = %s ", (pid,)) |
|
| 5046 | if cursor.fetchone() is None: |
|
| 5047 | cursor.close() |
|
| 5048 | cnx.close() |
|
| 5049 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5050 | description='API.POINT_NOT_FOUND') |
|
| 5051 | ||
| 5052 | cursor.execute(" SELECT id " |
|
| 5053 | " FROM tbl_energy_storage_containers_pcses_points " |
|
| 5054 | " WHERE pcs_id = %s AND point_id = %s ", (pcsid, pid)) |
|
| 5055 | if cursor.fetchone() is None: |
|
| 5056 | cursor.close() |
|
| 5057 | cnx.close() |
|
| 5058 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5059 | description='API.PCS_POINT_RELATION_NOT_FOUND') |
|
| 5060 | ||
| 5061 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_pcses_points " |
|
| 5062 | " WHERE pcs_id = %s AND point_id = %s ", (pcsid, pid)) |
|
| 5063 | cnx.commit() |
|
| 5064 | ||
| 5065 | cursor.close() |
|
| 5066 | cnx.close() |
|
| 5067 | ||
| 5068 | resp.status = falcon.HTTP_204 |
|
| 5069 | ||
| 5070 | ||
| 5071 | class EnergyStorageContainerScheduleCollection: |
|
| 5072 | def __init__(self): |
|
| @@ 4425-4488 (lines=64) @@ | ||
| 4422 | str(new_values['data']['point_id']) |
|
| 4423 | ||
| 4424 | ||
| 4425 | class EnergyStorageContainerLoadPointItem: |
|
| 4426 | def __init__(self): |
|
| 4427 | pass |
|
| 4428 | ||
| 4429 | @staticmethod |
|
| 4430 | def on_options(req, resp, id_, lid, pid): |
|
| 4431 | _ = req |
|
| 4432 | resp.status = falcon.HTTP_200 |
|
| 4433 | _ = id_ |
|
| 4434 | ||
| 4435 | @staticmethod |
|
| 4436 | @user_logger |
|
| 4437 | def on_delete(req, resp, id_, lid, pid): |
|
| 4438 | """Handles DELETE requests""" |
|
| 4439 | admin_control(req) |
|
| 4440 | if not id_.isdigit() or int(id_) <= 0: |
|
| 4441 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4442 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 4443 | if not lid.isdigit() or int(lid) <= 0: |
|
| 4444 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4445 | description='API.INVALID_LOAD_ID') |
|
| 4446 | if not pid.isdigit() or int(pid) <= 0: |
|
| 4447 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4448 | description='API.INVALID_POINT_ID') |
|
| 4449 | ||
| 4450 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 4451 | cursor = cnx.cursor() |
|
| 4452 | ||
| 4453 | cursor.execute(" SELECT name " |
|
| 4454 | " FROM tbl_energy_storage_containers_loads " |
|
| 4455 | " WHERE energy_storage_container_id = %s AND id = %s ", (id_, lid,)) |
|
| 4456 | if cursor.fetchone() is None: |
|
| 4457 | cursor.close() |
|
| 4458 | cnx.close() |
|
| 4459 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4460 | description='API.ENERGY_STORAGE_CONTAINER_LOAD_NOT_FOUND') |
|
| 4461 | ||
| 4462 | cursor.execute(" SELECT name " |
|
| 4463 | " FROM tbl_points " |
|
| 4464 | " WHERE id = %s ", (pid,)) |
|
| 4465 | if cursor.fetchone() is None: |
|
| 4466 | cursor.close() |
|
| 4467 | cnx.close() |
|
| 4468 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4469 | description='API.POINT_NOT_FOUND') |
|
| 4470 | ||
| 4471 | cursor.execute(" SELECT id " |
|
| 4472 | " FROM tbl_energy_storage_containers_loads_points " |
|
| 4473 | " WHERE load_id = %s AND point_id = %s ", (lid, pid)) |
|
| 4474 | if cursor.fetchone() is None: |
|
| 4475 | cursor.close() |
|
| 4476 | cnx.close() |
|
| 4477 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4478 | description='API.LOAD_POINT_RELATION_NOT_FOUND') |
|
| 4479 | ||
| 4480 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_loads_points " |
|
| 4481 | " WHERE load_id = %s AND point_id = %s ", (lid, pid)) |
|
| 4482 | cnx.commit() |
|
| 4483 | ||
| 4484 | cursor.close() |
|
| 4485 | cnx.close() |
|
| 4486 | ||
| 4487 | resp.status = falcon.HTTP_204 |
|
| 4488 | ||
| 4489 | ||
| 4490 | class EnergyStorageContainerPCSCollection: |
|
| 4491 | def __init__(self): |
|
| @@ 3794-3857 (lines=64) @@ | ||
| 3791 | str(new_values['data']['point_id']) |
|
| 3792 | ||
| 3793 | ||
| 3794 | class EnergyStorageContainerHVACPointItem: |
|
| 3795 | def __init__(self): |
|
| 3796 | pass |
|
| 3797 | ||
| 3798 | @staticmethod |
|
| 3799 | def on_options(req, resp, id_, hid, pid): |
|
| 3800 | _ = req |
|
| 3801 | resp.status = falcon.HTTP_200 |
|
| 3802 | _ = id_ |
|
| 3803 | ||
| 3804 | @staticmethod |
|
| 3805 | @user_logger |
|
| 3806 | def on_delete(req, resp, id_, hid, pid): |
|
| 3807 | """Handles DELETE requests""" |
|
| 3808 | admin_control(req) |
|
| 3809 | if not id_.isdigit() or int(id_) <= 0: |
|
| 3810 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3811 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 3812 | if not hid.isdigit() or int(hid) <= 0: |
|
| 3813 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3814 | description='API.INVALID_HVAC_ID') |
|
| 3815 | if not pid.isdigit() or int(pid) <= 0: |
|
| 3816 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3817 | description='API.INVALID_POINT_ID') |
|
| 3818 | ||
| 3819 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 3820 | cursor = cnx.cursor() |
|
| 3821 | ||
| 3822 | cursor.execute(" SELECT name " |
|
| 3823 | " FROM tbl_energy_storage_containers_hvacs " |
|
| 3824 | " WHERE energy_storage_container_id = %s AND id = %s ", (id_, hid,)) |
|
| 3825 | if cursor.fetchone() is None: |
|
| 3826 | cursor.close() |
|
| 3827 | cnx.close() |
|
| 3828 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3829 | description='API.ENERGY_STORAGE_CONTAINER_HVAC_NOT_FOUND') |
|
| 3830 | ||
| 3831 | cursor.execute(" SELECT name " |
|
| 3832 | " FROM tbl_points " |
|
| 3833 | " WHERE id = %s ", (pid,)) |
|
| 3834 | if cursor.fetchone() is None: |
|
| 3835 | cursor.close() |
|
| 3836 | cnx.close() |
|
| 3837 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3838 | description='API.POINT_NOT_FOUND') |
|
| 3839 | ||
| 3840 | cursor.execute(" SELECT id " |
|
| 3841 | " FROM tbl_energy_storage_containers_hvacs_points " |
|
| 3842 | " WHERE hvac_id = %s AND point_id = %s ", (hid, pid)) |
|
| 3843 | if cursor.fetchone() is None: |
|
| 3844 | cursor.close() |
|
| 3845 | cnx.close() |
|
| 3846 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3847 | description='API.HVAC_POINT_RELATION_NOT_FOUND') |
|
| 3848 | ||
| 3849 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_hvacs_points " |
|
| 3850 | " WHERE hvac_id = %s AND point_id = %s ", (hid, pid)) |
|
| 3851 | cnx.commit() |
|
| 3852 | ||
| 3853 | cursor.close() |
|
| 3854 | cnx.close() |
|
| 3855 | ||
| 3856 | resp.status = falcon.HTTP_204 |
|
| 3857 | ||
| 3858 | ||
| 3859 | class EnergyStorageContainerLoadCollection: |
|
| 3860 | def __init__(self): |
|
| @@ 3308-3371 (lines=64) @@ | ||
| 3305 | str(new_values['data']['point_id']) |
|
| 3306 | ||
| 3307 | ||
| 3308 | class EnergyStorageContainerGridPointItem: |
|
| 3309 | def __init__(self): |
|
| 3310 | pass |
|
| 3311 | ||
| 3312 | @staticmethod |
|
| 3313 | def on_options(req, resp, id_, gid, pid): |
|
| 3314 | _ = req |
|
| 3315 | resp.status = falcon.HTTP_200 |
|
| 3316 | _ = id_ |
|
| 3317 | ||
| 3318 | @staticmethod |
|
| 3319 | @user_logger |
|
| 3320 | def on_delete(req, resp, id_, gid, pid): |
|
| 3321 | """Handles DELETE requests""" |
|
| 3322 | admin_control(req) |
|
| 3323 | if not id_.isdigit() or int(id_) <= 0: |
|
| 3324 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3325 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 3326 | if not gid.isdigit() or int(gid) <= 0: |
|
| 3327 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3328 | description='API.INVALID_GRID_ID') |
|
| 3329 | if not pid.isdigit() or int(pid) <= 0: |
|
| 3330 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3331 | description='API.INVALID_POINT_ID') |
|
| 3332 | ||
| 3333 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 3334 | cursor = cnx.cursor() |
|
| 3335 | ||
| 3336 | cursor.execute(" SELECT name " |
|
| 3337 | " FROM tbl_energy_storage_containers_grids " |
|
| 3338 | " WHERE energy_storage_container_id = %s AND id = %s ", (id_, gid,)) |
|
| 3339 | if cursor.fetchone() is None: |
|
| 3340 | cursor.close() |
|
| 3341 | cnx.close() |
|
| 3342 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3343 | description='API.ENERGY_STORAGE_CONTAINER_GRID_NOT_FOUND') |
|
| 3344 | ||
| 3345 | cursor.execute(" SELECT name " |
|
| 3346 | " FROM tbl_points " |
|
| 3347 | " WHERE id = %s ", (pid,)) |
|
| 3348 | if cursor.fetchone() is None: |
|
| 3349 | cursor.close() |
|
| 3350 | cnx.close() |
|
| 3351 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3352 | description='API.POINT_NOT_FOUND') |
|
| 3353 | ||
| 3354 | cursor.execute(" SELECT id " |
|
| 3355 | " FROM tbl_energy_storage_containers_grids_points " |
|
| 3356 | " WHERE grid_id = %s AND point_id = %s ", (gid, pid)) |
|
| 3357 | if cursor.fetchone() is None: |
|
| 3358 | cursor.close() |
|
| 3359 | cnx.close() |
|
| 3360 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3361 | description='API.GRID_POINT_RELATION_NOT_FOUND') |
|
| 3362 | ||
| 3363 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_grids_points " |
|
| 3364 | " WHERE grid_id = %s AND point_id = %s ", (gid, pid)) |
|
| 3365 | cnx.commit() |
|
| 3366 | ||
| 3367 | cursor.close() |
|
| 3368 | cnx.close() |
|
| 3369 | ||
| 3370 | resp.status = falcon.HTTP_204 |
|
| 3371 | ||
| 3372 | ||
| 3373 | class EnergyStorageContainerHVACCollection: |
|
| 3374 | def __init__(self): |
|
| @@ 2637-2700 (lines=64) @@ | ||
| 2634 | str(new_values['data']['point_id']) |
|
| 2635 | ||
| 2636 | ||
| 2637 | class EnergyStorageContainerFirecontrolPointItem: |
|
| 2638 | def __init__(self): |
|
| 2639 | pass |
|
| 2640 | ||
| 2641 | @staticmethod |
|
| 2642 | def on_options(req, resp, id_, fid, pid): |
|
| 2643 | _ = req |
|
| 2644 | resp.status = falcon.HTTP_200 |
|
| 2645 | _ = id_ |
|
| 2646 | ||
| 2647 | @staticmethod |
|
| 2648 | @user_logger |
|
| 2649 | def on_delete(req, resp, id_, fid, pid): |
|
| 2650 | """Handles DELETE requests""" |
|
| 2651 | admin_control(req) |
|
| 2652 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2653 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2654 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 2655 | if not fid.isdigit() or int(fid) <= 0: |
|
| 2656 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2657 | description='API.INVALID_FIRECONTROL_ID') |
|
| 2658 | if not pid.isdigit() or int(pid) <= 0: |
|
| 2659 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2660 | description='API.INVALID_POINT_ID') |
|
| 2661 | ||
| 2662 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2663 | cursor = cnx.cursor() |
|
| 2664 | ||
| 2665 | cursor.execute(" SELECT name " |
|
| 2666 | " FROM tbl_energy_storage_containers_firecontrols " |
|
| 2667 | " WHERE energy_storage_container_id = %s AND id = %s ", (id_, fid,)) |
|
| 2668 | if cursor.fetchone() is None: |
|
| 2669 | cursor.close() |
|
| 2670 | cnx.close() |
|
| 2671 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2672 | description='API.ENERGY_STORAGE_CONTAINER_FIRECONTROL_NOT_FOUND') |
|
| 2673 | ||
| 2674 | cursor.execute(" SELECT name " |
|
| 2675 | " FROM tbl_points " |
|
| 2676 | " WHERE id = %s ", (pid,)) |
|
| 2677 | if cursor.fetchone() is None: |
|
| 2678 | cursor.close() |
|
| 2679 | cnx.close() |
|
| 2680 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2681 | description='API.POINT_NOT_FOUND') |
|
| 2682 | ||
| 2683 | cursor.execute(" SELECT id " |
|
| 2684 | " FROM tbl_energy_storage_containers_firecontrols_points " |
|
| 2685 | " WHERE firecontrol_id = %s AND point_id = %s ", (fid, pid)) |
|
| 2686 | if cursor.fetchone() is None: |
|
| 2687 | cursor.close() |
|
| 2688 | cnx.close() |
|
| 2689 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2690 | description='API.FIRECONTROL_POINT_RELATION_NOT_FOUND') |
|
| 2691 | ||
| 2692 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_firecontrols_points " |
|
| 2693 | " WHERE firecontrol_id = %s AND point_id = %s ", (fid, pid)) |
|
| 2694 | cnx.commit() |
|
| 2695 | ||
| 2696 | cursor.close() |
|
| 2697 | cnx.close() |
|
| 2698 | ||
| 2699 | resp.status = falcon.HTTP_204 |
|
| 2700 | ||
| 2701 | ||
| 2702 | class EnergyStorageContainerGridCollection: |
|
| 2703 | def __init__(self): |
|
| @@ 2151-2214 (lines=64) @@ | ||
| 2148 | str(new_values['data']['point_id']) |
|
| 2149 | ||
| 2150 | ||
| 2151 | class EnergyStorageContainerDCDCPointItem: |
|
| 2152 | def __init__(self): |
|
| 2153 | pass |
|
| 2154 | ||
| 2155 | @staticmethod |
|
| 2156 | def on_options(req, resp, id_, did, pid): |
|
| 2157 | _ = req |
|
| 2158 | resp.status = falcon.HTTP_200 |
|
| 2159 | _ = id_ |
|
| 2160 | ||
| 2161 | @staticmethod |
|
| 2162 | @user_logger |
|
| 2163 | def on_delete(req, resp, id_, did, pid): |
|
| 2164 | """Handles DELETE requests""" |
|
| 2165 | admin_control(req) |
|
| 2166 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2167 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2168 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 2169 | if not did.isdigit() or int(did) <= 0: |
|
| 2170 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2171 | description='API.INVALID_DCDC_ID') |
|
| 2172 | if not pid.isdigit() or int(pid) <= 0: |
|
| 2173 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2174 | description='API.INVALID_POINT_ID') |
|
| 2175 | ||
| 2176 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2177 | cursor = cnx.cursor() |
|
| 2178 | ||
| 2179 | cursor.execute(" SELECT name " |
|
| 2180 | " FROM tbl_energy_storage_containers_dcdcs " |
|
| 2181 | " WHERE energy_storage_container_id = %s AND id = %s ", (id_, did,)) |
|
| 2182 | if cursor.fetchone() is None: |
|
| 2183 | cursor.close() |
|
| 2184 | cnx.close() |
|
| 2185 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2186 | description='API.ENERGY_STORAGE_CONTAINER_DCDC_NOT_FOUND') |
|
| 2187 | ||
| 2188 | cursor.execute(" SELECT name " |
|
| 2189 | " FROM tbl_points " |
|
| 2190 | " WHERE id = %s ", (pid,)) |
|
| 2191 | if cursor.fetchone() is None: |
|
| 2192 | cursor.close() |
|
| 2193 | cnx.close() |
|
| 2194 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2195 | description='API.POINT_NOT_FOUND') |
|
| 2196 | ||
| 2197 | cursor.execute(" SELECT id " |
|
| 2198 | " FROM tbl_energy_storage_containers_dcdcs_points " |
|
| 2199 | " WHERE dcdc_id = %s AND point_id = %s ", (did, pid)) |
|
| 2200 | if cursor.fetchone() is None: |
|
| 2201 | cursor.close() |
|
| 2202 | cnx.close() |
|
| 2203 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2204 | description='API.DCDC_POINT_RELATION_NOT_FOUND') |
|
| 2205 | ||
| 2206 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_dcdcs_points " |
|
| 2207 | " WHERE dcdc_id = %s AND point_id = %s ", (did, pid)) |
|
| 2208 | cnx.commit() |
|
| 2209 | ||
| 2210 | cursor.close() |
|
| 2211 | cnx.close() |
|
| 2212 | ||
| 2213 | resp.status = falcon.HTTP_204 |
|
| 2214 | ||
| 2215 | ||
| 2216 | class EnergyStorageContainerFirecontrolCollection: |
|
| 2217 | def __init__(self): |
|
| @@ 1262-1325 (lines=64) @@ | ||
| 1259 | str(new_values['data']['point_id']) |
|
| 1260 | ||
| 1261 | ||
| 1262 | class EnergyStorageContainerBatteryPointItem: |
|
| 1263 | def __init__(self): |
|
| 1264 | pass |
|
| 1265 | ||
| 1266 | @staticmethod |
|
| 1267 | def on_options(req, resp, id_, bid, pid): |
|
| 1268 | _ = req |
|
| 1269 | resp.status = falcon.HTTP_200 |
|
| 1270 | _ = id_ |
|
| 1271 | ||
| 1272 | @staticmethod |
|
| 1273 | @user_logger |
|
| 1274 | def on_delete(req, resp, id_, bid, pid): |
|
| 1275 | """Handles DELETE requests""" |
|
| 1276 | admin_control(req) |
|
| 1277 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1278 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1279 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 1280 | if not bid.isdigit() or int(bid) <= 0: |
|
| 1281 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1282 | description='API.INVALID_BMS_ID') |
|
| 1283 | if not pid.isdigit() or int(pid) <= 0: |
|
| 1284 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1285 | description='API.INVALID_POINT_ID') |
|
| 1286 | ||
| 1287 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1288 | cursor = cnx.cursor() |
|
| 1289 | ||
| 1290 | cursor.execute(" SELECT name " |
|
| 1291 | " FROM tbl_energy_storage_containers_batteries " |
|
| 1292 | " WHERE energy_storage_container_id = %s AND id = %s ", (id_, bid,)) |
|
| 1293 | if cursor.fetchone() is None: |
|
| 1294 | cursor.close() |
|
| 1295 | cnx.close() |
|
| 1296 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1297 | description='API.ENERGY_STORAGE_CONTAINER_BMS_NOT_FOUND') |
|
| 1298 | ||
| 1299 | cursor.execute(" SELECT name " |
|
| 1300 | " FROM tbl_points " |
|
| 1301 | " WHERE id = %s ", (pid,)) |
|
| 1302 | if cursor.fetchone() is None: |
|
| 1303 | cursor.close() |
|
| 1304 | cnx.close() |
|
| 1305 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1306 | description='API.POINT_NOT_FOUND') |
|
| 1307 | ||
| 1308 | cursor.execute(" SELECT id " |
|
| 1309 | " FROM tbl_energy_storage_containers_bmses_points " |
|
| 1310 | " WHERE bms_id = %s AND point_id = %s ", (bid, pid)) |
|
| 1311 | if cursor.fetchone() is None: |
|
| 1312 | cursor.close() |
|
| 1313 | cnx.close() |
|
| 1314 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1315 | description='API.BMS_POINT_RELATION_NOT_FOUND') |
|
| 1316 | ||
| 1317 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_bmses_points " |
|
| 1318 | " WHERE bms_id = %s AND point_id = %s ", (bid, pid)) |
|
| 1319 | cnx.commit() |
|
| 1320 | ||
| 1321 | cursor.close() |
|
| 1322 | cnx.close() |
|
| 1323 | ||
| 1324 | resp.status = falcon.HTTP_204 |
|
| 1325 | ||
| 1326 | ||
| 1327 | class EnergyStorageContainerCommandCollection: |
|
| 1328 | def __init__(self): |
|
| @@ 7255-7318 (lines=64) @@ | ||
| 7252 | str(new_values['data']['point_id']) |
|
| 7253 | ||
| 7254 | ||
| 7255 | class MicrogridPowerConversionSystemPointItem: |
|
| 7256 | def __init__(self): |
|
| 7257 | pass |
|
| 7258 | ||
| 7259 | @staticmethod |
|
| 7260 | def on_options(req, resp, id_, pcsid, pid): |
|
| 7261 | _ = req |
|
| 7262 | resp.status = falcon.HTTP_200 |
|
| 7263 | _ = id_ |
|
| 7264 | _ = pcsid |
|
| 7265 | _ = pid |
|
| 7266 | ||
| 7267 | @staticmethod |
|
| 7268 | @user_logger |
|
| 7269 | def on_delete(req, resp, id_, pcsid, pid): |
|
| 7270 | admin_control(req) |
|
| 7271 | if not id_.isdigit() or int(id_) <= 0: |
|
| 7272 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 7273 | description='API.INVALID_MICROGRID_ID') |
|
| 7274 | if not pcsid.isdigit() or int(pcsid) <= 0: |
|
| 7275 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 7276 | description='API.INVALID_POWER_CONVERSION_SYSTEM_ID') |
|
| 7277 | if not pid.isdigit() or int(pid) <= 0: |
|
| 7278 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 7279 | description='API.INVALID_POINT_ID') |
|
| 7280 | ||
| 7281 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 7282 | cursor = cnx.cursor() |
|
| 7283 | ||
| 7284 | cursor.execute(" SELECT name " |
|
| 7285 | " FROM tbl_microgrids_power_conversion_systems " |
|
| 7286 | " WHERE microgrid_id = %s AND id = %s ", (id_, pcsid,)) |
|
| 7287 | if cursor.fetchone() is None: |
|
| 7288 | cursor.close() |
|
| 7289 | cnx.close() |
|
| 7290 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 7291 | description='API.MICROGRID_POWER_CONVERSION_SYSTEM_NOT_FOUND') |
|
| 7292 | ||
| 7293 | cursor.execute(" SELECT name " |
|
| 7294 | " FROM tbl_points " |
|
| 7295 | " WHERE id = %s ", (pid,)) |
|
| 7296 | if cursor.fetchone() is None: |
|
| 7297 | cursor.close() |
|
| 7298 | cnx.close() |
|
| 7299 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 7300 | description='API.POINT_NOT_FOUND') |
|
| 7301 | ||
| 7302 | cursor.execute(" SELECT id " |
|
| 7303 | " FROM tbl_microgrids_pcses_points " |
|
| 7304 | " WHERE pcs_id = %s AND point_id = %s ", (pcsid, pid)) |
|
| 7305 | if cursor.fetchone() is None: |
|
| 7306 | cursor.close() |
|
| 7307 | cnx.close() |
|
| 7308 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 7309 | description='API.POWER_CONVERSION_SYSTEM_POINT_RELATION_NOT_FOUND') |
|
| 7310 | ||
| 7311 | cursor.execute(" DELETE FROM tbl_microgrids_pcses_points " |
|
| 7312 | " WHERE pcs_id = %s AND point_id = %s ", (pcsid, pid)) |
|
| 7313 | cnx.commit() |
|
| 7314 | ||
| 7315 | cursor.close() |
|
| 7316 | cnx.close() |
|
| 7317 | ||
| 7318 | resp.status = falcon.HTTP_204 |
|
| 7319 | ||
| @@ 7069-7132 (lines=64) @@ | ||
| 7066 | str(new_values['data']['point_id']) |
|
| 7067 | ||
| 7068 | ||
| 7069 | class MicrogridPhotovoltaicPointItem: |
|
| 7070 | def __init__(self): |
|
| 7071 | pass |
|
| 7072 | ||
| 7073 | @staticmethod |
|
| 7074 | def on_options(req, resp, id_, pvid, pid): |
|
| 7075 | _ = req |
|
| 7076 | resp.status = falcon.HTTP_200 |
|
| 7077 | _ = id_ |
|
| 7078 | _ = pvid |
|
| 7079 | _ = pid |
|
| 7080 | ||
| 7081 | @staticmethod |
|
| 7082 | @user_logger |
|
| 7083 | def on_delete(req, resp, id_, pvid, pid): |
|
| 7084 | admin_control(req) |
|
| 7085 | if not id_.isdigit() or int(id_) <= 0: |
|
| 7086 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 7087 | description='API.INVALID_MICROGRID_ID') |
|
| 7088 | if not pvid.isdigit() or int(pvid) <= 0: |
|
| 7089 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 7090 | description='API.INVALID_PHOTOVOLTAIC_ID') |
|
| 7091 | if not pid.isdigit() or int(pid) <= 0: |
|
| 7092 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 7093 | description='API.INVALID_POINT_ID') |
|
| 7094 | ||
| 7095 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 7096 | cursor = cnx.cursor() |
|
| 7097 | ||
| 7098 | cursor.execute(" SELECT name " |
|
| 7099 | " FROM tbl_microgrids_photovoltaics " |
|
| 7100 | " WHERE microgrid_id = %s AND id = %s ", (id_, pvid,)) |
|
| 7101 | if cursor.fetchone() is None: |
|
| 7102 | cursor.close() |
|
| 7103 | cnx.close() |
|
| 7104 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 7105 | description='API.MICROGRID_PHOTOVOLTAIC_NOT_FOUND') |
|
| 7106 | ||
| 7107 | cursor.execute(" SELECT name " |
|
| 7108 | " FROM tbl_points " |
|
| 7109 | " WHERE id = %s ", (pid,)) |
|
| 7110 | if cursor.fetchone() is None: |
|
| 7111 | cursor.close() |
|
| 7112 | cnx.close() |
|
| 7113 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 7114 | description='API.POINT_NOT_FOUND') |
|
| 7115 | ||
| 7116 | cursor.execute(" SELECT id " |
|
| 7117 | " FROM tbl_microgrids_pvs_points " |
|
| 7118 | " WHERE pv_id = %s AND point_id = %s ", (pvid, pid)) |
|
| 7119 | if cursor.fetchone() is None: |
|
| 7120 | cursor.close() |
|
| 7121 | cnx.close() |
|
| 7122 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 7123 | description='API.PHOTOVOLTAIC_POINT_RELATION_NOT_FOUND') |
|
| 7124 | ||
| 7125 | cursor.execute(" DELETE FROM tbl_microgrids_pvs_points " |
|
| 7126 | " WHERE pv_id = %s AND point_id = %s ", (pvid, pid)) |
|
| 7127 | cnx.commit() |
|
| 7128 | ||
| 7129 | cursor.close() |
|
| 7130 | cnx.close() |
|
| 7131 | ||
| 7132 | resp.status = falcon.HTTP_204 |
|
| 7133 | ||
| 7134 | class MicrogridPowerConversionSystemPointCollection: |
|
| 7135 | def __init__(self): |
|
| @@ 6883-6946 (lines=64) @@ | ||
| 6880 | str(new_values['data']['point_id']) |
|
| 6881 | ||
| 6882 | ||
| 6883 | class MicrogridLoadPointItem: |
|
| 6884 | def __init__(self): |
|
| 6885 | pass |
|
| 6886 | ||
| 6887 | @staticmethod |
|
| 6888 | def on_options(req, resp, id_, lid, pid): |
|
| 6889 | _ = req |
|
| 6890 | resp.status = falcon.HTTP_200 |
|
| 6891 | _ = id_ |
|
| 6892 | _ = lid |
|
| 6893 | _ = pid |
|
| 6894 | ||
| 6895 | @staticmethod |
|
| 6896 | @user_logger |
|
| 6897 | def on_delete(req, resp, id_, lid, pid): |
|
| 6898 | admin_control(req) |
|
| 6899 | if not id_.isdigit() or int(id_) <= 0: |
|
| 6900 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 6901 | description='API.INVALID_MICROGRID_ID') |
|
| 6902 | if not lid.isdigit() or int(lid) <= 0: |
|
| 6903 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 6904 | description='API.INVALID_LOAD_ID') |
|
| 6905 | if not pid.isdigit() or int(pid) <= 0: |
|
| 6906 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 6907 | description='API.INVALID_POINT_ID') |
|
| 6908 | ||
| 6909 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 6910 | cursor = cnx.cursor() |
|
| 6911 | ||
| 6912 | cursor.execute(" SELECT name " |
|
| 6913 | " FROM tbl_microgrids_loads " |
|
| 6914 | " WHERE microgrid_id = %s AND id = %s ", (id_, lid,)) |
|
| 6915 | if cursor.fetchone() is None: |
|
| 6916 | cursor.close() |
|
| 6917 | cnx.close() |
|
| 6918 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 6919 | description='API.MICROGRID_LOAD_NOT_FOUND') |
|
| 6920 | ||
| 6921 | cursor.execute(" SELECT name " |
|
| 6922 | " FROM tbl_points " |
|
| 6923 | " WHERE id = %s ", (pid,)) |
|
| 6924 | if cursor.fetchone() is None: |
|
| 6925 | cursor.close() |
|
| 6926 | cnx.close() |
|
| 6927 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 6928 | description='API.POINT_NOT_FOUND') |
|
| 6929 | ||
| 6930 | cursor.execute(" SELECT id " |
|
| 6931 | " FROM tbl_microgrids_loads_points " |
|
| 6932 | " WHERE load_id = %s AND point_id = %s ", (lid, pid)) |
|
| 6933 | if cursor.fetchone() is None: |
|
| 6934 | cursor.close() |
|
| 6935 | cnx.close() |
|
| 6936 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 6937 | description='API.LOAD_POINT_RELATION_NOT_FOUND') |
|
| 6938 | ||
| 6939 | cursor.execute(" DELETE FROM tbl_microgrids_loads_points " |
|
| 6940 | " WHERE load_id = %s AND point_id = %s ", (lid, pid)) |
|
| 6941 | cnx.commit() |
|
| 6942 | ||
| 6943 | cursor.close() |
|
| 6944 | cnx.close() |
|
| 6945 | ||
| 6946 | resp.status = falcon.HTTP_204 |
|
| 6947 | ||
| 6948 | class MicrogridPhotovoltaicPointCollection: |
|
| 6949 | def __init__(self): |
|
| @@ 6697-6760 (lines=64) @@ | ||
| 6694 | str(new_values['data']['point_id']) |
|
| 6695 | ||
| 6696 | ||
| 6697 | class MicrogridHeatPumpPointItem: |
|
| 6698 | def __init__(self): |
|
| 6699 | pass |
|
| 6700 | ||
| 6701 | @staticmethod |
|
| 6702 | def on_options(req, resp, id_, hid, pid): |
|
| 6703 | _ = req |
|
| 6704 | resp.status = falcon.HTTP_200 |
|
| 6705 | _ = id_ |
|
| 6706 | _ = hid |
|
| 6707 | _ = pid |
|
| 6708 | ||
| 6709 | @staticmethod |
|
| 6710 | @user_logger |
|
| 6711 | def on_delete(req, resp, id_, hid, pid): |
|
| 6712 | admin_control(req) |
|
| 6713 | if not id_.isdigit() or int(id_) <= 0: |
|
| 6714 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 6715 | description='API.INVALID_MICROGRID_ID') |
|
| 6716 | if not hid.isdigit() or int(hid) <= 0: |
|
| 6717 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 6718 | description='API.INVALID_HEATPUMP_ID') |
|
| 6719 | if not pid.isdigit() or int(pid) <= 0: |
|
| 6720 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 6721 | description='API.INVALID_POINT_ID') |
|
| 6722 | ||
| 6723 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 6724 | cursor = cnx.cursor() |
|
| 6725 | ||
| 6726 | cursor.execute(" SELECT name " |
|
| 6727 | " FROM tbl_microgrids_heatpumps " |
|
| 6728 | " WHERE microgrid_id = %s AND id = %s ", (id_, hid,)) |
|
| 6729 | if cursor.fetchone() is None: |
|
| 6730 | cursor.close() |
|
| 6731 | cnx.close() |
|
| 6732 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 6733 | description='API.MICROGRID_HEATPUMP_NOT_FOUND') |
|
| 6734 | ||
| 6735 | cursor.execute(" SELECT name " |
|
| 6736 | " FROM tbl_points " |
|
| 6737 | " WHERE id = %s ", (pid,)) |
|
| 6738 | if cursor.fetchone() is None: |
|
| 6739 | cursor.close() |
|
| 6740 | cnx.close() |
|
| 6741 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 6742 | description='API.POINT_NOT_FOUND') |
|
| 6743 | ||
| 6744 | cursor.execute(" SELECT id " |
|
| 6745 | " FROM tbl_microgrids_heatpumps_points " |
|
| 6746 | " WHERE heatpump_id = %s AND point_id = %s ", (hid, pid)) |
|
| 6747 | if cursor.fetchone() is None: |
|
| 6748 | cursor.close() |
|
| 6749 | cnx.close() |
|
| 6750 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 6751 | description='API.HEATPUMP_POINT_RELATION_NOT_FOUND') |
|
| 6752 | ||
| 6753 | cursor.execute(" DELETE FROM tbl_microgrids_heatpumps_points " |
|
| 6754 | " WHERE heatpump_id = %s AND point_id = %s ", (hid, pid)) |
|
| 6755 | cnx.commit() |
|
| 6756 | ||
| 6757 | cursor.close() |
|
| 6758 | cnx.close() |
|
| 6759 | ||
| 6760 | resp.status = falcon.HTTP_204 |
|
| 6761 | ||
| 6762 | class MicrogridLoadPointCollection: |
|
| 6763 | def __init__(self): |
|
| @@ 6511-6574 (lines=64) @@ | ||
| 6508 | str(new_values['data']['point_id']) |
|
| 6509 | ||
| 6510 | ||
| 6511 | class MicrogridGridPointItem: |
|
| 6512 | def __init__(self): |
|
| 6513 | pass |
|
| 6514 | ||
| 6515 | @staticmethod |
|
| 6516 | def on_options(req, resp, id_, gid, pid): |
|
| 6517 | _ = req |
|
| 6518 | resp.status = falcon.HTTP_200 |
|
| 6519 | _ = id_ |
|
| 6520 | _ = gid |
|
| 6521 | _ = pid |
|
| 6522 | ||
| 6523 | @staticmethod |
|
| 6524 | @user_logger |
|
| 6525 | def on_delete(req, resp, id_, gid, pid): |
|
| 6526 | admin_control(req) |
|
| 6527 | if not id_.isdigit() or int(id_) <= 0: |
|
| 6528 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 6529 | description='API.INVALID_MICROGRID_ID') |
|
| 6530 | if not gid.isdigit() or int(gid) <= 0: |
|
| 6531 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 6532 | description='API.INVALID_GRID_ID') |
|
| 6533 | if not pid.isdigit() or int(pid) <= 0: |
|
| 6534 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 6535 | description='API.INVALID_POINT_ID') |
|
| 6536 | ||
| 6537 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 6538 | cursor = cnx.cursor() |
|
| 6539 | ||
| 6540 | cursor.execute(" SELECT name " |
|
| 6541 | " FROM tbl_microgrids_grids " |
|
| 6542 | " WHERE microgrid_id = %s AND id = %s ", (id_, gid,)) |
|
| 6543 | if cursor.fetchone() is None: |
|
| 6544 | cursor.close() |
|
| 6545 | cnx.close() |
|
| 6546 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 6547 | description='API.MICROGRID_GRID_NOT_FOUND') |
|
| 6548 | ||
| 6549 | cursor.execute(" SELECT name " |
|
| 6550 | " FROM tbl_points " |
|
| 6551 | " WHERE id = %s ", (pid,)) |
|
| 6552 | if cursor.fetchone() is None: |
|
| 6553 | cursor.close() |
|
| 6554 | cnx.close() |
|
| 6555 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 6556 | description='API.POINT_NOT_FOUND') |
|
| 6557 | ||
| 6558 | cursor.execute(" SELECT id " |
|
| 6559 | " FROM tbl_microgrids_grids_points " |
|
| 6560 | " WHERE grid_id = %s AND point_id = %s ", (gid, pid)) |
|
| 6561 | if cursor.fetchone() is None: |
|
| 6562 | cursor.close() |
|
| 6563 | cnx.close() |
|
| 6564 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 6565 | description='API.GRID_POINT_RELATION_NOT_FOUND') |
|
| 6566 | ||
| 6567 | cursor.execute(" DELETE FROM tbl_microgrids_grids_points " |
|
| 6568 | " WHERE grid_id = %s AND point_id = %s ", (gid, pid)) |
|
| 6569 | cnx.commit() |
|
| 6570 | ||
| 6571 | cursor.close() |
|
| 6572 | cnx.close() |
|
| 6573 | ||
| 6574 | resp.status = falcon.HTTP_204 |
|
| 6575 | ||
| 6576 | class MicrogridHeatPumpPointCollection: |
|
| 6577 | def __init__(self): |
|
| @@ 6325-6388 (lines=64) @@ | ||
| 6322 | str(new_values['data']['point_id']) |
|
| 6323 | ||
| 6324 | ||
| 6325 | class MicrogridGeneratorPointItem: |
|
| 6326 | def __init__(self): |
|
| 6327 | pass |
|
| 6328 | ||
| 6329 | @staticmethod |
|
| 6330 | def on_options(req, resp, id_, gid, pid): |
|
| 6331 | _ = req |
|
| 6332 | resp.status = falcon.HTTP_200 |
|
| 6333 | _ = id_ |
|
| 6334 | _ = gid |
|
| 6335 | _ = pid |
|
| 6336 | ||
| 6337 | @staticmethod |
|
| 6338 | @user_logger |
|
| 6339 | def on_delete(req, resp, id_, gid, pid): |
|
| 6340 | admin_control(req) |
|
| 6341 | if not id_.isdigit() or int(id_) <= 0: |
|
| 6342 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 6343 | description='API.INVALID_MICROGRID_ID') |
|
| 6344 | if not gid.isdigit() or int(gid) <= 0: |
|
| 6345 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 6346 | description='API.INVALID_GENERATOR_ID') |
|
| 6347 | if not pid.isdigit() or int(pid) <= 0: |
|
| 6348 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 6349 | description='API.INVALID_POINT_ID') |
|
| 6350 | ||
| 6351 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 6352 | cursor = cnx.cursor() |
|
| 6353 | ||
| 6354 | cursor.execute(" SELECT name " |
|
| 6355 | " FROM tbl_microgrids_generators " |
|
| 6356 | " WHERE microgrid_id = %s AND id = %s ", (id_, gid,)) |
|
| 6357 | if cursor.fetchone() is None: |
|
| 6358 | cursor.close() |
|
| 6359 | cnx.close() |
|
| 6360 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 6361 | description='API.MICROGRID_GENERATOR_NOT_FOUND') |
|
| 6362 | ||
| 6363 | cursor.execute(" SELECT name " |
|
| 6364 | " FROM tbl_points " |
|
| 6365 | " WHERE id = %s ", (pid,)) |
|
| 6366 | if cursor.fetchone() is None: |
|
| 6367 | cursor.close() |
|
| 6368 | cnx.close() |
|
| 6369 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 6370 | description='API.POINT_NOT_FOUND') |
|
| 6371 | ||
| 6372 | cursor.execute(" SELECT id " |
|
| 6373 | " FROM tbl_microgrids_generators_points " |
|
| 6374 | " WHERE generator_id = %s AND point_id = %s ", (gid, pid)) |
|
| 6375 | if cursor.fetchone() is None: |
|
| 6376 | cursor.close() |
|
| 6377 | cnx.close() |
|
| 6378 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 6379 | description='API.GENERATOR_POINT_RELATION_NOT_FOUND') |
|
| 6380 | ||
| 6381 | cursor.execute(" DELETE FROM tbl_microgrids_generators_points " |
|
| 6382 | " WHERE generator_id = %s AND point_id = %s ", (gid, pid)) |
|
| 6383 | cnx.commit() |
|
| 6384 | ||
| 6385 | cursor.close() |
|
| 6386 | cnx.close() |
|
| 6387 | ||
| 6388 | resp.status = falcon.HTTP_204 |
|
| 6389 | ||
| 6390 | class MicrogridGridPointCollection: |
|
| 6391 | def __init__(self): |
|
| @@ 6139-6202 (lines=64) @@ | ||
| 6136 | str(new_values['data']['point_id']) |
|
| 6137 | ||
| 6138 | ||
| 6139 | class MicrogridEVChargerPointItem: |
|
| 6140 | def __init__(self): |
|
| 6141 | pass |
|
| 6142 | ||
| 6143 | @staticmethod |
|
| 6144 | def on_options(req, resp, id_, eid, pid): |
|
| 6145 | _ = req |
|
| 6146 | resp.status = falcon.HTTP_200 |
|
| 6147 | _ = id_ |
|
| 6148 | _ = eid |
|
| 6149 | _ = pid |
|
| 6150 | ||
| 6151 | @staticmethod |
|
| 6152 | @user_logger |
|
| 6153 | def on_delete(req, resp, id_, eid, pid): |
|
| 6154 | admin_control(req) |
|
| 6155 | if not id_.isdigit() or int(id_) <= 0: |
|
| 6156 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 6157 | description='API.INVALID_MICROGRID_ID') |
|
| 6158 | if not eid.isdigit() or int(eid) <= 0: |
|
| 6159 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 6160 | description='API.INVALID_EVCHARGER_ID') |
|
| 6161 | if not pid.isdigit() or int(pid) <= 0: |
|
| 6162 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 6163 | description='API.INVALID_POINT_ID') |
|
| 6164 | ||
| 6165 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 6166 | cursor = cnx.cursor() |
|
| 6167 | ||
| 6168 | cursor.execute(" SELECT name " |
|
| 6169 | " FROM tbl_microgrids_evchargers " |
|
| 6170 | " WHERE microgrid_id = %s AND id = %s ", (id_, eid,)) |
|
| 6171 | if cursor.fetchone() is None: |
|
| 6172 | cursor.close() |
|
| 6173 | cnx.close() |
|
| 6174 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 6175 | description='API.MICROGRID_EVCHARGER_NOT_FOUND') |
|
| 6176 | ||
| 6177 | cursor.execute(" SELECT name " |
|
| 6178 | " FROM tbl_points " |
|
| 6179 | " WHERE id = %s ", (pid,)) |
|
| 6180 | if cursor.fetchone() is None: |
|
| 6181 | cursor.close() |
|
| 6182 | cnx.close() |
|
| 6183 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 6184 | description='API.POINT_NOT_FOUND') |
|
| 6185 | ||
| 6186 | cursor.execute(" SELECT id " |
|
| 6187 | " FROM tbl_microgrids_evchargers_points " |
|
| 6188 | " WHERE evcharger_id = %s AND point_id = %s ", (eid, pid)) |
|
| 6189 | if cursor.fetchone() is None: |
|
| 6190 | cursor.close() |
|
| 6191 | cnx.close() |
|
| 6192 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 6193 | description='API.EVCHARGER_POINT_RELATION_NOT_FOUND') |
|
| 6194 | ||
| 6195 | cursor.execute(" DELETE FROM tbl_microgrids_evchargers_points " |
|
| 6196 | " WHERE evcharger_id = %s AND point_id = %s ", (eid, pid)) |
|
| 6197 | cnx.commit() |
|
| 6198 | ||
| 6199 | cursor.close() |
|
| 6200 | cnx.close() |
|
| 6201 | ||
| 6202 | resp.status = falcon.HTTP_204 |
|
| 6203 | ||
| 6204 | class MicrogridGeneratorPointCollection: |
|
| 6205 | def __init__(self): |
|
| @@ 5953-6016 (lines=64) @@ | ||
| 5950 | str(new_values['data']['point_id']) |
|
| 5951 | ||
| 5952 | ||
| 5953 | class MicrogridBatteryPointItem: |
|
| 5954 | def __init__(self): |
|
| 5955 | pass |
|
| 5956 | ||
| 5957 | @staticmethod |
|
| 5958 | def on_options(req, resp, id_, bid, pid): |
|
| 5959 | _ = req |
|
| 5960 | resp.status = falcon.HTTP_200 |
|
| 5961 | _ = id_ |
|
| 5962 | _ = bid |
|
| 5963 | _ = pid |
|
| 5964 | ||
| 5965 | @staticmethod |
|
| 5966 | @user_logger |
|
| 5967 | def on_delete(req, resp, id_, bid, pid): |
|
| 5968 | admin_control(req) |
|
| 5969 | if not id_.isdigit() or int(id_) <= 0: |
|
| 5970 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5971 | description='API.INVALID_MICROGRID_ID') |
|
| 5972 | if not bid.isdigit() or int(bid) <= 0: |
|
| 5973 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5974 | description='API.INVALID_BATTERY_ID') |
|
| 5975 | if not pid.isdigit() or int(pid) <= 0: |
|
| 5976 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5977 | description='API.INVALID_POINT_ID') |
|
| 5978 | ||
| 5979 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 5980 | cursor = cnx.cursor() |
|
| 5981 | ||
| 5982 | cursor.execute(" SELECT name " |
|
| 5983 | " FROM tbl_microgrids_batteries " |
|
| 5984 | " WHERE microgrid_id = %s AND id = %s ", (id_, bid,)) |
|
| 5985 | if cursor.fetchone() is None: |
|
| 5986 | cursor.close() |
|
| 5987 | cnx.close() |
|
| 5988 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5989 | description='API.MICROGRID_BATTERY_NOT_FOUND') |
|
| 5990 | ||
| 5991 | cursor.execute(" SELECT name " |
|
| 5992 | " FROM tbl_points " |
|
| 5993 | " WHERE id = %s ", (pid,)) |
|
| 5994 | if cursor.fetchone() is None: |
|
| 5995 | cursor.close() |
|
| 5996 | cnx.close() |
|
| 5997 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5998 | description='API.POINT_NOT_FOUND') |
|
| 5999 | ||
| 6000 | cursor.execute(" SELECT id " |
|
| 6001 | " FROM tbl_microgrids_bmses_points " |
|
| 6002 | " WHERE bms_id = %s AND point_id = %s ", (bid, pid)) |
|
| 6003 | if cursor.fetchone() is None: |
|
| 6004 | cursor.close() |
|
| 6005 | cnx.close() |
|
| 6006 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 6007 | description='API.BATTERY_POINT_RELATION_NOT_FOUND') |
|
| 6008 | ||
| 6009 | cursor.execute(" DELETE FROM tbl_microgrids_bmses_points " |
|
| 6010 | " WHERE bms_id = %s AND point_id = %s ", (bid, pid)) |
|
| 6011 | cnx.commit() |
|
| 6012 | ||
| 6013 | cursor.close() |
|
| 6014 | cnx.close() |
|
| 6015 | ||
| 6016 | resp.status = falcon.HTTP_204 |
|
| 6017 | ||
| 6018 | class MicrogridEVChargerPointCollection: |
|
| 6019 | def __init__(self): |
|
| @@ 5735-5798 (lines=64) @@ | ||
| 5732 | str(new_values['data']['point_id']) |
|
| 5733 | ||
| 5734 | ||
| 5735 | class PhotovoltaicPowerStationLoadPointItem: |
|
| 5736 | def __init__(self): |
|
| 5737 | pass |
|
| 5738 | ||
| 5739 | @staticmethod |
|
| 5740 | def on_options(req, resp, id_, lid, pid): |
|
| 5741 | _ = req |
|
| 5742 | resp.status = falcon.HTTP_200 |
|
| 5743 | _ = id_ |
|
| 5744 | _ = lid |
|
| 5745 | _ = pid |
|
| 5746 | ||
| 5747 | @staticmethod |
|
| 5748 | @user_logger |
|
| 5749 | def on_delete(req, resp, id_, lid, pid): |
|
| 5750 | admin_control(req) |
|
| 5751 | if not id_.isdigit() or int(id_) <= 0: |
|
| 5752 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5753 | description='API.INVALID_PHOTOVOLTAIC_POWER_STATION_ID') |
|
| 5754 | if not lid.isdigit() or int(lid) <= 0: |
|
| 5755 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5756 | description='API.INVALID_LOAD_ID') |
|
| 5757 | if not pid.isdigit() or int(pid) <= 0: |
|
| 5758 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5759 | description='API.INVALID_POINT_ID') |
|
| 5760 | ||
| 5761 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 5762 | cursor = cnx.cursor() |
|
| 5763 | ||
| 5764 | cursor.execute(" SELECT name " |
|
| 5765 | " FROM tbl_photovoltaic_power_stations_loads " |
|
| 5766 | " WHERE photovoltaic_power_station_id = %s AND id = %s ", (id_, lid,)) |
|
| 5767 | if cursor.fetchone() is None: |
|
| 5768 | cursor.close() |
|
| 5769 | cnx.close() |
|
| 5770 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5771 | description='API.PHOTOVOLTAIC_LOAD_NOT_FOUND') |
|
| 5772 | ||
| 5773 | cursor.execute(" SELECT name " |
|
| 5774 | " FROM tbl_points " |
|
| 5775 | " WHERE id = %s ", (pid,)) |
|
| 5776 | if cursor.fetchone() is None: |
|
| 5777 | cursor.close() |
|
| 5778 | cnx.close() |
|
| 5779 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5780 | description='API.POINT_NOT_FOUND') |
|
| 5781 | ||
| 5782 | cursor.execute(" SELECT id " |
|
| 5783 | " FROM tbl_photovoltaic_power_stations_loads_points " |
|
| 5784 | " WHERE load_id = %s AND point_id = %s ", (lid, pid)) |
|
| 5785 | if cursor.fetchone() is None: |
|
| 5786 | cursor.close() |
|
| 5787 | cnx.close() |
|
| 5788 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5789 | description='API.LOAD_POINT_RELATION_NOT_FOUND') |
|
| 5790 | ||
| 5791 | cursor.execute(" DELETE FROM tbl_photovoltaic_power_stations_loads_points " |
|
| 5792 | " WHERE load_id = %s AND point_id = %s ", (lid, pid)) |
|
| 5793 | cnx.commit() |
|
| 5794 | ||
| 5795 | cursor.close() |
|
| 5796 | cnx.close() |
|
| 5797 | ||
| 5798 | resp.status = falcon.HTTP_204 |
|
| 5799 | ||
| 5800 | ||
| 5801 | ||
| @@ 5548-5611 (lines=64) @@ | ||
| 5545 | str(new_values['data']['point_id']) |
|
| 5546 | ||
| 5547 | ||
| 5548 | class PhotovoltaicPowerStationGridPointItem: |
|
| 5549 | def __init__(self): |
|
| 5550 | pass |
|
| 5551 | ||
| 5552 | @staticmethod |
|
| 5553 | def on_options(req, resp, id_, gid, pid): |
|
| 5554 | _ = req |
|
| 5555 | resp.status = falcon.HTTP_200 |
|
| 5556 | _ = id_ |
|
| 5557 | _ = gid |
|
| 5558 | _ = pid |
|
| 5559 | ||
| 5560 | @staticmethod |
|
| 5561 | @user_logger |
|
| 5562 | def on_delete(req, resp, id_, gid, pid): |
|
| 5563 | admin_control(req) |
|
| 5564 | if not id_.isdigit() or int(id_) <= 0: |
|
| 5565 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5566 | description='API.INVALID_PHOTOVOLTAIC_POWER_STATION_ID') |
|
| 5567 | if not gid.isdigit() or int(gid) <= 0: |
|
| 5568 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5569 | description='API.INVALID_GRID_ID') |
|
| 5570 | if not pid.isdigit() or int(pid) <= 0: |
|
| 5571 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5572 | description='API.INVALID_POINT_ID') |
|
| 5573 | ||
| 5574 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 5575 | cursor = cnx.cursor() |
|
| 5576 | ||
| 5577 | cursor.execute(" SELECT name " |
|
| 5578 | " FROM tbl_photovoltaic_power_stations_grids " |
|
| 5579 | " WHERE photovoltaic_power_station_id = %s AND id = %s ", (id_, gid,)) |
|
| 5580 | if cursor.fetchone() is None: |
|
| 5581 | cursor.close() |
|
| 5582 | cnx.close() |
|
| 5583 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5584 | description='API.PHOTOVOLTAIC_GRID_NOT_FOUND') |
|
| 5585 | ||
| 5586 | cursor.execute(" SELECT name " |
|
| 5587 | " FROM tbl_points " |
|
| 5588 | " WHERE id = %s ", (pid,)) |
|
| 5589 | if cursor.fetchone() is None: |
|
| 5590 | cursor.close() |
|
| 5591 | cnx.close() |
|
| 5592 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5593 | description='API.POINT_NOT_FOUND') |
|
| 5594 | ||
| 5595 | cursor.execute(" SELECT id " |
|
| 5596 | " FROM tbl_photovoltaic_power_stations_grids_points " |
|
| 5597 | " WHERE grid_id = %s AND point_id = %s ", (gid, pid)) |
|
| 5598 | if cursor.fetchone() is None: |
|
| 5599 | cursor.close() |
|
| 5600 | cnx.close() |
|
| 5601 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5602 | description='API.GRID_POINT_RELATION_NOT_FOUND') |
|
| 5603 | ||
| 5604 | cursor.execute(" DELETE FROM tbl_photovoltaic_power_stations_grids_points " |
|
| 5605 | " WHERE grid_id = %s AND point_id = %s ", (gid, pid)) |
|
| 5606 | cnx.commit() |
|
| 5607 | ||
| 5608 | cursor.close() |
|
| 5609 | cnx.close() |
|
| 5610 | ||
| 5611 | resp.status = falcon.HTTP_204 |
|
| 5612 | ||
| 5613 | ||
| 5614 | class PhotovoltaicPowerStationLoadPointCollection: |
|
| @@ 5361-5424 (lines=64) @@ | ||
| 5358 | str(new_values['data']['point_id']) |
|
| 5359 | ||
| 5360 | ||
| 5361 | class PhotovoltaicPowerStationInvertorPointItem: |
|
| 5362 | def __init__(self): |
|
| 5363 | pass |
|
| 5364 | ||
| 5365 | @staticmethod |
|
| 5366 | def on_options(req, resp, id_, iid, pid): |
|
| 5367 | _ = req |
|
| 5368 | resp.status = falcon.HTTP_200 |
|
| 5369 | _ = id_ |
|
| 5370 | _ = iid |
|
| 5371 | _ = pid |
|
| 5372 | ||
| 5373 | @staticmethod |
|
| 5374 | @user_logger |
|
| 5375 | def on_delete(req, resp, id_, iid, pid): |
|
| 5376 | admin_control(req) |
|
| 5377 | if not id_.isdigit() or int(id_) <= 0: |
|
| 5378 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5379 | description='API.INVALID_PHOTOVOLTAIC_POWER_STATION_ID') |
|
| 5380 | if not iid.isdigit() or int(iid) <= 0: |
|
| 5381 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5382 | description='API.INVALID_INVERTOR_ID') |
|
| 5383 | if not pid.isdigit() or int(pid) <= 0: |
|
| 5384 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5385 | description='API.INVALID_POINT_ID') |
|
| 5386 | ||
| 5387 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 5388 | cursor = cnx.cursor() |
|
| 5389 | ||
| 5390 | cursor.execute(" SELECT name " |
|
| 5391 | " FROM tbl_photovoltaic_power_stations_invertors " |
|
| 5392 | " WHERE photovoltaic_power_station_id = %s AND id = %s ", (id_, iid,)) |
|
| 5393 | if cursor.fetchone() is None: |
|
| 5394 | cursor.close() |
|
| 5395 | cnx.close() |
|
| 5396 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5397 | description='API.PHOTOVOLTAIC_INVERTOR_NOT_FOUND') |
|
| 5398 | ||
| 5399 | cursor.execute(" SELECT name " |
|
| 5400 | " FROM tbl_points " |
|
| 5401 | " WHERE id = %s ", (pid,)) |
|
| 5402 | if cursor.fetchone() is None: |
|
| 5403 | cursor.close() |
|
| 5404 | cnx.close() |
|
| 5405 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5406 | description='API.POINT_NOT_FOUND') |
|
| 5407 | ||
| 5408 | cursor.execute(" SELECT id " |
|
| 5409 | " FROM tbl_photovoltaic_power_stations_invertors_points " |
|
| 5410 | " WHERE invertor_id = %s AND point_id = %s ", (iid, pid)) |
|
| 5411 | if cursor.fetchone() is None: |
|
| 5412 | cursor.close() |
|
| 5413 | cnx.close() |
|
| 5414 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5415 | description='API.INVERTOR_POINT_RELATION_NOT_FOUND') |
|
| 5416 | ||
| 5417 | cursor.execute(" DELETE FROM tbl_photovoltaic_power_stations_invertors_points " |
|
| 5418 | " WHERE invertor_id = %s AND point_id = %s ", (iid, pid)) |
|
| 5419 | cnx.commit() |
|
| 5420 | ||
| 5421 | cursor.close() |
|
| 5422 | cnx.close() |
|
| 5423 | ||
| 5424 | resp.status = falcon.HTTP_204 |
|
| 5425 | ||
| 5426 | ||
| 5427 | class PhotovoltaicPowerStationGridPointCollection: |
|