@@ 4879-4939 (lines=61) @@ | ||
4876 | resp.location = '/photovoltaicpowerstations/' + str(id_) + '/users/' + str(user_id) |
|
4877 | ||
4878 | ||
4879 | class PhotovoltaicPowerStationUserItem: |
|
4880 | def __init__(self): |
|
4881 | """Initializes Class""" |
|
4882 | pass |
|
4883 | ||
4884 | @staticmethod |
|
4885 | def on_options(req, resp, id_, uid): |
|
4886 | resp.status = falcon.HTTP_200 |
|
4887 | ||
4888 | @staticmethod |
|
4889 | @user_logger |
|
4890 | def on_delete(req, resp, id_, uid): |
|
4891 | # todo Verify if the user is bound when deleting it |
|
4892 | admin_control(req) |
|
4893 | if not id_.isdigit() or int(id_) <= 0: |
|
4894 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
4895 | description='API.INVALID_PHOTOVOLTAIC_POWER_STATION_ID') |
|
4896 | ||
4897 | if not uid.isdigit() or int(uid) <= 0: |
|
4898 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
4899 | description='API.INVALID_USER_ID') |
|
4900 | ||
4901 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
4902 | cursor = cnx.cursor() |
|
4903 | cursor.execute(" SELECT name " |
|
4904 | " FROM tbl_photovoltaic_power_stations " |
|
4905 | " WHERE id = %s ", (id_,)) |
|
4906 | if cursor.fetchone() is None: |
|
4907 | cursor.close() |
|
4908 | cnx.close() |
|
4909 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
4910 | description='API.PHOTOVOLTAIC_POWER_STATION_NOT_FOUND') |
|
4911 | ||
4912 | cnx_user = mysql.connector.connect(**config.myems_user_db) |
|
4913 | cursor_user = cnx_user.cursor() |
|
4914 | cursor_user.execute(" SELECT name FROM tbl_users WHERE id = %s ", (uid,)) |
|
4915 | if cursor_user.fetchone() is None: |
|
4916 | cursor_user.close() |
|
4917 | cnx_user.close() |
|
4918 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
4919 | description='API.USER_NOT_FOUND') |
|
4920 | ||
4921 | cursor.execute(" SELECT id " |
|
4922 | " FROM tbl_photovoltaic_power_stations_users " |
|
4923 | " WHERE photovoltaic_power_station_id = %s AND user_id = %s ", (id_, uid)) |
|
4924 | if cursor.fetchone() is None: |
|
4925 | cursor.close() |
|
4926 | cnx.close() |
|
4927 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
4928 | description='API.PHOTOVOLTAIC_POWER_STATION_USER_RELATION_NOT_FOUND') |
|
4929 | ||
4930 | cursor.execute(" DELETE FROM tbl_photovoltaic_power_stations_users " |
|
4931 | " WHERE photovoltaic_power_station_id = %s AND user_id = %s ", (id_, uid)) |
|
4932 | cnx.commit() |
|
4933 | ||
4934 | cursor.close() |
|
4935 | cnx.close() |
|
4936 | cursor_user.close() |
|
4937 | cnx_user.close() |
|
4938 | ||
4939 | resp.status = falcon.HTTP_204 |
|
4940 |
@@ 989-1049 (lines=61) @@ | ||
986 | resp.location = '/energystoragepowerstations/' + str(id_) + '/users/' + str(user_id) |
|
987 | ||
988 | ||
989 | class EnergyStoragePowerStationUserItem: |
|
990 | def __init__(self): |
|
991 | """Initializes Class""" |
|
992 | pass |
|
993 | ||
994 | @staticmethod |
|
995 | def on_options(req, resp, id_, uid): |
|
996 | resp.status = falcon.HTTP_200 |
|
997 | ||
998 | @staticmethod |
|
999 | @user_logger |
|
1000 | def on_delete(req, resp, id_, uid): |
|
1001 | # todo Verify if the user is bound when deleting it |
|
1002 | admin_control(req) |
|
1003 | if not id_.isdigit() or int(id_) <= 0: |
|
1004 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1005 | description='API.INVALID_ENERGY_STORAGE_POWER_STATION_ID') |
|
1006 | ||
1007 | if not uid.isdigit() or int(uid) <= 0: |
|
1008 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1009 | description='API.INVALID_USER_ID') |
|
1010 | ||
1011 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1012 | cursor = cnx.cursor() |
|
1013 | cursor.execute(" SELECT name " |
|
1014 | " FROM tbl_energy_storage_power_stations " |
|
1015 | " WHERE id = %s ", (id_,)) |
|
1016 | if cursor.fetchone() is None: |
|
1017 | cursor.close() |
|
1018 | cnx.close() |
|
1019 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1020 | description='API.ENERGY_STORAGE_POWER_STATION_NOT_FOUND') |
|
1021 | ||
1022 | cnx_user = mysql.connector.connect(**config.myems_user_db) |
|
1023 | cursor_user = cnx_user.cursor() |
|
1024 | cursor_user.execute(" SELECT name FROM tbl_users WHERE id = %s ", (uid,)) |
|
1025 | if cursor_user.fetchone() is None: |
|
1026 | cursor_user.close() |
|
1027 | cnx_user.close() |
|
1028 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1029 | description='API.USER_NOT_FOUND') |
|
1030 | ||
1031 | cursor.execute(" SELECT id " |
|
1032 | " FROM tbl_energy_storage_power_stations_users " |
|
1033 | " WHERE energy_storage_power_station_id = %s AND user_id = %s ", (id_, uid)) |
|
1034 | if cursor.fetchone() is None: |
|
1035 | cursor.close() |
|
1036 | cnx.close() |
|
1037 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1038 | description='API.ENERGY_STORAGE_POWER_STATION_USER_RELATION_NOT_FOUND') |
|
1039 | ||
1040 | cursor.execute(" DELETE FROM tbl_energy_storage_power_stations_users " |
|
1041 | " WHERE energy_storage_power_station_id = %s AND user_id = %s ", (id_, uid)) |
|
1042 | cnx.commit() |
|
1043 | ||
1044 | cursor.close() |
|
1045 | cnx.close() |
|
1046 | cursor_user.close() |
|
1047 | cnx_user.close() |
|
1048 | ||
1049 | resp.status = falcon.HTTP_204 |
|
1050 | ||
1051 | ||
1052 | class EnergyStoragePowerStationExport: |
|
@@ 818-876 (lines=59) @@ | ||
815 | resp.location = '/energystoragepowerstationss/' + str(id_) + '/containers/' + str(energy_storage_container_id) |
|
816 | ||
817 | ||
818 | class EnergyStoragePowerStationContainerItem: |
|
819 | def __init__(self): |
|
820 | """Initializes Class""" |
|
821 | pass |
|
822 | ||
823 | @staticmethod |
|
824 | def on_options(req, resp, id_, sid): |
|
825 | resp.status = falcon.HTTP_200 |
|
826 | ||
827 | @staticmethod |
|
828 | @user_logger |
|
829 | def on_delete(req, resp, id_, sid): |
|
830 | admin_control(req) |
|
831 | if not id_.isdigit() or int(id_) <= 0: |
|
832 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
833 | description='API.INVALID_ENERGY_STORAGE_POWER_STATION_ID') |
|
834 | ||
835 | if not sid.isdigit() or int(sid) <= 0: |
|
836 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
837 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
838 | ||
839 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
840 | cursor = cnx.cursor() |
|
841 | ||
842 | cursor.execute(" SELECT name " |
|
843 | " FROM tbl_energy_storage_power_stations " |
|
844 | " WHERE id = %s ", (id_,)) |
|
845 | if cursor.fetchone() is None: |
|
846 | cursor.close() |
|
847 | cnx.close() |
|
848 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
849 | description='API.ENERGY_STORAGE_POWER_STATION_NOT_FOUND') |
|
850 | ||
851 | cursor.execute(" SELECT name " |
|
852 | " FROM tbl_energy_storage_containers " |
|
853 | " WHERE id = %s ", (sid,)) |
|
854 | if cursor.fetchone() is None: |
|
855 | cursor.close() |
|
856 | cnx.close() |
|
857 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
858 | description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND') |
|
859 | ||
860 | cursor.execute(" SELECT id " |
|
861 | " FROM tbl_energy_storage_power_stations_containers " |
|
862 | " WHERE energy_storage_power_station_id = %s AND energy_storage_container_id = %s ", (id_, sid)) |
|
863 | if cursor.fetchone() is None: |
|
864 | cursor.close() |
|
865 | cnx.close() |
|
866 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
867 | description='API.ENERGY_STORAGE_POWER_STATION_CONTAINER_RELATION_NOT_FOUND') |
|
868 | ||
869 | cursor.execute(" DELETE FROM tbl_energy_storage_power_stations_containers " |
|
870 | " WHERE energy_storage_power_station_id = %s AND energy_storage_container_id = %s ", (id_, sid)) |
|
871 | cnx.commit() |
|
872 | ||
873 | cursor.close() |
|
874 | cnx.close() |
|
875 | ||
876 | resp.status = falcon.HTTP_204 |
|
877 | ||
878 | ||
879 | class EnergyStoragePowerStationUserCollection: |
@@ 500-560 (lines=61) @@ | ||
497 | resp.location = '/costcenters/' + str(id_) + '/tariffs/' + str(new_values['data']['tariff_id']) |
|
498 | ||
499 | ||
500 | class CostCenterTariffItem: |
|
501 | def __init__(self): |
|
502 | """"Initializes CostCenterTariffItem""" |
|
503 | pass |
|
504 | ||
505 | @staticmethod |
|
506 | def on_options(req, resp, id_, tid): |
|
507 | _=req |
|
508 | resp.status = falcon.HTTP_200 |
|
509 | _=id_ |
|
510 | @staticmethod |
|
511 | @user_logger |
|
512 | def on_delete(req, resp, id_, tid): |
|
513 | """Handles DELETE requests""" |
|
514 | admin_control(req) |
|
515 | if not id_.isdigit() or int(id_) <= 0: |
|
516 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
517 | description='API.INVALID_COST_CENTER_ID') |
|
518 | ||
519 | if not tid.isdigit() or int(tid) <= 0: |
|
520 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
521 | description='API.INVALID_TARIFF_ID') |
|
522 | ||
523 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
524 | cursor = cnx.cursor() |
|
525 | ||
526 | cursor.execute(" SELECT name " |
|
527 | " FROM tbl_cost_centers " |
|
528 | " WHERE id = %s ", (id_,)) |
|
529 | if cursor.fetchone() is None: |
|
530 | cursor.close() |
|
531 | cnx.close() |
|
532 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
533 | description='API.COST_CENTER_NOT_FOUND') |
|
534 | ||
535 | cursor.execute(" SELECT name " |
|
536 | " FROM tbl_tariffs " |
|
537 | " WHERE id = %s ", (tid,)) |
|
538 | if cursor.fetchone() is None: |
|
539 | cursor.close() |
|
540 | cnx.close() |
|
541 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
542 | description='API.TARIFF_NOT_FOUND') |
|
543 | ||
544 | cursor.execute(" SELECT id " |
|
545 | " FROM tbl_cost_centers_tariffs " |
|
546 | " WHERE cost_center_id = %s AND tariff_id = %s ", (id_, tid)) |
|
547 | if cursor.fetchone() is None: |
|
548 | cursor.close() |
|
549 | cnx.close() |
|
550 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
551 | description='API.TARIFF_IS_NOT_ASSOCIATED_WITH_COST_CENTER') |
|
552 | ||
553 | cursor.execute(" DELETE FROM tbl_cost_centers_tariffs " |
|
554 | " WHERE cost_center_id = %s AND tariff_id = %s ", (id_, tid)) |
|
555 | cnx.commit() |
|
556 | ||
557 | cursor.close() |
|
558 | cnx.close() |
|
559 | ||
560 | resp.status = falcon.HTTP_204 |
|
561 |
@@ 5063-5122 (lines=60) @@ | ||
5060 | resp.location = '/microgrids/' + str(id_) + '/users/' + str(user_id) |
|
5061 | ||
5062 | ||
5063 | class MicrogridUserItem: |
|
5064 | def __init__(self): |
|
5065 | """Initializes Class""" |
|
5066 | pass |
|
5067 | ||
5068 | @staticmethod |
|
5069 | def on_options(req, resp, id_, uid): |
|
5070 | resp.status = falcon.HTTP_200 |
|
5071 | ||
5072 | @staticmethod |
|
5073 | @user_logger |
|
5074 | def on_delete(req, resp, id_, uid): |
|
5075 | # todo Verify if the user is bound when deleting it |
|
5076 | admin_control(req) |
|
5077 | if not id_.isdigit() or int(id_) <= 0: |
|
5078 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
5079 | description='API.INVALID_MICROGRID_ID') |
|
5080 | ||
5081 | if not uid.isdigit() or int(uid) <= 0: |
|
5082 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
5083 | description='API.INVALID_USER_ID') |
|
5084 | ||
5085 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
5086 | cursor = cnx.cursor() |
|
5087 | cursor.execute(" SELECT name " |
|
5088 | " FROM tbl_microgrids " |
|
5089 | " WHERE id = %s ", (id_,)) |
|
5090 | if cursor.fetchone() is None: |
|
5091 | cursor.close() |
|
5092 | cnx.close() |
|
5093 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5094 | description='API.MICROGRID_NOT_FOUND') |
|
5095 | ||
5096 | cnx_user = mysql.connector.connect(**config.myems_user_db) |
|
5097 | cursor_user = cnx_user.cursor() |
|
5098 | cursor_user.execute(" SELECT name FROM tbl_users WHERE id = %s ", (uid,)) |
|
5099 | if cursor_user.fetchone() is None: |
|
5100 | cursor_user.close() |
|
5101 | cnx_user.close() |
|
5102 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5103 | description='API.USER_NOT_FOUND') |
|
5104 | ||
5105 | cursor.execute(" SELECT id " |
|
5106 | " FROM tbl_microgrids_users " |
|
5107 | " WHERE microgrid_id = %s AND user_id = %s ", (id_, uid)) |
|
5108 | if cursor.fetchone() is None: |
|
5109 | cursor.close() |
|
5110 | cnx.close() |
|
5111 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5112 | description='API.MICROGRID_USER_RELATION_NOT_FOUND') |
|
5113 | ||
5114 | cursor.execute(" DELETE FROM tbl_microgrids_users WHERE microgrid_id = %s AND user_id = %s ", (id_, uid)) |
|
5115 | cnx.commit() |
|
5116 | ||
5117 | cursor.close() |
|
5118 | cnx.close() |
|
5119 | cursor_user.close() |
|
5120 | cnx_user.close() |
|
5121 | ||
5122 | resp.status = falcon.HTTP_204 |
|
5123 | ||
5124 | ||
5125 | class MicrogridExport: |
|
@@ 4892-4950 (lines=59) @@ | ||
4889 | resp.location = '/microgrids/' + str(id_) + '/sensors/' + str(sensor_id) |
|
4890 | ||
4891 | ||
4892 | class MicrogridSensorItem: |
|
4893 | def __init__(self): |
|
4894 | """Initializes Class""" |
|
4895 | pass |
|
4896 | ||
4897 | @staticmethod |
|
4898 | def on_options(req, resp, id_, sid): |
|
4899 | resp.status = falcon.HTTP_200 |
|
4900 | ||
4901 | @staticmethod |
|
4902 | @user_logger |
|
4903 | def on_delete(req, resp, id_, sid): |
|
4904 | admin_control(req) |
|
4905 | if not id_.isdigit() or int(id_) <= 0: |
|
4906 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
4907 | description='API.INVALID_MICROGRID_ID') |
|
4908 | ||
4909 | if not sid.isdigit() or int(sid) <= 0: |
|
4910 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
4911 | description='API.INVALID_SENSOR_ID') |
|
4912 | ||
4913 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
4914 | cursor = cnx.cursor() |
|
4915 | ||
4916 | cursor.execute(" SELECT name " |
|
4917 | " FROM tbl_microgrids " |
|
4918 | " WHERE id = %s ", (id_,)) |
|
4919 | if cursor.fetchone() is None: |
|
4920 | cursor.close() |
|
4921 | cnx.close() |
|
4922 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
4923 | description='API.MICROGRID_NOT_FOUND') |
|
4924 | ||
4925 | cursor.execute(" SELECT name " |
|
4926 | " FROM tbl_sensors " |
|
4927 | " WHERE id = %s ", (sid,)) |
|
4928 | if cursor.fetchone() is None: |
|
4929 | cursor.close() |
|
4930 | cnx.close() |
|
4931 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
4932 | description='API.SENSOR_NOT_FOUND') |
|
4933 | ||
4934 | cursor.execute(" SELECT id " |
|
4935 | " FROM tbl_microgrids_sensors " |
|
4936 | " WHERE microgrid_id = %s AND sensor_id = %s ", (id_, sid)) |
|
4937 | if cursor.fetchone() is None: |
|
4938 | cursor.close() |
|
4939 | cnx.close() |
|
4940 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
4941 | description='API.MICROGRID_SENSOR_RELATION_NOT_FOUND') |
|
4942 | ||
4943 | cursor.execute(" DELETE FROM tbl_microgrids_sensors " |
|
4944 | " WHERE microgrid_id = %s AND sensor_id = %s ", (id_, sid)) |
|
4945 | cnx.commit() |
|
4946 | ||
4947 | cursor.close() |
|
4948 | cnx.close() |
|
4949 | ||
4950 | resp.status = falcon.HTTP_204 |
|
4951 | ||
4952 | ||
4953 | class MicrogridUserCollection: |
@@ 2235-2294 (lines=60) @@ | ||
2232 | resp.location = '/combinedequipments/' + str(id_) + '/commands/' + str(command_id) |
|
2233 | ||
2234 | ||
2235 | class CombinedEquipmentCommandItem: |
|
2236 | def __init__(self): |
|
2237 | """Initializes Class""" |
|
2238 | pass |
|
2239 | ||
2240 | @staticmethod |
|
2241 | def on_options(req, resp, id_, cid): |
|
2242 | _=req |
|
2243 | resp.status = falcon.HTTP_200 |
|
2244 | _=id_ |
|
2245 | @staticmethod |
|
2246 | @user_logger |
|
2247 | def on_delete(req, resp, id_, cid): |
|
2248 | admin_control(req) |
|
2249 | if not id_.isdigit() or int(id_) <= 0: |
|
2250 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2251 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
2252 | ||
2253 | if not cid.isdigit() or int(cid) <= 0: |
|
2254 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2255 | description='API.INVALID_COMMAND_ID') |
|
2256 | ||
2257 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2258 | cursor = cnx.cursor() |
|
2259 | ||
2260 | cursor.execute(" SELECT name " |
|
2261 | " FROM tbl_combined_equipments " |
|
2262 | " WHERE id = %s ", (id_,)) |
|
2263 | if cursor.fetchone() is None: |
|
2264 | cursor.close() |
|
2265 | cnx.close() |
|
2266 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2267 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
2268 | ||
2269 | cursor.execute(" SELECT name " |
|
2270 | " FROM tbl_commands " |
|
2271 | " WHERE id = %s ", (cid,)) |
|
2272 | if cursor.fetchone() is None: |
|
2273 | cursor.close() |
|
2274 | cnx.close() |
|
2275 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2276 | description='API.COMMAND_NOT_FOUND') |
|
2277 | ||
2278 | cursor.execute(" SELECT id " |
|
2279 | " FROM tbl_combined_equipments_commands " |
|
2280 | " WHERE combined_equipment_id = %s AND command_id = %s ", (id_, cid)) |
|
2281 | if cursor.fetchone() is None: |
|
2282 | cursor.close() |
|
2283 | cnx.close() |
|
2284 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2285 | description='API.COMBINED_EQUIPMENT_COMMAND_RELATION_NOT_FOUND') |
|
2286 | ||
2287 | cursor.execute(" DELETE FROM tbl_combined_equipments_commands " |
|
2288 | " WHERE combined_equipment_id = %s AND command_id = %s ", (id_, cid)) |
|
2289 | cnx.commit() |
|
2290 | ||
2291 | cursor.close() |
|
2292 | cnx.close() |
|
2293 | ||
2294 | resp.status = falcon.HTTP_204 |
|
2295 | ||
2296 | ||
2297 | class CombinedEquipmentExport: |
|
@@ 2056-2115 (lines=60) @@ | ||
2053 | resp.location = '/combinedequipments/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
2054 | ||
2055 | ||
2056 | class CombinedEquipmentVirtualMeterItem: |
|
2057 | def __init__(self): |
|
2058 | """"Initializes CombinedEquipmentVirtualMeterItem""" |
|
2059 | pass |
|
2060 | ||
2061 | @staticmethod |
|
2062 | def on_options(req, resp, id_, mid): |
|
2063 | _=req |
|
2064 | resp.status = falcon.HTTP_200 |
|
2065 | _=id_ |
|
2066 | @staticmethod |
|
2067 | @user_logger |
|
2068 | def on_delete(req, resp, id_, mid): |
|
2069 | admin_control(req) |
|
2070 | if not id_.isdigit() or int(id_) <= 0: |
|
2071 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2072 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
2073 | ||
2074 | if not mid.isdigit() or int(mid) <= 0: |
|
2075 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2076 | description='API.INVALID_VIRTUAL_METER_ID') |
|
2077 | ||
2078 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2079 | cursor = cnx.cursor() |
|
2080 | ||
2081 | cursor.execute(" SELECT name " |
|
2082 | " FROM tbl_combined_equipments " |
|
2083 | " WHERE id = %s ", (id_,)) |
|
2084 | if cursor.fetchone() is None: |
|
2085 | cursor.close() |
|
2086 | cnx.close() |
|
2087 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2088 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
2089 | ||
2090 | cursor.execute(" SELECT name " |
|
2091 | " FROM tbl_virtual_meters " |
|
2092 | " WHERE id = %s ", (mid,)) |
|
2093 | if cursor.fetchone() is None: |
|
2094 | cursor.close() |
|
2095 | cnx.close() |
|
2096 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2097 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
2098 | ||
2099 | cursor.execute(" SELECT id " |
|
2100 | " FROM tbl_combined_equipments_virtual_meters " |
|
2101 | " WHERE combined_equipment_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
2102 | if cursor.fetchone() is None: |
|
2103 | cursor.close() |
|
2104 | cnx.close() |
|
2105 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2106 | description='API.COMBINED_EQUIPMENT_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
2107 | ||
2108 | cursor.execute(" DELETE FROM tbl_combined_equipments_virtual_meters " |
|
2109 | " WHERE combined_equipment_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
2110 | cnx.commit() |
|
2111 | ||
2112 | cursor.close() |
|
2113 | cnx.close() |
|
2114 | ||
2115 | resp.status = falcon.HTTP_204 |
|
2116 | ||
2117 | ||
2118 | class CombinedEquipmentCommandCollection: |
|
@@ 1854-1913 (lines=60) @@ | ||
1851 | resp.location = '/combinedequipments/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
1852 | ||
1853 | ||
1854 | class CombinedEquipmentOfflineMeterItem: |
|
1855 | def __init__(self): |
|
1856 | """"Initializes CombinedEquipmentOfflineMeterItem""" |
|
1857 | pass |
|
1858 | ||
1859 | @staticmethod |
|
1860 | def on_options(req, resp, id_, mid): |
|
1861 | _=req |
|
1862 | resp.status = falcon.HTTP_200 |
|
1863 | _=id_ |
|
1864 | @staticmethod |
|
1865 | @user_logger |
|
1866 | def on_delete(req, resp, id_, mid): |
|
1867 | admin_control(req) |
|
1868 | if not id_.isdigit() or int(id_) <= 0: |
|
1869 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1870 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
1871 | ||
1872 | if not mid.isdigit() or int(mid) <= 0: |
|
1873 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1874 | description='API.INVALID_OFFLINE_METER_ID') |
|
1875 | ||
1876 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1877 | cursor = cnx.cursor() |
|
1878 | ||
1879 | cursor.execute(" SELECT name " |
|
1880 | " FROM tbl_combined_equipments " |
|
1881 | " WHERE id = %s ", (id_,)) |
|
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.COMBINED_EQUIPMENT_NOT_FOUND') |
|
1887 | ||
1888 | cursor.execute(" SELECT name " |
|
1889 | " FROM tbl_offline_meters " |
|
1890 | " WHERE id = %s ", (mid,)) |
|
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.OFFLINE_METER_NOT_FOUND') |
|
1896 | ||
1897 | cursor.execute(" SELECT id " |
|
1898 | " FROM tbl_combined_equipments_offline_meters " |
|
1899 | " WHERE combined_equipment_id = %s AND offline_meter_id = %s ", (id_, 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.COMBINED_EQUIPMENT_OFFLINE_METER_RELATION_NOT_FOUND') |
|
1905 | ||
1906 | cursor.execute(" DELETE FROM tbl_combined_equipments_offline_meters " |
|
1907 | " WHERE combined_equipment_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1908 | cnx.commit() |
|
1909 | ||
1910 | cursor.close() |
|
1911 | cnx.close() |
|
1912 | ||
1913 | resp.status = falcon.HTTP_204 |
|
1914 | ||
1915 | ||
1916 | class CombinedEquipmentVirtualMeterCollection: |
|
@@ 1651-1710 (lines=60) @@ | ||
1648 | resp.location = '/combinedequipments/' + str(id_) + '/meters/' + str(meter_id) |
|
1649 | ||
1650 | ||
1651 | class CombinedEquipmentMeterItem: |
|
1652 | def __init__(self): |
|
1653 | """"Initializes CombinedEquipmentMeterItem""" |
|
1654 | pass |
|
1655 | ||
1656 | @staticmethod |
|
1657 | def on_options(req, resp, id_, mid): |
|
1658 | _=req |
|
1659 | resp.status = falcon.HTTP_200 |
|
1660 | _=id_ |
|
1661 | @staticmethod |
|
1662 | @user_logger |
|
1663 | def on_delete(req, resp, id_, mid): |
|
1664 | admin_control(req) |
|
1665 | if not id_.isdigit() or int(id_) <= 0: |
|
1666 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1667 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
1668 | ||
1669 | if not mid.isdigit() or int(mid) <= 0: |
|
1670 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1671 | description='API.INVALID_METER_ID') |
|
1672 | ||
1673 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1674 | cursor = cnx.cursor() |
|
1675 | ||
1676 | cursor.execute(" SELECT name " |
|
1677 | " FROM tbl_combined_equipments " |
|
1678 | " WHERE id = %s ", (id_,)) |
|
1679 | if cursor.fetchone() is None: |
|
1680 | cursor.close() |
|
1681 | cnx.close() |
|
1682 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1683 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
1684 | ||
1685 | cursor.execute(" SELECT name " |
|
1686 | " FROM tbl_meters " |
|
1687 | " WHERE id = %s ", (mid,)) |
|
1688 | if cursor.fetchone() is None: |
|
1689 | cursor.close() |
|
1690 | cnx.close() |
|
1691 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1692 | description='API.METER_NOT_FOUND') |
|
1693 | ||
1694 | cursor.execute(" SELECT id " |
|
1695 | " FROM tbl_combined_equipments_meters " |
|
1696 | " WHERE combined_equipment_id = %s AND meter_id = %s ", (id_, mid)) |
|
1697 | if cursor.fetchone() is None: |
|
1698 | cursor.close() |
|
1699 | cnx.close() |
|
1700 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1701 | description='API.COMBINED_EQUIPMENT_METER_RELATION_NOT_FOUND') |
|
1702 | ||
1703 | cursor.execute(" DELETE FROM tbl_combined_equipments_meters " |
|
1704 | " WHERE combined_equipment_id = %s AND meter_id = %s ", (id_, mid)) |
|
1705 | cnx.commit() |
|
1706 | ||
1707 | cursor.close() |
|
1708 | cnx.close() |
|
1709 | ||
1710 | resp.status = falcon.HTTP_204 |
|
1711 | ||
1712 | ||
1713 | class CombinedEquipmentOfflineMeterCollection: |
|
@@ 719-778 (lines=60) @@ | ||
716 | resp.location = '/combinedequipments/' + str(id_) + '/equipments/' + str(equipment_id) |
|
717 | ||
718 | ||
719 | class CombinedEquipmentEquipmentItem: |
|
720 | def __init__(self): |
|
721 | """Initializes CombinedEquipmentEquipmentItem""" |
|
722 | pass |
|
723 | ||
724 | @staticmethod |
|
725 | def on_options(req, resp, id_, eid): |
|
726 | _=req |
|
727 | resp.status = falcon.HTTP_200 |
|
728 | _=id_ |
|
729 | @staticmethod |
|
730 | @user_logger |
|
731 | def on_delete(req, resp, id_, eid): |
|
732 | admin_control(req) |
|
733 | if not id_.isdigit() or int(id_) <= 0: |
|
734 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
735 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
736 | ||
737 | if not eid.isdigit() or int(eid) <= 0: |
|
738 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
739 | description='API.INVALID_EQUIPMENT_ID') |
|
740 | ||
741 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
742 | cursor = cnx.cursor() |
|
743 | ||
744 | cursor.execute(" SELECT name " |
|
745 | " FROM tbl_combined_equipments " |
|
746 | " WHERE id = %s ", (id_,)) |
|
747 | if cursor.fetchone() is None: |
|
748 | cursor.close() |
|
749 | cnx.close() |
|
750 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
751 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
752 | ||
753 | cursor.execute(" SELECT name " |
|
754 | " FROM tbl_equipments " |
|
755 | " WHERE id = %s ", (eid,)) |
|
756 | if cursor.fetchone() is None: |
|
757 | cursor.close() |
|
758 | cnx.close() |
|
759 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
760 | description='API.EQUIPMENT_NOT_FOUND') |
|
761 | ||
762 | cursor.execute(" SELECT id " |
|
763 | " FROM tbl_combined_equipments_equipments " |
|
764 | " WHERE combined_equipment_id = %s AND equipment_id = %s ", (id_, eid)) |
|
765 | if cursor.fetchone() is None: |
|
766 | cursor.close() |
|
767 | cnx.close() |
|
768 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
769 | description='API.COMBINED_EQUIPMENT_EQUIPMENT_RELATION_NOT_FOUND') |
|
770 | ||
771 | cursor.execute(" DELETE FROM tbl_combined_equipments_equipments " |
|
772 | " WHERE combined_equipment_id = %s AND equipment_id = %s ", (id_, eid)) |
|
773 | cnx.commit() |
|
774 | ||
775 | cursor.close() |
|
776 | cnx.close() |
|
777 | ||
778 | resp.status = falcon.HTTP_204 |
|
779 | ||
780 | ||
781 | class CombinedEquipmentParameterCollection: |
@@ 1533-1592 (lines=60) @@ | ||
1530 | resp.location = '/spaces/' + str(id_) + '/meters/' + str(meter_id) |
|
1531 | ||
1532 | ||
1533 | class SpaceMeterItem: |
|
1534 | def __init__(self): |
|
1535 | """Initializes Class""" |
|
1536 | pass |
|
1537 | ||
1538 | @staticmethod |
|
1539 | def on_options(req, resp, id_, mid): |
|
1540 | resp.status = falcon.HTTP_200 |
|
1541 | ||
1542 | @staticmethod |
|
1543 | @user_logger |
|
1544 | def on_delete(req, resp, id_, mid): |
|
1545 | admin_control(req) |
|
1546 | if not id_.isdigit() or int(id_) <= 0: |
|
1547 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1548 | description='API.INVALID_SPACE_ID') |
|
1549 | ||
1550 | if not mid.isdigit() or int(mid) <= 0: |
|
1551 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1552 | description='API.INVALID_METER_ID') |
|
1553 | ||
1554 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1555 | cursor = cnx.cursor() |
|
1556 | ||
1557 | cursor.execute(" SELECT name " |
|
1558 | " FROM tbl_spaces " |
|
1559 | " WHERE id = %s ", (id_,)) |
|
1560 | if cursor.fetchone() is None: |
|
1561 | cursor.close() |
|
1562 | cnx.close() |
|
1563 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1564 | description='API.SPACE_NOT_FOUND') |
|
1565 | ||
1566 | cursor.execute(" SELECT name " |
|
1567 | " FROM tbl_meters " |
|
1568 | " WHERE id = %s ", (mid,)) |
|
1569 | if cursor.fetchone() is None: |
|
1570 | cursor.close() |
|
1571 | cnx.close() |
|
1572 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1573 | description='API.METER_NOT_FOUND') |
|
1574 | ||
1575 | cursor.execute(" SELECT id " |
|
1576 | " FROM tbl_spaces_meters " |
|
1577 | " WHERE space_id = %s AND meter_id = %s ", (id_, mid)) |
|
1578 | # use fetchall to avoid 'Unread result found' error in case there are duplicate rows |
|
1579 | rows = cursor.fetchall() |
|
1580 | if rows is None or len(rows) == 0: |
|
1581 | cursor.close() |
|
1582 | cnx.close() |
|
1583 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1584 | description='API.SPACE_METER_RELATION_NOT_FOUND') |
|
1585 | ||
1586 | cursor.execute(" DELETE FROM tbl_spaces_meters WHERE space_id = %s AND meter_id = %s ", (id_, mid)) |
|
1587 | cnx.commit() |
|
1588 | ||
1589 | cursor.close() |
|
1590 | cnx.close() |
|
1591 | ||
1592 | resp.status = falcon.HTTP_204 |
|
1593 | ||
1594 | ||
1595 | class SpaceMicrogridCollection: |
|
@@ 5594-5652 (lines=59) @@ | ||
5591 | resp.location = '/spaces/' + str(id_) + '/distributionsystems/' + str(distribution_system_id) |
|
5592 | ||
5593 | ||
5594 | class DistributionSystemItem: |
|
5595 | def __init__(self): |
|
5596 | """Initializes Class""" |
|
5597 | pass |
|
5598 | ||
5599 | @staticmethod |
|
5600 | def on_options(req, resp, id_, did): |
|
5601 | resp.status = falcon.HTTP_200 |
|
5602 | ||
5603 | @staticmethod |
|
5604 | @user_logger |
|
5605 | def on_delete(req, resp, id_, did): |
|
5606 | admin_control(req) |
|
5607 | if not id_.isdigit() or int(id_) <= 0: |
|
5608 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
5609 | description='API.INVALID_SPACE_ID') |
|
5610 | ||
5611 | if not did.isdigit() or int(did) <= 0: |
|
5612 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
5613 | description='API.INVALID_DISTRIBUTION_SYSTEM_ID') |
|
5614 | ||
5615 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
5616 | cursor = cnx.cursor() |
|
5617 | ||
5618 | cursor.execute(" SELECT name " |
|
5619 | " FROM tbl_spaces " |
|
5620 | " WHERE id = %s ", (id_,)) |
|
5621 | if cursor.fetchone() is None: |
|
5622 | cursor.close() |
|
5623 | cnx.close() |
|
5624 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5625 | description='API.SPACE_NOT_FOUND') |
|
5626 | ||
5627 | cursor.execute(" SELECT name " |
|
5628 | " FROM tbl_distribution_systems " |
|
5629 | " WHERE id = %s ", (did,)) |
|
5630 | if cursor.fetchone() is None: |
|
5631 | cursor.close() |
|
5632 | cnx.close() |
|
5633 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5634 | description='API.DISTRIBUTION_SYSTEM_NOT_FOUND') |
|
5635 | ||
5636 | cursor.execute(" SELECT id " |
|
5637 | " FROM tbl_spaces_distribution_systems " |
|
5638 | " WHERE space_id = %s AND distribution_system_id = %s ", (id_, did)) |
|
5639 | if cursor.fetchone() is None: |
|
5640 | cursor.close() |
|
5641 | cnx.close() |
|
5642 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5643 | description='API.SPACE_DISTRIBUTION_SYSTEM_RELATION_NOT_FOUND') |
|
5644 | ||
5645 | cursor.execute(" DELETE FROM tbl_spaces_distribution_systems " |
|
5646 | " WHERE space_id = %s AND distribution_system_id = %s ", (id_, did)) |
|
5647 | cnx.commit() |
|
5648 | ||
5649 | cursor.close() |
|
5650 | cnx.close() |
|
5651 | ||
5652 | resp.status = falcon.HTTP_204 |
|
5653 | ||
@@ 5418-5476 (lines=59) @@ | ||
5415 | resp.location = '/spaces/' + str(id_) + '/energyflowdiagrams/' + str(energy_flow_diagram_id) |
|
5416 | ||
5417 | ||
5418 | class SpaceEnergyFlowDiagramItem: |
|
5419 | def __init__(self): |
|
5420 | """Initializes Class""" |
|
5421 | pass |
|
5422 | ||
5423 | @staticmethod |
|
5424 | def on_options(req, resp, id_, eid): |
|
5425 | resp.status = falcon.HTTP_200 |
|
5426 | ||
5427 | @staticmethod |
|
5428 | @user_logger |
|
5429 | def on_delete(req, resp, id_, eid): |
|
5430 | admin_control(req) |
|
5431 | if not id_.isdigit() or int(id_) <= 0: |
|
5432 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
5433 | description='API.INVALID_SPACE_ID') |
|
5434 | ||
5435 | if not eid.isdigit() or int(eid) <= 0: |
|
5436 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
5437 | description='API.INVALID_ENERGY_FLOW_DIAGRAM_ID') |
|
5438 | ||
5439 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
5440 | cursor = cnx.cursor() |
|
5441 | ||
5442 | cursor.execute(" SELECT name " |
|
5443 | " FROM tbl_spaces " |
|
5444 | " WHERE id = %s ", (id_,)) |
|
5445 | if cursor.fetchone() is None: |
|
5446 | cursor.close() |
|
5447 | cnx.close() |
|
5448 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5449 | description='API.SPACE_NOT_FOUND') |
|
5450 | ||
5451 | cursor.execute(" SELECT name " |
|
5452 | " FROM tbl_energy_flow_diagrams " |
|
5453 | " WHERE id = %s ", (eid,)) |
|
5454 | if cursor.fetchone() is None: |
|
5455 | cursor.close() |
|
5456 | cnx.close() |
|
5457 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5458 | description='API.ENERGY_FLOW_DIAGRAM_NOT_FOUND') |
|
5459 | ||
5460 | cursor.execute(" SELECT id " |
|
5461 | " FROM tbl_spaces_energy_flow_diagrams " |
|
5462 | " WHERE space_id = %s AND energy_flow_diagram_id = %s ", (id_, eid)) |
|
5463 | if cursor.fetchone() is None: |
|
5464 | cursor.close() |
|
5465 | cnx.close() |
|
5466 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
5467 | description='API.SPACE_ENERGY_FLOW_DIAGRAM_RELATION_NOT_FOUND') |
|
5468 | ||
5469 | cursor.execute(" DELETE FROM tbl_spaces_energy_flow_diagrams " |
|
5470 | " WHERE space_id = %s AND energy_flow_diagram_id = %s ", (id_, eid)) |
|
5471 | cnx.commit() |
|
5472 | ||
5473 | cursor.close() |
|
5474 | cnx.close() |
|
5475 | ||
5476 | resp.status = falcon.HTTP_204 |
|
5477 | ||
5478 | ||
5479 | class DistributionSystemCollection: |
|
@@ 3513-3571 (lines=59) @@ | ||
3510 | resp.location = '/spaces/' + str(id_) + '/workingcalendars/' + str(working_calendar_id) |
|
3511 | ||
3512 | ||
3513 | class SpaceWorkingCalendarItem: |
|
3514 | def __init__(self): |
|
3515 | """Initializes SpaceWorkingCalendarItem Class""" |
|
3516 | pass |
|
3517 | ||
3518 | @staticmethod |
|
3519 | def on_options(req, resp, id_, wcid): |
|
3520 | resp.status = falcon.HTTP_200 |
|
3521 | ||
3522 | @staticmethod |
|
3523 | @user_logger |
|
3524 | def on_delete(req, resp, id_, wcid): |
|
3525 | admin_control(req) |
|
3526 | if not id_.isdigit() or int(id_) <= 0: |
|
3527 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
3528 | description='API.INVALID_SPACE_ID') |
|
3529 | ||
3530 | if not wcid.isdigit() or int(wcid) <= 0: |
|
3531 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
3532 | description='API.INVALID_WORKING_CALENDAR_ID') |
|
3533 | ||
3534 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
3535 | cursor = cnx.cursor() |
|
3536 | ||
3537 | cursor.execute(" SELECT name " |
|
3538 | " FROM tbl_spaces " |
|
3539 | " WHERE id = %s ", (id_,)) |
|
3540 | if cursor.fetchone() is None: |
|
3541 | cursor.close() |
|
3542 | cnx.close() |
|
3543 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3544 | description='API.SPACE_NOT_FOUND') |
|
3545 | ||
3546 | cursor.execute(" SELECT name " |
|
3547 | " FROM tbl_working_calendars " |
|
3548 | " WHERE id = %s ", (wcid,)) |
|
3549 | if cursor.fetchone() is None: |
|
3550 | cursor.close() |
|
3551 | cnx.close() |
|
3552 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3553 | description='API.WORKING_CALENDAR_NOT_FOUND') |
|
3554 | ||
3555 | cursor.execute(" SELECT id " |
|
3556 | " FROM tbl_spaces_working_calendars " |
|
3557 | " WHERE space_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
3558 | if cursor.fetchone() is None: |
|
3559 | cursor.close() |
|
3560 | cnx.close() |
|
3561 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3562 | description='API.SPACE_WORKING_CALENDAR_RELATION_NOT_FOUND') |
|
3563 | ||
3564 | cursor.execute(" DELETE FROM tbl_spaces_working_calendars " |
|
3565 | " WHERE space_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
3566 | cnx.commit() |
|
3567 | ||
3568 | cursor.close() |
|
3569 | cnx.close() |
|
3570 | ||
3571 | resp.status = falcon.HTTP_204 |
|
3572 | ||
3573 | ||
3574 | class SpaceCommandCollection: |
|
@@ 3152-3210 (lines=59) @@ | ||
3149 | resp.location = '/spaces/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
3150 | ||
3151 | ||
3152 | class SpaceVirtualMeterItem: |
|
3153 | def __init__(self): |
|
3154 | """Initializes Class""" |
|
3155 | pass |
|
3156 | ||
3157 | @staticmethod |
|
3158 | def on_options(req, resp, id_, mid): |
|
3159 | resp.status = falcon.HTTP_200 |
|
3160 | ||
3161 | @staticmethod |
|
3162 | @user_logger |
|
3163 | def on_delete(req, resp, id_, mid): |
|
3164 | admin_control(req) |
|
3165 | if not id_.isdigit() or int(id_) <= 0: |
|
3166 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
3167 | description='API.INVALID_SPACE_ID') |
|
3168 | ||
3169 | if not mid.isdigit() or int(mid) <= 0: |
|
3170 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
3171 | description='API.INVALID_VIRTUAL_METER_ID') |
|
3172 | ||
3173 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
3174 | cursor = cnx.cursor() |
|
3175 | ||
3176 | cursor.execute(" SELECT name " |
|
3177 | " FROM tbl_spaces " |
|
3178 | " WHERE id = %s ", (id_,)) |
|
3179 | if cursor.fetchone() is None: |
|
3180 | cursor.close() |
|
3181 | cnx.close() |
|
3182 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3183 | description='API.SPACE_NOT_FOUND') |
|
3184 | ||
3185 | cursor.execute(" SELECT name " |
|
3186 | " FROM tbl_virtual_meters " |
|
3187 | " WHERE id = %s ", (mid,)) |
|
3188 | if cursor.fetchone() is None: |
|
3189 | cursor.close() |
|
3190 | cnx.close() |
|
3191 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3192 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
3193 | ||
3194 | cursor.execute(" SELECT id " |
|
3195 | " FROM tbl_spaces_virtual_meters " |
|
3196 | " WHERE space_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
3197 | if cursor.fetchone() is None: |
|
3198 | cursor.close() |
|
3199 | cnx.close() |
|
3200 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3201 | description='API.SPACE_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
3202 | ||
3203 | cursor.execute(" DELETE FROM tbl_spaces_virtual_meters " |
|
3204 | " WHERE space_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
3205 | cnx.commit() |
|
3206 | ||
3207 | cursor.close() |
|
3208 | cnx.close() |
|
3209 | ||
3210 | resp.status = falcon.HTTP_204 |
|
3211 | ||
3212 | ||
3213 | class SpaceTreeCollection: |
|
@@ 2263-2321 (lines=59) @@ | ||
2260 | resp.location = '/spaces/' + str(id_) + '/points/' + str(point_id) |
|
2261 | ||
2262 | ||
2263 | class SpacePointItem: |
|
2264 | def __init__(self): |
|
2265 | """Initializes Class""" |
|
2266 | pass |
|
2267 | ||
2268 | @staticmethod |
|
2269 | def on_options(req, resp, id_, pid): |
|
2270 | resp.status = falcon.HTTP_200 |
|
2271 | ||
2272 | @staticmethod |
|
2273 | @user_logger |
|
2274 | def on_delete(req, resp, id_, pid): |
|
2275 | admin_control(req) |
|
2276 | if not id_.isdigit() or int(id_) <= 0: |
|
2277 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2278 | description='API.INVALID_SPACE_ID') |
|
2279 | ||
2280 | if not pid.isdigit() or int(pid) <= 0: |
|
2281 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2282 | description='API.INVALID_POINT_ID') |
|
2283 | ||
2284 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2285 | cursor = cnx.cursor() |
|
2286 | ||
2287 | cursor.execute(" SELECT name " |
|
2288 | " FROM tbl_spaces " |
|
2289 | " WHERE id = %s ", (id_,)) |
|
2290 | if cursor.fetchone() is None: |
|
2291 | cursor.close() |
|
2292 | cnx.close() |
|
2293 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2294 | description='API.SPACE_NOT_FOUND') |
|
2295 | ||
2296 | cursor.execute(" SELECT name " |
|
2297 | " FROM tbl_points " |
|
2298 | " WHERE id = %s ", (pid,)) |
|
2299 | if cursor.fetchone() is None: |
|
2300 | cursor.close() |
|
2301 | cnx.close() |
|
2302 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2303 | description='API.POINT_NOT_FOUND') |
|
2304 | ||
2305 | cursor.execute(" SELECT id " |
|
2306 | " FROM tbl_spaces_points " |
|
2307 | " WHERE space_id = %s AND point_id = %s ", (id_, pid)) |
|
2308 | if cursor.fetchone() is None: |
|
2309 | cursor.close() |
|
2310 | cnx.close() |
|
2311 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2312 | description='API.SPACE_POINT_RELATION_NOT_FOUND') |
|
2313 | ||
2314 | cursor.execute(" DELETE FROM tbl_spaces_points " |
|
2315 | " WHERE space_id = %s AND point_id = %s ", (id_, pid)) |
|
2316 | cnx.commit() |
|
2317 | ||
2318 | cursor.close() |
|
2319 | cnx.close() |
|
2320 | ||
2321 | resp.status = falcon.HTTP_204 |
|
2322 | ||
2323 | ||
2324 | class SpaceSensorCollection: |
|
@@ 2075-2133 (lines=59) @@ | ||
2072 | resp.location = '/spaces/' + str(id_) + '/photovoltaicpowerstations/' + str(photovoltaic_power_station_id) |
|
2073 | ||
2074 | ||
2075 | class SpacePhotovoltaicPowerStationItem: |
|
2076 | def __init__(self): |
|
2077 | """Initializes Class""" |
|
2078 | pass |
|
2079 | ||
2080 | @staticmethod |
|
2081 | def on_options(req, resp, id_, eid): |
|
2082 | resp.status = falcon.HTTP_200 |
|
2083 | ||
2084 | @staticmethod |
|
2085 | @user_logger |
|
2086 | def on_delete(req, resp, id_, eid): |
|
2087 | admin_control(req) |
|
2088 | if not id_.isdigit() or int(id_) <= 0: |
|
2089 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2090 | description='API.INVALID_SPACE_ID') |
|
2091 | ||
2092 | if not eid.isdigit() or int(eid) <= 0: |
|
2093 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2094 | description='API.INVALID_PHOTOVOLTAIC_POWER_STATION_ID') |
|
2095 | ||
2096 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2097 | cursor = cnx.cursor() |
|
2098 | ||
2099 | cursor.execute(" SELECT name " |
|
2100 | " FROM tbl_spaces " |
|
2101 | " WHERE id = %s ", (id_,)) |
|
2102 | if cursor.fetchone() is None: |
|
2103 | cursor.close() |
|
2104 | cnx.close() |
|
2105 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2106 | description='API.SPACE_NOT_FOUND') |
|
2107 | ||
2108 | cursor.execute(" SELECT name " |
|
2109 | " FROM tbl_photovoltaic_power_stations " |
|
2110 | " WHERE id = %s ", (eid,)) |
|
2111 | if cursor.fetchone() is None: |
|
2112 | cursor.close() |
|
2113 | cnx.close() |
|
2114 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2115 | description='API.PHOTOVOLTAIC_POWER_STATION_NOT_FOUND') |
|
2116 | ||
2117 | cursor.execute(" SELECT id " |
|
2118 | " FROM tbl_spaces_photovoltaic_power_stations " |
|
2119 | " WHERE space_id = %s AND photovoltaic_power_station_id = %s ", (id_, eid)) |
|
2120 | if cursor.fetchone() is None: |
|
2121 | cursor.close() |
|
2122 | cnx.close() |
|
2123 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2124 | description='API.SPACE_PHOTOVOLTAIC_POWER_STATION_RELATION_NOT_FOUND') |
|
2125 | ||
2126 | cursor.execute(" DELETE FROM tbl_spaces_photovoltaic_power_stations " |
|
2127 | " WHERE space_id = %s AND photovoltaic_power_station_id = %s ", (id_, eid)) |
|
2128 | cnx.commit() |
|
2129 | ||
2130 | cursor.close() |
|
2131 | cnx.close() |
|
2132 | ||
2133 | resp.status = falcon.HTTP_204 |
|
2134 | ||
2135 | ||
2136 | class SpacePointCollection: |
|
@@ 1899-1957 (lines=59) @@ | ||
1896 | resp.location = '/spaces/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
1897 | ||
1898 | ||
1899 | class SpaceOfflineMeterItem: |
|
1900 | def __init__(self): |
|
1901 | """Initializes Class""" |
|
1902 | pass |
|
1903 | ||
1904 | @staticmethod |
|
1905 | def on_options(req, resp, id_, mid): |
|
1906 | resp.status = falcon.HTTP_200 |
|
1907 | ||
1908 | @staticmethod |
|
1909 | @user_logger |
|
1910 | def on_delete(req, resp, id_, mid): |
|
1911 | admin_control(req) |
|
1912 | if not id_.isdigit() or int(id_) <= 0: |
|
1913 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1914 | description='API.INVALID_SPACE_ID') |
|
1915 | ||
1916 | if not mid.isdigit() or int(mid) <= 0: |
|
1917 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1918 | description='API.INVALID_OFFLINE_METER_ID') |
|
1919 | ||
1920 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1921 | cursor = cnx.cursor() |
|
1922 | ||
1923 | cursor.execute(" SELECT name " |
|
1924 | " FROM tbl_spaces " |
|
1925 | " WHERE id = %s ", (id_,)) |
|
1926 | if cursor.fetchone() is None: |
|
1927 | cursor.close() |
|
1928 | cnx.close() |
|
1929 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1930 | description='API.SPACE_NOT_FOUND') |
|
1931 | ||
1932 | cursor.execute(" SELECT name " |
|
1933 | " FROM tbl_offline_meters " |
|
1934 | " WHERE id = %s ", (mid,)) |
|
1935 | if cursor.fetchone() is None: |
|
1936 | cursor.close() |
|
1937 | cnx.close() |
|
1938 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1939 | description='API.OFFLINE_METER_NOT_FOUND') |
|
1940 | ||
1941 | cursor.execute(" SELECT id " |
|
1942 | " FROM tbl_spaces_offline_meters " |
|
1943 | " WHERE space_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1944 | if cursor.fetchone() is None: |
|
1945 | cursor.close() |
|
1946 | cnx.close() |
|
1947 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1948 | description='API.SPACE_OFFLINE_METER_RELATION_NOT_FOUND') |
|
1949 | ||
1950 | cursor.execute(" DELETE FROM tbl_spaces_offline_meters " |
|
1951 | " WHERE space_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1952 | cnx.commit() |
|
1953 | ||
1954 | cursor.close() |
|
1955 | cnx.close() |
|
1956 | ||
1957 | resp.status = falcon.HTTP_204 |
|
1958 | ||
1959 | ||
1960 | class SpacePhotovoltaicPowerStationCollection: |
|
@@ 1710-1768 (lines=59) @@ | ||
1707 | resp.location = '/spaces/' + str(id_) + '/microgrids/' + str(microgrid_id) |
|
1708 | ||
1709 | ||
1710 | class SpaceMicrogridItem: |
|
1711 | def __init__(self): |
|
1712 | """Initializes Class""" |
|
1713 | pass |
|
1714 | ||
1715 | @staticmethod |
|
1716 | def on_options(req, resp, id_, mid): |
|
1717 | resp.status = falcon.HTTP_200 |
|
1718 | ||
1719 | @staticmethod |
|
1720 | @user_logger |
|
1721 | def on_delete(req, resp, id_, mid): |
|
1722 | admin_control(req) |
|
1723 | if not id_.isdigit() or int(id_) <= 0: |
|
1724 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1725 | description='API.INVALID_SPACE_ID') |
|
1726 | ||
1727 | if not mid.isdigit() or int(mid) <= 0: |
|
1728 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1729 | description='API.INVALID_MICROGRID_ID') |
|
1730 | ||
1731 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1732 | cursor = cnx.cursor() |
|
1733 | ||
1734 | cursor.execute(" SELECT name " |
|
1735 | " FROM tbl_spaces " |
|
1736 | " WHERE id = %s ", (id_,)) |
|
1737 | if cursor.fetchone() is None: |
|
1738 | cursor.close() |
|
1739 | cnx.close() |
|
1740 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1741 | description='API.SPACE_NOT_FOUND') |
|
1742 | ||
1743 | cursor.execute(" SELECT name " |
|
1744 | " FROM tbl_microgrids " |
|
1745 | " WHERE id = %s ", (mid,)) |
|
1746 | if cursor.fetchone() is None: |
|
1747 | cursor.close() |
|
1748 | cnx.close() |
|
1749 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1750 | description='API.MICROGRID_NOT_FOUND') |
|
1751 | ||
1752 | cursor.execute(" SELECT id " |
|
1753 | " FROM tbl_spaces_microgrids " |
|
1754 | " WHERE space_id = %s AND microgrid_id = %s ", (id_, mid)) |
|
1755 | if cursor.fetchone() is None: |
|
1756 | cursor.close() |
|
1757 | cnx.close() |
|
1758 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1759 | description='API.SPACE_MICROGRID_RELATION_NOT_FOUND') |
|
1760 | ||
1761 | cursor.execute(" DELETE FROM tbl_spaces_microgrids " |
|
1762 | " WHERE space_id = %s AND microgrid_id = %s ", (id_, mid)) |
|
1763 | cnx.commit() |
|
1764 | ||
1765 | cursor.close() |
|
1766 | cnx.close() |
|
1767 | ||
1768 | resp.status = falcon.HTTP_204 |
|
1769 | ||
1770 | ||
1771 | class SpaceOfflineMeterCollection: |
|
@@ 1169-1227 (lines=59) @@ | ||
1166 | resp.location = '/spaces/' + str(id_) + '/energystoragepowerstations/' + str(energy_storage_power_station_id) |
|
1167 | ||
1168 | ||
1169 | class SpaceEnergyStoragePowerStationItem: |
|
1170 | def __init__(self): |
|
1171 | """Initializes Class""" |
|
1172 | pass |
|
1173 | ||
1174 | @staticmethod |
|
1175 | def on_options(req, resp, id_, eid): |
|
1176 | resp.status = falcon.HTTP_200 |
|
1177 | ||
1178 | @staticmethod |
|
1179 | @user_logger |
|
1180 | def on_delete(req, resp, id_, eid): |
|
1181 | admin_control(req) |
|
1182 | if not id_.isdigit() or int(id_) <= 0: |
|
1183 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1184 | description='API.INVALID_SPACE_ID') |
|
1185 | ||
1186 | if not eid.isdigit() or int(eid) <= 0: |
|
1187 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1188 | description='API.INVALID_ENERGY_STORAGE_POWER_STATION_ID') |
|
1189 | ||
1190 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1191 | cursor = cnx.cursor() |
|
1192 | ||
1193 | cursor.execute(" SELECT name " |
|
1194 | " FROM tbl_spaces " |
|
1195 | " WHERE id = %s ", (id_,)) |
|
1196 | if cursor.fetchone() is None: |
|
1197 | cursor.close() |
|
1198 | cnx.close() |
|
1199 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1200 | description='API.SPACE_NOT_FOUND') |
|
1201 | ||
1202 | cursor.execute(" SELECT name " |
|
1203 | " FROM tbl_energy_storage_power_stations " |
|
1204 | " WHERE id = %s ", (eid,)) |
|
1205 | if cursor.fetchone() is None: |
|
1206 | cursor.close() |
|
1207 | cnx.close() |
|
1208 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1209 | description='API.ENERGY_STORAGE_POWER_STATION_NOT_FOUND') |
|
1210 | ||
1211 | cursor.execute(" SELECT id " |
|
1212 | " FROM tbl_spaces_energy_storage_power_stations " |
|
1213 | " WHERE space_id = %s AND energy_storage_power_station_id = %s ", (id_, eid)) |
|
1214 | if cursor.fetchone() is None: |
|
1215 | cursor.close() |
|
1216 | cnx.close() |
|
1217 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1218 | description='API.SPACE_ENERGY_STORAGE_POWER_STATION_RELATION_NOT_FOUND') |
|
1219 | ||
1220 | cursor.execute(" DELETE FROM tbl_spaces_energy_storage_power_stations " |
|
1221 | " WHERE space_id = %s AND energy_storage_power_station_id = %s ", (id_, eid)) |
|
1222 | cnx.commit() |
|
1223 | ||
1224 | cursor.close() |
|
1225 | cnx.close() |
|
1226 | ||
1227 | resp.status = falcon.HTTP_204 |
|
1228 | ||
1229 | ||
1230 | class SpaceEquipmentCollection: |
|
@@ 954-1012 (lines=59) @@ | ||
951 | resp.location = '/spaces/' + str(id_) + '/combinedequipments/' + str(combined_equipment_id) |
|
952 | ||
953 | ||
954 | class SpaceCombinedEquipmentItem: |
|
955 | def __init__(self): |
|
956 | """Initializes Class""" |
|
957 | pass |
|
958 | ||
959 | @staticmethod |
|
960 | def on_options(req, resp, id_, eid): |
|
961 | resp.status = falcon.HTTP_200 |
|
962 | ||
963 | @staticmethod |
|
964 | @user_logger |
|
965 | def on_delete(req, resp, id_, eid): |
|
966 | admin_control(req) |
|
967 | if not id_.isdigit() or int(id_) <= 0: |
|
968 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
969 | description='API.INVALID_SPACE_ID') |
|
970 | ||
971 | if not eid.isdigit() or int(eid) <= 0: |
|
972 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
973 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
974 | ||
975 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
976 | cursor = cnx.cursor() |
|
977 | ||
978 | cursor.execute(" SELECT name " |
|
979 | " FROM tbl_spaces " |
|
980 | " WHERE id = %s ", (id_,)) |
|
981 | if cursor.fetchone() is None: |
|
982 | cursor.close() |
|
983 | cnx.close() |
|
984 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
985 | description='API.SPACE_NOT_FOUND') |
|
986 | ||
987 | cursor.execute(" SELECT name " |
|
988 | " FROM tbl_combined_equipments " |
|
989 | " WHERE id = %s ", (eid,)) |
|
990 | if cursor.fetchone() is None: |
|
991 | cursor.close() |
|
992 | cnx.close() |
|
993 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
994 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
995 | ||
996 | cursor.execute(" SELECT id " |
|
997 | " FROM tbl_spaces_combined_equipments " |
|
998 | " WHERE space_id = %s AND combined_equipment_id = %s ", (id_, eid)) |
|
999 | if cursor.fetchone() is None: |
|
1000 | cursor.close() |
|
1001 | cnx.close() |
|
1002 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1003 | description='API.SPACE_COMBINED_EQUIPMENT_RELATION_NOT_FOUND') |
|
1004 | ||
1005 | cursor.execute(" DELETE FROM tbl_spaces_combined_equipments " |
|
1006 | " WHERE space_id = %s AND combined_equipment_id = %s ", (id_, eid)) |
|
1007 | cnx.commit() |
|
1008 | ||
1009 | cursor.close() |
|
1010 | cnx.close() |
|
1011 | ||
1012 | resp.status = falcon.HTTP_204 |
|
1013 | ||
1014 | ||
1015 | class SpaceEnergyStoragePowerStationCollection: |
|
@@ 3689-3746 (lines=58) @@ | ||
3686 | resp.location = '/spaces/' + str(id_) + '/commands/' + str(command_id) |
|
3687 | ||
3688 | ||
3689 | class SpaceCommandItem: |
|
3690 | def __init__(self): |
|
3691 | """Initializes Class""" |
|
3692 | pass |
|
3693 | ||
3694 | @staticmethod |
|
3695 | def on_options(req, resp, id_, cid): |
|
3696 | resp.status = falcon.HTTP_200 |
|
3697 | ||
3698 | @staticmethod |
|
3699 | @user_logger |
|
3700 | def on_delete(req, resp, id_, cid): |
|
3701 | admin_control(req) |
|
3702 | if not id_.isdigit() or int(id_) <= 0: |
|
3703 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
3704 | description='API.INVALID_SPACE_ID') |
|
3705 | ||
3706 | if not cid.isdigit() or int(cid) <= 0: |
|
3707 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
3708 | description='API.INVALID_COMMAND_ID') |
|
3709 | ||
3710 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
3711 | cursor = cnx.cursor() |
|
3712 | ||
3713 | cursor.execute(" SELECT name " |
|
3714 | " FROM tbl_spaces " |
|
3715 | " WHERE id = %s ", (id_,)) |
|
3716 | if cursor.fetchone() is None: |
|
3717 | cursor.close() |
|
3718 | cnx.close() |
|
3719 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3720 | description='API.SPACE_NOT_FOUND') |
|
3721 | ||
3722 | cursor.execute(" SELECT name " |
|
3723 | " FROM tbl_commands " |
|
3724 | " WHERE id = %s ", (cid,)) |
|
3725 | if cursor.fetchone() is None: |
|
3726 | cursor.close() |
|
3727 | cnx.close() |
|
3728 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3729 | description='API.COMMAND_NOT_FOUND') |
|
3730 | ||
3731 | cursor.execute(" SELECT id " |
|
3732 | " FROM tbl_spaces_commands " |
|
3733 | " WHERE space_id = %s AND command_id = %s ", (id_, cid)) |
|
3734 | if cursor.fetchone() is None: |
|
3735 | cursor.close() |
|
3736 | cnx.close() |
|
3737 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3738 | description='API.SPACE_COMMAND_RELATION_NOT_FOUND') |
|
3739 | ||
3740 | cursor.execute(" DELETE FROM tbl_spaces_commands WHERE space_id = %s AND command_id = %s ", (id_, cid)) |
|
3741 | cnx.commit() |
|
3742 | ||
3743 | cursor.close() |
|
3744 | cnx.close() |
|
3745 | ||
3746 | resp.status = falcon.HTTP_204 |
|
3747 | ||
3748 | ||
3749 | class SpaceExport: |
|
@@ 2964-3021 (lines=58) @@ | ||
2961 | resp.location = '/spaces/' + str(id_) + '/tenants/' + str(tenant_id) |
|
2962 | ||
2963 | ||
2964 | class SpaceTenantItem: |
|
2965 | def __init__(self): |
|
2966 | """Initializes Class""" |
|
2967 | pass |
|
2968 | ||
2969 | @staticmethod |
|
2970 | def on_options(req, resp, id_, tid): |
|
2971 | resp.status = falcon.HTTP_200 |
|
2972 | ||
2973 | @staticmethod |
|
2974 | @user_logger |
|
2975 | def on_delete(req, resp, id_, tid): |
|
2976 | admin_control(req) |
|
2977 | if not id_.isdigit() or int(id_) <= 0: |
|
2978 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2979 | description='API.INVALID_SPACE_ID') |
|
2980 | ||
2981 | if not tid.isdigit() or int(tid) <= 0: |
|
2982 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2983 | description='API.INVALID_TENANT_ID') |
|
2984 | ||
2985 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2986 | cursor = cnx.cursor() |
|
2987 | ||
2988 | cursor.execute(" SELECT name " |
|
2989 | " FROM tbl_spaces " |
|
2990 | " WHERE id = %s ", (id_,)) |
|
2991 | if cursor.fetchone() is None: |
|
2992 | cursor.close() |
|
2993 | cnx.close() |
|
2994 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2995 | description='API.SPACE_NOT_FOUND') |
|
2996 | ||
2997 | cursor.execute(" SELECT name " |
|
2998 | " FROM tbl_tenants " |
|
2999 | " WHERE id = %s ", (tid,)) |
|
3000 | if cursor.fetchone() is None: |
|
3001 | cursor.close() |
|
3002 | cnx.close() |
|
3003 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3004 | description='API.TENANT_NOT_FOUND') |
|
3005 | ||
3006 | cursor.execute(" SELECT id " |
|
3007 | " FROM tbl_spaces_tenants " |
|
3008 | " WHERE space_id = %s AND tenant_id = %s ", (id_, tid)) |
|
3009 | if cursor.fetchone() is None: |
|
3010 | cursor.close() |
|
3011 | cnx.close() |
|
3012 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
3013 | description='API.SPACE_TENANT_RELATION_NOT_FOUND') |
|
3014 | ||
3015 | cursor.execute(" DELETE FROM tbl_spaces_tenants WHERE space_id = %s AND tenant_id = %s ", (id_, tid)) |
|
3016 | cnx.commit() |
|
3017 | ||
3018 | cursor.close() |
|
3019 | cnx.close() |
|
3020 | ||
3021 | resp.status = falcon.HTTP_204 |
|
3022 | ||
3023 | ||
3024 | class SpaceVirtualMeterCollection: |
|
@@ 2789-2846 (lines=58) @@ | ||
2786 | resp.location = '/spaces/' + str(id_) + '/stores/' + str(store_id) |
|
2787 | ||
2788 | ||
2789 | class SpaceStoreItem: |
|
2790 | def __init__(self): |
|
2791 | """Initializes Class""" |
|
2792 | pass |
|
2793 | ||
2794 | @staticmethod |
|
2795 | def on_options(req, resp, id_, tid): |
|
2796 | resp.status = falcon.HTTP_200 |
|
2797 | ||
2798 | @staticmethod |
|
2799 | @user_logger |
|
2800 | def on_delete(req, resp, id_, tid): |
|
2801 | admin_control(req) |
|
2802 | if not id_.isdigit() or int(id_) <= 0: |
|
2803 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2804 | description='API.INVALID_SPACE_ID') |
|
2805 | ||
2806 | if not tid.isdigit() or int(tid) <= 0: |
|
2807 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2808 | description='API.INVALID_STORE_ID') |
|
2809 | ||
2810 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2811 | cursor = cnx.cursor() |
|
2812 | ||
2813 | cursor.execute(" SELECT name " |
|
2814 | " FROM tbl_spaces " |
|
2815 | " WHERE id = %s ", (id_,)) |
|
2816 | if cursor.fetchone() is None: |
|
2817 | cursor.close() |
|
2818 | cnx.close() |
|
2819 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2820 | description='API.SPACE_NOT_FOUND') |
|
2821 | ||
2822 | cursor.execute(" SELECT name " |
|
2823 | " FROM tbl_stores " |
|
2824 | " WHERE id = %s ", (tid,)) |
|
2825 | if cursor.fetchone() is None: |
|
2826 | cursor.close() |
|
2827 | cnx.close() |
|
2828 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2829 | description='API.STORE_NOT_FOUND') |
|
2830 | ||
2831 | cursor.execute(" SELECT id " |
|
2832 | " FROM tbl_spaces_stores " |
|
2833 | " WHERE space_id = %s AND store_id = %s ", (id_, tid)) |
|
2834 | if cursor.fetchone() is None: |
|
2835 | cursor.close() |
|
2836 | cnx.close() |
|
2837 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2838 | description='API.SPACE_STORE_RELATION_NOT_FOUND') |
|
2839 | ||
2840 | cursor.execute(" DELETE FROM tbl_spaces_stores WHERE space_id = %s AND store_id = %s ", (id_, tid)) |
|
2841 | cnx.commit() |
|
2842 | ||
2843 | cursor.close() |
|
2844 | cnx.close() |
|
2845 | ||
2846 | resp.status = falcon.HTTP_204 |
|
2847 | ||
2848 | ||
2849 | class SpaceTenantCollection: |
|
@@ 2614-2671 (lines=58) @@ | ||
2611 | resp.location = '/spaces/' + str(id_) + '/shopfloors/' + str(shopfloor_id) |
|
2612 | ||
2613 | ||
2614 | class SpaceShopfloorItem: |
|
2615 | def __init__(self): |
|
2616 | """Initializes Class""" |
|
2617 | pass |
|
2618 | ||
2619 | @staticmethod |
|
2620 | def on_options(req, resp, id_, sid): |
|
2621 | resp.status = falcon.HTTP_200 |
|
2622 | ||
2623 | @staticmethod |
|
2624 | @user_logger |
|
2625 | def on_delete(req, resp, id_, sid): |
|
2626 | admin_control(req) |
|
2627 | if not id_.isdigit() or int(id_) <= 0: |
|
2628 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2629 | description='API.INVALID_SPACE_ID') |
|
2630 | ||
2631 | if not sid.isdigit() or int(sid) <= 0: |
|
2632 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2633 | description='API.INVALID_SHOPFLOOR_ID') |
|
2634 | ||
2635 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2636 | cursor = cnx.cursor() |
|
2637 | ||
2638 | cursor.execute(" SELECT name " |
|
2639 | " FROM tbl_spaces " |
|
2640 | " WHERE id = %s ", (id_,)) |
|
2641 | if cursor.fetchone() is None: |
|
2642 | cursor.close() |
|
2643 | cnx.close() |
|
2644 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2645 | description='API.SPACE_NOT_FOUND') |
|
2646 | ||
2647 | cursor.execute(" SELECT name " |
|
2648 | " FROM tbl_shopfloors " |
|
2649 | " WHERE id = %s ", (sid,)) |
|
2650 | if cursor.fetchone() is None: |
|
2651 | cursor.close() |
|
2652 | cnx.close() |
|
2653 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2654 | description='API.SHOPFLOOR_NOT_FOUND') |
|
2655 | ||
2656 | cursor.execute(" SELECT id " |
|
2657 | " FROM tbl_spaces_shopfloors " |
|
2658 | " WHERE space_id = %s AND shopfloor_id = %s ", (id_, sid)) |
|
2659 | if cursor.fetchone() is None: |
|
2660 | cursor.close() |
|
2661 | cnx.close() |
|
2662 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2663 | description='API.SPACE_SHOPFLOOR_RELATION_NOT_FOUND') |
|
2664 | ||
2665 | cursor.execute(" DELETE FROM tbl_spaces_shopfloors WHERE space_id = %s AND shopfloor_id = %s ", (id_, sid)) |
|
2666 | cnx.commit() |
|
2667 | ||
2668 | cursor.close() |
|
2669 | cnx.close() |
|
2670 | ||
2671 | resp.status = falcon.HTTP_204 |
|
2672 | ||
2673 | ||
2674 | class SpaceStoreCollection: |
|
@@ 2439-2496 (lines=58) @@ | ||
2436 | resp.location = '/spaces/' + str(id_) + '/sensors/' + str(sensor_id) |
|
2437 | ||
2438 | ||
2439 | class SpaceSensorItem: |
|
2440 | def __init__(self): |
|
2441 | """Initializes Class""" |
|
2442 | pass |
|
2443 | ||
2444 | @staticmethod |
|
2445 | def on_options(req, resp, id_, sid): |
|
2446 | resp.status = falcon.HTTP_200 |
|
2447 | ||
2448 | @staticmethod |
|
2449 | @user_logger |
|
2450 | def on_delete(req, resp, id_, sid): |
|
2451 | admin_control(req) |
|
2452 | if not id_.isdigit() or int(id_) <= 0: |
|
2453 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2454 | description='API.INVALID_SPACE_ID') |
|
2455 | ||
2456 | if not sid.isdigit() or int(sid) <= 0: |
|
2457 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2458 | description='API.INVALID_SENSOR_ID') |
|
2459 | ||
2460 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2461 | cursor = cnx.cursor() |
|
2462 | ||
2463 | cursor.execute(" SELECT name " |
|
2464 | " FROM tbl_spaces " |
|
2465 | " WHERE id = %s ", (id_,)) |
|
2466 | if cursor.fetchone() is None: |
|
2467 | cursor.close() |
|
2468 | cnx.close() |
|
2469 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2470 | description='API.SPACE_NOT_FOUND') |
|
2471 | ||
2472 | cursor.execute(" SELECT name " |
|
2473 | " FROM tbl_sensors " |
|
2474 | " WHERE id = %s ", (sid,)) |
|
2475 | if cursor.fetchone() is None: |
|
2476 | cursor.close() |
|
2477 | cnx.close() |
|
2478 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2479 | description='API.SENSOR_NOT_FOUND') |
|
2480 | ||
2481 | cursor.execute(" SELECT id " |
|
2482 | " FROM tbl_spaces_sensors " |
|
2483 | " WHERE space_id = %s AND sensor_id = %s ", (id_, sid)) |
|
2484 | if cursor.fetchone() is None: |
|
2485 | cursor.close() |
|
2486 | cnx.close() |
|
2487 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2488 | description='API.SPACE_SENSOR_RELATION_NOT_FOUND') |
|
2489 | ||
2490 | cursor.execute(" DELETE FROM tbl_spaces_sensors WHERE space_id = %s AND sensor_id = %s ", (id_, sid)) |
|
2491 | cnx.commit() |
|
2492 | ||
2493 | cursor.close() |
|
2494 | cnx.close() |
|
2495 | ||
2496 | resp.status = falcon.HTTP_204 |
|
2497 | ||
2498 | ||
2499 | class SpaceShopfloorCollection: |
|
@@ 1345-1402 (lines=58) @@ | ||
1342 | resp.location = '/spaces/' + str(id_) + '/equipments/' + str(equipment_id) |
|
1343 | ||
1344 | ||
1345 | class SpaceEquipmentItem: |
|
1346 | def __init__(self): |
|
1347 | """Initializes Class""" |
|
1348 | pass |
|
1349 | ||
1350 | @staticmethod |
|
1351 | def on_options(req, resp, id_, eid): |
|
1352 | resp.status = falcon.HTTP_200 |
|
1353 | ||
1354 | @staticmethod |
|
1355 | @user_logger |
|
1356 | def on_delete(req, resp, id_, eid): |
|
1357 | admin_control(req) |
|
1358 | if not id_.isdigit() or int(id_) <= 0: |
|
1359 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1360 | description='API.INVALID_SPACE_ID') |
|
1361 | ||
1362 | if not eid.isdigit() or int(eid) <= 0: |
|
1363 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1364 | description='API.INVALID_EQUIPMENT_ID') |
|
1365 | ||
1366 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1367 | cursor = cnx.cursor() |
|
1368 | ||
1369 | cursor.execute(" SELECT name " |
|
1370 | " FROM tbl_spaces " |
|
1371 | " WHERE id = %s ", (id_,)) |
|
1372 | if cursor.fetchone() is None: |
|
1373 | cursor.close() |
|
1374 | cnx.close() |
|
1375 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1376 | description='API.SPACE_NOT_FOUND') |
|
1377 | ||
1378 | cursor.execute(" SELECT name " |
|
1379 | " FROM tbl_equipments " |
|
1380 | " WHERE id = %s ", (eid,)) |
|
1381 | if cursor.fetchone() is None: |
|
1382 | cursor.close() |
|
1383 | cnx.close() |
|
1384 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1385 | description='API.EQUIPMENT_NOT_FOUND') |
|
1386 | ||
1387 | cursor.execute(" SELECT id " |
|
1388 | " FROM tbl_spaces_equipments " |
|
1389 | " WHERE space_id = %s AND equipment_id = %s ", (id_, eid)) |
|
1390 | if cursor.fetchone() is None: |
|
1391 | cursor.close() |
|
1392 | cnx.close() |
|
1393 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1394 | description='API.SPACE_EQUIPMENT_RELATION_NOT_FOUND') |
|
1395 | ||
1396 | cursor.execute(" DELETE FROM tbl_spaces_equipments WHERE space_id = %s AND equipment_id = %s ", (id_, eid)) |
|
1397 | cnx.commit() |
|
1398 | ||
1399 | cursor.close() |
|
1400 | cnx.close() |
|
1401 | ||
1402 | resp.status = falcon.HTTP_204 |
|
1403 | ||
1404 | ||
1405 | class SpaceMeterCollection: |
@@ 533-592 (lines=60) @@ | ||
530 | resp.location = '/distributioncircuits/' + str(id_) + '/points/' + str(new_values['data']['point_id']) |
|
531 | ||
532 | ||
533 | class DistributionCircuitPointItem: |
|
534 | def __init__(self): |
|
535 | """Initializes DistributionCircuitPointItem""" |
|
536 | pass |
|
537 | ||
538 | @staticmethod |
|
539 | def on_options(req, resp, id_, pid): |
|
540 | _=req |
|
541 | resp.status = falcon.HTTP_200 |
|
542 | _=id_ |
|
543 | @staticmethod |
|
544 | @user_logger |
|
545 | def on_delete(req, resp, id_, pid): |
|
546 | admin_control(req) |
|
547 | if not id_.isdigit() or int(id_) <= 0: |
|
548 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
549 | description='API.INVALID_DISTRIBUTION_CIRCUIT_ID') |
|
550 | ||
551 | if not pid.isdigit() or int(pid) <= 0: |
|
552 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
553 | description='API.INVALID_POINT_ID') |
|
554 | ||
555 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
556 | cursor = cnx.cursor() |
|
557 | ||
558 | cursor.execute(" SELECT name " |
|
559 | " FROM tbl_distribution_circuits " |
|
560 | " WHERE id = %s ", (id_,)) |
|
561 | if cursor.fetchone() is None: |
|
562 | cursor.close() |
|
563 | cnx.close() |
|
564 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
565 | description='API.DISTRIBUTION_CIRCUIT_NOT_FOUND') |
|
566 | ||
567 | cursor.execute(" SELECT name " |
|
568 | " FROM tbl_points " |
|
569 | " WHERE id = %s ", (pid,)) |
|
570 | if cursor.fetchone() is None: |
|
571 | cursor.close() |
|
572 | cnx.close() |
|
573 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
574 | description='API.POINT_NOT_FOUND') |
|
575 | ||
576 | cursor.execute(" SELECT id " |
|
577 | " FROM tbl_distribution_circuits_points " |
|
578 | " WHERE distribution_circuit_id = %s AND point_id = %s ", (id_, pid)) |
|
579 | if cursor.fetchone() is None: |
|
580 | cursor.close() |
|
581 | cnx.close() |
|
582 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
583 | description='API.DISTRIBUTION_CIRCUIT_POINT_RELATION_NOT_FOUND') |
|
584 | ||
585 | cursor.execute(" DELETE FROM tbl_distribution_circuits_points " |
|
586 | " WHERE distribution_circuit_id = %s AND point_id = %s ", (id_, pid)) |
|
587 | cnx.commit() |
|
588 | ||
589 | cursor.close() |
|
590 | cnx.close() |
|
591 | ||
592 | resp.status = falcon.HTTP_204 |
|
593 | ||
594 |
@@ 1853-1911 (lines=59) @@ | ||
1850 | resp.location = '/equipments/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
1851 | ||
1852 | ||
1853 | class EquipmentVirtualMeterItem: |
|
1854 | def __init__(self): |
|
1855 | """Initializes EquipmentVirtualMeterItem""" |
|
1856 | pass |
|
1857 | ||
1858 | @staticmethod |
|
1859 | def on_options(req, resp, id_, mid): |
|
1860 | resp.status = falcon.HTTP_200 |
|
1861 | ||
1862 | @staticmethod |
|
1863 | @user_logger |
|
1864 | def on_delete(req, resp, id_, mid): |
|
1865 | admin_control(req) |
|
1866 | if not id_.isdigit() or int(id_) <= 0: |
|
1867 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1868 | description='API.INVALID_EQUIPMENT_ID') |
|
1869 | ||
1870 | if not mid.isdigit() or int(mid) <= 0: |
|
1871 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1872 | description='API.INVALID_VIRTUAL_METER_ID') |
|
1873 | ||
1874 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1875 | cursor = cnx.cursor() |
|
1876 | ||
1877 | cursor.execute(" SELECT name " |
|
1878 | " FROM tbl_equipments " |
|
1879 | " WHERE id = %s ", (id_,)) |
|
1880 | if cursor.fetchone() is None: |
|
1881 | cursor.close() |
|
1882 | cnx.close() |
|
1883 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1884 | description='API.EQUIPMENT_NOT_FOUND') |
|
1885 | ||
1886 | cursor.execute(" SELECT name " |
|
1887 | " FROM tbl_virtual_meters " |
|
1888 | " WHERE id = %s ", (mid,)) |
|
1889 | if cursor.fetchone() is None: |
|
1890 | cursor.close() |
|
1891 | cnx.close() |
|
1892 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1893 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
1894 | ||
1895 | cursor.execute(" SELECT id " |
|
1896 | " FROM tbl_equipments_virtual_meters " |
|
1897 | " WHERE equipment_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1898 | if cursor.fetchone() is None: |
|
1899 | cursor.close() |
|
1900 | cnx.close() |
|
1901 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1902 | description='API.EQUIPMENT_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
1903 | ||
1904 | cursor.execute(" DELETE FROM tbl_equipments_virtual_meters " |
|
1905 | " WHERE equipment_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1906 | cnx.commit() |
|
1907 | ||
1908 | cursor.close() |
|
1909 | cnx.close() |
|
1910 | ||
1911 | resp.status = falcon.HTTP_204 |
|
1912 | ||
1913 | ||
1914 | class EquipmentCommandCollection: |
|
@@ 1655-1713 (lines=59) @@ | ||
1652 | resp.location = '/equipments/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
1653 | ||
1654 | ||
1655 | class EquipmentOfflineMeterItem: |
|
1656 | def __init__(self): |
|
1657 | """Initializes EquipmentOfflineMeterItem""" |
|
1658 | pass |
|
1659 | ||
1660 | @staticmethod |
|
1661 | def on_options(req, resp, id_, mid): |
|
1662 | resp.status = falcon.HTTP_200 |
|
1663 | ||
1664 | @staticmethod |
|
1665 | @user_logger |
|
1666 | def on_delete(req, resp, id_, mid): |
|
1667 | admin_control(req) |
|
1668 | if not id_.isdigit() or int(id_) <= 0: |
|
1669 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1670 | description='API.INVALID_EQUIPMENT_ID') |
|
1671 | ||
1672 | if not mid.isdigit() or int(mid) <= 0: |
|
1673 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1674 | description='API.INVALID_OFFLINE_METER_ID') |
|
1675 | ||
1676 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1677 | cursor = cnx.cursor() |
|
1678 | ||
1679 | cursor.execute(" SELECT name " |
|
1680 | " FROM tbl_equipments " |
|
1681 | " WHERE id = %s ", (id_,)) |
|
1682 | if cursor.fetchone() is None: |
|
1683 | cursor.close() |
|
1684 | cnx.close() |
|
1685 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1686 | description='API.EQUIPMENT_NOT_FOUND') |
|
1687 | ||
1688 | cursor.execute(" SELECT name " |
|
1689 | " FROM tbl_offline_meters " |
|
1690 | " WHERE id = %s ", (mid,)) |
|
1691 | if cursor.fetchone() is None: |
|
1692 | cursor.close() |
|
1693 | cnx.close() |
|
1694 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1695 | description='API.OFFLINE_METER_NOT_FOUND') |
|
1696 | ||
1697 | cursor.execute(" SELECT id " |
|
1698 | " FROM tbl_equipments_offline_meters " |
|
1699 | " WHERE equipment_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1700 | if cursor.fetchone() is None: |
|
1701 | cursor.close() |
|
1702 | cnx.close() |
|
1703 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1704 | description='API.EQUIPMENT_OFFLINE_METER_RELATION_NOT_FOUND') |
|
1705 | ||
1706 | cursor.execute(" DELETE FROM tbl_equipments_offline_meters " |
|
1707 | " WHERE equipment_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1708 | cnx.commit() |
|
1709 | ||
1710 | cursor.close() |
|
1711 | cnx.close() |
|
1712 | ||
1713 | resp.status = falcon.HTTP_204 |
|
1714 | ||
1715 | ||
1716 | class EquipmentVirtualMeterCollection: |
|
@@ 2031-2088 (lines=58) @@ | ||
2028 | resp.location = '/equipments/' + str(id_) + '/commands/' + str(command_id) |
|
2029 | ||
2030 | ||
2031 | class EquipmentCommandItem: |
|
2032 | def __init__(self): |
|
2033 | """Initializes Class""" |
|
2034 | pass |
|
2035 | ||
2036 | @staticmethod |
|
2037 | def on_options(req, resp, id_, cid): |
|
2038 | resp.status = falcon.HTTP_200 |
|
2039 | ||
2040 | @staticmethod |
|
2041 | @user_logger |
|
2042 | def on_delete(req, resp, id_, cid): |
|
2043 | admin_control(req) |
|
2044 | if not id_.isdigit() or int(id_) <= 0: |
|
2045 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2046 | description='API.INVALID_EQUIPMENT_ID') |
|
2047 | ||
2048 | if not cid.isdigit() or int(cid) <= 0: |
|
2049 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2050 | description='API.INVALID_COMMAND_ID') |
|
2051 | ||
2052 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2053 | cursor = cnx.cursor() |
|
2054 | ||
2055 | cursor.execute(" SELECT name " |
|
2056 | " FROM tbl_equipments " |
|
2057 | " WHERE id = %s ", (id_,)) |
|
2058 | if cursor.fetchone() is None: |
|
2059 | cursor.close() |
|
2060 | cnx.close() |
|
2061 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2062 | description='API.EQUIPMENT_NOT_FOUND') |
|
2063 | ||
2064 | cursor.execute(" SELECT name " |
|
2065 | " FROM tbl_commands " |
|
2066 | " WHERE id = %s ", (cid,)) |
|
2067 | if cursor.fetchone() is None: |
|
2068 | cursor.close() |
|
2069 | cnx.close() |
|
2070 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2071 | description='API.COMMAND_NOT_FOUND') |
|
2072 | ||
2073 | cursor.execute(" SELECT id " |
|
2074 | " FROM tbl_equipments_commands " |
|
2075 | " WHERE equipment_id = %s AND command_id = %s ", (id_, cid)) |
|
2076 | if cursor.fetchone() is None: |
|
2077 | cursor.close() |
|
2078 | cnx.close() |
|
2079 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
2080 | description='API.EQUIPMENT_COMMAND_RELATION_NOT_FOUND') |
|
2081 | ||
2082 | cursor.execute(" DELETE FROM tbl_equipments_commands WHERE equipment_id = %s AND command_id = %s ", (id_, cid)) |
|
2083 | cnx.commit() |
|
2084 | ||
2085 | cursor.close() |
|
2086 | cnx.close() |
|
2087 | ||
2088 | resp.status = falcon.HTTP_204 |
|
2089 | ||
2090 | ||
2091 | class EquipmentExport: |
|
@@ 1458-1515 (lines=58) @@ | ||
1455 | resp.location = '/equipments/' + str(id_) + '/meters/' + str(meter_id) |
|
1456 | ||
1457 | ||
1458 | class EquipmentMeterItem: |
|
1459 | def __init__(self): |
|
1460 | """Initializes EquipmentMeterItem""" |
|
1461 | pass |
|
1462 | ||
1463 | @staticmethod |
|
1464 | def on_options(req, resp, id_, mid): |
|
1465 | resp.status = falcon.HTTP_200 |
|
1466 | ||
1467 | @staticmethod |
|
1468 | @user_logger |
|
1469 | def on_delete(req, resp, id_, mid): |
|
1470 | admin_control(req) |
|
1471 | if not id_.isdigit() or int(id_) <= 0: |
|
1472 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1473 | description='API.INVALID_EQUIPMENT_ID') |
|
1474 | ||
1475 | if not mid.isdigit() or int(mid) <= 0: |
|
1476 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1477 | description='API.INVALID_METER_ID') |
|
1478 | ||
1479 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1480 | cursor = cnx.cursor() |
|
1481 | ||
1482 | cursor.execute(" SELECT name " |
|
1483 | " FROM tbl_equipments " |
|
1484 | " WHERE id = %s ", (id_,)) |
|
1485 | if cursor.fetchone() is None: |
|
1486 | cursor.close() |
|
1487 | cnx.close() |
|
1488 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1489 | description='API.EQUIPMENT_NOT_FOUND') |
|
1490 | ||
1491 | cursor.execute(" SELECT name " |
|
1492 | " FROM tbl_meters " |
|
1493 | " WHERE id = %s ", (mid,)) |
|
1494 | if cursor.fetchone() is None: |
|
1495 | cursor.close() |
|
1496 | cnx.close() |
|
1497 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1498 | description='API.METER_NOT_FOUND') |
|
1499 | ||
1500 | cursor.execute(" SELECT id " |
|
1501 | " FROM tbl_equipments_meters " |
|
1502 | " WHERE equipment_id = %s AND meter_id = %s ", (id_, mid)) |
|
1503 | if cursor.fetchone() is None: |
|
1504 | cursor.close() |
|
1505 | cnx.close() |
|
1506 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1507 | description='API.EQUIPMENT_METER_RELATION_NOT_FOUND') |
|
1508 | ||
1509 | cursor.execute(" DELETE FROM tbl_equipments_meters WHERE equipment_id = %s AND meter_id = %s ", (id_, mid)) |
|
1510 | cnx.commit() |
|
1511 | ||
1512 | cursor.close() |
|
1513 | cnx.close() |
|
1514 | ||
1515 | resp.status = falcon.HTTP_204 |
|
1516 | ||
1517 | ||
1518 | class EquipmentOfflineMeterCollection: |
@@ 1731-1789 (lines=59) @@ | ||
1728 | resp.location = '/tenants/' + str(id_) + '/workingcalendars/' + str(working_calendar_id) |
|
1729 | ||
1730 | ||
1731 | class TenantWorkingCalendarItem: |
|
1732 | def __init__(self): |
|
1733 | """Initializes TenantWorkingCalendarItem Class""" |
|
1734 | pass |
|
1735 | ||
1736 | @staticmethod |
|
1737 | def on_options(req, resp, id_, wcid): |
|
1738 | resp.status = falcon.HTTP_200 |
|
1739 | ||
1740 | @staticmethod |
|
1741 | @user_logger |
|
1742 | def on_delete(req, resp, id_, wcid): |
|
1743 | admin_control(req) |
|
1744 | if not id_.isdigit() or int(id_) <= 0: |
|
1745 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1746 | description='API.INVALID_TENANT_ID') |
|
1747 | ||
1748 | if not wcid.isdigit() or int(wcid) <= 0: |
|
1749 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1750 | description='API.INVALID_WORKING_CALENDAR_ID') |
|
1751 | ||
1752 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1753 | cursor = cnx.cursor() |
|
1754 | ||
1755 | cursor.execute(" SELECT name " |
|
1756 | " FROM tbl_tenants " |
|
1757 | " WHERE id = %s ", (id_,)) |
|
1758 | if cursor.fetchone() is None: |
|
1759 | cursor.close() |
|
1760 | cnx.close() |
|
1761 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1762 | description='API.TENANT_NOT_FOUND') |
|
1763 | ||
1764 | cursor.execute(" SELECT name " |
|
1765 | " FROM tbl_working_calendars " |
|
1766 | " WHERE id = %s ", (wcid,)) |
|
1767 | if cursor.fetchone() is None: |
|
1768 | cursor.close() |
|
1769 | cnx.close() |
|
1770 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1771 | description='API.WORKING_CALENDAR_NOT_FOUND') |
|
1772 | ||
1773 | cursor.execute(" SELECT id " |
|
1774 | " FROM tbl_tenants_working_calendars " |
|
1775 | " WHERE tenant_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
1776 | if cursor.fetchone() is None: |
|
1777 | cursor.close() |
|
1778 | cnx.close() |
|
1779 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1780 | description='API.TENANT_WORKING_CALENDAR_RELATION_NOT_FOUND') |
|
1781 | ||
1782 | cursor.execute(" DELETE FROM tbl_tenants_working_calendars " |
|
1783 | " WHERE tenant_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
1784 | cnx.commit() |
|
1785 | ||
1786 | cursor.close() |
|
1787 | cnx.close() |
|
1788 | ||
1789 | resp.status = falcon.HTTP_204 |
|
1790 | ||
1791 | ||
1792 | class TenantCommandCollection: |
|
@@ 1553-1611 (lines=59) @@ | ||
1550 | resp.location = '/tenants/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
1551 | ||
1552 | ||
1553 | class TenantVirtualMeterItem: |
|
1554 | def __init__(self): |
|
1555 | """Initializes Class""" |
|
1556 | pass |
|
1557 | ||
1558 | @staticmethod |
|
1559 | def on_options(req, resp, id_, mid): |
|
1560 | resp.status = falcon.HTTP_200 |
|
1561 | ||
1562 | @staticmethod |
|
1563 | @user_logger |
|
1564 | def on_delete(req, resp, id_, mid): |
|
1565 | admin_control(req) |
|
1566 | if not id_.isdigit() or int(id_) <= 0: |
|
1567 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1568 | description='API.INVALID_TENANT_ID') |
|
1569 | ||
1570 | if not mid.isdigit() or int(mid) <= 0: |
|
1571 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1572 | description='API.INVALID_VIRTUAL_METER_ID') |
|
1573 | ||
1574 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1575 | cursor = cnx.cursor() |
|
1576 | ||
1577 | cursor.execute(" SELECT name " |
|
1578 | " FROM tbl_tenants " |
|
1579 | " WHERE id = %s ", (id_,)) |
|
1580 | if cursor.fetchone() is None: |
|
1581 | cursor.close() |
|
1582 | cnx.close() |
|
1583 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1584 | description='API.TENANT_NOT_FOUND') |
|
1585 | ||
1586 | cursor.execute(" SELECT name " |
|
1587 | " FROM tbl_virtual_meters " |
|
1588 | " WHERE id = %s ", (mid,)) |
|
1589 | if cursor.fetchone() is None: |
|
1590 | cursor.close() |
|
1591 | cnx.close() |
|
1592 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1593 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
1594 | ||
1595 | cursor.execute(" SELECT id " |
|
1596 | " FROM tbl_tenants_virtual_meters " |
|
1597 | " WHERE tenant_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1598 | if cursor.fetchone() is None: |
|
1599 | cursor.close() |
|
1600 | cnx.close() |
|
1601 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1602 | description='API.TENANT_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
1603 | ||
1604 | cursor.execute(" DELETE FROM tbl_tenants_virtual_meters " |
|
1605 | " WHERE tenant_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1606 | cnx.commit() |
|
1607 | ||
1608 | cursor.close() |
|
1609 | cnx.close() |
|
1610 | ||
1611 | resp.status = falcon.HTTP_204 |
|
1612 | ||
1613 | ||
1614 | class TenantWorkingCalendarCollection: |
|
@@ 1185-1243 (lines=59) @@ | ||
1182 | resp.location = '/tenants/' + str(id_) + '/points/' + str(point_id) |
|
1183 | ||
1184 | ||
1185 | class TenantPointItem: |
|
1186 | def __init__(self): |
|
1187 | """Initializes Class""" |
|
1188 | pass |
|
1189 | ||
1190 | @staticmethod |
|
1191 | def on_options(req, resp, id_, pid): |
|
1192 | resp.status = falcon.HTTP_200 |
|
1193 | ||
1194 | @staticmethod |
|
1195 | @user_logger |
|
1196 | def on_delete(req, resp, id_, pid): |
|
1197 | admin_control(req) |
|
1198 | if not id_.isdigit() or int(id_) <= 0: |
|
1199 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1200 | description='API.INVALID_TENANT_ID') |
|
1201 | ||
1202 | if not pid.isdigit() or int(pid) <= 0: |
|
1203 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1204 | description='API.INVALID_POINT_ID') |
|
1205 | ||
1206 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1207 | cursor = cnx.cursor() |
|
1208 | ||
1209 | cursor.execute(" SELECT name " |
|
1210 | " FROM tbl_tenants " |
|
1211 | " WHERE id = %s ", (id_,)) |
|
1212 | if cursor.fetchone() is None: |
|
1213 | cursor.close() |
|
1214 | cnx.close() |
|
1215 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1216 | description='API.TENANT_NOT_FOUND') |
|
1217 | ||
1218 | cursor.execute(" SELECT name " |
|
1219 | " FROM tbl_points " |
|
1220 | " WHERE id = %s ", (pid,)) |
|
1221 | if cursor.fetchone() is None: |
|
1222 | cursor.close() |
|
1223 | cnx.close() |
|
1224 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1225 | description='API.POINT_NOT_FOUND') |
|
1226 | ||
1227 | cursor.execute(" SELECT id " |
|
1228 | " FROM tbl_tenants_points " |
|
1229 | " WHERE tenant_id = %s AND point_id = %s ", (id_, pid)) |
|
1230 | if cursor.fetchone() is None: |
|
1231 | cursor.close() |
|
1232 | cnx.close() |
|
1233 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1234 | description='API.TENANT_POINT_RELATION_NOT_FOUND') |
|
1235 | ||
1236 | cursor.execute(" DELETE FROM tbl_tenants_points " |
|
1237 | " WHERE tenant_id = %s AND point_id = %s ", (id_, pid)) |
|
1238 | cnx.commit() |
|
1239 | ||
1240 | cursor.close() |
|
1241 | cnx.close() |
|
1242 | ||
1243 | resp.status = falcon.HTTP_204 |
|
1244 | ||
1245 | ||
1246 | class TenantSensorCollection: |
|
@@ 995-1053 (lines=59) @@ | ||
992 | resp.location = '/tenants/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
993 | ||
994 | ||
995 | class TenantOfflineMeterItem: |
|
996 | def __init__(self): |
|
997 | """Initializes Class""" |
|
998 | pass |
|
999 | ||
1000 | @staticmethod |
|
1001 | def on_options(req, resp, id_, mid): |
|
1002 | resp.status = falcon.HTTP_200 |
|
1003 | ||
1004 | @staticmethod |
|
1005 | @user_logger |
|
1006 | def on_delete(req, resp, id_, mid): |
|
1007 | admin_control(req) |
|
1008 | if not id_.isdigit() or int(id_) <= 0: |
|
1009 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1010 | description='API.INVALID_TENANT_ID') |
|
1011 | ||
1012 | if not mid.isdigit() or int(mid) <= 0: |
|
1013 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1014 | description='API.INVALID_OFFLINE_METER_ID') |
|
1015 | ||
1016 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1017 | cursor = cnx.cursor() |
|
1018 | ||
1019 | cursor.execute(" SELECT name " |
|
1020 | " FROM tbl_tenants " |
|
1021 | " WHERE id = %s ", (id_,)) |
|
1022 | if cursor.fetchone() is None: |
|
1023 | cursor.close() |
|
1024 | cnx.close() |
|
1025 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1026 | description='API.TENANT_NOT_FOUND') |
|
1027 | ||
1028 | cursor.execute(" SELECT name " |
|
1029 | " FROM tbl_offline_meters " |
|
1030 | " WHERE id = %s ", (mid,)) |
|
1031 | if cursor.fetchone() is None: |
|
1032 | cursor.close() |
|
1033 | cnx.close() |
|
1034 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1035 | description='API.OFFLINE_METER_NOT_FOUND') |
|
1036 | ||
1037 | cursor.execute(" SELECT id " |
|
1038 | " FROM tbl_tenants_offline_meters " |
|
1039 | " WHERE tenant_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1040 | if cursor.fetchone() is None: |
|
1041 | cursor.close() |
|
1042 | cnx.close() |
|
1043 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1044 | description='API.TENANT_OFFLINE_METER_RELATION_NOT_FOUND') |
|
1045 | ||
1046 | cursor.execute(" DELETE FROM tbl_tenants_offline_meters " |
|
1047 | " WHERE tenant_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1048 | cnx.commit() |
|
1049 | ||
1050 | cursor.close() |
|
1051 | cnx.close() |
|
1052 | ||
1053 | resp.status = falcon.HTTP_204 |
|
1054 | ||
1055 | ||
1056 | class TenantPointCollection: |
|
@@ 1909-1966 (lines=58) @@ | ||
1906 | resp.location = '/tenants/' + str(id_) + '/commands/' + str(command_id) |
|
1907 | ||
1908 | ||
1909 | class TenantCommandItem: |
|
1910 | def __init__(self): |
|
1911 | """Initializes Class""" |
|
1912 | pass |
|
1913 | ||
1914 | @staticmethod |
|
1915 | def on_options(req, resp, id_, cid): |
|
1916 | resp.status = falcon.HTTP_200 |
|
1917 | ||
1918 | @staticmethod |
|
1919 | @user_logger |
|
1920 | def on_delete(req, resp, id_, cid): |
|
1921 | admin_control(req) |
|
1922 | if not id_.isdigit() or int(id_) <= 0: |
|
1923 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1924 | description='API.INVALID_TENANT_ID') |
|
1925 | ||
1926 | if not cid.isdigit() or int(cid) <= 0: |
|
1927 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1928 | description='API.INVALID_COMMAND_ID') |
|
1929 | ||
1930 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1931 | cursor = cnx.cursor() |
|
1932 | ||
1933 | cursor.execute(" SELECT name " |
|
1934 | " FROM tbl_tenants " |
|
1935 | " WHERE id = %s ", (id_,)) |
|
1936 | if cursor.fetchone() is None: |
|
1937 | cursor.close() |
|
1938 | cnx.close() |
|
1939 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1940 | description='API.TENANT_NOT_FOUND') |
|
1941 | ||
1942 | cursor.execute(" SELECT name " |
|
1943 | " FROM tbl_commands " |
|
1944 | " WHERE id = %s ", (cid,)) |
|
1945 | if cursor.fetchone() is None: |
|
1946 | cursor.close() |
|
1947 | cnx.close() |
|
1948 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1949 | description='API.COMMAND_NOT_FOUND') |
|
1950 | ||
1951 | cursor.execute(" SELECT id " |
|
1952 | " FROM tbl_tenants_commands " |
|
1953 | " WHERE tenant_id = %s AND command_id = %s ", (id_, cid)) |
|
1954 | if cursor.fetchone() is None: |
|
1955 | cursor.close() |
|
1956 | cnx.close() |
|
1957 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1958 | description='API.TENANT_COMMAND_RELATION_NOT_FOUND') |
|
1959 | ||
1960 | cursor.execute(" DELETE FROM tbl_tenants_commands WHERE tenant_id = %s AND command_id = %s ", (id_, cid)) |
|
1961 | cnx.commit() |
|
1962 | ||
1963 | cursor.close() |
|
1964 | cnx.close() |
|
1965 | ||
1966 | resp.status = falcon.HTTP_204 |
|
1967 | ||
1968 | ||
1969 | class TenantExport: |
|
@@ 1363-1420 (lines=58) @@ | ||
1360 | resp.location = '/tenants/' + str(id_) + '/sensors/' + str(sensor_id) |
|
1361 | ||
1362 | ||
1363 | class TenantSensorItem: |
|
1364 | def __init__(self): |
|
1365 | """Initializes Class""" |
|
1366 | pass |
|
1367 | ||
1368 | @staticmethod |
|
1369 | def on_options(req, resp, id_, sid): |
|
1370 | resp.status = falcon.HTTP_200 |
|
1371 | ||
1372 | @staticmethod |
|
1373 | @user_logger |
|
1374 | def on_delete(req, resp, id_, sid): |
|
1375 | admin_control(req) |
|
1376 | if not id_.isdigit() or int(id_) <= 0: |
|
1377 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1378 | description='API.INVALID_TENANT_ID') |
|
1379 | ||
1380 | if not sid.isdigit() or int(sid) <= 0: |
|
1381 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1382 | description='API.INVALID_SENSOR_ID') |
|
1383 | ||
1384 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1385 | cursor = cnx.cursor() |
|
1386 | ||
1387 | cursor.execute(" SELECT name " |
|
1388 | " FROM tbl_tenants " |
|
1389 | " WHERE id = %s ", (id_,)) |
|
1390 | if cursor.fetchone() is None: |
|
1391 | cursor.close() |
|
1392 | cnx.close() |
|
1393 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1394 | description='API.TENANT_NOT_FOUND') |
|
1395 | ||
1396 | cursor.execute(" SELECT name " |
|
1397 | " FROM tbl_sensors " |
|
1398 | " WHERE id = %s ", (sid,)) |
|
1399 | if cursor.fetchone() is None: |
|
1400 | cursor.close() |
|
1401 | cnx.close() |
|
1402 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1403 | description='API.SENSOR_NOT_FOUND') |
|
1404 | ||
1405 | cursor.execute(" SELECT id " |
|
1406 | " FROM tbl_tenants_sensors " |
|
1407 | " WHERE tenant_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1408 | if cursor.fetchone() is None: |
|
1409 | cursor.close() |
|
1410 | cnx.close() |
|
1411 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1412 | description='API.TENANT_SENSOR_RELATION_NOT_FOUND') |
|
1413 | ||
1414 | cursor.execute(" DELETE FROM tbl_tenants_sensors WHERE tenant_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1415 | cnx.commit() |
|
1416 | ||
1417 | cursor.close() |
|
1418 | cnx.close() |
|
1419 | ||
1420 | resp.status = falcon.HTTP_204 |
|
1421 | ||
1422 | ||
1423 | class TenantVirtualMeterCollection: |
|
@@ 805-862 (lines=58) @@ | ||
802 | resp.location = '/tenants/' + str(id_) + '/meters/' + str(meter_id) |
|
803 | ||
804 | ||
805 | class TenantMeterItem: |
|
806 | def __init__(self): |
|
807 | """Initializes Class""" |
|
808 | pass |
|
809 | ||
810 | @staticmethod |
|
811 | def on_options(req, resp, id_, mid): |
|
812 | resp.status = falcon.HTTP_200 |
|
813 | ||
814 | @staticmethod |
|
815 | @user_logger |
|
816 | def on_delete(req, resp, id_, mid): |
|
817 | admin_control(req) |
|
818 | if not id_.isdigit() or int(id_) <= 0: |
|
819 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
820 | description='API.INVALID_TENANT_ID') |
|
821 | ||
822 | if not mid.isdigit() or int(mid) <= 0: |
|
823 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
824 | description='API.INVALID_METER_ID') |
|
825 | ||
826 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
827 | cursor = cnx.cursor() |
|
828 | ||
829 | cursor.execute(" SELECT name " |
|
830 | " FROM tbl_tenants " |
|
831 | " WHERE id = %s ", (id_,)) |
|
832 | if cursor.fetchone() is None: |
|
833 | cursor.close() |
|
834 | cnx.close() |
|
835 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
836 | description='API.TENANT_NOT_FOUND') |
|
837 | ||
838 | cursor.execute(" SELECT name " |
|
839 | " FROM tbl_meters " |
|
840 | " WHERE id = %s ", (mid,)) |
|
841 | if cursor.fetchone() is None: |
|
842 | cursor.close() |
|
843 | cnx.close() |
|
844 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
845 | description='API.METER_NOT_FOUND') |
|
846 | ||
847 | cursor.execute(" SELECT id " |
|
848 | " FROM tbl_tenants_meters " |
|
849 | " WHERE tenant_id = %s AND meter_id = %s ", (id_, mid)) |
|
850 | if cursor.fetchone() is None: |
|
851 | cursor.close() |
|
852 | cnx.close() |
|
853 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
854 | description='API.TENANT_METER_RELATION_NOT_FOUND') |
|
855 | ||
856 | cursor.execute(" DELETE FROM tbl_tenants_meters WHERE tenant_id = %s AND meter_id = %s ", (id_, mid)) |
|
857 | cnx.commit() |
|
858 | ||
859 | cursor.close() |
|
860 | cnx.close() |
|
861 | ||
862 | resp.status = falcon.HTTP_204 |
|
863 | ||
864 | ||
865 | class TenantOfflineMeterCollection: |
@@ 1678-1736 (lines=59) @@ | ||
1675 | resp.location = '/shopfloors/' + str(id_) + '/workingcalendars/' + str(working_calendar_id) |
|
1676 | ||
1677 | ||
1678 | class ShopfloorWorkingCalendarItem: |
|
1679 | def __init__(self): |
|
1680 | """Initializes ShopfloorWorkingCalendarItem Class""" |
|
1681 | pass |
|
1682 | ||
1683 | @staticmethod |
|
1684 | def on_options(req, resp, id_, wcid): |
|
1685 | resp.status = falcon.HTTP_200 |
|
1686 | ||
1687 | @staticmethod |
|
1688 | @user_logger |
|
1689 | def on_delete(req, resp, id_, wcid): |
|
1690 | admin_control(req) |
|
1691 | if not id_.isdigit() or int(id_) <= 0: |
|
1692 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1693 | description='API.INVALID_SHOPFLOOR_ID') |
|
1694 | ||
1695 | if not wcid.isdigit() or int(wcid) <= 0: |
|
1696 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1697 | description='API.INVALID_WORKING_CALENDAR_ID') |
|
1698 | ||
1699 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1700 | cursor = cnx.cursor() |
|
1701 | ||
1702 | cursor.execute(" SELECT name " |
|
1703 | " FROM tbl_shopfloors " |
|
1704 | " WHERE id = %s ", (id_,)) |
|
1705 | if cursor.fetchone() is None: |
|
1706 | cursor.close() |
|
1707 | cnx.close() |
|
1708 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1709 | description='API.SHOPFLOOR_NOT_FOUND') |
|
1710 | ||
1711 | cursor.execute(" SELECT name " |
|
1712 | " FROM tbl_working_calendars " |
|
1713 | " WHERE id = %s ", (wcid,)) |
|
1714 | if cursor.fetchone() is None: |
|
1715 | cursor.close() |
|
1716 | cnx.close() |
|
1717 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1718 | description='API.WORKING_CALENDAR_NOT_FOUND') |
|
1719 | ||
1720 | cursor.execute(" SELECT id " |
|
1721 | " FROM tbl_shopfloors_working_calendars " |
|
1722 | " WHERE shopfloor_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
1723 | if cursor.fetchone() is None: |
|
1724 | cursor.close() |
|
1725 | cnx.close() |
|
1726 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1727 | description='API.SHOPFLOOR_WORKING_CALENDAR_RELATION_NOT_FOUND') |
|
1728 | ||
1729 | cursor.execute(" DELETE FROM tbl_shopfloors_working_calendars " |
|
1730 | " WHERE shopfloor_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
1731 | cnx.commit() |
|
1732 | ||
1733 | cursor.close() |
|
1734 | cnx.close() |
|
1735 | ||
1736 | resp.status = falcon.HTTP_204 |
|
1737 | ||
1738 | ||
1739 | class ShopfloorCommandCollection: |
|
@@ 1502-1560 (lines=59) @@ | ||
1499 | resp.location = '/shopfloors/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
1500 | ||
1501 | ||
1502 | class ShopfloorVirtualMeterItem: |
|
1503 | def __init__(self): |
|
1504 | """Initializes ShopfloorVirtualMeterItem""" |
|
1505 | pass |
|
1506 | ||
1507 | @staticmethod |
|
1508 | def on_options(req, resp, id_, mid): |
|
1509 | resp.status = falcon.HTTP_200 |
|
1510 | ||
1511 | @staticmethod |
|
1512 | @user_logger |
|
1513 | def on_delete(req, resp, id_, mid): |
|
1514 | admin_control(req) |
|
1515 | if not id_.isdigit() or int(id_) <= 0: |
|
1516 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1517 | description='API.INVALID_SHOPFLOOR_ID') |
|
1518 | ||
1519 | if not mid.isdigit() or int(mid) <= 0: |
|
1520 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1521 | description='API.INVALID_VIRTUAL_METER_ID') |
|
1522 | ||
1523 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1524 | cursor = cnx.cursor() |
|
1525 | ||
1526 | cursor.execute(" SELECT name " |
|
1527 | " FROM tbl_shopfloors " |
|
1528 | " WHERE id = %s ", (id_,)) |
|
1529 | if cursor.fetchone() is None: |
|
1530 | cursor.close() |
|
1531 | cnx.close() |
|
1532 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1533 | description='API.SHOPFLOOR_NOT_FOUND') |
|
1534 | ||
1535 | cursor.execute(" SELECT name " |
|
1536 | " FROM tbl_virtual_meters " |
|
1537 | " WHERE id = %s ", (mid,)) |
|
1538 | if cursor.fetchone() is None: |
|
1539 | cursor.close() |
|
1540 | cnx.close() |
|
1541 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1542 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
1543 | ||
1544 | cursor.execute(" SELECT id " |
|
1545 | " FROM tbl_shopfloors_virtual_meters " |
|
1546 | " WHERE shopfloor_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1547 | if cursor.fetchone() is None: |
|
1548 | cursor.close() |
|
1549 | cnx.close() |
|
1550 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1551 | description='API.SHOPFLOOR_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
1552 | ||
1553 | cursor.execute(" DELETE FROM tbl_shopfloors_virtual_meters " |
|
1554 | " WHERE shopfloor_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1555 | cnx.commit() |
|
1556 | ||
1557 | cursor.close() |
|
1558 | cnx.close() |
|
1559 | ||
1560 | resp.status = falcon.HTTP_204 |
|
1561 | ||
1562 | ||
1563 | class ShopfloorWorkingCalendarCollection: |
|
@@ 1138-1196 (lines=59) @@ | ||
1135 | resp.location = '/shopfloors/' + str(id_) + '/points/' + str(point_id) |
|
1136 | ||
1137 | ||
1138 | class ShopfloorPointItem: |
|
1139 | def __init__(self): |
|
1140 | """Initializes ShopfloorPointItem""" |
|
1141 | pass |
|
1142 | ||
1143 | @staticmethod |
|
1144 | def on_options(req, resp, id_, pid): |
|
1145 | resp.status = falcon.HTTP_200 |
|
1146 | ||
1147 | @staticmethod |
|
1148 | @user_logger |
|
1149 | def on_delete(req, resp, id_, pid): |
|
1150 | admin_control(req) |
|
1151 | if not id_.isdigit() or int(id_) <= 0: |
|
1152 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1153 | description='API.INVALID_SHOPFLOOR_ID') |
|
1154 | ||
1155 | if not pid.isdigit() or int(pid) <= 0: |
|
1156 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1157 | description='API.INVALID_POINT_ID') |
|
1158 | ||
1159 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1160 | cursor = cnx.cursor() |
|
1161 | ||
1162 | cursor.execute(" SELECT name " |
|
1163 | " FROM tbl_shopfloors " |
|
1164 | " WHERE id = %s ", (id_,)) |
|
1165 | if cursor.fetchone() is None: |
|
1166 | cursor.close() |
|
1167 | cnx.close() |
|
1168 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1169 | description='API.SHOPFLOOR_NOT_FOUND') |
|
1170 | ||
1171 | cursor.execute(" SELECT name " |
|
1172 | " FROM tbl_points " |
|
1173 | " WHERE id = %s ", (pid,)) |
|
1174 | if cursor.fetchone() is None: |
|
1175 | cursor.close() |
|
1176 | cnx.close() |
|
1177 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1178 | description='API.POINT_NOT_FOUND') |
|
1179 | ||
1180 | cursor.execute(" SELECT id " |
|
1181 | " FROM tbl_shopfloors_points " |
|
1182 | " WHERE shopfloor_id = %s AND point_id = %s ", (id_, pid)) |
|
1183 | if cursor.fetchone() is None: |
|
1184 | cursor.close() |
|
1185 | cnx.close() |
|
1186 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1187 | description='API.SHOPFLOOR_POINT_RELATION_NOT_FOUND') |
|
1188 | ||
1189 | cursor.execute(" DELETE FROM tbl_shopfloors_points " |
|
1190 | " WHERE shopfloor_id = %s AND point_id = %s ", (id_, pid)) |
|
1191 | cnx.commit() |
|
1192 | ||
1193 | cursor.close() |
|
1194 | cnx.close() |
|
1195 | ||
1196 | resp.status = falcon.HTTP_204 |
|
1197 | ||
1198 | ||
1199 | class ShopfloorSensorCollection: |
|
@@ 950-1008 (lines=59) @@ | ||
947 | resp.location = '/shopfloors/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
948 | ||
949 | ||
950 | class ShopfloorOfflineMeterItem: |
|
951 | def __init__(self): |
|
952 | """Initializes ShopfloorOfflineMeterItem""" |
|
953 | pass |
|
954 | ||
955 | @staticmethod |
|
956 | def on_options(req, resp, id_, mid): |
|
957 | resp.status = falcon.HTTP_200 |
|
958 | ||
959 | @staticmethod |
|
960 | @user_logger |
|
961 | def on_delete(req, resp, id_, mid): |
|
962 | admin_control(req) |
|
963 | if not id_.isdigit() or int(id_) <= 0: |
|
964 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
965 | description='API.INVALID_SHOPFLOOR_ID') |
|
966 | ||
967 | if not mid.isdigit() or int(mid) <= 0: |
|
968 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
969 | description='API.INVALID_OFFLINE_METER_ID') |
|
970 | ||
971 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
972 | cursor = cnx.cursor() |
|
973 | ||
974 | cursor.execute(" SELECT name " |
|
975 | " FROM tbl_shopfloors " |
|
976 | " WHERE id = %s ", (id_,)) |
|
977 | if cursor.fetchone() is None: |
|
978 | cursor.close() |
|
979 | cnx.close() |
|
980 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
981 | description='API.SHOPFLOOR_NOT_FOUND') |
|
982 | ||
983 | cursor.execute(" SELECT name " |
|
984 | " FROM tbl_offline_meters " |
|
985 | " WHERE id = %s ", (mid,)) |
|
986 | if cursor.fetchone() is None: |
|
987 | cursor.close() |
|
988 | cnx.close() |
|
989 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
990 | description='API.OFFLINE_METER_NOT_FOUND') |
|
991 | ||
992 | cursor.execute(" SELECT id " |
|
993 | " FROM tbl_shopfloors_offline_meters " |
|
994 | " WHERE shopfloor_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
995 | if cursor.fetchone() is None: |
|
996 | cursor.close() |
|
997 | cnx.close() |
|
998 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
999 | description='API.SHOPFLOOR_OFFLINE_METER_RELATION_NOT_FOUND') |
|
1000 | ||
1001 | cursor.execute(" DELETE FROM tbl_shopfloors_offline_meters " |
|
1002 | " WHERE shopfloor_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1003 | cnx.commit() |
|
1004 | ||
1005 | cursor.close() |
|
1006 | cnx.close() |
|
1007 | ||
1008 | resp.status = falcon.HTTP_204 |
|
1009 | ||
1010 | ||
1011 | class ShopfloorPointCollection: |
|
@@ 573-631 (lines=59) @@ | ||
570 | resp.location = '/shopfloors/' + str(id_) + '/equipments/' + str(equipment_id) |
|
571 | ||
572 | ||
573 | class ShopfloorEquipmentItem: |
|
574 | def __init__(self): |
|
575 | """Initializes ShopfloorEquipmentItem""" |
|
576 | pass |
|
577 | ||
578 | @staticmethod |
|
579 | def on_options(req, resp, id_, eid): |
|
580 | resp.status = falcon.HTTP_200 |
|
581 | ||
582 | @staticmethod |
|
583 | @user_logger |
|
584 | def on_delete(req, resp, id_, eid): |
|
585 | admin_control(req) |
|
586 | if not id_.isdigit() or int(id_) <= 0: |
|
587 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
588 | description='API.INVALID_SHOPFLOOR_ID') |
|
589 | ||
590 | if not eid.isdigit() or int(eid) <= 0: |
|
591 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
592 | description='API.INVALID_EQUIPMENT_ID') |
|
593 | ||
594 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
595 | cursor = cnx.cursor() |
|
596 | ||
597 | cursor.execute(" SELECT name " |
|
598 | " FROM tbl_shopfloors " |
|
599 | " WHERE id = %s ", (id_,)) |
|
600 | if cursor.fetchone() is None: |
|
601 | cursor.close() |
|
602 | cnx.close() |
|
603 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
604 | description='API.SHOPFLOOR_NOT_FOUND') |
|
605 | ||
606 | cursor.execute(" SELECT name " |
|
607 | " FROM tbl_equipments " |
|
608 | " WHERE id = %s ", (eid,)) |
|
609 | if cursor.fetchone() is None: |
|
610 | cursor.close() |
|
611 | cnx.close() |
|
612 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
613 | description='API.EQUIPMENT_NOT_FOUND') |
|
614 | ||
615 | cursor.execute(" SELECT id " |
|
616 | " FROM tbl_shopfloors_equipments " |
|
617 | " WHERE shopfloor_id = %s AND equipment_id = %s ", (id_, eid)) |
|
618 | if cursor.fetchone() is None: |
|
619 | cursor.close() |
|
620 | cnx.close() |
|
621 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
622 | description='API.SHOPFLOOR_EQUIPMENT_RELATION_NOT_FOUND') |
|
623 | ||
624 | cursor.execute(" DELETE FROM tbl_shopfloors_equipments " |
|
625 | " WHERE shopfloor_id = %s AND equipment_id = %s ", (id_, eid)) |
|
626 | cnx.commit() |
|
627 | ||
628 | cursor.close() |
|
629 | cnx.close() |
|
630 | ||
631 | resp.status = falcon.HTTP_204 |
|
632 | ||
633 | ||
634 | class ShopfloorMeterCollection: |
|
@@ 1854-1911 (lines=58) @@ | ||
1851 | resp.location = '/shopfloors/' + str(id_) + '/commands/' + str(command_id) |
|
1852 | ||
1853 | ||
1854 | class ShopfloorCommandItem: |
|
1855 | def __init__(self): |
|
1856 | """Initializes Class""" |
|
1857 | pass |
|
1858 | ||
1859 | @staticmethod |
|
1860 | def on_options(req, resp, id_, cid): |
|
1861 | resp.status = falcon.HTTP_200 |
|
1862 | ||
1863 | @staticmethod |
|
1864 | @user_logger |
|
1865 | def on_delete(req, resp, id_, cid): |
|
1866 | admin_control(req) |
|
1867 | if not id_.isdigit() or int(id_) <= 0: |
|
1868 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1869 | description='API.INVALID_SHOPFLOOR_ID') |
|
1870 | ||
1871 | if not cid.isdigit() or int(cid) <= 0: |
|
1872 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1873 | description='API.INVALID_COMMAND_ID') |
|
1874 | ||
1875 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1876 | cursor = cnx.cursor() |
|
1877 | ||
1878 | cursor.execute(" SELECT name " |
|
1879 | " FROM tbl_shopfloors " |
|
1880 | " WHERE id = %s ", (id_,)) |
|
1881 | if cursor.fetchone() is None: |
|
1882 | cursor.close() |
|
1883 | cnx.close() |
|
1884 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1885 | description='API.SHOPFLOOR_NOT_FOUND') |
|
1886 | ||
1887 | cursor.execute(" SELECT name " |
|
1888 | " FROM tbl_commands " |
|
1889 | " WHERE id = %s ", (cid,)) |
|
1890 | if cursor.fetchone() is None: |
|
1891 | cursor.close() |
|
1892 | cnx.close() |
|
1893 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1894 | description='API.COMMAND_NOT_FOUND') |
|
1895 | ||
1896 | cursor.execute(" SELECT id " |
|
1897 | " FROM tbl_shopfloors_commands " |
|
1898 | " WHERE shopfloor_id = %s AND command_id = %s ", (id_, cid)) |
|
1899 | if cursor.fetchone() is None: |
|
1900 | cursor.close() |
|
1901 | cnx.close() |
|
1902 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1903 | description='API.SHOPFLOOR_COMMAND_RELATION_NOT_FOUND') |
|
1904 | ||
1905 | cursor.execute(" DELETE FROM tbl_shopfloors_commands WHERE shopfloor_id = %s AND command_id = %s ", (id_, cid)) |
|
1906 | cnx.commit() |
|
1907 | ||
1908 | cursor.close() |
|
1909 | cnx.close() |
|
1910 | ||
1911 | resp.status = falcon.HTTP_204 |
|
1912 | ||
1913 | ||
1914 | class ShopfloorExport: |
|
@@ 1314-1371 (lines=58) @@ | ||
1311 | resp.location = '/shopfloors/' + str(id_) + '/sensors/' + str(sensor_id) |
|
1312 | ||
1313 | ||
1314 | class ShopfloorSensorItem: |
|
1315 | def __init__(self): |
|
1316 | """Initializes ShopfloorSensorItem""" |
|
1317 | pass |
|
1318 | ||
1319 | @staticmethod |
|
1320 | def on_options(req, resp, id_, sid): |
|
1321 | resp.status = falcon.HTTP_200 |
|
1322 | ||
1323 | @staticmethod |
|
1324 | @user_logger |
|
1325 | def on_delete(req, resp, id_, sid): |
|
1326 | admin_control(req) |
|
1327 | if not id_.isdigit() or int(id_) <= 0: |
|
1328 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1329 | description='API.INVALID_SHOPFLOOR_ID') |
|
1330 | ||
1331 | if not sid.isdigit() or int(sid) <= 0: |
|
1332 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1333 | description='API.INVALID_SENSOR_ID') |
|
1334 | ||
1335 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1336 | cursor = cnx.cursor() |
|
1337 | ||
1338 | cursor.execute(" SELECT name " |
|
1339 | " FROM tbl_shopfloors " |
|
1340 | " WHERE id = %s ", (id_,)) |
|
1341 | if cursor.fetchone() is None: |
|
1342 | cursor.close() |
|
1343 | cnx.close() |
|
1344 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1345 | description='API.SHOPFLOOR_NOT_FOUND') |
|
1346 | ||
1347 | cursor.execute(" SELECT name " |
|
1348 | " FROM tbl_sensors " |
|
1349 | " WHERE id = %s ", (sid,)) |
|
1350 | if cursor.fetchone() is None: |
|
1351 | cursor.close() |
|
1352 | cnx.close() |
|
1353 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1354 | description='API.SENSOR_NOT_FOUND') |
|
1355 | ||
1356 | cursor.execute(" SELECT id " |
|
1357 | " FROM tbl_shopfloors_sensors " |
|
1358 | " WHERE shopfloor_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1359 | if cursor.fetchone() is None: |
|
1360 | cursor.close() |
|
1361 | cnx.close() |
|
1362 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1363 | description='API.SHOPFLOOR_SENSOR_RELATION_NOT_FOUND') |
|
1364 | ||
1365 | cursor.execute(" DELETE FROM tbl_shopfloors_sensors WHERE shopfloor_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1366 | cnx.commit() |
|
1367 | ||
1368 | cursor.close() |
|
1369 | cnx.close() |
|
1370 | ||
1371 | resp.status = falcon.HTTP_204 |
|
1372 | ||
1373 | ||
1374 | class ShopfloorVirtualMeterCollection: |
|
@@ 762-819 (lines=58) @@ | ||
759 | resp.location = '/shopfloors/' + str(id_) + '/meters/' + str(meter_id) |
|
760 | ||
761 | ||
762 | class ShopfloorMeterItem: |
|
763 | def __init__(self): |
|
764 | """Initializes ShopfloorMeterItem""" |
|
765 | pass |
|
766 | ||
767 | @staticmethod |
|
768 | def on_options(req, resp, id_, mid): |
|
769 | resp.status = falcon.HTTP_200 |
|
770 | ||
771 | @staticmethod |
|
772 | @user_logger |
|
773 | def on_delete(req, resp, id_, mid): |
|
774 | admin_control(req) |
|
775 | if not id_.isdigit() or int(id_) <= 0: |
|
776 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
777 | description='API.INVALID_SHOPFLOOR_ID') |
|
778 | ||
779 | if not mid.isdigit() or int(mid) <= 0: |
|
780 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
781 | description='API.INVALID_METER_ID') |
|
782 | ||
783 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
784 | cursor = cnx.cursor() |
|
785 | ||
786 | cursor.execute(" SELECT name " |
|
787 | " FROM tbl_shopfloors " |
|
788 | " WHERE id = %s ", (id_,)) |
|
789 | if cursor.fetchone() is None: |
|
790 | cursor.close() |
|
791 | cnx.close() |
|
792 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
793 | description='API.SHOPFLOOR_NOT_FOUND') |
|
794 | ||
795 | cursor.execute(" SELECT name " |
|
796 | " FROM tbl_meters " |
|
797 | " WHERE id = %s ", (mid,)) |
|
798 | if cursor.fetchone() is None: |
|
799 | cursor.close() |
|
800 | cnx.close() |
|
801 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
802 | description='API.METER_NOT_FOUND') |
|
803 | ||
804 | cursor.execute(" SELECT id " |
|
805 | " FROM tbl_shopfloors_meters " |
|
806 | " WHERE shopfloor_id = %s AND meter_id = %s ", (id_, mid)) |
|
807 | if cursor.fetchone() is None: |
|
808 | cursor.close() |
|
809 | cnx.close() |
|
810 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
811 | description='API.SHOPFLOOR_METER_RELATION_NOT_FOUND') |
|
812 | ||
813 | cursor.execute(" DELETE FROM tbl_shopfloors_meters WHERE shopfloor_id = %s AND meter_id = %s ", (id_, mid)) |
|
814 | cnx.commit() |
|
815 | ||
816 | cursor.close() |
|
817 | cnx.close() |
|
818 | ||
819 | resp.status = falcon.HTTP_204 |
|
820 | ||
821 | ||
822 | class ShopfloorOfflineMeterCollection: |
@@ 1621-1679 (lines=59) @@ | ||
1618 | resp.location = '/stores/' + str(id_) + '/workingcalendars/' + str(working_calendar_id) |
|
1619 | ||
1620 | ||
1621 | class StoreWorkingCalendarItem: |
|
1622 | def __init__(self): |
|
1623 | """Initializes StoreWorkingCalendarItem Class""" |
|
1624 | pass |
|
1625 | ||
1626 | @staticmethod |
|
1627 | def on_options(req, resp, id_, wcid): |
|
1628 | resp.status = falcon.HTTP_200 |
|
1629 | ||
1630 | @staticmethod |
|
1631 | @user_logger |
|
1632 | def on_delete(req, resp, id_, wcid): |
|
1633 | admin_control(req) |
|
1634 | if not id_.isdigit() or int(id_) <= 0: |
|
1635 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1636 | description='API.INVALID_STORE_ID') |
|
1637 | ||
1638 | if not wcid.isdigit() or int(wcid) <= 0: |
|
1639 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1640 | description='API.INVALID_WORKING_CALENDAR_ID') |
|
1641 | ||
1642 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1643 | cursor = cnx.cursor() |
|
1644 | ||
1645 | cursor.execute(" SELECT name " |
|
1646 | " FROM tbl_stores " |
|
1647 | " WHERE id = %s ", (id_,)) |
|
1648 | if cursor.fetchone() is None: |
|
1649 | cursor.close() |
|
1650 | cnx.close() |
|
1651 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1652 | description='API.STORE_NOT_FOUND') |
|
1653 | ||
1654 | cursor.execute(" SELECT name " |
|
1655 | " FROM tbl_working_calendars " |
|
1656 | " WHERE id = %s ", (wcid,)) |
|
1657 | if cursor.fetchone() is None: |
|
1658 | cursor.close() |
|
1659 | cnx.close() |
|
1660 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1661 | description='API.WORKING_CALENDAR_NOT_FOUND') |
|
1662 | ||
1663 | cursor.execute(" SELECT id " |
|
1664 | " FROM tbl_stores_working_calendars " |
|
1665 | " WHERE store_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
1666 | if cursor.fetchone() is None: |
|
1667 | cursor.close() |
|
1668 | cnx.close() |
|
1669 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1670 | description='API.STORE_WORKING_CALENDAR_RELATION_NOT_FOUND') |
|
1671 | ||
1672 | cursor.execute(" DELETE FROM tbl_stores_working_calendars " |
|
1673 | " WHERE store_id = %s AND working_calendar_id = %s ", (id_, wcid)) |
|
1674 | cnx.commit() |
|
1675 | ||
1676 | cursor.close() |
|
1677 | cnx.close() |
|
1678 | ||
1679 | resp.status = falcon.HTTP_204 |
|
1680 | ||
1681 | ||
1682 | class StoreCommandCollection: |
|
@@ 1445-1503 (lines=59) @@ | ||
1442 | resp.location = '/stores/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
1443 | ||
1444 | ||
1445 | class StoreVirtualMeterItem: |
|
1446 | def __init__(self): |
|
1447 | """Initializes Class""" |
|
1448 | pass |
|
1449 | ||
1450 | @staticmethod |
|
1451 | def on_options(req, resp, id_, mid): |
|
1452 | resp.status = falcon.HTTP_200 |
|
1453 | ||
1454 | @staticmethod |
|
1455 | @user_logger |
|
1456 | def on_delete(req, resp, id_, mid): |
|
1457 | admin_control(req) |
|
1458 | if not id_.isdigit() or int(id_) <= 0: |
|
1459 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1460 | description='API.INVALID_STORE_ID') |
|
1461 | ||
1462 | if not mid.isdigit() or int(mid) <= 0: |
|
1463 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1464 | description='API.INVALID_VIRTUAL_METER_ID') |
|
1465 | ||
1466 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1467 | cursor = cnx.cursor() |
|
1468 | ||
1469 | cursor.execute(" SELECT name " |
|
1470 | " FROM tbl_stores " |
|
1471 | " WHERE id = %s ", (id_,)) |
|
1472 | if cursor.fetchone() is None: |
|
1473 | cursor.close() |
|
1474 | cnx.close() |
|
1475 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1476 | description='API.STORE_NOT_FOUND') |
|
1477 | ||
1478 | cursor.execute(" SELECT name " |
|
1479 | " FROM tbl_virtual_meters " |
|
1480 | " WHERE id = %s ", (mid,)) |
|
1481 | if cursor.fetchone() is None: |
|
1482 | cursor.close() |
|
1483 | cnx.close() |
|
1484 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1485 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
1486 | ||
1487 | cursor.execute(" SELECT id " |
|
1488 | " FROM tbl_stores_virtual_meters " |
|
1489 | " WHERE store_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1490 | if cursor.fetchone() is None: |
|
1491 | cursor.close() |
|
1492 | cnx.close() |
|
1493 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1494 | description='API.STORE_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
1495 | ||
1496 | cursor.execute(" DELETE FROM tbl_stores_virtual_meters " |
|
1497 | " WHERE store_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1498 | cnx.commit() |
|
1499 | ||
1500 | cursor.close() |
|
1501 | cnx.close() |
|
1502 | ||
1503 | resp.status = falcon.HTTP_204 |
|
1504 | ||
1505 | ||
1506 | class StoreWorkingCalendarCollection: |
|
@@ 1081-1139 (lines=59) @@ | ||
1078 | resp.location = '/stores/' + str(id_) + '/points/' + str(point_id) |
|
1079 | ||
1080 | ||
1081 | class StorePointItem: |
|
1082 | def __init__(self): |
|
1083 | """Initializes Class""" |
|
1084 | pass |
|
1085 | ||
1086 | @staticmethod |
|
1087 | def on_options(req, resp, id_, pid): |
|
1088 | resp.status = falcon.HTTP_200 |
|
1089 | ||
1090 | @staticmethod |
|
1091 | @user_logger |
|
1092 | def on_delete(req, resp, id_, pid): |
|
1093 | admin_control(req) |
|
1094 | if not id_.isdigit() or int(id_) <= 0: |
|
1095 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1096 | description='API.INVALID_STORE_ID') |
|
1097 | ||
1098 | if not pid.isdigit() or int(pid) <= 0: |
|
1099 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1100 | description='API.INVALID_POINT_ID') |
|
1101 | ||
1102 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1103 | cursor = cnx.cursor() |
|
1104 | ||
1105 | cursor.execute(" SELECT name " |
|
1106 | " FROM tbl_stores " |
|
1107 | " WHERE id = %s ", (id_,)) |
|
1108 | if cursor.fetchone() is None: |
|
1109 | cursor.close() |
|
1110 | cnx.close() |
|
1111 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1112 | description='API.STORE_NOT_FOUND') |
|
1113 | ||
1114 | cursor.execute(" SELECT name " |
|
1115 | " FROM tbl_points " |
|
1116 | " WHERE id = %s ", (pid,)) |
|
1117 | if cursor.fetchone() is None: |
|
1118 | cursor.close() |
|
1119 | cnx.close() |
|
1120 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1121 | description='API.POINT_NOT_FOUND') |
|
1122 | ||
1123 | cursor.execute(" SELECT id " |
|
1124 | " FROM tbl_stores_points " |
|
1125 | " WHERE store_id = %s AND point_id = %s ", (id_, pid)) |
|
1126 | if cursor.fetchone() is None: |
|
1127 | cursor.close() |
|
1128 | cnx.close() |
|
1129 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1130 | description='API.STORE_POINT_RELATION_NOT_FOUND') |
|
1131 | ||
1132 | cursor.execute(" DELETE FROM tbl_stores_points " |
|
1133 | " WHERE store_id = %s AND point_id = %s ", (id_, pid)) |
|
1134 | cnx.commit() |
|
1135 | ||
1136 | cursor.close() |
|
1137 | cnx.close() |
|
1138 | ||
1139 | resp.status = falcon.HTTP_204 |
|
1140 | ||
1141 | ||
1142 | class StoreSensorCollection: |
|
@@ 893-951 (lines=59) @@ | ||
890 | resp.location = '/stores/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
891 | ||
892 | ||
893 | class StoreOfflineMeterItem: |
|
894 | def __init__(self): |
|
895 | """Initializes Class""" |
|
896 | pass |
|
897 | ||
898 | @staticmethod |
|
899 | def on_options(req, resp, id_, mid): |
|
900 | resp.status = falcon.HTTP_200 |
|
901 | ||
902 | @staticmethod |
|
903 | @user_logger |
|
904 | def on_delete(req, resp, id_, mid): |
|
905 | admin_control(req) |
|
906 | if not id_.isdigit() or int(id_) <= 0: |
|
907 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
908 | description='API.INVALID_STORE_ID') |
|
909 | ||
910 | if not mid.isdigit() or int(mid) <= 0: |
|
911 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
912 | description='API.INVALID_OFFLINE_METER_ID') |
|
913 | ||
914 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
915 | cursor = cnx.cursor() |
|
916 | ||
917 | cursor.execute(" SELECT name " |
|
918 | " FROM tbl_stores " |
|
919 | " WHERE id = %s ", (id_,)) |
|
920 | if cursor.fetchone() is None: |
|
921 | cursor.close() |
|
922 | cnx.close() |
|
923 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
924 | description='API.STORE_NOT_FOUND') |
|
925 | ||
926 | cursor.execute(" SELECT name " |
|
927 | " FROM tbl_offline_meters " |
|
928 | " WHERE id = %s ", (mid,)) |
|
929 | if cursor.fetchone() is None: |
|
930 | cursor.close() |
|
931 | cnx.close() |
|
932 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
933 | description='API.OFFLINE_METER_NOT_FOUND') |
|
934 | ||
935 | cursor.execute(" SELECT id " |
|
936 | " FROM tbl_stores_offline_meters " |
|
937 | " WHERE store_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
938 | if cursor.fetchone() is None: |
|
939 | cursor.close() |
|
940 | cnx.close() |
|
941 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
942 | description='API.STORE_OFFLINE_METER_RELATION_NOT_FOUND') |
|
943 | ||
944 | cursor.execute(" DELETE FROM tbl_stores_offline_meters " |
|
945 | " WHERE store_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
946 | cnx.commit() |
|
947 | ||
948 | cursor.close() |
|
949 | cnx.close() |
|
950 | ||
951 | resp.status = falcon.HTTP_204 |
|
952 | ||
953 | ||
954 | class StorePointCollection: |
|
@@ 1797-1854 (lines=58) @@ | ||
1794 | resp.location = '/stores/' + str(id_) + '/commands/' + str(command_id) |
|
1795 | ||
1796 | ||
1797 | class StoreCommandItem: |
|
1798 | def __init__(self): |
|
1799 | """Initializes Class""" |
|
1800 | pass |
|
1801 | ||
1802 | @staticmethod |
|
1803 | def on_options(req, resp, id_, cid): |
|
1804 | resp.status = falcon.HTTP_200 |
|
1805 | ||
1806 | @staticmethod |
|
1807 | @user_logger |
|
1808 | def on_delete(req, resp, id_, cid): |
|
1809 | admin_control(req) |
|
1810 | if not id_.isdigit() or int(id_) <= 0: |
|
1811 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1812 | description='API.INVALID_STORE_ID') |
|
1813 | ||
1814 | if not cid.isdigit() or int(cid) <= 0: |
|
1815 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1816 | description='API.INVALID_COMMAND_ID') |
|
1817 | ||
1818 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1819 | cursor = cnx.cursor() |
|
1820 | ||
1821 | cursor.execute(" SELECT name " |
|
1822 | " FROM tbl_stores " |
|
1823 | " WHERE id = %s ", (id_,)) |
|
1824 | if cursor.fetchone() is None: |
|
1825 | cursor.close() |
|
1826 | cnx.close() |
|
1827 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1828 | description='API.STORE_NOT_FOUND') |
|
1829 | ||
1830 | cursor.execute(" SELECT name " |
|
1831 | " FROM tbl_commands " |
|
1832 | " WHERE id = %s ", (cid,)) |
|
1833 | if cursor.fetchone() is None: |
|
1834 | cursor.close() |
|
1835 | cnx.close() |
|
1836 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1837 | description='API.COMMAND_NOT_FOUND') |
|
1838 | ||
1839 | cursor.execute(" SELECT id " |
|
1840 | " FROM tbl_stores_commands " |
|
1841 | " WHERE store_id = %s AND command_id = %s ", (id_, cid)) |
|
1842 | if cursor.fetchone() is None: |
|
1843 | cursor.close() |
|
1844 | cnx.close() |
|
1845 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1846 | description='API.STORE_COMMAND_RELATION_NOT_FOUND') |
|
1847 | ||
1848 | cursor.execute(" DELETE FROM tbl_stores_commands WHERE store_id = %s AND command_id = %s ", (id_, cid)) |
|
1849 | cnx.commit() |
|
1850 | ||
1851 | cursor.close() |
|
1852 | cnx.close() |
|
1853 | ||
1854 | resp.status = falcon.HTTP_204 |
|
1855 | ||
1856 | ||
1857 | class StoreExport: |
|
@@ 1257-1314 (lines=58) @@ | ||
1254 | resp.location = '/stores/' + str(id_) + '/sensors/' + str(sensor_id) |
|
1255 | ||
1256 | ||
1257 | class StoreSensorItem: |
|
1258 | def __init__(self): |
|
1259 | """Initializes Class""" |
|
1260 | pass |
|
1261 | ||
1262 | @staticmethod |
|
1263 | def on_options(req, resp, id_, sid): |
|
1264 | resp.status = falcon.HTTP_200 |
|
1265 | ||
1266 | @staticmethod |
|
1267 | @user_logger |
|
1268 | def on_delete(req, resp, id_, sid): |
|
1269 | admin_control(req) |
|
1270 | if not id_.isdigit() or int(id_) <= 0: |
|
1271 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1272 | description='API.INVALID_STORE_ID') |
|
1273 | ||
1274 | if not sid.isdigit() or int(sid) <= 0: |
|
1275 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1276 | description='API.INVALID_SENSOR_ID') |
|
1277 | ||
1278 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1279 | cursor = cnx.cursor() |
|
1280 | ||
1281 | cursor.execute(" SELECT name " |
|
1282 | " FROM tbl_stores " |
|
1283 | " WHERE id = %s ", (id_,)) |
|
1284 | if cursor.fetchone() is None: |
|
1285 | cursor.close() |
|
1286 | cnx.close() |
|
1287 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1288 | description='API.STORE_NOT_FOUND') |
|
1289 | ||
1290 | cursor.execute(" SELECT name " |
|
1291 | " FROM tbl_sensors " |
|
1292 | " WHERE id = %s ", (sid,)) |
|
1293 | if cursor.fetchone() is None: |
|
1294 | cursor.close() |
|
1295 | cnx.close() |
|
1296 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1297 | description='API.SENSOR_NOT_FOUND') |
|
1298 | ||
1299 | cursor.execute(" SELECT id " |
|
1300 | " FROM tbl_stores_sensors " |
|
1301 | " WHERE store_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1302 | if cursor.fetchone() is None: |
|
1303 | cursor.close() |
|
1304 | cnx.close() |
|
1305 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1306 | description='API.STORE_SENSOR_RELATION_NOT_FOUND') |
|
1307 | ||
1308 | cursor.execute(" DELETE FROM tbl_stores_sensors WHERE store_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1309 | cnx.commit() |
|
1310 | ||
1311 | cursor.close() |
|
1312 | cnx.close() |
|
1313 | ||
1314 | resp.status = falcon.HTTP_204 |
|
1315 | ||
1316 | ||
1317 | class StoreVirtualMeterCollection: |
|
@@ 705-762 (lines=58) @@ | ||
702 | resp.location = '/stores/' + str(id_) + '/meters/' + str(meter_id) |
|
703 | ||
704 | ||
705 | class StoreMeterItem: |
|
706 | def __init__(self): |
|
707 | """Initializes Class""" |
|
708 | pass |
|
709 | ||
710 | @staticmethod |
|
711 | def on_options(req, resp, id_, mid): |
|
712 | resp.status = falcon.HTTP_200 |
|
713 | ||
714 | @staticmethod |
|
715 | @user_logger |
|
716 | def on_delete(req, resp, id_, mid): |
|
717 | admin_control(req) |
|
718 | if not id_.isdigit() or int(id_) <= 0: |
|
719 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
720 | description='API.INVALID_STORE_ID') |
|
721 | ||
722 | if not mid.isdigit() or int(mid) <= 0: |
|
723 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
724 | description='API.INVALID_METER_ID') |
|
725 | ||
726 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
727 | cursor = cnx.cursor() |
|
728 | ||
729 | cursor.execute(" SELECT name " |
|
730 | " FROM tbl_stores " |
|
731 | " WHERE id = %s ", (id_,)) |
|
732 | if cursor.fetchone() is None: |
|
733 | cursor.close() |
|
734 | cnx.close() |
|
735 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
736 | description='API.STORE_NOT_FOUND') |
|
737 | ||
738 | cursor.execute(" SELECT name " |
|
739 | " FROM tbl_meters " |
|
740 | " WHERE id = %s ", (mid,)) |
|
741 | if cursor.fetchone() is None: |
|
742 | cursor.close() |
|
743 | cnx.close() |
|
744 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
745 | description='API.METER_NOT_FOUND') |
|
746 | ||
747 | cursor.execute(" SELECT id " |
|
748 | " FROM tbl_stores_meters " |
|
749 | " WHERE store_id = %s AND meter_id = %s ", (id_, mid)) |
|
750 | if cursor.fetchone() is None: |
|
751 | cursor.close() |
|
752 | cnx.close() |
|
753 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
754 | description='API.STORE_METER_RELATION_NOT_FOUND') |
|
755 | ||
756 | cursor.execute(" DELETE FROM tbl_stores_meters WHERE store_id = %s AND meter_id = %s ", (id_, mid)) |
|
757 | cnx.commit() |
|
758 | ||
759 | cursor.close() |
|
760 | cnx.close() |
|
761 | ||
762 | resp.status = falcon.HTTP_204 |
|
763 | ||
764 | ||
765 | class StoreOfflineMeterCollection: |
@@ 1336-1394 (lines=59) @@ | ||
1333 | resp.location = '/combinedequipments/' + str(id_) + '/commands/' + str(command_id) |
|
1334 | ||
1335 | ||
1336 | class EnergyStorageContainerCommandItem: |
|
1337 | def __init__(self): |
|
1338 | """Initializes Class""" |
|
1339 | pass |
|
1340 | ||
1341 | @staticmethod |
|
1342 | def on_options(req, resp, id_, cid): |
|
1343 | resp.status = falcon.HTTP_200 |
|
1344 | ||
1345 | @staticmethod |
|
1346 | @user_logger |
|
1347 | def on_delete(req, resp, id_, cid): |
|
1348 | admin_control(req) |
|
1349 | if not id_.isdigit() or int(id_) <= 0: |
|
1350 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1351 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
1352 | ||
1353 | if not cid.isdigit() or int(cid) <= 0: |
|
1354 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1355 | description='API.INVALID_COMMAND_ID') |
|
1356 | ||
1357 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1358 | cursor = cnx.cursor() |
|
1359 | ||
1360 | cursor.execute(" SELECT name " |
|
1361 | " FROM tbl_energy_storage_containers " |
|
1362 | " WHERE id = %s ", (id_,)) |
|
1363 | if cursor.fetchone() is None: |
|
1364 | cursor.close() |
|
1365 | cnx.close() |
|
1366 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1367 | description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND') |
|
1368 | ||
1369 | cursor.execute(" SELECT name " |
|
1370 | " FROM tbl_commands " |
|
1371 | " WHERE id = %s ", (cid,)) |
|
1372 | if cursor.fetchone() is None: |
|
1373 | cursor.close() |
|
1374 | cnx.close() |
|
1375 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1376 | description='API.COMMAND_NOT_FOUND') |
|
1377 | ||
1378 | cursor.execute(" SELECT id " |
|
1379 | " FROM tbl_energy_storage_containers_commands " |
|
1380 | " WHERE energy_storage_container_id = %s AND command_id = %s ", (id_, cid)) |
|
1381 | if cursor.fetchone() is None: |
|
1382 | cursor.close() |
|
1383 | cnx.close() |
|
1384 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1385 | description='API.ENERGY_STORAGE_CONTAINER_COMMAND_RELATION_NOT_FOUND') |
|
1386 | ||
1387 | cursor.execute(" DELETE FROM tbl_energy_storage_containers_commands " |
|
1388 | " WHERE energy_storage_container_id = %s AND command_id = %s ", (id_, cid)) |
|
1389 | cnx.commit() |
|
1390 | ||
1391 | cursor.close() |
|
1392 | cnx.close() |
|
1393 | ||
1394 | resp.status = falcon.HTTP_204 |
|
1395 | ||
1396 | ||
1397 | class EnergyStorageContainerDCDCCollection: |
@@ 1081-1139 (lines=59) @@ | ||
1078 | resp.location = '/meters/' + str(id_) + '/points/' + str(new_values['data']['point_id']) |
|
1079 | ||
1080 | ||
1081 | class MeterPointItem: |
|
1082 | def __init__(self): |
|
1083 | """Initializes MeterPointItem""" |
|
1084 | pass |
|
1085 | ||
1086 | @staticmethod |
|
1087 | def on_options(req, resp, id_, pid): |
|
1088 | resp.status = falcon.HTTP_200 |
|
1089 | ||
1090 | @staticmethod |
|
1091 | @user_logger |
|
1092 | def on_delete(req, resp, id_, pid): |
|
1093 | """Handles DELETE requests""" |
|
1094 | admin_control(req) |
|
1095 | if not id_.isdigit() or int(id_) <= 0: |
|
1096 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1097 | description='API.INVALID_METER_ID') |
|
1098 | ||
1099 | if not pid.isdigit() or int(pid) <= 0: |
|
1100 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1101 | description='API.INVALID_POINT_ID') |
|
1102 | ||
1103 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1104 | cursor = cnx.cursor() |
|
1105 | ||
1106 | cursor.execute(" SELECT name " |
|
1107 | " FROM tbl_meters " |
|
1108 | " WHERE id = %s ", (id_,)) |
|
1109 | if cursor.fetchone() is None: |
|
1110 | cursor.close() |
|
1111 | cnx.close() |
|
1112 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1113 | description='API.METER_NOT_FOUND') |
|
1114 | ||
1115 | cursor.execute(" SELECT name " |
|
1116 | " FROM tbl_points " |
|
1117 | " WHERE id = %s ", (pid,)) |
|
1118 | if cursor.fetchone() is None: |
|
1119 | cursor.close() |
|
1120 | cnx.close() |
|
1121 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1122 | description='API.POINT_NOT_FOUND') |
|
1123 | ||
1124 | cursor.execute(" SELECT id " |
|
1125 | " FROM tbl_meters_points " |
|
1126 | " WHERE meter_id = %s AND point_id = %s ", (id_, pid)) |
|
1127 | if cursor.fetchone() is None: |
|
1128 | cursor.close() |
|
1129 | cnx.close() |
|
1130 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1131 | description='API.METER_POINT_RELATION_NOT_FOUND') |
|
1132 | ||
1133 | cursor.execute(" DELETE FROM tbl_meters_points WHERE meter_id = %s AND point_id = %s ", (id_, pid)) |
|
1134 | cnx.commit() |
|
1135 | ||
1136 | cursor.close() |
|
1137 | cnx.close() |
|
1138 | ||
1139 | resp.status = falcon.HTTP_204 |
|
1140 | ||
1141 | ||
1142 | class MeterCommandCollection: |
|
@@ 1257-1314 (lines=58) @@ | ||
1254 | resp.location = '/meters/' + str(id_) + '/commands/' + str(command_id) |
|
1255 | ||
1256 | ||
1257 | class MeterCommandItem: |
|
1258 | def __init__(self): |
|
1259 | """Initializes Class""" |
|
1260 | pass |
|
1261 | ||
1262 | @staticmethod |
|
1263 | def on_options(req, resp, id_, cid): |
|
1264 | resp.status = falcon.HTTP_200 |
|
1265 | ||
1266 | @staticmethod |
|
1267 | @user_logger |
|
1268 | def on_delete(req, resp, id_, cid): |
|
1269 | admin_control(req) |
|
1270 | if not id_.isdigit() or int(id_) <= 0: |
|
1271 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1272 | description='API.INVALID_METER_ID') |
|
1273 | ||
1274 | if not cid.isdigit() or int(cid) <= 0: |
|
1275 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1276 | description='API.INVALID_COMMAND_ID') |
|
1277 | ||
1278 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1279 | cursor = cnx.cursor() |
|
1280 | ||
1281 | cursor.execute(" SELECT name " |
|
1282 | " FROM tbl_meters " |
|
1283 | " WHERE id = %s ", (id_,)) |
|
1284 | if cursor.fetchone() is None: |
|
1285 | cursor.close() |
|
1286 | cnx.close() |
|
1287 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1288 | description='API.METER_NOT_FOUND') |
|
1289 | ||
1290 | cursor.execute(" SELECT name " |
|
1291 | " FROM tbl_commands " |
|
1292 | " WHERE id = %s ", (cid,)) |
|
1293 | if cursor.fetchone() is None: |
|
1294 | cursor.close() |
|
1295 | cnx.close() |
|
1296 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1297 | description='API.COMMAND_NOT_FOUND') |
|
1298 | ||
1299 | cursor.execute(" SELECT id " |
|
1300 | " FROM tbl_meters_commands " |
|
1301 | " WHERE meter_id = %s AND command_id = %s ", (id_, cid)) |
|
1302 | if cursor.fetchone() is None: |
|
1303 | cursor.close() |
|
1304 | cnx.close() |
|
1305 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
1306 | description='API.METER_COMMAND_RELATION_NOT_FOUND') |
|
1307 | ||
1308 | cursor.execute(" DELETE FROM tbl_meters_commands WHERE meter_id = %s AND command_id = %s ", (id_, cid)) |
|
1309 | cnx.commit() |
|
1310 | ||
1311 | cursor.close() |
|
1312 | cnx.close() |
|
1313 | ||
1314 | resp.status = falcon.HTTP_204 |
|
1315 | ||
1316 | ||
1317 | class MeterExport: |
@@ 550-608 (lines=59) @@ | ||
547 | resp.location = '/virtualpowerplants/' + str(id_) + '/microgrids/' + str(microgrid_id) |
|
548 | ||
549 | ||
550 | class VirtualPowerPlantMicrogridItem: |
|
551 | def __init__(self): |
|
552 | """Initializes Class""" |
|
553 | pass |
|
554 | ||
555 | @staticmethod |
|
556 | def on_options(req, resp, id_, sid): |
|
557 | resp.status = falcon.HTTP_200 |
|
558 | ||
559 | @staticmethod |
|
560 | @user_logger |
|
561 | def on_delete(req, resp, id_, mid): |
|
562 | admin_control(req) |
|
563 | if not id_.isdigit() or int(id_) <= 0: |
|
564 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
565 | description='API.INVALID_VIRTUAL_POWER_PLANT_ID') |
|
566 | ||
567 | if not mid.isdigit() or int(mid) <= 0: |
|
568 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
569 | description='API.INVALID_MICROGRID_ID') |
|
570 | ||
571 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
572 | cursor = cnx.cursor() |
|
573 | ||
574 | cursor.execute(" SELECT name " |
|
575 | " FROM tbl_virtual_power_plants " |
|
576 | " WHERE id = %s ", (id_,)) |
|
577 | if cursor.fetchone() is None: |
|
578 | cursor.close() |
|
579 | cnx.close() |
|
580 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
581 | description='API.VIRTUAL_POWER_PLANT_NOT_FOUND') |
|
582 | ||
583 | cursor.execute(" SELECT name " |
|
584 | " FROM tbl_microgrids " |
|
585 | " WHERE id = %s ", (mid,)) |
|
586 | if cursor.fetchone() is None: |
|
587 | cursor.close() |
|
588 | cnx.close() |
|
589 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
590 | description='API.MICROGRID_NOT_FOUND') |
|
591 | ||
592 | cursor.execute(" SELECT id " |
|
593 | " FROM tbl_virtual_power_plants_microgrids " |
|
594 | " WHERE virtual_power_plant_id = %s AND microgrid_id = %s ", (id_, mid)) |
|
595 | if cursor.fetchone() is None: |
|
596 | cursor.close() |
|
597 | cnx.close() |
|
598 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
599 | description='API.VIRTUAL_POWER_PLANT_MICROGRID_RELATION_NOT_FOUND') |
|
600 | ||
601 | cursor.execute(" DELETE FROM tbl_virtual_power_plants_microgrids " |
|
602 | " WHERE virtual_power_plant_id = %s AND microgrid_id = %s ", (id_, mid)) |
|
603 | cnx.commit() |
|
604 | ||
605 | cursor.close() |
|
606 | cnx.close() |
|
607 | ||
608 | resp.status = falcon.HTTP_204 |
|
609 | ||
610 | ||
611 | class VirtualPowerPlantExport: |
@@ 417-474 (lines=58) @@ | ||
414 | resp.location = '/sensors/' + str(id_) + '/points/' + str(new_values['data']['point_id']) |
|
415 | ||
416 | ||
417 | class SensorPointItem: |
|
418 | def __init__(self): |
|
419 | """"Initializes SensorPointItem""" |
|
420 | pass |
|
421 | ||
422 | @staticmethod |
|
423 | def on_options(req, resp, id_, pid): |
|
424 | resp.status = falcon.HTTP_200 |
|
425 | ||
426 | @staticmethod |
|
427 | @user_logger |
|
428 | def on_delete(req, resp, id_, pid): |
|
429 | admin_control(req) |
|
430 | if not id_.isdigit() or int(id_) <= 0: |
|
431 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
432 | description='API.INVALID_SENSOR_ID') |
|
433 | ||
434 | if not pid.isdigit() or int(pid) <= 0: |
|
435 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
436 | description='API.INVALID_POINT_ID') |
|
437 | ||
438 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
439 | cursor = cnx.cursor() |
|
440 | ||
441 | cursor.execute(" SELECT name " |
|
442 | " FROM tbl_sensors " |
|
443 | " WHERE id = %s ", (id_,)) |
|
444 | if cursor.fetchone() is None: |
|
445 | cursor.close() |
|
446 | cnx.close() |
|
447 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
448 | description='API.SENSOR_NOT_FOUND') |
|
449 | ||
450 | cursor.execute(" SELECT name " |
|
451 | " FROM tbl_points " |
|
452 | " WHERE id = %s ", (pid,)) |
|
453 | if cursor.fetchone() is None: |
|
454 | cursor.close() |
|
455 | cnx.close() |
|
456 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
457 | description='API.POINT_NOT_FOUND') |
|
458 | ||
459 | cursor.execute(" SELECT id " |
|
460 | " FROM tbl_sensors_points " |
|
461 | " WHERE sensor_id = %s AND point_id = %s ", (id_, pid)) |
|
462 | if cursor.fetchone() is None: |
|
463 | cursor.close() |
|
464 | cnx.close() |
|
465 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
466 | description='API.SENSOR_POINT_RELATION_NOT_FOUND') |
|
467 | ||
468 | cursor.execute(" DELETE FROM tbl_sensors_points WHERE sensor_id = %s AND point_id = %s ", (id_, pid)) |
|
469 | cnx.commit() |
|
470 | ||
471 | cursor.close() |
|
472 | cnx.close() |
|
473 | ||
474 | resp.status = falcon.HTTP_204 |
|
475 | ||
476 | ||
477 | class SensorExport: |