Code Duplication    Length = 173-173 lines in 3 locations

myems-api/core/energystoragecontainer.py 3 locations

@@ 2858-3030 (lines=173) @@
2855
        resp.location = '/energystoragecontainers/' + str(id_) + '/hvacs/' + str(new_id)
2856
2857
2858
class EnergyStorageContainerHVACItem:
2859
    def __init__(self):
2860
        """Initializes Class"""
2861
        pass
2862
2863
    @staticmethod
2864
    def on_options(req, resp, id_, hid):
2865
        resp.status = falcon.HTTP_200
2866
2867
    @staticmethod
2868
    def on_get(req, resp, id_, hid):
2869
        access_control(req)
2870
        if not id_.isdigit() or int(id_) <= 0:
2871
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2872
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
2873
        if not hid.isdigit() or int(hid) <= 0:
2874
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2875
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_HVAC_ID')
2876
2877
        cnx = mysql.connector.connect(**config.myems_system_db)
2878
        cursor = cnx.cursor()
2879
2880
        cursor.execute(" SELECT name "
2881
                       " FROM tbl_energy_storage_containers "
2882
                       " WHERE id = %s ", (id_,))
2883
        if cursor.fetchone() is None:
2884
            cursor.close()
2885
            cnx.close()
2886
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2887
                                   description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND')
2888
2889
        query = (" SELECT id, name, uuid "
2890
                 " FROM tbl_energy_storage_containers ")
2891
        cursor.execute(query)
2892
        rows_energystoragecontainers = cursor.fetchall()
2893
2894
        energy_storage_container_dict = dict()
2895
        if rows_energystoragecontainers is not None and len(rows_energystoragecontainers) > 0:
2896
            for row in rows_energystoragecontainers:
2897
                energy_storage_container_dict[row[0]] = {"id": row[0],
2898
                                                         "name": row[1],
2899
                                                         "uuid": row[2]}
2900
2901
        query = (" SELECT id, name, uuid "
2902
                 " FROM tbl_energy_storage_containers_hvacs "
2903
                 " WHERE id = %s ")
2904
        cursor.execute(query, (hid,))
2905
        row = cursor.fetchone()
2906
        cursor.close()
2907
        cnx.close()
2908
2909
        if row is None:
2910
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2911
                                   description='API.ENERGY_STORAGE_CONTAINER_HVAC_NOT_FOUND')
2912
        else:
2913
            meta_result = {"id": row[0],
2914
                           "name": row[1],
2915
                           "uuid": row[2]
2916
                           }
2917
2918
        resp.text = json.dumps(meta_result)
2919
2920
    @staticmethod
2921
    @user_logger
2922
    def on_delete(req, resp, id_, hid):
2923
        admin_control(req)
2924
        if not id_.isdigit() or int(id_) <= 0:
2925
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2926
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
2927
        if not hid.isdigit() or int(hid) <= 0:
2928
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2929
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_HVAC_ID')
2930
2931
        cnx = mysql.connector.connect(**config.myems_system_db)
2932
        cursor = cnx.cursor()
2933
2934
        cursor.execute(" SELECT name "
2935
                       " FROM tbl_energy_storage_containers "
2936
                       " WHERE id = %s ", (id_,))
2937
        if cursor.fetchone() is None:
2938
            cursor.close()
2939
            cnx.close()
2940
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2941
                                   description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND')
2942
2943
        cursor.execute(" SELECT name "
2944
                       " FROM tbl_energy_storage_containers_hvacs "
2945
                       " WHERE id = %s ", (hid,))
2946
        if cursor.fetchone() is None:
2947
            cursor.close()
2948
            cnx.close()
2949
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2950
                                   description='API.ENERGY_STORAGE_CONTAINER_HVAC_NOT_FOUND')
2951
2952
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_hvacs "
2953
                       " WHERE id = %s ", (hid,))
2954
        cnx.commit()
2955
2956
        cursor.close()
2957
        cnx.close()
2958
2959
        resp.status = falcon.HTTP_204
2960
2961
    @staticmethod
2962
    @user_logger
2963
    def on_put(req, resp, id_, hid):
2964
        """Handles PUT requests"""
