@@ 2431-2487 (lines=57) @@ | ||
2428 | resp.location = '/spaces/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
2429 | ||
2430 | ||
2431 | class SpaceVirtualMeterItem: |
|
2432 | @staticmethod |
|
2433 | def __init__(): |
|
2434 | pass |
|
2435 | ||
2436 | @staticmethod |
|
2437 | def on_options(req, resp, id_, mid): |
|
2438 | resp.status = falcon.HTTP_200 |
|
2439 | ||
2440 | @staticmethod |
|
2441 | def on_delete(req, resp, id_, mid): |
|
2442 | if not id_.isdigit() or int(id_) <= 0: |
|
2443 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2444 | description='API.INVALID_SPACE_ID') |
|
2445 | ||
2446 | if not mid.isdigit() or int(mid) <= 0: |
|
2447 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2448 | description='API.INVALID_VIRTUAL_METER_ID') |
|
2449 | ||
2450 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2451 | cursor = cnx.cursor() |
|
2452 | ||
2453 | cursor.execute(" SELECT name " |
|
2454 | " FROM tbl_spaces " |
|
2455 | " WHERE id = %s ", (id_,)) |
|
2456 | if cursor.fetchone() is None: |
|
2457 | cursor.close() |
|
2458 | cnx.disconnect() |
|
2459 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
2460 | description='API.SPACE_NOT_FOUND') |
|
2461 | ||
2462 | cursor.execute(" SELECT name " |
|
2463 | " FROM tbl_virtual_meters " |
|
2464 | " WHERE id = %s ", (mid,)) |
|
2465 | if cursor.fetchone() is None: |
|
2466 | cursor.close() |
|
2467 | cnx.disconnect() |
|
2468 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
2469 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
2470 | ||
2471 | cursor.execute(" SELECT id " |
|
2472 | " FROM tbl_spaces_virtual_meters " |
|
2473 | " WHERE space_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
2474 | if cursor.fetchone() is None: |
|
2475 | cursor.close() |
|
2476 | cnx.disconnect() |
|
2477 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
2478 | description='API.SPACE_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
2479 | ||
2480 | cursor.execute(" DELETE FROM tbl_spaces_virtual_meters " |
|
2481 | " WHERE space_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
2482 | cnx.commit() |
|
2483 | ||
2484 | cursor.close() |
|
2485 | cnx.disconnect() |
|
2486 | ||
2487 | resp.status = falcon.HTTP_204 |
|
2488 | ||
2489 | ||
2490 | class SpaceTreeCollection: |
|
@@ 1596-1652 (lines=57) @@ | ||
1593 | resp.location = '/spaces/' + str(id_) + '/points/' + str(point_id) |
|
1594 | ||
1595 | ||
1596 | class SpacePointItem: |
|
1597 | @staticmethod |
|
1598 | def __init__(): |
|
1599 | pass |
|
1600 | ||
1601 | @staticmethod |
|
1602 | def on_options(req, resp, id_, pid): |
|
1603 | resp.status = falcon.HTTP_200 |
|
1604 | ||
1605 | @staticmethod |
|
1606 | def on_delete(req, resp, id_, pid): |
|
1607 | if not id_.isdigit() or int(id_) <= 0: |
|
1608 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1609 | description='API.INVALID_SPACE_ID') |
|
1610 | ||
1611 | if not pid.isdigit() or int(pid) <= 0: |
|
1612 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1613 | description='API.INVALID_POINT_ID') |
|
1614 | ||
1615 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1616 | cursor = cnx.cursor() |
|
1617 | ||
1618 | cursor.execute(" SELECT name " |
|
1619 | " FROM tbl_spaces " |
|
1620 | " WHERE id = %s ", (id_,)) |
|
1621 | if cursor.fetchone() is None: |
|
1622 | cursor.close() |
|
1623 | cnx.disconnect() |
|
1624 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1625 | description='API.SPACE_NOT_FOUND') |
|
1626 | ||
1627 | cursor.execute(" SELECT name " |
|
1628 | " FROM tbl_points " |
|
1629 | " WHERE id = %s ", (pid,)) |
|
1630 | if cursor.fetchone() is None: |
|
1631 | cursor.close() |
|
1632 | cnx.disconnect() |
|
1633 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1634 | description='API.POINT_NOT_FOUND') |
|
1635 | ||
1636 | cursor.execute(" SELECT id " |
|
1637 | " FROM tbl_spaces_points " |
|
1638 | " WHERE space_id = %s AND point_id = %s ", (id_, pid)) |
|
1639 | if cursor.fetchone() is None: |
|
1640 | cursor.close() |
|
1641 | cnx.disconnect() |
|
1642 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1643 | description='API.SPACE_POINT_RELATION_NOT_FOUND') |
|
1644 | ||
1645 | cursor.execute(" DELETE FROM tbl_spaces_points " |
|
1646 | " WHERE space_id = %s AND point_id = %s ", (id_, pid)) |
|
1647 | cnx.commit() |
|
1648 | ||
1649 | cursor.close() |
|
1650 | cnx.disconnect() |
|
1651 | ||
1652 | resp.status = falcon.HTTP_204 |
|
1653 | ||
1654 | ||
1655 | class SpaceSensorCollection: |
|
@@ 1418-1474 (lines=57) @@ | ||
1415 | resp.location = '/spaces/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
1416 | ||
1417 | ||
1418 | class SpaceOfflineMeterItem: |
|
1419 | @staticmethod |
|
1420 | def __init__(): |
|
1421 | pass |
|
1422 | ||
1423 | @staticmethod |
|
1424 | def on_options(req, resp, id_, mid): |
|
1425 | resp.status = falcon.HTTP_200 |
|
1426 | ||
1427 | @staticmethod |
|
1428 | def on_delete(req, resp, id_, mid): |
|
1429 | if not id_.isdigit() or int(id_) <= 0: |
|
1430 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1431 | description='API.INVALID_SPACE_ID') |
|
1432 | ||
1433 | if not mid.isdigit() or int(mid) <= 0: |
|
1434 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1435 | description='API.INVALID_OFFLINE_METER_ID') |
|
1436 | ||
1437 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1438 | cursor = cnx.cursor() |
|
1439 | ||
1440 | cursor.execute(" SELECT name " |
|
1441 | " FROM tbl_spaces " |
|
1442 | " WHERE id = %s ", (id_,)) |
|
1443 | if cursor.fetchone() is None: |
|
1444 | cursor.close() |
|
1445 | cnx.disconnect() |
|
1446 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1447 | description='API.SPACE_NOT_FOUND') |
|
1448 | ||
1449 | cursor.execute(" SELECT name " |
|
1450 | " FROM tbl_offline_meters " |
|
1451 | " WHERE id = %s ", (mid,)) |
|
1452 | if cursor.fetchone() is None: |
|
1453 | cursor.close() |
|
1454 | cnx.disconnect() |
|
1455 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1456 | description='API.OFFLINE_METER_NOT_FOUND') |
|
1457 | ||
1458 | cursor.execute(" SELECT id " |
|
1459 | " FROM tbl_spaces_offline_meters " |
|
1460 | " WHERE space_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1461 | if cursor.fetchone() is None: |
|
1462 | cursor.close() |
|
1463 | cnx.disconnect() |
|
1464 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1465 | description='API.SPACE_OFFLINE_METER_RELATION_NOT_FOUND') |
|
1466 | ||
1467 | cursor.execute(" DELETE FROM tbl_spaces_offline_meters " |
|
1468 | " WHERE space_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1469 | cnx.commit() |
|
1470 | ||
1471 | cursor.close() |
|
1472 | cnx.disconnect() |
|
1473 | ||
1474 | resp.status = falcon.HTTP_204 |
|
1475 | ||
1476 | ||
1477 | class SpacePointCollection: |
|
@@ 897-953 (lines=57) @@ | ||
894 | resp.location = '/spaces/' + str(id_) + '/combinedequipments/' + str(combined_equipment_id) |
|
895 | ||
896 | ||
897 | class SpaceCombinedEquipmentItem: |
|
898 | @staticmethod |
|
899 | def __init__(): |
|
900 | pass |
|
901 | ||
902 | @staticmethod |
|
903 | def on_options(req, resp, id_, eid): |
|
904 | resp.status = falcon.HTTP_200 |
|
905 | ||
906 | @staticmethod |
|
907 | def on_delete(req, resp, id_, eid): |
|
908 | if not id_.isdigit() or int(id_) <= 0: |
|
909 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
910 | description='API.INVALID_SPACE_ID') |
|
911 | ||
912 | if not eid.isdigit() or int(eid) <= 0: |
|
913 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
914 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
915 | ||
916 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
917 | cursor = cnx.cursor() |
|
918 | ||
919 | cursor.execute(" SELECT name " |
|
920 | " FROM tbl_spaces " |
|
921 | " WHERE id = %s ", (id_,)) |
|
922 | if cursor.fetchone() is None: |
|
923 | cursor.close() |
|
924 | cnx.disconnect() |
|
925 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
926 | description='API.SPACE_NOT_FOUND') |
|
927 | ||
928 | cursor.execute(" SELECT name " |
|
929 | " FROM tbl_combined_equipments " |
|
930 | " WHERE id = %s ", (eid,)) |
|
931 | if cursor.fetchone() is None: |
|
932 | cursor.close() |
|
933 | cnx.disconnect() |
|
934 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
935 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
936 | ||
937 | cursor.execute(" SELECT id " |
|
938 | " FROM tbl_spaces_combined_equipments " |
|
939 | " WHERE space_id = %s AND combined_equipment_id = %s ", (id_, eid)) |
|
940 | if cursor.fetchone() is None: |
|
941 | cursor.close() |
|
942 | cnx.disconnect() |
|
943 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
944 | description='API.SPACE_COMBINED_EQUIPMENT_RELATION_NOT_FOUND') |
|
945 | ||
946 | cursor.execute(" DELETE FROM tbl_spaces_combined_equipments " |
|
947 | " WHERE space_id = %s AND combined_equipment_id = %s ", (id_, eid)) |
|
948 | cnx.commit() |
|
949 | ||
950 | cursor.close() |
|
951 | cnx.disconnect() |
|
952 | ||
953 | resp.status = falcon.HTTP_204 |
|
954 | ||
955 | ||
956 | class SpaceEquipmentCollection: |
|
@@ 2253-2308 (lines=56) @@ | ||
2250 | resp.location = '/spaces/' + str(id_) + '/tenants/' + str(tenant_id) |
|
2251 | ||
2252 | ||
2253 | class SpaceTenantItem: |
|
2254 | @staticmethod |
|
2255 | def __init__(): |
|
2256 | pass |
|
2257 | ||
2258 | @staticmethod |
|
2259 | def on_options(req, resp, id_, tid): |
|
2260 | resp.status = falcon.HTTP_200 |
|
2261 | ||
2262 | @staticmethod |
|
2263 | def on_delete(req, resp, id_, tid): |
|
2264 | if not id_.isdigit() or int(id_) <= 0: |
|
2265 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2266 | description='API.INVALID_SPACE_ID') |
|
2267 | ||
2268 | if not tid.isdigit() or int(tid) <= 0: |
|
2269 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2270 | description='API.INVALID_TENANT_ID') |
|
2271 | ||
2272 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2273 | cursor = cnx.cursor() |
|
2274 | ||
2275 | cursor.execute(" SELECT name " |
|
2276 | " FROM tbl_spaces " |
|
2277 | " WHERE id = %s ", (id_,)) |
|
2278 | if cursor.fetchone() is None: |
|
2279 | cursor.close() |
|
2280 | cnx.disconnect() |
|
2281 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
2282 | description='API.SPACE_NOT_FOUND') |
|
2283 | ||
2284 | cursor.execute(" SELECT name " |
|
2285 | " FROM tbl_tenants " |
|
2286 | " WHERE id = %s ", (tid,)) |
|
2287 | if cursor.fetchone() is None: |
|
2288 | cursor.close() |
|
2289 | cnx.disconnect() |
|
2290 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
2291 | description='API.TENANT_NOT_FOUND') |
|
2292 | ||
2293 | cursor.execute(" SELECT id " |
|
2294 | " FROM tbl_spaces_tenants " |
|
2295 | " WHERE space_id = %s AND tenant_id = %s ", (id_, tid)) |
|
2296 | if cursor.fetchone() is None: |
|
2297 | cursor.close() |
|
2298 | cnx.disconnect() |
|
2299 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
2300 | description='API.SPACE_TENANT_RELATION_NOT_FOUND') |
|
2301 | ||
2302 | cursor.execute(" DELETE FROM tbl_spaces_tenants WHERE space_id = %s AND tenant_id = %s ", (id_, tid)) |
|
2303 | cnx.commit() |
|
2304 | ||
2305 | cursor.close() |
|
2306 | cnx.disconnect() |
|
2307 | ||
2308 | resp.status = falcon.HTTP_204 |
|
2309 | ||
2310 | ||
2311 | class SpaceVirtualMeterCollection: |
|
@@ 2089-2144 (lines=56) @@ | ||
2086 | resp.location = '/spaces/' + str(id_) + '/stores/' + str(store_id) |
|
2087 | ||
2088 | ||
2089 | class SpaceStoreItem: |
|
2090 | @staticmethod |
|
2091 | def __init__(): |
|
2092 | pass |
|
2093 | ||
2094 | @staticmethod |
|
2095 | def on_options(req, resp, id_, tid): |
|
2096 | resp.status = falcon.HTTP_200 |
|
2097 | ||
2098 | @staticmethod |
|
2099 | def on_delete(req, resp, id_, tid): |
|
2100 | if not id_.isdigit() or int(id_) <= 0: |
|
2101 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2102 | description='API.INVALID_SPACE_ID') |
|
2103 | ||
2104 | if not tid.isdigit() or int(tid) <= 0: |
|
2105 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
2106 | description='API.INVALID_STORE_ID') |
|
2107 | ||
2108 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
2109 | cursor = cnx.cursor() |
|
2110 | ||
2111 | cursor.execute(" SELECT name " |
|
2112 | " FROM tbl_spaces " |
|
2113 | " WHERE id = %s ", (id_,)) |
|
2114 | if cursor.fetchone() is None: |
|
2115 | cursor.close() |
|
2116 | cnx.disconnect() |
|
2117 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
2118 | description='API.SPACE_NOT_FOUND') |
|
2119 | ||
2120 | cursor.execute(" SELECT name " |
|
2121 | " FROM tbl_stores " |
|
2122 | " WHERE id = %s ", (tid,)) |
|
2123 | if cursor.fetchone() is None: |
|
2124 | cursor.close() |
|
2125 | cnx.disconnect() |
|
2126 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
2127 | description='API.STORE_NOT_FOUND') |
|
2128 | ||
2129 | cursor.execute(" SELECT id " |
|
2130 | " FROM tbl_spaces_stores " |
|
2131 | " WHERE space_id = %s AND store_id = %s ", (id_, tid)) |
|
2132 | if cursor.fetchone() is None: |
|
2133 | cursor.close() |
|
2134 | cnx.disconnect() |
|
2135 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
2136 | description='API.SPACE_STORE_RELATION_NOT_FOUND') |
|
2137 | ||
2138 | cursor.execute(" DELETE FROM tbl_spaces_stores WHERE space_id = %s AND store_id = %s ", (id_, tid)) |
|
2139 | cnx.commit() |
|
2140 | ||
2141 | cursor.close() |
|
2142 | cnx.disconnect() |
|
2143 | ||
2144 | resp.status = falcon.HTTP_204 |
|
2145 | ||
2146 | ||
2147 | class SpaceTenantCollection: |
|
@@ 1925-1980 (lines=56) @@ | ||
1922 | resp.location = '/spaces/' + str(id_) + '/shopfloors/' + str(shopfloor_id) |
|
1923 | ||
1924 | ||
1925 | class SpaceShopfloorItem: |
|
1926 | @staticmethod |
|
1927 | def __init__(): |
|
1928 | pass |
|
1929 | ||
1930 | @staticmethod |
|
1931 | def on_options(req, resp, id_, sid): |
|
1932 | resp.status = falcon.HTTP_200 |
|
1933 | ||
1934 | @staticmethod |
|
1935 | def on_delete(req, resp, id_, sid): |
|
1936 | if not id_.isdigit() or int(id_) <= 0: |
|
1937 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1938 | description='API.INVALID_SPACE_ID') |
|
1939 | ||
1940 | if not sid.isdigit() or int(sid) <= 0: |
|
1941 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1942 | description='API.INVALID_SHOPFLOOR_ID') |
|
1943 | ||
1944 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1945 | cursor = cnx.cursor() |
|
1946 | ||
1947 | cursor.execute(" SELECT name " |
|
1948 | " FROM tbl_spaces " |
|
1949 | " WHERE id = %s ", (id_,)) |
|
1950 | if cursor.fetchone() is None: |
|
1951 | cursor.close() |
|
1952 | cnx.disconnect() |
|
1953 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1954 | description='API.SPACE_NOT_FOUND') |
|
1955 | ||
1956 | cursor.execute(" SELECT name " |
|
1957 | " FROM tbl_shopfloors " |
|
1958 | " WHERE id = %s ", (sid,)) |
|
1959 | if cursor.fetchone() is None: |
|
1960 | cursor.close() |
|
1961 | cnx.disconnect() |
|
1962 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1963 | description='API.SHOPFLOOR_NOT_FOUND') |
|
1964 | ||
1965 | cursor.execute(" SELECT id " |
|
1966 | " FROM tbl_spaces_shopfloors " |
|
1967 | " WHERE space_id = %s AND shopfloor_id = %s ", (id_, sid)) |
|
1968 | if cursor.fetchone() is None: |
|
1969 | cursor.close() |
|
1970 | cnx.disconnect() |
|
1971 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1972 | description='API.SPACE_SHOPFLOOR_RELATION_NOT_FOUND') |
|
1973 | ||
1974 | cursor.execute(" DELETE FROM tbl_spaces_shopfloors WHERE space_id = %s AND shopfloor_id = %s ", (id_, sid)) |
|
1975 | cnx.commit() |
|
1976 | ||
1977 | cursor.close() |
|
1978 | cnx.disconnect() |
|
1979 | ||
1980 | resp.status = falcon.HTTP_204 |
|
1981 | ||
1982 | ||
1983 | class SpaceStoreCollection: |
|
@@ 1761-1816 (lines=56) @@ | ||
1758 | resp.location = '/spaces/' + str(id_) + '/sensors/' + str(sensor_id) |
|
1759 | ||
1760 | ||
1761 | class SpaceSensorItem: |
|
1762 | @staticmethod |
|
1763 | def __init__(): |
|
1764 | pass |
|
1765 | ||
1766 | @staticmethod |
|
1767 | def on_options(req, resp, id_, sid): |
|
1768 | resp.status = falcon.HTTP_200 |
|
1769 | ||
1770 | @staticmethod |
|
1771 | def on_delete(req, resp, id_, sid): |
|
1772 | if not id_.isdigit() or int(id_) <= 0: |
|
1773 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1774 | description='API.INVALID_SPACE_ID') |
|
1775 | ||
1776 | if not sid.isdigit() or int(sid) <= 0: |
|
1777 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1778 | description='API.INVALID_SENSOR_ID') |
|
1779 | ||
1780 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1781 | cursor = cnx.cursor() |
|
1782 | ||
1783 | cursor.execute(" SELECT name " |
|
1784 | " FROM tbl_spaces " |
|
1785 | " WHERE id = %s ", (id_,)) |
|
1786 | if cursor.fetchone() is None: |
|
1787 | cursor.close() |
|
1788 | cnx.disconnect() |
|
1789 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1790 | description='API.SPACE_NOT_FOUND') |
|
1791 | ||
1792 | cursor.execute(" SELECT name " |
|
1793 | " FROM tbl_sensors " |
|
1794 | " WHERE id = %s ", (sid,)) |
|
1795 | if cursor.fetchone() is None: |
|
1796 | cursor.close() |
|
1797 | cnx.disconnect() |
|
1798 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1799 | description='API.SENSOR_NOT_FOUND') |
|
1800 | ||
1801 | cursor.execute(" SELECT id " |
|
1802 | " FROM tbl_spaces_sensors " |
|
1803 | " WHERE space_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1804 | if cursor.fetchone() is None: |
|
1805 | cursor.close() |
|
1806 | cnx.disconnect() |
|
1807 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1808 | description='API.SPACE_SENSOR_RELATION_NOT_FOUND') |
|
1809 | ||
1810 | cursor.execute(" DELETE FROM tbl_spaces_sensors WHERE space_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1811 | cnx.commit() |
|
1812 | ||
1813 | cursor.close() |
|
1814 | cnx.disconnect() |
|
1815 | ||
1816 | resp.status = falcon.HTTP_204 |
|
1817 | ||
1818 | ||
1819 | class SpaceShopfloorCollection: |
|
@@ 1240-1295 (lines=56) @@ | ||
1237 | resp.location = '/spaces/' + str(id_) + '/meters/' + str(meter_id) |
|
1238 | ||
1239 | ||
1240 | class SpaceMeterItem: |
|
1241 | @staticmethod |
|
1242 | def __init__(): |
|
1243 | pass |
|
1244 | ||
1245 | @staticmethod |
|
1246 | def on_options(req, resp, id_, mid): |
|
1247 | resp.status = falcon.HTTP_200 |
|
1248 | ||
1249 | @staticmethod |
|
1250 | def on_delete(req, resp, id_, mid): |
|
1251 | if not id_.isdigit() or int(id_) <= 0: |
|
1252 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1253 | description='API.INVALID_SPACE_ID') |
|
1254 | ||
1255 | if not mid.isdigit() or int(mid) <= 0: |
|
1256 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1257 | description='API.INVALID_METER_ID') |
|
1258 | ||
1259 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1260 | cursor = cnx.cursor() |
|
1261 | ||
1262 | cursor.execute(" SELECT name " |
|
1263 | " FROM tbl_spaces " |
|
1264 | " WHERE id = %s ", (id_,)) |
|
1265 | if cursor.fetchone() is None: |
|
1266 | cursor.close() |
|
1267 | cnx.disconnect() |
|
1268 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1269 | description='API.SPACE_NOT_FOUND') |
|
1270 | ||
1271 | cursor.execute(" SELECT name " |
|
1272 | " FROM tbl_meters " |
|
1273 | " WHERE id = %s ", (mid,)) |
|
1274 | if cursor.fetchone() is None: |
|
1275 | cursor.close() |
|
1276 | cnx.disconnect() |
|
1277 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1278 | description='API.METER_NOT_FOUND') |
|
1279 | ||
1280 | cursor.execute(" SELECT id " |
|
1281 | " FROM tbl_spaces_meters " |
|
1282 | " WHERE space_id = %s AND meter_id = %s ", (id_, mid)) |
|
1283 | if cursor.fetchone() is None: |
|
1284 | cursor.close() |
|
1285 | cnx.disconnect() |
|
1286 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1287 | description='API.SPACE_METER_RELATION_NOT_FOUND') |
|
1288 | ||
1289 | cursor.execute(" DELETE FROM tbl_spaces_meters WHERE space_id = %s AND meter_id = %s ", (id_, mid)) |
|
1290 | cnx.commit() |
|
1291 | ||
1292 | cursor.close() |
|
1293 | cnx.disconnect() |
|
1294 | ||
1295 | resp.status = falcon.HTTP_204 |
|
1296 | ||
1297 | ||
1298 | class SpaceOfflineMeterCollection: |
|
@@ 1062-1117 (lines=56) @@ | ||
1059 | resp.location = '/spaces/' + str(id_) + '/equipments/' + str(equipment_id) |
|
1060 | ||
1061 | ||
1062 | class SpaceEquipmentItem: |
|
1063 | @staticmethod |
|
1064 | def __init__(): |
|
1065 | pass |
|
1066 | ||
1067 | @staticmethod |
|
1068 | def on_options(req, resp, id_, eid): |
|
1069 | resp.status = falcon.HTTP_200 |
|
1070 | ||
1071 | @staticmethod |
|
1072 | def on_delete(req, resp, id_, eid): |
|
1073 | if not id_.isdigit() or int(id_) <= 0: |
|
1074 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1075 | description='API.INVALID_SPACE_ID') |
|
1076 | ||
1077 | if not eid.isdigit() or int(eid) <= 0: |
|
1078 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1079 | description='API.INVALID_EQUIPMENT_ID') |
|
1080 | ||
1081 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1082 | cursor = cnx.cursor() |
|
1083 | ||
1084 | cursor.execute(" SELECT name " |
|
1085 | " FROM tbl_spaces " |
|
1086 | " WHERE id = %s ", (id_,)) |
|
1087 | if cursor.fetchone() is None: |
|
1088 | cursor.close() |
|
1089 | cnx.disconnect() |
|
1090 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1091 | description='API.SPACE_NOT_FOUND') |
|
1092 | ||
1093 | cursor.execute(" SELECT name " |
|
1094 | " FROM tbl_equipments " |
|
1095 | " WHERE id = %s ", (eid,)) |
|
1096 | if cursor.fetchone() is None: |
|
1097 | cursor.close() |
|
1098 | cnx.disconnect() |
|
1099 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1100 | description='API.EQUIPMENT_NOT_FOUND') |
|
1101 | ||
1102 | cursor.execute(" SELECT id " |
|
1103 | " FROM tbl_spaces_equipments " |
|
1104 | " WHERE space_id = %s AND equipment_id = %s ", (id_, eid)) |
|
1105 | if cursor.fetchone() is None: |
|
1106 | cursor.close() |
|
1107 | cnx.disconnect() |
|
1108 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1109 | description='API.SPACE_EQUIPMENT_RELATION_NOT_FOUND') |
|
1110 | ||
1111 | cursor.execute(" DELETE FROM tbl_spaces_equipments WHERE space_id = %s AND equipment_id = %s ", (id_, eid)) |
|
1112 | cnx.commit() |
|
1113 | ||
1114 | cursor.close() |
|
1115 | cnx.disconnect() |
|
1116 | ||
1117 | resp.status = falcon.HTTP_204 |
|
1118 | ||
1119 | ||
1120 | class SpaceMeterCollection: |
@@ 1865-1921 (lines=57) @@ | ||
1862 | resp.location = '/combinedequipments/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
1863 | ||
1864 | ||
1865 | class CombinedEquipmentVirtualMeterItem: |
|
1866 | @staticmethod |
|
1867 | def __init__(): |
|
1868 | pass |
|
1869 | ||
1870 | @staticmethod |
|
1871 | def on_options(req, resp, id_, mid): |
|
1872 | resp.status = falcon.HTTP_200 |
|
1873 | ||
1874 | @staticmethod |
|
1875 | def on_delete(req, resp, id_, mid): |
|
1876 | if not id_.isdigit() or int(id_) <= 0: |
|
1877 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1878 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
1879 | ||
1880 | if not mid.isdigit() or int(mid) <= 0: |
|
1881 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1882 | description='API.INVALID_VIRTUAL_METER_ID') |
|
1883 | ||
1884 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1885 | cursor = cnx.cursor() |
|
1886 | ||
1887 | cursor.execute(" SELECT name " |
|
1888 | " FROM tbl_combined_equipments " |
|
1889 | " WHERE id = %s ", (id_,)) |
|
1890 | if cursor.fetchone() is None: |
|
1891 | cursor.close() |
|
1892 | cnx.disconnect() |
|
1893 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1894 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
1895 | ||
1896 | cursor.execute(" SELECT name " |
|
1897 | " FROM tbl_virtual_meters " |
|
1898 | " WHERE id = %s ", (mid,)) |
|
1899 | if cursor.fetchone() is None: |
|
1900 | cursor.close() |
|
1901 | cnx.disconnect() |
|
1902 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1903 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
1904 | ||
1905 | cursor.execute(" SELECT id " |
|
1906 | " FROM tbl_combined_equipments_virtual_meters " |
|
1907 | " WHERE combined_equipment_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1908 | if cursor.fetchone() is None: |
|
1909 | cursor.close() |
|
1910 | cnx.disconnect() |
|
1911 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1912 | description='API.COMBINED_EQUIPMENT_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
1913 | ||
1914 | cursor.execute(" DELETE FROM tbl_combined_equipments_virtual_meters " |
|
1915 | " WHERE combined_equipment_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1916 | cnx.commit() |
|
1917 | ||
1918 | cursor.close() |
|
1919 | cnx.disconnect() |
|
1920 | ||
1921 | resp.status = falcon.HTTP_204 |
|
1922 | ||
@@ 1678-1734 (lines=57) @@ | ||
1675 | resp.location = '/combinedequipments/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
1676 | ||
1677 | ||
1678 | class CombinedEquipmentOfflineMeterItem: |
|
1679 | @staticmethod |
|
1680 | def __init__(): |
|
1681 | pass |
|
1682 | ||
1683 | @staticmethod |
|
1684 | def on_options(req, resp, id_, mid): |
|
1685 | resp.status = falcon.HTTP_200 |
|
1686 | ||
1687 | @staticmethod |
|
1688 | def on_delete(req, resp, id_, mid): |
|
1689 | if not id_.isdigit() or int(id_) <= 0: |
|
1690 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1691 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
1692 | ||
1693 | if not mid.isdigit() or int(mid) <= 0: |
|
1694 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1695 | description='API.INVALID_OFFLINE_METER_ID') |
|
1696 | ||
1697 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1698 | cursor = cnx.cursor() |
|
1699 | ||
1700 | cursor.execute(" SELECT name " |
|
1701 | " FROM tbl_combined_equipments " |
|
1702 | " WHERE id = %s ", (id_,)) |
|
1703 | if cursor.fetchone() is None: |
|
1704 | cursor.close() |
|
1705 | cnx.disconnect() |
|
1706 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1707 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
1708 | ||
1709 | cursor.execute(" SELECT name " |
|
1710 | " FROM tbl_offline_meters " |
|
1711 | " WHERE id = %s ", (mid,)) |
|
1712 | if cursor.fetchone() is None: |
|
1713 | cursor.close() |
|
1714 | cnx.disconnect() |
|
1715 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1716 | description='API.OFFLINE_METER_NOT_FOUND') |
|
1717 | ||
1718 | cursor.execute(" SELECT id " |
|
1719 | " FROM tbl_combined_equipments_offline_meters " |
|
1720 | " WHERE combined_equipment_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1721 | if cursor.fetchone() is None: |
|
1722 | cursor.close() |
|
1723 | cnx.disconnect() |
|
1724 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1725 | description='API.COMBINED_EQUIPMENT_OFFLINE_METER_RELATION_NOT_FOUND') |
|
1726 | ||
1727 | cursor.execute(" DELETE FROM tbl_combined_equipments_offline_meters " |
|
1728 | " WHERE combined_equipment_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1729 | cnx.commit() |
|
1730 | ||
1731 | cursor.close() |
|
1732 | cnx.disconnect() |
|
1733 | ||
1734 | resp.status = falcon.HTTP_204 |
|
1735 | ||
1736 | ||
1737 | class CombinedEquipmentVirtualMeterCollection: |
|
@@ 1491-1547 (lines=57) @@ | ||
1488 | resp.location = '/combinedequipments/' + str(id_) + '/meters/' + str(meter_id) |
|
1489 | ||
1490 | ||
1491 | class CombinedEquipmentMeterItem: |
|
1492 | @staticmethod |
|
1493 | def __init__(): |
|
1494 | pass |
|
1495 | ||
1496 | @staticmethod |
|
1497 | def on_options(req, resp, id_, mid): |
|
1498 | resp.status = falcon.HTTP_200 |
|
1499 | ||
1500 | @staticmethod |
|
1501 | def on_delete(req, resp, id_, mid): |
|
1502 | if not id_.isdigit() or int(id_) <= 0: |
|
1503 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1504 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
1505 | ||
1506 | if not mid.isdigit() or int(mid) <= 0: |
|
1507 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1508 | description='API.INVALID_METER_ID') |
|
1509 | ||
1510 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1511 | cursor = cnx.cursor() |
|
1512 | ||
1513 | cursor.execute(" SELECT name " |
|
1514 | " FROM tbl_combined_equipments " |
|
1515 | " WHERE id = %s ", (id_,)) |
|
1516 | if cursor.fetchone() is None: |
|
1517 | cursor.close() |
|
1518 | cnx.disconnect() |
|
1519 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1520 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
1521 | ||
1522 | cursor.execute(" SELECT name " |
|
1523 | " FROM tbl_meters " |
|
1524 | " WHERE id = %s ", (mid,)) |
|
1525 | if cursor.fetchone() is None: |
|
1526 | cursor.close() |
|
1527 | cnx.disconnect() |
|
1528 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1529 | description='API.METER_NOT_FOUND') |
|
1530 | ||
1531 | cursor.execute(" SELECT id " |
|
1532 | " FROM tbl_combined_equipments_meters " |
|
1533 | " WHERE combined_equipment_id = %s AND meter_id = %s ", (id_, mid)) |
|
1534 | if cursor.fetchone() is None: |
|
1535 | cursor.close() |
|
1536 | cnx.disconnect() |
|
1537 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1538 | description='API.COMBINED_EQUIPMENT_METER_RELATION_NOT_FOUND') |
|
1539 | ||
1540 | cursor.execute(" DELETE FROM tbl_combined_equipments_meters " |
|
1541 | " WHERE combined_equipment_id = %s AND meter_id = %s ", (id_, mid)) |
|
1542 | cnx.commit() |
|
1543 | ||
1544 | cursor.close() |
|
1545 | cnx.disconnect() |
|
1546 | ||
1547 | resp.status = falcon.HTTP_204 |
|
1548 | ||
1549 | ||
1550 | class CombinedEquipmentOfflineMeterCollection: |
|
@@ 621-677 (lines=57) @@ | ||
618 | resp.location = '/combinedequipments/' + str(id_) + '/equipments/' + str(equipment_id) |
|
619 | ||
620 | ||
621 | class CombinedEquipmentEquipmentItem: |
|
622 | @staticmethod |
|
623 | def __init__(): |
|
624 | pass |
|
625 | ||
626 | @staticmethod |
|
627 | def on_options(req, resp, id_, eid): |
|
628 | resp.status = falcon.HTTP_200 |
|
629 | ||
630 | @staticmethod |
|
631 | def on_delete(req, resp, id_, eid): |
|
632 | if not id_.isdigit() or int(id_) <= 0: |
|
633 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
634 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
635 | ||
636 | if not eid.isdigit() or int(eid) <= 0: |
|
637 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
638 | description='API.INVALID_EQUIPMENT_ID') |
|
639 | ||
640 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
641 | cursor = cnx.cursor() |
|
642 | ||
643 | cursor.execute(" SELECT name " |
|
644 | " FROM tbl_combined_equipments " |
|
645 | " WHERE id = %s ", (id_,)) |
|
646 | if cursor.fetchone() is None: |
|
647 | cursor.close() |
|
648 | cnx.disconnect() |
|
649 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
650 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
651 | ||
652 | cursor.execute(" SELECT name " |
|
653 | " FROM tbl_equipments " |
|
654 | " WHERE id = %s ", (eid,)) |
|
655 | if cursor.fetchone() is None: |
|
656 | cursor.close() |
|
657 | cnx.disconnect() |
|
658 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
659 | description='API.EQUIPMENT_NOT_FOUND') |
|
660 | ||
661 | cursor.execute(" SELECT id " |
|
662 | " FROM tbl_combined_equipments_equipments " |
|
663 | " WHERE combined_equipment_id = %s AND equipment_id = %s ", (id_, eid)) |
|
664 | if cursor.fetchone() is None: |
|
665 | cursor.close() |
|
666 | cnx.disconnect() |
|
667 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
668 | description='API.COMBINED_EQUIPMENT_EQUIPMENT_RELATION_NOT_FOUND') |
|
669 | ||
670 | cursor.execute(" DELETE FROM tbl_combined_equipments_equipments " |
|
671 | " WHERE combined_equipment_id = %s AND equipment_id = %s ", (id_, eid)) |
|
672 | cnx.commit() |
|
673 | ||
674 | cursor.close() |
|
675 | cnx.disconnect() |
|
676 | ||
677 | resp.status = falcon.HTTP_204 |
|
678 | ||
679 | ||
680 | class CombinedEquipmentParameterCollection: |
@@ 1708-1764 (lines=57) @@ | ||
1705 | resp.location = '/equipments/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
1706 | ||
1707 | ||
1708 | class EquipmentVirtualMeterItem: |
|
1709 | @staticmethod |
|
1710 | def __init__(): |
|
1711 | pass |
|
1712 | ||
1713 | @staticmethod |
|
1714 | def on_options(req, resp, id_, mid): |
|
1715 | resp.status = falcon.HTTP_200 |
|
1716 | ||
1717 | @staticmethod |
|
1718 | def on_delete(req, resp, id_, mid): |
|
1719 | if not id_.isdigit() or int(id_) <= 0: |
|
1720 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1721 | description='API.INVALID_EQUIPMENT_ID') |
|
1722 | ||
1723 | if not mid.isdigit() or int(mid) <= 0: |
|
1724 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1725 | description='API.INVALID_VIRTUAL_METER_ID') |
|
1726 | ||
1727 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1728 | cursor = cnx.cursor() |
|
1729 | ||
1730 | cursor.execute(" SELECT name " |
|
1731 | " FROM tbl_equipments " |
|
1732 | " WHERE id = %s ", (id_,)) |
|
1733 | if cursor.fetchone() is None: |
|
1734 | cursor.close() |
|
1735 | cnx.disconnect() |
|
1736 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1737 | description='API.EQUIPMENT_NOT_FOUND') |
|
1738 | ||
1739 | cursor.execute(" SELECT name " |
|
1740 | " FROM tbl_virtual_meters " |
|
1741 | " WHERE id = %s ", (mid,)) |
|
1742 | if cursor.fetchone() is None: |
|
1743 | cursor.close() |
|
1744 | cnx.disconnect() |
|
1745 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1746 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
1747 | ||
1748 | cursor.execute(" SELECT id " |
|
1749 | " FROM tbl_equipments_virtual_meters " |
|
1750 | " WHERE equipment_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1751 | if cursor.fetchone() is None: |
|
1752 | cursor.close() |
|
1753 | cnx.disconnect() |
|
1754 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1755 | description='API.EQUIPMENT_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
1756 | ||
1757 | cursor.execute(" DELETE FROM tbl_equipments_virtual_meters " |
|
1758 | " WHERE equipment_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1759 | cnx.commit() |
|
1760 | ||
1761 | cursor.close() |
|
1762 | cnx.disconnect() |
|
1763 | ||
1764 | resp.status = falcon.HTTP_204 |
|
1765 | ||
@@ 1522-1578 (lines=57) @@ | ||
1519 | resp.location = '/equipments/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
1520 | ||
1521 | ||
1522 | class EquipmentOfflineMeterItem: |
|
1523 | @staticmethod |
|
1524 | def __init__(): |
|
1525 | pass |
|
1526 | ||
1527 | @staticmethod |
|
1528 | def on_options(req, resp, id_, mid): |
|
1529 | resp.status = falcon.HTTP_200 |
|
1530 | ||
1531 | @staticmethod |
|
1532 | def on_delete(req, resp, id_, mid): |
|
1533 | if not id_.isdigit() or int(id_) <= 0: |
|
1534 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1535 | description='API.INVALID_EQUIPMENT_ID') |
|
1536 | ||
1537 | if not mid.isdigit() or int(mid) <= 0: |
|
1538 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1539 | description='API.INVALID_OFFLINE_METER_ID') |
|
1540 | ||
1541 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1542 | cursor = cnx.cursor() |
|
1543 | ||
1544 | cursor.execute(" SELECT name " |
|
1545 | " FROM tbl_equipments " |
|
1546 | " WHERE id = %s ", (id_,)) |
|
1547 | if cursor.fetchone() is None: |
|
1548 | cursor.close() |
|
1549 | cnx.disconnect() |
|
1550 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1551 | description='API.EQUIPMENT_NOT_FOUND') |
|
1552 | ||
1553 | cursor.execute(" SELECT name " |
|
1554 | " FROM tbl_offline_meters " |
|
1555 | " WHERE id = %s ", (mid,)) |
|
1556 | if cursor.fetchone() is None: |
|
1557 | cursor.close() |
|
1558 | cnx.disconnect() |
|
1559 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1560 | description='API.OFFLINE_METER_NOT_FOUND') |
|
1561 | ||
1562 | cursor.execute(" SELECT id " |
|
1563 | " FROM tbl_equipments_offline_meters " |
|
1564 | " WHERE equipment_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1565 | if cursor.fetchone() is None: |
|
1566 | cursor.close() |
|
1567 | cnx.disconnect() |
|
1568 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1569 | description='API.EQUIPMENT_OFFLINE_METER_RELATION_NOT_FOUND') |
|
1570 | ||
1571 | cursor.execute(" DELETE FROM tbl_equipments_offline_meters " |
|
1572 | " WHERE equipment_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1573 | cnx.commit() |
|
1574 | ||
1575 | cursor.close() |
|
1576 | cnx.disconnect() |
|
1577 | ||
1578 | resp.status = falcon.HTTP_204 |
|
1579 | ||
1580 | ||
1581 | class EquipmentVirtualMeterCollection: |
|
@@ 1337-1392 (lines=56) @@ | ||
1334 | resp.location = '/equipments/' + str(id_) + '/meters/' + str(meter_id) |
|
1335 | ||
1336 | ||
1337 | class EquipmentMeterItem: |
|
1338 | @staticmethod |
|
1339 | def __init__(): |
|
1340 | pass |
|
1341 | ||
1342 | @staticmethod |
|
1343 | def on_options(req, resp, id_, mid): |
|
1344 | resp.status = falcon.HTTP_200 |
|
1345 | ||
1346 | @staticmethod |
|
1347 | def on_delete(req, resp, id_, mid): |
|
1348 | if not id_.isdigit() or int(id_) <= 0: |
|
1349 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1350 | description='API.INVALID_EQUIPMENT_ID') |
|
1351 | ||
1352 | if not mid.isdigit() or int(mid) <= 0: |
|
1353 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1354 | description='API.INVALID_METER_ID') |
|
1355 | ||
1356 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1357 | cursor = cnx.cursor() |
|
1358 | ||
1359 | cursor.execute(" SELECT name " |
|
1360 | " FROM tbl_equipments " |
|
1361 | " WHERE id = %s ", (id_,)) |
|
1362 | if cursor.fetchone() is None: |
|
1363 | cursor.close() |
|
1364 | cnx.disconnect() |
|
1365 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1366 | description='API.EQUIPMENT_NOT_FOUND') |
|
1367 | ||
1368 | cursor.execute(" SELECT name " |
|
1369 | " FROM tbl_meters " |
|
1370 | " WHERE id = %s ", (mid,)) |
|
1371 | if cursor.fetchone() is None: |
|
1372 | cursor.close() |
|
1373 | cnx.disconnect() |
|
1374 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1375 | description='API.METER_NOT_FOUND') |
|
1376 | ||
1377 | cursor.execute(" SELECT id " |
|
1378 | " FROM tbl_equipments_meters " |
|
1379 | " WHERE equipment_id = %s AND meter_id = %s ", (id_, mid)) |
|
1380 | if cursor.fetchone() is None: |
|
1381 | cursor.close() |
|
1382 | cnx.disconnect() |
|
1383 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1384 | description='API.EQUIPMENT_METER_RELATION_NOT_FOUND') |
|
1385 | ||
1386 | cursor.execute(" DELETE FROM tbl_equipments_meters WHERE equipment_id = %s AND meter_id = %s ", (id_, mid)) |
|
1387 | cnx.commit() |
|
1388 | ||
1389 | cursor.close() |
|
1390 | cnx.disconnect() |
|
1391 | ||
1392 | resp.status = falcon.HTTP_204 |
|
1393 | ||
1394 | ||
1395 | class EquipmentOfflineMeterCollection: |
@@ 1506-1562 (lines=57) @@ | ||
1503 | resp.location = '/tenants/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
1504 | ||
1505 | ||
1506 | class TenantVirtualMeterItem: |
|
1507 | @staticmethod |
|
1508 | def __init__(): |
|
1509 | pass |
|
1510 | ||
1511 | @staticmethod |
|
1512 | def on_options(req, resp, id_, mid): |
|
1513 | resp.status = falcon.HTTP_200 |
|
1514 | ||
1515 | @staticmethod |
|
1516 | def on_delete(req, resp, id_, mid): |
|
1517 | if not id_.isdigit() or int(id_) <= 0: |
|
1518 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1519 | description='API.INVALID_TENANT_ID') |
|
1520 | ||
1521 | if not mid.isdigit() or int(mid) <= 0: |
|
1522 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1523 | description='API.INVALID_VIRTUAL_METER_ID') |
|
1524 | ||
1525 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1526 | cursor = cnx.cursor() |
|
1527 | ||
1528 | cursor.execute(" SELECT name " |
|
1529 | " FROM tbl_tenants " |
|
1530 | " WHERE id = %s ", (id_,)) |
|
1531 | if cursor.fetchone() is None: |
|
1532 | cursor.close() |
|
1533 | cnx.disconnect() |
|
1534 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1535 | description='API.TENANT_NOT_FOUND') |
|
1536 | ||
1537 | cursor.execute(" SELECT name " |
|
1538 | " FROM tbl_virtual_meters " |
|
1539 | " WHERE id = %s ", (mid,)) |
|
1540 | if cursor.fetchone() is None: |
|
1541 | cursor.close() |
|
1542 | cnx.disconnect() |
|
1543 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1544 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
1545 | ||
1546 | cursor.execute(" SELECT id " |
|
1547 | " FROM tbl_tenants_virtual_meters " |
|
1548 | " WHERE tenant_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1549 | if cursor.fetchone() is None: |
|
1550 | cursor.close() |
|
1551 | cnx.disconnect() |
|
1552 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1553 | description='API.TENANT_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
1554 | ||
1555 | cursor.execute(" DELETE FROM tbl_tenants_virtual_meters " |
|
1556 | " WHERE tenant_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1557 | cnx.commit() |
|
1558 | ||
1559 | cursor.close() |
|
1560 | cnx.disconnect() |
|
1561 | ||
1562 | resp.status = falcon.HTTP_204 |
|
1563 | ||
1564 | ||
1565 | ||
@@ 1163-1219 (lines=57) @@ | ||
1160 | resp.location = '/tenants/' + str(id_) + '/points/' + str(point_id) |
|
1161 | ||
1162 | ||
1163 | class TenantPointItem: |
|
1164 | @staticmethod |
|
1165 | def __init__(): |
|
1166 | pass |
|
1167 | ||
1168 | @staticmethod |
|
1169 | def on_options(req, resp, id_, pid): |
|
1170 | resp.status = falcon.HTTP_200 |
|
1171 | ||
1172 | @staticmethod |
|
1173 | def on_delete(req, resp, id_, pid): |
|
1174 | if not id_.isdigit() or int(id_) <= 0: |
|
1175 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1176 | description='API.INVALID_TENANT_ID') |
|
1177 | ||
1178 | if not pid.isdigit() or int(pid) <= 0: |
|
1179 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1180 | description='API.INVALID_POINT_ID') |
|
1181 | ||
1182 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1183 | cursor = cnx.cursor() |
|
1184 | ||
1185 | cursor.execute(" SELECT name " |
|
1186 | " FROM tbl_tenants " |
|
1187 | " WHERE id = %s ", (id_,)) |
|
1188 | if cursor.fetchone() is None: |
|
1189 | cursor.close() |
|
1190 | cnx.disconnect() |
|
1191 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1192 | description='API.TENANT_NOT_FOUND') |
|
1193 | ||
1194 | cursor.execute(" SELECT name " |
|
1195 | " FROM tbl_points " |
|
1196 | " WHERE id = %s ", (pid,)) |
|
1197 | if cursor.fetchone() is None: |
|
1198 | cursor.close() |
|
1199 | cnx.disconnect() |
|
1200 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1201 | description='API.POINT_NOT_FOUND') |
|
1202 | ||
1203 | cursor.execute(" SELECT id " |
|
1204 | " FROM tbl_tenants_points " |
|
1205 | " WHERE tenant_id = %s AND point_id = %s ", (id_, pid)) |
|
1206 | if cursor.fetchone() is None: |
|
1207 | cursor.close() |
|
1208 | cnx.disconnect() |
|
1209 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1210 | description='API.TENANT_POINT_RELATION_NOT_FOUND') |
|
1211 | ||
1212 | cursor.execute(" DELETE FROM tbl_tenants_points " |
|
1213 | " WHERE tenant_id = %s AND point_id = %s ", (id_, pid)) |
|
1214 | cnx.commit() |
|
1215 | ||
1216 | cursor.close() |
|
1217 | cnx.disconnect() |
|
1218 | ||
1219 | resp.status = falcon.HTTP_204 |
|
1220 | ||
1221 | ||
1222 | class TenantSensorCollection: |
|
@@ 985-1041 (lines=57) @@ | ||
982 | resp.location = '/tenants/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
983 | ||
984 | ||
985 | class TenantOfflineMeterItem: |
|
986 | @staticmethod |
|
987 | def __init__(): |
|
988 | pass |
|
989 | ||
990 | @staticmethod |
|
991 | def on_options(req, resp, id_, mid): |
|
992 | resp.status = falcon.HTTP_200 |
|
993 | ||
994 | @staticmethod |
|
995 | def on_delete(req, resp, id_, mid): |
|
996 | if not id_.isdigit() or int(id_) <= 0: |
|
997 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
998 | description='API.INVALID_TENANT_ID') |
|
999 | ||
1000 | if not mid.isdigit() or int(mid) <= 0: |
|
1001 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1002 | description='API.INVALID_OFFLINE_METER_ID') |
|
1003 | ||
1004 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1005 | cursor = cnx.cursor() |
|
1006 | ||
1007 | cursor.execute(" SELECT name " |
|
1008 | " FROM tbl_tenants " |
|
1009 | " WHERE id = %s ", (id_,)) |
|
1010 | if cursor.fetchone() is None: |
|
1011 | cursor.close() |
|
1012 | cnx.disconnect() |
|
1013 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1014 | description='API.TENANT_NOT_FOUND') |
|
1015 | ||
1016 | cursor.execute(" SELECT name " |
|
1017 | " FROM tbl_offline_meters " |
|
1018 | " WHERE id = %s ", (mid,)) |
|
1019 | if cursor.fetchone() is None: |
|
1020 | cursor.close() |
|
1021 | cnx.disconnect() |
|
1022 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1023 | description='API.OFFLINE_METER_NOT_FOUND') |
|
1024 | ||
1025 | cursor.execute(" SELECT id " |
|
1026 | " FROM tbl_tenants_offline_meters " |
|
1027 | " WHERE tenant_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1028 | if cursor.fetchone() is None: |
|
1029 | cursor.close() |
|
1030 | cnx.disconnect() |
|
1031 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1032 | description='API.TENANT_OFFLINE_METER_RELATION_NOT_FOUND') |
|
1033 | ||
1034 | cursor.execute(" DELETE FROM tbl_tenants_offline_meters " |
|
1035 | " WHERE tenant_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1036 | cnx.commit() |
|
1037 | ||
1038 | cursor.close() |
|
1039 | cnx.disconnect() |
|
1040 | ||
1041 | resp.status = falcon.HTTP_204 |
|
1042 | ||
1043 | ||
1044 | class TenantPointCollection: |
|
@@ 1328-1383 (lines=56) @@ | ||
1325 | resp.location = '/tenants/' + str(id_) + '/sensors/' + str(sensor_id) |
|
1326 | ||
1327 | ||
1328 | class TenantSensorItem: |
|
1329 | @staticmethod |
|
1330 | def __init__(): |
|
1331 | pass |
|
1332 | ||
1333 | @staticmethod |
|
1334 | def on_options(req, resp, id_, sid): |
|
1335 | resp.status = falcon.HTTP_200 |
|
1336 | ||
1337 | @staticmethod |
|
1338 | def on_delete(req, resp, id_, sid): |
|
1339 | if not id_.isdigit() or int(id_) <= 0: |
|
1340 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1341 | description='API.INVALID_TENANT_ID') |
|
1342 | ||
1343 | if not sid.isdigit() or int(sid) <= 0: |
|
1344 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1345 | description='API.INVALID_SENSOR_ID') |
|
1346 | ||
1347 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1348 | cursor = cnx.cursor() |
|
1349 | ||
1350 | cursor.execute(" SELECT name " |
|
1351 | " FROM tbl_tenants " |
|
1352 | " WHERE id = %s ", (id_,)) |
|
1353 | if cursor.fetchone() is None: |
|
1354 | cursor.close() |
|
1355 | cnx.disconnect() |
|
1356 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1357 | description='API.TENANT_NOT_FOUND') |
|
1358 | ||
1359 | cursor.execute(" SELECT name " |
|
1360 | " FROM tbl_sensors " |
|
1361 | " WHERE id = %s ", (sid,)) |
|
1362 | if cursor.fetchone() is None: |
|
1363 | cursor.close() |
|
1364 | cnx.disconnect() |
|
1365 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1366 | description='API.SENSOR_NOT_FOUND') |
|
1367 | ||
1368 | cursor.execute(" SELECT id " |
|
1369 | " FROM tbl_tenants_sensors " |
|
1370 | " WHERE tenant_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1371 | if cursor.fetchone() is None: |
|
1372 | cursor.close() |
|
1373 | cnx.disconnect() |
|
1374 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1375 | description='API.TENANT_SENSOR_RELATION_NOT_FOUND') |
|
1376 | ||
1377 | cursor.execute(" DELETE FROM tbl_tenants_sensors WHERE tenant_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1378 | cnx.commit() |
|
1379 | ||
1380 | cursor.close() |
|
1381 | cnx.disconnect() |
|
1382 | ||
1383 | resp.status = falcon.HTTP_204 |
|
1384 | ||
1385 | ||
1386 | class TenantVirtualMeterCollection: |
|
@@ 807-862 (lines=56) @@ | ||
804 | resp.location = '/tenants/' + str(id_) + '/meters/' + str(meter_id) |
|
805 | ||
806 | ||
807 | class TenantMeterItem: |
|
808 | @staticmethod |
|
809 | def __init__(): |
|
810 | pass |
|
811 | ||
812 | @staticmethod |
|
813 | def on_options(req, resp, id_, mid): |
|
814 | resp.status = falcon.HTTP_200 |
|
815 | ||
816 | @staticmethod |
|
817 | def on_delete(req, resp, id_, mid): |
|
818 | if not id_.isdigit() or int(id_) <= 0: |
|
819 | raise falcon.HTTPError(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(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.disconnect() |
|
835 | raise falcon.HTTPError(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.disconnect() |
|
844 | raise falcon.HTTPError(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.disconnect() |
|
853 | raise falcon.HTTPError(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.disconnect() |
|
861 | ||
862 | resp.status = falcon.HTTP_204 |
|
863 | ||
864 | ||
865 | class TenantOfflineMeterCollection: |
@@ 1498-1554 (lines=57) @@ | ||
1495 | resp.location = '/shopfloors/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
1496 | ||
1497 | ||
1498 | class ShopfloorVirtualMeterItem: |
|
1499 | @staticmethod |
|
1500 | def __init__(): |
|
1501 | pass |
|
1502 | ||
1503 | @staticmethod |
|
1504 | def on_options(req, resp, id_, mid): |
|
1505 | resp.status = falcon.HTTP_200 |
|
1506 | ||
1507 | @staticmethod |
|
1508 | def on_delete(req, resp, id_, mid): |
|
1509 | if not id_.isdigit() or int(id_) <= 0: |
|
1510 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1511 | description='API.INVALID_SHOPFLOOR_ID') |
|
1512 | ||
1513 | if not mid.isdigit() or int(mid) <= 0: |
|
1514 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1515 | description='API.INVALID_VIRTUAL_METER_ID') |
|
1516 | ||
1517 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1518 | cursor = cnx.cursor() |
|
1519 | ||
1520 | cursor.execute(" SELECT name " |
|
1521 | " FROM tbl_shopfloors " |
|
1522 | " WHERE id = %s ", (id_,)) |
|
1523 | if cursor.fetchone() is None: |
|
1524 | cursor.close() |
|
1525 | cnx.disconnect() |
|
1526 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1527 | description='API.SHOPFLOOR_NOT_FOUND') |
|
1528 | ||
1529 | cursor.execute(" SELECT name " |
|
1530 | " FROM tbl_virtual_meters " |
|
1531 | " WHERE id = %s ", (mid,)) |
|
1532 | if cursor.fetchone() is None: |
|
1533 | cursor.close() |
|
1534 | cnx.disconnect() |
|
1535 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1536 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
1537 | ||
1538 | cursor.execute(" SELECT id " |
|
1539 | " FROM tbl_shopfloors_virtual_meters " |
|
1540 | " WHERE shopfloor_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1541 | if cursor.fetchone() is None: |
|
1542 | cursor.close() |
|
1543 | cnx.disconnect() |
|
1544 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1545 | description='API.SHOPFLOOR_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
1546 | ||
1547 | cursor.execute(" DELETE FROM tbl_shopfloors_virtual_meters " |
|
1548 | " WHERE shopfloor_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1549 | cnx.commit() |
|
1550 | ||
1551 | cursor.close() |
|
1552 | cnx.disconnect() |
|
1553 | ||
1554 | resp.status = falcon.HTTP_204 |
|
1555 | ||
1556 | ||
1557 | ||
@@ 1155-1211 (lines=57) @@ | ||
1152 | resp.location = '/shopfloors/' + str(id_) + '/points/' + str(point_id) |
|
1153 | ||
1154 | ||
1155 | class ShopfloorPointItem: |
|
1156 | @staticmethod |
|
1157 | def __init__(): |
|
1158 | pass |
|
1159 | ||
1160 | @staticmethod |
|
1161 | def on_options(req, resp, id_, pid): |
|
1162 | resp.status = falcon.HTTP_200 |
|
1163 | ||
1164 | @staticmethod |
|
1165 | def on_delete(req, resp, id_, pid): |
|
1166 | if not id_.isdigit() or int(id_) <= 0: |
|
1167 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1168 | description='API.INVALID_SHOPFLOOR_ID') |
|
1169 | ||
1170 | if not pid.isdigit() or int(pid) <= 0: |
|
1171 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1172 | description='API.INVALID_POINT_ID') |
|
1173 | ||
1174 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1175 | cursor = cnx.cursor() |
|
1176 | ||
1177 | cursor.execute(" SELECT name " |
|
1178 | " FROM tbl_shopfloors " |
|
1179 | " WHERE id = %s ", (id_,)) |
|
1180 | if cursor.fetchone() is None: |
|
1181 | cursor.close() |
|
1182 | cnx.disconnect() |
|
1183 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1184 | description='API.SHOPFLOOR_NOT_FOUND') |
|
1185 | ||
1186 | cursor.execute(" SELECT name " |
|
1187 | " FROM tbl_points " |
|
1188 | " WHERE id = %s ", (pid,)) |
|
1189 | if cursor.fetchone() is None: |
|
1190 | cursor.close() |
|
1191 | cnx.disconnect() |
|
1192 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1193 | description='API.POINT_NOT_FOUND') |
|
1194 | ||
1195 | cursor.execute(" SELECT id " |
|
1196 | " FROM tbl_shopfloors_points " |
|
1197 | " WHERE shopfloor_id = %s AND point_id = %s ", (id_, pid)) |
|
1198 | if cursor.fetchone() is None: |
|
1199 | cursor.close() |
|
1200 | cnx.disconnect() |
|
1201 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1202 | description='API.SHOPFLOOR_POINT_RELATION_NOT_FOUND') |
|
1203 | ||
1204 | cursor.execute(" DELETE FROM tbl_shopfloors_points " |
|
1205 | " WHERE shopfloor_id = %s AND point_id = %s ", (id_, pid)) |
|
1206 | cnx.commit() |
|
1207 | ||
1208 | cursor.close() |
|
1209 | cnx.disconnect() |
|
1210 | ||
1211 | resp.status = falcon.HTTP_204 |
|
1212 | ||
1213 | ||
1214 | class ShopfloorSensorCollection: |
|
@@ 977-1033 (lines=57) @@ | ||
974 | resp.location = '/shopfloors/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
975 | ||
976 | ||
977 | class ShopfloorOfflineMeterItem: |
|
978 | @staticmethod |
|
979 | def __init__(): |
|
980 | pass |
|
981 | ||
982 | @staticmethod |
|
983 | def on_options(req, resp, id_, mid): |
|
984 | resp.status = falcon.HTTP_200 |
|
985 | ||
986 | @staticmethod |
|
987 | def on_delete(req, resp, id_, mid): |
|
988 | if not id_.isdigit() or int(id_) <= 0: |
|
989 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
990 | description='API.INVALID_SHOPFLOOR_ID') |
|
991 | ||
992 | if not mid.isdigit() or int(mid) <= 0: |
|
993 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
994 | description='API.INVALID_OFFLINE_METER_ID') |
|
995 | ||
996 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
997 | cursor = cnx.cursor() |
|
998 | ||
999 | cursor.execute(" SELECT name " |
|
1000 | " FROM tbl_shopfloors " |
|
1001 | " WHERE id = %s ", (id_,)) |
|
1002 | if cursor.fetchone() is None: |
|
1003 | cursor.close() |
|
1004 | cnx.disconnect() |
|
1005 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1006 | description='API.SHOPFLOOR_NOT_FOUND') |
|
1007 | ||
1008 | cursor.execute(" SELECT name " |
|
1009 | " FROM tbl_offline_meters " |
|
1010 | " WHERE id = %s ", (mid,)) |
|
1011 | if cursor.fetchone() is None: |
|
1012 | cursor.close() |
|
1013 | cnx.disconnect() |
|
1014 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1015 | description='API.OFFLINE_METER_NOT_FOUND') |
|
1016 | ||
1017 | cursor.execute(" SELECT id " |
|
1018 | " FROM tbl_shopfloors_offline_meters " |
|
1019 | " WHERE shopfloor_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1020 | if cursor.fetchone() is None: |
|
1021 | cursor.close() |
|
1022 | cnx.disconnect() |
|
1023 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1024 | description='API.SHOPFLOOR_OFFLINE_METER_RELATION_NOT_FOUND') |
|
1025 | ||
1026 | cursor.execute(" DELETE FROM tbl_shopfloors_offline_meters " |
|
1027 | " WHERE shopfloor_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
1028 | cnx.commit() |
|
1029 | ||
1030 | cursor.close() |
|
1031 | cnx.disconnect() |
|
1032 | ||
1033 | resp.status = falcon.HTTP_204 |
|
1034 | ||
1035 | ||
1036 | class ShopfloorPointCollection: |
|
@@ 620-676 (lines=57) @@ | ||
617 | resp.location = '/shopfloors/' + str(id_) + '/equipments/' + str(equipment_id) |
|
618 | ||
619 | ||
620 | class ShopfloorEquipmentItem: |
|
621 | @staticmethod |
|
622 | def __init__(): |
|
623 | pass |
|
624 | ||
625 | @staticmethod |
|
626 | def on_options(req, resp, id_, eid): |
|
627 | resp.status = falcon.HTTP_200 |
|
628 | ||
629 | @staticmethod |
|
630 | def on_delete(req, resp, id_, eid): |
|
631 | if not id_.isdigit() or int(id_) <= 0: |
|
632 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
633 | description='API.INVALID_SHOPFLOOR_ID') |
|
634 | ||
635 | if not eid.isdigit() or int(eid) <= 0: |
|
636 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
637 | description='API.INVALID_EQUIPMENT_ID') |
|
638 | ||
639 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
640 | cursor = cnx.cursor() |
|
641 | ||
642 | cursor.execute(" SELECT name " |
|
643 | " FROM tbl_shopfloors " |
|
644 | " WHERE id = %s ", (id_,)) |
|
645 | if cursor.fetchone() is None: |
|
646 | cursor.close() |
|
647 | cnx.disconnect() |
|
648 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
649 | description='API.SHOPFLOOR_NOT_FOUND') |
|
650 | ||
651 | cursor.execute(" SELECT name " |
|
652 | " FROM tbl_equipments " |
|
653 | " WHERE id = %s ", (eid,)) |
|
654 | if cursor.fetchone() is None: |
|
655 | cursor.close() |
|
656 | cnx.disconnect() |
|
657 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
658 | description='API.EQUIPMENT_NOT_FOUND') |
|
659 | ||
660 | cursor.execute(" SELECT id " |
|
661 | " FROM tbl_shopfloors_equipments " |
|
662 | " WHERE shopfloor_id = %s AND equipment_id = %s ", (id_, eid)) |
|
663 | if cursor.fetchone() is None: |
|
664 | cursor.close() |
|
665 | cnx.disconnect() |
|
666 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
667 | description='API.SHOPFLOOR_EQUIPMENT_RELATION_NOT_FOUND') |
|
668 | ||
669 | cursor.execute(" DELETE FROM tbl_shopfloors_equipments " |
|
670 | " WHERE shopfloor_id = %s AND equipment_id = %s ", (id_, eid)) |
|
671 | cnx.commit() |
|
672 | ||
673 | cursor.close() |
|
674 | cnx.disconnect() |
|
675 | ||
676 | resp.status = falcon.HTTP_204 |
|
677 | ||
678 | ||
679 | class ShopfloorMeterCollection: |
|
@@ 1320-1375 (lines=56) @@ | ||
1317 | resp.location = '/shopfloors/' + str(id_) + '/sensors/' + str(sensor_id) |
|
1318 | ||
1319 | ||
1320 | class ShopfloorSensorItem: |
|
1321 | @staticmethod |
|
1322 | def __init__(): |
|
1323 | pass |
|
1324 | ||
1325 | @staticmethod |
|
1326 | def on_options(req, resp, id_, sid): |
|
1327 | resp.status = falcon.HTTP_200 |
|
1328 | ||
1329 | @staticmethod |
|
1330 | def on_delete(req, resp, id_, sid): |
|
1331 | if not id_.isdigit() or int(id_) <= 0: |
|
1332 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1333 | description='API.INVALID_SHOPFLOOR_ID') |
|
1334 | ||
1335 | if not sid.isdigit() or int(sid) <= 0: |
|
1336 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1337 | description='API.INVALID_SENSOR_ID') |
|
1338 | ||
1339 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1340 | cursor = cnx.cursor() |
|
1341 | ||
1342 | cursor.execute(" SELECT name " |
|
1343 | " FROM tbl_shopfloors " |
|
1344 | " WHERE id = %s ", (id_,)) |
|
1345 | if cursor.fetchone() is None: |
|
1346 | cursor.close() |
|
1347 | cnx.disconnect() |
|
1348 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1349 | description='API.SHOPFLOOR_NOT_FOUND') |
|
1350 | ||
1351 | cursor.execute(" SELECT name " |
|
1352 | " FROM tbl_sensors " |
|
1353 | " WHERE id = %s ", (sid,)) |
|
1354 | if cursor.fetchone() is None: |
|
1355 | cursor.close() |
|
1356 | cnx.disconnect() |
|
1357 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1358 | description='API.SENSOR_NOT_FOUND') |
|
1359 | ||
1360 | cursor.execute(" SELECT id " |
|
1361 | " FROM tbl_shopfloors_sensors " |
|
1362 | " WHERE shopfloor_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1363 | if cursor.fetchone() is None: |
|
1364 | cursor.close() |
|
1365 | cnx.disconnect() |
|
1366 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1367 | description='API.SHOPFLOOR_SENSOR_RELATION_NOT_FOUND') |
|
1368 | ||
1369 | cursor.execute(" DELETE FROM tbl_shopfloors_sensors WHERE shopfloor_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1370 | cnx.commit() |
|
1371 | ||
1372 | cursor.close() |
|
1373 | cnx.disconnect() |
|
1374 | ||
1375 | resp.status = falcon.HTTP_204 |
|
1376 | ||
1377 | ||
1378 | class ShopfloorVirtualMeterCollection: |
|
@@ 799-854 (lines=56) @@ | ||
796 | resp.location = '/shopfloors/' + str(id_) + '/meters/' + str(meter_id) |
|
797 | ||
798 | ||
799 | class ShopfloorMeterItem: |
|
800 | @staticmethod |
|
801 | def __init__(): |
|
802 | pass |
|
803 | ||
804 | @staticmethod |
|
805 | def on_options(req, resp, id_, mid): |
|
806 | resp.status = falcon.HTTP_200 |
|
807 | ||
808 | @staticmethod |
|
809 | def on_delete(req, resp, id_, mid): |
|
810 | if not id_.isdigit() or int(id_) <= 0: |
|
811 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
812 | description='API.INVALID_SHOPFLOOR_ID') |
|
813 | ||
814 | if not mid.isdigit() or int(mid) <= 0: |
|
815 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
816 | description='API.INVALID_METER_ID') |
|
817 | ||
818 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
819 | cursor = cnx.cursor() |
|
820 | ||
821 | cursor.execute(" SELECT name " |
|
822 | " FROM tbl_shopfloors " |
|
823 | " WHERE id = %s ", (id_,)) |
|
824 | if cursor.fetchone() is None: |
|
825 | cursor.close() |
|
826 | cnx.disconnect() |
|
827 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
828 | description='API.SHOPFLOOR_NOT_FOUND') |
|
829 | ||
830 | cursor.execute(" SELECT name " |
|
831 | " FROM tbl_meters " |
|
832 | " WHERE id = %s ", (mid,)) |
|
833 | if cursor.fetchone() is None: |
|
834 | cursor.close() |
|
835 | cnx.disconnect() |
|
836 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
837 | description='API.METER_NOT_FOUND') |
|
838 | ||
839 | cursor.execute(" SELECT id " |
|
840 | " FROM tbl_shopfloors_meters " |
|
841 | " WHERE shopfloor_id = %s AND meter_id = %s ", (id_, mid)) |
|
842 | if cursor.fetchone() is None: |
|
843 | cursor.close() |
|
844 | cnx.disconnect() |
|
845 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
846 | description='API.SHOPFLOOR_METER_RELATION_NOT_FOUND') |
|
847 | ||
848 | cursor.execute(" DELETE FROM tbl_shopfloors_meters WHERE shopfloor_id = %s AND meter_id = %s ", (id_, mid)) |
|
849 | cnx.commit() |
|
850 | ||
851 | cursor.close() |
|
852 | cnx.disconnect() |
|
853 | ||
854 | resp.status = falcon.HTTP_204 |
|
855 | ||
856 | ||
857 | class ShopfloorOfflineMeterCollection: |
@@ 1409-1465 (lines=57) @@ | ||
1406 | resp.location = '/stores/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
1407 | ||
1408 | ||
1409 | class StoreVirtualMeterItem: |
|
1410 | @staticmethod |
|
1411 | def __init__(): |
|
1412 | pass |
|
1413 | ||
1414 | @staticmethod |
|
1415 | def on_options(req, resp, id_, mid): |
|
1416 | resp.status = falcon.HTTP_200 |
|
1417 | ||
1418 | @staticmethod |
|
1419 | def on_delete(req, resp, id_, mid): |
|
1420 | if not id_.isdigit() or int(id_) <= 0: |
|
1421 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1422 | description='API.INVALID_STORE_ID') |
|
1423 | ||
1424 | if not mid.isdigit() or int(mid) <= 0: |
|
1425 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1426 | description='API.INVALID_VIRTUAL_METER_ID') |
|
1427 | ||
1428 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1429 | cursor = cnx.cursor() |
|
1430 | ||
1431 | cursor.execute(" SELECT name " |
|
1432 | " FROM tbl_stores " |
|
1433 | " WHERE id = %s ", (id_,)) |
|
1434 | if cursor.fetchone() is None: |
|
1435 | cursor.close() |
|
1436 | cnx.disconnect() |
|
1437 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1438 | description='API.STORE_NOT_FOUND') |
|
1439 | ||
1440 | cursor.execute(" SELECT name " |
|
1441 | " FROM tbl_virtual_meters " |
|
1442 | " WHERE id = %s ", (mid,)) |
|
1443 | if cursor.fetchone() is None: |
|
1444 | cursor.close() |
|
1445 | cnx.disconnect() |
|
1446 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1447 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
1448 | ||
1449 | cursor.execute(" SELECT id " |
|
1450 | " FROM tbl_stores_virtual_meters " |
|
1451 | " WHERE store_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1452 | if cursor.fetchone() is None: |
|
1453 | cursor.close() |
|
1454 | cnx.disconnect() |
|
1455 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1456 | description='API.STORE_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
1457 | ||
1458 | cursor.execute(" DELETE FROM tbl_stores_virtual_meters " |
|
1459 | " WHERE store_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
1460 | cnx.commit() |
|
1461 | ||
1462 | cursor.close() |
|
1463 | cnx.disconnect() |
|
1464 | ||
1465 | resp.status = falcon.HTTP_204 |
|
1466 | ||
1467 | ||
1468 | ||
@@ 1066-1122 (lines=57) @@ | ||
1063 | resp.location = '/stores/' + str(id_) + '/points/' + str(point_id) |
|
1064 | ||
1065 | ||
1066 | class StorePointItem: |
|
1067 | @staticmethod |
|
1068 | def __init__(): |
|
1069 | pass |
|
1070 | ||
1071 | @staticmethod |
|
1072 | def on_options(req, resp, id_, pid): |
|
1073 | resp.status = falcon.HTTP_200 |
|
1074 | ||
1075 | @staticmethod |
|
1076 | def on_delete(req, resp, id_, pid): |
|
1077 | if not id_.isdigit() or int(id_) <= 0: |
|
1078 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1079 | description='API.INVALID_STORE_ID') |
|
1080 | ||
1081 | if not pid.isdigit() or int(pid) <= 0: |
|
1082 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1083 | description='API.INVALID_POINT_ID') |
|
1084 | ||
1085 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1086 | cursor = cnx.cursor() |
|
1087 | ||
1088 | cursor.execute(" SELECT name " |
|
1089 | " FROM tbl_stores " |
|
1090 | " WHERE id = %s ", (id_,)) |
|
1091 | if cursor.fetchone() is None: |
|
1092 | cursor.close() |
|
1093 | cnx.disconnect() |
|
1094 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1095 | description='API.STORE_NOT_FOUND') |
|
1096 | ||
1097 | cursor.execute(" SELECT name " |
|
1098 | " FROM tbl_points " |
|
1099 | " WHERE id = %s ", (pid,)) |
|
1100 | if cursor.fetchone() is None: |
|
1101 | cursor.close() |
|
1102 | cnx.disconnect() |
|
1103 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1104 | description='API.POINT_NOT_FOUND') |
|
1105 | ||
1106 | cursor.execute(" SELECT id " |
|
1107 | " FROM tbl_stores_points " |
|
1108 | " WHERE store_id = %s AND point_id = %s ", (id_, pid)) |
|
1109 | if cursor.fetchone() is None: |
|
1110 | cursor.close() |
|
1111 | cnx.disconnect() |
|
1112 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1113 | description='API.STORE_POINT_RELATION_NOT_FOUND') |
|
1114 | ||
1115 | cursor.execute(" DELETE FROM tbl_stores_points " |
|
1116 | " WHERE store_id = %s AND point_id = %s ", (id_, pid)) |
|
1117 | cnx.commit() |
|
1118 | ||
1119 | cursor.close() |
|
1120 | cnx.disconnect() |
|
1121 | ||
1122 | resp.status = falcon.HTTP_204 |
|
1123 | ||
1124 | ||
1125 | class StoreSensorCollection: |
|
@@ 888-944 (lines=57) @@ | ||
885 | resp.location = '/stores/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
886 | ||
887 | ||
888 | class StoreOfflineMeterItem: |
|
889 | @staticmethod |
|
890 | def __init__(): |
|
891 | pass |
|
892 | ||
893 | @staticmethod |
|
894 | def on_options(req, resp, id_, mid): |
|
895 | resp.status = falcon.HTTP_200 |
|
896 | ||
897 | @staticmethod |
|
898 | def on_delete(req, resp, id_, mid): |
|
899 | if not id_.isdigit() or int(id_) <= 0: |
|
900 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
901 | description='API.INVALID_STORE_ID') |
|
902 | ||
903 | if not mid.isdigit() or int(mid) <= 0: |
|
904 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
905 | description='API.INVALID_OFFLINE_METER_ID') |
|
906 | ||
907 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
908 | cursor = cnx.cursor() |
|
909 | ||
910 | cursor.execute(" SELECT name " |
|
911 | " FROM tbl_stores " |
|
912 | " WHERE id = %s ", (id_,)) |
|
913 | if cursor.fetchone() is None: |
|
914 | cursor.close() |
|
915 | cnx.disconnect() |
|
916 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
917 | description='API.STORE_NOT_FOUND') |
|
918 | ||
919 | cursor.execute(" SELECT name " |
|
920 | " FROM tbl_offline_meters " |
|
921 | " WHERE id = %s ", (mid,)) |
|
922 | if cursor.fetchone() is None: |
|
923 | cursor.close() |
|
924 | cnx.disconnect() |
|
925 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
926 | description='API.OFFLINE_METER_NOT_FOUND') |
|
927 | ||
928 | cursor.execute(" SELECT id " |
|
929 | " FROM tbl_stores_offline_meters " |
|
930 | " WHERE store_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
931 | if cursor.fetchone() is None: |
|
932 | cursor.close() |
|
933 | cnx.disconnect() |
|
934 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
935 | description='API.STORE_OFFLINE_METER_RELATION_NOT_FOUND') |
|
936 | ||
937 | cursor.execute(" DELETE FROM tbl_stores_offline_meters " |
|
938 | " WHERE store_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
939 | cnx.commit() |
|
940 | ||
941 | cursor.close() |
|
942 | cnx.disconnect() |
|
943 | ||
944 | resp.status = falcon.HTTP_204 |
|
945 | ||
946 | ||
947 | class StorePointCollection: |
|
@@ 1231-1286 (lines=56) @@ | ||
1228 | resp.location = '/stores/' + str(id_) + '/sensors/' + str(sensor_id) |
|
1229 | ||
1230 | ||
1231 | class StoreSensorItem: |
|
1232 | @staticmethod |
|
1233 | def __init__(): |
|
1234 | pass |
|
1235 | ||
1236 | @staticmethod |
|
1237 | def on_options(req, resp, id_, sid): |
|
1238 | resp.status = falcon.HTTP_200 |
|
1239 | ||
1240 | @staticmethod |
|
1241 | def on_delete(req, resp, id_, sid): |
|
1242 | if not id_.isdigit() or int(id_) <= 0: |
|
1243 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1244 | description='API.INVALID_STORE_ID') |
|
1245 | ||
1246 | if not sid.isdigit() or int(sid) <= 0: |
|
1247 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
1248 | description='API.INVALID_SENSOR_ID') |
|
1249 | ||
1250 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
1251 | cursor = cnx.cursor() |
|
1252 | ||
1253 | cursor.execute(" SELECT name " |
|
1254 | " FROM tbl_stores " |
|
1255 | " WHERE id = %s ", (id_,)) |
|
1256 | if cursor.fetchone() is None: |
|
1257 | cursor.close() |
|
1258 | cnx.disconnect() |
|
1259 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1260 | description='API.STORE_NOT_FOUND') |
|
1261 | ||
1262 | cursor.execute(" SELECT name " |
|
1263 | " FROM tbl_sensors " |
|
1264 | " WHERE id = %s ", (sid,)) |
|
1265 | if cursor.fetchone() is None: |
|
1266 | cursor.close() |
|
1267 | cnx.disconnect() |
|
1268 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1269 | description='API.SENSOR_NOT_FOUND') |
|
1270 | ||
1271 | cursor.execute(" SELECT id " |
|
1272 | " FROM tbl_stores_sensors " |
|
1273 | " WHERE store_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1274 | if cursor.fetchone() is None: |
|
1275 | cursor.close() |
|
1276 | cnx.disconnect() |
|
1277 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
1278 | description='API.STORE_SENSOR_RELATION_NOT_FOUND') |
|
1279 | ||
1280 | cursor.execute(" DELETE FROM tbl_stores_sensors WHERE store_id = %s AND sensor_id = %s ", (id_, sid)) |
|
1281 | cnx.commit() |
|
1282 | ||
1283 | cursor.close() |
|
1284 | cnx.disconnect() |
|
1285 | ||
1286 | resp.status = falcon.HTTP_204 |
|
1287 | ||
1288 | ||
1289 | class StoreVirtualMeterCollection: |
|
@@ 710-765 (lines=56) @@ | ||
707 | resp.location = '/stores/' + str(id_) + '/meters/' + str(meter_id) |
|
708 | ||
709 | ||
710 | class StoreMeterItem: |
|
711 | @staticmethod |
|
712 | def __init__(): |
|
713 | pass |
|
714 | ||
715 | @staticmethod |
|
716 | def on_options(req, resp, id_, mid): |
|
717 | resp.status = falcon.HTTP_200 |
|
718 | ||
719 | @staticmethod |
|
720 | def on_delete(req, resp, id_, mid): |
|
721 | if not id_.isdigit() or int(id_) <= 0: |
|
722 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
723 | description='API.INVALID_STORE_ID') |
|
724 | ||
725 | if not mid.isdigit() or int(mid) <= 0: |
|
726 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
727 | description='API.INVALID_METER_ID') |
|
728 | ||
729 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
730 | cursor = cnx.cursor() |
|
731 | ||
732 | cursor.execute(" SELECT name " |
|
733 | " FROM tbl_stores " |
|
734 | " WHERE id = %s ", (id_,)) |
|
735 | if cursor.fetchone() is None: |
|
736 | cursor.close() |
|
737 | cnx.disconnect() |
|
738 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
739 | description='API.STORE_NOT_FOUND') |
|
740 | ||
741 | cursor.execute(" SELECT name " |
|
742 | " FROM tbl_meters " |
|
743 | " WHERE id = %s ", (mid,)) |
|
744 | if cursor.fetchone() is None: |
|
745 | cursor.close() |
|
746 | cnx.disconnect() |
|
747 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
748 | description='API.METER_NOT_FOUND') |
|
749 | ||
750 | cursor.execute(" SELECT id " |
|
751 | " FROM tbl_stores_meters " |
|
752 | " WHERE store_id = %s AND meter_id = %s ", (id_, mid)) |
|
753 | if cursor.fetchone() is None: |
|
754 | cursor.close() |
|
755 | cnx.disconnect() |
|
756 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
757 | description='API.STORE_METER_RELATION_NOT_FOUND') |
|
758 | ||
759 | cursor.execute(" DELETE FROM tbl_stores_meters WHERE store_id = %s AND meter_id = %s ", (id_, mid)) |
|
760 | cnx.commit() |
|
761 | ||
762 | cursor.close() |
|
763 | cnx.disconnect() |
|
764 | ||
765 | resp.status = falcon.HTTP_204 |
|
766 | ||
767 | ||
768 | class StoreOfflineMeterCollection: |
@@ 489-545 (lines=57) @@ | ||
486 | resp.location = '/distributioncircuits/' + str(id_) + '/points/' + str(new_values['data']['point_id']) |
|
487 | ||
488 | ||
489 | class DistributionCircuitPointItem: |
|
490 | @staticmethod |
|
491 | def __init__(): |
|
492 | pass |
|
493 | ||
494 | @staticmethod |
|
495 | def on_options(req, resp, id_, pid): |
|
496 | resp.status = falcon.HTTP_200 |
|
497 | ||
498 | @staticmethod |
|
499 | def on_delete(req, resp, id_, pid): |
|
500 | if not id_.isdigit() or int(id_) <= 0: |
|
501 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
502 | description='API.INVALID_DISTRIBUTION_CIRCUIT_ID') |
|
503 | ||
504 | if not pid.isdigit() or int(pid) <= 0: |
|
505 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
506 | description='API.INVALID_POINT_ID') |
|
507 | ||
508 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
509 | cursor = cnx.cursor() |
|
510 | ||
511 | cursor.execute(" SELECT name " |
|
512 | " FROM tbl_distribution_circuits " |
|
513 | " WHERE id = %s ", (id_,)) |
|
514 | if cursor.fetchone() is None: |
|
515 | cursor.close() |
|
516 | cnx.disconnect() |
|
517 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
518 | description='API.DISTRIBUTION_CIRCUIT_NOT_FOUND') |
|
519 | ||
520 | cursor.execute(" SELECT name " |
|
521 | " FROM tbl_points " |
|
522 | " WHERE id = %s ", (pid,)) |
|
523 | if cursor.fetchone() is None: |
|
524 | cursor.close() |
|
525 | cnx.disconnect() |
|
526 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
527 | description='API.POINT_NOT_FOUND') |
|
528 | ||
529 | cursor.execute(" SELECT id " |
|
530 | " FROM tbl_distribution_circuits_points " |
|
531 | " WHERE distribution_circuit_id = %s AND point_id = %s ", (id_, pid)) |
|
532 | if cursor.fetchone() is None: |
|
533 | cursor.close() |
|
534 | cnx.disconnect() |
|
535 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
536 | description='API.DISTRIBUTION_CIRCUIT_POINT_RELATION_NOT_FOUND') |
|
537 | ||
538 | cursor.execute(" DELETE FROM tbl_distribution_circuits_points " |
|
539 | " WHERE distribution_circuit_id = %s AND point_id = %s ", (id_, pid)) |
|
540 | cnx.commit() |
|
541 | ||
542 | cursor.close() |
|
543 | cnx.disconnect() |
|
544 | ||
545 | resp.status = falcon.HTTP_204 |
|
546 | ||
547 |
@@ 460-516 (lines=57) @@ | ||
457 | resp.location = '/costcenters/' + str(id_) + '/tariffs/' + str(new_values['data']['tariff_id']) |
|
458 | ||
459 | ||
460 | class CostCenterTariffItem: |
|
461 | @staticmethod |
|
462 | def __init__(): |
|
463 | pass |
|
464 | ||
465 | @staticmethod |
|
466 | def on_options(req, resp, id_, tid): |
|
467 | resp.status = falcon.HTTP_200 |
|
468 | ||
469 | @staticmethod |
|
470 | def on_delete(req, resp, id_, tid): |
|
471 | if not id_.isdigit() or int(id_) <= 0: |
|
472 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
473 | description='API.INVALID_COST_CENTER_ID') |
|
474 | ||
475 | if not tid.isdigit() or int(tid) <= 0: |
|
476 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
477 | description='API.INVALID_TARIFF_ID') |
|
478 | ||
479 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
480 | cursor = cnx.cursor() |
|
481 | ||
482 | cursor.execute(" SELECT name " |
|
483 | " FROM tbl_cost_centers " |
|
484 | " WHERE id = %s ", (id_,)) |
|
485 | if cursor.fetchone() is None: |
|
486 | cursor.close() |
|
487 | cnx.disconnect() |
|
488 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
489 | description='API.COST_CENTER_NOT_FOUND') |
|
490 | ||
491 | cursor.execute(" SELECT name " |
|
492 | " FROM tbl_tariffs " |
|
493 | " WHERE id = %s ", (tid,)) |
|
494 | if cursor.fetchone() is None: |
|
495 | cursor.close() |
|
496 | cnx.disconnect() |
|
497 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
498 | description='API.TARIFF_NOT_FOUND') |
|
499 | ||
500 | cursor.execute(" SELECT id " |
|
501 | " FROM tbl_cost_centers_tariffs " |
|
502 | " WHERE cost_center_id = %s AND tariff_id = %s ", (id_, tid)) |
|
503 | if cursor.fetchone() is None: |
|
504 | cursor.close() |
|
505 | cnx.disconnect() |
|
506 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
507 | description='API.TARIFF_IS_NOT_ASSOCIATED_WITH_COST_CENTER') |
|
508 | ||
509 | cursor.execute(" DELETE FROM tbl_cost_centers_tariffs " |
|
510 | " WHERE cost_center_id = %s AND tariff_id = %s ", (id_, tid)) |
|
511 | cnx.commit() |
|
512 | ||
513 | cursor.close() |
|
514 | cnx.disconnect() |
|
515 | ||
516 | resp.status = falcon.HTTP_204 |
|
517 |
@@ 945-1000 (lines=56) @@ | ||
942 | resp.location = '/meters/' + str(id_) + '/points/' + str(new_values['data']['point_id']) |
|
943 | ||
944 | ||
945 | class MeterPointItem: |
|
946 | @staticmethod |
|
947 | def __init__(): |
|
948 | pass |
|
949 | ||
950 | @staticmethod |
|
951 | def on_options(req, resp, id_, pid): |
|
952 | resp.status = falcon.HTTP_200 |
|
953 | ||
954 | @staticmethod |
|
955 | def on_delete(req, resp, id_, pid): |
|
956 | if not id_.isdigit() or int(id_) <= 0: |
|
957 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
958 | description='API.INVALID_METER_ID') |
|
959 | ||
960 | if not pid.isdigit() or int(pid) <= 0: |
|
961 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
962 | description='API.INVALID_POINT_ID') |
|
963 | ||
964 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
965 | cursor = cnx.cursor() |
|
966 | ||
967 | cursor.execute(" SELECT name " |
|
968 | " FROM tbl_meters " |
|
969 | " WHERE id = %s ", (id_,)) |
|
970 | if cursor.fetchone() is None: |
|
971 | cursor.close() |
|
972 | cnx.disconnect() |
|
973 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
974 | description='API.METER_NOT_FOUND') |
|
975 | ||
976 | cursor.execute(" SELECT name " |
|
977 | " FROM tbl_points " |
|
978 | " WHERE id = %s ", (pid,)) |
|
979 | if cursor.fetchone() is None: |
|
980 | cursor.close() |
|
981 | cnx.disconnect() |
|
982 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
983 | description='API.POINT_NOT_FOUND') |
|
984 | ||
985 | cursor.execute(" SELECT id " |
|
986 | " FROM tbl_meters_points " |
|
987 | " WHERE meter_id = %s AND point_id = %s ", (id_, pid)) |
|
988 | if cursor.fetchone() is None: |
|
989 | cursor.close() |
|
990 | cnx.disconnect() |
|
991 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
992 | description='API.METER_POINT_RELATION_NOT_FOUND') |
|
993 | ||
994 | cursor.execute(" DELETE FROM tbl_meters_points WHERE meter_id = %s AND point_id = %s ", (id_, pid)) |
|
995 | cnx.commit() |
|
996 | ||
997 | cursor.close() |
|
998 | cnx.disconnect() |
|
999 | ||
1000 | resp.status = falcon.HTTP_204 |
|
1001 | ||
1002 |
@@ 369-424 (lines=56) @@ | ||
366 | resp.location = '/sensors/' + str(id_) + '/points/' + str(new_values['data']['point_id']) |
|
367 | ||
368 | ||
369 | class SensorPointItem: |
|
370 | @staticmethod |
|
371 | def __init__(): |
|
372 | pass |
|
373 | ||
374 | @staticmethod |
|
375 | def on_options(req, resp, id_, pid): |
|
376 | resp.status = falcon.HTTP_200 |
|
377 | ||
378 | @staticmethod |
|
379 | def on_delete(req, resp, id_, pid): |
|
380 | if not id_.isdigit() or int(id_) <= 0: |
|
381 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
382 | description='API.INVALID_SENSOR_ID') |
|
383 | ||
384 | if not pid.isdigit() or int(pid) <= 0: |
|
385 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
386 | description='API.INVALID_POINT_ID') |
|
387 | ||
388 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
389 | cursor = cnx.cursor() |
|
390 | ||
391 | cursor.execute(" SELECT name " |
|
392 | " FROM tbl_sensors " |
|
393 | " WHERE id = %s ", (id_,)) |
|
394 | if cursor.fetchone() is None: |
|
395 | cursor.close() |
|
396 | cnx.disconnect() |
|
397 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
398 | description='API.SENSOR_NOT_FOUND') |
|
399 | ||
400 | cursor.execute(" SELECT name " |
|
401 | " FROM tbl_points " |
|
402 | " WHERE id = %s ", (pid,)) |
|
403 | if cursor.fetchone() is None: |
|
404 | cursor.close() |
|
405 | cnx.disconnect() |
|
406 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
407 | description='API.POINT_NOT_FOUND') |
|
408 | ||
409 | cursor.execute(" SELECT id " |
|
410 | " FROM tbl_sensors_points " |
|
411 | " WHERE sensor_id = %s AND point_id = %s ", (id_, pid)) |
|
412 | if cursor.fetchone() is None: |
|
413 | cursor.close() |
|
414 | cnx.disconnect() |
|
415 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
416 | description='API.SENSOR_POINT_RELATION_NOT_FOUND') |
|
417 | ||
418 | cursor.execute(" DELETE FROM tbl_sensors_points WHERE sensor_id = %s AND point_id = %s ", (id_, pid)) |
|
419 | cnx.commit() |
|
420 | ||
421 | cursor.close() |
|
422 | cnx.disconnect() |
|
423 | ||
424 | resp.status = falcon.HTTP_204 |
|
425 | ||
426 |