| @@ 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 | ||
| @@ 2450-2506 (lines=57) @@ | ||
| 2447 | resp.location = '/spaces/' + str(id_) + '/virtualmeters/' + str(virtual_meter_id) |
|
| 2448 | ||
| 2449 | ||
| 2450 | class SpaceVirtualMeterItem: |
|
| 2451 | @staticmethod |
|
| 2452 | def __init__(): |
|
| 2453 | pass |
|
| 2454 | ||
| 2455 | @staticmethod |
|
| 2456 | def on_options(req, resp, id_, mid): |
|
| 2457 | resp.status = falcon.HTTP_200 |
|
| 2458 | ||
| 2459 | @staticmethod |
|
| 2460 | def on_delete(req, resp, id_, mid): |
|
| 2461 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2462 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2463 | description='API.INVALID_SPACE_ID') |
|
| 2464 | ||
| 2465 | if not mid.isdigit() or int(mid) <= 0: |
|
| 2466 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2467 | description='API.INVALID_VIRTUAL_METER_ID') |
|
| 2468 | ||
| 2469 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2470 | cursor = cnx.cursor() |
|
| 2471 | ||
| 2472 | cursor.execute(" SELECT name " |
|
| 2473 | " FROM tbl_spaces " |
|
| 2474 | " WHERE id = %s ", (id_,)) |
|
| 2475 | if cursor.fetchone() is None: |
|
| 2476 | cursor.close() |
|
| 2477 | cnx.disconnect() |
|
| 2478 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2479 | description='API.SPACE_NOT_FOUND') |
|
| 2480 | ||
| 2481 | cursor.execute(" SELECT name " |
|
| 2482 | " FROM tbl_virtual_meters " |
|
| 2483 | " WHERE id = %s ", (mid,)) |
|
| 2484 | if cursor.fetchone() is None: |
|
| 2485 | cursor.close() |
|
| 2486 | cnx.disconnect() |
|
| 2487 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2488 | description='API.VIRTUAL_METER_NOT_FOUND') |
|
| 2489 | ||
| 2490 | cursor.execute(" SELECT id " |
|
| 2491 | " FROM tbl_spaces_virtual_meters " |
|
| 2492 | " WHERE space_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
| 2493 | if cursor.fetchone() is None: |
|
| 2494 | cursor.close() |
|
| 2495 | cnx.disconnect() |
|
| 2496 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2497 | description='API.SPACE_VIRTUAL_METER_RELATION_NOT_FOUND') |
|
| 2498 | ||
| 2499 | cursor.execute(" DELETE FROM tbl_spaces_virtual_meters " |
|
| 2500 | " WHERE space_id = %s AND virtual_meter_id = %s ", (id_, mid)) |
|
| 2501 | cnx.commit() |
|
| 2502 | ||
| 2503 | cursor.close() |
|
| 2504 | cnx.disconnect() |
|
| 2505 | ||
| 2506 | resp.status = falcon.HTTP_204 |
|
| 2507 | ||
| 2508 | ||
| 2509 | class SpaceTreeCollection: |
|
| @@ 1615-1671 (lines=57) @@ | ||
| 1612 | resp.location = '/spaces/' + str(id_) + '/points/' + str(point_id) |
|
| 1613 | ||
| 1614 | ||
| 1615 | class SpacePointItem: |
|
| 1616 | @staticmethod |
|
| 1617 | def __init__(): |
|
| 1618 | pass |
|
| 1619 | ||
| 1620 | @staticmethod |
|
| 1621 | def on_options(req, resp, id_, pid): |
|
| 1622 | resp.status = falcon.HTTP_200 |
|
| 1623 | ||
| 1624 | @staticmethod |
|
| 1625 | def on_delete(req, resp, id_, pid): |
|
| 1626 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1627 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1628 | description='API.INVALID_SPACE_ID') |
|
| 1629 | ||
| 1630 | if not pid.isdigit() or int(pid) <= 0: |
|
| 1631 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1632 | description='API.INVALID_POINT_ID') |
|
| 1633 | ||
| 1634 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1635 | cursor = cnx.cursor() |
|
| 1636 | ||
| 1637 | cursor.execute(" SELECT name " |
|
| 1638 | " FROM tbl_spaces " |
|
| 1639 | " WHERE id = %s ", (id_,)) |
|
| 1640 | if cursor.fetchone() is None: |
|
| 1641 | cursor.close() |
|
| 1642 | cnx.disconnect() |
|
| 1643 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1644 | description='API.SPACE_NOT_FOUND') |
|
| 1645 | ||
| 1646 | cursor.execute(" SELECT name " |
|
| 1647 | " FROM tbl_points " |
|
| 1648 | " WHERE id = %s ", (pid,)) |
|
| 1649 | if cursor.fetchone() is None: |
|
| 1650 | cursor.close() |
|
| 1651 | cnx.disconnect() |
|
| 1652 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1653 | description='API.POINT_NOT_FOUND') |
|
| 1654 | ||
| 1655 | cursor.execute(" SELECT id " |
|
| 1656 | " FROM tbl_spaces_points " |
|
| 1657 | " WHERE space_id = %s AND point_id = %s ", (id_, pid)) |
|
| 1658 | if cursor.fetchone() is None: |
|
| 1659 | cursor.close() |
|
| 1660 | cnx.disconnect() |
|
| 1661 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1662 | description='API.SPACE_POINT_RELATION_NOT_FOUND') |
|
| 1663 | ||
| 1664 | cursor.execute(" DELETE FROM tbl_spaces_points " |
|
| 1665 | " WHERE space_id = %s AND point_id = %s ", (id_, pid)) |
|
| 1666 | cnx.commit() |
|
| 1667 | ||
| 1668 | cursor.close() |
|
| 1669 | cnx.disconnect() |
|
| 1670 | ||
| 1671 | resp.status = falcon.HTTP_204 |
|
| 1672 | ||
| 1673 | ||
| 1674 | class SpaceSensorCollection: |
|
| @@ 1437-1493 (lines=57) @@ | ||
| 1434 | resp.location = '/spaces/' + str(id_) + '/offlinemeters/' + str(offline_meter_id) |
|
| 1435 | ||
| 1436 | ||
| 1437 | class SpaceOfflineMeterItem: |
|
| 1438 | @staticmethod |
|
| 1439 | def __init__(): |
|
| 1440 | pass |
|
| 1441 | ||
| 1442 | @staticmethod |
|
| 1443 | def on_options(req, resp, id_, mid): |
|
| 1444 | resp.status = falcon.HTTP_200 |
|
| 1445 | ||
| 1446 | @staticmethod |
|
| 1447 | def on_delete(req, resp, id_, mid): |
|
| 1448 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1449 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1450 | description='API.INVALID_SPACE_ID') |
|
| 1451 | ||
| 1452 | if not mid.isdigit() or int(mid) <= 0: |
|
| 1453 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1454 | description='API.INVALID_OFFLINE_METER_ID') |
|
| 1455 | ||
| 1456 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1457 | cursor = cnx.cursor() |
|
| 1458 | ||
| 1459 | cursor.execute(" SELECT name " |
|
| 1460 | " FROM tbl_spaces " |
|
| 1461 | " WHERE id = %s ", (id_,)) |
|
| 1462 | if cursor.fetchone() is None: |
|
| 1463 | cursor.close() |
|
| 1464 | cnx.disconnect() |
|
| 1465 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1466 | description='API.SPACE_NOT_FOUND') |
|
| 1467 | ||
| 1468 | cursor.execute(" SELECT name " |
|
| 1469 | " FROM tbl_offline_meters " |
|
| 1470 | " WHERE id = %s ", (mid,)) |
|
| 1471 | if cursor.fetchone() is None: |
|
| 1472 | cursor.close() |
|
| 1473 | cnx.disconnect() |
|
| 1474 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1475 | description='API.OFFLINE_METER_NOT_FOUND') |
|
| 1476 | ||
| 1477 | cursor.execute(" SELECT id " |
|
| 1478 | " FROM tbl_spaces_offline_meters " |
|
| 1479 | " WHERE space_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
| 1480 | if cursor.fetchone() is None: |
|
| 1481 | cursor.close() |
|
| 1482 | cnx.disconnect() |
|
| 1483 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1484 | description='API.SPACE_OFFLINE_METER_RELATION_NOT_FOUND') |
|
| 1485 | ||
| 1486 | cursor.execute(" DELETE FROM tbl_spaces_offline_meters " |
|
| 1487 | " WHERE space_id = %s AND offline_meter_id = %s ", (id_, mid)) |
|
| 1488 | cnx.commit() |
|
| 1489 | ||
| 1490 | cursor.close() |
|
| 1491 | cnx.disconnect() |
|
| 1492 | ||
| 1493 | resp.status = falcon.HTTP_204 |
|
| 1494 | ||
| 1495 | ||
| 1496 | class SpacePointCollection: |
|
| @@ 916-972 (lines=57) @@ | ||
| 913 | resp.location = '/spaces/' + str(id_) + '/combinedequipments/' + str(combined_equipment_id) |
|
| 914 | ||
| 915 | ||
| 916 | class SpaceCombinedEquipmentItem: |
|
| 917 | @staticmethod |
|
| 918 | def __init__(): |
|
| 919 | pass |
|
| 920 | ||
| 921 | @staticmethod |
|
| 922 | def on_options(req, resp, id_, eid): |
|
| 923 | resp.status = falcon.HTTP_200 |
|
| 924 | ||
| 925 | @staticmethod |
|
| 926 | def on_delete(req, resp, id_, eid): |
|
| 927 | if not id_.isdigit() or int(id_) <= 0: |
|
| 928 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 929 | description='API.INVALID_SPACE_ID') |
|
| 930 | ||
| 931 | if not eid.isdigit() or int(eid) <= 0: |
|
| 932 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 933 | description='API.INVALID_COMBINED_EQUIPMENT_ID') |
|
| 934 | ||
| 935 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 936 | cursor = cnx.cursor() |
|
| 937 | ||
| 938 | cursor.execute(" SELECT name " |
|
| 939 | " FROM tbl_spaces " |
|
| 940 | " WHERE id = %s ", (id_,)) |
|
| 941 | if cursor.fetchone() is None: |
|
| 942 | cursor.close() |
|
| 943 | cnx.disconnect() |
|
| 944 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 945 | description='API.SPACE_NOT_FOUND') |
|
| 946 | ||
| 947 | cursor.execute(" SELECT name " |
|
| 948 | " FROM tbl_combined_equipments " |
|
| 949 | " WHERE id = %s ", (eid,)) |
|
| 950 | if cursor.fetchone() is None: |
|
| 951 | cursor.close() |
|
| 952 | cnx.disconnect() |
|
| 953 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 954 | description='API.COMBINED_EQUIPMENT_NOT_FOUND') |
|
| 955 | ||
| 956 | cursor.execute(" SELECT id " |
|
| 957 | " FROM tbl_spaces_combined_equipments " |
|
| 958 | " WHERE space_id = %s AND combined_equipment_id = %s ", (id_, eid)) |
|
| 959 | if cursor.fetchone() is None: |
|
| 960 | cursor.close() |
|
| 961 | cnx.disconnect() |
|
| 962 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 963 | description='API.SPACE_COMBINED_EQUIPMENT_RELATION_NOT_FOUND') |
|
| 964 | ||
| 965 | cursor.execute(" DELETE FROM tbl_spaces_combined_equipments " |
|
| 966 | " WHERE space_id = %s AND combined_equipment_id = %s ", (id_, eid)) |
|
| 967 | cnx.commit() |
|
| 968 | ||
| 969 | cursor.close() |
|
| 970 | cnx.disconnect() |
|
| 971 | ||
| 972 | resp.status = falcon.HTTP_204 |
|
| 973 | ||
| 974 | ||
| 975 | class SpaceEquipmentCollection: |
|
| @@ 2272-2327 (lines=56) @@ | ||
| 2269 | resp.location = '/spaces/' + str(id_) + '/tenants/' + str(tenant_id) |
|
| 2270 | ||
| 2271 | ||
| 2272 | class SpaceTenantItem: |
|
| 2273 | @staticmethod |
|
| 2274 | def __init__(): |
|
| 2275 | pass |
|
| 2276 | ||
| 2277 | @staticmethod |
|
| 2278 | def on_options(req, resp, id_, tid): |
|
| 2279 | resp.status = falcon.HTTP_200 |
|
| 2280 | ||
| 2281 | @staticmethod |
|
| 2282 | def on_delete(req, resp, id_, tid): |
|
| 2283 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2284 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2285 | description='API.INVALID_SPACE_ID') |
|
| 2286 | ||
| 2287 | if not tid.isdigit() or int(tid) <= 0: |
|
| 2288 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2289 | description='API.INVALID_TENANT_ID') |
|
| 2290 | ||
| 2291 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2292 | cursor = cnx.cursor() |
|
| 2293 | ||
| 2294 | cursor.execute(" SELECT name " |
|
| 2295 | " FROM tbl_spaces " |
|
| 2296 | " WHERE id = %s ", (id_,)) |
|
| 2297 | if cursor.fetchone() is None: |
|
| 2298 | cursor.close() |
|
| 2299 | cnx.disconnect() |
|
| 2300 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2301 | description='API.SPACE_NOT_FOUND') |
|
| 2302 | ||
| 2303 | cursor.execute(" SELECT name " |
|
| 2304 | " FROM tbl_tenants " |
|
| 2305 | " WHERE id = %s ", (tid,)) |
|
| 2306 | if cursor.fetchone() is None: |
|
| 2307 | cursor.close() |
|
| 2308 | cnx.disconnect() |
|
| 2309 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2310 | description='API.TENANT_NOT_FOUND') |
|
| 2311 | ||
| 2312 | cursor.execute(" SELECT id " |
|
| 2313 | " FROM tbl_spaces_tenants " |
|
| 2314 | " WHERE space_id = %s AND tenant_id = %s ", (id_, tid)) |
|
| 2315 | if cursor.fetchone() is None: |
|
| 2316 | cursor.close() |
|
| 2317 | cnx.disconnect() |
|
| 2318 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2319 | description='API.SPACE_TENANT_RELATION_NOT_FOUND') |
|
| 2320 | ||
| 2321 | cursor.execute(" DELETE FROM tbl_spaces_tenants WHERE space_id = %s AND tenant_id = %s ", (id_, tid)) |
|
| 2322 | cnx.commit() |
|
| 2323 | ||
| 2324 | cursor.close() |
|
| 2325 | cnx.disconnect() |
|
| 2326 | ||
| 2327 | resp.status = falcon.HTTP_204 |
|
| 2328 | ||
| 2329 | ||
| 2330 | class SpaceVirtualMeterCollection: |
|
| @@ 2108-2163 (lines=56) @@ | ||
| 2105 | resp.location = '/spaces/' + str(id_) + '/stores/' + str(store_id) |
|
| 2106 | ||
| 2107 | ||
| 2108 | class SpaceStoreItem: |
|
| 2109 | @staticmethod |
|
| 2110 | def __init__(): |
|
| 2111 | pass |
|
| 2112 | ||
| 2113 | @staticmethod |
|
| 2114 | def on_options(req, resp, id_, tid): |
|
| 2115 | resp.status = falcon.HTTP_200 |
|
| 2116 | ||
| 2117 | @staticmethod |
|
| 2118 | def on_delete(req, resp, id_, tid): |
|
| 2119 | if not id_.isdigit() or int(id_) <= 0: |
|
| 2120 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2121 | description='API.INVALID_SPACE_ID') |
|
| 2122 | ||
| 2123 | if not tid.isdigit() or int(tid) <= 0: |
|
| 2124 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 2125 | description='API.INVALID_STORE_ID') |
|
| 2126 | ||
| 2127 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 2128 | cursor = cnx.cursor() |
|
| 2129 | ||
| 2130 | cursor.execute(" SELECT name " |
|
| 2131 | " FROM tbl_spaces " |
|
| 2132 | " WHERE id = %s ", (id_,)) |
|
| 2133 | if cursor.fetchone() is None: |
|
| 2134 | cursor.close() |
|
| 2135 | cnx.disconnect() |
|
| 2136 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2137 | description='API.SPACE_NOT_FOUND') |
|
| 2138 | ||
| 2139 | cursor.execute(" SELECT name " |
|
| 2140 | " FROM tbl_stores " |
|
| 2141 | " WHERE id = %s ", (tid,)) |
|
| 2142 | if cursor.fetchone() is None: |
|
| 2143 | cursor.close() |
|
| 2144 | cnx.disconnect() |
|
| 2145 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2146 | description='API.STORE_NOT_FOUND') |
|
| 2147 | ||
| 2148 | cursor.execute(" SELECT id " |
|
| 2149 | " FROM tbl_spaces_stores " |
|
| 2150 | " WHERE space_id = %s AND store_id = %s ", (id_, tid)) |
|
| 2151 | if cursor.fetchone() is None: |
|
| 2152 | cursor.close() |
|
| 2153 | cnx.disconnect() |
|
| 2154 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 2155 | description='API.SPACE_STORE_RELATION_NOT_FOUND') |
|
| 2156 | ||
| 2157 | cursor.execute(" DELETE FROM tbl_spaces_stores WHERE space_id = %s AND store_id = %s ", (id_, tid)) |
|
| 2158 | cnx.commit() |
|
| 2159 | ||
| 2160 | cursor.close() |
|
| 2161 | cnx.disconnect() |
|
| 2162 | ||
| 2163 | resp.status = falcon.HTTP_204 |
|
| 2164 | ||
| 2165 | ||
| 2166 | class SpaceTenantCollection: |
|
| @@ 1944-1999 (lines=56) @@ | ||
| 1941 | resp.location = '/spaces/' + str(id_) + '/shopfloors/' + str(shopfloor_id) |
|
| 1942 | ||
| 1943 | ||
| 1944 | class SpaceShopfloorItem: |
|
| 1945 | @staticmethod |
|
| 1946 | def __init__(): |
|
| 1947 | pass |
|
| 1948 | ||
| 1949 | @staticmethod |
|
| 1950 | def on_options(req, resp, id_, sid): |
|
| 1951 | resp.status = falcon.HTTP_200 |
|
| 1952 | ||
| 1953 | @staticmethod |
|
| 1954 | def on_delete(req, resp, id_, sid): |
|
| 1955 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1956 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1957 | description='API.INVALID_SPACE_ID') |
|
| 1958 | ||
| 1959 | if not sid.isdigit() or int(sid) <= 0: |
|
| 1960 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1961 | description='API.INVALID_SHOPFLOOR_ID') |
|
| 1962 | ||
| 1963 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1964 | cursor = cnx.cursor() |
|
| 1965 | ||
| 1966 | cursor.execute(" SELECT name " |
|
| 1967 | " FROM tbl_spaces " |
|
| 1968 | " WHERE id = %s ", (id_,)) |
|
| 1969 | if cursor.fetchone() is None: |
|
| 1970 | cursor.close() |
|
| 1971 | cnx.disconnect() |
|
| 1972 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1973 | description='API.SPACE_NOT_FOUND') |
|
| 1974 | ||
| 1975 | cursor.execute(" SELECT name " |
|
| 1976 | " FROM tbl_shopfloors " |
|
| 1977 | " WHERE id = %s ", (sid,)) |
|
| 1978 | if cursor.fetchone() is None: |
|
| 1979 | cursor.close() |
|
| 1980 | cnx.disconnect() |
|
| 1981 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1982 | description='API.SHOPFLOOR_NOT_FOUND') |
|
| 1983 | ||
| 1984 | cursor.execute(" SELECT id " |
|
| 1985 | " FROM tbl_spaces_shopfloors " |
|
| 1986 | " WHERE space_id = %s AND shopfloor_id = %s ", (id_, sid)) |
|
| 1987 | if cursor.fetchone() is None: |
|
| 1988 | cursor.close() |
|
| 1989 | cnx.disconnect() |
|
| 1990 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1991 | description='API.SPACE_SHOPFLOOR_RELATION_NOT_FOUND') |
|
| 1992 | ||
| 1993 | cursor.execute(" DELETE FROM tbl_spaces_shopfloors WHERE space_id = %s AND shopfloor_id = %s ", (id_, sid)) |
|
| 1994 | cnx.commit() |
|
| 1995 | ||
| 1996 | cursor.close() |
|
| 1997 | cnx.disconnect() |
|
| 1998 | ||
| 1999 | resp.status = falcon.HTTP_204 |
|
| 2000 | ||
| 2001 | ||
| 2002 | class SpaceStoreCollection: |
|
| @@ 1780-1835 (lines=56) @@ | ||
| 1777 | resp.location = '/spaces/' + str(id_) + '/sensors/' + str(sensor_id) |
|
| 1778 | ||
| 1779 | ||
| 1780 | class SpaceSensorItem: |
|
| 1781 | @staticmethod |
|
| 1782 | def __init__(): |
|
| 1783 | pass |
|
| 1784 | ||
| 1785 | @staticmethod |
|
| 1786 | def on_options(req, resp, id_, sid): |
|
| 1787 | resp.status = falcon.HTTP_200 |
|
| 1788 | ||
| 1789 | @staticmethod |
|
| 1790 | def on_delete(req, resp, id_, sid): |
|
| 1791 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1792 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1793 | description='API.INVALID_SPACE_ID') |
|
| 1794 | ||
| 1795 | if not sid.isdigit() or int(sid) <= 0: |
|
| 1796 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1797 | description='API.INVALID_SENSOR_ID') |
|
| 1798 | ||
| 1799 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1800 | cursor = cnx.cursor() |
|
| 1801 | ||
| 1802 | cursor.execute(" SELECT name " |
|
| 1803 | " FROM tbl_spaces " |
|
| 1804 | " WHERE id = %s ", (id_,)) |
|
| 1805 | if cursor.fetchone() is None: |
|
| 1806 | cursor.close() |
|
| 1807 | cnx.disconnect() |
|
| 1808 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1809 | description='API.SPACE_NOT_FOUND') |
|
| 1810 | ||
| 1811 | cursor.execute(" SELECT name " |
|
| 1812 | " FROM tbl_sensors " |
|
| 1813 | " WHERE id = %s ", (sid,)) |
|
| 1814 | if cursor.fetchone() is None: |
|
| 1815 | cursor.close() |
|
| 1816 | cnx.disconnect() |
|
| 1817 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1818 | description='API.SENSOR_NOT_FOUND') |
|
| 1819 | ||
| 1820 | cursor.execute(" SELECT id " |
|
| 1821 | " FROM tbl_spaces_sensors " |
|
| 1822 | " WHERE space_id = %s AND sensor_id = %s ", (id_, sid)) |
|
| 1823 | if cursor.fetchone() is None: |
|
| 1824 | cursor.close() |
|
| 1825 | cnx.disconnect() |
|
| 1826 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1827 | description='API.SPACE_SENSOR_RELATION_NOT_FOUND') |
|
| 1828 | ||
| 1829 | cursor.execute(" DELETE FROM tbl_spaces_sensors WHERE space_id = %s AND sensor_id = %s ", (id_, sid)) |
|
| 1830 | cnx.commit() |
|
| 1831 | ||
| 1832 | cursor.close() |
|
| 1833 | cnx.disconnect() |
|
| 1834 | ||
| 1835 | resp.status = falcon.HTTP_204 |
|
| 1836 | ||
| 1837 | ||
| 1838 | class SpaceShopfloorCollection: |
|
| @@ 1259-1314 (lines=56) @@ | ||
| 1256 | resp.location = '/spaces/' + str(id_) + '/meters/' + str(meter_id) |
|
| 1257 | ||
| 1258 | ||
| 1259 | class SpaceMeterItem: |
|
| 1260 | @staticmethod |
|
| 1261 | def __init__(): |
|
| 1262 | pass |
|
| 1263 | ||
| 1264 | @staticmethod |
|
| 1265 | def on_options(req, resp, id_, mid): |
|
| 1266 | resp.status = falcon.HTTP_200 |
|
| 1267 | ||
| 1268 | @staticmethod |
|
| 1269 | def on_delete(req, resp, id_, mid): |
|
| 1270 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1271 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1272 | description='API.INVALID_SPACE_ID') |
|
| 1273 | ||
| 1274 | if not mid.isdigit() or int(mid) <= 0: |
|
| 1275 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1276 | description='API.INVALID_METER_ID') |
|
| 1277 | ||
| 1278 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1279 | cursor = cnx.cursor() |
|
| 1280 | ||
| 1281 | cursor.execute(" SELECT name " |
|
| 1282 | " FROM tbl_spaces " |
|
| 1283 | " WHERE id = %s ", (id_,)) |
|
| 1284 | if cursor.fetchone() is None: |
|
| 1285 | cursor.close() |
|
| 1286 | cnx.disconnect() |
|
| 1287 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1288 | description='API.SPACE_NOT_FOUND') |
|
| 1289 | ||
| 1290 | cursor.execute(" SELECT name " |
|
| 1291 | " FROM tbl_meters " |
|
| 1292 | " WHERE id = %s ", (mid,)) |
|
| 1293 | if cursor.fetchone() is None: |
|
| 1294 | cursor.close() |
|
| 1295 | cnx.disconnect() |
|
| 1296 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1297 | description='API.METER_NOT_FOUND') |
|
| 1298 | ||
| 1299 | cursor.execute(" SELECT id " |
|
| 1300 | " FROM tbl_spaces_meters " |
|
| 1301 | " WHERE space_id = %s AND meter_id = %s ", (id_, mid)) |
|
| 1302 | if cursor.fetchone() is None: |
|
| 1303 | cursor.close() |
|
| 1304 | cnx.disconnect() |
|
| 1305 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1306 | description='API.SPACE_METER_RELATION_NOT_FOUND') |
|
| 1307 | ||
| 1308 | cursor.execute(" DELETE FROM tbl_spaces_meters WHERE space_id = %s AND meter_id = %s ", (id_, mid)) |
|
| 1309 | cnx.commit() |
|
| 1310 | ||
| 1311 | cursor.close() |
|
| 1312 | cnx.disconnect() |
|
| 1313 | ||
| 1314 | resp.status = falcon.HTTP_204 |
|
| 1315 | ||
| 1316 | ||
| 1317 | class SpaceOfflineMeterCollection: |
|
| @@ 1081-1136 (lines=56) @@ | ||
| 1078 | resp.location = '/spaces/' + str(id_) + '/equipments/' + str(equipment_id) |
|
| 1079 | ||
| 1080 | ||
| 1081 | class SpaceEquipmentItem: |
|
| 1082 | @staticmethod |
|
| 1083 | def __init__(): |
|
| 1084 | pass |
|
| 1085 | ||
| 1086 | @staticmethod |
|
| 1087 | def on_options(req, resp, id_, eid): |
|
| 1088 | resp.status = falcon.HTTP_200 |
|
| 1089 | ||
| 1090 | @staticmethod |
|
| 1091 | def on_delete(req, resp, id_, eid): |
|
| 1092 | if not id_.isdigit() or int(id_) <= 0: |
|
| 1093 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1094 | description='API.INVALID_SPACE_ID') |
|
| 1095 | ||
| 1096 | if not eid.isdigit() or int(eid) <= 0: |
|
| 1097 | raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 1098 | description='API.INVALID_EQUIPMENT_ID') |
|
| 1099 | ||
| 1100 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 1101 | cursor = cnx.cursor() |
|
| 1102 | ||
| 1103 | cursor.execute(" SELECT name " |
|
| 1104 | " FROM tbl_spaces " |
|
| 1105 | " WHERE id = %s ", (id_,)) |
|
| 1106 | if cursor.fetchone() is None: |
|
| 1107 | cursor.close() |
|
| 1108 | cnx.disconnect() |
|
| 1109 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1110 | description='API.SPACE_NOT_FOUND') |
|
| 1111 | ||
| 1112 | cursor.execute(" SELECT name " |
|
| 1113 | " FROM tbl_equipments " |
|
| 1114 | " WHERE id = %s ", (eid,)) |
|
| 1115 | if cursor.fetchone() is None: |
|
| 1116 | cursor.close() |
|
| 1117 | cnx.disconnect() |
|
| 1118 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1119 | description='API.EQUIPMENT_NOT_FOUND') |
|
| 1120 | ||
| 1121 | cursor.execute(" SELECT id " |
|
| 1122 | " FROM tbl_spaces_equipments " |
|
| 1123 | " WHERE space_id = %s AND equipment_id = %s ", (id_, eid)) |
|
| 1124 | if cursor.fetchone() is None: |
|
| 1125 | cursor.close() |
|
| 1126 | cnx.disconnect() |
|
| 1127 | raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 1128 | description='API.SPACE_EQUIPMENT_RELATION_NOT_FOUND') |
|
| 1129 | ||
| 1130 | cursor.execute(" DELETE FROM tbl_spaces_equipments WHERE space_id = %s AND equipment_id = %s ", (id_, eid)) |
|
| 1131 | cnx.commit() |
|
| 1132 | ||
| 1133 | cursor.close() |
|
| 1134 | cnx.disconnect() |
|
| 1135 | ||
| 1136 | resp.status = falcon.HTTP_204 |
|
| 1137 | ||
| 1138 | ||
| 1139 | class SpaceMeterCollection: |
|