Skip to content

Commit

Permalink
Fix some RuboCop warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jvendetti committed Apr 17, 2023
1 parent ee324c0 commit 3a72c18
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions app/controllers/mappings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# frozen_string_literal: true

require 'cgi'

class MappingsController < ApplicationController
include ActionView::Helpers::NumberHelper
include MappingStatistics

layout :determine_layout
before_action :authorize_and_redirect, :only=>[:create,:new,:destroy]
before_action :authorize_and_redirect, only: [:create, :new, :destroy]

MAPPINGS_URL = "#{LinkedData::Client.settings.rest_url}/mappings"

def index
ontology_list = LinkedData::Client::Models::Ontology.all.select {|o| !o.summaryOnly}
ontology_list = LinkedData::Client::Models::Ontology.all.select { |o| !o.summaryOnly }
ontologies_mapping_count = LinkedData::Client::HTTP.get("#{MAPPINGS_URL}/statistics/ontologies")
ontologies_hash = {}
ontology_list.each do |ontology|
Expand All @@ -29,7 +31,7 @@ def index
next if ontology.nil?

mapping_count = ontologies_mapping_count[ontology_acronym]
next if mapping_count.nil? || mapping_count.to_i == 0
next if mapping_count.nil? || mapping_count.to_i.zero?

select_text = "#{ontology.name} - #{ontology.acronym} (#{number_with_delimiter(mapping_count, delimiter: ',')})"
@options[select_text] = ontology_acronym
Expand All @@ -54,7 +56,8 @@ def show

page = params[:page] || 1
ontologies = [@ontology.acronym, @target_ontology.acronym]
@mapping_pages = LinkedData::Client::HTTP.get(MAPPINGS_URL, {page: page, ontologies: ontologies.join(",")})
@mapping_pages = LinkedData::Client::HTTP.get(MAPPINGS_URL,
{ page: page, ontologies: ontologies.join(',') })
@mappings = @mapping_pages.collection
@delete_mapping_permission = check_delete_mapping_permission(@mappings)

Expand All @@ -68,29 +71,30 @@ def show
total_results = @mapping_pages.pageCount * @mapping_pages.collection.length

# This converts the mappings into an object that can be used with the pagination plugin
@page_results = WillPaginate::Collection.create(@mapping_pages.page, @mapping_pages.collection.length, total_results) do |pager|
pager.replace(@mapping_pages.collection)
@page_results = WillPaginate::Collection.create(@mapping_pages.page,
@mapping_pages.collection.length, total_results) do |pager|
pager.replace(@mapping_pages.collection)
end

render :partial => 'show'
render partial: 'show'
end

def get_concept_table
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontologyid]).first
@concept = @ontology.explore.single_class({full: true}, params[:conceptid])
@concept = @ontology.explore.single_class({ full: true }, params[:conceptid])

@mappings = @concept.explore.mappings

@delete_mapping_permission = check_delete_mapping_permission(@mappings)

render :partial => "mapping_table"
render partial: 'mapping_table'
end

def new
@ontology_from = LinkedData::Client::Models::Ontology.find(params[:ontology_from])
@ontology_to = LinkedData::Client::Models::Ontology.find(params[:ontology_to])
@concept_from = @ontology_from.explore.single_class({full: true}, params[:conceptid_from]) if @ontology_from
@concept_to = @ontology_to.explore.single_class({full: true}, params[:conceptid_to]) if @ontology_to
@concept_from = @ontology_from.explore.single_class({ full: true }, params[:conceptid_from]) if @ontology_from
@concept_to = @ontology_to.explore.single_class({ full: true }, params[:conceptid_to]) if @ontology_to

# Defaults just in case nothing gets provided
@ontology_from ||= LinkedData::Client::Models::Ontology.new
Expand All @@ -99,16 +103,16 @@ def new
@concept_to ||= LinkedData::Client::Models::Class.new

@mapping_relation_options = [
["Identical (skos:exactMatch)", "http://www.w3.org/2004/02/skos/core#exactMatch"],
["Similar (skos:closeMatch)", "http://www.w3.org/2004/02/skos/core#closeMatch"],
["Related (skos:relatedMatch)", "http://www.w3.org/2004/02/skos/core#relatedMatch"],
["Broader (skos:broadMatch)", "http://www.w3.org/2004/02/skos/core#broadMatch"],
["Narrower (skos:narrowMatch)", "http://www.w3.org/2004/02/skos/core#narrowMatch"]
['Identical (skos:exactMatch)', 'http://www.w3.org/2004/02/skos/core#exactMatch'],
['Similar (skos:closeMatch)', 'http://www.w3.org/2004/02/skos/core#closeMatch'],
['Related (skos:relatedMatch)', 'http://www.w3.org/2004/02/skos/core#relatedMatch'],
['Broader (skos:broadMatch)', 'http://www.w3.org/2004/02/skos/core#broadMatch'],
['Narrower (skos:narrowMatch)', 'http://www.w3.org/2004/02/skos/core#narrowMatch']
]

respond_to do |format|
format.js
end
end
end

# POST /mappings
Expand All @@ -133,25 +137,25 @@ def create
raise Exception, @mapping_saved.errors
else
@delete_mapping_permission = check_delete_mapping_permission(@mapping_saved)
render :json => @mapping_saved
render json: @mapping_saved
end
end

def destroy
errors = []
successes = []
mapping_ids = params[:mappingids].split(",")
mapping_ids = params[:mappingids].split(',')
mapping_ids.each do |map_id|
begin
map_uri = "#{MAPPINGS_URL}/#{CGI.escape(map_id)}"
result = LinkedData::Client::HTTP.delete(map_uri)
raise Exception if !result.nil? #&& result["errorCode"]
raise Exception if !result.nil? # && result["errorCode"]

successes << map_id
rescue Exception => e
errors << map_id
end
end
render :json => { :success => successes, :error => errors }
render json: { success: successes, error: errors }
end

end

0 comments on commit 3a72c18

Please sign in to comment.