| @@ 5802-5867 (lines=66) @@ | ||
| 5799 | resp.location = '/energystoragecontainers/' + str(new_id) |
|
| 5800 | ||
| 5801 | ||
| 5802 | class EnergyStorageContainerExport: |
|
| 5803 | def __init__(self): |
|
| 5804 | """"Initializes Class""" |
|
| 5805 | pass |
|
| 5806 | ||
| 5807 | @staticmethod |
|
| 5808 | def on_options(req, resp, id_): |
|
| 5809 | resp.status = falcon.HTTP_200 |
|
| 5810 | ||
| 5811 | @staticmethod |
|
| 5812 | def on_get(req, resp, id_): |
|
| 5813 | access_control(req) |
|
| 5814 | if not id_.isdigit() or int(id_) <= 0: |
|
| 5815 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5816 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 5817 | ||
| 5818 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 5819 | cursor = cnx.cursor() |
|
| 5820 | ||
| 5821 | query = (" SELECT id, name, uuid " |
|
| 5822 | " FROM tbl_contacts ") |
|
| 5823 | cursor.execute(query) |
|
| 5824 | rows_contacts = cursor.fetchall() |
|
| 5825 | ||
| 5826 | contact_dict = dict() |
|
| 5827 | if rows_contacts is not None and len(rows_contacts) > 0: |
|
| 5828 | for row in rows_contacts: |
|
| 5829 | contact_dict[row[0]] = {"id": row[0], |
|
| 5830 | "name": row[1], |
|
| 5831 | "uuid": row[2]} |
|
| 5832 | ||
| 5833 | query = (" SELECT id, name, uuid " |
|
| 5834 | " FROM tbl_cost_centers ") |
|
| 5835 | cursor.execute(query) |
|
| 5836 | rows_cost_centers = cursor.fetchall() |
|
| 5837 | ||
| 5838 | cost_center_dict = dict() |
|
| 5839 | if rows_cost_centers is not None and len(rows_cost_centers) > 0: |
|
| 5840 | for row in rows_cost_centers: |
|
| 5841 | cost_center_dict[row[0]] = {"id": row[0], |
|
| 5842 | "name": row[1], |
|
| 5843 | "uuid": row[2]} |
|
| 5844 | ||
| 5845 | query = (" SELECT id, name, uuid, " |
|
| 5846 | " rated_capacity, rated_power, contact_id, cost_center_id, description " |
|
| 5847 | " FROM tbl_energy_storage_containers " |
|
| 5848 | " WHERE id = %s ") |
|
| 5849 | cursor.execute(query, (id_,)) |
|
| 5850 | row = cursor.fetchone() |
|
| 5851 | cursor.close() |
|
| 5852 | cnx.close() |
|
| 5853 | ||
| 5854 | if row is None: |
|
| 5855 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5856 | description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND') |
|
| 5857 | else: |
|
| 5858 | meta_result = {"id": row[0], |
|
| 5859 | "name": row[1], |
|
| 5860 | "uuid": row[2], |
|
| 5861 | "rated_capacity": row[3], |
|
| 5862 | "rated_power": row[4], |
|
| 5863 | "contact": contact_dict.get(row[5], None), |
|
| 5864 | "cost_center": cost_center_dict.get(row[6], None), |
|
| 5865 | "description": row[7]} |
|
| 5866 | ||
| 5867 | resp.text = json.dumps(meta_result) |
|
| 5868 | ||
| 5869 | ||
| 5870 | class EnergyStorageContainerImport: |
|
| @@ 5192-5257 (lines=66) @@ | ||
| 5189 | resp.location = '/hybridpowerstations/' + str(new_id) |
|
| 5190 | ||
| 5191 | ||
| 5192 | class HybridPowerStationExport: |
|
| 5193 | def __init__(self): |
|
| 5194 | """"Initializes Class""" |
|
| 5195 | pass |
|
| 5196 | ||
| 5197 | @staticmethod |
|
| 5198 | def on_options(req, resp, id_): |
|
| 5199 | resp.status = falcon.HTTP_200 |
|
| 5200 | ||
| 5201 | @staticmethod |
|
| 5202 | def on_get(req, resp, id_): |
|
| 5203 | access_control(req) |
|
| 5204 | if not id_.isdigit() or int(id_) <= 0: |
|
| 5205 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5206 | description='API.INVALID_HYBRID_POWER_STATION_ID') |
|
| 5207 | ||
| 5208 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 5209 | cursor = cnx.cursor() |
|
| 5210 | ||
| 5211 | query = (" SELECT id, name, uuid " |
|
| 5212 | " FROM tbl_contacts ") |
|
| 5213 | cursor.execute(query) |
|
| 5214 | rows_contacts = cursor.fetchall() |
|
| 5215 | ||
| 5216 | contact_dict = dict() |
|
| 5217 | if rows_contacts is not None and len(rows_contacts) > 0: |
|
| 5218 | for row in rows_contacts: |
|
| 5219 | contact_dict[row[0]] = {"id": row[0], |
|
| 5220 | "name": row[1], |
|
| 5221 | "uuid": row[2]} |
|
| 5222 | ||
| 5223 | query = (" SELECT id, name, uuid " |
|
| 5224 | " FROM tbl_cost_centers ") |
|
| 5225 | cursor.execute(query) |
|
| 5226 | rows_cost_centers = cursor.fetchall() |
|
| 5227 | ||
| 5228 | cost_center_dict = dict() |
|
| 5229 | if rows_cost_centers is not None and len(rows_cost_centers) > 0: |
|
| 5230 | for row in rows_cost_centers: |
|
| 5231 | cost_center_dict[row[0]] = {"id": row[0], |
|
| 5232 | "name": row[1], |
|
| 5233 | "uuid": row[2]} |
|
| 5234 | ||
| 5235 | query = (" SELECT id, name, uuid, " |
|
| 5236 | " rated_capacity, rated_power, contact_id, cost_center_id, description " |
|
| 5237 | " FROM tbl_hybrid_power_stations " |
|
| 5238 | " WHERE id = %s ") |
|
| 5239 | cursor.execute(query, (id_,)) |
|
| 5240 | row = cursor.fetchone() |
|
| 5241 | cursor.close() |
|
| 5242 | cnx.close() |
|
| 5243 | ||
| 5244 | if row is None: |
|
| 5245 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5246 | description='API.HYBRID_POWER_STATION_NOT_FOUND') |
|
| 5247 | else: |
|
| 5248 | meta_result = {"id": row[0], |
|
| 5249 | "name": row[1], |
|
| 5250 | "uuid": row[2], |
|
| 5251 | "rated_capacity": row[3], |
|
| 5252 | "rated_power": row[4], |
|
| 5253 | "contact": contact_dict.get(row[5], None), |
|
| 5254 | "cost_center": cost_center_dict.get(row[6], None), |
|
| 5255 | "description": row[7]} |
|
| 5256 | ||
| 5257 | resp.text = json.dumps(meta_result) |
|
| 5258 | ||
| 5259 | ||
| 5260 | class HybridPowerStationImport: |
|