2965
        admin_control(req)
2966
        try:
2967
            raw_json = req.stream.read().decode('utf-8')
2968
        except Exception as ex:
2969
            raise falcon.HTTPError(status=falcon.HTTP_400,
2970
                                   title='API.BAD_REQUEST',
2971
                                   description='API.FAILED_TO_READ_REQUEST_STREAM')
2972
        if not id_.isdigit() or int(id_) <= 0:
2973
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2974
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
2975
2976
        if not hid.isdigit() or int(hid) <= 0:
2977
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2978
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_HVAC_ID')
2979
2980
        new_values = json.loads(raw_json)
2981
2982
        if 'name' not in new_values['data'].keys() or \
2983
                not isinstance(new_values['data']['name'], str) or \
2984
                len(str.strip(new_values['data']['name'])) == 0:
2985
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2986
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_HVAC_NAME')
2987
        name = str.strip(new_values['data']['name'])
2988
2989
        cnx = mysql.connector.connect(**config.myems_system_db)
2990
        cursor = cnx.cursor()
2991
2992
        cursor.execute(" SELECT name "
2993
                       " FROM tbl_energy_storage_containers "
2994
                       " WHERE id = %s ", (id_,))
2995
        if cursor.fetchone() is None:
2996
            cursor.close()
2997
            cnx.close()
2998
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2999
                                   description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND')
3000
3001
        cursor.execute(" SELECT name "
3002
                       " FROM tbl_energy_storage_containers_hvacs "
3003
                       " WHERE id = %s ", (hid,))
3004
        if cursor.fetchone() is None:
3005
            cursor.close()
3006
            cnx.close()
3007
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
3008
                                   description='API.ENERGY_STORAGE_CONTAINER_HVAC_NOT_FOUND')
3009
3010
        cursor.execute(" SELECT name "
3011
                       " FROM tbl_energy_storage_containers_hvacs "
3012
                       " WHERE energy_storage_container_id = %s AND name = %s AND id != %s ",
3013
                       (id_, name, hid))
3014
        if cursor.fetchone() is not None:
3015
            cursor.close()
3016
            cnx.close()
3017
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
3018
                                   description='API.ENERGY_STORAGE_CONTAINER_HVAC_NAME_IS_ALREADY_IN_USE')
3019
3020
        update_row = (" UPDATE tbl_energy_storage_containers_hvacs "
3021
                      " SET name = %s "
3022
                      "     WHERE id = %s ")
3023
        cursor.execute(update_row, (name,
3024
                                    hid))
3025
        cnx.commit()
3026
3027
        cursor.close()
3028
        cnx.close()
3029
3030
        resp.status = falcon.HTTP_200
3031
3032
3033
class EnergyStorageContainerLoadCollection:
@@ 2081-2253 (lines=173) @@
2078
        resp.location = '/energystoragecontainers/' + str(id_) + '/firecontrols/' + str(new_id)
2079
2080
2081
class EnergyStorageContainerFirecontrolItem:
2082
    def __init__(self):
2083
        """Initializes Class"""
2084
        pass
2085
2086
    @staticmethod
2087
    def on_options(req, resp, id_, fid):
2088
        resp.status = falcon.HTTP_200
2089
2090
    @staticmethod
2091
    def on_get(req, resp, id_, fid):
2092
        access_control(req)
2093
        if not id_.isdigit() or int(id_) <= 0:
2094
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2095
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
2096
        if not fid.isdigit() or int(fid) <= 0:
2097
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2098
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_FIRECONTROL_ID')
2099
2100
        cnx = mysql.connector.connect(**config.myems_system_db)
2101
        cursor = cnx.cursor()
2102
2103
        cursor.execute(" SELECT name "
2104
                       " FROM tbl_energy_storage_containers "
2105
                       " WHERE id = %s ", (id_,))
2106
        if cursor.fetchone() is None:
2107
            cursor.close()
2108
            cnx.close()
2109
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2110
                                   description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND')
2111
2112
        query = (" SELECT id, name, uuid "
2113
                 " FROM tbl_energy_storage_containers ")
2114
        cursor.execute(query)
2115
        rows_energystoragecontainers = cursor.fetchall()
