@@ 4969-5031 (lines=63) @@ | ||
4966 | resp.location = '/photovoltaicpowerstations/' + str(id_) + '/users/' + str(user_id) |
|
4967 | ||
4968 | ||
4969 | class PhotovoltaicPowerStationUserItem: |
|
4970 | def __init__(self): |
|
4971 | """Initializes Class""" |
|
4972 | pass |
|
4973 | ||
4974 | @staticmethod |
|
4975 | def on_options(req, resp, id_, uid): |
|
4976 | _ = req |
|
4977 | resp.status = falcon.HTTP_200 |
|
4978 | _ = id_ |
|
4979 | ||
4980 | @staticmethod |
|
4981 | @user_logger |
|
4982 | def on_delete(req, resp, id_, uid): |
|
4983 | # todo Verify if the user is bound when deleting it |
|
4984 | admin_control(req) |
|
4985 | if not id_.isdigit() or int(id_) <= 0: |
|
4986 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
4987 | description='API.INVALID_PHOTOVOLTAIC_POWER_STATION_ID') |
|
4988 | ||
4989 | if not uid.isdigit() or int(uid) <= 0: |
|
4990 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
4991 | description='API.INVALID_USER_ID') |
|
4992 | ||
4993 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
4994 | cursor = cnx.cursor() |
|
4995 | cursor.execute(" SELECT name " |
|
4996 | " FROM tbl_photovoltaic_power_stations " |
|
4997 | " WHERE id = %s ", (id_,)) |
|
4998 | if cursor.fetchone() is None: |
|
4999 | cursor.close() |
|
5000 | cnx.close() |
|
5001 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5002 | description='API.PHOTOVOLTAIC_POWER_STATION_NOT_FOUND') |
|
5003 | ||
5004 | cnx_user = mysql.connector.connect(**config.myems_user_db) |
|
5005 | cursor_user = cnx_user.cursor() |
|
5006 | cursor_user.execute(" SELECT name FROM tbl_users WHERE id = %s ", (uid,)) |
|
5007 | if cursor_user.fetchone() is None: |
|
5008 | cursor_user.close() |
|
5009 | cnx_user.close() |
|
5010 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5011 | description='API.USER_NOT_FOUND') |
|
5012 | ||
5013 | cursor.execute(" SELECT id " |
|
5014 | " FROM tbl_photovoltaic_power_stations_users " |
|
5015 | " WHERE photovoltaic_power_station_id = %s AND user_id = %s ", (id_, uid)) |
|
5016 | if cursor.fetchone() is None: |
|
5017 | cursor.close() |
|
5018 | cnx.close() |
|
5019 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5020 | description='API.PHOTOVOLTAIC_POWER_STATION_USER_RELATION_NOT_FOUND') |
|
5021 | ||
5022 | cursor.execute(" DELETE FROM tbl_photovoltaic_power_stations_users " |
|
5023 | " WHERE photovoltaic_power_station_id = %s AND user_id = %s ", (id_, uid)) |
|
5024 | cnx.commit() |
|
5025 | ||
5026 | cursor.close() |
|
5027 | cnx.close() |
|
5028 | cursor_user.close() |
|
5029 | cnx_user.close() |
|
5030 | ||
5031 | resp.status = falcon.HTTP_204 |
|
5032 | ||
5033 | ||
5034 | class PhotovoltaicPowerStationDataSourceCollection: |
|
@@ 5154-5215 (lines=62) @@ | ||
5151 | resp.location = '/photovoltaicpowerstations/' + str(id_) + '/datasources/' + str(data_source_id) |
|
5152 | ||
5153 | ||
5154 | class PhotovoltaicPowerStationDataSourceItem: |
|
5155 | def __init__(self): |
|
5156 | """Initializes Class""" |
|
5157 | pass |
|
5158 | ||
5159 | @staticmethod |
|
5160 | def on_options(req, resp, id_, dsid): |
|
5161 | _ = req |
|
5162 | resp.status = falcon.HTTP_200 |
|
5163 | _ = id_ |
|
5164 | _ = dsid |
|
5165 | ||
5166 | @staticmethod |
|
5167 | @user_logger |
|
5168 | def on_delete(req, resp, id_, dsid): |
|
5169 | admin_control(req) |
|
5170 | if not id_.isdigit() or int(id_) <= 0: |
|
5171 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
5172 | description='API.INVALID_PHOTOVOLTAIC_POWER_STATION_ID') |
|
5173 | ||
5174 | if not dsid.isdigit() or int(dsid) <= 0: |
|
5175 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
5176 | description='API.INVALID_DATA_SOURCE_ID') |
|
5177 | ||
5178 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
5179 | cursor = cnx.cursor() |
|
5180 | ||
5181 | cursor.execute(" SELECT name " |
|
5182 | " FROM tbl_photovoltaic_power_stations " |
|
5183 | " WHERE id = %s ", (id_,)) |
|
5184 | if cursor.fetchone() is None: |
|
5185 | cursor.close() |
|
5186 | cnx.close() |
|
5187 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5188 | description='API.PHOTOVOLTAIC_POWER_STATION_NOT_FOUND') |
|
5189 | ||
5190 | cursor.execute(" SELECT name " |
|
5191 | " FROM tbl_data_sources " |
|
5192 | " WHERE id = %s ", (dsid,)) |
|
5193 | if cursor.fetchone() is None: |
|
5194 | cursor.close() |
|
5195 | cnx.close() |
|
5196 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5197 | description='API.DATA_SOURCE_NOT_FOUND') |
|
5198 | ||
5199 | cursor.execute(" SELECT id " |
|
5200 | " FROM tbl_photovoltaic_power_stations_data_sources " |
|
5201 | " WHERE photovoltaic_power_station_id = %s AND data_source_id = %s ", (id_, dsid)) |
|
5202 | if cursor.fetchone() is None: |
|
5203 | cursor.close() |
|
5204 | cnx.close() |
|
5205 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5206 | description='API.PHOTOVOLTAIC_POWER_STATION_DATA_SOURCE_RELATION_NOT_FOUND') |
|
5207 | ||
5208 | cursor.execute(" DELETE FROM tbl_photovoltaic_power_stations_data_sources " |
|
5209 | " WHERE photovoltaic_power_station_id = %s AND data_source_id = %s ", (id_, dsid)) |
|
5210 | cnx.commit() |
|
5211 | ||
5212 | cursor.close() |
|
5213 | cnx.close() |
|
5214 | ||
5215 | resp.status = falcon.HTTP_204 |
|
5216 | ||
5217 | class PhotovoltaicPowerStationInvertorPointCollection: |
|
5218 | def __init__(self): |
@@ 1083-1145 (lines=63) @@ | ||
1080 | resp.location = '/energystoragepowerstations/' + str(id_) + '/users/' + str(user_id) |
|
1081 | ||
1082 | ||
1083 | class EnergyStoragePowerStationUserItem: |
|
1084 | def __init__(self): |
|
1085 | """Initializes Class""" |
|
1086 | pass |
|
1087 | ||
1088 | @staticmethod |
|
1089 | def on_options(req, resp, id_, uid): |
|
1090 | _ = req |
|
1091 | resp.status = falcon.HTTP_200 |
|
1092 | _ = id_ |
|
1093 | ||
1094 | @staticmethod |
|
1095 | @user_logger |
|
1096 | def on_delete(req, resp, id_, uid): |
|
1097 | # todo Verify if the user is bound when deleting it |
|
1098 | admin_control(req) |
|
1099 | if not id_.isdigit() or int(id_) <= 0: |
|
1100 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1101 | description='API.INVALID_ENERGY_STORAGE_POWER_STATION_ID') |
|
1102 | ||
1103 | if not uid.isdigit() or int(uid) <= 0: |
|
1104 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1105 | description='API.INVALID_USER_ID') |
|
1106 | ||
1107 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1108 | cursor = cnx.cursor() |
|
1109 | cursor.execute(" SELECT name " |
|
1110 | " FROM tbl_energy_storage_power_stations " |
|
1111 | " WHERE id = %s ", (id_,)) |
|
1112 | if cursor.fetchone() is None: |
|
1113 | cursor.close() |
|
1114 | cnx.close() |
|
1115 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1116 | description='API.ENERGY_STORAGE_POWER_STATION_NOT_FOUND') |
|
1117 | ||
1118 | cnx_user = mysql.connector.connect(**config.myems_user_db) |
|
1119 | cursor_user = cnx_user.cursor() |
|
1120 | cursor_user.execute(" SELECT name FROM tbl_users WHERE id = %s ", (uid,)) |
|
1121 | if cursor_user.fetchone() is None: |
|
1122 | cursor_user.close() |
|
1123 | cnx_user.close() |
|
1124 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1125 | description='API.USER_NOT_FOUND') |
|
1126 | ||
1127 | cursor.execute(" SELECT id " |
|
1128 | " FROM tbl_energy_storage_power_stations_users " |
|
1129 | " WHERE energy_storage_power_station_id = %s AND user_id = %s ", (id_, uid)) |
|
1130 | if cursor.fetchone() is None: |
|
1131 | cursor.close() |
|
1132 | cnx.close() |
|
1133 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1134 | description='API.ENERGY_STORAGE_POWER_STATION_USER_RELATION_NOT_FOUND') |
|
1135 | ||
1136 | cursor.execute(" DELETE FROM tbl_energy_storage_power_stations_users " |
|
1137 | " WHERE energy_storage_power_station_id = %s AND user_id = %s ", (id_, uid)) |
|
1138 | cnx.commit() |
|
1139 | ||
1140 | cursor.close() |
|
1141 | cnx.close() |
|
1142 | cursor_user.close() |
|
1143 | cnx_user.close() |
|
1144 | ||
1145 | resp.status = falcon.HTTP_204 |
|
1146 | ||
1147 | ||
1148 | class EnergyStoragePowerStationExport: |
|
@@ 861-921 (lines=61) @@ | ||
858 | resp.location = '/energystoragepowerstationss/' + str(id_) + '/containers/' + str(energy_storage_container_id) |
|
859 | ||
860 | ||
861 | class EnergyStoragePowerStationContainerItem: |
|
862 | def __init__(self): |
|
863 | """Initializes Class""" |
|
864 | pass |
|
865 | ||
866 | @staticmethod |
|
867 | def on_options(req, resp, id_, sid): |
|
868 | _ = req |
|
869 | resp.status = falcon.HTTP_200 |
|
870 | _ = id_ |
|
871 | ||
872 | @staticmethod |
|
873 | @user_logger |
|
874 | def on_delete(req, resp, id_, sid): |
|
875 | admin_control(req) |
|
876 | if not id_.isdigit() or int(id_) <= 0: |
|
877 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
878 | description='API.INVALID_ENERGY_STORAGE_POWER_STATION_ID') |
|
879 | ||
880 | if not sid.isdigit() or int(sid) <= 0: |
|
881 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
882 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
883 | ||
884 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
885 | cursor = cnx.cursor() |
|
886 | ||
887 | cursor.execute(" SELECT name " |
|
888 | " FROM tbl_energy_storage_power_stations " |
|
889 | " WHERE id = %s ", (id_,)) |
|
890 | if cursor.fetchone() is None: |
|
891 | cursor.close() |
|
892 | cnx.close() |
|
893 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
894 | description='API.ENERGY_STORAGE_POWER_STATION_NOT_FOUND') |
|
895 | ||
896 | cursor.execute(" SELECT name " |
|
897 | " FROM tbl_energy_storage_containers " |
|
898 | " WHERE id = %s ", (sid,)) |
|
899 | if cursor.fetchone() is None: |
|
900 | cursor.close() |
|
901 | cnx.close() |
|
902 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
903 | description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND') |
|
904 | ||
905 | cursor.execute(" SELECT id " |
|
906 | " FROM tbl_energy_storage_power_stations_containers " |
|
907 | " WHERE energy_storage_power_station_id = %s AND energy_storage_container_id = %s ", (id_, sid)) |
|
908 | if cursor.fetchone() is None: |
|
909 | cursor.close() |
|
910 | cnx.close() |
|
911 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
912 | description='API.ENERGY_STORAGE_POWER_STATION_CONTAINER_RELATION_NOT_FOUND') |
|
913 | ||
914 | cursor.execute(" DELETE FROM tbl_energy_storage_power_stations_containers " |
|
915 | " WHERE energy_storage_power_station_id = %s AND energy_storage_container_id = %s ", (id_, sid)) |
|
916 | cnx.commit() |
|
917 | ||
918 | cursor.close() |
|
919 | cnx.close() |
|
920 | ||
921 | resp.status = falcon.HTTP_204 |
|
922 | ||
923 | ||
924 | class EnergyStoragePowerStationDataSourcePointCollection: |
@@ 5144-5205 (lines=62) @@ | ||
5141 | resp.location = '/microgrids/' + str(id_) + '/users/' + str(user_id) |
|
5142 | ||
5143 | ||
5144 | class MicrogridUserItem: |
|
5145 | def __init__(self): |
|
5146 | """Initializes Class""" |
|
5147 | pass |
|
5148 | ||
5149 | @staticmethod |
|
5150 | def on_options(req, resp, id_, uid): |
|
5151 | _ = req |
|
5152 | resp.status = falcon.HTTP_200 |
|
5153 | _ = id_ |
|
5154 | ||
5155 | @staticmethod |
|
5156 | @user_logger |
|
5157 | def on_delete(req, resp, id_, uid): |
|
5158 | # todo Verify if the user is bound when deleting it |
|
5159 | admin_control(req) |
|
5160 | if not id_.isdigit() or int(id_) <= 0: |
|
5161 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
5162 | description='API.INVALID_MICROGRID_ID') |
|
5163 | ||
5164 | if not uid.isdigit() or int(uid) <= 0: |
|
5165 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
5166 | description='API.INVALID_USER_ID') |
|
5167 | ||
5168 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
5169 | cursor = cnx.cursor() |
|
5170 | cursor.execute(" SELECT name " |
|
5171 | " FROM tbl_microgrids " |
|
5172 | " WHERE id = %s ", (id_,)) |
|
5173 | if cursor.fetchone() is None: |
|
5174 | cursor.close() |
|
5175 | cnx.close() |
|
5176 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5177 | description='API.MICROGRID_NOT_FOUND') |
|
5178 | ||
5179 | cnx_user = mysql.connector.connect(**config.myems_user_db) |
|
5180 | cursor_user = cnx_user.cursor() |
|
5181 | cursor_user.execute(" SELECT name FROM tbl_users WHERE id = %s ", (uid,)) |
|
5182 | if cursor_user.fetchone() is None: |
|
5183 | cursor_user.close() |
|
5184 | cnx_user.close() |
|
5185 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5186 | description='API.USER_NOT_FOUND') |
|
5187 | ||
5188 | cursor.execute(" SELECT id " |
|
5189 | " FROM tbl_microgrids_users " |
|
5190 | " WHERE microgrid_id = %s AND user_id = %s ", (id_, uid)) |
|
5191 | if cursor.fetchone() is None: |
|
5192 | cursor.close() |
|
5193 | cnx.close() |
|
5194 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5195 | description='API.MICROGRID_USER_RELATION_NOT_FOUND') |
|
5196 | ||
5197 | cursor.execute(" DELETE FROM tbl_microgrids_users WHERE microgrid_id = %s AND user_id = %s ", (id_, uid)) |
|
5198 | cnx.commit() |
|
5199 | ||
5200 | cursor.close() |
|
5201 | cnx.close() |
|
5202 | cursor_user.close() |
|
5203 | cnx_user.close() |
|
5204 | ||
5205 | resp.status = falcon.HTTP_204 |
|
5206 | ||
5207 | ||
5208 | class MicrogridExport: |
|
@@ 4968-5028 (lines=61) @@ | ||
4965 | resp.location = '/microgrids/' + str(id_) + '/sensors/' + str(sensor_id) |
|
4966 | ||
4967 | ||
4968 | class MicrogridSensorItem: |
|
4969 | def __init__(self): |
|
4970 | """Initializes Class""" |
|
4971 | pass |
|
4972 | ||
4973 | @staticmethod |
|
4974 | def on_options(req, resp, id_, sid): |
|
4975 | _ = req |
|
4976 | resp.status = falcon.HTTP_200 |
|
4977 | _ = id_ |
|
4978 | ||
4979 | @staticmethod |
|
4980 | @user_logger |
|
4981 | def on_delete(req, resp, id_, sid): |
|
4982 | admin_control(req) |
|
4983 | if not id_.isdigit() or int(id_) <= 0: |
|
4984 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
4985 | description='API.INVALID_MICROGRID_ID') |
|
4986 | ||
4987 | if not sid.isdigit() or int(sid) <= 0: |
|
4988 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
4989 | description='API.INVALID_SENSOR_ID') |
|
4990 | ||
4991 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
4992 | cursor = cnx.cursor() |
|
4993 | ||
4994 | cursor.execute(" SELECT name " |
|
4995 | " FROM tbl_microgrids " |
|
4996 | " WHERE id = %s ", (id_,)) |
|
4997 | if cursor.fetchone() is None: |
|
4998 | cursor.close() |
|
4999 | cnx.close() |
|
5000 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5001 | description='API.MICROGRID_NOT_FOUND') |
|
5002 | ||
5003 | cursor.execute(" SELECT name " |
|
5004 | " FROM tbl_sensors " |
|
5005 | " WHERE id = %s ", (sid,)) |
|
5006 | if cursor.fetchone() is None: |
|
5007 | cursor.close() |
|
5008 | cnx.close() |
|
5009 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5010 | description='API.SENSOR_NOT_FOUND') |
|
5011 | ||
5012 | cursor.execute(" SELECT id " |
|
5013 | " FROM tbl_microgrids_sensors " |
|
5014 | " WHERE microgrid_id = %s AND sensor_id = %s ", (id_, sid)) |
|
5015 | if cursor.fetchone() is None: |
|
5016 | cursor.close() |
|
5017 | cnx.close() |
|
5018 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5019 | description='API.MICROGRID_SENSOR_RELATION_NOT_FOUND') |
|
5020 | ||
5021 | cursor.execute(" DELETE FROM tbl_microgrids_sensors " |
|
5022 | " WHERE microgrid_id = %s AND sensor_id = %s ", (id_, sid)) |
|
5023 | cnx.commit() |
|
5024 | ||
5025 | cursor.close() |
|
5026 | cnx.close() |
|
5027 | ||
5028 | resp.status = falcon.HTTP_204 |
|
5029 | ||
5030 | ||
5031 | class MicrogridUserCollection: |
|
@@ 5709-5765 (lines=57) @@ | ||
5706 | resp.status = falcon.HTTP_201 |
|
5707 | resp.location = '/microgrids/' + str(id_) + '/datasources/' + str(data_source_id) |
|
5708 | ||
5709 | class MicrogridDataSourceItem: |
|
5710 | def __init__(self): |
|
5711 | pass |
|
5712 | ||
5713 | @staticmethod |
|
5714 | def on_options(req, resp, id_, dsid): |
|
5715 | _ = req |
|
5716 | _ = id_ |
|
5717 | _ = dsid |
|
5718 | resp.status = falcon.HTTP_200 |
|
5719 | ||
5720 | @staticmethod |
|
5721 | @user_logger |
|
5722 | def on_delete(req, resp, id_, dsid): |
|
5723 | admin_control(req) |
|
5724 | ||
5725 | if not id_.isdigit() or int(id_) <= 0: |
|
5726 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
5727 | description='API.INVALID_MICROGRID_ID') |
|
5728 | ||
5729 | if not dsid.isdigit() or int(dsid) <= 0: |
|
5730 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
5731 | description='API.INVALID_DATA_SOURCE_ID') |
|
5732 | ||
5733 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
5734 | cursor = cnx.cursor() |
|
5735 | ||
5736 | cursor.execute(" SELECT name FROM tbl_microgrids WHERE id = %s ", (id_,)) |
|
5737 | if cursor.fetchone() is None: |
|
5738 | cursor.close() |
|
5739 | cnx.close() |
|
5740 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5741 | description='API.MICROGRID_NOT_FOUND') |
|
5742 | ||
5743 | cursor.execute(" SELECT name FROM tbl_data_sources WHERE id = %s ", (dsid,)) |
|
5744 | if cursor.fetchone() is None: |
|
5745 | cursor.close() |
|
5746 | cnx.close() |
|
5747 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5748 | description='API.DATA_SOURCE_NOT_FOUND') |
|
5749 | ||
5750 | cursor.execute(" SELECT id " |
|
5751 | " FROM tbl_microgrids_data_sources " |
|
5752 | " WHERE microgrid_id = %s AND data_source_id = %s ", (id_, dsid)) |
|
5753 | if cursor.fetchone() is None: |
|
5754 | cursor.close() |
|
5755 | cnx.close() |
|
5756 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5757 | description='API.MICROGRID_DATA_SOURCE_RELATION_NOT_FOUND') |
|
5758 | ||
5759 | cursor.execute(" DELETE FROM tbl_microgrids_data_sources " |
|
5760 | " WHERE microgrid_id = %s AND data_source_id = %s ", (id_, dsid)) |
|
5761 | cnx.commit() |
|
5762 | cursor.close() |
|
5763 | cnx.close() |
|
5764 | ||
5765 | resp.status = falcon.HTTP_204 |
|
5766 |
@@ 1880-1941 (lines=62) @@ | ||
1877 | resp.location = '/equipments/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
1878 | ||
1879 | ||
1880 | class EquipmentVirtualMeterItem: |
|
1881 | def __init__(self): |
|
1882 | """Initializes EquipmentVirtualMeterItem""" |
|
1883 | pass |
|
1884 | ||
1885 | @staticmethod |
|
1886 | def on_options(req, resp, id_, mid): |
|
1887 | _ = req |
|
1888 | resp.status = falcon.HTTP_200 |
|
1889 | _ = id_ |
|
1890 | _ = mid |
|
1891 | ||
1892 | @staticmethod |
|
1893 | @user_logger |
|
1894 | def on_delete(req, resp, id_, mid): |
|
1895 | admin_control(req) |
|
1896 | if not id_.isdigit() or int(id_) <= 0: |
|
1897 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1898 | description='API.INVALID_EQUIPMENT_ID') |
|
1899 | ||
1900 | if not mid.isdigit() or int(mid) <= 0: |
|
1901 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1902 | description='API.INVALID_VIRTUAL_METER_ID') |
|
1903 | ||
1904 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1905 | cursor = cnx.cursor() |
|
1906 | ||
1907 | cursor.execute(" SELECT name " |
|
1908 | " FROM tbl_equipments " |
|
1909 | " WHERE id = %s ", (id_,)) |
|
1910 | if cursor.fetchone() is None: |
|
1911 | cursor.close() |
|
1912 | cnx.close() |
|
1913 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1914 | description='API.EQUIPMENT_NOT_FOUND') |
|
1915 | ||
1916 | cursor.execute(" SELECT name " |
|
1917 | " FROM tbl_virtual_meters " |
|
1918 | " WHERE id = %s ", (mid,)) |
|
1919 | if cursor.fetchone() is None: |
|
1920 | cursor.close() |
|
1921 | cnx.close() |
|
1922 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1923 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
1924 | ||
1925 | cursor.execute(" SELECT id " |
|
1926 | " FROM tbl_equipments_virtual_meters " |
|
1927 | " WHERE equipment_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1928 | if cursor.fetchone() is None: |
|
1929 | cursor.close() |
|
1930 | cnx.close() |
|
1931 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1932 | description='API.EQUIPMENT_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
1933 | ||
1934 | cursor.execute(" DELETE FROM tbl_equipments_virtual_meters " |
|
1935 | " WHERE equipment_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1936 | cnx.commit() |
|
1937 | ||
1938 | cursor.close() |
|
1939 | cnx.close() |
|
1940 | ||
1941 | resp.status = falcon.HTTP_204 |
|
1942 | ||
1943 | ||
1944 | class EquipmentCommandCollection: |
|
@@ 1676-1737 (lines=62) @@ | ||
1673 | resp.location = '/equipments/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
1674 | ||
1675 | ||
1676 | class EquipmentOfflineMeterItem: |
|
1677 | def __init__(self): |
|
1678 | """Initializes EquipmentOfflineMeterItem""" |
|
1679 | pass |
|
1680 | ||
1681 | @staticmethod |
|
1682 | def on_options(req, resp, id_, mid): |
|
1683 | _ = req |
|
1684 | resp.status = falcon.HTTP_200 |
|
1685 | _ = id_ |
|
1686 | _ = mid |
|
1687 | ||
1688 | @staticmethod |
|
1689 | @user_logger |
|
1690 | def on_delete(req, resp, id_, mid): |
|
1691 | admin_control(req) |
|
1692 | if not id_.isdigit() or int(id_) <= 0: |
|
1693 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1694 | description='API.INVALID_EQUIPMENT_ID') |
|
1695 | ||
1696 | if not mid.isdigit() or int(mid) <= 0: |
|
1697 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1698 | description='API.INVALID_OFFLINE_METER_ID') |
|
1699 | ||
1700 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1701 | cursor = cnx.cursor() |
|
1702 | ||
1703 | cursor.execute(" SELECT name " |
|
1704 | " FROM tbl_equipments " |
|
1705 | " WHERE id = %s ", (id_,)) |
|
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.EQUIPMENT_NOT_FOUND') |
|
1711 | ||
1712 | cursor.execute(" SELECT name " |
|
1713 | " FROM tbl_offline_meters " |
|
1714 | " WHERE id = %s ", (mid,)) |
|
1715 | if cursor.fetchone() is None: |
|
1716 | cursor.close() |
|
1717 | cnx.close() |
|
1718 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1719 | description='API.OFFLINE_METER_NOT_FOUND') |
|
1720 | ||
1721 | cursor.execute(" SELECT id " |
|
1722 | " FROM tbl_equipments_offline_meters " |
|
1723 | " WHERE equipment_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1724 | if cursor.fetchone() is None: |
|
1725 | cursor.close() |
|
1726 | cnx.close() |
|
1727 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1728 | description='API.EQUIPMENT_OFFLINE_METER_RELATION_NOT_FOUND') |
|
1729 | ||
1730 | cursor.execute(" DELETE FROM tbl_equipments_offline_meters " |
|
1731 | " WHERE equipment_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1732 | cnx.commit() |
|
1733 | ||
1734 | cursor.close() |
|
1735 | cnx.close() |
|
1736 | ||
1737 | resp.status = falcon.HTTP_204 |
|
1738 | ||
1739 | ||
1740 | class EquipmentVirtualMeterCollection: |
|
@@ 2064-2124 (lines=61) @@ | ||
2061 | resp.location = '/equipments/' + str(id_) + '/commands/' + str(command_id) |
|
2062 | ||
2063 | ||
2064 | class EquipmentCommandItem: |
|
2065 | def __init__(self): |
|
2066 | """Initializes Class""" |
|
2067 | pass |
|
2068 | ||
2069 | @staticmethod |
|
2070 | def on_options(req, resp, id_, cid): |
|
2071 | _ = req |
|
2072 | resp.status = falcon.HTTP_200 |
|
2073 | _ = id_ |
|
2074 | _ = cid |
|
2075 | ||
2076 | @staticmethod |
|
2077 | @user_logger |
|
2078 | def on_delete(req, resp, id_, cid): |
|
2079 | admin_control(req) |
|
2080 | if not id_.isdigit() or int(id_) <= 0: |
|
2081 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2082 | description='API.INVALID_EQUIPMENT_ID') |
|
2083 | ||
2084 | if not cid.isdigit() or int(cid) <= 0: |
|
2085 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2086 | description='API.INVALID_COMMAND_ID') |
|
2087 | ||
2088 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2089 | cursor = cnx.cursor() |
|
2090 | ||
2091 | cursor.execute(" SELECT name " |
|
2092 | " FROM tbl_equipments " |
|
2093 | " WHERE id = %s ", (id_,)) |
|
2094 | if cursor.fetchone() is None: |
|
2095 | cursor.close() |
|
2096 | cnx.close() |
|
2097 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2098 | description='API.EQUIPMENT_NOT_FOUND') |
|
2099 | ||
2100 | cursor.execute(" SELECT name " |
|
2101 | " FROM tbl_commands " |
|
2102 | " WHERE id = %s ", (cid,)) |
|
2103 | if cursor.fetchone() is None: |
|
2104 | cursor.close() |
|
2105 | cnx.close() |
|
2106 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2107 | description='API.COMMAND_NOT_FOUND') |
|
2108 | ||
2109 | cursor.execute(" SELECT id " |
|
2110 | " FROM tbl_equipments_commands " |
|
2111 | " WHERE equipment_id = %s AND command_id = %s ", (id_, cid)) |
|
2112 | if cursor.fetchone() is None: |
|
2113 | cursor.close() |
|
2114 | cnx.close() |
|
2115 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2116 | description='API.EQUIPMENT_COMMAND_RELATION_NOT_FOUND') |
|
2117 | ||
2118 | cursor.execute(" DELETE FROM tbl_equipments_commands WHERE equipment_id = %s AND command_id = %s ", (id_, cid)) |
|
2119 | cnx.commit() |
|
2120 | ||
2121 | cursor.close() |
|
2122 | cnx.close() |
|
2123 | ||
2124 | resp.status = falcon.HTTP_204 |
|
2125 | ||
2126 | ||
2127 | class EquipmentExport: |
|
@@ 1473-1533 (lines=61) @@ | ||
1470 | resp.location = '/equipments/' + str(id_) + '/meters/' + str(meter_id) |
|
1471 | ||
1472 | ||
1473 | class EquipmentMeterItem: |
|
1474 | def __init__(self): |
|
1475 | """Initializes EquipmentMeterItem""" |
|
1476 | pass |
|
1477 | ||
1478 | @staticmethod |
|
1479 | def on_options(req, resp, id_, mid): |
|
1480 | _ = req |
|
1481 | resp.status = falcon.HTTP_200 |
|
1482 | _ = id_ |
|
1483 | _ = mid |
|
1484 | ||
1485 | @staticmethod |
|
1486 | @user_logger |
|
1487 | def on_delete(req, resp, id_, mid): |
|
1488 | admin_control(req) |
|
1489 | if not id_.isdigit() or int(id_) <= 0: |
|
1490 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1491 | description='API.INVALID_EQUIPMENT_ID') |
|
1492 | ||
1493 | if not mid.isdigit() or int(mid) <= 0: |
|
1494 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1495 | description='API.INVALID_METER_ID') |
|
1496 | ||
1497 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1498 | cursor = cnx.cursor() |
|
1499 | ||
1500 | cursor.execute(" SELECT name " |
|
1501 | " FROM tbl_equipments " |
|
1502 | " WHERE id = %s ", (id_,)) |
|
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_NOT_FOUND') |
|
1508 | ||
1509 | cursor.execute(" SELECT name " |
|
1510 | " FROM tbl_meters " |
|
1511 | " WHERE id = %s ", (mid,)) |
|
1512 | if cursor.fetchone() is None: |
|
1513 | cursor.close() |
|
1514 | cnx.close() |
|
1515 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1516 | description='API.METER_NOT_FOUND') |
|
1517 | ||
1518 | cursor.execute(" SELECT id " |
|
1519 | " FROM tbl_equipments_meters " |
|
1520 | " WHERE equipment_id = %s AND meter_id = %s ", (id_, mid)) |
|
1521 | if cursor.fetchone() is None: |
|
1522 | cursor.close() |
|
1523 | cnx.close() |
|
1524 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1525 | description='API.EQUIPMENT_METER_RELATION_NOT_FOUND') |
|
1526 | ||
1527 | cursor.execute(" DELETE FROM tbl_equipments_meters WHERE equipment_id = %s AND meter_id = %s ", (id_, mid)) |
|
1528 | cnx.commit() |
|
1529 | ||
1530 | cursor.close() |
|
1531 | cnx.close() |
|
1532 | ||
1533 | resp.status = falcon.HTTP_204 |
|
1534 | ||
1535 | ||
1536 | class EquipmentOfflineMeterCollection: |
@@ 1722-1783 (lines=62) @@ | ||
1719 | resp.location = '/shopfloors/' + str(id_) + '/workingcalendars/' + str(working_calendar_id) |
|
1720 | ||
1721 | ||
1722 | class ShopfloorWorkingCalendarItem: |
|
1723 | def __init__(self): |
|
1724 | """Initializes ShopfloorWorkingCalendarItem Class""" |
|
1725 | pass |
|
1726 | ||
1727 | @staticmethod |
|
1728 | def on_options(req, resp, id_, wcid): |
|
1729 | resp.status = falcon.HTTP_200 |
|
1730 | _ = req |
|
1731 | _ = id_ |
|
1732 | _ = wcid |
|
1733 | ||
1734 | @staticmethod |
|
1735 | @user_logger |
|
1736 | def on_delete(req, resp, id_, wcid): |
|
1737 | admin_control(req) |
|
1738 | if not id_.isdigit() or int(id_) <= 0: |
|
1739 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1740 | description='API.INVALID_SHOPFLOOR_ID') |
|
1741 | ||
1742 | if not wcid.isdigit() or int(wcid) <= 0: |
|
1743 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1744 | description='API.INVALID_WORKING_CALENDAR_ID') |
|
1745 | ||
1746 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1747 | cursor = cnx.cursor() |
|
1748 | ||
1749 | cursor.execute(" SELECT name " |
|
1750 | " FROM tbl_shopfloors " |
|
1751 | " WHERE id = %s ", (id_,)) |
|
1752 | if cursor.fetchone() is None: |
|
1753 | cursor.close() |
|
1754 | cnx.close() |
|
1755 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1756 | description='API.SHOPFLOOR_NOT_FOUND') |
|
1757 | ||
1758 | cursor.execute(" SELECT name " |
|
1759 | " FROM tbl_working_calendars " |
|
1760 | " WHERE id = %s ", (wcid,)) |
|
1761 | if cursor.fetchone() is None: |
|
1762 | cursor.close() |
|
1763 | cnx.close() |
|
1764 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1765 | description='API.WORKING_CALENDAR_NOT_FOUND') |
|
1766 | ||
1767 | cursor.execute(" SELECT id " |
|
1768 | " FROM tbl_shopfloors_working_calendars " |
|
1769 | " WHERE shopfloor_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
1770 | if cursor.fetchone() is None: |
|
1771 | cursor.close() |
|
1772 | cnx.close() |
|
1773 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1774 | description='API.SHOPFLOOR_WORKING_CALENDAR_RELATION_NOT_FOUND') |
|
1775 | ||
1776 | cursor.execute(" DELETE FROM tbl_shopfloors_working_calendars " |
|
1777 | " WHERE shopfloor_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
1778 | cnx.commit() |
|
1779 | ||
1780 | cursor.close() |
|
1781 | cnx.close() |
|
1782 | ||
1783 | resp.status = falcon.HTTP_204 |
|
1784 | ||
1785 | ||
1786 | class ShopfloorCommandCollection: |
|
@@ 1540-1601 (lines=62) @@ | ||
1537 | resp.location = '/shopfloors/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
1538 | ||
1539 | ||
1540 | class ShopfloorVirtualMeterItem: |
|
1541 | def __init__(self): |
|
1542 | """Initializes ShopfloorVirtualMeterItem""" |
|
1543 | pass |
|
1544 | ||
1545 | @staticmethod |
|
1546 | def on_options(req, resp, id_, mid): |
|
1547 | resp.status = falcon.HTTP_200 |
|
1548 | _ = req |
|
1549 | _ = id_ |
|
1550 | _ = mid |
|
1551 | ||
1552 | @staticmethod |
|
1553 | @user_logger |
|
1554 | def on_delete(req, resp, id_, mid): |
|
1555 | admin_control(req) |
|
1556 | if not id_.isdigit() or int(id_) <= 0: |
|
1557 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1558 | description='API.INVALID_SHOPFLOOR_ID') |
|
1559 | ||
1560 | if not mid.isdigit() or int(mid) <= 0: |
|
1561 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1562 | description='API.INVALID_VIRTUAL_METER_ID') |
|
1563 | ||
1564 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1565 | cursor = cnx.cursor() |
|
1566 | ||
1567 | cursor.execute(" SELECT name " |
|
1568 | " FROM tbl_shopfloors " |
|
1569 | " WHERE id = %s ", (id_,)) |
|
1570 | if cursor.fetchone() is None: |
|
1571 | cursor.close() |
|
1572 | cnx.close() |
|
1573 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1574 | description='API.SHOPFLOOR_NOT_FOUND') |
|
1575 | ||
1576 | cursor.execute(" SELECT name " |
|
1577 | " FROM tbl_virtual_meters " |
|
1578 | " WHERE id = %s ", (mid,)) |
|
1579 | if cursor.fetchone() is None: |
|
1580 | cursor.close() |
|
1581 | cnx.close() |
|
1582 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1583 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
1584 | ||
1585 | cursor.execute(" SELECT id " |
|
1586 | " FROM tbl_shopfloors_virtual_meters " |
|
1587 | " WHERE shopfloor_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1588 | if cursor.fetchone() is None: |
|
1589 | cursor.close() |
|
1590 | cnx.close() |
|
1591 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1592 | description='API.SHOPFLOOR_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
1593 | ||
1594 | cursor.execute(" DELETE FROM tbl_shopfloors_virtual_meters " |
|
1595 | " WHERE shopfloor_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1596 | cnx.commit() |
|
1597 | ||
1598 | cursor.close() |
|
1599 | cnx.close() |
|
1600 | ||
1601 | resp.status = falcon.HTTP_204 |
|
1602 | ||
1603 | ||
1604 | class ShopfloorWorkingCalendarCollection: |
|
@@ 1164-1225 (lines=62) @@ | ||
1161 | resp.location = '/shopfloors/' + str(id_) + '/points/' + str(point_id) |
|
1162 | ||
1163 | ||
1164 | class ShopfloorPointItem: |
|
1165 | def __init__(self): |
|
1166 | """Initializes ShopfloorPointItem""" |
|
1167 | pass |
|
1168 | ||
1169 | @staticmethod |
|
1170 | def on_options(req, resp, id_, pid): |
|
1171 | resp.status = falcon.HTTP_200 |
|
1172 | _ = req |
|
1173 | _ = id_ |
|
1174 | _ = pid |
|
1175 | ||
1176 | @staticmethod |
|
1177 | @user_logger |
|
1178 | def on_delete(req, resp, id_, pid): |
|
1179 | admin_control(req) |
|
1180 | if not id_.isdigit() or int(id_) <= 0: |
|
1181 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1182 | description='API.INVALID_SHOPFLOOR_ID') |
|
1183 | ||
1184 | if not pid.isdigit() or int(pid) <= 0: |
|
1185 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1186 | description='API.INVALID_POINT_ID') |
|
1187 | ||
1188 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1189 | cursor = cnx.cursor() |
|
1190 | ||
1191 | cursor.execute(" SELECT name " |
|
1192 | " FROM tbl_shopfloors " |
|
1193 | " WHERE id = %s ", (id_,)) |
|
1194 | if cursor.fetchone() is None: |
|
1195 | cursor.close() |
|
1196 | cnx.close() |
|
1197 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1198 | description='API.SHOPFLOOR_NOT_FOUND') |
|
1199 | ||
1200 | cursor.execute(" SELECT name " |
|
1201 | " FROM tbl_points " |
|
1202 | " WHERE id = %s ", (pid,)) |
|
1203 | if cursor.fetchone() is None: |
|
1204 | cursor.close() |
|
1205 | cnx.close() |
|
1206 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1207 | description='API.POINT_NOT_FOUND') |
|
1208 | ||
1209 | cursor.execute(" SELECT id " |
|
1210 | " FROM tbl_shopfloors_points " |
|
1211 | " WHERE shopfloor_id = %s AND point_id = %s ", (id_, pid)) |
|
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.SHOPFLOOR_POINT_RELATION_NOT_FOUND') |
|
1217 | ||
1218 | cursor.execute(" DELETE FROM tbl_shopfloors_points " |
|
1219 | " WHERE shopfloor_id = %s AND point_id = %s ", (id_, pid)) |
|
1220 | cnx.commit() |
|
1221 | ||
1222 | cursor.close() |
|
1223 | cnx.close() |
|
1224 | ||
1225 | resp.status = falcon.HTTP_204 |
|
1226 | ||
1227 | ||
1228 | class ShopfloorSensorCollection: |
|
@@ 970-1031 (lines=62) @@ | ||
967 | resp.location = '/shopfloors/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
968 | ||
969 | ||
970 | class ShopfloorOfflineMeterItem: |
|
971 | def __init__(self): |
|
972 | """Initializes ShopfloorOfflineMeterItem""" |
|
973 | pass |
|
974 | ||
975 | @staticmethod |
|
976 | def on_options(req, resp, id_, mid): |
|
977 | resp.status = falcon.HTTP_200 |
|
978 | _ = req |
|
979 | _ = id_ |
|
980 | _ = mid |
|
981 | ||
982 | @staticmethod |
|
983 | @user_logger |
|
984 | def on_delete(req, resp, id_, mid): |
|
985 | admin_control(req) |
|
986 | if not id_.isdigit() or int(id_) <= 0: |
|
987 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
988 | description='API.INVALID_SHOPFLOOR_ID') |
|
989 | ||
990 | if not mid.isdigit() or int(mid) <= 0: |
|
991 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
992 | description='API.INVALID_OFFLINE_METER_ID') |
|
993 | ||
994 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
995 | cursor = cnx.cursor() |
|
996 | ||
997 | cursor.execute(" SELECT name " |
|
998 | " FROM tbl_shopfloors " |
|
999 | " WHERE id = %s ", (id_,)) |
|
1000 | if cursor.fetchone() is None: |
|
1001 | cursor.close() |
|
1002 | cnx.close() |
|
1003 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1004 | description='API.SHOPFLOOR_NOT_FOUND') |
|
1005 | ||
1006 | cursor.execute(" SELECT name " |
|
1007 | " FROM tbl_offline_meters " |
|
1008 | " WHERE id = %s ", (mid,)) |
|
1009 | if cursor.fetchone() is None: |
|
1010 | cursor.close() |
|
1011 | cnx.close() |
|
1012 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1013 | description='API.OFFLINE_METER_NOT_FOUND') |
|
1014 | ||
1015 | cursor.execute(" SELECT id " |
|
1016 | " FROM tbl_shopfloors_offline_meters " |
|
1017 | " WHERE shopfloor_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1018 | if cursor.fetchone() is None: |
|
1019 | cursor.close() |
|
1020 | cnx.close() |
|
1021 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1022 | description='API.SHOPFLOOR_OFFLINE_METER_RELATION_NOT_FOUND') |
|
1023 | ||
1024 | cursor.execute(" DELETE FROM tbl_shopfloors_offline_meters " |
|
1025 | " WHERE shopfloor_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1026 | cnx.commit() |
|
1027 | ||
1028 | cursor.close() |
|
1029 | cnx.close() |
|
1030 | ||
1031 | resp.status = falcon.HTTP_204 |
|
1032 | ||
1033 | ||
1034 | class ShopfloorPointCollection: |
|
@@ 581-642 (lines=62) @@ | ||
578 | resp.location = '/shopfloors/' + str(id_) + '/equipments/' + str(equipment_id) |
|
579 | ||
580 | ||
581 | class ShopfloorEquipmentItem: |
|
582 | def __init__(self): |
|
583 | """Initializes ShopfloorEquipmentItem""" |
|
584 | pass |
|
585 | ||
586 | @staticmethod |
|
587 | def on_options(req, resp, id_, eid): |
|
588 | resp.status = falcon.HTTP_200 |
|
589 | _ = req |
|
590 | _ = id_ |
|
591 | _ = eid |
|
592 | ||
593 | @staticmethod |
|
594 | @user_logger |
|
595 | def on_delete(req, resp, id_, eid): |
|
596 | admin_control(req) |
|
597 | if not id_.isdigit() or int(id_) <= 0: |
|
598 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
599 | description='API.INVALID_SHOPFLOOR_ID') |
|
600 | ||
601 | if not eid.isdigit() or int(eid) <= 0: |
|
602 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
603 | description='API.INVALID_EQUIPMENT_ID') |
|
604 | ||
605 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
606 | cursor = cnx.cursor() |
|
607 | ||
608 | cursor.execute(" SELECT name " |
|
609 | " FROM tbl_shopfloors " |
|
610 | " WHERE id = %s ", (id_,)) |
|
611 | if cursor.fetchone() is None: |
|
612 | cursor.close() |
|
613 | cnx.close() |
|
614 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
615 | description='API.SHOPFLOOR_NOT_FOUND') |
|
616 | ||
617 | cursor.execute(" SELECT name " |
|
618 | " FROM tbl_equipments " |
|
619 | " WHERE id = %s ", (eid,)) |
|
620 | if cursor.fetchone() is None: |
|
621 | cursor.close() |
|
622 | cnx.close() |
|
623 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
624 | description='API.EQUIPMENT_NOT_FOUND') |
|
625 | ||
626 | cursor.execute(" SELECT id " |
|
627 | " FROM tbl_shopfloors_equipments " |
|
628 | " WHERE shopfloor_id = %s AND equipment_id = %s ", (id_, eid)) |
|
629 | if cursor.fetchone() is None: |
|
630 | cursor.close() |
|
631 | cnx.close() |
|
632 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
633 | description='API.SHOPFLOOR_EQUIPMENT_RELATION_NOT_FOUND') |
|
634 | ||
635 | cursor.execute(" DELETE FROM tbl_shopfloors_equipments " |
|
636 | " WHERE shopfloor_id = %s AND equipment_id = %s ", (id_, eid)) |
|
637 | cnx.commit() |
|
638 | ||
639 | cursor.close() |
|
640 | cnx.close() |
|
641 | ||
642 | resp.status = falcon.HTTP_204 |
|
643 | ||
644 | ||
645 | class ShopfloorMeterCollection: |
|
@@ 1904-1964 (lines=61) @@ | ||
1901 | resp.location = '/shopfloors/' + str(id_) + '/commands/' + str(command_id) |
|
1902 | ||
1903 | ||
1904 | class ShopfloorCommandItem: |
|
1905 | def __init__(self): |
|
1906 | """Initializes Class""" |
|
1907 | pass |
|
1908 | ||
1909 | @staticmethod |
|
1910 | def on_options(req, resp, id_, cid): |
|
1911 | resp.status = falcon.HTTP_200 |
|
1912 | _ = req |
|
1913 | _ = id_ |
|
1914 | _ = cid |
|
1915 | ||
1916 | @staticmethod |
|
1917 | @user_logger |
|
1918 | def on_delete(req, resp, id_, cid): |
|
1919 | admin_control(req) |
|
1920 | if not id_.isdigit() or int(id_) <= 0: |
|
1921 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1922 | description='API.INVALID_SHOPFLOOR_ID') |
|
1923 | ||
1924 | if not cid.isdigit() or int(cid) <= 0: |
|
1925 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1926 | description='API.INVALID_COMMAND_ID') |
|
1927 | ||
1928 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1929 | cursor = cnx.cursor() |
|
1930 | ||
1931 | cursor.execute(" SELECT name " |
|
1932 | " FROM tbl_shopfloors " |
|
1933 | " WHERE id = %s ", (id_,)) |
|
1934 | if cursor.fetchone() is None: |
|
1935 | cursor.close() |
|
1936 | cnx.close() |
|
1937 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1938 | description='API.SHOPFLOOR_NOT_FOUND') |
|
1939 | ||
1940 | cursor.execute(" SELECT name " |
|
1941 | " FROM tbl_commands " |
|
1942 | " WHERE id = %s ", (cid,)) |
|
1943 | if cursor.fetchone() is None: |
|
1944 | cursor.close() |
|
1945 | cnx.close() |
|
1946 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1947 | description='API.COMMAND_NOT_FOUND') |
|
1948 | ||
1949 | cursor.execute(" SELECT id " |
|
1950 | " FROM tbl_shopfloors_commands " |
|
1951 | " WHERE shopfloor_id = %s AND command_id = %s ", (id_, cid)) |
|
1952 | if cursor.fetchone() is None: |
|
1953 | cursor.close() |
|
1954 | cnx.close() |
|
1955 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1956 | description='API.SHOPFLOOR_COMMAND_RELATION_NOT_FOUND') |
|
1957 | ||
1958 | cursor.execute(" DELETE FROM tbl_shopfloors_commands WHERE shopfloor_id = %s AND command_id = %s ", (id_, cid)) |
|
1959 | cnx.commit() |
|
1960 | ||
1961 | cursor.close() |
|
1962 | cnx.close() |
|
1963 | ||
1964 | resp.status = falcon.HTTP_204 |
|
1965 | ||
1966 | ||
1967 | class ShopfloorExport: |
|
@@ 1346-1406 (lines=61) @@ | ||
1343 | resp.location = '/shopfloors/' + str(id_) + '/sensors/' + str(sensor_id) |
|
1344 | ||
1345 | ||
1346 | class ShopfloorSensorItem: |
|
1347 | def __init__(self): |
|
1348 | """Initializes ShopfloorSensorItem""" |
|
1349 | pass |
|
1350 | ||
1351 | @staticmethod |
|
1352 | def on_options(req, resp, id_, sid): |
|
1353 | resp.status = falcon.HTTP_200 |
|
1354 | _ = req |
|
1355 | _ = id_ |
|
1356 | _ = sid |
|
1357 | ||
1358 | @staticmethod |
|
1359 | @user_logger |
|
1360 | def on_delete(req, resp, id_, sid): |
|
1361 | admin_control(req) |
|
1362 | if not id_.isdigit() or int(id_) <= 0: |
|
1363 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1364 | description='API.INVALID_SHOPFLOOR_ID') |
|
1365 | ||
1366 | if not sid.isdigit() or int(sid) <= 0: |
|
1367 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1368 | description='API.INVALID_SENSOR_ID') |
|
1369 | ||
1370 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1371 | cursor = cnx.cursor() |
|
1372 | ||
1373 | cursor.execute(" SELECT name " |
|
1374 | " FROM tbl_shopfloors " |
|
1375 | " WHERE id = %s ", (id_,)) |
|
1376 | if cursor.fetchone() is None: |
|
1377 | cursor.close() |
|
1378 | cnx.close() |
|
1379 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1380 | description='API.SHOPFLOOR_NOT_FOUND') |
|
1381 | ||
1382 | cursor.execute(" SELECT name " |
|
1383 | " FROM tbl_sensors " |
|
1384 | " WHERE id = %s ", (sid,)) |
|
1385 | if cursor.fetchone() is None: |
|
1386 | cursor.close() |
|
1387 | cnx.close() |
|
1388 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1389 | description='API.SENSOR_NOT_FOUND') |
|
1390 | ||
1391 | cursor.execute(" SELECT id " |
|
1392 | " FROM tbl_shopfloors_sensors " |
|
1393 | " WHERE shopfloor_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1394 | if cursor.fetchone() is None: |
|
1395 | cursor.close() |
|
1396 | cnx.close() |
|
1397 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1398 | description='API.SHOPFLOOR_SENSOR_RELATION_NOT_FOUND') |
|
1399 | ||
1400 | cursor.execute(" DELETE FROM tbl_shopfloors_sensors WHERE shopfloor_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1401 | cnx.commit() |
|
1402 | ||
1403 | cursor.close() |
|
1404 | cnx.close() |
|
1405 | ||
1406 | resp.status = falcon.HTTP_204 |
|
1407 | ||
1408 | ||
1409 | class ShopfloorVirtualMeterCollection: |
|
@@ 776-836 (lines=61) @@ | ||
773 | resp.location = '/shopfloors/' + str(id_) + '/meters/' + str(meter_id) |
|
774 | ||
775 | ||
776 | class ShopfloorMeterItem: |
|
777 | def __init__(self): |
|
778 | """Initializes ShopfloorMeterItem""" |
|
779 | pass |
|
780 | ||
781 | @staticmethod |
|
782 | def on_options(req, resp, id_, mid): |
|
783 | resp.status = falcon.HTTP_200 |
|
784 | _ = req |
|
785 | _ = id_ |
|
786 | _ = mid |
|
787 | ||
788 | @staticmethod |
|
789 | @user_logger |
|
790 | def on_delete(req, resp, id_, mid): |
|
791 | admin_control(req) |
|
792 | if not id_.isdigit() or int(id_) <= 0: |
|
793 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
794 | description='API.INVALID_SHOPFLOOR_ID') |
|
795 | ||
796 | if not mid.isdigit() or int(mid) <= 0: |
|
797 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
798 | description='API.INVALID_METER_ID') |
|
799 | ||
800 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
801 | cursor = cnx.cursor() |
|
802 | ||
803 | cursor.execute(" SELECT name " |
|
804 | " FROM tbl_shopfloors " |
|
805 | " WHERE id = %s ", (id_,)) |
|
806 | if cursor.fetchone() is None: |
|
807 | cursor.close() |
|
808 | cnx.close() |
|
809 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
810 | description='API.SHOPFLOOR_NOT_FOUND') |
|
811 | ||
812 | cursor.execute(" SELECT name " |
|
813 | " FROM tbl_meters " |
|
814 | " WHERE id = %s ", (mid,)) |
|
815 | if cursor.fetchone() is None: |
|
816 | cursor.close() |
|
817 | cnx.close() |
|
818 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
819 | description='API.METER_NOT_FOUND') |
|
820 | ||
821 | cursor.execute(" SELECT id " |
|
822 | " FROM tbl_shopfloors_meters " |
|
823 | " WHERE shopfloor_id = %s AND meter_id = %s ", (id_, mid)) |
|
824 | if cursor.fetchone() is None: |
|
825 | cursor.close() |
|
826 | cnx.close() |
|
827 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
828 | description='API.SHOPFLOOR_METER_RELATION_NOT_FOUND') |
|
829 | ||
830 | cursor.execute(" DELETE FROM tbl_shopfloors_meters WHERE shopfloor_id = %s AND meter_id = %s ", (id_, mid)) |
|
831 | cnx.commit() |
|
832 | ||
833 | cursor.close() |
|
834 | cnx.close() |
|
835 | ||
836 | resp.status = falcon.HTTP_204 |
|
837 | ||
838 | ||
839 | class ShopfloorOfflineMeterCollection: |
@@ 1558-1619 (lines=62) @@ | ||
1555 | resp.location = '/spaces/' + str(id_) + '/meters/' + str(meter_id) |
|
1556 | ||
1557 | ||
1558 | class SpaceMeterItem: |
|
1559 | def __init__(self): |
|
1560 | """Initializes Class""" |
|
1561 | pass |
|
1562 | ||
1563 | @staticmethod |
|
1564 | def on_options(req, resp, id_, mid): |
|
1565 | _ = req |
|
1566 | resp.status = falcon.HTTP_200 |
|
1567 | _ = id_ |
|
1568 | ||
1569 | @staticmethod |
|
1570 | @user_logger |
|
1571 | def on_delete(req, resp, id_, mid): |
|
1572 | admin_control(req) |
|
1573 | if not id_.isdigit() or int(id_) <= 0: |
|
1574 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1575 | description='API.INVALID_SPACE_ID') |
|
1576 | ||
1577 | if not mid.isdigit() or int(mid) <= 0: |
|
1578 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1579 | description='API.INVALID_METER_ID') |
|
1580 | ||
1581 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1582 | cursor = cnx.cursor() |
|
1583 | ||
1584 | cursor.execute(" SELECT name " |
|
1585 | " FROM tbl_spaces " |
|
1586 | " WHERE id = %s ", (id_,)) |
|
1587 | if cursor.fetchone() is None: |
|
1588 | cursor.close() |
|
1589 | cnx.close() |
|
1590 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1591 | description='API.SPACE_NOT_FOUND') |
|
1592 | ||
1593 | cursor.execute(" SELECT name " |
|
1594 | " FROM tbl_meters " |
|
1595 | " WHERE id = %s ", (mid,)) |
|
1596 | if cursor.fetchone() is None: |
|
1597 | cursor.close() |
|
1598 | cnx.close() |
|
1599 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1600 | description='API.METER_NOT_FOUND') |
|
1601 | ||
1602 | cursor.execute(" SELECT id " |
|
1603 | " FROM tbl_spaces_meters " |
|
1604 | " WHERE space_id = %s AND meter_id = %s ", (id_, mid)) |
|
1605 | # use fetchall to avoid 'Unread result found' error in case there are duplicate rows |
|
1606 | rows = cursor.fetchall() |
|
1607 | if rows is None or len(rows) == 0: |
|
1608 | cursor.close() |
|
1609 | cnx.close() |
|
1610 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1611 | description='API.SPACE_METER_RELATION_NOT_FOUND') |
|
1612 | ||
1613 | cursor.execute(" DELETE FROM tbl_spaces_meters WHERE space_id = %s AND meter_id = %s ", (id_, mid)) |
|
1614 | cnx.commit() |
|
1615 | ||
1616 | cursor.close() |
|
1617 | cnx.close() |
|
1618 | ||
1619 | resp.status = falcon.HTTP_204 |
|
1620 | ||
1621 | ||
1622 | class SpaceMicrogridCollection: |
|
@@ 5692-5752 (lines=61) @@ | ||
5689 | resp.location = '/spaces/' + str(id_) + '/distributionsystems/' + str(distribution_system_id) |
|
5690 | ||
5691 | ||
5692 | class DistributionSystemItem: |
|
5693 | def __init__(self): |
|
5694 | """Initializes Class""" |
|
5695 | pass |
|
5696 | ||
5697 | @staticmethod |
|
5698 | def on_options(req, resp, id_, did): |
|
5699 | _ = req |
|
5700 | resp.status = falcon.HTTP_200 |
|
5701 | _ = id_ |
|
5702 | ||
5703 | @staticmethod |
|
5704 | @user_logger |
|
5705 | def on_delete(req, resp, id_, did): |
|
5706 | admin_control(req) |
|
5707 | if not id_.isdigit() or int(id_) <= 0: |
|
5708 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
5709 | description='API.INVALID_SPACE_ID') |
|
5710 | ||
5711 | if not did.isdigit() or int(did) <= 0: |
|
5712 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
5713 | description='API.INVALID_DISTRIBUTION_SYSTEM_ID') |
|
5714 | ||
5715 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
5716 | cursor = cnx.cursor() |
|
5717 | ||
5718 | cursor.execute(" SELECT name " |
|
5719 | " FROM tbl_spaces " |
|
5720 | " WHERE id = %s ", (id_,)) |
|
5721 | if cursor.fetchone() is None: |
|
5722 | cursor.close() |
|
5723 | cnx.close() |
|
5724 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5725 | description='API.SPACE_NOT_FOUND') |
|
5726 | ||
5727 | cursor.execute(" SELECT name " |
|
5728 | " FROM tbl_distribution_systems " |
|
5729 | " WHERE id = %s ", (did,)) |
|
5730 | if cursor.fetchone() is None: |
|
5731 | cursor.close() |
|
5732 | cnx.close() |
|
5733 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5734 | description='API.DISTRIBUTION_SYSTEM_NOT_FOUND') |
|
5735 | ||
5736 | cursor.execute(" SELECT id " |
|
5737 | " FROM tbl_spaces_distribution_systems " |
|
5738 | " WHERE space_id = %s AND distribution_system_id = %s ", (id_, did)) |
|
5739 | if cursor.fetchone() is None: |
|
5740 | cursor.close() |
|
5741 | cnx.close() |
|
5742 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5743 | description='API.SPACE_DISTRIBUTION_SYSTEM_RELATION_NOT_FOUND') |
|
5744 | ||
5745 | cursor.execute(" DELETE FROM tbl_spaces_distribution_systems " |
|
5746 | " WHERE space_id = %s AND distribution_system_id = %s ", (id_, did)) |
|
5747 | cnx.commit() |
|
5748 | ||
5749 | cursor.close() |
|
5750 | cnx.close() |
|
5751 | ||
5752 | resp.status = falcon.HTTP_204 |
|
5753 | ||
@@ 5511-5571 (lines=61) @@ | ||
5508 | resp.location = '/spaces/' + str(id_) + '/energyflowdiagrams/' + str(energy_flow_diagram_id) |
|
5509 | ||
5510 | ||
5511 | class SpaceEnergyFlowDiagramItem: |
|
5512 | def __init__(self): |
|
5513 | """Initializes Class""" |
|
5514 | pass |
|
5515 | ||
5516 | @staticmethod |
|
5517 | def on_options(req, resp, id_, eid): |
|
5518 | _ = req |
|
5519 | resp.status = falcon.HTTP_200 |
|
5520 | _ = id_ |
|
5521 | ||
5522 | @staticmethod |
|
5523 | @user_logger |
|
5524 | def on_delete(req, resp, id_, eid): |
|
5525 | admin_control(req) |
|
5526 | if not id_.isdigit() or int(id_) <= 0: |
|
5527 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
5528 | description='API.INVALID_SPACE_ID') |
|
5529 | ||
5530 | if not eid.isdigit() or int(eid) <= 0: |
|
5531 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
5532 | description='API.INVALID_ENERGY_FLOW_DIAGRAM_ID') |
|
5533 | ||
5534 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
5535 | cursor = cnx.cursor() |
|
5536 | ||
5537 | cursor.execute(" SELECT name " |
|
5538 | " FROM tbl_spaces " |
|
5539 | " WHERE id = %s ", (id_,)) |
|
5540 | if cursor.fetchone() is None: |
|
5541 | cursor.close() |
|
5542 | cnx.close() |
|
5543 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5544 | description='API.SPACE_NOT_FOUND') |
|
5545 | ||
5546 | cursor.execute(" SELECT name " |
|
5547 | " FROM tbl_energy_flow_diagrams " |
|
5548 | " WHERE id = %s ", (eid,)) |
|
5549 | if cursor.fetchone() is None: |
|
5550 | cursor.close() |
|
5551 | cnx.close() |
|
5552 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5553 | description='API.ENERGY_FLOW_DIAGRAM_NOT_FOUND') |
|
5554 | ||
5555 | cursor.execute(" SELECT id " |
|
5556 | " FROM tbl_spaces_energy_flow_diagrams " |
|
5557 | " WHERE space_id = %s AND energy_flow_diagram_id = %s ", (id_, eid)) |
|
5558 | if cursor.fetchone() is None: |
|
5559 | cursor.close() |
|
5560 | cnx.close() |
|
5561 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5562 | description='API.SPACE_ENERGY_FLOW_DIAGRAM_RELATION_NOT_FOUND') |
|
5563 | ||
5564 | cursor.execute(" DELETE FROM tbl_spaces_energy_flow_diagrams " |
|
5565 | " WHERE space_id = %s AND energy_flow_diagram_id = %s ", (id_, eid)) |
|
5566 | cnx.commit() |
|
5567 | ||
5568 | cursor.close() |
|
5569 | cnx.close() |
|
5570 | ||
5571 | resp.status = falcon.HTTP_204 |
|
5572 | ||
5573 | ||
5574 | class DistributionSystemCollection: |
|
@@ 3591-3651 (lines=61) @@ | ||
3588 | resp.location = '/spaces/' + str(id_) + '/workingcalendars/' + str(working_calendar_id) |
|
3589 | ||
3590 | ||
3591 | class SpaceWorkingCalendarItem: |
|
3592 | def __init__(self): |
|
3593 | """Initializes SpaceWorkingCalendarItem Class""" |
|
3594 | pass |
|
3595 | ||
3596 | @staticmethod |
|
3597 | def on_options(req, resp, id_, wcid): |
|
3598 | _ = req |
|
3599 | resp.status = falcon.HTTP_200 |
|
3600 | _ = id_ |
|
3601 | ||
3602 | @staticmethod |
|
3603 | @user_logger |
|
3604 | def on_delete(req, resp, id_, wcid): |
|
3605 | admin_control(req) |
|
3606 | if not id_.isdigit() or int(id_) <= 0: |
|
3607 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
3608 | description='API.INVALID_SPACE_ID') |
|
3609 | ||
3610 | if not wcid.isdigit() or int(wcid) <= 0: |
|
3611 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
3612 | description='API.INVALID_WORKING_CALENDAR_ID') |
|
3613 | ||
3614 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
3615 | cursor = cnx.cursor() |
|
3616 | ||
3617 | cursor.execute(" SELECT name " |
|
3618 | " FROM tbl_spaces " |
|
3619 | " WHERE id = %s ", (id_,)) |
|
3620 | if cursor.fetchone() is None: |
|
3621 | cursor.close() |
|
3622 | cnx.close() |
|
3623 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3624 | description='API.SPACE_NOT_FOUND') |
|
3625 | ||
3626 | cursor.execute(" SELECT name " |
|
3627 | " FROM tbl_working_calendars " |
|
3628 | " WHERE id = %s ", (wcid,)) |
|
3629 | if cursor.fetchone() is None: |
|
3630 | cursor.close() |
|
3631 | cnx.close() |
|
3632 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3633 | description='API.WORKING_CALENDAR_NOT_FOUND') |
|
3634 | ||
3635 | cursor.execute(" SELECT id " |
|
3636 | " FROM tbl_spaces_working_calendars " |
|
3637 | " WHERE space_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
3638 | if cursor.fetchone() is None: |
|
3639 | cursor.close() |
|
3640 | cnx.close() |
|
3641 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3642 | description='API.SPACE_WORKING_CALENDAR_RELATION_NOT_FOUND') |
|
3643 | ||
3644 | cursor.execute(" DELETE FROM tbl_spaces_working_calendars " |
|
3645 | " WHERE space_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
3646 | cnx.commit() |
|
3647 | ||
3648 | cursor.close() |
|
3649 | cnx.close() |
|
3650 | ||
3651 | resp.status = falcon.HTTP_204 |
|
3652 | ||
3653 | ||
3654 | class SpaceCommandCollection: |
|
@@ 3222-3282 (lines=61) @@ | ||
3219 | resp.location = '/spaces/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
3220 | ||
3221 | ||
3222 | class SpaceVirtualMeterItem: |
|
3223 | def __init__(self): |
|
3224 | """Initializes Class""" |
|
3225 | pass |
|
3226 | ||
3227 | @staticmethod |
|
3228 | def on_options(req, resp, id_, mid): |
|
3229 | _ = req |
|
3230 | resp.status = falcon.HTTP_200 |
|
3231 | _ = id_ |
|
3232 | ||
3233 | @staticmethod |
|
3234 | @user_logger |
|
3235 | def on_delete(req, resp, id_, mid): |
|
3236 | admin_control(req) |
|
3237 | if not id_.isdigit() or int(id_) <= 0: |
|
3238 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
3239 | description='API.INVALID_SPACE_ID') |
|
3240 | ||
3241 | if not mid.isdigit() or int(mid) <= 0: |
|
3242 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
3243 | description='API.INVALID_VIRTUAL_METER_ID') |
|
3244 | ||
3245 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
3246 | cursor = cnx.cursor() |
|
3247 | ||
3248 | cursor.execute(" SELECT name " |
|
3249 | " FROM tbl_spaces " |
|
3250 | " WHERE id = %s ", (id_,)) |
|
3251 | if cursor.fetchone() is None: |
|
3252 | cursor.close() |
|
3253 | cnx.close() |
|
3254 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3255 | description='API.SPACE_NOT_FOUND') |
|
3256 | ||
3257 | cursor.execute(" SELECT name " |
|
3258 | " FROM tbl_virtual_meters " |
|
3259 | " WHERE id = %s ", (mid,)) |
|
3260 | if cursor.fetchone() is None: |
|
3261 | cursor.close() |
|
3262 | cnx.close() |
|
3263 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3264 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
3265 | ||
3266 | cursor.execute(" SELECT id " |
|
3267 | " FROM tbl_spaces_virtual_meters " |
|
3268 | " WHERE space_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
3269 | if cursor.fetchone() is None: |
|
3270 | cursor.close() |
|
3271 | cnx.close() |
|
3272 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3273 | description='API.SPACE_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
3274 | ||
3275 | cursor.execute(" DELETE FROM tbl_spaces_virtual_meters " |
|
3276 | " WHERE space_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
3277 | cnx.commit() |
|
3278 | ||
3279 | cursor.close() |
|
3280 | cnx.close() |
|
3281 | ||
3282 | resp.status = falcon.HTTP_204 |
|
3283 | ||
3284 | ||
3285 | class SpaceTreeCollection: |
|
@@ 2308-2368 (lines=61) @@ | ||
2305 | resp.location = '/spaces/' + str(id_) + '/points/' + str(point_id) |
|
2306 | ||
2307 | ||
2308 | class SpacePointItem: |
|
2309 | def __init__(self): |
|
2310 | """Initializes Class""" |
|
2311 | pass |
|
2312 | ||
2313 | @staticmethod |
|
2314 | def on_options(req, resp, id_, pid): |
|
2315 | _ = req |
|
2316 | resp.status = falcon.HTTP_200 |
|
2317 | _ = id_ |
|
2318 | ||
2319 | @staticmethod |
|
2320 | @user_logger |
|
2321 | def on_delete(req, resp, id_, pid): |
|
2322 | admin_control(req) |
|
2323 | if not id_.isdigit() or int(id_) <= 0: |
|
2324 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2325 | description='API.INVALID_SPACE_ID') |
|
2326 | ||
2327 | if not pid.isdigit() or int(pid) <= 0: |
|
2328 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2329 | description='API.INVALID_POINT_ID') |
|
2330 | ||
2331 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2332 | cursor = cnx.cursor() |
|
2333 | ||
2334 | cursor.execute(" SELECT name " |
|
2335 | " FROM tbl_spaces " |
|
2336 | " WHERE id = %s ", (id_,)) |
|
2337 | if cursor.fetchone() is None: |
|
2338 | cursor.close() |
|
2339 | cnx.close() |
|
2340 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2341 | description='API.SPACE_NOT_FOUND') |
|
2342 | ||
2343 | cursor.execute(" SELECT name " |
|
2344 | " FROM tbl_points " |
|
2345 | " WHERE id = %s ", (pid,)) |
|
2346 | if cursor.fetchone() is None: |
|
2347 | cursor.close() |
|
2348 | cnx.close() |
|
2349 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2350 | description='API.POINT_NOT_FOUND') |
|
2351 | ||
2352 | cursor.execute(" SELECT id " |
|
2353 | " FROM tbl_spaces_points " |
|
2354 | " WHERE space_id = %s AND point_id = %s ", (id_, pid)) |
|
2355 | if cursor.fetchone() is None: |
|
2356 | cursor.close() |
|
2357 | cnx.close() |
|
2358 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2359 | description='API.SPACE_POINT_RELATION_NOT_FOUND') |
|
2360 | ||
2361 | cursor.execute(" DELETE FROM tbl_spaces_points " |
|
2362 | " WHERE space_id = %s AND point_id = %s ", (id_, pid)) |
|
2363 | cnx.commit() |
|
2364 | ||
2365 | cursor.close() |
|
2366 | cnx.close() |
|
2367 | ||
2368 | resp.status = falcon.HTTP_204 |
|
2369 | ||
2370 | ||
2371 | class SpaceSensorCollection: |
|
@@ 2115-2175 (lines=61) @@ | ||
2112 | resp.location = '/spaces/' + str(id_) + '/photovoltaicpowerstations/' + str(photovoltaic_power_station_id) |
|
2113 | ||
2114 | ||
2115 | class SpacePhotovoltaicPowerStationItem: |
|
2116 | def __init__(self): |
|
2117 | """Initializes Class""" |
|
2118 | pass |
|
2119 | ||
2120 | @staticmethod |
|
2121 | def on_options(req, resp, id_, eid): |
|
2122 | _ = req |
|
2123 | resp.status = falcon.HTTP_200 |
|
2124 | _ = id_ |
|
2125 | ||
2126 | @staticmethod |
|
2127 | @user_logger |
|
2128 | def on_delete(req, resp, id_, eid): |
|
2129 | admin_control(req) |
|
2130 | if not id_.isdigit() or int(id_) <= 0: |
|
2131 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2132 | description='API.INVALID_SPACE_ID') |
|
2133 | ||
2134 | if not eid.isdigit() or int(eid) <= 0: |
|
2135 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2136 | description='API.INVALID_PHOTOVOLTAIC_POWER_STATION_ID') |
|
2137 | ||
2138 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2139 | cursor = cnx.cursor() |
|
2140 | ||
2141 | cursor.execute(" SELECT name " |
|
2142 | " FROM tbl_spaces " |
|
2143 | " WHERE id = %s ", (id_,)) |
|
2144 | if cursor.fetchone() is None: |
|
2145 | cursor.close() |
|
2146 | cnx.close() |
|
2147 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2148 | description='API.SPACE_NOT_FOUND') |
|
2149 | ||
2150 | cursor.execute(" SELECT name " |
|
2151 | " FROM tbl_photovoltaic_power_stations " |
|
2152 | " WHERE id = %s ", (eid,)) |
|
2153 | if cursor.fetchone() is None: |
|
2154 | cursor.close() |
|
2155 | cnx.close() |
|
2156 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2157 | description='API.PHOTOVOLTAIC_POWER_STATION_NOT_FOUND') |
|
2158 | ||
2159 | cursor.execute(" SELECT id " |
|
2160 | " FROM tbl_spaces_photovoltaic_power_stations " |
|
2161 | " WHERE space_id = %s AND photovoltaic_power_station_id = %s ", (id_, eid)) |
|
2162 | if cursor.fetchone() is None: |
|
2163 | cursor.close() |
|
2164 | cnx.close() |
|
2165 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2166 | description='API.SPACE_PHOTOVOLTAIC_POWER_STATION_RELATION_NOT_FOUND') |
|
2167 | ||
2168 | cursor.execute(" DELETE FROM tbl_spaces_photovoltaic_power_stations " |
|
2169 | " WHERE space_id = %s AND photovoltaic_power_station_id = %s ", (id_, eid)) |
|
2170 | cnx.commit() |
|
2171 | ||
2172 | cursor.close() |
|
2173 | cnx.close() |
|
2174 | ||
2175 | resp.status = falcon.HTTP_204 |
|
2176 | ||
2177 | ||
2178 | class SpacePointCollection: |
|
@@ 1934-1994 (lines=61) @@ | ||
1931 | resp.location = '/spaces/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
1932 | ||
1933 | ||
1934 | class SpaceOfflineMeterItem: |
|
1935 | def __init__(self): |
|
1936 | """Initializes Class""" |
|
1937 | pass |
|
1938 | ||
1939 | @staticmethod |
|
1940 | def on_options(req, resp, id_, mid): |
|
1941 | _ = req |
|
1942 | resp.status = falcon.HTTP_200 |
|
1943 | _ = id_ |
|
1944 | ||
1945 | @staticmethod |
|
1946 | @user_logger |
|
1947 | def on_delete(req, resp, id_, mid): |
|
1948 | admin_control(req) |
|
1949 | if not id_.isdigit() or int(id_) <= 0: |
|
1950 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1951 | description='API.INVALID_SPACE_ID') |
|
1952 | ||
1953 | if not mid.isdigit() or int(mid) <= 0: |
|
1954 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1955 | description='API.INVALID_OFFLINE_METER_ID') |
|
1956 | ||
1957 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1958 | cursor = cnx.cursor() |
|
1959 | ||
1960 | cursor.execute(" SELECT name " |
|
1961 | " FROM tbl_spaces " |
|
1962 | " WHERE id = %s ", (id_,)) |
|
1963 | if cursor.fetchone() is None: |
|
1964 | cursor.close() |
|
1965 | cnx.close() |
|
1966 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1967 | description='API.SPACE_NOT_FOUND') |
|
1968 | ||
1969 | cursor.execute(" SELECT name " |
|
1970 | " FROM tbl_offline_meters " |
|
1971 | " WHERE id = %s ", (mid,)) |
|
1972 | if cursor.fetchone() is None: |
|
1973 | cursor.close() |
|
1974 | cnx.close() |
|
1975 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1976 | description='API.OFFLINE_METER_NOT_FOUND') |
|
1977 | ||
1978 | cursor.execute(" SELECT id " |
|
1979 | " FROM tbl_spaces_offline_meters " |
|
1980 | " WHERE space_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1981 | if cursor.fetchone() is None: |
|
1982 | cursor.close() |
|
1983 | cnx.close() |
|
1984 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1985 | description='API.SPACE_OFFLINE_METER_RELATION_NOT_FOUND') |
|
1986 | ||
1987 | cursor.execute(" DELETE FROM tbl_spaces_offline_meters " |
|
1988 | " WHERE space_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1989 | cnx.commit() |
|
1990 | ||
1991 | cursor.close() |
|
1992 | cnx.close() |
|
1993 | ||
1994 | resp.status = falcon.HTTP_204 |
|
1995 | ||
1996 | ||
1997 | class SpacePhotovoltaicPowerStationCollection: |
|
@@ 1740-1800 (lines=61) @@ | ||
1737 | resp.location = '/spaces/' + str(id_) + '/microgrids/' + str(microgrid_id) |
|
1738 | ||
1739 | ||
1740 | class SpaceMicrogridItem: |
|
1741 | def __init__(self): |
|
1742 | """Initializes Class""" |
|
1743 | pass |
|
1744 | ||
1745 | @staticmethod |
|
1746 | def on_options(req, resp, id_, mid): |
|
1747 | _ = req |
|
1748 | resp.status = falcon.HTTP_200 |
|
1749 | _ = id_ |
|
1750 | ||
1751 | @staticmethod |
|
1752 | @user_logger |
|
1753 | def on_delete(req, resp, id_, mid): |
|
1754 | admin_control(req) |
|
1755 | if not id_.isdigit() or int(id_) <= 0: |
|
1756 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1757 | description='API.INVALID_SPACE_ID') |
|
1758 | ||
1759 | if not mid.isdigit() or int(mid) <= 0: |
|
1760 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1761 | description='API.INVALID_MICROGRID_ID') |
|
1762 | ||
1763 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1764 | cursor = cnx.cursor() |
|
1765 | ||
1766 | cursor.execute(" SELECT name " |
|
1767 | " FROM tbl_spaces " |
|
1768 | " WHERE id = %s ", (id_,)) |
|
1769 | if cursor.fetchone() is None: |
|
1770 | cursor.close() |
|
1771 | cnx.close() |
|
1772 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1773 | description='API.SPACE_NOT_FOUND') |
|
1774 | ||
1775 | cursor.execute(" SELECT name " |
|
1776 | " FROM tbl_microgrids " |
|
1777 | " WHERE id = %s ", (mid,)) |
|
1778 | if cursor.fetchone() is None: |
|
1779 | cursor.close() |
|
1780 | cnx.close() |
|
1781 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1782 | description='API.MICROGRID_NOT_FOUND') |
|
1783 | ||
1784 | cursor.execute(" SELECT id " |
|
1785 | " FROM tbl_spaces_microgrids " |
|
1786 | " WHERE space_id = %s AND microgrid_id = %s ", (id_, mid)) |
|
1787 | if cursor.fetchone() is None: |
|
1788 | cursor.close() |
|
1789 | cnx.close() |
|
1790 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1791 | description='API.SPACE_MICROGRID_RELATION_NOT_FOUND') |
|
1792 | ||
1793 | cursor.execute(" DELETE FROM tbl_spaces_microgrids " |
|
1794 | " WHERE space_id = %s AND microgrid_id = %s ", (id_, mid)) |
|
1795 | cnx.commit() |
|
1796 | ||
1797 | cursor.close() |
|
1798 | cnx.close() |
|
1799 | ||
1800 | resp.status = falcon.HTTP_204 |
|
1801 | ||
1802 | ||
1803 | class SpaceOfflineMeterCollection: |
|
@@ 1184-1244 (lines=61) @@ | ||
1181 | resp.location = '/spaces/' + str(id_) + '/energystoragepowerstations/' + str(energy_storage_power_station_id) |
|
1182 | ||
1183 | ||
1184 | class SpaceEnergyStoragePowerStationItem: |
|
1185 | def __init__(self): |
|
1186 | """Initializes Class""" |
|
1187 | pass |
|
1188 | ||
1189 | @staticmethod |
|
1190 | def on_options(req, resp, id_, eid): |
|
1191 | _ = req |
|
1192 | resp.status = falcon.HTTP_200 |
|
1193 | _ = id_ |
|
1194 | ||
1195 | @staticmethod |
|
1196 | @user_logger |
|
1197 | def on_delete(req, resp, id_, eid): |
|
1198 | admin_control(req) |
|
1199 | if not id_.isdigit() or int(id_) <= 0: |
|
1200 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1201 | description='API.INVALID_SPACE_ID') |
|
1202 | ||
1203 | if not eid.isdigit() or int(eid) <= 0: |
|
1204 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1205 | description='API.INVALID_ENERGY_STORAGE_POWER_STATION_ID') |
|
1206 | ||
1207 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1208 | cursor = cnx.cursor() |
|
1209 | ||
1210 | cursor.execute(" SELECT name " |
|
1211 | " FROM tbl_spaces " |
|
1212 | " WHERE id = %s ", (id_,)) |
|
1213 | if cursor.fetchone() is None: |
|
1214 | cursor.close() |
|
1215 | cnx.close() |
|
1216 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1217 | description='API.SPACE_NOT_FOUND') |
|
1218 | ||
1219 | cursor.execute(" SELECT name " |
|
1220 | " FROM tbl_energy_storage_power_stations " |
|
1221 | " WHERE id = %s ", (eid,)) |
|
1222 | if cursor.fetchone() is None: |
|
1223 | cursor.close() |
|
1224 | cnx.close() |
|
1225 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1226 | description='API.ENERGY_STORAGE_POWER_STATION_NOT_FOUND') |
|
1227 | ||
1228 | cursor.execute(" SELECT id " |
|
1229 | " FROM tbl_spaces_energy_storage_power_stations " |
|
1230 | " WHERE space_id = %s AND energy_storage_power_station_id = %s ", (id_, eid)) |
|
1231 | if cursor.fetchone() is None: |
|
1232 | cursor.close() |
|
1233 | cnx.close() |
|
1234 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1235 | description='API.SPACE_ENERGY_STORAGE_POWER_STATION_RELATION_NOT_FOUND') |
|
1236 | ||
1237 | cursor.execute(" DELETE FROM tbl_spaces_energy_storage_power_stations " |
|
1238 | " WHERE space_id = %s AND energy_storage_power_station_id = %s ", (id_, eid)) |
|
1239 | cnx.commit() |
|
1240 | ||
1241 | cursor.close() |
|
1242 | cnx.close() |
|
1243 | ||
1244 | resp.status = falcon.HTTP_204 |
|
1245 | ||
1246 | ||
1247 | class SpaceEquipmentCollection: |
|
@@ 964-1024 (lines=61) @@ | ||
961 | resp.location = '/spaces/' + str(id_) + '/combinedequipments/' + str(combined_equipment_id) |
|
962 | ||
963 | ||
964 | class SpaceCombinedEquipmentItem: |
|
965 | def __init__(self): |
|
966 | """Initializes Class""" |
|
967 | pass |
|
968 | ||
969 | @staticmethod |
|
970 | def on_options(req, resp, id_, eid): |
|
971 | _ = req |
|
972 | resp.status = falcon.HTTP_200 |
|
973 | _ = id_ |
|
974 | ||
975 | @staticmethod |
|
976 | @user_logger |
|
977 | def on_delete(req, resp, id_, eid): |
|
978 | admin_control(req) |
|
979 | if not id_.isdigit() or int(id_) <= 0: |
|
980 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
981 | description='API.INVALID_SPACE_ID') |
|
982 | ||
983 | if not eid.isdigit() or int(eid) <= 0: |
|
984 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
985 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
986 | ||
987 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
988 | cursor = cnx.cursor() |
|
989 | ||
990 | cursor.execute(" SELECT name " |
|
991 | " FROM tbl_spaces " |
|
992 | " WHERE id = %s ", (id_,)) |
|
993 | if cursor.fetchone() is None: |
|
994 | cursor.close() |
|
995 | cnx.close() |
|
996 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
997 | description='API.SPACE_NOT_FOUND') |
|
998 | ||
999 | cursor.execute(" SELECT name " |
|
1000 | " FROM tbl_combined_equipments " |
|
1001 | " WHERE id = %s ", (eid,)) |
|
1002 | if cursor.fetchone() is None: |
|
1003 | cursor.close() |
|
1004 | cnx.close() |
|
1005 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1006 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
1007 | ||
1008 | cursor.execute(" SELECT id " |
|
1009 | " FROM tbl_spaces_combined_equipments " |
|
1010 | " WHERE space_id = %s AND combined_equipment_id = %s ", (id_, eid)) |
|
1011 | if cursor.fetchone() is None: |
|
1012 | cursor.close() |
|
1013 | cnx.close() |
|
1014 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1015 | description='API.SPACE_COMBINED_EQUIPMENT_RELATION_NOT_FOUND') |
|
1016 | ||
1017 | cursor.execute(" DELETE FROM tbl_spaces_combined_equipments " |
|
1018 | " WHERE space_id = %s AND combined_equipment_id = %s ", (id_, eid)) |
|
1019 | cnx.commit() |
|
1020 | ||
1021 | cursor.close() |
|
1022 | cnx.close() |
|
1023 | ||
1024 | resp.status = falcon.HTTP_204 |
|
1025 | ||
1026 | ||
1027 | class SpaceEnergyStoragePowerStationCollection: |
|
@@ 3772-3831 (lines=60) @@ | ||
3769 | resp.location = '/spaces/' + str(id_) + '/commands/' + str(command_id) |
|
3770 | ||
3771 | ||
3772 | class SpaceCommandItem: |
|
3773 | def __init__(self): |
|
3774 | """Initializes Class""" |
|
3775 | pass |
|
3776 | ||
3777 | @staticmethod |
|
3778 | def on_options(req, resp, id_, cid): |
|
3779 | _ = req |
|
3780 | resp.status = falcon.HTTP_200 |
|
3781 | _ = id_ |
|
3782 | ||
3783 | @staticmethod |
|
3784 | @user_logger |
|
3785 | def on_delete(req, resp, id_, cid): |
|
3786 | admin_control(req) |
|
3787 | if not id_.isdigit() or int(id_) <= 0: |
|
3788 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
3789 | description='API.INVALID_SPACE_ID') |
|
3790 | ||
3791 | if not cid.isdigit() or int(cid) <= 0: |
|
3792 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
3793 | description='API.INVALID_COMMAND_ID') |
|
3794 | ||
3795 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
3796 | cursor = cnx.cursor() |
|
3797 | ||
3798 | cursor.execute(" SELECT name " |
|
3799 | " FROM tbl_spaces " |
|
3800 | " WHERE id = %s ", (id_,)) |
|
3801 | if cursor.fetchone() is None: |
|
3802 | cursor.close() |
|
3803 | cnx.close() |
|
3804 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3805 | description='API.SPACE_NOT_FOUND') |
|
3806 | ||
3807 | cursor.execute(" SELECT name " |
|
3808 | " FROM tbl_commands " |
|
3809 | " WHERE id = %s ", (cid,)) |
|
3810 | if cursor.fetchone() is None: |
|
3811 | cursor.close() |
|
3812 | cnx.close() |
|
3813 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3814 | description='API.COMMAND_NOT_FOUND') |
|
3815 | ||
3816 | cursor.execute(" SELECT id " |
|
3817 | " FROM tbl_spaces_commands " |
|
3818 | " WHERE space_id = %s AND command_id = %s ", (id_, cid)) |
|
3819 | if cursor.fetchone() is None: |
|
3820 | cursor.close() |
|
3821 | cnx.close() |
|
3822 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3823 | description='API.SPACE_COMMAND_RELATION_NOT_FOUND') |
|
3824 | ||
3825 | cursor.execute(" DELETE FROM tbl_spaces_commands WHERE space_id = %s AND command_id = %s ", (id_, cid)) |
|
3826 | cnx.commit() |
|
3827 | ||
3828 | cursor.close() |
|
3829 | cnx.close() |
|
3830 | ||
3831 | resp.status = falcon.HTTP_204 |
|
3832 | ||
3833 | ||
3834 | class SpaceExport: |
|
@@ 3029-3088 (lines=60) @@ | ||
3026 | resp.location = '/spaces/' + str(id_) + '/tenants/' + str(tenant_id) |
|
3027 | ||
3028 | ||
3029 | class SpaceTenantItem: |
|
3030 | def __init__(self): |
|
3031 | """Initializes Class""" |
|
3032 | pass |
|
3033 | ||
3034 | @staticmethod |
|
3035 | def on_options(req, resp, id_, tid): |
|
3036 | _ = req |
|
3037 | resp.status = falcon.HTTP_200 |
|
3038 | _ = id_ |
|
3039 | ||
3040 | @staticmethod |
|
3041 | @user_logger |
|
3042 | def on_delete(req, resp, id_, tid): |
|
3043 | admin_control(req) |
|
3044 | if not id_.isdigit() or int(id_) <= 0: |
|
3045 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
3046 | description='API.INVALID_SPACE_ID') |
|
3047 | ||
3048 | if not tid.isdigit() or int(tid) <= 0: |
|
3049 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
3050 | description='API.INVALID_TENANT_ID') |
|
3051 | ||
3052 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
3053 | cursor = cnx.cursor() |
|
3054 | ||
3055 | cursor.execute(" SELECT name " |
|
3056 | " FROM tbl_spaces " |
|
3057 | " WHERE id = %s ", (id_,)) |
|
3058 | if cursor.fetchone() is None: |
|
3059 | cursor.close() |
|
3060 | cnx.close() |
|
3061 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3062 | description='API.SPACE_NOT_FOUND') |
|
3063 | ||
3064 | cursor.execute(" SELECT name " |
|
3065 | " FROM tbl_tenants " |
|
3066 | " WHERE id = %s ", (tid,)) |
|
3067 | if cursor.fetchone() is None: |
|
3068 | cursor.close() |
|
3069 | cnx.close() |
|
3070 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3071 | description='API.TENANT_NOT_FOUND') |
|
3072 | ||
3073 | cursor.execute(" SELECT id " |
|
3074 | " FROM tbl_spaces_tenants " |
|
3075 | " WHERE space_id = %s AND tenant_id = %s ", (id_, tid)) |
|
3076 | if cursor.fetchone() is None: |
|
3077 | cursor.close() |
|
3078 | cnx.close() |
|
3079 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3080 | description='API.SPACE_TENANT_RELATION_NOT_FOUND') |
|
3081 | ||
3082 | cursor.execute(" DELETE FROM tbl_spaces_tenants WHERE space_id = %s AND tenant_id = %s ", (id_, tid)) |
|
3083 | cnx.commit() |
|
3084 | ||
3085 | cursor.close() |
|
3086 | cnx.close() |
|
3087 | ||
3088 | resp.status = falcon.HTTP_204 |
|
3089 | ||
3090 | ||
3091 | class SpaceVirtualMeterCollection: |
|
@@ 2849-2908 (lines=60) @@ | ||
2846 | resp.location = '/spaces/' + str(id_) + '/stores/' + str(store_id) |
|
2847 | ||
2848 | ||
2849 | class SpaceStoreItem: |
|
2850 | def __init__(self): |
|
2851 | """Initializes Class""" |
|
2852 | pass |
|
2853 | ||
2854 | @staticmethod |
|
2855 | def on_options(req, resp, id_, tid): |
|
2856 | _ = req |
|
2857 | resp.status = falcon.HTTP_200 |
|
2858 | _ = id_ |
|
2859 | ||
2860 | @staticmethod |
|
2861 | @user_logger |
|
2862 | def on_delete(req, resp, id_, tid): |
|
2863 | admin_control(req) |
|
2864 | if not id_.isdigit() or int(id_) <= 0: |
|
2865 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2866 | description='API.INVALID_SPACE_ID') |
|
2867 | ||
2868 | if not tid.isdigit() or int(tid) <= 0: |
|
2869 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2870 | description='API.INVALID_STORE_ID') |
|
2871 | ||
2872 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2873 | cursor = cnx.cursor() |
|
2874 | ||
2875 | cursor.execute(" SELECT name " |
|
2876 | " FROM tbl_spaces " |
|
2877 | " WHERE id = %s ", (id_,)) |
|
2878 | if cursor.fetchone() is None: |
|
2879 | cursor.close() |
|
2880 | cnx.close() |
|
2881 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2882 | description='API.SPACE_NOT_FOUND') |
|
2883 | ||
2884 | cursor.execute(" SELECT name " |
|
2885 | " FROM tbl_stores " |
|
2886 | " WHERE id = %s ", (tid,)) |
|
2887 | if cursor.fetchone() is None: |
|
2888 | cursor.close() |
|
2889 | cnx.close() |
|
2890 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2891 | description='API.STORE_NOT_FOUND') |
|
2892 | ||
2893 | cursor.execute(" SELECT id " |
|
2894 | " FROM tbl_spaces_stores " |
|
2895 | " WHERE space_id = %s AND store_id = %s ", (id_, tid)) |
|
2896 | if cursor.fetchone() is None: |
|
2897 | cursor.close() |
|
2898 | cnx.close() |
|
2899 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2900 | description='API.SPACE_STORE_RELATION_NOT_FOUND') |
|
2901 | ||
2902 | cursor.execute(" DELETE FROM tbl_spaces_stores WHERE space_id = %s AND store_id = %s ", (id_, tid)) |
|
2903 | cnx.commit() |
|
2904 | ||
2905 | cursor.close() |
|
2906 | cnx.close() |
|
2907 | ||
2908 | resp.status = falcon.HTTP_204 |
|
2909 | ||
2910 | ||
2911 | class SpaceTenantCollection: |
|
@@ 2669-2728 (lines=60) @@ | ||
2666 | resp.location = '/spaces/' + str(id_) + '/shopfloors/' + str(shopfloor_id) |
|
2667 | ||
2668 | ||
2669 | class SpaceShopfloorItem: |
|
2670 | def __init__(self): |
|
2671 | """Initializes Class""" |
|
2672 | pass |
|
2673 | ||
2674 | @staticmethod |
|
2675 | def on_options(req, resp, id_, sid): |
|
2676 | _ = req |
|
2677 | resp.status = falcon.HTTP_200 |
|
2678 | _ = id_ |
|
2679 | ||
2680 | @staticmethod |
|
2681 | @user_logger |
|
2682 | def on_delete(req, resp, id_, sid): |
|
2683 | admin_control(req) |
|
2684 | if not id_.isdigit() or int(id_) <= 0: |
|
2685 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2686 | description='API.INVALID_SPACE_ID') |
|
2687 | ||
2688 | if not sid.isdigit() or int(sid) <= 0: |
|
2689 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2690 | description='API.INVALID_SHOPFLOOR_ID') |
|
2691 | ||
2692 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2693 | cursor = cnx.cursor() |
|
2694 | ||
2695 | cursor.execute(" SELECT name " |
|
2696 | " FROM tbl_spaces " |
|
2697 | " WHERE id = %s ", (id_,)) |
|
2698 | if cursor.fetchone() is None: |
|
2699 | cursor.close() |
|
2700 | cnx.close() |
|
2701 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2702 | description='API.SPACE_NOT_FOUND') |
|
2703 | ||
2704 | cursor.execute(" SELECT name " |
|
2705 | " FROM tbl_shopfloors " |
|
2706 | " WHERE id = %s ", (sid,)) |
|
2707 | if cursor.fetchone() is None: |
|
2708 | cursor.close() |
|
2709 | cnx.close() |
|
2710 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2711 | description='API.SHOPFLOOR_NOT_FOUND') |
|
2712 | ||
2713 | cursor.execute(" SELECT id " |
|
2714 | " FROM tbl_spaces_shopfloors " |
|
2715 | " WHERE space_id = %s AND shopfloor_id = %s ", (id_, sid)) |
|
2716 | if cursor.fetchone() is None: |
|
2717 | cursor.close() |
|
2718 | cnx.close() |
|
2719 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2720 | description='API.SPACE_SHOPFLOOR_RELATION_NOT_FOUND') |
|
2721 | ||
2722 | cursor.execute(" DELETE FROM tbl_spaces_shopfloors WHERE space_id = %s AND shopfloor_id = %s ", (id_, sid)) |
|
2723 | cnx.commit() |
|
2724 | ||
2725 | cursor.close() |
|
2726 | cnx.close() |
|
2727 | ||
2728 | resp.status = falcon.HTTP_204 |
|
2729 | ||
2730 | ||
2731 | class SpaceStoreCollection: |
|
@@ 2489-2548 (lines=60) @@ | ||
2486 | resp.location = '/spaces/' + str(id_) + '/sensors/' + str(sensor_id) |
|
2487 | ||
2488 | ||
2489 | class SpaceSensorItem: |
|
2490 | def __init__(self): |
|
2491 | """Initializes Class""" |
|
2492 | pass |
|
2493 | ||
2494 | @staticmethod |
|
2495 | def on_options(req, resp, id_, sid): |
|
2496 | _ = req |
|
2497 | resp.status = falcon.HTTP_200 |
|
2498 | _ = id_ |
|
2499 | ||
2500 | @staticmethod |
|
2501 | @user_logger |
|
2502 | def on_delete(req, resp, id_, sid): |
|
2503 | admin_control(req) |
|
2504 | if not id_.isdigit() or int(id_) <= 0: |
|
2505 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2506 | description='API.INVALID_SPACE_ID') |
|
2507 | ||
2508 | if not sid.isdigit() or int(sid) <= 0: |
|
2509 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2510 | description='API.INVALID_SENSOR_ID') |
|
2511 | ||
2512 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2513 | cursor = cnx.cursor() |
|
2514 | ||
2515 | cursor.execute(" SELECT name " |
|
2516 | " FROM tbl_spaces " |
|
2517 | " WHERE id = %s ", (id_,)) |
|
2518 | if cursor.fetchone() is None: |
|
2519 | cursor.close() |
|
2520 | cnx.close() |
|
2521 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2522 | description='API.SPACE_NOT_FOUND') |
|
2523 | ||
2524 | cursor.execute(" SELECT name " |
|
2525 | " FROM tbl_sensors " |
|
2526 | " WHERE id = %s ", (sid,)) |
|
2527 | if cursor.fetchone() is None: |
|
2528 | cursor.close() |
|
2529 | cnx.close() |
|
2530 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2531 | description='API.SENSOR_NOT_FOUND') |
|
2532 | ||
2533 | cursor.execute(" SELECT id " |
|
2534 | " FROM tbl_spaces_sensors " |
|
2535 | " WHERE space_id = %s AND sensor_id = %s ", (id_, sid)) |
|
2536 | if cursor.fetchone() is None: |
|
2537 | cursor.close() |
|
2538 | cnx.close() |
|
2539 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2540 | description='API.SPACE_SENSOR_RELATION_NOT_FOUND') |
|
2541 | ||
2542 | cursor.execute(" DELETE FROM tbl_spaces_sensors WHERE space_id = %s AND sensor_id = %s ", (id_, sid)) |
|
2543 | cnx.commit() |
|
2544 | ||
2545 | cursor.close() |
|
2546 | cnx.close() |
|
2547 | ||
2548 | resp.status = falcon.HTTP_204 |
|
2549 | ||
2550 | ||
2551 | class SpaceShopfloorCollection: |
|
@@ 1365-1424 (lines=60) @@ | ||
1362 | resp.location = '/spaces/' + str(id_) + '/equipments/' + str(equipment_id) |
|
1363 | ||
1364 | ||
1365 | class SpaceEquipmentItem: |
|
1366 | def __init__(self): |
|
1367 | """Initializes Class""" |
|
1368 | pass |
|
1369 | ||
1370 | @staticmethod |
|
1371 | def on_options(req, resp, id_, eid): |
|
1372 | _ = req |
|
1373 | resp.status = falcon.HTTP_200 |
|
1374 | _ = id_ |
|
1375 | ||
1376 | @staticmethod |
|
1377 | @user_logger |
|
1378 | def on_delete(req, resp, id_, eid): |
|
1379 | admin_control(req) |
|
1380 | if not id_.isdigit() or int(id_) <= 0: |
|
1381 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1382 | description='API.INVALID_SPACE_ID') |
|
1383 | ||
1384 | if not eid.isdigit() or int(eid) <= 0: |
|
1385 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1386 | description='API.INVALID_EQUIPMENT_ID') |
|
1387 | ||
1388 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1389 | cursor = cnx.cursor() |
|
1390 | ||
1391 | cursor.execute(" SELECT name " |
|
1392 | " FROM tbl_spaces " |
|
1393 | " WHERE id = %s ", (id_,)) |
|
1394 | if cursor.fetchone() is None: |
|
1395 | cursor.close() |
|
1396 | cnx.close() |
|
1397 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1398 | description='API.SPACE_NOT_FOUND') |
|
1399 | ||
1400 | cursor.execute(" SELECT name " |
|
1401 | " FROM tbl_equipments " |
|
1402 | " WHERE id = %s ", (eid,)) |
|
1403 | if cursor.fetchone() is None: |
|
1404 | cursor.close() |
|
1405 | cnx.close() |
|
1406 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1407 | description='API.EQUIPMENT_NOT_FOUND') |
|
1408 | ||
1409 | cursor.execute(" SELECT id " |
|
1410 | " FROM tbl_spaces_equipments " |
|
1411 | " WHERE space_id = %s AND equipment_id = %s ", (id_, eid)) |
|
1412 | if cursor.fetchone() is None: |
|
1413 | cursor.close() |
|
1414 | cnx.close() |
|
1415 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1416 | description='API.SPACE_EQUIPMENT_RELATION_NOT_FOUND') |
|
1417 | ||
1418 | cursor.execute(" DELETE FROM tbl_spaces_equipments WHERE space_id = %s AND equipment_id = %s ", (id_, eid)) |
|
1419 | cnx.commit() |
|
1420 | ||
1421 | cursor.close() |
|
1422 | cnx.close() |
|
1423 | ||
1424 | resp.status = falcon.HTTP_204 |
|
1425 | ||
1426 | ||
1427 | class SpaceMeterCollection: |
@@ 1192-1253 (lines=62) @@ | ||
1189 | resp.location = '/meters/' + str(id_) + '/points/' + str(new_values['data']['point_id']) |
|
1190 | ||
1191 | ||
1192 | class MeterPointItem: |
|
1193 | def __init__(self): |
|
1194 | """Initializes MeterPointItem""" |
|
1195 | pass |
|
1196 | ||
1197 | @staticmethod |
|
1198 | def on_options(req, resp, id_, pid): |
|
1199 | _ = req |
|
1200 | _ = id_ |
|
1201 | _ = pid |
|
1202 | resp.status = falcon.HTTP_200 |
|
1203 | ||
1204 | @staticmethod |
|
1205 | @user_logger |
|
1206 | def on_delete(req, resp, id_, pid): |
|
1207 | """Handles DELETE requests""" |
|
1208 | admin_control(req) |
|
1209 | if not id_.isdigit() or int(id_) <= 0: |
|
1210 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1211 | description='API.INVALID_METER_ID') |
|
1212 | ||
1213 | if not pid.isdigit() or int(pid) <= 0: |
|
1214 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1215 | description='API.INVALID_POINT_ID') |
|
1216 | ||
1217 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1218 | cursor = cnx.cursor() |
|
1219 | ||
1220 | cursor.execute(" SELECT name " |
|
1221 | " FROM tbl_meters " |
|
1222 | " WHERE id = %s ", (id_,)) |
|
1223 | if cursor.fetchone() is None: |
|
1224 | cursor.close() |
|
1225 | cnx.close() |
|
1226 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1227 | description='API.METER_NOT_FOUND') |
|
1228 | ||
1229 | cursor.execute(" SELECT name " |
|
1230 | " FROM tbl_points " |
|
1231 | " WHERE id = %s ", (pid,)) |
|
1232 | if cursor.fetchone() is None: |
|
1233 | cursor.close() |
|
1234 | cnx.close() |
|
1235 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1236 | description='API.POINT_NOT_FOUND') |
|
1237 | ||
1238 | cursor.execute(" SELECT id " |
|
1239 | " FROM tbl_meters_points " |
|
1240 | " WHERE meter_id = %s AND point_id = %s ", (id_, pid)) |
|
1241 | if cursor.fetchone() is None: |
|
1242 | cursor.close() |
|
1243 | cnx.close() |
|
1244 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1245 | description='API.METER_POINT_RELATION_NOT_FOUND') |
|
1246 | ||
1247 | cursor.execute(" DELETE FROM tbl_meters_points WHERE meter_id = %s AND point_id = %s ", (id_, pid)) |
|
1248 | cnx.commit() |
|
1249 | ||
1250 | cursor.close() |
|
1251 | cnx.close() |
|
1252 | ||
1253 | resp.status = falcon.HTTP_204 |
|
1254 | ||
1255 | ||
1256 | class MeterCommandCollection: |
|
@@ 1374-1434 (lines=61) @@ | ||
1371 | resp.location = '/meters/' + str(id_) + '/commands/' + str(command_id) |
|
1372 | ||
1373 | ||
1374 | class MeterCommandItem: |
|
1375 | def __init__(self): |
|
1376 | """Initializes Class""" |
|
1377 | pass |
|
1378 | ||
1379 | @staticmethod |
|
1380 | def on_options(req, resp, id_, cid): |
|
1381 | _ = req |
|
1382 | _ = id_ |
|
1383 | _ = cid |
|
1384 | resp.status = falcon.HTTP_200 |
|
1385 | ||
1386 | @staticmethod |
|
1387 | @user_logger |
|
1388 | def on_delete(req, resp, id_, cid): |
|
1389 | admin_control(req) |
|
1390 | if not id_.isdigit() or int(id_) <= 0: |
|
1391 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1392 | description='API.INVALID_METER_ID') |
|
1393 | ||
1394 | if not cid.isdigit() or int(cid) <= 0: |
|
1395 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1396 | description='API.INVALID_COMMAND_ID') |
|
1397 | ||
1398 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1399 | cursor = cnx.cursor() |
|
1400 | ||
1401 | cursor.execute(" SELECT name " |
|
1402 | " FROM tbl_meters " |
|
1403 | " WHERE id = %s ", (id_,)) |
|
1404 | if cursor.fetchone() is None: |
|
1405 | cursor.close() |
|
1406 | cnx.close() |
|
1407 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1408 | description='API.METER_NOT_FOUND') |
|
1409 | ||
1410 | cursor.execute(" SELECT name " |
|
1411 | " FROM tbl_commands " |
|
1412 | " WHERE id = %s ", (cid,)) |
|
1413 | if cursor.fetchone() is None: |
|
1414 | cursor.close() |
|
1415 | cnx.close() |
|
1416 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1417 | description='API.COMMAND_NOT_FOUND') |
|
1418 | ||
1419 | cursor.execute(" SELECT id " |
|
1420 | " FROM tbl_meters_commands " |
|
1421 | " WHERE meter_id = %s AND command_id = %s ", (id_, cid)) |
|
1422 | if cursor.fetchone() is None: |
|
1423 | cursor.close() |
|
1424 | cnx.close() |
|
1425 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1426 | description='API.METER_COMMAND_RELATION_NOT_FOUND') |
|
1427 | ||
1428 | cursor.execute(" DELETE FROM tbl_meters_commands WHERE meter_id = %s AND command_id = %s ", (id_, cid)) |
|
1429 | cnx.commit() |
|
1430 | ||
1431 | cursor.close() |
|
1432 | cnx.close() |
|
1433 | ||
1434 | resp.status = falcon.HTTP_204 |
|
1435 | ||
1436 | ||
1437 | class MeterExport: |
@@ 586-647 (lines=62) @@ | ||
583 | resp.location = '/costcenters/' + str(id_) + '/tariffs/' + str(new_values['data']['tariff_id']) |
|
584 | ||
585 | ||
586 | class CostCenterTariffItem: |
|
587 | def __init__(self): |
|
588 | """"Initializes CostCenterTariffItem""" |
|
589 | pass |
|
590 | ||
591 | @staticmethod |
|
592 | def on_options(req, resp, id_, tid): |
|
593 | _ = req |
|
594 | resp.status = falcon.HTTP_200 |
|
595 | _ = id_ |
|
596 | ||
597 | @staticmethod |
|
598 | @user_logger |
|
599 | def on_delete(req, resp, id_, tid): |
|
600 | """Handles DELETE requests""" |
|
601 | admin_control(req) |
|
602 | if not id_.isdigit() or int(id_) <= 0: |
|
603 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
604 | description='API.INVALID_COST_CENTER_ID') |
|
605 | ||
606 | if not tid.isdigit() or int(tid) <= 0: |
|
607 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
608 | description='API.INVALID_TARIFF_ID') |
|
609 | ||
610 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
611 | cursor = cnx.cursor() |
|
612 | ||
613 | cursor.execute(" SELECT name " |
|
614 | " FROM tbl_cost_centers " |
|
615 | " WHERE id = %s ", (id_,)) |
|
616 | if cursor.fetchone() is None: |
|
617 | cursor.close() |
|
618 | cnx.close() |
|
619 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
620 | description='API.COST_CENTER_NOT_FOUND') |
|
621 | ||
622 | cursor.execute(" SELECT name " |
|
623 | " FROM tbl_tariffs " |
|
624 | " WHERE id = %s ", (tid,)) |
|
625 | if cursor.fetchone() is None: |
|
626 | cursor.close() |
|
627 | cnx.close() |
|
628 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
629 | description='API.TARIFF_NOT_FOUND') |
|
630 | ||
631 | cursor.execute(" SELECT id " |
|
632 | " FROM tbl_cost_centers_tariffs " |
|
633 | " WHERE cost_center_id = %s AND tariff_id = %s ", (id_, tid)) |
|
634 | if cursor.fetchone() is None: |
|
635 | cursor.close() |
|
636 | cnx.close() |
|
637 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
638 | description='API.TARIFF_IS_NOT_ASSOCIATED_WITH_COST_CENTER') |
|
639 | ||
640 | cursor.execute(" DELETE FROM tbl_cost_centers_tariffs " |
|
641 | " WHERE cost_center_id = %s AND tariff_id = %s ", (id_, tid)) |
|
642 | cnx.commit() |
|
643 | ||
644 | cursor.close() |
|
645 | cnx.close() |
|
646 | ||
647 | resp.status = falcon.HTTP_204 |
|
648 |
@@ 2247-2307 (lines=61) @@ | ||
2244 | resp.location = '/combinedequipments/' + str(id_) + '/commands/' + str(command_id) |
|
2245 | ||
2246 | ||
2247 | class CombinedEquipmentCommandItem: |
|
2248 | def __init__(self): |
|
2249 | """Initializes Class""" |
|
2250 | pass |
|
2251 | ||
2252 | @staticmethod |
|
2253 | def on_options(req, resp, id_, cid): |
|
2254 | _ = req |
|
2255 | resp.status = falcon.HTTP_200 |
|
2256 | _ = id_ |
|
2257 | ||
2258 | @staticmethod |
|
2259 | @user_logger |
|
2260 | def on_delete(req, resp, id_, cid): |
|
2261 | admin_control(req) |
|
2262 | if not id_.isdigit() or int(id_) <= 0: |
|
2263 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2264 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
2265 | ||
2266 | if not cid.isdigit() or int(cid) <= 0: |
|
2267 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2268 | description='API.INVALID_COMMAND_ID') |
|
2269 | ||
2270 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2271 | cursor = cnx.cursor() |
|
2272 | ||
2273 | cursor.execute(" SELECT name " |
|
2274 | " FROM tbl_combined_equipments " |
|
2275 | " WHERE id = %s ", (id_,)) |
|
2276 | if cursor.fetchone() is None: |
|
2277 | cursor.close() |
|
2278 | cnx.close() |
|
2279 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2280 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
2281 | ||
2282 | cursor.execute(" SELECT name " |
|
2283 | " FROM tbl_commands " |
|
2284 | " WHERE id = %s ", (cid,)) |
|
2285 | if cursor.fetchone() is None: |
|
2286 | cursor.close() |
|
2287 | cnx.close() |
|
2288 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2289 | description='API.COMMAND_NOT_FOUND') |
|
2290 | ||
2291 | cursor.execute(" SELECT id " |
|
2292 | " FROM tbl_combined_equipments_commands " |
|
2293 | " WHERE combined_equipment_id = %s AND command_id = %s ", (id_, cid)) |
|
2294 | if cursor.fetchone() is None: |
|
2295 | cursor.close() |
|
2296 | cnx.close() |
|
2297 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2298 | description='API.COMBINED_EQUIPMENT_COMMAND_RELATION_NOT_FOUND') |
|
2299 | ||
2300 | cursor.execute(" DELETE FROM tbl_combined_equipments_commands " |
|
2301 | " WHERE combined_equipment_id = %s AND command_id = %s ", (id_, cid)) |
|
2302 | cnx.commit() |
|
2303 | ||
2304 | cursor.close() |
|
2305 | cnx.close() |
|
2306 | ||
2307 | resp.status = falcon.HTTP_204 |
|
2308 | ||
2309 | ||
2310 | class CombinedEquipmentExport: |
|
@@ 2066-2126 (lines=61) @@ | ||
2063 | resp.location = '/combinedequipments/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
2064 | ||
2065 | ||
2066 | class CombinedEquipmentVirtualMeterItem: |
|
2067 | def __init__(self): |
|
2068 | """"Initializes CombinedEquipmentVirtualMeterItem""" |
|
2069 | pass |
|
2070 | ||
2071 | @staticmethod |
|
2072 | def on_options(req, resp, id_, mid): |
|
2073 | _ = req |
|
2074 | resp.status = falcon.HTTP_200 |
|
2075 | _ = id_ |
|
2076 | ||
2077 | @staticmethod |
|
2078 | @user_logger |
|
2079 | def on_delete(req, resp, id_, mid): |
|
2080 | admin_control(req) |
|
2081 | if not id_.isdigit() or int(id_) <= 0: |
|
2082 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2083 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
2084 | ||
2085 | if not mid.isdigit() or int(mid) <= 0: |
|
2086 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2087 | description='API.INVALID_VIRTUAL_METER_ID') |
|
2088 | ||
2089 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2090 | cursor = cnx.cursor() |
|
2091 | ||
2092 | cursor.execute(" SELECT name " |
|
2093 | " FROM tbl_combined_equipments " |
|
2094 | " WHERE id = %s ", (id_,)) |
|
2095 | if cursor.fetchone() is None: |
|
2096 | cursor.close() |
|
2097 | cnx.close() |
|
2098 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2099 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
2100 | ||
2101 | cursor.execute(" SELECT name " |
|
2102 | " FROM tbl_virtual_meters " |
|
2103 | " WHERE id = %s ", (mid,)) |
|
2104 | if cursor.fetchone() is None: |
|
2105 | cursor.close() |
|
2106 | cnx.close() |
|
2107 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2108 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
2109 | ||
2110 | cursor.execute(" SELECT id " |
|
2111 | " FROM tbl_combined_equipments_virtual_meters " |
|
2112 | " WHERE combined_equipment_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
2113 | if cursor.fetchone() is None: |
|
2114 | cursor.close() |
|
2115 | cnx.close() |
|
2116 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2117 | description='API.COMBINED_EQUIPMENT_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
2118 | ||
2119 | cursor.execute(" DELETE FROM tbl_combined_equipments_virtual_meters " |
|
2120 | " WHERE combined_equipment_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
2121 | cnx.commit() |
|
2122 | ||
2123 | cursor.close() |
|
2124 | cnx.close() |
|
2125 | ||
2126 | resp.status = falcon.HTTP_204 |
|
2127 | ||
2128 | ||
2129 | class CombinedEquipmentCommandCollection: |
|
@@ 1862-1922 (lines=61) @@ | ||
1859 | resp.location = '/combinedequipments/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
1860 | ||
1861 | ||
1862 | class CombinedEquipmentOfflineMeterItem: |
|
1863 | def __init__(self): |
|
1864 | """"Initializes CombinedEquipmentOfflineMeterItem""" |
|
1865 | pass |
|
1866 | ||
1867 | @staticmethod |
|
1868 | def on_options(req, resp, id_, mid): |
|
1869 | _ = req |
|
1870 | resp.status = falcon.HTTP_200 |
|
1871 | _ = id_ |
|
1872 | ||
1873 | @staticmethod |
|
1874 | @user_logger |
|
1875 | def on_delete(req, resp, id_, mid): |
|
1876 | admin_control(req) |
|
1877 | if not id_.isdigit() or int(id_) <= 0: |
|
1878 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1879 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
1880 | ||
1881 | if not mid.isdigit() or int(mid) <= 0: |
|
1882 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1883 | description='API.INVALID_OFFLINE_METER_ID') |
|
1884 | ||
1885 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1886 | cursor = cnx.cursor() |
|
1887 | ||
1888 | cursor.execute(" SELECT name " |
|
1889 | " FROM tbl_combined_equipments " |
|
1890 | " WHERE id = %s ", (id_,)) |
|
1891 | if cursor.fetchone() is None: |
|
1892 | cursor.close() |
|
1893 | cnx.close() |
|
1894 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1895 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
1896 | ||
1897 | cursor.execute(" SELECT name " |
|
1898 | " FROM tbl_offline_meters " |
|
1899 | " WHERE id = %s ", (mid,)) |
|
1900 | if cursor.fetchone() is None: |
|
1901 | cursor.close() |
|
1902 | cnx.close() |
|
1903 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1904 | description='API.OFFLINE_METER_NOT_FOUND') |
|
1905 | ||
1906 | cursor.execute(" SELECT id " |
|
1907 | " FROM tbl_combined_equipments_offline_meters " |
|
1908 | " WHERE combined_equipment_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1909 | if cursor.fetchone() is None: |
|
1910 | cursor.close() |
|
1911 | cnx.close() |
|
1912 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1913 | description='API.COMBINED_EQUIPMENT_OFFLINE_METER_RELATION_NOT_FOUND') |
|
1914 | ||
1915 | cursor.execute(" DELETE FROM tbl_combined_equipments_offline_meters " |
|
1916 | " WHERE combined_equipment_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1917 | cnx.commit() |
|
1918 | ||
1919 | cursor.close() |
|
1920 | cnx.close() |
|
1921 | ||
1922 | resp.status = falcon.HTTP_204 |
|
1923 | ||
1924 | ||
1925 | class CombinedEquipmentVirtualMeterCollection: |
|
@@ 1657-1717 (lines=61) @@ | ||
1654 | resp.location = '/combinedequipments/' + str(id_) + '/meters/' + str(meter_id) |
|
1655 | ||
1656 | ||
1657 | class CombinedEquipmentMeterItem: |
|
1658 | def __init__(self): |
|
1659 | """"Initializes CombinedEquipmentMeterItem""" |
|
1660 | pass |
|
1661 | ||
1662 | @staticmethod |
|
1663 | def on_options(req, resp, id_, mid): |
|
1664 | _ = req |
|
1665 | resp.status = falcon.HTTP_200 |
|
1666 | _ = id_ |
|
1667 | ||
1668 | @staticmethod |
|
1669 | @user_logger |
|
1670 | def on_delete(req, resp, id_, mid): |
|
1671 | admin_control(req) |
|
1672 | if not id_.isdigit() or int(id_) <= 0: |
|
1673 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1674 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
1675 | ||
1676 | if not mid.isdigit() or int(mid) <= 0: |
|
1677 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1678 | description='API.INVALID_METER_ID') |
|
1679 | ||
1680 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1681 | cursor = cnx.cursor() |
|
1682 | ||
1683 | cursor.execute(" SELECT name " |
|
1684 | " FROM tbl_combined_equipments " |
|
1685 | " WHERE id = %s ", (id_,)) |
|
1686 | if cursor.fetchone() is None: |
|
1687 | cursor.close() |
|
1688 | cnx.close() |
|
1689 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1690 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
1691 | ||
1692 | cursor.execute(" SELECT name " |
|
1693 | " FROM tbl_meters " |
|
1694 | " WHERE id = %s ", (mid,)) |
|
1695 | if cursor.fetchone() is None: |
|
1696 | cursor.close() |
|
1697 | cnx.close() |
|
1698 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1699 | description='API.METER_NOT_FOUND') |
|
1700 | ||
1701 | cursor.execute(" SELECT id " |
|
1702 | " FROM tbl_combined_equipments_meters " |
|
1703 | " WHERE combined_equipment_id = %s AND meter_id = %s ", (id_, mid)) |
|
1704 | if cursor.fetchone() is None: |
|
1705 | cursor.close() |
|
1706 | cnx.close() |
|
1707 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1708 | description='API.COMBINED_EQUIPMENT_METER_RELATION_NOT_FOUND') |
|
1709 | ||
1710 | cursor.execute(" DELETE FROM tbl_combined_equipments_meters " |
|
1711 | " WHERE combined_equipment_id = %s AND meter_id = %s ", (id_, mid)) |
|
1712 | cnx.commit() |
|
1713 | ||
1714 | cursor.close() |
|
1715 | cnx.close() |
|
1716 | ||
1717 | resp.status = falcon.HTTP_204 |
|
1718 | ||
1719 | ||
1720 | class CombinedEquipmentOfflineMeterCollection: |
|
@@ 721-781 (lines=61) @@ | ||
718 | resp.location = '/combinedequipments/' + str(id_) + '/equipments/' + str(equipment_id) |
|
719 | ||
720 | ||
721 | class CombinedEquipmentEquipmentItem: |
|
722 | def __init__(self): |
|
723 | """Initializes CombinedEquipmentEquipmentItem""" |
|
724 | pass |
|
725 | ||
726 | @staticmethod |
|
727 | def on_options(req, resp, id_, eid): |
|
728 | _ = req |
|
729 | resp.status = falcon.HTTP_200 |
|
730 | _ = id_ |
|
731 | ||
732 | @staticmethod |
|
733 | @user_logger |
|
734 | def on_delete(req, resp, id_, eid): |
|
735 | admin_control(req) |
|
736 | if not id_.isdigit() or int(id_) <= 0: |
|
737 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
738 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
739 | ||
740 | if not eid.isdigit() or int(eid) <= 0: |
|
741 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
742 | description='API.INVALID_EQUIPMENT_ID') |
|
743 | ||
744 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
745 | cursor = cnx.cursor() |
|
746 | ||
747 | cursor.execute(" SELECT name " |
|
748 | " FROM tbl_combined_equipments " |
|
749 | " WHERE id = %s ", (id_,)) |
|
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.COMBINED_EQUIPMENT_NOT_FOUND') |
|
755 | ||
756 | cursor.execute(" SELECT name " |
|
757 | " FROM tbl_equipments " |
|
758 | " WHERE id = %s ", (eid,)) |
|
759 | if cursor.fetchone() is None: |
|
760 | cursor.close() |
|
761 | cnx.close() |
|
762 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
763 | description='API.EQUIPMENT_NOT_FOUND') |
|
764 | ||
765 | cursor.execute(" SELECT id " |
|
766 | " FROM tbl_combined_equipments_equipments " |
|
767 | " WHERE combined_equipment_id = %s AND equipment_id = %s ", (id_, eid)) |
|
768 | if cursor.fetchone() is None: |
|
769 | cursor.close() |
|
770 | cnx.close() |
|
771 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
772 | description='API.COMBINED_EQUIPMENT_EQUIPMENT_RELATION_NOT_FOUND') |
|
773 | ||
774 | cursor.execute(" DELETE FROM tbl_combined_equipments_equipments " |
|
775 | " WHERE combined_equipment_id = %s AND equipment_id = %s ", (id_, eid)) |
|
776 | cnx.commit() |
|
777 | ||
778 | cursor.close() |
|
779 | cnx.close() |
|
780 | ||
781 | resp.status = falcon.HTTP_204 |
|
782 | ||
783 | ||
784 | class CombinedEquipmentParameterCollection: |
@@ 1764-1824 (lines=61) @@ | ||
1761 | resp.location = '/tenants/' + str(id_) + '/workingcalendars/' + str(working_calendar_id) |
|
1762 | ||
1763 | ||
1764 | class TenantWorkingCalendarItem: |
|
1765 | def __init__(self): |
|
1766 | """Initializes TenantWorkingCalendarItem Class""" |
|
1767 | pass |
|
1768 | ||
1769 | @staticmethod |
|
1770 | def on_options(req, resp, id_, wcid): |
|
1771 | _ = req |
|
1772 | resp.status = falcon.HTTP_200 |
|
1773 | _ = id_ |
|
1774 | ||
1775 | @staticmethod |
|
1776 | @user_logger |
|
1777 | def on_delete(req, resp, id_, wcid): |
|
1778 | admin_control(req) |
|
1779 | if not id_.isdigit() or int(id_) <= 0: |
|
1780 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1781 | description='API.INVALID_TENANT_ID') |
|
1782 | ||
1783 | if not wcid.isdigit() or int(wcid) <= 0: |
|
1784 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1785 | description='API.INVALID_WORKING_CALENDAR_ID') |
|
1786 | ||
1787 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1788 | cursor = cnx.cursor() |
|
1789 | ||
1790 | cursor.execute(" SELECT name " |
|
1791 | " FROM tbl_tenants " |
|
1792 | " WHERE id = %s ", (id_,)) |
|
1793 | if cursor.fetchone() is None: |
|
1794 | cursor.close() |
|
1795 | cnx.close() |
|
1796 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1797 | description='API.TENANT_NOT_FOUND') |
|
1798 | ||
1799 | cursor.execute(" SELECT name " |
|
1800 | " FROM tbl_working_calendars " |
|
1801 | " WHERE id = %s ", (wcid,)) |
|
1802 | if cursor.fetchone() is None: |
|
1803 | cursor.close() |
|
1804 | cnx.close() |
|
1805 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1806 | description='API.WORKING_CALENDAR_NOT_FOUND') |
|
1807 | ||
1808 | cursor.execute(" SELECT id " |
|
1809 | " FROM tbl_tenants_working_calendars " |
|
1810 | " WHERE tenant_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
1811 | if cursor.fetchone() is None: |
|
1812 | cursor.close() |
|
1813 | cnx.close() |
|
1814 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1815 | description='API.TENANT_WORKING_CALENDAR_RELATION_NOT_FOUND') |
|
1816 | ||
1817 | cursor.execute(" DELETE FROM tbl_tenants_working_calendars " |
|
1818 | " WHERE tenant_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
1819 | cnx.commit() |
|
1820 | ||
1821 | cursor.close() |
|
1822 | cnx.close() |
|
1823 | ||
1824 | resp.status = falcon.HTTP_204 |
|
1825 | ||
1826 | ||
1827 | class TenantCommandCollection: |
|
@@ 1581-1641 (lines=61) @@ | ||
1578 | resp.location = '/tenants/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
1579 | ||
1580 | ||
1581 | class TenantVirtualMeterItem: |
|
1582 | def __init__(self): |
|
1583 | """Initializes Class""" |
|
1584 | pass |
|
1585 | ||
1586 | @staticmethod |
|
1587 | def on_options(req, resp, id_, mid): |
|
1588 | _ = req |
|
1589 | resp.status = falcon.HTTP_200 |
|
1590 | _ = id_ |
|
1591 | ||
1592 | @staticmethod |
|
1593 | @user_logger |
|
1594 | def on_delete(req, resp, id_, mid): |
|
1595 | admin_control(req) |
|
1596 | if not id_.isdigit() or int(id_) <= 0: |
|
1597 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1598 | description='API.INVALID_TENANT_ID') |
|
1599 | ||
1600 | if not mid.isdigit() or int(mid) <= 0: |
|
1601 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1602 | description='API.INVALID_VIRTUAL_METER_ID') |
|
1603 | ||
1604 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1605 | cursor = cnx.cursor() |
|
1606 | ||
1607 | cursor.execute(" SELECT name " |
|
1608 | " FROM tbl_tenants " |
|
1609 | " WHERE id = %s ", (id_,)) |
|
1610 | if cursor.fetchone() is None: |
|
1611 | cursor.close() |
|
1612 | cnx.close() |
|
1613 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1614 | description='API.TENANT_NOT_FOUND') |
|
1615 | ||
1616 | cursor.execute(" SELECT name " |
|
1617 | " FROM tbl_virtual_meters " |
|
1618 | " WHERE id = %s ", (mid,)) |
|
1619 | if cursor.fetchone() is None: |
|
1620 | cursor.close() |
|
1621 | cnx.close() |
|
1622 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1623 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
1624 | ||
1625 | cursor.execute(" SELECT id " |
|
1626 | " FROM tbl_tenants_virtual_meters " |
|
1627 | " WHERE tenant_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1628 | if cursor.fetchone() is None: |
|
1629 | cursor.close() |
|
1630 | cnx.close() |
|
1631 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1632 | description='API.TENANT_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
1633 | ||
1634 | cursor.execute(" DELETE FROM tbl_tenants_virtual_meters " |
|
1635 | " WHERE tenant_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1636 | cnx.commit() |
|
1637 | ||
1638 | cursor.close() |
|
1639 | cnx.close() |
|
1640 | ||
1641 | resp.status = falcon.HTTP_204 |
|
1642 | ||
1643 | ||
1644 | class TenantWorkingCalendarCollection: |
|
@@ 1203-1263 (lines=61) @@ | ||
1200 | resp.location = '/tenants/' + str(id_) + '/points/' + str(point_id) |
|
1201 | ||
1202 | ||
1203 | class TenantPointItem: |
|
1204 | def __init__(self): |
|
1205 | """Initializes Class""" |
|
1206 | pass |
|
1207 | ||
1208 | @staticmethod |
|
1209 | def on_options(req, resp, id_, pid): |
|
1210 | _ = req |
|
1211 | resp.status = falcon.HTTP_200 |
|
1212 | _ = id_ |
|
1213 | ||
1214 | @staticmethod |
|
1215 | @user_logger |
|
1216 | def on_delete(req, resp, id_, pid): |
|
1217 | admin_control(req) |
|
1218 | if not id_.isdigit() or int(id_) <= 0: |
|
1219 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1220 | description='API.INVALID_TENANT_ID') |
|
1221 | ||
1222 | if not pid.isdigit() or int(pid) <= 0: |
|
1223 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1224 | description='API.INVALID_POINT_ID') |
|
1225 | ||
1226 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1227 | cursor = cnx.cursor() |
|
1228 | ||
1229 | cursor.execute(" SELECT name " |
|
1230 | " FROM tbl_tenants " |
|
1231 | " WHERE id = %s ", (id_,)) |
|
1232 | if cursor.fetchone() is None: |
|
1233 | cursor.close() |
|
1234 | cnx.close() |
|
1235 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1236 | description='API.TENANT_NOT_FOUND') |
|
1237 | ||
1238 | cursor.execute(" SELECT name " |
|
1239 | " FROM tbl_points " |
|
1240 | " WHERE id = %s ", (pid,)) |
|
1241 | if cursor.fetchone() is None: |
|
1242 | cursor.close() |
|
1243 | cnx.close() |
|
1244 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1245 | description='API.POINT_NOT_FOUND') |
|
1246 | ||
1247 | cursor.execute(" SELECT id " |
|
1248 | " FROM tbl_tenants_points " |
|
1249 | " WHERE tenant_id = %s AND point_id = %s ", (id_, pid)) |
|
1250 | if cursor.fetchone() is None: |
|
1251 | cursor.close() |
|
1252 | cnx.close() |
|
1253 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1254 | description='API.TENANT_POINT_RELATION_NOT_FOUND') |
|
1255 | ||
1256 | cursor.execute(" DELETE FROM tbl_tenants_points " |
|
1257 | " WHERE tenant_id = %s AND point_id = %s ", (id_, pid)) |
|
1258 | cnx.commit() |
|
1259 | ||
1260 | cursor.close() |
|
1261 | cnx.close() |
|
1262 | ||
1263 | resp.status = falcon.HTTP_204 |
|
1264 | ||
1265 | ||
1266 | class TenantSensorCollection: |
|
@@ 1008-1068 (lines=61) @@ | ||
1005 | resp.location = '/tenants/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
1006 | ||
1007 | ||
1008 | class TenantOfflineMeterItem: |
|
1009 | def __init__(self): |
|
1010 | """Initializes Class""" |
|
1011 | pass |
|
1012 | ||
1013 | @staticmethod |
|
1014 | def on_options(req, resp, id_, mid): |
|
1015 | _ = req |
|
1016 | resp.status = falcon.HTTP_200 |
|
1017 | _ = id_ |
|
1018 | ||
1019 | @staticmethod |
|
1020 | @user_logger |
|
1021 | def on_delete(req, resp, id_, mid): |
|
1022 | admin_control(req) |
|
1023 | if not id_.isdigit() or int(id_) <= 0: |
|
1024 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1025 | description='API.INVALID_TENANT_ID') |
|
1026 | ||
1027 | if not mid.isdigit() or int(mid) <= 0: |
|
1028 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1029 | description='API.INVALID_OFFLINE_METER_ID') |
|
1030 | ||
1031 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1032 | cursor = cnx.cursor() |
|
1033 | ||
1034 | cursor.execute(" SELECT name " |
|
1035 | " FROM tbl_tenants " |
|
1036 | " WHERE id = %s ", (id_,)) |
|
1037 | if cursor.fetchone() is None: |
|
1038 | cursor.close() |
|
1039 | cnx.close() |
|
1040 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1041 | description='API.TENANT_NOT_FOUND') |
|
1042 | ||
1043 | cursor.execute(" SELECT name " |
|
1044 | " FROM tbl_offline_meters " |
|
1045 | " WHERE id = %s ", (mid,)) |
|
1046 | if cursor.fetchone() is None: |
|
1047 | cursor.close() |
|
1048 | cnx.close() |
|
1049 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1050 | description='API.OFFLINE_METER_NOT_FOUND') |
|
1051 | ||
1052 | cursor.execute(" SELECT id " |
|
1053 | " FROM tbl_tenants_offline_meters " |
|
1054 | " WHERE tenant_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1055 | if cursor.fetchone() is None: |
|
1056 | cursor.close() |
|
1057 | cnx.close() |
|
1058 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1059 | description='API.TENANT_OFFLINE_METER_RELATION_NOT_FOUND') |
|
1060 | ||
1061 | cursor.execute(" DELETE FROM tbl_tenants_offline_meters " |
|
1062 | " WHERE tenant_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1063 | cnx.commit() |
|
1064 | ||
1065 | cursor.close() |
|
1066 | cnx.close() |
|
1067 | ||
1068 | resp.status = falcon.HTTP_204 |
|
1069 | ||
1070 | ||
1071 | class TenantPointCollection: |
|
@@ 1947-2006 (lines=60) @@ | ||
1944 | resp.location = '/tenants/' + str(id_) + '/commands/' + str(command_id) |
|
1945 | ||
1946 | ||
1947 | class TenantCommandItem: |
|
1948 | def __init__(self): |
|
1949 | """Initializes Class""" |
|
1950 | pass |
|
1951 | ||
1952 | @staticmethod |
|
1953 | def on_options(req, resp, id_, cid): |
|
1954 | _ = req |
|
1955 | resp.status = falcon.HTTP_200 |
|
1956 | _ = id_ |
|
1957 | ||
1958 | @staticmethod |
|
1959 | @user_logger |
|
1960 | def on_delete(req, resp, id_, cid): |
|
1961 | admin_control(req) |
|
1962 | if not id_.isdigit() or int(id_) <= 0: |
|
1963 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1964 | description='API.INVALID_TENANT_ID') |
|
1965 | ||
1966 | if not cid.isdigit() or int(cid) <= 0: |
|
1967 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1968 | description='API.INVALID_COMMAND_ID') |
|
1969 | ||
1970 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1971 | cursor = cnx.cursor() |
|
1972 | ||
1973 | cursor.execute(" SELECT name " |
|
1974 | " FROM tbl_tenants " |
|
1975 | " WHERE id = %s ", (id_,)) |
|
1976 | if cursor.fetchone() is None: |
|
1977 | cursor.close() |
|
1978 | cnx.close() |
|
1979 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1980 | description='API.TENANT_NOT_FOUND') |
|
1981 | ||
1982 | cursor.execute(" SELECT name " |
|
1983 | " FROM tbl_commands " |
|
1984 | " WHERE id = %s ", (cid,)) |
|
1985 | if cursor.fetchone() is None: |
|
1986 | cursor.close() |
|
1987 | cnx.close() |
|
1988 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1989 | description='API.COMMAND_NOT_FOUND') |
|
1990 | ||
1991 | cursor.execute(" SELECT id " |
|
1992 | " FROM tbl_tenants_commands " |
|
1993 | " WHERE tenant_id = %s AND command_id = %s ", (id_, cid)) |
|
1994 | if cursor.fetchone() is None: |
|
1995 | cursor.close() |
|
1996 | cnx.close() |
|
1997 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1998 | description='API.TENANT_COMMAND_RELATION_NOT_FOUND') |
|
1999 | ||
2000 | cursor.execute(" DELETE FROM tbl_tenants_commands WHERE tenant_id = %s AND command_id = %s ", (id_, cid)) |
|
2001 | cnx.commit() |
|
2002 | ||
2003 | cursor.close() |
|
2004 | cnx.close() |
|
2005 | ||
2006 | resp.status = falcon.HTTP_204 |
|
2007 | ||
2008 | ||
2009 | class TenantExport: |
|
@@ 1386-1445 (lines=60) @@ | ||
1383 | resp.location = '/tenants/' + str(id_) + '/sensors/' + str(sensor_id) |
|
1384 | ||
1385 | ||
1386 | class TenantSensorItem: |
|
1387 | def __init__(self): |
|
1388 | """Initializes Class""" |
|
1389 | pass |
|
1390 | ||
1391 | @staticmethod |
|
1392 | def on_options(req, resp, id_, sid): |
|
1393 | _ = req |
|
1394 | resp.status = falcon.HTTP_200 |
|
1395 | _ = id_ |
|
1396 | ||
1397 | @staticmethod |
|
1398 | @user_logger |
|
1399 | def on_delete(req, resp, id_, sid): |
|
1400 | admin_control(req) |
|
1401 | if not id_.isdigit() or int(id_) <= 0: |
|
1402 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1403 | description='API.INVALID_TENANT_ID') |
|
1404 | ||
1405 | if not sid.isdigit() or int(sid) <= 0: |
|
1406 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1407 | description='API.INVALID_SENSOR_ID') |
|
1408 | ||
1409 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1410 | cursor = cnx.cursor() |
|
1411 | ||
1412 | cursor.execute(" SELECT name " |
|
1413 | " FROM tbl_tenants " |
|
1414 | " WHERE id = %s ", (id_,)) |
|
1415 | if cursor.fetchone() is None: |
|
1416 | cursor.close() |
|
1417 | cnx.close() |
|
1418 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1419 | description='API.TENANT_NOT_FOUND') |
|
1420 | ||
1421 | cursor.execute(" SELECT name " |
|
1422 | " FROM tbl_sensors " |
|
1423 | " WHERE id = %s ", (sid,)) |
|
1424 | if cursor.fetchone() is None: |
|
1425 | cursor.close() |
|
1426 | cnx.close() |
|
1427 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1428 | description='API.SENSOR_NOT_FOUND') |
|
1429 | ||
1430 | cursor.execute(" SELECT id " |
|
1431 | " FROM tbl_tenants_sensors " |
|
1432 | " WHERE tenant_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1433 | if cursor.fetchone() is None: |
|
1434 | cursor.close() |
|
1435 | cnx.close() |
|
1436 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1437 | description='API.TENANT_SENSOR_RELATION_NOT_FOUND') |
|
1438 | ||
1439 | cursor.execute(" DELETE FROM tbl_tenants_sensors WHERE tenant_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1440 | cnx.commit() |
|
1441 | ||
1442 | cursor.close() |
|
1443 | cnx.close() |
|
1444 | ||
1445 | resp.status = falcon.HTTP_204 |
|
1446 | ||
1447 | ||
1448 | class TenantVirtualMeterCollection: |
|
@@ 813-872 (lines=60) @@ | ||
810 | resp.location = '/tenants/' + str(id_) + '/meters/' + str(meter_id) |
|
811 | ||
812 | ||
813 | class TenantMeterItem: |
|
814 | def __init__(self): |
|
815 | """Initializes Class""" |
|
816 | pass |
|
817 | ||
818 | @staticmethod |
|
819 | def on_options(req, resp, id_, mid): |
|
820 | _ = req |
|
821 | resp.status = falcon.HTTP_200 |
|
822 | _ = id_ |
|
823 | ||
824 | @staticmethod |
|
825 | @user_logger |
|
826 | def on_delete(req, resp, id_, mid): |
|
827 | admin_control(req) |
|
828 | if not id_.isdigit() or int(id_) <= 0: |
|
829 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
830 | description='API.INVALID_TENANT_ID') |
|
831 | ||
832 | if not mid.isdigit() or int(mid) <= 0: |
|
833 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
834 | description='API.INVALID_METER_ID') |
|
835 | ||
836 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
837 | cursor = cnx.cursor() |
|
838 | ||
839 | cursor.execute(" SELECT name " |
|
840 | " FROM tbl_tenants " |
|
841 | " WHERE id = %s ", (id_,)) |
|
842 | if cursor.fetchone() is None: |
|
843 | cursor.close() |
|
844 | cnx.close() |
|
845 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
846 | description='API.TENANT_NOT_FOUND') |
|
847 | ||
848 | cursor.execute(" SELECT name " |
|
849 | " FROM tbl_meters " |
|
850 | " WHERE id = %s ", (mid,)) |
|
851 | if cursor.fetchone() is None: |
|
852 | cursor.close() |
|
853 | cnx.close() |
|
854 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
855 | description='API.METER_NOT_FOUND') |
|
856 | ||
857 | cursor.execute(" SELECT id " |
|
858 | " FROM tbl_tenants_meters " |
|
859 | " WHERE tenant_id = %s AND meter_id = %s ", (id_, mid)) |
|
860 | if cursor.fetchone() is None: |
|
861 | cursor.close() |
|
862 | cnx.close() |
|
863 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
864 | description='API.TENANT_METER_RELATION_NOT_FOUND') |
|
865 | ||
866 | cursor.execute(" DELETE FROM tbl_tenants_meters WHERE tenant_id = %s AND meter_id = %s ", (id_, mid)) |
|
867 | cnx.commit() |
|
868 | ||
869 | cursor.close() |
|
870 | cnx.close() |
|
871 | ||
872 | resp.status = falcon.HTTP_204 |
|
873 | ||
874 | ||
875 | class TenantOfflineMeterCollection: |
@@ 1654-1714 (lines=61) @@ | ||
1651 | resp.location = '/stores/' + str(id_) + '/workingcalendars/' + str(working_calendar_id) |
|
1652 | ||
1653 | ||
1654 | class StoreWorkingCalendarItem: |
|
1655 | def __init__(self): |
|
1656 | """Initializes StoreWorkingCalendarItem Class""" |
|
1657 | pass |
|
1658 | ||
1659 | @staticmethod |
|
1660 | def on_options(req, resp, id_, wcid): |
|
1661 | _ = req |
|
1662 | resp.status = falcon.HTTP_200 |
|
1663 | _ = id_ |
|
1664 | ||
1665 | @staticmethod |
|
1666 | @user_logger |
|
1667 | def on_delete(req, resp, id_, wcid): |
|
1668 | admin_control(req) |
|
1669 | if not id_.isdigit() or int(id_) <= 0: |
|
1670 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1671 | description='API.INVALID_STORE_ID') |
|
1672 | ||
1673 | if not wcid.isdigit() or int(wcid) <= 0: |
|
1674 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1675 | description='API.INVALID_WORKING_CALENDAR_ID') |
|
1676 | ||
1677 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1678 | cursor = cnx.cursor() |
|
1679 | ||
1680 | cursor.execute(" SELECT name " |
|
1681 | " FROM tbl_stores " |
|
1682 | " WHERE id = %s ", (id_,)) |
|
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.STORE_NOT_FOUND') |
|
1688 | ||
1689 | cursor.execute(" SELECT name " |
|
1690 | " FROM tbl_working_calendars " |
|
1691 | " WHERE id = %s ", (wcid,)) |
|
1692 | if cursor.fetchone() is None: |
|
1693 | cursor.close() |
|
1694 | cnx.close() |
|
1695 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1696 | description='API.WORKING_CALENDAR_NOT_FOUND') |
|
1697 | ||
1698 | cursor.execute(" SELECT id " |
|
1699 | " FROM tbl_stores_working_calendars " |
|
1700 | " WHERE store_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
1701 | if cursor.fetchone() is None: |
|
1702 | cursor.close() |
|
1703 | cnx.close() |
|
1704 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1705 | description='API.STORE_WORKING_CALENDAR_RELATION_NOT_FOUND') |
|
1706 | ||
1707 | cursor.execute(" DELETE FROM tbl_stores_working_calendars " |
|
1708 | " WHERE store_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
1709 | cnx.commit() |
|
1710 | ||
1711 | cursor.close() |
|
1712 | cnx.close() |
|
1713 | ||
1714 | resp.status = falcon.HTTP_204 |
|
1715 | ||
1716 | ||
1717 | class StoreCommandCollection: |
|
@@ 1473-1533 (lines=61) @@ | ||
1470 | resp.location = '/stores/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
1471 | ||
1472 | ||
1473 | class StoreVirtualMeterItem: |
|
1474 | def __init__(self): |
|
1475 | """Initializes Class""" |
|
1476 | pass |
|
1477 | ||
1478 | @staticmethod |
|
1479 | def on_options(req, resp, id_, mid): |
|
1480 | _ = req |
|
1481 | resp.status = falcon.HTTP_200 |
|
1482 | _ = id_ |
|
1483 | ||
1484 | @staticmethod |
|
1485 | @user_logger |
|
1486 | def on_delete(req, resp, id_, mid): |
|
1487 | admin_control(req) |
|
1488 | if not id_.isdigit() or int(id_) <= 0: |
|
1489 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1490 | description='API.INVALID_STORE_ID') |
|
1491 | ||
1492 | if not mid.isdigit() or int(mid) <= 0: |
|
1493 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1494 | description='API.INVALID_VIRTUAL_METER_ID') |
|
1495 | ||
1496 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1497 | cursor = cnx.cursor() |
|
1498 | ||
1499 | cursor.execute(" SELECT name " |
|
1500 | " FROM tbl_stores " |
|
1501 | " WHERE id = %s ", (id_,)) |
|
1502 | if cursor.fetchone() is None: |
|
1503 | cursor.close() |
|
1504 | cnx.close() |
|
1505 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1506 | description='API.STORE_NOT_FOUND') |
|
1507 | ||
1508 | cursor.execute(" SELECT name " |
|
1509 | " FROM tbl_virtual_meters " |
|
1510 | " WHERE id = %s ", (mid,)) |
|
1511 | if cursor.fetchone() is None: |
|
1512 | cursor.close() |
|
1513 | cnx.close() |
|
1514 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1515 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
1516 | ||
1517 | cursor.execute(" SELECT id " |
|
1518 | " FROM tbl_stores_virtual_meters " |
|
1519 | " WHERE store_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1520 | if cursor.fetchone() is None: |
|
1521 | cursor.close() |
|
1522 | cnx.close() |
|
1523 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1524 | description='API.STORE_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
1525 | ||
1526 | cursor.execute(" DELETE FROM tbl_stores_virtual_meters " |
|
1527 | " WHERE store_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1528 | cnx.commit() |
|
1529 | ||
1530 | cursor.close() |
|
1531 | cnx.close() |
|
1532 | ||
1533 | resp.status = falcon.HTTP_204 |
|
1534 | ||
1535 | ||
1536 | class StoreWorkingCalendarCollection: |
|
@@ 1099-1159 (lines=61) @@ | ||
1096 | resp.location = '/stores/' + str(id_) + '/points/' + str(point_id) |
|
1097 | ||
1098 | ||
1099 | class StorePointItem: |
|
1100 | def __init__(self): |
|
1101 | """Initializes Class""" |
|
1102 | pass |
|
1103 | ||
1104 | @staticmethod |
|
1105 | def on_options(req, resp, id_, pid): |
|
1106 | _ = req |
|
1107 | resp.status = falcon.HTTP_200 |
|
1108 | _ = id_ |
|
1109 | ||
1110 | @staticmethod |
|
1111 | @user_logger |
|
1112 | def on_delete(req, resp, id_, pid): |
|
1113 | admin_control(req) |
|
1114 | if not id_.isdigit() or int(id_) <= 0: |
|
1115 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1116 | description='API.INVALID_STORE_ID') |
|
1117 | ||
1118 | if not pid.isdigit() or int(pid) <= 0: |
|
1119 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1120 | description='API.INVALID_POINT_ID') |
|
1121 | ||
1122 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1123 | cursor = cnx.cursor() |
|
1124 | ||
1125 | cursor.execute(" SELECT name " |
|
1126 | " FROM tbl_stores " |
|
1127 | " WHERE id = %s ", (id_,)) |
|
1128 | if cursor.fetchone() is None: |
|
1129 | cursor.close() |
|
1130 | cnx.close() |
|
1131 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1132 | description='API.STORE_NOT_FOUND') |
|
1133 | ||
1134 | cursor.execute(" SELECT name " |
|
1135 | " FROM tbl_points " |
|
1136 | " WHERE id = %s ", (pid,)) |
|
1137 | if cursor.fetchone() is None: |
|
1138 | cursor.close() |
|
1139 | cnx.close() |
|
1140 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1141 | description='API.POINT_NOT_FOUND') |
|
1142 | ||
1143 | cursor.execute(" SELECT id " |
|
1144 | " FROM tbl_stores_points " |
|
1145 | " WHERE store_id = %s AND point_id = %s ", (id_, pid)) |
|
1146 | if cursor.fetchone() is None: |
|
1147 | cursor.close() |
|
1148 | cnx.close() |
|
1149 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1150 | description='API.STORE_POINT_RELATION_NOT_FOUND') |
|
1151 | ||
1152 | cursor.execute(" DELETE FROM tbl_stores_points " |
|
1153 | " WHERE store_id = %s AND point_id = %s ", (id_, pid)) |
|
1154 | cnx.commit() |
|
1155 | ||
1156 | cursor.close() |
|
1157 | cnx.close() |
|
1158 | ||
1159 | resp.status = falcon.HTTP_204 |
|
1160 | ||
1161 | ||
1162 | class StoreSensorCollection: |
|
@@ 906-966 (lines=61) @@ | ||
903 | resp.location = '/stores/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
904 | ||
905 | ||
906 | class StoreOfflineMeterItem: |
|
907 | def __init__(self): |
|
908 | """Initializes Class""" |
|
909 | pass |
|
910 | ||
911 | @staticmethod |
|
912 | def on_options(req, resp, id_, mid): |
|
913 | _ = req |
|
914 | resp.status = falcon.HTTP_200 |
|
915 | _ = id_ |
|
916 | ||
917 | @staticmethod |
|
918 | @user_logger |
|
919 | def on_delete(req, resp, id_, mid): |
|
920 | admin_control(req) |
|
921 | if not id_.isdigit() or int(id_) <= 0: |
|
922 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
923 | description='API.INVALID_STORE_ID') |
|
924 | ||
925 | if not mid.isdigit() or int(mid) <= 0: |
|
926 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
927 | description='API.INVALID_OFFLINE_METER_ID') |
|
928 | ||
929 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
930 | cursor = cnx.cursor() |
|
931 | ||
932 | cursor.execute(" SELECT name " |
|
933 | " FROM tbl_stores " |
|
934 | " WHERE id = %s ", (id_,)) |
|
935 | if cursor.fetchone() is None: |
|
936 | cursor.close() |
|
937 | cnx.close() |
|
938 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
939 | description='API.STORE_NOT_FOUND') |
|
940 | ||
941 | cursor.execute(" SELECT name " |
|
942 | " FROM tbl_offline_meters " |
|
943 | " WHERE id = %s ", (mid,)) |
|
944 | if cursor.fetchone() is None: |
|
945 | cursor.close() |
|
946 | cnx.close() |
|
947 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
948 | description='API.OFFLINE_METER_NOT_FOUND') |
|
949 | ||
950 | cursor.execute(" SELECT id " |
|
951 | " FROM tbl_stores_offline_meters " |
|
952 | " WHERE store_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
953 | if cursor.fetchone() is None: |
|
954 | cursor.close() |
|
955 | cnx.close() |
|
956 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
957 | description='API.STORE_OFFLINE_METER_RELATION_NOT_FOUND') |
|
958 | ||
959 | cursor.execute(" DELETE FROM tbl_stores_offline_meters " |
|
960 | " WHERE store_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
961 | cnx.commit() |
|
962 | ||
963 | cursor.close() |
|
964 | cnx.close() |
|
965 | ||
966 | resp.status = falcon.HTTP_204 |
|
967 | ||
968 | ||
969 | class StorePointCollection: |
|
@@ 1835-1894 (lines=60) @@ | ||
1832 | resp.location = '/stores/' + str(id_) + '/commands/' + str(command_id) |
|
1833 | ||
1834 | ||
1835 | class StoreCommandItem: |
|
1836 | def __init__(self): |
|
1837 | """Initializes Class""" |
|
1838 | pass |
|
1839 | ||
1840 | @staticmethod |
|
1841 | def on_options(req, resp, id_, cid): |
|
1842 | _ = req |
|
1843 | resp.status = falcon.HTTP_200 |
|
1844 | _ = id_ |
|
1845 | ||
1846 | @staticmethod |
|
1847 | @user_logger |
|
1848 | def on_delete(req, resp, id_, cid): |
|
1849 | admin_control(req) |
|
1850 | if not id_.isdigit() or int(id_) <= 0: |
|
1851 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1852 | description='API.INVALID_STORE_ID') |
|
1853 | ||
1854 | if not cid.isdigit() or int(cid) <= 0: |
|
1855 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1856 | description='API.INVALID_COMMAND_ID') |
|
1857 | ||
1858 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1859 | cursor = cnx.cursor() |
|
1860 | ||
1861 | cursor.execute(" SELECT name " |
|
1862 | " FROM tbl_stores " |
|
1863 | " WHERE id = %s ", (id_,)) |
|
1864 | if cursor.fetchone() is None: |
|
1865 | cursor.close() |
|
1866 | cnx.close() |
|
1867 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1868 | description='API.STORE_NOT_FOUND') |
|
1869 | ||
1870 | cursor.execute(" SELECT name " |
|
1871 | " FROM tbl_commands " |
|
1872 | " WHERE id = %s ", (cid,)) |
|
1873 | if cursor.fetchone() is None: |
|
1874 | cursor.close() |
|
1875 | cnx.close() |
|
1876 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1877 | description='API.COMMAND_NOT_FOUND') |
|
1878 | ||
1879 | cursor.execute(" SELECT id " |
|
1880 | " FROM tbl_stores_commands " |
|
1881 | " WHERE store_id = %s AND command_id = %s ", (id_, cid)) |
|
1882 | if cursor.fetchone() is None: |
|
1883 | cursor.close() |
|
1884 | cnx.close() |
|
1885 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1886 | description='API.STORE_COMMAND_RELATION_NOT_FOUND') |
|
1887 | ||
1888 | cursor.execute(" DELETE FROM tbl_stores_commands WHERE store_id = %s AND command_id = %s ", (id_, cid)) |
|
1889 | cnx.commit() |
|
1890 | ||
1891 | cursor.close() |
|
1892 | cnx.close() |
|
1893 | ||
1894 | resp.status = falcon.HTTP_204 |
|
1895 | ||
1896 | ||
1897 | class StoreExport: |
|
@@ 1280-1339 (lines=60) @@ | ||
1277 | resp.location = '/stores/' + str(id_) + '/sensors/' + str(sensor_id) |
|
1278 | ||
1279 | ||
1280 | class StoreSensorItem: |
|
1281 | def __init__(self): |
|
1282 | """Initializes Class""" |
|
1283 | pass |
|
1284 | ||
1285 | @staticmethod |
|
1286 | def on_options(req, resp, id_, sid): |
|
1287 | _ = req |
|
1288 | resp.status = falcon.HTTP_200 |
|
1289 | _ = id_ |
|
1290 | ||
1291 | @staticmethod |
|
1292 | @user_logger |
|
1293 | def on_delete(req, resp, id_, sid): |
|
1294 | admin_control(req) |
|
1295 | if not id_.isdigit() or int(id_) <= 0: |
|
1296 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1297 | description='API.INVALID_STORE_ID') |
|
1298 | ||
1299 | if not sid.isdigit() or int(sid) <= 0: |
|
1300 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1301 | description='API.INVALID_SENSOR_ID') |
|
1302 | ||
1303 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1304 | cursor = cnx.cursor() |
|
1305 | ||
1306 | cursor.execute(" SELECT name " |
|
1307 | " FROM tbl_stores " |
|
1308 | " WHERE id = %s ", (id_,)) |
|
1309 | if cursor.fetchone() is None: |
|
1310 | cursor.close() |
|
1311 | cnx.close() |
|
1312 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1313 | description='API.STORE_NOT_FOUND') |
|
1314 | ||
1315 | cursor.execute(" SELECT name " |
|
1316 | " FROM tbl_sensors " |
|
1317 | " WHERE id = %s ", (sid,)) |
|
1318 | if cursor.fetchone() is None: |
|
1319 | cursor.close() |
|
1320 | cnx.close() |
|
1321 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1322 | description='API.SENSOR_NOT_FOUND') |
|
1323 | ||
1324 | cursor.execute(" SELECT id " |
|
1325 | " FROM tbl_stores_sensors " |
|
1326 | " WHERE store_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1327 | if cursor.fetchone() is None: |
|
1328 | cursor.close() |
|
1329 | cnx.close() |
|
1330 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1331 | description='API.STORE_SENSOR_RELATION_NOT_FOUND') |
|
1332 | ||
1333 | cursor.execute(" DELETE FROM tbl_stores_sensors WHERE store_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1334 | cnx.commit() |
|
1335 | ||
1336 | cursor.close() |
|
1337 | cnx.close() |
|
1338 | ||
1339 | resp.status = falcon.HTTP_204 |
|
1340 | ||
1341 | ||
1342 | class StoreVirtualMeterCollection: |
|
@@ 713-772 (lines=60) @@ | ||
710 | resp.location = '/stores/' + str(id_) + '/meters/' + str(meter_id) |
|
711 | ||
712 | ||
713 | class StoreMeterItem: |
|
714 | def __init__(self): |
|
715 | """Initializes Class""" |
|
716 | pass |
|
717 | ||
718 | @staticmethod |
|
719 | def on_options(req, resp, id_, mid): |
|
720 | _ = req |
|
721 | resp.status = falcon.HTTP_200 |
|
722 | _ = id_ |
|
723 | ||
724 | @staticmethod |
|
725 | @user_logger |
|
726 | def on_delete(req, resp, id_, mid): |
|
727 | admin_control(req) |
|
728 | if not id_.isdigit() or int(id_) <= 0: |
|
729 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
730 | description='API.INVALID_STORE_ID') |
|
731 | ||
732 | if not mid.isdigit() or int(mid) <= 0: |
|
733 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
734 | description='API.INVALID_METER_ID') |
|
735 | ||
736 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
737 | cursor = cnx.cursor() |
|
738 | ||
739 | cursor.execute(" SELECT name " |
|
740 | " FROM tbl_stores " |
|
741 | " WHERE id = %s ", (id_,)) |
|
742 | if cursor.fetchone() is None: |
|
743 | cursor.close() |
|
744 | cnx.close() |
|
745 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
746 | description='API.STORE_NOT_FOUND') |
|
747 | ||
748 | cursor.execute(" SELECT name " |
|
749 | " FROM tbl_meters " |
|
750 | " WHERE id = %s ", (mid,)) |
|
751 | if cursor.fetchone() is None: |
|
752 | cursor.close() |
|
753 | cnx.close() |
|
754 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
755 | description='API.METER_NOT_FOUND') |
|
756 | ||
757 | cursor.execute(" SELECT id " |
|
758 | " FROM tbl_stores_meters " |
|
759 | " WHERE store_id = %s AND meter_id = %s ", (id_, mid)) |
|
760 | if cursor.fetchone() is None: |
|
761 | cursor.close() |
|
762 | cnx.close() |
|
763 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
764 | description='API.STORE_METER_RELATION_NOT_FOUND') |
|
765 | ||
766 | cursor.execute(" DELETE FROM tbl_stores_meters WHERE store_id = %s AND meter_id = %s ", (id_, mid)) |
|
767 | cnx.commit() |
|
768 | ||
769 | cursor.close() |
|
770 | cnx.close() |
|
771 | ||
772 | resp.status = falcon.HTTP_204 |
|
773 | ||
774 | ||
775 | class StoreOfflineMeterCollection: |
@@ 1578-1638 (lines=61) @@ | ||
1575 | resp.location = '/energystoragecontainers/' + str(id_) + '/datasources/' + str(data_source_id) |
|
1576 | ||
1577 | ||
1578 | class EnergyStorageContainerDataSourceItem: |
|
1579 | def __init__(self): |
|
1580 | """Initializes Class""" |
|
1581 | pass |
|
1582 | ||
1583 | @staticmethod |
|
1584 | def on_options(req, resp, id_, dsid): |
|
1585 | _ = req |
|
1586 | resp.status = falcon.HTTP_200 |
|
1587 | _ = id_ |
|
1588 | ||
1589 | @staticmethod |
|
1590 | @user_logger |
|
1591 | def on_delete(req, resp, id_, dsid): |
|
1592 | admin_control(req) |
|
1593 | if not id_.isdigit() or int(id_) <= 0: |
|
1594 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1595 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
1596 | ||
1597 | if not dsid.isdigit() or int(dsid) <= 0: |
|
1598 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1599 | description='API.INVALID_DATA_SOURCE_ID') |
|
1600 | ||
1601 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1602 | cursor = cnx.cursor() |
|
1603 | ||
1604 | cursor.execute(" SELECT name " |
|
1605 | " FROM tbl_energy_storage_containers " |
|
1606 | " WHERE id = %s ", (id_,)) |
|
1607 | if cursor.fetchone() is None: |
|
1608 | cursor.close() |
|
1609 | cnx.close() |
|
1610 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1611 | description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND') |
|
1612 | ||
1613 | cursor.execute(" SELECT name " |
|
1614 | " FROM tbl_data_sources " |
|
1615 | " WHERE id = %s ", (dsid,)) |
|
1616 | if cursor.fetchone() is None: |
|
1617 | cursor.close() |
|
1618 | cnx.close() |
|
1619 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1620 | description='API.DATA_SOURCE_NOT_FOUND') |
|
1621 | ||
1622 | cursor.execute(" SELECT id " |
|
1623 | " FROM tbl_energy_storage_containers_data_sources " |
|
1624 | " WHERE energy_storage_container_id = %s AND data_source_id = %s ", (id_, dsid)) |
|
1625 | if cursor.fetchone() is None: |
|
1626 | cursor.close() |
|
1627 | cnx.close() |
|
1628 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1629 | description='API.ENERGY_STORAGE_CONTAINER_DATA_SOURCE_RELATION_NOT_FOUND') |
|
1630 | ||
1631 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_data_sources " |
|
1632 | " WHERE energy_storage_container_id = %s AND data_source_id = %s ", (id_, dsid)) |
|
1633 | cnx.commit() |
|
1634 | ||
1635 | cursor.close() |
|
1636 | cnx.close() |
|
1637 | ||
1638 | resp.status = falcon.HTTP_204 |
|
1639 | ||
1640 | ||
1641 | class EnergyStorageContainerDataSourcePointCollection: |
|
@@ 1395-1455 (lines=61) @@ | ||
1392 | resp.location = '/energystoragecontainers/' + str(id_) + '/commands/' + str(command_id) |
|
1393 | ||
1394 | ||
1395 | class EnergyStorageContainerCommandItem: |
|
1396 | def __init__(self): |
|
1397 | """Initializes Class""" |
|
1398 | pass |
|
1399 | ||
1400 | @staticmethod |
|
1401 | def on_options(req, resp, id_, cid): |
|
1402 | _ = req |
|
1403 | resp.status = falcon.HTTP_200 |
|
1404 | _ = id_ |
|
1405 | ||
1406 | @staticmethod |
|
1407 | @user_logger |
|
1408 | def on_delete(req, resp, id_, cid): |
|
1409 | admin_control(req) |
|
1410 | if not id_.isdigit() or int(id_) <= 0: |
|
1411 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1412 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
1413 | ||
1414 | if not cid.isdigit() or int(cid) <= 0: |
|
1415 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1416 | description='API.INVALID_COMMAND_ID') |
|
1417 | ||
1418 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1419 | cursor = cnx.cursor() |
|
1420 | ||
1421 | cursor.execute(" SELECT name " |
|
1422 | " FROM tbl_energy_storage_containers " |
|
1423 | " WHERE id = %s ", (id_,)) |
|
1424 | if cursor.fetchone() is None: |
|
1425 | cursor.close() |
|
1426 | cnx.close() |
|
1427 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1428 | description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND') |
|
1429 | ||
1430 | cursor.execute(" SELECT name " |
|
1431 | " FROM tbl_commands " |
|
1432 | " WHERE id = %s ", (cid,)) |
|
1433 | if cursor.fetchone() is None: |
|
1434 | cursor.close() |
|
1435 | cnx.close() |
|
1436 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1437 | description='API.COMMAND_NOT_FOUND') |
|
1438 | ||
1439 | cursor.execute(" SELECT id " |
|
1440 | " FROM tbl_energy_storage_containers_commands " |
|
1441 | " WHERE energy_storage_container_id = %s AND command_id = %s ", (id_, cid)) |
|
1442 | if cursor.fetchone() is None: |
|
1443 | cursor.close() |
|
1444 | cnx.close() |
|
1445 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1446 | description='API.ENERGY_STORAGE_CONTAINER_COMMAND_RELATION_NOT_FOUND') |
|
1447 | ||
1448 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_commands " |
|
1449 | " WHERE energy_storage_container_id = %s AND command_id = %s ", (id_, cid)) |
|
1450 | cnx.commit() |
|
1451 | ||
1452 | cursor.close() |
|
1453 | cnx.close() |
|
1454 | ||
1455 | resp.status = falcon.HTTP_204 |
|
1456 | ||
1457 | ||
1458 | class EnergyStorageContainerDataSourceCollection: |
@@ 558-618 (lines=61) @@ | ||
555 | resp.location = '/virtualpowerplants/' + str(id_) + '/microgrids/' + str(microgrid_id) |
|
556 | ||
557 | ||
558 | class VirtualPowerPlantMicrogridItem: |
|
559 | def __init__(self): |
|
560 | """Initializes Class""" |
|
561 | pass |
|
562 | ||
563 | @staticmethod |
|
564 | def on_options(req, resp, id_, sid): |
|
565 | _ = req |
|
566 | resp.status = falcon.HTTP_200 |
|
567 | _ = id_ |
|
568 | ||
569 | @staticmethod |
|
570 | @user_logger |
|
571 | def on_delete(req, resp, id_, mid): |
|
572 | admin_control(req) |
|
573 | if not id_.isdigit() or int(id_) <= 0: |
|
574 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
575 | description='API.INVALID_VIRTUAL_POWER_PLANT_ID') |
|
576 | ||
577 | if not mid.isdigit() or int(mid) <= 0: |
|
578 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
579 | description='API.INVALID_MICROGRID_ID') |
|
580 | ||
581 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
582 | cursor = cnx.cursor() |
|
583 | ||
584 | cursor.execute(" SELECT name " |
|
585 | " FROM tbl_virtual_power_plants " |
|
586 | " WHERE id = %s ", (id_,)) |
|
587 | if cursor.fetchone() is None: |
|
588 | cursor.close() |
|
589 | cnx.close() |
|
590 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
591 | description='API.VIRTUAL_POWER_PLANT_NOT_FOUND') |
|
592 | ||
593 | cursor.execute(" SELECT name " |
|
594 | " FROM tbl_microgrids " |
|
595 | " WHERE id = %s ", (mid,)) |
|
596 | if cursor.fetchone() is None: |
|
597 | cursor.close() |
|
598 | cnx.close() |
|
599 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
600 | description='API.MICROGRID_NOT_FOUND') |
|
601 | ||
602 | cursor.execute(" SELECT id " |
|
603 | " FROM tbl_virtual_power_plants_microgrids " |
|
604 | " WHERE virtual_power_plant_id = %s AND microgrid_id = %s ", (id_, mid)) |
|
605 | if cursor.fetchone() is None: |
|
606 | cursor.close() |
|
607 | cnx.close() |
|
608 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
609 | description='API.VIRTUAL_POWER_PLANT_MICROGRID_RELATION_NOT_FOUND') |
|
610 | ||
611 | cursor.execute(" DELETE FROM tbl_virtual_power_plants_microgrids " |
|
612 | " WHERE virtual_power_plant_id = %s AND microgrid_id = %s ", (id_, mid)) |
|
613 | cnx.commit() |
|
614 | ||
615 | cursor.close() |
|
616 | cnx.close() |
|
617 | ||
618 | resp.status = falcon.HTTP_204 |
|
619 | ||
620 | ||
621 | class VirtualPowerPlantExport: |
@@ 535-595 (lines=61) @@ | ||
532 | resp.location = '/distributioncircuits/' + str(id_) + '/points/' + str(new_values['data']['point_id']) |
|
533 | ||
534 | ||
535 | class DistributionCircuitPointItem: |
|
536 | def __init__(self): |
|
537 | """Initializes DistributionCircuitPointItem""" |
|
538 | pass |
|
539 | ||
540 | @staticmethod |
|
541 | def on_options(req, resp, id_, pid): |
|
542 | _ = req |
|
543 | resp.status = falcon.HTTP_200 |
|
544 | _ = id_ |
|
545 | ||
546 | @staticmethod |
|
547 | @user_logger |
|
548 | def on_delete(req, resp, id_, pid): |
|
549 | admin_control(req) |
|
550 | if not id_.isdigit() or int(id_) <= 0: |
|
551 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
552 | description='API.INVALID_DISTRIBUTION_CIRCUIT_ID') |
|
553 | ||
554 | if not pid.isdigit() or int(pid) <= 0: |
|
555 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
556 | description='API.INVALID_POINT_ID') |
|
557 | ||
558 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
559 | cursor = cnx.cursor() |
|
560 | ||
561 | cursor.execute(" SELECT name " |
|
562 | " FROM tbl_distribution_circuits " |
|
563 | " WHERE id = %s ", (id_,)) |
|
564 | if cursor.fetchone() is None: |
|
565 | cursor.close() |
|
566 | cnx.close() |
|
567 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
568 | description='API.DISTRIBUTION_CIRCUIT_NOT_FOUND') |
|
569 | ||
570 | cursor.execute(" SELECT name " |
|
571 | " FROM tbl_points " |
|
572 | " WHERE id = %s ", (pid,)) |
|
573 | if cursor.fetchone() is None: |
|
574 | cursor.close() |
|
575 | cnx.close() |
|
576 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
577 | description='API.POINT_NOT_FOUND') |
|
578 | ||
579 | cursor.execute(" SELECT id " |
|
580 | " FROM tbl_distribution_circuits_points " |
|
581 | " WHERE distribution_circuit_id = %s AND point_id = %s ", (id_, pid)) |
|
582 | if cursor.fetchone() is None: |
|
583 | cursor.close() |
|
584 | cnx.close() |
|
585 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
586 | description='API.DISTRIBUTION_CIRCUIT_POINT_RELATION_NOT_FOUND') |
|
587 | ||
588 | cursor.execute(" DELETE FROM tbl_distribution_circuits_points " |
|
589 | " WHERE distribution_circuit_id = %s AND point_id = %s ", (id_, pid)) |
|
590 | cnx.commit() |
|
591 | ||
592 | cursor.close() |
|
593 | cnx.close() |
|
594 | ||
595 | resp.status = falcon.HTTP_204 |
|
596 | ||
597 |
@@ 425-484 (lines=60) @@ | ||
422 | resp.location = '/sensors/' + str(id_) + '/points/' + str(new_values['data']['point_id']) |
|
423 | ||
424 | ||
425 | class SensorPointItem: |
|
426 | def __init__(self): |
|
427 | """"Initializes SensorPointItem""" |
|
428 | pass |
|
429 | ||
430 | @staticmethod |
|
431 | def on_options(req, resp, id_, pid): |
|
432 | _ = req |
|
433 | resp.status = falcon.HTTP_200 |
|
434 | _ = id_ |
|
435 | ||
436 | @staticmethod |
|
437 | @user_logger |
|
438 | def on_delete(req, resp, id_, pid): |
|
439 | admin_control(req) |
|
440 | if not id_.isdigit() or int(id_) <= 0: |
|
441 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
442 | description='API.INVALID_SENSOR_ID') |
|
443 | ||
444 | if not pid.isdigit() or int(pid) <= 0: |
|
445 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
446 | description='API.INVALID_POINT_ID') |
|
447 | ||
448 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
449 | cursor = cnx.cursor() |
|
450 | ||
451 | cursor.execute(" SELECT name " |
|
452 | " FROM tbl_sensors " |
|
453 | " WHERE id = %s ", (id_,)) |
|
454 | if cursor.fetchone() is None: |
|
455 | cursor.close() |
|
456 | cnx.close() |
|
457 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
458 | description='API.SENSOR_NOT_FOUND') |
|
459 | ||
460 | cursor.execute(" SELECT name " |
|
461 | " FROM tbl_points " |
|
462 | " WHERE id = %s ", (pid,)) |
|
463 | if cursor.fetchone() is None: |
|
464 | cursor.close() |
|
465 | cnx.close() |
|
466 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
467 | description='API.POINT_NOT_FOUND') |
|
468 | ||
469 | cursor.execute(" SELECT id " |
|
470 | " FROM tbl_sensors_points " |
|
471 | " WHERE sensor_id = %s AND point_id = %s ", (id_, pid)) |
|
472 | if cursor.fetchone() is None: |
|
473 | cursor.close() |
|
474 | cnx.close() |
|
475 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
476 | description='API.SENSOR_POINT_RELATION_NOT_FOUND') |
|
477 | ||
478 | cursor.execute(" DELETE FROM tbl_sensors_points WHERE sensor_id = %s AND point_id = %s ", (id_, pid)) |
|
479 | cnx.commit() |
|
480 | ||
481 | cursor.close() |
|
482 | cnx.close() |
|
483 | ||
484 | resp.status = falcon.HTTP_204 |
|
485 | ||
486 | ||
487 | class SensorExport: |