|
@@ 1513-1608 (lines=96) @@
|
| 1510 |
|
description='API.COMBINED_EQUIPMENT_PARAMETER_NAME_IS_ALREADY_IN_USE') |
| 1511 |
|
|
| 1512 |
|
# validate by parameter type |
| 1513 |
|
if parameter_type == 'point': |
| 1514 |
|
if point_id is None: |
| 1515 |
|
cursor.close() |
| 1516 |
|
cnx.close() |
| 1517 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
| 1518 |
|
description='API.INVALID_POINT_ID') |
| 1519 |
|
|
| 1520 |
|
if len(data_source_ids) == 0: |
| 1521 |
|
cursor.close() |
| 1522 |
|
cnx.close() |
| 1523 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.NOT_FOUND', |
| 1524 |
|
description='API.POINT_NOT_FOUND') |
| 1525 |
|
|
| 1526 |
|
format_strings = ','.join(['%s'] * len(data_source_ids)) |
| 1527 |
|
query = (" SELECT id, name " |
| 1528 |
|
" FROM tbl_points " |
| 1529 |
|
" WHERE id = %s AND data_source_id IN (" + format_strings + ") ") |
| 1530 |
|
cursor.execute(query, (point_id,) + data_source_ids) |
| 1531 |
|
row = cursor.fetchone() |
| 1532 |
|
if row is None: |
| 1533 |
|
cursor.close() |
| 1534 |
|
cnx.close() |
| 1535 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
| 1536 |
|
description='API.POINT_NOT_FOUND') |
| 1537 |
|
|
| 1538 |
|
elif parameter_type == 'constant': |
| 1539 |
|
if constant is None: |
| 1540 |
|
cursor.close() |
| 1541 |
|
cnx.close() |
| 1542 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
| 1543 |
|
description='API.INVALID_CONSTANT_VALUE') |
| 1544 |
|
|
| 1545 |
|
elif parameter_type == 'fraction': |
| 1546 |
|
|
| 1547 |
|
query = (" SELECT id, name, uuid " |
| 1548 |
|
" FROM tbl_meters ") |
| 1549 |
|
cursor.execute(query) |
| 1550 |
|
rows_meters = cursor.fetchall() |
| 1551 |
|
|
| 1552 |
|
meter_dict = dict() |
| 1553 |
|
if rows_meters is not None and len(rows_meters) > 0: |
| 1554 |
|
for row in rows_meters: |
| 1555 |
|
meter_dict[row[2]] = {"type": 'meter', |
| 1556 |
|
"id": row[0], |
| 1557 |
|
"name": row[1], |
| 1558 |
|
"uuid": row[2]} |
| 1559 |
|
|
| 1560 |
|
query = (" SELECT id, name, uuid " |
| 1561 |
|
" FROM tbl_offline_meters ") |
| 1562 |
|
cursor.execute(query) |
| 1563 |
|
rows_offline_meters = cursor.fetchall() |
| 1564 |
|
|
| 1565 |
|
offline_meter_dict = dict() |
| 1566 |
|
if rows_offline_meters is not None and len(rows_offline_meters) > 0: |
| 1567 |
|
for row in rows_offline_meters: |
| 1568 |
|
offline_meter_dict[row[2]] = {"type": 'offline_meter', |
| 1569 |
|
"id": row[0], |
| 1570 |
|
"name": row[1], |
| 1571 |
|
"uuid": row[2]} |
| 1572 |
|
|
| 1573 |
|
query = (" SELECT id, name, uuid " |
| 1574 |
|
" FROM tbl_virtual_meters ") |
| 1575 |
|
cursor.execute(query) |
| 1576 |
|
rows_virtual_meters = cursor.fetchall() |
| 1577 |
|
|
| 1578 |
|
virtual_meter_dict = dict() |
| 1579 |
|
if rows_virtual_meters is not None and len(rows_virtual_meters) > 0: |
| 1580 |
|
for row in rows_virtual_meters: |
| 1581 |
|
virtual_meter_dict[row[2]] = {"type": 'virtual_meter', |
| 1582 |
|
"id": row[0], |
| 1583 |
|
"name": row[1], |
| 1584 |
|
"uuid": row[2]} |
| 1585 |
|
|
| 1586 |
|
# validate numerator meter uuid |
| 1587 |
|
if meter_dict.get(numerator_meter_uuid) is None and \ |
| 1588 |
|
virtual_meter_dict.get(numerator_meter_uuid) is None and \ |
| 1589 |
|
offline_meter_dict.get(numerator_meter_uuid) is None: |
| 1590 |
|
cursor.close() |
| 1591 |
|
cnx.close() |
| 1592 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
| 1593 |
|
description='API.INVALID_NUMERATOR_METER_UUID') |
| 1594 |
|
|
| 1595 |
|
# validate denominator meter uuid |
| 1596 |
|
if denominator_meter_uuid == numerator_meter_uuid: |
| 1597 |
|
cursor.close() |
| 1598 |
|
cnx.close() |
| 1599 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
| 1600 |
|
description='API.INVALID_DENOMINATOR_METER_UUID') |
| 1601 |
|
|
| 1602 |
|
if denominator_meter_uuid not in meter_dict and \ |
| 1603 |
|
denominator_meter_uuid not in virtual_meter_dict and \ |
| 1604 |
|
denominator_meter_uuid not in offline_meter_dict: |
| 1605 |
|
cursor.close() |
| 1606 |
|
cnx.close() |
| 1607 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
| 1608 |
|
description='API.INVALID_DENOMINATOR_METER_UUID') |
| 1609 |
|
|
| 1610 |
|
add_values = (" UPDATE tbl_combined_equipments_parameters " |
| 1611 |
|
" SET name = %s , parameter_type = %s, constant = %s, " |
|
@@ 1089-1183 (lines=95) @@
|
| 1086 |
|
description='API.COMBINED_EQUIPMENT_PARAMETER_NAME_IS_ALREADY_IN_USE') |
| 1087 |
|
|
| 1088 |
|
# validate by parameter type |
| 1089 |
|
if parameter_type == 'point': |
| 1090 |
|
if point_id is None: |
| 1091 |
|
cursor.close() |
| 1092 |
|
cnx.close() |
| 1093 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
| 1094 |
|
description='API.INVALID_POINT_ID') |
| 1095 |
|
|
| 1096 |
|
if len(data_source_ids) == 0: |
| 1097 |
|
cursor.close() |
| 1098 |
|
cnx.close() |
| 1099 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.NOT_FOUND', |
| 1100 |
|
description='API.POINT_NOT_FOUND') |
| 1101 |
|
|
| 1102 |
|
format_strings = ','.join(['%s'] * len(data_source_ids)) |
| 1103 |
|
query = (" SELECT id, name " |
| 1104 |
|
" FROM tbl_points " |
| 1105 |
|
" WHERE id = %s AND data_source_id IN (" + format_strings + ") ") |
| 1106 |
|
cursor.execute(query, (point_id,) + data_source_ids) |
| 1107 |
|
if cursor.fetchone() is None: |
| 1108 |
|
cursor.close() |
| 1109 |
|
cnx.close() |
| 1110 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
| 1111 |
|
description='API.POINT_NOT_FOUND') |
| 1112 |
|
|
| 1113 |
|
elif parameter_type == 'constant': |
| 1114 |
|
if constant is None: |
| 1115 |
|
cursor.close() |
| 1116 |
|
cnx.close() |
| 1117 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
| 1118 |
|
description='API.INVALID_CONSTANT_VALUE') |
| 1119 |
|
|
| 1120 |
|
elif parameter_type == 'fraction': |
| 1121 |
|
|
| 1122 |
|
query = (" SELECT id, name, uuid " |
| 1123 |
|
" FROM tbl_meters ") |
| 1124 |
|
cursor.execute(query) |
| 1125 |
|
rows_meters = cursor.fetchall() |
| 1126 |
|
|
| 1127 |
|
meter_dict = dict() |
| 1128 |
|
if rows_meters is not None and len(rows_meters) > 0: |
| 1129 |
|
for row in rows_meters: |
| 1130 |
|
meter_dict[row[2]] = {"type": 'meter', |
| 1131 |
|
"id": row[0], |
| 1132 |
|
"name": row[1], |
| 1133 |
|
"uuid": row[2]} |
| 1134 |
|
|
| 1135 |
|
query = (" SELECT id, name, uuid " |
| 1136 |
|
" FROM tbl_offline_meters ") |
| 1137 |
|
cursor.execute(query) |
| 1138 |
|
rows_offline_meters = cursor.fetchall() |
| 1139 |
|
|
| 1140 |
|
offline_meter_dict = dict() |
| 1141 |
|
if rows_offline_meters is not None and len(rows_offline_meters) > 0: |
| 1142 |
|
for row in rows_offline_meters: |
| 1143 |
|
offline_meter_dict[row[2]] = {"type": 'offline_meter', |
| 1144 |
|
"id": row[0], |
| 1145 |
|
"name": row[1], |
| 1146 |
|
"uuid": row[2]} |
| 1147 |
|
|
| 1148 |
|
query = (" SELECT id, name, uuid " |
| 1149 |
|
" FROM tbl_virtual_meters ") |
| 1150 |
|
cursor.execute(query) |
| 1151 |
|
rows_virtual_meters = cursor.fetchall() |
| 1152 |
|
|
| 1153 |
|
virtual_meter_dict = dict() |
| 1154 |
|
if rows_virtual_meters is not None and len(rows_virtual_meters) > 0: |
| 1155 |
|
for row in rows_virtual_meters: |
| 1156 |
|
virtual_meter_dict[row[2]] = {"type": 'virtual_meter', |
| 1157 |
|
"id": row[0], |
| 1158 |
|
"name": row[1], |
| 1159 |
|
"uuid": row[2]} |
| 1160 |
|
|
| 1161 |
|
# validate numerator meter uuid |
| 1162 |
|
if meter_dict.get(numerator_meter_uuid) is None and \ |
| 1163 |
|
virtual_meter_dict.get(numerator_meter_uuid) is None and \ |
| 1164 |
|
offline_meter_dict.get(numerator_meter_uuid) is None: |
| 1165 |
|
cursor.close() |
| 1166 |
|
cnx.close() |
| 1167 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
| 1168 |
|
description='API.INVALID_NUMERATOR_METER_UUID') |
| 1169 |
|
|
| 1170 |
|
# validate denominator meter uuid |
| 1171 |
|
if denominator_meter_uuid == numerator_meter_uuid: |
| 1172 |
|
cursor.close() |
| 1173 |
|
cnx.close() |
| 1174 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
| 1175 |
|
description='API.INVALID_DENOMINATOR_METER_UUID') |
| 1176 |
|
|
| 1177 |
|
if denominator_meter_uuid not in meter_dict and \ |
| 1178 |
|
denominator_meter_uuid not in virtual_meter_dict and \ |
| 1179 |
|
denominator_meter_uuid not in offline_meter_dict: |
| 1180 |
|
cursor.close() |
| 1181 |
|
cnx.close() |
| 1182 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
| 1183 |
|
description='API.INVALID_DENOMINATOR_METER_UUID') |
| 1184 |
|
|
| 1185 |
|
add_values = (" INSERT INTO tbl_combined_equipments_parameters " |
| 1186 |
|
" (combined_equipment_id, name, parameter_type, constant, " |