2116
2117
        energy_storage_container_dict = dict()
2118
        if rows_energystoragecontainers is not None and len(rows_energystoragecontainers) > 0:
2119
            for row in rows_energystoragecontainers:
2120
                energy_storage_container_dict[row[0]] = {"id": row[0],
2121
                                                         "name": row[1],
2122
                                                         "uuid": row[2]}
2123
2124
        query = (" SELECT id, name, uuid "
2125
                 " FROM tbl_energy_storage_containers_firecontrols "
2126
                 " WHERE id = %s ")
2127
        cursor.execute(query, (fid,))
2128
        row = cursor.fetchone()
2129
        cursor.close()
2130
        cnx.close()
2131
2132
        if row is None:
2133
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2134
                                   description='API.ENERGY_STORAGE_CONTAINER_FIRECONTROL_NOT_FOUND')
2135
        else:
2136
            meta_result = {"id": row[0],
2137
                           "name": row[1],
2138
                           "uuid": row[2]
2139
                           }
2140
2141
        resp.text = json.dumps(meta_result)
2142
2143
    @staticmethod
2144
    @user_logger
2145
    def on_delete(req, resp, id_, fid):
2146
        admin_control(req)
2147
        if not id_.isdigit() or int(id_) <= 0:
2148
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2149
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
2150
        if not fid.isdigit() or int(fid) <= 0:
2151
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2152
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_FIRECONTROL_ID')
2153
2154
        cnx = mysql.connector.connect(**config.myems_system_db)
2155
        cursor = cnx.cursor()
2156
2157
        cursor.execute(" SELECT name "
2158
                       " FROM tbl_energy_storage_containers "
2159
                       " WHERE id = %s ", (id_,))
2160
        if cursor.fetchone() is None:
2161
            cursor.close()
2162
            cnx.close()
2163
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2164
                                   description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND')
2165
2166
        cursor.execute(" SELECT name "
2167
                       " FROM tbl_energy_storage_containers_firecontrols "
2168
                       " WHERE id = %s ", (fid,))
2169
        if cursor.fetchone() is None:
2170
            cursor.close()
2171
            cnx.close()
2172
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2173
                                   description='API.ENERGY_STORAGE_CONTAINER_FIRECONTROL_NOT_FOUND')
2174
2175
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_firecontrols "
2176
                       " WHERE id = %s ", (fid,))
2177
        cnx.commit()
2178
2179
        cursor.close()
2180
        cnx.close()
2181
2182
        resp.status = falcon.HTTP_204
2183
2184
    @staticmethod
2185
    @user_logger
2186
    def on_put(req, resp, id_, fid):
2187
        """Handles PUT requests"""
2188
        admin_control(req)
2189
        try:
2190
            raw_json = req.stream.read().decode('utf-8')
2191
        except Exception as ex:
2192
            raise falcon.HTTPError(status=falcon.HTTP_400,
2193
                                   title='API.BAD_REQUEST',
2194
                                   description='API.FAILED_TO_READ_REQUEST_STREAM')
2195
        if not id_.isdigit() or int(id_) <= 0:
2196
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2197
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
2198
2199
        if not fid.isdigit() or int(fid) <= 0:
2200
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2201
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_FIRECONTROL_ID')
2202
2203
        new_values = json.loads(raw_json)
2204
2205
        if 'name' not in new_values['data'].keys() or \
2206
                not isinstance(new_values['data']['name'], str) or \
2207
                len(str.strip(new_values['data']['name'])) == 0:
2208
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2209
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_FIRECONTROL_NAME')
2210
        name = str.strip(new_values['data']['name'])
2211
2212
        cnx = mysql.connector.connect(**config.myems_system_db)
2213
        cursor = cnx.cursor()
2214
2215
        cursor.execute(" SELECT name "
2216
                       " FROM tbl_energy_storage_containers "
2217
                       " WHERE id = %s ", (id_,))
2218
        if cursor.fetchone() is None:
2219
            cursor.close()
2220
            cnx.close()
2221
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2222
                                   description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND')
2223
2224
        cursor.execute(" SELECT name "
2225
                       " FROM tbl_energy_storage_containers_firecontrols "
2226
                       " WHERE id = %s ", (fid,))
