| @@ 5064-5124 (lines=61) @@ | ||
| 5061 | resp.location = '/hybridpowerstations/' + str(id_) + '/users/' + str(user_id) |
|
| 5062 | ||
| 5063 | ||
| 5064 | class HybridPowerStationUserItem: |
|
| 5065 | def __init__(self): |
|
| 5066 | """Initializes Class""" |
|
| 5067 | pass |
|
| 5068 | ||
| 5069 | @staticmethod |
|
| 5070 | def on_options(req, resp, id_, uid): |
|
| 5071 | resp.status = falcon.HTTP_200 |
|
| 5072 | ||
| 5073 | @staticmethod |
|
| 5074 | @user_logger |
|
| 5075 | def on_delete(req, resp, id_, uid): |
|
| 5076 | # todo Verify if the user is bound when deleting it |
|
| 5077 | admin_control(req) |
|
| 5078 | if not id_.isdigit() or int(id_) <= 0: |
|
| 5079 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5080 | description='API.INVALID_HYBRID_POWER_STATION_ID') |
|
| 5081 | ||
| 5082 | if not uid.isdigit() or int(uid) <= 0: |
|
| 5083 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5084 | description='API.INVALID_USER_ID') |
|
| 5085 | ||
| 5086 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 5087 | cursor = cnx.cursor() |
|
| 5088 | cursor.execute(" SELECT name " |
|
| 5089 | " FROM tbl_hybrid_power_stations " |
|
| 5090 | " WHERE id = %s ", (id_,)) |
|
| 5091 | if cursor.fetchone() is None: |
|
| 5092 | cursor.close() |
|
| 5093 | cnx.close() |
|
| 5094 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5095 | description='API.HYBRID_POWER_STATION_NOT_FOUND') |
|
| 5096 | ||
| 5097 | cnx_user = mysql.connector.connect(**config.myems_user_db) |
|
| 5098 | cursor_user = cnx_user.cursor() |
|
| 5099 | cursor_user.execute(" SELECT name FROM tbl_users WHERE id = %s ", (uid,)) |
|
| 5100 | if cursor_user.fetchone() is None: |
|
| 5101 | cursor_user.close() |
|
| 5102 | cnx_user.close() |
|
| 5103 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5104 | description='API.USER_NOT_FOUND') |
|
| 5105 | ||
| 5106 | cursor.execute(" SELECT id " |
|
| 5107 | " FROM tbl_hybrid_power_stations_users " |
|
| 5108 | " WHERE hybrid_power_station_id = %s AND user_id = %s ", (id_, uid)) |
|
| 5109 | if cursor.fetchone() is None: |
|
| 5110 | cursor.close() |
|
| 5111 | cnx.close() |
|
| 5112 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5113 | description='API.HYBRID_POWER_STATION_USER_RELATION_NOT_FOUND') |
|
| 5114 | ||
| 5115 | cursor.execute(" DELETE FROM tbl_hybrid_power_stations_users " |
|
| 5116 | " WHERE hybrid_power_station_id = %s AND user_id = %s ", (id_, uid)) |
|
| 5117 | cnx.commit() |
|
| 5118 | ||
| 5119 | cursor.close() |
|
| 5120 | cnx.close() |
|
| 5121 | cursor_user.close() |
|
| 5122 | cnx_user.close() |
|
| 5123 | ||
| 5124 | resp.status = falcon.HTTP_204 |
|
| 5125 | ||
| 5126 | ||
| 5127 | class HybridPowerStationClone: |
|
| @@ 1439-1497 (lines=59) @@ | ||
| 1436 | resp.location = '/combinedequipments/' + str(id_) + '/commands/' + str(command_id) |
|
| 1437 | ||
| 1438 | ||
| 1439 | class HybridPowerStationCommandItem: |
|
| 1440 | def __init__(self): |
|
| 1441 | """Initializes Class""" |
|
| 1442 | pass |
|
| 1443 | ||
| 1444 | @staticmethod |
|
| 1445 | def on_options(req, resp, id_, cid): |
|
| 1446 | resp.status = falcon.HTTP_200 |
|
| 1447 | ||
| 1448 | @staticmethod |
|
| 1449 | @user_logger |
|
| 1450 | def on_delete(req, resp, id_, cid): |
|
| 1451 | admin_control(req) |
|
| 1452 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1453 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1454 | description='API.INVALID_HYBRID_POWER_STATION_ID') |
|
| 1455 | ||
| 1456 | if not cid.isdigit() or int(cid) <= 0: |
|
| 1457 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1458 | description='API.INVALID_COMMAND_ID') |
|
| 1459 | ||
| 1460 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1461 | cursor = cnx.cursor() |
|
| 1462 | ||
| 1463 | cursor.execute(" SELECT name " |
|
| 1464 | " FROM tbl_hybrid_power_stations " |
|
| 1465 | " WHERE id = %s ", (id_,)) |
|
| 1466 | if cursor.fetchone() is None: |
|
| 1467 | cursor.close() |
|
| 1468 | cnx.close() |
|
| 1469 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1470 | description='API.HYBRID_POWER_STATION_NOT_FOUND') |
|
| 1471 | ||
| 1472 | cursor.execute(" SELECT name " |
|
| 1473 | " FROM tbl_commands " |
|
| 1474 | " WHERE id = %s ", (cid,)) |
|
| 1475 | if cursor.fetchone() is None: |
|
| 1476 | cursor.close() |
|
| 1477 | cnx.close() |
|
| 1478 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1479 | description='API.COMMAND_NOT_FOUND') |
|
| 1480 | ||
| 1481 | cursor.execute(" SELECT id " |
|
| 1482 | " FROM tbl_hybrid_power_stations_commands " |
|
| 1483 | " WHERE hybrid_power_station_id = %s AND command_id = %s ", (id_, cid)) |
|
| 1484 | if cursor.fetchone() is None: |
|
| 1485 | cursor.close() |
|
| 1486 | cnx.close() |
|
| 1487 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1488 | description='API.HYBRID_POWER_STATION_COMMAND_RELATION_NOT_FOUND') |
|
| 1489 | ||
| 1490 | cursor.execute(" DELETE FROM tbl_hybrid_power_stations_commands " |
|
| 1491 | " WHERE hybrid_power_station_id = %s AND command_id = %s ", (id_, cid)) |
|
| 1492 | cnx.commit() |
|
| 1493 | ||
| 1494 | cursor.close() |
|
| 1495 | cnx.close() |
|
| 1496 | ||
| 1497 | resp.status = falcon.HTTP_204 |
|
| 1498 | ||
| 1499 | ||
| 1500 | class HybridPowerStationCMCollection: |
|
| @@ 4908-4968 (lines=61) @@ | ||
| 4905 | resp.location = '/photovoltaicpowerstations/' + str(id_) + '/users/' + str(user_id) |
|
| 4906 | ||
| 4907 | ||
| 4908 | class PhotovoltaicPowerStationUserItem: |
|
| 4909 | def __init__(self): |
|
| 4910 | """Initializes Class""" |
|
| 4911 | pass |
|
| 4912 | ||
| 4913 | @staticmethod |
|
| 4914 | def on_options(req, resp, id_, uid): |
|
| 4915 | resp.status = falcon.HTTP_200 |
|
| 4916 | ||
| 4917 | @staticmethod |
|
| 4918 | @user_logger |
|
| 4919 | def on_delete(req, resp, id_, uid): |
|
| 4920 | # todo Verify if the user is bound when deleting it |
|
| 4921 | admin_control(req) |
|
| 4922 | if not id_.isdigit() or int(id_) <= 0: |
|
| 4923 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4924 | description='API.INVALID_PHOTOVOLTAIC_POWER_STATION_ID') |
|
| 4925 | ||
| 4926 | if not uid.isdigit() or int(uid) <= 0: |
|
| 4927 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4928 | description='API.INVALID_USER_ID') |
|
| 4929 | ||
| 4930 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 4931 | cursor = cnx.cursor() |
|
| 4932 | cursor.execute(" SELECT name " |
|
| 4933 | " FROM tbl_photovoltaic_power_stations " |
|
| 4934 | " WHERE id = %s ", (id_,)) |
|
| 4935 | if cursor.fetchone() is None: |
|
| 4936 | cursor.close() |
|
| 4937 | cnx.close() |
|
| 4938 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4939 | description='API.PHOTOVOLTAIC_POWER_STATION_NOT_FOUND') |
|
| 4940 | ||
| 4941 | cnx_user = mysql.connector.connect(**config.myems_user_db) |
|
| 4942 | cursor_user = cnx_user.cursor() |
|
| 4943 | cursor_user.execute(" SELECT name FROM tbl_users WHERE id = %s ", (uid,)) |
|
| 4944 | if cursor_user.fetchone() is None: |
|
| 4945 | cursor_user.close() |
|
| 4946 | cnx_user.close() |
|
| 4947 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4948 | description='API.USER_NOT_FOUND') |
|
| 4949 | ||
| 4950 | cursor.execute(" SELECT id " |
|
| 4951 | " FROM tbl_photovoltaic_power_stations_users " |
|
| 4952 | " WHERE photovoltaic_power_station_id = %s AND user_id = %s ", (id_, uid)) |
|
| 4953 | if cursor.fetchone() is None: |
|
| 4954 | cursor.close() |
|
| 4955 | cnx.close() |
|
| 4956 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4957 | description='API.PHOTOVOLTAIC_POWER_STATION_USER_RELATION_NOT_FOUND') |
|
| 4958 | ||
| 4959 | cursor.execute(" DELETE FROM tbl_photovoltaic_power_stations_users " |
|
| 4960 | " WHERE photovoltaic_power_station_id = %s AND user_id = %s ", (id_, uid)) |
|
| 4961 | cnx.commit() |
|
| 4962 | ||
| 4963 | cursor.close() |
|
| 4964 | cnx.close() |
|
| 4965 | cursor_user.close() |
|
| 4966 | cnx_user.close() |
|
| 4967 | ||
| 4968 | resp.status = falcon.HTTP_204 |
|
| 4969 | ||
| @@ 1007-1067 (lines=61) @@ | ||
| 1004 | resp.location = '/energystoragepowerstations/' + str(id_) + '/users/' + str(user_id) |
|
| 1005 | ||
| 1006 | ||
| 1007 | class EnergyStoragePowerStationUserItem: |
|
| 1008 | def __init__(self): |
|
| 1009 | """Initializes Class""" |
|
| 1010 | pass |
|
| 1011 | ||
| 1012 | @staticmethod |
|
| 1013 | def on_options(req, resp, id_, uid): |
|
| 1014 | resp.status = falcon.HTTP_200 |
|
| 1015 | ||
| 1016 | @staticmethod |
|
| 1017 | @user_logger |
|
| 1018 | def on_delete(req, resp, id_, uid): |
|
| 1019 | # todo Verify if the user is bound when deleting it |
|
| 1020 | admin_control(req) |
|
| 1021 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1022 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1023 | description='API.INVALID_ENERGY_STORAGE_POWER_STATION_ID') |
|
| 1024 | ||
| 1025 | if not uid.isdigit() or int(uid) <= 0: |
|
| 1026 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1027 | description='API.INVALID_USER_ID') |
|
| 1028 | ||
| 1029 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1030 | cursor = cnx.cursor() |
|
| 1031 | cursor.execute(" SELECT name " |
|
| 1032 | " FROM tbl_energy_storage_power_stations " |
|
| 1033 | " WHERE id = %s ", (id_,)) |
|
| 1034 | if cursor.fetchone() is None: |
|
| 1035 | cursor.close() |
|
| 1036 | cnx.close() |
|
| 1037 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1038 | description='API.ENERGY_STORAGE_POWER_STATION_NOT_FOUND') |
|
| 1039 | ||
| 1040 | cnx_user = mysql.connector.connect(**config.myems_user_db) |
|
| 1041 | cursor_user = cnx_user.cursor() |
|
| 1042 | cursor_user.execute(" SELECT name FROM tbl_users WHERE id = %s ", (uid,)) |
|
| 1043 | if cursor_user.fetchone() is None: |
|
| 1044 | cursor_user.close() |
|
| 1045 | cnx_user.close() |
|
| 1046 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1047 | description='API.USER_NOT_FOUND') |
|
| 1048 | ||
| 1049 | cursor.execute(" SELECT id " |
|
| 1050 | " FROM tbl_energy_storage_power_stations_users " |
|
| 1051 | " WHERE energy_storage_power_station_id = %s AND user_id = %s ", (id_, uid)) |
|
| 1052 | if cursor.fetchone() is None: |
|
| 1053 | cursor.close() |
|
| 1054 | cnx.close() |
|
| 1055 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1056 | description='API.ENERGY_STORAGE_POWER_STATION_USER_RELATION_NOT_FOUND') |
|
| 1057 | ||
| 1058 | cursor.execute(" DELETE FROM tbl_energy_storage_power_stations_users " |
|
| 1059 | " WHERE energy_storage_power_station_id = %s AND user_id = %s ", (id_, uid)) |
|
| 1060 | cnx.commit() |
|
| 1061 | ||
| 1062 | cursor.close() |
|
| 1063 | cnx.close() |
|
| 1064 | cursor_user.close() |
|
| 1065 | cnx_user.close() |
|
| 1066 | ||
| 1067 | resp.status = falcon.HTTP_204 |
|
| 1068 | ||
| 1069 | ||
| 1070 | class EnergyStoragePowerStationExport: |
|
| @@ 836-894 (lines=59) @@ | ||
| 833 | resp.location = '/energystoragepowerstationss/' + str(id_) + '/containers/' + str(energy_storage_container_id) |
|
| 834 | ||
| 835 | ||
| 836 | class EnergyStoragePowerStationContainerItem: |
|
| 837 | def __init__(self): |
|
| 838 | """Initializes Class""" |
|
| 839 | pass |
|
| 840 | ||
| 841 | @staticmethod |
|
| 842 | def on_options(req, resp, id_, sid): |
|
| 843 | resp.status = falcon.HTTP_200 |
|
| 844 | ||
| 845 | @staticmethod |
|
| 846 | @user_logger |
|
| 847 | def on_delete(req, resp, id_, sid): |
|
| 848 | admin_control(req) |
|
| 849 | if not id_.isdigit() or int(id_) <= 0: |
|
| 850 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 851 | description='API.INVALID_ENERGY_STORAGE_POWER_STATION_ID') |
|
| 852 | ||
| 853 | if not sid.isdigit() or int(sid) <= 0: |
|
| 854 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 855 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 856 | ||
| 857 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 858 | cursor = cnx.cursor() |
|
| 859 | ||
| 860 | cursor.execute(" SELECT name " |
|
| 861 | " FROM tbl_energy_storage_power_stations " |
|
| 862 | " WHERE id = %s ", (id_,)) |
|
| 863 | if cursor.fetchone() is None: |
|
| 864 | cursor.close() |
|
| 865 | cnx.close() |
|
| 866 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 867 | description='API.ENERGY_STORAGE_POWER_STATION_NOT_FOUND') |
|
| 868 | ||
| 869 | cursor.execute(" SELECT name " |
|
| 870 | " FROM tbl_energy_storage_containers " |
|
| 871 | " WHERE id = %s ", (sid,)) |
|
| 872 | if cursor.fetchone() is None: |
|
| 873 | cursor.close() |
|
| 874 | cnx.close() |
|
| 875 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 876 | description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND') |
|
| 877 | ||
| 878 | cursor.execute(" SELECT id " |
|
| 879 | " FROM tbl_energy_storage_power_stations_containers " |
|
| 880 | " WHERE energy_storage_power_station_id = %s AND energy_storage_container_id = %s ", (id_, sid)) |
|
| 881 | if cursor.fetchone() is None: |
|
| 882 | cursor.close() |
|
| 883 | cnx.close() |
|
| 884 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 885 | description='API.ENERGY_STORAGE_POWER_STATION_CONTAINER_RELATION_NOT_FOUND') |
|
| 886 | ||
| 887 | cursor.execute(" DELETE FROM tbl_energy_storage_power_stations_containers " |
|
| 888 | " WHERE energy_storage_power_station_id = %s AND energy_storage_container_id = %s ", (id_, sid)) |
|
| 889 | cnx.commit() |
|
| 890 | ||
| 891 | cursor.close() |
|
| 892 | cnx.close() |
|
| 893 | ||
| 894 | resp.status = falcon.HTTP_204 |
|
| 895 | ||
| 896 | ||
| 897 | class EnergyStoragePowerStationUserCollection: |
|
| @@ 5063-5122 (lines=60) @@ | ||
| 5060 | resp.location = '/microgrids/' + str(id_) + '/users/' + str(user_id) |
|
| 5061 | ||
| 5062 | ||
| 5063 | class MicrogridUserItem: |
|
| 5064 | def __init__(self): |
|
| 5065 | """Initializes Class""" |
|
| 5066 | pass |
|
| 5067 | ||
| 5068 | @staticmethod |
|
| 5069 | def on_options(req, resp, id_, uid): |
|
| 5070 | resp.status = falcon.HTTP_200 |
|
| 5071 | ||
| 5072 | @staticmethod |
|
| 5073 | @user_logger |
|
| 5074 | def on_delete(req, resp, id_, uid): |
|
| 5075 | # todo Verify if the user is bound when deleting it |
|
| 5076 | admin_control(req) |
|
| 5077 | if not id_.isdigit() or int(id_) <= 0: |
|
| 5078 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5079 | description='API.INVALID_MICROGRID_ID') |
|
| 5080 | ||
| 5081 | if not uid.isdigit() or int(uid) <= 0: |
|
| 5082 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5083 | description='API.INVALID_USER_ID') |
|
| 5084 | ||
| 5085 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 5086 | cursor = cnx.cursor() |
|
| 5087 | cursor.execute(" SELECT name " |
|
| 5088 | " FROM tbl_microgrids " |
|
| 5089 | " WHERE id = %s ", (id_,)) |
|
| 5090 | if cursor.fetchone() is None: |
|
| 5091 | cursor.close() |
|
| 5092 | cnx.close() |
|
| 5093 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5094 | description='API.MICROGRID_NOT_FOUND') |
|
| 5095 | ||
| 5096 | cnx_user = mysql.connector.connect(**config.myems_user_db) |
|
| 5097 | cursor_user = cnx_user.cursor() |
|
| 5098 | cursor_user.execute(" SELECT name FROM tbl_users WHERE id = %s ", (uid,)) |
|
| 5099 | if cursor_user.fetchone() is None: |
|
| 5100 | cursor_user.close() |
|
| 5101 | cnx_user.close() |
|
| 5102 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5103 | description='API.USER_NOT_FOUND') |
|
| 5104 | ||
| 5105 | cursor.execute(" SELECT id " |
|
| 5106 | " FROM tbl_microgrids_users " |
|
| 5107 | " WHERE microgrid_id = %s AND user_id = %s ", (id_, uid)) |
|
| 5108 | if cursor.fetchone() is None: |
|
| 5109 | cursor.close() |
|
| 5110 | cnx.close() |
|
| 5111 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5112 | description='API.MICROGRID_USER_RELATION_NOT_FOUND') |
|
| 5113 | ||
| 5114 | cursor.execute(" DELETE FROM tbl_microgrids_users WHERE microgrid_id = %s AND user_id = %s ", (id_, uid)) |
|
| 5115 | cnx.commit() |
|
| 5116 | ||
| 5117 | cursor.close() |
|
| 5118 | cnx.close() |
|
| 5119 | cursor_user.close() |
|
| 5120 | cnx_user.close() |
|
| 5121 | ||
| 5122 | resp.status = falcon.HTTP_204 |
|
| 5123 | ||
| 5124 | ||
| 5125 | class MicrogridExport: |
|
| @@ 4892-4950 (lines=59) @@ | ||
| 4889 | resp.location = '/microgrids/' + str(id_) + '/sensors/' + str(sensor_id) |
|
| 4890 | ||
| 4891 | ||
| 4892 | class MicrogridSensorItem: |
|
| 4893 | def __init__(self): |
|
| 4894 | """Initializes Class""" |
|
| 4895 | pass |
|
| 4896 | ||
| 4897 | @staticmethod |
|
| 4898 | def on_options(req, resp, id_, sid): |
|
| 4899 | resp.status = falcon.HTTP_200 |
|
| 4900 | ||
| 4901 | @staticmethod |
|
| 4902 | @user_logger |
|
| 4903 | def on_delete(req, resp, id_, sid): |
|
| 4904 | admin_control(req) |
|
| 4905 | if not id_.isdigit() or int(id_) <= 0: |
|
| 4906 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4907 | description='API.INVALID_MICROGRID_ID') |
|
| 4908 | ||
| 4909 | if not sid.isdigit() or int(sid) <= 0: |
|
| 4910 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 4911 | description='API.INVALID_SENSOR_ID') |
|
| 4912 | ||
| 4913 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 4914 | cursor = cnx.cursor() |
|
| 4915 | ||
| 4916 | cursor.execute(" SELECT name " |
|
| 4917 | " FROM tbl_microgrids " |
|
| 4918 | " WHERE id = %s ", (id_,)) |
|
| 4919 | if cursor.fetchone() is None: |
|
| 4920 | cursor.close() |
|
| 4921 | cnx.close() |
|
| 4922 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4923 | description='API.MICROGRID_NOT_FOUND') |
|
| 4924 | ||
| 4925 | cursor.execute(" SELECT name " |
|
| 4926 | " FROM tbl_sensors " |
|
| 4927 | " WHERE id = %s ", (sid,)) |
|
| 4928 | if cursor.fetchone() is None: |
|
| 4929 | cursor.close() |
|
| 4930 | cnx.close() |
|
| 4931 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4932 | description='API.SENSOR_NOT_FOUND') |
|
| 4933 | ||
| 4934 | cursor.execute(" SELECT id " |
|
| 4935 | " FROM tbl_microgrids_sensors " |
|
| 4936 | " WHERE microgrid_id = %s AND sensor_id = %s ", (id_, sid)) |
|
| 4937 | if cursor.fetchone() is None: |
|
| 4938 | cursor.close() |
|
| 4939 | cnx.close() |
|
| 4940 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 4941 | description='API.MICROGRID_SENSOR_RELATION_NOT_FOUND') |
|
| 4942 | ||
| 4943 | cursor.execute(" DELETE FROM tbl_microgrids_sensors " |
|
| 4944 | " WHERE microgrid_id = %s AND sensor_id = %s ", (id_, sid)) |
|
| 4945 | cnx.commit() |
|
| 4946 | ||
| 4947 | cursor.close() |
|
| 4948 | cnx.close() |
|
| 4949 | ||
| 4950 | resp.status = falcon.HTTP_204 |
|
| 4951 | ||
| 4952 | ||
| 4953 | class MicrogridUserCollection: |
|
| @@ 1670-1729 (lines=60) @@ | ||
| 1667 | resp.location = '/spaces/' + str(id_) + '/meters/' + str(meter_id) |
|
| 1668 | ||
| 1669 | ||
| 1670 | class SpaceMeterItem: |
|
| 1671 | def __init__(self): |
|
| 1672 | """Initializes Class""" |
|
| 1673 | pass |
|
| 1674 | ||
| 1675 | @staticmethod |
|
| 1676 | def on_options(req, resp, id_, mid): |
|
| 1677 | resp.status = falcon.HTTP_200 |
|
| 1678 | ||
| 1679 | @staticmethod |
|
| 1680 | @user_logger |
|
| 1681 | def on_delete(req, resp, id_, mid): |
|
| 1682 | admin_control(req) |
|
| 1683 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1684 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1685 | description='API.INVALID_SPACE_ID') |
|
| 1686 | ||
| 1687 | if not mid.isdigit() or int(mid) <= 0: |
|
| 1688 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1689 | description='API.INVALID_METER_ID') |
|
| 1690 | ||
| 1691 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1692 | cursor = cnx.cursor() |
|
| 1693 | ||
| 1694 | cursor.execute(" SELECT name " |
|
| 1695 | " FROM tbl_spaces " |
|
| 1696 | " WHERE id = %s ", (id_,)) |
|
| 1697 | if cursor.fetchone() is None: |
|
| 1698 | cursor.close() |
|
| 1699 | cnx.close() |
|
| 1700 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1701 | description='API.SPACE_NOT_FOUND') |
|
| 1702 | ||
| 1703 | cursor.execute(" SELECT name " |
|
| 1704 | " FROM tbl_meters " |
|
| 1705 | " WHERE id = %s ", (mid,)) |
|
| 1706 | if cursor.fetchone() is None: |
|
| 1707 | cursor.close() |
|
| 1708 | cnx.close() |
|
| 1709 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1710 | description='API.METER_NOT_FOUND') |
|
| 1711 | ||
| 1712 | cursor.execute(" SELECT id " |
|
| 1713 | " FROM tbl_spaces_meters " |
|
| 1714 | " WHERE space_id = %s AND meter_id = %s ", (id_, mid)) |
|
| 1715 | # use fetchall to avoid 'Unread result found' error in case there are duplicate rows |
|
| 1716 | rows = cursor.fetchall() |
|
| 1717 | if rows is None or len(rows) == 0: |
|
| 1718 | cursor.close() |
|
| 1719 | cnx.close() |
|
| 1720 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1721 | description='API.SPACE_METER_RELATION_NOT_FOUND') |
|
| 1722 | ||
| 1723 | cursor.execute(" DELETE FROM tbl_spaces_meters WHERE space_id = %s AND meter_id = %s ", (id_, mid)) |
|
| 1724 | cnx.commit() |
|
| 1725 | ||
| 1726 | cursor.close() |
|
| 1727 | cnx.close() |
|
| 1728 | ||
| 1729 | resp.status = falcon.HTTP_204 |
|
| 1730 | ||
| 1731 | ||
| 1732 | class SpaceMicrogridCollection: |
|
| @@ 5730-5788 (lines=59) @@ | ||
| 5727 | resp.location = '/spaces/' + str(id_) + '/distributionsystems/' + str(distribution_system_id) |
|
| 5728 | ||
| 5729 | ||
| 5730 | class DistributionSystemItem: |
|
| 5731 | def __init__(self): |
|
| 5732 | """Initializes Class""" |
|
| 5733 | pass |
|
| 5734 | ||
| 5735 | @staticmethod |
|
| 5736 | def on_options(req, resp, id_, did): |
|
| 5737 | resp.status = falcon.HTTP_200 |
|
| 5738 | ||
| 5739 | @staticmethod |
|
| 5740 | @user_logger |
|
| 5741 | def on_delete(req, resp, id_, did): |
|
| 5742 | admin_control(req) |
|
| 5743 | if not id_.isdigit() or int(id_) <= 0: |
|
| 5744 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5745 | description='API.INVALID_SPACE_ID') |
|
| 5746 | ||
| 5747 | if not did.isdigit() or int(did) <= 0: |
|
| 5748 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5749 | description='API.INVALID_DISTRIBUTION_SYSTEM_ID') |
|
| 5750 | ||
| 5751 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 5752 | cursor = cnx.cursor() |
|
| 5753 | ||
| 5754 | cursor.execute(" SELECT name " |
|
| 5755 | " FROM tbl_spaces " |
|
| 5756 | " WHERE id = %s ", (id_,)) |
|
| 5757 | if cursor.fetchone() is None: |
|
| 5758 | cursor.close() |
|
| 5759 | cnx.close() |
|
| 5760 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5761 | description='API.SPACE_NOT_FOUND') |
|
| 5762 | ||
| 5763 | cursor.execute(" SELECT name " |
|
| 5764 | " FROM tbl_distribution_systems " |
|
| 5765 | " WHERE id = %s ", (did,)) |
|
| 5766 | if cursor.fetchone() is None: |
|
| 5767 | cursor.close() |
|
| 5768 | cnx.close() |
|
| 5769 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5770 | description='API.DISTRIBUTION_SYSTEM_NOT_FOUND') |
|
| 5771 | ||
| 5772 | cursor.execute(" SELECT id " |
|
| 5773 | " FROM tbl_spaces_distribution_systems " |
|
| 5774 | " WHERE space_id = %s AND distribution_system_id = %s ", (id_, did)) |
|
| 5775 | if cursor.fetchone() is None: |
|
| 5776 | cursor.close() |
|
| 5777 | cnx.close() |
|
| 5778 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5779 | description='API.SPACE_DISTRIBUTION_SYSTEM_RELATION_NOT_FOUND') |
|
| 5780 | ||
| 5781 | cursor.execute(" DELETE FROM tbl_spaces_distribution_systems " |
|
| 5782 | " WHERE space_id = %s AND distribution_system_id = %s ", (id_, did)) |
|
| 5783 | cnx.commit() |
|
| 5784 | ||
| 5785 | cursor.close() |
|
| 5786 | cnx.close() |
|
| 5787 | ||
| 5788 | resp.status = falcon.HTTP_204 |
|
| @@ 5555-5613 (lines=59) @@ | ||
| 5552 | resp.location = '/spaces/' + str(id_) + '/energyflowdiagrams/' + str(energy_flow_diagram_id) |
|
| 5553 | ||
| 5554 | ||
| 5555 | class SpaceEnergyFlowDiagramItem: |
|
| 5556 | def __init__(self): |
|
| 5557 | """Initializes Class""" |
|
| 5558 | pass |
|
| 5559 | ||
| 5560 | @staticmethod |
|
| 5561 | def on_options(req, resp, id_, eid): |
|
| 5562 | resp.status = falcon.HTTP_200 |
|
| 5563 | ||
| 5564 | @staticmethod |
|
| 5565 | @user_logger |
|
| 5566 | def on_delete(req, resp, id_, eid): |
|
| 5567 | admin_control(req) |
|
| 5568 | if not id_.isdigit() or int(id_) <= 0: |
|
| 5569 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5570 | description='API.INVALID_SPACE_ID') |
|
| 5571 | ||
| 5572 | if not eid.isdigit() or int(eid) <= 0: |
|
| 5573 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5574 | description='API.INVALID_ENERGY_FLOW_DIAGRAM_ID') |
|
| 5575 | ||
| 5576 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 5577 | cursor = cnx.cursor() |
|
| 5578 | ||
| 5579 | cursor.execute(" SELECT name " |
|
| 5580 | " FROM tbl_spaces " |
|
| 5581 | " WHERE id = %s ", (id_,)) |
|
| 5582 | if cursor.fetchone() is None: |
|
| 5583 | cursor.close() |
|
| 5584 | cnx.close() |
|
| 5585 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5586 | description='API.SPACE_NOT_FOUND') |
|
| 5587 | ||
| 5588 | cursor.execute(" SELECT name " |
|
| 5589 | " FROM tbl_energy_flow_diagrams " |
|
| 5590 | " WHERE id = %s ", (eid,)) |
|
| 5591 | if cursor.fetchone() is None: |
|
| 5592 | cursor.close() |
|
| 5593 | cnx.close() |
|
| 5594 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5595 | description='API.ENERGY_FLOW_DIAGRAM_NOT_FOUND') |
|
| 5596 | ||
| 5597 | cursor.execute(" SELECT id " |
|
| 5598 | " FROM tbl_spaces_energy_flow_diagrams " |
|
| 5599 | " WHERE space_id = %s AND energy_flow_diagram_id = %s ", (id_, eid)) |
|
| 5600 | if cursor.fetchone() is None: |
|
| 5601 | cursor.close() |
|
| 5602 | cnx.close() |
|
| 5603 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5604 | description='API.SPACE_ENERGY_FLOW_DIAGRAM_RELATION_NOT_FOUND') |
|
| 5605 | ||
| 5606 | cursor.execute(" DELETE FROM tbl_spaces_energy_flow_diagrams " |
|
| 5607 | " WHERE space_id = %s AND energy_flow_diagram_id = %s ", (id_, eid)) |
|
| 5608 | cnx.commit() |
|
| 5609 | ||
| 5610 | cursor.close() |
|
| 5611 | cnx.close() |
|
| 5612 | ||
| 5613 | resp.status = falcon.HTTP_204 |
|
| 5614 | ||
| 5615 | class DistributionSystemCollection: |
|
| 5616 | def __init__(self): |
|
| @@ 3650-3708 (lines=59) @@ | ||
| 3647 | resp.location = '/spaces/' + str(id_) + '/workingcalendars/' + str(working_calendar_id) |
|
| 3648 | ||
| 3649 | ||
| 3650 | class SpaceWorkingCalendarItem: |
|
| 3651 | def __init__(self): |
|
| 3652 | """Initializes SpaceWorkingCalendarItem Class""" |
|
| 3653 | pass |
|
| 3654 | ||
| 3655 | @staticmethod |
|
| 3656 | def on_options(req, resp, id_, wcid): |
|
| 3657 | resp.status = falcon.HTTP_200 |
|
| 3658 | ||
| 3659 | @staticmethod |
|
| 3660 | @user_logger |
|
| 3661 | def on_delete(req, resp, id_, wcid): |
|
| 3662 | admin_control(req) |
|
| 3663 | if not id_.isdigit() or int(id_) <= 0: |
|
| 3664 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3665 | description='API.INVALID_SPACE_ID') |
|
| 3666 | ||
| 3667 | if not wcid.isdigit() or int(wcid) <= 0: |
|
| 3668 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3669 | description='API.INVALID_WORKING_CALENDAR_ID') |
|
| 3670 | ||
| 3671 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 3672 | cursor = cnx.cursor() |
|
| 3673 | ||
| 3674 | cursor.execute(" SELECT name " |
|
| 3675 | " FROM tbl_spaces " |
|
| 3676 | " WHERE id = %s ", (id_,)) |
|
| 3677 | if cursor.fetchone() is None: |
|
| 3678 | cursor.close() |
|
| 3679 | cnx.close() |
|
| 3680 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3681 | description='API.SPACE_NOT_FOUND') |
|
| 3682 | ||
| 3683 | cursor.execute(" SELECT name " |
|
| 3684 | " FROM tbl_working_calendars " |
|
| 3685 | " WHERE id = %s ", (wcid,)) |
|
| 3686 | if cursor.fetchone() is None: |
|
| 3687 | cursor.close() |
|
| 3688 | cnx.close() |
|
| 3689 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3690 | description='API.WORKING_CALENDAR_NOT_FOUND') |
|
| 3691 | ||
| 3692 | cursor.execute(" SELECT id " |
|
| 3693 | " FROM tbl_spaces_working_calendars " |
|
| 3694 | " WHERE space_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
| 3695 | if cursor.fetchone() is None: |
|
| 3696 | cursor.close() |
|
| 3697 | cnx.close() |
|
| 3698 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3699 | description='API.SPACE_WORKING_CALENDAR_RELATION_NOT_FOUND') |
|
| 3700 | ||
| 3701 | cursor.execute(" DELETE FROM tbl_spaces_working_calendars " |
|
| 3702 | " WHERE space_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
| 3703 | cnx.commit() |
|
| 3704 | ||
| 3705 | cursor.close() |
|
| 3706 | cnx.close() |
|
| 3707 | ||
| 3708 | resp.status = falcon.HTTP_204 |
|
| 3709 | ||
| 3710 | ||
| 3711 | class SpaceCommandCollection: |
|
| @@ 3289-3347 (lines=59) @@ | ||
| 3286 | resp.location = '/spaces/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
| 3287 | ||
| 3288 | ||
| 3289 | class SpaceVirtualMeterItem: |
|
| 3290 | def __init__(self): |
|
| 3291 | """Initializes Class""" |
|
| 3292 | pass |
|
| 3293 | ||
| 3294 | @staticmethod |
|
| 3295 | def on_options(req, resp, id_, mid): |
|
| 3296 | resp.status = falcon.HTTP_200 |
|
| 3297 | ||
| 3298 | @staticmethod |
|
| 3299 | @user_logger |
|
| 3300 | def on_delete(req, resp, id_, mid): |
|
| 3301 | admin_control(req) |
|
| 3302 | if not id_.isdigit() or int(id_) <= 0: |
|
| 3303 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3304 | description='API.INVALID_SPACE_ID') |
|
| 3305 | ||
| 3306 | if not mid.isdigit() or int(mid) <= 0: |
|
| 3307 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3308 | description='API.INVALID_VIRTUAL_METER_ID') |
|
| 3309 | ||
| 3310 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 3311 | cursor = cnx.cursor() |
|
| 3312 | ||
| 3313 | cursor.execute(" SELECT name " |
|
| 3314 | " FROM tbl_spaces " |
|
| 3315 | " WHERE id = %s ", (id_,)) |
|
| 3316 | if cursor.fetchone() is None: |
|
| 3317 | cursor.close() |
|
| 3318 | cnx.close() |
|
| 3319 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3320 | description='API.SPACE_NOT_FOUND') |
|
| 3321 | ||
| 3322 | cursor.execute(" SELECT name " |
|
| 3323 | " FROM tbl_virtual_meters " |
|
| 3324 | " WHERE id = %s ", (mid,)) |
|
| 3325 | if cursor.fetchone() is None: |
|
| 3326 | cursor.close() |
|
| 3327 | cnx.close() |
|
| 3328 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3329 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
| 3330 | ||
| 3331 | cursor.execute(" SELECT id " |
|
| 3332 | " FROM tbl_spaces_virtual_meters " |
|
| 3333 | " WHERE space_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
| 3334 | if cursor.fetchone() is None: |
|
| 3335 | cursor.close() |
|
| 3336 | cnx.close() |
|
| 3337 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3338 | description='API.SPACE_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
| 3339 | ||
| 3340 | cursor.execute(" DELETE FROM tbl_spaces_virtual_meters " |
|
| 3341 | " WHERE space_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
| 3342 | cnx.commit() |
|
| 3343 | ||
| 3344 | cursor.close() |
|
| 3345 | cnx.close() |
|
| 3346 | ||
| 3347 | resp.status = falcon.HTTP_204 |
|
| 3348 | ||
| 3349 | ||
| 3350 | class SpaceTreeCollection: |
|
| @@ 2400-2458 (lines=59) @@ | ||
| 2397 | resp.location = '/spaces/' + str(id_) + '/points/' + str(point_id) |
|
| 2398 | ||
| 2399 | ||
| 2400 | class SpacePointItem: |
|
| 2401 | def __init__(self): |
|
| 2402 | """Initializes Class""" |
|
| 2403 | pass |
|
| 2404 | ||
| 2405 | @staticmethod |
|
| 2406 | def on_options(req, resp, id_, pid): |
|
| 2407 | resp.status = falcon.HTTP_200 |
|
| 2408 | ||
| 2409 | @staticmethod |
|
| 2410 | @user_logger |
|
| 2411 | def on_delete(req, resp, id_, pid): |
|
| 2412 | admin_control(req) |
|
| 2413 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2414 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2415 | description='API.INVALID_SPACE_ID') |
|
| 2416 | ||
| 2417 | if not pid.isdigit() or int(pid) <= 0: |
|
| 2418 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2419 | description='API.INVALID_POINT_ID') |
|
| 2420 | ||
| 2421 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2422 | cursor = cnx.cursor() |
|
| 2423 | ||
| 2424 | cursor.execute(" SELECT name " |
|
| 2425 | " FROM tbl_spaces " |
|
| 2426 | " WHERE id = %s ", (id_,)) |
|
| 2427 | if cursor.fetchone() is None: |
|
| 2428 | cursor.close() |
|
| 2429 | cnx.close() |
|
| 2430 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2431 | description='API.SPACE_NOT_FOUND') |
|
| 2432 | ||
| 2433 | cursor.execute(" SELECT name " |
|
| 2434 | " FROM tbl_points " |
|
| 2435 | " WHERE id = %s ", (pid,)) |
|
| 2436 | if cursor.fetchone() is None: |
|
| 2437 | cursor.close() |
|
| 2438 | cnx.close() |
|
| 2439 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2440 | description='API.POINT_NOT_FOUND') |
|
| 2441 | ||
| 2442 | cursor.execute(" SELECT id " |
|
| 2443 | " FROM tbl_spaces_points " |
|
| 2444 | " WHERE space_id = %s AND point_id = %s ", (id_, pid)) |
|
| 2445 | if cursor.fetchone() is None: |
|
| 2446 | cursor.close() |
|
| 2447 | cnx.close() |
|
| 2448 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2449 | description='API.SPACE_POINT_RELATION_NOT_FOUND') |
|
| 2450 | ||
| 2451 | cursor.execute(" DELETE FROM tbl_spaces_points " |
|
| 2452 | " WHERE space_id = %s AND point_id = %s ", (id_, pid)) |
|
| 2453 | cnx.commit() |
|
| 2454 | ||
| 2455 | cursor.close() |
|
| 2456 | cnx.close() |
|
| 2457 | ||
| 2458 | resp.status = falcon.HTTP_204 |
|
| 2459 | ||
| 2460 | ||
| 2461 | class SpaceSensorCollection: |
|
| @@ 2212-2270 (lines=59) @@ | ||
| 2209 | resp.location = '/spaces/' + str(id_) + '/photovoltaicpowerstations/' + str(photovoltaic_power_station_id) |
|
| 2210 | ||
| 2211 | ||
| 2212 | class SpacePhotovoltaicPowerStationItem: |
|
| 2213 | def __init__(self): |
|
| 2214 | """Initializes Class""" |
|
| 2215 | pass |
|
| 2216 | ||
| 2217 | @staticmethod |
|
| 2218 | def on_options(req, resp, id_, eid): |
|
| 2219 | resp.status = falcon.HTTP_200 |
|
| 2220 | ||
| 2221 | @staticmethod |
|
| 2222 | @user_logger |
|
| 2223 | def on_delete(req, resp, id_, eid): |
|
| 2224 | admin_control(req) |
|
| 2225 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2226 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2227 | description='API.INVALID_SPACE_ID') |
|
| 2228 | ||
| 2229 | if not eid.isdigit() or int(eid) <= 0: |
|
| 2230 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2231 | description='API.INVALID_PHOTOVOLTAIC_POWER_STATION_ID') |
|
| 2232 | ||
| 2233 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2234 | cursor = cnx.cursor() |
|
| 2235 | ||
| 2236 | cursor.execute(" SELECT name " |
|
| 2237 | " FROM tbl_spaces " |
|
| 2238 | " WHERE id = %s ", (id_,)) |
|
| 2239 | if cursor.fetchone() is None: |
|
| 2240 | cursor.close() |
|
| 2241 | cnx.close() |
|
| 2242 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2243 | description='API.SPACE_NOT_FOUND') |
|
| 2244 | ||
| 2245 | cursor.execute(" SELECT name " |
|
| 2246 | " FROM tbl_photovoltaic_power_stations " |
|
| 2247 | " WHERE id = %s ", (eid,)) |
|
| 2248 | if cursor.fetchone() is None: |
|
| 2249 | cursor.close() |
|
| 2250 | cnx.close() |
|
| 2251 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2252 | description='API.PHOTOVOLTAIC_POWER_STATION_NOT_FOUND') |
|
| 2253 | ||
| 2254 | cursor.execute(" SELECT id " |
|
| 2255 | " FROM tbl_spaces_photovoltaic_power_stations " |
|
| 2256 | " WHERE space_id = %s AND photovoltaic_power_station_id = %s ", (id_, eid)) |
|
| 2257 | if cursor.fetchone() is None: |
|
| 2258 | cursor.close() |
|
| 2259 | cnx.close() |
|
| 2260 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2261 | description='API.SPACE_PHOTOVOLTAIC_POWER_STATION_RELATION_NOT_FOUND') |
|
| 2262 | ||
| 2263 | cursor.execute(" DELETE FROM tbl_spaces_photovoltaic_power_stations " |
|
| 2264 | " WHERE space_id = %s AND photovoltaic_power_station_id = %s ", (id_, eid)) |
|
| 2265 | cnx.commit() |
|
| 2266 | ||
| 2267 | cursor.close() |
|
| 2268 | cnx.close() |
|
| 2269 | ||
| 2270 | resp.status = falcon.HTTP_204 |
|
| 2271 | ||
| 2272 | ||
| 2273 | class SpacePointCollection: |
|
| @@ 2036-2094 (lines=59) @@ | ||
| 2033 | resp.location = '/spaces/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
| 2034 | ||
| 2035 | ||
| 2036 | class SpaceOfflineMeterItem: |
|
| 2037 | def __init__(self): |
|
| 2038 | """Initializes Class""" |
|
| 2039 | pass |
|
| 2040 | ||
| 2041 | @staticmethod |
|
| 2042 | def on_options(req, resp, id_, mid): |
|
| 2043 | resp.status = falcon.HTTP_200 |
|
| 2044 | ||
| 2045 | @staticmethod |
|
| 2046 | @user_logger |
|
| 2047 | def on_delete(req, resp, id_, mid): |
|
| 2048 | admin_control(req) |
|
| 2049 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2050 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2051 | description='API.INVALID_SPACE_ID') |
|
| 2052 | ||
| 2053 | if not mid.isdigit() or int(mid) <= 0: |
|
| 2054 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2055 | description='API.INVALID_OFFLINE_METER_ID') |
|
| 2056 | ||
| 2057 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2058 | cursor = cnx.cursor() |
|
| 2059 | ||
| 2060 | cursor.execute(" SELECT name " |
|
| 2061 | " FROM tbl_spaces " |
|
| 2062 | " WHERE id = %s ", (id_,)) |
|
| 2063 | if cursor.fetchone() is None: |
|
| 2064 | cursor.close() |
|
| 2065 | cnx.close() |
|
| 2066 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2067 | description='API.SPACE_NOT_FOUND') |
|
| 2068 | ||
| 2069 | cursor.execute(" SELECT name " |
|
| 2070 | " FROM tbl_offline_meters " |
|
| 2071 | " WHERE id = %s ", (mid,)) |
|
| 2072 | if cursor.fetchone() is None: |
|
| 2073 | cursor.close() |
|
| 2074 | cnx.close() |
|
| 2075 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2076 | description='API.OFFLINE_METER_NOT_FOUND') |
|
| 2077 | ||
| 2078 | cursor.execute(" SELECT id " |
|
| 2079 | " FROM tbl_spaces_offline_meters " |
|
| 2080 | " WHERE space_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
| 2081 | if cursor.fetchone() is None: |
|
| 2082 | cursor.close() |
|
| 2083 | cnx.close() |
|
| 2084 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2085 | description='API.SPACE_OFFLINE_METER_RELATION_NOT_FOUND') |
|
| 2086 | ||
| 2087 | cursor.execute(" DELETE FROM tbl_spaces_offline_meters " |
|
| 2088 | " WHERE space_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
| 2089 | cnx.commit() |
|
| 2090 | ||
| 2091 | cursor.close() |
|
| 2092 | cnx.close() |
|
| 2093 | ||
| 2094 | resp.status = falcon.HTTP_204 |
|
| 2095 | ||
| 2096 | ||
| 2097 | class SpacePhotovoltaicPowerStationCollection: |
|
| @@ 1847-1905 (lines=59) @@ | ||
| 1844 | resp.location = '/spaces/' + str(id_) + '/microgrids/' + str(microgrid_id) |
|
| 1845 | ||
| 1846 | ||
| 1847 | class SpaceMicrogridItem: |
|
| 1848 | def __init__(self): |
|
| 1849 | """Initializes Class""" |
|
| 1850 | pass |
|
| 1851 | ||
| 1852 | @staticmethod |
|
| 1853 | def on_options(req, resp, id_, mid): |
|
| 1854 | resp.status = falcon.HTTP_200 |
|
| 1855 | ||
| 1856 | @staticmethod |
|
| 1857 | @user_logger |
|
| 1858 | def on_delete(req, resp, id_, mid): |
|
| 1859 | admin_control(req) |
|
| 1860 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1861 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1862 | description='API.INVALID_SPACE_ID') |
|
| 1863 | ||
| 1864 | if not mid.isdigit() or int(mid) <= 0: |
|
| 1865 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1866 | description='API.INVALID_MICROGRID_ID') |
|
| 1867 | ||
| 1868 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1869 | cursor = cnx.cursor() |
|
| 1870 | ||
| 1871 | cursor.execute(" SELECT name " |
|
| 1872 | " FROM tbl_spaces " |
|
| 1873 | " WHERE id = %s ", (id_,)) |
|
| 1874 | if cursor.fetchone() is None: |
|
| 1875 | cursor.close() |
|
| 1876 | cnx.close() |
|
| 1877 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1878 | description='API.SPACE_NOT_FOUND') |
|
| 1879 | ||
| 1880 | cursor.execute(" SELECT name " |
|
| 1881 | " FROM tbl_microgrids " |
|
| 1882 | " WHERE id = %s ", (mid,)) |
|
| 1883 | if cursor.fetchone() is None: |
|
| 1884 | cursor.close() |
|
| 1885 | cnx.close() |
|
| 1886 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1887 | description='API.MICROGRID_NOT_FOUND') |
|
| 1888 | ||
| 1889 | cursor.execute(" SELECT id " |
|
| 1890 | " FROM tbl_spaces_microgrids " |
|
| 1891 | " WHERE space_id = %s AND microgrid_id = %s ", (id_, mid)) |
|
| 1892 | if cursor.fetchone() is None: |
|
| 1893 | cursor.close() |
|
| 1894 | cnx.close() |
|
| 1895 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1896 | description='API.SPACE_MICROGRID_RELATION_NOT_FOUND') |
|
| 1897 | ||
| 1898 | cursor.execute(" DELETE FROM tbl_spaces_microgrids " |
|
| 1899 | " WHERE space_id = %s AND microgrid_id = %s ", (id_, mid)) |
|
| 1900 | cnx.commit() |
|
| 1901 | ||
| 1902 | cursor.close() |
|
| 1903 | cnx.close() |
|
| 1904 | ||
| 1905 | resp.status = falcon.HTTP_204 |
|
| 1906 | ||
| 1907 | ||
| 1908 | class SpaceOfflineMeterCollection: |
|
| @@ 1481-1539 (lines=59) @@ | ||
| 1478 | resp.location = '/spaces/' + str(id_) + '/energystoragepowerstations/' + str(hybrid_power_station_id) |
|
| 1479 | ||
| 1480 | ||
| 1481 | class SpaceHybridPowerStationItem: |
|
| 1482 | def __init__(self): |
|
| 1483 | """Initializes Class""" |
|
| 1484 | pass |
|
| 1485 | ||
| 1486 | @staticmethod |
|
| 1487 | def on_options(req, resp, id_, eid): |
|
| 1488 | resp.status = falcon.HTTP_200 |
|
| 1489 | ||
| 1490 | @staticmethod |
|
| 1491 | @user_logger |
|
| 1492 | def on_delete(req, resp, id_, eid): |
|
| 1493 | admin_control(req) |
|
| 1494 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1495 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1496 | description='API.INVALID_SPACE_ID') |
|
| 1497 | ||
| 1498 | if not eid.isdigit() or int(eid) <= 0: |
|
| 1499 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1500 | description='API.INVALID_HYBRID_POWER_STATION_ID') |
|
| 1501 | ||
| 1502 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1503 | cursor = cnx.cursor() |
|
| 1504 | ||
| 1505 | cursor.execute(" SELECT name " |
|
| 1506 | " FROM tbl_spaces " |
|
| 1507 | " WHERE id = %s ", (id_,)) |
|
| 1508 | if cursor.fetchone() is None: |
|
| 1509 | cursor.close() |
|
| 1510 | cnx.close() |
|
| 1511 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1512 | description='API.SPACE_NOT_FOUND') |
|
| 1513 | ||
| 1514 | cursor.execute(" SELECT name " |
|
| 1515 | " FROM tbl_hybrid_power_stations " |
|
| 1516 | " WHERE id = %s ", (eid,)) |
|
| 1517 | if cursor.fetchone() is None: |
|
| 1518 | cursor.close() |
|
| 1519 | cnx.close() |
|
| 1520 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1521 | description='API.HYBRID_POWER_STATION_NOT_FOUND') |
|
| 1522 | ||
| 1523 | cursor.execute(" SELECT id " |
|
| 1524 | " FROM tbl_spaces_hybrid_power_stations " |
|
| 1525 | " WHERE space_id = %s AND hybrid_power_station_id = %s ", (id_, eid)) |
|
| 1526 | if cursor.fetchone() is None: |
|
| 1527 | cursor.close() |
|
| 1528 | cnx.close() |
|
| 1529 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1530 | description='API.SPACE_HYBRID_POWER_STATION_RELATION_NOT_FOUND') |
|
| 1531 | ||
| 1532 | cursor.execute(" DELETE FROM tbl_spaces_hybrid_power_stations " |
|
| 1533 | " WHERE space_id = %s AND hybrid_power_station_id = %s ", (id_, eid)) |
|
| 1534 | cnx.commit() |
|
| 1535 | ||
| 1536 | cursor.close() |
|
| 1537 | cnx.close() |
|
| 1538 | ||
| 1539 | resp.status = falcon.HTTP_204 |
|
| 1540 | ||
| 1541 | ||
| 1542 | class SpaceMeterCollection: |
|
| @@ 1130-1188 (lines=59) @@ | ||
| 1127 | resp.location = '/spaces/' + str(id_) + '/energystoragepowerstations/' + str(energy_storage_power_station_id) |
|
| 1128 | ||
| 1129 | ||
| 1130 | class SpaceEnergyStoragePowerStationItem: |
|
| 1131 | def __init__(self): |
|
| 1132 | """Initializes Class""" |
|
| 1133 | pass |
|
| 1134 | ||
| 1135 | @staticmethod |
|
| 1136 | def on_options(req, resp, id_, eid): |
|
| 1137 | resp.status = falcon.HTTP_200 |
|
| 1138 | ||
| 1139 | @staticmethod |
|
| 1140 | @user_logger |
|
| 1141 | def on_delete(req, resp, id_, eid): |
|
| 1142 | admin_control(req) |
|
| 1143 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1144 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1145 | description='API.INVALID_SPACE_ID') |
|
| 1146 | ||
| 1147 | if not eid.isdigit() or int(eid) <= 0: |
|
| 1148 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1149 | description='API.INVALID_ENERGY_STORAGE_POWER_STATION_ID') |
|
| 1150 | ||
| 1151 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1152 | cursor = cnx.cursor() |
|
| 1153 | ||
| 1154 | cursor.execute(" SELECT name " |
|
| 1155 | " FROM tbl_spaces " |
|
| 1156 | " WHERE id = %s ", (id_,)) |
|
| 1157 | if cursor.fetchone() is None: |
|
| 1158 | cursor.close() |
|
| 1159 | cnx.close() |
|
| 1160 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1161 | description='API.SPACE_NOT_FOUND') |
|
| 1162 | ||
| 1163 | cursor.execute(" SELECT name " |
|
| 1164 | " FROM tbl_energy_storage_power_stations " |
|
| 1165 | " WHERE id = %s ", (eid,)) |
|
| 1166 | if cursor.fetchone() is None: |
|
| 1167 | cursor.close() |
|
| 1168 | cnx.close() |
|
| 1169 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1170 | description='API.ENERGY_STORAGE_POWER_STATION_NOT_FOUND') |
|
| 1171 | ||
| 1172 | cursor.execute(" SELECT id " |
|
| 1173 | " FROM tbl_spaces_energy_storage_power_stations " |
|
| 1174 | " WHERE space_id = %s AND energy_storage_power_station_id = %s ", (id_, eid)) |
|
| 1175 | if cursor.fetchone() is None: |
|
| 1176 | cursor.close() |
|
| 1177 | cnx.close() |
|
| 1178 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1179 | description='API.SPACE_ENERGY_STORAGE_POWER_STATION_RELATION_NOT_FOUND') |
|
| 1180 | ||
| 1181 | cursor.execute(" DELETE FROM tbl_spaces_energy_storage_power_stations " |
|
| 1182 | " WHERE space_id = %s AND energy_storage_power_station_id = %s ", (id_, eid)) |
|
| 1183 | cnx.commit() |
|
| 1184 | ||
| 1185 | cursor.close() |
|
| 1186 | cnx.close() |
|
| 1187 | ||
| 1188 | resp.status = falcon.HTTP_204 |
|
| 1189 | ||
| 1190 | ||
| 1191 | class SpaceEquipmentCollection: |
|
| @@ 954-1012 (lines=59) @@ | ||
| 951 | resp.location = '/spaces/' + str(id_) + '/combinedequipments/' + str(combined_equipment_id) |
|
| 952 | ||
| 953 | ||
| 954 | class SpaceCombinedEquipmentItem: |
|
| 955 | def __init__(self): |
|
| 956 | """Initializes Class""" |
|
| 957 | pass |
|
| 958 | ||
| 959 | @staticmethod |
|
| 960 | def on_options(req, resp, id_, eid): |
|
| 961 | resp.status = falcon.HTTP_200 |
|
| 962 | ||
| 963 | @staticmethod |
|
| 964 | @user_logger |
|
| 965 | def on_delete(req, resp, id_, eid): |
|
| 966 | admin_control(req) |
|
| 967 | if not id_.isdigit() or int(id_) <= 0: |
|
| 968 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 969 | description='API.INVALID_SPACE_ID') |
|
| 970 | ||
| 971 | if not eid.isdigit() or int(eid) <= 0: |
|
| 972 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 973 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
| 974 | ||
| 975 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 976 | cursor = cnx.cursor() |
|
| 977 | ||
| 978 | cursor.execute(" SELECT name " |
|
| 979 | " FROM tbl_spaces " |
|
| 980 | " WHERE id = %s ", (id_,)) |
|
| 981 | if cursor.fetchone() is None: |
|
| 982 | cursor.close() |
|
| 983 | cnx.close() |
|
| 984 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 985 | description='API.SPACE_NOT_FOUND') |
|
| 986 | ||
| 987 | cursor.execute(" SELECT name " |
|
| 988 | " FROM tbl_combined_equipments " |
|
| 989 | " WHERE id = %s ", (eid,)) |
|
| 990 | if cursor.fetchone() is None: |
|
| 991 | cursor.close() |
|
| 992 | cnx.close() |
|
| 993 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 994 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
| 995 | ||
| 996 | cursor.execute(" SELECT id " |
|
| 997 | " FROM tbl_spaces_combined_equipments " |
|
| 998 | " WHERE space_id = %s AND combined_equipment_id = %s ", (id_, eid)) |
|
| 999 | if cursor.fetchone() is None: |
|
| 1000 | cursor.close() |
|
| 1001 | cnx.close() |
|
| 1002 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1003 | description='API.SPACE_COMBINED_EQUIPMENT_RELATION_NOT_FOUND') |
|
| 1004 | ||
| 1005 | cursor.execute(" DELETE FROM tbl_spaces_combined_equipments " |
|
| 1006 | " WHERE space_id = %s AND combined_equipment_id = %s ", (id_, eid)) |
|
| 1007 | cnx.commit() |
|
| 1008 | ||
| 1009 | cursor.close() |
|
| 1010 | cnx.close() |
|
| 1011 | ||
| 1012 | resp.status = falcon.HTTP_204 |
|
| 1013 | ||
| 1014 | ||
| 1015 | class SpaceEnergyStoragePowerStationCollection: |
|
| @@ 3826-3883 (lines=58) @@ | ||
| 3823 | resp.location = '/spaces/' + str(id_) + '/commands/' + str(command_id) |
|
| 3824 | ||
| 3825 | ||
| 3826 | class SpaceCommandItem: |
|
| 3827 | def __init__(self): |
|
| 3828 | """Initializes Class""" |
|
| 3829 | pass |
|
| 3830 | ||
| 3831 | @staticmethod |
|
| 3832 | def on_options(req, resp, id_, cid): |
|
| 3833 | resp.status = falcon.HTTP_200 |
|
| 3834 | ||
| 3835 | @staticmethod |
|
| 3836 | @user_logger |
|
| 3837 | def on_delete(req, resp, id_, cid): |
|
| 3838 | admin_control(req) |
|
| 3839 | if not id_.isdigit() or int(id_) <= 0: |
|
| 3840 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3841 | description='API.INVALID_SPACE_ID') |
|
| 3842 | ||
| 3843 | if not cid.isdigit() or int(cid) <= 0: |
|
| 3844 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3845 | description='API.INVALID_COMMAND_ID') |
|
| 3846 | ||
| 3847 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 3848 | cursor = cnx.cursor() |
|
| 3849 | ||
| 3850 | cursor.execute(" SELECT name " |
|
| 3851 | " FROM tbl_spaces " |
|
| 3852 | " WHERE id = %s ", (id_,)) |
|
| 3853 | if cursor.fetchone() is None: |
|
| 3854 | cursor.close() |
|
| 3855 | cnx.close() |
|
| 3856 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3857 | description='API.SPACE_NOT_FOUND') |
|
| 3858 | ||
| 3859 | cursor.execute(" SELECT name " |
|
| 3860 | " FROM tbl_commands " |
|
| 3861 | " WHERE id = %s ", (cid,)) |
|
| 3862 | if cursor.fetchone() is None: |
|
| 3863 | cursor.close() |
|
| 3864 | cnx.close() |
|
| 3865 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3866 | description='API.COMMAND_NOT_FOUND') |
|
| 3867 | ||
| 3868 | cursor.execute(" SELECT id " |
|
| 3869 | " FROM tbl_spaces_commands " |
|
| 3870 | " WHERE space_id = %s AND command_id = %s ", (id_, cid)) |
|
| 3871 | if cursor.fetchone() is None: |
|
| 3872 | cursor.close() |
|
| 3873 | cnx.close() |
|
| 3874 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3875 | description='API.SPACE_COMMAND_RELATION_NOT_FOUND') |
|
| 3876 | ||
| 3877 | cursor.execute(" DELETE FROM tbl_spaces_commands WHERE space_id = %s AND command_id = %s ", (id_, cid)) |
|
| 3878 | cnx.commit() |
|
| 3879 | ||
| 3880 | cursor.close() |
|
| 3881 | cnx.close() |
|
| 3882 | ||
| 3883 | resp.status = falcon.HTTP_204 |
|
| 3884 | ||
| 3885 | ||
| 3886 | class SpaceExport: |
|
| @@ 3101-3158 (lines=58) @@ | ||
| 3098 | resp.location = '/spaces/' + str(id_) + '/tenants/' + str(tenant_id) |
|
| 3099 | ||
| 3100 | ||
| 3101 | class SpaceTenantItem: |
|
| 3102 | def __init__(self): |
|
| 3103 | """Initializes Class""" |
|
| 3104 | pass |
|
| 3105 | ||
| 3106 | @staticmethod |
|
| 3107 | def on_options(req, resp, id_, tid): |
|
| 3108 | resp.status = falcon.HTTP_200 |
|
| 3109 | ||
| 3110 | @staticmethod |
|
| 3111 | @user_logger |
|
| 3112 | def on_delete(req, resp, id_, tid): |
|
| 3113 | admin_control(req) |
|
| 3114 | if not id_.isdigit() or int(id_) <= 0: |
|
| 3115 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3116 | description='API.INVALID_SPACE_ID') |
|
| 3117 | ||
| 3118 | if not tid.isdigit() or int(tid) <= 0: |
|
| 3119 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 3120 | description='API.INVALID_TENANT_ID') |
|
| 3121 | ||
| 3122 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 3123 | cursor = cnx.cursor() |
|
| 3124 | ||
| 3125 | cursor.execute(" SELECT name " |
|
| 3126 | " FROM tbl_spaces " |
|
| 3127 | " WHERE id = %s ", (id_,)) |
|
| 3128 | if cursor.fetchone() is None: |
|
| 3129 | cursor.close() |
|
| 3130 | cnx.close() |
|
| 3131 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3132 | description='API.SPACE_NOT_FOUND') |
|
| 3133 | ||
| 3134 | cursor.execute(" SELECT name " |
|
| 3135 | " FROM tbl_tenants " |
|
| 3136 | " WHERE id = %s ", (tid,)) |
|
| 3137 | if cursor.fetchone() is None: |
|
| 3138 | cursor.close() |
|
| 3139 | cnx.close() |
|
| 3140 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3141 | description='API.TENANT_NOT_FOUND') |
|
| 3142 | ||
| 3143 | cursor.execute(" SELECT id " |
|
| 3144 | " FROM tbl_spaces_tenants " |
|
| 3145 | " WHERE space_id = %s AND tenant_id = %s ", (id_, tid)) |
|
| 3146 | if cursor.fetchone() is None: |
|
| 3147 | cursor.close() |
|
| 3148 | cnx.close() |
|
| 3149 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 3150 | description='API.SPACE_TENANT_RELATION_NOT_FOUND') |
|
| 3151 | ||
| 3152 | cursor.execute(" DELETE FROM tbl_spaces_tenants WHERE space_id = %s AND tenant_id = %s ", (id_, tid)) |
|
| 3153 | cnx.commit() |
|
| 3154 | ||
| 3155 | cursor.close() |
|
| 3156 | cnx.close() |
|
| 3157 | ||
| 3158 | resp.status = falcon.HTTP_204 |
|
| 3159 | ||
| 3160 | ||
| 3161 | class SpaceVirtualMeterCollection: |
|
| @@ 2926-2983 (lines=58) @@ | ||
| 2923 | resp.location = '/spaces/' + str(id_) + '/stores/' + str(store_id) |
|
| 2924 | ||
| 2925 | ||
| 2926 | class SpaceStoreItem: |
|
| 2927 | def __init__(self): |
|
| 2928 | """Initializes Class""" |
|
| 2929 | pass |
|
| 2930 | ||
| 2931 | @staticmethod |
|
| 2932 | def on_options(req, resp, id_, tid): |
|
| 2933 | resp.status = falcon.HTTP_200 |
|
| 2934 | ||
| 2935 | @staticmethod |
|
| 2936 | @user_logger |
|
| 2937 | def on_delete(req, resp, id_, tid): |
|
| 2938 | admin_control(req) |
|
| 2939 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2940 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2941 | description='API.INVALID_SPACE_ID') |
|
| 2942 | ||
| 2943 | if not tid.isdigit() or int(tid) <= 0: |
|
| 2944 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2945 | description='API.INVALID_STORE_ID') |
|
| 2946 | ||
| 2947 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2948 | cursor = cnx.cursor() |
|
| 2949 | ||
| 2950 | cursor.execute(" SELECT name " |
|
| 2951 | " FROM tbl_spaces " |
|
| 2952 | " WHERE id = %s ", (id_,)) |
|
| 2953 | if cursor.fetchone() is None: |
|
| 2954 | cursor.close() |
|
| 2955 | cnx.close() |
|
| 2956 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2957 | description='API.SPACE_NOT_FOUND') |
|
| 2958 | ||
| 2959 | cursor.execute(" SELECT name " |
|
| 2960 | " FROM tbl_stores " |
|
| 2961 | " WHERE id = %s ", (tid,)) |
|
| 2962 | if cursor.fetchone() is None: |
|
| 2963 | cursor.close() |
|
| 2964 | cnx.close() |
|
| 2965 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2966 | description='API.STORE_NOT_FOUND') |
|
| 2967 | ||
| 2968 | cursor.execute(" SELECT id " |
|
| 2969 | " FROM tbl_spaces_stores " |
|
| 2970 | " WHERE space_id = %s AND store_id = %s ", (id_, tid)) |
|
| 2971 | if cursor.fetchone() is None: |
|
| 2972 | cursor.close() |
|
| 2973 | cnx.close() |
|
| 2974 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2975 | description='API.SPACE_STORE_RELATION_NOT_FOUND') |
|
| 2976 | ||
| 2977 | cursor.execute(" DELETE FROM tbl_spaces_stores WHERE space_id = %s AND store_id = %s ", (id_, tid)) |
|
| 2978 | cnx.commit() |
|
| 2979 | ||
| 2980 | cursor.close() |
|
| 2981 | cnx.close() |
|
| 2982 | ||
| 2983 | resp.status = falcon.HTTP_204 |
|
| 2984 | ||
| 2985 | ||
| 2986 | class SpaceTenantCollection: |
|
| @@ 2751-2808 (lines=58) @@ | ||
| 2748 | resp.location = '/spaces/' + str(id_) + '/shopfloors/' + str(shopfloor_id) |
|
| 2749 | ||
| 2750 | ||
| 2751 | class SpaceShopfloorItem: |
|
| 2752 | def __init__(self): |
|
| 2753 | """Initializes Class""" |
|
| 2754 | pass |
|
| 2755 | ||
| 2756 | @staticmethod |
|
| 2757 | def on_options(req, resp, id_, sid): |
|
| 2758 | resp.status = falcon.HTTP_200 |
|
| 2759 | ||
| 2760 | @staticmethod |
|
| 2761 | @user_logger |
|
| 2762 | def on_delete(req, resp, id_, sid): |
|
| 2763 | admin_control(req) |
|
| 2764 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2765 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2766 | description='API.INVALID_SPACE_ID') |
|
| 2767 | ||
| 2768 | if not sid.isdigit() or int(sid) <= 0: |
|
| 2769 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2770 | description='API.INVALID_SHOPFLOOR_ID') |
|
| 2771 | ||
| 2772 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2773 | cursor = cnx.cursor() |
|
| 2774 | ||
| 2775 | cursor.execute(" SELECT name " |
|
| 2776 | " FROM tbl_spaces " |
|
| 2777 | " WHERE id = %s ", (id_,)) |
|
| 2778 | if cursor.fetchone() is None: |
|
| 2779 | cursor.close() |
|
| 2780 | cnx.close() |
|
| 2781 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2782 | description='API.SPACE_NOT_FOUND') |
|
| 2783 | ||
| 2784 | cursor.execute(" SELECT name " |
|
| 2785 | " FROM tbl_shopfloors " |
|
| 2786 | " WHERE id = %s ", (sid,)) |
|
| 2787 | if cursor.fetchone() is None: |
|
| 2788 | cursor.close() |
|
| 2789 | cnx.close() |
|
| 2790 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2791 | description='API.SHOPFLOOR_NOT_FOUND') |
|
| 2792 | ||
| 2793 | cursor.execute(" SELECT id " |
|
| 2794 | " FROM tbl_spaces_shopfloors " |
|
| 2795 | " WHERE space_id = %s AND shopfloor_id = %s ", (id_, sid)) |
|
| 2796 | if cursor.fetchone() is None: |
|
| 2797 | cursor.close() |
|
| 2798 | cnx.close() |
|
| 2799 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2800 | description='API.SPACE_SHOPFLOOR_RELATION_NOT_FOUND') |
|
| 2801 | ||
| 2802 | cursor.execute(" DELETE FROM tbl_spaces_shopfloors WHERE space_id = %s AND shopfloor_id = %s ", (id_, sid)) |
|
| 2803 | cnx.commit() |
|
| 2804 | ||
| 2805 | cursor.close() |
|
| 2806 | cnx.close() |
|
| 2807 | ||
| 2808 | resp.status = falcon.HTTP_204 |
|
| 2809 | ||
| 2810 | ||
| 2811 | class SpaceStoreCollection: |
|
| @@ 2576-2633 (lines=58) @@ | ||
| 2573 | resp.location = '/spaces/' + str(id_) + '/sensors/' + str(sensor_id) |
|
| 2574 | ||
| 2575 | ||
| 2576 | class SpaceSensorItem: |
|
| 2577 | def __init__(self): |
|
| 2578 | """Initializes Class""" |
|
| 2579 | pass |
|
| 2580 | ||
| 2581 | @staticmethod |
|
| 2582 | def on_options(req, resp, id_, sid): |
|
| 2583 | resp.status = falcon.HTTP_200 |
|
| 2584 | ||
| 2585 | @staticmethod |
|
| 2586 | @user_logger |
|
| 2587 | def on_delete(req, resp, id_, sid): |
|
| 2588 | admin_control(req) |
|
| 2589 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2590 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2591 | description='API.INVALID_SPACE_ID') |
|
| 2592 | ||
| 2593 | if not sid.isdigit() or int(sid) <= 0: |
|
| 2594 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2595 | description='API.INVALID_SENSOR_ID') |
|
| 2596 | ||
| 2597 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2598 | cursor = cnx.cursor() |
|
| 2599 | ||
| 2600 | cursor.execute(" SELECT name " |
|
| 2601 | " FROM tbl_spaces " |
|
| 2602 | " WHERE id = %s ", (id_,)) |
|
| 2603 | if cursor.fetchone() is None: |
|
| 2604 | cursor.close() |
|
| 2605 | cnx.close() |
|
| 2606 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2607 | description='API.SPACE_NOT_FOUND') |
|
| 2608 | ||
| 2609 | cursor.execute(" SELECT name " |
|
| 2610 | " FROM tbl_sensors " |
|
| 2611 | " WHERE id = %s ", (sid,)) |
|
| 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.SENSOR_NOT_FOUND') |
|
| 2617 | ||
| 2618 | cursor.execute(" SELECT id " |
|
| 2619 | " FROM tbl_spaces_sensors " |
|
| 2620 | " WHERE space_id = %s AND sensor_id = %s ", (id_, sid)) |
|
| 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.SPACE_SENSOR_RELATION_NOT_FOUND') |
|
| 2626 | ||
| 2627 | cursor.execute(" DELETE FROM tbl_spaces_sensors WHERE space_id = %s AND sensor_id = %s ", (id_, sid)) |
|
| 2628 | cnx.commit() |
|
| 2629 | ||
| 2630 | cursor.close() |
|
| 2631 | cnx.close() |
|
| 2632 | ||
| 2633 | resp.status = falcon.HTTP_204 |
|
| 2634 | ||
| 2635 | ||
| 2636 | class SpaceShopfloorCollection: |
|
| @@ 1306-1363 (lines=58) @@ | ||
| 1303 | resp.location = '/spaces/' + str(id_) + '/equipments/' + str(equipment_id) |
|
| 1304 | ||
| 1305 | ||
| 1306 | class SpaceEquipmentItem: |
|
| 1307 | def __init__(self): |
|
| 1308 | """Initializes Class""" |
|
| 1309 | pass |
|
| 1310 | ||
| 1311 | @staticmethod |
|
| 1312 | def on_options(req, resp, id_, eid): |
|
| 1313 | resp.status = falcon.HTTP_200 |
|
| 1314 | ||
| 1315 | @staticmethod |
|
| 1316 | @user_logger |
|
| 1317 | def on_delete(req, resp, id_, eid): |
|
| 1318 | admin_control(req) |
|
| 1319 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1320 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1321 | description='API.INVALID_SPACE_ID') |
|
| 1322 | ||
| 1323 | if not eid.isdigit() or int(eid) <= 0: |
|
| 1324 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1325 | description='API.INVALID_EQUIPMENT_ID') |
|
| 1326 | ||
| 1327 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1328 | cursor = cnx.cursor() |
|
| 1329 | ||
| 1330 | cursor.execute(" SELECT name " |
|
| 1331 | " FROM tbl_spaces " |
|
| 1332 | " WHERE id = %s ", (id_,)) |
|
| 1333 | if cursor.fetchone() is None: |
|
| 1334 | cursor.close() |
|
| 1335 | cnx.close() |
|
| 1336 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1337 | description='API.SPACE_NOT_FOUND') |
|
| 1338 | ||
| 1339 | cursor.execute(" SELECT name " |
|
| 1340 | " FROM tbl_equipments " |
|
| 1341 | " WHERE id = %s ", (eid,)) |
|
| 1342 | if cursor.fetchone() is None: |
|
| 1343 | cursor.close() |
|
| 1344 | cnx.close() |
|
| 1345 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1346 | description='API.EQUIPMENT_NOT_FOUND') |
|
| 1347 | ||
| 1348 | cursor.execute(" SELECT id " |
|
| 1349 | " FROM tbl_spaces_equipments " |
|
| 1350 | " WHERE space_id = %s AND equipment_id = %s ", (id_, eid)) |
|
| 1351 | if cursor.fetchone() is None: |
|
| 1352 | cursor.close() |
|
| 1353 | cnx.close() |
|
| 1354 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1355 | description='API.SPACE_EQUIPMENT_RELATION_NOT_FOUND') |
|
| 1356 | ||
| 1357 | cursor.execute(" DELETE FROM tbl_spaces_equipments WHERE space_id = %s AND equipment_id = %s ", (id_, eid)) |
|
| 1358 | cnx.commit() |
|
| 1359 | ||
| 1360 | cursor.close() |
|
| 1361 | cnx.close() |
|
| 1362 | ||
| 1363 | resp.status = falcon.HTTP_204 |
|
| 1364 | ||
| 1365 | ||
| 1366 | class SpaceHybridPowerStationCollection: |
|
| @@ 494-553 (lines=60) @@ | ||
| 491 | resp.location = '/costcenters/' + str(id_) + '/tariffs/' + str(new_values['data']['tariff_id']) |
|
| 492 | ||
| 493 | ||
| 494 | class CostCenterTariffItem: |
|
| 495 | def __init__(self): |
|
| 496 | """"Initializes CostCenterTariffItem""" |
|
| 497 | pass |
|
| 498 | ||
| 499 | @staticmethod |
|
| 500 | def on_options(req, resp, id_, tid): |
|
| 501 | resp.status = falcon.HTTP_200 |
|
| 502 | ||
| 503 | @staticmethod |
|
| 504 | @user_logger |
|
| 505 | def on_delete(req, resp, id_, tid): |
|
| 506 | """Handles DELETE requests""" |
|
| 507 | admin_control(req) |
|
| 508 | if not id_.isdigit() or int(id_) <= 0: |
|
| 509 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 510 | description='API.INVALID_COST_CENTER_ID') |
|
| 511 | ||
| 512 | if not tid.isdigit() or int(tid) <= 0: |
|
| 513 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 514 | description='API.INVALID_TARIFF_ID') |
|
| 515 | ||
| 516 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 517 | cursor = cnx.cursor() |
|
| 518 | ||
| 519 | cursor.execute(" SELECT name " |
|
| 520 | " FROM tbl_cost_centers " |
|
| 521 | " WHERE id = %s ", (id_,)) |
|
| 522 | if cursor.fetchone() is None: |
|
| 523 | cursor.close() |
|
| 524 | cnx.close() |
|
| 525 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 526 | description='API.COST_CENTER_NOT_FOUND') |
|
| 527 | ||
| 528 | cursor.execute(" SELECT name " |
|
| 529 | " FROM tbl_tariffs " |
|
| 530 | " WHERE id = %s ", (tid,)) |
|
| 531 | if cursor.fetchone() is None: |
|
| 532 | cursor.close() |
|
| 533 | cnx.close() |
|
| 534 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 535 | description='API.TARIFF_NOT_FOUND') |
|
| 536 | ||
| 537 | cursor.execute(" SELECT id " |
|
| 538 | " FROM tbl_cost_centers_tariffs " |
|
| 539 | " WHERE cost_center_id = %s AND tariff_id = %s ", (id_, tid)) |
|
| 540 | if cursor.fetchone() is None: |
|
| 541 | cursor.close() |
|
| 542 | cnx.close() |
|
| 543 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 544 | description='API.TARIFF_IS_NOT_ASSOCIATED_WITH_COST_CENTER') |
|
| 545 | ||
| 546 | cursor.execute(" DELETE FROM tbl_cost_centers_tariffs " |
|
| 547 | " WHERE cost_center_id = %s AND tariff_id = %s ", (id_, tid)) |
|
| 548 | cnx.commit() |
|
| 549 | ||
| 550 | cursor.close() |
|
| 551 | cnx.close() |
|
| 552 | ||
| 553 | resp.status = falcon.HTTP_204 |
|
| 554 | ||
| @@ 2213-2271 (lines=59) @@ | ||
| 2210 | resp.location = '/combinedequipments/' + str(id_) + '/commands/' + str(command_id) |
|
| 2211 | ||
| 2212 | ||
| 2213 | class CombinedEquipmentCommandItem: |
|
| 2214 | def __init__(self): |
|
| 2215 | """Initializes Class""" |
|
| 2216 | pass |
|
| 2217 | ||
| 2218 | @staticmethod |
|
| 2219 | def on_options(req, resp, id_, cid): |
|
| 2220 | resp.status = falcon.HTTP_200 |
|
| 2221 | ||
| 2222 | @staticmethod |
|
| 2223 | @user_logger |
|
| 2224 | def on_delete(req, resp, id_, cid): |
|
| 2225 | admin_control(req) |
|
| 2226 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2227 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2228 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
| 2229 | ||
| 2230 | if not cid.isdigit() or int(cid) <= 0: |
|
| 2231 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2232 | description='API.INVALID_COMMAND_ID') |
|
| 2233 | ||
| 2234 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2235 | cursor = cnx.cursor() |
|
| 2236 | ||
| 2237 | cursor.execute(" SELECT name " |
|
| 2238 | " FROM tbl_combined_equipments " |
|
| 2239 | " WHERE id = %s ", (id_,)) |
|
| 2240 | if cursor.fetchone() is None: |
|
| 2241 | cursor.close() |
|
| 2242 | cnx.close() |
|
| 2243 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2244 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
| 2245 | ||
| 2246 | cursor.execute(" SELECT name " |
|
| 2247 | " FROM tbl_commands " |
|
| 2248 | " WHERE id = %s ", (cid,)) |
|
| 2249 | if cursor.fetchone() is None: |
|
| 2250 | cursor.close() |
|
| 2251 | cnx.close() |
|
| 2252 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2253 | description='API.COMMAND_NOT_FOUND') |
|
| 2254 | ||
| 2255 | cursor.execute(" SELECT id " |
|
| 2256 | " FROM tbl_combined_equipments_commands " |
|
| 2257 | " WHERE combined_equipment_id = %s AND command_id = %s ", (id_, cid)) |
|
| 2258 | if cursor.fetchone() is None: |
|
| 2259 | cursor.close() |
|
| 2260 | cnx.close() |
|
| 2261 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2262 | description='API.COMBINED_EQUIPMENT_COMMAND_RELATION_NOT_FOUND') |
|
| 2263 | ||
| 2264 | cursor.execute(" DELETE FROM tbl_combined_equipments_commands " |
|
| 2265 | " WHERE combined_equipment_id = %s AND command_id = %s ", (id_, cid)) |
|
| 2266 | cnx.commit() |
|
| 2267 | ||
| 2268 | cursor.close() |
|
| 2269 | cnx.close() |
|
| 2270 | ||
| 2271 | resp.status = falcon.HTTP_204 |
|
| 2272 | ||
| 2273 | ||
| 2274 | class CombinedEquipmentExport: |
|
| @@ 2037-2095 (lines=59) @@ | ||
| 2034 | resp.location = '/combinedequipments/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
| 2035 | ||
| 2036 | ||
| 2037 | class CombinedEquipmentVirtualMeterItem: |
|
| 2038 | def __init__(self): |
|
| 2039 | """"Initializes CombinedEquipmentVirtualMeterItem""" |
|
| 2040 | pass |
|
| 2041 | ||
| 2042 | @staticmethod |
|
| 2043 | def on_options(req, resp, id_, mid): |
|
| 2044 | resp.status = falcon.HTTP_200 |
|
| 2045 | ||
| 2046 | @staticmethod |
|
| 2047 | @user_logger |
|
| 2048 | def on_delete(req, resp, id_, mid): |
|
| 2049 | admin_control(req) |
|
| 2050 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2051 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2052 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
| 2053 | ||
| 2054 | if not mid.isdigit() or int(mid) <= 0: |
|
| 2055 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2056 | description='API.INVALID_VIRTUAL_METER_ID') |
|
| 2057 | ||
| 2058 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2059 | cursor = cnx.cursor() |
|
| 2060 | ||
| 2061 | cursor.execute(" SELECT name " |
|
| 2062 | " FROM tbl_combined_equipments " |
|
| 2063 | " WHERE id = %s ", (id_,)) |
|
| 2064 | if cursor.fetchone() is None: |
|
| 2065 | cursor.close() |
|
| 2066 | cnx.close() |
|
| 2067 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2068 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
| 2069 | ||
| 2070 | cursor.execute(" SELECT name " |
|
| 2071 | " FROM tbl_virtual_meters " |
|
| 2072 | " WHERE id = %s ", (mid,)) |
|
| 2073 | if cursor.fetchone() is None: |
|
| 2074 | cursor.close() |
|
| 2075 | cnx.close() |
|
| 2076 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2077 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
| 2078 | ||
| 2079 | cursor.execute(" SELECT id " |
|
| 2080 | " FROM tbl_combined_equipments_virtual_meters " |
|
| 2081 | " WHERE combined_equipment_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
| 2082 | if cursor.fetchone() is None: |
|
| 2083 | cursor.close() |
|
| 2084 | cnx.close() |
|
| 2085 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2086 | description='API.COMBINED_EQUIPMENT_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
| 2087 | ||
| 2088 | cursor.execute(" DELETE FROM tbl_combined_equipments_virtual_meters " |
|
| 2089 | " WHERE combined_equipment_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
| 2090 | cnx.commit() |
|
| 2091 | ||
| 2092 | cursor.close() |
|
| 2093 | cnx.close() |
|
| 2094 | ||
| 2095 | resp.status = falcon.HTTP_204 |
|
| 2096 | ||
| 2097 | ||
| 2098 | class CombinedEquipmentCommandCollection: |
|
| @@ 1838-1896 (lines=59) @@ | ||
| 1835 | resp.location = '/combinedequipments/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
| 1836 | ||
| 1837 | ||
| 1838 | class CombinedEquipmentOfflineMeterItem: |
|
| 1839 | def __init__(self): |
|
| 1840 | """"Initializes CombinedEquipmentOfflineMeterItem""" |
|
| 1841 | pass |
|
| 1842 | ||
| 1843 | @staticmethod |
|
| 1844 | def on_options(req, resp, id_, mid): |
|
| 1845 | resp.status = falcon.HTTP_200 |
|
| 1846 | ||
| 1847 | @staticmethod |
|
| 1848 | @user_logger |
|
| 1849 | def on_delete(req, resp, id_, mid): |
|
| 1850 | admin_control(req) |
|
| 1851 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1852 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1853 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
| 1854 | ||
| 1855 | if not mid.isdigit() or int(mid) <= 0: |
|
| 1856 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1857 | description='API.INVALID_OFFLINE_METER_ID') |
|
| 1858 | ||
| 1859 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1860 | cursor = cnx.cursor() |
|
| 1861 | ||
| 1862 | cursor.execute(" SELECT name " |
|
| 1863 | " FROM tbl_combined_equipments " |
|
| 1864 | " WHERE id = %s ", (id_,)) |
|
| 1865 | if cursor.fetchone() is None: |
|
| 1866 | cursor.close() |
|
| 1867 | cnx.close() |
|
| 1868 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1869 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
| 1870 | ||
| 1871 | cursor.execute(" SELECT name " |
|
| 1872 | " FROM tbl_offline_meters " |
|
| 1873 | " WHERE id = %s ", (mid,)) |
|
| 1874 | if cursor.fetchone() is None: |
|
| 1875 | cursor.close() |
|
| 1876 | cnx.close() |
|
| 1877 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1878 | description='API.OFFLINE_METER_NOT_FOUND') |
|
| 1879 | ||
| 1880 | cursor.execute(" SELECT id " |
|
| 1881 | " FROM tbl_combined_equipments_offline_meters " |
|
| 1882 | " WHERE combined_equipment_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
| 1883 | if cursor.fetchone() is None: |
|
| 1884 | cursor.close() |
|
| 1885 | cnx.close() |
|
| 1886 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1887 | description='API.COMBINED_EQUIPMENT_OFFLINE_METER_RELATION_NOT_FOUND') |
|
| 1888 | ||
| 1889 | cursor.execute(" DELETE FROM tbl_combined_equipments_offline_meters " |
|
| 1890 | " WHERE combined_equipment_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
| 1891 | cnx.commit() |
|
| 1892 | ||
| 1893 | cursor.close() |
|
| 1894 | cnx.close() |
|
| 1895 | ||
| 1896 | resp.status = falcon.HTTP_204 |
|
| 1897 | ||
| 1898 | ||
| 1899 | class CombinedEquipmentVirtualMeterCollection: |
|
| @@ 1638-1696 (lines=59) @@ | ||
| 1635 | resp.location = '/combinedequipments/' + str(id_) + '/meters/' + str(meter_id) |
|
| 1636 | ||
| 1637 | ||
| 1638 | class CombinedEquipmentMeterItem: |
|
| 1639 | def __init__(self): |
|
| 1640 | """"Initializes CombinedEquipmentMeterItem""" |
|
| 1641 | pass |
|
| 1642 | ||
| 1643 | @staticmethod |
|
| 1644 | def on_options(req, resp, id_, mid): |
|
| 1645 | resp.status = falcon.HTTP_200 |
|
| 1646 | ||
| 1647 | @staticmethod |
|
| 1648 | @user_logger |
|
| 1649 | def on_delete(req, resp, id_, mid): |
|
| 1650 | admin_control(req) |
|
| 1651 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1652 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1653 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
| 1654 | ||
| 1655 | if not mid.isdigit() or int(mid) <= 0: |
|
| 1656 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1657 | description='API.INVALID_METER_ID') |
|
| 1658 | ||
| 1659 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1660 | cursor = cnx.cursor() |
|
| 1661 | ||
| 1662 | cursor.execute(" SELECT name " |
|
| 1663 | " FROM tbl_combined_equipments " |
|
| 1664 | " WHERE id = %s ", (id_,)) |
|
| 1665 | if cursor.fetchone() is None: |
|
| 1666 | cursor.close() |
|
| 1667 | cnx.close() |
|
| 1668 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1669 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
| 1670 | ||
| 1671 | cursor.execute(" SELECT name " |
|
| 1672 | " FROM tbl_meters " |
|
| 1673 | " WHERE id = %s ", (mid,)) |
|
| 1674 | if cursor.fetchone() is None: |
|
| 1675 | cursor.close() |
|
| 1676 | cnx.close() |
|
| 1677 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1678 | description='API.METER_NOT_FOUND') |
|
| 1679 | ||
| 1680 | cursor.execute(" SELECT id " |
|
| 1681 | " FROM tbl_combined_equipments_meters " |
|
| 1682 | " WHERE combined_equipment_id = %s AND meter_id = %s ", (id_, mid)) |
|
| 1683 | if cursor.fetchone() is None: |
|
| 1684 | cursor.close() |
|
| 1685 | cnx.close() |
|
| 1686 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1687 | description='API.COMBINED_EQUIPMENT_METER_RELATION_NOT_FOUND') |
|
| 1688 | ||
| 1689 | cursor.execute(" DELETE FROM tbl_combined_equipments_meters " |
|
| 1690 | " WHERE combined_equipment_id = %s AND meter_id = %s ", (id_, mid)) |
|
| 1691 | cnx.commit() |
|
| 1692 | ||
| 1693 | cursor.close() |
|
| 1694 | cnx.close() |
|
| 1695 | ||
| 1696 | resp.status = falcon.HTTP_204 |
|
| 1697 | ||
| 1698 | ||
| 1699 | class CombinedEquipmentOfflineMeterCollection: |
|
| @@ 713-771 (lines=59) @@ | ||
| 710 | resp.location = '/combinedequipments/' + str(id_) + '/equipments/' + str(equipment_id) |
|
| 711 | ||
| 712 | ||
| 713 | class CombinedEquipmentEquipmentItem: |
|
| 714 | def __init__(self): |
|
| 715 | """Initializes CombinedEquipmentEquipmentItem""" |
|
| 716 | pass |
|
| 717 | ||
| 718 | @staticmethod |
|
| 719 | def on_options(req, resp, id_, eid): |
|
| 720 | resp.status = falcon.HTTP_200 |
|
| 721 | ||
| 722 | @staticmethod |
|
| 723 | @user_logger |
|
| 724 | def on_delete(req, resp, id_, eid): |
|
| 725 | admin_control(req) |
|
| 726 | if not id_.isdigit() or int(id_) <= 0: |
|
| 727 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 728 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
| 729 | ||
| 730 | if not eid.isdigit() or int(eid) <= 0: |
|
| 731 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 732 | description='API.INVALID_EQUIPMENT_ID') |
|
| 733 | ||
| 734 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 735 | cursor = cnx.cursor() |
|
| 736 | ||
| 737 | cursor.execute(" SELECT name " |
|
| 738 | " FROM tbl_combined_equipments " |
|
| 739 | " WHERE id = %s ", (id_,)) |
|
| 740 | if cursor.fetchone() is None: |
|
| 741 | cursor.close() |
|
| 742 | cnx.close() |
|
| 743 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 744 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
| 745 | ||
| 746 | cursor.execute(" SELECT name " |
|
| 747 | " FROM tbl_equipments " |
|
| 748 | " WHERE id = %s ", (eid,)) |
|
| 749 | if cursor.fetchone() is None: |
|
| 750 | cursor.close() |
|
| 751 | cnx.close() |
|
| 752 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 753 | description='API.EQUIPMENT_NOT_FOUND') |
|
| 754 | ||
| 755 | cursor.execute(" SELECT id " |
|
| 756 | " FROM tbl_combined_equipments_equipments " |
|
| 757 | " WHERE combined_equipment_id = %s AND equipment_id = %s ", (id_, eid)) |
|
| 758 | if cursor.fetchone() is None: |
|
| 759 | cursor.close() |
|
| 760 | cnx.close() |
|
| 761 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 762 | description='API.COMBINED_EQUIPMENT_EQUIPMENT_RELATION_NOT_FOUND') |
|
| 763 | ||
| 764 | cursor.execute(" DELETE FROM tbl_combined_equipments_equipments " |
|
| 765 | " WHERE combined_equipment_id = %s AND equipment_id = %s ", (id_, eid)) |
|
| 766 | cnx.commit() |
|
| 767 | ||
| 768 | cursor.close() |
|
| 769 | cnx.close() |
|
| 770 | ||
| 771 | resp.status = falcon.HTTP_204 |
|
| 772 | ||
| 773 | ||
| 774 | class CombinedEquipmentParameterCollection: |
|
| @@ 1853-1911 (lines=59) @@ | ||
| 1850 | resp.location = '/equipments/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
| 1851 | ||
| 1852 | ||
| 1853 | class EquipmentVirtualMeterItem: |
|
| 1854 | def __init__(self): |
|
| 1855 | """Initializes EquipmentVirtualMeterItem""" |
|
| 1856 | pass |
|
| 1857 | ||
| 1858 | @staticmethod |
|
| 1859 | def on_options(req, resp, id_, mid): |
|
| 1860 | resp.status = falcon.HTTP_200 |
|
| 1861 | ||
| 1862 | @staticmethod |
|
| 1863 | @user_logger |
|
| 1864 | def on_delete(req, resp, id_, mid): |
|
| 1865 | admin_control(req) |
|
| 1866 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1867 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1868 | description='API.INVALID_EQUIPMENT_ID') |
|
| 1869 | ||
| 1870 | if not mid.isdigit() or int(mid) <= 0: |
|
| 1871 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1872 | description='API.INVALID_VIRTUAL_METER_ID') |
|
| 1873 | ||
| 1874 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1875 | cursor = cnx.cursor() |
|
| 1876 | ||
| 1877 | cursor.execute(" SELECT name " |
|
| 1878 | " FROM tbl_equipments " |
|
| 1879 | " WHERE id = %s ", (id_,)) |
|
| 1880 | if cursor.fetchone() is None: |
|
| 1881 | cursor.close() |
|
| 1882 | cnx.close() |
|
| 1883 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1884 | description='API.EQUIPMENT_NOT_FOUND') |
|
| 1885 | ||
| 1886 | cursor.execute(" SELECT name " |
|
| 1887 | " FROM tbl_virtual_meters " |
|
| 1888 | " WHERE id = %s ", (mid,)) |
|
| 1889 | if cursor.fetchone() is None: |
|
| 1890 | cursor.close() |
|
| 1891 | cnx.close() |
|
| 1892 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1893 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
| 1894 | ||
| 1895 | cursor.execute(" SELECT id " |
|
| 1896 | " FROM tbl_equipments_virtual_meters " |
|
| 1897 | " WHERE equipment_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
| 1898 | if cursor.fetchone() is None: |
|
| 1899 | cursor.close() |
|
| 1900 | cnx.close() |
|
| 1901 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1902 | description='API.EQUIPMENT_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
| 1903 | ||
| 1904 | cursor.execute(" DELETE FROM tbl_equipments_virtual_meters " |
|
| 1905 | " WHERE equipment_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
| 1906 | cnx.commit() |
|
| 1907 | ||
| 1908 | cursor.close() |
|
| 1909 | cnx.close() |
|
| 1910 | ||
| 1911 | resp.status = falcon.HTTP_204 |
|
| 1912 | ||
| 1913 | ||
| 1914 | class EquipmentCommandCollection: |
|
| @@ 1655-1713 (lines=59) @@ | ||
| 1652 | resp.location = '/equipments/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
| 1653 | ||
| 1654 | ||
| 1655 | class EquipmentOfflineMeterItem: |
|
| 1656 | def __init__(self): |
|
| 1657 | """Initializes EquipmentOfflineMeterItem""" |
|
| 1658 | pass |
|
| 1659 | ||
| 1660 | @staticmethod |
|
| 1661 | def on_options(req, resp, id_, mid): |
|
| 1662 | resp.status = falcon.HTTP_200 |
|
| 1663 | ||
| 1664 | @staticmethod |
|
| 1665 | @user_logger |
|
| 1666 | def on_delete(req, resp, id_, mid): |
|
| 1667 | admin_control(req) |
|
| 1668 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1669 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1670 | description='API.INVALID_EQUIPMENT_ID') |
|
| 1671 | ||
| 1672 | if not mid.isdigit() or int(mid) <= 0: |
|
| 1673 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1674 | description='API.INVALID_OFFLINE_METER_ID') |
|
| 1675 | ||
| 1676 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1677 | cursor = cnx.cursor() |
|
| 1678 | ||
| 1679 | cursor.execute(" SELECT name " |
|
| 1680 | " FROM tbl_equipments " |
|
| 1681 | " WHERE id = %s ", (id_,)) |
|
| 1682 | if cursor.fetchone() is None: |
|
| 1683 | cursor.close() |
|
| 1684 | cnx.close() |
|
| 1685 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1686 | description='API.EQUIPMENT_NOT_FOUND') |
|
| 1687 | ||
| 1688 | cursor.execute(" SELECT name " |
|
| 1689 | " FROM tbl_offline_meters " |
|
| 1690 | " WHERE id = %s ", (mid,)) |
|
| 1691 | if cursor.fetchone() is None: |
|
| 1692 | cursor.close() |
|
| 1693 | cnx.close() |
|
| 1694 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1695 | description='API.OFFLINE_METER_NOT_FOUND') |
|
| 1696 | ||
| 1697 | cursor.execute(" SELECT id " |
|
| 1698 | " FROM tbl_equipments_offline_meters " |
|
| 1699 | " WHERE equipment_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
| 1700 | if cursor.fetchone() is None: |
|
| 1701 | cursor.close() |
|
| 1702 | cnx.close() |
|
| 1703 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1704 | description='API.EQUIPMENT_OFFLINE_METER_RELATION_NOT_FOUND') |
|
| 1705 | ||
| 1706 | cursor.execute(" DELETE FROM tbl_equipments_offline_meters " |
|
| 1707 | " WHERE equipment_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
| 1708 | cnx.commit() |
|
| 1709 | ||
| 1710 | cursor.close() |
|
| 1711 | cnx.close() |
|
| 1712 | ||
| 1713 | resp.status = falcon.HTTP_204 |
|
| 1714 | ||
| 1715 | ||
| 1716 | class EquipmentVirtualMeterCollection: |
|
| @@ 2031-2088 (lines=58) @@ | ||
| 2028 | resp.location = '/equipments/' + str(id_) + '/commands/' + str(command_id) |
|
| 2029 | ||
| 2030 | ||
| 2031 | class EquipmentCommandItem: |
|
| 2032 | def __init__(self): |
|
| 2033 | """Initializes Class""" |
|
| 2034 | pass |
|
| 2035 | ||
| 2036 | @staticmethod |
|
| 2037 | def on_options(req, resp, id_, cid): |
|
| 2038 | resp.status = falcon.HTTP_200 |
|
| 2039 | ||
| 2040 | @staticmethod |
|
| 2041 | @user_logger |
|
| 2042 | def on_delete(req, resp, id_, cid): |
|
| 2043 | admin_control(req) |
|
| 2044 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2045 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2046 | description='API.INVALID_EQUIPMENT_ID') |
|
| 2047 | ||
| 2048 | if not cid.isdigit() or int(cid) <= 0: |
|
| 2049 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2050 | description='API.INVALID_COMMAND_ID') |
|
| 2051 | ||
| 2052 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2053 | cursor = cnx.cursor() |
|
| 2054 | ||
| 2055 | cursor.execute(" SELECT name " |
|
| 2056 | " FROM tbl_equipments " |
|
| 2057 | " WHERE id = %s ", (id_,)) |
|
| 2058 | if cursor.fetchone() is None: |
|
| 2059 | cursor.close() |
|
| 2060 | cnx.close() |
|
| 2061 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2062 | description='API.EQUIPMENT_NOT_FOUND') |
|
| 2063 | ||
| 2064 | cursor.execute(" SELECT name " |
|
| 2065 | " FROM tbl_commands " |
|
| 2066 | " WHERE id = %s ", (cid,)) |
|
| 2067 | if cursor.fetchone() is None: |
|
| 2068 | cursor.close() |
|
| 2069 | cnx.close() |
|
| 2070 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2071 | description='API.COMMAND_NOT_FOUND') |
|
| 2072 | ||
| 2073 | cursor.execute(" SELECT id " |
|
| 2074 | " FROM tbl_equipments_commands " |
|
| 2075 | " WHERE equipment_id = %s AND command_id = %s ", (id_, cid)) |
|
| 2076 | if cursor.fetchone() is None: |
|
| 2077 | cursor.close() |
|
| 2078 | cnx.close() |
|
| 2079 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2080 | description='API.EQUIPMENT_COMMAND_RELATION_NOT_FOUND') |
|
| 2081 | ||
| 2082 | cursor.execute(" DELETE FROM tbl_equipments_commands WHERE equipment_id = %s AND command_id = %s ", (id_, cid)) |
|
| 2083 | cnx.commit() |
|
| 2084 | ||
| 2085 | cursor.close() |
|
| 2086 | cnx.close() |
|
| 2087 | ||
| 2088 | resp.status = falcon.HTTP_204 |
|
| 2089 | ||
| 2090 | ||
| 2091 | class EquipmentExport: |
|
| @@ 1458-1515 (lines=58) @@ | ||
| 1455 | resp.location = '/equipments/' + str(id_) + '/meters/' + str(meter_id) |
|
| 1456 | ||
| 1457 | ||
| 1458 | class EquipmentMeterItem: |
|
| 1459 | def __init__(self): |
|
| 1460 | """Initializes EquipmentMeterItem""" |
|
| 1461 | pass |
|
| 1462 | ||
| 1463 | @staticmethod |
|
| 1464 | def on_options(req, resp, id_, mid): |
|
| 1465 | resp.status = falcon.HTTP_200 |
|
| 1466 | ||
| 1467 | @staticmethod |
|
| 1468 | @user_logger |
|
| 1469 | def on_delete(req, resp, id_, mid): |
|
| 1470 | admin_control(req) |
|
| 1471 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1472 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1473 | description='API.INVALID_EQUIPMENT_ID') |
|
| 1474 | ||
| 1475 | if not mid.isdigit() or int(mid) <= 0: |
|
| 1476 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1477 | description='API.INVALID_METER_ID') |
|
| 1478 | ||
| 1479 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1480 | cursor = cnx.cursor() |
|
| 1481 | ||
| 1482 | cursor.execute(" SELECT name " |
|
| 1483 | " FROM tbl_equipments " |
|
| 1484 | " WHERE id = %s ", (id_,)) |
|
| 1485 | if cursor.fetchone() is None: |
|
| 1486 | cursor.close() |
|
| 1487 | cnx.close() |
|
| 1488 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1489 | description='API.EQUIPMENT_NOT_FOUND') |
|
| 1490 | ||
| 1491 | cursor.execute(" SELECT name " |
|
| 1492 | " FROM tbl_meters " |
|
| 1493 | " WHERE id = %s ", (mid,)) |
|
| 1494 | if cursor.fetchone() is None: |
|
| 1495 | cursor.close() |
|
| 1496 | cnx.close() |
|
| 1497 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1498 | description='API.METER_NOT_FOUND') |
|
| 1499 | ||
| 1500 | cursor.execute(" SELECT id " |
|
| 1501 | " FROM tbl_equipments_meters " |
|
| 1502 | " WHERE equipment_id = %s AND meter_id = %s ", (id_, mid)) |
|
| 1503 | if cursor.fetchone() is None: |
|
| 1504 | cursor.close() |
|
| 1505 | cnx.close() |
|
| 1506 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1507 | description='API.EQUIPMENT_METER_RELATION_NOT_FOUND') |
|
| 1508 | ||
| 1509 | cursor.execute(" DELETE FROM tbl_equipments_meters WHERE equipment_id = %s AND meter_id = %s ", (id_, mid)) |
|
| 1510 | cnx.commit() |
|
| 1511 | ||
| 1512 | cursor.close() |
|
| 1513 | cnx.close() |
|
| 1514 | ||
| 1515 | resp.status = falcon.HTTP_204 |
|
| 1516 | ||
| 1517 | ||
| 1518 | class EquipmentOfflineMeterCollection: |
|
| @@ 1731-1789 (lines=59) @@ | ||
| 1728 | resp.location = '/tenants/' + str(id_) + '/workingcalendars/' + str(working_calendar_id) |
|
| 1729 | ||
| 1730 | ||
| 1731 | class TenantWorkingCalendarItem: |
|
| 1732 | def __init__(self): |
|
| 1733 | """Initializes TenantWorkingCalendarItem Class""" |
|
| 1734 | pass |
|
| 1735 | ||
| 1736 | @staticmethod |
|
| 1737 | def on_options(req, resp, id_, wcid): |
|
| 1738 | resp.status = falcon.HTTP_200 |
|
| 1739 | ||
| 1740 | @staticmethod |
|
| 1741 | @user_logger |
|
| 1742 | def on_delete(req, resp, id_, wcid): |
|
| 1743 | admin_control(req) |
|
| 1744 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1745 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1746 | description='API.INVALID_TENANT_ID') |
|
| 1747 | ||
| 1748 | if not wcid.isdigit() or int(wcid) <= 0: |
|
| 1749 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1750 | description='API.INVALID_WORKING_CALENDAR_ID') |
|
| 1751 | ||
| 1752 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1753 | cursor = cnx.cursor() |
|
| 1754 | ||
| 1755 | cursor.execute(" SELECT name " |
|
| 1756 | " FROM tbl_tenants " |
|
| 1757 | " WHERE id = %s ", (id_,)) |
|
| 1758 | if cursor.fetchone() is None: |
|
| 1759 | cursor.close() |
|
| 1760 | cnx.close() |
|
| 1761 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1762 | description='API.TENANT_NOT_FOUND') |
|
| 1763 | ||
| 1764 | cursor.execute(" SELECT name " |
|
| 1765 | " FROM tbl_working_calendars " |
|
| 1766 | " WHERE id = %s ", (wcid,)) |
|
| 1767 | if cursor.fetchone() is None: |
|
| 1768 | cursor.close() |
|
| 1769 | cnx.close() |
|
| 1770 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1771 | description='API.WORKING_CALENDAR_NOT_FOUND') |
|
| 1772 | ||
| 1773 | cursor.execute(" SELECT id " |
|
| 1774 | " FROM tbl_tenants_working_calendars " |
|
| 1775 | " WHERE tenant_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
| 1776 | if cursor.fetchone() is None: |
|
| 1777 | cursor.close() |
|
| 1778 | cnx.close() |
|
| 1779 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1780 | description='API.TENANT_WORKING_CALENDAR_RELATION_NOT_FOUND') |
|
| 1781 | ||
| 1782 | cursor.execute(" DELETE FROM tbl_tenants_working_calendars " |
|
| 1783 | " WHERE tenant_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
| 1784 | cnx.commit() |
|
| 1785 | ||
| 1786 | cursor.close() |
|
| 1787 | cnx.close() |
|
| 1788 | ||
| 1789 | resp.status = falcon.HTTP_204 |
|
| 1790 | ||
| 1791 | ||
| 1792 | class TenantCommandCollection: |
|
| @@ 1553-1611 (lines=59) @@ | ||
| 1550 | resp.location = '/tenants/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
| 1551 | ||
| 1552 | ||
| 1553 | class TenantVirtualMeterItem: |
|
| 1554 | def __init__(self): |
|
| 1555 | """Initializes Class""" |
|
| 1556 | pass |
|
| 1557 | ||
| 1558 | @staticmethod |
|
| 1559 | def on_options(req, resp, id_, mid): |
|
| 1560 | resp.status = falcon.HTTP_200 |
|
| 1561 | ||
| 1562 | @staticmethod |
|
| 1563 | @user_logger |
|
| 1564 | def on_delete(req, resp, id_, mid): |
|
| 1565 | admin_control(req) |
|
| 1566 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1567 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1568 | description='API.INVALID_TENANT_ID') |
|
| 1569 | ||
| 1570 | if not mid.isdigit() or int(mid) <= 0: |
|
| 1571 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1572 | description='API.INVALID_VIRTUAL_METER_ID') |
|
| 1573 | ||
| 1574 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1575 | cursor = cnx.cursor() |
|
| 1576 | ||
| 1577 | cursor.execute(" SELECT name " |
|
| 1578 | " FROM tbl_tenants " |
|
| 1579 | " WHERE id = %s ", (id_,)) |
|
| 1580 | if cursor.fetchone() is None: |
|
| 1581 | cursor.close() |
|
| 1582 | cnx.close() |
|
| 1583 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1584 | description='API.TENANT_NOT_FOUND') |
|
| 1585 | ||
| 1586 | cursor.execute(" SELECT name " |
|
| 1587 | " FROM tbl_virtual_meters " |
|
| 1588 | " WHERE id = %s ", (mid,)) |
|
| 1589 | if cursor.fetchone() is None: |
|
| 1590 | cursor.close() |
|
| 1591 | cnx.close() |
|
| 1592 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1593 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
| 1594 | ||
| 1595 | cursor.execute(" SELECT id " |
|
| 1596 | " FROM tbl_tenants_virtual_meters " |
|
| 1597 | " WHERE tenant_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
| 1598 | if cursor.fetchone() is None: |
|
| 1599 | cursor.close() |
|
| 1600 | cnx.close() |
|
| 1601 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1602 | description='API.TENANT_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
| 1603 | ||
| 1604 | cursor.execute(" DELETE FROM tbl_tenants_virtual_meters " |
|
| 1605 | " WHERE tenant_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
| 1606 | cnx.commit() |
|
| 1607 | ||
| 1608 | cursor.close() |
|
| 1609 | cnx.close() |
|
| 1610 | ||
| 1611 | resp.status = falcon.HTTP_204 |
|
| 1612 | ||
| 1613 | ||
| 1614 | class TenantWorkingCalendarCollection: |
|
| @@ 1185-1243 (lines=59) @@ | ||
| 1182 | resp.location = '/tenants/' + str(id_) + '/points/' + str(point_id) |
|
| 1183 | ||
| 1184 | ||
| 1185 | class TenantPointItem: |
|
| 1186 | def __init__(self): |
|
| 1187 | """Initializes Class""" |
|
| 1188 | pass |
|
| 1189 | ||
| 1190 | @staticmethod |
|
| 1191 | def on_options(req, resp, id_, pid): |
|
| 1192 | resp.status = falcon.HTTP_200 |
|
| 1193 | ||
| 1194 | @staticmethod |
|
| 1195 | @user_logger |
|
| 1196 | def on_delete(req, resp, id_, pid): |
|
| 1197 | admin_control(req) |
|
| 1198 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1199 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1200 | description='API.INVALID_TENANT_ID') |
|
| 1201 | ||
| 1202 | if not pid.isdigit() or int(pid) <= 0: |
|
| 1203 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1204 | description='API.INVALID_POINT_ID') |
|
| 1205 | ||
| 1206 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1207 | cursor = cnx.cursor() |
|
| 1208 | ||
| 1209 | cursor.execute(" SELECT name " |
|
| 1210 | " FROM tbl_tenants " |
|
| 1211 | " WHERE id = %s ", (id_,)) |
|
| 1212 | if cursor.fetchone() is None: |
|
| 1213 | cursor.close() |
|
| 1214 | cnx.close() |
|
| 1215 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1216 | description='API.TENANT_NOT_FOUND') |
|
| 1217 | ||
| 1218 | cursor.execute(" SELECT name " |
|
| 1219 | " FROM tbl_points " |
|
| 1220 | " WHERE id = %s ", (pid,)) |
|
| 1221 | if cursor.fetchone() is None: |
|
| 1222 | cursor.close() |
|
| 1223 | cnx.close() |
|
| 1224 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1225 | description='API.POINT_NOT_FOUND') |
|
| 1226 | ||
| 1227 | cursor.execute(" SELECT id " |
|
| 1228 | " FROM tbl_tenants_points " |
|
| 1229 | " WHERE tenant_id = %s AND point_id = %s ", (id_, pid)) |
|
| 1230 | if cursor.fetchone() is None: |
|
| 1231 | cursor.close() |
|
| 1232 | cnx.close() |
|
| 1233 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1234 | description='API.TENANT_POINT_RELATION_NOT_FOUND') |
|
| 1235 | ||
| 1236 | cursor.execute(" DELETE FROM tbl_tenants_points " |
|
| 1237 | " WHERE tenant_id = %s AND point_id = %s ", (id_, pid)) |
|
| 1238 | cnx.commit() |
|
| 1239 | ||
| 1240 | cursor.close() |
|
| 1241 | cnx.close() |
|
| 1242 | ||
| 1243 | resp.status = falcon.HTTP_204 |
|
| 1244 | ||
| 1245 | ||
| 1246 | class TenantSensorCollection: |
|
| @@ 995-1053 (lines=59) @@ | ||
| 992 | resp.location = '/tenants/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
| 993 | ||
| 994 | ||
| 995 | class TenantOfflineMeterItem: |
|
| 996 | def __init__(self): |
|
| 997 | """Initializes Class""" |
|
| 998 | pass |
|
| 999 | ||
| 1000 | @staticmethod |
|
| 1001 | def on_options(req, resp, id_, mid): |
|
| 1002 | resp.status = falcon.HTTP_200 |
|
| 1003 | ||
| 1004 | @staticmethod |
|
| 1005 | @user_logger |
|
| 1006 | def on_delete(req, resp, id_, mid): |
|
| 1007 | admin_control(req) |
|
| 1008 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1009 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1010 | description='API.INVALID_TENANT_ID') |
|
| 1011 | ||
| 1012 | if not mid.isdigit() or int(mid) <= 0: |
|
| 1013 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1014 | description='API.INVALID_OFFLINE_METER_ID') |
|
| 1015 | ||
| 1016 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1017 | cursor = cnx.cursor() |
|
| 1018 | ||
| 1019 | cursor.execute(" SELECT name " |
|
| 1020 | " FROM tbl_tenants " |
|
| 1021 | " WHERE id = %s ", (id_,)) |
|
| 1022 | if cursor.fetchone() is None: |
|
| 1023 | cursor.close() |
|
| 1024 | cnx.close() |
|
| 1025 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1026 | description='API.TENANT_NOT_FOUND') |
|
| 1027 | ||
| 1028 | cursor.execute(" SELECT name " |
|
| 1029 | " FROM tbl_offline_meters " |
|
| 1030 | " WHERE id = %s ", (mid,)) |
|
| 1031 | if cursor.fetchone() is None: |
|
| 1032 | cursor.close() |
|
| 1033 | cnx.close() |
|
| 1034 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1035 | description='API.OFFLINE_METER_NOT_FOUND') |
|
| 1036 | ||
| 1037 | cursor.execute(" SELECT id " |
|
| 1038 | " FROM tbl_tenants_offline_meters " |
|
| 1039 | " WHERE tenant_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
| 1040 | if cursor.fetchone() is None: |
|
| 1041 | cursor.close() |
|
| 1042 | cnx.close() |
|
| 1043 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1044 | description='API.TENANT_OFFLINE_METER_RELATION_NOT_FOUND') |
|
| 1045 | ||
| 1046 | cursor.execute(" DELETE FROM tbl_tenants_offline_meters " |
|
| 1047 | " WHERE tenant_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
| 1048 | cnx.commit() |
|
| 1049 | ||
| 1050 | cursor.close() |
|
| 1051 | cnx.close() |
|
| 1052 | ||
| 1053 | resp.status = falcon.HTTP_204 |
|
| 1054 | ||
| 1055 | ||
| 1056 | class TenantPointCollection: |
|
| @@ 1909-1966 (lines=58) @@ | ||
| 1906 | resp.location = '/tenants/' + str(id_) + '/commands/' + str(command_id) |
|
| 1907 | ||
| 1908 | ||
| 1909 | class TenantCommandItem: |
|
| 1910 | def __init__(self): |
|
| 1911 | """Initializes Class""" |
|
| 1912 | pass |
|
| 1913 | ||
| 1914 | @staticmethod |
|
| 1915 | def on_options(req, resp, id_, cid): |
|
| 1916 | resp.status = falcon.HTTP_200 |
|
| 1917 | ||
| 1918 | @staticmethod |
|
| 1919 | @user_logger |
|
| 1920 | def on_delete(req, resp, id_, cid): |
|
| 1921 | admin_control(req) |
|
| 1922 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1923 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1924 | description='API.INVALID_TENANT_ID') |
|
| 1925 | ||
| 1926 | if not cid.isdigit() or int(cid) <= 0: |
|
| 1927 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1928 | description='API.INVALID_COMMAND_ID') |
|
| 1929 | ||
| 1930 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1931 | cursor = cnx.cursor() |
|
| 1932 | ||
| 1933 | cursor.execute(" SELECT name " |
|
| 1934 | " FROM tbl_tenants " |
|
| 1935 | " WHERE id = %s ", (id_,)) |
|
| 1936 | if cursor.fetchone() is None: |
|
| 1937 | cursor.close() |
|
| 1938 | cnx.close() |
|
| 1939 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1940 | description='API.TENANT_NOT_FOUND') |
|
| 1941 | ||
| 1942 | cursor.execute(" SELECT name " |
|
| 1943 | " FROM tbl_commands " |
|
| 1944 | " WHERE id = %s ", (cid,)) |
|
| 1945 | if cursor.fetchone() is None: |
|
| 1946 | cursor.close() |
|
| 1947 | cnx.close() |
|
| 1948 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1949 | description='API.COMMAND_NOT_FOUND') |
|
| 1950 | ||
| 1951 | cursor.execute(" SELECT id " |
|
| 1952 | " FROM tbl_tenants_commands " |
|
| 1953 | " WHERE tenant_id = %s AND command_id = %s ", (id_, cid)) |
|
| 1954 | if cursor.fetchone() is None: |
|
| 1955 | cursor.close() |
|
| 1956 | cnx.close() |
|
| 1957 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1958 | description='API.TENANT_COMMAND_RELATION_NOT_FOUND') |
|
| 1959 | ||
| 1960 | cursor.execute(" DELETE FROM tbl_tenants_commands WHERE tenant_id = %s AND command_id = %s ", (id_, cid)) |
|
| 1961 | cnx.commit() |
|
| 1962 | ||
| 1963 | cursor.close() |
|
| 1964 | cnx.close() |
|
| 1965 | ||
| 1966 | resp.status = falcon.HTTP_204 |
|
| 1967 | ||
| 1968 | ||
| 1969 | class TenantExport: |
|
| @@ 1363-1420 (lines=58) @@ | ||
| 1360 | resp.location = '/tenants/' + str(id_) + '/sensors/' + str(sensor_id) |
|
| 1361 | ||
| 1362 | ||
| 1363 | class TenantSensorItem: |
|
| 1364 | def __init__(self): |
|
| 1365 | """Initializes Class""" |
|
| 1366 | pass |
|
| 1367 | ||
| 1368 | @staticmethod |
|
| 1369 | def on_options(req, resp, id_, sid): |
|
| 1370 | resp.status = falcon.HTTP_200 |
|
| 1371 | ||
| 1372 | @staticmethod |
|
| 1373 | @user_logger |
|
| 1374 | def on_delete(req, resp, id_, sid): |
|
| 1375 | admin_control(req) |
|
| 1376 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1377 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1378 | description='API.INVALID_TENANT_ID') |
|
| 1379 | ||
| 1380 | if not sid.isdigit() or int(sid) <= 0: |
|
| 1381 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1382 | description='API.INVALID_SENSOR_ID') |
|
| 1383 | ||
| 1384 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1385 | cursor = cnx.cursor() |
|
| 1386 | ||
| 1387 | cursor.execute(" SELECT name " |
|
| 1388 | " FROM tbl_tenants " |
|
| 1389 | " WHERE id = %s ", (id_,)) |
|
| 1390 | if cursor.fetchone() is None: |
|
| 1391 | cursor.close() |
|
| 1392 | cnx.close() |
|
| 1393 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1394 | description='API.TENANT_NOT_FOUND') |
|
| 1395 | ||
| 1396 | cursor.execute(" SELECT name " |
|
| 1397 | " FROM tbl_sensors " |
|
| 1398 | " WHERE id = %s ", (sid,)) |
|
| 1399 | if cursor.fetchone() is None: |
|
| 1400 | cursor.close() |
|
| 1401 | cnx.close() |
|
| 1402 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1403 | description='API.SENSOR_NOT_FOUND') |
|
| 1404 | ||
| 1405 | cursor.execute(" SELECT id " |
|
| 1406 | " FROM tbl_tenants_sensors " |
|
| 1407 | " WHERE tenant_id = %s AND sensor_id = %s ", (id_, sid)) |
|
| 1408 | if cursor.fetchone() is None: |
|
| 1409 | cursor.close() |
|
| 1410 | cnx.close() |
|
| 1411 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1412 | description='API.TENANT_SENSOR_RELATION_NOT_FOUND') |
|
| 1413 | ||
| 1414 | cursor.execute(" DELETE FROM tbl_tenants_sensors WHERE tenant_id = %s AND sensor_id = %s ", (id_, sid)) |
|
| 1415 | cnx.commit() |
|
| 1416 | ||
| 1417 | cursor.close() |
|
| 1418 | cnx.close() |
|
| 1419 | ||
| 1420 | resp.status = falcon.HTTP_204 |
|
| 1421 | ||
| 1422 | ||
| 1423 | class TenantVirtualMeterCollection: |
|
| @@ 805-862 (lines=58) @@ | ||
| 802 | resp.location = '/tenants/' + str(id_) + '/meters/' + str(meter_id) |
|
| 803 | ||
| 804 | ||
| 805 | class TenantMeterItem: |
|
| 806 | def __init__(self): |
|
| 807 | """Initializes Class""" |
|
| 808 | pass |
|
| 809 | ||
| 810 | @staticmethod |
|
| 811 | def on_options(req, resp, id_, mid): |
|
| 812 | resp.status = falcon.HTTP_200 |
|
| 813 | ||
| 814 | @staticmethod |
|
| 815 | @user_logger |
|
| 816 | def on_delete(req, resp, id_, mid): |
|
| 817 | admin_control(req) |
|
| 818 | if not id_.isdigit() or int(id_) <= 0: |
|
| 819 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 820 | description='API.INVALID_TENANT_ID') |
|
| 821 | ||
| 822 | if not mid.isdigit() or int(mid) <= 0: |
|
| 823 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 824 | description='API.INVALID_METER_ID') |
|
| 825 | ||
| 826 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 827 | cursor = cnx.cursor() |
|
| 828 | ||
| 829 | cursor.execute(" SELECT name " |
|
| 830 | " FROM tbl_tenants " |
|
| 831 | " WHERE id = %s ", (id_,)) |
|
| 832 | if cursor.fetchone() is None: |
|
| 833 | cursor.close() |
|
| 834 | cnx.close() |
|
| 835 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 836 | description='API.TENANT_NOT_FOUND') |
|
| 837 | ||
| 838 | cursor.execute(" SELECT name " |
|
| 839 | " FROM tbl_meters " |
|
| 840 | " WHERE id = %s ", (mid,)) |
|
| 841 | if cursor.fetchone() is None: |
|
| 842 | cursor.close() |
|
| 843 | cnx.close() |
|
| 844 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 845 | description='API.METER_NOT_FOUND') |
|
| 846 | ||
| 847 | cursor.execute(" SELECT id " |
|
| 848 | " FROM tbl_tenants_meters " |
|
| 849 | " WHERE tenant_id = %s AND meter_id = %s ", (id_, mid)) |
|
| 850 | if cursor.fetchone() is None: |
|
| 851 | cursor.close() |
|
| 852 | cnx.close() |
|
| 853 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 854 | description='API.TENANT_METER_RELATION_NOT_FOUND') |
|
| 855 | ||
| 856 | cursor.execute(" DELETE FROM tbl_tenants_meters WHERE tenant_id = %s AND meter_id = %s ", (id_, mid)) |
|
| 857 | cnx.commit() |
|
| 858 | ||
| 859 | cursor.close() |
|
| 860 | cnx.close() |
|
| 861 | ||
| 862 | resp.status = falcon.HTTP_204 |
|
| 863 | ||
| 864 | ||
| 865 | class TenantOfflineMeterCollection: |
|
| @@ 1678-1736 (lines=59) @@ | ||
| 1675 | resp.location = '/shopfloors/' + str(id_) + '/workingcalendars/' + str(working_calendar_id) |
|
| 1676 | ||
| 1677 | ||
| 1678 | class ShopfloorWorkingCalendarItem: |
|
| 1679 | def __init__(self): |
|
| 1680 | """Initializes ShopfloorWorkingCalendarItem Class""" |
|
| 1681 | pass |
|
| 1682 | ||
| 1683 | @staticmethod |
|
| 1684 | def on_options(req, resp, id_, wcid): |
|
| 1685 | resp.status = falcon.HTTP_200 |
|
| 1686 | ||
| 1687 | @staticmethod |
|
| 1688 | @user_logger |
|
| 1689 | def on_delete(req, resp, id_, wcid): |
|
| 1690 | admin_control(req) |
|
| 1691 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1692 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1693 | description='API.INVALID_SHOPFLOOR_ID') |
|
| 1694 | ||
| 1695 | if not wcid.isdigit() or int(wcid) <= 0: |
|
| 1696 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1697 | description='API.INVALID_WORKING_CALENDAR_ID') |
|
| 1698 | ||
| 1699 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1700 | cursor = cnx.cursor() |
|
| 1701 | ||
| 1702 | cursor.execute(" SELECT name " |
|
| 1703 | " FROM tbl_shopfloors " |
|
| 1704 | " WHERE id = %s ", (id_,)) |
|
| 1705 | if cursor.fetchone() is None: |
|
| 1706 | cursor.close() |
|
| 1707 | cnx.close() |
|
| 1708 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1709 | description='API.SHOPFLOOR_NOT_FOUND') |
|
| 1710 | ||
| 1711 | cursor.execute(" SELECT name " |
|
| 1712 | " FROM tbl_working_calendars " |
|
| 1713 | " WHERE id = %s ", (wcid,)) |
|
| 1714 | if cursor.fetchone() is None: |
|
| 1715 | cursor.close() |
|
| 1716 | cnx.close() |
|
| 1717 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1718 | description='API.WORKING_CALENDAR_NOT_FOUND') |
|
| 1719 | ||
| 1720 | cursor.execute(" SELECT id " |
|
| 1721 | " FROM tbl_shopfloors_working_calendars " |
|
| 1722 | " WHERE shopfloor_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
| 1723 | if cursor.fetchone() is None: |
|
| 1724 | cursor.close() |
|
| 1725 | cnx.close() |
|
| 1726 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1727 | description='API.SHOPFLOOR_WORKING_CALENDAR_RELATION_NOT_FOUND') |
|
| 1728 | ||
| 1729 | cursor.execute(" DELETE FROM tbl_shopfloors_working_calendars " |
|
| 1730 | " WHERE shopfloor_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
| 1731 | cnx.commit() |
|
| 1732 | ||
| 1733 | cursor.close() |
|
| 1734 | cnx.close() |
|
| 1735 | ||
| 1736 | resp.status = falcon.HTTP_204 |
|
| 1737 | ||
| 1738 | ||
| 1739 | class ShopfloorCommandCollection: |
|
| @@ 1502-1560 (lines=59) @@ | ||
| 1499 | resp.location = '/shopfloors/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
| 1500 | ||
| 1501 | ||
| 1502 | class ShopfloorVirtualMeterItem: |
|
| 1503 | def __init__(self): |
|
| 1504 | """Initializes ShopfloorVirtualMeterItem""" |
|
| 1505 | pass |
|
| 1506 | ||
| 1507 | @staticmethod |
|
| 1508 | def on_options(req, resp, id_, mid): |
|
| 1509 | resp.status = falcon.HTTP_200 |
|
| 1510 | ||
| 1511 | @staticmethod |
|
| 1512 | @user_logger |
|
| 1513 | def on_delete(req, resp, id_, mid): |
|
| 1514 | admin_control(req) |
|
| 1515 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1516 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1517 | description='API.INVALID_SHOPFLOOR_ID') |
|
| 1518 | ||
| 1519 | if not mid.isdigit() or int(mid) <= 0: |
|
| 1520 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1521 | description='API.INVALID_VIRTUAL_METER_ID') |
|
| 1522 | ||
| 1523 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1524 | cursor = cnx.cursor() |
|
| 1525 | ||
| 1526 | cursor.execute(" SELECT name " |
|
| 1527 | " FROM tbl_shopfloors " |
|
| 1528 | " WHERE id = %s ", (id_,)) |
|
| 1529 | if cursor.fetchone() is None: |
|
| 1530 | cursor.close() |
|
| 1531 | cnx.close() |
|
| 1532 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1533 | description='API.SHOPFLOOR_NOT_FOUND') |
|
| 1534 | ||
| 1535 | cursor.execute(" SELECT name " |
|
| 1536 | " FROM tbl_virtual_meters " |
|
| 1537 | " WHERE id = %s ", (mid,)) |
|
| 1538 | if cursor.fetchone() is None: |
|
| 1539 | cursor.close() |
|
| 1540 | cnx.close() |
|
| 1541 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1542 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
| 1543 | ||
| 1544 | cursor.execute(" SELECT id " |
|
| 1545 | " FROM tbl_shopfloors_virtual_meters " |
|
| 1546 | " WHERE shopfloor_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
| 1547 | if cursor.fetchone() is None: |
|
| 1548 | cursor.close() |
|
| 1549 | cnx.close() |
|
| 1550 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1551 | description='API.SHOPFLOOR_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
| 1552 | ||
| 1553 | cursor.execute(" DELETE FROM tbl_shopfloors_virtual_meters " |
|
| 1554 | " WHERE shopfloor_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
| 1555 | cnx.commit() |
|
| 1556 | ||
| 1557 | cursor.close() |
|
| 1558 | cnx.close() |
|
| 1559 | ||
| 1560 | resp.status = falcon.HTTP_204 |
|
| 1561 | ||
| 1562 | ||
| 1563 | class ShopfloorWorkingCalendarCollection: |
|
| @@ 1138-1196 (lines=59) @@ | ||
| 1135 | resp.location = '/shopfloors/' + str(id_) + '/points/' + str(point_id) |
|
| 1136 | ||
| 1137 | ||
| 1138 | class ShopfloorPointItem: |
|
| 1139 | def __init__(self): |
|
| 1140 | """Initializes ShopfloorPointItem""" |
|
| 1141 | pass |
|
| 1142 | ||
| 1143 | @staticmethod |
|
| 1144 | def on_options(req, resp, id_, pid): |
|
| 1145 | resp.status = falcon.HTTP_200 |
|
| 1146 | ||
| 1147 | @staticmethod |
|
| 1148 | @user_logger |
|
| 1149 | def on_delete(req, resp, id_, pid): |
|
| 1150 | admin_control(req) |
|
| 1151 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1152 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1153 | description='API.INVALID_SHOPFLOOR_ID') |
|
| 1154 | ||
| 1155 | if not pid.isdigit() or int(pid) <= 0: |
|
| 1156 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1157 | description='API.INVALID_POINT_ID') |
|
| 1158 | ||
| 1159 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1160 | cursor = cnx.cursor() |
|
| 1161 | ||
| 1162 | cursor.execute(" SELECT name " |
|
| 1163 | " FROM tbl_shopfloors " |
|
| 1164 | " WHERE id = %s ", (id_,)) |
|
| 1165 | if cursor.fetchone() is None: |
|
| 1166 | cursor.close() |
|
| 1167 | cnx.close() |
|
| 1168 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1169 | description='API.SHOPFLOOR_NOT_FOUND') |
|
| 1170 | ||
| 1171 | cursor.execute(" SELECT name " |
|
| 1172 | " FROM tbl_points " |
|
| 1173 | " WHERE id = %s ", (pid,)) |
|
| 1174 | if cursor.fetchone() is None: |
|
| 1175 | cursor.close() |
|
| 1176 | cnx.close() |
|
| 1177 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1178 | description='API.POINT_NOT_FOUND') |
|
| 1179 | ||
| 1180 | cursor.execute(" SELECT id " |
|
| 1181 | " FROM tbl_shopfloors_points " |
|
| 1182 | " WHERE shopfloor_id = %s AND point_id = %s ", (id_, pid)) |
|
| 1183 | if cursor.fetchone() is None: |
|
| 1184 | cursor.close() |
|
| 1185 | cnx.close() |
|
| 1186 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1187 | description='API.SHOPFLOOR_POINT_RELATION_NOT_FOUND') |
|
| 1188 | ||
| 1189 | cursor.execute(" DELETE FROM tbl_shopfloors_points " |
|
| 1190 | " WHERE shopfloor_id = %s AND point_id = %s ", (id_, pid)) |
|
| 1191 | cnx.commit() |
|
| 1192 | ||
| 1193 | cursor.close() |
|
| 1194 | cnx.close() |
|
| 1195 | ||
| 1196 | resp.status = falcon.HTTP_204 |
|
| 1197 | ||
| 1198 | ||
| 1199 | class ShopfloorSensorCollection: |
|
| @@ 950-1008 (lines=59) @@ | ||
| 947 | resp.location = '/shopfloors/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
| 948 | ||
| 949 | ||
| 950 | class ShopfloorOfflineMeterItem: |
|
| 951 | def __init__(self): |
|
| 952 | """Initializes ShopfloorOfflineMeterItem""" |
|
| 953 | pass |
|
| 954 | ||
| 955 | @staticmethod |
|
| 956 | def on_options(req, resp, id_, mid): |
|
| 957 | resp.status = falcon.HTTP_200 |
|
| 958 | ||
| 959 | @staticmethod |
|
| 960 | @user_logger |
|
| 961 | def on_delete(req, resp, id_, mid): |
|
| 962 | admin_control(req) |
|
| 963 | if not id_.isdigit() or int(id_) <= 0: |
|
| 964 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 965 | description='API.INVALID_SHOPFLOOR_ID') |
|
| 966 | ||
| 967 | if not mid.isdigit() or int(mid) <= 0: |
|
| 968 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 969 | description='API.INVALID_OFFLINE_METER_ID') |
|
| 970 | ||
| 971 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 972 | cursor = cnx.cursor() |
|
| 973 | ||
| 974 | cursor.execute(" SELECT name " |
|
| 975 | " FROM tbl_shopfloors " |
|
| 976 | " WHERE id = %s ", (id_,)) |
|
| 977 | if cursor.fetchone() is None: |
|
| 978 | cursor.close() |
|
| 979 | cnx.close() |
|
| 980 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 981 | description='API.SHOPFLOOR_NOT_FOUND') |
|
| 982 | ||
| 983 | cursor.execute(" SELECT name " |
|
| 984 | " FROM tbl_offline_meters " |
|
| 985 | " WHERE id = %s ", (mid,)) |
|
| 986 | if cursor.fetchone() is None: |
|
| 987 | cursor.close() |
|
| 988 | cnx.close() |
|
| 989 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 990 | description='API.OFFLINE_METER_NOT_FOUND') |
|
| 991 | ||
| 992 | cursor.execute(" SELECT id " |
|
| 993 | " FROM tbl_shopfloors_offline_meters " |
|
| 994 | " WHERE shopfloor_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
| 995 | if cursor.fetchone() is None: |
|
| 996 | cursor.close() |
|
| 997 | cnx.close() |
|
| 998 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 999 | description='API.SHOPFLOOR_OFFLINE_METER_RELATION_NOT_FOUND') |
|
| 1000 | ||
| 1001 | cursor.execute(" DELETE FROM tbl_shopfloors_offline_meters " |
|
| 1002 | " WHERE shopfloor_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
| 1003 | cnx.commit() |
|
| 1004 | ||
| 1005 | cursor.close() |
|
| 1006 | cnx.close() |
|
| 1007 | ||
| 1008 | resp.status = falcon.HTTP_204 |
|
| 1009 | ||
| 1010 | ||
| 1011 | class ShopfloorPointCollection: |
|
| @@ 573-631 (lines=59) @@ | ||
| 570 | resp.location = '/shopfloors/' + str(id_) + '/equipments/' + str(equipment_id) |
|
| 571 | ||
| 572 | ||
| 573 | class ShopfloorEquipmentItem: |
|
| 574 | def __init__(self): |
|
| 575 | """Initializes ShopfloorEquipmentItem""" |
|
| 576 | pass |
|
| 577 | ||
| 578 | @staticmethod |
|
| 579 | def on_options(req, resp, id_, eid): |
|
| 580 | resp.status = falcon.HTTP_200 |
|
| 581 | ||
| 582 | @staticmethod |
|
| 583 | @user_logger |
|
| 584 | def on_delete(req, resp, id_, eid): |
|
| 585 | admin_control(req) |
|
| 586 | if not id_.isdigit() or int(id_) <= 0: |
|
| 587 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 588 | description='API.INVALID_SHOPFLOOR_ID') |
|
| 589 | ||
| 590 | if not eid.isdigit() or int(eid) <= 0: |
|
| 591 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 592 | description='API.INVALID_EQUIPMENT_ID') |
|
| 593 | ||
| 594 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 595 | cursor = cnx.cursor() |
|
| 596 | ||
| 597 | cursor.execute(" SELECT name " |
|
| 598 | " FROM tbl_shopfloors " |
|
| 599 | " WHERE id = %s ", (id_,)) |
|
| 600 | if cursor.fetchone() is None: |
|
| 601 | cursor.close() |
|
| 602 | cnx.close() |
|
| 603 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 604 | description='API.SHOPFLOOR_NOT_FOUND') |
|
| 605 | ||
| 606 | cursor.execute(" SELECT name " |
|
| 607 | " FROM tbl_equipments " |
|
| 608 | " WHERE id = %s ", (eid,)) |
|
| 609 | if cursor.fetchone() is None: |
|
| 610 | cursor.close() |
|
| 611 | cnx.close() |
|
| 612 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 613 | description='API.EQUIPMENT_NOT_FOUND') |
|
| 614 | ||
| 615 | cursor.execute(" SELECT id " |
|
| 616 | " FROM tbl_shopfloors_equipments " |
|
| 617 | " WHERE shopfloor_id = %s AND equipment_id = %s ", (id_, eid)) |
|
| 618 | if cursor.fetchone() is None: |
|
| 619 | cursor.close() |
|
| 620 | cnx.close() |
|
| 621 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 622 | description='API.SHOPFLOOR_EQUIPMENT_RELATION_NOT_FOUND') |
|
| 623 | ||
| 624 | cursor.execute(" DELETE FROM tbl_shopfloors_equipments " |
|
| 625 | " WHERE shopfloor_id = %s AND equipment_id = %s ", (id_, eid)) |
|
| 626 | cnx.commit() |
|
| 627 | ||
| 628 | cursor.close() |
|
| 629 | cnx.close() |
|
| 630 | ||
| 631 | resp.status = falcon.HTTP_204 |
|
| 632 | ||
| 633 | ||
| 634 | class ShopfloorMeterCollection: |
|
| @@ 1854-1911 (lines=58) @@ | ||
| 1851 | resp.location = '/shopfloors/' + str(id_) + '/commands/' + str(command_id) |
|
| 1852 | ||
| 1853 | ||
| 1854 | class ShopfloorCommandItem: |
|
| 1855 | def __init__(self): |
|
| 1856 | """Initializes Class""" |
|
| 1857 | pass |
|
| 1858 | ||
| 1859 | @staticmethod |
|
| 1860 | def on_options(req, resp, id_, cid): |
|
| 1861 | resp.status = falcon.HTTP_200 |
|
| 1862 | ||
| 1863 | @staticmethod |
|
| 1864 | @user_logger |
|
| 1865 | def on_delete(req, resp, id_, cid): |
|
| 1866 | admin_control(req) |
|
| 1867 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1868 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1869 | description='API.INVALID_SHOPFLOOR_ID') |
|
| 1870 | ||
| 1871 | if not cid.isdigit() or int(cid) <= 0: |
|
| 1872 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1873 | description='API.INVALID_COMMAND_ID') |
|
| 1874 | ||
| 1875 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1876 | cursor = cnx.cursor() |
|
| 1877 | ||
| 1878 | cursor.execute(" SELECT name " |
|
| 1879 | " FROM tbl_shopfloors " |
|
| 1880 | " WHERE id = %s ", (id_,)) |
|
| 1881 | if cursor.fetchone() is None: |
|
| 1882 | cursor.close() |
|
| 1883 | cnx.close() |
|
| 1884 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1885 | description='API.SHOPFLOOR_NOT_FOUND') |
|
| 1886 | ||
| 1887 | cursor.execute(" SELECT name " |
|
| 1888 | " FROM tbl_commands " |
|
| 1889 | " WHERE id = %s ", (cid,)) |
|
| 1890 | if cursor.fetchone() is None: |
|
| 1891 | cursor.close() |
|
| 1892 | cnx.close() |
|
| 1893 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1894 | description='API.COMMAND_NOT_FOUND') |
|
| 1895 | ||
| 1896 | cursor.execute(" SELECT id " |
|
| 1897 | " FROM tbl_shopfloors_commands " |
|
| 1898 | " WHERE shopfloor_id = %s AND command_id = %s ", (id_, cid)) |
|
| 1899 | if cursor.fetchone() is None: |
|
| 1900 | cursor.close() |
|
| 1901 | cnx.close() |
|
| 1902 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1903 | description='API.SHOPFLOOR_COMMAND_RELATION_NOT_FOUND') |
|
| 1904 | ||
| 1905 | cursor.execute(" DELETE FROM tbl_shopfloors_commands WHERE shopfloor_id = %s AND command_id = %s ", (id_, cid)) |
|
| 1906 | cnx.commit() |
|
| 1907 | ||
| 1908 | cursor.close() |
|
| 1909 | cnx.close() |
|
| 1910 | ||
| 1911 | resp.status = falcon.HTTP_204 |
|
| 1912 | ||
| 1913 | ||
| 1914 | class ShopfloorExport: |
|
| @@ 1314-1371 (lines=58) @@ | ||
| 1311 | resp.location = '/shopfloors/' + str(id_) + '/sensors/' + str(sensor_id) |
|
| 1312 | ||
| 1313 | ||
| 1314 | class ShopfloorSensorItem: |
|
| 1315 | def __init__(self): |
|
| 1316 | """Initializes ShopfloorSensorItem""" |
|
| 1317 | pass |
|
| 1318 | ||
| 1319 | @staticmethod |
|
| 1320 | def on_options(req, resp, id_, sid): |
|
| 1321 | resp.status = falcon.HTTP_200 |
|
| 1322 | ||
| 1323 | @staticmethod |
|
| 1324 | @user_logger |
|
| 1325 | def on_delete(req, resp, id_, sid): |
|
| 1326 | admin_control(req) |
|
| 1327 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1328 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1329 | description='API.INVALID_SHOPFLOOR_ID') |
|
| 1330 | ||
| 1331 | if not sid.isdigit() or int(sid) <= 0: |
|
| 1332 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1333 | description='API.INVALID_SENSOR_ID') |
|
| 1334 | ||
| 1335 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1336 | cursor = cnx.cursor() |
|
| 1337 | ||
| 1338 | cursor.execute(" SELECT name " |
|
| 1339 | " FROM tbl_shopfloors " |
|
| 1340 | " WHERE id = %s ", (id_,)) |
|
| 1341 | if cursor.fetchone() is None: |
|
| 1342 | cursor.close() |
|
| 1343 | cnx.close() |
|
| 1344 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1345 | description='API.SHOPFLOOR_NOT_FOUND') |
|
| 1346 | ||
| 1347 | cursor.execute(" SELECT name " |
|
| 1348 | " FROM tbl_sensors " |
|
| 1349 | " WHERE id = %s ", (sid,)) |
|
| 1350 | if cursor.fetchone() is None: |
|
| 1351 | cursor.close() |
|
| 1352 | cnx.close() |
|
| 1353 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1354 | description='API.SENSOR_NOT_FOUND') |
|
| 1355 | ||
| 1356 | cursor.execute(" SELECT id " |
|
| 1357 | " FROM tbl_shopfloors_sensors " |
|
| 1358 | " WHERE shopfloor_id = %s AND sensor_id = %s ", (id_, sid)) |
|
| 1359 | if cursor.fetchone() is None: |
|
| 1360 | cursor.close() |
|
| 1361 | cnx.close() |
|
| 1362 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1363 | description='API.SHOPFLOOR_SENSOR_RELATION_NOT_FOUND') |
|
| 1364 | ||
| 1365 | cursor.execute(" DELETE FROM tbl_shopfloors_sensors WHERE shopfloor_id = %s AND sensor_id = %s ", (id_, sid)) |
|
| 1366 | cnx.commit() |
|
| 1367 | ||
| 1368 | cursor.close() |
|
| 1369 | cnx.close() |
|
| 1370 | ||
| 1371 | resp.status = falcon.HTTP_204 |
|
| 1372 | ||
| 1373 | ||
| 1374 | class ShopfloorVirtualMeterCollection: |
|
| @@ 762-819 (lines=58) @@ | ||
| 759 | resp.location = '/shopfloors/' + str(id_) + '/meters/' + str(meter_id) |
|
| 760 | ||
| 761 | ||
| 762 | class ShopfloorMeterItem: |
|
| 763 | def __init__(self): |
|
| 764 | """Initializes ShopfloorMeterItem""" |
|
| 765 | pass |
|
| 766 | ||
| 767 | @staticmethod |
|
| 768 | def on_options(req, resp, id_, mid): |
|
| 769 | resp.status = falcon.HTTP_200 |
|
| 770 | ||
| 771 | @staticmethod |
|
| 772 | @user_logger |
|
| 773 | def on_delete(req, resp, id_, mid): |
|
| 774 | admin_control(req) |
|
| 775 | if not id_.isdigit() or int(id_) <= 0: |
|
| 776 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 777 | description='API.INVALID_SHOPFLOOR_ID') |
|
| 778 | ||
| 779 | if not mid.isdigit() or int(mid) <= 0: |
|
| 780 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 781 | description='API.INVALID_METER_ID') |
|
| 782 | ||
| 783 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 784 | cursor = cnx.cursor() |
|
| 785 | ||
| 786 | cursor.execute(" SELECT name " |
|
| 787 | " FROM tbl_shopfloors " |
|
| 788 | " WHERE id = %s ", (id_,)) |
|
| 789 | if cursor.fetchone() is None: |
|
| 790 | cursor.close() |
|
| 791 | cnx.close() |
|
| 792 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 793 | description='API.SHOPFLOOR_NOT_FOUND') |
|
| 794 | ||
| 795 | cursor.execute(" SELECT name " |
|
| 796 | " FROM tbl_meters " |
|
| 797 | " WHERE id = %s ", (mid,)) |
|
| 798 | if cursor.fetchone() is None: |
|
| 799 | cursor.close() |
|
| 800 | cnx.close() |
|
| 801 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 802 | description='API.METER_NOT_FOUND') |
|
| 803 | ||
| 804 | cursor.execute(" SELECT id " |
|
| 805 | " FROM tbl_shopfloors_meters " |
|
| 806 | " WHERE shopfloor_id = %s AND meter_id = %s ", (id_, mid)) |
|
| 807 | if cursor.fetchone() is None: |
|
| 808 | cursor.close() |
|
| 809 | cnx.close() |
|
| 810 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 811 | description='API.SHOPFLOOR_METER_RELATION_NOT_FOUND') |
|
| 812 | ||
| 813 | cursor.execute(" DELETE FROM tbl_shopfloors_meters WHERE shopfloor_id = %s AND meter_id = %s ", (id_, mid)) |
|
| 814 | cnx.commit() |
|
| 815 | ||
| 816 | cursor.close() |
|
| 817 | cnx.close() |
|
| 818 | ||
| 819 | resp.status = falcon.HTTP_204 |
|
| 820 | ||
| 821 | ||
| 822 | class ShopfloorOfflineMeterCollection: |
|
| @@ 1621-1679 (lines=59) @@ | ||
| 1618 | resp.location = '/stores/' + str(id_) + '/workingcalendars/' + str(working_calendar_id) |
|
| 1619 | ||
| 1620 | ||
| 1621 | class StoreWorkingCalendarItem: |
|
| 1622 | def __init__(self): |
|
| 1623 | """Initializes StoreWorkingCalendarItem Class""" |
|
| 1624 | pass |
|
| 1625 | ||
| 1626 | @staticmethod |
|
| 1627 | def on_options(req, resp, id_, wcid): |
|
| 1628 | resp.status = falcon.HTTP_200 |
|
| 1629 | ||
| 1630 | @staticmethod |
|
| 1631 | @user_logger |
|
| 1632 | def on_delete(req, resp, id_, wcid): |
|
| 1633 | admin_control(req) |
|
| 1634 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1635 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1636 | description='API.INVALID_STORE_ID') |
|
| 1637 | ||
| 1638 | if not wcid.isdigit() or int(wcid) <= 0: |
|
| 1639 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1640 | description='API.INVALID_WORKING_CALENDAR_ID') |
|
| 1641 | ||
| 1642 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1643 | cursor = cnx.cursor() |
|
| 1644 | ||
| 1645 | cursor.execute(" SELECT name " |
|
| 1646 | " FROM tbl_stores " |
|
| 1647 | " WHERE id = %s ", (id_,)) |
|
| 1648 | if cursor.fetchone() is None: |
|
| 1649 | cursor.close() |
|
| 1650 | cnx.close() |
|
| 1651 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1652 | description='API.STORE_NOT_FOUND') |
|
| 1653 | ||
| 1654 | cursor.execute(" SELECT name " |
|
| 1655 | " FROM tbl_working_calendars " |
|
| 1656 | " WHERE id = %s ", (wcid,)) |
|
| 1657 | if cursor.fetchone() is None: |
|
| 1658 | cursor.close() |
|
| 1659 | cnx.close() |
|
| 1660 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1661 | description='API.WORKING_CALENDAR_NOT_FOUND') |
|
| 1662 | ||
| 1663 | cursor.execute(" SELECT id " |
|
| 1664 | " FROM tbl_stores_working_calendars " |
|
| 1665 | " WHERE store_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
| 1666 | if cursor.fetchone() is None: |
|
| 1667 | cursor.close() |
|
| 1668 | cnx.close() |
|
| 1669 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1670 | description='API.STORE_WORKING_CALENDAR_RELATION_NOT_FOUND') |
|
| 1671 | ||
| 1672 | cursor.execute(" DELETE FROM tbl_stores_working_calendars " |
|
| 1673 | " WHERE store_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
| 1674 | cnx.commit() |
|
| 1675 | ||
| 1676 | cursor.close() |
|
| 1677 | cnx.close() |
|
| 1678 | ||
| 1679 | resp.status = falcon.HTTP_204 |
|
| 1680 | ||
| 1681 | ||
| 1682 | class StoreCommandCollection: |
|
| @@ 1445-1503 (lines=59) @@ | ||
| 1442 | resp.location = '/stores/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
| 1443 | ||
| 1444 | ||
| 1445 | class StoreVirtualMeterItem: |
|
| 1446 | def __init__(self): |
|
| 1447 | """Initializes Class""" |
|
| 1448 | pass |
|
| 1449 | ||
| 1450 | @staticmethod |
|
| 1451 | def on_options(req, resp, id_, mid): |
|
| 1452 | resp.status = falcon.HTTP_200 |
|
| 1453 | ||
| 1454 | @staticmethod |
|
| 1455 | @user_logger |
|
| 1456 | def on_delete(req, resp, id_, mid): |
|
| 1457 | admin_control(req) |
|
| 1458 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1459 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1460 | description='API.INVALID_STORE_ID') |
|
| 1461 | ||
| 1462 | if not mid.isdigit() or int(mid) <= 0: |
|
| 1463 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1464 | description='API.INVALID_VIRTUAL_METER_ID') |
|
| 1465 | ||
| 1466 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1467 | cursor = cnx.cursor() |
|
| 1468 | ||
| 1469 | cursor.execute(" SELECT name " |
|
| 1470 | " FROM tbl_stores " |
|
| 1471 | " WHERE id = %s ", (id_,)) |
|
| 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.STORE_NOT_FOUND') |
|
| 1477 | ||
| 1478 | cursor.execute(" SELECT name " |
|
| 1479 | " FROM tbl_virtual_meters " |
|
| 1480 | " WHERE id = %s ", (mid,)) |
|
| 1481 | if cursor.fetchone() is None: |
|
| 1482 | cursor.close() |
|
| 1483 | cnx.close() |
|
| 1484 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1485 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
| 1486 | ||
| 1487 | cursor.execute(" SELECT id " |
|
| 1488 | " FROM tbl_stores_virtual_meters " |
|
| 1489 | " WHERE store_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
| 1490 | if cursor.fetchone() is None: |
|
| 1491 | cursor.close() |
|
| 1492 | cnx.close() |
|
| 1493 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1494 | description='API.STORE_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
| 1495 | ||
| 1496 | cursor.execute(" DELETE FROM tbl_stores_virtual_meters " |
|
| 1497 | " WHERE store_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
| 1498 | cnx.commit() |
|
| 1499 | ||
| 1500 | cursor.close() |
|
| 1501 | cnx.close() |
|
| 1502 | ||
| 1503 | resp.status = falcon.HTTP_204 |
|
| 1504 | ||
| 1505 | ||
| 1506 | class StoreWorkingCalendarCollection: |
|
| @@ 1081-1139 (lines=59) @@ | ||
| 1078 | resp.location = '/stores/' + str(id_) + '/points/' + str(point_id) |
|
| 1079 | ||
| 1080 | ||
| 1081 | class StorePointItem: |
|
| 1082 | def __init__(self): |
|
| 1083 | """Initializes Class""" |
|
| 1084 | pass |
|
| 1085 | ||
| 1086 | @staticmethod |
|
| 1087 | def on_options(req, resp, id_, pid): |
|
| 1088 | resp.status = falcon.HTTP_200 |
|
| 1089 | ||
| 1090 | @staticmethod |
|
| 1091 | @user_logger |
|
| 1092 | def on_delete(req, resp, id_, pid): |
|
| 1093 | admin_control(req) |
|
| 1094 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1095 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1096 | description='API.INVALID_STORE_ID') |
|
| 1097 | ||
| 1098 | if not pid.isdigit() or int(pid) <= 0: |
|
| 1099 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1100 | description='API.INVALID_POINT_ID') |
|
| 1101 | ||
| 1102 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1103 | cursor = cnx.cursor() |
|
| 1104 | ||
| 1105 | cursor.execute(" SELECT name " |
|
| 1106 | " FROM tbl_stores " |
|
| 1107 | " WHERE id = %s ", (id_,)) |
|
| 1108 | if cursor.fetchone() is None: |
|
| 1109 | cursor.close() |
|
| 1110 | cnx.close() |
|
| 1111 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1112 | description='API.STORE_NOT_FOUND') |
|
| 1113 | ||
| 1114 | cursor.execute(" SELECT name " |
|
| 1115 | " FROM tbl_points " |
|
| 1116 | " WHERE id = %s ", (pid,)) |
|
| 1117 | if cursor.fetchone() is None: |
|
| 1118 | cursor.close() |
|
| 1119 | cnx.close() |
|
| 1120 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1121 | description='API.POINT_NOT_FOUND') |
|
| 1122 | ||
| 1123 | cursor.execute(" SELECT id " |
|
| 1124 | " FROM tbl_stores_points " |
|
| 1125 | " WHERE store_id = %s AND point_id = %s ", (id_, pid)) |
|
| 1126 | if cursor.fetchone() is None: |
|
| 1127 | cursor.close() |
|
| 1128 | cnx.close() |
|
| 1129 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1130 | description='API.STORE_POINT_RELATION_NOT_FOUND') |
|
| 1131 | ||
| 1132 | cursor.execute(" DELETE FROM tbl_stores_points " |
|
| 1133 | " WHERE store_id = %s AND point_id = %s ", (id_, pid)) |
|
| 1134 | cnx.commit() |
|
| 1135 | ||
| 1136 | cursor.close() |
|
| 1137 | cnx.close() |
|
| 1138 | ||
| 1139 | resp.status = falcon.HTTP_204 |
|
| 1140 | ||
| 1141 | ||
| 1142 | class StoreSensorCollection: |
|
| @@ 893-951 (lines=59) @@ | ||
| 890 | resp.location = '/stores/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
| 891 | ||
| 892 | ||
| 893 | class StoreOfflineMeterItem: |
|
| 894 | def __init__(self): |
|
| 895 | """Initializes Class""" |
|
| 896 | pass |
|
| 897 | ||
| 898 | @staticmethod |
|
| 899 | def on_options(req, resp, id_, mid): |
|
| 900 | resp.status = falcon.HTTP_200 |
|
| 901 | ||
| 902 | @staticmethod |
|
| 903 | @user_logger |
|
| 904 | def on_delete(req, resp, id_, mid): |
|
| 905 | admin_control(req) |
|
| 906 | if not id_.isdigit() or int(id_) <= 0: |
|
| 907 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 908 | description='API.INVALID_STORE_ID') |
|
| 909 | ||
| 910 | if not mid.isdigit() or int(mid) <= 0: |
|
| 911 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 912 | description='API.INVALID_OFFLINE_METER_ID') |
|
| 913 | ||
| 914 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 915 | cursor = cnx.cursor() |
|
| 916 | ||
| 917 | cursor.execute(" SELECT name " |
|
| 918 | " FROM tbl_stores " |
|
| 919 | " WHERE id = %s ", (id_,)) |
|
| 920 | if cursor.fetchone() is None: |
|
| 921 | cursor.close() |
|
| 922 | cnx.close() |
|
| 923 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 924 | description='API.STORE_NOT_FOUND') |
|
| 925 | ||
| 926 | cursor.execute(" SELECT name " |
|
| 927 | " FROM tbl_offline_meters " |
|
| 928 | " WHERE id = %s ", (mid,)) |
|
| 929 | if cursor.fetchone() is None: |
|
| 930 | cursor.close() |
|
| 931 | cnx.close() |
|
| 932 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 933 | description='API.OFFLINE_METER_NOT_FOUND') |
|
| 934 | ||
| 935 | cursor.execute(" SELECT id " |
|
| 936 | " FROM tbl_stores_offline_meters " |
|
| 937 | " WHERE store_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
| 938 | if cursor.fetchone() is None: |
|
| 939 | cursor.close() |
|
| 940 | cnx.close() |
|
| 941 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 942 | description='API.STORE_OFFLINE_METER_RELATION_NOT_FOUND') |
|
| 943 | ||
| 944 | cursor.execute(" DELETE FROM tbl_stores_offline_meters " |
|
| 945 | " WHERE store_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
| 946 | cnx.commit() |
|
| 947 | ||
| 948 | cursor.close() |
|
| 949 | cnx.close() |
|
| 950 | ||
| 951 | resp.status = falcon.HTTP_204 |
|
| 952 | ||
| 953 | ||
| 954 | class StorePointCollection: |
|
| @@ 1797-1854 (lines=58) @@ | ||
| 1794 | resp.location = '/stores/' + str(id_) + '/commands/' + str(command_id) |
|
| 1795 | ||
| 1796 | ||
| 1797 | class StoreCommandItem: |
|
| 1798 | def __init__(self): |
|
| 1799 | """Initializes Class""" |
|
| 1800 | pass |
|
| 1801 | ||
| 1802 | @staticmethod |
|
| 1803 | def on_options(req, resp, id_, cid): |
|
| 1804 | resp.status = falcon.HTTP_200 |
|
| 1805 | ||
| 1806 | @staticmethod |
|
| 1807 | @user_logger |
|
| 1808 | def on_delete(req, resp, id_, cid): |
|
| 1809 | admin_control(req) |
|
| 1810 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1811 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1812 | description='API.INVALID_STORE_ID') |
|
| 1813 | ||
| 1814 | if not cid.isdigit() or int(cid) <= 0: |
|
| 1815 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1816 | description='API.INVALID_COMMAND_ID') |
|
| 1817 | ||
| 1818 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1819 | cursor = cnx.cursor() |
|
| 1820 | ||
| 1821 | cursor.execute(" SELECT name " |
|
| 1822 | " FROM tbl_stores " |
|
| 1823 | " WHERE id = %s ", (id_,)) |
|
| 1824 | if cursor.fetchone() is None: |
|
| 1825 | cursor.close() |
|
| 1826 | cnx.close() |
|
| 1827 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1828 | description='API.STORE_NOT_FOUND') |
|
| 1829 | ||
| 1830 | cursor.execute(" SELECT name " |
|
| 1831 | " FROM tbl_commands " |
|
| 1832 | " WHERE id = %s ", (cid,)) |
|
| 1833 | if cursor.fetchone() is None: |
|
| 1834 | cursor.close() |
|
| 1835 | cnx.close() |
|
| 1836 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1837 | description='API.COMMAND_NOT_FOUND') |
|
| 1838 | ||
| 1839 | cursor.execute(" SELECT id " |
|
| 1840 | " FROM tbl_stores_commands " |
|
| 1841 | " WHERE store_id = %s AND command_id = %s ", (id_, cid)) |
|
| 1842 | if cursor.fetchone() is None: |
|
| 1843 | cursor.close() |
|
| 1844 | cnx.close() |
|
| 1845 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1846 | description='API.STORE_COMMAND_RELATION_NOT_FOUND') |
|
| 1847 | ||
| 1848 | cursor.execute(" DELETE FROM tbl_stores_commands WHERE store_id = %s AND command_id = %s ", (id_, cid)) |
|
| 1849 | cnx.commit() |
|
| 1850 | ||
| 1851 | cursor.close() |
|
| 1852 | cnx.close() |
|
| 1853 | ||
| 1854 | resp.status = falcon.HTTP_204 |
|
| 1855 | ||
| 1856 | ||
| 1857 | class StoreExport: |
|
| @@ 1257-1314 (lines=58) @@ | ||
| 1254 | resp.location = '/stores/' + str(id_) + '/sensors/' + str(sensor_id) |
|
| 1255 | ||
| 1256 | ||
| 1257 | class StoreSensorItem: |
|
| 1258 | def __init__(self): |
|
| 1259 | """Initializes Class""" |
|
| 1260 | pass |
|
| 1261 | ||
| 1262 | @staticmethod |
|
| 1263 | def on_options(req, resp, id_, sid): |
|
| 1264 | resp.status = falcon.HTTP_200 |
|
| 1265 | ||
| 1266 | @staticmethod |
|
| 1267 | @user_logger |
|
| 1268 | def on_delete(req, resp, id_, sid): |
|
| 1269 | admin_control(req) |
|
| 1270 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1271 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1272 | description='API.INVALID_STORE_ID') |
|
| 1273 | ||
| 1274 | if not sid.isdigit() or int(sid) <= 0: |
|
| 1275 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1276 | description='API.INVALID_SENSOR_ID') |
|
| 1277 | ||
| 1278 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1279 | cursor = cnx.cursor() |
|
| 1280 | ||
| 1281 | cursor.execute(" SELECT name " |
|
| 1282 | " FROM tbl_stores " |
|
| 1283 | " WHERE id = %s ", (id_,)) |
|
| 1284 | if cursor.fetchone() is None: |
|
| 1285 | cursor.close() |
|
| 1286 | cnx.close() |
|
| 1287 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1288 | description='API.STORE_NOT_FOUND') |
|
| 1289 | ||
| 1290 | cursor.execute(" SELECT name " |
|
| 1291 | " FROM tbl_sensors " |
|
| 1292 | " WHERE id = %s ", (sid,)) |
|
| 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.SENSOR_NOT_FOUND') |
|
| 1298 | ||
| 1299 | cursor.execute(" SELECT id " |
|
| 1300 | " FROM tbl_stores_sensors " |
|
| 1301 | " WHERE store_id = %s AND sensor_id = %s ", (id_, sid)) |
|
| 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.STORE_SENSOR_RELATION_NOT_FOUND') |
|
| 1307 | ||
| 1308 | cursor.execute(" DELETE FROM tbl_stores_sensors WHERE store_id = %s AND sensor_id = %s ", (id_, sid)) |
|
| 1309 | cnx.commit() |
|
| 1310 | ||
| 1311 | cursor.close() |
|
| 1312 | cnx.close() |
|
| 1313 | ||
| 1314 | resp.status = falcon.HTTP_204 |
|
| 1315 | ||
| 1316 | ||
| 1317 | class StoreVirtualMeterCollection: |
|
| @@ 705-762 (lines=58) @@ | ||
| 702 | resp.location = '/stores/' + str(id_) + '/meters/' + str(meter_id) |
|
| 703 | ||
| 704 | ||
| 705 | class StoreMeterItem: |
|
| 706 | def __init__(self): |
|
| 707 | """Initializes Class""" |
|
| 708 | pass |
|
| 709 | ||
| 710 | @staticmethod |
|
| 711 | def on_options(req, resp, id_, mid): |
|
| 712 | resp.status = falcon.HTTP_200 |
|
| 713 | ||
| 714 | @staticmethod |
|
| 715 | @user_logger |
|
| 716 | def on_delete(req, resp, id_, mid): |
|
| 717 | admin_control(req) |
|
| 718 | if not id_.isdigit() or int(id_) <= 0: |
|
| 719 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 720 | description='API.INVALID_STORE_ID') |
|
| 721 | ||
| 722 | if not mid.isdigit() or int(mid) <= 0: |
|
| 723 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 724 | description='API.INVALID_METER_ID') |
|
| 725 | ||
| 726 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 727 | cursor = cnx.cursor() |
|
| 728 | ||
| 729 | cursor.execute(" SELECT name " |
|
| 730 | " FROM tbl_stores " |
|
| 731 | " WHERE id = %s ", (id_,)) |
|
| 732 | if cursor.fetchone() is None: |
|
| 733 | cursor.close() |
|
| 734 | cnx.close() |
|
| 735 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 736 | description='API.STORE_NOT_FOUND') |
|
| 737 | ||
| 738 | cursor.execute(" SELECT name " |
|
| 739 | " FROM tbl_meters " |
|
| 740 | " WHERE id = %s ", (mid,)) |
|
| 741 | if cursor.fetchone() is None: |
|
| 742 | cursor.close() |
|
| 743 | cnx.close() |
|
| 744 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 745 | description='API.METER_NOT_FOUND') |
|
| 746 | ||
| 747 | cursor.execute(" SELECT id " |
|
| 748 | " FROM tbl_stores_meters " |
|
| 749 | " WHERE store_id = %s AND meter_id = %s ", (id_, mid)) |
|
| 750 | if cursor.fetchone() is None: |
|
| 751 | cursor.close() |
|
| 752 | cnx.close() |
|
| 753 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 754 | description='API.STORE_METER_RELATION_NOT_FOUND') |
|
| 755 | ||
| 756 | cursor.execute(" DELETE FROM tbl_stores_meters WHERE store_id = %s AND meter_id = %s ", (id_, mid)) |
|
| 757 | cnx.commit() |
|
| 758 | ||
| 759 | cursor.close() |
|
| 760 | cnx.close() |
|
| 761 | ||
| 762 | resp.status = falcon.HTTP_204 |
|
| 763 | ||
| 764 | ||
| 765 | class StoreOfflineMeterCollection: |
|
| @@ 1603-1661 (lines=59) @@ | ||
| 1600 | resp.location = '/combinedequipments/' + str(id_) + '/commands/' + str(command_id) |
|
| 1601 | ||
| 1602 | ||
| 1603 | class EnergyStorageContainerCommandItem: |
|
| 1604 | def __init__(self): |
|
| 1605 | """Initializes Class""" |
|
| 1606 | pass |
|
| 1607 | ||
| 1608 | @staticmethod |
|
| 1609 | def on_options(req, resp, id_, cid): |
|
| 1610 | resp.status = falcon.HTTP_200 |
|
| 1611 | ||
| 1612 | @staticmethod |
|
| 1613 | @user_logger |
|
| 1614 | def on_delete(req, resp, id_, cid): |
|
| 1615 | admin_control(req) |
|
| 1616 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1617 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1618 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 1619 | ||
| 1620 | if not cid.isdigit() or int(cid) <= 0: |
|
| 1621 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1622 | description='API.INVALID_COMMAND_ID') |
|
| 1623 | ||
| 1624 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1625 | cursor = cnx.cursor() |
|
| 1626 | ||
| 1627 | cursor.execute(" SELECT name " |
|
| 1628 | " FROM tbl_energy_storage_containers " |
|
| 1629 | " WHERE id = %s ", (id_,)) |
|
| 1630 | if cursor.fetchone() is None: |
|
| 1631 | cursor.close() |
|
| 1632 | cnx.close() |
|
| 1633 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1634 | description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND') |
|
| 1635 | ||
| 1636 | cursor.execute(" SELECT name " |
|
| 1637 | " FROM tbl_commands " |
|
| 1638 | " WHERE id = %s ", (cid,)) |
|
| 1639 | if cursor.fetchone() is None: |
|
| 1640 | cursor.close() |
|
| 1641 | cnx.close() |
|
| 1642 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1643 | description='API.COMMAND_NOT_FOUND') |
|
| 1644 | ||
| 1645 | cursor.execute(" SELECT id " |
|
| 1646 | " FROM tbl_energy_storage_containers_commands " |
|
| 1647 | " WHERE energy_storage_container_id = %s AND command_id = %s ", (id_, cid)) |
|
| 1648 | if cursor.fetchone() is None: |
|
| 1649 | cursor.close() |
|
| 1650 | cnx.close() |
|
| 1651 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1652 | description='API.ENERGY_STORAGE_CONTAINER_COMMAND_RELATION_NOT_FOUND') |
|
| 1653 | ||
| 1654 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_commands " |
|
| 1655 | " WHERE energy_storage_container_id = %s AND command_id = %s ", (id_, cid)) |
|
| 1656 | cnx.commit() |
|
| 1657 | ||
| 1658 | cursor.close() |
|
| 1659 | cnx.close() |
|
| 1660 | ||
| 1661 | resp.status = falcon.HTTP_204 |
|
| 1662 | ||
| 1663 | ||
| 1664 | class EnergyStorageContainerDCDCCollection: |
|
| @@ 1081-1139 (lines=59) @@ | ||
| 1078 | resp.location = '/meters/' + str(id_) + '/points/' + str(new_values['data']['point_id']) |
|
| 1079 | ||
| 1080 | ||
| 1081 | class MeterPointItem: |
|
| 1082 | def __init__(self): |
|
| 1083 | """Initializes MeterPointItem""" |
|
| 1084 | pass |
|
| 1085 | ||
| 1086 | @staticmethod |
|
| 1087 | def on_options(req, resp, id_, pid): |
|
| 1088 | resp.status = falcon.HTTP_200 |
|
| 1089 | ||
| 1090 | @staticmethod |
|
| 1091 | @user_logger |
|
| 1092 | def on_delete(req, resp, id_, pid): |
|
| 1093 | """Handles DELETE requests""" |
|
| 1094 | admin_control(req) |
|
| 1095 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1096 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1097 | description='API.INVALID_METER_ID') |
|
| 1098 | ||
| 1099 | if not pid.isdigit() or int(pid) <= 0: |
|
| 1100 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1101 | description='API.INVALID_POINT_ID') |
|
| 1102 | ||
| 1103 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1104 | cursor = cnx.cursor() |
|
| 1105 | ||
| 1106 | cursor.execute(" SELECT name " |
|
| 1107 | " FROM tbl_meters " |
|
| 1108 | " WHERE id = %s ", (id_,)) |
|
| 1109 | if cursor.fetchone() is None: |
|
| 1110 | cursor.close() |
|
| 1111 | cnx.close() |
|
| 1112 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1113 | description='API.METER_NOT_FOUND') |
|
| 1114 | ||
| 1115 | cursor.execute(" SELECT name " |
|
| 1116 | " FROM tbl_points " |
|
| 1117 | " WHERE id = %s ", (pid,)) |
|
| 1118 | if cursor.fetchone() is None: |
|
| 1119 | cursor.close() |
|
| 1120 | cnx.close() |
|
| 1121 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1122 | description='API.POINT_NOT_FOUND') |
|
| 1123 | ||
| 1124 | cursor.execute(" SELECT id " |
|
| 1125 | " FROM tbl_meters_points " |
|
| 1126 | " WHERE meter_id = %s AND point_id = %s ", (id_, pid)) |
|
| 1127 | if cursor.fetchone() is None: |
|
| 1128 | cursor.close() |
|
| 1129 | cnx.close() |
|
| 1130 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1131 | description='API.METER_POINT_RELATION_NOT_FOUND') |
|
| 1132 | ||
| 1133 | cursor.execute(" DELETE FROM tbl_meters_points WHERE meter_id = %s AND point_id = %s ", (id_, pid)) |
|
| 1134 | cnx.commit() |
|
| 1135 | ||
| 1136 | cursor.close() |
|
| 1137 | cnx.close() |
|
| 1138 | ||
| 1139 | resp.status = falcon.HTTP_204 |
|
| 1140 | ||
| 1141 | ||
| 1142 | class MeterCommandCollection: |
|
| @@ 1257-1314 (lines=58) @@ | ||
| 1254 | resp.location = '/meters/' + str(id_) + '/commands/' + str(command_id) |
|
| 1255 | ||
| 1256 | ||
| 1257 | class MeterCommandItem: |
|
| 1258 | def __init__(self): |
|
| 1259 | """Initializes Class""" |
|
| 1260 | pass |
|
| 1261 | ||
| 1262 | @staticmethod |
|
| 1263 | def on_options(req, resp, id_, cid): |
|
| 1264 | resp.status = falcon.HTTP_200 |
|
| 1265 | ||
| 1266 | @staticmethod |
|
| 1267 | @user_logger |
|
| 1268 | def on_delete(req, resp, id_, cid): |
|
| 1269 | admin_control(req) |
|
| 1270 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1271 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1272 | description='API.INVALID_METER_ID') |
|
| 1273 | ||
| 1274 | if not cid.isdigit() or int(cid) <= 0: |
|
| 1275 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1276 | description='API.INVALID_COMMAND_ID') |
|
| 1277 | ||
| 1278 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1279 | cursor = cnx.cursor() |
|
| 1280 | ||
| 1281 | cursor.execute(" SELECT name " |
|
| 1282 | " FROM tbl_meters " |
|
| 1283 | " WHERE id = %s ", (id_,)) |
|
| 1284 | if cursor.fetchone() is None: |
|
| 1285 | cursor.close() |
|
| 1286 | cnx.close() |
|
| 1287 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1288 | description='API.METER_NOT_FOUND') |
|
| 1289 | ||
| 1290 | cursor.execute(" SELECT name " |
|
| 1291 | " FROM tbl_commands " |
|
| 1292 | " WHERE id = %s ", (cid,)) |
|
| 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.COMMAND_NOT_FOUND') |
|
| 1298 | ||
| 1299 | cursor.execute(" SELECT id " |
|
| 1300 | " FROM tbl_meters_commands " |
|
| 1301 | " WHERE meter_id = %s AND command_id = %s ", (id_, cid)) |
|
| 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.METER_COMMAND_RELATION_NOT_FOUND') |
|
| 1307 | ||
| 1308 | cursor.execute(" DELETE FROM tbl_meters_commands WHERE meter_id = %s AND command_id = %s ", (id_, cid)) |
|
| 1309 | cnx.commit() |
|
| 1310 | ||
| 1311 | cursor.close() |
|
| 1312 | cnx.close() |
|
| 1313 | ||
| 1314 | resp.status = falcon.HTTP_204 |
|
| 1315 | ||
| 1316 | ||
| 1317 | class MeterExport: |
|
| @@ 550-608 (lines=59) @@ | ||
| 547 | resp.location = '/virtualpowerplants/' + str(id_) + '/microgrids/' + str(microgrid_id) |
|
| 548 | ||
| 549 | ||
| 550 | class VirtualPowerPlantMicrogridItem: |
|
| 551 | def __init__(self): |
|
| 552 | """Initializes Class""" |
|
| 553 | pass |
|
| 554 | ||
| 555 | @staticmethod |
|
| 556 | def on_options(req, resp, id_, sid): |
|
| 557 | resp.status = falcon.HTTP_200 |
|
| 558 | ||
| 559 | @staticmethod |
|
| 560 | @user_logger |
|
| 561 | def on_delete(req, resp, id_, mid): |
|
| 562 | admin_control(req) |
|
| 563 | if not id_.isdigit() or int(id_) <= 0: |
|
| 564 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 565 | description='API.INVALID_VIRTUAL_POWER_PLANT_ID') |
|
| 566 | ||
| 567 | if not mid.isdigit() or int(mid) <= 0: |
|
| 568 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 569 | description='API.INVALID_MICROGRID_ID') |
|
| 570 | ||
| 571 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 572 | cursor = cnx.cursor() |
|
| 573 | ||
| 574 | cursor.execute(" SELECT name " |
|
| 575 | " FROM tbl_virtual_power_plants " |
|
| 576 | " WHERE id = %s ", (id_,)) |
|
| 577 | if cursor.fetchone() is None: |
|
| 578 | cursor.close() |
|
| 579 | cnx.close() |
|
| 580 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 581 | description='API.VIRTUAL_POWER_PLANT_NOT_FOUND') |
|
| 582 | ||
| 583 | cursor.execute(" SELECT name " |
|
| 584 | " FROM tbl_microgrids " |
|
| 585 | " WHERE id = %s ", (mid,)) |
|
| 586 | if cursor.fetchone() is None: |
|
| 587 | cursor.close() |
|
| 588 | cnx.close() |
|
| 589 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 590 | description='API.MICROGRID_NOT_FOUND') |
|
| 591 | ||
| 592 | cursor.execute(" SELECT id " |
|
| 593 | " FROM tbl_virtual_power_plants_microgrids " |
|
| 594 | " WHERE virtual_power_plant_id = %s AND microgrid_id = %s ", (id_, mid)) |
|
| 595 | if cursor.fetchone() is None: |
|
| 596 | cursor.close() |
|
| 597 | cnx.close() |
|
| 598 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 599 | description='API.VIRTUAL_POWER_PLANT_MICROGRID_RELATION_NOT_FOUND') |
|
| 600 | ||
| 601 | cursor.execute(" DELETE FROM tbl_virtual_power_plants_microgrids " |
|
| 602 | " WHERE virtual_power_plant_id = %s AND microgrid_id = %s ", (id_, mid)) |
|
| 603 | cnx.commit() |
|
| 604 | ||
| 605 | cursor.close() |
|
| 606 | cnx.close() |
|
| 607 | ||
| 608 | resp.status = falcon.HTTP_204 |
|
| 609 | ||
| 610 | ||
| 611 | class VirtualPowerPlantExport: |
|
| @@ 527-585 (lines=59) @@ | ||
| 524 | resp.location = '/distributioncircuits/' + str(id_) + '/points/' + str(new_values['data']['point_id']) |
|
| 525 | ||
| 526 | ||
| 527 | class DistributionCircuitPointItem: |
|
| 528 | def __init__(self): |
|
| 529 | """Initializes DistributionCircuitPointItem""" |
|
| 530 | pass |
|
| 531 | ||
| 532 | @staticmethod |
|
| 533 | def on_options(req, resp, id_, pid): |
|
| 534 | resp.status = falcon.HTTP_200 |
|
| 535 | ||
| 536 | @staticmethod |
|
| 537 | @user_logger |
|
| 538 | def on_delete(req, resp, id_, pid): |
|
| 539 | admin_control(req) |
|
| 540 | if not id_.isdigit() or int(id_) <= 0: |
|
| 541 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 542 | description='API.INVALID_DISTRIBUTION_CIRCUIT_ID') |
|
| 543 | ||
| 544 | if not pid.isdigit() or int(pid) <= 0: |
|
| 545 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 546 | description='API.INVALID_POINT_ID') |
|
| 547 | ||
| 548 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 549 | cursor = cnx.cursor() |
|
| 550 | ||
| 551 | cursor.execute(" SELECT name " |
|
| 552 | " FROM tbl_distribution_circuits " |
|
| 553 | " WHERE id = %s ", (id_,)) |
|
| 554 | if cursor.fetchone() is None: |
|
| 555 | cursor.close() |
|
| 556 | cnx.close() |
|
| 557 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 558 | description='API.DISTRIBUTION_CIRCUIT_NOT_FOUND') |
|
| 559 | ||
| 560 | cursor.execute(" SELECT name " |
|
| 561 | " FROM tbl_points " |
|
| 562 | " WHERE id = %s ", (pid,)) |
|
| 563 | if cursor.fetchone() is None: |
|
| 564 | cursor.close() |
|
| 565 | cnx.close() |
|
| 566 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 567 | description='API.POINT_NOT_FOUND') |
|
| 568 | ||
| 569 | cursor.execute(" SELECT id " |
|
| 570 | " FROM tbl_distribution_circuits_points " |
|
| 571 | " WHERE distribution_circuit_id = %s AND point_id = %s ", (id_, pid)) |
|
| 572 | if cursor.fetchone() is None: |
|
| 573 | cursor.close() |
|
| 574 | cnx.close() |
|
| 575 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 576 | description='API.DISTRIBUTION_CIRCUIT_POINT_RELATION_NOT_FOUND') |
|
| 577 | ||
| 578 | cursor.execute(" DELETE FROM tbl_distribution_circuits_points " |
|
| 579 | " WHERE distribution_circuit_id = %s AND point_id = %s ", (id_, pid)) |
|
| 580 | cnx.commit() |
|
| 581 | ||
| 582 | cursor.close() |
|
| 583 | cnx.close() |
|
| 584 | ||
| 585 | resp.status = falcon.HTTP_204 |
|
| 586 | ||
| 587 | ||
| @@ 417-474 (lines=58) @@ | ||
| 414 | resp.location = '/sensors/' + str(id_) + '/points/' + str(new_values['data']['point_id']) |
|
| 415 | ||
| 416 | ||
| 417 | class SensorPointItem: |
|
| 418 | def __init__(self): |
|
| 419 | """"Initializes SensorPointItem""" |
|
| 420 | pass |
|
| 421 | ||
| 422 | @staticmethod |
|
| 423 | def on_options(req, resp, id_, pid): |
|
| 424 | resp.status = falcon.HTTP_200 |
|
| 425 | ||
| 426 | @staticmethod |
|
| 427 | @user_logger |
|
| 428 | def on_delete(req, resp, id_, pid): |
|
| 429 | admin_control(req) |
|
| 430 | if not id_.isdigit() or int(id_) <= 0: |
|
| 431 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 432 | description='API.INVALID_SENSOR_ID') |
|
| 433 | ||
| 434 | if not pid.isdigit() or int(pid) <= 0: |
|
| 435 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 436 | description='API.INVALID_POINT_ID') |
|
| 437 | ||
| 438 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 439 | cursor = cnx.cursor() |
|
| 440 | ||
| 441 | cursor.execute(" SELECT name " |
|
| 442 | " FROM tbl_sensors " |
|
| 443 | " WHERE id = %s ", (id_,)) |
|
| 444 | if cursor.fetchone() is None: |
|
| 445 | cursor.close() |
|
| 446 | cnx.close() |
|
| 447 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 448 | description='API.SENSOR_NOT_FOUND') |
|
| 449 | ||
| 450 | cursor.execute(" SELECT name " |
|
| 451 | " FROM tbl_points " |
|
| 452 | " WHERE id = %s ", (pid,)) |
|
| 453 | if cursor.fetchone() is None: |
|
| 454 | cursor.close() |
|
| 455 | cnx.close() |
|
| 456 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 457 | description='API.POINT_NOT_FOUND') |
|
| 458 | ||
| 459 | cursor.execute(" SELECT id " |
|
| 460 | " FROM tbl_sensors_points " |
|
| 461 | " WHERE sensor_id = %s AND point_id = %s ", (id_, pid)) |
|
| 462 | if cursor.fetchone() is None: |
|
| 463 | cursor.close() |
|
| 464 | cnx.close() |
|
| 465 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 466 | description='API.SENSOR_POINT_RELATION_NOT_FOUND') |
|
| 467 | ||
| 468 | cursor.execute(" DELETE FROM tbl_sensors_points WHERE sensor_id = %s AND point_id = %s ", (id_, pid)) |
|
| 469 | cnx.commit() |
|
| 470 | ||
| 471 | cursor.close() |
|
| 472 | cnx.close() |
|
| 473 | ||
| 474 | resp.status = falcon.HTTP_204 |
|
| 475 | ||
| 476 | ||
| 477 | class SensorExport: |
|