| @@ 5737-5799 (lines=63) @@ | ||
| 5734 | resp.status = falcon.HTTP_204 |
|
| 5735 | ||
| 5736 | ||
| 5737 | class EnergyStorageContainerClone: |
|
| 5738 | def __init__(self): |
|
| 5739 | """Initializes Class""" |
|
| 5740 | pass |
|
| 5741 | ||
| 5742 | @staticmethod |
|
| 5743 | def on_options(req, resp, id_): |
|
| 5744 | resp.status = falcon.HTTP_200 |
|
| 5745 | ||
| 5746 | @staticmethod |
|
| 5747 | @user_logger |
|
| 5748 | def on_post(req, resp, id_): |
|
| 5749 | """Handles POST requests""" |
|
| 5750 | access_control(req) |
|
| 5751 | if not id_.isdigit() or int(id_) <= 0: |
|
| 5752 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5753 | description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID') |
|
| 5754 | ||
| 5755 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 5756 | cursor = cnx.cursor() |
|
| 5757 | ||
| 5758 | query = (" SELECT id, name, uuid, " |
|
| 5759 | " rated_capacity, rated_power, contact_id, cost_center_id, description " |
|
| 5760 | " FROM tbl_energy_storage_containers " |
|
| 5761 | " WHERE id = %s ") |
|
| 5762 | cursor.execute(query, (id_,)) |
|
| 5763 | row = cursor.fetchone() |
|
| 5764 | ||
| 5765 | if row is None: |
|
| 5766 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5767 | description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND') |
|
| 5768 | else: |
|
| 5769 | meta_result = {"id": row[0], |
|
| 5770 | "name": row[1], |
|
| 5771 | "uuid": row[2], |
|
| 5772 | "rated_capacity": row[3], |
|
| 5773 | "rated_power": row[4], |
|
| 5774 | "contact_id": row[5], |
|
| 5775 | "cost_center_id": row[6], |
|
| 5776 | "description": row[7]} |
|
| 5777 | timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6]) |
|
| 5778 | if config.utc_offset[0] == '-': |
|
| 5779 | timezone_offset = -timezone_offset |
|
| 5780 | new_name = str.strip(meta_result['name']) + \ |
|
| 5781 | (datetime.utcnow() + timedelta(minutes=timezone_offset)).isoformat(sep='-', timespec='seconds') |
|
| 5782 | add_values = (" INSERT INTO tbl_energy_storage_containers " |
|
| 5783 | " (name, uuid, rated_capacity, rated_power, contact_id, " |
|
| 5784 | " cost_center_id, description) " |
|
| 5785 | " VALUES (%s, %s, %s, %s, %s, %s, %s) ") |
|
| 5786 | cursor.execute(add_values, (new_name, |
|
| 5787 | str(uuid.uuid4()), |
|
| 5788 | meta_result['rated_capacity'], |
|
| 5789 | meta_result['rated_power'], |
|
| 5790 | meta_result['contact_id'], |
|
| 5791 | meta_result['cost_center_id'], |
|
| 5792 | meta_result['description'])) |
|
| 5793 | new_id = cursor.lastrowid |
|
| 5794 | cnx.commit() |
|
| 5795 | cursor.close() |
|
| 5796 | cnx.close() |
|
| 5797 | ||
| 5798 | resp.status = falcon.HTTP_201 |
|
| 5799 | resp.location = '/energystoragecontainers/' + str(new_id) |
|
| 5800 | ||
| 5801 | ||
| 5802 | class EnergyStorageContainerExport: |
|
| @@ 5127-5189 (lines=63) @@ | ||
| 5124 | resp.status = falcon.HTTP_204 |
|
| 5125 | ||
| 5126 | ||
| 5127 | class HybridPowerStationClone: |
|
| 5128 | def __init__(self): |
|
| 5129 | """Initializes Class""" |
|
| 5130 | pass |
|
| 5131 | ||
| 5132 | @staticmethod |
|
| 5133 | def on_options(req, resp, id_): |
|
| 5134 | resp.status = falcon.HTTP_200 |
|
| 5135 | ||
| 5136 | @staticmethod |
|
| 5137 | @user_logger |
|
| 5138 | def on_post(req, resp, id_): |
|
| 5139 | """Handles POST requests""" |
|
| 5140 | access_control(req) |
|
| 5141 | if not id_.isdigit() or int(id_) <= 0: |
|
| 5142 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 5143 | description='API.INVALID_HYBRID_POWER_STATION_ID') |
|
| 5144 | ||
| 5145 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 5146 | cursor = cnx.cursor() |
|
| 5147 | ||
| 5148 | query = (" SELECT id, name, uuid, " |
|
| 5149 | " rated_capacity, rated_power, contact_id, cost_center_id, description " |
|
| 5150 | " FROM tbl_hybrid_power_stations " |
|
| 5151 | " WHERE id = %s ") |
|
| 5152 | cursor.execute(query, (id_,)) |
|
| 5153 | row = cursor.fetchone() |
|
| 5154 | ||
| 5155 | if row is None: |
|
| 5156 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 5157 | description='API.HYBRID_POWER_STATION_NOT_FOUND') |
|
| 5158 | else: |
|
| 5159 | meta_result = {"id": row[0], |
|
| 5160 | "name": row[1], |
|
| 5161 | "uuid": row[2], |
|
| 5162 | "rated_capacity": row[3], |
|
| 5163 | "rated_power": row[4], |
|
| 5164 | "contact_id": row[5], |
|
| 5165 | "cost_center_id": row[6], |
|
| 5166 | "description": row[7]} |
|
| 5167 | timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6]) |
|
| 5168 | if config.utc_offset[0] == '-': |
|
| 5169 | timezone_offset = -timezone_offset |
|
| 5170 | new_name = str.strip(meta_result['name']) + \ |
|
| 5171 | (datetime.utcnow() + timedelta(minutes=timezone_offset)).isoformat(sep='-', timespec='seconds') |
|
| 5172 | add_values = (" INSERT INTO tbl_hybrid_power_stations " |
|
| 5173 | " (name, uuid, rated_capacity, rated_power, contact_id, " |
|
| 5174 | " cost_center_id, description) " |
|
| 5175 | " VALUES (%s, %s, %s, %s, %s, %s, %s) ") |
|
| 5176 | cursor.execute(add_values, (new_name, |
|
| 5177 | str(uuid.uuid4()), |
|
| 5178 | meta_result['rated_capacity'], |
|
| 5179 | meta_result['rated_power'], |
|
| 5180 | meta_result['contact_id'], |
|
| 5181 | meta_result['cost_center_id'], |
|
| 5182 | meta_result['description'])) |
|
| 5183 | new_id = cursor.lastrowid |
|
| 5184 | cnx.commit() |
|
| 5185 | cursor.close() |
|
| 5186 | cnx.close() |
|
| 5187 | ||
| 5188 | resp.status = falcon.HTTP_201 |
|
| 5189 | resp.location = '/hybridpowerstations/' + str(new_id) |
|
| 5190 | ||
| 5191 | ||
| 5192 | class HybridPowerStationExport: |
|