2227
        if cursor.fetchone() is None:
2228
            cursor.close()
2229
            cnx.close()
2230
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
2231
                                   description='API.ENERGY_STORAGE_CONTAINER_FIRECONTROL_NOT_FOUND')
2232
2233
        cursor.execute(" SELECT name "
2234
                       " FROM tbl_energy_storage_containers_firecontrols "
2235
                       " WHERE energy_storage_container_id = %s AND name = %s AND id != %s ",
2236
                       (id_, name, fid))
2237
        if cursor.fetchone() is not None:
2238
            cursor.close()
2239
            cnx.close()
2240
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
2241
                                   description='API.ENERGY_STORAGE_CONTAINER_FIRECONTROL_NAME_IS_ALREADY_IN_USE')
2242
2243
        update_row = (" UPDATE tbl_energy_storage_containers_firecontrols "
2244
                      " SET name = %s "
2245
                      "     WHERE id = %s ")
2246
        cursor.execute(update_row, (name,
2247
                                    fid))
2248
        cnx.commit()
2249
2250
        cursor.close()
2251
        cnx.close()
2252
2253
        resp.status = falcon.HTTP_200
2254
2255
2256
class EnergyStorageContainerGridCollection:
@@ 1785-1957 (lines=173) @@
1782
        resp.location = '/energystoragecontainers/' + str(id_) + '/dcdcs/' + str(new_id)
1783
1784
1785
class EnergyStorageContainerDCDCItem:
1786
    def __init__(self):
1787
        """Initializes Class"""
1788
        pass
1789
1790
    @staticmethod
1791
    def on_options(req, resp, id_, did):
1792
        resp.status = falcon.HTTP_200
1793
1794
    @staticmethod
1795
    def on_get(req, resp, id_, did):
1796
        access_control(req)
1797
        if not id_.isdigit() or int(id_) <= 0:
1798
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
1799
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
1800
        if not did.isdigit() or int(did) <= 0:
1801
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
1802
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_DCDC_ID')
1803
1804
        cnx = mysql.connector.connect(**config.myems_system_db)
1805
        cursor = cnx.cursor()
1806
1807
        cursor.execute(" SELECT name "
1808
                       " FROM tbl_energy_storage_containers "
1809
                       " WHERE id = %s ", (id_,))
1810
        if cursor.fetchone() is None:
1811
            cursor.close()
1812
            cnx.close()
1813
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
1814
                                   description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND')
1815
1816
        query = (" SELECT id, name, uuid "
1817
                 " FROM tbl_energy_storage_containers ")
1818
        cursor.execute(query)
1819
        rows_energystoragecontainers = cursor.fetchall()
1820
1821
        energy_storage_container_dict = dict()
1822
        if rows_energystoragecontainers is not None and len(rows_energystoragecontainers) > 0:
1823
            for row in rows_energystoragecontainers:
1824
                energy_storage_container_dict[row[0]] = {"id": row[0],
1825
                                                         "name": row[1],
1826
                                                         "uuid": row[2]}
1827
1828
        query = (" SELECT id, name, uuid "
1829
                 " FROM tbl_energy_storage_containers_dcdcs "
1830
                 " WHERE id = %s ")
1831
        cursor.execute(query, (did,))
1832
        row = cursor.fetchone()
1833
        cursor.close()
1834
        cnx.close()
1835
1836
        if row is None:
1837
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
1838
                                   description='API.ENERGY_STORAGE_CONTAINER_DCDC_NOT_FOUND')
1839
        else:
1840
            meta_result = {"id": row[0],
1841
                           "name": row[1],
1842
                           "uuid": row[2]
1843
                           }
1844
1845
        resp.text = json.dumps(meta_result)
1846
1847
    @staticmethod
1848
    @user_logger
1849
    def on_delete(req, resp, id_, did):
1850
        admin_control(req)
1851
        if not id_.isdigit() or int(id_) <= 0:
1852
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
1853
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
1854
        if not did.isdigit() or int(did) <= 0:
1855
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
1856
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_DCDC_ID')
1857
1858
        cnx = mysql.connector.connect(**config.myems_system_db)
