Skip to content

Commit

Permalink
Merge pull request #1546 from OpenC3/sonarcloud-highs
Browse files Browse the repository at this point in the history
beginning to address the SonarCloud Highs
  • Loading branch information
ryanmelt authored Oct 24, 2024
2 parents 06e9234 + 83bd5c2 commit 6b5acfc
Show file tree
Hide file tree
Showing 34 changed files with 166 additions and 139 deletions.
10 changes: 6 additions & 4 deletions openc3-cosmos-cmd-tlm-api/app/controllers/activity_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
require 'openc3/topics/timeline_topic'

class ActivityController < ApplicationController
NOT_FOUND = 'not found'

def initialize
super()
@model_class = OpenC3::ActivityModel
Expand Down Expand Up @@ -160,7 +162,7 @@ def show
begin
model = @model_class.score(name: params[:name], score: params[:id].to_i, scope: params[:scope])
if model.nil?
render :json => { :status => 'error', :message => 'not found' }, :status => 404
render :json => { :status => 'error', :message => NOT_FOUND }, :status => 404
else
render :json => model.as_json(:allow_nan => true), :status => 200
end
Expand Down Expand Up @@ -195,7 +197,7 @@ def event
return unless authorization('script_run')
model = @model_class.score(name: params[:name], score: params[:id].to_i, scope: params[:scope])
if model.nil?
render :json => { :status => 'error', :message => 'not found' }, :status => 404
render :json => { :status => 'error', :message => NOT_FOUND }, :status => 404
return
end
begin
Expand Down Expand Up @@ -243,7 +245,7 @@ def update
return unless authorization('script_run')
model = @model_class.score(name: params[:name], score: params[:id].to_i, scope: params[:scope])
if model.nil?
render :json => { :status => 'error', :message => 'not found' }, :status => 404
render :json => { :status => 'error', :message => NOT_FOUND }, :status => 404
return
end
begin
Expand Down Expand Up @@ -292,7 +294,7 @@ def destroy
begin
ret = @model_class.destroy(name: params[:name], scope: params[:scope], score: params[:id].to_i, uuid: params[:uuid], recurring: params[:recurring])
if ret == 0
render :json => { :status => 'error', :message => "Activity not found" }, :status => 404
render :json => { :status => 'error', :message => NOT_FOUND }, :status => 404
else
OpenC3::Logger.info(
"Activity destroyed name: #{params[:name]} id:#{params[:id]} recurring:#{params[:recurring]}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
require 'time'

class MetadataController < ApplicationController
NOT_FOUND = 'not found'

def initialize
@model_class = OpenC3::MetadataModel
end
Expand Down Expand Up @@ -110,7 +112,7 @@ def show
if model_hash
render json: model_hash, status: 200
else
render json: { status: 'error', message: 'not found' }, status: 404
render json: { status: 'error', message: NOT_FOUND }, status: 404
end
end
end
Expand Down Expand Up @@ -141,7 +143,7 @@ def update
action do
hash = @model_class.get(start: params[:id].to_i, scope: params[:scope])
if hash.nil?
render json: { status: 'error', message: 'not found' }, status: 404
render json: { status: 'error', message: NOT_FOUND }, status: 404
return
end
model = @model_class.from_json(hash.symbolize_keys, scope: params[:scope])
Expand Down Expand Up @@ -179,7 +181,7 @@ def destroy
action do
count = @model_class.destroy(start: params[:id].to_i, scope: params[:scope])
if count == 0
render json: { status: 'error', message: 'not found' }, status: 404
render json: { status: 'error', message: NOT_FOUND }, status: 404
return
end
OpenC3::Logger.info(
Expand Down
8 changes: 5 additions & 3 deletions openc3-cosmos-cmd-tlm-api/app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
require 'time'

class NotesController < ApplicationController
NOT_FOUND = 'not found'

def initialize
super()
@model_class = OpenC3::NoteModel
Expand Down Expand Up @@ -112,7 +114,7 @@ def show
if model_hash
render json: model_hash, status: 200
else
render json: { status: 'error', message: 'not found' }, status: 404
render json: { status: 'error', message: NOT_FOUND }, status: 404
end
end
end
Expand Down Expand Up @@ -144,7 +146,7 @@ def update
action do
hash = @model_class.get(start: params[:id].to_i, scope: params[:scope])
if hash.nil?
render json: { status: 'error', message: 'not found' }, status: 404
render json: { status: 'error', message: NOT_FOUND }, status: 404
return
end
model = @model_class.from_json(hash.symbolize_keys, scope: params[:scope])
Expand Down Expand Up @@ -184,7 +186,7 @@ def destroy
action do
count = @model_class.destroy(start: params[:id].to_i, scope: params[:scope])
if count == 0
render json: { status: 'error', message: 'not found' }, status: 404
render json: { status: 'error', message: NOT_FOUND }, status: 404
return
end
OpenC3::Logger.info(
Expand Down
12 changes: 7 additions & 5 deletions openc3-cosmos-cmd-tlm-api/app/controllers/reaction_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
require 'openc3/topics/autonomic_topic'

class ReactionController < ApplicationController
NOT_FOUND = 'not found'

def initialize
super()
@model_class = OpenC3::ReactionModel
Expand Down Expand Up @@ -147,7 +149,7 @@ def update
begin
model = @model_class.get(name: params[:name], scope: params[:scope])
if model.nil?
render :json => { :status => 'error', :message => 'not found' }, :status => 404
render :json => { :status => 'error', :message => NOT_FOUND }, :status => 404
return
end
hash = params.to_unsafe_h.slice(:snooze, :triggers, :triggerLevel, :actions).to_h
Expand Down Expand Up @@ -193,7 +195,7 @@ def enable
begin
model = @model_class.get(name: params[:name], scope: params[:scope])
if model.nil?
render :json => { :status => 'error', :message => 'not found' }, :status => 404
render :json => { :status => 'error', :message => NOT_FOUND }, :status => 404
return
end
# Notify the ReactionMicroservice to enable the ReactionModel
Expand Down Expand Up @@ -228,7 +230,7 @@ def disable
begin
model = @model_class.get(name: params[:name], scope: params[:scope])
if model.nil?
render :json => { :status => 'error', :message => 'not found' }, :status => 404
render :json => { :status => 'error', :message => NOT_FOUND }, :status => 404
return
end
# Notify the ReactionMicroservice to disable the ReactionModel
Expand All @@ -248,7 +250,7 @@ def execute
begin
model = @model_class.get(name: params[:name], scope: params[:scope])
if model.nil?
render :json => { :status => 'error', :message => 'not found' }, :status => 404
render :json => { :status => 'error', :message => NOT_FOUND }, :status => 404
return
end
# Notify the ReactionMicroservice to execute the ReactionModel
Expand Down Expand Up @@ -279,7 +281,7 @@ def destroy
begin
model = @model_class.get(name: params[:name], scope: params[:scope])
if model.nil?
render :json => { :status => 'error', :message => 'not found' }, :status => 404
render :json => { :status => 'error', :message => NOT_FOUND }, :status => 404
return
end
# Notify the ReactionMicroservice to delete the ReactionModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def keywords
TLM_KEYWORDS
when 'SCREEN'
screen_keywords()
else
[]
end
render :json => keywords, :status => 200
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ def destroy
model.undeploy()
model.notify(kind: 'deleted')
OpenC3::Logger.info("Timeline destroyed: #{params[:name]}", scope: params[:scope], user: username())
puts "Render:#{{ 'name' => params[:name]}}"
render :json => { 'name' => params[:name]}, :status => 204
rescue OpenC3::TimelineError => e
logger.error(e.formatted)
Expand Down
12 changes: 7 additions & 5 deletions openc3-cosmos-cmd-tlm-api/app/controllers/trigger_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
require 'openc3/topics/autonomic_topic'

class TriggerController < ApplicationController
NOT_FOUND = 'not found'

def initialize
@model_class = OpenC3::TriggerModel
end
Expand Down Expand Up @@ -59,7 +61,7 @@ def show
begin
model = @model_class.get(name: params[:name], group: params[:group], scope: params[:scope])
if model.nil?
render :json => { :status => 'error', :message => 'not found' }, :status => 404
render :json => { :status => 'error', :message => NOT_FOUND }, :status => 404
return
end
render :json => model.as_json(:allow_nan => true), :status => 200
Expand Down Expand Up @@ -157,7 +159,7 @@ def update
begin
model = @model_class.get(name: params[:name], group: params[:group], scope: params[:scope])
if model.nil?
render json: { status: 'error', message: 'not found' }, status: 404
render json: { status: 'error', message: NOT_FOUND }, status: 404
return
end
hash = params.to_unsafe_h.slice(:left, :operator, :right).to_h
Expand Down Expand Up @@ -203,7 +205,7 @@ def enable
begin
model = @model_class.get(name: params[:name], group: params[:group], scope: params[:scope])
if model.nil?
render :json => { :status => 'error', :message => 'not found' }, :status => 404
render :json => { :status => 'error', :message => NOT_FOUND }, :status => 404
return
end
# Notify the TriggerGroupMicroservice to enable the TriggerModel
Expand Down Expand Up @@ -239,7 +241,7 @@ def disable
begin
model = @model_class.get(name: params[:name], group: params[:group], scope: params[:scope])
if model.nil?
render :json => { :status => 'error', :message => 'not found' }, :status => 404
render :json => { :status => 'error', :message => NOT_FOUND }, :status => 404
return
end
# Notify the TriggerGroupMicroservice to disable the TriggerModel
Expand Down Expand Up @@ -269,7 +271,7 @@ def destroy
begin
model = @model_class.get(name: params[:name], group: params[:group], scope: params[:scope])
if model.nil?
render :json => { :status => 'error', :message => 'not found' }, :status => 404
render :json => { :status => 'error', :message => NOT_FOUND }, :status => 404
return
end
unless model.dependents.empty?
Expand Down
4 changes: 2 additions & 2 deletions openc3-cosmos-cmd-tlm-api/app/models/messages_thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ def handle_log_entry(log_entry)
return nil if @level == "ERROR" or @level == "FATAL"
when "ERROR"
return nil if @level == "FATAL"
else # 'FATAL'
return log_entry
end
# when "FATAL" fall through and return the log_entry
end

return log_entry
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

# Helper class to collect StreamingObjects
Expand Down Expand Up @@ -140,6 +140,7 @@ def apply_last_offsets(last_offsets)
end

def handoff(collection)
# empty for a reason
end

def length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def generate_activity_hash(start)
delete :destroy, params: {'scope'=>'DEFAULT', 'name'=>'test', "id"=>"200", "uuid"=>"123456"}
ret = JSON.parse(response.body, :allow_nan => true, :create_additions => true)
expect(ret['status']).to eql('error')
expect(ret['message']).to eql("Activity not found")
expect(ret['message']).to eql("not found")
expect(response).to have_http_status(:not_found)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
puts index
end

if false
puts false
else
puts true
end

wait_expression('false', 10)
wait(10)

Expand Down
Loading

0 comments on commit 6b5acfc

Please sign in to comment.