Fixed cognitive complexity issues reported by SonarQube.

This commit is contained in:
Aditya Toshniwal
2020-08-11 15:13:35 +05:30
committed by Akshay Joshi
parent 082b968bbc
commit 8129df42da
5 changed files with 177 additions and 214 deletions

View File

@@ -325,19 +325,9 @@ class JobScheduleView(PGChildNodeView):
sid: Server ID
jid: Job ID
"""
data = {}
if request.args:
for k, v in request.args.items():
try:
data[k] = json.loads(
v.decode('utf-8') if hasattr(v, 'decode') else v
)
except ValueError:
data[k] = v
else:
data = json.loads(request.data.decode())
# convert python list literal to postgres array literal.
format_schedule_data(data)
data = json.loads(request.data, encoding='utf-8')
# convert python list literal to postgres array literal.
format_schedule_data(data)
sql = render_template(
"/".join([self.template_path, self._CREATE_SQL]),

View File

@@ -431,11 +431,9 @@ SELECT EXISTS(
data['jstconntype'] = row['jstconntype']
if row['jstconntype']:
if not ('jstdbname' in data):
data['jstdbname'] = row['jstdbname']
data['jstdbname'] = data.get('jstdbname', row['jstdbname'])
else:
if not ('jstconnstr' in data):
data['jstconnstr'] = row['jstconnstr']
data['jstconnstr'] = data.get('jstconnstr', row['jstconnstr'])
sql = render_template(
"/".join([self.template_path, self._UPDATE_SQL]),
@@ -516,9 +514,7 @@ SELECT EXISTS(
sql = ''
for k, v in request.args.items():
try:
data[k] = json.loads(
v.decode('utf-8') if hasattr(v, 'decode') else v
)
data[k] = json.loads(v, 'utf-8')
except ValueError:
data[k] = v
@@ -529,46 +525,49 @@ SELECT EXISTS(
data=data,
has_connstr=self.manager.db_info['pgAgent']['has_connstr']
)
else:
if (
self.manager.db_info['pgAgent']['has_connstr'] and
'jstconntype' not in data and
('jstdbname' in data or 'jstconnstr' in data)
):
sql = render_template(
"/".join([self.template_path, self._PROPERTIES_SQL]),
jstid=jstid,
jid=jid,
has_connstr=self.manager.db_info['pgAgent']['has_connstr']
)
status, res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
errormsg=gettext(
"Could not find the specified job step."
)
)
row = res['rows'][0]
data['jstconntype'] = row['jstconntype']
if row['jstconntype']:
if not ('jstdbname' in data):
data['jstdbname'] = row['jstdbname']
else:
if not ('jstconnstr' in data):
data['jstconnstr'] = row['jstconnstr']
return make_json_response(
data=sql,
status=200
)
if (
self.manager.db_info['pgAgent']['has_connstr'] and
'jstconntype' not in data and
('jstdbname' in data or 'jstconnstr' in data)
):
sql = render_template(
"/".join([self.template_path, self._UPDATE_SQL]),
jid=jid,
"/".join([self.template_path, self._PROPERTIES_SQL]),
jstid=jstid,
data=data,
jid=jid,
has_connstr=self.manager.db_info['pgAgent']['has_connstr']
)
status, res = self.conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
if len(res['rows']) == 0:
return gone(
errormsg=gettext(
"Could not find the specified job step."
)
)
row = res['rows'][0]
data['jstconntype'] = row['jstconntype']
if row['jstconntype']:
data['jstdbname'] = data.get('jstdbname', row['jstdbname'])
else:
data['jstconnstr'] = data.get('jstconnstr', row['jstconnstr'])
sql = render_template(
"/".join([self.template_path, self._UPDATE_SQL]),
jid=jid,
jstid=jstid,
data=data,
has_connstr=self.manager.db_info['pgAgent']['has_connstr']
)
return make_json_response(
data=sql,