1859
        cursor = cnx.cursor()
1860
1861
        cursor.execute(" SELECT name "
1862
                       " FROM tbl_energy_storage_containers "
1863
                       " WHERE id = %s ", (id_,))
1864
        if cursor.fetchone() is None:
1865
            cursor.close()
1866
            cnx.close()
1867
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
1868
                                   description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND')
1869
1870
        cursor.execute(" SELECT name "
1871
                       " FROM tbl_energy_storage_containers_dcdcs "
1872
                       " WHERE id = %s ", (did,))
1873
        if cursor.fetchone() is None:
1874
            cursor.close()
1875
            cnx.close()
1876
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
1877
                                   description='API.ENERGY_STORAGE_CONTAINER_DCDC_NOT_FOUND')
1878
1879
        cursor.execute(" DELETE FROM tbl_energy_storage_containers_dcdcs "
1880
                       " WHERE id = %s ", (did,))
1881
        cnx.commit()
1882
1883
        cursor.close()
1884
        cnx.close()
1885
1886
        resp.status = falcon.HTTP_204
1887
1888
    @staticmethod
1889
    @user_logger
1890
    def on_put(req, resp, id_, did):
1891
        """Handles PUT requests"""
1892
        admin_control(req)
1893
        try:
1894
            raw_json = req.stream.read().decode('utf-8')
1895
        except Exception as ex:
1896
            raise falcon.HTTPError(status=falcon.HTTP_400,
1897
                                   title='API.BAD_REQUEST',
1898
                                   description='API.FAILED_TO_READ_REQUEST_STREAM')
1899
        if not id_.isdigit() or int(id_) <= 0:
1900
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
1901
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_ID')
1902
1903
        if not did.isdigit() or int(did) <= 0:
1904
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
1905
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_DCDC_ID')
1906
1907
        new_values = json.loads(raw_json)
1908
1909
        if 'name' not in new_values['data'].keys() or \
1910
                not isinstance(new_values['data']['name'], str) or \
1911
                len(str.strip(new_values['data']['name'])) == 0:
1912
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
1913
                                   description='API.INVALID_ENERGY_STORAGE_CONTAINER_DCDC_NAME')
1914
        name = str.strip(new_values['data']['name'])
1915
1916
        cnx = mysql.connector.connect(**config.myems_system_db)
1917
        cursor = cnx.cursor()
1918
1919
        cursor.execute(" SELECT name "
1920
                       " FROM tbl_energy_storage_containers "
1921
                       " WHERE id = %s ", (id_,))
1922
        if cursor.fetchone() is None:
1923
            cursor.close()
1924
            cnx.close()
1925
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
1926
                                   description='API.ENERGY_STORAGE_CONTAINER_NOT_FOUND')
1927
1928
        cursor.execute(" SELECT name "
1929
                       " FROM tbl_energy_storage_containers_dcdcs "
1930
                       " WHERE id = %s ", (did,))
1931
        if cursor.fetchone() is None:
1932
            cursor.close()
1933
            cnx.close()
1934
            raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
1935
                                   description='API.ENERGY_STORAGE_CONTAINER_DCDC_NOT_FOUND')
1936
1937
        cursor.execute(" SELECT name "
1938
                       " FROM tbl_energy_storage_containers_dcdcs "
1939
                       " WHERE energy_storage_container_id = %s AND name = %s AND id != %s ",
1940
                       (id_, name, did))
1941
        if cursor.fetchone() is not None:
1942
            cursor.close()
1943
            cnx.close()
1944
            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
1945
                                   description='API.ENERGY_STORAGE_CONTAINER_DCDC_NAME_IS_ALREADY_IN_USE')
1946
1947
        update_row = (" UPDATE tbl_energy_storage_containers_dcdcs "
1948
                      " SET name = %s "
1949
                      "     WHERE id = %s ")
1950
        cursor.execute(update_row, (name,
1951
                                    did))
1952
        cnx.commit()
1953
1954
        cursor.close()
1955
        cnx.close()
1956
1957
        resp.status = falcon.HTTP_200
1958
1959
1960
class EnergyStorageContainerFirecontrolCollection: